1 SPDX-License-Identifier: GPL-2.0
2 aufs5.15.41 kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a6313a969bc5..aca4b89d41a1 100644
8 @@ -312,6 +312,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 84c5e4cdfee5..b4fcdad8412e 100644
20 @@ -138,3 +138,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 aufs5.15.41 base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index c8103e57a70b..e1b9eaca78fd 100644
32 @@ -3122,6 +3122,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 8cba10aafadb..7a9e40b97831 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -799,6 +799,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 cf871a81f4fd..bc5095b734f5 100644
85 @@ -1320,7 +1320,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 9c6c6a3e2de5..02382fa9bd34 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 b696543adab8..c45740054bc7 100644
120 @@ -808,6 +808,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 5dbce4dcc1a7..3e6ba363b777 100644
137 @@ -759,8 +759,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 @@ -770,9 +770,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 56eba723477e..e60d8ad85400 100644
163 --- a/include/linux/fs.h
164 +++ b/include/linux/fs.h
165 @@ -1381,6 +1381,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 @@ -2092,6 +2093,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 @@ -2615,6 +2617,7 @@ extern int current_umask(void);
182 extern void ihold(struct inode * inode);
183 extern void iput(struct inode *);
184 extern int generic_update_time(struct inode *, struct timespec64 *, int);
185 +extern int update_time(struct inode *, struct timespec64 *, int);
188 extern struct kobject *fs_kobj;
189 @@ -2778,6 +2781,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
192 void emergency_thaw_all(void);
193 +extern int __sync_filesystem(struct super_block *, int);
194 extern int sync_filesystem(struct super_block *);
195 extern const struct file_operations def_blk_fops;
196 extern const struct file_operations def_chr_fops;
197 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
198 index 9fe165beb0f9..e47f7e15eeaf 100644
199 --- a/include/linux/lockdep.h
200 +++ b/include/linux/lockdep.h
201 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
202 return lock->key == key;
205 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
210 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
211 index 8f882f5881e8..6b9808f09843 100644
212 --- a/include/linux/mnt_namespace.h
213 +++ b/include/linux/mnt_namespace.h
214 @@ -7,12 +7,15 @@ struct mnt_namespace;
216 struct user_namespace;
220 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
221 struct user_namespace *, struct fs_struct *);
222 extern void put_mnt_ns(struct mnt_namespace *ns);
223 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
225 +extern int is_current_mnt_ns(struct vfsmount *mnt);
227 extern const struct file_operations proc_mounts_operations;
228 extern const struct file_operations proc_mountinfo_operations;
229 extern const struct file_operations proc_mountstats_operations;
230 diff --git a/include/linux/splice.h b/include/linux/splice.h
231 index a55179fd60fc..8e21c53cf883 100644
232 --- a/include/linux/splice.h
233 +++ b/include/linux/splice.h
234 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
236 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
237 extern const struct pipe_buf_operations default_pipe_buf_ops;
239 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
240 + loff_t *ppos, size_t len, unsigned int flags);
241 +extern long do_splice_to(struct file *in, loff_t *ppos,
242 + struct pipe_inode_info *pipe, size_t len,
243 + unsigned int flags);
245 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
246 index a30702b847ba..ce380d0abdf0 100644
247 --- a/kernel/locking/lockdep.c
248 +++ b/kernel/locking/lockdep.c
249 @@ -187,7 +187,7 @@ unsigned long max_lock_class_idx;
250 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
251 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
253 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
254 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
256 unsigned int class_idx = hlock->class_idx;
258 @@ -208,6 +208,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
260 return lock_classes + class_idx;
262 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
264 #ifdef CONFIG_LOCK_STAT
265 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
266 SPDX-License-Identifier: GPL-2.0
267 aufs5.15.41 mmap patch
269 diff --git a/fs/proc/base.c b/fs/proc/base.c
270 index 1f394095eb88..93f2479ef319 100644
273 @@ -2189,7 +2189,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
275 vma = find_exact_vma(mm, vm_start, vm_end);
276 if (vma && vma->vm_file) {
277 - *path = vma->vm_file->f_path;
278 + *path = vma_pr_or_file(vma)->f_path;
282 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
283 index 13452b32e2bd..38acccfef9d4 100644
284 --- a/fs/proc/nommu.c
285 +++ b/fs/proc/nommu.c
286 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
287 file = region->vm_file;
290 - struct inode *inode = file_inode(region->vm_file);
291 + struct inode *inode;
293 + file = vmr_pr_or_file(region);
294 + inode = file_inode(file);
295 dev = inode->i_sb->s_dev;
298 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
299 index 79ca4d69dfd6..3d3067c8d868 100644
300 --- a/fs/proc/task_mmu.c
301 +++ b/fs/proc/task_mmu.c
302 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
303 const char *name = NULL;
306 - struct inode *inode = file_inode(vma->vm_file);
307 + struct inode *inode;
309 + file = vma_pr_or_file(vma);
310 + inode = file_inode(file);
311 dev = inode->i_sb->s_dev;
313 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
314 @@ -1888,7 +1891,7 @@ static int show_numa_map(struct seq_file *m, void *v)
315 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
316 struct vm_area_struct *vma = v;
317 struct numa_maps *md = &numa_priv->md;
318 - struct file *file = vma->vm_file;
319 + struct file *file = vma_pr_or_file(vma);
320 struct mm_struct *mm = vma->vm_mm;
321 struct mempolicy *pol;
323 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
324 index a6d21fc0033c..02c2de31196e 100644
325 --- a/fs/proc/task_nommu.c
326 +++ b/fs/proc/task_nommu.c
327 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
331 - struct inode *inode = file_inode(vma->vm_file);
332 + struct inode *inode;
334 + file = vma_pr_or_file(vma);
335 + inode = file_inode(file);
336 dev = inode->i_sb->s_dev;
338 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
339 diff --git a/include/linux/mm.h b/include/linux/mm.h
340 index 04345ff97f8c..4ab9bb75c894 100644
341 --- a/include/linux/mm.h
342 +++ b/include/linux/mm.h
343 @@ -1813,6 +1813,43 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
344 unmap_mapping_range(mapping, holebegin, holelen, 0);
347 +#if IS_ENABLED(CONFIG_AUFS_FS)
348 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
349 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
351 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
352 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
354 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
356 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
358 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
359 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
362 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
363 +extern void vmr_do_fput(struct vm_region *, const char[], int);
365 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
367 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
368 +#endif /* !CONFIG_MMU */
372 +#define vma_file_update_time(vma) file_update_time((vma)->vm_file)
373 +#define vma_pr_or_file(vma) (vma)->vm_file
374 +#define vma_get_file(vma) get_file((vma)->vm_file)
375 +#define vma_fput(vma) fput((vma)->vm_file)
378 +#define vmr_pr_or_file(region) (region)->vm_file
379 +#define vmr_fput(region) fput((region)->vm_file)
380 +#endif /* !CONFIG_MMU */
382 +#endif /* CONFIG_AUFS_FS */
384 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
385 void *buf, int len, unsigned int gup_flags);
386 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
387 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
388 index 7f8ee09c711f..8fea872e08f7 100644
389 --- a/include/linux/mm_types.h
390 +++ b/include/linux/mm_types.h
391 @@ -294,6 +294,9 @@ struct vm_region {
392 unsigned long vm_top; /* region allocated to here */
393 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
394 struct file *vm_file; /* the backing file or NULL */
395 +#if IS_ENABLED(CONFIG_AUFS_FS)
396 + struct file *vm_prfile; /* the virtual backing file or NULL */
399 int vm_usage; /* region usage count (access under nommu_region_sem) */
400 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
401 @@ -373,6 +376,9 @@ struct vm_area_struct {
402 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
404 struct file * vm_file; /* File we map to (can be NULL). */
405 +#if IS_ENABLED(CONFIG_AUFS_FS)
406 + struct file *vm_prfile; /* shadow of vm_file */
408 void * vm_private_data; /* was vm_pte (shared mem) */
411 diff --git a/kernel/fork.c b/kernel/fork.c
412 index 89475c994ca9..82f46f8f4090 100644
415 @@ -573,7 +573,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
417 struct address_space *mapping = file->f_mapping;
421 i_mmap_lock_write(mapping);
422 if (tmp->vm_flags & VM_SHARED)
423 mapping_allow_writable(mapping);
424 diff --git a/mm/Makefile b/mm/Makefile
425 index fc60a40ce954..d45773672730 100644
428 @@ -130,3 +130,4 @@ obj-$(CONFIG_PAGE_REPORTING) += page_reporting.o
429 obj-$(CONFIG_IO_MAPPING) += io-mapping.o
430 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
431 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
432 +obj-$(CONFIG_AUFS_FS:m=y) += prfile.o
433 diff --git a/mm/filemap.c b/mm/filemap.c
434 index 00e391e75880..d8b52d814319 100644
437 @@ -3353,7 +3353,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
438 vm_fault_t ret = VM_FAULT_LOCKED;
440 sb_start_pagefault(mapping->host->i_sb);
441 - file_update_time(vmf->vma->vm_file);
442 + vma_file_update_time(vmf->vma);
444 if (page->mapping != mapping) {
446 diff --git a/mm/mmap.c b/mm/mmap.c
447 index 6bb553ed5c55..3f9d6d155171 100644
450 @@ -183,7 +183,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
451 if (vma->vm_ops && vma->vm_ops->close)
452 vma->vm_ops->close(vma);
454 - fput(vma->vm_file);
456 mpol_put(vma_policy(vma));
459 @@ -952,7 +952,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
462 uprobe_munmap(next, next->vm_start, next->vm_end);
467 anon_vma_merge(vma, next);
468 @@ -1880,7 +1880,7 @@ close_and_free_vma:
469 if (vma->vm_ops && vma->vm_ops->close)
470 vma->vm_ops->close(vma);
472 - fput(vma->vm_file);
476 /* Undo any partial mapping done by a device driver. */
477 @@ -2723,7 +2723,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
481 - get_file(new->vm_file);
484 if (new->vm_ops && new->vm_ops->open)
485 new->vm_ops->open(new);
486 @@ -2742,7 +2742,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
487 if (new->vm_ops && new->vm_ops->close)
488 new->vm_ops->close(new);
490 - fput(new->vm_file);
492 unlink_anon_vmas(new);
494 mpol_put(vma_policy(new));
495 @@ -2938,6 +2938,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
496 unsigned long populate = 0;
497 unsigned long ret = -EINVAL;
499 +#if IS_ENABLED(CONFIG_AUFS_FS)
500 + struct file *prfile;
503 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
504 current->comm, current->pid);
505 @@ -2993,10 +2996,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
506 if (vma->vm_flags & VM_LOCKED)
509 +#if IS_ENABLED(CONFIG_AUFS_FS)
511 + file = vma->vm_file;
512 + prfile = vma->vm_prfile;
513 + ret = do_mmap(vma->vm_file, start, size,
514 + prot, flags, pgoff, &populate, NULL);
515 + if (!IS_ERR_VALUE(ret) && file && prfile) {
516 + struct vm_area_struct *new_vma;
518 + new_vma = find_vma(mm, ret);
519 + if (!new_vma->vm_prfile)
520 + new_vma->vm_prfile = prfile;
521 + if (new_vma != vma)
525 + * two fput()s instead of vma_fput(vma),
526 + * coz vma may not be available anymore.
532 file = get_file(vma->vm_file);
533 ret = do_mmap(vma->vm_file, start, size,
534 prot, flags, pgoff, &populate, NULL);
536 +#endif /* CONFIG_AUFS_FS */
538 mmap_write_unlock(mm);
540 @@ -3277,7 +3304,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
541 if (anon_vma_clone(new_vma, vma))
542 goto out_free_mempol;
543 if (new_vma->vm_file)
544 - get_file(new_vma->vm_file);
545 + vma_get_file(new_vma);
546 if (new_vma->vm_ops && new_vma->vm_ops->open)
547 new_vma->vm_ops->open(new_vma);
548 vma_link(mm, new_vma, prev, rb_link, rb_parent);
549 diff --git a/mm/nommu.c b/mm/nommu.c
550 index 02d2427b8f9e..a7419302ab4e 100644
553 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
554 up_write(&nommu_region_sem);
557 - fput(region->vm_file);
560 /* IO memory and memory shared directly out of the pagecache
561 * from ramfs/tmpfs mustn't be released here */
562 @@ -655,7 +655,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
563 if (vma->vm_ops && vma->vm_ops->close)
564 vma->vm_ops->close(vma);
566 - fput(vma->vm_file);
568 put_nommu_region(vma->vm_region);
571 @@ -1175,7 +1175,7 @@ unsigned long do_mmap(struct file *file,
572 goto error_just_free;
575 - fput(region->vm_file);
577 kmem_cache_free(vm_region_jar, region);
580 @@ -1252,10 +1252,10 @@ unsigned long do_mmap(struct file *file,
581 up_write(&nommu_region_sem);
584 - fput(region->vm_file);
586 kmem_cache_free(vm_region_jar, region);
588 - fput(vma->vm_file);
593 diff --git a/mm/prfile.c b/mm/prfile.c
595 index 000000000000..511543ab1b41
599 +// SPDX-License-Identifier: GPL-2.0
601 + * Mainly for aufs which mmap(2) different file and wants to print different
602 + * path in /proc/PID/maps.
603 + * Call these functions via macros defined in linux/mm.h.
605 + * See Documentation/filesystems/aufs/design/06mmap.txt
607 + * Copyright (c) 2014-2021 Junjro R. Okajima
608 + * Copyright (c) 2014 Ian Campbell
611 +#include <linux/mm.h>
612 +#include <linux/file.h>
613 +#include <linux/fs.h>
615 +/* #define PRFILE_TRACE */
616 +static inline void prfile_trace(struct file *f, struct file *pr,
617 + const char func[], int line, const char func2[])
621 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
625 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
628 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
630 + prfile_trace(f, pr, func, line, __func__);
631 + file_update_time(f);
633 + file_update_time(pr);
636 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
639 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
641 + prfile_trace(f, pr, func, line, __func__);
642 + return (f && pr) ? pr : f;
645 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
647 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
649 + prfile_trace(f, pr, func, line, __func__);
655 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
657 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
659 + prfile_trace(f, pr, func, line, __func__);
666 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
669 + struct file *f = region->vm_file, *pr = region->vm_prfile;
671 + prfile_trace(f, pr, func, line, __func__);
672 + return (f && pr) ? pr : f;
675 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
677 + struct file *f = region->vm_file, *pr = region->vm_prfile;
679 + prfile_trace(f, pr, func, line, __func__);
684 +#endif /* !CONFIG_MMU */
685 SPDX-License-Identifier: GPL-2.0
686 aufs5.15.41 standalone patch
688 diff --git a/fs/dcache.c b/fs/dcache.c
689 index bc5095b734f5..9508bd57a3bc 100644
692 @@ -1425,6 +1425,7 @@ void d_walk(struct dentry *parent, void *data,
696 +EXPORT_SYMBOL_GPL(d_walk);
699 struct vfsmount *mnt;
700 @@ -2970,6 +2971,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
702 write_sequnlock(&rename_lock);
704 +EXPORT_SYMBOL_GPL(d_exchange);
707 * d_ancestor - search for an ancestor
708 diff --git a/fs/exec.c b/fs/exec.c
709 index 29e865c59854..3ea36fa14622 100644
712 @@ -111,6 +111,7 @@ bool path_noexec(const struct path *path)
713 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
714 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
716 +EXPORT_SYMBOL_GPL(path_noexec);
720 diff --git a/fs/fcntl.c b/fs/fcntl.c
721 index 02382fa9bd34..3418c60b9014 100644
724 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
728 +EXPORT_SYMBOL_GPL(setfl);
730 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
732 diff --git a/fs/file_table.c b/fs/file_table.c
733 index e8c9016703ad..5e7a880830fb 100644
734 --- a/fs/file_table.c
735 +++ b/fs/file_table.c
736 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
738 return ERR_PTR(-ENFILE);
740 +EXPORT_SYMBOL_GPL(alloc_empty_file);
743 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
744 diff --git a/fs/namespace.c b/fs/namespace.c
745 index c45740054bc7..d3d750635610 100644
748 @@ -439,6 +439,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
749 mnt_dec_writers(real_mount(mnt));
752 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
755 * mnt_drop_write - give up write access to a mount
756 @@ -813,6 +814,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
758 return check_mnt(real_mount(mnt));
760 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
763 * vfsmount lock must be held for write
764 @@ -2011,6 +2013,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
768 +EXPORT_SYMBOL_GPL(iterate_mounts);
770 static void lock_mnt_tree(struct mount *mnt)
772 diff --git a/fs/notify/group.c b/fs/notify/group.c
773 index fb89c351295d..460ad19c2570 100644
774 --- a/fs/notify/group.c
775 +++ b/fs/notify/group.c
776 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
778 refcount_inc(&group->refcnt);
780 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
783 * Drop a reference to a group. Free it if it's through.
784 diff --git a/fs/open.c b/fs/open.c
785 index e0df1536eb69..81b2d7c83add 100644
788 @@ -65,6 +65,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
789 inode_unlock(dentry->d_inode);
792 +EXPORT_SYMBOL_GPL(do_truncate);
794 long vfs_truncate(const struct path *path, loff_t length)
796 diff --git a/fs/read_write.c b/fs/read_write.c
797 index af057c57bdc6..76017f8331fb 100644
798 --- a/fs/read_write.c
799 +++ b/fs/read_write.c
800 @@ -492,6 +492,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
804 +EXPORT_SYMBOL_GPL(vfs_read);
806 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
808 @@ -602,6 +603,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
809 file_end_write(file);
812 +EXPORT_SYMBOL_GPL(vfs_write);
814 /* file_ppos returns &file->f_pos or NULL if file is stream */
815 static inline loff_t *file_ppos(struct file *file)
816 diff --git a/fs/splice.c b/fs/splice.c
817 index 3e6ba363b777..7c1be373eb7c 100644
820 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
821 return warn_unsupported(out, "write");
822 return out->f_op->splice_write(pipe, out, ppos, len, flags);
824 +EXPORT_SYMBOL_GPL(do_splice_from);
827 * Attempt to initiate a splice from a file to a pipe.
828 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
829 return warn_unsupported(in, "read");
830 return in->f_op->splice_read(in, ppos, pipe, len, flags);
832 +EXPORT_SYMBOL_GPL(do_splice_to);
835 * splice_direct_to_actor - splices data directly between two non-pipes
836 diff --git a/fs/xattr.c b/fs/xattr.c
837 index 5c8c5175b385..ff7e9ff774b7 100644
840 @@ -384,6 +384,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
841 *xattr_value = value;
844 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
847 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
848 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
849 index ce380d0abdf0..409c7d1a6803 100644
850 --- a/kernel/locking/lockdep.c
851 +++ b/kernel/locking/lockdep.c
852 @@ -208,6 +208,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
854 return lock_classes + class_idx;
856 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
857 #define hlock_class(hlock) lockdep_hlock_class(hlock)
859 #ifdef CONFIG_LOCK_STAT
860 diff --git a/kernel/task_work.c b/kernel/task_work.c
861 index 1698fbe6f0e1..081b05acadf8 100644
862 --- a/kernel/task_work.c
863 +++ b/kernel/task_work.c
864 @@ -167,3 +167,4 @@ void task_work_run(void)
868 +EXPORT_SYMBOL_GPL(task_work_run);
869 diff --git a/security/security.c b/security/security.c
870 index da631339e969..894203de3bcb 100644
871 --- a/security/security.c
872 +++ b/security/security.c
873 @@ -1160,6 +1160,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
875 return call_int_hook(path_rmdir, 0, dir, dentry);
877 +EXPORT_SYMBOL_GPL(security_path_rmdir);
879 int security_path_unlink(const struct path *dir, struct dentry *dentry)
881 @@ -1176,6 +1177,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
883 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
885 +EXPORT_SYMBOL_GPL(security_path_symlink);
887 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
888 struct dentry *new_dentry)
889 @@ -1184,6 +1186,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
891 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
893 +EXPORT_SYMBOL_GPL(security_path_link);
895 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
896 const struct path *new_dir, struct dentry *new_dentry,
897 @@ -1211,6 +1214,7 @@ int security_path_truncate(const struct path *path)
899 return call_int_hook(path_truncate, 0, path);
901 +EXPORT_SYMBOL_GPL(security_path_truncate);
903 int security_path_chmod(const struct path *path, umode_t mode)
905 @@ -1218,6 +1222,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
907 return call_int_hook(path_chmod, 0, path, mode);
909 +EXPORT_SYMBOL_GPL(security_path_chmod);
911 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
913 @@ -1225,6 +1230,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
915 return call_int_hook(path_chown, 0, path, uid, gid);
917 +EXPORT_SYMBOL_GPL(security_path_chown);
919 int security_path_chroot(const struct path *path)
921 @@ -1325,6 +1331,7 @@ int security_inode_permission(struct inode *inode, int mask)
923 return call_int_hook(inode_permission, 0, inode, mask);
925 +EXPORT_SYMBOL_GPL(security_inode_permission);
927 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
929 @@ -1522,6 +1529,7 @@ int security_file_permission(struct file *file, int mask)
931 return fsnotify_perm(file, mask);
933 +EXPORT_SYMBOL_GPL(security_file_permission);
935 int security_file_alloc(struct file *file)
937 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
938 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
939 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-10-26 22:30:38.455982192 +0200
941 +What: /debug/aufs/si_<id>/
943 +Contact: J. R. Okajima <hooanon05g@gmail.com>
945 + Under /debug/aufs, a directory named si_<id> is created
946 + per aufs mount, where <id> is a unique id generated
949 +What: /debug/aufs/si_<id>/plink
951 +Contact: J. R. Okajima <hooanon05g@gmail.com>
953 + It has three lines and shows the information about the
954 + pseudo-link. The first line is a single number
955 + representing a number of buckets. The second line is a
956 + number of pseudo-links per buckets (separated by a
957 + blank). The last line is a single number representing a
958 + total number of psedo-links.
959 + When the aufs mount option 'noplink' is specified, it
960 + will show "1\n0\n0\n".
962 +What: /debug/aufs/si_<id>/xib
964 +Contact: J. R. Okajima <hooanon05g@gmail.com>
966 + It shows the consumed blocks by xib (External Inode Number
967 + Bitmap), its block size and file size.
968 + When the aufs mount option 'noxino' is specified, it
969 + will be empty. About XINO files, see the aufs manual.
971 +What: /debug/aufs/si_<id>/xi<branch-index>
973 +Contact: J. R. Okajima <hooanon05g@gmail.com>
975 + It shows the consumed blocks by xino (External Inode Number
976 + Translation Table), its link count, block size and file
978 + Due to the file size limit, there may exist multiple
979 + xino files per branch. In this case, "-N" is added to
980 + the filename and it corresponds to the index of the
981 + internal xino array. "-0" is omitted.
982 + When the aufs mount option 'noxino' is specified, Those
983 + entries won't exist. About XINO files, see the aufs
986 +What: /debug/aufs/si_<id>/xigen
988 +Contact: J. R. Okajima <hooanon05g@gmail.com>
990 + It shows the consumed blocks by xigen (External Inode
991 + Generation Table), its block size and file size.
992 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
994 + When the aufs mount option 'noxino' is specified, it
995 + will be empty. About XINO files, see the aufs manual.
996 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
997 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
998 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-10-26 22:30:38.455982192 +0200
1000 +What: /sys/fs/aufs/si_<id>/
1002 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1004 + Under /sys/fs/aufs, a directory named si_<id> is created
1005 + per aufs mount, where <id> is a unique id generated
1008 +What: /sys/fs/aufs/si_<id>/br<idx>
1010 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1012 + It shows the abolute path of a member directory (which
1013 + is called branch) in aufs, and its permission.
1015 +What: /sys/fs/aufs/si_<id>/brid<idx>
1017 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1019 + It shows the id of a member directory (which is called
1022 +What: /sys/fs/aufs/si_<id>/xi_path
1024 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1026 + It shows the abolute path of XINO (External Inode Number
1027 + Bitmap, Translation Table and Generation Table) file
1028 + even if it is the default path.
1029 + When the aufs mount option 'noxino' is specified, it
1030 + will be empty. About XINO files, see the aufs manual.
1031 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1032 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1033 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-10-26 22:30:38.459315526 +0200
1036 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1038 +# This program is free software; you can redistribute it and/or modify
1039 +# it under the terms of the GNU General Public License as published by
1040 +# the Free Software Foundation; either version 2 of the License, or
1041 +# (at your option) any later version.
1043 +# This program is distributed in the hope that it will be useful,
1044 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1045 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1046 +# GNU General Public License for more details.
1048 +# You should have received a copy of the GNU General Public License
1049 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1052 +----------------------------------------
1054 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1055 +1. abbrev. for "advanced multi-layered unification filesystem".
1056 +2. abbrev. for "another unionfs".
1057 +3. abbrev. for "auf das" in German which means "on the" in English.
1058 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1059 + But "Filesystem aufs Filesystem" is hard to understand.
1060 +4. abbrev. for "African Urban Fashion Show".
1062 +AUFS is a filesystem with features:
1063 +- multi layered stackable unification filesystem, the member directory
1064 + is called as a branch.
1065 +- branch permission and attribute, 'readonly', 'real-readonly',
1066 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1068 +- internal "file copy-on-write".
1069 +- logical deletion, whiteout.
1070 +- dynamic branch manipulation, adding, deleting and changing permission.
1071 +- allow bypassing aufs, user's direct branch access.
1072 +- external inode number translation table and bitmap which maintains the
1073 + persistent aufs inode number.
1074 +- seekable directory, including NFS readdir.
1075 +- file mapping, mmap and sharing pages.
1076 +- pseudo-link, hardlink over branches.
1077 +- loopback mounted filesystem as a branch.
1078 +- several policies to select one among multiple writable branches.
1079 +- revert a single systemcall when an error occurs in aufs.
1083 +Multi Layered Stackable Unification Filesystem
1084 +----------------------------------------------------------------------
1085 +Most people already knows what it is.
1086 +It is a filesystem which unifies several directories and provides a
1087 +merged single directory. When users access a file, the access will be
1088 +passed/re-directed/converted (sorry, I am not sure which English word is
1089 +correct) to the real file on the member filesystem. The member
1090 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1091 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1092 +readonly branch is handled by creating 'whiteout' on the upper writable
1095 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1096 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1097 +different approaches to implement the merged-view.
1098 +The former tries putting it into VFS, and the latter implements as a
1099 +separate filesystem.
1100 +(If I misunderstand about these implementations, please let me know and
1101 +I shall correct it. Because it is a long time ago when I read their
1102 +source files last time).
1104 +UnionMount's approach will be able to small, but may be hard to share
1105 +branches between several UnionMount since the whiteout in it is
1106 +implemented in the inode on branch filesystem and always
1107 +shared. According to Bharata's post, readdir does not seems to be
1109 +There are several missing features known in this implementations such as
1110 +- for users, the inode number may change silently. eg. copy-up.
1111 +- link(2) may break by copy-up.
1112 +- read(2) may get an obsoleted filedata (fstat(2) too).
1113 +- fcntl(F_SETLK) may be broken by copy-up.
1114 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1117 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1118 +merged into mainline. This is another implementation of UnionMount as a
1119 +separated filesystem. All the limitations and known problems which
1120 +UnionMount are equally inherited to "overlay" filesystem.
1122 +Unionfs has a longer history. When I started implementing a stackable
1123 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1124 +inode, dentry and file objects and they have an array pointing lower
1125 +same kind objects. After contributing many patches for Unionfs, I
1126 +re-started my project AUFS (Jun 2006).
1128 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1129 +implemented my own ideas, approaches and enhancements and it became
1130 +totally different one.
1132 +Comparing DM snapshot and fs based implementation
1133 +- the number of bytes to be copied between devices is much smaller.
1134 +- the type of filesystem must be one and only.
1135 +- the fs must be writable, no readonly fs, even for the lower original
1136 + device. so the compression fs will not be usable. but if we use
1137 + loopback mount, we may address this issue.
1139 + mount /cdrom/squashfs.img /sq
1140 + losetup /sq/ext2.img
1141 + losetup /somewhere/cow
1142 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1143 +- it will be difficult (or needs more operations) to extract the
1144 + difference between the original device and COW.
1145 +- DM snapshot-merge may help a lot when users try merging. in the
1146 + fs-layer union, users will use rsync(1).
1148 +You may want to read my old paper "Filesystems in LiveCD"
1149 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1152 +Several characters/aspects/persona of aufs
1153 +----------------------------------------------------------------------
1155 +Aufs has several characters, aspects or persona.
1156 +1. a filesystem, callee of VFS helper
1157 +2. sub-VFS, caller of VFS helper for branches
1158 +3. a virtual filesystem which maintains persistent inode number
1159 +4. reader/writer of files on branches such like an application
1161 +1. Callee of VFS Helper
1162 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1163 +unlink(2) from an application reaches sys_unlink() kernel function and
1164 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1165 +calls filesystem specific unlink operation. Actually aufs implements the
1166 +unlink operation but it behaves like a redirector.
1168 +2. Caller of VFS Helper for Branches
1169 +aufs_unlink() passes the unlink request to the branch filesystem as if
1170 +it were called from VFS. So the called unlink operation of the branch
1171 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1172 +every necessary pre/post operation for the branch filesystem.
1173 +- acquire the lock for the parent dir on a branch
1174 +- lookup in a branch
1175 +- revalidate dentry on a branch
1176 +- mnt_want_write() for a branch
1177 +- vfs_unlink() for a branch
1178 +- mnt_drop_write() for a branch
1179 +- release the lock on a branch
1181 +3. Persistent Inode Number
1182 +One of the most important issue for a filesystem is to maintain inode
1183 +numbers. This is particularly important to support exporting a
1184 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1185 +backend block device for its own. But some storage is necessary to
1186 +keep and maintain the inode numbers. It may be a large space and may not
1187 +suit to keep in memory. Aufs rents some space from its first writable
1188 +branch filesystem (by default) and creates file(s) on it. These files
1189 +are created by aufs internally and removed soon (currently) keeping
1191 +Note: Because these files are removed, they are totally gone after
1192 + unmounting aufs. It means the inode numbers are not persistent
1193 + across unmount or reboot. I have a plan to make them really
1194 + persistent which will be important for aufs on NFS server.
1196 +4. Read/Write Files Internally (copy-on-write)
1197 +Because a branch can be readonly, when you write a file on it, aufs will
1198 +"copy-up" it to the upper writable branch internally. And then write the
1199 +originally requested thing to the file. Generally kernel doesn't
1200 +open/read/write file actively. In aufs, even a single write may cause a
1201 +internal "file copy". This behaviour is very similar to cp(1) command.
1203 +Some people may think it is better to pass such work to user space
1204 +helper, instead of doing in kernel space. Actually I am still thinking
1205 +about it. But currently I have implemented it in kernel space.
1206 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1207 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1208 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-10-26 22:30:38.459315526 +0200
1211 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1213 +# This program is free software; you can redistribute it and/or modify
1214 +# it under the terms of the GNU General Public License as published by
1215 +# the Free Software Foundation; either version 2 of the License, or
1216 +# (at your option) any later version.
1218 +# This program is distributed in the hope that it will be useful,
1219 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1220 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1221 +# GNU General Public License for more details.
1223 +# You should have received a copy of the GNU General Public License
1224 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1226 +Basic Aufs Internal Structure
1228 +Superblock/Inode/Dentry/File Objects
1229 +----------------------------------------------------------------------
1230 +As like an ordinary filesystem, aufs has its own
1231 +superblock/inode/dentry/file objects. All these objects have a
1232 +dynamically allocated array and store the same kind of pointers to the
1233 +lower filesystem, branch.
1234 +For example, when you build a union with one readwrite branch and one
1235 +readonly, mounted /au, /rw and /ro respectively.
1237 +- /ro/fileA exists but /rw/fileA
1239 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1240 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1241 +- [0] = NULL (because /rw/fileA doesn't exist)
1244 +This style of an array is essentially same to the aufs
1245 +superblock/inode/dentry/file objects.
1247 +Because aufs supports manipulating branches, ie. add/delete/change
1248 +branches dynamically, these objects has its own generation. When
1249 +branches are changed, the generation in aufs superblock is
1250 +incremented. And a generation in other object are compared when it is
1251 +accessed. When a generation in other objects are obsoleted, aufs
1252 +refreshes the internal array.
1256 +----------------------------------------------------------------------
1257 +Additionally aufs superblock has some data for policies to select one
1258 +among multiple writable branches, XIB files, pseudo-links and kobject.
1259 +See below in detail.
1260 +About the policies which supports copy-down a directory, see
1261 +wbr_policy.txt too.
1264 +Branch and XINO(External Inode Number Translation Table)
1265 +----------------------------------------------------------------------
1266 +Every branch has its own xino (external inode number translation table)
1267 +file. The xino file is created and unlinked by aufs internally. When two
1268 +members of a union exist on the same filesystem, they share the single
1270 +The struct of a xino file is simple, just a sequence of aufs inode
1271 +numbers which is indexed by the lower inode number.
1272 +In the above sample, assume the inode number of /ro/fileA is i111 and
1273 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1274 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1276 +When the inode numbers are not contiguous, the xino file will be sparse
1277 +which has a hole in it and doesn't consume as much disk space as it
1278 +might appear. If your branch filesystem consumes disk space for such
1279 +holes, then you should specify 'xino=' option at mounting aufs.
1281 +Aufs has a mount option to free the disk blocks for such holes in XINO
1282 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1283 +meet a problem of disk shortage due to XINO files, then you should try
1284 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1285 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1286 +the holes in XINO files.
1288 +Also a writable branch has three kinds of "whiteout bases". All these
1289 +are existed when the branch is joined to aufs, and their names are
1290 +whiteout-ed doubly, so that users will never see their names in aufs
1292 +1. a regular file which will be hardlinked to all whiteouts.
1293 +2. a directory to store a pseudo-link.
1294 +3. a directory to store an "orphan"-ed file temporary.
1297 + When you remove a file on a readonly branch, aufs handles it as a
1298 + logical deletion and creates a whiteout on the upper writable branch
1299 + as a hardlink of this file in order not to consume inode on the
1302 + See below, Pseudo-link.
1304 + When "fileC" exists on the lower readonly branch only and it is
1305 + opened and removed with its parent dir, and then user writes
1306 + something into it, then aufs copies-up fileC to this
1307 + directory. Because there is no other dir to store fileC. After
1308 + creating a file under this dir, the file is unlinked.
1310 +Because aufs supports manipulating branches, ie. add/delete/change
1311 +dynamically, a branch has its own id. When the branch order changes,
1312 +aufs finds the new index by searching the branch id.
1316 +----------------------------------------------------------------------
1317 +Assume "fileA" exists on the lower readonly branch only and it is
1318 +hardlinked to "fileB" on the branch. When you write something to fileA,
1319 +aufs copies-up it to the upper writable branch. Additionally aufs
1320 +creates a hardlink under the Pseudo-link Directory of the writable
1321 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1322 +simple list. If fileB is read after unlinking fileA, aufs returns
1323 +filedata from the pseudo-link instead of the lower readonly
1324 +branch. Because the pseudo-link is based upon the inode, to keep the
1325 +inode number by xino (see above) is essentially necessary.
1327 +All the hardlinks under the Pseudo-link Directory of the writable branch
1328 +should be restored in a proper location later. Aufs provides a utility
1329 +to do this. The userspace helpers executed at remounting and unmounting
1331 +During this utility is running, it puts aufs into the pseudo-link
1332 +maintenance mode. In this mode, only the process which began the
1333 +maintenance mode (and its child processes) is allowed to operate in
1334 +aufs. Some other processes which are not related to the pseudo-link will
1335 +be allowed to run too, but the rest have to return an error or wait
1336 +until the maintenance mode ends. If a process already acquires an inode
1337 +mutex (in VFS), it has to return an error.
1340 +XIB(external inode number bitmap)
1341 +----------------------------------------------------------------------
1342 +Addition to the xino file per a branch, aufs has an external inode number
1343 +bitmap in a superblock object. It is also an internal file such like a
1345 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1347 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1349 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1350 +reduce the number of consumed disk blocks for these files.
1353 +Virtual or Vertical Dir, and Readdir in Userspace
1354 +----------------------------------------------------------------------
1355 +In order to support multiple layers (branches), aufs readdir operation
1356 +constructs a virtual dir block on memory. For readdir, aufs calls
1357 +vfs_readdir() internally for each dir on branches, merges their entries
1358 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1359 +object. So the file object has its entry list until it is closed. The
1360 +entry list will be updated when the file position is zero and becomes
1361 +obsoleted. This decision is made in aufs automatically.
1363 +The dynamically allocated memory block for the name of entries has a
1364 +unit of 512 bytes (by default) and stores the names contiguously (no
1365 +padding). Another block for each entry is handled by kmem_cache too.
1366 +During building dir blocks, aufs creates hash list and judging whether
1367 +the entry is whiteouted by its upper branch or already listed.
1368 +The merged result is cached in the corresponding inode object and
1369 +maintained by a customizable life-time option.
1371 +Some people may call it can be a security hole or invite DoS attack
1372 +since the opened and once readdir-ed dir (file object) holds its entry
1373 +list and becomes a pressure for system memory. But I'd say it is similar
1374 +to files under /proc or /sys. The virtual files in them also holds a
1375 +memory page (generally) while they are opened. When an idea to reduce
1376 +memory for them is introduced, it will be applied to aufs too.
1377 +For those who really hate this situation, I've developed readdir(3)
1378 +library which operates this merging in userspace. You just need to set
1379 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1380 +kernel space for readdir(3).
1384 +----------------------------------------------------------------------
1385 +Aufs sometimes requires privilege access to a branch. For instance,
1386 +in copy-up/down operation. When a user process is going to make changes
1387 +to a file which exists in the lower readonly branch only, and the mode
1388 +of one of ancestor directories may not be writable by a user
1389 +process. Here aufs copy-up the file with its ancestors and they may
1390 +require privilege to set its owner/group/mode/etc.
1391 +This is a typical case of a application character of aufs (see
1394 +Aufs uses workqueue synchronously for this case. It creates its own
1395 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1396 +passes the request to call mkdir or write (for example), and wait for
1397 +its completion. This approach solves a problem of a signal handler
1399 +If aufs didn't adopt the workqueue and changed the privilege of the
1400 +process, then the process may receive the unexpected SIGXFSZ or other
1403 +Also aufs uses the system global workqueue ("events" kernel thread) too
1404 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1405 +whiteout base and etc. This is unrelated to a privilege.
1406 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1407 +superblock at the beginning, at the same time waits for the completion
1408 +of all queued asynchronous tasks.
1412 +----------------------------------------------------------------------
1413 +The whiteout in aufs is very similar to Unionfs's. That is represented
1414 +by its filename. UnionMount takes an approach of a file mode, but I am
1415 +afraid several utilities (find(1) or something) will have to support it.
1417 +Basically the whiteout represents "logical deletion" which stops aufs to
1418 +lookup further, but also it represents "dir is opaque" which also stop
1421 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1422 +In order to make several functions in a single systemcall to be
1423 +revertible, aufs adopts an approach to rename a directory to a temporary
1424 +unique whiteouted name.
1425 +For example, in rename(2) dir where the target dir already existed, aufs
1426 +renames the target dir to a temporary unique whiteouted name before the
1427 +actual rename on a branch, and then handles other actions (make it opaque,
1428 +update the attributes, etc). If an error happens in these actions, aufs
1429 +simply renames the whiteouted name back and returns an error. If all are
1430 +succeeded, aufs registers a function to remove the whiteouted unique
1431 +temporary name completely and asynchronously to the system global
1436 +----------------------------------------------------------------------
1437 +It is a well-known feature or concept.
1438 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1439 +internally and makes change to the new file on the upper writable branch.
1440 +When the trigger systemcall does not update the timestamps of the parent
1441 +dir, aufs reverts it after copy-up.
1444 +Move-down (aufs3.9 and later)
1445 +----------------------------------------------------------------------
1446 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1447 +the lower readonly branch to the upper writable branch when a user
1448 +changes something about the file.
1449 +"Move-down" is an opposite action of copy-up. Basically this action is
1450 +ran manually instead of automatically and internally.
1451 +For desgin and implementation, aufs has to consider these issues.
1452 +- whiteout for the file may exist on the lower branch.
1453 +- ancestor directories may not exist on the lower branch.
1454 +- diropq for the ancestor directories may exist on the upper branch.
1455 +- free space on the lower branch will reduce.
1456 +- another access to the file may happen during moving-down, including
1457 + UDBA (see "Revalidate Dentry and UDBA").
1458 +- the file should not be hard-linked nor pseudo-linked. they should be
1459 + handled by auplink utility later.
1461 +Sometimes users want to move-down a file from the upper writable branch
1462 +to the lower readonly or writable branch. For instance,
1463 +- the free space of the upper writable branch is going to run out.
1464 +- create a new intermediate branch between the upper and lower branch.
1467 +For this purpose, use "aumvdown" command in aufs-util.git.
1468 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1469 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1470 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-10-26 22:30:38.459315526 +0200
1473 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1475 +# This program is free software; you can redistribute it and/or modify
1476 +# it under the terms of the GNU General Public License as published by
1477 +# the Free Software Foundation; either version 2 of the License, or
1478 +# (at your option) any later version.
1480 +# This program is distributed in the hope that it will be useful,
1481 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1482 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1483 +# GNU General Public License for more details.
1485 +# You should have received a copy of the GNU General Public License
1486 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1488 +Support for a branch who has its ->atomic_open()
1489 +----------------------------------------------------------------------
1490 +The filesystems who implement its ->atomic_open() are not majority. For
1491 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1492 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1493 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1494 +sure whether all filesystems who have ->atomic_open() behave like this,
1495 +but NFSv4 surely returns the error.
1497 +In order to support ->atomic_open() for aufs, there are a few
1500 +A. Introduce aufs_atomic_open()
1501 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1503 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1504 + an aufs user Pip Cet's approach
1505 + - calls aufs_create(), VFS finish_open() and notify_change().
1506 + - pass fake-mode to finish_open(), and then correct the mode by
1508 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1509 + - no aufs_atomic_open().
1510 + - aufs_lookup() registers the TID to an aufs internal object.
1511 + - aufs_create() does nothing when the matching TID is registered, but
1512 + registers the mode.
1513 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1514 + TID is registered.
1515 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1517 + - no aufs_atomic_open().
1518 + - aufs_create() registers the TID to an internal object. this info
1519 + represents "this process created this file just now."
1520 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1521 + registered TID and re-try open() with superuser's credential.
1523 +Pros and cons for each approach.
1526 + - straightforward but highly depends upon VFS internal.
1527 + - the atomic behavaiour is kept.
1528 + - some of parameters such as nameidata are hard to reproduce for
1532 + - easy to implement.
1533 + - the atomic behavaiour is lost.
1535 + - the atomic behavaiour is kept.
1536 + - dirty and tricky.
1537 + - VFS checks whether the file is created correctly after calling
1538 + ->create(), which means this approach doesn't work.
1540 + - easy to implement.
1541 + - the atomic behavaiour is lost.
1542 + - to open a file with superuser's credential and give it to a user
1543 + process is a bad idea, since the file object keeps the credential
1544 + in it. It may affect LSM or something. This approach doesn't work
1547 +The approach A is ideal, but it hard to implement. So here is a
1548 +variation of A, which is to be implemented.
1550 +A-1. Introduce aufs_atomic_open()
1551 + - calls branch fs ->atomic_open() if exists. otherwise calls
1552 + vfs_create() and finish_open().
1553 + - the demerit is that the several checks after branch fs
1554 + ->atomic_open() are lost. in the ordinary case, the checks are
1555 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1556 + be implemented in aufs, but not all I am afraid.
1557 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1558 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1559 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-10-26 22:30:38.459315526 +0200
1562 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1564 +# This program is free software; you can redistribute it and/or modify
1565 +# it under the terms of the GNU General Public License as published by
1566 +# the Free Software Foundation; either version 2 of the License, or
1567 +# (at your option) any later version.
1569 +# This program is distributed in the hope that it will be useful,
1570 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1571 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1572 +# GNU General Public License for more details.
1574 +# You should have received a copy of the GNU General Public License
1575 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1578 +----------------------------------------------------------------------
1579 +Since aufs has a character of sub-VFS (see Introduction), it operates
1580 +lookup for branches as VFS does. It may be a heavy work. But almost all
1581 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1582 +directly connected to its parent. Digging down the directory hierarchy
1583 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1586 +When a branch is a remote filesystem, aufs basically relies upon its
1587 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1589 +For d_revalidate, aufs implements three levels of revalidate tests. See
1590 +"Revalidate Dentry and UDBA" in detail.
1593 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1594 +----------------------------------------------------------------------
1595 +Let's try case study.
1596 +- aufs has two branches, upper readwrite and lower readonly.
1598 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1599 +- user invoked "chmod a+rx /au/dirA"
1600 +- the internal copy-up is activated and "/rw/dirA" is created and its
1601 + permission bits are set to world readable.
1602 +- then "/au/dirA" becomes world readable?
1604 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1605 +or it may be a natively readonly filesystem. If aufs respects the lower
1606 +branch, it should not respond readdir request from other users. But user
1607 +allowed it by chmod. Should really aufs rejects showing the entries
1610 +To be honest, I don't have a good solution for this case. So aufs
1611 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1613 +When dirperm1 is specified, aufs checks only the highest one for the
1614 +directory permission, and shows the entries. Otherwise, as usual, checks
1615 +every dir existing on all branches and rejects the request.
1617 +As a side effect, dirperm1 option improves the performance of aufs
1618 +because the number of permission check is reduced when the number of
1622 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1623 +----------------------------------------------------------------------
1624 +Generally VFS helpers re-validate a dentry as a part of lookup.
1625 +0. digging down the directory hierarchy.
1626 +1. lock the parent dir by its i_mutex.
1627 +2. lookup the final (child) entry.
1629 +4. call the actual operation (create, unlink, etc.)
1630 +5. unlock the parent dir
1632 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1633 +called. Actually aufs implements it and checks the dentry on a branch is
1635 +But it is not enough. Because aufs has to release the lock for the
1636 +parent dir on a branch at the end of ->lookup() (step 2) and
1637 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1639 +If the file on a branch is changed directly, eg. bypassing aufs, after
1640 +aufs released the lock, then the subsequent operation may cause
1641 +something unpleasant result.
1643 +This situation is a result of VFS architecture, ->lookup() and
1644 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1645 +design from VFS's point of view. It is just not suitable for sub-VFS
1648 +Aufs supports such case by three level of revalidation which is
1649 +selectable by user.
1650 +1. Simple Revalidate
1651 + Addition to the native flow in VFS's, confirm the child-parent
1652 + relationship on the branch just after locking the parent dir on the
1653 + branch in the "actual operation" (step 4). When this validation
1654 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1655 + checks the validation of the dentry on branches.
1656 +2. Monitor Changes Internally by Inotify/Fsnotify
1657 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1658 + the dentry on the branch, and returns EBUSY if it finds different
1660 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1661 + during it is in cache. When the event is notified, aufs registers a
1662 + function to kernel 'events' thread by schedule_work(). And the
1663 + function sets some special status to the cached aufs dentry and inode
1664 + private data. If they are not cached, then aufs has nothing to
1665 + do. When the same file is accessed through aufs (step 0-3) later,
1666 + aufs will detect the status and refresh all necessary data.
1667 + In this mode, aufs has to ignore the event which is fired by aufs
1669 +3. No Extra Validation
1670 + This is the simplest test and doesn't add any additional revalidation
1671 + test, and skip the revalidation in step 4. It is useful and improves
1672 + aufs performance when system surely hide the aufs branches from user,
1673 + by over-mounting something (or another method).
1674 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1675 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1676 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-10-26 22:30:38.459315526 +0200
1679 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1681 +# This program is free software; you can redistribute it and/or modify
1682 +# it under the terms of the GNU General Public License as published by
1683 +# the Free Software Foundation; either version 2 of the License, or
1684 +# (at your option) any later version.
1686 +# This program is distributed in the hope that it will be useful,
1687 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1688 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1689 +# GNU General Public License for more details.
1691 +# You should have received a copy of the GNU General Public License
1692 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1694 +Branch Manipulation
1696 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1697 +and changing its permission/attribute, there are a lot of works to do.
1701 +----------------------------------------------------------------------
1702 +o Confirm the adding dir exists outside of aufs, including loopback
1703 + mount, and its various attributes.
1704 +o Initialize the xino file and whiteout bases if necessary.
1707 +o Check the owner/group/mode of the directory
1708 + When the owner/group/mode of the adding directory differs from the
1709 + existing branch, aufs issues a warning because it may impose a
1711 + For example, when a upper writable branch has a world writable empty
1712 + top directory, a malicious user can create any files on the writable
1713 + branch directly, like copy-up and modify manually. If something like
1714 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1715 + writable branch, and the writable branch is world-writable, then a
1716 + malicious guy may create /etc/passwd on the writable branch directly
1717 + and the infected file will be valid in aufs.
1718 + I am afraid it can be a security issue, but aufs can do nothing except
1719 + producing a warning.
1723 +----------------------------------------------------------------------
1724 +o Confirm the deleting branch is not busy
1725 + To be general, there is one merit to adopt "remount" interface to
1726 + manipulate branches. It is to discard caches. At deleting a branch,
1727 + aufs checks the still cached (and connected) dentries and inodes. If
1728 + there are any, then they are all in-use. An inode without its
1729 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1731 + For the cached one, aufs checks whether the same named entry exists on
1733 + If the cached one is a directory, because aufs provides a merged view
1734 + to users, as long as one dir is left on any branch aufs can show the
1735 + dir to users. In this case, the branch can be removed from aufs.
1736 + Otherwise aufs rejects deleting the branch.
1738 + If any file on the deleting branch is opened by aufs, then aufs
1742 +Modify the Permission of a Branch
1743 +----------------------------------------------------------------------
1744 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1747 +o rw --> ro: Confirm the modifying branch is not busy
1748 + Aufs rejects the request if any of these conditions are true.
1749 + - a file on the branch is mmap-ed.
1750 + - a regular file on the branch is opened for write and there is no
1751 + same named entry on the upper branch.
1752 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1753 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1754 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-10-26 22:30:38.459315526 +0200
1757 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1759 +# This program is free software; you can redistribute it and/or modify
1760 +# it under the terms of the GNU General Public License as published by
1761 +# the Free Software Foundation; either version 2 of the License, or
1762 +# (at your option) any later version.
1764 +# This program is distributed in the hope that it will be useful,
1765 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1766 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1767 +# GNU General Public License for more details.
1769 +# You should have received a copy of the GNU General Public License
1770 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1772 +Policies to Select One among Multiple Writable Branches
1773 +----------------------------------------------------------------------
1774 +When the number of writable branch is more than one, aufs has to decide
1775 +the target branch for file creation or copy-up. By default, the highest
1776 +writable branch which has the parent (or ancestor) dir of the target
1777 +file is chosen (top-down-parent policy).
1778 +By user's request, aufs implements some other policies to select the
1779 +writable branch, for file creation several policies, round-robin,
1780 +most-free-space, and other policies. For copy-up, top-down-parent,
1781 +bottom-up-parent, bottom-up and others.
1783 +As expected, the round-robin policy selects the branch in circular. When
1784 +you have two writable branches and creates 10 new files, 5 files will be
1785 +created for each branch. mkdir(2) systemcall is an exception. When you
1786 +create 10 new directories, all will be created on the same branch.
1787 +And the most-free-space policy selects the one which has most free
1788 +space among the writable branches. The amount of free space will be
1789 +checked by aufs internally, and users can specify its time interval.
1791 +The policies for copy-up is more simple,
1792 +top-down-parent is equivalent to the same named on in create policy,
1793 +bottom-up-parent selects the writable branch where the parent dir
1794 +exists and the nearest upper one from the copyup-source,
1795 +bottom-up selects the nearest upper writable branch from the
1796 +copyup-source, regardless the existence of the parent dir.
1798 +There are some rules or exceptions to apply these policies.
1799 +- If there is a readonly branch above the policy-selected branch and
1800 + the parent dir is marked as opaque (a variation of whiteout), or the
1801 + target (creating) file is whiteout-ed on the upper readonly branch,
1802 + then the result of the policy is ignored and the target file will be
1803 + created on the nearest upper writable branch than the readonly branch.
1804 +- If there is a writable branch above the policy-selected branch and
1805 + the parent dir is marked as opaque or the target file is whiteouted
1806 + on the branch, then the result of the policy is ignored and the target
1807 + file will be created on the highest one among the upper writable
1808 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1810 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1811 + They try selecting the branch where the source exists as possible
1812 + since copyup a large file will take long time. If it can't be,
1813 + ie. the branch where the source exists is readonly, then they will
1814 + follow the copyup policy.
1815 +- There is an exception for rename(2) when the target exists.
1816 + If the rename target exists, aufs compares the index of the branches
1817 + where the source and the target exists and selects the higher
1818 + one. If the selected branch is readonly, then aufs follows the
1820 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1821 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1822 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-10-26 22:30:38.459315526 +0200
1825 +// to view this graph, run dot(1) command in GRAPHVIZ.
1829 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1833 +aufs_rename -> whinfo [label="store/remove"];
1836 +inode_list [label="h_inum list in branch\ncache"];
1839 +whinode [label="h_inum list file"];
1842 +brmgmt [label="br_add/del/mod/umount"];
1844 +brmgmt -> inode_list [label="create/remove"];
1845 +brmgmt -> whinode [label="load/store"];
1847 +inode_list -> whinode [style=dashed,dir=both];
1849 +aufs_rename -> inode_list [label="add/del"];
1851 +aufs_lookup -> inode_list [label="search"];
1853 +aufs_lookup -> whinfo [label="load/remove"];
1855 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1856 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1857 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-10-26 22:30:38.459315526 +0200
1860 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1862 +# This program is free software; you can redistribute it and/or modify
1863 +# it under the terms of the GNU General Public License as published by
1864 +# the Free Software Foundation; either version 2 of the License, or
1865 +# (at your option) any later version.
1867 +# This program is distributed in the hope that it will be useful,
1868 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1869 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1870 +# GNU General Public License for more details.
1872 +# You should have received a copy of the GNU General Public License
1873 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1875 +Special handling for renaming a directory (DIRREN)
1876 +----------------------------------------------------------------------
1877 +First, let's assume we have a simple usecase.
1881 +- /ro/dirA and /ro/dirA/file exist too
1882 +- there is no dirB on both branches
1883 +- a user issues rename("dirA", "dirB")
1885 +Now, what should aufs behave against this rename(2)?
1886 +There are a few possible cases.
1889 + since dirA exists on a readonly branch which cannot be renamed.
1891 + it is possible to copy-up dirA (only the dir itself), but the child
1892 + entries ("file" in this case) should not be. it must be a bad
1893 + approach to copy-up recursively.
1894 +C. returns a success.
1895 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1896 + is a violation of aufs' policy.
1897 +D. construct an extra information which indicates that /ro/dirA should
1898 + be handled as the name of dirB.
1899 + overlayfs has a similar feature called REDIRECT.
1901 +Until now, aufs implements the case B only which returns EXDEV, and
1902 +expects the userspace application behaves like mv(1) which tries
1903 +issueing rename(2) recursively.
1905 +A new aufs feature called DIRREN is introduced which implements the case
1906 +D. There are several "extra information" added.
1908 +1. detailed info per renamed directory
1909 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1910 +2. the inode-number list of directories on a branch
1911 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1913 +The filename of "detailed info per directory" represents the lower
1914 +branch, and its format is
1915 +- a type of the branch id
1917 + + uuid (not implemented yet)
1920 +- the inode-number of the branch root dir
1922 +And it contains these info in a single regular file.
1924 +- branch's inode-number of the logically renamed dir
1925 +- the name of the before-renamed dir
1927 +The "detailed info per directory" file is created in aufs rename(2), and
1928 +loaded in any lookup.
1929 +The info is considered in lookup for the matching case only. Here
1930 +"matching" means that the root of branch (in the info filename) is same
1931 +to the current looking-up branch. After looking-up the before-renamed
1932 +name, the inode-number is compared. And the matched dentry is used.
1934 +The "inode-number list of directories" is a regular file which contains
1935 +simply the inode-numbers on the branch. The file is created or updated
1936 +in removing the branch, and loaded in adding the branch. Its lifetime is
1937 +equal to the branch.
1938 +The list is referred in lookup, and when the current target inode is
1939 +found in the list, the aufs tries loading the "detailed info per
1940 +directory" and get the changed and valid name of the dir.
1942 +Theoretically these "extra informaiton" may be able to be put into XATTR
1943 +in the dir inode. But aufs doesn't choose this way because
1944 +1. XATTR may not be supported by the branch (or its configuration)
1945 +2. XATTR may have its size limit.
1946 +3. XATTR may be less easy to convert than a regular file, when the
1947 + format of the info is changed in the future.
1948 +At the same time, I agree that the regular file approach is much slower
1949 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1952 +This DIRREN feature is enabled by aufs configuration, and is activated
1953 +by a new mount option.
1955 +For the more complicated case, there is a work with UDBA option, which
1956 +is to dected the direct access to the branches (by-passing aufs) and to
1957 +maintain the cashes in aufs. Since a single cached aufs dentry may
1958 +contains two names, before- and after-rename, the name comparision in
1959 +UDBA handler may not work correctly. In this case, the behaviour will be
1960 +equivalen to udba=reval case.
1961 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1962 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1963 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-10-26 22:30:38.459315526 +0200
1966 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1968 +# This program is free software; you can redistribute it and/or modify
1969 +# it under the terms of the GNU General Public License as published by
1970 +# the Free Software Foundation; either version 2 of the License, or
1971 +# (at your option) any later version.
1973 +# This program is distributed in the hope that it will be useful,
1974 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1975 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1976 +# GNU General Public License for more details.
1978 +# You should have received a copy of the GNU General Public License
1979 +# along with this program; if not, write to the Free Software
1980 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1983 +File-based Hierarchical Storage Management (FHSM)
1984 +----------------------------------------------------------------------
1985 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1986 +storage world. Aufs provides this feature as file-based with multiple
1987 +writable branches, based upon the principle of "Colder, the Lower".
1988 +Here the word "colder" means that the less used files, and "lower" means
1989 +that the position in the order of the stacked branches vertically.
1990 +These multiple writable branches are prioritized, ie. the topmost one
1991 +should be the fastest drive and be used heavily.
1993 +o Characters in aufs FHSM story
1994 +- aufs itself and a new branch attribute.
1995 +- a new ioctl interface to move-down and to establish a connection with
1996 + the daemon ("move-down" is a converse of "copy-up").
1997 +- userspace tool and daemon.
1999 +The userspace daemon establishes a connection with aufs and waits for
2000 +the notification. The notified information is very similar to struct
2001 +statfs containing the number of consumed blocks and inodes.
2002 +When the consumed blocks/inodes of a branch exceeds the user-specified
2003 +upper watermark, the daemon activates its move-down process until the
2004 +consumed blocks/inodes reaches the user-specified lower watermark.
2006 +The actual move-down is done by aufs based upon the request from
2007 +user-space since we need to maintain the inode number and the internal
2008 +pointer arrays in aufs.
2010 +Currently aufs FHSM handles the regular files only. Additionally they
2011 +must not be hard-linked nor pseudo-linked.
2014 +o Cowork of aufs and the user-space daemon
2015 + During the userspace daemon established the connection, aufs sends a
2016 + small notification to it whenever aufs writes something into the
2017 + writable branch. But it may cost high since aufs issues statfs(2)
2018 + internally. So user can specify a new option to cache the
2019 + info. Actually the notification is controlled by these factors.
2020 + + the specified cache time.
2021 + + classified as "force" by aufs internally.
2022 + Until the specified time expires, aufs doesn't send the info
2023 + except the forced cases. When aufs decide forcing, the info is always
2024 + notified to userspace.
2025 + For example, the number of free inodes is generally large enough and
2026 + the shortage of it happens rarely. So aufs doesn't force the
2027 + notification when creating a new file, directory and others. This is
2028 + the typical case which aufs doesn't force.
2029 + When aufs writes the actual filedata and the files consumes any of new
2030 + blocks, the aufs forces notifying.
2033 +o Interfaces in aufs
2034 +- New branch attribute.
2036 + Specifies that the branch is managed by FHSM feature. In other word,
2037 + participant in the FHSM.
2038 + When nofhsm is set to the branch, it will not be the source/target
2039 + branch of the move-down operation. This attribute is set
2040 + independently from coo and moo attributes, and if you want full
2041 + FHSM, you should specify them as well.
2042 +- New mount option.
2044 + Specifies a second to suppress many less important info to be
2047 + + AUFS_CTL_FHSM_FD
2048 + create a new file descriptor which userspace can read the notification
2049 + (a subset of struct statfs) from aufs.
2050 +- Module parameter 'brs'
2051 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2053 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2054 + When there are two or more branches with fhsm attributes,
2055 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2056 + terminates it. As a result of remounting and branch-manipulation, the
2057 + number of branches with fhsm attribute can be one. In this case,
2058 + /sbin/mount.aufs will terminate the user-space daemon.
2061 +Finally the operation is done as these steps in kernel-space.
2063 + + no one else is using the file.
2064 + + the file is not hard-linked.
2065 + + the file is not pseudo-linked.
2066 + + the file is a regular file.
2067 + + the parent dir is not opaqued.
2068 +- find the target writable branch.
2069 +- make sure the file is not whiteout-ed by the upper (than the target)
2071 +- make the parent dir on the target branch.
2072 +- mutex lock the inode on the branch.
2073 +- unlink the whiteout on the target branch (if exists).
2074 +- lookup and create the whiteout-ed temporary name on the target branch.
2075 +- copy the file as the whiteout-ed temporary name on the target branch.
2076 +- rename the whiteout-ed temporary name to the original name.
2077 +- unlink the file on the source branch.
2078 +- maintain the internal pointer array and the external inode number
2080 +- maintain the timestamps and other attributes of the parent dir and the
2083 +And of course, in every step, an error may happen. So the operation
2084 +should restore the original file state after an error happens.
2085 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2086 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2087 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-10-26 22:30:38.459315526 +0200
2090 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2092 +# This program is free software; you can redistribute it and/or modify
2093 +# it under the terms of the GNU General Public License as published by
2094 +# the Free Software Foundation; either version 2 of the License, or
2095 +# (at your option) any later version.
2097 +# This program is distributed in the hope that it will be useful,
2098 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2099 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2100 +# GNU General Public License for more details.
2102 +# You should have received a copy of the GNU General Public License
2103 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2105 +mmap(2) -- File Memory Mapping
2106 +----------------------------------------------------------------------
2107 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2108 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2110 +This approach is simple and good, but there is one problem.
2111 +Under /proc, several entries show the mmapped files by its path (with
2112 +device and inode number), and the printed path will be the path on the
2113 +branch fs's instead of virtual aufs's.
2114 +This is not a problem in most cases, but some utilities lsof(1) (and its
2115 +user) may expect the path on aufs.
2117 +To address this issue, aufs adds a new member called vm_prfile in struct
2118 +vm_area_struct (and struct vm_region). The original vm_file points to
2119 +the file on the branch fs in order to handle everything correctly as
2120 +usual. The new vm_prfile points to a virtual file in aufs, and the
2121 +show-functions in procfs refers to vm_prfile if it is set.
2122 +Also we need to maintain several other places where touching vm_file
2124 +- fork()/clone() copies vma and the reference count of vm_file is
2126 +- merging vma maintains the ref count too.
2128 +This is not a good approach. It just fakes the printed path. But it
2129 +leaves all behaviour around f_mapping unchanged. This is surely an
2131 +Actually aufs had adopted another complicated approach which calls
2132 +generic_file_mmap() and handles struct vm_operations_struct. In this
2133 +approach, aufs met a hard problem and I could not solve it without
2134 +switching the approach.
2136 +There may be one more another approach which is
2137 +- bind-mount the branch-root onto the aufs-root internally
2138 +- grab the new vfsmount (ie. struct mount)
2139 +- lazy-umount the branch-root internally
2140 +- in open(2) the aufs-file, open the branch-file with the hidden
2141 + vfsmount (instead of the original branch's vfsmount)
2142 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2143 + but it may be possible from userspace by the mount helper.
2145 +Adding the internal hidden vfsmount and using it in opening a file, the
2146 +file path under /proc will be printed correctly. This approach looks
2147 +smarter, but is not possible I am afraid.
2148 +- aufs-root may be bind-mount later. when it happens, another hidden
2149 + vfsmount will be required.
2150 +- it is hard to get the chance to bind-mount and lazy-umount
2151 + + in kernel-space, FS can have vfsmount in open(2) via
2152 + file->f_path, and aufs can know its vfsmount. But several locks are
2153 + already acquired, and if aufs tries to bind-mount and lazy-umount
2154 + here, then it may cause a deadlock.
2155 + + in user-space, bind-mount doesn't invoke the mount helper.
2156 +- since /proc shows dev and ino, aufs has to give vma these info. it
2157 + means a new member vm_prinode will be necessary. this is essentially
2158 + equivalent to vm_prfile described above.
2160 +I have to give up this "looks-smater" approach.
2161 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2162 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2163 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-10-26 22:30:38.459315526 +0200
2166 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2168 +# This program is free software; you can redistribute it and/or modify
2169 +# it under the terms of the GNU General Public License as published by
2170 +# the Free Software Foundation; either version 2 of the License, or
2171 +# (at your option) any later version.
2173 +# This program is distributed in the hope that it will be useful,
2174 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2175 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2176 +# GNU General Public License for more details.
2178 +# You should have received a copy of the GNU General Public License
2179 +# along with this program; if not, write to the Free Software
2180 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2183 +Listing XATTR/EA and getting the value
2184 +----------------------------------------------------------------------
2185 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2186 +shows the values from the topmost existing file. This behaviour is good
2187 +for the non-dir entries since the bahaviour exactly matches the shown
2188 +information. But for the directories, aufs considers all the same named
2189 +entries on the lower branches. Which means, if one of the lower entry
2190 +rejects readdir call, then aufs returns an error even if the topmost
2191 +entry allows it. This behaviour is necessary to respect the branch fs's
2192 +security, but can make users confused since the user-visible standard
2193 +attributes don't match the behaviour.
2194 +To address this issue, aufs has a mount option called dirperm1 which
2195 +checks the permission for the topmost entry only, and ignores the lower
2196 +entry's permission.
2198 +A similar issue can happen around XATTR.
2199 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2200 +always set. Otherwise these very unpleasant situation would happen.
2201 +- listxattr(2) may return the duplicated entries.
2202 +- users may not be able to remove or reset the XATTR forever,
2205 +XATTR/EA support in the internal (copy,move)-(up,down)
2206 +----------------------------------------------------------------------
2207 +Generally the extended attributes of inode are categorized as these.
2208 +- "security" for LSM and capability.
2209 +- "system" for posix ACL, 'acl' mount option is required for the branch
2211 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2212 +- "user" for userspace, 'user_xattr' mount option is required for the
2213 + branch fs generally.
2215 +Moreover there are some other categories. Aufs handles these rather
2216 +unpopular categories as the ordinary ones, ie. there is no special
2217 +condition nor exception.
2219 +In copy-up, the support for XATTR on the dst branch may differ from the
2220 +src branch. In this case, the copy-up operation will get an error and
2221 +the original user operation which triggered the copy-up will fail. It
2222 +can happen that even all copy-up will fail.
2223 +When both of src and dst branches support XATTR and if an error occurs
2224 +during copying XATTR, then the copy-up should fail obviously. That is a
2225 +good reason and aufs should return an error to userspace. But when only
2226 +the src branch support that XATTR, aufs should not return an error.
2227 +For example, the src branch supports ACL but the dst branch doesn't
2228 +because the dst branch may natively un-support it or temporary
2229 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2230 +may NOT return an error even if the XATTR is not supported. It is
2231 +totally up to the branch fs.
2233 +Anyway when the aufs internal copy-up gets an error from the dst branch
2234 +fs, then aufs tries removing the just copied entry and returns the error
2235 +to the userspace. The worst case of this situation will be all copy-up
2238 +For the copy-up operation, there two basic approaches.
2239 +- copy the specified XATTR only (by category above), and return the
2240 + error unconditionally if it happens.
2241 +- copy all XATTR, and ignore the error on the specified category only.
2243 +In order to support XATTR and to implement the correct behaviour, aufs
2244 +chooses the latter approach and introduces some new branch attributes,
2245 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2246 +They correspond to the XATTR namespaces (see above). Additionally, to be
2247 +convenient, "icex" is also provided which means all "icex*" attributes
2248 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2250 +The meaning of these attributes is to ignore the error from setting
2251 +XATTR on that branch.
2252 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2253 +error from the dst branch according to the specified attributes.
2255 +Some XATTR may have its default value. The default value may come from
2256 +the parent dir or the environment. If the default value is set at the
2257 +file creating-time, it will be overwritten by copy-up.
2258 +Some contradiction may happen I am afraid.
2259 +Do we need another attribute to stop copying XATTR? I am unsure. For
2260 +now, aufs implements the branch attributes to ignore the error.
2261 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2262 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2263 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-10-26 22:30:38.459315526 +0200
2266 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2268 +# This program is free software; you can redistribute it and/or modify
2269 +# it under the terms of the GNU General Public License as published by
2270 +# the Free Software Foundation; either version 2 of the License, or
2271 +# (at your option) any later version.
2273 +# This program is distributed in the hope that it will be useful,
2274 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2275 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2276 +# GNU General Public License for more details.
2278 +# You should have received a copy of the GNU General Public License
2279 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2281 +Export Aufs via NFS
2282 +----------------------------------------------------------------------
2283 +Here is an approach.
2284 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2286 +- iget_locked(): initialize aufs inode generation for a new inode, and
2287 + store it in xigen file.
2288 +- destroy_inode(): increment aufs inode generation and store it in xigen
2289 + file. it is necessary even if it is not unlinked, because any data of
2290 + inode may be changed by UDBA.
2291 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2292 + build file handle by
2293 + + branch id (4 bytes)
2294 + + superblock generation (4 bytes)
2295 + + inode number (4 or 8 bytes)
2296 + + parent dir inode number (4 or 8 bytes)
2297 + + inode generation (4 bytes))
2298 + + return value of exportfs_encode_fh() for the parent on a branch (4
2300 + + file handle for a branch (by exportfs_encode_fh())
2302 + + find the index of a branch from its id in handle, and check it is
2303 + still exist in aufs.
2304 + + 1st level: get the inode number from handle and search it in cache.
2305 + + 2nd level: if not found in cache, get the parent inode number from
2306 + the handle and search it in cache. and then open the found parent
2307 + dir, find the matching inode number by vfs_readdir() and get its
2308 + name, and call lookup_one_len() for the target dentry.
2309 + + 3rd level: if the parent dir is not cached, call
2310 + exportfs_decode_fh() for a branch and get the parent on a branch,
2311 + build a pathname of it, convert it a pathname in aufs, call
2312 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2314 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2315 + for every branch, but not itself. to get this, (currently) aufs
2316 + searches in current->nsproxy->mnt_ns list. it may not be a good
2317 + idea, but I didn't get other approach.
2318 + + test the generation of the gotten inode.
2319 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2320 + convert it into ESTALE for NFSD.
2321 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2322 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2323 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2324 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2325 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-10-26 22:30:38.459315526 +0200
2328 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2330 +# This program is free software; you can redistribute it and/or modify
2331 +# it under the terms of the GNU General Public License as published by
2332 +# the Free Software Foundation; either version 2 of the License, or
2333 +# (at your option) any later version.
2335 +# This program is distributed in the hope that it will be useful,
2336 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2337 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2338 +# GNU General Public License for more details.
2340 +# You should have received a copy of the GNU General Public License
2341 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2343 +Show Whiteout Mode (shwh)
2344 +----------------------------------------------------------------------
2345 +Generally aufs hides the name of whiteouts. But in some cases, to show
2346 +them is very useful for users. For instance, creating a new middle layer
2347 +(branch) by merging existing layers.
2349 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2350 +When you have three branches,
2351 +- Bottom: 'system', squashfs (underlying base system), read-only
2352 +- Middle: 'mods', squashfs, read-only
2353 +- Top: 'overlay', ram (tmpfs), read-write
2355 +The top layer is loaded at boot time and saved at shutdown, to preserve
2356 +the changes made to the system during the session.
2357 +When larger changes have been made, or smaller changes have accumulated,
2358 +the size of the saved top layer data grows. At this point, it would be
2359 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2360 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2361 +restoring save and load speed.
2363 +This merging is simplified by the use of another aufs mount, of just the
2364 +two overlay branches using the 'shwh' option.
2365 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2366 + aufs /livesys/merge_union
2368 +A merged view of these two branches is then available at
2369 +/livesys/merge_union, and the new feature is that the whiteouts are
2371 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2372 +writing to all branches. Also the default mode for all branches is 'ro'.
2373 +It is now possible to save the combined contents of the two overlay
2374 +branches to a new squashfs, e.g.:
2375 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2377 +This new squashfs archive can be stored on the boot device and the
2378 +initramfs will use it to replace the old one at the next boot.
2379 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2380 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2381 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-10-26 22:30:38.459315526 +0200
2384 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2386 +# This program is free software; you can redistribute it and/or modify
2387 +# it under the terms of the GNU General Public License as published by
2388 +# the Free Software Foundation; either version 2 of the License, or
2389 +# (at your option) any later version.
2391 +# This program is distributed in the hope that it will be useful,
2392 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2393 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2394 +# GNU General Public License for more details.
2396 +# You should have received a copy of the GNU General Public License
2397 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2399 +Dynamically customizable FS operations
2400 +----------------------------------------------------------------------
2401 +Generally FS operations (struct inode_operations, struct
2402 +address_space_operations, struct file_operations, etc.) are defined as
2403 +"static const", but it never means that FS have only one set of
2404 +operation. Some FS have multiple sets of them. For instance, ext2 has
2405 +three sets, one for XIP, for NOBH, and for normal.
2406 +Since aufs overrides and redirects these operations, sometimes aufs has
2407 +to change its behaviour according to the branch FS type. More importantly
2408 +VFS acts differently if a function (member in the struct) is set or
2409 +not. It means aufs should have several sets of operations and select one
2410 +among them according to the branch FS definition.
2412 +In order to solve this problem and not to affect the behaviour of VFS,
2413 +aufs defines these operations dynamically. For instance, aufs defines
2414 +dummy direct_IO function for struct address_space_operations, but it may
2415 +not be set to the address_space_operations actually. When the branch FS
2416 +doesn't have it, aufs doesn't set it to its address_space_operations
2417 +while the function definition itself is still alive. So the behaviour
2418 +itself will not change, and it will return an error when direct_IO is
2421 +The lifetime of these dynamically generated operation object is
2422 +maintained by aufs branch object. When the branch is removed from aufs,
2423 +the reference counter of the object is decremented. When it reaches
2424 +zero, the dynamically generated operation object will be freed.
2426 +This approach is designed to support AIO (io_submit), Direct I/O and
2428 +Currently this approach is applied to address_space_operations for
2429 +regular files only.
2430 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2431 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2432 +++ linux/Documentation/filesystems/aufs/README 2022-10-26 22:30:38.455982192 +0200
2435 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2441 +----------------------------------------
2442 +In the early days, aufs was entirely re-designed and re-implemented
2443 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2444 +improvements and implementations, it became totally different from
2445 +Unionfs while keeping the basic features.
2446 +Later, Unionfs Version 2.x series began taking some of the same
2447 +approaches to aufs1's.
2448 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2449 +University and his team.
2451 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2453 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2454 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2455 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2456 + or aufs1 from CVS on SourceForge.
2458 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2459 + According to Christoph Hellwig, linux rejects all union-type
2460 + filesystems but UnionMount.
2461 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2463 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2464 + UnionMount, and he pointed out an issue around a directory mutex
2465 + lock and aufs addressed it. But it is still unsure whether aufs will
2466 + be merged (or any other union solution).
2467 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2471 +----------------------------------------
2472 +- unite several directories into a single virtual filesystem. The member
2473 + directory is called as a branch.
2474 +- you can specify the permission flags to the branch, which are 'readonly',
2475 + 'readwrite' and 'whiteout-able.'
2476 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2477 + readonly branch are modifiable logically.
2478 +- dynamic branch manipulation, add, del.
2481 +Also there are many enhancements in aufs, such as:
2482 +- test only the highest one for the directory permission (dirperm1)
2483 +- copyup on open (coo=)
2484 +- 'move' policy for copy-up between two writable branches, after
2485 + checking free space.
2487 +- readdir(3) in userspace.
2488 +- keep inode number by external inode number table
2489 +- keep the timestamps of file/dir in internal copyup operation
2490 +- seekable directory, supporting NFS readdir.
2491 +- whiteout is hardlinked in order to reduce the consumption of inodes
2493 +- do not copyup, nor create a whiteout when it is unnecessary
2494 +- revert a single systemcall when an error occurs in aufs
2495 +- remount interface instead of ioctl
2496 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2497 +- loopback mounted filesystem as a branch
2498 +- kernel thread for removing the dir who has a plenty of whiteouts
2499 +- support copyup sparse file (a file which has a 'hole' in it)
2500 +- default permission flags for branches
2501 +- selectable permission flags for ro branch, whether whiteout can
2504 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2505 +- support multiple writable branches, some policies to select one
2506 + among multiple writable branches.
2507 +- a new semantics for link(2) and rename(2) to support multiple
2508 + writable branches.
2509 +- no glibc changes are required.
2510 +- pseudo hardlink (hardlink over branches)
2511 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2512 + including NFS or remote filesystem branch.
2513 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2516 +Currently these features are dropped temporary from aufs5.
2517 +See design/08plan.txt in detail.
2518 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2520 +- statistics of aufs thread (/sys/fs/aufs/stat)
2522 +Features or just an idea in the future (see also design/*.txt),
2523 +- reorder the branch index without del/re-add.
2524 +- permanent xino files for NFSD
2525 +- an option for refreshing the opened files after add/del branches
2526 +- light version, without branch manipulation. (unnecessary?)
2527 +- copyup in userspace
2528 +- inotify in userspace
2533 +----------------------------------------
2534 +There are three GIT trees for aufs5, aufs5-linux.git,
2535 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2537 +While the aufs-util is always necessary, you need either of aufs5-linux
2538 +or aufs5-standalone.
2540 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2541 +git://git.kernel.org/.../torvalds/linux.git.
2542 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2543 +build aufs5 as an external kernel module.
2544 +Several extra patches are not included in this tree. Only
2545 +aufs5-standalone tree contains them. They are described in the later
2546 +section "Configuration and Compilation."
2548 +On the other hand, the aufs5-standalone tree has only aufs source files
2549 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2550 +But you need to apply all aufs patches manually.
2552 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2553 +represents the linux kernel version, "linux-5.x". For instance,
2554 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2555 +"aufs5.x-rcN" branch.
2558 +$ git clone --reference /your/linux/git/tree \
2559 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2560 +- if you don't have linux GIT tree, then remove "--reference ..."
2561 +$ cd aufs5-linux.git
2562 +$ git checkout origin/aufs5.0
2564 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2565 +leave the patch-work to GIT.
2566 +$ cd /your/linux/git/tree
2567 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2569 +$ git checkout -b my5.0 v5.0
2570 +$ (add your local change...)
2571 +$ git pull aufs5 aufs5.0
2572 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2573 +- you may need to solve some conflicts between your_changes and
2574 + aufs5.0. in this case, git-rerere is recommended so that you can
2575 + solve the similar conflicts automatically when you upgrade to 5.1 or
2576 + later in the future.
2578 +o aufs5-standalone tree
2579 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2580 +$ cd aufs5-standalone.git
2581 +$ git checkout origin/aufs5.0
2584 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2585 +- note that the public aufs-util.git is on SourceForge instead of
2588 +$ git checkout origin/aufs5.0
2590 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2591 +The minor version number, 'x' in '5.x', of aufs may not always
2592 +follow the minor version number of the kernel.
2593 +Because changes in the kernel that cause the use of a new
2594 +minor version number do not always require changes to aufs-util.
2596 +Since aufs-util has its own minor version number, you may not be
2597 +able to find a GIT branch in aufs-util for your kernel's
2598 +exact minor version number.
2599 +In this case, you should git-checkout the branch for the
2600 +nearest lower number.
2602 +For (an unreleased) example:
2603 +If you are using "linux-5.10" and the "aufs5.10" branch
2604 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2605 +or something numerically smaller is the branch for your kernel.
2607 +Also you can view all branches by
2611 +3. Configuration and Compilation
2612 +----------------------------------------
2613 +Make sure you have git-checkout'ed the correct branch.
2615 +For aufs5-linux tree,
2616 +- enable CONFIG_AUFS_FS.
2617 +- set other aufs configurations if necessary.
2618 +- for aufs5.13 and later
2619 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2620 + also a caller of VFS functions for branch filesystems, subclassing of
2621 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2622 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2623 + need to customize some LOCKDEP numbers. Here are what I use on my
2625 + CONFIG_LOCKDEP_BITS=21
2626 + CONFIG_LOCKDEP_CHAINS_BITS=21
2627 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2629 +For aufs5-standalone tree,
2630 +There are several ways to build.
2633 +- apply ./aufs5-kbuild.patch to your kernel source files.
2634 +- apply ./aufs5-base.patch too.
2635 +- apply ./aufs5-mmap.patch too.
2636 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2637 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2638 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2639 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2640 +- enable CONFIG_AUFS_FS, you can select either
2642 +- and build your kernel as usual.
2643 +- install the built kernel.
2644 +- install the header files too by "make headers_install" to the
2645 + directory where you specify. By default, it is $PWD/usr.
2646 + "make help" shows a brief note for headers_install.
2647 +- and reboot your system.
2650 +- module only (CONFIG_AUFS_FS=m).
2651 +- apply ./aufs5-base.patch to your kernel source files.
2652 +- apply ./aufs5-mmap.patch too.
2653 +- apply ./aufs5-standalone.patch too.
2654 +- build your kernel, don't forget "make headers_install", and reboot.
2655 +- edit ./config.mk and set other aufs configurations if necessary.
2656 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2657 + every aufs configurations.
2658 +- build the module by simple "make".
2659 +- you can specify ${KDIR} make variable which points to your kernel
2661 +- install the files
2662 + + run "make install" to install the aufs module, or copy the built
2663 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2664 + + run "make install_headers" (instead of headers_install) to install
2665 + the modified aufs header file (you can specify DESTDIR which is
2666 + available in aufs standalone version's Makefile only), or copy
2667 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2668 + you like manually. By default, the target directory is $PWD/usr.
2669 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2670 + kernel source tree.
2672 +Note: The header file aufs_type.h is necessary to build aufs-util
2673 + as well as "make headers_install" in the kernel source tree.
2674 + headers_install is subject to be forgotten, but it is essentially
2675 + necessary, not only for building aufs-util.
2676 + You may not meet problems without headers_install in some older
2680 +- read README in aufs-util, build and install it
2681 +- note that your distribution may contain an obsoleted version of
2682 + aufs_type.h in /usr/include/linux or something. When you build aufs
2683 + utilities, make sure that your compiler refers the correct aufs header
2684 + file which is built by "make headers_install."
2685 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2686 + then run "make install_ulib" too. And refer to the aufs manual in
2689 +There several other patches in aufs5-standalone.git. They are all
2690 +optional. When you meet some problems, they will help you.
2691 +- aufs5-loopback.patch
2692 + Supports a nested loopback mount in a branch-fs. This patch is
2693 + unnecessary until aufs produces a message like "you may want to try
2694 + another patch for loopback file".
2696 + Modifies a system global kernel internal function get_next_ino() in
2697 + order to stop assigning 0 for an inode-number. Not directly related to
2698 + aufs, but recommended generally.
2700 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2701 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2702 + duplication of inode number, which is important for backup tools and
2703 + other utilities. When you find aufs XINO files for tmpfs branch
2704 + growing too much, try this patch.
2708 +----------------------------------------
2709 +At first, make sure aufs-util are installed, and please read the aufs
2710 +manual, aufs.5 in aufs-util.git tree.
2714 +$ mkdir /tmp/rw /tmp/aufs
2715 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2717 +Here is another example. The result is equivalent.
2718 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2720 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2721 +# mount -o remount,append:${HOME} /tmp/aufs
2723 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2724 +you modify a file under /tmp/aufs, the one on your home directory is
2725 +not affected, instead the same named file will be newly created under
2726 +/tmp/rw. And all of your modification to a file will be applied to
2727 +the one under /tmp/rw. This is called the file based Copy on Write
2729 +Aufs mount options are described in aufs.5.
2730 +If you run chroot or something and make your aufs as a root directory,
2731 +then you need to customize the shutdown script. See the aufs manual in
2734 +Additionally, there are some sample usages of aufs which are a
2735 +diskless system with network booting, and LiveCD over NFS.
2736 +See sample dir in CVS tree on SourceForge.
2740 +----------------------------------------
2741 +When you have any problems or strange behaviour in aufs, please let me
2743 +- /proc/mounts (instead of the output of mount(8))
2744 +- /sys/module/aufs/*
2745 +- /sys/fs/aufs/* (if you have them)
2746 +- /debug/aufs/* (if you have them)
2747 +- linux kernel version
2748 + if your kernel is not plain, for example modified by distributor,
2749 + the url where i can download its source is necessary too.
2750 +- aufs version which was printed at loading the module or booting the
2751 + system, instead of the date you downloaded.
2752 +- configuration (define/undefine CONFIG_AUFS_xxx)
2753 +- kernel configuration or /proc/config.gz (if you have it)
2754 +- LSM (linux security module, if you are using)
2755 +- behaviour which you think to be incorrect
2756 +- actual operation, reproducible one is better
2757 +- mailto: aufs-users at lists.sourceforge.net
2759 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2760 +and Feature Requests) on SourceForge. Please join and write to
2764 +6. Acknowledgements
2765 +----------------------------------------
2766 +Thanks to everyone who have tried and are using aufs, whoever
2767 +have reported a bug or any feedback.
2769 +Especially donators:
2770 +Tomas Matejicek(slax.org) made a donation (much more than once).
2771 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2772 + scripts) is making "doubling" donations.
2773 + Unfortunately I cannot list all of the donators, but I really
2775 + It ends Aug 2010, but the ordinary donation URL is still available.
2776 + <http://sourceforge.net/donate/index.php?group_id=167503>
2777 +Dai Itasaka made a donation (2007/8).
2778 +Chuck Smith made a donation (2008/4, 10 and 12).
2779 +Henk Schoneveld made a donation (2008/9).
2780 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2781 +Francois Dupoux made a donation (2008/11).
2782 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2783 + aufs2 GIT tree (2009/2).
2784 +William Grant made a donation (2009/3).
2785 +Patrick Lane made a donation (2009/4).
2786 +The Mail Archive (mail-archive.com) made donations (2009/5).
2787 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2788 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2789 +Pavel Pronskiy made a donation (2011/2).
2790 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2791 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2792 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2794 +Sam Liddicott made a donation (2011/9).
2795 +Era Scarecrow made a donation (2013/4).
2796 +Bor Ratajc made a donation (2013/4).
2797 +Alessandro Gorreta made a donation (2013/4).
2798 +POIRETTE Marc made a donation (2013/4).
2799 +Alessandro Gorreta made a donation (2013/4).
2800 +lauri kasvandik made a donation (2013/5).
2801 +"pemasu from Finland" made a donation (2013/7).
2802 +The Parted Magic Project made a donation (2013/9 and 11).
2803 +Pavel Barta made a donation (2013/10).
2804 +Nikolay Pertsev made a donation (2014/5).
2805 +James B made a donation (2014/7, 2015/7, and 2021/12).
2806 +Stefano Di Biase made a donation (2014/8).
2807 +Daniel Epellei made a donation (2015/1).
2808 +OmegaPhil made a donation (2016/1, 2018/4).
2809 +Tomasz Szewczyk made a donation (2016/4).
2810 +James Burry made a donation (2016/12).
2811 +Carsten Rose made a donation (2018/9).
2812 +Porteus Kiosk made a donation (2018/10).
2813 +Enya Quetzalli Gomez Rodriguez made a donation (2022/5).
2815 +Thank you very much.
2816 +Donations are always, including future donations, very important and
2817 +helpful for me to keep on developing aufs.
2821 +----------------------------------------
2822 +If you are an experienced user, no explanation is needed. Aufs is
2823 +just a linux filesystem.
2828 +# Local variables: ;
2831 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2832 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2833 +++ linux/fs/aufs/aufs.h 2022-10-26 22:30:38.459315526 +0200
2835 +/* SPDX-License-Identifier: GPL-2.0 */
2837 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2839 + * This program, aufs is free software; you can redistribute it and/or modify
2840 + * it under the terms of the GNU General Public License as published by
2841 + * the Free Software Foundation; either version 2 of the License, or
2842 + * (at your option) any later version.
2844 + * This program is distributed in the hope that it will be useful,
2845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2847 + * GNU General Public License for more details.
2849 + * You should have received a copy of the GNU General Public License
2850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2854 + * all header files
2862 +#define AuStub(type, name, body, ...) \
2863 + static inline type name(__VA_ARGS__) { body; }
2865 +#define AuStubVoid(name, ...) \
2866 + AuStub(void, name, , __VA_ARGS__)
2867 +#define AuStubInt0(name, ...) \
2868 + AuStub(int, name, return 0, __VA_ARGS__)
2872 +#include "branch.h"
2875 +#include "dbgaufs.h"
2876 +#include "dentry.h"
2878 +#include "dirren.h"
2881 +#include "fstype.h"
2886 +#include "module.h"
2890 +#include "sysaufs.h"
2895 +#endif /* __KERNEL__ */
2896 +#endif /* __AUFS_H__ */
2897 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2898 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2899 +++ linux/fs/aufs/branch.c 2022-10-26 22:30:38.462648858 +0200
2901 +// SPDX-License-Identifier: GPL-2.0
2903 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2905 + * This program, aufs is free software; you can redistribute it and/or modify
2906 + * it under the terms of the GNU General Public License as published by
2907 + * the Free Software Foundation; either version 2 of the License, or
2908 + * (at your option) any later version.
2910 + * This program is distributed in the hope that it will be useful,
2911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2913 + * GNU General Public License for more details.
2915 + * You should have received a copy of the GNU General Public License
2916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2920 + * branch management
2923 +#include <linux/compat.h>
2924 +#include <linux/statfs.h>
2928 + * free a single branch
2930 +static void au_br_do_free(struct au_branch *br)
2933 + struct au_wbr *wbr;
2934 + struct au_dykey **key;
2936 + au_hnotify_fin_br(br);
2937 + /* always, regardless the mount option */
2938 + au_dr_hino_free(&br->br_dirren);
2941 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2942 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2943 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2944 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2948 + for (i = 0; i < AuBrWh_Last; i++)
2949 + dput(wbr->wbr_wh[i]);
2950 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2951 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2954 + if (br->br_fhsm) {
2955 + au_br_fhsm_fin(br->br_fhsm);
2956 + au_kfree_try_rcu(br->br_fhsm);
2959 + key = br->br_dykey;
2960 + for (i = 0; i < AuBrDynOp; i++, key++)
2966 + /* recursive lock, s_umount of branch's */
2967 + /* synchronize_rcu(); */ /* why? */
2969 + path_put(&br->br_path);
2971 + au_kfree_rcu(wbr);
2972 + au_lcnt_wait_for_fin(&br->br_nfiles);
2973 + au_lcnt_wait_for_fin(&br->br_count);
2974 + /* I don't know why, but percpu_refcount requires this */
2975 + /* synchronize_rcu(); */
2980 + * frees all branches
2982 +void au_br_free(struct au_sbinfo *sbinfo)
2984 + aufs_bindex_t bmax;
2985 + struct au_branch **br;
2987 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2989 + bmax = sbinfo->si_bbot + 1;
2990 + br = sbinfo->si_branch;
2992 + au_br_do_free(*br++);
2996 + * find the index of a branch which is specified by @br_id.
2998 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3000 + aufs_bindex_t bindex, bbot;
3002 + bbot = au_sbbot(sb);
3003 + for (bindex = 0; bindex <= bbot; bindex++)
3004 + if (au_sbr_id(sb, bindex) == br_id)
3009 +/* ---------------------------------------------------------------------- */
3015 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3016 + struct dentry *h_root)
3018 + if (unlikely(h_adding == h_root
3019 + || au_test_loopback_overlap(sb, h_adding)))
3021 + if (h_adding->d_sb != h_root->d_sb)
3023 + return au_test_subdir(h_adding, h_root)
3024 + || au_test_subdir(h_root, h_adding);
3028 + * returns a newly allocated branch. @new_nbranch is a number of branches
3029 + * after adding a branch.
3031 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3034 + struct au_branch *add_branch;
3035 + struct dentry *root;
3036 + struct inode *inode;
3040 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3041 + if (unlikely(!add_branch))
3043 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3044 + if (unlikely(!add_branch->br_xino))
3046 + err = au_hnotify_init_br(add_branch, perm);
3047 + if (unlikely(err))
3050 + if (au_br_writable(perm)) {
3051 + /* may be freed separately at changing the branch permission */
3052 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3054 + if (unlikely(!add_branch->br_wbr))
3058 + if (au_br_fhsm(perm)) {
3059 + err = au_fhsm_br_alloc(add_branch);
3060 + if (unlikely(err))
3064 + root = sb->s_root;
3065 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3067 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3069 + inode = d_inode(root);
3070 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3074 + return add_branch; /* success */
3077 + au_kfree_rcu(add_branch->br_wbr);
3079 + au_hnotify_fin_br(add_branch);
3081 + au_xino_put(add_branch);
3083 + au_kfree_rcu(add_branch);
3085 + return ERR_PTR(err);
3089 + * test if the branch permission is legal or not.
3091 +static int test_br(struct inode *inode, int brperm, char *path)
3095 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3100 + pr_err("write permission for readonly mount or inode, %s\n", path);
3108 + * 0: success, the caller will add it
3109 + * plus: success, it is already unified, the caller should ignore it
3112 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3115 + aufs_bindex_t bbot, bindex;
3116 + struct dentry *root, *h_dentry;
3117 + struct inode *inode, *h_inode;
3119 + root = sb->s_root;
3120 + bbot = au_sbbot(sb);
3121 + if (unlikely(bbot >= 0
3122 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3126 + pr_err("%s duplicated\n", add->pathname);
3131 + err = -ENOSPC; /* -E2BIG; */
3132 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3133 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3134 + pr_err("number of branches exceeded %s\n", add->pathname);
3139 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3140 + pr_err("bad index %d\n", add->bindex);
3144 + inode = d_inode(add->path.dentry);
3146 + if (unlikely(!inode->i_nlink)) {
3147 + pr_err("no existence %s\n", add->pathname);
3152 + if (unlikely(inode->i_sb == sb)) {
3153 + pr_err("%s must be outside\n", add->pathname);
3157 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3158 + pr_err("unsupported filesystem, %s (%s)\n",
3159 + add->pathname, au_sbtype(inode->i_sb));
3163 + if (unlikely(inode->i_sb->s_stack_depth)) {
3164 + pr_err("already stacked, %s (%s)\n",
3165 + add->pathname, au_sbtype(inode->i_sb));
3169 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3170 + if (unlikely(err))
3174 + return 0; /* success */
3177 + for (bindex = 0; bindex <= bbot; bindex++)
3178 + if (unlikely(test_overlap(sb, add->path.dentry,
3179 + au_h_dptr(root, bindex)))) {
3180 + pr_err("%s is overlapped\n", add->pathname);
3185 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3186 + h_dentry = au_h_dptr(root, 0);
3187 + h_inode = d_inode(h_dentry);
3188 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3189 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3190 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3191 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3193 + i_uid_read(inode), i_gid_read(inode),
3194 + (inode->i_mode & S_IALLUGO),
3195 + i_uid_read(h_inode), i_gid_read(h_inode),
3196 + (h_inode->i_mode & S_IALLUGO));
3204 + * initialize or clean the whiteouts for an adding branch
3206 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3209 + int err, old_perm;
3210 + aufs_bindex_t bindex;
3211 + struct inode *h_inode;
3212 + struct au_wbr *wbr;
3213 + struct au_hinode *hdir;
3214 + struct dentry *h_dentry;
3216 + err = vfsub_mnt_want_write(au_br_mnt(br));
3217 + if (unlikely(err))
3221 + old_perm = br->br_perm;
3222 + br->br_perm = new_perm;
3225 + bindex = au_br_index(sb, br->br_id);
3226 + if (0 <= bindex) {
3227 + hdir = au_hi(d_inode(sb->s_root), bindex);
3228 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3230 + h_dentry = au_br_dentry(br);
3231 + h_inode = d_inode(h_dentry);
3232 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3235 + err = au_wh_init(br, sb);
3237 + wbr_wh_write_lock(wbr);
3238 + err = au_wh_init(br, sb);
3239 + wbr_wh_write_unlock(wbr);
3242 + au_hn_inode_unlock(hdir);
3244 + inode_unlock(h_inode);
3245 + vfsub_mnt_drop_write(au_br_mnt(br));
3246 + br->br_perm = old_perm;
3248 + if (!err && wbr && !au_br_writable(new_perm)) {
3249 + au_kfree_rcu(wbr);
3250 + br->br_wbr = NULL;
3257 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3261 + struct kstatfs kst;
3262 + struct au_wbr *wbr;
3265 + au_rw_init(&wbr->wbr_wh_rwsem);
3266 + atomic_set(&wbr->wbr_wh_running, 0);
3269 + * a limit for rmdir/rename a dir
3270 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3272 + err = vfs_statfs(&br->br_path, &kst);
3273 + if (unlikely(err))
3276 + if (kst.f_namelen >= NAME_MAX)
3277 + err = au_br_init_wh(sb, br, perm);
3279 + pr_err("%pd(%s), unsupported namelen %ld\n",
3281 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3287 +/* initialize a new branch */
3288 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3289 + struct au_opt_add *add)
3292 + struct au_branch *brbase;
3294 + struct inode *h_inode;
3297 + br->br_perm = add->perm;
3298 + br->br_path = add->path; /* set first, path_get() later */
3299 + spin_lock_init(&br->br_dykey_lock);
3300 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3301 + au_lcnt_init(&br->br_count, /*release*/NULL);
3302 + br->br_id = au_new_br_id(sb);
3303 + AuDebugOn(br->br_id < 0);
3305 + /* always, regardless the given option */
3306 + err = au_dr_br_init(sb, br, &add->path);
3307 + if (unlikely(err))
3310 + if (au_br_writable(add->perm)) {
3311 + err = au_wbr_init(br, sb, add->perm);
3312 + if (unlikely(err))
3316 + if (au_opt_test(au_mntflags(sb), XINO)) {
3317 + brbase = au_sbr(sb, 0);
3318 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3320 + h_inode = d_inode(add->path.dentry);
3321 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3322 + if (unlikely(err)) {
3323 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3328 + sysaufs_br_init(br);
3329 + path_get(&br->br_path);
3330 + goto out; /* success */
3333 + memset(&br->br_path, 0, sizeof(br->br_path));
3338 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3339 + struct au_branch *br, aufs_bindex_t bbot,
3340 + aufs_bindex_t amount)
3342 + struct au_branch **brp;
3344 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3346 + brp = sbinfo->si_branch + bindex;
3347 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3349 + sbinfo->si_bbot++;
3350 + if (unlikely(bbot < 0))
3351 + sbinfo->si_bbot = 0;
3354 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3355 + aufs_bindex_t bbot, aufs_bindex_t amount)
3357 + struct au_hdentry *hdp;
3359 + AuRwMustWriteLock(&dinfo->di_rwsem);
3361 + hdp = au_hdentry(dinfo, bindex);
3362 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3363 + au_h_dentry_init(hdp);
3365 + if (unlikely(bbot < 0))
3366 + dinfo->di_btop = 0;
3369 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3370 + aufs_bindex_t bbot, aufs_bindex_t amount)
3372 + struct au_hinode *hip;
3374 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3376 + hip = au_hinode(iinfo, bindex);
3377 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3378 + au_hinode_init(hip);
3380 + if (unlikely(bbot < 0))
3381 + iinfo->ii_btop = 0;
3384 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3385 + aufs_bindex_t bindex)
3387 + struct dentry *root, *h_dentry;
3388 + struct inode *root_inode, *h_inode;
3389 + aufs_bindex_t bbot, amount;
3391 + root = sb->s_root;
3392 + root_inode = d_inode(root);
3393 + bbot = au_sbbot(sb);
3394 + amount = bbot + 1 - bindex;
3395 + h_dentry = au_br_dentry(br);
3396 + au_sbilist_lock();
3397 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3398 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3399 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3400 + au_set_h_dptr(root, bindex, dget(h_dentry));
3401 + h_inode = d_inode(h_dentry);
3402 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3403 + au_sbilist_unlock();
3406 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3409 + aufs_bindex_t bbot, add_bindex;
3410 + struct dentry *root, *h_dentry;
3411 + struct inode *root_inode;
3412 + struct au_branch *add_branch;
3414 + root = sb->s_root;
3415 + root_inode = d_inode(root);
3416 + IMustLock(root_inode);
3417 + IiMustWriteLock(root_inode);
3418 + err = test_add(sb, add, remount);
3419 + if (unlikely(err < 0))
3423 + goto out; /* success */
3426 + bbot = au_sbbot(sb);
3427 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3428 + err = PTR_ERR(add_branch);
3429 + if (IS_ERR(add_branch))
3432 + err = au_br_init(add_branch, sb, add);
3433 + if (unlikely(err)) {
3434 + au_br_do_free(add_branch);
3438 + add_bindex = add->bindex;
3439 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3440 + au_br_do_add(sb, add_branch, add_bindex);
3441 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3442 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3444 + h_dentry = add->path.dentry;
3445 + if (!add_bindex) {
3446 + au_cpup_attr_all(root_inode, /*force*/1);
3447 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3449 + au_add_nlink(root_inode, d_inode(h_dentry));
3455 +/* ---------------------------------------------------------------------- */
3457 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3458 + unsigned long long max __maybe_unused,
3461 + unsigned long long n;
3462 + struct file **p, *f;
3463 + struct hlist_bl_head *files;
3464 + struct hlist_bl_node *pos;
3465 + struct au_finfo *finfo;
3469 + files = &au_sbi(sb)->si_files;
3470 + hlist_bl_lock(files);
3471 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3472 + f = finfo->fi_file;
3474 + && !special_file(file_inode(f)->i_mode)) {
3478 + AuDebugOn(n > max);
3481 + hlist_bl_unlock(files);
3486 +static struct file **au_farray_alloc(struct super_block *sb,
3487 + unsigned long long *max)
3489 + struct au_sbinfo *sbi;
3492 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3493 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3496 +static void au_farray_free(struct file **a, unsigned long long max)
3498 + unsigned long long ull;
3500 + for (ull = 0; ull < max; ull++)
3506 +/* ---------------------------------------------------------------------- */
3512 +/* to show the line number, do not make it inlined function */
3513 +#define AuVerbose(do_info, fmt, ...) do { \
3515 + pr_info(fmt, ##__VA_ARGS__); \
3518 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3519 + aufs_bindex_t bbot)
3521 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3524 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3525 + aufs_bindex_t bbot)
3527 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3531 + * test if the branch is deletable or not.
3533 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3534 + unsigned int sigen, const unsigned int verbose)
3536 + int err, i, j, ndentry;
3537 + aufs_bindex_t btop, bbot;
3538 + struct au_dcsub_pages dpages;
3539 + struct au_dpage *dpage;
3542 + err = au_dpages_init(&dpages, GFP_NOFS);
3543 + if (unlikely(err))
3545 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3546 + if (unlikely(err))
3549 + for (i = 0; !err && i < dpages.ndpage; i++) {
3550 + dpage = dpages.dpages + i;
3551 + ndentry = dpage->ndentry;
3552 + for (j = 0; !err && j < ndentry; j++) {
3553 + d = dpage->dentries[j];
3554 + AuDebugOn(au_dcount(d) <= 0);
3555 + if (!au_digen_test(d, sigen)) {
3556 + di_read_lock_child(d, AuLock_IR);
3557 + if (unlikely(au_dbrange_test(d))) {
3558 + di_read_unlock(d, AuLock_IR);
3562 + di_write_lock_child(d);
3563 + if (unlikely(au_dbrange_test(d))) {
3564 + di_write_unlock(d);
3567 + err = au_reval_dpath(d, sigen);
3569 + di_downgrade_lock(d, AuLock_IR);
3571 + di_write_unlock(d);
3576 + /* AuDbgDentry(d); */
3577 + btop = au_dbtop(d);
3578 + bbot = au_dbbot(d);
3579 + if (btop <= bindex
3581 + && au_h_dptr(d, bindex)
3582 + && au_test_dbusy(d, btop, bbot)) {
3584 + AuVerbose(verbose, "busy %pd\n", d);
3587 + di_read_unlock(d, AuLock_IR);
3592 + au_dpages_free(&dpages);
3597 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3598 + unsigned int sigen, const unsigned int verbose)
3601 + unsigned long long max, ull;
3602 + struct inode *i, **array;
3603 + aufs_bindex_t btop, bbot;
3605 + array = au_iarray_alloc(sb, &max);
3606 + err = PTR_ERR(array);
3607 + if (IS_ERR(array))
3611 + AuDbg("b%d\n", bindex);
3612 + for (ull = 0; !err && ull < max; ull++) {
3616 + if (i->i_ino == AUFS_ROOT_INO)
3619 + /* AuDbgInode(i); */
3620 + if (au_iigen(i, NULL) == sigen)
3621 + ii_read_lock_child(i);
3623 + ii_write_lock_child(i);
3624 + err = au_refresh_hinode_self(i);
3627 + ii_downgrade_lock(i);
3629 + ii_write_unlock(i);
3634 + btop = au_ibtop(i);
3635 + bbot = au_ibbot(i);
3636 + if (btop <= bindex
3638 + && au_h_iptr(i, bindex)
3639 + && au_test_ibusy(i, btop, bbot)) {
3641 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3644 + ii_read_unlock(i);
3646 + au_iarray_free(array, max);
3652 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3653 + const unsigned int verbose)
3656 + unsigned int sigen;
3658 + sigen = au_sigen(root->d_sb);
3659 + DiMustNoWaiters(root);
3660 + IiMustNoWaiters(d_inode(root));
3661 + di_write_unlock(root);
3662 + err = test_dentry_busy(root, bindex, sigen, verbose);
3664 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3665 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3670 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3671 + struct file **to_free, int *idx)
3674 + unsigned char matched, root;
3675 + aufs_bindex_t bindex, bbot;
3676 + struct au_fidir *fidir;
3677 + struct au_hfile *hfile;
3680 + root = IS_ROOT(file->f_path.dentry);
3683 + to_free[*idx] = file;
3689 + fidir = au_fi(file)->fi_hdir;
3690 + AuDebugOn(!fidir);
3691 + bbot = au_fbbot_dir(file);
3692 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3693 + hfile = fidir->fd_hfile + bindex;
3694 + if (!hfile->hf_file)
3697 + if (hfile->hf_br->br_id == br_id) {
3709 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3710 + struct file **to_free, int opened)
3713 + unsigned long long ull, max;
3714 + aufs_bindex_t btop;
3715 + struct file *file, **array;
3716 + struct dentry *root;
3717 + struct au_hfile *hfile;
3719 + array = au_farray_alloc(sb, &max);
3720 + err = PTR_ERR(array);
3721 + if (IS_ERR(array))
3726 + root = sb->s_root;
3727 + di_write_unlock(root);
3728 + for (ull = 0; ull < max; ull++) {
3729 + file = array[ull];
3730 + if (unlikely(!file))
3733 + /* AuDbg("%pD\n", file); */
3734 + fi_read_lock(file);
3735 + btop = au_fbtop(file);
3736 + if (!d_is_dir(file->f_path.dentry)) {
3737 + hfile = &au_fi(file)->fi_htop;
3738 + if (hfile->hf_br->br_id == br_id)
3741 + err = test_dir_busy(file, br_id, to_free, &idx);
3742 + fi_read_unlock(file);
3743 + if (unlikely(err))
3746 + di_write_lock_child(root);
3747 + au_farray_free(array, max);
3748 + AuDebugOn(idx > opened);
3754 +static void br_del_file(struct file **to_free, unsigned long long opened,
3755 + aufs_bindex_t br_id)
3757 + unsigned long long ull;
3758 + aufs_bindex_t bindex, btop, bbot, bfound;
3759 + struct file *file;
3760 + struct au_fidir *fidir;
3761 + struct au_hfile *hfile;
3763 + for (ull = 0; ull < opened; ull++) {
3764 + file = to_free[ull];
3765 + if (unlikely(!file))
3768 + /* AuDbg("%pD\n", file); */
3769 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3771 + fidir = au_fi(file)->fi_hdir;
3772 + AuDebugOn(!fidir);
3773 + fi_write_lock(file);
3774 + btop = au_fbtop(file);
3775 + bbot = au_fbbot_dir(file);
3776 + for (bindex = btop; bindex <= bbot; bindex++) {
3777 + hfile = fidir->fd_hfile + bindex;
3778 + if (!hfile->hf_file)
3781 + if (hfile->hf_br->br_id == br_id) {
3786 + AuDebugOn(bfound < 0);
3787 + au_set_h_fptr(file, bfound, NULL);
3788 + if (bfound == btop) {
3789 + for (btop++; btop <= bbot; btop++)
3790 + if (au_hf_dir(file, btop)) {
3791 + au_set_fbtop(file, btop);
3795 + fi_write_unlock(file);
3799 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3800 + const aufs_bindex_t bindex,
3801 + const aufs_bindex_t bbot)
3803 + struct au_branch **brp, **p;
3805 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3807 + brp = sbinfo->si_branch + bindex;
3808 + if (bindex < bbot)
3809 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3810 + sbinfo->si_branch[0 + bbot] = NULL;
3811 + sbinfo->si_bbot--;
3813 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3816 + sbinfo->si_branch = p;
3817 + /* harmless error */
3820 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3821 + const aufs_bindex_t bbot)
3823 + struct au_hdentry *hdp, *p;
3825 + AuRwMustWriteLock(&dinfo->di_rwsem);
3827 + hdp = au_hdentry(dinfo, bindex);
3828 + if (bindex < bbot)
3829 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3830 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3833 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3836 + dinfo->di_hdentry = p;
3837 + /* harmless error */
3840 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3841 + const aufs_bindex_t bbot)
3843 + struct au_hinode *hip, *p;
3845 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3847 + hip = au_hinode(iinfo, bindex);
3848 + if (bindex < bbot)
3849 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3850 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3853 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3856 + iinfo->ii_hinode = p;
3857 + /* harmless error */
3860 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3861 + struct au_branch *br)
3863 + aufs_bindex_t bbot;
3864 + struct au_sbinfo *sbinfo;
3865 + struct dentry *root, *h_root;
3866 + struct inode *inode, *h_inode;
3867 + struct au_hinode *hinode;
3869 + SiMustWriteLock(sb);
3871 + root = sb->s_root;
3872 + inode = d_inode(root);
3873 + sbinfo = au_sbi(sb);
3874 + bbot = sbinfo->si_bbot;
3876 + h_root = au_h_dptr(root, bindex);
3877 + hinode = au_hi(inode, bindex);
3878 + h_inode = au_igrab(hinode->hi_inode);
3881 + au_sbilist_lock();
3882 + au_br_do_del_brp(sbinfo, bindex, bbot);
3883 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3884 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3885 + au_sbilist_unlock();
3887 + /* ignore an error */
3888 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3892 + au_br_do_free(br);
3895 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3896 + unsigned long long max, void *arg)
3901 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3904 + unsigned long long opened;
3905 + unsigned int mnt_flags;
3906 + aufs_bindex_t bindex, bbot, br_id;
3907 + unsigned char do_wh, verbose;
3908 + struct au_branch *br;
3909 + struct au_wbr *wbr;
3910 + struct dentry *root;
3911 + struct file **to_free;
3916 + root = sb->s_root;
3917 + bindex = au_find_dbindex(root, del->h_path.dentry);
3920 + goto out; /* success */
3922 + pr_err("%s no such branch\n", del->pathname);
3925 + AuDbg("bindex b%d\n", bindex);
3928 + mnt_flags = au_mntflags(sb);
3929 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3930 + bbot = au_sbbot(sb);
3931 + if (unlikely(!bbot)) {
3932 + AuVerbose(verbose, "no more branches left\n");
3936 + br = au_sbr(sb, bindex);
3937 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3938 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3939 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3943 + br_id = br->br_id;
3944 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3945 + if (unlikely(opened)) {
3946 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3947 + err = PTR_ERR(to_free);
3948 + if (IS_ERR(to_free))
3951 + err = test_file_busy(sb, br_id, to_free, opened);
3952 + if (unlikely(err)) {
3953 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3959 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3961 + /* instead of WbrWhMustWriteLock(wbr) */
3962 + SiMustWriteLock(sb);
3963 + for (i = 0; i < AuBrWh_Last; i++) {
3964 + dput(wbr->wbr_wh[i]);
3965 + wbr->wbr_wh[i] = NULL;
3969 + err = test_children_busy(root, bindex, verbose);
3970 + if (unlikely(err)) {
3979 + * now we confirmed the branch is deletable.
3980 + * let's free the remaining opened dirs on the branch.
3982 + di_write_unlock(root);
3983 + br_del_file(to_free, opened, br_id);
3984 + di_write_lock_child(root);
3987 + sysaufs_brs_del(sb, bindex); /* remove successors */
3988 + dbgaufs_xino_del(br); /* remove one */
3989 + au_br_do_del(sb, bindex, br);
3990 + sysaufs_brs_add(sb, bindex); /* append successors */
3991 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3994 + au_cpup_attr_all(d_inode(root), /*force*/1);
3995 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3997 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3998 + if (au_opt_test(mnt_flags, PLINK))
3999 + au_plink_half_refresh(sb, br_id);
4001 + goto out; /* success */
4005 + rerr = au_br_init_wh(sb, br, br->br_perm);
4007 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4008 + del->pathname, rerr);
4011 + au_farray_free(to_free, opened);
4015 +/* ---------------------------------------------------------------------- */
4017 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4020 + aufs_bindex_t btop, bbot;
4021 + struct aufs_ibusy ibusy;
4022 + struct inode *inode, *h_inode;
4025 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4028 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4030 + /* VERIFY_WRITE */
4031 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4032 + if (unlikely(err)) {
4039 + si_read_lock(sb, AuLock_FLUSH);
4040 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4044 + ibusy.h_ino = 0; /* invalid */
4045 + inode = ilookup(sb, ibusy.ino);
4047 + || inode->i_ino == AUFS_ROOT_INO
4048 + || au_is_bad_inode(inode))
4051 + ii_read_lock_child(inode);
4052 + btop = au_ibtop(inode);
4053 + bbot = au_ibbot(inode);
4054 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4055 + h_inode = au_h_iptr(inode, ibusy.bindex);
4056 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4057 + ibusy.h_ino = h_inode->i_ino;
4059 + ii_read_unlock(inode);
4063 + si_read_unlock(sb);
4065 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4066 + if (unlikely(err)) {
4075 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4077 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4080 +#ifdef CONFIG_COMPAT
4081 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4083 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4087 +/* ---------------------------------------------------------------------- */
4090 + * change a branch permission
4093 +static void au_warn_ima(void)
4096 + /* since it doesn't support mark_files_ro() */
4097 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4101 +static int do_need_sigen_inc(int a, int b)
4103 + return au_br_whable(a) && !au_br_whable(b);
4106 +static int need_sigen_inc(int old, int new)
4108 + return do_need_sigen_inc(old, new)
4109 + || do_need_sigen_inc(new, old);
4112 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4115 + unsigned int mnt_flags;
4116 + unsigned long long ull, max;
4117 + aufs_bindex_t br_id;
4118 + unsigned char verbose, writer;
4119 + struct file *file, *hf, **array;
4120 + struct au_hfile *hfile;
4121 + struct inode *h_inode;
4123 + mnt_flags = au_mntflags(sb);
4124 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4126 + array = au_farray_alloc(sb, &max);
4127 + err = PTR_ERR(array);
4128 + if (IS_ERR(array))
4132 + br_id = au_sbr_id(sb, bindex);
4133 + for (ull = 0; ull < max; ull++) {
4134 + file = array[ull];
4135 + if (unlikely(!file))
4138 + /* AuDbg("%pD\n", file); */
4139 + fi_read_lock(file);
4140 + if (unlikely(au_test_mmapped(file))) {
4142 + AuVerbose(verbose, "mmapped %pD\n", file);
4144 + FiMustNoWaiters(file);
4145 + fi_read_unlock(file);
4149 + hfile = &au_fi(file)->fi_htop;
4150 + hf = hfile->hf_file;
4151 + if (!d_is_reg(file->f_path.dentry)
4152 + || !(file->f_mode & FMODE_WRITE)
4153 + || hfile->hf_br->br_id != br_id
4154 + || !(hf->f_mode & FMODE_WRITE))
4155 + array[ull] = NULL;
4161 + FiMustNoWaiters(file);
4162 + fi_read_unlock(file);
4170 + for (ull = 0; ull < max; ull++) {
4171 + file = array[ull];
4175 + /* todo: already flushed? */
4177 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4178 + * approach which resets f_mode and calls mnt_drop_write() and
4179 + * file_release_write() for each file, because the branch
4180 + * attribute in aufs world is totally different from the native
4183 + /* fi_read_lock(file); */
4184 + hfile = &au_fi(file)->fi_htop;
4185 + hf = hfile->hf_file;
4186 + /* fi_read_unlock(file); */
4187 + spin_lock(&hf->f_lock);
4188 + writer = !!(hf->f_mode & FMODE_WRITER);
4189 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4190 + spin_unlock(&hf->f_lock);
4192 + h_inode = file_inode(hf);
4193 + if (hf->f_mode & FMODE_READ)
4194 + i_readcount_inc(h_inode);
4195 + put_write_access(h_inode);
4196 + __mnt_drop_write(hf->f_path.mnt);
4201 + au_farray_free(array, max);
4207 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4211 + aufs_bindex_t bindex;
4212 + struct dentry *root;
4213 + struct au_branch *br;
4214 + struct au_br_fhsm *bf;
4216 + root = sb->s_root;
4217 + bindex = au_find_dbindex(root, mod->h_root);
4220 + return 0; /* success */
4222 + pr_err("%s no such branch\n", mod->path);
4225 + AuDbg("bindex b%d\n", bindex);
4227 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4228 + if (unlikely(err))
4231 + br = au_sbr(sb, bindex);
4232 + AuDebugOn(mod->h_root != au_br_dentry(br));
4233 + if (br->br_perm == mod->perm)
4234 + return 0; /* success */
4236 + /* pre-allocate for non-fhsm --> fhsm */
4238 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4239 + err = au_fhsm_br_alloc(br);
4240 + if (unlikely(err))
4243 + br->br_fhsm = NULL;
4246 + if (au_br_writable(br->br_perm)) {
4247 + /* remove whiteout base */
4248 + err = au_br_init_wh(sb, br, mod->perm);
4249 + if (unlikely(err))
4252 + if (!au_br_writable(mod->perm)) {
4253 + /* rw --> ro, file might be mmapped */
4254 + DiMustNoWaiters(root);
4255 + IiMustNoWaiters(d_inode(root));
4256 + di_write_unlock(root);
4257 + err = au_br_mod_files_ro(sb, bindex);
4258 + /* aufs_write_lock() calls ..._child() */
4259 + di_write_lock_child(root);
4261 + if (unlikely(err)) {
4263 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4266 + rerr = au_wbr_init(br, sb, br->br_perm);
4267 + if (unlikely(rerr)) {
4268 + AuIOErr("nested error %d (%d)\n",
4270 + br->br_perm = mod->perm;
4274 + } else if (au_br_writable(mod->perm)) {
4277 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4279 + err = au_wbr_init(br, sb, mod->perm);
4280 + if (unlikely(err)) {
4281 + au_kfree_rcu(br->br_wbr);
4282 + br->br_wbr = NULL;
4286 + if (unlikely(err))
4289 + if (au_br_fhsm(br->br_perm)) {
4290 + if (!au_br_fhsm(mod->perm)) {
4291 + /* fhsm --> non-fhsm */
4292 + au_br_fhsm_fin(br->br_fhsm);
4293 + au_kfree_rcu(br->br_fhsm);
4294 + br->br_fhsm = NULL;
4296 + } else if (au_br_fhsm(mod->perm))
4297 + /* non-fhsm --> fhsm */
4300 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4301 + br->br_perm = mod->perm;
4302 + goto out; /* success */
4305 + au_kfree_try_rcu(bf);
4311 +/* ---------------------------------------------------------------------- */
4313 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4316 + struct kstatfs kstfs;
4318 + err = vfs_statfs(&br->br_path, &kstfs);
4320 + stfs->f_blocks = kstfs.f_blocks;
4321 + stfs->f_bavail = kstfs.f_bavail;
4322 + stfs->f_files = kstfs.f_files;
4323 + stfs->f_ffree = kstfs.f_ffree;
4328 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4329 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4330 +++ linux/fs/aufs/branch.h 2022-10-26 22:30:38.462648858 +0200
4332 +/* SPDX-License-Identifier: GPL-2.0 */
4334 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4336 + * This program, aufs is free software; you can redistribute it and/or modify
4337 + * it under the terms of the GNU General Public License as published by
4338 + * the Free Software Foundation; either version 2 of the License, or
4339 + * (at your option) any later version.
4341 + * This program is distributed in the hope that it will be useful,
4342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4344 + * GNU General Public License for more details.
4346 + * You should have received a copy of the GNU General Public License
4347 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4351 + * branch filesystems and xino for them
4354 +#ifndef __AUFS_BRANCH_H__
4355 +#define __AUFS_BRANCH_H__
4359 +#include <linux/mount.h>
4360 +#include "dirren.h"
4366 +/* ---------------------------------------------------------------------- */
4370 + struct file **xi_file;
4371 + unsigned int xi_nfile;
4377 + /* reserved for future use */
4378 + /* unsigned long *bitmap; */
4379 + wait_queue_head_t wqh;
4382 + struct mutex xi_mtx; /* protects xi_file array */
4383 + struct hlist_bl_head xi_writing;
4385 + atomic_t xi_truncating;
4387 + struct kref xi_kref;
4390 +/* File-based Hierarchical Storage Management */
4391 +struct au_br_fhsm {
4392 +#ifdef CONFIG_AUFS_FHSM
4393 + struct mutex bf_lock;
4394 + unsigned long bf_jiffy;
4395 + struct aufs_stfs bf_stfs;
4400 +/* members for writable branch only */
4401 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4403 + struct au_rwsem wbr_wh_rwsem;
4404 + struct dentry *wbr_wh[AuBrWh_Last];
4405 + atomic_t wbr_wh_running;
4406 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4407 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4408 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4411 + unsigned long long wbr_bytes;
4414 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4415 +#define AuBrDynOp (AuDyLast * 4)
4417 +#ifdef CONFIG_AUFS_HFSNOTIFY
4418 +/* support for asynchronous destruction */
4419 +struct au_br_hfsnotify {
4420 + struct fsnotify_group *hfsn_group;
4424 +/* sysfs entries */
4425 +struct au_brsysfs {
4427 + struct attribute attr;
4436 +/* protected by superblock rwsem */
4438 + struct au_xino *br_xino;
4440 + aufs_bindex_t br_id;
4443 + struct path br_path;
4444 + spinlock_t br_dykey_lock;
4445 + struct au_dykey *br_dykey[AuBrDynOp];
4446 + au_lcnt_t br_nfiles; /* opened files */
4447 + au_lcnt_t br_count; /* in-use for other */
4449 + struct au_wbr *br_wbr;
4450 + struct au_br_fhsm *br_fhsm;
4452 +#ifdef CONFIG_AUFS_HFSNOTIFY
4453 + struct au_br_hfsnotify *br_hfsn;
4456 +#ifdef CONFIG_SYSFS
4457 + /* entries under sysfs per mount-point */
4458 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4461 +#ifdef CONFIG_DEBUG_FS
4462 + struct dentry *br_dbgaufs; /* xino */
4465 + struct au_dr_br br_dirren;
4468 +/* ---------------------------------------------------------------------- */
4470 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4472 + return br->br_path.mnt;
4475 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4477 + return br->br_path.dentry;
4480 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4482 + return mnt_user_ns(br->br_path.mnt);
4485 +static inline struct super_block *au_br_sb(struct au_branch *br)
4487 + return au_br_mnt(br)->mnt_sb;
4490 +static inline int au_br_rdonly(struct au_branch *br)
4492 + return (sb_rdonly(au_br_sb(br))
4493 + || !au_br_writable(br->br_perm))
4497 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4499 +#ifdef CONFIG_AUFS_HNOTIFY
4500 + return !(brperm & AuBrPerm_RR);
4506 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4508 + int err, exec_flag;
4511 + exec_flag = oflag & __FMODE_EXEC;
4512 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4518 +static inline void au_xino_get(struct au_branch *br)
4520 + struct au_xino *xi;
4524 + kref_get(&xi->xi_kref);
4527 +static inline int au_xino_count(struct au_branch *br)
4530 + struct au_xino *xi;
4535 + v = kref_read(&xi->xi_kref);
4540 +/* ---------------------------------------------------------------------- */
4544 +void au_br_free(struct au_sbinfo *sinfo);
4545 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4547 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4549 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4550 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4551 +#ifdef CONFIG_COMPAT
4552 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4555 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4558 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4561 +static const loff_t au_loff_max = LLONG_MAX;
4563 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4564 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4566 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4567 + struct file *copy_src);
4569 + struct au_xino *xi; /* switch between xino and xigen */
4571 + struct path *base;
4572 + struct file *copy_src;
4574 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4576 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4578 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4580 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4581 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4583 +int au_xib_trunc(struct super_block *sb);
4584 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4586 +struct au_xino *au_xino_alloc(unsigned int nfile);
4587 +int au_xino_put(struct au_branch *br);
4588 +struct file *au_xino_file1(struct au_xino *xi);
4590 +struct au_opt_xino;
4591 +void au_xino_clr(struct super_block *sb);
4592 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4593 +struct file *au_xino_def(struct super_block *sb);
4594 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4595 + struct path *base);
4597 +ino_t au_xino_new_ino(struct super_block *sb);
4598 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4600 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4601 + ino_t h_ino, int idx);
4602 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4605 +int au_xino_path(struct seq_file *seq, struct file *file);
4607 +/* ---------------------------------------------------------------------- */
4609 +/* @idx is signed to accept -1 meaning the first file */
4610 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4612 + struct file *file;
4619 + if (idx < xi->xi_nfile)
4620 + file = xi->xi_file[idx];
4622 + file = au_xino_file1(xi);
4628 +/* ---------------------------------------------------------------------- */
4630 +/* Superblock to branch */
4632 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4634 + return au_sbr(sb, bindex)->br_id;
4638 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4640 + return au_br_mnt(au_sbr(sb, bindex));
4644 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4646 + return au_br_userns(au_sbr(sb, bindex));
4650 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4652 + return au_br_sb(au_sbr(sb, bindex));
4655 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4657 + return au_sbr(sb, bindex)->br_perm;
4660 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4662 + return au_br_whable(au_sbr_perm(sb, bindex));
4665 +/* ---------------------------------------------------------------------- */
4667 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4668 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4669 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4670 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4672 +#define wbr_wh_read_trylock_nested(wbr) \
4673 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4674 +#define wbr_wh_write_trylock_nested(wbr) \
4675 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4678 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4679 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4680 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4682 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4683 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4684 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4686 +/* ---------------------------------------------------------------------- */
4688 +#ifdef CONFIG_AUFS_FHSM
4689 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4691 + mutex_init(&brfhsm->bf_lock);
4692 + brfhsm->bf_jiffy = 0;
4693 + brfhsm->bf_readable = 0;
4696 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4698 + mutex_destroy(&brfhsm->bf_lock);
4701 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4702 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4705 +#endif /* __KERNEL__ */
4706 +#endif /* __AUFS_BRANCH_H__ */
4707 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4708 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4709 +++ linux/fs/aufs/conf.mk 2022-10-26 22:30:38.462648858 +0200
4711 +# SPDX-License-Identifier: GPL-2.0
4713 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4717 +AuConfStr += ${1}=${${1}}
4721 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4723 + HNOTIFY HFSNOTIFY \
4735 +$(foreach i, ${AuConfAll}, \
4736 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4738 +AuConfName = ${obj}/conf.str
4739 +${AuConfName}.tmp: FORCE
4740 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4741 +${AuConfName}: ${AuConfName}.tmp
4742 + @diff -q $< $@ > /dev/null 2>&1 || { \
4743 + echo ' GEN ' $@; \
4747 +clean-files += ${AuConfName} ${AuConfName}.tmp
4748 +${obj}/sysfs.o: ${AuConfName}
4750 +-include ${srctree}/${src}/conf_priv.mk
4751 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4752 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4753 +++ linux/fs/aufs/cpup.c 2022-10-26 22:30:38.462648858 +0200
4755 +// SPDX-License-Identifier: GPL-2.0
4757 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4759 + * This program, aufs is free software; you can redistribute it and/or modify
4760 + * it under the terms of the GNU General Public License as published by
4761 + * the Free Software Foundation; either version 2 of the License, or
4762 + * (at your option) any later version.
4764 + * This program is distributed in the hope that it will be useful,
4765 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4766 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4767 + * GNU General Public License for more details.
4769 + * You should have received a copy of the GNU General Public License
4770 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4774 + * copy-up functions, see wbr_policy.c for copy-down
4777 +#include <linux/fs_stack.h>
4778 +#include <linux/mm.h>
4779 +#include <linux/task_work.h>
4782 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4784 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4785 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4787 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4789 + dst->i_flags |= iflags & ~mask;
4790 + if (au_test_fs_notime(dst->i_sb))
4791 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4794 +void au_cpup_attr_timesizes(struct inode *inode)
4796 + struct inode *h_inode;
4798 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4799 + fsstack_copy_attr_times(inode, h_inode);
4800 + fsstack_copy_inode_size(inode, h_inode);
4803 +void au_cpup_attr_nlink(struct inode *inode, int force)
4805 + struct inode *h_inode;
4806 + struct super_block *sb;
4807 + aufs_bindex_t bindex, bbot;
4810 + bindex = au_ibtop(inode);
4811 + h_inode = au_h_iptr(inode, bindex);
4813 + && !S_ISDIR(h_inode->i_mode)
4814 + && au_opt_test(au_mntflags(sb), PLINK)
4815 + && au_plink_test(inode))
4819 + * 0 can happen in revalidating.
4820 + * h_inode->i_mutex may not be held here, but it is harmless since once
4821 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4823 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4824 + * the incorrect link count.
4826 + set_nlink(inode, h_inode->i_nlink);
4829 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4830 + * it may includes whplink directory.
4832 + if (S_ISDIR(h_inode->i_mode)) {
4833 + bbot = au_ibbot(inode);
4834 + for (bindex++; bindex <= bbot; bindex++) {
4835 + h_inode = au_h_iptr(inode, bindex);
4837 + au_add_nlink(inode, h_inode);
4842 +void au_cpup_attr_changeable(struct inode *inode)
4844 + struct inode *h_inode;
4846 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4847 + inode->i_mode = h_inode->i_mode;
4848 + inode->i_uid = h_inode->i_uid;
4849 + inode->i_gid = h_inode->i_gid;
4850 + au_cpup_attr_timesizes(inode);
4851 + au_cpup_attr_flags(inode, h_inode->i_flags);
4854 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4856 + struct au_iinfo *iinfo = au_ii(inode);
4858 + IiMustWriteLock(inode);
4860 + iinfo->ii_higen = h_inode->i_generation;
4861 + iinfo->ii_hsb1 = h_inode->i_sb;
4864 +void au_cpup_attr_all(struct inode *inode, int force)
4866 + struct inode *h_inode;
4868 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4869 + au_cpup_attr_changeable(inode);
4870 + if (inode->i_nlink > 0)
4871 + au_cpup_attr_nlink(inode, force);
4872 + inode->i_rdev = h_inode->i_rdev;
4873 + inode->i_blkbits = h_inode->i_blkbits;
4874 + au_cpup_igen(inode, h_inode);
4877 +/* ---------------------------------------------------------------------- */
4879 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4881 +/* keep the timestamps of the parent dir when cpup */
4882 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4883 + struct path *h_path)
4885 + struct inode *h_inode;
4887 + dt->dt_dentry = dentry;
4888 + dt->dt_h_path = *h_path;
4889 + h_inode = d_inode(h_path->dentry);
4890 + dt->dt_atime = h_inode->i_atime;
4891 + dt->dt_mtime = h_inode->i_mtime;
4895 +void au_dtime_revert(struct au_dtime *dt)
4897 + struct iattr attr;
4900 + attr.ia_atime = dt->dt_atime;
4901 + attr.ia_mtime = dt->dt_mtime;
4902 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4903 + | ATTR_ATIME | ATTR_ATIME_SET;
4905 + /* no delegation since this is a directory */
4906 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4907 + if (unlikely(err))
4908 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4911 +/* ---------------------------------------------------------------------- */
4913 +/* internal use only */
4914 +struct au_cpup_reg_attr {
4917 + unsigned int iflags; /* inode->i_flags */
4920 +static noinline_for_stack
4921 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4922 + struct au_cpup_reg_attr *h_src_attr)
4924 + int err, sbits, icex;
4925 + unsigned int mnt_flags;
4926 + unsigned char verbose;
4928 + struct path h_path;
4929 + struct inode *h_isrc, *h_idst;
4930 + struct kstat *h_st;
4931 + struct au_branch *br;
4933 + br = au_sbr(dst->d_sb, bindex);
4934 + h_path.mnt = au_br_mnt(br);
4935 + h_path.dentry = au_h_dptr(dst, bindex);
4936 + h_idst = d_inode(h_path.dentry);
4937 + h_isrc = d_inode(h_src->dentry);
4938 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4939 + | ATTR_ATIME | ATTR_MTIME
4940 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4941 + if (h_src_attr && h_src_attr->valid) {
4942 + h_st = &h_src_attr->st;
4943 + ia.ia_uid = h_st->uid;
4944 + ia.ia_gid = h_st->gid;
4945 + ia.ia_atime = h_st->atime;
4946 + ia.ia_mtime = h_st->mtime;
4947 + if (h_idst->i_mode != h_st->mode
4948 + && !S_ISLNK(h_idst->i_mode)) {
4949 + ia.ia_valid |= ATTR_MODE;
4950 + ia.ia_mode = h_st->mode;
4952 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4953 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4955 + ia.ia_uid = h_isrc->i_uid;
4956 + ia.ia_gid = h_isrc->i_gid;
4957 + ia.ia_atime = h_isrc->i_atime;
4958 + ia.ia_mtime = h_isrc->i_mtime;
4959 + if (h_idst->i_mode != h_isrc->i_mode
4960 + && !S_ISLNK(h_idst->i_mode)) {
4961 + ia.ia_valid |= ATTR_MODE;
4962 + ia.ia_mode = h_isrc->i_mode;
4964 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4965 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4967 + /* no delegation since it is just created */
4968 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4970 + /* is this nfs only? */
4971 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4972 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4973 + ia.ia_mode = h_isrc->i_mode;
4974 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4977 + icex = br->br_perm & AuBrAttr_ICEX;
4979 + mnt_flags = au_mntflags(dst->d_sb);
4980 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4981 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4987 +/* ---------------------------------------------------------------------- */
4989 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4990 + char *buf, unsigned long blksize)
4993 + size_t sz, rbytes, wbytes;
4994 + unsigned char all_zero;
4996 + struct inode *h_inode;
4997 + /* reduce stack usage */
5000 + zp = page_address(ZERO_PAGE(0));
5001 + if (unlikely(!zp))
5002 + return -ENOMEM; /* possible? */
5007 + AuDbg("len %lld\n", len);
5009 + if (len < blksize)
5013 + /* todo: signal_pending? */
5014 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5015 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5018 + if (unlikely(err < 0))
5022 + if (len >= rbytes && rbytes == blksize)
5023 + all_zero = !memcmp(buf, zp, rbytes);
5030 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5032 + /* todo: signal_pending? */
5033 + if (unlikely(err == -EAGAIN || err == -EINTR))
5035 + if (unlikely(err < 0))
5040 + if (unlikely(err < 0))
5046 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5048 + if (unlikely(res < 0))
5055 + /* the last block may be a hole */
5056 + if (!err && all_zero) {
5057 + AuLabel(last hole);
5060 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5061 + /* nfs requires this step to make last hole */
5062 + /* is this only nfs? */
5064 + /* todo: signal_pending? */
5065 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5066 + } while (err == -EAGAIN || err == -EINTR);
5073 + ia->ia_size = dst->f_pos;
5074 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5075 + ia->ia_file = dst;
5076 + h_inode = file_inode(dst);
5077 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5078 + /* no delegation since it is just created */
5079 + err = vfsub_notify_change(&dst->f_path, ia,
5080 + /*delegated*/NULL);
5081 + inode_unlock(h_inode);
5088 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5091 + unsigned long blksize;
5092 + unsigned char do_kfree;
5094 + struct super_block *h_sb;
5097 + h_sb = file_inode(dst)->i_sb;
5098 + blksize = h_sb->s_blocksize;
5099 + if (!blksize || PAGE_SIZE < blksize)
5100 + blksize = PAGE_SIZE;
5101 + AuDbg("blksize %lu\n", blksize);
5102 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5104 + buf = kmalloc(blksize, GFP_NOFS);
5106 + buf = (void *)__get_free_page(GFP_NOFS);
5107 + if (unlikely(!buf))
5110 + if (len > (1 << 22))
5111 + AuDbg("copying a large file %lld\n", (long long)len);
5115 + err = au_do_copy_file(dst, src, len, buf, blksize);
5117 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5118 + au_kfree_do_rcu(buf);
5120 + free_page((unsigned long)buf);
5126 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5129 + struct super_block *h_src_sb;
5130 + struct inode *h_src_inode;
5132 + h_src_inode = file_inode(src);
5133 + h_src_sb = h_src_inode->i_sb;
5135 + /* XFS acquires inode_lock */
5136 + if (!au_test_xfs(h_src_sb))
5137 + err = au_copy_file(dst, src, len);
5139 + inode_unlock_shared(h_src_inode);
5140 + err = au_copy_file(dst, src, len);
5141 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5147 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5151 + struct super_block *h_src_sb;
5152 + struct inode *h_src_inode;
5154 + h_src_inode = file_inode(src);
5155 + h_src_sb = h_src_inode->i_sb;
5156 + if (h_src_sb != file_inode(dst)->i_sb
5157 + || !dst->f_op->remap_file_range) {
5158 + err = au_do_copy(dst, src, len);
5162 + if (!au_test_nfs(h_src_sb)) {
5163 + inode_unlock_shared(h_src_inode);
5164 + lo = vfsub_clone_file_range(src, dst, len);
5165 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5167 + lo = vfsub_clone_file_range(src, dst, len);
5170 + goto out; /* success */
5171 + } else if (lo >= 0)
5172 + /* todo: possible? */
5173 + /* paritially succeeded */
5174 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5175 + else if (lo != -EOPNOTSUPP) {
5176 + /* older XFS has a condition in cloning */
5181 + /* the backend fs on NFS may not support cloning */
5182 + err = au_do_copy(dst, src, len);
5190 + * to support a sparse file which is opened with O_APPEND,
5191 + * we need to close the file.
5193 +static int au_cp_regular(struct au_cp_generic *cpg)
5196 + enum { SRC, DST };
5198 + aufs_bindex_t bindex;
5199 + unsigned int flags;
5200 + struct dentry *dentry;
5202 + struct file *file;
5205 + .bindex = cpg->bsrc,
5206 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5209 + .bindex = cpg->bdst,
5210 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5211 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5214 + struct au_branch *br;
5215 + struct super_block *sb, *h_src_sb;
5216 + struct inode *h_src_inode;
5217 + struct task_struct *tsk = current;
5219 + /* bsrc branch can be ro/rw. */
5220 + sb = cpg->dentry->d_sb;
5222 + for (i = 0; i < 2; i++, f++) {
5223 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5224 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5225 + /*file*/NULL, f->force_wr);
5226 + if (IS_ERR(f->file)) {
5227 + err = PTR_ERR(f->file);
5235 + /* try stopping to update while we copyup */
5236 + h_src_inode = d_inode(file[SRC].dentry);
5237 + h_src_sb = h_src_inode->i_sb;
5238 + if (!au_test_nfs(h_src_sb))
5239 + IMustLock(h_src_inode);
5240 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5242 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5243 + if (tsk->flags & PF_KTHREAD)
5244 + __fput_sync(file[DST].file);
5246 + /* it happened actually */
5247 + fput(file[DST].file);
5250 + * we have to call both since we don't know which place the file
5254 + flush_delayed_fput();
5256 + br = au_sbr(sb, file[DST].bindex);
5257 + au_lcnt_dec(&br->br_nfiles);
5260 + fput(file[SRC].file);
5261 + br = au_sbr(sb, file[SRC].bindex);
5262 + au_lcnt_dec(&br->br_nfiles);
5267 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5268 + struct au_cpup_reg_attr *h_src_attr)
5272 + struct path h_path;
5273 + struct inode *h_src_inode, *h_dst_inode;
5276 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5277 + l = i_size_read(h_src_inode);
5278 + if (cpg->len == -1 || l < cpg->len)
5281 + /* try stopping to update while we are referencing */
5282 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5283 + au_pin_hdir_unlock(cpg->pin);
5285 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5286 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5287 + h_src_attr->iflags = h_src_inode->i_flags;
5288 + if (!au_test_nfs(h_src_inode->i_sb))
5289 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5291 + inode_unlock_shared(h_src_inode);
5292 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5293 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5295 + if (unlikely(err)) {
5296 + inode_unlock_shared(h_src_inode);
5299 + h_src_attr->valid = 1;
5300 + if (!au_test_nfs(h_src_inode->i_sb)) {
5301 + err = au_cp_regular(cpg);
5302 + inode_unlock_shared(h_src_inode);
5304 + inode_unlock_shared(h_src_inode);
5305 + err = au_cp_regular(cpg);
5307 + rerr = au_pin_hdir_relock(cpg->pin);
5311 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5312 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5313 + h_dst_inode = d_inode(h_path.dentry);
5314 + spin_lock(&h_dst_inode->i_lock);
5315 + h_dst_inode->i_state |= I_LINKABLE;
5316 + spin_unlock(&h_dst_inode->i_lock);
5323 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5324 + struct inode *h_dir)
5327 + DEFINE_DELAYED_CALL(done);
5330 + sym = vfs_get_link(h_src, &done);
5331 + err = PTR_ERR(sym);
5335 + err = vfsub_symlink(h_dir, h_path, sym);
5338 + do_delayed_call(&done);
5343 + * regardless 'acl' option, reset all ACL.
5344 + * All ACL will be copied up later from the original entry on the lower branch.
5346 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5349 + struct dentry *h_dentry;
5350 + struct inode *h_inode;
5351 + struct user_namespace *h_userns;
5353 + h_userns = mnt_user_ns(h_path->mnt);
5354 + h_dentry = h_path->dentry;
5355 + h_inode = d_inode(h_dentry);
5356 + /* forget_all_cached_acls(h_inode)); */
5357 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5359 + if (err == -EOPNOTSUPP)
5362 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5368 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5369 + struct inode *h_dir, struct path *h_path)
5372 + struct inode *dir, *inode;
5373 + struct user_namespace *h_userns;
5375 + h_userns = mnt_user_ns(h_path->mnt);
5376 + err = vfsub_removexattr(h_userns, h_path->dentry,
5377 + XATTR_NAME_POSIX_ACL_DEFAULT);
5379 + if (err == -EOPNOTSUPP)
5381 + if (unlikely(err))
5385 + * strange behaviour from the users view,
5386 + * particularly setattr case
5388 + dir = d_inode(dst_parent);
5389 + if (au_ibtop(dir) == cpg->bdst)
5390 + au_cpup_attr_nlink(dir, /*force*/1);
5391 + inode = d_inode(cpg->dentry);
5392 + au_cpup_attr_nlink(inode, /*force*/1);
5398 +static noinline_for_stack
5399 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5400 + struct au_cpup_reg_attr *h_src_attr)
5404 + unsigned int mnt_flags;
5405 + unsigned char isdir, isreg, force;
5406 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5407 + struct au_dtime dt;
5408 + struct path h_path;
5409 + struct dentry *h_src, *h_dst, *h_parent;
5410 + struct inode *h_inode, *h_dir;
5411 + struct super_block *sb;
5413 + /* bsrc branch can be ro/rw. */
5414 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5415 + h_inode = d_inode(h_src);
5416 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5418 + /* try stopping to be referenced while we are creating */
5419 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5420 + if (au_ftest_cpup(cpg->flags, RENAME))
5421 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5422 + AUFS_WH_PFX_LEN));
5423 + h_parent = h_dst->d_parent; /* dir inode is locked */
5424 + h_dir = d_inode(h_parent);
5426 + AuDebugOn(h_parent != h_dst->d_parent);
5428 + sb = cpg->dentry->d_sb;
5429 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5431 + h_path.dentry = h_parent;
5432 + au_dtime_store(&dt, dst_parent, &h_path);
5434 + h_path.dentry = h_dst;
5438 + mode = h_inode->i_mode;
5439 + switch (mode & S_IFMT) {
5442 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5444 + err = au_do_cpup_regular(cpg, h_src_attr);
5448 + err = vfsub_mkdir(h_dir, &h_path, mode);
5450 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5453 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5457 + AuDebugOn(!capable(CAP_MKNOD));
5461 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5464 + AuIOErr("Unknown inode type 0%o\n", mode);
5468 + err = au_reset_acl(h_dir, &h_path, mode);
5470 + mnt_flags = au_mntflags(sb);
5471 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5473 + && au_opt_test(mnt_flags, XINO)
5474 + && (h_inode->i_nlink == 1
5475 + || (h_inode->i_state & I_LINKABLE))
5476 + /* todo: unnecessary? */
5477 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5478 + && cpg->bdst < cpg->bsrc
5479 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5480 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5481 + /* ignore this error */
5486 + force = !!cpg->len;
5487 + if (cpg->len == -1)
5488 + force = !!i_size_read(h_inode);
5490 + au_fhsm_wrote(sb, cpg->bdst, force);
5494 + au_dtime_revert(&dt);
5498 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5501 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5502 + struct path h_ppath;
5503 + struct inode *h_dir;
5504 + aufs_bindex_t bdst;
5506 + dentry = cpg->dentry;
5508 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5509 + h_dentry = au_h_dptr(dentry, bdst);
5510 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5512 + au_set_h_dptr(dentry, bdst, NULL);
5513 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5515 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5516 + au_set_h_dptr(dentry, bdst, h_dentry);
5519 + parent = dget_parent(dentry);
5520 + h_ppath.dentry = au_h_dptr(parent, bdst);
5522 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5523 + if (IS_ERR(h_path->dentry))
5524 + err = PTR_ERR(h_path->dentry);
5526 + if (unlikely(err))
5529 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5530 + h_dir = d_inode(h_parent);
5532 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5533 + /* no delegation since it is just created */
5534 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5536 + dput(h_path->dentry);
5543 + * copyup the @dentry from @bsrc to @bdst.
5544 + * the caller must set the both of lower dentries.
5545 + * @len is for truncating when it is -1 copyup the entire file.
5546 + * in link/rename cases, @dst_parent may be different from the real one.
5547 + * basic->bsrc can be larger than basic->bdst.
5548 + * aufs doesn't touch the credential so
5549 + * security_inode_copy_up{,_xattr}() are unnecessary.
5551 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5554 + aufs_bindex_t old_ibtop;
5555 + unsigned char isdir, plink;
5556 + struct dentry *h_src, *h_dst, *h_parent;
5557 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5558 + struct super_block *sb;
5559 + struct au_branch *br;
5560 + struct path h_src_path;
5561 + /* to reduce stack size */
5563 + struct au_dtime dt;
5564 + struct path h_path;
5565 + struct au_cpup_reg_attr h_src_attr;
5569 + a = kmalloc(sizeof(*a), GFP_NOFS);
5572 + a->h_src_attr.valid = 0;
5574 + sb = cpg->dentry->d_sb;
5575 + br = au_sbr(sb, cpg->bdst);
5576 + a->h_path.mnt = au_br_mnt(br);
5577 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5578 + h_parent = h_dst->d_parent; /* dir inode is locked */
5579 + h_dir = d_inode(h_parent);
5582 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5583 + inode = d_inode(cpg->dentry);
5586 + dst_parent = dget_parent(cpg->dentry);
5590 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5591 + dst_inode = au_h_iptr(inode, cpg->bdst);
5593 + if (unlikely(!plink)) {
5595 + AuIOErr("hi%lu(i%lu) exists on b%d "
5596 + "but plink is disabled\n",
5597 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5601 + if (dst_inode->i_nlink) {
5602 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5604 + h_src = au_plink_lkup(inode, cpg->bdst);
5605 + err = PTR_ERR(h_src);
5606 + if (IS_ERR(h_src))
5608 + if (unlikely(d_is_negative(h_src))) {
5610 + AuIOErr("i%lu exists on b%d "
5611 + "but not pseudo-linked\n",
5612 + inode->i_ino, cpg->bdst);
5618 + a->h_path.dentry = h_parent;
5619 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5622 + a->h_path.dentry = h_dst;
5624 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5625 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5626 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5628 + au_dtime_revert(&a->dt);
5629 + if (unlikely(err == -EWOULDBLOCK)) {
5630 + pr_warn("cannot retry for NFSv4 delegation"
5631 + " for an internal link\n");
5637 + /* todo: cpup_wh_file? */
5639 + au_update_ibrange(inode, /*do_put_zero*/1);
5642 + isdir = S_ISDIR(inode->i_mode);
5643 + old_ibtop = au_ibtop(inode);
5644 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5645 + if (unlikely(err))
5647 + dst_inode = d_inode(h_dst);
5648 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5649 + /* todo: necessary? */
5650 + /* au_pin_hdir_unlock(cpg->pin); */
5652 + h_src_path.dentry = h_src;
5653 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5654 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5655 + if (unlikely(err)) {
5656 + /* todo: necessary? */
5657 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5658 + inode_unlock(dst_inode);
5662 + if (cpg->bdst < old_ibtop) {
5663 + if (S_ISREG(inode->i_mode)) {
5664 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5665 + if (unlikely(err)) {
5666 + /* ignore an error */
5667 + /* au_pin_hdir_relock(cpg->pin); */
5668 + inode_unlock(dst_inode);
5672 + au_set_ibtop(inode, cpg->bdst);
5674 + au_set_ibbot(inode, cpg->bdst);
5675 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5676 + au_hi_flags(inode, isdir));
5678 + /* todo: necessary? */
5679 + /* err = au_pin_hdir_relock(cpg->pin); */
5680 + inode_unlock(dst_inode);
5681 + if (unlikely(err))
5684 + src_inode = d_inode(h_src);
5686 + && (src_inode->i_nlink > 1
5687 + || src_inode->i_state & I_LINKABLE)
5689 + au_plink_append(inode, cpg->bdst, h_dst);
5691 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5692 + a->h_path.dentry = h_dst;
5693 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5696 + goto out_parent; /* success */
5700 + a->h_path.dentry = h_parent;
5701 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5702 + a->h_path.dentry = h_dst;
5704 + if (d_is_positive(h_dst)) {
5706 + /* no delegation since it is just created */
5707 + rerr = vfsub_unlink(h_dir, &a->h_path,
5708 + /*delegated*/NULL, /*force*/0);
5710 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5712 + au_dtime_revert(&a->dt);
5714 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5724 +#if 0 /* reserved */
5725 +struct au_cpup_single_args {
5727 + struct au_cp_generic *cpg;
5728 + struct dentry *dst_parent;
5731 +static void au_call_cpup_single(void *args)
5733 + struct au_cpup_single_args *a = args;
5735 + au_pin_hdir_acquire_nest(a->cpg->pin);
5736 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5737 + au_pin_hdir_release(a->cpg->pin);
5742 + * prevent SIGXFSZ in copy-up.
5743 + * testing CAP_MKNOD is for generic fs,
5744 + * but CAP_FSETID is for xfs only, currently.
5746 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5749 + struct super_block *sb;
5750 + struct inode *h_dir;
5753 + sb = au_pinned_parent(pin)->d_sb;
5754 + if (!au_wkq_test()
5755 + && (!au_sbi(sb)->si_plink_maint_pid
5756 + || au_plink_maint(sb, AuLock_NOPLM))) {
5757 + switch (mode & S_IFMT) {
5759 + /* no condition about RLIMIT_FSIZE and the file size */
5764 + do_sio = !capable(CAP_MKNOD);
5768 + do_sio = ((mode & (S_ISUID | S_ISGID))
5769 + && !capable(CAP_FSETID));
5770 + /* this workaround may be removed in the future */
5772 + h_dir = au_pinned_h_dir(pin);
5773 + do_sio = h_dir->i_mode & S_ISVTX;
5780 +#if 0 /* reserved */
5781 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5784 + struct dentry *h_dentry;
5786 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5787 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5788 + err = au_cpup_single(cpg, dst_parent);
5790 + struct au_cpup_single_args args = {
5793 + .dst_parent = dst_parent
5795 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5796 + if (unlikely(wkq_err))
5805 + * copyup the @dentry from the first active lower branch to @bdst,
5806 + * using au_cpup_single().
5808 +static int au_cpup_simple(struct au_cp_generic *cpg)
5811 + unsigned int flags_orig;
5812 + struct dentry *dentry;
5814 + AuDebugOn(cpg->bsrc < 0);
5816 + dentry = cpg->dentry;
5817 + DiMustWriteLock(dentry);
5819 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5821 + flags_orig = cpg->flags;
5822 + au_fset_cpup(cpg->flags, RENAME);
5823 + err = au_cpup_single(cpg, NULL);
5824 + cpg->flags = flags_orig;
5826 + return 0; /* success */
5829 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5830 + au_set_dbtop(dentry, cpg->bsrc);
5836 +struct au_cpup_simple_args {
5838 + struct au_cp_generic *cpg;
5841 +static void au_call_cpup_simple(void *args)
5843 + struct au_cpup_simple_args *a = args;
5845 + au_pin_hdir_acquire_nest(a->cpg->pin);
5846 + *a->errp = au_cpup_simple(a->cpg);
5847 + au_pin_hdir_release(a->cpg->pin);
5850 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5853 + struct dentry *dentry, *parent;
5854 + struct file *h_file;
5855 + struct inode *h_dir;
5856 + struct user_namespace *h_userns;
5858 + dentry = cpg->dentry;
5860 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5861 + AuDebugOn(cpg->bsrc < 0);
5862 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5863 + err = PTR_ERR(h_file);
5864 + if (IS_ERR(h_file))
5868 + parent = dget_parent(dentry);
5869 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5870 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5871 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5872 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5873 + err = au_cpup_simple(cpg);
5875 + struct au_cpup_simple_args args = {
5879 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5880 + if (unlikely(wkq_err))
5886 + au_h_open_post(dentry, cpg->bsrc, h_file);
5892 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5894 + aufs_bindex_t bsrc, bbot;
5895 + struct dentry *dentry, *h_dentry;
5897 + if (cpg->bsrc < 0) {
5898 + dentry = cpg->dentry;
5899 + bbot = au_dbbot(dentry);
5900 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5901 + h_dentry = au_h_dptr(dentry, bsrc);
5903 + AuDebugOn(d_is_negative(h_dentry));
5907 + AuDebugOn(bsrc > bbot);
5910 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5911 + return au_do_sio_cpup_simple(cpg);
5914 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5916 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5917 + return au_do_sio_cpup_simple(cpg);
5920 +/* ---------------------------------------------------------------------- */
5923 + * copyup the deleted file for writing.
5925 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5926 + struct file *file)
5929 + unsigned int flags_orig;
5930 + aufs_bindex_t bsrc_orig;
5931 + struct au_dinfo *dinfo;
5933 + struct au_hdentry *hd;
5934 + struct dentry *h_dentry;
5937 + dinfo = au_di(cpg->dentry);
5938 + AuRwMustWriteLock(&dinfo->di_rwsem);
5940 + bsrc_orig = cpg->bsrc;
5941 + cpg->bsrc = dinfo->di_btop;
5942 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5943 + hdst.h_dentry = hdst.hd->hd_dentry;
5944 + hdst.hd->hd_dentry = wh_dentry;
5945 + dinfo->di_btop = cpg->bdst;
5947 + hsrc.h_dentry = NULL;
5949 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5950 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5951 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5953 + flags_orig = cpg->flags;
5954 + cpg->flags = !AuCpup_DTIME;
5955 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5956 + cpg->flags = flags_orig;
5959 + err = au_reopen_nondir(file);
5960 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5962 + hdst.hd->hd_dentry = hdst.h_dentry;
5963 + dinfo->di_btop = cpg->bsrc;
5964 + cpg->bsrc = bsrc_orig;
5969 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5972 + aufs_bindex_t bdst;
5973 + struct au_dtime dt;
5974 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5975 + struct au_branch *br;
5976 + struct path h_path;
5978 + dentry = cpg->dentry;
5980 + br = au_sbr(dentry->d_sb, bdst);
5981 + parent = dget_parent(dentry);
5982 + h_parent = au_h_dptr(parent, bdst);
5983 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5984 + err = PTR_ERR(wh_dentry);
5985 + if (IS_ERR(wh_dentry))
5988 + h_path.dentry = h_parent;
5989 + h_path.mnt = au_br_mnt(br);
5990 + au_dtime_store(&dt, parent, &h_path);
5991 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5992 + if (unlikely(err))
5996 + h_path.dentry = wh_dentry;
5997 + if (!d_is_dir(wh_dentry)) {
5998 + /* no delegation since it is just created */
5999 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6000 + /*delegated*/NULL, /*force*/0);
6002 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6003 + if (unlikely(err)) {
6004 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6008 + au_dtime_revert(&dt);
6009 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6018 +struct au_cpup_wh_args {
6020 + struct au_cp_generic *cpg;
6021 + struct file *file;
6024 +static void au_call_cpup_wh(void *args)
6026 + struct au_cpup_wh_args *a = args;
6028 + au_pin_hdir_acquire_nest(a->cpg->pin);
6029 + *a->errp = au_cpup_wh(a->cpg, a->file);
6030 + au_pin_hdir_release(a->cpg->pin);
6033 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6036 + aufs_bindex_t bdst;
6037 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6038 + struct inode *dir, *h_dir, *h_tmpdir;
6039 + struct au_wbr *wbr;
6040 + struct au_pin wh_pin, *pin_orig;
6041 + struct user_namespace *h_userns;
6043 + dentry = cpg->dentry;
6045 + parent = dget_parent(dentry);
6046 + dir = d_inode(parent);
6049 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6052 + if (!h_dir->i_nlink) {
6053 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6054 + h_orph = wbr->wbr_orph;
6056 + h_parent = dget(au_h_dptr(parent, bdst));
6057 + au_set_h_dptr(parent, bdst, dget(h_orph));
6058 + h_tmpdir = d_inode(h_orph);
6059 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6061 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6062 + /* todo: au_h_open_pre()? */
6064 + pin_orig = cpg->pin;
6065 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6066 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6067 + cpg->pin = &wh_pin;
6070 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6071 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6072 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6073 + err = au_cpup_wh(cpg, file);
6075 + struct au_cpup_wh_args args = {
6080 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6081 + if (unlikely(wkq_err))
6086 + inode_unlock(h_tmpdir);
6087 + /* todo: au_h_open_post()? */
6088 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6089 + au_set_h_dptr(parent, bdst, h_parent);
6090 + AuDebugOn(!pin_orig);
6091 + cpg->pin = pin_orig;
6099 +/* ---------------------------------------------------------------------- */
6102 + * generic routine for both of copy-up and copy-down.
6104 +/* cf. revalidate function in file.c */
6105 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6106 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6107 + struct au_pin *pin,
6108 + struct dentry *h_parent, void *arg),
6112 + struct au_pin pin;
6113 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6116 + parent = dget_parent(dentry);
6117 + if (IS_ROOT(parent))
6120 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6121 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6123 + /* do not use au_dpage */
6124 + real_parent = parent;
6127 + parent = dget_parent(dentry);
6128 + h_parent = au_h_dptr(parent, bdst);
6130 + goto out; /* success */
6132 + /* find top dir which is necessary to cpup */
6136 + parent = dget_parent(d);
6137 + di_read_lock_parent3(parent, !AuLock_IR);
6138 + h_parent = au_h_dptr(parent, bdst);
6139 + di_read_unlock(parent, !AuLock_IR);
6140 + } while (!h_parent);
6142 + if (d != real_parent)
6143 + di_write_lock_child3(d);
6145 + /* somebody else might create while we were sleeping */
6146 + h_dentry = au_h_dptr(d, bdst);
6147 + if (!h_dentry || d_is_negative(h_dentry)) {
6149 + au_update_dbtop(d);
6151 + au_pin_set_dentry(&pin, d);
6152 + err = au_do_pin(&pin);
6154 + err = cp(d, bdst, &pin, h_parent, arg);
6159 + if (d != real_parent)
6160 + di_write_unlock(d);
6161 + if (unlikely(err))
6170 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6171 + struct au_pin *pin,
6172 + struct dentry *h_parent __maybe_unused,
6173 + void *arg __maybe_unused)
6175 + struct au_cp_generic cpg = {
6181 + .flags = AuCpup_DTIME
6183 + return au_sio_cpup_simple(&cpg);
6186 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6188 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6191 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6194 + struct dentry *parent;
6195 + struct inode *dir;
6197 + parent = dget_parent(dentry);
6198 + dir = d_inode(parent);
6200 + if (au_h_iptr(dir, bdst))
6203 + di_read_unlock(parent, AuLock_IR);
6204 + di_write_lock_parent(parent);
6205 + /* someone else might change our inode while we were sleeping */
6206 + if (!au_h_iptr(dir, bdst))
6207 + err = au_cpup_dirs(dentry, bdst);
6208 + di_downgrade_lock(parent, AuLock_IR);
6214 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6215 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6216 +++ linux/fs/aufs/cpup.h 2022-10-26 22:30:38.462648858 +0200
6218 +/* SPDX-License-Identifier: GPL-2.0 */
6220 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6222 + * This program, aufs is free software; you can redistribute it and/or modify
6223 + * it under the terms of the GNU General Public License as published by
6224 + * the Free Software Foundation; either version 2 of the License, or
6225 + * (at your option) any later version.
6227 + * This program is distributed in the hope that it will be useful,
6228 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6229 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6230 + * GNU General Public License for more details.
6232 + * You should have received a copy of the GNU General Public License
6233 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6237 + * copy-up/down functions
6240 +#ifndef __AUFS_CPUP_H__
6241 +#define __AUFS_CPUP_H__
6245 +#include <linux/path.h>
6251 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6252 +void au_cpup_attr_timesizes(struct inode *inode);
6253 +void au_cpup_attr_nlink(struct inode *inode, int force);
6254 +void au_cpup_attr_changeable(struct inode *inode);
6255 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6256 +void au_cpup_attr_all(struct inode *inode, int force);
6258 +/* ---------------------------------------------------------------------- */
6260 +struct au_cp_generic {
6261 + struct dentry *dentry;
6262 + aufs_bindex_t bdst, bsrc;
6264 + struct au_pin *pin;
6265 + unsigned int flags;
6269 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6270 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6272 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6273 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6275 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6277 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6278 + the branch is marked as RO */
6280 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6281 +#undef AuCpup_HOPEN
6282 +#define AuCpup_HOPEN 0
6285 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6286 +#define au_fset_cpup(flags, name) \
6287 + do { (flags) |= AuCpup_##name; } while (0)
6288 +#define au_fclr_cpup(flags, name) \
6289 + do { (flags) &= ~AuCpup_##name; } while (0)
6291 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6292 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6293 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6294 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6296 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6297 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6298 + struct au_pin *pin,
6299 + struct dentry *h_parent, void *arg),
6301 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6302 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6304 +/* ---------------------------------------------------------------------- */
6306 +/* keep timestamps when copyup */
6308 + struct dentry *dt_dentry;
6309 + struct path dt_h_path;
6310 + struct timespec64 dt_atime, dt_mtime;
6312 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6313 + struct path *h_path);
6314 +void au_dtime_revert(struct au_dtime *dt);
6316 +#endif /* __KERNEL__ */
6317 +#endif /* __AUFS_CPUP_H__ */
6318 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6319 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6320 +++ linux/fs/aufs/dbgaufs.c 2022-10-26 22:30:38.462648858 +0200
6322 +// SPDX-License-Identifier: GPL-2.0
6324 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6326 + * This program, aufs is free software; you can redistribute it and/or modify
6327 + * it under the terms of the GNU General Public License as published by
6328 + * the Free Software Foundation; either version 2 of the License, or
6329 + * (at your option) any later version.
6331 + * This program is distributed in the hope that it will be useful,
6332 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6333 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6334 + * GNU General Public License for more details.
6336 + * You should have received a copy of the GNU General Public License
6337 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6341 + * debugfs interface
6344 +#include <linux/debugfs.h>
6347 +#ifndef CONFIG_SYSFS
6348 +#error DEBUG_FS depends upon SYSFS
6351 +static struct dentry *dbgaufs;
6352 +static const mode_t dbgaufs_mode = 0444;
6354 +/* 20 is max digits length of ulong 64 */
6355 +struct dbgaufs_arg {
6361 + * common function for all XINO files
6363 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6364 + struct file *file)
6368 + p = file->private_data;
6370 + /* this is struct dbgaufs_arg */
6371 + AuDebugOn(!au_kfree_sz_test(p));
6372 + au_kfree_do_rcu(p);
6377 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6382 + struct dbgaufs_arg *p;
6385 + p = kmalloc(sizeof(*p), GFP_NOFS);
6391 + file->private_data = p;
6395 + err = vfsub_getattr(&xf->f_path, &st);
6399 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6400 + cnt, st.blocks, st.blksize,
6401 + (long long)st.size);
6403 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6404 + st.blocks, st.blksize,
6405 + (long long)st.size);
6406 + AuDebugOn(p->n >= sizeof(p->a));
6408 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6416 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6417 + size_t count, loff_t *ppos)
6419 + struct dbgaufs_arg *p;
6421 + p = file->private_data;
6422 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6425 +/* ---------------------------------------------------------------------- */
6427 +struct dbgaufs_plink_arg {
6432 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6433 + struct file *file)
6435 + free_page((unsigned long)file->private_data);
6439 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6441 + int err, i, limit;
6442 + unsigned long n, sum;
6443 + struct dbgaufs_plink_arg *p;
6444 + struct au_sbinfo *sbinfo;
6445 + struct super_block *sb;
6446 + struct hlist_bl_head *hbl;
6449 + p = (void *)get_zeroed_page(GFP_NOFS);
6454 + sbinfo = inode->i_private;
6455 + sb = sbinfo->si_sb;
6456 + si_noflush_read_lock(sb);
6457 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6458 + limit = PAGE_SIZE - sizeof(p->n);
6460 + /* the number of buckets */
6461 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6466 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6468 + n = au_hbl_count(hbl);
6471 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6474 + if (unlikely(limit <= 0))
6477 + p->a[p->n - 1] = '\n';
6479 + /* the sum of plinks */
6480 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6483 + if (unlikely(limit <= 0))
6486 +#define str "1\n0\n0\n"
6487 + p->n = sizeof(str) - 1;
6488 + strcpy(p->a, str);
6491 + si_read_unlock(sb);
6494 + file->private_data = p;
6495 + goto out; /* success */
6498 + free_page((unsigned long)p);
6503 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6504 + size_t count, loff_t *ppos)
6506 + struct dbgaufs_plink_arg *p;
6508 + p = file->private_data;
6509 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6512 +static const struct file_operations dbgaufs_plink_fop = {
6513 + .owner = THIS_MODULE,
6514 + .open = dbgaufs_plink_open,
6515 + .release = dbgaufs_plink_release,
6516 + .read = dbgaufs_plink_read
6519 +/* ---------------------------------------------------------------------- */
6521 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6524 + struct au_sbinfo *sbinfo;
6525 + struct super_block *sb;
6527 + sbinfo = inode->i_private;
6528 + sb = sbinfo->si_sb;
6529 + si_noflush_read_lock(sb);
6530 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6531 + si_read_unlock(sb);
6535 +static const struct file_operations dbgaufs_xib_fop = {
6536 + .owner = THIS_MODULE,
6537 + .open = dbgaufs_xib_open,
6538 + .release = dbgaufs_xi_release,
6539 + .read = dbgaufs_xi_read
6542 +/* ---------------------------------------------------------------------- */
6544 +#define DbgaufsXi_PREFIX "xi"
6546 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6550 + aufs_bindex_t bindex;
6551 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6552 + struct au_sbinfo *sbinfo;
6553 + struct super_block *sb;
6554 + struct au_xino *xi;
6556 + struct qstr *name;
6557 + struct au_branch *br;
6560 + name = &file->f_path.dentry->d_name;
6561 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6562 + || memcmp(name->name, DbgaufsXi_PREFIX,
6563 + sizeof(DbgaufsXi_PREFIX) - 1)))
6566 + AuDebugOn(name->len >= sizeof(a));
6567 + memcpy(a, name->name, name->len);
6568 + a[name->len] = '\0';
6569 + p = strchr(a, '-');
6572 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6573 + if (unlikely(err))
6578 + err = kstrtol(p + 1, 10, &l);
6579 + if (unlikely(err))
6585 + sbinfo = inode->i_private;
6586 + sb = sbinfo->si_sb;
6587 + si_noflush_read_lock(sb);
6588 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6590 + br = au_sbr(sb, bindex);
6592 + if (unlikely(idx >= xi->xi_nfile))
6594 + xf = au_xino_file(xi, idx);
6596 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6597 + au_xino_count(br));
6600 + si_read_unlock(sb);
6606 +static const struct file_operations dbgaufs_xino_fop = {
6607 + .owner = THIS_MODULE,
6608 + .open = dbgaufs_xino_open,
6609 + .release = dbgaufs_xi_release,
6610 + .read = dbgaufs_xi_read
6613 +void dbgaufs_xino_del(struct au_branch *br)
6615 + struct dentry *dbgaufs;
6617 + dbgaufs = br->br_dbgaufs;
6621 + br->br_dbgaufs = NULL;
6622 + /* debugfs acquires the parent i_mutex */
6624 + debugfs_remove(dbgaufs);
6628 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6630 + aufs_bindex_t bbot;
6631 + struct au_branch *br;
6633 + if (!au_sbi(sb)->si_dbgaufs)
6636 + bbot = au_sbbot(sb);
6637 + for (; bindex <= bbot; bindex++) {
6638 + br = au_sbr(sb, bindex);
6639 + dbgaufs_xino_del(br);
6643 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6644 + unsigned int idx, struct dentry *parent,
6645 + struct au_sbinfo *sbinfo)
6647 + struct au_branch *br;
6649 + /* "xi" bindex(5) "-" idx(2) NULL */
6650 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6653 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6655 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6657 + br = au_sbr(sb, bindex);
6658 + if (br->br_dbgaufs) {
6659 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6661 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6662 + /* debugfs acquires the parent i_mutex */
6664 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6668 + pr_warn("failed renaming %pd/%s, ignored.\n",
6673 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6674 + sbinfo, &dbgaufs_xino_fop);
6676 + if (unlikely(!br->br_dbgaufs))
6677 + pr_warn("failed creating %pd/%s, ignored.\n",
6682 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6683 + struct dentry *parent, struct au_sbinfo *sbinfo)
6685 + struct au_branch *br;
6686 + struct au_xino *xi;
6689 + br = au_sbr(sb, bindex);
6691 + for (u = 0; u < xi->xi_nfile; u++)
6692 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6695 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6697 + struct au_sbinfo *sbinfo;
6698 + struct dentry *parent;
6699 + aufs_bindex_t bbot;
6701 + if (!au_opt_test(au_mntflags(sb), XINO))
6704 + sbinfo = au_sbi(sb);
6705 + parent = sbinfo->si_dbgaufs;
6709 + bbot = au_sbbot(sb);
6711 + for (; bindex <= bbot; bindex++)
6712 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6714 + for (; bbot >= bindex; bbot--)
6715 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6718 +/* ---------------------------------------------------------------------- */
6720 +#ifdef CONFIG_AUFS_EXPORT
6721 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6724 + struct au_sbinfo *sbinfo;
6725 + struct super_block *sb;
6727 + sbinfo = inode->i_private;
6728 + sb = sbinfo->si_sb;
6729 + si_noflush_read_lock(sb);
6730 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6731 + si_read_unlock(sb);
6735 +static const struct file_operations dbgaufs_xigen_fop = {
6736 + .owner = THIS_MODULE,
6737 + .open = dbgaufs_xigen_open,
6738 + .release = dbgaufs_xi_release,
6739 + .read = dbgaufs_xi_read
6742 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6747 + * This function is a dynamic '__init' function actually,
6748 + * so the tiny check for si_rwsem is unnecessary.
6750 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6753 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6754 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6755 + &dbgaufs_xigen_fop);
6756 + if (sbinfo->si_dbgaufs_xigen)
6762 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6766 +#endif /* CONFIG_AUFS_EXPORT */
6768 +/* ---------------------------------------------------------------------- */
6770 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6773 + * This function is a dynamic '__fin' function actually,
6774 + * so the tiny check for si_rwsem is unnecessary.
6776 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6778 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6779 + sbinfo->si_dbgaufs = NULL;
6782 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6785 + char name[SysaufsSiNameLen];
6788 + * This function is a dynamic '__init' function actually,
6789 + * so the tiny check for si_rwsem is unnecessary.
6791 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6795 + AuErr1("/debug/aufs is uninitialized\n");
6800 + sysaufs_name(sbinfo, name);
6801 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6802 + if (unlikely(!sbinfo->si_dbgaufs))
6805 + /* regardless plink/noplink option */
6806 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6807 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6808 + &dbgaufs_plink_fop);
6809 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6812 + /* regardless xino/noxino option */
6813 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6814 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6815 + &dbgaufs_xib_fop);
6816 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6819 + err = dbgaufs_xigen_init(sbinfo);
6821 + goto out; /* success */
6824 + dbgaufs_si_fin(sbinfo);
6826 + if (unlikely(err))
6827 + pr_err("debugfs/aufs failed\n");
6831 +/* ---------------------------------------------------------------------- */
6833 +void dbgaufs_fin(void)
6835 + debugfs_remove(dbgaufs);
6838 +int __init dbgaufs_init(void)
6843 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6848 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6849 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6850 +++ linux/fs/aufs/dbgaufs.h 2022-10-26 22:30:38.462648858 +0200
6852 +/* SPDX-License-Identifier: GPL-2.0 */
6854 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6856 + * This program, aufs is free software; you can redistribute it and/or modify
6857 + * it under the terms of the GNU General Public License as published by
6858 + * the Free Software Foundation; either version 2 of the License, or
6859 + * (at your option) any later version.
6861 + * This program is distributed in the hope that it will be useful,
6862 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6863 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6864 + * GNU General Public License for more details.
6866 + * You should have received a copy of the GNU General Public License
6867 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6871 + * debugfs interface
6874 +#ifndef __DBGAUFS_H__
6875 +#define __DBGAUFS_H__
6879 +struct super_block;
6883 +#ifdef CONFIG_DEBUG_FS
6885 +void dbgaufs_xino_del(struct au_branch *br);
6886 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6887 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6888 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6889 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6890 +void dbgaufs_fin(void);
6891 +int __init dbgaufs_init(void);
6893 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6894 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6895 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6897 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6898 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6899 +AuStubVoid(dbgaufs_fin, void)
6900 +AuStubInt0(__init dbgaufs_init, void)
6901 +#endif /* CONFIG_DEBUG_FS */
6903 +#endif /* __KERNEL__ */
6904 +#endif /* __DBGAUFS_H__ */
6905 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6906 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6907 +++ linux/fs/aufs/dcsub.c 2022-10-26 22:30:38.462648858 +0200
6909 +// SPDX-License-Identifier: GPL-2.0
6911 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6913 + * This program, aufs is free software; you can redistribute it and/or modify
6914 + * it under the terms of the GNU General Public License as published by
6915 + * the Free Software Foundation; either version 2 of the License, or
6916 + * (at your option) any later version.
6918 + * This program is distributed in the hope that it will be useful,
6919 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6920 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6921 + * GNU General Public License for more details.
6923 + * You should have received a copy of the GNU General Public License
6924 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6928 + * sub-routines for dentry cache
6933 +static void au_dpage_free(struct au_dpage *dpage)
6936 + struct dentry **p;
6938 + p = dpage->dentries;
6939 + for (i = 0; i < dpage->ndentry; i++)
6941 + free_page((unsigned long)dpage->dentries);
6944 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6950 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6951 + if (unlikely(!dpages->dpages))
6954 + p = (void *)__get_free_page(gfp);
6958 + dpages->dpages[0].ndentry = 0;
6959 + dpages->dpages[0].dentries = p;
6960 + dpages->ndpage = 1;
6961 + return 0; /* success */
6964 + au_kfree_try_rcu(dpages->dpages);
6969 +void au_dpages_free(struct au_dcsub_pages *dpages)
6972 + struct au_dpage *p;
6974 + p = dpages->dpages;
6975 + for (i = 0; i < dpages->ndpage; i++)
6976 + au_dpage_free(p++);
6977 + au_kfree_try_rcu(dpages->dpages);
6980 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6981 + struct dentry *dentry, gfp_t gfp)
6984 + struct au_dpage *dpage;
6987 + dpage = dpages->dpages + dpages->ndpage - 1;
6988 + sz = PAGE_SIZE / sizeof(dentry);
6989 + if (unlikely(dpage->ndentry >= sz)) {
6990 + AuLabel(new dpage);
6992 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6993 + p = au_kzrealloc(dpages->dpages, sz,
6994 + sz + sizeof(*dpages->dpages), gfp,
6999 + dpages->dpages = p;
7000 + dpage = dpages->dpages + dpages->ndpage;
7001 + p = (void *)__get_free_page(gfp);
7005 + dpage->ndentry = 0;
7006 + dpage->dentries = p;
7010 + AuDebugOn(au_dcount(dentry) <= 0);
7011 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7012 + return 0; /* success */
7018 +/* todo: BAD approach */
7019 +/* copied from linux/fs/dcache.c */
7027 +extern void d_walk(struct dentry *parent, void *data,
7028 + enum d_walk_ret (*enter)(void *, struct dentry *));
7030 +struct ac_dpages_arg {
7032 + struct au_dcsub_pages *dpages;
7033 + struct super_block *sb;
7034 + au_dpages_test test;
7038 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7040 + enum d_walk_ret ret;
7041 + struct ac_dpages_arg *arg = _arg;
7043 + ret = D_WALK_CONTINUE;
7044 + if (dentry->d_sb == arg->sb
7045 + && !IS_ROOT(dentry)
7046 + && au_dcount(dentry) > 0
7048 + && (!arg->test || arg->test(dentry, arg->arg))) {
7049 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7050 + if (unlikely(arg->err))
7051 + ret = D_WALK_QUIT;
7057 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7058 + au_dpages_test test, void *arg)
7060 + struct ac_dpages_arg args = {
7068 + d_walk(root, &args, au_call_dpages_append);
7073 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7074 + int do_include, au_dpages_test test, void *arg)
7079 + write_seqlock(&rename_lock);
7080 + spin_lock(&dentry->d_lock);
7082 + && au_dcount(dentry) > 0
7083 + && (!test || test(dentry, arg)))
7084 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7085 + spin_unlock(&dentry->d_lock);
7086 + if (unlikely(err))
7090 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7093 + while (!IS_ROOT(dentry)) {
7094 + dentry = dentry->d_parent; /* rename_lock is locked */
7095 + spin_lock(&dentry->d_lock);
7096 + if (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))
7105 + write_sequnlock(&rename_lock);
7109 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7111 + return au_di(dentry) && dentry->d_sb == arg;
7114 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7115 + struct dentry *dentry, int do_include)
7117 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7118 + au_dcsub_dpages_aufs, dentry->d_sb);
7121 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7123 + struct path path[2] = {
7132 + return path_is_under(path + 0, path + 1);
7134 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7135 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7136 +++ linux/fs/aufs/dcsub.h 2022-10-26 22:30:38.462648858 +0200
7138 +/* SPDX-License-Identifier: GPL-2.0 */
7140 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7142 + * This program, aufs is free software; you can redistribute it and/or modify
7143 + * it under the terms of the GNU General Public License as published by
7144 + * the Free Software Foundation; either version 2 of the License, or
7145 + * (at your option) any later version.
7147 + * This program is distributed in the hope that it will be useful,
7148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7150 + * GNU General Public License for more details.
7152 + * You should have received a copy of the GNU General Public License
7153 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7157 + * sub-routines for dentry cache
7160 +#ifndef __AUFS_DCSUB_H__
7161 +#define __AUFS_DCSUB_H__
7165 +#include <linux/dcache.h>
7166 +#include <linux/fs.h>
7170 + struct dentry **dentries;
7173 +struct au_dcsub_pages {
7175 + struct au_dpage *dpages;
7178 +/* ---------------------------------------------------------------------- */
7181 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7182 +void au_dpages_free(struct au_dcsub_pages *dpages);
7183 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7184 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7185 + au_dpages_test test, void *arg);
7186 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7187 + int do_include, au_dpages_test test, void *arg);
7188 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7189 + struct dentry *dentry, int do_include);
7190 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7192 +/* ---------------------------------------------------------------------- */
7195 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7196 + * include/linux/dcache.h. Try them (in the future).
7199 +static inline int au_d_hashed_positive(struct dentry *d)
7202 + struct inode *inode = d_inode(d);
7205 + if (unlikely(d_unhashed(d)
7206 + || d_is_negative(d)
7207 + || !inode->i_nlink))
7212 +static inline int au_d_linkable(struct dentry *d)
7215 + struct inode *inode = d_inode(d);
7217 + err = au_d_hashed_positive(d);
7219 + && d_is_positive(d)
7220 + && (inode->i_state & I_LINKABLE))
7225 +static inline int au_d_alive(struct dentry *d)
7228 + struct inode *inode;
7232 + err = au_d_hashed_positive(d);
7234 + inode = d_inode(d);
7235 + if (unlikely(d_unlinked(d)
7236 + || d_is_negative(d)
7237 + || !inode->i_nlink))
7243 +static inline int au_alive_dir(struct dentry *d)
7247 + err = au_d_alive(d);
7248 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7253 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7255 + return a->len == b->len
7256 + && !memcmp(a->name, b->name, a->len);
7261 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7263 + * the type of d_lockref.count became int, but the inlined function d_count()
7264 + * still returns unsigned int.
7265 + * I don't know why. Maybe it is for every d_count() users?
7266 + * Anyway au_dcount() lives on.
7268 +static inline int au_dcount(struct dentry *d)
7270 + return (int)d_count(d);
7273 +#endif /* __KERNEL__ */
7274 +#endif /* __AUFS_DCSUB_H__ */
7275 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7276 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7277 +++ linux/fs/aufs/debug.c 2022-10-26 22:30:38.462648858 +0200
7279 +// SPDX-License-Identifier: GPL-2.0
7281 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7283 + * This program, aufs is free software; you can redistribute it and/or modify
7284 + * it under the terms of the GNU General Public License as published by
7285 + * the Free Software Foundation; either version 2 of the License, or
7286 + * (at your option) any later version.
7288 + * This program is distributed in the hope that it will be useful,
7289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7291 + * GNU General Public License for more details.
7293 + * You should have received a copy of the GNU General Public License
7294 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7298 + * debug print functions
7301 +#include <linux/iversion.h>
7304 +/* Returns 0, or -errno. arg is in kp->arg. */
7305 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7309 + err = kstrtoint(val, 0, &n);
7319 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7320 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7325 + return sprintf(buffer, "%d", atomic_read(a));
7328 +static const struct kernel_param_ops param_ops_atomic_t = {
7329 + .set = param_atomic_t_set,
7330 + .get = param_atomic_t_get
7331 + /* void (*free)(void *arg) */
7334 +atomic_t aufs_debug = ATOMIC_INIT(0);
7335 +MODULE_PARM_DESC(debug, "debug print");
7336 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7338 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7339 +char *au_plevel = KERN_DEBUG;
7340 +#define dpri(fmt, ...) do { \
7342 + && strcmp(au_plevel, KERN_DEBUG)) \
7343 + || au_debug_test()) \
7344 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7347 +/* ---------------------------------------------------------------------- */
7349 +void au_dpri_whlist(struct au_nhash *whlist)
7351 + unsigned long ul, n;
7352 + struct hlist_head *head;
7353 + struct au_vdir_wh *pos;
7355 + n = whlist->nh_num;
7356 + head = whlist->nh_head;
7357 + for (ul = 0; ul < n; ul++) {
7358 + hlist_for_each_entry(pos, head, wh_hash)
7359 + dpri("b%d, %.*s, %d\n",
7361 + pos->wh_str.len, pos->wh_str.name,
7367 +void au_dpri_vdir(struct au_vdir *vdir)
7370 + union au_vdir_deblk_p p;
7373 + if (!vdir || IS_ERR(vdir)) {
7374 + dpri("err %ld\n", PTR_ERR(vdir));
7378 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7379 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7380 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7381 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7382 + p.deblk = vdir->vd_deblk[ul];
7384 + dpri("[%lu]: %p\n", ul, o);
7388 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7389 + struct dentry *wh)
7394 + if (!inode || IS_ERR(inode)) {
7395 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7399 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7400 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7401 + && sizeof(inode->i_blocks) != sizeof(u64));
7403 + n = (void *)wh->d_name.name;
7404 + l = wh->d_name.len;
7407 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7408 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7410 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7411 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7412 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7413 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7414 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7415 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7416 + inode->i_generation,
7417 + l ? ", wh " : "", l, n);
7421 +void au_dpri_inode(struct inode *inode)
7423 + struct au_iinfo *iinfo;
7424 + struct au_hinode *hi;
7425 + aufs_bindex_t bindex;
7428 + err = do_pri_inode(-1, inode, -1, NULL);
7429 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7432 + iinfo = au_ii(inode);
7433 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7434 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7435 + if (iinfo->ii_btop < 0)
7438 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7439 + hi = au_hinode(iinfo, bindex);
7441 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7445 +void au_dpri_dalias(struct inode *inode)
7449 + spin_lock(&inode->i_lock);
7450 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7451 + au_dpri_dentry(d);
7452 + spin_unlock(&inode->i_lock);
7455 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7457 + struct dentry *wh = NULL;
7459 + struct inode *inode;
7460 + struct au_iinfo *iinfo;
7461 + struct au_hinode *hi;
7463 + if (!dentry || IS_ERR(dentry)) {
7464 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7467 + /* do not call dget_parent() here */
7468 + /* note: access d_xxx without d_lock */
7469 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7470 + bindex, dentry, dentry,
7471 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7472 + au_dcount(dentry), dentry->d_flags,
7473 + d_unhashed(dentry) ? "un" : "");
7476 + if (d_is_positive(dentry))
7477 + inode = d_inode(dentry);
7479 + && au_test_aufs(dentry->d_sb)
7481 + && !au_is_bad_inode(inode)) {
7482 + iinfo = au_ii(inode);
7483 + hi = au_hinode(iinfo, bindex);
7485 + wh = hi->hi_whdentry;
7487 + do_pri_inode(bindex, inode, hn, wh);
7491 +void au_dpri_dentry(struct dentry *dentry)
7493 + struct au_dinfo *dinfo;
7494 + aufs_bindex_t bindex;
7497 + err = do_pri_dentry(-1, dentry);
7498 + if (err || !au_test_aufs(dentry->d_sb))
7501 + dinfo = au_di(dentry);
7504 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7505 + dinfo->di_btop, dinfo->di_bbot,
7506 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7507 + dinfo->di_tmpfile);
7508 + if (dinfo->di_btop < 0)
7510 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7511 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7514 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7518 + if (!file || IS_ERR(file)) {
7519 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7524 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7525 + && au_test_aufs(file->f_path.dentry->d_sb)
7527 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7528 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7529 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7530 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7531 + file->f_version, file->f_pos, a);
7532 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7533 + do_pri_dentry(bindex, file->f_path.dentry);
7537 +void au_dpri_file(struct file *file)
7539 + struct au_finfo *finfo;
7540 + struct au_fidir *fidir;
7541 + struct au_hfile *hfile;
7542 + aufs_bindex_t bindex;
7545 + err = do_pri_file(-1, file);
7547 + || IS_ERR_OR_NULL(file->f_path.dentry)
7548 + || !au_test_aufs(file->f_path.dentry->d_sb))
7551 + finfo = au_fi(file);
7554 + if (finfo->fi_btop < 0)
7556 + fidir = finfo->fi_hdir;
7558 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7560 + for (bindex = finfo->fi_btop;
7561 + bindex >= 0 && bindex <= fidir->fd_bbot;
7563 + hfile = fidir->fd_hfile + bindex;
7564 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7568 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7570 + struct vfsmount *mnt;
7571 + struct super_block *sb;
7573 + if (!br || IS_ERR(br))
7575 + mnt = au_br_mnt(br);
7576 + if (!mnt || IS_ERR(mnt))
7579 + if (!sb || IS_ERR(sb))
7582 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7583 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7585 + bindex, br->br_perm, br->br_id, br->br_wbr,
7586 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7587 + sb->s_flags, sb->s_count,
7588 + atomic_read(&sb->s_active),
7589 + !!au_xino_file(br->br_xino, /*idx*/-1));
7593 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7597 +void au_dpri_sb(struct super_block *sb)
7599 + struct au_sbinfo *sbinfo;
7600 + aufs_bindex_t bindex;
7602 + /* to reduce stack size */
7604 + struct vfsmount mnt;
7605 + struct au_branch fake;
7608 + /* this function can be called from magic sysrq */
7609 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7610 + if (unlikely(!a)) {
7611 + dpri("no memory\n");
7615 + a->mnt.mnt_sb = sb;
7616 + a->fake.br_path.mnt = &a->mnt;
7617 + err = do_pri_br(-1, &a->fake);
7619 + dpri("dev 0x%x\n", sb->s_dev);
7620 + if (err || !au_test_aufs(sb))
7623 + sbinfo = au_sbi(sb);
7626 + dpri("nw %d, gen %u, kobj %d\n",
7627 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7628 + kref_read(&sbinfo->si_kobj.kref));
7629 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7630 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7633 +/* ---------------------------------------------------------------------- */
7635 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7637 + struct inode *h_inode, *inode = d_inode(dentry);
7638 + struct dentry *h_dentry;
7639 + aufs_bindex_t bindex, bbot, bi;
7641 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7644 + bbot = au_dbbot(dentry);
7645 + bi = au_ibbot(inode);
7648 + bindex = au_dbtop(dentry);
7649 + bi = au_ibtop(inode);
7653 + for (; bindex <= bbot; bindex++) {
7654 + h_dentry = au_h_dptr(dentry, bindex);
7657 + h_inode = au_h_iptr(inode, bindex);
7658 + if (unlikely(h_inode != d_inode(h_dentry))) {
7660 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7661 + AuDbgDentry(dentry);
7662 + AuDbgInode(inode);
7664 + if (au_test_fuse(h_inode->i_sb))
7672 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7675 + struct au_dcsub_pages dpages;
7676 + struct au_dpage *dpage;
7677 + struct dentry **dentries;
7679 + err = au_dpages_init(&dpages, GFP_NOFS);
7681 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7683 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7684 + dpage = dpages.dpages + i;
7685 + dentries = dpage->dentries;
7686 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7687 + AuDebugOn(au_digen_test(dentries[j], sigen));
7689 + au_dpages_free(&dpages);
7692 +void au_dbg_verify_kthread(void)
7694 + if (au_wkq_test()) {
7697 + * It may be recursive, but udba=notify between two aufs mounts,
7698 + * where a single ro branch is shared, is not a problem.
7704 +/* ---------------------------------------------------------------------- */
7706 +int __init au_debug_init(void)
7708 + aufs_bindex_t bindex;
7709 + struct au_vdir_destr destr;
7712 + AuDebugOn(bindex >= 0);
7715 + AuDebugOn(destr.len < NAME_MAX);
7717 +#ifdef CONFIG_4KSTACKS
7718 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7723 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7724 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7725 +++ linux/fs/aufs/debug.h 2022-10-26 22:30:38.462648858 +0200
7727 +/* SPDX-License-Identifier: GPL-2.0 */
7729 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7731 + * This program, aufs is free software; you can redistribute it and/or modify
7732 + * it under the terms of the GNU General Public License as published by
7733 + * the Free Software Foundation; either version 2 of the License, or
7734 + * (at your option) any later version.
7736 + * This program is distributed in the hope that it will be useful,
7737 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7738 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7739 + * GNU General Public License for more details.
7741 + * You should have received a copy of the GNU General Public License
7742 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7746 + * debug print functions
7749 +#ifndef __AUFS_DEBUG_H__
7750 +#define __AUFS_DEBUG_H__
7754 +#include <linux/atomic.h>
7755 +#include <linux/module.h>
7756 +#include <linux/kallsyms.h>
7757 +#include <linux/sysrq.h>
7759 +#ifdef CONFIG_AUFS_DEBUG
7760 +#define AuDebugOn(a) BUG_ON(a)
7762 +/* module parameter */
7763 +extern atomic_t aufs_debug;
7764 +static inline void au_debug_on(void)
7766 + atomic_inc(&aufs_debug);
7768 +static inline void au_debug_off(void)
7770 + atomic_dec_if_positive(&aufs_debug);
7773 +static inline int au_debug_test(void)
7775 + return atomic_read(&aufs_debug) > 0;
7778 +#define AuDebugOn(a) do {} while (0)
7779 +AuStubVoid(au_debug_on, void)
7780 +AuStubVoid(au_debug_off, void)
7781 +AuStubInt0(au_debug_test, void)
7782 +#endif /* CONFIG_AUFS_DEBUG */
7784 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7786 +/* ---------------------------------------------------------------------- */
7790 +#define AuDbg(fmt, ...) do { \
7791 + if (au_debug_test()) \
7792 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7794 +#define AuLabel(l) AuDbg(#l "\n")
7795 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7796 +#define AuWarn1(fmt, ...) do { \
7797 + static unsigned char _c; \
7799 + pr_warn(fmt, ##__VA_ARGS__); \
7802 +#define AuErr1(fmt, ...) do { \
7803 + static unsigned char _c; \
7805 + pr_err(fmt, ##__VA_ARGS__); \
7808 +#define AuIOErr1(fmt, ...) do { \
7809 + static unsigned char _c; \
7811 + AuIOErr(fmt, ##__VA_ARGS__); \
7814 +#define AuUnsupportMsg "This operation is not supported." \
7815 + " Please report this application to aufs-users ML."
7816 +#define AuUnsupport(fmt, ...) do { \
7817 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7821 +#define AuTraceErr(e) do { \
7822 + if (unlikely((e) < 0)) \
7823 + AuDbg("err %d\n", (int)(e)); \
7826 +#define AuTraceErrPtr(p) do { \
7828 + AuDbg("err %ld\n", PTR_ERR(p)); \
7831 +/* dirty macros for debug print, use with "%.*s" and caution */
7832 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7834 +/* ---------------------------------------------------------------------- */
7837 +#ifdef CONFIG_AUFS_DEBUG
7838 +extern struct mutex au_dbg_mtx;
7839 +extern char *au_plevel;
7841 +void au_dpri_whlist(struct au_nhash *whlist);
7843 +void au_dpri_vdir(struct au_vdir *vdir);
7845 +void au_dpri_inode(struct inode *inode);
7846 +void au_dpri_dalias(struct inode *inode);
7847 +void au_dpri_dentry(struct dentry *dentry);
7849 +void au_dpri_file(struct file *filp);
7850 +struct super_block;
7851 +void au_dpri_sb(struct super_block *sb);
7853 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7854 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7855 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7856 +void au_dbg_verify_kthread(void);
7858 +int __init au_debug_init(void);
7860 +#define AuDbgWhlist(w) do { \
7861 + mutex_lock(&au_dbg_mtx); \
7863 + au_dpri_whlist(w); \
7864 + mutex_unlock(&au_dbg_mtx); \
7867 +#define AuDbgVdir(v) do { \
7868 + mutex_lock(&au_dbg_mtx); \
7870 + au_dpri_vdir(v); \
7871 + mutex_unlock(&au_dbg_mtx); \
7874 +#define AuDbgInode(i) do { \
7875 + mutex_lock(&au_dbg_mtx); \
7877 + au_dpri_inode(i); \
7878 + mutex_unlock(&au_dbg_mtx); \
7881 +#define AuDbgDAlias(i) do { \
7882 + mutex_lock(&au_dbg_mtx); \
7884 + au_dpri_dalias(i); \
7885 + mutex_unlock(&au_dbg_mtx); \
7888 +#define AuDbgDentry(d) do { \
7889 + mutex_lock(&au_dbg_mtx); \
7891 + au_dpri_dentry(d); \
7892 + mutex_unlock(&au_dbg_mtx); \
7895 +#define AuDbgFile(f) do { \
7896 + mutex_lock(&au_dbg_mtx); \
7898 + au_dpri_file(f); \
7899 + mutex_unlock(&au_dbg_mtx); \
7902 +#define AuDbgSb(sb) do { \
7903 + mutex_lock(&au_dbg_mtx); \
7904 + AuDbg(#sb "\n"); \
7906 + mutex_unlock(&au_dbg_mtx); \
7909 +#define AuDbgSym(addr) do { \
7910 + char sym[KSYM_SYMBOL_LEN]; \
7911 + sprint_symbol(sym, (unsigned long)addr); \
7912 + AuDbg("%s\n", sym); \
7915 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7916 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7917 +AuStubVoid(au_dbg_verify_kthread, void)
7918 +AuStubInt0(__init au_debug_init, void)
7920 +#define AuDbgWhlist(w) do {} while (0)
7921 +#define AuDbgVdir(v) do {} while (0)
7922 +#define AuDbgInode(i) do {} while (0)
7923 +#define AuDbgDAlias(i) do {} while (0)
7924 +#define AuDbgDentry(d) do {} while (0)
7925 +#define AuDbgFile(f) do {} while (0)
7926 +#define AuDbgSb(sb) do {} while (0)
7927 +#define AuDbgSym(addr) do {} while (0)
7928 +#endif /* CONFIG_AUFS_DEBUG */
7930 +/* ---------------------------------------------------------------------- */
7932 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7933 +int __init au_sysrq_init(void);
7934 +void au_sysrq_fin(void);
7936 +#ifdef CONFIG_HW_CONSOLE
7937 +#define au_dbg_blocked() do { \
7939 + handle_sysrq('w'); \
7942 +AuStubVoid(au_dbg_blocked, void)
7946 +AuStubInt0(__init au_sysrq_init, void)
7947 +AuStubVoid(au_sysrq_fin, void)
7948 +AuStubVoid(au_dbg_blocked, void)
7949 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7951 +#endif /* __KERNEL__ */
7952 +#endif /* __AUFS_DEBUG_H__ */
7953 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7954 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7955 +++ linux/fs/aufs/dentry.c 2022-10-26 22:30:38.462648858 +0200
7957 +// SPDX-License-Identifier: GPL-2.0
7959 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7961 + * This program, aufs is free software; you can redistribute it and/or modify
7962 + * it under the terms of the GNU General Public License as published by
7963 + * the Free Software Foundation; either version 2 of the License, or
7964 + * (at your option) any later version.
7966 + * This program is distributed in the hope that it will be useful,
7967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7969 + * GNU General Public License for more details.
7971 + * You should have received a copy of the GNU General Public License
7972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7976 + * lookup and dentry operations
7979 +#include <linux/iversion.h>
7983 + * returns positive/negative dentry, NULL or an error.
7984 + * NULL means whiteout-ed or not-found.
7986 +static struct dentry*
7987 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7988 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7990 + struct dentry *h_dentry;
7991 + struct inode *h_inode;
7992 + struct au_branch *br;
7993 + struct user_namespace *h_userns;
7994 + struct path h_path;
7995 + int wh_found, opq;
7996 + unsigned char wh_able;
7997 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7998 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8002 + br = au_sbr(dentry->d_sb, bindex);
8003 + h_path.dentry = h_parent;
8004 + h_path.mnt = au_br_mnt(br);
8005 + h_userns = au_br_userns(br);
8006 + wh_able = !!au_br_whable(br->br_perm);
8008 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
8010 + h_dentry = ERR_PTR(wh_found);
8013 + if (unlikely(wh_found < 0))
8016 + /* We found a whiteout */
8017 + /* au_set_dbbot(dentry, bindex); */
8018 + au_set_dbwh(dentry, bindex);
8020 + return NULL; /* success */
8024 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8026 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8027 + if (IS_ERR(h_dentry)) {
8028 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8034 + h_inode = d_inode(h_dentry);
8035 + if (d_is_negative(h_dentry)) {
8038 + } else if (wh_found
8039 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8041 + else if (au_ftest_lkup(args->flags, DIRREN)
8043 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8044 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8045 + (unsigned long long)h_inode->i_ino);
8049 + if (au_dbbot(dentry) <= bindex)
8050 + au_set_dbbot(dentry, bindex);
8051 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8052 + au_set_dbtop(dentry, bindex);
8053 + au_set_h_dptr(dentry, bindex, h_dentry);
8055 + if (!d_is_dir(h_dentry)
8057 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8058 + goto out; /* success */
8060 + h_path.dentry = h_dentry;
8061 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8062 + opq = au_diropq_test(h_userns, &h_path);
8063 + inode_unlock_shared(h_inode);
8065 + au_set_dbdiropq(dentry, bindex);
8066 + else if (unlikely(opq < 0)) {
8067 + au_set_h_dptr(dentry, bindex, NULL);
8068 + h_dentry = ERR_PTR(opq);
8079 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8081 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8082 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8088 + * returns the number of lower positive dentries,
8089 + * otherwise an error.
8090 + * can be called at unlinking with @type is zero.
8092 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8093 + unsigned int flags)
8095 + int npositive, err;
8096 + aufs_bindex_t bindex, btail, bdiropq;
8097 + unsigned char isdir, dirperm1, dirren;
8098 + struct au_do_lookup_args args = {
8100 + .name = &dentry->d_name
8102 + struct dentry *parent;
8103 + struct super_block *sb;
8105 + sb = dentry->d_sb;
8106 + err = au_test_shwh(sb, args.name);
8107 + if (unlikely(err))
8110 + err = au_wh_name_alloc(&args.whname, args.name);
8111 + if (unlikely(err))
8114 + isdir = !!d_is_dir(dentry);
8115 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8116 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8118 + au_fset_lkup(args.flags, DIRREN);
8121 + parent = dget_parent(dentry);
8122 + btail = au_dbtaildir(parent);
8123 + for (bindex = btop; bindex <= btail; bindex++) {
8124 + struct dentry *h_parent, *h_dentry;
8125 + struct inode *h_inode, *h_dir;
8126 + struct au_branch *br;
8128 + h_dentry = au_h_dptr(dentry, bindex);
8130 + if (d_is_positive(h_dentry))
8134 + h_parent = au_h_dptr(parent, bindex);
8135 + if (!h_parent || !d_is_dir(h_parent))
8139 + /* if the inum matches, then use the prepared name */
8140 + err = au_dr_lkup_name(&args, bindex);
8141 + if (unlikely(err))
8145 + h_dir = d_inode(h_parent);
8146 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8147 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8148 + inode_unlock_shared(h_dir);
8149 + err = PTR_ERR(h_dentry);
8150 + if (IS_ERR(h_dentry))
8153 + au_fclr_lkup(args.flags, ALLOW_NEG);
8155 + au_fset_lkup(args.flags, IGNORE_PERM);
8157 + if (au_dbwh(dentry) == bindex)
8161 + if (d_is_negative(h_dentry))
8163 + h_inode = d_inode(h_dentry);
8166 + args.type = h_inode->i_mode & S_IFMT;
8167 + if (args.type != S_IFDIR)
8170 + /* the type of lower may be different */
8171 + bdiropq = au_dbdiropq(dentry);
8172 + if (bdiropq >= 0 && bdiropq <= bindex)
8175 + br = au_sbr(sb, bindex);
8177 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8178 + /*add_ent*/NULL)) {
8179 + /* prepare next name to lookup */
8180 + err = au_dr_lkup(&args, dentry, bindex);
8181 + if (unlikely(err))
8187 + AuLabel(positive);
8188 + au_update_dbtop(dentry);
8191 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8192 + && au_dbtop(dentry) < 0)) {
8194 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8200 + au_kfree_try_rcu(args.whname.name);
8202 + au_dr_lkup_fin(&args);
8207 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8208 + struct path *ppath)
8210 + struct dentry *dentry;
8213 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8214 + dentry = vfsub_lkup_one(name, ppath);
8216 + struct vfsub_lkup_one_args args = {
8222 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8223 + if (unlikely(wkq_err))
8224 + dentry = ERR_PTR(wkq_err);
8231 + * lookup @dentry on @bindex which should be negative.
8233 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8236 + struct dentry *parent, *h_dentry;
8237 + struct au_branch *br;
8238 + struct user_namespace *h_userns;
8239 + struct path h_ppath;
8241 + parent = dget_parent(dentry);
8242 + br = au_sbr(dentry->d_sb, bindex);
8243 + h_ppath.dentry = au_h_dptr(parent, bindex);
8244 + h_ppath.mnt = au_br_mnt(br);
8245 + h_userns = au_br_userns(br);
8247 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8249 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8250 + err = PTR_ERR(h_dentry);
8251 + if (IS_ERR(h_dentry))
8253 + if (unlikely(d_is_positive(h_dentry))) {
8255 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8261 + if (bindex < au_dbtop(dentry))
8262 + au_set_dbtop(dentry, bindex);
8263 + if (au_dbbot(dentry) < bindex)
8264 + au_set_dbbot(dentry, bindex);
8265 + au_set_h_dptr(dentry, bindex, h_dentry);
8272 +/* ---------------------------------------------------------------------- */
8274 +/* subset of struct inode */
8276 + unsigned long i_ino;
8277 + /* unsigned int i_nlink; */
8283 + blkcnt_t i_blocks;
8288 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8290 + ia->i_ino = h_inode->i_ino;
8291 + /* ia->i_nlink = h_inode->i_nlink; */
8292 + ia->i_uid = h_inode->i_uid;
8293 + ia->i_gid = h_inode->i_gid;
8294 + ia->i_version = inode_query_iversion(h_inode);
8296 + ia->i_size = h_inode->i_size;
8297 + ia->i_blocks = h_inode->i_blocks;
8299 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8302 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8304 + return ia->i_ino != h_inode->i_ino
8305 + /* || ia->i_nlink != h_inode->i_nlink */
8306 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8307 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8308 + || !inode_eq_iversion(h_inode, ia->i_version)
8310 + || ia->i_size != h_inode->i_size
8311 + || ia->i_blocks != h_inode->i_blocks
8313 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8316 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8317 + struct au_branch *br)
8320 + struct au_iattr ia;
8321 + struct inode *h_inode;
8322 + struct dentry *h_d;
8323 + struct super_block *h_sb;
8324 + struct path h_ppath;
8327 + memset(&ia, -1, sizeof(ia));
8328 + h_sb = h_dentry->d_sb;
8330 + if (d_is_positive(h_dentry)) {
8331 + h_inode = d_inode(h_dentry);
8332 + au_iattr_save(&ia, h_inode);
8333 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8334 + /* nfs d_revalidate may return 0 for negative dentry */
8335 + /* fuse d_revalidate always return 0 for negative dentry */
8338 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8339 + h_ppath.dentry = h_parent;
8340 + h_ppath.mnt = au_br_mnt(br);
8341 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8342 + err = PTR_ERR(h_d);
8347 + if (unlikely(h_d != h_dentry
8348 + || d_inode(h_d) != h_inode
8349 + || (h_inode && au_iattr_test(&ia, h_inode))))
8350 + err = au_busy_or_stale();
8358 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8359 + struct dentry *h_parent, struct au_branch *br)
8364 + if (udba == AuOpt_UDBA_REVAL
8365 + && !au_test_fs_remote(h_dentry->d_sb)) {
8367 + err = (d_inode(h_dentry->d_parent) != h_dir);
8368 + } else if (udba != AuOpt_UDBA_NONE)
8369 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8374 +/* ---------------------------------------------------------------------- */
8376 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8379 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8380 + struct au_hdentry tmp, *p, *q;
8381 + struct au_dinfo *dinfo;
8382 + struct super_block *sb;
8384 + DiMustWriteLock(dentry);
8386 + sb = dentry->d_sb;
8387 + dinfo = au_di(dentry);
8388 + bbot = dinfo->di_bbot;
8389 + bwh = dinfo->di_bwh;
8390 + bdiropq = dinfo->di_bdiropq;
8391 + bindex = dinfo->di_btop;
8392 + p = au_hdentry(dinfo, bindex);
8393 + for (; bindex <= bbot; bindex++, p++) {
8394 + if (!p->hd_dentry)
8397 + new_bindex = au_br_index(sb, p->hd_id);
8398 + if (new_bindex == bindex)
8401 + if (dinfo->di_bwh == bindex)
8403 + if (dinfo->di_bdiropq == bindex)
8404 + bdiropq = new_bindex;
8405 + if (new_bindex < 0) {
8407 + p->hd_dentry = NULL;
8411 + /* swap two lower dentries, and loop again */
8412 + q = au_hdentry(dinfo, new_bindex);
8416 + if (tmp.hd_dentry) {
8422 + dinfo->di_bwh = -1;
8423 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8424 + dinfo->di_bwh = bwh;
8426 + dinfo->di_bdiropq = -1;
8428 + && bdiropq <= au_sbbot(sb)
8429 + && au_sbr_whable(sb, bdiropq))
8430 + dinfo->di_bdiropq = bdiropq;
8433 + dinfo->di_btop = -1;
8434 + dinfo->di_bbot = -1;
8435 + bbot = au_dbbot(parent);
8437 + p = au_hdentry(dinfo, bindex);
8438 + for (; bindex <= bbot; bindex++, p++)
8439 + if (p->hd_dentry) {
8440 + dinfo->di_btop = bindex;
8444 + if (dinfo->di_btop >= 0) {
8446 + p = au_hdentry(dinfo, bindex);
8447 + for (; bindex >= 0; bindex--, p--)
8448 + if (p->hd_dentry) {
8449 + dinfo->di_bbot = bindex;
8458 +static void au_do_hide(struct dentry *dentry)
8460 + struct inode *inode;
8462 + if (d_really_is_positive(dentry)) {
8463 + inode = d_inode(dentry);
8464 + if (!d_is_dir(dentry)) {
8465 + if (inode->i_nlink && !d_unhashed(dentry))
8466 + drop_nlink(inode);
8468 + clear_nlink(inode);
8469 + /* stop next lookup */
8470 + inode->i_flags |= S_DEAD;
8472 + smp_mb(); /* necessary? */
8477 +static int au_hide_children(struct dentry *parent)
8479 + int err, i, j, ndentry;
8480 + struct au_dcsub_pages dpages;
8481 + struct au_dpage *dpage;
8482 + struct dentry *dentry;
8484 + err = au_dpages_init(&dpages, GFP_NOFS);
8485 + if (unlikely(err))
8487 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8488 + if (unlikely(err))
8491 + /* in reverse order */
8492 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8493 + dpage = dpages.dpages + i;
8494 + ndentry = dpage->ndentry;
8495 + for (j = ndentry - 1; j >= 0; j--) {
8496 + dentry = dpage->dentries[j];
8497 + if (dentry != parent)
8498 + au_do_hide(dentry);
8503 + au_dpages_free(&dpages);
8508 +static void au_hide(struct dentry *dentry)
8512 + AuDbgDentry(dentry);
8513 + if (d_is_dir(dentry)) {
8514 + /* shrink_dcache_parent(dentry); */
8515 + err = au_hide_children(dentry);
8516 + if (unlikely(err))
8517 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8520 + au_do_hide(dentry);
8524 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8526 + * a dirty branch is added
8527 + * - on the top of layers
8528 + * - in the middle of layers
8529 + * - to the bottom of layers
8531 + * on the added branch there exists
8534 + * - a same named entry
8536 + * * negative --> positive
8537 + * * positive --> positive
8538 + * - type is unchanged
8539 + * - type is changed
8541 + * * negative --> negative
8542 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8545 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8546 + struct au_dinfo *tmp)
8549 + aufs_bindex_t bindex, bbot;
8551 + struct dentry *dentry;
8552 + struct inode *inode;
8554 + } orig_h, tmp_h = {
8557 + struct au_hdentry *hd;
8558 + struct inode *inode, *h_inode;
8559 + struct dentry *h_dentry;
8562 + AuDebugOn(dinfo->di_btop < 0);
8564 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8565 + orig_h.inode = NULL;
8566 + if (d_is_positive(orig_h.dentry)) {
8567 + orig_h.inode = d_inode(orig_h.dentry);
8568 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8570 + if (tmp->di_btop >= 0) {
8571 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8572 + if (d_is_positive(tmp_h.dentry)) {
8573 + tmp_h.inode = d_inode(tmp_h.dentry);
8574 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8579 + if (d_really_is_positive(dentry))
8580 + inode = d_inode(dentry);
8581 + if (!orig_h.inode) {
8582 + AuDbg("negative originally\n");
8588 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8589 + AuDebugOn(dinfo->di_bdiropq != -1);
8591 + if (!tmp_h.inode) {
8592 + AuDbg("negative --> negative\n");
8593 + /* should have only one negative lower */
8594 + if (tmp->di_btop >= 0
8595 + && tmp->di_btop < dinfo->di_btop) {
8596 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8597 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8598 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8599 + au_di_cp(dinfo, tmp);
8600 + hd = au_hdentry(tmp, tmp->di_btop);
8601 + au_set_h_dptr(dentry, tmp->di_btop,
8602 + dget(hd->hd_dentry));
8604 + au_dbg_verify_dinode(dentry);
8606 + AuDbg("negative --> positive\n");
8608 + * similar to the behaviour of creating with bypassing
8610 + * unhash it in order to force an error in the
8611 + * succeeding create operation.
8612 + * we should not set S_DEAD here.
8615 + /* au_di_swap(tmp, dinfo); */
8616 + au_dbg_verify_dinode(dentry);
8619 + AuDbg("positive originally\n");
8620 + /* inode may be NULL */
8621 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8622 + if (!tmp_h.inode) {
8623 + AuDbg("positive --> negative\n");
8624 + /* or bypassing aufs */
8626 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8627 + dinfo->di_bwh = tmp->di_bwh;
8629 + err = au_refresh_hinode_self(inode);
8630 + au_dbg_verify_dinode(dentry);
8631 + } else if (orig_h.mode == tmp_h.mode) {
8632 + AuDbg("positive --> positive, same type\n");
8633 + if (!S_ISDIR(orig_h.mode)
8634 + && dinfo->di_btop > tmp->di_btop) {
8636 + * similar to the behaviour of removing and
8641 + err = au_refresh_hinode_self(inode);
8642 + au_dbg_verify_dinode(dentry);
8644 + /* fill empty slots */
8645 + if (dinfo->di_btop > tmp->di_btop)
8646 + dinfo->di_btop = tmp->di_btop;
8647 + if (dinfo->di_bbot < tmp->di_bbot)
8648 + dinfo->di_bbot = tmp->di_bbot;
8649 + dinfo->di_bwh = tmp->di_bwh;
8650 + dinfo->di_bdiropq = tmp->di_bdiropq;
8651 + bbot = dinfo->di_bbot;
8652 + bindex = tmp->di_btop;
8653 + hd = au_hdentry(tmp, bindex);
8654 + for (; bindex <= bbot; bindex++, hd++) {
8655 + if (au_h_dptr(dentry, bindex))
8657 + h_dentry = hd->hd_dentry;
8660 + AuDebugOn(d_is_negative(h_dentry));
8661 + h_inode = d_inode(h_dentry);
8662 + AuDebugOn(orig_h.mode
8663 + != (h_inode->i_mode
8665 + au_set_h_dptr(dentry, bindex,
8669 + err = au_refresh_hinode(inode, dentry);
8670 + au_dbg_verify_dinode(dentry);
8673 + AuDbg("positive --> positive, different type\n");
8674 + /* similar to the behaviour of removing and creating */
8677 + err = au_refresh_hinode_self(inode);
8678 + au_dbg_verify_dinode(dentry);
8686 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8688 + const struct dentry_operations *dop
8689 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8690 + static const unsigned int mask
8691 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8693 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8695 + if (dentry->d_op == dop)
8698 + AuDbg("%pd\n", dentry);
8699 + spin_lock(&dentry->d_lock);
8700 + if (dop == &aufs_dop)
8701 + dentry->d_flags |= mask;
8703 + dentry->d_flags &= ~mask;
8704 + dentry->d_op = dop;
8705 + spin_unlock(&dentry->d_lock);
8708 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8710 + int err, ebrange, nbr;
8711 + unsigned int sigen;
8712 + struct au_dinfo *dinfo, *tmp;
8713 + struct super_block *sb;
8714 + struct inode *inode;
8716 + DiMustWriteLock(dentry);
8717 + AuDebugOn(IS_ROOT(dentry));
8718 + AuDebugOn(d_really_is_negative(parent));
8720 + sb = dentry->d_sb;
8721 + sigen = au_sigen(sb);
8722 + err = au_digen_test(parent, sigen);
8723 + if (unlikely(err))
8726 + nbr = au_sbbot(sb) + 1;
8727 + dinfo = au_di(dentry);
8728 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8729 + if (unlikely(err))
8731 + ebrange = au_dbrange_test(dentry);
8733 + ebrange = au_do_refresh_hdentry(dentry, parent);
8735 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8736 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8737 + if (d_really_is_positive(dentry)) {
8738 + inode = d_inode(dentry);
8739 + err = au_refresh_hinode_self(inode);
8741 + au_dbg_verify_dinode(dentry);
8743 + goto out_dgen; /* success */
8747 + /* temporary dinfo */
8748 + AuDbgDentry(dentry);
8750 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8751 + if (unlikely(!tmp))
8753 + au_di_swap(tmp, dinfo);
8754 + /* returns the number of positive dentries */
8756 + * if current working dir is removed, it returns an error.
8757 + * but the dentry is legal.
8759 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8760 + AuDbgDentry(dentry);
8761 + au_di_swap(tmp, dinfo);
8762 + if (err == -ENOENT)
8765 + /* compare/refresh by dinfo */
8766 + AuDbgDentry(dentry);
8767 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8768 + au_dbg_verify_dinode(dentry);
8771 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8772 + au_rw_write_unlock(&tmp->di_rwsem);
8774 + if (unlikely(err))
8778 + au_update_digen(dentry);
8780 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8781 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8782 + AuDbgDentry(dentry);
8788 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8789 + struct dentry *dentry, aufs_bindex_t bindex)
8794 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8797 + AuDbg("b%d\n", bindex);
8799 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8800 + * due to whiteout and branch permission.
8802 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8803 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8804 + /* it may return tri-state */
8805 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8807 + if (unlikely(valid < 0))
8817 +/* todo: remove this */
8818 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8819 + unsigned int flags, int do_udba, int dirren)
8822 + umode_t mode, h_mode;
8823 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8824 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8825 + struct inode *h_inode, *h_cached_inode;
8826 + struct dentry *h_dentry;
8827 + struct qstr *name, *h_name;
8834 + unhashed = !!d_unhashed(dentry);
8835 + is_root = !!IS_ROOT(dentry);
8836 + name = &dentry->d_name;
8837 + tmpfile = au_di(dentry)->di_tmpfile;
8840 + * Theoretically, REVAL test should be unnecessary in case of
8842 + * But {fs,i}notify doesn't fire some necessary events,
8843 + * IN_ATTRIB for atime/nlink/pageio
8844 + * Let's do REVAL test too.
8846 + if (do_udba && inode) {
8847 + mode = (inode->i_mode & S_IFMT);
8848 + plus = (inode->i_nlink > 0);
8849 + ibs = au_ibtop(inode);
8850 + ibe = au_ibbot(inode);
8853 + btop = au_dbtop(dentry);
8855 + if (inode && S_ISDIR(inode->i_mode))
8856 + btail = au_dbtaildir(dentry);
8857 + for (bindex = btop; bindex <= btail; bindex++) {
8858 + h_dentry = au_h_dptr(dentry, bindex);
8862 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8863 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8864 + spin_lock(&h_dentry->d_lock);
8865 + h_name = &h_dentry->d_name;
8866 + if (unlikely(do_udba
8869 + && (unhashed != !!d_unhashed(h_dentry)
8870 + || (!tmpfile && !dirren
8871 + && !au_qstreq(name, h_name))
8874 + && !(flags & LOOKUP_OPEN)
8875 + && (h_dentry->d_flags
8876 + & DCACHE_NFSFS_RENAMED)))
8880 + h_unhashed = d_unhashed(h_dentry);
8881 + spin_unlock(&h_dentry->d_lock);
8882 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8883 + unhashed, h_unhashed, dentry, h_dentry);
8886 + spin_unlock(&h_dentry->d_lock);
8888 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8889 + if (unlikely(err))
8890 + /* do not goto err, to keep the errno */
8893 + /* todo: plink too? */
8898 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8902 + if (d_is_positive(h_dentry))
8903 + h_inode = d_inode(h_dentry);
8906 + h_cached_inode = h_inode;
8908 + h_mode = (h_inode->i_mode & S_IFMT);
8909 + h_plus = (h_inode->i_nlink > 0);
8911 + if (inode && ibs <= bindex && bindex <= ibe)
8912 + h_cached_inode = au_h_iptr(inode, bindex);
8915 + if (unlikely(plus != h_plus && !tmpfile))
8918 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8920 + && !IS_ROOT(h_dentry)
8921 + && unhashed != d_unhashed(h_dentry)))
8924 + if (unlikely(mode != h_mode
8925 + || h_cached_inode != h_inode))
8938 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8939 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8942 + struct dentry *parent;
8944 + if (!au_digen_test(dentry, sigen))
8947 + parent = dget_parent(dentry);
8948 + di_read_lock_parent(parent, AuLock_IR);
8949 + AuDebugOn(au_digen_test(parent, sigen));
8950 + au_dbg_verify_gen(parent, sigen);
8951 + err = au_refresh_dentry(dentry, parent);
8952 + di_read_unlock(parent, AuLock_IR);
8958 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8961 + struct dentry *d, *parent;
8963 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8964 + return simple_reval_dpath(dentry, sigen);
8966 + /* slow loop, keep it simple and stupid */
8967 + /* cf: au_cpup_dirs() */
8970 + while (au_digen_test(dentry, sigen)) {
8974 + parent = dget_parent(d);
8975 + if (!au_digen_test(parent, sigen))
8981 + di_write_lock_child2(d);
8983 + /* someone might update our dentry while we were sleeping */
8984 + if (au_digen_test(d, sigen)) {
8986 + * todo: consolidate with simple_reval_dpath(),
8987 + * do_refresh() and au_reval_for_attr().
8989 + di_read_lock_parent(parent, AuLock_IR);
8990 + err = au_refresh_dentry(d, parent);
8991 + di_read_unlock(parent, AuLock_IR);
8995 + di_write_unlock(d);
8997 + if (unlikely(err))
9005 + * if valid returns 1, otherwise 0.
9007 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9010 + unsigned int sigen;
9011 + unsigned char do_udba, dirren;
9012 + struct super_block *sb;
9013 + struct inode *inode;
9015 + /* todo: support rcu-walk? */
9016 + if (flags & LOOKUP_RCU)
9020 + if (unlikely(!au_di(dentry)))
9024 + sb = dentry->d_sb;
9027 + * i_mutex of parent dir may be held,
9028 + * but we should not return 'invalid' due to busy.
9030 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9031 + if (unlikely(err)) {
9037 + if (d_really_is_positive(dentry))
9038 + inode = d_inode(dentry);
9039 + if (unlikely(inode && au_is_bad_inode(inode))) {
9044 + if (unlikely(au_dbrange_test(dentry))) {
9050 + sigen = au_sigen(sb);
9051 + if (au_digen_test(dentry, sigen)) {
9052 + AuDebugOn(IS_ROOT(dentry));
9053 + err = au_reval_dpath(dentry, sigen);
9054 + if (unlikely(err)) {
9059 + di_downgrade_lock(dentry, AuLock_IR);
9062 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9064 + && !(inode->i_state && I_LINKABLE)
9065 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9070 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9071 + if (do_udba && inode) {
9072 + aufs_bindex_t btop = au_ibtop(inode);
9073 + struct inode *h_inode;
9076 + h_inode = au_h_iptr(inode, btop);
9077 + if (h_inode && au_test_higen(inode, h_inode)) {
9084 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9085 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9086 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9088 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9094 + di_downgrade_lock(dentry, AuLock_IR);
9096 + aufs_read_unlock(dentry, AuLock_IR);
9101 + AuDbg("%pd invalid, %d\n", dentry, valid);
9107 +static void aufs_d_release(struct dentry *dentry)
9109 + if (au_di(dentry)) {
9110 + au_di_fin(dentry);
9111 + au_hn_di_reinit(dentry);
9115 +const struct dentry_operations aufs_dop = {
9116 + .d_revalidate = aufs_d_revalidate,
9117 + .d_weak_revalidate = aufs_d_revalidate,
9118 + .d_release = aufs_d_release
9121 +/* aufs_dop without d_revalidate */
9122 +const struct dentry_operations aufs_dop_noreval = {
9123 + .d_release = aufs_d_release
9125 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9126 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9127 +++ linux/fs/aufs/dentry.h 2022-10-26 22:30:38.462648858 +0200
9129 +/* SPDX-License-Identifier: GPL-2.0 */
9131 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9133 + * This program, aufs is free software; you can redistribute it and/or modify
9134 + * it under the terms of the GNU General Public License as published by
9135 + * the Free Software Foundation; either version 2 of the License, or
9136 + * (at your option) any later version.
9138 + * This program is distributed in the hope that it will be useful,
9139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9141 + * GNU General Public License for more details.
9143 + * You should have received a copy of the GNU General Public License
9144 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9148 + * lookup and dentry operations
9151 +#ifndef __AUFS_DENTRY_H__
9152 +#define __AUFS_DENTRY_H__
9156 +#include <linux/dcache.h>
9157 +#include "dirren.h"
9160 +struct au_hdentry {
9161 + struct dentry *hd_dentry;
9162 + aufs_bindex_t hd_id;
9166 + atomic_t di_generation;
9168 + struct au_rwsem di_rwsem;
9169 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9170 + unsigned char di_tmpfile; /* to allow the different name */
9171 + struct au_hdentry *di_hdentry;
9172 + struct rcu_head rcu;
9173 +} ____cacheline_aligned_in_smp;
9175 +/* ---------------------------------------------------------------------- */
9177 +/* flags for au_lkup_dentry() */
9178 +#define AuLkup_ALLOW_NEG 1
9179 +#define AuLkup_IGNORE_PERM (1 << 1)
9180 +#define AuLkup_DIRREN (1 << 2)
9181 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9182 +#define au_fset_lkup(flags, name) \
9183 + do { (flags) |= AuLkup_##name; } while (0)
9184 +#define au_fclr_lkup(flags, name) \
9185 + do { (flags) &= ~AuLkup_##name; } while (0)
9187 +#ifndef CONFIG_AUFS_DIRREN
9188 +#undef AuLkup_DIRREN
9189 +#define AuLkup_DIRREN 0
9192 +struct au_do_lookup_args {
9193 + unsigned int flags;
9195 + struct qstr whname, *name;
9196 + struct au_dr_lookup dirren;
9199 +/* ---------------------------------------------------------------------- */
9202 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9204 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9205 + struct path *ppath);
9206 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9207 + struct dentry *h_parent, struct au_branch *br);
9209 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9210 + unsigned int flags);
9211 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9212 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9213 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9214 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9217 +void au_di_init_once(void *_di);
9218 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9219 +void au_di_free(struct au_dinfo *dinfo);
9220 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9221 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9222 +int au_di_init(struct dentry *dentry);
9223 +void au_di_fin(struct dentry *dentry);
9224 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9226 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9227 +void di_read_unlock(struct dentry *d, int flags);
9228 +void di_downgrade_lock(struct dentry *d, int flags);
9229 +void di_write_lock(struct dentry *d, unsigned int lsc);
9230 +void di_write_unlock(struct dentry *d);
9231 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9232 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9233 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9235 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9236 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9237 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9238 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9240 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9241 + struct dentry *h_dentry);
9242 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9243 +int au_dbrange_test(struct dentry *dentry);
9244 +void au_update_digen(struct dentry *dentry);
9245 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9246 +void au_update_dbtop(struct dentry *dentry);
9247 +void au_update_dbbot(struct dentry *dentry);
9248 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9250 +/* ---------------------------------------------------------------------- */
9252 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9254 + return dentry->d_fsdata;
9257 +/* ---------------------------------------------------------------------- */
9259 +/* lock subclass for dinfo */
9261 + AuLsc_DI_CHILD, /* child first */
9262 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9263 + AuLsc_DI_CHILD3, /* copyup dirs */
9267 + AuLsc_DI_TMP /* temp for replacing dinfo */
9271 + * di_read_lock_child, di_write_lock_child,
9272 + * di_read_lock_child2, di_write_lock_child2,
9273 + * di_read_lock_child3, di_write_lock_child3,
9274 + * di_read_lock_parent, di_write_lock_parent,
9275 + * di_read_lock_parent2, di_write_lock_parent2,
9276 + * di_read_lock_parent3, di_write_lock_parent3,
9278 +#define AuReadLockFunc(name, lsc) \
9279 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9280 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9282 +#define AuWriteLockFunc(name, lsc) \
9283 +static inline void di_write_lock_##name(struct dentry *d) \
9284 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9286 +#define AuRWLockFuncs(name, lsc) \
9287 + AuReadLockFunc(name, lsc) \
9288 + AuWriteLockFunc(name, lsc)
9290 +AuRWLockFuncs(child, CHILD);
9291 +AuRWLockFuncs(child2, CHILD2);
9292 +AuRWLockFuncs(child3, CHILD3);
9293 +AuRWLockFuncs(parent, PARENT);
9294 +AuRWLockFuncs(parent2, PARENT2);
9295 +AuRWLockFuncs(parent3, PARENT3);
9297 +#undef AuReadLockFunc
9298 +#undef AuWriteLockFunc
9299 +#undef AuRWLockFuncs
9301 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9302 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9303 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9305 +/* ---------------------------------------------------------------------- */
9307 +/* todo: memory barrier? */
9308 +static inline unsigned int au_digen(struct dentry *d)
9310 + return atomic_read(&au_di(d)->di_generation);
9313 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9315 + hdentry->hd_dentry = NULL;
9318 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9319 + aufs_bindex_t bindex)
9321 + return di->di_hdentry + bindex;
9324 +static inline void au_hdput(struct au_hdentry *hd)
9327 + dput(hd->hd_dentry);
9330 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9332 + DiMustAnyLock(dentry);
9333 + return au_di(dentry)->di_btop;
9336 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9338 + DiMustAnyLock(dentry);
9339 + return au_di(dentry)->di_bbot;
9342 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9344 + DiMustAnyLock(dentry);
9345 + return au_di(dentry)->di_bwh;
9348 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9350 + DiMustAnyLock(dentry);
9351 + return au_di(dentry)->di_bdiropq;
9354 +/* todo: hard/soft set? */
9355 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9357 + DiMustWriteLock(dentry);
9358 + au_di(dentry)->di_btop = bindex;
9361 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9363 + DiMustWriteLock(dentry);
9364 + au_di(dentry)->di_bbot = bindex;
9367 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9369 + DiMustWriteLock(dentry);
9370 + /* dbwh can be outside of btop - bbot range */
9371 + au_di(dentry)->di_bwh = bindex;
9374 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9376 + DiMustWriteLock(dentry);
9377 + au_di(dentry)->di_bdiropq = bindex;
9380 +/* ---------------------------------------------------------------------- */
9382 +#ifdef CONFIG_AUFS_HNOTIFY
9383 +static inline void au_digen_dec(struct dentry *d)
9385 + atomic_dec(&au_di(d)->di_generation);
9388 +static inline void au_hn_di_reinit(struct dentry *dentry)
9390 + dentry->d_fsdata = NULL;
9393 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9394 +#endif /* CONFIG_AUFS_HNOTIFY */
9396 +#endif /* __KERNEL__ */
9397 +#endif /* __AUFS_DENTRY_H__ */
9398 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9399 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9400 +++ linux/fs/aufs/dinfo.c 2022-10-26 22:30:38.462648858 +0200
9402 +// SPDX-License-Identifier: GPL-2.0
9404 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9406 + * This program, aufs is free software; you can redistribute it and/or modify
9407 + * it under the terms of the GNU General Public License as published by
9408 + * the Free Software Foundation; either version 2 of the License, or
9409 + * (at your option) any later version.
9411 + * This program is distributed in the hope that it will be useful,
9412 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9413 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9414 + * GNU General Public License for more details.
9416 + * You should have received a copy of the GNU General Public License
9417 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9421 + * dentry private data
9426 +void au_di_init_once(void *_dinfo)
9428 + struct au_dinfo *dinfo = _dinfo;
9430 + au_rw_init(&dinfo->di_rwsem);
9433 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9435 + struct au_dinfo *dinfo;
9438 + dinfo = au_cache_alloc_dinfo();
9439 + if (unlikely(!dinfo))
9442 + nbr = au_sbbot(sb) + 1;
9445 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9446 + if (dinfo->di_hdentry) {
9447 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9448 + dinfo->di_btop = -1;
9449 + dinfo->di_bbot = -1;
9450 + dinfo->di_bwh = -1;
9451 + dinfo->di_bdiropq = -1;
9452 + dinfo->di_tmpfile = 0;
9453 + for (i = 0; i < nbr; i++)
9454 + dinfo->di_hdentry[i].hd_id = -1;
9458 + au_cache_free_dinfo(dinfo);
9465 +void au_di_free(struct au_dinfo *dinfo)
9467 + struct au_hdentry *p;
9468 + aufs_bindex_t bbot, bindex;
9470 + /* dentry may not be revalidated */
9471 + bindex = dinfo->di_btop;
9472 + if (bindex >= 0) {
9473 + bbot = dinfo->di_bbot;
9474 + p = au_hdentry(dinfo, bindex);
9475 + while (bindex++ <= bbot)
9478 + au_kfree_try_rcu(dinfo->di_hdentry);
9479 + au_cache_free_dinfo(dinfo);
9482 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9484 + struct au_hdentry *p;
9487 + AuRwMustWriteLock(&a->di_rwsem);
9488 + AuRwMustWriteLock(&b->di_rwsem);
9490 +#define DiSwap(v, name) \
9492 + v = a->di_##name; \
9493 + a->di_##name = b->di_##name; \
9494 + b->di_##name = v; \
9497 + DiSwap(p, hdentry);
9501 + DiSwap(bi, bdiropq);
9507 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9509 + AuRwMustWriteLock(&dst->di_rwsem);
9510 + AuRwMustWriteLock(&src->di_rwsem);
9512 + dst->di_btop = src->di_btop;
9513 + dst->di_bbot = src->di_bbot;
9514 + dst->di_bwh = src->di_bwh;
9515 + dst->di_bdiropq = src->di_bdiropq;
9519 +int au_di_init(struct dentry *dentry)
9522 + struct super_block *sb;
9523 + struct au_dinfo *dinfo;
9526 + sb = dentry->d_sb;
9527 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9529 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9530 + /* smp_mb(); */ /* atomic_set */
9531 + dentry->d_fsdata = dinfo;
9538 +void au_di_fin(struct dentry *dentry)
9540 + struct au_dinfo *dinfo;
9542 + dinfo = au_di(dentry);
9543 + AuRwDestroy(&dinfo->di_rwsem);
9544 + au_di_free(dinfo);
9547 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9550 + struct au_hdentry *hdp;
9552 + AuRwMustWriteLock(&dinfo->di_rwsem);
9555 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9557 + sz = sizeof(*hdp);
9558 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9561 + dinfo->di_hdentry = hdp;
9568 +/* ---------------------------------------------------------------------- */
9570 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9573 + case AuLsc_DI_CHILD:
9574 + ii_write_lock_child(inode);
9576 + case AuLsc_DI_CHILD2:
9577 + ii_write_lock_child2(inode);
9579 + case AuLsc_DI_CHILD3:
9580 + ii_write_lock_child3(inode);
9582 + case AuLsc_DI_PARENT:
9583 + ii_write_lock_parent(inode);
9585 + case AuLsc_DI_PARENT2:
9586 + ii_write_lock_parent2(inode);
9588 + case AuLsc_DI_PARENT3:
9589 + ii_write_lock_parent3(inode);
9596 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9599 + case AuLsc_DI_CHILD:
9600 + ii_read_lock_child(inode);
9602 + case AuLsc_DI_CHILD2:
9603 + ii_read_lock_child2(inode);
9605 + case AuLsc_DI_CHILD3:
9606 + ii_read_lock_child3(inode);
9608 + case AuLsc_DI_PARENT:
9609 + ii_read_lock_parent(inode);
9611 + case AuLsc_DI_PARENT2:
9612 + ii_read_lock_parent2(inode);
9614 + case AuLsc_DI_PARENT3:
9615 + ii_read_lock_parent3(inode);
9622 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9624 + struct inode *inode;
9626 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9627 + if (d_really_is_positive(d)) {
9628 + inode = d_inode(d);
9629 + if (au_ftest_lock(flags, IW))
9630 + do_ii_write_lock(inode, lsc);
9631 + else if (au_ftest_lock(flags, IR))
9632 + do_ii_read_lock(inode, lsc);
9636 +void di_read_unlock(struct dentry *d, int flags)
9638 + struct inode *inode;
9640 + if (d_really_is_positive(d)) {
9641 + inode = d_inode(d);
9642 + if (au_ftest_lock(flags, IW)) {
9643 + au_dbg_verify_dinode(d);
9644 + ii_write_unlock(inode);
9645 + } else if (au_ftest_lock(flags, IR)) {
9646 + au_dbg_verify_dinode(d);
9647 + ii_read_unlock(inode);
9650 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9653 +void di_downgrade_lock(struct dentry *d, int flags)
9655 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9656 + ii_downgrade_lock(d_inode(d));
9657 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9660 +void di_write_lock(struct dentry *d, unsigned int lsc)
9662 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9663 + if (d_really_is_positive(d))
9664 + do_ii_write_lock(d_inode(d), lsc);
9667 +void di_write_unlock(struct dentry *d)
9669 + au_dbg_verify_dinode(d);
9670 + if (d_really_is_positive(d))
9671 + ii_write_unlock(d_inode(d));
9672 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9675 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9677 + AuDebugOn(d1 == d2
9678 + || d_inode(d1) == d_inode(d2)
9679 + || d1->d_sb != d2->d_sb);
9681 + if ((isdir && au_test_subdir(d1, d2))
9683 + di_write_lock_child(d1);
9684 + di_write_lock_child2(d2);
9686 + di_write_lock_child(d2);
9687 + di_write_lock_child2(d1);
9691 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9693 + AuDebugOn(d1 == d2
9694 + || d_inode(d1) == d_inode(d2)
9695 + || d1->d_sb != d2->d_sb);
9697 + if ((isdir && au_test_subdir(d1, d2))
9699 + di_write_lock_parent(d1);
9700 + di_write_lock_parent2(d2);
9702 + di_write_lock_parent(d2);
9703 + di_write_lock_parent2(d1);
9707 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9709 + di_write_unlock(d1);
9710 + if (d_inode(d1) == d_inode(d2))
9711 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9713 + di_write_unlock(d2);
9716 +/* ---------------------------------------------------------------------- */
9718 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9722 + DiMustAnyLock(dentry);
9724 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9726 + AuDebugOn(bindex < 0);
9727 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9728 + AuDebugOn(d && au_dcount(d) <= 0);
9733 + * extended version of au_h_dptr().
9734 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9737 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9739 + struct dentry *h_dentry;
9740 + struct inode *inode, *h_inode;
9742 + AuDebugOn(d_really_is_negative(dentry));
9745 + if (au_dbtop(dentry) <= bindex
9746 + && bindex <= au_dbbot(dentry))
9747 + h_dentry = au_h_dptr(dentry, bindex);
9748 + if (h_dentry && !au_d_linkable(h_dentry)) {
9750 + goto out; /* success */
9753 + inode = d_inode(dentry);
9754 + AuDebugOn(bindex < au_ibtop(inode));
9755 + AuDebugOn(au_ibbot(inode) < bindex);
9756 + h_inode = au_h_iptr(inode, bindex);
9757 + h_dentry = d_find_alias(h_inode);
9759 + if (!IS_ERR(h_dentry)) {
9760 + if (!au_d_linkable(h_dentry))
9761 + goto out; /* success */
9767 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9768 + h_dentry = au_plink_lkup(inode, bindex);
9769 + AuDebugOn(!h_dentry);
9770 + if (!IS_ERR(h_dentry)) {
9771 + if (!au_d_hashed_positive(h_dentry))
9772 + goto out; /* success */
9779 + AuDbgDentry(h_dentry);
9783 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9785 + aufs_bindex_t bbot, bwh;
9787 + bbot = au_dbbot(dentry);
9789 + bwh = au_dbwh(dentry);
9792 + if (0 < bwh && bwh < bbot)
9798 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9800 + aufs_bindex_t bbot, bopq;
9802 + bbot = au_dbtail(dentry);
9804 + bopq = au_dbdiropq(dentry);
9805 + if (0 <= bopq && bopq < bbot)
9811 +/* ---------------------------------------------------------------------- */
9813 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9814 + struct dentry *h_dentry)
9816 + struct au_dinfo *dinfo;
9817 + struct au_hdentry *hd;
9818 + struct au_branch *br;
9820 + DiMustWriteLock(dentry);
9822 + dinfo = au_di(dentry);
9823 + hd = au_hdentry(dinfo, bindex);
9825 + hd->hd_dentry = h_dentry;
9827 + br = au_sbr(dentry->d_sb, bindex);
9828 + hd->hd_id = br->br_id;
9832 +int au_dbrange_test(struct dentry *dentry)
9835 + aufs_bindex_t btop, bbot;
9838 + btop = au_dbtop(dentry);
9839 + bbot = au_dbbot(dentry);
9841 + AuDebugOn(bbot < 0 && btop > bbot);
9844 + AuDebugOn(bbot >= 0);
9850 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9855 + if (unlikely(au_digen(dentry) != sigen
9856 + || au_iigen_test(d_inode(dentry), sigen)))
9862 +void au_update_digen(struct dentry *dentry)
9864 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9865 + /* smp_mb(); */ /* atomic_set */
9868 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9870 + struct au_dinfo *dinfo;
9871 + struct dentry *h_d;
9872 + struct au_hdentry *hdp;
9873 + aufs_bindex_t bindex, bbot;
9875 + DiMustWriteLock(dentry);
9877 + dinfo = au_di(dentry);
9878 + if (!dinfo || dinfo->di_btop < 0)
9881 + if (do_put_zero) {
9882 + bbot = dinfo->di_bbot;
9883 + bindex = dinfo->di_btop;
9884 + hdp = au_hdentry(dinfo, bindex);
9885 + for (; bindex <= bbot; bindex++, hdp++) {
9886 + h_d = hdp->hd_dentry;
9887 + if (h_d && d_is_negative(h_d))
9888 + au_set_h_dptr(dentry, bindex, NULL);
9892 + dinfo->di_btop = 0;
9893 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9894 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9895 + if (hdp->hd_dentry)
9897 + if (dinfo->di_btop > dinfo->di_bbot) {
9898 + dinfo->di_btop = -1;
9899 + dinfo->di_bbot = -1;
9903 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9904 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9905 + if (hdp->hd_dentry)
9907 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9910 +void au_update_dbtop(struct dentry *dentry)
9912 + aufs_bindex_t bindex, bbot;
9913 + struct dentry *h_dentry;
9915 + bbot = au_dbbot(dentry);
9916 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9917 + h_dentry = au_h_dptr(dentry, bindex);
9920 + if (d_is_positive(h_dentry)) {
9921 + au_set_dbtop(dentry, bindex);
9924 + au_set_h_dptr(dentry, bindex, NULL);
9928 +void au_update_dbbot(struct dentry *dentry)
9930 + aufs_bindex_t bindex, btop;
9931 + struct dentry *h_dentry;
9933 + btop = au_dbtop(dentry);
9934 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9935 + h_dentry = au_h_dptr(dentry, bindex);
9938 + if (d_is_positive(h_dentry)) {
9939 + au_set_dbbot(dentry, bindex);
9942 + au_set_h_dptr(dentry, bindex, NULL);
9946 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9948 + aufs_bindex_t bindex, bbot;
9950 + bbot = au_dbbot(dentry);
9951 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9952 + if (au_h_dptr(dentry, bindex) == h_dentry)
9956 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9957 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9958 +++ linux/fs/aufs/dir.c 2022-10-26 22:30:38.462648858 +0200
9960 +// SPDX-License-Identifier: GPL-2.0
9962 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9964 + * This program, aufs is free software; you can redistribute it and/or modify
9965 + * it under the terms of the GNU General Public License as published by
9966 + * the Free Software Foundation; either version 2 of the License, or
9967 + * (at your option) any later version.
9969 + * This program is distributed in the hope that it will be useful,
9970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9972 + * GNU General Public License for more details.
9974 + * You should have received a copy of the GNU General Public License
9975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9979 + * directory operations
9982 +#include <linux/fs_stack.h>
9983 +#include <linux/iversion.h>
9986 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9988 + unsigned int nlink;
9990 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9992 + nlink = dir->i_nlink;
9993 + nlink += h_dir->i_nlink - 2;
9994 + if (h_dir->i_nlink < 2)
9996 + smp_mb(); /* for i_nlink */
9997 + /* 0 can happen in revaliding */
9998 + set_nlink(dir, nlink);
10001 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10003 + unsigned int nlink;
10005 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10007 + nlink = dir->i_nlink;
10008 + nlink -= h_dir->i_nlink - 2;
10009 + if (h_dir->i_nlink < 2)
10011 + smp_mb(); /* for i_nlink */
10012 + /* nlink == 0 means the branch-fs is broken */
10013 + set_nlink(dir, nlink);
10016 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10019 + aufs_bindex_t bindex, bbot;
10020 + struct file *h_file;
10021 + struct dentry *h_dentry;
10025 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10027 + bbot = au_fbbot_dir(file);
10028 + for (bindex = au_fbtop(file);
10029 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10031 + h_file = au_hf_dir(file, bindex);
10032 + if (h_file && file_inode(h_file))
10033 + sz += vfsub_f_size_read(h_file);
10036 + AuDebugOn(!dentry);
10037 + AuDebugOn(!d_is_dir(dentry));
10039 + bbot = au_dbtaildir(dentry);
10040 + for (bindex = au_dbtop(dentry);
10041 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10043 + h_dentry = au_h_dptr(dentry, bindex);
10044 + if (h_dentry && d_is_positive(h_dentry))
10045 + sz += i_size_read(d_inode(h_dentry));
10048 + if (sz < KMALLOC_MAX_SIZE)
10049 + sz = roundup_pow_of_two(sz);
10050 + if (sz > KMALLOC_MAX_SIZE)
10051 + sz = KMALLOC_MAX_SIZE;
10052 + else if (sz < NAME_MAX) {
10053 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10054 + sz = AUFS_RDBLK_DEF;
10059 +struct au_dir_ts_arg {
10060 + struct dentry *dentry;
10061 + aufs_bindex_t brid;
10064 +static void au_do_dir_ts(void *arg)
10066 + struct au_dir_ts_arg *a = arg;
10067 + struct au_dtime dt;
10068 + struct path h_path;
10069 + struct inode *dir, *h_dir;
10070 + struct super_block *sb;
10071 + struct au_branch *br;
10072 + struct au_hinode *hdir;
10074 + aufs_bindex_t btop, bindex;
10076 + sb = a->dentry->d_sb;
10077 + if (d_really_is_negative(a->dentry))
10079 + /* no dir->i_mutex lock */
10080 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10082 + dir = d_inode(a->dentry);
10083 + btop = au_ibtop(dir);
10084 + bindex = au_br_index(sb, a->brid);
10085 + if (bindex < btop)
10088 + br = au_sbr(sb, bindex);
10089 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10090 + if (!h_path.dentry)
10092 + h_path.mnt = au_br_mnt(br);
10093 + au_dtime_store(&dt, a->dentry, &h_path);
10095 + br = au_sbr(sb, btop);
10096 + if (!au_br_writable(br->br_perm))
10098 + h_path.dentry = au_h_dptr(a->dentry, btop);
10099 + h_path.mnt = au_br_mnt(br);
10100 + err = vfsub_mnt_want_write(h_path.mnt);
10103 + hdir = au_hi(dir, btop);
10104 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10105 + h_dir = au_h_iptr(dir, btop);
10106 + if (h_dir->i_nlink
10107 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10108 + dt.dt_h_path = h_path;
10109 + au_dtime_revert(&dt);
10111 + au_hn_inode_unlock(hdir);
10112 + vfsub_mnt_drop_write(h_path.mnt);
10113 + au_cpup_attr_timesizes(dir);
10116 + aufs_read_unlock(a->dentry, AuLock_DW);
10119 + au_nwt_done(&au_sbi(sb)->si_nowait);
10120 + au_kfree_try_rcu(arg);
10123 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10125 + int perm, wkq_err;
10126 + aufs_bindex_t btop;
10127 + struct au_dir_ts_arg *arg;
10128 + struct dentry *dentry;
10129 + struct super_block *sb;
10133 + dentry = d_find_any_alias(dir);
10134 + AuDebugOn(!dentry);
10135 + sb = dentry->d_sb;
10136 + btop = au_ibtop(dir);
10137 + if (btop == bindex) {
10138 + au_cpup_attr_timesizes(dir);
10142 + perm = au_sbr_perm(sb, btop);
10143 + if (!au_br_writable(perm))
10146 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10150 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10151 + arg->brid = au_sbr_id(sb, bindex);
10152 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10153 + if (unlikely(wkq_err)) {
10154 + pr_err("wkq %d\n", wkq_err);
10156 + au_kfree_try_rcu(arg);
10163 +/* ---------------------------------------------------------------------- */
10165 +static int reopen_dir(struct file *file)
10168 + unsigned int flags;
10169 + aufs_bindex_t bindex, btail, btop;
10170 + struct dentry *dentry, *h_dentry;
10171 + struct file *h_file;
10173 + /* open all lower dirs */
10174 + dentry = file->f_path.dentry;
10175 + btop = au_dbtop(dentry);
10176 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10177 + au_set_h_fptr(file, bindex, NULL);
10178 + au_set_fbtop(file, btop);
10180 + btail = au_dbtaildir(dentry);
10181 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10182 + au_set_h_fptr(file, bindex, NULL);
10183 + au_set_fbbot_dir(file, btail);
10185 + flags = vfsub_file_flags(file);
10186 + for (bindex = btop; bindex <= btail; bindex++) {
10187 + h_dentry = au_h_dptr(dentry, bindex);
10190 + h_file = au_hf_dir(file, bindex);
10194 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10195 + err = PTR_ERR(h_file);
10196 + if (IS_ERR(h_file))
10197 + goto out; /* close all? */
10198 + au_set_h_fptr(file, bindex, h_file);
10200 + au_update_figen(file);
10201 + /* todo: necessary? */
10202 + /* file->f_ra = h_file->f_ra; */
10209 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10212 + aufs_bindex_t bindex, btail;
10213 + struct dentry *dentry, *h_dentry;
10214 + struct vfsmount *mnt;
10216 + FiMustWriteLock(file);
10217 + AuDebugOn(h_file);
10220 + mnt = file->f_path.mnt;
10221 + dentry = file->f_path.dentry;
10222 + file->f_version = inode_query_iversion(d_inode(dentry));
10223 + bindex = au_dbtop(dentry);
10224 + au_set_fbtop(file, bindex);
10225 + btail = au_dbtaildir(dentry);
10226 + au_set_fbbot_dir(file, btail);
10227 + for (; !err && bindex <= btail; bindex++) {
10228 + h_dentry = au_h_dptr(dentry, bindex);
10232 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10233 + if (unlikely(err))
10235 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10236 + if (IS_ERR(h_file)) {
10237 + err = PTR_ERR(h_file);
10240 + au_set_h_fptr(file, bindex, h_file);
10242 + au_update_figen(file);
10243 + /* todo: necessary? */
10244 + /* file->f_ra = h_file->f_ra; */
10246 + return 0; /* success */
10249 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10250 + au_set_h_fptr(file, bindex, NULL);
10251 + au_set_fbtop(file, -1);
10252 + au_set_fbbot_dir(file, -1);
10257 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10258 + struct file *file)
10261 + struct super_block *sb;
10262 + struct au_fidir *fidir;
10265 + sb = file->f_path.dentry->d_sb;
10266 + si_read_lock(sb, AuLock_FLUSH);
10267 + fidir = au_fidir_alloc(sb);
10269 + struct au_do_open_args args = {
10270 + .open = do_open_dir,
10273 + err = au_do_open(file, &args);
10274 + if (unlikely(err))
10275 + au_kfree_rcu(fidir);
10277 + si_read_unlock(sb);
10281 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10282 + struct file *file)
10284 + struct au_vdir *vdir_cache;
10285 + struct au_finfo *finfo;
10286 + struct au_fidir *fidir;
10287 + struct au_hfile *hf;
10288 + aufs_bindex_t bindex, bbot;
10290 + finfo = au_fi(file);
10291 + fidir = finfo->fi_hdir;
10293 + au_hbl_del(&finfo->fi_hlist,
10294 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10295 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10297 + au_vdir_free(vdir_cache);
10299 + bindex = finfo->fi_btop;
10300 + if (bindex >= 0) {
10301 + hf = fidir->fd_hfile + bindex;
10303 + * calls fput() instead of filp_close(),
10304 + * since no dnotify or lock for the lower file.
10306 + bbot = fidir->fd_bbot;
10307 + for (; bindex <= bbot; bindex++, hf++)
10309 + au_hfput(hf, /*execed*/0);
10311 + au_kfree_rcu(fidir);
10312 + finfo->fi_hdir = NULL;
10314 + au_finfo_fin(file);
10318 +/* ---------------------------------------------------------------------- */
10320 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10323 + aufs_bindex_t bindex, bbot;
10324 + struct file *h_file;
10327 + bbot = au_fbbot_dir(file);
10328 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10329 + h_file = au_hf_dir(file, bindex);
10331 + err = vfsub_flush(h_file, id);
10336 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10338 + return au_do_flush(file, id, au_do_flush_dir);
10341 +/* ---------------------------------------------------------------------- */
10343 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10346 + aufs_bindex_t bbot, bindex;
10347 + struct inode *inode;
10348 + struct super_block *sb;
10351 + sb = dentry->d_sb;
10352 + inode = d_inode(dentry);
10353 + IMustLock(inode);
10354 + bbot = au_dbbot(dentry);
10355 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10356 + struct path h_path;
10358 + if (au_test_ro(sb, bindex, inode))
10360 + h_path.dentry = au_h_dptr(dentry, bindex);
10361 + if (!h_path.dentry)
10364 + h_path.mnt = au_sbr_mnt(sb, bindex);
10365 + err = vfsub_fsync(NULL, &h_path, datasync);
10371 +static int au_do_fsync_dir(struct file *file, int datasync)
10374 + aufs_bindex_t bbot, bindex;
10375 + struct file *h_file;
10376 + struct super_block *sb;
10377 + struct inode *inode;
10379 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10380 + if (unlikely(err))
10383 + inode = file_inode(file);
10384 + sb = inode->i_sb;
10385 + bbot = au_fbbot_dir(file);
10386 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10387 + h_file = au_hf_dir(file, bindex);
10388 + if (!h_file || au_test_ro(sb, bindex, inode))
10391 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10399 + * @file may be NULL
10401 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10405 + struct dentry *dentry;
10406 + struct inode *inode;
10407 + struct super_block *sb;
10410 + dentry = file->f_path.dentry;
10411 + inode = d_inode(dentry);
10412 + inode_lock(inode);
10413 + sb = dentry->d_sb;
10414 + si_noflush_read_lock(sb);
10416 + err = au_do_fsync_dir(file, datasync);
10418 + di_write_lock_child(dentry);
10419 + err = au_do_fsync_dir_no_file(dentry, datasync);
10421 + au_cpup_attr_timesizes(inode);
10422 + di_write_unlock(dentry);
10424 + fi_write_unlock(file);
10426 + si_read_unlock(sb);
10427 + inode_unlock(inode);
10431 +/* ---------------------------------------------------------------------- */
10433 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10436 + struct dentry *dentry;
10437 + struct inode *inode, *h_inode;
10438 + struct super_block *sb;
10440 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10442 + dentry = file->f_path.dentry;
10443 + inode = d_inode(dentry);
10444 + IMustLock(inode);
10446 + sb = dentry->d_sb;
10447 + si_read_lock(sb, AuLock_FLUSH);
10448 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10449 + if (unlikely(err))
10451 + err = au_alive_dir(dentry);
10453 + err = au_vdir_init(file);
10454 + di_downgrade_lock(dentry, AuLock_IR);
10455 + if (unlikely(err))
10458 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10459 + if (!au_test_nfsd()) {
10460 + err = au_vdir_fill_de(file, ctx);
10461 + fsstack_copy_attr_atime(inode, h_inode);
10464 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10465 + * encode_fh() and others.
10467 + atomic_inc(&h_inode->i_count);
10468 + di_read_unlock(dentry, AuLock_IR);
10469 + si_read_unlock(sb);
10470 + err = au_vdir_fill_de(file, ctx);
10471 + fsstack_copy_attr_atime(inode, h_inode);
10472 + fi_write_unlock(file);
10480 + di_read_unlock(dentry, AuLock_IR);
10481 + fi_write_unlock(file);
10483 + si_read_unlock(sb);
10487 +/* ---------------------------------------------------------------------- */
10489 +#define AuTestEmpty_WHONLY 1
10490 +#define AuTestEmpty_CALLED (1 << 1)
10491 +#define AuTestEmpty_SHWH (1 << 2)
10492 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10493 +#define au_fset_testempty(flags, name) \
10494 + do { (flags) |= AuTestEmpty_##name; } while (0)
10495 +#define au_fclr_testempty(flags, name) \
10496 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10498 +#ifndef CONFIG_AUFS_SHWH
10499 +#undef AuTestEmpty_SHWH
10500 +#define AuTestEmpty_SHWH 0
10503 +struct test_empty_arg {
10504 + struct dir_context ctx;
10505 + struct au_nhash *whlist;
10506 + unsigned int flags;
10508 + aufs_bindex_t bindex;
10511 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10512 + int namelen, loff_t offset __maybe_unused, u64 ino,
10513 + unsigned int d_type)
10515 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10517 + char *name = (void *)__name;
10520 + au_fset_testempty(arg->flags, CALLED);
10522 + if (name[0] == '.'
10523 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10524 + goto out; /* success */
10526 + if (namelen <= AUFS_WH_PFX_LEN
10527 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10528 + if (au_ftest_testempty(arg->flags, WHONLY)
10529 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10530 + arg->err = -ENOTEMPTY;
10534 + name += AUFS_WH_PFX_LEN;
10535 + namelen -= AUFS_WH_PFX_LEN;
10536 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10537 + arg->err = au_nhash_append_wh
10538 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10539 + au_ftest_testempty(arg->flags, SHWH));
10543 + AuTraceErr(arg->err);
10547 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10550 + struct file *h_file;
10551 + struct au_branch *br;
10553 + h_file = au_h_open(dentry, arg->bindex,
10554 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10555 + /*file*/NULL, /*force_wr*/0);
10556 + err = PTR_ERR(h_file);
10557 + if (IS_ERR(h_file))
10561 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10562 + && !file_inode(h_file)->i_nlink)
10567 + au_fclr_testempty(arg->flags, CALLED);
10569 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10572 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10576 + br = au_sbr(dentry->d_sb, arg->bindex);
10577 + au_lcnt_dec(&br->br_nfiles);
10582 +struct do_test_empty_args {
10584 + struct dentry *dentry;
10585 + struct test_empty_arg *arg;
10588 +static void call_do_test_empty(void *args)
10590 + struct do_test_empty_args *a = args;
10591 + *a->errp = do_test_empty(a->dentry, a->arg);
10594 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10596 + int err, wkq_err;
10597 + struct dentry *h_dentry;
10598 + struct inode *h_inode;
10599 + struct user_namespace *h_userns;
10601 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10602 + h_dentry = au_h_dptr(dentry, arg->bindex);
10603 + h_inode = d_inode(h_dentry);
10604 + /* todo: i_mode changes anytime? */
10605 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10606 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10607 + inode_unlock_shared(h_inode);
10609 + err = do_test_empty(dentry, arg);
10611 + struct do_test_empty_args args = {
10613 + .dentry = dentry,
10616 + unsigned int flags = arg->flags;
10618 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10619 + if (unlikely(wkq_err))
10621 + arg->flags = flags;
10627 +int au_test_empty_lower(struct dentry *dentry)
10630 + unsigned int rdhash;
10631 + aufs_bindex_t bindex, btop, btail;
10632 + struct au_nhash whlist;
10633 + struct test_empty_arg arg = {
10635 + .actor = test_empty_cb
10638 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10640 + SiMustAnyLock(dentry->d_sb);
10642 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10644 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10645 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10646 + if (unlikely(err))
10650 + arg.whlist = &whlist;
10651 + btop = au_dbtop(dentry);
10652 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10653 + au_fset_testempty(arg.flags, SHWH);
10654 + test_empty = do_test_empty;
10655 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10656 + test_empty = sio_test_empty;
10657 + arg.bindex = btop;
10658 + err = test_empty(dentry, &arg);
10659 + if (unlikely(err))
10662 + au_fset_testempty(arg.flags, WHONLY);
10663 + btail = au_dbtaildir(dentry);
10664 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10665 + struct dentry *h_dentry;
10667 + h_dentry = au_h_dptr(dentry, bindex);
10668 + if (h_dentry && d_is_positive(h_dentry)) {
10669 + arg.bindex = bindex;
10670 + err = test_empty(dentry, &arg);
10675 + au_nhash_wh_free(&whlist);
10680 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10683 + struct test_empty_arg arg = {
10685 + .actor = test_empty_cb
10688 + aufs_bindex_t bindex, btail;
10691 + arg.whlist = whlist;
10692 + arg.flags = AuTestEmpty_WHONLY;
10693 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10694 + au_fset_testempty(arg.flags, SHWH);
10695 + btail = au_dbtaildir(dentry);
10696 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10697 + struct dentry *h_dentry;
10699 + h_dentry = au_h_dptr(dentry, bindex);
10700 + if (h_dentry && d_is_positive(h_dentry)) {
10701 + arg.bindex = bindex;
10702 + err = sio_test_empty(dentry, &arg);
10709 +/* ---------------------------------------------------------------------- */
10711 +const struct file_operations aufs_dir_fop = {
10712 + .owner = THIS_MODULE,
10713 + .llseek = default_llseek,
10714 + .read = generic_read_dir,
10715 + .iterate_shared = aufs_iterate_shared,
10716 + .unlocked_ioctl = aufs_ioctl_dir,
10717 +#ifdef CONFIG_COMPAT
10718 + .compat_ioctl = aufs_compat_ioctl_dir,
10720 + .open = aufs_open_dir,
10721 + .release = aufs_release_dir,
10722 + .flush = aufs_flush_dir,
10723 + .fsync = aufs_fsync_dir
10725 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10726 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10727 +++ linux/fs/aufs/dir.h 2022-10-26 22:30:38.462648858 +0200
10729 +/* SPDX-License-Identifier: GPL-2.0 */
10731 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10733 + * This program, aufs is free software; you can redistribute it and/or modify
10734 + * it under the terms of the GNU General Public License as published by
10735 + * the Free Software Foundation; either version 2 of the License, or
10736 + * (at your option) any later version.
10738 + * This program is distributed in the hope that it will be useful,
10739 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10740 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10741 + * GNU General Public License for more details.
10743 + * You should have received a copy of the GNU General Public License
10744 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10748 + * directory operations
10751 +#ifndef __AUFS_DIR_H__
10752 +#define __AUFS_DIR_H__
10756 +#include <linux/fs.h>
10758 +/* ---------------------------------------------------------------------- */
10760 +/* need to be faster and smaller */
10763 + unsigned int nh_num;
10764 + struct hlist_head *nh_head;
10767 +struct au_vdir_destr {
10768 + unsigned char len;
10769 + unsigned char name[];
10772 +struct au_vdir_dehstr {
10773 + struct hlist_node hash;
10774 + struct au_vdir_destr *str;
10775 + struct rcu_head rcu;
10776 +} ____cacheline_aligned_in_smp;
10778 +struct au_vdir_de {
10780 + unsigned char de_type;
10781 + /* caution: packed */
10782 + struct au_vdir_destr de_str;
10785 +struct au_vdir_wh {
10786 + struct hlist_node wh_hash;
10787 +#ifdef CONFIG_AUFS_SHWH
10789 + aufs_bindex_t wh_bindex;
10790 + unsigned char wh_type;
10792 + aufs_bindex_t wh_bindex;
10794 + /* caution: packed */
10795 + struct au_vdir_destr wh_str;
10798 +union au_vdir_deblk_p {
10799 + unsigned char *deblk;
10800 + struct au_vdir_de *de;
10804 + unsigned char **vd_deblk;
10805 + unsigned long vd_nblk;
10807 + unsigned long ul;
10808 + union au_vdir_deblk_p p;
10812 + unsigned int vd_deblk_sz;
10813 + unsigned long vd_jiffy;
10814 + struct rcu_head rcu;
10815 +} ____cacheline_aligned_in_smp;
10817 +/* ---------------------------------------------------------------------- */
10820 +extern const struct file_operations aufs_dir_fop;
10821 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10822 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10823 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10824 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10825 +int au_test_empty_lower(struct dentry *dentry);
10826 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10829 +unsigned int au_rdhash_est(loff_t sz);
10830 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10831 +void au_nhash_wh_free(struct au_nhash *whlist);
10832 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10834 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10835 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10836 + unsigned int d_type, aufs_bindex_t bindex,
10837 + unsigned char shwh);
10838 +void au_vdir_free(struct au_vdir *vdir);
10839 +int au_vdir_init(struct file *file);
10840 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10843 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10845 +#ifdef CONFIG_AUFS_RDU
10847 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10848 +#ifdef CONFIG_COMPAT
10849 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10850 + unsigned long arg);
10853 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10854 + unsigned int cmd, unsigned long arg)
10855 +#ifdef CONFIG_COMPAT
10856 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10857 + unsigned int cmd, unsigned long arg)
10861 +#endif /* __KERNEL__ */
10862 +#endif /* __AUFS_DIR_H__ */
10863 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10864 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10865 +++ linux/fs/aufs/dirren.c 2022-10-26 22:30:38.462648858 +0200
10867 +// SPDX-License-Identifier: GPL-2.0
10869 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10871 + * This program, aufs is free software; you can redistribute it and/or modify
10872 + * it under the terms of the GNU General Public License as published by
10873 + * the Free Software Foundation; either version 2 of the License, or
10874 + * (at your option) any later version.
10876 + * This program is distributed in the hope that it will be useful,
10877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10879 + * GNU General Public License for more details.
10881 + * You should have received a copy of the GNU General Public License
10882 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10886 + * special handling in renaming a directory
10887 + * in order to support looking-up the before-renamed name on the lower readonly
10891 +#include <linux/byteorder/generic.h>
10894 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10898 + idx = au_dr_ihash(ent->dr_h_ino);
10899 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10902 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10905 + struct hlist_bl_head *hbl;
10908 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10909 + hbl = dr->dr_h_ino + i;
10910 + hlist_bl_lock(hbl);
10911 + ret &= hlist_bl_empty(hbl);
10912 + hlist_bl_unlock(hbl);
10918 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10920 + struct au_dr_hino *found, *ent;
10921 + struct hlist_bl_head *hbl;
10922 + struct hlist_bl_node *pos;
10926 + idx = au_dr_ihash(ino);
10927 + hbl = dr->dr_h_ino + idx;
10928 + hlist_bl_lock(hbl);
10929 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10930 + if (ent->dr_h_ino == ino) {
10934 + hlist_bl_unlock(hbl);
10939 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10940 + struct au_dr_hino *add_ent)
10943 + struct hlist_bl_head *hbl;
10944 + struct hlist_bl_node *pos;
10945 + struct au_dr_hino *ent;
10948 + idx = au_dr_ihash(ino);
10949 + hbl = dr->dr_h_ino + idx;
10950 +#if 0 /* debug print */
10952 + struct hlist_bl_node *tmp;
10954 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10955 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10958 + hlist_bl_lock(hbl);
10959 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10960 + if (ent->dr_h_ino == ino) {
10964 + if (!found && add_ent)
10965 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10966 + hlist_bl_unlock(hbl);
10968 + if (!found && add_ent)
10969 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10974 +void au_dr_hino_free(struct au_dr_br *dr)
10977 + struct hlist_bl_head *hbl;
10978 + struct hlist_bl_node *pos, *tmp;
10979 + struct au_dr_hino *ent;
10981 + /* SiMustWriteLock(sb); */
10983 + for (i = 0; i < AuDirren_NHASH; i++) {
10984 + hbl = dr->dr_h_ino + i;
10985 + /* no spinlock since sbinfo must be write-locked */
10986 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10987 + au_kfree_rcu(ent);
10988 + INIT_HLIST_BL_HEAD(hbl);
10992 +/* returns the number of inodes or an error */
10993 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10994 + struct file *hinofile)
10998 + loff_t pos, oldsize;
11000 + struct inode *hinoinode;
11001 + struct hlist_bl_head *hbl;
11002 + struct hlist_bl_node *n1, *n2;
11003 + struct au_dr_hino *ent;
11005 + SiMustWriteLock(sb);
11006 + AuDebugOn(!au_br_writable(br->br_perm));
11008 + hinoinode = file_inode(hinofile);
11009 + oldsize = i_size_read(hinoinode);
11013 + hbl = br->br_dirren.dr_h_ino;
11014 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11015 + /* no bit-lock since sbinfo must be write-locked */
11016 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11017 + AuDbg("hi%llu, %pD2\n",
11018 + (unsigned long long)ent->dr_h_ino, hinofile);
11019 + u64 = cpu_to_be64(ent->dr_h_ino);
11020 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11021 + if (ssz == sizeof(u64))
11024 + /* write error */
11025 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11032 + /* regardless the error */
11033 + if (pos < oldsize) {
11034 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11042 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11049 + struct au_dr_hino *ent;
11050 + struct inode *hinoinode;
11051 + struct hlist_bl_head *hbl;
11055 + hbl = dr->dr_h_ino;
11056 + hinoinode = file_inode(hinofile);
11057 + sz = i_size_read(hinoinode);
11058 + AuDebugOn(sz % sizeof(u64));
11059 + n = sz / sizeof(u64);
11061 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11062 + if (unlikely(ssz != sizeof(u64))) {
11063 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11070 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11076 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11077 + AuDbg("hi%llu, %pD2\n",
11078 + (unsigned long long)ent->dr_h_ino, hinofile);
11079 + hidx = au_dr_ihash(ent->dr_h_ino);
11080 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11082 + goto out; /* success */
11085 + au_dr_hino_free(dr);
11092 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11093 + * @path is a switch to distinguish load and store.
11095 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11096 + struct au_branch *br, const struct path *path)
11099 + unsigned char load, suspend;
11100 + struct file *hinofile;
11101 + struct au_hinode *hdir;
11102 + struct inode *dir, *delegated;
11103 + struct path hinopath;
11104 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11105 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11107 + AuDebugOn(bindex < 0 && !br);
11108 + AuDebugOn(bindex >= 0 && br);
11113 + br = au_sbr(sb, bindex);
11116 + path = &br->br_path;
11117 + AuDebugOn(!au_br_writable(br->br_perm));
11118 + if (unlikely(!au_br_writable(br->br_perm)))
11124 + dir = d_inode(sb->s_root);
11125 + hdir = au_hinode(au_ii(dir), bindex);
11126 + dir = hdir->hi_inode;
11127 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11129 + dir = d_inode(path->dentry);
11130 + inode_lock_nested(dir, AuLsc_I_CHILD);
11132 + hinopath.mnt = path->mnt;
11133 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11134 + err = PTR_ERR(hinopath.dentry);
11135 + if (IS_ERR(hinopath.dentry))
11139 + flags = O_RDONLY;
11141 + if (d_is_negative(hinopath.dentry))
11142 + goto out_dput; /* success */
11144 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11145 + if (d_is_positive(hinopath.dentry)) {
11146 + delegated = NULL;
11147 + err = vfsub_unlink(dir, &hinopath, &delegated,
11150 + if (unlikely(err))
11151 + pr_err("ignored err %d, %pd2\n",
11152 + err, hinopath.dentry);
11153 + if (unlikely(err == -EWOULDBLOCK))
11158 + } else if (!d_is_positive(hinopath.dentry)) {
11159 + err = vfsub_create(dir, &hinopath, 0600,
11160 + /*want_excl*/false);
11162 + if (unlikely(err))
11165 + flags = O_WRONLY;
11167 + hinofile = vfsub_dentry_open(&hinopath, flags);
11169 + au_hn_inode_unlock(hdir);
11171 + inode_unlock(dir);
11172 + dput(hinopath.dentry);
11173 + AuTraceErrPtr(hinofile);
11174 + if (IS_ERR(hinofile)) {
11175 + err = PTR_ERR(hinofile);
11180 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11182 + err = au_dr_hino_store(sb, br, hinofile);
11187 + dput(hinopath.dentry);
11190 + au_hn_inode_unlock(hdir);
11192 + inode_unlock(dir);
11198 +/* ---------------------------------------------------------------------- */
11200 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11203 + struct kstatfs kstfs;
11205 + struct dentry *dentry;
11206 + struct super_block *sb;
11208 + err = vfs_statfs((void *)path, &kstfs);
11210 + if (unlikely(err))
11213 + /* todo: support for UUID */
11215 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11216 + brid->type = AuBrid_FSID;
11217 + brid->fsid = kstfs.f_fsid;
11219 + dentry = path->dentry;
11220 + sb = dentry->d_sb;
11223 + brid->type = AuBrid_DEV;
11232 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11233 + const struct path *path)
11236 + struct au_dr_br *dr;
11237 + struct hlist_bl_head *hbl;
11239 + dr = &br->br_dirren;
11240 + hbl = dr->dr_h_ino;
11241 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11242 + INIT_HLIST_BL_HEAD(hbl);
11244 + err = au_dr_brid_init(&dr->dr_brid, path);
11245 + if (unlikely(err))
11248 + if (au_opt_test(au_mntflags(sb), DIRREN))
11249 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11256 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11261 + if (au_br_writable(br->br_perm))
11262 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11264 + au_dr_hino_free(&br->br_dirren);
11269 +/* ---------------------------------------------------------------------- */
11271 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11272 + char *buf, size_t sz)
11275 + unsigned int major, minor;
11279 + err = snprintf(p, sz, "%d_", brid->type);
11280 + AuDebugOn(err > sz);
11283 + switch (brid->type) {
11284 + case AuBrid_Unset:
11286 + case AuBrid_UUID:
11287 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11289 + case AuBrid_FSID:
11290 + err = snprintf(p, sz, "%08x-%08x",
11291 + brid->fsid.val[0], brid->fsid.val[1]);
11294 + major = MAJOR(brid->dev);
11295 + minor = MINOR(brid->dev);
11296 + if (major <= 0xff && minor <= 0xff)
11297 + err = snprintf(p, sz, "%02x%02x", major, minor);
11299 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11302 + AuDebugOn(err > sz);
11305 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11306 + AuDebugOn(err > sz);
11313 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11316 + struct dentry *br_dentry;
11317 + struct inode *br_inode;
11319 + br_dentry = au_br_dentry(br);
11320 + br_inode = d_inode(br_dentry);
11321 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11322 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11323 + AuDebugOn(rlen > len);
11328 +/* ---------------------------------------------------------------------- */
11331 + * from the given @h_dentry, construct drinfo at @*fdata.
11332 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11335 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11336 + struct dentry *h_dentry,
11337 + unsigned char *allocated)
11340 + struct au_drinfo_fdata *f, *p;
11341 + struct au_drinfo *drinfo;
11342 + struct inode *h_inode;
11343 + struct qstr *qname;
11347 + h_inode = d_inode(h_dentry);
11348 + qname = &h_dentry->d_name;
11349 + drinfo = &f->drinfo;
11350 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11351 + drinfo->oldnamelen = qname->len;
11352 + if (*allocated < sizeof(*f) + qname->len) {
11353 + v = roundup_pow_of_two(*allocated + qname->len);
11354 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11355 + if (unlikely(!p)) {
11363 + drinfo = &f->drinfo;
11365 + memcpy(drinfo->oldname, qname->name, qname->len);
11366 + AuDbg("i%llu, %.*s\n",
11367 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11368 + drinfo->oldname);
11375 +/* callers have to free the return value */
11376 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11378 + struct au_drinfo *ret, *drinfo;
11379 + struct au_drinfo_fdata fdata;
11384 + ret = ERR_PTR(-EIO);
11386 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11387 + if (unlikely(ssz != sizeof(fdata))) {
11388 + AuIOErr("ssz %zd, %u, %pD2\n",
11389 + ssz, (unsigned int)sizeof(fdata), file);
11393 + fdata.magic = ntohl((__force __be32)fdata.magic);
11394 + switch (fdata.magic) {
11395 + case AUFS_DRINFO_MAGIC_V1:
11398 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11399 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11403 + drinfo = &fdata.drinfo;
11404 + len = drinfo->oldnamelen;
11406 + AuIOErr("broken drinfo %pD2\n", file);
11411 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11412 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11413 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11414 + (unsigned long long)drinfo->ino,
11415 + (unsigned long long)h_ino, file);
11416 + goto out; /* success */
11419 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11420 + if (unlikely(!ret)) {
11421 + ret = ERR_PTR(-ENOMEM);
11422 + AuTraceErrPtr(ret);
11427 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11428 + if (unlikely(ssz != len)) {
11429 + au_kfree_rcu(ret);
11430 + ret = ERR_PTR(-EIO);
11431 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11435 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11441 +/* ---------------------------------------------------------------------- */
11443 +/* in order to be revertible */
11444 +struct au_drinfo_rev_elm {
11446 + struct dentry *info_dentry;
11447 + struct au_drinfo *info_last;
11450 +struct au_drinfo_rev {
11451 + unsigned char already;
11452 + aufs_bindex_t nelm;
11453 + struct au_drinfo_rev_elm elm[];
11456 +/* todo: isn't it too large? */
11457 +struct au_drinfo_store {
11458 + struct path h_ppath;
11459 + struct dentry *h_dentry;
11460 + struct au_drinfo_fdata *fdata;
11461 + char *infoname; /* inside of whname, just after PFX */
11462 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11463 + aufs_bindex_t btgt, btail;
11464 + unsigned char no_sio,
11465 + allocated, /* current size of *fdata */
11466 + infonamelen, /* room size for p */
11467 + whnamelen, /* length of the generated name */
11468 + renameback; /* renamed back */
11471 +/* on rename(2) error, the caller should revert it using @elm */
11472 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11473 + struct au_drinfo_rev_elm *elm)
11478 + struct path infopath = {
11479 + .mnt = w->h_ppath.mnt
11481 + struct inode *h_dir, *h_inode, *delegated;
11482 + struct file *infofile;
11483 + struct qstr *qname;
11486 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11488 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11490 + AuTraceErrPtr(infopath.dentry);
11491 + if (IS_ERR(infopath.dentry)) {
11492 + err = PTR_ERR(infopath.dentry);
11497 + h_dir = d_inode(w->h_ppath.dentry);
11498 + if (elm && d_is_negative(infopath.dentry)) {
11499 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11501 + if (unlikely(err))
11503 + elm->created = 1;
11504 + elm->info_dentry = dget(infopath.dentry);
11507 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11508 + AuTraceErrPtr(infofile);
11509 + if (IS_ERR(infofile)) {
11510 + err = PTR_ERR(infofile);
11514 + h_inode = d_inode(infopath.dentry);
11515 + if (elm && i_size_read(h_inode)) {
11516 + h_inode = d_inode(w->h_dentry);
11517 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11518 + AuTraceErrPtr(elm->info_last);
11519 + if (IS_ERR(elm->info_last)) {
11520 + err = PTR_ERR(elm->info_last);
11521 + elm->info_last = NULL;
11522 + AuDebugOn(elm->info_dentry);
11527 + if (elm && w->renameback) {
11528 + delegated = NULL;
11529 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11531 + if (unlikely(err == -EWOULDBLOCK))
11537 + qname = &w->h_dentry->d_name;
11538 + len = sizeof(*w->fdata) + qname->len;
11540 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11541 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11542 + if (ssz == len) {
11543 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11544 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11545 + goto out_fput; /* success */
11550 + /* the caller should revert it using @elm */
11556 + dput(infopath.dentry);
11562 +struct au_call_drinfo_do_store_args {
11564 + struct au_drinfo_store *w;
11565 + struct au_drinfo_rev_elm *elm;
11568 +static void au_call_drinfo_do_store(void *args)
11570 + struct au_call_drinfo_do_store_args *a = args;
11572 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11575 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11576 + struct au_drinfo_rev_elm *elm)
11578 + int err, wkq_err;
11581 + err = au_drinfo_do_store(w, elm);
11583 + struct au_call_drinfo_do_store_args a = {
11588 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11589 + if (unlikely(wkq_err))
11597 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11598 + aufs_bindex_t btgt)
11602 + memset(w, 0, sizeof(*w));
11603 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11604 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11605 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11606 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11608 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11611 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11612 + if (unlikely(!w->fdata)) {
11616 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11623 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11625 + au_kfree_rcu(w->fdata);
11628 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11629 + struct au_drinfo_store *w)
11631 + struct au_drinfo_rev_elm *elm;
11632 + struct inode *h_dir, *delegated;
11634 + struct path infopath = {
11635 + .mnt = w->h_ppath.mnt
11638 + h_dir = d_inode(w->h_ppath.dentry);
11639 + IMustLock(h_dir);
11643 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11644 + AuDebugOn(elm->created && elm->info_last);
11645 + if (elm->created) {
11647 + delegated = NULL;
11648 + infopath.dentry = elm->info_dentry;
11649 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11652 + if (unlikely(err == -EWOULDBLOCK))
11654 + dput(elm->info_dentry);
11655 + } else if (elm->info_last) {
11657 + w->fdata->drinfo = *elm->info_last;
11658 + memcpy(w->fdata->drinfo.oldname,
11659 + elm->info_last->oldname,
11660 + elm->info_last->oldnamelen);
11661 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11662 + au_kfree_rcu(elm->info_last);
11664 + if (unlikely(err))
11665 + AuIOErr("%d, %s\n", err, w->whname);
11666 + /* go on even if err */
11670 +/* caller has to call au_dr_rename_fin() later */
11671 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11672 + struct qstr *dst_name, void *_rev)
11674 + int err, sz, nelm;
11675 + aufs_bindex_t bindex, btail;
11676 + struct au_drinfo_store work;
11677 + struct au_drinfo_rev *rev, **p;
11678 + struct au_drinfo_rev_elm *elm;
11679 + struct super_block *sb;
11680 + struct au_branch *br;
11681 + struct au_hinode *hdir;
11683 + err = au_drinfo_store_work_init(&work, btgt);
11685 + if (unlikely(err))
11689 + btail = au_dbtaildir(dentry);
11690 + nelm = btail - btgt;
11691 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11692 + rev = kcalloc(1, sz, GFP_NOFS);
11693 + if (unlikely(!rev)) {
11697 + rev->nelm = nelm;
11703 + sb = dentry->d_sb;
11704 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11705 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11706 + hdir = au_hi(d_inode(dentry), btgt);
11707 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11708 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11709 + work.h_dentry = au_h_dptr(dentry, bindex);
11710 + if (!work.h_dentry)
11713 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11714 + &work.allocated);
11716 + if (unlikely(err))
11719 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11720 + br = au_sbr(sb, bindex);
11721 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11722 + work.whnamelen += au_drinfo_name(br, work.infoname,
11723 + work.infonamelen);
11724 + AuDbg("whname %.*s, i%llu, %.*s\n",
11725 + work.whnamelen, work.whname,
11726 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11727 + work.fdata->drinfo.oldnamelen,
11728 + work.fdata->drinfo.oldname);
11730 + err = au_drinfo_store_sio(&work, elm);
11732 + if (unlikely(err))
11735 + if (unlikely(err)) {
11736 + /* revert all drinfo */
11737 + au_drinfo_store_rev(rev, &work);
11738 + au_kfree_try_rcu(rev);
11741 + au_hn_inode_unlock(hdir);
11744 + au_drinfo_store_work_fin(&work);
11749 +/* ---------------------------------------------------------------------- */
11751 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11752 + struct qstr *dst_name, void *_rev)
11754 + int err, already;
11756 + struct super_block *sb;
11757 + struct au_branch *br;
11758 + struct au_dr_br *dr;
11759 + struct dentry *h_dentry;
11760 + struct inode *h_inode;
11761 + struct au_dr_hino *ent;
11762 + struct au_drinfo_rev *rev, **p;
11764 + AuDbg("bindex %d\n", bindex);
11767 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11768 + if (unlikely(!ent))
11772 + br = au_sbr(sb, bindex);
11773 + dr = &br->br_dirren;
11774 + h_dentry = au_h_dptr(src, bindex);
11775 + h_inode = d_inode(h_dentry);
11776 + ino = h_inode->i_ino;
11777 + ent->dr_h_ino = ino;
11778 + already = au_dr_hino_test_add(dr, ino, ent);
11779 + AuDbg("b%d, hi%llu, already %d\n",
11780 + bindex, (unsigned long long)ino, already);
11782 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11787 + rev->already = already;
11788 + goto out; /* success */
11793 + au_dr_hino_del(dr, ent);
11794 + au_kfree_rcu(ent);
11801 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11803 + struct au_drinfo_rev *rev;
11804 + struct au_drinfo_rev_elm *elm;
11809 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11810 + dput(elm->info_dentry);
11811 + au_kfree_rcu(elm->info_last);
11813 + au_kfree_try_rcu(rev);
11816 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11819 + struct au_drinfo_store work;
11820 + struct au_drinfo_rev *rev = _rev;
11821 + struct super_block *sb;
11822 + struct au_branch *br;
11823 + struct inode *h_inode;
11824 + struct au_dr_br *dr;
11825 + struct au_dr_hino *ent;
11827 + err = au_drinfo_store_work_init(&work, btgt);
11828 + if (unlikely(err))
11832 + br = au_sbr(sb, btgt);
11833 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11834 + work.h_ppath.mnt = au_br_mnt(br);
11835 + au_drinfo_store_rev(rev, &work);
11836 + au_drinfo_store_work_fin(&work);
11837 + if (rev->already)
11840 + dr = &br->br_dirren;
11841 + h_inode = d_inode(work.h_ppath.dentry);
11842 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11844 + au_dr_hino_del(dr, ent);
11845 + au_kfree_rcu(ent);
11848 + au_kfree_try_rcu(rev);
11849 + if (unlikely(err))
11850 + pr_err("failed to remove dirren info\n");
11853 +/* ---------------------------------------------------------------------- */
11855 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11856 + char *whname, int whnamelen,
11857 + struct dentry **info_dentry)
11859 + struct au_drinfo *drinfo;
11861 + struct inode *h_dir;
11862 + struct path infopath;
11865 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11867 + *info_dentry = NULL;
11870 + h_dir = d_inode(h_ppath->dentry);
11871 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11872 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11873 + if (IS_ERR(infopath.dentry)) {
11874 + drinfo = (void *)infopath.dentry;
11878 + if (d_is_negative(infopath.dentry))
11879 + goto out_dput; /* success */
11881 + infopath.mnt = h_ppath->mnt;
11882 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11883 + inode_unlock_shared(h_dir);
11886 + drinfo = (void *)f;
11890 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11891 + if (IS_ERR_OR_NULL(drinfo))
11894 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11895 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11900 + dput(infopath.dentry);
11903 + inode_unlock_shared(h_dir);
11904 + AuTraceErrPtr(drinfo);
11908 +struct au_drinfo_do_load_args {
11909 + struct au_drinfo **drinfop;
11910 + struct path *h_ppath;
11913 + struct dentry **info_dentry;
11916 +static void au_call_drinfo_do_load(void *args)
11918 + struct au_drinfo_do_load_args *a = args;
11920 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11924 +struct au_drinfo_load {
11925 + struct path h_ppath;
11926 + struct qstr *qname;
11927 + unsigned char no_sio;
11929 + aufs_bindex_t ninfo;
11930 + struct au_drinfo **drinfo;
11933 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11934 + struct au_branch *br)
11936 + int err, wkq_err, whnamelen, e;
11937 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11938 + = AUFS_WH_DR_INFO_PFX;
11939 + struct au_drinfo *drinfo;
11940 + struct qstr oldname;
11941 + struct inode *h_dir, *delegated;
11942 + struct dentry *info_dentry;
11943 + struct path infopath;
11945 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11946 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11947 + sizeof(whname) - whnamelen);
11949 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11952 + struct au_drinfo_do_load_args args = {
11953 + .drinfop = &drinfo,
11954 + .h_ppath = &w->h_ppath,
11955 + .whname = whname,
11956 + .whnamelen = whnamelen,
11957 + .info_dentry = &info_dentry
11959 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11960 + if (unlikely(wkq_err))
11961 + drinfo = ERR_PTR(wkq_err);
11963 + err = PTR_ERR(drinfo);
11964 + if (IS_ERR_OR_NULL(drinfo))
11968 + oldname.len = drinfo->oldnamelen;
11969 + oldname.name = drinfo->oldname;
11970 + if (au_qstreq(w->qname, &oldname)) {
11971 + /* the name is renamed back */
11972 + au_kfree_rcu(drinfo);
11975 + infopath.dentry = info_dentry;
11976 + infopath.mnt = w->h_ppath.mnt;
11977 + h_dir = d_inode(w->h_ppath.dentry);
11978 + delegated = NULL;
11979 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11980 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11981 + inode_unlock(h_dir);
11983 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11984 + if (unlikely(e == -EWOULDBLOCK))
11987 + au_kfree_rcu(w->drinfo[bindex]);
11988 + w->drinfo[bindex] = drinfo;
11989 + dput(info_dentry);
11996 +/* ---------------------------------------------------------------------- */
11998 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12000 + struct au_drinfo **p = drinfo;
12003 + au_kfree_rcu(*drinfo++);
12004 + au_kfree_try_rcu(p);
12007 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12008 + aufs_bindex_t btgt)
12011 + struct au_drinfo_load w;
12012 + aufs_bindex_t bindex, bbot;
12013 + struct au_branch *br;
12014 + struct inode *h_dir;
12015 + struct au_dr_hino *ent;
12016 + struct super_block *sb;
12018 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12019 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12020 + AuLNPair(&lkup->whname), btgt);
12022 + sb = dentry->d_sb;
12023 + bbot = au_sbbot(sb);
12024 + w.ninfo = bbot + 1;
12025 + if (!lkup->dirren.drinfo) {
12026 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12027 + sizeof(*lkup->dirren.drinfo),
12029 + if (unlikely(!lkup->dirren.drinfo)) {
12033 + lkup->dirren.ninfo = w.ninfo;
12035 + w.drinfo = lkup->dirren.drinfo;
12036 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12037 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12038 + AuDebugOn(!w.h_ppath.dentry);
12039 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12040 + w.qname = &dentry->d_name;
12043 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12044 + br = au_sbr(sb, bindex);
12045 + err = au_drinfo_load(&w, bindex, br);
12046 + if (unlikely(err))
12048 + if (w.drinfo[bindex])
12052 + br = au_sbr(sb, btgt);
12053 + h_dir = d_inode(w.h_ppath.dentry);
12054 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12056 + au_dr_hino_del(&br->br_dirren, ent);
12057 + au_kfree_rcu(ent);
12059 + goto out; /* success */
12062 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12063 + lkup->dirren.ninfo = 0;
12064 + lkup->dirren.drinfo = NULL;
12070 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12072 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12075 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12078 + struct au_drinfo *drinfo;
12081 + if (!lkup->dirren.drinfo)
12083 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12084 + drinfo = lkup->dirren.drinfo[btgt];
12088 + au_kfree_try_rcu(lkup->whname.name);
12089 + lkup->whname.name = NULL;
12090 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12091 + lkup->dirren.dr_name.name = drinfo->oldname;
12092 + lkup->name = &lkup->dirren.dr_name;
12093 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12095 + AuDbg("name %.*s, whname %.*s, b%d\n",
12096 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12104 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12108 + struct au_drinfo *drinfo;
12111 + if (!lkup->dirren.drinfo)
12113 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12114 + drinfo = lkup->dirren.drinfo[bindex];
12118 + match = (drinfo->ino == h_ino);
12119 + AuDbg("match %d\n", match);
12125 +/* ---------------------------------------------------------------------- */
12127 +int au_dr_opt_set(struct super_block *sb)
12130 + aufs_bindex_t bindex, bbot;
12131 + struct au_branch *br;
12134 + bbot = au_sbbot(sb);
12135 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12136 + br = au_sbr(sb, bindex);
12137 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12143 +int au_dr_opt_flush(struct super_block *sb)
12146 + aufs_bindex_t bindex, bbot;
12147 + struct au_branch *br;
12150 + bbot = au_sbbot(sb);
12151 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12152 + br = au_sbr(sb, bindex);
12153 + if (au_br_writable(br->br_perm))
12154 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12160 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12163 + aufs_bindex_t bindex, bbot;
12164 + struct au_branch *br;
12168 + err = au_dr_opt_flush(sb);
12169 + if (unlikely(err))
12173 + bbot = au_sbbot(sb);
12174 + for (bindex = 0; bindex <= bbot; bindex++) {
12175 + br = au_sbr(sb, bindex);
12176 + au_dr_hino_free(&br->br_dirren);
12182 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12183 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12184 +++ linux/fs/aufs/dirren.h 2022-10-26 22:30:38.465982192 +0200
12186 +/* SPDX-License-Identifier: GPL-2.0 */
12188 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12190 + * This program, aufs is free software; you can redistribute it and/or modify
12191 + * it under the terms of the GNU General Public License as published by
12192 + * the Free Software Foundation; either version 2 of the License, or
12193 + * (at your option) any later version.
12195 + * This program is distributed in the hope that it will be useful,
12196 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12197 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12198 + * GNU General Public License for more details.
12200 + * You should have received a copy of the GNU General Public License
12201 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12205 + * renamed dir info
12208 +#ifndef __AUFS_DIRREN_H__
12209 +#define __AUFS_DIRREN_H__
12213 +#include <linux/dcache.h>
12214 +#include <linux/statfs.h>
12215 +#include <linux/uuid.h>
12218 +#define AuDirren_NHASH 100
12220 +#ifdef CONFIG_AUFS_DIRREN
12221 +enum au_brid_type {
12228 +struct au_dr_brid {
12229 + enum au_brid_type type;
12231 + uuid_t uuid; /* unimplemented yet */
12237 +/* 20 is the max digits length of ulong 64 */
12238 +/* brid-type "_" uuid "_" inum */
12239 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12240 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12242 +struct au_dr_hino {
12243 + struct hlist_bl_node dr_hnode;
12248 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12249 + struct au_dr_brid dr_brid;
12252 +struct au_dr_lookup {
12253 + /* dr_name is pointed by struct au_do_lookup_args.name */
12254 + struct qstr dr_name; /* subset of dr_info */
12255 + aufs_bindex_t ninfo;
12256 + struct au_drinfo **drinfo;
12259 +struct au_dr_hino;
12261 +struct au_dr_br { };
12262 +struct au_dr_lookup { };
12265 +/* ---------------------------------------------------------------------- */
12268 +struct au_do_lookup_args;
12270 +#ifdef CONFIG_AUFS_DIRREN
12271 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12272 + struct au_dr_hino *add_ent);
12273 +void au_dr_hino_free(struct au_dr_br *dr);
12274 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12275 + const struct path *path);
12276 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12277 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12278 + struct qstr *dst_name, void *_rev);
12279 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12280 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12281 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12282 + aufs_bindex_t bindex);
12283 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12284 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12286 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12287 +int au_dr_opt_set(struct super_block *sb);
12288 +int au_dr_opt_flush(struct super_block *sb);
12289 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12291 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12292 + struct au_dr_hino *add_ent);
12293 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12294 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12295 + const struct path *path);
12296 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12297 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12298 + struct qstr *dst_name, void *_rev);
12299 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12300 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12302 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12303 + aufs_bindex_t bindex);
12304 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12305 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12306 + aufs_bindex_t bindex, ino_t h_ino);
12307 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12308 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12309 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12310 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12313 +/* ---------------------------------------------------------------------- */
12315 +#ifdef CONFIG_AUFS_DIRREN
12316 +static inline int au_dr_ihash(ino_t h_ino)
12318 + return h_ino % AuDirren_NHASH;
12321 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12324 +#endif /* __KERNEL__ */
12325 +#endif /* __AUFS_DIRREN_H__ */
12326 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12327 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12328 +++ linux/fs/aufs/dynop.c 2022-10-26 22:30:38.465982192 +0200
12330 +// SPDX-License-Identifier: GPL-2.0
12332 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12334 + * This program, aufs is free software; you can redistribute it and/or modify
12335 + * it under the terms of the GNU General Public License as published by
12336 + * the Free Software Foundation; either version 2 of the License, or
12337 + * (at your option) any later version.
12339 + * This program is distributed in the hope that it will be useful,
12340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12342 + * GNU General Public License for more details.
12344 + * You should have received a copy of the GNU General Public License
12345 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12349 + * dynamically customizable operations for regular files
12354 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12357 + * How large will these lists be?
12358 + * Usually just a few elements, 20-30 at most for each, I guess.
12360 +static struct hlist_bl_head dynop[AuDyLast];
12362 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12363 + const void *h_op)
12365 + struct au_dykey *key, *tmp;
12366 + struct hlist_bl_node *pos;
12369 + hlist_bl_lock(hbl);
12370 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12371 + if (tmp->dk_op.dy_hop == h_op) {
12372 + if (kref_get_unless_zero(&tmp->dk_kref))
12376 + hlist_bl_unlock(hbl);
12381 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12383 + struct au_dykey **k, *found;
12384 + const void *h_op = key->dk_op.dy_hop;
12388 + k = br->br_dykey;
12389 + for (i = 0; i < AuBrDynOp; i++)
12391 + if (k[i]->dk_op.dy_hop == h_op) {
12398 + spin_lock(&br->br_dykey_lock);
12399 + for (; i < AuBrDynOp; i++)
12401 + if (k[i]->dk_op.dy_hop == h_op) {
12409 + spin_unlock(&br->br_dykey_lock);
12410 + BUG_ON(i == AuBrDynOp); /* expand the array */
12416 +/* kref_get() if @key is already added */
12417 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12419 + struct au_dykey *tmp, *found;
12420 + struct hlist_bl_node *pos;
12421 + const void *h_op = key->dk_op.dy_hop;
12424 + hlist_bl_lock(hbl);
12425 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12426 + if (tmp->dk_op.dy_hop == h_op) {
12427 + if (kref_get_unless_zero(&tmp->dk_kref))
12432 + hlist_bl_add_head(&key->dk_hnode, hbl);
12433 + hlist_bl_unlock(hbl);
12440 +static void dy_free_rcu(struct rcu_head *rcu)
12442 + struct au_dykey *key;
12444 + key = container_of(rcu, struct au_dykey, dk_rcu);
12449 +static void dy_free(struct kref *kref)
12451 + struct au_dykey *key;
12452 + struct hlist_bl_head *hbl;
12454 + key = container_of(kref, struct au_dykey, dk_kref);
12455 + hbl = dynop + key->dk_op.dy_type;
12456 + au_hbl_del(&key->dk_hnode, hbl);
12457 + call_rcu(&key->dk_rcu, dy_free_rcu);
12460 +void au_dy_put(struct au_dykey *key)
12462 + kref_put(&key->dk_kref, dy_free);
12465 +/* ---------------------------------------------------------------------- */
12467 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12469 +#ifdef CONFIG_AUFS_DEBUG
12470 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12471 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12473 +#define DyDbgDeclare(cnt) do {} while (0)
12474 +#define DyDbgInc(cnt) do {} while (0)
12477 +#define DySet(func, dst, src, h_op, h_sb) do { \
12479 + if (h_op->func) { \
12481 + dst.func = src.func; \
12483 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12487 +#define DySetForce(func, dst, src) do { \
12488 + AuDebugOn(!src.func); \
12490 + dst.func = src.func; \
12493 +#define DySetAop(func) \
12494 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12495 +#define DySetAopForce(func) \
12496 + DySetForce(func, dyaop->da_op, aufs_aop)
12498 +static void dy_aop(struct au_dykey *key, const void *h_op,
12499 + struct super_block *h_sb __maybe_unused)
12501 + struct au_dyaop *dyaop = (void *)key;
12502 + const struct address_space_operations *h_aop = h_op;
12503 + DyDbgDeclare(cnt);
12505 + AuDbg("%s\n", au_sbtype(h_sb));
12507 + DySetAop(writepage);
12508 + DySetAopForce(readpage); /* force */
12509 + DySetAop(writepages);
12510 + DySetAop(set_page_dirty);
12511 + DySetAop(readpages);
12512 + DySetAop(readahead);
12513 + DySetAop(write_begin);
12514 + DySetAop(write_end);
12516 + DySetAop(invalidatepage);
12517 + DySetAop(releasepage);
12518 + DySetAop(freepage);
12519 + /* this one will be changed according to an aufs mount option */
12520 + DySetAop(direct_IO);
12521 + DySetAop(migratepage);
12522 + DySetAop(isolate_page);
12523 + DySetAop(putback_page);
12524 + DySetAop(launder_page);
12525 + DySetAop(is_partially_uptodate);
12526 + DySetAop(is_dirty_writeback);
12527 + DySetAop(error_remove_page);
12528 + DySetAop(swap_activate);
12529 + DySetAop(swap_deactivate);
12531 + DyDbgSize(cnt, *h_aop);
12534 +/* ---------------------------------------------------------------------- */
12536 +static void dy_bug(struct kref *kref)
12541 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12543 + struct au_dykey *key, *old;
12544 + struct hlist_bl_head *hbl;
12547 + void (*set)(struct au_dykey *key, const void *h_op,
12548 + struct super_block *h_sb __maybe_unused);
12550 + static const struct op a[] = {
12552 + .sz = sizeof(struct au_dyaop),
12556 + const struct op *p;
12558 + hbl = dynop + op->dy_type;
12559 + key = dy_gfind_get(hbl, op->dy_hop);
12561 + goto out_add; /* success */
12563 + p = a + op->dy_type;
12564 + key = kzalloc(p->sz, GFP_NOFS);
12565 + if (unlikely(!key)) {
12566 + key = ERR_PTR(-ENOMEM);
12570 + key->dk_op.dy_hop = op->dy_hop;
12571 + kref_init(&key->dk_kref);
12572 + p->set(key, op->dy_hop, au_br_sb(br));
12573 + old = dy_gadd(hbl, key);
12575 + au_kfree_rcu(key);
12580 + old = dy_bradd(br, key);
12582 + /* its ref-count should never be zero here */
12583 + kref_put(&key->dk_kref, dy_bug);
12588 +/* ---------------------------------------------------------------------- */
12590 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12591 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12592 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12593 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12594 + * See the aufs manual in detail.
12596 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12599 + dyaop->da_op.direct_IO = NULL;
12601 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12604 +static struct au_dyaop *dy_aget(struct au_branch *br,
12605 + const struct address_space_operations *h_aop,
12608 + struct au_dyaop *dyaop;
12609 + struct au_dynop op;
12611 + op.dy_type = AuDy_AOP;
12612 + op.dy_haop = h_aop;
12613 + dyaop = (void *)dy_get(&op, br);
12614 + if (IS_ERR(dyaop))
12616 + dy_adx(dyaop, do_dx);
12622 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12623 + struct inode *h_inode)
12626 + struct super_block *sb;
12627 + struct au_branch *br;
12628 + struct au_dyaop *dyaop;
12630 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12631 + IiMustWriteLock(inode);
12633 + sb = inode->i_sb;
12634 + br = au_sbr(sb, bindex);
12635 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12636 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12637 + err = PTR_ERR(dyaop);
12638 + if (IS_ERR(dyaop))
12639 + /* unnecessary to call dy_fput() */
12643 + inode->i_mapping->a_ops = &dyaop->da_op;
12650 + * Is it safe to replace a_ops during the inode/file is in operation?
12651 + * Yes, I hope so.
12653 +int au_dy_irefresh(struct inode *inode)
12656 + aufs_bindex_t btop;
12657 + struct inode *h_inode;
12660 + if (S_ISREG(inode->i_mode)) {
12661 + btop = au_ibtop(inode);
12662 + h_inode = au_h_iptr(inode, btop);
12663 + err = au_dy_iaop(inode, btop, h_inode);
12668 +void au_dy_arefresh(int do_dx)
12670 + struct hlist_bl_head *hbl;
12671 + struct hlist_bl_node *pos;
12672 + struct au_dykey *key;
12674 + hbl = dynop + AuDy_AOP;
12675 + hlist_bl_lock(hbl);
12676 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12677 + dy_adx((void *)key, do_dx);
12678 + hlist_bl_unlock(hbl);
12681 +/* ---------------------------------------------------------------------- */
12683 +void __init au_dy_init(void)
12687 + for (i = 0; i < AuDyLast; i++)
12688 + INIT_HLIST_BL_HEAD(dynop + i);
12691 +void au_dy_fin(void)
12695 + for (i = 0; i < AuDyLast; i++)
12696 + WARN_ON(!hlist_bl_empty(dynop + i));
12698 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12699 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12700 +++ linux/fs/aufs/dynop.h 2022-10-26 22:30:38.465982192 +0200
12702 +/* SPDX-License-Identifier: GPL-2.0 */
12704 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12706 + * This program, aufs is free software; you can redistribute it and/or modify
12707 + * it under the terms of the GNU General Public License as published by
12708 + * the Free Software Foundation; either version 2 of the License, or
12709 + * (at your option) any later version.
12711 + * This program is distributed in the hope that it will be useful,
12712 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12713 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12714 + * GNU General Public License for more details.
12716 + * You should have received a copy of the GNU General Public License
12717 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12721 + * dynamically customizable operations (for regular files only)
12724 +#ifndef __AUFS_DYNOP_H__
12725 +#define __AUFS_DYNOP_H__
12729 +#include <linux/fs.h>
12730 +#include <linux/kref.h>
12732 +enum {AuDy_AOP, AuDyLast};
12737 + const void *dy_hop;
12738 + const struct address_space_operations *dy_haop;
12744 + struct hlist_bl_node dk_hnode;
12745 + struct rcu_head dk_rcu;
12747 + struct au_dynop dk_op;
12750 + * during I am in the branch local array, kref is gotten. when the
12751 + * branch is removed, kref is put.
12753 + struct kref dk_kref;
12756 +/* stop unioning since their sizes are very different from each other */
12758 + struct au_dykey da_key;
12759 + struct address_space_operations da_op; /* not const */
12761 +/* make sure that 'struct au_dykey *' can be any type */
12762 +static_assert(!offsetof(struct au_dyaop, da_key));
12764 +/* ---------------------------------------------------------------------- */
12768 +void au_dy_put(struct au_dykey *key);
12769 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12770 + struct inode *h_inode);
12771 +int au_dy_irefresh(struct inode *inode);
12772 +void au_dy_arefresh(int do_dio);
12774 +void __init au_dy_init(void);
12775 +void au_dy_fin(void);
12777 +#endif /* __KERNEL__ */
12778 +#endif /* __AUFS_DYNOP_H__ */
12779 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12780 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12781 +++ linux/fs/aufs/export.c 2022-10-26 22:30:38.465982192 +0200
12783 +// SPDX-License-Identifier: GPL-2.0
12785 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12787 + * This program, aufs is free software; you can redistribute it and/or modify
12788 + * it under the terms of the GNU General Public License as published by
12789 + * the Free Software Foundation; either version 2 of the License, or
12790 + * (at your option) any later version.
12792 + * This program is distributed in the hope that it will be useful,
12793 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12794 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12795 + * GNU General Public License for more details.
12797 + * You should have received a copy of the GNU General Public License
12798 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12805 +#include <linux/exportfs.h>
12806 +#include <linux/fs_struct.h>
12807 +#include <linux/nsproxy.h>
12808 +#include <linux/random.h>
12809 +#include <linux/writeback.h>
12813 +#ifdef CONFIG_AUFS_INO_T_64
12821 +static ino_t decode_ino(__u32 *a)
12825 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12827 +#ifdef CONFIG_AUFS_INO_T_64
12833 +static void encode_ino(__u32 *a, ino_t ino)
12839 +#ifdef CONFIG_AUFS_INO_T_64
12844 +/* NFS file handle */
12848 +#ifdef CONFIG_AUFS_INO_T_64
12849 + /* support 64bit inode number */
12862 + Fh_ino = Fh_ino1,
12863 + Fh_dir_ino = Fh_dir_ino1
12866 +static int au_test_anon(struct dentry *dentry)
12868 + /* note: read d_flags without d_lock */
12869 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12872 +int au_test_nfsd(void)
12875 + struct task_struct *tsk = current;
12876 + char comm[sizeof(tsk->comm)];
12879 + if (tsk->flags & PF_KTHREAD) {
12880 + get_task_comm(comm, tsk);
12881 + ret = !strcmp(comm, "nfsd");
12887 +/* ---------------------------------------------------------------------- */
12888 +/* inode generation external table */
12890 +void au_xigen_inc(struct inode *inode)
12895 + struct super_block *sb;
12896 + struct au_sbinfo *sbinfo;
12898 + sb = inode->i_sb;
12899 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12901 + sbinfo = au_sbi(sb);
12902 + pos = inode->i_ino;
12903 + pos *= sizeof(igen);
12904 + igen = inode->i_generation + 1;
12905 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12906 + if (sz == sizeof(igen))
12907 + return; /* success */
12909 + if (unlikely(sz >= 0))
12910 + AuIOErr("xigen error (%zd)\n", sz);
12913 +int au_xigen_new(struct inode *inode)
12918 + struct super_block *sb;
12919 + struct au_sbinfo *sbinfo;
12920 + struct file *file;
12923 + /* todo: dirty, at mount time */
12924 + if (inode->i_ino == AUFS_ROOT_INO)
12926 + sb = inode->i_sb;
12927 + SiMustAnyLock(sb);
12928 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12932 + pos = inode->i_ino;
12933 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12934 + AuIOErr1("too large i%lld\n", pos);
12937 + pos *= sizeof(inode->i_generation);
12940 + sbinfo = au_sbi(sb);
12941 + file = sbinfo->si_xigen;
12944 + if (vfsub_f_size_read(file)
12945 + < pos + sizeof(inode->i_generation)) {
12946 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12947 + sz = xino_fwrite(file, &inode->i_generation,
12948 + sizeof(inode->i_generation), &pos);
12950 + sz = xino_fread(file, &inode->i_generation,
12951 + sizeof(inode->i_generation), &pos);
12952 + if (sz == sizeof(inode->i_generation))
12953 + goto out; /* success */
12956 + if (unlikely(sz >= 0)) {
12958 + AuIOErr("xigen error (%zd)\n", sz);
12965 +int au_xigen_set(struct super_block *sb, struct path *path)
12968 + struct au_sbinfo *sbinfo;
12969 + struct file *file;
12971 + SiMustWriteLock(sb);
12973 + sbinfo = au_sbi(sb);
12974 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12975 + err = PTR_ERR(file);
12976 + if (IS_ERR(file))
12979 + if (sbinfo->si_xigen)
12980 + fput(sbinfo->si_xigen);
12981 + sbinfo->si_xigen = file;
12988 +void au_xigen_clr(struct super_block *sb)
12990 + struct au_sbinfo *sbinfo;
12992 + SiMustWriteLock(sb);
12994 + sbinfo = au_sbi(sb);
12995 + if (sbinfo->si_xigen) {
12996 + fput(sbinfo->si_xigen);
12997 + sbinfo->si_xigen = NULL;
13001 +/* ---------------------------------------------------------------------- */
13003 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13006 + struct dentry *dentry, *d;
13007 + struct inode *inode;
13008 + unsigned int sigen;
13011 + inode = ilookup(sb, ino);
13015 + dentry = ERR_PTR(-ESTALE);
13016 + sigen = au_sigen(sb);
13017 + if (unlikely(au_is_bad_inode(inode)
13018 + || IS_DEADDIR(inode)
13019 + || sigen != au_iigen(inode, NULL)))
13023 + if (!dir_ino || S_ISDIR(inode->i_mode))
13024 + dentry = d_find_alias(inode);
13026 + spin_lock(&inode->i_lock);
13027 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13028 + spin_lock(&d->d_lock);
13029 + if (!au_test_anon(d)
13030 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13031 + dentry = dget_dlock(d);
13032 + spin_unlock(&d->d_lock);
13035 + spin_unlock(&d->d_lock);
13037 + spin_unlock(&inode->i_lock);
13039 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13040 + /* need to refresh */
13048 + AuTraceErrPtr(dentry);
13052 +/* ---------------------------------------------------------------------- */
13054 +/* todo: dirty? */
13055 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13057 +struct au_compare_mnt_args {
13059 + struct super_block *sb;
13062 + struct vfsmount *mnt;
13065 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13067 + struct au_compare_mnt_args *a = arg;
13069 + if (mnt->mnt_sb != a->sb)
13071 + a->mnt = mntget(mnt);
13075 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13078 + struct path root;
13079 + struct au_compare_mnt_args args = {
13083 + get_fs_root(current->fs, &root);
13085 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13086 + rcu_read_unlock();
13089 + AuDebugOn(!args.mnt);
13093 +struct au_nfsd_si_lock {
13094 + unsigned int sigen;
13095 + aufs_bindex_t bindex, br_id;
13096 + unsigned char force_lock;
13099 +static int si_nfsd_read_lock(struct super_block *sb,
13100 + struct au_nfsd_si_lock *nsi_lock)
13103 + aufs_bindex_t bindex;
13105 + si_read_lock(sb, AuLock_FLUSH);
13107 + /* branch id may be wrapped around */
13109 + bindex = au_br_index(sb, nsi_lock->br_id);
13110 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13111 + goto out; /* success */
13115 + if (!nsi_lock->force_lock)
13116 + si_read_unlock(sb);
13119 + nsi_lock->bindex = bindex;
13123 +struct find_name_by_ino {
13124 + struct dir_context ctx;
13125 + int called, found;
13132 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13133 + loff_t offset, u64 ino, unsigned int d_type)
13135 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13139 + if (a->ino != ino)
13142 + memcpy(a->name, name, namelen);
13143 + a->namelen = namelen;
13148 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13149 + struct au_nfsd_si_lock *nsi_lock)
13151 + struct dentry *dentry, *parent;
13152 + struct file *file;
13153 + struct inode *dir;
13154 + struct find_name_by_ino arg = {
13156 + .actor = find_name_by_ino
13161 + parent = path->dentry;
13163 + si_read_unlock(parent->d_sb);
13164 + file = vfsub_dentry_open(path, au_dir_roflags);
13165 + dentry = (void *)file;
13166 + if (IS_ERR(file))
13169 + dentry = ERR_PTR(-ENOMEM);
13170 + arg.name = (void *)__get_free_page(GFP_NOFS);
13171 + if (unlikely(!arg.name))
13178 + err = vfsub_iterate_dir(file, &arg.ctx);
13179 + } while (!err && !arg.found && arg.called);
13180 + dentry = ERR_PTR(err);
13181 + if (unlikely(err))
13183 + /* instead of ENOENT */
13184 + dentry = ERR_PTR(-ESTALE);
13188 + /* do not call vfsub_lkup_one() */
13189 + dir = d_inode(parent);
13190 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13191 + AuTraceErrPtr(dentry);
13192 + if (IS_ERR(dentry))
13194 + AuDebugOn(au_test_anon(dentry));
13195 + if (unlikely(d_really_is_negative(dentry))) {
13197 + dentry = ERR_PTR(-ENOENT);
13201 + free_page((unsigned long)arg.name);
13205 + if (unlikely(nsi_lock
13206 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13207 + if (!IS_ERR(dentry)) {
13209 + dentry = ERR_PTR(-ESTALE);
13211 + AuTraceErrPtr(dentry);
13215 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13217 + struct au_nfsd_si_lock *nsi_lock)
13219 + struct dentry *dentry;
13220 + struct path path;
13222 + if (dir_ino != AUFS_ROOT_INO) {
13223 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13224 + dentry = path.dentry;
13225 + if (!path.dentry || IS_ERR(path.dentry))
13227 + AuDebugOn(au_test_anon(path.dentry));
13229 + path.dentry = dget(sb->s_root);
13231 + path.mnt = au_mnt_get(sb);
13232 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13236 + AuTraceErrPtr(dentry);
13240 +/* ---------------------------------------------------------------------- */
13242 +static int h_acceptable(void *expv, struct dentry *dentry)
13247 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13248 + char *buf, int len, struct super_block *sb)
13252 + struct path path;
13254 + p = d_path(h_rootpath, buf, len);
13259 + path.mnt = h_rootpath->mnt;
13260 + path.dentry = h_parent;
13261 + p = d_path(&path, buf, len);
13267 + path.mnt = au_mnt_get(sb);
13268 + path.dentry = sb->s_root;
13269 + p = d_path(&path, buf, len - strlen(p));
13270 + mntput(path.mnt);
13274 + p[strlen(p)] = '/';
13277 + AuTraceErrPtr(p);
13282 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13283 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13285 + struct dentry *dentry, *h_parent, *root;
13286 + struct super_block *h_sb;
13287 + char *pathname, *p;
13288 + struct vfsmount *h_mnt;
13289 + struct au_branch *br;
13291 + struct path path;
13293 + br = au_sbr(sb, nsi_lock->bindex);
13294 + h_mnt = au_br_mnt(br);
13295 + h_sb = h_mnt->mnt_sb;
13296 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13298 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13299 + fh_len - Fh_tail, fh[Fh_h_type],
13300 + h_acceptable, /*context*/NULL);
13302 + dentry = h_parent;
13303 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13304 + AuWarn1("%s decode_fh failed, %ld\n",
13305 + au_sbtype(h_sb), PTR_ERR(h_parent));
13309 + if (unlikely(au_test_anon(h_parent))) {
13310 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13311 + au_sbtype(h_sb));
13312 + goto out_h_parent;
13315 + dentry = ERR_PTR(-ENOMEM);
13316 + pathname = (void *)__get_free_page(GFP_NOFS);
13317 + if (unlikely(!pathname))
13318 + goto out_h_parent;
13320 + root = sb->s_root;
13321 + path.mnt = h_mnt;
13322 + di_read_lock_parent(root, !AuLock_IR);
13323 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13324 + di_read_unlock(root, !AuLock_IR);
13325 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13326 + dentry = (void *)p;
13328 + goto out_pathname;
13330 + si_read_unlock(sb);
13331 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13332 + dentry = ERR_PTR(err);
13333 + if (unlikely(err))
13336 + dentry = ERR_PTR(-ENOENT);
13337 + AuDebugOn(au_test_anon(path.dentry));
13338 + if (unlikely(d_really_is_negative(path.dentry)))
13341 + if (ino != d_inode(path.dentry)->i_ino)
13342 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13344 + dentry = dget(path.dentry);
13349 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13350 + if (!IS_ERR(dentry)) {
13352 + dentry = ERR_PTR(-ESTALE);
13355 + free_page((unsigned long)pathname);
13359 + AuTraceErrPtr(dentry);
13363 +/* ---------------------------------------------------------------------- */
13365 +static struct dentry *
13366 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13369 + struct dentry *dentry;
13370 + __u32 *fh = fid->raw;
13371 + struct au_branch *br;
13372 + ino_t ino, dir_ino;
13373 + struct au_nfsd_si_lock nsi_lock = {
13377 + dentry = ERR_PTR(-ESTALE);
13378 + /* it should never happen, but the file handle is unreliable */
13379 + if (unlikely(fh_len < Fh_tail))
13381 + nsi_lock.sigen = fh[Fh_sigen];
13382 + nsi_lock.br_id = fh[Fh_br_id];
13384 + /* branch id may be wrapped around */
13386 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13388 + nsi_lock.force_lock = 1;
13390 + /* is this inode still cached? */
13391 + ino = decode_ino(fh + Fh_ino);
13392 + /* it should never happen */
13393 + if (unlikely(ino == AUFS_ROOT_INO))
13396 + dir_ino = decode_ino(fh + Fh_dir_ino);
13397 + dentry = decode_by_ino(sb, ino, dir_ino);
13398 + if (IS_ERR(dentry))
13403 + /* is the parent dir cached? */
13404 + br = au_sbr(sb, nsi_lock.bindex);
13405 + au_lcnt_inc(&br->br_nfiles);
13406 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13407 + if (IS_ERR(dentry))
13412 + /* lookup path */
13413 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13414 + if (IS_ERR(dentry))
13416 + if (unlikely(!dentry))
13417 + /* todo?: make it ESTALE */
13421 + if (!au_digen_test(dentry, au_sigen(sb))
13422 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13423 + goto out_unlock; /* success */
13426 + dentry = ERR_PTR(-ESTALE);
13429 + au_lcnt_dec(&br->br_nfiles);
13430 + si_read_unlock(sb);
13432 + AuTraceErrPtr(dentry);
13436 +#if 0 /* reserved for future use */
13437 +/* support subtreecheck option */
13438 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13439 + int fh_len, int fh_type)
13441 + struct dentry *parent;
13442 + __u32 *fh = fid->raw;
13445 + dir_ino = decode_ino(fh + Fh_dir_ino);
13446 + parent = decode_by_ino(sb, dir_ino, 0);
13447 + if (IS_ERR(parent))
13450 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13451 + dir_ino, fh, fh_len);
13454 + AuTraceErrPtr(parent);
13459 +/* ---------------------------------------------------------------------- */
13461 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13462 + struct inode *dir)
13465 + aufs_bindex_t bindex;
13466 + struct super_block *sb, *h_sb;
13467 + struct dentry *dentry, *parent, *h_parent;
13468 + struct inode *h_dir;
13469 + struct au_branch *br;
13472 + if (unlikely(*max_len <= Fh_tail)) {
13473 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13477 + err = FILEID_ROOT;
13478 + if (inode->i_ino == AUFS_ROOT_INO) {
13479 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13484 + sb = inode->i_sb;
13485 + err = si_read_lock(sb, AuLock_FLUSH);
13486 + if (unlikely(err))
13489 +#ifdef CONFIG_AUFS_DEBUG
13490 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13491 + AuWarn1("NFS-exporting requires xino\n");
13495 + ii_read_lock_child(inode);
13496 + bindex = au_ibtop(inode);
13498 + dentry = d_find_any_alias(inode);
13499 + if (unlikely(!dentry))
13501 + AuDebugOn(au_test_anon(dentry));
13502 + parent = dget_parent(dentry);
13504 + if (unlikely(!parent))
13506 + if (d_really_is_positive(parent))
13507 + dir = d_inode(parent);
13510 + ii_read_lock_parent(dir);
13511 + h_dir = au_h_iptr(dir, bindex);
13512 + ii_read_unlock(dir);
13513 + if (unlikely(!h_dir))
13515 + h_parent = d_find_any_alias(h_dir);
13516 + if (unlikely(!h_parent))
13517 + goto out_hparent;
13520 + br = au_sbr(sb, bindex);
13521 + h_sb = au_br_sb(br);
13522 + if (unlikely(!h_sb->s_export_op)) {
13523 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13524 + goto out_hparent;
13527 + fh[Fh_br_id] = br->br_id;
13528 + fh[Fh_sigen] = au_sigen(sb);
13529 + encode_ino(fh + Fh_ino, inode->i_ino);
13530 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13531 + fh[Fh_igen] = inode->i_generation;
13533 + *max_len -= Fh_tail;
13534 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13536 + /*connectable or subtreecheck*/0);
13537 + err = fh[Fh_h_type];
13538 + *max_len += Fh_tail;
13539 + /* todo: macros? */
13540 + if (err != FILEID_INVALID)
13543 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13550 + ii_read_unlock(inode);
13551 + si_read_unlock(sb);
13553 + if (unlikely(err < 0))
13554 + err = FILEID_INVALID;
13558 +/* ---------------------------------------------------------------------- */
13560 +static int aufs_commit_metadata(struct inode *inode)
13563 + aufs_bindex_t bindex;
13564 + struct super_block *sb;
13565 + struct inode *h_inode;
13566 + int (*f)(struct inode *inode);
13568 + sb = inode->i_sb;
13569 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13570 + ii_write_lock_child(inode);
13571 + bindex = au_ibtop(inode);
13572 + AuDebugOn(bindex < 0);
13573 + h_inode = au_h_iptr(inode, bindex);
13575 + f = h_inode->i_sb->s_export_op->commit_metadata;
13577 + err = f(h_inode);
13579 + err = sync_inode_metadata(h_inode, /*wait*/1);
13581 + au_cpup_attr_timesizes(inode);
13582 + ii_write_unlock(inode);
13583 + si_read_unlock(sb);
13587 +/* ---------------------------------------------------------------------- */
13589 +static struct export_operations aufs_export_op = {
13590 + .fh_to_dentry = aufs_fh_to_dentry,
13591 + /* .fh_to_parent = aufs_fh_to_parent, */
13592 + .encode_fh = aufs_encode_fh,
13593 + .commit_metadata = aufs_commit_metadata
13596 +void au_export_init(struct super_block *sb)
13598 + struct au_sbinfo *sbinfo;
13601 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13602 + && IS_MODULE(CONFIG_EXPORTFS),
13603 + AUFS_NAME ": unsupported configuration "
13604 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13606 + sb->s_export_op = &aufs_export_op;
13607 + sbinfo = au_sbi(sb);
13608 + sbinfo->si_xigen = NULL;
13609 + get_random_bytes(&u, sizeof(u));
13610 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13611 + atomic_set(&sbinfo->si_xigen_next, u);
13613 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13614 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13615 +++ linux/fs/aufs/fhsm.c 2022-10-26 22:30:38.465982192 +0200
13617 +// SPDX-License-Identifier: GPL-2.0
13619 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13621 + * This program, aufs is free software; you can redistribute it and/or modify
13622 + * it under the terms of the GNU General Public License as published by
13623 + * the Free Software Foundation; either version 2 of the License, or
13624 + * (at your option) any later version.
13626 + * This program is distributed in the hope that it will be useful,
13627 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13628 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13629 + * GNU General Public License for more details.
13631 + * You should have received a copy of the GNU General Public License
13632 + * along with this program; if not, write to the Free Software
13633 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13637 + * File-based Hierarchy Storage Management
13640 +#include <linux/anon_inodes.h>
13641 +#include <linux/poll.h>
13642 +#include <linux/seq_file.h>
13643 +#include <linux/statfs.h>
13646 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13648 + struct au_sbinfo *sbinfo;
13649 + struct au_fhsm *fhsm;
13651 + SiMustAnyLock(sb);
13653 + sbinfo = au_sbi(sb);
13654 + fhsm = &sbinfo->si_fhsm;
13655 + AuDebugOn(!fhsm);
13656 + return fhsm->fhsm_bottom;
13659 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13661 + struct au_sbinfo *sbinfo;
13662 + struct au_fhsm *fhsm;
13664 + SiMustWriteLock(sb);
13666 + sbinfo = au_sbi(sb);
13667 + fhsm = &sbinfo->si_fhsm;
13668 + AuDebugOn(!fhsm);
13669 + fhsm->fhsm_bottom = bindex;
13672 +/* ---------------------------------------------------------------------- */
13674 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13676 + struct au_br_fhsm *bf;
13678 + bf = br->br_fhsm;
13679 + MtxMustLock(&bf->bf_lock);
13681 + return !bf->bf_readable
13682 + || time_after(jiffies,
13683 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13686 +/* ---------------------------------------------------------------------- */
13688 +static void au_fhsm_notify(struct super_block *sb, int val)
13690 + struct au_sbinfo *sbinfo;
13691 + struct au_fhsm *fhsm;
13693 + SiMustAnyLock(sb);
13695 + sbinfo = au_sbi(sb);
13696 + fhsm = &sbinfo->si_fhsm;
13697 + if (au_fhsm_pid(fhsm)
13698 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13699 + atomic_set(&fhsm->fhsm_readable, val);
13701 + wake_up(&fhsm->fhsm_wqh);
13705 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13706 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13709 + struct au_branch *br;
13710 + struct au_br_fhsm *bf;
13712 + br = au_sbr(sb, bindex);
13713 + AuDebugOn(au_br_rdonly(br));
13714 + bf = br->br_fhsm;
13718 + mutex_lock(&bf->bf_lock);
13720 + MtxMustLock(&bf->bf_lock);
13722 + /* sb->s_root for NFS is unreliable */
13723 + err = au_br_stfs(br, &bf->bf_stfs);
13724 + if (unlikely(err)) {
13725 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13729 + bf->bf_jiffy = jiffies;
13730 + bf->bf_readable = 1;
13732 + au_fhsm_notify(sb, /*val*/1);
13734 + *rstfs = bf->bf_stfs;
13738 + mutex_unlock(&bf->bf_lock);
13739 + au_fhsm_notify(sb, /*val*/1);
13744 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13747 + struct au_sbinfo *sbinfo;
13748 + struct au_fhsm *fhsm;
13749 + struct au_branch *br;
13750 + struct au_br_fhsm *bf;
13752 + AuDbg("b%d, force %d\n", bindex, force);
13753 + SiMustAnyLock(sb);
13755 + sbinfo = au_sbi(sb);
13756 + fhsm = &sbinfo->si_fhsm;
13757 + if (!au_ftest_si(sbinfo, FHSM)
13758 + || fhsm->fhsm_bottom == bindex)
13761 + br = au_sbr(sb, bindex);
13762 + bf = br->br_fhsm;
13764 + mutex_lock(&bf->bf_lock);
13766 + || au_fhsm_pid(fhsm)
13767 + || au_fhsm_test_jiffy(sbinfo, br))
13768 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13770 + mutex_unlock(&bf->bf_lock);
13773 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13775 + aufs_bindex_t bindex, bbot;
13776 + struct au_branch *br;
13778 + /* exclude the bottom */
13779 + bbot = au_fhsm_bottom(sb);
13780 + for (bindex = 0; bindex < bbot; bindex++) {
13781 + br = au_sbr(sb, bindex);
13782 + if (au_br_fhsm(br->br_perm))
13783 + au_fhsm_wrote(sb, bindex, force);
13787 +/* ---------------------------------------------------------------------- */
13789 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13792 + struct au_sbinfo *sbinfo;
13793 + struct au_fhsm *fhsm;
13796 + sbinfo = file->private_data;
13797 + fhsm = &sbinfo->si_fhsm;
13798 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13799 + if (atomic_read(&fhsm->fhsm_readable))
13800 + mask = EPOLLIN /* | EPOLLRDNORM */;
13803 + AuDbg("mask 0x%x\n", mask);
13807 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13808 + struct aufs_stfs *stfs, __s16 brid)
13812 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13814 + err = __put_user(brid, &stbr->brid);
13815 + if (unlikely(err))
13821 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13822 + struct aufs_stbr __user *stbr, size_t count)
13826 + aufs_bindex_t bindex, bbot;
13827 + struct au_branch *br;
13828 + struct au_br_fhsm *bf;
13830 + /* except the bottom branch */
13833 + bbot = au_fhsm_bottom(sb);
13834 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13835 + br = au_sbr(sb, bindex);
13836 + if (!au_br_fhsm(br->br_perm))
13839 + bf = br->br_fhsm;
13840 + mutex_lock(&bf->bf_lock);
13841 + if (bf->bf_readable) {
13843 + if (count >= sizeof(*stbr))
13844 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13847 + bf->bf_readable = 0;
13848 + count -= sizeof(*stbr);
13852 + mutex_unlock(&bf->bf_lock);
13855 + err = sizeof(*stbr) * nstbr;
13860 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13865 + aufs_bindex_t nfhsm, bindex, bbot;
13866 + struct au_sbinfo *sbinfo;
13867 + struct au_fhsm *fhsm;
13868 + struct au_branch *br;
13869 + struct super_block *sb;
13872 + sbinfo = file->private_data;
13873 + fhsm = &sbinfo->si_fhsm;
13875 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13876 + if (!atomic_read(&fhsm->fhsm_readable)) {
13877 + if (vfsub_file_flags(file) & O_NONBLOCK)
13880 + err = wait_event_interruptible_locked_irq
13882 + atomic_read(&fhsm->fhsm_readable));
13884 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13885 + if (unlikely(err))
13888 + /* sb may already be dead */
13889 + au_rw_read_lock(&sbinfo->si_rwsem);
13890 + readable = atomic_read(&fhsm->fhsm_readable);
13891 + if (readable > 0) {
13892 + sb = sbinfo->si_sb;
13894 + /* exclude the bottom branch */
13896 + bbot = au_fhsm_bottom(sb);
13897 + for (bindex = 0; bindex < bbot; bindex++) {
13898 + br = au_sbr(sb, bindex);
13899 + if (au_br_fhsm(br->br_perm))
13903 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13904 + atomic_set(&fhsm->fhsm_readable, 0);
13905 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13909 + au_rw_read_unlock(&sbinfo->si_rwsem);
13917 +static int au_fhsm_release(struct inode *inode, struct file *file)
13919 + struct au_sbinfo *sbinfo;
13920 + struct au_fhsm *fhsm;
13922 + /* sb may already be dead */
13923 + sbinfo = file->private_data;
13924 + fhsm = &sbinfo->si_fhsm;
13925 + spin_lock(&fhsm->fhsm_spin);
13926 + fhsm->fhsm_pid = 0;
13927 + spin_unlock(&fhsm->fhsm_spin);
13928 + kobject_put(&sbinfo->si_kobj);
13933 +static const struct file_operations au_fhsm_fops = {
13934 + .owner = THIS_MODULE,
13935 + .llseek = noop_llseek,
13936 + .read = au_fhsm_read,
13937 + .poll = au_fhsm_poll,
13938 + .release = au_fhsm_release
13941 +int au_fhsm_fd(struct super_block *sb, int oflags)
13944 + struct au_sbinfo *sbinfo;
13945 + struct au_fhsm *fhsm;
13948 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13952 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13956 + sbinfo = au_sbi(sb);
13957 + fhsm = &sbinfo->si_fhsm;
13958 + spin_lock(&fhsm->fhsm_spin);
13959 + if (!fhsm->fhsm_pid)
13960 + fhsm->fhsm_pid = current->pid;
13963 + spin_unlock(&fhsm->fhsm_spin);
13964 + if (unlikely(err))
13967 + oflags |= O_RDONLY;
13968 + /* oflags |= FMODE_NONOTIFY; */
13969 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13971 + if (unlikely(fd < 0))
13974 + /* succeed regardless 'fhsm' status */
13975 + kobject_get(&sbinfo->si_kobj);
13976 + si_noflush_read_lock(sb);
13977 + if (au_ftest_si(sbinfo, FHSM))
13978 + au_fhsm_wrote_all(sb, /*force*/0);
13979 + si_read_unlock(sb);
13980 + goto out; /* success */
13983 + spin_lock(&fhsm->fhsm_spin);
13984 + fhsm->fhsm_pid = 0;
13985 + spin_unlock(&fhsm->fhsm_spin);
13991 +/* ---------------------------------------------------------------------- */
13993 +int au_fhsm_br_alloc(struct au_branch *br)
13998 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14000 + au_br_fhsm_init(br->br_fhsm);
14007 +/* ---------------------------------------------------------------------- */
14009 +void au_fhsm_fin(struct super_block *sb)
14011 + au_fhsm_notify(sb, /*val*/-1);
14014 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14016 + struct au_fhsm *fhsm;
14018 + fhsm = &sbinfo->si_fhsm;
14019 + spin_lock_init(&fhsm->fhsm_spin);
14020 + init_waitqueue_head(&fhsm->fhsm_wqh);
14021 + atomic_set(&fhsm->fhsm_readable, 0);
14022 + fhsm->fhsm_expire
14023 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14024 + fhsm->fhsm_bottom = -1;
14027 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14029 + sbinfo->si_fhsm.fhsm_expire
14030 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14033 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14037 + if (!au_ftest_si(sbinfo, FHSM))
14040 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14041 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14042 + seq_printf(seq, ",fhsm_sec=%u", u);
14044 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14045 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14046 +++ linux/fs/aufs/file.c 2022-10-26 22:30:38.465982192 +0200
14048 +// SPDX-License-Identifier: GPL-2.0
14050 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14052 + * This program, aufs is free software; you can redistribute it and/or modify
14053 + * it under the terms of the GNU General Public License as published by
14054 + * the Free Software Foundation; either version 2 of the License, or
14055 + * (at your option) any later version.
14057 + * This program is distributed in the hope that it will be useful,
14058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14060 + * GNU General Public License for more details.
14062 + * You should have received a copy of the GNU General Public License
14063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14067 + * handling file/dir, and address_space operation
14070 +#ifdef CONFIG_AUFS_DEBUG
14071 +#include <linux/migrate.h>
14073 +#include <linux/pagemap.h>
14076 +/* drop flags for writing */
14077 +unsigned int au_file_roflags(unsigned int flags)
14079 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14080 + flags |= O_RDONLY | O_NOATIME;
14084 +/* common functions to regular file and dir */
14085 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14086 + struct file *file, int force_wr)
14088 + struct file *h_file;
14089 + struct dentry *h_dentry;
14090 + struct inode *h_inode;
14091 + struct super_block *sb;
14092 + struct au_branch *br;
14093 + struct path h_path;
14096 + /* a race condition can happen between open and unlink/rmdir */
14097 + h_file = ERR_PTR(-ENOENT);
14098 + h_dentry = au_h_dptr(dentry, bindex);
14099 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14101 + h_inode = d_inode(h_dentry);
14102 + spin_lock(&h_dentry->d_lock);
14103 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14104 + /* || !d_inode(dentry)->i_nlink */
14106 + spin_unlock(&h_dentry->d_lock);
14107 + if (unlikely(err))
14110 + sb = dentry->d_sb;
14111 + br = au_sbr(sb, bindex);
14112 + err = au_br_test_oflag(flags, br);
14113 + h_file = ERR_PTR(err);
14114 + if (unlikely(err))
14117 + /* drop flags for writing */
14118 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14119 + if (force_wr && !(flags & O_WRONLY))
14121 + flags = au_file_roflags(flags);
14123 + h_file = ERR_PTR(-EROFS);
14124 + flags = au_file_roflags(flags);
14125 + if (unlikely(vfsub_native_ro(h_inode)
14126 + || IS_APPEND(h_inode)))
14128 + flags &= ~O_ACCMODE;
14129 + flags |= O_WRONLY;
14132 + flags &= ~O_CREAT;
14133 + au_lcnt_inc(&br->br_nfiles);
14134 + h_path.dentry = h_dentry;
14135 + h_path.mnt = au_br_mnt(br);
14136 + h_file = vfsub_dentry_open(&h_path, flags);
14137 + if (IS_ERR(h_file))
14140 + if (flags & __FMODE_EXEC) {
14141 + err = deny_write_access(h_file);
14142 + if (unlikely(err)) {
14144 + h_file = ERR_PTR(err);
14148 + fsnotify_open(h_file);
14149 + goto out; /* success */
14152 + au_lcnt_dec(&br->br_nfiles);
14157 +static int au_cmoo(struct dentry *dentry)
14159 + int err, cmoo, matched;
14160 + unsigned int udba;
14161 + struct path h_path;
14162 + struct au_pin pin;
14163 + struct au_cp_generic cpg = {
14164 + .dentry = dentry,
14169 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14171 + struct inode *delegated;
14172 + struct super_block *sb;
14173 + struct au_sbinfo *sbinfo;
14174 + struct au_fhsm *fhsm;
14176 + struct au_branch *br;
14177 + struct dentry *parent;
14178 + struct au_hinode *hdir;
14180 + DiMustWriteLock(dentry);
14181 + IiMustWriteLock(d_inode(dentry));
14184 + if (IS_ROOT(dentry))
14186 + cpg.bsrc = au_dbtop(dentry);
14190 + sb = dentry->d_sb;
14191 + sbinfo = au_sbi(sb);
14192 + fhsm = &sbinfo->si_fhsm;
14193 + pid = au_fhsm_pid(fhsm);
14196 + && (current->pid == pid
14197 + || rcu_dereference(current->real_parent)->pid == pid));
14198 + rcu_read_unlock();
14202 + br = au_sbr(sb, cpg.bsrc);
14203 + cmoo = au_br_cmoo(br->br_perm);
14206 + if (!d_is_reg(dentry))
14207 + cmoo &= AuBrAttr_COO_ALL;
14211 + parent = dget_parent(dentry);
14212 + di_write_lock_parent(parent);
14213 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14215 + if (unlikely(err < 0)) {
14216 + err = 0; /* there is no upper writable branch */
14219 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14221 + /* do not respect the coo attrib for the target branch */
14222 + err = au_cpup_dirs(dentry, cpg.bdst);
14223 + if (unlikely(err))
14226 + di_downgrade_lock(parent, AuLock_IR);
14227 + udba = au_opt_udba(sb);
14228 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14229 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14230 + if (unlikely(err))
14233 + err = au_sio_cpup_simple(&cpg);
14235 + if (unlikely(err))
14237 + if (!(cmoo & AuBrWAttr_MOO))
14238 + goto out_parent; /* success */
14240 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14241 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14242 + if (unlikely(err))
14245 + h_path.mnt = au_br_mnt(br);
14246 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14247 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14248 + delegated = NULL;
14249 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14251 + /* todo: keep h_dentry or not? */
14252 + if (unlikely(err == -EWOULDBLOCK)) {
14253 + pr_warn("cannot retry for NFSv4 delegation"
14254 + " for an internal unlink\n");
14257 + if (unlikely(err)) {
14258 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14262 + goto out_parent; /* success */
14265 + di_downgrade_lock(parent, AuLock_IR);
14267 + di_read_unlock(parent, AuLock_IR);
14274 +int au_do_open(struct file *file, struct au_do_open_args *args)
14276 + int err, aopen = args->aopen;
14277 + struct dentry *dentry;
14278 + struct au_finfo *finfo;
14281 + err = au_finfo_init(file, args->fidir);
14284 + err = au_finfo_init(file, args->fidir);
14287 + if (unlikely(err))
14290 + dentry = file->f_path.dentry;
14291 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14292 + di_write_lock_child(dentry);
14293 + err = au_cmoo(dentry);
14294 + di_downgrade_lock(dentry, AuLock_IR);
14297 + err = args->open(file, vfsub_file_flags(file), NULL);
14300 + err = args->open(file, vfsub_file_flags(file),
14305 + di_read_unlock(dentry, AuLock_IR);
14307 + finfo = au_fi(file);
14309 + finfo->fi_file = file;
14310 + au_hbl_add(&finfo->fi_hlist,
14311 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14314 + fi_write_unlock(file);
14317 + fi_write_unlock(file);
14320 + if (unlikely(err)) {
14321 + finfo->fi_hdir = NULL;
14322 + au_finfo_fin(file);
14330 +int au_reopen_nondir(struct file *file)
14333 + aufs_bindex_t btop;
14334 + struct dentry *dentry;
14335 + struct au_branch *br;
14336 + struct file *h_file, *h_file_tmp;
14338 + dentry = file->f_path.dentry;
14339 + btop = au_dbtop(dentry);
14340 + br = au_sbr(dentry->d_sb, btop);
14341 + h_file_tmp = NULL;
14342 + if (au_fbtop(file) == btop) {
14343 + h_file = au_hf_top(file);
14344 + if (file->f_mode == h_file->f_mode)
14345 + return 0; /* success */
14346 + h_file_tmp = h_file;
14347 + get_file(h_file_tmp);
14348 + au_lcnt_inc(&br->br_nfiles);
14349 + au_set_h_fptr(file, btop, NULL);
14351 + AuDebugOn(au_fi(file)->fi_hdir);
14354 + * file exists on both of rw and ro
14355 + * open --> dbtop and fbtop are both 0
14356 + * prepend a branch as rw, "rw" become ro
14358 + * delete the top branch, "rw" becomes rw again
14359 + * --> dbtop is 1, fbtop is still 0
14360 + * write --> fbtop is 0 but dbtop is 1
14362 + /* AuDebugOn(au_fbtop(file) < btop); */
14364 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14365 + file, /*force_wr*/0);
14366 + err = PTR_ERR(h_file);
14367 + if (IS_ERR(h_file)) {
14368 + if (h_file_tmp) {
14370 + au_set_h_fptr(file, btop, h_file_tmp);
14371 + h_file_tmp = NULL;
14373 + goto out; /* todo: close all? */
14377 + au_set_fbtop(file, btop);
14378 + au_set_h_fptr(file, btop, h_file);
14379 + au_update_figen(file);
14380 + /* todo: necessary? */
14381 + /* file->f_ra = h_file->f_ra; */
14384 + if (h_file_tmp) {
14385 + fput(h_file_tmp);
14386 + au_lcnt_dec(&br->br_nfiles);
14391 +/* ---------------------------------------------------------------------- */
14393 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14394 + struct dentry *hi_wh)
14397 + aufs_bindex_t btop;
14398 + struct au_dinfo *dinfo;
14399 + struct dentry *h_dentry;
14400 + struct au_hdentry *hdp;
14402 + dinfo = au_di(file->f_path.dentry);
14403 + AuRwMustWriteLock(&dinfo->di_rwsem);
14405 + btop = dinfo->di_btop;
14406 + dinfo->di_btop = btgt;
14407 + hdp = au_hdentry(dinfo, btgt);
14408 + h_dentry = hdp->hd_dentry;
14409 + hdp->hd_dentry = hi_wh;
14410 + err = au_reopen_nondir(file);
14411 + hdp->hd_dentry = h_dentry;
14412 + dinfo->di_btop = btop;
14417 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14418 + aufs_bindex_t bcpup, struct au_pin *pin)
14421 + struct inode *inode, *h_inode;
14422 + struct dentry *h_dentry, *hi_wh;
14423 + struct au_cp_generic cpg = {
14424 + .dentry = file->f_path.dentry,
14431 + au_update_dbtop(cpg.dentry);
14432 + inode = d_inode(cpg.dentry);
14434 + if (au_dbtop(cpg.dentry) <= bcpup
14435 + && au_dbbot(cpg.dentry) >= bcpup) {
14436 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14437 + if (h_dentry && d_is_positive(h_dentry))
14438 + h_inode = d_inode(h_dentry);
14440 + hi_wh = au_hi_wh(inode, bcpup);
14441 + if (!hi_wh && !h_inode)
14442 + err = au_sio_cpup_wh(&cpg, file);
14444 + /* already copied-up after unlink */
14445 + err = au_reopen_wh(file, bcpup, hi_wh);
14448 + && (inode->i_nlink > 1
14449 + || (inode->i_state & I_LINKABLE))
14450 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14451 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14457 + * prepare the @file for writing.
14459 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14462 + aufs_bindex_t dbtop;
14463 + struct dentry *parent;
14464 + struct inode *inode;
14465 + struct super_block *sb;
14466 + struct file *h_file;
14467 + struct au_cp_generic cpg = {
14468 + .dentry = file->f_path.dentry,
14473 + .flags = AuCpup_DTIME
14476 + sb = cpg.dentry->d_sb;
14477 + inode = d_inode(cpg.dentry);
14478 + cpg.bsrc = au_fbtop(file);
14479 + err = au_test_ro(sb, cpg.bsrc, inode);
14480 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14481 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14486 + /* need to cpup or reopen */
14487 + parent = dget_parent(cpg.dentry);
14488 + di_write_lock_parent(parent);
14489 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14491 + if (unlikely(err < 0))
14495 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14496 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14497 + if (unlikely(err))
14501 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14502 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14503 + if (unlikely(err))
14506 + dbtop = au_dbtop(cpg.dentry);
14507 + if (dbtop <= cpg.bdst)
14508 + cpg.bsrc = cpg.bdst;
14510 + if (dbtop <= cpg.bdst /* just reopen */
14511 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14513 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14514 + if (IS_ERR(h_file))
14515 + err = PTR_ERR(h_file);
14517 + di_downgrade_lock(parent, AuLock_IR);
14518 + if (dbtop > cpg.bdst)
14519 + err = au_sio_cpup_simple(&cpg);
14521 + err = au_reopen_nondir(file);
14522 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14524 + } else { /* copyup as wh and reopen */
14526 + * since writable hfsplus branch is not supported,
14527 + * h_open_pre/post() are unnecessary.
14529 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14530 + di_downgrade_lock(parent, AuLock_IR);
14534 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14535 + goto out_dput; /* success */
14541 + di_downgrade_lock(parent, AuLock_IR);
14543 + di_read_unlock(parent, AuLock_IR);
14550 +/* ---------------------------------------------------------------------- */
14552 +int au_do_flush(struct file *file, fl_owner_t id,
14553 + int (*flush)(struct file *file, fl_owner_t id))
14556 + struct super_block *sb;
14557 + struct inode *inode;
14559 + inode = file_inode(file);
14560 + sb = inode->i_sb;
14561 + si_noflush_read_lock(sb);
14562 + fi_read_lock(file);
14563 + ii_read_lock_child(inode);
14565 + err = flush(file, id);
14566 + au_cpup_attr_timesizes(inode);
14568 + ii_read_unlock(inode);
14569 + fi_read_unlock(file);
14570 + si_read_unlock(sb);
14574 +/* ---------------------------------------------------------------------- */
14576 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14579 + struct au_pin pin;
14580 + struct au_finfo *finfo;
14581 + struct dentry *parent, *hi_wh;
14582 + struct inode *inode;
14583 + struct super_block *sb;
14584 + struct au_cp_generic cpg = {
14585 + .dentry = file->f_path.dentry,
14590 + .flags = AuCpup_DTIME
14593 + FiMustWriteLock(file);
14596 + finfo = au_fi(file);
14597 + sb = cpg.dentry->d_sb;
14598 + inode = d_inode(cpg.dentry);
14599 + cpg.bdst = au_ibtop(inode);
14600 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14603 + parent = dget_parent(cpg.dentry);
14604 + if (au_test_ro(sb, cpg.bdst, inode)) {
14605 + di_read_lock_parent(parent, !AuLock_IR);
14606 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14608 + di_read_unlock(parent, !AuLock_IR);
14609 + if (unlikely(err < 0))
14614 + di_read_lock_parent(parent, AuLock_IR);
14615 + hi_wh = au_hi_wh(inode, cpg.bdst);
14616 + if (!S_ISDIR(inode->i_mode)
14617 + && au_opt_test(au_mntflags(sb), PLINK)
14618 + && au_plink_test(inode)
14619 + && !d_unhashed(cpg.dentry)
14620 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14621 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14622 + if (unlikely(err))
14625 + /* always superio. */
14626 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14627 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14629 + err = au_sio_cpup_simple(&cpg);
14632 + } else if (hi_wh) {
14633 + /* already copied-up after unlink */
14634 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14635 + *need_reopen = 0;
14639 + di_read_unlock(parent, AuLock_IR);
14646 +static void au_do_refresh_dir(struct file *file)
14648 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14649 + struct au_hfile *p, tmp, *q;
14650 + struct au_finfo *finfo;
14651 + struct super_block *sb;
14652 + struct au_fidir *fidir;
14654 + FiMustWriteLock(file);
14656 + sb = file->f_path.dentry->d_sb;
14657 + finfo = au_fi(file);
14658 + fidir = finfo->fi_hdir;
14659 + AuDebugOn(!fidir);
14660 + p = fidir->fd_hfile + finfo->fi_btop;
14661 + brid = p->hf_br->br_id;
14662 + bbot = fidir->fd_bbot;
14663 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14667 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14668 + if (new_bindex == bindex)
14670 + if (new_bindex < 0) {
14671 + au_set_h_fptr(file, bindex, NULL);
14675 + /* swap two lower inode, and loop again */
14676 + q = fidir->fd_hfile + new_bindex;
14680 + if (tmp.hf_file) {
14686 + p = fidir->fd_hfile;
14687 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14688 + bbot = au_sbbot(sb);
14689 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14690 + finfo->fi_btop++, p++)
14691 + if (p->hf_file) {
14692 + if (file_inode(p->hf_file))
14694 + au_hfput(p, /*execed*/0);
14697 + bbot = au_br_index(sb, brid);
14698 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14699 + finfo->fi_btop++, p++)
14701 + au_hfput(p, /*execed*/0);
14702 + bbot = au_sbbot(sb);
14705 + p = fidir->fd_hfile + bbot;
14706 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14707 + fidir->fd_bbot--, p--)
14708 + if (p->hf_file) {
14709 + if (file_inode(p->hf_file))
14711 + au_hfput(p, /*execed*/0);
14713 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14717 + * after branch manipulating, refresh the file.
14719 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14721 + int err, need_reopen, nbr;
14722 + aufs_bindex_t bbot, bindex;
14723 + struct dentry *dentry;
14724 + struct super_block *sb;
14725 + struct au_finfo *finfo;
14726 + struct au_hfile *hfile;
14728 + dentry = file->f_path.dentry;
14729 + sb = dentry->d_sb;
14730 + nbr = au_sbbot(sb) + 1;
14731 + finfo = au_fi(file);
14732 + if (!finfo->fi_hdir) {
14733 + hfile = &finfo->fi_htop;
14734 + AuDebugOn(!hfile->hf_file);
14735 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14736 + AuDebugOn(bindex < 0);
14737 + if (bindex != finfo->fi_btop)
14738 + au_set_fbtop(file, bindex);
14740 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14741 + if (unlikely(err))
14743 + au_do_refresh_dir(file);
14748 + if (!au_test_mmapped(file))
14749 + err = au_file_refresh_by_inode(file, &need_reopen);
14750 + if (finfo->fi_hdir)
14751 + /* harmless if err */
14752 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14753 + if (!err && need_reopen && !d_unlinked(dentry))
14754 + err = reopen(file);
14756 + au_update_figen(file);
14757 + goto out; /* success */
14760 + /* error, close all lower files */
14761 + if (finfo->fi_hdir) {
14762 + bbot = au_fbbot_dir(file);
14763 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14764 + au_set_h_fptr(file, bindex, NULL);
14771 +/* common function to regular file and dir */
14772 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14773 + int wlock, unsigned int fi_lsc)
14776 + unsigned int sigen, figen;
14777 + aufs_bindex_t btop;
14778 + unsigned char pseudo_link;
14779 + struct dentry *dentry;
14780 + struct inode *inode;
14783 + dentry = file->f_path.dentry;
14784 + inode = d_inode(dentry);
14785 + sigen = au_sigen(dentry->d_sb);
14786 + fi_write_lock_nested(file, fi_lsc);
14787 + figen = au_figen(file);
14789 + di_write_lock_child(dentry);
14791 + di_write_lock_child2(dentry);
14792 + btop = au_dbtop(dentry);
14793 + pseudo_link = (btop != au_ibtop(inode));
14794 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14796 + di_downgrade_lock(dentry, AuLock_IR);
14797 + fi_downgrade_lock(file);
14799 + goto out; /* success */
14802 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14803 + if (au_digen_test(dentry, sigen)) {
14804 + err = au_reval_dpath(dentry, sigen);
14805 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14809 + err = refresh_file(file, reopen);
14812 + di_downgrade_lock(dentry, AuLock_IR);
14813 + fi_downgrade_lock(file);
14816 + di_write_unlock(dentry);
14817 + fi_write_unlock(file);
14824 +/* ---------------------------------------------------------------------- */
14826 +/* cf. aufs_nopage() */
14827 +/* for madvise(2) */
14828 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14830 + unlock_page(page);
14834 +/* it will never be called, but necessary to support O_DIRECT */
14835 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14836 +{ BUG(); return 0; }
14838 +/* they will never be called. */
14839 +#ifdef CONFIG_AUFS_DEBUG
14840 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14841 + loff_t pos, unsigned len, unsigned flags,
14842 + struct page **pagep, void **fsdata)
14843 +{ AuUnsupport(); return 0; }
14844 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14845 + loff_t pos, unsigned len, unsigned copied,
14846 + struct page *page, void *fsdata)
14847 +{ AuUnsupport(); return 0; }
14848 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14849 +{ AuUnsupport(); return 0; }
14851 +static int aufs_set_page_dirty(struct page *page)
14852 +{ AuUnsupport(); return 0; }
14853 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14854 + unsigned int length)
14855 +{ AuUnsupport(); }
14856 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14857 +{ AuUnsupport(); return 0; }
14858 +#if 0 /* called by memory compaction regardless file */
14859 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14860 + struct page *page, enum migrate_mode mode)
14861 +{ AuUnsupport(); return 0; }
14863 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14864 +{ AuUnsupport(); return true; }
14865 +static void aufs_putback_page(struct page *page)
14866 +{ AuUnsupport(); }
14867 +static int aufs_launder_page(struct page *page)
14868 +{ AuUnsupport(); return 0; }
14869 +static int aufs_is_partially_uptodate(struct page *page,
14870 + unsigned long from,
14871 + unsigned long count)
14872 +{ AuUnsupport(); return 0; }
14873 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14875 +{ AuUnsupport(); }
14876 +static int aufs_error_remove_page(struct address_space *mapping,
14877 + struct page *page)
14878 +{ AuUnsupport(); return 0; }
14879 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14881 +{ AuUnsupport(); return 0; }
14882 +static void aufs_swap_deactivate(struct file *file)
14883 +{ AuUnsupport(); }
14884 +#endif /* CONFIG_AUFS_DEBUG */
14886 +const struct address_space_operations aufs_aop = {
14887 + .readpage = aufs_readpage,
14888 + .direct_IO = aufs_direct_IO,
14889 +#ifdef CONFIG_AUFS_DEBUG
14890 + .writepage = aufs_writepage,
14891 + /* no writepages, because of writepage */
14892 + .set_page_dirty = aufs_set_page_dirty,
14893 + /* no readpages, because of readpage */
14894 + .write_begin = aufs_write_begin,
14895 + .write_end = aufs_write_end,
14896 + /* no bmap, no block device */
14897 + .invalidatepage = aufs_invalidatepage,
14898 + .releasepage = aufs_releasepage,
14899 + /* is fallback_migrate_page ok? */
14900 + /* .migratepage = aufs_migratepage, */
14901 + .isolate_page = aufs_isolate_page,
14902 + .putback_page = aufs_putback_page,
14903 + .launder_page = aufs_launder_page,
14904 + .is_partially_uptodate = aufs_is_partially_uptodate,
14905 + .is_dirty_writeback = aufs_is_dirty_writeback,
14906 + .error_remove_page = aufs_error_remove_page,
14907 + .swap_activate = aufs_swap_activate,
14908 + .swap_deactivate = aufs_swap_deactivate
14909 +#endif /* CONFIG_AUFS_DEBUG */
14911 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14912 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14913 +++ linux/fs/aufs/file.h 2022-10-26 22:30:38.465982192 +0200
14915 +/* SPDX-License-Identifier: GPL-2.0 */
14917 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14919 + * This program, aufs is free software; you can redistribute it and/or modify
14920 + * it under the terms of the GNU General Public License as published by
14921 + * the Free Software Foundation; either version 2 of the License, or
14922 + * (at your option) any later version.
14924 + * This program is distributed in the hope that it will be useful,
14925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14927 + * GNU General Public License for more details.
14929 + * You should have received a copy of the GNU General Public License
14930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14934 + * file operations
14937 +#ifndef __AUFS_FILE_H__
14938 +#define __AUFS_FILE_H__
14942 +#include <linux/file.h>
14943 +#include <linux/fs.h>
14944 +#include <linux/mm_types.h>
14945 +#include <linux/poll.h>
14946 +#include "rwsem.h"
14950 + struct file *hf_file;
14951 + struct au_branch *hf_br;
14956 + aufs_bindex_t fd_bbot;
14957 + aufs_bindex_t fd_nent;
14958 + struct au_vdir *fd_vdir_cache;
14959 + struct au_hfile fd_hfile[];
14962 +static inline int au_fidir_sz(int nent)
14964 + AuDebugOn(nent < 0);
14965 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14969 + atomic_t fi_generation;
14971 + struct au_rwsem fi_rwsem;
14972 + aufs_bindex_t fi_btop;
14974 + /* do not union them */
14975 + struct { /* for non-dir */
14976 + struct au_hfile fi_htop;
14977 + atomic_t fi_mmapped;
14979 + struct au_fidir *fi_hdir; /* for dir only */
14981 + struct hlist_bl_node fi_hlist;
14982 + struct file *fi_file; /* very ugly */
14983 + struct rcu_head rcu;
14984 +} ____cacheline_aligned_in_smp;
14986 +/* ---------------------------------------------------------------------- */
14989 +extern const struct address_space_operations aufs_aop;
14990 +unsigned int au_file_roflags(unsigned int flags);
14991 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14992 + struct file *file, int force_wr);
14993 +struct au_do_open_args {
14995 + int (*open)(struct file *file, int flags,
14996 + struct file *h_file);
14997 + struct au_fidir *fidir;
14998 + struct file *h_file;
15000 +int au_do_open(struct file *file, struct au_do_open_args *args);
15001 +int au_reopen_nondir(struct file *file);
15003 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15004 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15005 + int wlock, unsigned int fi_lsc);
15006 +int au_do_flush(struct file *file, fl_owner_t id,
15007 + int (*flush)(struct file *file, fl_owner_t id));
15010 +#ifdef CONFIG_AUFS_POLL
15011 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15014 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15016 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15018 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15019 + struct file *h_file);
15021 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15022 + aufs_bindex_t bindex, int force_wr)
15023 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15024 + struct file *h_file);
15028 +extern const struct file_operations aufs_file_fop;
15029 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15030 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15031 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15034 +void au_hfput(struct au_hfile *hf, int execed);
15035 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15036 + struct file *h_file);
15038 +void au_update_figen(struct file *file);
15039 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15040 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15042 +void au_fi_init_once(void *_fi);
15043 +void au_finfo_fin(struct file *file);
15044 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15047 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15048 +#ifdef CONFIG_COMPAT
15049 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15050 + unsigned long arg);
15051 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15052 + unsigned long arg);
15055 +/* ---------------------------------------------------------------------- */
15057 +static inline struct au_finfo *au_fi(struct file *file)
15059 + return file->private_data;
15062 +/* ---------------------------------------------------------------------- */
15064 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15065 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15066 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15067 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15069 +#define fi_read_trylock_nested(f) \
15070 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15071 +#define fi_write_trylock_nested(f) \
15072 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15075 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15076 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15077 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15079 +/* lock subclass for finfo */
15085 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15087 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15090 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15092 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15096 + * fi_read_lock_1, fi_write_lock_1,
15097 + * fi_read_lock_2, fi_write_lock_2
15099 +#define AuReadLockFunc(name) \
15100 +static inline void fi_read_lock_##name(struct file *f) \
15101 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15103 +#define AuWriteLockFunc(name) \
15104 +static inline void fi_write_lock_##name(struct file *f) \
15105 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15107 +#define AuRWLockFuncs(name) \
15108 + AuReadLockFunc(name) \
15109 + AuWriteLockFunc(name)
15114 +#undef AuReadLockFunc
15115 +#undef AuWriteLockFunc
15116 +#undef AuRWLockFuncs
15118 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15119 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15120 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15122 +/* ---------------------------------------------------------------------- */
15124 +/* todo: hard/soft set? */
15125 +static inline aufs_bindex_t au_fbtop(struct file *file)
15127 + FiMustAnyLock(file);
15128 + return au_fi(file)->fi_btop;
15131 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15133 + FiMustAnyLock(file);
15134 + AuDebugOn(!au_fi(file)->fi_hdir);
15135 + return au_fi(file)->fi_hdir->fd_bbot;
15138 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15140 + FiMustAnyLock(file);
15141 + AuDebugOn(!au_fi(file)->fi_hdir);
15142 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15145 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15147 + FiMustWriteLock(file);
15148 + au_fi(file)->fi_btop = bindex;
15151 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15153 + FiMustWriteLock(file);
15154 + AuDebugOn(!au_fi(file)->fi_hdir);
15155 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15158 +static inline void au_set_fvdir_cache(struct file *file,
15159 + struct au_vdir *vdir_cache)
15161 + FiMustWriteLock(file);
15162 + AuDebugOn(!au_fi(file)->fi_hdir);
15163 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15166 +static inline struct file *au_hf_top(struct file *file)
15168 + FiMustAnyLock(file);
15169 + AuDebugOn(au_fi(file)->fi_hdir);
15170 + return au_fi(file)->fi_htop.hf_file;
15173 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15175 + FiMustAnyLock(file);
15176 + AuDebugOn(!au_fi(file)->fi_hdir);
15177 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15180 +/* todo: memory barrier? */
15181 +static inline unsigned int au_figen(struct file *f)
15183 + return atomic_read(&au_fi(f)->fi_generation);
15186 +static inline void au_set_mmapped(struct file *f)
15188 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15190 + pr_warn("fi_mmapped wrapped around\n");
15191 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15195 +static inline void au_unset_mmapped(struct file *f)
15197 + atomic_dec(&au_fi(f)->fi_mmapped);
15200 +static inline int au_test_mmapped(struct file *f)
15202 + return atomic_read(&au_fi(f)->fi_mmapped);
15205 +/* customize vma->vm_file */
15207 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15208 + struct file *file)
15212 + f = vma->vm_file;
15214 + vma->vm_file = file;
15219 +#define AuDbgVmRegion(file, vma) do {} while (0)
15221 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15222 + struct file *file)
15224 + au_do_vm_file_reset(vma, file);
15227 +#define AuDbgVmRegion(file, vma) \
15228 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15230 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15231 + struct file *file)
15235 + au_do_vm_file_reset(vma, file);
15236 + f = vma->vm_region->vm_file;
15238 + vma->vm_region->vm_file = file;
15241 +#endif /* CONFIG_MMU */
15243 +/* handle vma->vm_prfile */
15244 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15245 + struct file *file)
15248 + vma->vm_prfile = file;
15249 +#ifndef CONFIG_MMU
15251 + vma->vm_region->vm_prfile = file;
15255 +#endif /* __KERNEL__ */
15256 +#endif /* __AUFS_FILE_H__ */
15257 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15258 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15259 +++ linux/fs/aufs/finfo.c 2022-10-26 22:30:38.465982192 +0200
15261 +// SPDX-License-Identifier: GPL-2.0
15263 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15265 + * This program, aufs is free software; you can redistribute it and/or modify
15266 + * it under the terms of the GNU General Public License as published by
15267 + * the Free Software Foundation; either version 2 of the License, or
15268 + * (at your option) any later version.
15270 + * This program is distributed in the hope that it will be useful,
15271 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15272 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15273 + * GNU General Public License for more details.
15275 + * You should have received a copy of the GNU General Public License
15276 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15280 + * file private data
15285 +void au_hfput(struct au_hfile *hf, int execed)
15288 + allow_write_access(hf->hf_file);
15289 + fput(hf->hf_file);
15290 + hf->hf_file = NULL;
15291 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15292 + hf->hf_br = NULL;
15295 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15297 + struct au_finfo *finfo = au_fi(file);
15298 + struct au_hfile *hf;
15299 + struct au_fidir *fidir;
15301 + fidir = finfo->fi_hdir;
15303 + AuDebugOn(finfo->fi_btop != bindex);
15304 + hf = &finfo->fi_htop;
15306 + hf = fidir->fd_hfile + bindex;
15308 + if (hf && hf->hf_file)
15309 + au_hfput(hf, vfsub_file_execed(file));
15311 + FiMustWriteLock(file);
15312 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15313 + hf->hf_file = val;
15314 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15318 +void au_update_figen(struct file *file)
15320 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15321 + /* smp_mb(); */ /* atomic_set */
15324 +/* ---------------------------------------------------------------------- */
15326 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15328 + struct au_fidir *fidir;
15331 + nbr = au_sbbot(sb) + 1;
15333 + nbr = 2; /* initial allocate for 2 branches */
15334 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15336 + fidir->fd_bbot = -1;
15337 + fidir->fd_nent = nbr;
15343 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15346 + struct au_fidir *fidir, *p;
15348 + AuRwMustWriteLock(&finfo->fi_rwsem);
15349 + fidir = finfo->fi_hdir;
15350 + AuDebugOn(!fidir);
15353 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15354 + GFP_NOFS, may_shrink);
15356 + p->fd_nent = nbr;
15357 + finfo->fi_hdir = p;
15364 +/* ---------------------------------------------------------------------- */
15366 +void au_finfo_fin(struct file *file)
15368 + struct au_finfo *finfo;
15370 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15372 + finfo = au_fi(file);
15373 + AuDebugOn(finfo->fi_hdir);
15374 + AuRwDestroy(&finfo->fi_rwsem);
15375 + au_cache_free_finfo(finfo);
15378 +void au_fi_init_once(void *_finfo)
15380 + struct au_finfo *finfo = _finfo;
15382 + au_rw_init(&finfo->fi_rwsem);
15385 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15388 + struct au_finfo *finfo;
15389 + struct dentry *dentry;
15392 + dentry = file->f_path.dentry;
15393 + finfo = au_cache_alloc_finfo();
15394 + if (unlikely(!finfo))
15398 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15399 + au_rw_write_lock(&finfo->fi_rwsem);
15400 + finfo->fi_btop = -1;
15401 + finfo->fi_hdir = fidir;
15402 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15403 + /* smp_mb(); */ /* atomic_set */
15405 + file->private_data = finfo;
15410 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15411 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15412 +++ linux/fs/aufs/f_op.c 2022-10-26 22:30:38.465982192 +0200
15414 +// SPDX-License-Identifier: GPL-2.0
15416 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15418 + * This program, aufs is free software; you can redistribute it and/or modify
15419 + * it under the terms of the GNU General Public License as published by
15420 + * the Free Software Foundation; either version 2 of the License, or
15421 + * (at your option) any later version.
15423 + * This program is distributed in the hope that it will be useful,
15424 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15425 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15426 + * GNU General Public License for more details.
15428 + * You should have received a copy of the GNU General Public License
15429 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15433 + * file and vm operations
15436 +#include <linux/aio.h>
15437 +#include <linux/fs_stack.h>
15438 +#include <linux/mman.h>
15439 +#include <linux/security.h>
15442 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15445 + aufs_bindex_t bindex;
15446 + struct dentry *dentry, *h_dentry;
15447 + struct au_finfo *finfo;
15448 + struct inode *h_inode;
15450 + FiMustWriteLock(file);
15453 + dentry = file->f_path.dentry;
15454 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15455 + finfo = au_fi(file);
15456 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15457 + atomic_set(&finfo->fi_mmapped, 0);
15458 + bindex = au_dbtop(dentry);
15460 + h_dentry = au_h_dptr(dentry, bindex);
15461 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15462 + if (unlikely(err))
15464 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15465 + if (IS_ERR(h_file)) {
15466 + err = PTR_ERR(h_file);
15470 + h_dentry = h_file->f_path.dentry;
15471 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15472 + if (unlikely(err))
15474 + /* br ref is already inc-ed */
15477 + if ((flags & __O_TMPFILE)
15478 + && !(flags & O_EXCL)) {
15479 + h_inode = file_inode(h_file);
15480 + spin_lock(&h_inode->i_lock);
15481 + h_inode->i_state |= I_LINKABLE;
15482 + spin_unlock(&h_inode->i_lock);
15484 + au_set_fbtop(file, bindex);
15485 + au_set_h_fptr(file, bindex, h_file);
15486 + au_update_figen(file);
15487 + /* todo: necessary? */
15488 + /* file->f_ra = h_file->f_ra; */
15494 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15495 + struct file *file)
15498 + struct super_block *sb;
15499 + struct au_do_open_args args = {
15500 + .open = au_do_open_nondir
15503 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15504 + file, vfsub_file_flags(file), file->f_mode);
15506 + sb = file->f_path.dentry->d_sb;
15507 + si_read_lock(sb, AuLock_FLUSH);
15508 + err = au_do_open(file, &args);
15509 + si_read_unlock(sb);
15513 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15515 + struct au_finfo *finfo;
15516 + aufs_bindex_t bindex;
15518 + finfo = au_fi(file);
15519 + au_hbl_del(&finfo->fi_hlist,
15520 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15521 + bindex = finfo->fi_btop;
15523 + au_set_h_fptr(file, bindex, NULL);
15525 + au_finfo_fin(file);
15529 +/* ---------------------------------------------------------------------- */
15531 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15534 + struct file *h_file;
15537 + h_file = au_hf_top(file);
15539 + err = vfsub_flush(h_file, id);
15543 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15545 + return au_do_flush(file, id, au_do_flush_nondir);
15548 +/* ---------------------------------------------------------------------- */
15550 + * read and write functions acquire [fdi]_rwsem once, but release before
15551 + * mmap_sem. This is because to stop a race condition between mmap(2).
15552 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15553 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15554 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15557 +/* Callers should call au_read_post() or fput() in the end */
15558 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15560 + struct file *h_file;
15563 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15565 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15566 + h_file = au_hf_top(file);
15567 + get_file(h_file);
15569 + fi_read_unlock(file);
15571 + h_file = ERR_PTR(err);
15576 +static void au_read_post(struct inode *inode, struct file *h_file)
15578 + /* update without lock, I don't think it a problem */
15579 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15583 +struct au_write_pre {
15585 + unsigned int lsc;
15589 + aufs_bindex_t btop;
15593 + * return with iinfo is write-locked
15594 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15597 +static struct file *au_write_pre(struct file *file, int do_ready,
15598 + struct au_write_pre *wpre)
15600 + struct file *h_file;
15601 + struct dentry *dentry;
15603 + unsigned int lsc;
15604 + struct au_pin pin;
15609 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15610 + h_file = ERR_PTR(err);
15611 + if (unlikely(err))
15614 + dentry = file->f_path.dentry;
15616 + err = au_ready_to_write(file, -1, &pin);
15617 + if (unlikely(err)) {
15618 + h_file = ERR_PTR(err);
15619 + di_write_unlock(dentry);
15624 + di_downgrade_lock(dentry, /*flags*/0);
15626 + wpre->btop = au_fbtop(file);
15627 + h_file = au_hf_top(file);
15628 + get_file(h_file);
15630 + wpre->blks = file_inode(h_file)->i_blocks;
15633 + di_read_unlock(dentry, /*flags*/0);
15636 + fi_write_unlock(file);
15641 +static void au_write_post(struct inode *inode, struct file *h_file,
15642 + struct au_write_pre *wpre, ssize_t written)
15644 + struct inode *h_inode;
15646 + au_cpup_attr_timesizes(inode);
15647 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15648 + h_inode = file_inode(h_file);
15649 + inode->i_mode = h_inode->i_mode;
15650 + ii_write_unlock(inode);
15651 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15653 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15654 + /*force*/h_inode->i_blocks > wpre->blks);
15659 + * todo: very ugly
15660 + * it locks both of i_mutex and si_rwsem for read in safe.
15661 + * if the plink maintenance mode continues forever (that is the problem),
15662 + * may loop forever.
15664 +static void au_mtx_and_read_lock(struct inode *inode)
15667 + struct super_block *sb = inode->i_sb;
15670 + inode_lock(inode);
15671 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15674 + inode_unlock(inode);
15675 + si_read_lock(sb, AuLock_NOPLMW);
15676 + si_read_unlock(sb);
15680 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15681 + struct iov_iter *iov_iter)
15684 + struct file *file;
15685 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15687 + err = security_file_permission(h_file, rw);
15688 + if (unlikely(err))
15691 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15693 + if (rw == MAY_READ)
15694 + iter = h_file->f_op->read_iter;
15695 + else if (rw == MAY_WRITE)
15696 + iter = h_file->f_op->write_iter;
15698 + file = kio->ki_filp;
15699 + kio->ki_filp = h_file;
15702 + err = iter(kio, iov_iter);
15705 + /* currently there is no such fs */
15707 + kio->ki_filp = file;
15713 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15716 + struct file *file, *h_file;
15717 + struct inode *inode;
15718 + struct super_block *sb;
15720 + file = kio->ki_filp;
15721 + inode = file_inode(file);
15722 + sb = inode->i_sb;
15723 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15725 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15726 + err = PTR_ERR(h_file);
15727 + if (IS_ERR(h_file))
15730 + if (au_test_loopback_kthread()) {
15731 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15732 + if (file->f_mapping != h_file->f_mapping) {
15733 + file->f_mapping = h_file->f_mapping;
15734 + smp_mb(); /* unnecessary? */
15737 + fi_read_unlock(file);
15739 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15740 + /* todo: necessary? */
15741 + /* file->f_ra = h_file->f_ra; */
15742 + au_read_post(inode, h_file);
15745 + si_read_unlock(sb);
15749 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15752 + struct au_write_pre wpre;
15753 + struct inode *inode;
15754 + struct file *file, *h_file;
15756 + file = kio->ki_filp;
15757 + inode = file_inode(file);
15758 + au_mtx_and_read_lock(inode);
15761 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15762 + err = PTR_ERR(h_file);
15763 + if (IS_ERR(h_file))
15766 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15767 + au_write_post(inode, h_file, &wpre, err);
15770 + si_read_unlock(inode->i_sb);
15771 + inode_unlock(inode);
15776 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15777 + * don't have their own .splice_{read,write} implimentations, and they use
15778 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15779 + * simple converters to f_op->iter_read() and ->iter_write().
15780 + * But we keep our own implementations because some non-mainlined FSes may have
15781 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15782 + * away an opportunity to co-work with aufs from them.
15784 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15785 + struct pipe_inode_info *pipe, size_t len,
15786 + unsigned int flags)
15789 + struct file *h_file;
15790 + struct inode *inode;
15791 + struct super_block *sb;
15793 + inode = file_inode(file);
15794 + sb = inode->i_sb;
15795 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15797 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15798 + err = PTR_ERR(h_file);
15799 + if (IS_ERR(h_file))
15802 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15803 + /* todo: necessary? */
15804 + /* file->f_ra = h_file->f_ra; */
15805 + au_read_post(inode, h_file);
15808 + si_read_unlock(sb);
15813 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15814 + size_t len, unsigned int flags)
15817 + struct au_write_pre wpre;
15818 + struct inode *inode;
15819 + struct file *h_file;
15821 + inode = file_inode(file);
15822 + au_mtx_and_read_lock(inode);
15825 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15826 + err = PTR_ERR(h_file);
15827 + if (IS_ERR(h_file))
15830 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15831 + au_write_post(inode, h_file, &wpre, err);
15834 + si_read_unlock(inode->i_sb);
15835 + inode_unlock(inode);
15839 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15843 + struct au_write_pre wpre;
15844 + struct inode *inode;
15845 + struct file *h_file;
15847 + inode = file_inode(file);
15848 + au_mtx_and_read_lock(inode);
15851 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15852 + err = PTR_ERR(h_file);
15853 + if (IS_ERR(h_file))
15857 + err = vfs_fallocate(h_file, mode, offset, len);
15859 + au_write_post(inode, h_file, &wpre, /*written*/1);
15862 + si_read_unlock(inode->i_sb);
15863 + inode_unlock(inode);
15867 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15868 + struct file *dst, loff_t dst_pos,
15869 + size_t len, unsigned int flags)
15872 + struct au_write_pre wpre;
15873 + enum { SRC, DST };
15875 + struct inode *inode;
15876 + struct file *h_file;
15877 + struct super_block *h_sb;
15879 +#define a_src a[SRC]
15880 +#define a_dst a[DST]
15883 + a_src.inode = file_inode(src);
15884 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15886 + a_dst.inode = file_inode(dst);
15887 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15890 + au_mtx_and_read_lock(a_dst.inode);
15892 + * in order to match the order in di_write_lock2_{child,parent}(),
15893 + * use f_path.dentry for this comparison.
15895 + if (src->f_path.dentry < dst->f_path.dentry) {
15896 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15897 + err = PTR_ERR(a_src.h_file);
15898 + if (IS_ERR(a_src.h_file))
15901 + wpre.lsc = AuLsc_FI_2;
15902 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15903 + err = PTR_ERR(a_dst.h_file);
15904 + if (IS_ERR(a_dst.h_file)) {
15905 + au_read_post(a_src.inode, a_src.h_file);
15909 + wpre.lsc = AuLsc_FI_1;
15910 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15911 + err = PTR_ERR(a_dst.h_file);
15912 + if (IS_ERR(a_dst.h_file))
15915 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15916 + err = PTR_ERR(a_src.h_file);
15917 + if (IS_ERR(a_src.h_file)) {
15918 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15925 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15926 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15927 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15933 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15934 + dst_pos, len, flags);
15937 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15938 + fi_read_unlock(src);
15939 + au_read_post(a_src.inode, a_src.h_file);
15941 + si_read_unlock(a_dst.inode->i_sb);
15942 + inode_unlock(a_dst.inode);
15949 +/* ---------------------------------------------------------------------- */
15952 + * The locking order around current->mmap_sem.
15953 + * - in most and regular cases
15954 + * file I/O syscall -- aufs_read() or something
15955 + * -- si_rwsem for read -- mmap_sem
15956 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15958 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15959 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15960 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15961 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15962 + * It means that when aufs acquires si_rwsem for write, the process should never
15963 + * acquire mmap_sem.
15965 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15966 + * problem either since any directory is not able to be mmap-ed.
15967 + * The similar scenario is applied to aufs_readlink() too.
15970 +#if 0 /* stop calling security_file_mmap() */
15971 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15972 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15974 +static unsigned long au_arch_prot_conv(unsigned long flags)
15976 + /* currently ppc64 only */
15977 +#ifdef CONFIG_PPC64
15978 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15979 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15980 + return AuConv_VM_PROT(flags, SAO);
15982 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15987 +static unsigned long au_prot_conv(unsigned long flags)
15989 + return AuConv_VM_PROT(flags, READ)
15990 + | AuConv_VM_PROT(flags, WRITE)
15991 + | AuConv_VM_PROT(flags, EXEC)
15992 + | au_arch_prot_conv(flags);
15995 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15996 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15998 +static unsigned long au_flag_conv(unsigned long flags)
16000 + return AuConv_VM_MAP(flags, GROWSDOWN)
16001 + | AuConv_VM_MAP(flags, DENYWRITE)
16002 + | AuConv_VM_MAP(flags, LOCKED);
16006 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16009 + const unsigned char wlock
16010 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16011 + struct super_block *sb;
16012 + struct file *h_file;
16013 + struct inode *inode;
16015 + AuDbgVmRegion(file, vma);
16017 + inode = file_inode(file);
16018 + sb = inode->i_sb;
16020 + si_read_lock(sb, AuLock_NOPLMW);
16022 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16024 + err = PTR_ERR(h_file);
16025 + if (IS_ERR(h_file))
16029 + au_set_mmapped(file);
16030 + au_vm_file_reset(vma, h_file);
16032 + * we cannot call security_mmap_file() here since it may acquire
16033 + * mmap_sem or i_mutex.
16035 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16036 + * au_flag_conv(vma->vm_flags));
16039 + err = call_mmap(h_file, vma);
16041 + au_vm_prfile_set(vma, file);
16042 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16043 + goto out_fput; /* success */
16045 + au_unset_mmapped(file);
16046 + au_vm_file_reset(vma, file);
16050 + ii_write_unlock(inode);
16055 + si_read_unlock(sb);
16061 +/* ---------------------------------------------------------------------- */
16063 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16067 + struct au_write_pre wpre;
16068 + struct inode *inode;
16069 + struct file *h_file;
16071 + err = 0; /* -EBADF; */ /* posix? */
16072 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16075 + inode = file_inode(file);
16076 + au_mtx_and_read_lock(inode);
16079 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16080 + err = PTR_ERR(h_file);
16081 + if (IS_ERR(h_file))
16084 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16085 + au_write_post(inode, h_file, &wpre, /*written*/0);
16088 + si_read_unlock(inode->i_sb);
16089 + inode_unlock(inode);
16094 +static int aufs_fasync(int fd, struct file *file, int flag)
16097 + struct file *h_file;
16098 + struct super_block *sb;
16100 + sb = file->f_path.dentry->d_sb;
16101 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16103 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16104 + err = PTR_ERR(h_file);
16105 + if (IS_ERR(h_file))
16108 + if (h_file->f_op->fasync)
16109 + err = h_file->f_op->fasync(fd, h_file, flag);
16110 + fput(h_file); /* instead of au_read_post() */
16113 + si_read_unlock(sb);
16117 +static int aufs_setfl(struct file *file, unsigned long arg)
16120 + struct file *h_file;
16121 + struct super_block *sb;
16123 + sb = file->f_path.dentry->d_sb;
16124 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16126 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16127 + err = PTR_ERR(h_file);
16128 + if (IS_ERR(h_file))
16131 + /* stop calling h_file->fasync */
16132 + arg |= vfsub_file_flags(file) & FASYNC;
16133 + err = setfl(/*unused fd*/-1, h_file, arg);
16134 + fput(h_file); /* instead of au_read_post() */
16137 + si_read_unlock(sb);
16141 +/* ---------------------------------------------------------------------- */
16143 +/* no one supports this operation, currently */
16144 +#if 0 /* reserved for future use */
16145 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16146 + size_t len, loff_t *pos, int more)
16151 +/* ---------------------------------------------------------------------- */
16153 +const struct file_operations aufs_file_fop = {
16154 + .owner = THIS_MODULE,
16156 + .llseek = default_llseek,
16158 + .read_iter = aufs_read_iter,
16159 + .write_iter = aufs_write_iter,
16161 +#ifdef CONFIG_AUFS_POLL
16162 + .poll = aufs_poll,
16164 + .unlocked_ioctl = aufs_ioctl_nondir,
16165 +#ifdef CONFIG_COMPAT
16166 + .compat_ioctl = aufs_compat_ioctl_nondir,
16168 + .mmap = aufs_mmap,
16169 + .open = aufs_open_nondir,
16170 + .flush = aufs_flush_nondir,
16171 + .release = aufs_release_nondir,
16172 + .fsync = aufs_fsync_nondir,
16173 + .fasync = aufs_fasync,
16174 + /* .sendpage = aufs_sendpage, */
16175 + .setfl = aufs_setfl,
16176 + .splice_write = aufs_splice_write,
16177 + .splice_read = aufs_splice_read,
16178 +#if 0 /* reserved for future use */
16179 + .aio_splice_write = aufs_aio_splice_write,
16180 + .aio_splice_read = aufs_aio_splice_read,
16182 + .fallocate = aufs_fallocate,
16183 + .copy_file_range = aufs_copy_file_range
16185 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16186 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16187 +++ linux/fs/aufs/fsctx.c 2022-10-26 22:30:38.465982192 +0200
16189 +// SPDX-License-Identifier: GPL-2.0
16191 + * Copyright (C) 2022 Junjiro R. Okajima
16193 + * This program, aufs is free software; you can redistribute it and/or modify
16194 + * it under the terms of the GNU General Public License as published by
16195 + * the Free Software Foundation; either version 2 of the License, or
16196 + * (at your option) any later version.
16198 + * This program is distributed in the hope that it will be useful,
16199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16201 + * GNU General Public License for more details.
16203 + * You should have received a copy of the GNU General Public License
16204 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16208 + * fs context, aka new mount api
16211 +#include <linux/fs_context.h>
16214 +struct au_fsctx_opts {
16215 + aufs_bindex_t bindex;
16216 + unsigned char skipped;
16217 + struct au_opt *opt, *opt_tail;
16218 + struct super_block *sb;
16219 + struct au_sbinfo *sbinfo;
16220 + struct au_opts opts;
16223 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16224 +static int cvt_err(int err)
16238 +static int au_fsctx_reconfigure(struct fs_context *fc)
16241 + unsigned int mntflags;
16242 + struct dentry *root;
16243 + struct super_block *sb;
16244 + struct inode *inode;
16245 + struct au_fsctx_opts *a = fc->fs_private;
16247 + AuDbg("fc %p\n", fc);
16251 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16253 + di_write_lock_child(root);
16254 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16255 + aufs_write_unlock(root);
16258 + inode = d_inode(root);
16259 + inode_lock(inode);
16260 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16261 + if (unlikely(err))
16263 + di_write_lock_child(root);
16265 + /* au_opts_remount() may return an error */
16266 + err = au_opts_remount(sb, &a->opts);
16268 + if (au_ftest_opts(a->opts.flags, REFRESH))
16269 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16272 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16273 + mntflags = au_mntflags(sb);
16274 + do_dx = !!au_opt_test(mntflags, DIO);
16275 + au_dy_arefresh(do_dx);
16278 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16279 + aufs_write_unlock(root);
16282 + inode_unlock(inode);
16283 + err = cvt_err(err);
16289 +/* ---------------------------------------------------------------------- */
16291 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16294 + struct au_fsctx_opts *a = fc->fs_private;
16295 + struct au_sbinfo *sbinfo = a->sbinfo;
16296 + struct dentry *root;
16297 + struct inode *inode;
16299 + sbinfo->si_sb = sb;
16300 + sb->s_fs_info = sbinfo;
16301 + kobject_get(&sbinfo->si_kobj);
16303 + __si_write_lock(sb);
16305 + au_sbilist_add(sb);
16307 + /* all timestamps always follow the ones on the branch */
16308 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16309 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16310 + sb->s_op = &aufs_sop;
16311 + sb->s_d_op = &aufs_dop;
16312 + sb->s_magic = AUFS_SUPER_MAGIC;
16313 + sb->s_maxbytes = 0;
16314 + sb->s_stack_depth = 1;
16315 + au_export_init(sb);
16316 + au_xattr_init(sb);
16318 + err = au_alloc_root(sb);
16319 + if (unlikely(err)) {
16320 + si_write_unlock(sb);
16323 + root = sb->s_root;
16324 + inode = d_inode(root);
16325 + ii_write_lock_parent(inode);
16326 + aufs_write_unlock(root);
16328 + /* lock vfs_inode first, then aufs. */
16329 + inode_lock(inode);
16330 + aufs_write_lock(root);
16331 + err = au_opts_mount(sb, &a->opts);
16333 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16334 + sb->s_d_op = &aufs_dop_noreval;
16335 + /* infofc(fc, "%ps", sb->s_d_op); */
16336 + pr_info("%ps\n", sb->s_d_op);
16337 + au_refresh_dop(root, /*force_reval*/0);
16338 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16339 + au_refresh_iop(inode, /*force_getattr*/0);
16341 + aufs_write_unlock(root);
16342 + inode_unlock(inode);
16344 + goto out; /* success */
16347 + sb->s_root = NULL;
16350 + if (unlikely(err))
16351 + kobject_put(&sbinfo->si_kobj);
16353 + err = cvt_err(err);
16358 +static int au_fsctx_get_tree(struct fs_context *fc)
16362 + AuDbg("fc %p\n", fc);
16363 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16369 +/* ---------------------------------------------------------------------- */
16371 +static void au_fsctx_dump(struct au_opts *opts)
16373 +#ifdef CONFIG_AUFS_DEBUG
16374 + /* reduce stack space */
16376 + struct au_opt_add *add;
16377 + struct au_opt_del *del;
16378 + struct au_opt_mod *mod;
16379 + struct au_opt_xino *xino;
16380 + struct au_opt_xino_itrunc *xino_itrunc;
16381 + struct au_opt_wbr_create *create;
16383 + struct au_opt *opt;
16386 + while (opt->type != Opt_tail) {
16387 + switch (opt->type) {
16389 + u.add = &opt->add;
16390 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16391 + u.add->bindex, u.add->pathname, u.add->perm,
16392 + u.add->path.dentry);
16397 + u.del = &opt->del;
16398 + AuDbg("del {%s, %p}\n",
16399 + u.del->pathname, u.del->h_path.dentry);
16404 + u.mod = &opt->mod;
16405 + AuDbg("mod {%s, 0x%x, %p}\n",
16406 + u.mod->path, u.mod->perm, u.mod->h_root);
16409 + u.add = &opt->add;
16410 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16411 + u.add->bindex, u.add->pathname, u.add->perm,
16412 + u.add->path.dentry);
16414 + case Opt_prepend:
16415 + u.add = &opt->add;
16416 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16417 + u.add->bindex, u.add->pathname, u.add->perm,
16418 + u.add->path.dentry);
16422 + AuDbg("dirwh %d\n", opt->dirwh);
16424 + case Opt_rdcache:
16425 + AuDbg("rdcache %d\n", opt->rdcache);
16428 + AuDbg("rdblk %d\n", opt->rdblk);
16431 + AuDbg("rdhash %u\n", opt->rdhash);
16435 + u.xino = &opt->xino;
16436 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16439 +#define au_fsctx_TF(name) \
16440 + case Opt_##name: \
16444 + AuLabel(no##name); \
16447 + /* simple true/false flag */
16448 + au_fsctx_TF(trunc_xino);
16449 + au_fsctx_TF(trunc_xib);
16450 + au_fsctx_TF(dirperm1);
16451 + au_fsctx_TF(plink);
16452 + au_fsctx_TF(shwh);
16453 + au_fsctx_TF(dio);
16454 + au_fsctx_TF(warn_perm);
16455 + au_fsctx_TF(verbose);
16456 + au_fsctx_TF(sum);
16457 + au_fsctx_TF(dirren);
16458 + au_fsctx_TF(acl);
16459 +#undef au_fsctx_TF
16461 + case Opt_trunc_xino_path:
16463 + case Opt_itrunc_xino:
16464 + u.xino_itrunc = &opt->xino_itrunc;
16465 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16471 + case Opt_list_plink:
16472 + AuLabel(list_plink);
16475 + AuDbg("udba %d, %s\n",
16476 + opt->udba, au_optstr_udba(opt->udba));
16478 + case Opt_diropq_a:
16479 + AuLabel(diropq_a);
16481 + case Opt_diropq_w:
16482 + AuLabel(diropq_w);
16487 + case Opt_wbr_create:
16488 + u.create = &opt->wbr_create;
16489 + AuDbg("create %d, %s\n", u.create->wbr_create,
16490 + au_optstr_wbr_create(u.create->wbr_create));
16491 + switch (u.create->wbr_create) {
16492 + case AuWbrCreate_MFSV:
16494 + case AuWbrCreate_PMFSV:
16495 + AuDbg("%d sec\n", u.create->mfs_second);
16497 + case AuWbrCreate_MFSRR:
16499 + case AuWbrCreate_TDMFS:
16500 + AuDbg("%llu watermark\n",
16501 + u.create->mfsrr_watermark);
16503 + case AuWbrCreate_MFSRRV:
16505 + case AuWbrCreate_TDMFSV:
16507 + case AuWbrCreate_PMFSRRV:
16508 + AuDbg("%llu watermark, %d sec\n",
16509 + u.create->mfsrr_watermark,
16510 + u.create->mfs_second);
16514 + case Opt_wbr_copyup:
16515 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16516 + au_optstr_wbr_copyup(opt->wbr_copyup));
16518 + case Opt_fhsm_sec:
16519 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16523 + AuDbg("type %d\n", opt->type);
16531 +/* ---------------------------------------------------------------------- */
16534 + * For conditionally compiled mount options.
16535 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16537 +#define au_ignore_flag(name, action) \
16538 + fsparam_flag(name, action), \
16539 + fsparam_flag("no" name, Opt_ignore_silent)
16541 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16542 + fsparam_string("br", Opt_br),
16544 + /* "add=%d:%s" or "ins=%d:%s" */
16545 + fsparam_string("add", Opt_add),
16546 + fsparam_string("ins", Opt_add),
16547 + fsparam_path("append", Opt_append),
16548 + fsparam_path("prepend", Opt_prepend),
16550 + fsparam_path("del", Opt_del),
16551 + /* fsparam_s32("idel", Opt_idel), */
16552 + fsparam_path("mod", Opt_mod),
16553 + /* fsparam_string("imod", Opt_imod), */
16555 + fsparam_s32("dirwh", Opt_dirwh),
16557 + fsparam_path("xino", Opt_xino),
16558 + fsparam_flag("noxino", Opt_noxino),
16559 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16560 + /* "trunc_xino_v=%d:%d" */
16561 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16562 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16563 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16564 + /* fsparam_path("zxino", Opt_zxino), */
16565 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16567 +#ifdef CONFIG_PROC_FS
16568 + fsparam_flag_no("plink", Opt_plink),
16570 + au_ignore_flag("plink", Opt_ignore),
16573 +#ifdef CONFIG_AUFS_DEBUG
16574 + fsparam_flag("list_plink", Opt_list_plink),
16577 + fsparam_string("udba", Opt_udba),
16579 + fsparam_flag_no("dio", Opt_dio),
16581 +#ifdef CONFIG_AUFS_DIRREN
16582 + fsparam_flag_no("dirren", Opt_dirren),
16584 + au_ignore_flag("dirren", Opt_ignore),
16587 +#ifdef CONFIG_AUFS_FHSM
16588 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16590 + fsparam_s32("fhsm_sec", Opt_ignore),
16593 + /* always | a | whiteouted | w */
16594 + fsparam_string("diropq", Opt_diropq),
16596 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16598 +#ifdef CONFIG_AUFS_SHWH
16599 + fsparam_flag_no("shwh", Opt_shwh),
16601 + au_ignore_flag("shwh", Opt_err),
16604 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16606 + fsparam_flag_no("verbose", Opt_verbose),
16607 + fsparam_flag("v", Opt_verbose),
16608 + fsparam_flag("quiet", Opt_noverbose),
16609 + fsparam_flag("q", Opt_noverbose),
16610 + /* user-space may handle this */
16611 + fsparam_flag("silent", Opt_noverbose),
16613 + fsparam_flag_no("sum", Opt_sum),
16614 + fsparam_flag("wsum", Opt_wsum),
16616 + fsparam_s32("rdcache", Opt_rdcache),
16617 + /* "def" or s32 */
16618 + fsparam_string("rdblk", Opt_rdblk),
16619 + /* "def" or s32 */
16620 + fsparam_string("rdhash", Opt_rdhash),
16622 + fsparam_string("create", Opt_wbr_create),
16623 + fsparam_string("create_policy", Opt_wbr_create),
16624 + fsparam_string("cpup", Opt_wbr_copyup),
16625 + fsparam_string("copyup", Opt_wbr_copyup),
16626 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16628 + /* generic VFS flag */
16629 +#ifdef CONFIG_FS_POSIX_ACL
16630 + fsparam_flag_no("acl", Opt_acl),
16632 + au_ignore_flag("acl", Opt_ignore),
16635 + /* internal use for the scripts */
16636 + fsparam_string("si", Opt_ignore_silent),
16638 + /* obsoleted, keep them temporary */
16639 + fsparam_flag("nodlgt", Opt_ignore_silent),
16640 + fsparam_flag("clean_plink", Opt_ignore),
16641 + fsparam_string("dirs", Opt_br),
16642 + fsparam_u32("debug", Opt_ignore),
16643 + /* "whiteout" or "all" */
16644 + fsparam_string("delete", Opt_ignore),
16645 + fsparam_string("imap", Opt_ignore),
16647 + /* temporary workaround, due to old mount(8)? */
16648 + fsparam_flag("relatime", Opt_ignore_silent),
16653 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16654 + char *brspec, size_t speclen,
16655 + aufs_bindex_t bindex)
16660 + AuDbg("brspec %s\n", brspec);
16664 + speclen = strlen(brspec);
16665 + /* will be freed by au_fsctx_free() */
16666 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16667 + if (unlikely(!p)) {
16668 + errorfc(fc, "failed in %s", brspec);
16671 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16678 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16682 + struct au_fsctx_opts *a = fc->fs_private;
16683 + struct au_opt *opt = a->opt;
16684 + aufs_bindex_t bindex = a->bindex;
16686 + AuDbg("brspec %s\n", brspec);
16689 + while ((p = strsep(&brspec, ":")) && *p) {
16690 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16692 + if (unlikely(err))
16696 + if (unlikely(opt > a->opt_tail)) {
16702 + opt->type = Opt_tail;
16705 + a->bindex = bindex;
16712 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16716 + struct au_fsctx_opts *a = fc->fs_private;
16717 + struct au_opt *opt = a->opt;
16720 + p = strchr(addspec, ':');
16721 + if (unlikely(!p)) {
16722 + errorfc(fc, "bad arg in %s", addspec);
16726 + err = kstrtoint(addspec, 0, &n);
16727 + if (unlikely(err)) {
16728 + errorfc(fc, "bad integer in %s", addspec);
16731 + AuDbg("n %d\n", n);
16732 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16739 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16740 + struct fs_parameter *param)
16745 + /* will be freed by au_fsctx_free() */
16746 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16747 + if (unlikely(!del->pathname))
16749 + AuDbg("del %s\n", del->pathname);
16750 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16751 + if (unlikely(err))
16752 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16759 +#if 0 /* reserved for future use */
16760 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16761 + aufs_bindex_t bindex)
16764 + struct super_block *sb;
16765 + struct dentry *root;
16766 + struct au_fsctx_opts *a = fc->fs_private;
16772 + root = sb->s_root;
16773 + aufs_read_lock(root, AuLock_FLUSH);
16774 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16775 + errorfc(fc, "out of bounds, %d", bindex);
16780 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16781 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16784 + aufs_read_unlock(root, !AuLock_IR);
16790 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16791 + struct fs_parameter *param)
16794 + struct path path;
16798 + /* will be freed by au_fsctx_free() */
16799 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16800 + if (unlikely(!mod->path))
16804 + p = strchr(mod->path, '=');
16805 + if (unlikely(!p)) {
16806 + errorfc(fc, "no permission %s", mod->path);
16811 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16812 + if (unlikely(err)) {
16813 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16817 + mod->perm = au_br_perm_val(p);
16818 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16819 + mod->h_root = dget(path.dentry);
16827 +#if 0 /* reserved for future use */
16828 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16833 + struct super_block *sb;
16834 + struct dentry *root;
16835 + struct au_fsctx_opts *a = fc->fs_private;
16841 + p = strchr(ibrspec, ':');
16842 + if (unlikely(!p)) {
16843 + errorfc(fc, "no index, %s", ibrspec);
16847 + err = kstrtoint(ibrspec, 0, &n);
16848 + if (unlikely(err)) {
16849 + errorfc(fc, "bad integer in %s", ibrspec);
16852 + AuDbg("n %d\n", n);
16854 + root = sb->s_root;
16855 + aufs_read_lock(root, AuLock_FLUSH);
16856 + if (n < 0 || au_sbbot(sb) < n) {
16857 + errorfc(fc, "out of bounds, %d", bindex);
16862 + mod->perm = au_br_perm_val(p);
16863 + AuDbg("mod path %s, perm 0x%x, %s\n",
16864 + mod->path, mod->perm, p);
16865 + mod->h_root = dget(au_h_dptr(root, bindex));
16868 + aufs_read_unlock(root, !AuLock_IR);
16875 +static int au_fsctx_parse_xino(struct fs_context *fc,
16876 + struct au_opt_xino *xino,
16877 + struct fs_parameter *param)
16880 + struct au_fsctx_opts *a = fc->fs_private;
16883 + /* will be freed by au_opts_free() */
16884 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16885 + if (unlikely(!xino->path))
16887 + AuDbg("path %s\n", xino->path);
16889 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16891 + err = PTR_ERR(xino->file);
16892 + if (IS_ERR(xino->file)) {
16893 + xino->file = NULL;
16898 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16900 + errorfc(fc, "%s must be outside", xino->path);
16909 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16910 + struct au_opt_xino_itrunc *xino_itrunc,
16914 + aufs_bindex_t bbot, bindex;
16915 + struct path path;
16916 + struct dentry *root;
16917 + struct au_fsctx_opts *a = fc->fs_private;
16919 + AuDebugOn(!a->sb);
16921 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16922 + if (unlikely(err)) {
16923 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16927 + xino_itrunc->bindex = -1;
16928 + root = a->sb->s_root;
16929 + aufs_read_lock(root, AuLock_FLUSH);
16930 + bbot = au_sbbot(a->sb);
16931 + for (bindex = 0; bindex <= bbot; bindex++) {
16932 + if (au_h_dptr(root, bindex) == path.dentry) {
16933 + xino_itrunc->bindex = bindex;
16937 + aufs_read_unlock(root, !AuLock_IR);
16940 + if (unlikely(xino_itrunc->bindex < 0)) {
16942 + errorfc(fc, "no such branch %s", pathname);
16950 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16951 + struct au_opt_xino_itrunc *xino_itrunc,
16952 + unsigned int bindex)
16955 + aufs_bindex_t bbot;
16956 + struct super_block *sb;
16957 + struct au_fsctx_opts *a = fc->fs_private;
16963 + si_noflush_read_lock(sb);
16964 + bbot = au_sbbot(sb);
16965 + si_read_unlock(sb);
16966 + if (bindex <= bbot)
16967 + xino_itrunc->bindex = bindex;
16970 + errorfc(fc, "out of bounds, %u", bindex);
16977 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16980 + struct fs_parse_result result;
16981 + struct au_fsctx_opts *a = fc->fs_private;
16982 + struct au_opt *opt = a->opt;
16984 + AuDbg("fc %p, param {key %s, string %s}\n",
16985 + fc, param->key, param->string);
16986 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16987 + if (unlikely(err < 0))
16990 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16991 + token, result.negated, result.uint_64);
16997 + err = au_fsctx_parse_br(fc, param->string);
17000 + err = au_fsctx_parse_add(fc, param->string);
17003 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17004 + /*dummy bindex*/1);
17006 + case Opt_prepend:
17007 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17012 + err = au_fsctx_parse_del(fc, &opt->del, param);
17014 +#if 0 /* reserved for future use */
17021 + del->pathname = "(indexed)";
17022 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17027 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17029 +#ifdef IMOD /* reserved for future use */
17036 + u.mod->path = "(indexed)";
17037 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17042 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17044 + case Opt_trunc_xino_path:
17046 + errorfc(fc, "no such branch %s", param->string);
17049 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17053 + case Opt_trunc_xino_v:
17059 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17063 + case Opt_itrunc_xino:
17065 + errorfc(fc, "out of bounds %s", param->string);
17068 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17074 + opt->dirwh = result.int_32;
17077 + case Opt_rdcache:
17078 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17079 + errorfc(fc, "rdcache must be smaller than %d",
17080 + AUFS_RDCACHE_MAX);
17084 + opt->rdcache = result.int_32;
17089 + opt->rdblk = AUFS_RDBLK_DEF;
17090 + if (!strcmp(param->string, "def"))
17093 + err = kstrtoint(param->string, 0, &result.int_32);
17094 + if (unlikely(err)) {
17095 + errorfc(fc, "bad value in %s", param->key);
17099 + if (unlikely(result.int_32 < 0
17100 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17101 + errorfc(fc, "bad value in %s", param->key);
17104 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17105 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17109 + opt->rdblk = result.int_32;
17114 + opt->rdhash = AUFS_RDHASH_DEF;
17115 + if (!strcmp(param->string, "def"))
17118 + err = kstrtoint(param->string, 0, &result.int_32);
17119 + if (unlikely(err)) {
17120 + errorfc(fc, "bad value in %s", param->key);
17123 + /* how about zero? */
17124 + if (result.int_32 < 0
17125 + || result.int_32 * sizeof(struct hlist_head)
17126 + > KMALLOC_MAX_SIZE) {
17128 + errorfc(fc, "bad integer in %s", param->key);
17131 + opt->rdhash = result.int_32;
17136 + * As other options, fs/aufs/opts.c can handle these strings by
17137 + * match_token(). But "diropq=" is deprecated now and will
17138 + * never have other value. So simple strcmp() is enough here.
17140 + if (!strcmp(param->string, "a") ||
17141 + !strcmp(param->string, "always")) {
17143 + opt->type = Opt_diropq_a;
17144 + } else if (!strcmp(param->string, "w") ||
17145 + !strcmp(param->string, "whiteouted")) {
17147 + opt->type = Opt_diropq_w;
17149 + errorfc(fc, "unknown value %s", param->string);
17153 + opt->udba = au_udba_val(param->string);
17154 + if (opt->udba >= 0)
17157 + errorf(fc, "wrong value, %s", param->string);
17160 + case Opt_wbr_create:
17161 + opt->wbr_create.wbr_create
17162 + = au_wbr_create_val(param->string, &opt->wbr_create);
17163 + if (opt->wbr_create.wbr_create >= 0)
17166 + errorf(fc, "wrong value, %s", param->key);
17169 + case Opt_wbr_copyup:
17170 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17171 + if (opt->wbr_copyup >= 0)
17174 + errorfc(fc, "wrong value, %s", param->key);
17177 + case Opt_fhsm_sec:
17178 + if (unlikely(result.int_32 < 0)) {
17179 + errorfc(fc, "bad integer in %s\n", param->key);
17184 + opt->fhsm_second = result.int_32;
17186 + warnfc(fc, "ignored %s %s", param->key, param->string);
17189 + /* simple true/false flag */
17190 +#define au_fsctx_TF(name) \
17191 + case Opt_##name: \
17193 + opt->tf = !result.negated; \
17195 + au_fsctx_TF(trunc_xino);
17196 + au_fsctx_TF(trunc_xib);
17197 + au_fsctx_TF(dirperm1);
17198 + au_fsctx_TF(plink);
17199 + au_fsctx_TF(shwh);
17200 + au_fsctx_TF(dio);
17201 + au_fsctx_TF(warn_perm);
17202 + au_fsctx_TF(verbose);
17203 + au_fsctx_TF(sum);
17204 + au_fsctx_TF(dirren);
17205 + au_fsctx_TF(acl);
17206 +#undef au_fsctx_TF
17208 + case Opt_noverbose:
17210 + opt->type = Opt_verbose;
17216 + case Opt_list_plink:
17223 + warnfc(fc, "ignored %s", param->key);
17225 + case Opt_ignore_silent:
17234 + if (unlikely(err))
17242 + case Opt_noverbose:
17247 + opt->type = token;
17251 + if (unlikely(opt > a->opt_tail)) {
17255 + opt->type = Opt_tail;
17263 + * these options accept both 'name=val' and 'name:val' form.
17264 + * some accept optional '=' in its value.
17265 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17267 +static inline unsigned int is_colonopt(char *str)
17269 +#define do_test(name) \
17270 + if (!strncmp(str, name ":", sizeof(name))) \
17271 + return sizeof(name) - 1
17275 + do_test("append");
17276 + do_test("prepend");
17278 + /* do_test("idel"); */
17280 + /* do_test("imod"); */
17286 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17291 + struct au_fsctx_opts *a = fc->fs_private;
17294 + AuDbg("str %s\n", str);
17296 + u = is_colonopt(str);
17299 + str = strchr(str, ',');
17305 + AuDbg("str %s\n", str);
17307 + err = generic_parse_monolithic(fc, str);
17309 + au_fsctx_dump(&a->opts);
17314 +/* ---------------------------------------------------------------------- */
17316 +static void au_fsctx_opts_free(struct au_opts *opts)
17318 + struct au_opt *opt;
17321 + while (opt->type != Opt_tail) {
17322 + switch (opt->type) {
17327 + case Opt_prepend:
17328 + kfree(opt->add.pathname);
17329 + path_put(&opt->add.path);
17332 + kfree(opt->del.pathname);
17335 + path_put(&opt->del.h_path);
17338 + kfree(opt->mod.path);
17341 + dput(opt->mod.h_root);
17344 + kfree(opt->xino.path);
17345 + fput(opt->xino.file);
17352 +static void au_fsctx_free(struct fs_context *fc)
17354 + struct au_fsctx_opts *a = fc->fs_private;
17356 + /* fs_type=%p, root=%pD */
17357 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17358 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17360 + kobject_put(&a->sbinfo->si_kobj);
17361 + au_fsctx_opts_free(&a->opts);
17362 + free_page((unsigned long)a->opts.opt);
17366 +static const struct fs_context_operations au_fsctx_ops = {
17367 + .free = au_fsctx_free,
17368 + .parse_param = au_fsctx_parse_param,
17369 + .parse_monolithic = au_fsctx_parse_monolithic,
17370 + .get_tree = au_fsctx_get_tree,
17371 + .reconfigure = au_fsctx_reconfigure
17373 + * nfs4 requires ->dup()? No.
17374 + * I don't know what is this ->dup() for.
17378 +int aufs_fsctx_init(struct fs_context *fc)
17381 + struct au_fsctx_opts *a;
17383 + /* fs_type=%p, root=%pD */
17384 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17385 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17387 + /* they will be freed by au_fsctx_free() */
17389 + a = kzalloc(sizeof(*a), GFP_NOFS);
17390 + if (unlikely(!a))
17393 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17394 + if (unlikely(!a->opts.opt))
17396 + a->opt = a->opts.opt;
17397 + a->opt->type = Opt_tail;
17398 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17399 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17400 + a->opts.sb_flags = fc->sb_flags;
17404 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17405 + a->opts.flags = AuOpts_REMOUNT;
17406 + a->sb = fc->root->d_sb;
17407 + a->sbinfo = au_sbi(a->sb);
17408 + kobject_get(&a->sbinfo->si_kobj);
17410 + a->sbinfo = au_si_alloc(a->sb);
17411 + AuDebugOn(!a->sbinfo);
17412 + err = PTR_ERR(a->sbinfo);
17413 + if (IS_ERR(a->sbinfo))
17415 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17419 + fc->fs_private = a;
17420 + fc->ops = &au_fsctx_ops;
17421 + goto out; /* success */
17424 + free_page((unsigned long)a->opts.opt);
17431 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17432 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17433 +++ linux/fs/aufs/fstype.h 2022-10-26 22:30:38.465982192 +0200
17435 +/* SPDX-License-Identifier: GPL-2.0 */
17437 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17439 + * This program, aufs is free software; you can redistribute it and/or modify
17440 + * it under the terms of the GNU General Public License as published by
17441 + * the Free Software Foundation; either version 2 of the License, or
17442 + * (at your option) any later version.
17444 + * This program is distributed in the hope that it will be useful,
17445 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17446 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17447 + * GNU General Public License for more details.
17449 + * You should have received a copy of the GNU General Public License
17450 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17454 + * judging filesystem type
17457 +#ifndef __AUFS_FSTYPE_H__
17458 +#define __AUFS_FSTYPE_H__
17462 +#include <linux/fs.h>
17463 +#include <linux/magic.h>
17464 +#include <linux/nfs_fs.h>
17465 +#include <linux/romfs_fs.h>
17467 +static inline int au_test_aufs(struct super_block *sb)
17469 + return sb->s_magic == AUFS_SUPER_MAGIC;
17472 +static inline const char *au_sbtype(struct super_block *sb)
17474 + return sb->s_type->name;
17477 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17479 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17480 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17486 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17488 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17489 + return sb->s_magic == ROMFS_MAGIC;
17495 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17497 +#if IS_ENABLED(CONFIG_CRAMFS)
17498 + return sb->s_magic == CRAMFS_MAGIC;
17503 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17505 +#if IS_ENABLED(CONFIG_NFS_FS)
17506 + return sb->s_magic == NFS_SUPER_MAGIC;
17512 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17514 +#if IS_ENABLED(CONFIG_FUSE_FS)
17515 + return sb->s_magic == FUSE_SUPER_MAGIC;
17521 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17523 +#if IS_ENABLED(CONFIG_XFS_FS)
17524 + return sb->s_magic == XFS_SB_MAGIC;
17530 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17532 +#ifdef CONFIG_TMPFS
17533 + return sb->s_magic == TMPFS_MAGIC;
17539 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17541 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17542 + return !strcmp(au_sbtype(sb), "ecryptfs");
17548 +static inline int au_test_ramfs(struct super_block *sb)
17550 + return sb->s_magic == RAMFS_MAGIC;
17553 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17555 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17556 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17562 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17564 +#ifdef CONFIG_PROC_FS
17565 + return sb->s_magic == PROC_SUPER_MAGIC;
17571 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17573 +#ifdef CONFIG_SYSFS
17574 + return sb->s_magic == SYSFS_MAGIC;
17580 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17582 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17583 + return sb->s_magic == CONFIGFS_MAGIC;
17589 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17591 +#if IS_ENABLED(CONFIG_MINIX_FS)
17592 + return sb->s_magic == MINIX3_SUPER_MAGIC
17593 + || sb->s_magic == MINIX2_SUPER_MAGIC
17594 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17595 + || sb->s_magic == MINIX_SUPER_MAGIC
17596 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17602 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17604 +#if IS_ENABLED(CONFIG_FAT_FS)
17605 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17611 +static inline int au_test_msdos(struct super_block *sb)
17613 + return au_test_fat(sb);
17616 +static inline int au_test_vfat(struct super_block *sb)
17618 + return au_test_fat(sb);
17621 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17623 +#ifdef CONFIG_SECURITYFS
17624 + return sb->s_magic == SECURITYFS_MAGIC;
17630 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17632 +#if IS_ENABLED(CONFIG_SQUASHFS)
17633 + return sb->s_magic == SQUASHFS_MAGIC;
17639 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17641 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17642 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17648 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17650 +#if IS_ENABLED(CONFIG_XENFS)
17651 + return sb->s_magic == XENFS_SUPER_MAGIC;
17657 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17659 +#ifdef CONFIG_DEBUG_FS
17660 + return sb->s_magic == DEBUGFS_MAGIC;
17666 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17668 +#if IS_ENABLED(CONFIG_NILFS)
17669 + return sb->s_magic == NILFS_SUPER_MAGIC;
17675 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17677 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17678 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17684 +/* ---------------------------------------------------------------------- */
17686 + * they can't be an aufs branch.
17688 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17691 +#ifndef CONFIG_AUFS_BR_RAMFS
17692 + au_test_ramfs(sb) ||
17694 + au_test_procfs(sb)
17695 + || au_test_sysfs(sb)
17696 + || au_test_configfs(sb)
17697 + || au_test_debugfs(sb)
17698 + || au_test_securityfs(sb)
17699 + || au_test_xenfs(sb)
17700 + || au_test_ecryptfs(sb)
17701 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17702 + || au_test_aufs(sb); /* will be supported in next version */
17705 +static inline int au_test_fs_remote(struct super_block *sb)
17707 + return !au_test_tmpfs(sb)
17708 +#ifdef CONFIG_AUFS_BR_RAMFS
17709 + && !au_test_ramfs(sb)
17711 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17714 +/* ---------------------------------------------------------------------- */
17717 + * Note: these functions (below) are created after reading ->getattr() in all
17718 + * filesystems under linux/fs. it means we have to do so in every update...
17722 + * some filesystems require getattr to refresh the inode attributes before
17724 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17725 + * and leave the work for d_revalidate()
17727 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17729 + return au_test_nfs(sb)
17730 + || au_test_fuse(sb)
17731 + /* || au_test_btrfs(sb) */ /* untested */
17736 + * filesystems which don't maintain i_size or i_blocks.
17738 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17740 + return au_test_xfs(sb)
17741 + || au_test_btrfs(sb)
17742 + || au_test_ubifs(sb)
17743 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17744 + /* || au_test_minix(sb) */ /* untested */
17749 + * filesystems which don't store the correct value in some of their inode
17752 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17754 + return au_test_fs_bad_iattr_size(sb)
17755 + || au_test_fat(sb)
17756 + || au_test_msdos(sb)
17757 + || au_test_vfat(sb);
17760 +/* they don't check i_nlink in link(2) */
17761 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17763 + return au_test_tmpfs(sb)
17764 +#ifdef CONFIG_AUFS_BR_RAMFS
17765 + || au_test_ramfs(sb)
17767 + || au_test_ubifs(sb)
17768 + || au_test_hfsplus(sb);
17772 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17774 +static inline int au_test_fs_notime(struct super_block *sb)
17776 + return au_test_nfs(sb)
17777 + || au_test_fuse(sb)
17778 + || au_test_ubifs(sb)
17782 +/* temporary support for i#1 in cramfs */
17783 +static inline int au_test_fs_unique_ino(struct inode *inode)
17785 + if (au_test_cramfs(inode->i_sb))
17786 + return inode->i_ino != 1;
17790 +/* ---------------------------------------------------------------------- */
17793 + * the filesystem where the xino files placed must support i/o after unlink and
17794 + * maintain i_size and i_blocks.
17796 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17798 + return au_test_fs_remote(sb)
17799 + || au_test_fs_bad_iattr_size(sb)
17800 + /* don't want unnecessary work for xino */
17801 + || au_test_aufs(sb)
17802 + || au_test_ecryptfs(sb)
17803 + || au_test_nilfs(sb);
17806 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17808 + return au_test_tmpfs(sb)
17809 + || au_test_ramfs(sb);
17813 + * test if the @sb is real-readonly.
17815 +static inline int au_test_fs_rr(struct super_block *sb)
17817 + return au_test_squashfs(sb)
17818 + || au_test_iso9660(sb)
17819 + || au_test_cramfs(sb)
17820 + || au_test_romfs(sb);
17824 + * test if the @inode is nfs with 'noacl' option
17825 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17827 +static inline int au_test_nfs_noacl(struct inode *inode)
17829 + return au_test_nfs(inode->i_sb)
17830 + /* && IS_POSIXACL(inode) */
17831 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17834 +#endif /* __KERNEL__ */
17835 +#endif /* __AUFS_FSTYPE_H__ */
17836 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17837 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17838 +++ linux/fs/aufs/hbl.h 2022-10-26 22:30:38.465982192 +0200
17840 +/* SPDX-License-Identifier: GPL-2.0 */
17842 + * Copyright (C) 2017-2021 Junjiro R. Okajima
17844 + * This program, aufs is free software; you can redistribute it and/or modify
17845 + * it under the terms of the GNU General Public License as published by
17846 + * the Free Software Foundation; either version 2 of the License, or
17847 + * (at your option) any later version.
17849 + * This program is distributed in the hope that it will be useful,
17850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17852 + * GNU General Public License for more details.
17854 + * You should have received a copy of the GNU General Public License
17855 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17859 + * helpers for hlist_bl.h
17862 +#ifndef __AUFS_HBL_H__
17863 +#define __AUFS_HBL_H__
17867 +#include <linux/list_bl.h>
17869 +static inline void au_hbl_add(struct hlist_bl_node *node,
17870 + struct hlist_bl_head *hbl)
17872 + hlist_bl_lock(hbl);
17873 + hlist_bl_add_head(node, hbl);
17874 + hlist_bl_unlock(hbl);
17877 +static inline void au_hbl_del(struct hlist_bl_node *node,
17878 + struct hlist_bl_head *hbl)
17880 + hlist_bl_lock(hbl);
17881 + hlist_bl_del(node);
17882 + hlist_bl_unlock(hbl);
17885 +#define au_hbl_for_each(pos, head) \
17886 + for (pos = hlist_bl_first(head); \
17890 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17892 + unsigned long cnt;
17893 + struct hlist_bl_node *pos;
17896 + hlist_bl_lock(hbl);
17897 + au_hbl_for_each(pos, hbl)
17899 + hlist_bl_unlock(hbl);
17903 +#endif /* __KERNEL__ */
17904 +#endif /* __AUFS_HBL_H__ */
17905 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17906 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17907 +++ linux/fs/aufs/hfsnotify.c 2022-10-26 22:30:38.465982192 +0200
17909 +// SPDX-License-Identifier: GPL-2.0
17911 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17913 + * This program, aufs is free software; you can redistribute it and/or modify
17914 + * it under the terms of the GNU General Public License as published by
17915 + * the Free Software Foundation; either version 2 of the License, or
17916 + * (at your option) any later version.
17918 + * This program is distributed in the hope that it will be useful,
17919 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17920 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17921 + * GNU General Public License for more details.
17923 + * You should have received a copy of the GNU General Public License
17924 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17928 + * fsnotify for the lower directories
17933 +/* FS_IN_IGNORED is unnecessary */
17934 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17935 + | FS_CREATE | FS_EVENT_ON_CHILD);
17936 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17937 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17939 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17941 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17943 + /* AuDbg("here\n"); */
17944 + au_cache_free_hnotify(hn);
17945 + smp_mb__before_atomic(); /* for atomic64_dec */
17946 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17947 + wake_up(&au_hfsn_wq);
17950 +static int au_hfsn_alloc(struct au_hinode *hinode)
17953 + struct au_hnotify *hn;
17954 + struct super_block *sb;
17955 + struct au_branch *br;
17956 + struct fsnotify_mark *mark;
17957 + aufs_bindex_t bindex;
17959 + hn = hinode->hi_notify;
17960 + sb = hn->hn_aufs_inode->i_sb;
17961 + bindex = au_br_index(sb, hinode->hi_id);
17962 + br = au_sbr(sb, bindex);
17963 + AuDebugOn(!br->br_hfsn);
17965 + mark = &hn->hn_mark;
17966 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17967 + mark->mask = AuHfsnMask;
17969 + * by udba rename or rmdir, aufs assign a new inode to the known
17970 + * h_inode, so specify 1 to allow dups.
17973 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17979 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17981 + struct fsnotify_mark *mark;
17982 + unsigned long long ull;
17983 + struct fsnotify_group *group;
17985 + ull = atomic64_inc_return(&au_hfsn_ifree);
17988 + mark = &hn->hn_mark;
17989 + spin_lock(&mark->lock);
17990 + group = mark->group;
17991 + fsnotify_get_group(group);
17992 + spin_unlock(&mark->lock);
17994 + fsnotify_destroy_mark(mark, group);
17995 + fsnotify_put_mark(mark);
17996 + fsnotify_put_group(group);
17999 + /* free hn by myself */
18003 +/* ---------------------------------------------------------------------- */
18005 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18007 + struct fsnotify_mark *mark;
18009 + mark = &hinode->hi_notify->hn_mark;
18010 + spin_lock(&mark->lock);
18012 + AuDebugOn(mark->mask & AuHfsnMask);
18013 + mark->mask |= AuHfsnMask;
18015 + AuDebugOn(!(mark->mask & AuHfsnMask));
18016 + mark->mask &= ~AuHfsnMask;
18018 + spin_unlock(&mark->lock);
18019 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18022 +/* ---------------------------------------------------------------------- */
18024 +/* #define AuDbgHnotify */
18025 +#ifdef AuDbgHnotify
18026 +static char *au_hfsn_name(u32 mask)
18028 +#ifdef CONFIG_AUFS_DEBUG
18029 +#define test_ret(flag) \
18031 + if (mask & flag) \
18034 + test_ret(FS_ACCESS);
18035 + test_ret(FS_MODIFY);
18036 + test_ret(FS_ATTRIB);
18037 + test_ret(FS_CLOSE_WRITE);
18038 + test_ret(FS_CLOSE_NOWRITE);
18039 + test_ret(FS_OPEN);
18040 + test_ret(FS_MOVED_FROM);
18041 + test_ret(FS_MOVED_TO);
18042 + test_ret(FS_CREATE);
18043 + test_ret(FS_DELETE);
18044 + test_ret(FS_DELETE_SELF);
18045 + test_ret(FS_MOVE_SELF);
18046 + test_ret(FS_UNMOUNT);
18047 + test_ret(FS_Q_OVERFLOW);
18048 + test_ret(FS_IN_IGNORED);
18049 + test_ret(FS_ISDIR);
18050 + test_ret(FS_IN_ONESHOT);
18051 + test_ret(FS_EVENT_ON_CHILD);
18060 +/* ---------------------------------------------------------------------- */
18062 +static void au_hfsn_free_group(struct fsnotify_group *group)
18064 + struct au_br_hfsnotify *hfsn = group->private;
18066 + /* AuDbg("here\n"); */
18067 + au_kfree_try_rcu(hfsn);
18070 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18071 + u32 mask, const void *data, int data_type,
18072 + struct inode *dir,
18073 + const struct qstr *file_name, u32 cookie,
18074 + struct fsnotify_iter_info *iter_info)
18077 + struct au_hnotify *hnotify;
18078 + struct inode *h_dir, *h_inode;
18079 + struct fsnotify_mark *inode_mark;
18081 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
18084 + /* if FS_UNMOUNT happens, there must be another bug */
18085 + AuDebugOn(mask & FS_UNMOUNT);
18086 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18091 +#ifdef AuDbgHnotify
18093 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
18094 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
18095 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18096 + h_dir->i_ino, mask, au_hfsn_name(mask),
18097 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
18098 + /* WARN_ON(1); */
18103 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18104 + AuDebugOn(!inode_mark);
18105 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18106 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18112 +static struct fsnotify_ops au_hfsn_ops = {
18113 + .handle_event = au_hfsn_handle_event,
18114 + .free_group_priv = au_hfsn_free_group,
18115 + .free_mark = au_hfsn_free_mark
18118 +/* ---------------------------------------------------------------------- */
18120 +static void au_hfsn_fin_br(struct au_branch *br)
18122 + struct au_br_hfsnotify *hfsn;
18124 + hfsn = br->br_hfsn;
18127 + fsnotify_put_group(hfsn->hfsn_group);
18132 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18135 + struct fsnotify_group *group;
18136 + struct au_br_hfsnotify *hfsn;
18139 + br->br_hfsn = NULL;
18140 + if (!au_br_hnotifyable(perm))
18144 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18145 + if (unlikely(!hfsn))
18149 + group = fsnotify_alloc_group(&au_hfsn_ops);
18150 + if (IS_ERR(group)) {
18151 + err = PTR_ERR(group);
18152 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18156 + group->private = hfsn;
18157 + hfsn->hfsn_group = group;
18158 + br->br_hfsn = hfsn;
18159 + goto out; /* success */
18162 + au_kfree_try_rcu(hfsn);
18167 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18172 + if (!br->br_hfsn)
18173 + err = au_hfsn_init_br(br, perm);
18178 +/* ---------------------------------------------------------------------- */
18180 +static void au_hfsn_fin(void)
18182 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18183 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18186 +const struct au_hnotify_op au_hnotify_op = {
18187 + .ctl = au_hfsn_ctl,
18188 + .alloc = au_hfsn_alloc,
18189 + .free = au_hfsn_free,
18191 + .fin = au_hfsn_fin,
18193 + .reset_br = au_hfsn_reset_br,
18194 + .fin_br = au_hfsn_fin_br,
18195 + .init_br = au_hfsn_init_br
18197 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18198 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18199 +++ linux/fs/aufs/hfsplus.c 2022-10-26 22:30:38.465982192 +0200
18201 +// SPDX-License-Identifier: GPL-2.0
18203 + * Copyright (C) 2010-2021 Junjiro R. Okajima
18205 + * This program, aufs is free software; you can redistribute it and/or modify
18206 + * it under the terms of the GNU General Public License as published by
18207 + * the Free Software Foundation; either version 2 of the License, or
18208 + * (at your option) any later version.
18210 + * This program is distributed in the hope that it will be useful,
18211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18213 + * GNU General Public License for more details.
18215 + * You should have received a copy of the GNU General Public License
18216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18220 + * special support for filesystems which acquires an inode mutex
18221 + * at final closing a file, eg, hfsplus.
18223 + * This trick is very simple and stupid, just to open the file before really
18224 + * necessary open to tell hfsplus that this is not the final closing.
18225 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18226 + * and au_h_open_post() after releasing it.
18231 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18234 + struct file *h_file;
18235 + struct dentry *h_dentry;
18237 + h_dentry = au_h_dptr(dentry, bindex);
18238 + AuDebugOn(!h_dentry);
18239 + AuDebugOn(d_is_negative(h_dentry));
18242 + if (au_test_hfsplus(h_dentry->d_sb)
18243 + && d_is_reg(h_dentry))
18244 + h_file = au_h_open(dentry, bindex,
18245 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18246 + /*file*/NULL, force_wr);
18250 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18251 + struct file *h_file)
18253 + struct au_branch *br;
18257 + br = au_sbr(dentry->d_sb, bindex);
18258 + au_lcnt_dec(&br->br_nfiles);
18261 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18262 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18263 +++ linux/fs/aufs/hnotify.c 2022-10-26 22:30:38.465982192 +0200
18265 +// SPDX-License-Identifier: GPL-2.0
18267 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18269 + * This program, aufs is free software; you can redistribute it and/or modify
18270 + * it under the terms of the GNU General Public License as published by
18271 + * the Free Software Foundation; either version 2 of the License, or
18272 + * (at your option) any later version.
18274 + * This program is distributed in the hope that it will be useful,
18275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18277 + * GNU General Public License for more details.
18279 + * You should have received a copy of the GNU General Public License
18280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18284 + * abstraction to notify the direct changes on lower directories
18287 +/* #include <linux/iversion.h> */
18290 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18293 + struct au_hnotify *hn;
18296 + hn = au_cache_alloc_hnotify();
18298 + hn->hn_aufs_inode = inode;
18299 + hinode->hi_notify = hn;
18300 + err = au_hnotify_op.alloc(hinode);
18302 + if (unlikely(err)) {
18303 + hinode->hi_notify = NULL;
18304 + au_cache_free_hnotify(hn);
18306 + * The upper dir was removed by udba, but the same named
18307 + * dir left. In this case, aufs assigns a new inode
18308 + * number and set the monitor again.
18309 + * For the lower dir, the old monitor is still left.
18311 + if (err == -EEXIST)
18320 +void au_hn_free(struct au_hinode *hinode)
18322 + struct au_hnotify *hn;
18324 + hn = hinode->hi_notify;
18326 + hinode->hi_notify = NULL;
18327 + if (au_hnotify_op.free(hinode, hn))
18328 + au_cache_free_hnotify(hn);
18332 +/* ---------------------------------------------------------------------- */
18334 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18336 + if (hinode->hi_notify)
18337 + au_hnotify_op.ctl(hinode, do_set);
18340 +void au_hn_reset(struct inode *inode, unsigned int flags)
18342 + aufs_bindex_t bindex, bbot;
18343 + struct inode *hi;
18344 + struct dentry *iwhdentry;
18346 + bbot = au_ibbot(inode);
18347 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18348 + hi = au_h_iptr(inode, bindex);
18352 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18353 + iwhdentry = au_hi_wh(inode, bindex);
18357 + au_set_h_iptr(inode, bindex, NULL, 0);
18358 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18359 + flags & ~AuHi_XINO);
18362 + /* inode_unlock(hi); */
18366 +/* ---------------------------------------------------------------------- */
18368 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18371 + aufs_bindex_t bindex, bbot, bfound, btop;
18372 + struct inode *h_i;
18375 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18376 + pr_warn("branch root dir was changed\n");
18381 + bbot = au_ibbot(inode);
18382 + btop = au_ibtop(inode);
18383 +#if 0 /* reserved for future use */
18384 + if (bindex == bbot) {
18385 + /* keep this ino in rename case */
18389 + for (bindex = btop; bindex <= bbot; bindex++)
18390 + if (au_h_iptr(inode, bindex) == h_inode) {
18397 + for (bindex = btop; bindex <= bbot; bindex++) {
18398 + h_i = au_h_iptr(inode, bindex);
18402 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18403 + /* ignore this error */
18404 + /* bad action? */
18407 + /* children inode number will be broken */
18414 +static int hn_gen_tree(struct dentry *dentry)
18416 + int err, i, j, ndentry;
18417 + struct au_dcsub_pages dpages;
18418 + struct au_dpage *dpage;
18419 + struct dentry **dentries;
18421 + err = au_dpages_init(&dpages, GFP_NOFS);
18422 + if (unlikely(err))
18424 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18425 + if (unlikely(err))
18428 + for (i = 0; i < dpages.ndpage; i++) {
18429 + dpage = dpages.dpages + i;
18430 + dentries = dpage->dentries;
18431 + ndentry = dpage->ndentry;
18432 + for (j = 0; j < ndentry; j++) {
18433 + struct dentry *d;
18440 + if (d_really_is_positive(d))
18441 + /* todo: reset children xino?
18442 + cached children only? */
18443 + au_iigen_dec(d_inode(d));
18448 + au_dpages_free(&dpages);
18454 + * return 0 if processed.
18456 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18457 + const unsigned int isdir)
18460 + struct dentry *d;
18461 + struct qstr *dname;
18464 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18465 + pr_warn("branch root dir was changed\n");
18471 + AuDebugOn(!name);
18472 + au_iigen_dec(inode);
18473 + spin_lock(&inode->i_lock);
18474 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18475 + spin_lock(&d->d_lock);
18476 + dname = &d->d_name;
18477 + if (dname->len != nlen
18478 + && memcmp(dname->name, name, nlen)) {
18479 + spin_unlock(&d->d_lock);
18484 + spin_unlock(&d->d_lock);
18487 + spin_unlock(&inode->i_lock);
18489 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18490 + d = d_find_any_alias(inode);
18492 + au_iigen_dec(inode);
18496 + spin_lock(&d->d_lock);
18497 + dname = &d->d_name;
18498 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18499 + spin_unlock(&d->d_lock);
18500 + err = hn_gen_tree(d);
18501 + spin_lock(&d->d_lock);
18503 + spin_unlock(&d->d_lock);
18512 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18516 + if (IS_ROOT(dentry)) {
18517 + pr_warn("branch root dir was changed\n");
18523 + au_digen_dec(dentry);
18524 + if (d_really_is_positive(dentry))
18525 + au_iigen_dec(d_inode(dentry));
18527 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18528 + if (d_really_is_positive(dentry))
18529 + err = hn_gen_tree(dentry);
18536 +/* ---------------------------------------------------------------------- */
18538 +/* hnotify job flags */
18539 +#define AuHnJob_XINO0 1
18540 +#define AuHnJob_GEN (1 << 1)
18541 +#define AuHnJob_DIRENT (1 << 2)
18542 +#define AuHnJob_ISDIR (1 << 3)
18543 +#define AuHnJob_TRYXINO0 (1 << 4)
18544 +#define AuHnJob_MNTPNT (1 << 5)
18545 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18546 +#define au_fset_hnjob(flags, name) \
18547 + do { (flags) |= AuHnJob_##name; } while (0)
18548 +#define au_fclr_hnjob(flags, name) \
18549 + do { (flags) &= ~AuHnJob_##name; } while (0)
18557 +struct au_hnotify_args {
18558 + struct inode *h_dir, *dir, *h_child_inode;
18560 + unsigned int flags[AuHnLast];
18561 + unsigned int h_child_nlen;
18562 + char h_child_name[];
18565 +struct hn_job_args {
18566 + unsigned int flags;
18567 + struct inode *inode, *h_inode, *dir, *h_dir;
18568 + struct dentry *dentry;
18573 +static int hn_job(struct hn_job_args *a)
18575 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18579 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18580 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18582 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18585 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18586 + if (!a->h_inode->i_nlink
18587 + && !(a->h_inode->i_state & I_LINKABLE))
18588 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18589 + inode_unlock_shared(a->h_inode);
18592 + /* make the generation obsolete */
18593 + if (au_ftest_hnjob(a->flags, GEN)) {
18596 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18598 + if (e && a->dentry)
18599 + hn_gen_by_name(a->dentry, isdir);
18600 + /* ignore this error */
18603 + /* make dir entries obsolete */
18604 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18605 + struct au_vdir *vdir;
18607 + vdir = au_ivdir(a->inode);
18609 + vdir->vd_jiffy = 0;
18610 + /* IMustLock(a->inode); */
18611 + /* inode_inc_iversion(a->inode); */
18614 + /* can do nothing but warn */
18615 + if (au_ftest_hnjob(a->flags, MNTPNT)
18617 + && d_mountpoint(a->dentry))
18618 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18623 +/* ---------------------------------------------------------------------- */
18625 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18626 + struct inode *dir)
18628 + struct dentry *dentry, *d, *parent;
18629 + struct qstr *dname;
18631 + parent = d_find_any_alias(dir);
18636 + spin_lock(&parent->d_lock);
18637 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18638 + /* AuDbg("%pd\n", d); */
18639 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18640 + dname = &d->d_name;
18641 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18642 + goto cont_unlock;
18646 + goto cont_unlock;
18647 + if (au_dcount(d) > 0) {
18648 + dentry = dget_dlock(d);
18649 + spin_unlock(&d->d_lock);
18654 + spin_unlock(&d->d_lock);
18656 + spin_unlock(&parent->d_lock);
18660 + di_write_lock_child(dentry);
18665 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18666 + aufs_bindex_t bindex, ino_t h_ino)
18668 + struct inode *inode;
18673 + err = au_xino_read(sb, bindex, h_ino, &ino);
18675 + inode = ilookup(sb, ino);
18679 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18680 + pr_warn("wrong root branch\n");
18686 + ii_write_lock_child(inode);
18692 +static void au_hn_bh(void *_args)
18694 + struct au_hnotify_args *a = _args;
18695 + struct super_block *sb;
18696 + aufs_bindex_t bindex, bbot, bfound;
18697 + unsigned char xino, try_iput;
18699 + struct inode *inode;
18701 + struct hn_job_args args;
18702 + struct dentry *dentry;
18703 + struct au_sbinfo *sbinfo;
18705 + AuDebugOn(!_args);
18706 + AuDebugOn(!a->h_dir);
18707 + AuDebugOn(!a->dir);
18708 + AuDebugOn(!a->mask);
18709 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18710 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18711 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18716 + * do not lock a->dir->i_mutex here
18717 + * because of d_revalidate() may cause a deadlock.
18719 + sb = a->dir->i_sb;
18721 + sbinfo = au_sbi(sb);
18722 + AuDebugOn(!sbinfo);
18723 + si_write_lock(sb, AuLock_NOPLMW);
18725 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18726 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18727 + case FS_MOVED_FROM:
18728 + case FS_MOVED_TO:
18729 + AuWarn1("DIRREN with UDBA may not work correctly "
18730 + "for the direct rename(2)\n");
18733 + ii_read_lock_parent(a->dir);
18735 + bbot = au_ibbot(a->dir);
18736 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18737 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18741 + ii_read_unlock(a->dir);
18742 + if (unlikely(bfound < 0))
18745 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18747 + if (a->h_child_inode)
18748 + h_ino = a->h_child_inode->i_ino;
18750 + if (a->h_child_nlen
18751 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18752 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18753 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18756 + if (dentry && d_really_is_positive(dentry))
18757 + inode = d_inode(dentry);
18758 + if (xino && !inode && h_ino
18759 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18760 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18761 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18762 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18766 + args.flags = a->flags[AuHn_CHILD];
18767 + args.dentry = dentry;
18768 + args.inode = inode;
18769 + args.h_inode = a->h_child_inode;
18770 + args.dir = a->dir;
18771 + args.h_dir = a->h_dir;
18772 + args.h_name = a->h_child_name;
18773 + args.h_nlen = a->h_child_nlen;
18774 + err = hn_job(&args);
18776 + if (au_di(dentry))
18777 + di_write_unlock(dentry);
18780 + if (inode && try_iput) {
18781 + ii_write_unlock(inode);
18785 + ii_write_lock_parent(a->dir);
18786 + args.flags = a->flags[AuHn_PARENT];
18787 + args.dentry = NULL;
18788 + args.inode = a->dir;
18789 + args.h_inode = a->h_dir;
18791 + args.h_dir = NULL;
18792 + args.h_name = NULL;
18794 + err = hn_job(&args);
18795 + ii_write_unlock(a->dir);
18798 + iput(a->h_child_inode);
18801 + si_write_unlock(sb);
18802 + au_nwt_done(&sbinfo->si_nowait);
18806 +/* ---------------------------------------------------------------------- */
18808 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18809 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18812 + unsigned int flags[AuHnLast], f;
18813 + unsigned char isdir, isroot, wh;
18814 + struct inode *dir;
18815 + struct au_hnotify_args *args;
18816 + char *p, *h_child_name;
18819 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18820 + dir = igrab(hnotify->hn_aufs_inode);
18824 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18826 + h_child_name = (void *)h_child_qstr->name;
18827 + len = h_child_qstr->len;
18828 + if (h_child_name) {
18829 + if (len > AUFS_WH_PFX_LEN
18830 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18831 + h_child_name += AUFS_WH_PFX_LEN;
18832 + len -= AUFS_WH_PFX_LEN;
18838 + if (h_child_inode)
18839 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18840 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18841 + flags[AuHn_CHILD] = 0;
18843 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18844 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18845 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18846 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18847 + case FS_MOVED_FROM:
18848 + case FS_MOVED_TO:
18849 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18850 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18853 + AuDebugOn(!h_child_name);
18858 + * aufs never be able to get this child inode.
18859 + * revalidation should be in d_revalidate()
18860 + * by checking i_nlink, i_generation or d_unhashed().
18862 + AuDebugOn(!h_child_name);
18863 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18864 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18872 + h_child_inode = NULL;
18875 + /* iput() and kfree() will be called in au_hnotify() */
18876 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18877 + if (unlikely(!args)) {
18878 + AuErr1("no memory\n");
18882 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18883 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18884 + args->mask = mask;
18886 + args->h_dir = igrab(h_dir);
18887 + if (h_child_inode)
18888 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18889 + args->h_child_inode = h_child_inode;
18890 + args->h_child_nlen = len;
18892 + p = (void *)args;
18893 + p += sizeof(*args);
18894 + memcpy(p, h_child_name, len);
18898 + /* NFS fires the event for silly-renamed one from kworker */
18900 + if (!dir->i_nlink
18901 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18903 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18904 + if (unlikely(err)) {
18905 + pr_err("wkq %d\n", err);
18906 + iput(args->h_child_inode);
18907 + iput(args->h_dir);
18909 + au_kfree_rcu(args);
18916 +/* ---------------------------------------------------------------------- */
18918 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18922 + AuDebugOn(!(udba & AuOptMask_UDBA));
18925 + if (au_hnotify_op.reset_br)
18926 + err = au_hnotify_op.reset_br(udba, br, perm);
18931 +int au_hnotify_init_br(struct au_branch *br, int perm)
18936 + if (au_hnotify_op.init_br)
18937 + err = au_hnotify_op.init_br(br, perm);
18942 +void au_hnotify_fin_br(struct au_branch *br)
18944 + if (au_hnotify_op.fin_br)
18945 + au_hnotify_op.fin_br(br);
18948 +static void au_hn_destroy_cache(void)
18950 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18951 + au_cache[AuCache_HNOTIFY] = NULL;
18954 +int __init au_hnotify_init(void)
18959 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18960 + if (au_cache[AuCache_HNOTIFY]) {
18962 + if (au_hnotify_op.init)
18963 + err = au_hnotify_op.init();
18964 + if (unlikely(err))
18965 + au_hn_destroy_cache();
18971 +void au_hnotify_fin(void)
18973 + if (au_hnotify_op.fin)
18974 + au_hnotify_op.fin();
18976 + /* cf. au_cache_fin() */
18977 + if (au_cache[AuCache_HNOTIFY])
18978 + au_hn_destroy_cache();
18980 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18981 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18982 +++ linux/fs/aufs/iinfo.c 2022-10-26 22:30:38.469315525 +0200
18984 +// SPDX-License-Identifier: GPL-2.0
18986 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18988 + * This program, aufs is free software; you can redistribute it and/or modify
18989 + * it under the terms of the GNU General Public License as published by
18990 + * the Free Software Foundation; either version 2 of the License, or
18991 + * (at your option) any later version.
18993 + * This program is distributed in the hope that it will be useful,
18994 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18995 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18996 + * GNU General Public License for more details.
18998 + * You should have received a copy of the GNU General Public License
18999 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19003 + * inode private data
19008 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19010 + struct inode *h_inode;
19011 + struct au_hinode *hinode;
19013 + IiMustAnyLock(inode);
19015 + hinode = au_hinode(au_ii(inode), bindex);
19016 + h_inode = hinode->hi_inode;
19017 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19021 +/* todo: hard/soft set? */
19022 +void au_hiput(struct au_hinode *hinode)
19024 + au_hn_free(hinode);
19025 + dput(hinode->hi_whdentry);
19026 + iput(hinode->hi_inode);
19029 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19031 + unsigned int flags;
19032 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19035 + if (au_opt_test(mnt_flags, XINO))
19036 + au_fset_hi(flags, XINO);
19037 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19038 + au_fset_hi(flags, HNOTIFY);
19042 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19043 + struct inode *h_inode, unsigned int flags)
19045 + struct au_hinode *hinode;
19046 + struct inode *hi;
19047 + struct au_iinfo *iinfo = au_ii(inode);
19049 + IiMustWriteLock(inode);
19051 + hinode = au_hinode(iinfo, bindex);
19052 + hi = hinode->hi_inode;
19053 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19056 + au_hiput(hinode);
19057 + hinode->hi_inode = h_inode;
19060 + struct super_block *sb = inode->i_sb;
19061 + struct au_branch *br;
19063 + AuDebugOn(inode->i_mode
19064 + && (h_inode->i_mode & S_IFMT)
19065 + != (inode->i_mode & S_IFMT));
19066 + if (bindex == iinfo->ii_btop)
19067 + au_cpup_igen(inode, h_inode);
19068 + br = au_sbr(sb, bindex);
19069 + hinode->hi_id = br->br_id;
19070 + if (au_ftest_hi(flags, XINO)) {
19071 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19073 + if (unlikely(err))
19074 + AuIOErr1("failed au_xino_write() %d\n", err);
19077 + if (au_ftest_hi(flags, HNOTIFY)
19078 + && au_br_hnotifyable(br->br_perm)) {
19079 + err = au_hn_alloc(hinode, inode);
19080 + if (unlikely(err))
19081 + AuIOErr1("au_hn_alloc() %d\n", err);
19086 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19087 + struct dentry *h_wh)
19089 + struct au_hinode *hinode;
19091 + IiMustWriteLock(inode);
19093 + hinode = au_hinode(au_ii(inode), bindex);
19094 + AuDebugOn(hinode->hi_whdentry);
19095 + hinode->hi_whdentry = h_wh;
19098 +void au_update_iigen(struct inode *inode, int half)
19100 + struct au_iinfo *iinfo;
19101 + struct au_iigen *iigen;
19102 + unsigned int sigen;
19104 + sigen = au_sigen(inode->i_sb);
19105 + iinfo = au_ii(inode);
19106 + iigen = &iinfo->ii_generation;
19107 + spin_lock(&iigen->ig_spin);
19108 + iigen->ig_generation = sigen;
19110 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19112 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19113 + spin_unlock(&iigen->ig_spin);
19116 +/* it may be called at remount time, too */
19117 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19119 + struct au_iinfo *iinfo;
19120 + aufs_bindex_t bindex, bbot;
19122 + AuDebugOn(au_is_bad_inode(inode));
19123 + IiMustWriteLock(inode);
19125 + iinfo = au_ii(inode);
19126 + if (do_put_zero && iinfo->ii_btop >= 0) {
19127 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19129 + struct inode *h_i;
19131 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19134 + && !(h_i->i_state & I_LINKABLE))
19135 + au_set_h_iptr(inode, bindex, NULL, 0);
19139 + iinfo->ii_btop = -1;
19140 + iinfo->ii_bbot = -1;
19141 + bbot = au_sbbot(inode->i_sb);
19142 + for (bindex = 0; bindex <= bbot; bindex++)
19143 + if (au_hinode(iinfo, bindex)->hi_inode) {
19144 + iinfo->ii_btop = bindex;
19147 + if (iinfo->ii_btop >= 0)
19148 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19149 + if (au_hinode(iinfo, bindex)->hi_inode) {
19150 + iinfo->ii_bbot = bindex;
19153 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19156 +/* ---------------------------------------------------------------------- */
19158 +void au_icntnr_init_once(void *_c)
19160 + struct au_icntnr *c = _c;
19161 + struct au_iinfo *iinfo = &c->iinfo;
19163 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19164 + au_rw_init(&iinfo->ii_rwsem);
19165 + inode_init_once(&c->vfs_inode);
19168 +void au_hinode_init(struct au_hinode *hinode)
19170 + hinode->hi_inode = NULL;
19171 + hinode->hi_id = -1;
19172 + au_hn_init(hinode);
19173 + hinode->hi_whdentry = NULL;
19176 +int au_iinfo_init(struct inode *inode)
19178 + struct au_iinfo *iinfo;
19179 + struct super_block *sb;
19180 + struct au_hinode *hi;
19183 + sb = inode->i_sb;
19184 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19185 + nbr = au_sbbot(sb) + 1;
19186 + if (unlikely(nbr <= 0))
19188 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19190 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19192 + iinfo->ii_hinode = hi;
19193 + for (i = 0; i < nbr; i++, hi++)
19194 + au_hinode_init(hi);
19196 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19197 + iinfo->ii_btop = -1;
19198 + iinfo->ii_bbot = -1;
19199 + iinfo->ii_vdir = NULL;
19205 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19208 + struct au_hinode *hip;
19210 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19213 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19216 + iinfo->ii_hinode = hip;
19217 + i = iinfo->ii_bbot + 1;
19219 + for (; i < nbr; i++, hip++)
19220 + au_hinode_init(hip);
19227 +void au_iinfo_fin(struct inode *inode)
19229 + struct au_iinfo *iinfo;
19230 + struct au_hinode *hi;
19231 + struct super_block *sb;
19232 + aufs_bindex_t bindex, bbot;
19233 + const unsigned char unlinked = !inode->i_nlink;
19235 + AuDebugOn(au_is_bad_inode(inode));
19237 + sb = inode->i_sb;
19238 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19239 + if (si_pid_test(sb))
19240 + au_xino_delete_inode(inode, unlinked);
19243 + * it is safe to hide the dependency between sbinfo and
19247 + si_noflush_read_lock(sb);
19248 + au_xino_delete_inode(inode, unlinked);
19249 + si_read_unlock(sb);
19253 + iinfo = au_ii(inode);
19254 + if (iinfo->ii_vdir)
19255 + au_vdir_free(iinfo->ii_vdir);
19257 + bindex = iinfo->ii_btop;
19258 + if (bindex >= 0) {
19259 + hi = au_hinode(iinfo, bindex);
19260 + bbot = iinfo->ii_bbot;
19261 + while (bindex++ <= bbot) {
19262 + if (hi->hi_inode)
19267 + au_kfree_rcu(iinfo->ii_hinode);
19268 + AuRwDestroy(&iinfo->ii_rwsem);
19270 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19271 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19272 +++ linux/fs/aufs/inode.c 2022-10-26 22:30:38.469315525 +0200
19274 +// SPDX-License-Identifier: GPL-2.0
19276 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19278 + * This program, aufs is free software; you can redistribute it and/or modify
19279 + * it under the terms of the GNU General Public License as published by
19280 + * the Free Software Foundation; either version 2 of the License, or
19281 + * (at your option) any later version.
19283 + * This program is distributed in the hope that it will be useful,
19284 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19285 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19286 + * GNU General Public License for more details.
19288 + * You should have received a copy of the GNU General Public License
19289 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19293 + * inode functions
19296 +#include <linux/iversion.h>
19299 +struct inode *au_igrab(struct inode *inode)
19302 + AuDebugOn(!atomic_read(&inode->i_count));
19308 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19310 + au_cpup_attr_all(inode, /*force*/0);
19311 + au_update_iigen(inode, /*half*/1);
19313 + inode_inc_iversion(inode);
19316 +static int au_ii_refresh(struct inode *inode, int *update)
19320 + aufs_bindex_t bindex, new_bindex;
19321 + struct super_block *sb;
19322 + struct au_iinfo *iinfo;
19323 + struct au_hinode *p, *q, tmp;
19325 + AuDebugOn(au_is_bad_inode(inode));
19326 + IiMustWriteLock(inode);
19329 + sb = inode->i_sb;
19330 + nbr = au_sbbot(sb) + 1;
19331 + type = inode->i_mode & S_IFMT;
19332 + iinfo = au_ii(inode);
19333 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19334 + if (unlikely(err))
19337 + AuDebugOn(iinfo->ii_btop < 0);
19338 + p = au_hinode(iinfo, iinfo->ii_btop);
19339 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19341 + if (!p->hi_inode)
19344 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19345 + new_bindex = au_br_index(sb, p->hi_id);
19346 + if (new_bindex == bindex)
19349 + if (new_bindex < 0) {
19352 + p->hi_inode = NULL;
19356 + if (new_bindex < iinfo->ii_btop)
19357 + iinfo->ii_btop = new_bindex;
19358 + if (iinfo->ii_bbot < new_bindex)
19359 + iinfo->ii_bbot = new_bindex;
19360 + /* swap two lower inode, and loop again */
19361 + q = au_hinode(iinfo, new_bindex);
19365 + if (tmp.hi_inode) {
19370 + au_update_ibrange(inode, /*do_put_zero*/0);
19371 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19372 + e = au_dy_irefresh(inode);
19373 + if (unlikely(e && !err))
19381 +void au_refresh_iop(struct inode *inode, int force_getattr)
19384 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19385 + const struct inode_operations *iop
19386 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19388 + if (inode->i_op == iop)
19391 + switch (inode->i_mode & S_IFMT) {
19393 + type = AuIop_DIR;
19396 + type = AuIop_SYMLINK;
19399 + type = AuIop_OTHER;
19403 + inode->i_op = iop + type;
19404 + /* unnecessary smp_wmb() */
19407 +int au_refresh_hinode_self(struct inode *inode)
19411 + err = au_ii_refresh(inode, &update);
19413 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19419 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19421 + int err, e, update;
19422 + unsigned int flags;
19424 + aufs_bindex_t bindex, bbot;
19425 + unsigned char isdir;
19426 + struct au_hinode *p;
19427 + struct au_iinfo *iinfo;
19429 + err = au_ii_refresh(inode, &update);
19430 + if (unlikely(err))
19434 + iinfo = au_ii(inode);
19435 + p = au_hinode(iinfo, iinfo->ii_btop);
19436 + mode = (inode->i_mode & S_IFMT);
19437 + isdir = S_ISDIR(mode);
19438 + flags = au_hi_flags(inode, isdir);
19439 + bbot = au_dbbot(dentry);
19440 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19441 + struct inode *h_i, *h_inode;
19442 + struct dentry *h_d;
19444 + h_d = au_h_dptr(dentry, bindex);
19445 + if (!h_d || d_is_negative(h_d))
19448 + h_inode = d_inode(h_d);
19449 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19450 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19451 + h_i = au_h_iptr(inode, bindex);
19453 + if (h_i == h_inode)
19459 + if (bindex < iinfo->ii_btop)
19460 + iinfo->ii_btop = bindex;
19461 + if (iinfo->ii_bbot < bindex)
19462 + iinfo->ii_bbot = bindex;
19463 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19466 + au_update_ibrange(inode, /*do_put_zero*/0);
19467 + e = au_dy_irefresh(inode);
19468 + if (unlikely(e && !err))
19471 + au_refresh_hinode_attr(inode, update && isdir);
19478 +static int set_inode(struct inode *inode, struct dentry *dentry)
19481 + unsigned int flags;
19483 + aufs_bindex_t bindex, btop, btail;
19484 + unsigned char isdir;
19485 + struct dentry *h_dentry;
19486 + struct inode *h_inode;
19487 + struct au_iinfo *iinfo;
19488 + const struct inode_operations *iop;
19490 + IiMustWriteLock(inode);
19494 + iop = au_sbi(inode->i_sb)->si_iop_array;
19495 + btop = au_dbtop(dentry);
19496 + h_dentry = au_h_dptr(dentry, btop);
19497 + h_inode = d_inode(h_dentry);
19498 + mode = h_inode->i_mode;
19499 + switch (mode & S_IFMT) {
19501 + btail = au_dbtail(dentry);
19502 + inode->i_op = iop + AuIop_OTHER;
19503 + inode->i_fop = &aufs_file_fop;
19504 + err = au_dy_iaop(inode, btop, h_inode);
19505 + if (unlikely(err))
19510 + btail = au_dbtaildir(dentry);
19511 + inode->i_op = iop + AuIop_DIR;
19512 + inode->i_fop = &aufs_dir_fop;
19515 + btail = au_dbtail(dentry);
19516 + inode->i_op = iop + AuIop_SYMLINK;
19522 + btail = au_dbtail(dentry);
19523 + inode->i_op = iop + AuIop_OTHER;
19524 + init_special_inode(inode, mode, h_inode->i_rdev);
19527 + AuIOErr("Unknown file type 0%o\n", mode);
19532 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19533 + flags = au_hi_flags(inode, isdir);
19534 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19535 + && au_ftest_hi(flags, HNOTIFY)
19536 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19537 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19538 + au_fclr_hi(flags, HNOTIFY);
19539 + iinfo = au_ii(inode);
19540 + iinfo->ii_btop = btop;
19541 + iinfo->ii_bbot = btail;
19542 + for (bindex = btop; bindex <= btail; bindex++) {
19543 + h_dentry = au_h_dptr(dentry, bindex);
19545 + au_set_h_iptr(inode, bindex,
19546 + au_igrab(d_inode(h_dentry)), flags);
19548 + au_cpup_attr_all(inode, /*force*/1);
19550 + * to force calling aufs_get_acl() every time,
19551 + * do not call cache_no_acl() for aufs inode.
19559 + * successful returns with iinfo write_locked
19561 + * zero: success, matched
19562 + * plus: no error, but unmatched
19564 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19567 + unsigned int gen, igflags;
19568 + aufs_bindex_t bindex, bbot;
19569 + struct inode *h_inode, *h_dinode;
19570 + struct dentry *h_dentry;
19573 + * before this function, if aufs got any iinfo lock, it must be only
19574 + * one, the parent dir.
19575 + * it can happen by UDBA and the obsoleted inode number.
19578 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19582 + ii_write_lock_new_child(inode);
19583 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19584 + h_dinode = d_inode(h_dentry);
19585 + bbot = au_ibbot(inode);
19586 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19587 + h_inode = au_h_iptr(inode, bindex);
19588 + if (!h_inode || h_inode != h_dinode)
19592 + gen = au_iigen(inode, &igflags);
19593 + if (gen == au_digen(dentry)
19594 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19597 + /* fully refresh inode using dentry */
19598 + err = au_refresh_hinode(inode, dentry);
19600 + au_update_iigen(inode, /*half*/0);
19604 + if (unlikely(err))
19605 + ii_write_unlock(inode);
19610 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19611 + unsigned int d_type, ino_t *ino)
19614 + const int isnondir = d_type != DT_DIR;
19616 + /* prevent hardlinked inode number from race condition */
19618 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19619 + if (unlikely(err))
19623 + err = au_xino_read(sb, bindex, h_ino, ino);
19624 + if (unlikely(err))
19625 + goto out_xinondir;
19629 + *ino = au_xino_new_ino(sb);
19630 + if (unlikely(!*ino))
19631 + goto out_xinondir;
19632 + err = au_xino_write(sb, bindex, h_ino, *ino);
19633 + if (unlikely(err))
19634 + goto out_xinondir;
19638 + if (isnondir && idx >= 0)
19639 + au_xinondir_leave(sb, bindex, h_ino, idx);
19644 +/* successful returns with iinfo write_locked */
19645 +/* todo: return with unlocked? */
19646 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19648 + struct inode *inode, *h_inode;
19649 + struct dentry *h_dentry;
19650 + struct super_block *sb;
19651 + ino_t h_ino, ino;
19652 + int err, idx, hlinked;
19653 + aufs_bindex_t btop;
19655 + sb = dentry->d_sb;
19656 + btop = au_dbtop(dentry);
19657 + h_dentry = au_h_dptr(dentry, btop);
19658 + h_inode = d_inode(h_dentry);
19659 + h_ino = h_inode->i_ino;
19660 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19664 + * stop 'race'-ing between hardlinks under different
19668 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19669 + inode = ERR_PTR(err);
19670 + if (unlikely(err))
19674 + err = au_xino_read(sb, btop, h_ino, &ino);
19675 + inode = ERR_PTR(err);
19676 + if (unlikely(err))
19677 + goto out_xinondir;
19680 + ino = au_xino_new_ino(sb);
19681 + if (unlikely(!ino)) {
19682 + inode = ERR_PTR(-EIO);
19683 + goto out_xinondir;
19687 + AuDbg("i%lu\n", (unsigned long)ino);
19688 + inode = au_iget_locked(sb, ino);
19689 + err = PTR_ERR(inode);
19690 + if (IS_ERR(inode))
19691 + goto out_xinondir;
19693 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19694 + if (inode->i_state & I_NEW) {
19695 + ii_write_lock_new_child(inode);
19696 + err = set_inode(inode, dentry);
19698 + unlock_new_inode(inode);
19699 + goto out_xinondir; /* success */
19703 + * iget_failed() calls iput(), but we need to call
19704 + * ii_write_unlock() after iget_failed(). so dirty hack for
19707 + atomic_inc(&inode->i_count);
19708 + iget_failed(inode);
19709 + ii_write_unlock(inode);
19710 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19711 + /* ignore this error */
19713 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19715 + * horrible race condition between lookup, readdir and copyup
19716 + * (or something).
19718 + if (hlinked && idx >= 0)
19719 + au_xinondir_leave(sb, btop, h_ino, idx);
19720 + err = reval_inode(inode, dentry);
19721 + if (unlikely(err < 0)) {
19726 + goto out; /* success */
19727 + else if (hlinked && idx >= 0) {
19728 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19729 + if (unlikely(err)) {
19731 + inode = ERR_PTR(err);
19737 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19738 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19739 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19740 + btop, au_sbtype(h_dentry->d_sb), dentry,
19741 + (unsigned long)h_ino, (unsigned long)ino);
19743 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19746 + if (hlinked && idx >= 0)
19747 + au_xinondir_leave(sb, btop, h_ino, idx);
19753 + inode = ERR_PTR(err);
19755 + if (hlinked && idx >= 0)
19756 + au_xinondir_leave(sb, btop, h_ino, idx);
19761 +/* ---------------------------------------------------------------------- */
19763 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19764 + struct inode *inode)
19767 + struct inode *hi;
19769 + err = au_br_rdonly(au_sbr(sb, bindex));
19771 + /* pseudo-link after flushed may happen out of bounds */
19774 + && au_ibtop(inode) <= bindex
19775 + && bindex <= au_ibbot(inode)) {
19777 + * permission check is unnecessary since vfsub routine
19778 + * will be called later
19780 + hi = au_h_iptr(inode, bindex);
19782 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19788 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19791 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19793 + return inode_permission(h_userns, h_inode, mask);
19796 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19799 + if (au_test_nfs(h_inode->i_sb)
19800 + && (mask & MAY_WRITE)
19801 + && S_ISDIR(h_inode->i_mode))
19802 + mask |= MAY_READ; /* force permission check */
19803 + return au_test_h_perm(h_userns, h_inode, mask);
19805 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19806 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19807 +++ linux/fs/aufs/inode.h 2022-10-26 22:30:38.469315525 +0200
19809 +/* SPDX-License-Identifier: GPL-2.0 */
19811 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19813 + * This program, aufs is free software; you can redistribute it and/or modify
19814 + * it under the terms of the GNU General Public License as published by
19815 + * the Free Software Foundation; either version 2 of the License, or
19816 + * (at your option) any later version.
19818 + * This program is distributed in the hope that it will be useful,
19819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19821 + * GNU General Public License for more details.
19823 + * You should have received a copy of the GNU General Public License
19824 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19828 + * inode operations
19831 +#ifndef __AUFS_INODE_H__
19832 +#define __AUFS_INODE_H__
19836 +#include <linux/fsnotify.h>
19837 +#include "rwsem.h"
19841 +struct au_hnotify {
19842 +#ifdef CONFIG_AUFS_HNOTIFY
19843 +#ifdef CONFIG_AUFS_HFSNOTIFY
19844 + /* never use fsnotify_add_vfsmount_mark() */
19845 + struct fsnotify_mark hn_mark;
19847 + struct inode *hn_aufs_inode; /* no get/put */
19848 + struct rcu_head rcu;
19850 +} ____cacheline_aligned_in_smp;
19852 +struct au_hinode {
19853 + struct inode *hi_inode;
19854 + aufs_bindex_t hi_id;
19855 +#ifdef CONFIG_AUFS_HNOTIFY
19856 + struct au_hnotify *hi_notify;
19859 + /* reference to the copied-up whiteout with get/put */
19860 + struct dentry *hi_whdentry;
19864 +#define AuIG_HALF_REFRESHED 1
19865 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19866 +#define au_ig_fset(flags, name) \
19867 + do { (flags) |= AuIG_##name; } while (0)
19868 +#define au_ig_fclr(flags, name) \
19869 + do { (flags) &= ~AuIG_##name; } while (0)
19872 + spinlock_t ig_spin;
19873 + __u32 ig_generation, ig_flags;
19878 + struct au_iigen ii_generation;
19879 + struct super_block *ii_hsb1; /* no get/put */
19881 + struct au_rwsem ii_rwsem;
19882 + aufs_bindex_t ii_btop, ii_bbot;
19884 + struct au_hinode *ii_hinode;
19885 + struct au_vdir *ii_vdir;
19888 +struct au_icntnr {
19889 + struct au_iinfo iinfo;
19890 + struct inode vfs_inode;
19891 + struct hlist_bl_node plink;
19892 + struct rcu_head rcu;
19893 +} ____cacheline_aligned_in_smp;
19895 +/* au_pin flags */
19896 +#define AuPin_DI_LOCKED 1
19897 +#define AuPin_MNT_WRITE (1 << 1)
19898 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19899 +#define au_fset_pin(flags, name) \
19900 + do { (flags) |= AuPin_##name; } while (0)
19901 +#define au_fclr_pin(flags, name) \
19902 + do { (flags) &= ~AuPin_##name; } while (0)
19906 + struct dentry *dentry;
19907 + unsigned int udba;
19908 + unsigned char lsc_di, lsc_hi, flags;
19909 + aufs_bindex_t bindex;
19912 + struct dentry *parent;
19913 + struct au_hinode *hdir;
19914 + struct vfsmount *h_mnt;
19916 + /* temporary unlock/relock for copyup */
19917 + struct dentry *h_dentry, *h_parent;
19918 + struct au_branch *br;
19919 + struct task_struct *task;
19922 +void au_pin_hdir_unlock(struct au_pin *p);
19923 +int au_pin_hdir_lock(struct au_pin *p);
19924 +int au_pin_hdir_relock(struct au_pin *p);
19925 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19926 +void au_pin_hdir_release(struct au_pin *p);
19928 +/* ---------------------------------------------------------------------- */
19930 +static inline struct au_iinfo *au_ii(struct inode *inode)
19932 + BUG_ON(is_bad_inode(inode));
19933 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19936 +/* ---------------------------------------------------------------------- */
19939 +struct inode *au_igrab(struct inode *inode);
19940 +void au_refresh_iop(struct inode *inode, int force_getattr);
19941 +int au_refresh_hinode_self(struct inode *inode);
19942 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19943 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19944 + unsigned int d_type, ino_t *ino);
19945 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19946 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19947 + struct inode *inode);
19948 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
19950 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
19953 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19954 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19956 +#ifdef CONFIG_AUFS_SHWH
19957 + return au_ino(sb, bindex, h_ino, d_type, ino);
19970 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19971 + aufs_iop_nogetattr[AuIop_Last];
19973 +/* au_wr_dir flags */
19974 +#define AuWrDir_ADD_ENTRY 1
19975 +#define AuWrDir_ISDIR (1 << 1)
19976 +#define AuWrDir_TMPFILE (1 << 2)
19977 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19978 +#define au_fset_wrdir(flags, name) \
19979 + do { (flags) |= AuWrDir_##name; } while (0)
19980 +#define au_fclr_wrdir(flags, name) \
19981 + do { (flags) &= ~AuWrDir_##name; } while (0)
19983 +struct au_wr_dir_args {
19984 + aufs_bindex_t force_btgt;
19985 + unsigned char flags;
19987 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19988 + struct au_wr_dir_args *args);
19990 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19991 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19992 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19993 + unsigned int udba, unsigned char flags);
19994 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19995 + unsigned int udba, unsigned char flags) __must_check;
19996 +int au_do_pin(struct au_pin *pin) __must_check;
19997 +void au_unpin(struct au_pin *pin);
19998 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
20000 +#define AuIcpup_DID_CPUP 1
20001 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20002 +#define au_fset_icpup(flags, name) \
20003 + do { (flags) |= AuIcpup_##name; } while (0)
20004 +#define au_fclr_icpup(flags, name) \
20005 + do { (flags) &= ~AuIcpup_##name; } while (0)
20007 +struct au_icpup_args {
20008 + unsigned char flags;
20009 + unsigned char pin_flags;
20010 + aufs_bindex_t btgt;
20011 + unsigned int udba;
20012 + struct au_pin pin;
20013 + struct path h_path;
20014 + struct inode *h_inode;
20017 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20018 + struct au_icpup_args *a);
20020 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20021 + struct path *h_path, int locked);
20024 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20025 + struct dentry *h_parent, int isdir);
20026 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
20027 + struct dentry *dentry, umode_t mode, dev_t dev);
20028 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
20029 + struct dentry *dentry, const char *symname);
20030 +int aufs_create(struct user_namespace *userns, struct inode *dir,
20031 + struct dentry *dentry, umode_t mode, bool want_excl);
20032 +struct vfsub_aopen_args;
20033 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20034 + struct vfsub_aopen_args *args);
20035 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
20036 + struct dentry *dentry, umode_t mode);
20037 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20038 + struct dentry *dentry);
20039 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20040 + struct dentry *dentry, umode_t mode);
20043 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20044 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20045 + struct dentry *h_parent, int isdir);
20046 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20047 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20050 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20051 +int aufs_rename(struct user_namespace *userns,
20052 + struct inode *_src_dir, struct dentry *_src_dentry,
20053 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20054 + unsigned int _flags);
20057 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20058 +void au_hiput(struct au_hinode *hinode);
20059 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20060 + struct dentry *h_wh);
20061 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20063 +/* hinode flags */
20064 +#define AuHi_XINO 1
20065 +#define AuHi_HNOTIFY (1 << 1)
20066 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20067 +#define au_fset_hi(flags, name) \
20068 + do { (flags) |= AuHi_##name; } while (0)
20069 +#define au_fclr_hi(flags, name) \
20070 + do { (flags) &= ~AuHi_##name; } while (0)
20072 +#ifndef CONFIG_AUFS_HNOTIFY
20073 +#undef AuHi_HNOTIFY
20074 +#define AuHi_HNOTIFY 0
20077 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20078 + struct inode *h_inode, unsigned int flags);
20080 +void au_update_iigen(struct inode *inode, int half);
20081 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20083 +void au_icntnr_init_once(void *_c);
20084 +void au_hinode_init(struct au_hinode *hinode);
20085 +int au_iinfo_init(struct inode *inode);
20086 +void au_iinfo_fin(struct inode *inode);
20087 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20089 +#ifdef CONFIG_PROC_FS
20091 +int au_plink_maint(struct super_block *sb, int flags);
20093 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20094 +int au_plink_maint_enter(struct super_block *sb);
20095 +#ifdef CONFIG_AUFS_DEBUG
20096 +void au_plink_list(struct super_block *sb);
20098 +AuStubVoid(au_plink_list, struct super_block *sb)
20100 +int au_plink_test(struct inode *inode);
20101 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20102 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20103 + struct dentry *h_dentry);
20104 +void au_plink_put(struct super_block *sb, int verbose);
20105 +void au_plink_clean(struct super_block *sb, int verbose);
20106 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20108 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20109 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20110 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20111 +AuStubVoid(au_plink_list, struct super_block *sb);
20112 +AuStubInt0(au_plink_test, struct inode *inode);
20113 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20114 + struct inode *inode, aufs_bindex_t bindex);
20115 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20116 + struct dentry *h_dentry);
20117 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20118 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20119 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20120 +#endif /* CONFIG_PROC_FS */
20122 +#ifdef CONFIG_AUFS_XATTR
20124 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20125 + unsigned int verbose);
20126 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20127 +void au_xattr_init(struct super_block *sb);
20129 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20130 + int ignore_flags, unsigned int verbose);
20131 +AuStubVoid(au_xattr_init, struct super_block *sb);
20134 +#ifdef CONFIG_FS_POSIX_ACL
20135 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
20136 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
20137 + struct posix_acl *acl, int type);
20140 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20146 +struct au_sxattr {
20150 + const char *name;
20151 + const void *value;
20156 + struct posix_acl *acl;
20161 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20162 + struct au_sxattr *arg);
20165 +/* ---------------------------------------------------------------------- */
20167 +/* lock subclass for iinfo */
20169 + AuLsc_II_CHILD, /* child first */
20170 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20171 + AuLsc_II_CHILD3, /* copyup dirs */
20172 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20173 + AuLsc_II_PARENT2,
20174 + AuLsc_II_PARENT3, /* copyup dirs */
20175 + AuLsc_II_NEW_CHILD
20179 + * ii_read_lock_child, ii_write_lock_child,
20180 + * ii_read_lock_child2, ii_write_lock_child2,
20181 + * ii_read_lock_child3, ii_write_lock_child3,
20182 + * ii_read_lock_parent, ii_write_lock_parent,
20183 + * ii_read_lock_parent2, ii_write_lock_parent2,
20184 + * ii_read_lock_parent3, ii_write_lock_parent3,
20185 + * ii_read_lock_new_child, ii_write_lock_new_child,
20187 +#define AuReadLockFunc(name, lsc) \
20188 +static inline void ii_read_lock_##name(struct inode *i) \
20190 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20193 +#define AuWriteLockFunc(name, lsc) \
20194 +static inline void ii_write_lock_##name(struct inode *i) \
20196 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20199 +#define AuRWLockFuncs(name, lsc) \
20200 + AuReadLockFunc(name, lsc) \
20201 + AuWriteLockFunc(name, lsc)
20203 +AuRWLockFuncs(child, CHILD);
20204 +AuRWLockFuncs(child2, CHILD2);
20205 +AuRWLockFuncs(child3, CHILD3);
20206 +AuRWLockFuncs(parent, PARENT);
20207 +AuRWLockFuncs(parent2, PARENT2);
20208 +AuRWLockFuncs(parent3, PARENT3);
20209 +AuRWLockFuncs(new_child, NEW_CHILD);
20211 +#undef AuReadLockFunc
20212 +#undef AuWriteLockFunc
20213 +#undef AuRWLockFuncs
20215 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20216 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20217 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20219 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20220 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20221 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20223 +/* ---------------------------------------------------------------------- */
20225 +static inline void au_icntnr_init(struct au_icntnr *c)
20227 +#ifdef CONFIG_AUFS_DEBUG
20228 + c->vfs_inode.i_mode = 0;
20232 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20234 + unsigned int gen;
20235 + struct au_iinfo *iinfo;
20236 + struct au_iigen *iigen;
20238 + iinfo = au_ii(inode);
20239 + iigen = &iinfo->ii_generation;
20240 + spin_lock(&iigen->ig_spin);
20242 + *igflags = iigen->ig_flags;
20243 + gen = iigen->ig_generation;
20244 + spin_unlock(&iigen->ig_spin);
20249 +/* tiny test for inode number */
20250 +/* tmpfs generation is too rough */
20251 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20253 + struct au_iinfo *iinfo;
20255 + iinfo = au_ii(inode);
20256 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20257 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20258 + && iinfo->ii_higen == h_inode->i_generation);
20261 +static inline void au_iigen_dec(struct inode *inode)
20263 + struct au_iinfo *iinfo;
20264 + struct au_iigen *iigen;
20266 + iinfo = au_ii(inode);
20267 + iigen = &iinfo->ii_generation;
20268 + spin_lock(&iigen->ig_spin);
20269 + iigen->ig_generation--;
20270 + spin_unlock(&iigen->ig_spin);
20273 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20278 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20284 +/* ---------------------------------------------------------------------- */
20286 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20287 + aufs_bindex_t bindex)
20289 + return iinfo->ii_hinode + bindex;
20292 +static inline int au_is_bad_inode(struct inode *inode)
20294 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20297 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20298 + aufs_bindex_t bindex)
20300 + IiMustAnyLock(inode);
20301 + return au_hinode(au_ii(inode), bindex)->hi_id;
20304 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20306 + IiMustAnyLock(inode);
20307 + return au_ii(inode)->ii_btop;
20310 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20312 + IiMustAnyLock(inode);
20313 + return au_ii(inode)->ii_bbot;
20316 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20318 + IiMustAnyLock(inode);
20319 + return au_ii(inode)->ii_vdir;
20322 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20324 + IiMustAnyLock(inode);
20325 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20328 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20330 + IiMustWriteLock(inode);
20331 + au_ii(inode)->ii_btop = bindex;
20334 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20336 + IiMustWriteLock(inode);
20337 + au_ii(inode)->ii_bbot = bindex;
20340 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20342 + IiMustWriteLock(inode);
20343 + au_ii(inode)->ii_vdir = vdir;
20346 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20348 + IiMustAnyLock(inode);
20349 + return au_hinode(au_ii(inode), bindex);
20352 +/* ---------------------------------------------------------------------- */
20354 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20357 + return pin->parent;
20361 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20363 + if (pin && pin->hdir)
20364 + return pin->hdir->hi_inode;
20368 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20371 + return pin->hdir;
20375 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20378 + pin->dentry = dentry;
20381 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20382 + unsigned char lflag)
20386 + au_fset_pin(pin->flags, DI_LOCKED);
20388 + au_fclr_pin(pin->flags, DI_LOCKED);
20392 +#if 0 /* reserved */
20393 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20396 + dput(pin->parent);
20397 + pin->parent = dget(parent);
20402 +/* ---------------------------------------------------------------------- */
20405 +#ifdef CONFIG_AUFS_HNOTIFY
20406 +struct au_hnotify_op {
20407 + void (*ctl)(struct au_hinode *hinode, int do_set);
20408 + int (*alloc)(struct au_hinode *hinode);
20411 + * if it returns true, the caller should free hinode->hi_notify,
20412 + * otherwise ->free() frees it.
20414 + int (*free)(struct au_hinode *hinode,
20415 + struct au_hnotify *hn) __must_check;
20417 + void (*fin)(void);
20418 + int (*init)(void);
20420 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20421 + void (*fin_br)(struct au_branch *br);
20422 + int (*init_br)(struct au_branch *br, int perm);
20426 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20427 +void au_hn_free(struct au_hinode *hinode);
20428 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20429 +void au_hn_reset(struct inode *inode, unsigned int flags);
20430 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20431 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20432 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20433 +int au_hnotify_init_br(struct au_branch *br, int perm);
20434 +void au_hnotify_fin_br(struct au_branch *br);
20435 +int __init au_hnotify_init(void);
20436 +void au_hnotify_fin(void);
20439 +extern const struct au_hnotify_op au_hnotify_op;
20442 +void au_hn_init(struct au_hinode *hinode)
20444 + hinode->hi_notify = NULL;
20447 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20449 + return hinode->hi_notify;
20453 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20454 + struct au_hinode *hinode __maybe_unused,
20455 + struct inode *inode __maybe_unused)
20456 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20457 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20458 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20459 + int do_set __maybe_unused)
20460 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20461 + unsigned int flags __maybe_unused)
20462 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20463 + struct au_branch *br __maybe_unused,
20464 + int perm __maybe_unused)
20465 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20466 + int perm __maybe_unused)
20467 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20468 +AuStubInt0(__init au_hnotify_init, void)
20469 +AuStubVoid(au_hnotify_fin, void)
20470 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20471 +#endif /* CONFIG_AUFS_HNOTIFY */
20473 +static inline void au_hn_suspend(struct au_hinode *hdir)
20475 + au_hn_ctl(hdir, /*do_set*/0);
20478 +static inline void au_hn_resume(struct au_hinode *hdir)
20480 + au_hn_ctl(hdir, /*do_set*/1);
20483 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20485 + inode_lock(hdir->hi_inode);
20486 + au_hn_suspend(hdir);
20489 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20490 + unsigned int sc __maybe_unused)
20492 + inode_lock_nested(hdir->hi_inode, sc);
20493 + au_hn_suspend(hdir);
20496 +#if 0 /* unused */
20497 +#include "vfsub.h"
20498 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20501 + inode_lock_shared_nested(hdir->hi_inode, sc);
20502 + au_hn_suspend(hdir);
20506 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20508 + au_hn_resume(hdir);
20509 + inode_unlock(hdir->hi_inode);
20512 +#endif /* __KERNEL__ */
20513 +#endif /* __AUFS_INODE_H__ */
20514 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20515 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20516 +++ linux/fs/aufs/ioctl.c 2022-10-26 22:30:38.469315525 +0200
20518 +// SPDX-License-Identifier: GPL-2.0
20520 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20522 + * This program, aufs is free software; you can redistribute it and/or modify
20523 + * it under the terms of the GNU General Public License as published by
20524 + * the Free Software Foundation; either version 2 of the License, or
20525 + * (at your option) any later version.
20527 + * This program is distributed in the hope that it will be useful,
20528 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20529 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20530 + * GNU General Public License for more details.
20532 + * You should have received a copy of the GNU General Public License
20533 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20538 + * plink-management and readdir in userspace.
20539 + * assist the pathconf(3) wrapper library.
20541 + * File-based Hierarchical Storage Management.
20544 +#include <linux/compat.h>
20545 +#include <linux/file.h>
20548 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20551 + aufs_bindex_t wbi, bindex, bbot;
20552 + struct file *h_file;
20553 + struct super_block *sb;
20554 + struct dentry *root;
20555 + struct au_branch *br;
20556 + struct aufs_wbr_fd wbrfd = {
20557 + .oflags = au_dir_roflags,
20560 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20561 + | O_NOATIME | O_CLOEXEC;
20563 + AuDebugOn(wbrfd.oflags & ~valid);
20566 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20567 + if (unlikely(err)) {
20573 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20574 + wbrfd.oflags |= au_dir_roflags;
20575 + AuDbg("0%o\n", wbrfd.oflags);
20576 + if (unlikely(wbrfd.oflags & ~valid))
20580 + fd = get_unused_fd_flags(0);
20582 + if (unlikely(fd < 0))
20585 + h_file = ERR_PTR(-EINVAL);
20588 + sb = path->dentry->d_sb;
20589 + root = sb->s_root;
20590 + aufs_read_lock(root, AuLock_IR);
20591 + bbot = au_sbbot(sb);
20592 + if (wbrfd.brid >= 0) {
20593 + wbi = au_br_index(sb, wbrfd.brid);
20594 + if (unlikely(wbi < 0 || wbi > bbot))
20598 + h_file = ERR_PTR(-ENOENT);
20599 + br = au_sbr(sb, wbi);
20600 + if (!au_br_writable(br->br_perm)) {
20604 + bindex = wbi + 1;
20606 + for (; bindex <= bbot; bindex++) {
20607 + br = au_sbr(sb, bindex);
20608 + if (au_br_writable(br->br_perm)) {
20610 + br = au_sbr(sb, wbi);
20615 + AuDbg("wbi %d\n", wbi);
20617 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20621 + aufs_read_unlock(root, AuLock_IR);
20622 + err = PTR_ERR(h_file);
20623 + if (IS_ERR(h_file))
20626 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20627 + fd_install(fd, h_file);
20629 + goto out; /* success */
20632 + put_unused_fd(fd);
20638 +/* ---------------------------------------------------------------------- */
20640 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20643 + struct dentry *dentry;
20646 + case AUFS_CTL_RDU:
20647 + case AUFS_CTL_RDU_INO:
20648 + err = au_rdu_ioctl(file, cmd, arg);
20651 + case AUFS_CTL_WBR_FD:
20652 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20655 + case AUFS_CTL_IBUSY:
20656 + err = au_ibusy_ioctl(file, arg);
20659 + case AUFS_CTL_BRINFO:
20660 + err = au_brinfo_ioctl(file, arg);
20663 + case AUFS_CTL_FHSM_FD:
20664 + dentry = file->f_path.dentry;
20665 + if (IS_ROOT(dentry))
20666 + err = au_fhsm_fd(dentry->d_sb, arg);
20672 + /* do not call the lower */
20673 + AuDbg("0x%x\n", cmd);
20681 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20686 + case AUFS_CTL_MVDOWN:
20687 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20690 + case AUFS_CTL_WBR_FD:
20691 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20695 + /* do not call the lower */
20696 + AuDbg("0x%x\n", cmd);
20704 +#ifdef CONFIG_COMPAT
20705 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20706 + unsigned long arg)
20711 + case AUFS_CTL_RDU:
20712 + case AUFS_CTL_RDU_INO:
20713 + err = au_rdu_compat_ioctl(file, cmd, arg);
20716 + case AUFS_CTL_IBUSY:
20717 + err = au_ibusy_compat_ioctl(file, arg);
20720 + case AUFS_CTL_BRINFO:
20721 + err = au_brinfo_compat_ioctl(file, arg);
20725 + err = aufs_ioctl_dir(file, cmd, arg);
20732 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20733 + unsigned long arg)
20735 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20738 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20739 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20740 +++ linux/fs/aufs/i_op_add.c 2022-10-26 22:30:38.469315525 +0200
20742 +// SPDX-License-Identifier: GPL-2.0
20744 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20746 + * This program, aufs is free software; you can redistribute it and/or modify
20747 + * it under the terms of the GNU General Public License as published by
20748 + * the Free Software Foundation; either version 2 of the License, or
20749 + * (at your option) any later version.
20751 + * This program is distributed in the hope that it will be useful,
20752 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20753 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20754 + * GNU General Public License for more details.
20756 + * You should have received a copy of the GNU General Public License
20757 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20761 + * inode operations (add entry)
20764 +#include <linux/iversion.h>
20768 + * final procedure of adding a new entry, except link(2).
20769 + * remove whiteout, instantiate, copyup the parent dir's times and size
20770 + * and update version.
20771 + * if it failed, re-create the removed whiteout.
20773 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20774 + struct dentry *wh_dentry, struct dentry *dentry)
20777 + aufs_bindex_t bwh;
20778 + struct path h_path;
20779 + struct super_block *sb;
20780 + struct inode *inode, *h_dir;
20781 + struct dentry *wh;
20786 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20787 + IMustLock(h_dir);
20788 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20789 + bwh = au_dbwh(dentry);
20790 + h_path.dentry = wh_dentry;
20791 + h_path.mnt = au_sbr_mnt(sb, bindex);
20792 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20794 + if (unlikely(err))
20798 + inode = au_new_inode(dentry, /*must_new*/1);
20799 + if (!IS_ERR(inode)) {
20800 + d_instantiate(dentry, inode);
20801 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20803 + au_dir_ts(dir, bindex);
20804 + inode_inc_iversion(dir);
20805 + au_fhsm_wrote(sb, bindex, /*force*/0);
20806 + return 0; /* success */
20809 + err = PTR_ERR(inode);
20814 + /* dir inode is locked */
20815 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20816 + rerr = PTR_ERR(wh);
20817 + if (IS_ERR(wh)) {
20818 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20819 + dentry, err, rerr);
20828 +static int au_d_may_add(struct dentry *dentry)
20833 + if (unlikely(d_unhashed(dentry)))
20835 + if (unlikely(d_really_is_positive(dentry)))
20841 + * simple tests for the adding inode operations.
20842 + * following the checks in vfs, plus the parent-child relationship.
20844 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20845 + struct dentry *h_parent, int isdir)
20849 + struct dentry *h_dentry;
20850 + struct inode *h_inode;
20852 + err = -ENAMETOOLONG;
20853 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20856 + h_dentry = au_h_dptr(dentry, bindex);
20857 + if (d_really_is_negative(dentry)) {
20859 + if (unlikely(d_is_positive(h_dentry)))
20862 + /* rename(2) case */
20864 + if (unlikely(d_is_negative(h_dentry)))
20866 + h_inode = d_inode(h_dentry);
20867 + if (unlikely(!h_inode->i_nlink))
20870 + h_mode = h_inode->i_mode;
20873 + if (unlikely(S_ISDIR(h_mode)))
20875 + } else if (unlikely(!S_ISDIR(h_mode))) {
20882 + /* expected parent dir is locked */
20883 + if (unlikely(h_parent != h_dentry->d_parent))
20892 + * initial procedure of adding a new entry.
20893 + * prepare writable branch and the parent dir, lock it,
20894 + * and lookup whiteout for the new entry.
20896 +static struct dentry*
20897 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20898 + struct dentry *src_dentry, struct au_pin *pin,
20899 + struct au_wr_dir_args *wr_dir_args)
20901 + struct dentry *wh_dentry, *h_parent;
20902 + struct super_block *sb;
20903 + struct au_branch *br;
20905 + unsigned int udba;
20906 + aufs_bindex_t bcpup;
20908 + AuDbg("%pd\n", dentry);
20910 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20912 + wh_dentry = ERR_PTR(err);
20913 + if (unlikely(err < 0))
20916 + sb = dentry->d_sb;
20917 + udba = au_opt_udba(sb);
20918 + err = au_pin(pin, dentry, bcpup, udba,
20919 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20920 + wh_dentry = ERR_PTR(err);
20921 + if (unlikely(err))
20924 + h_parent = au_pinned_h_parent(pin);
20925 + if (udba != AuOpt_UDBA_NONE
20926 + && au_dbtop(dentry) == bcpup)
20927 + err = au_may_add(dentry, bcpup, h_parent,
20928 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20929 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20930 + err = -ENAMETOOLONG;
20931 + wh_dentry = ERR_PTR(err);
20932 + if (unlikely(err))
20935 + br = au_sbr(sb, bcpup);
20937 + struct path tmp = {
20938 + .dentry = h_parent,
20939 + .mnt = au_br_mnt(br)
20941 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20944 + wh_dentry = NULL;
20945 + if (bcpup != au_dbwh(dentry))
20946 + goto out; /* success */
20949 + * ENAMETOOLONG here means that if we allowed create such name, then it
20950 + * would not be able to removed in the future. So we don't allow such
20951 + * name here and we don't handle ENAMETOOLONG differently here.
20953 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20956 + if (IS_ERR(wh_dentry))
20959 + return wh_dentry;
20962 +/* ---------------------------------------------------------------------- */
20964 +enum { Mknod, Symlink, Creat };
20965 +struct simple_arg {
20972 + struct vfsub_aopen_args *aopen;
20975 + const char *symname;
20984 +static int add_simple(struct inode *dir, struct dentry *dentry,
20985 + struct simple_arg *arg)
20988 + aufs_bindex_t btop;
20989 + unsigned char created;
20990 + const unsigned char try_aopen
20991 + = (arg->type == Creat && arg->u.c.try_aopen);
20992 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20993 + struct dentry *wh_dentry, *parent;
20994 + struct inode *h_dir;
20995 + struct super_block *sb;
20996 + struct au_branch *br;
20997 + /* to reduce stack size */
20999 + struct au_dtime dt;
21000 + struct au_pin pin;
21001 + struct path h_path;
21002 + struct au_wr_dir_args wr_dir_args;
21005 + AuDbg("%pd\n", dentry);
21009 + a = kmalloc(sizeof(*a), GFP_NOFS);
21010 + if (unlikely(!a))
21012 + a->wr_dir_args.force_btgt = -1;
21013 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21015 + parent = dentry->d_parent; /* dir inode is locked */
21016 + if (!try_aopen) {
21017 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21018 + if (unlikely(err))
21021 + err = au_d_may_add(dentry);
21022 + if (unlikely(err))
21025 + di_write_lock_parent(parent);
21026 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21027 + &a->pin, &a->wr_dir_args);
21028 + err = PTR_ERR(wh_dentry);
21029 + if (IS_ERR(wh_dentry))
21032 + btop = au_dbtop(dentry);
21033 + sb = dentry->d_sb;
21034 + br = au_sbr(sb, btop);
21035 + a->h_path.dentry = au_h_dptr(dentry, btop);
21036 + a->h_path.mnt = au_br_mnt(br);
21037 + h_dir = au_pinned_h_dir(&a->pin);
21038 + switch (arg->type) {
21040 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21041 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21042 + arg->u.c.want_excl);
21044 + if (!err && try_aopen)
21045 + aopen->file->f_mode |= FMODE_CREATED;
21048 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21049 + AuDbg("err %d\n", err);
21050 + AuDbgFile(aopen->file);
21051 + created = err >= 0
21052 + && !!(aopen->file->f_mode & FMODE_CREATED);
21056 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21060 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21067 + if (unlikely(err < 0))
21070 + err = epilog(dir, btop, wh_dentry, dentry);
21072 + goto out_unpin; /* success */
21075 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21076 + /* no delegation since it is just created */
21077 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21080 + AuIOErr("%pd revert failure(%d, %d)\n",
21081 + dentry, err, rerr);
21084 + au_dtime_revert(&a->dt);
21086 + if (try_aopen && h_dir->i_op->atomic_open
21087 + && (aopen->file->f_mode & FMODE_OPENED))
21088 + /* aopen->file is still opened */
21089 + au_lcnt_dec(&aopen->br->br_nfiles);
21092 + au_unpin(&a->pin);
21096 + di_write_unlock(parent);
21098 + if (unlikely(err)) {
21099 + au_update_dbtop(dentry);
21103 + aufs_read_unlock(dentry, AuLock_DW);
21110 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
21111 + struct dentry *dentry, umode_t mode, dev_t dev)
21113 + struct simple_arg arg = {
21120 + return add_simple(dir, dentry, &arg);
21123 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
21124 + struct dentry *dentry, const char *symname)
21126 + struct simple_arg arg = {
21128 + .u.s.symname = symname
21130 + return add_simple(dir, dentry, &arg);
21133 +int aufs_create(struct user_namespace *userns, struct inode *dir,
21134 + struct dentry *dentry, umode_t mode, bool want_excl)
21136 + struct simple_arg arg = {
21140 + .want_excl = want_excl
21143 + return add_simple(dir, dentry, &arg);
21146 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21147 + struct vfsub_aopen_args *aopen_args)
21149 + struct simple_arg arg = {
21152 + .mode = aopen_args->create_mode,
21153 + .want_excl = aopen_args->open_flag & O_EXCL,
21154 + .try_aopen = true,
21155 + .aopen = aopen_args
21158 + return add_simple(dir, dentry, &arg);
21161 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
21162 + struct dentry *dentry, umode_t mode)
21165 + aufs_bindex_t bindex;
21166 + struct super_block *sb;
21167 + struct dentry *parent, *h_parent, *h_dentry;
21168 + struct inode *h_dir, *inode;
21169 + struct vfsmount *h_mnt;
21170 + struct user_namespace *h_userns;
21171 + struct au_wr_dir_args wr_dir_args = {
21172 + .force_btgt = -1,
21173 + .flags = AuWrDir_TMPFILE
21176 + /* copy-up may happen */
21180 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21181 + if (unlikely(err))
21184 + err = au_di_init(dentry);
21185 + if (unlikely(err))
21189 + parent = d_find_any_alias(dir);
21190 + AuDebugOn(!parent);
21191 + di_write_lock_parent(parent);
21192 + if (unlikely(d_inode(parent) != dir))
21195 + err = au_digen_test(parent, au_sigen(sb));
21196 + if (unlikely(err))
21199 + bindex = au_dbtop(parent);
21200 + au_set_dbtop(dentry, bindex);
21201 + au_set_dbbot(dentry, bindex);
21202 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21204 + if (unlikely(err < 0))
21207 + err = -EOPNOTSUPP;
21208 + h_dir = au_h_iptr(dir, bindex);
21209 + if (unlikely(!h_dir->i_op->tmpfile))
21212 + h_mnt = au_sbr_mnt(sb, bindex);
21213 + err = vfsub_mnt_want_write(h_mnt);
21214 + if (unlikely(err))
21217 + h_userns = mnt_user_ns(h_mnt);
21218 + h_parent = au_h_dptr(parent, bindex);
21219 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
21220 + if (IS_ERR(h_dentry)) {
21221 + err = PTR_ERR(h_dentry);
21225 + au_set_dbtop(dentry, bindex);
21226 + au_set_dbbot(dentry, bindex);
21227 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21228 + inode = au_new_inode(dentry, /*must_new*/1);
21229 + if (IS_ERR(inode)) {
21230 + err = PTR_ERR(inode);
21231 + au_set_h_dptr(dentry, bindex, NULL);
21232 + au_set_dbtop(dentry, -1);
21233 + au_set_dbbot(dentry, -1);
21235 + if (!inode->i_nlink)
21236 + set_nlink(inode, 1);
21237 + d_tmpfile(dentry, inode);
21238 + au_di(dentry)->di_tmpfile = 1;
21240 + /* update without i_mutex */
21241 + if (au_ibtop(dir) == au_dbtop(dentry))
21242 + au_cpup_attr_timesizes(dir);
21247 + vfsub_mnt_drop_write(h_mnt);
21249 + di_write_unlock(parent);
21251 + di_write_unlock(dentry);
21252 + if (unlikely(err)) {
21253 + au_di_fin(dentry);
21254 + dentry->d_fsdata = NULL;
21257 + si_read_unlock(sb);
21259 + inode_unlock(dir);
21263 +/* ---------------------------------------------------------------------- */
21265 +struct au_link_args {
21266 + aufs_bindex_t bdst, bsrc;
21267 + struct au_pin pin;
21268 + struct path h_path;
21269 + struct dentry *src_parent, *parent;
21272 +static int au_cpup_before_link(struct dentry *src_dentry,
21273 + struct au_link_args *a)
21276 + struct dentry *h_src_dentry;
21277 + struct au_cp_generic cpg = {
21278 + .dentry = src_dentry,
21283 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21286 + di_read_lock_parent(a->src_parent, AuLock_IR);
21287 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21288 + if (unlikely(err))
21291 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21292 + err = au_pin(&a->pin, src_dentry, a->bdst,
21293 + au_opt_udba(src_dentry->d_sb),
21294 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21295 + if (unlikely(err))
21298 + err = au_sio_cpup_simple(&cpg);
21299 + au_unpin(&a->pin);
21302 + di_read_unlock(a->src_parent, AuLock_IR);
21306 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21307 + struct au_link_args *a)
21310 + unsigned char plink;
21311 + aufs_bindex_t bbot;
21312 + struct dentry *h_src_dentry;
21313 + struct inode *h_inode, *inode, *delegated;
21314 + struct super_block *sb;
21315 + struct file *h_file;
21319 + sb = src_dentry->d_sb;
21320 + inode = d_inode(src_dentry);
21321 + if (au_ibtop(inode) <= a->bdst)
21322 + h_inode = au_h_iptr(inode, a->bdst);
21323 + if (!h_inode || !h_inode->i_nlink) {
21324 + /* copyup src_dentry as the name of dentry. */
21325 + bbot = au_dbbot(dentry);
21326 + if (bbot < a->bsrc)
21327 + au_set_dbbot(dentry, a->bsrc);
21328 + au_set_h_dptr(dentry, a->bsrc,
21329 + dget(au_h_dptr(src_dentry, a->bsrc)));
21330 + dget(a->h_path.dentry);
21331 + au_set_h_dptr(dentry, a->bdst, NULL);
21332 + AuDbg("temporary d_inode...\n");
21333 + spin_lock(&dentry->d_lock);
21334 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21335 + spin_unlock(&dentry->d_lock);
21336 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21337 + if (IS_ERR(h_file))
21338 + err = PTR_ERR(h_file);
21340 + struct au_cp_generic cpg = {
21341 + .dentry = dentry,
21346 + .flags = AuCpup_KEEPLINO
21348 + err = au_sio_cpup_simple(&cpg);
21349 + au_h_open_post(dentry, a->bsrc, h_file);
21351 + dput(a->h_path.dentry);
21352 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21354 + au_set_h_dptr(dentry, a->bdst,
21355 + a->h_path.dentry);
21357 + spin_lock(&dentry->d_lock);
21358 + dentry->d_inode = NULL; /* restore */
21359 + spin_unlock(&dentry->d_lock);
21360 + AuDbg("temporary d_inode...done\n");
21361 + au_set_h_dptr(dentry, a->bsrc, NULL);
21362 + au_set_dbbot(dentry, bbot);
21364 + /* the inode of src_dentry already exists on a.bdst branch */
21365 + h_src_dentry = d_find_alias(h_inode);
21366 + if (!h_src_dentry && au_plink_test(inode)) {
21368 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21369 + err = PTR_ERR(h_src_dentry);
21370 + if (IS_ERR(h_src_dentry))
21373 + if (unlikely(d_is_negative(h_src_dentry))) {
21374 + dput(h_src_dentry);
21375 + h_src_dentry = NULL;
21379 + if (h_src_dentry) {
21380 + delegated = NULL;
21381 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21382 + &a->h_path, &delegated);
21383 + if (unlikely(err == -EWOULDBLOCK)) {
21384 + pr_warn("cannot retry for NFSv4 delegation"
21385 + " for an internal link\n");
21388 + dput(h_src_dentry);
21390 + AuIOErr("no dentry found for hi%lu on b%d\n",
21391 + h_inode->i_ino, a->bdst);
21396 + if (!err && !plink)
21397 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21404 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21405 + struct dentry *dentry)
21408 + struct au_dtime dt;
21409 + struct au_link_args *a;
21410 + struct dentry *wh_dentry, *h_src_dentry;
21411 + struct inode *inode, *delegated;
21412 + struct super_block *sb;
21413 + struct au_wr_dir_args wr_dir_args = {
21414 + /* .force_btgt = -1, */
21415 + .flags = AuWrDir_ADD_ENTRY
21419 + inode = d_inode(src_dentry);
21420 + IMustLock(inode);
21423 + a = kzalloc(sizeof(*a), GFP_NOFS);
21424 + if (unlikely(!a))
21427 + a->parent = dentry->d_parent; /* dir inode is locked */
21428 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21429 + AuLock_NOPLM | AuLock_GEN);
21430 + if (unlikely(err))
21432 + err = au_d_linkable(src_dentry);
21433 + if (unlikely(err))
21435 + err = au_d_may_add(dentry);
21436 + if (unlikely(err))
21439 + a->src_parent = dget_parent(src_dentry);
21440 + wr_dir_args.force_btgt = au_ibtop(inode);
21442 + di_write_lock_parent(a->parent);
21443 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21444 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21446 + err = PTR_ERR(wh_dentry);
21447 + if (IS_ERR(wh_dentry))
21451 + sb = dentry->d_sb;
21452 + a->bdst = au_dbtop(dentry);
21453 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21454 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21455 + a->bsrc = au_ibtop(inode);
21456 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21457 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21458 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21459 + if (!h_src_dentry) {
21460 + a->bsrc = au_dbtop(src_dentry);
21461 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21462 + AuDebugOn(!h_src_dentry);
21463 + } else if (IS_ERR(h_src_dentry)) {
21464 + err = PTR_ERR(h_src_dentry);
21469 + * aufs doesn't touch the credential so
21470 + * security_dentry_create_files_as() is unnecessary.
21472 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21473 + if (a->bdst < a->bsrc
21474 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21475 + err = au_cpup_or_link(src_dentry, dentry, a);
21477 + delegated = NULL;
21478 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21479 + &a->h_path, &delegated);
21480 + if (unlikely(err == -EWOULDBLOCK)) {
21481 + pr_warn("cannot retry for NFSv4 delegation"
21482 + " for an internal link\n");
21486 + dput(h_src_dentry);
21489 + * copyup src_dentry to the branch we process,
21490 + * and then link(2) to it.
21492 + dput(h_src_dentry);
21493 + if (a->bdst < a->bsrc
21494 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21495 + au_unpin(&a->pin);
21496 + di_write_unlock(a->parent);
21497 + err = au_cpup_before_link(src_dentry, a);
21498 + di_write_lock_parent(a->parent);
21500 + err = au_pin(&a->pin, dentry, a->bdst,
21502 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21503 + if (unlikely(err))
21507 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21509 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21510 + delegated = NULL;
21511 + err = vfsub_link(h_src_dentry,
21512 + au_pinned_h_dir(&a->pin),
21513 + &a->h_path, &delegated);
21514 + if (unlikely(err == -EWOULDBLOCK)) {
21515 + pr_warn("cannot retry"
21516 + " for NFSv4 delegation"
21517 + " for an internal link\n");
21523 + if (unlikely(err))
21527 + a->h_path.dentry = wh_dentry;
21528 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21530 + if (unlikely(err))
21534 + au_dir_ts(dir, a->bdst);
21535 + inode_inc_iversion(dir);
21536 + inc_nlink(inode);
21537 + inode->i_ctime = dir->i_ctime;
21538 + d_instantiate(dentry, au_igrab(inode));
21539 + if (d_unhashed(a->h_path.dentry))
21540 + /* some filesystem calls d_drop() */
21542 + /* some filesystems consume an inode even hardlink */
21543 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21544 + goto out_unpin; /* success */
21547 + /* no delegation since it is just created */
21548 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21549 + /*delegated*/NULL, /*force*/0);
21550 + if (unlikely(rerr)) {
21551 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21554 + au_dtime_revert(&dt);
21556 + au_unpin(&a->pin);
21560 + di_write_unlock(a->parent);
21561 + dput(a->src_parent);
21563 + if (unlikely(err)) {
21564 + au_update_dbtop(dentry);
21567 + aufs_read_and_write_unlock2(dentry, src_dentry);
21575 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
21576 + struct dentry *dentry, umode_t mode)
21579 + aufs_bindex_t bindex;
21580 + unsigned char diropq;
21581 + struct path h_path;
21582 + struct dentry *wh_dentry, *parent, *opq_dentry;
21583 + struct inode *h_inode;
21584 + struct super_block *sb;
21586 + struct au_pin pin;
21587 + struct au_dtime dt;
21588 + } *a; /* reduce the stack usage */
21589 + struct au_wr_dir_args wr_dir_args = {
21590 + .force_btgt = -1,
21591 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21597 + a = kmalloc(sizeof(*a), GFP_NOFS);
21598 + if (unlikely(!a))
21601 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21602 + if (unlikely(err))
21604 + err = au_d_may_add(dentry);
21605 + if (unlikely(err))
21608 + parent = dentry->d_parent; /* dir inode is locked */
21609 + di_write_lock_parent(parent);
21610 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21611 + &a->pin, &wr_dir_args);
21612 + err = PTR_ERR(wh_dentry);
21613 + if (IS_ERR(wh_dentry))
21616 + sb = dentry->d_sb;
21617 + bindex = au_dbtop(dentry);
21618 + h_path.dentry = au_h_dptr(dentry, bindex);
21619 + h_path.mnt = au_sbr_mnt(sb, bindex);
21620 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21621 + if (unlikely(err))
21624 + /* make the dir opaque */
21626 + h_inode = d_inode(h_path.dentry);
21628 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21629 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21630 + opq_dentry = au_diropq_create(dentry, bindex);
21631 + inode_unlock(h_inode);
21632 + err = PTR_ERR(opq_dentry);
21633 + if (IS_ERR(opq_dentry))
21635 + dput(opq_dentry);
21639 + err = epilog(dir, bindex, wh_dentry, dentry);
21642 + goto out_unpin; /* success */
21647 + AuLabel(revert opq);
21648 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21649 + rerr = au_diropq_remove(dentry, bindex);
21650 + inode_unlock(h_inode);
21652 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21653 + dentry, err, rerr);
21659 + AuLabel(revert dir);
21660 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21662 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21663 + dentry, err, rerr);
21666 + au_dtime_revert(&a->dt);
21668 + au_unpin(&a->pin);
21671 + di_write_unlock(parent);
21673 + if (unlikely(err)) {
21674 + au_update_dbtop(dentry);
21677 + aufs_read_unlock(dentry, AuLock_DW);
21683 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21684 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21685 +++ linux/fs/aufs/i_op.c 2022-10-26 22:30:38.469315525 +0200
21687 +// SPDX-License-Identifier: GPL-2.0
21689 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21691 + * This program, aufs is free software; you can redistribute it and/or modify
21692 + * it under the terms of the GNU General Public License as published by
21693 + * the Free Software Foundation; either version 2 of the License, or
21694 + * (at your option) any later version.
21696 + * This program is distributed in the hope that it will be useful,
21697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21699 + * GNU General Public License for more details.
21701 + * You should have received a copy of the GNU General Public License
21702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21706 + * inode operations (except add/del/rename)
21709 +#include <linux/device_cgroup.h>
21710 +#include <linux/fs_stack.h>
21711 +#include <linux/iversion.h>
21712 +#include <linux/security.h>
21715 +static int h_permission(struct inode *h_inode, int mask,
21716 + struct path *h_path, int brperm)
21719 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21720 + struct user_namespace *h_userns;
21723 + if (write_mask && IS_IMMUTABLE(h_inode))
21727 + if (((mask & MAY_EXEC)
21728 + && S_ISREG(h_inode->i_mode)
21729 + && (path_noexec(h_path)
21730 + || !(h_inode->i_mode & 0111))))
21734 + * - skip the lower fs test in the case of write to ro branch.
21735 + * - nfs dir permission write check is optimized, but a policy for
21736 + * link/rename requires a real check.
21737 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21738 + * in this case, generic_permission() returns -EOPNOTSUPP.
21740 + h_userns = mnt_user_ns(h_path->mnt);
21741 + if ((write_mask && !au_br_writable(brperm))
21742 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21743 + && write_mask && !(mask & MAY_READ))
21744 + || !h_inode->i_op->permission) {
21745 + /* AuLabel(generic_permission); */
21746 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
21747 + err = generic_permission(h_userns, h_inode, mask);
21748 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21749 + err = h_inode->i_op->permission(h_userns, h_inode,
21753 + /* AuLabel(h_inode->permission); */
21754 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
21759 + err = devcgroup_inode_permission(h_inode, mask);
21761 + err = security_inode_permission(h_inode, mask);
21767 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
21771 + aufs_bindex_t bindex, bbot;
21772 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21773 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21774 + struct inode *h_inode;
21775 + struct super_block *sb;
21776 + struct au_branch *br;
21778 + /* todo: support rcu-walk? */
21779 + if (mask & MAY_NOT_BLOCK)
21782 + sb = inode->i_sb;
21783 + si_read_lock(sb, AuLock_FLUSH);
21784 + ii_read_lock_child(inode);
21785 +#if 0 /* reserved for future use */
21787 + * This test may be rather 'too much' since the test is essentially done
21788 + * in the aufs_lookup(). Theoretically it is possible that the inode
21789 + * generation doesn't match to the superblock's here. But it isn't a
21790 + * big deal I suppose.
21792 + err = au_iigen_test(inode, au_sigen(sb));
21793 + if (unlikely(err))
21799 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21800 + err = au_busy_or_stale();
21801 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21802 + if (unlikely(!h_inode
21803 + || (h_inode->i_mode & S_IFMT)
21804 + != (inode->i_mode & S_IFMT)))
21808 + bindex = au_ibtop(inode);
21809 + br = au_sbr(sb, bindex);
21810 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21813 + && !special_file(h_inode->i_mode)) {
21814 + /* test whether the upper writable branch exists */
21816 + for (; bindex >= 0; bindex--)
21817 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21825 + /* non-write to dir */
21827 + bbot = au_ibbot(inode);
21828 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21829 + h_inode = au_h_iptr(inode, bindex);
21831 + err = au_busy_or_stale();
21832 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21835 + br = au_sbr(sb, bindex);
21836 + err = h_permission(h_inode, mask, &br->br_path,
21842 + ii_read_unlock(inode);
21843 + si_read_unlock(sb);
21847 +/* ---------------------------------------------------------------------- */
21849 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21850 + unsigned int flags)
21852 + struct dentry *ret, *parent;
21853 + struct inode *inode;
21854 + struct super_block *sb;
21855 + int err, npositive;
21859 + /* todo: support rcu-walk? */
21860 + ret = ERR_PTR(-ECHILD);
21861 + if (flags & LOOKUP_RCU)
21864 + ret = ERR_PTR(-ENAMETOOLONG);
21865 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21869 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21870 + ret = ERR_PTR(err);
21871 + if (unlikely(err))
21874 + err = au_di_init(dentry);
21875 + ret = ERR_PTR(err);
21876 + if (unlikely(err))
21880 + npositive = 0; /* suppress a warning */
21881 + parent = dentry->d_parent; /* dir inode is locked */
21882 + di_read_lock_parent(parent, AuLock_IR);
21883 + err = au_alive_dir(parent);
21885 + err = au_digen_test(parent, au_sigen(sb));
21887 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21888 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21889 + AuLkup_ALLOW_NEG);
21892 + di_read_unlock(parent, AuLock_IR);
21893 + ret = ERR_PTR(err);
21894 + if (unlikely(err < 0))
21898 + inode = au_new_inode(dentry, /*must_new*/0);
21899 + if (IS_ERR(inode)) {
21900 + ret = (void *)inode;
21907 + atomic_inc(&inode->i_count);
21908 + ret = d_splice_alias(inode, dentry);
21909 +#if 0 /* reserved for future use */
21910 + if (unlikely(d_need_lookup(dentry))) {
21911 + spin_lock(&dentry->d_lock);
21912 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21913 + spin_unlock(&dentry->d_lock);
21917 + if (!IS_ERR(ret)) {
21919 + if (ret && ret != dentry)
21920 + ii_write_unlock(inode);
21922 + ii_write_unlock(inode);
21929 + di_write_unlock(dentry);
21931 + si_read_unlock(sb);
21936 +/* ---------------------------------------------------------------------- */
21939 + * very dirty and complicated aufs ->atomic_open().
21940 + * aufs_atomic_open()
21941 + * + au_aopen_or_create()
21943 + * + vfsub_atomic_open()
21944 + * + branch fs ->atomic_open()
21945 + * may call the actual 'open' for h_file
21946 + * + inc br_nfiles only if opened
21947 + * + au_aopen_no_open() or au_aopen_do_open()
21949 + * au_aopen_do_open()
21950 + * + finish_open()
21951 + * + au_do_aopen()
21952 + * + au_do_open() the body of all 'open'
21953 + * + au_do_open_nondir()
21954 + * set the passed h_file
21956 + * au_aopen_no_open()
21957 + * + finish_no_open()
21960 +struct aopen_node {
21961 + struct hlist_bl_node hblist;
21962 + struct file *file, *h_file;
21965 +static int au_do_aopen(struct inode *inode, struct file *file)
21967 + struct hlist_bl_head *aopen;
21968 + struct hlist_bl_node *pos;
21969 + struct aopen_node *node;
21970 + struct au_do_open_args args = {
21972 + .open = au_do_open_nondir
21975 + aopen = &au_sbi(inode->i_sb)->si_aopen;
21976 + hlist_bl_lock(aopen);
21977 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
21978 + if (node->file == file) {
21979 + args.h_file = node->h_file;
21982 + hlist_bl_unlock(aopen);
21983 + /* AuDebugOn(!args.h_file); */
21985 + return au_do_open(file, &args);
21988 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
21989 + struct aopen_node *aopen_node)
21992 + struct hlist_bl_head *aopen;
21995 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
21996 + au_hbl_add(&aopen_node->hblist, aopen);
21997 + err = finish_open(file, dentry, au_do_aopen);
21998 + au_hbl_del(&aopen_node->hblist, aopen);
21999 + /* AuDbgFile(file); */
22000 + AuDbg("%pd%s%s\n", dentry,
22001 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22002 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22008 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22014 + err = finish_no_open(file, dentry);
22020 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22021 + struct file *file, unsigned int open_flag,
22022 + umode_t create_mode)
22024 + int err, did_open;
22025 + unsigned int lkup_flags;
22026 + aufs_bindex_t bindex;
22027 + struct super_block *sb;
22028 + struct dentry *parent, *d;
22029 + struct vfsub_aopen_args args = {
22030 + .open_flag = open_flag,
22031 + .create_mode = create_mode
22033 + struct aopen_node aopen_node = {
22038 + AuDbg("open_flag 0%o\n", open_flag);
22039 + AuDbgDentry(dentry);
22042 + if (!au_di(dentry)) {
22043 + lkup_flags = LOOKUP_OPEN;
22044 + if (open_flag & O_CREAT)
22045 + lkup_flags |= LOOKUP_CREATE;
22046 + d = aufs_lookup(dir, dentry, lkup_flags);
22048 + err = PTR_ERR(d);
22053 + * obsoleted dentry found.
22054 + * another error will be returned later.
22060 + AuDbgDentry(dentry);
22063 + if (d_is_positive(dentry)
22064 + || d_unhashed(dentry)
22065 + || d_unlinked(dentry)
22066 + || !(open_flag & O_CREAT)) {
22067 + err = au_aopen_no_open(file, dentry);
22068 + goto out; /* success */
22071 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22072 + if (unlikely(err))
22075 + sb = dentry->d_sb;
22076 + parent = dentry->d_parent; /* dir is locked */
22077 + di_write_lock_parent(parent);
22078 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22079 + if (unlikely(err < 0))
22082 + AuDbgDentry(dentry);
22083 + if (d_is_positive(dentry)) {
22084 + err = au_aopen_no_open(file, dentry);
22085 + goto out_parent; /* success */
22088 + args.file = alloc_empty_file(file->f_flags, current_cred());
22089 + err = PTR_ERR(args.file);
22090 + if (IS_ERR(args.file))
22093 + bindex = au_dbtop(dentry);
22094 + err = au_aopen_or_create(dir, dentry, &args);
22096 + AuDbgFile(args.file);
22097 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22098 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22101 + args.file = NULL;
22103 + di_write_unlock(parent);
22104 + di_write_unlock(dentry);
22105 + if (unlikely(err < 0)) {
22112 + err = au_aopen_no_open(file, dentry);
22114 + aopen_node.h_file = args.file;
22115 + err = au_aopen_do_open(file, dentry, &aopen_node);
22117 + if (unlikely(err < 0)) {
22121 + au_lcnt_dec(&args.br->br_nfiles);
22123 + goto out_sb; /* success */
22126 + di_write_unlock(parent);
22127 + di_write_unlock(dentry);
22129 + si_read_unlock(sb);
22137 +/* ---------------------------------------------------------------------- */
22139 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22140 + const unsigned char add_entry, aufs_bindex_t bcpup,
22141 + aufs_bindex_t btop)
22144 + struct dentry *h_parent;
22145 + struct inode *h_dir;
22148 + IMustLock(d_inode(parent));
22150 + di_write_lock_parent(parent);
22153 + if (!au_h_dptr(parent, bcpup)) {
22154 + if (btop > bcpup)
22155 + err = au_cpup_dirs(dentry, bcpup);
22156 + else if (btop < bcpup)
22157 + err = au_cpdown_dirs(dentry, bcpup);
22161 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22162 + h_parent = au_h_dptr(parent, bcpup);
22163 + h_dir = d_inode(h_parent);
22164 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22165 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22166 + /* todo: no unlock here */
22167 + inode_unlock_shared(h_dir);
22169 + AuDbg("bcpup %d\n", bcpup);
22171 + if (d_really_is_negative(dentry))
22172 + au_set_h_dptr(dentry, btop, NULL);
22173 + au_update_dbrange(dentry, /*do_put_zero*/0);
22178 + di_write_unlock(parent);
22180 + err = bcpup; /* success */
22187 + * decide the branch and the parent dir where we will create a new entry.
22188 + * returns new bindex or an error.
22189 + * copyup the parent dir if needed.
22191 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22192 + struct au_wr_dir_args *args)
22195 + unsigned int flags;
22196 + aufs_bindex_t bcpup, btop, src_btop;
22197 + const unsigned char add_entry
22198 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22199 + | au_ftest_wrdir(args->flags, TMPFILE);
22200 + struct super_block *sb;
22201 + struct dentry *parent;
22202 + struct au_sbinfo *sbinfo;
22204 + sb = dentry->d_sb;
22205 + sbinfo = au_sbi(sb);
22206 + parent = dget_parent(dentry);
22207 + btop = au_dbtop(dentry);
22209 + if (args->force_btgt < 0) {
22210 + if (src_dentry) {
22211 + src_btop = au_dbtop(src_dentry);
22212 + if (src_btop < btop)
22213 + bcpup = src_btop;
22214 + } else if (add_entry) {
22216 + if (au_ftest_wrdir(args->flags, ISDIR))
22217 + au_fset_wbr(flags, DIR);
22218 + err = AuWbrCreate(sbinfo, dentry, flags);
22222 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22224 + err = AuWbrCopyup(sbinfo, dentry);
22226 + if (!IS_ROOT(dentry)) {
22227 + di_read_lock_parent(parent, !AuLock_IR);
22228 + err = AuWbrCopyup(sbinfo, dentry);
22229 + di_read_unlock(parent, !AuLock_IR);
22231 + err = AuWbrCopyup(sbinfo, dentry);
22234 + if (unlikely(err < 0))
22238 + bcpup = args->force_btgt;
22239 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22242 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22244 + if (bcpup == btop)
22245 + goto out; /* success */
22247 + /* copyup the new parent into the branch we process */
22248 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22250 + if (d_really_is_negative(dentry)) {
22251 + au_set_h_dptr(dentry, btop, NULL);
22252 + au_set_dbtop(dentry, bcpup);
22253 + au_set_dbbot(dentry, bcpup);
22255 + AuDebugOn(add_entry
22256 + && !au_ftest_wrdir(args->flags, TMPFILE)
22257 + && !au_h_dptr(dentry, bcpup));
22265 +/* ---------------------------------------------------------------------- */
22267 +void au_pin_hdir_unlock(struct au_pin *p)
22270 + au_hn_inode_unlock(p->hdir);
22273 +int au_pin_hdir_lock(struct au_pin *p)
22281 + /* even if an error happens later, keep this lock */
22282 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22285 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22290 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22291 + p->h_parent, p->br);
22297 +int au_pin_hdir_relock(struct au_pin *p)
22300 + struct inode *h_i;
22301 + struct dentry *h_d[] = {
22306 + err = au_pin_hdir_lock(p);
22307 + if (unlikely(err))
22310 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22313 + if (d_is_positive(h_d[i])) {
22314 + h_i = d_inode(h_d[i]);
22315 + err = !h_i->i_nlink;
22323 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22325 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22328 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22331 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22332 + p->lsc_hi, 0, NULL, _RET_IP_);
22333 + au_pin_hdir_set_owner(p, current);
22337 +void au_pin_hdir_release(struct au_pin *p)
22340 + au_pin_hdir_set_owner(p, p->task);
22341 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22345 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22347 + if (pin && pin->parent)
22348 + return au_h_dptr(pin->parent, pin->bindex);
22352 +void au_unpin(struct au_pin *p)
22355 + au_pin_hdir_unlock(p);
22356 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22357 + vfsub_mnt_drop_write(p->h_mnt);
22361 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22362 + di_read_unlock(p->parent, AuLock_IR);
22363 + iput(p->hdir->hi_inode);
22365 + p->parent = NULL;
22368 + /* do not clear p->task */
22371 +int au_do_pin(struct au_pin *p)
22374 + struct super_block *sb;
22375 + struct inode *h_dir;
22378 + sb = p->dentry->d_sb;
22379 + p->br = au_sbr(sb, p->bindex);
22380 + if (IS_ROOT(p->dentry)) {
22381 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22382 + p->h_mnt = au_br_mnt(p->br);
22383 + err = vfsub_mnt_want_write(p->h_mnt);
22384 + if (unlikely(err)) {
22385 + au_fclr_pin(p->flags, MNT_WRITE);
22392 + p->h_dentry = NULL;
22393 + if (p->bindex <= au_dbbot(p->dentry))
22394 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22396 + p->parent = dget_parent(p->dentry);
22397 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22398 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22401 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22402 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22404 + h_dir = p->hdir->hi_inode;
22408 + * if DI_LOCKED is not set, then p->parent may be different
22409 + * and h_parent can be NULL.
22411 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22413 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22414 + di_read_unlock(p->parent, AuLock_IR);
22416 + p->parent = NULL;
22420 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22421 + p->h_mnt = au_br_mnt(p->br);
22422 + err = vfsub_mnt_want_write(p->h_mnt);
22423 + if (unlikely(err)) {
22424 + au_fclr_pin(p->flags, MNT_WRITE);
22425 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22426 + di_read_unlock(p->parent, AuLock_IR);
22428 + p->parent = NULL;
22434 + err = au_pin_hdir_lock(p);
22436 + goto out; /* success */
22441 + pr_err("err %d\n", err);
22442 + err = au_busy_or_stale();
22447 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22448 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22449 + unsigned int udba, unsigned char flags)
22451 + p->dentry = dentry;
22453 + p->lsc_di = lsc_di;
22454 + p->lsc_hi = lsc_hi;
22455 + p->flags = flags;
22456 + p->bindex = bindex;
22458 + p->parent = NULL;
22462 + p->h_dentry = NULL;
22463 + p->h_parent = NULL;
22465 + p->task = current;
22468 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22469 + unsigned int udba, unsigned char flags)
22471 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22473 + return au_do_pin(pin);
22476 +/* ---------------------------------------------------------------------- */
22479 + * ->setattr() and ->getattr() are called in various cases.
22480 + * chmod, stat: dentry is revalidated.
22481 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22483 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22485 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22486 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22489 + struct dentry *parent;
22492 + if (au_digen_test(dentry, sigen)) {
22493 + parent = dget_parent(dentry);
22494 + di_read_lock_parent(parent, AuLock_IR);
22495 + err = au_refresh_dentry(dentry, parent);
22496 + di_read_unlock(parent, AuLock_IR);
22504 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22505 + struct au_icpup_args *a)
22509 + aufs_bindex_t btop, ibtop;
22510 + struct dentry *hi_wh, *parent;
22511 + struct inode *inode;
22512 + struct au_wr_dir_args wr_dir_args = {
22513 + .force_btgt = -1,
22517 + if (d_is_dir(dentry))
22518 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22519 + /* plink or hi_wh() case */
22520 + btop = au_dbtop(dentry);
22521 + inode = d_inode(dentry);
22522 + ibtop = au_ibtop(inode);
22523 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22524 + wr_dir_args.force_btgt = ibtop;
22525 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22526 + if (unlikely(err < 0))
22530 + au_fset_icpup(a->flags, DID_CPUP);
22533 + a->pin_flags = AuPin_MNT_WRITE;
22535 + if (!IS_ROOT(dentry)) {
22536 + au_fset_pin(a->pin_flags, DI_LOCKED);
22537 + parent = dget_parent(dentry);
22538 + di_write_lock_parent(parent);
22541 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22542 + if (unlikely(err))
22546 + a->h_path.dentry = au_h_dptr(dentry, btop);
22547 + a->h_inode = d_inode(a->h_path.dentry);
22548 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22549 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22550 + if (ia->ia_size < i_size_read(a->h_inode))
22551 + sz = ia->ia_size;
22552 + inode_unlock_shared(a->h_inode);
22556 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22557 + hi_wh = au_hi_wh(inode, a->btgt);
22559 + struct au_cp_generic cpg = {
22560 + .dentry = dentry,
22566 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22567 + if (unlikely(err))
22569 + hi_wh = au_hi_wh(inode, a->btgt);
22570 + /* todo: revalidate hi_wh? */
22575 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22576 + di_downgrade_lock(parent, AuLock_IR);
22580 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22581 + goto out; /* success */
22583 + if (!d_unhashed(dentry)) {
22584 + struct au_cp_generic cpg = {
22585 + .dentry = dentry,
22590 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22592 + err = au_sio_cpup_simple(&cpg);
22594 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22595 + } else if (!hi_wh)
22596 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22598 + a->h_path.dentry = hi_wh; /* do not dget here */
22601 + a->h_inode = d_inode(a->h_path.dentry);
22603 + goto out; /* success */
22604 + au_unpin(&a->pin);
22607 + di_write_unlock(parent);
22612 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22616 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
22617 + struct iattr *ia)
22620 + struct inode *inode, *delegated;
22621 + struct super_block *sb;
22622 + struct file *file;
22623 + struct au_icpup_args *a;
22624 + struct user_namespace *h_userns;
22626 + inode = d_inode(dentry);
22627 + IMustLock(inode);
22629 + err = setattr_prepare(userns, dentry, ia);
22630 + if (unlikely(err))
22634 + a = kzalloc(sizeof(*a), GFP_NOFS);
22635 + if (unlikely(!a))
22638 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22639 + ia->ia_valid &= ~ATTR_MODE;
22642 + sb = dentry->d_sb;
22643 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22644 + if (unlikely(err))
22647 + if (ia->ia_valid & ATTR_FILE) {
22648 + /* currently ftruncate(2) only */
22649 + AuDebugOn(!d_is_reg(dentry));
22650 + file = ia->ia_file;
22651 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22653 + if (unlikely(err))
22655 + ia->ia_file = au_hf_top(file);
22656 + a->udba = AuOpt_UDBA_NONE;
22658 + /* fchmod() doesn't pass ia_file */
22659 + a->udba = au_opt_udba(sb);
22660 + di_write_lock_child(dentry);
22661 + /* no d_unlinked(), to set UDBA_NONE for root */
22662 + if (d_unhashed(dentry))
22663 + a->udba = AuOpt_UDBA_NONE;
22664 + if (a->udba != AuOpt_UDBA_NONE) {
22665 + AuDebugOn(IS_ROOT(dentry));
22666 + err = au_reval_for_attr(dentry, au_sigen(sb));
22667 + if (unlikely(err))
22672 + err = au_pin_and_icpup(dentry, ia, a);
22673 + if (unlikely(err < 0))
22675 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22676 + ia->ia_file = NULL;
22677 + ia->ia_valid &= ~ATTR_FILE;
22680 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22681 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22682 + == (ATTR_MODE | ATTR_CTIME)) {
22683 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22684 + if (unlikely(err))
22686 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22687 + && (ia->ia_valid & ATTR_CTIME)) {
22688 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22689 + if (unlikely(err))
22693 + if (ia->ia_valid & ATTR_SIZE) {
22696 + if (ia->ia_size < i_size_read(inode))
22698 + truncate_setsize(inode, ia->ia_size);
22701 + if (ia->ia_valid & ATTR_FILE)
22703 + inode_unlock(a->h_inode);
22704 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22705 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22707 + delegated = NULL;
22709 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22711 + err = break_deleg_wait(&delegated);
22719 + * regardless aufs 'acl' option setting.
22720 + * why don't all acl-aware fs call this func from their ->setattr()?
22722 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22723 + h_userns = mnt_user_ns(a->h_path.mnt);
22724 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
22727 + au_cpup_attr_changeable(inode);
22730 + inode_unlock(a->h_inode);
22731 + au_unpin(&a->pin);
22732 + if (unlikely(err))
22733 + au_update_dbtop(dentry);
22735 + di_write_unlock(dentry);
22737 + fi_write_unlock(file);
22738 + ia->ia_file = file;
22739 + ia->ia_valid |= ATTR_FILE;
22742 + si_read_unlock(sb);
22750 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22751 +static int au_h_path_to_set_attr(struct dentry *dentry,
22752 + struct au_icpup_args *a, struct path *h_path)
22755 + struct super_block *sb;
22757 + sb = dentry->d_sb;
22758 + a->udba = au_opt_udba(sb);
22759 + /* no d_unlinked(), to set UDBA_NONE for root */
22760 + if (d_unhashed(dentry))
22761 + a->udba = AuOpt_UDBA_NONE;
22762 + if (a->udba != AuOpt_UDBA_NONE) {
22763 + AuDebugOn(IS_ROOT(dentry));
22764 + err = au_reval_for_attr(dentry, au_sigen(sb));
22765 + if (unlikely(err))
22768 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22769 + if (unlikely(err < 0))
22772 + h_path->dentry = a->h_path.dentry;
22773 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22779 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22780 + struct au_sxattr *arg)
22783 + struct path h_path;
22784 + struct super_block *sb;
22785 + struct au_icpup_args *a;
22786 + struct inode *h_inode;
22787 + struct user_namespace *h_userns;
22789 + IMustLock(inode);
22792 + a = kzalloc(sizeof(*a), GFP_NOFS);
22793 + if (unlikely(!a))
22796 + sb = dentry->d_sb;
22797 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22798 + if (unlikely(err))
22801 + h_path.dentry = NULL; /* silence gcc */
22802 + di_write_lock_child(dentry);
22803 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22804 + if (unlikely(err))
22806 + h_userns = mnt_user_ns(h_path.mnt);
22808 + inode_unlock(a->h_inode);
22809 + switch (arg->type) {
22810 + case AU_XATTR_SET:
22811 + AuDebugOn(d_is_negative(h_path.dentry));
22812 + err = vfsub_setxattr(h_userns, h_path.dentry,
22813 + arg->u.set.name, arg->u.set.value,
22814 + arg->u.set.size, arg->u.set.flags);
22817 + err = -EOPNOTSUPP;
22818 + h_inode = d_inode(h_path.dentry);
22819 + if (h_inode->i_op->set_acl) {
22820 + /* this will call posix_acl_update_mode */
22821 + err = h_inode->i_op->set_acl(h_userns, h_inode,
22822 + arg->u.acl_set.acl,
22823 + arg->u.acl_set.type);
22828 + au_cpup_attr_timesizes(inode);
22830 + au_unpin(&a->pin);
22831 + if (unlikely(err))
22832 + au_update_dbtop(dentry);
22835 + di_write_unlock(dentry);
22836 + si_read_unlock(sb);
22845 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22846 + unsigned int nlink)
22850 + inode->i_mode = st->mode;
22851 + /* don't i_[ug]id_write() here */
22852 + inode->i_uid = st->uid;
22853 + inode->i_gid = st->gid;
22854 + inode->i_atime = st->atime;
22855 + inode->i_mtime = st->mtime;
22856 + inode->i_ctime = st->ctime;
22858 + au_cpup_attr_nlink(inode, /*force*/0);
22859 + if (S_ISDIR(inode->i_mode)) {
22860 + n = inode->i_nlink;
22863 + smp_mb(); /* for i_nlink */
22864 + /* 0 can happen */
22865 + set_nlink(inode, n);
22868 + spin_lock(&inode->i_lock);
22869 + inode->i_blocks = st->blocks;
22870 + i_size_write(inode, st->size);
22871 + spin_unlock(&inode->i_lock);
22875 + * common routine for aufs_getattr() and au_getxattr().
22876 + * returns zero or negative (an error).
22877 + * @dentry will be read-locked in success.
22879 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22880 + struct path *h_path, int locked)
22883 + unsigned int mnt_flags, sigen;
22884 + unsigned char udba_none;
22885 + aufs_bindex_t bindex;
22886 + struct super_block *sb, *h_sb;
22888 + h_path->mnt = NULL;
22889 + h_path->dentry = NULL;
22892 + sb = dentry->d_sb;
22893 + mnt_flags = au_mntflags(sb);
22894 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22896 + if (unlikely(locked))
22897 + goto body; /* skip locking dinfo */
22899 + /* support fstat(2) */
22900 + if (!d_unlinked(dentry) && !udba_none) {
22901 + sigen = au_sigen(sb);
22902 + err = au_digen_test(dentry, sigen);
22904 + di_read_lock_child(dentry, AuLock_IR);
22905 + err = au_dbrange_test(dentry);
22906 + if (unlikely(err)) {
22907 + di_read_unlock(dentry, AuLock_IR);
22911 + AuDebugOn(IS_ROOT(dentry));
22912 + di_write_lock_child(dentry);
22913 + err = au_dbrange_test(dentry);
22915 + err = au_reval_for_attr(dentry, sigen);
22917 + di_downgrade_lock(dentry, AuLock_IR);
22919 + di_write_unlock(dentry);
22924 + di_read_lock_child(dentry, AuLock_IR);
22928 + inode = d_inode(dentry);
22929 + if (unlikely(!inode))
22932 + bindex = au_ibtop(inode);
22933 + h_path->mnt = au_sbr_mnt(sb, bindex);
22934 + h_sb = h_path->mnt->mnt_sb;
22936 + && !au_test_fs_bad_iattr(h_sb)
22938 + goto out; /* success */
22940 + if (au_dbtop(dentry) == bindex)
22941 + h_path->dentry = au_h_dptr(dentry, bindex);
22942 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22943 + h_path->dentry = au_plink_lkup(inode, bindex);
22944 + if (IS_ERR(h_path->dentry))
22945 + /* pretending success */
22946 + h_path->dentry = NULL;
22948 + dput(h_path->dentry);
22955 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
22956 + struct kstat *st, u32 request, unsigned int query)
22959 + unsigned char positive;
22960 + struct path h_path;
22961 + struct dentry *dentry;
22962 + struct inode *inode;
22963 + struct super_block *sb;
22965 + dentry = path->dentry;
22966 + inode = d_inode(dentry);
22967 + sb = dentry->d_sb;
22968 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22969 + if (unlikely(err))
22971 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
22973 + if (unlikely(err))
22975 + if (unlikely(!h_path.dentry))
22976 + /* illegally overlapped or something */
22977 + goto out_fill; /* pretending success */
22979 + positive = d_is_positive(h_path.dentry);
22981 + /* no vfsub version */
22982 + err = vfs_getattr(&h_path, st, request, query);
22985 + au_refresh_iattr(inode, st,
22986 + d_inode(h_path.dentry)->i_nlink);
22987 + goto out_fill; /* success */
22993 + generic_fillattr(userns, inode, st);
22995 + di_read_unlock(dentry, AuLock_IR);
22997 + si_read_unlock(sb);
23003 +/* ---------------------------------------------------------------------- */
23005 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23006 + struct delayed_call *done)
23009 + struct dentry *h_dentry;
23010 + struct inode *h_inode;
23012 + aufs_bindex_t bindex;
23014 + ret = NULL; /* suppress a warning */
23019 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23020 + if (unlikely(err))
23023 + err = au_d_hashed_positive(dentry);
23024 + if (unlikely(err))
23028 + inode = d_inode(dentry);
23029 + bindex = au_ibtop(inode);
23030 + h_inode = au_h_iptr(inode, bindex);
23031 + if (unlikely(!h_inode->i_op->get_link))
23036 + if (au_dbtop(dentry) <= bindex) {
23037 + h_dentry = au_h_dptr(dentry, bindex);
23042 + h_dentry = d_find_any_alias(h_inode);
23043 + if (IS_ERR(h_dentry)) {
23044 + err = PTR_ERR(h_dentry);
23048 + if (unlikely(!h_dentry))
23052 + AuDbg("%ps\n", h_inode->i_op->get_link);
23053 + AuDbgDentry(h_dentry);
23054 + ret = vfs_get_link(h_dentry, done);
23057 + err = PTR_ERR(ret);
23060 + aufs_read_unlock(dentry, AuLock_IR);
23062 + if (unlikely(err))
23063 + ret = ERR_PTR(err);
23064 + AuTraceErrPtr(ret);
23068 +/* ---------------------------------------------------------------------- */
23070 +static int au_is_special(struct inode *inode)
23072 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23075 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23079 + aufs_bindex_t bindex;
23080 + struct super_block *sb;
23081 + struct inode *h_inode;
23082 + struct vfsmount *h_mnt;
23084 + sb = inode->i_sb;
23085 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23086 + "unexpected s_flags 0x%lx", sb->s_flags);
23088 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23090 + si_read_lock(sb, AuLock_FLUSH);
23091 + ii_write_lock_child(inode);
23094 + bindex = au_ibtop(inode);
23095 + h_inode = au_h_iptr(inode, bindex);
23096 + if (!au_test_ro(sb, bindex, inode)) {
23097 + h_mnt = au_sbr_mnt(sb, bindex);
23098 + err = vfsub_mnt_want_write(h_mnt);
23100 + err = vfsub_update_time(h_inode, ts, flags);
23101 + vfsub_mnt_drop_write(h_mnt);
23103 + } else if (au_is_special(h_inode)) {
23105 + * Never copy-up here.
23106 + * These special files may already be opened and used for
23107 + * communicating. If we copied it up, then the communication
23108 + * would be corrupted.
23110 + AuWarn1("timestamps for i%lu are ignored "
23111 + "since it is on readonly branch (hi%lu).\n",
23112 + inode->i_ino, h_inode->i_ino);
23113 + } else if (flags & ~S_ATIME) {
23115 + AuIOErr1("unexpected flags 0x%x\n", flags);
23120 + au_cpup_attr_timesizes(inode);
23121 + ii_write_unlock(inode);
23122 + si_read_unlock(sb);
23125 + if (!err && (flags & S_VERSION))
23126 + inode_inc_iversion(inode);
23131 +/* ---------------------------------------------------------------------- */
23133 +/* no getattr version will be set by module.c:aufs_init() */
23134 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23136 + [AuIop_SYMLINK] = {
23137 + .permission = aufs_permission,
23138 +#ifdef CONFIG_FS_POSIX_ACL
23139 + .get_acl = aufs_get_acl,
23140 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23143 + .setattr = aufs_setattr,
23144 + .getattr = aufs_getattr,
23146 +#ifdef CONFIG_AUFS_XATTR
23147 + .listxattr = aufs_listxattr,
23150 + .get_link = aufs_get_link,
23152 + /* .update_time = aufs_update_time */
23155 + .create = aufs_create,
23156 + .lookup = aufs_lookup,
23157 + .link = aufs_link,
23158 + .unlink = aufs_unlink,
23159 + .symlink = aufs_symlink,
23160 + .mkdir = aufs_mkdir,
23161 + .rmdir = aufs_rmdir,
23162 + .mknod = aufs_mknod,
23163 + .rename = aufs_rename,
23165 + .permission = aufs_permission,
23166 +#ifdef CONFIG_FS_POSIX_ACL
23167 + .get_acl = aufs_get_acl,
23168 + .set_acl = aufs_set_acl,
23171 + .setattr = aufs_setattr,
23172 + .getattr = aufs_getattr,
23174 +#ifdef CONFIG_AUFS_XATTR
23175 + .listxattr = aufs_listxattr,
23178 + .update_time = aufs_update_time,
23179 + .atomic_open = aufs_atomic_open,
23180 + .tmpfile = aufs_tmpfile
23182 + [AuIop_OTHER] = {
23183 + .permission = aufs_permission,
23184 +#ifdef CONFIG_FS_POSIX_ACL
23185 + .get_acl = aufs_get_acl,
23186 + .set_acl = aufs_set_acl,
23189 + .setattr = aufs_setattr,
23190 + .getattr = aufs_getattr,
23192 +#ifdef CONFIG_AUFS_XATTR
23193 + .listxattr = aufs_listxattr,
23196 + .update_time = aufs_update_time
23199 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23200 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23201 +++ linux/fs/aufs/i_op_del.c 2022-10-26 22:30:38.469315525 +0200
23203 +// SPDX-License-Identifier: GPL-2.0
23205 + * Copyright (C) 2005-2021 Junjiro R. Okajima
23207 + * This program, aufs is free software; you can redistribute it and/or modify
23208 + * it under the terms of the GNU General Public License as published by
23209 + * the Free Software Foundation; either version 2 of the License, or
23210 + * (at your option) any later version.
23212 + * This program is distributed in the hope that it will be useful,
23213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23215 + * GNU General Public License for more details.
23217 + * You should have received a copy of the GNU General Public License
23218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23222 + * inode operations (del entry)
23225 +#include <linux/iversion.h>
23229 + * decide if a new whiteout for @dentry is necessary or not.
23230 + * when it is necessary, prepare the parent dir for the upper branch whose
23231 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23232 + * be done by caller.
23234 + * 0: wh is unnecessary
23235 + * plus: wh is necessary
23238 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23240 + int need_wh, err;
23241 + aufs_bindex_t btop;
23242 + struct super_block *sb;
23244 + sb = dentry->d_sb;
23245 + btop = au_dbtop(dentry);
23246 + if (*bcpup < 0) {
23248 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23249 + err = AuWbrCopyup(au_sbi(sb), dentry);
23251 + if (unlikely(err < 0))
23255 + AuDebugOn(btop < *bcpup
23256 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23257 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23259 + if (*bcpup != btop) {
23260 + err = au_cpup_dirs(dentry, *bcpup);
23261 + if (unlikely(err))
23265 + struct au_dinfo *dinfo, *tmp;
23267 + need_wh = -ENOMEM;
23268 + dinfo = au_di(dentry);
23269 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23271 + au_di_cp(tmp, dinfo);
23272 + au_di_swap(tmp, dinfo);
23273 + /* returns the number of positive dentries */
23274 + need_wh = au_lkup_dentry(dentry, btop + 1,
23275 + /* AuLkup_IGNORE_PERM */ 0);
23276 + au_di_swap(tmp, dinfo);
23277 + au_rw_write_unlock(&tmp->di_rwsem);
23281 + AuDbg("need_wh %d\n", need_wh);
23289 + * simple tests for the del-entry operations.
23290 + * following the checks in vfs, plus the parent-child relationship.
23292 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23293 + struct dentry *h_parent, int isdir)
23297 + struct dentry *h_dentry, *h_latest;
23298 + struct inode *h_inode;
23299 + struct path h_ppath;
23300 + struct super_block *sb;
23301 + struct au_branch *br;
23302 + struct user_namespace *h_userns;
23304 + h_dentry = au_h_dptr(dentry, bindex);
23305 + if (d_really_is_positive(dentry)) {
23307 + if (unlikely(d_is_negative(h_dentry)))
23309 + h_inode = d_inode(h_dentry);
23310 + if (unlikely(!h_inode->i_nlink))
23313 + h_mode = h_inode->i_mode;
23316 + if (unlikely(S_ISDIR(h_mode)))
23318 + } else if (unlikely(!S_ISDIR(h_mode))) {
23323 + /* rename(2) case */
23325 + if (unlikely(d_is_positive(h_dentry)))
23330 + /* expected parent dir is locked */
23331 + if (unlikely(h_parent != h_dentry->d_parent))
23336 + * rmdir a dir may break the consistency on some filesystem.
23337 + * let's try heavy test.
23340 + sb = dentry->d_sb;
23341 + br = au_sbr(sb, bindex);
23342 + h_userns = au_br_userns(br);
23343 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23344 + && au_test_h_perm(h_userns, d_inode(h_parent),
23345 + MAY_EXEC | MAY_WRITE)))
23348 + h_ppath.dentry = h_parent;
23349 + h_ppath.mnt = au_br_mnt(br);
23350 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
23352 + if (IS_ERR(h_latest))
23354 + if (h_latest == h_dentry)
23363 + * decide the branch where we operate for @dentry. the branch index will be set
23364 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23365 + * dir for reverting.
23366 + * when a new whiteout is necessary, create it.
23368 +static struct dentry*
23369 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23370 + struct au_dtime *dt, struct au_pin *pin)
23372 + struct dentry *wh_dentry;
23373 + struct super_block *sb;
23374 + struct path h_path;
23375 + int err, need_wh;
23376 + unsigned int udba;
23377 + aufs_bindex_t bcpup;
23379 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23380 + wh_dentry = ERR_PTR(need_wh);
23381 + if (unlikely(need_wh < 0))
23384 + sb = dentry->d_sb;
23385 + udba = au_opt_udba(sb);
23387 + err = au_pin(pin, dentry, bcpup, udba,
23388 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23389 + wh_dentry = ERR_PTR(err);
23390 + if (unlikely(err))
23393 + h_path.dentry = au_pinned_h_parent(pin);
23394 + if (udba != AuOpt_UDBA_NONE
23395 + && au_dbtop(dentry) == bcpup) {
23396 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23397 + wh_dentry = ERR_PTR(err);
23398 + if (unlikely(err))
23402 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23403 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23404 + wh_dentry = NULL;
23406 + goto out; /* success, no need to create whiteout */
23408 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23409 + if (IS_ERR(wh_dentry))
23412 + /* returns with the parent is locked and wh_dentry is dget-ed */
23413 + goto out; /* success */
23418 + return wh_dentry;
23422 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23423 + * in order to be revertible and save time for removing many child whiteouts
23425 + * returns 1 when there are too many child whiteout and caller should remove
23426 + * them asynchronously. returns 0 when the number of children is enough small to
23427 + * remove now or the branch fs is a remote fs.
23428 + * otherwise return an error.
23430 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23431 + struct au_nhash *whlist, struct inode *dir)
23433 + int rmdir_later, err, dirwh;
23434 + struct dentry *h_dentry;
23435 + struct super_block *sb;
23436 + struct inode *inode;
23438 + sb = dentry->d_sb;
23439 + SiMustAnyLock(sb);
23440 + h_dentry = au_h_dptr(dentry, bindex);
23441 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23442 + if (unlikely(err))
23445 + /* stop monitoring */
23446 + inode = d_inode(dentry);
23447 + au_hn_free(au_hi(inode, bindex));
23449 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23450 + dirwh = au_sbi(sb)->si_dirwh;
23451 + rmdir_later = (dirwh <= 1);
23452 + if (!rmdir_later)
23453 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23456 + return rmdir_later;
23459 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23460 + if (unlikely(err)) {
23461 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23462 + h_dentry, bindex, err);
23472 + * final procedure for deleting a entry.
23473 + * maintain dentry and iattr.
23475 +static void epilog(struct inode *dir, struct dentry *dentry,
23476 + aufs_bindex_t bindex)
23478 + struct inode *inode;
23480 + inode = d_inode(dentry);
23482 + inode->i_ctime = dir->i_ctime;
23484 + au_dir_ts(dir, bindex);
23485 + inode_inc_iversion(dir);
23489 + * when an error happened, remove the created whiteout and revert everything.
23491 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23492 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23493 + struct dentry *dentry, struct au_dtime *dt)
23496 + struct path h_path = {
23497 + .dentry = wh_dentry,
23498 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23501 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23503 + au_set_dbwh(dentry, bwh);
23504 + au_dtime_revert(dt);
23508 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23512 +/* ---------------------------------------------------------------------- */
23514 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23517 + aufs_bindex_t bwh, bindex, btop;
23518 + struct inode *inode, *h_dir, *delegated;
23519 + struct dentry *parent, *wh_dentry;
23520 + /* to reduce stack size */
23522 + struct au_dtime dt;
23523 + struct au_pin pin;
23524 + struct path h_path;
23530 + a = kmalloc(sizeof(*a), GFP_NOFS);
23531 + if (unlikely(!a))
23534 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23535 + if (unlikely(err))
23537 + err = au_d_hashed_positive(dentry);
23538 + if (unlikely(err))
23540 + inode = d_inode(dentry);
23541 + IMustLock(inode);
23543 + if (unlikely(d_is_dir(dentry)))
23544 + goto out_unlock; /* possible? */
23546 + btop = au_dbtop(dentry);
23547 + bwh = au_dbwh(dentry);
23549 + parent = dentry->d_parent; /* dir inode is locked */
23550 + di_write_lock_parent(parent);
23551 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23553 + err = PTR_ERR(wh_dentry);
23554 + if (IS_ERR(wh_dentry))
23557 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23558 + a->h_path.dentry = au_h_dptr(dentry, btop);
23559 + dget(a->h_path.dentry);
23560 + if (bindex == btop) {
23561 + h_dir = au_pinned_h_dir(&a->pin);
23562 + delegated = NULL;
23563 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23564 + if (unlikely(err == -EWOULDBLOCK)) {
23565 + pr_warn("cannot retry for NFSv4 delegation"
23566 + " for an internal unlink\n");
23570 + /* dir inode is locked */
23571 + h_dir = d_inode(wh_dentry->d_parent);
23572 + IMustLock(h_dir);
23577 + vfsub_drop_nlink(inode);
23578 + epilog(dir, dentry, bindex);
23580 + /* update target timestamps */
23581 + if (bindex == btop) {
23582 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23584 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23586 + /* todo: this timestamp may be reverted later */
23587 + inode->i_ctime = h_dir->i_ctime;
23588 + goto out_unpin; /* success */
23595 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23602 + au_unpin(&a->pin);
23604 + dput(a->h_path.dentry);
23606 + di_write_unlock(parent);
23608 + aufs_read_unlock(dentry, AuLock_DW);
23615 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23617 + int err, rmdir_later;
23618 + aufs_bindex_t bwh, bindex, btop;
23619 + struct inode *inode;
23620 + struct dentry *parent, *wh_dentry, *h_dentry;
23621 + struct au_whtmp_rmdir *args;
23622 + /* to reduce stack size */
23624 + struct au_dtime dt;
23625 + struct au_pin pin;
23631 + a = kmalloc(sizeof(*a), GFP_NOFS);
23632 + if (unlikely(!a))
23635 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23636 + if (unlikely(err))
23638 + err = au_alive_dir(dentry);
23639 + if (unlikely(err))
23641 + inode = d_inode(dentry);
23642 + IMustLock(inode);
23644 + if (unlikely(!d_is_dir(dentry)))
23645 + goto out_unlock; /* possible? */
23648 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23649 + if (unlikely(!args))
23652 + parent = dentry->d_parent; /* dir inode is locked */
23653 + di_write_lock_parent(parent);
23654 + err = au_test_empty(dentry, &args->whlist);
23655 + if (unlikely(err))
23658 + btop = au_dbtop(dentry);
23659 + bwh = au_dbwh(dentry);
23661 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23663 + err = PTR_ERR(wh_dentry);
23664 + if (IS_ERR(wh_dentry))
23667 + h_dentry = au_h_dptr(dentry, btop);
23670 + if (bindex == btop) {
23671 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23673 + rmdir_later = err;
23677 + /* stop monitoring */
23678 + au_hn_free(au_hi(inode, btop));
23680 + /* dir inode is locked */
23681 + IMustLock(d_inode(wh_dentry->d_parent));
23686 + vfsub_dead_dir(inode);
23687 + au_set_dbdiropq(dentry, -1);
23688 + epilog(dir, dentry, bindex);
23690 + if (rmdir_later) {
23691 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23695 + goto out_unpin; /* success */
23703 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23710 + au_unpin(&a->pin);
23714 + di_write_unlock(parent);
23716 + au_whtmp_rmdir_free(args);
23718 + aufs_read_unlock(dentry, AuLock_DW);
23725 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23726 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23727 +++ linux/fs/aufs/i_op_ren.c 2022-10-26 22:30:38.469315525 +0200
23729 +// SPDX-License-Identifier: GPL-2.0
23731 + * Copyright (C) 2005-2021 Junjiro R. Okajima
23733 + * This program, aufs is free software; you can redistribute it and/or modify
23734 + * it under the terms of the GNU General Public License as published by
23735 + * the Free Software Foundation; either version 2 of the License, or
23736 + * (at your option) any later version.
23738 + * This program is distributed in the hope that it will be useful,
23739 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23740 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23741 + * GNU General Public License for more details.
23743 + * You should have received a copy of the GNU General Public License
23744 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23748 + * inode operation (rename entry)
23749 + * todo: this is crazy monster
23752 +#include <linux/iversion.h>
23755 +enum { AuSRC, AuDST, AuSrcDst };
23756 +enum { AuPARENT, AuCHILD, AuParentChild };
23758 +#define AuRen_ISDIR_SRC 1
23759 +#define AuRen_ISDIR_DST (1 << 1)
23760 +#define AuRen_ISSAMEDIR (1 << 2)
23761 +#define AuRen_WHSRC (1 << 3)
23762 +#define AuRen_WHDST (1 << 4)
23763 +#define AuRen_MNT_WRITE (1 << 5)
23764 +#define AuRen_DT_DSTDIR (1 << 6)
23765 +#define AuRen_DIROPQ_SRC (1 << 7)
23766 +#define AuRen_DIROPQ_DST (1 << 8)
23767 +#define AuRen_DIRREN (1 << 9)
23768 +#define AuRen_DROPPED_SRC (1 << 10)
23769 +#define AuRen_DROPPED_DST (1 << 11)
23770 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23771 +#define au_fset_ren(flags, name) \
23772 + do { (flags) |= AuRen_##name; } while (0)
23773 +#define au_fclr_ren(flags, name) \
23774 + do { (flags) &= ~AuRen_##name; } while (0)
23776 +#ifndef CONFIG_AUFS_DIRREN
23777 +#undef AuRen_DIRREN
23778 +#define AuRen_DIRREN 0
23781 +struct au_ren_args {
23783 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23785 + struct inode *dir, *inode;
23786 + struct au_hinode *hdir, *hinode;
23787 + struct au_dtime dt[AuParentChild];
23788 + aufs_bindex_t btop, bdiropq;
23791 +#define src_dentry sd[AuSRC].dentry
23792 +#define src_dir sd[AuSRC].dir
23793 +#define src_inode sd[AuSRC].inode
23794 +#define src_h_dentry sd[AuSRC].h_dentry
23795 +#define src_parent sd[AuSRC].parent
23796 +#define src_h_parent sd[AuSRC].h_parent
23797 +#define src_wh_dentry sd[AuSRC].wh_dentry
23798 +#define src_hdir sd[AuSRC].hdir
23799 +#define src_hinode sd[AuSRC].hinode
23800 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23801 +#define src_dt sd[AuSRC].dt
23802 +#define src_btop sd[AuSRC].btop
23803 +#define src_bdiropq sd[AuSRC].bdiropq
23805 +#define dst_dentry sd[AuDST].dentry
23806 +#define dst_dir sd[AuDST].dir
23807 +#define dst_inode sd[AuDST].inode
23808 +#define dst_h_dentry sd[AuDST].h_dentry
23809 +#define dst_parent sd[AuDST].parent
23810 +#define dst_h_parent sd[AuDST].h_parent
23811 +#define dst_wh_dentry sd[AuDST].wh_dentry
23812 +#define dst_hdir sd[AuDST].hdir
23813 +#define dst_hinode sd[AuDST].hinode
23814 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23815 +#define dst_dt sd[AuDST].dt
23816 +#define dst_btop sd[AuDST].btop
23817 +#define dst_bdiropq sd[AuDST].bdiropq
23819 + struct dentry *h_trap;
23820 + struct au_branch *br;
23821 + struct path h_path;
23822 + struct au_nhash whlist;
23823 + aufs_bindex_t btgt, src_bwh;
23826 + unsigned short auren_flags;
23827 + unsigned char flags; /* syscall parameter */
23828 + unsigned char exchange;
23831 + struct au_whtmp_rmdir *thargs;
23832 + struct dentry *h_dst;
23833 + struct au_hinode *h_root;
23836 +/* ---------------------------------------------------------------------- */
23839 + * functions for reverting.
23840 + * when an error happened in a single rename systemcall, we should revert
23841 + * everything as if nothing happened.
23842 + * we don't need to revert the copied-up/down the parent dir since they are
23846 +#define RevertFailure(fmt, ...) do { \
23847 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23848 + ##__VA_ARGS__, err, rerr); \
23852 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23855 + struct dentry *d;
23856 +#define src_or_dst(member) a->sd[idx].member
23858 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23859 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23860 + rerr = au_diropq_remove(d, a->btgt);
23861 + au_hn_inode_unlock(src_or_dst(hinode));
23862 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23864 + RevertFailure("remove diropq %pd", d);
23866 +#undef src_or_dst_
23869 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23871 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23872 + au_ren_do_rev_diropq(err, a, AuSRC);
23873 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23874 + au_ren_do_rev_diropq(err, a, AuDST);
23877 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23880 + struct inode *delegated;
23881 + struct path h_ppath = {
23882 + .dentry = a->src_h_parent,
23883 + .mnt = a->h_path.mnt
23886 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23887 + rerr = PTR_ERR(a->h_path.dentry);
23888 + if (IS_ERR(a->h_path.dentry)) {
23889 + RevertFailure("lkup one %pd", a->src_dentry);
23893 + delegated = NULL;
23894 + rerr = vfsub_rename(a->dst_h_dir,
23895 + au_h_dptr(a->src_dentry, a->btgt),
23896 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23897 + if (unlikely(rerr == -EWOULDBLOCK)) {
23898 + pr_warn("cannot retry for NFSv4 delegation"
23899 + " for an internal rename\n");
23902 + d_drop(a->h_path.dentry);
23903 + dput(a->h_path.dentry);
23904 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23906 + RevertFailure("rename %pd", a->src_dentry);
23909 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23912 + struct inode *delegated;
23913 + struct path h_ppath = {
23914 + .dentry = a->dst_h_parent,
23915 + .mnt = a->h_path.mnt
23918 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23919 + rerr = PTR_ERR(a->h_path.dentry);
23920 + if (IS_ERR(a->h_path.dentry)) {
23921 + RevertFailure("lkup one %pd", a->dst_dentry);
23924 + if (d_is_positive(a->h_path.dentry)) {
23925 + d_drop(a->h_path.dentry);
23926 + dput(a->h_path.dentry);
23930 + delegated = NULL;
23931 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23932 + &delegated, a->flags);
23933 + if (unlikely(rerr == -EWOULDBLOCK)) {
23934 + pr_warn("cannot retry for NFSv4 delegation"
23935 + " for an internal rename\n");
23938 + d_drop(a->h_path.dentry);
23939 + dput(a->h_path.dentry);
23941 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23943 + RevertFailure("rename %pd", a->h_dst);
23946 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23950 + a->h_path.dentry = a->src_wh_dentry;
23951 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23952 + au_set_dbwh(a->src_dentry, a->src_bwh);
23954 + RevertFailure("unlink %pd", a->src_wh_dentry);
23956 +#undef RevertFailure
23958 +/* ---------------------------------------------------------------------- */
23961 + * when we have to copyup the renaming entry, do it with the rename-target name
23962 + * in order to minimize the cost (the later actual rename is unnecessary).
23963 + * otherwise rename it on the target branch.
23965 +static int au_ren_or_cpup(struct au_ren_args *a)
23968 + struct dentry *d;
23969 + struct inode *delegated;
23971 + d = a->src_dentry;
23972 + if (au_dbtop(d) == a->btgt) {
23973 + a->h_path.dentry = a->dst_h_dentry;
23974 + AuDebugOn(au_dbtop(d) != a->btgt);
23975 + delegated = NULL;
23976 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
23977 + a->dst_h_dir, &a->h_path, &delegated,
23979 + if (unlikely(err == -EWOULDBLOCK)) {
23980 + pr_warn("cannot retry for NFSv4 delegation"
23981 + " for an internal rename\n");
23987 + if (!err && a->h_dst)
23988 + /* it will be set to dinfo later */
23994 +/* cf. aufs_rmdir() */
23995 +static int au_ren_del_whtmp(struct au_ren_args *a)
23998 + struct inode *dir;
24000 + dir = a->dst_dir;
24001 + SiMustAnyLock(dir->i_sb);
24002 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24003 + au_sbi(dir->i_sb)->si_dirwh)
24004 + || au_test_fs_remote(a->h_dst->d_sb)) {
24005 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24006 + if (unlikely(err))
24007 + pr_warn("failed removing whtmp dir %pd (%d), "
24008 + "ignored.\n", a->h_dst, err);
24010 + au_nhash_wh_free(&a->thargs->whlist);
24011 + a->thargs->whlist = a->whlist;
24012 + a->whlist.nh_num = 0;
24013 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24015 + a->thargs = NULL;
24021 +/* make it 'opaque' dir. */
24022 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24025 + struct dentry *d, *diropq;
24026 +#define src_or_dst(member) a->sd[idx].member
24029 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24030 + src_or_dst(bdiropq) = au_dbdiropq(d);
24031 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24032 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24033 + diropq = au_diropq_create(d, a->btgt);
24034 + au_hn_inode_unlock(src_or_dst(hinode));
24035 + if (IS_ERR(diropq))
24036 + err = PTR_ERR(diropq);
24040 +#undef src_or_dst_
24044 +static int au_ren_diropq(struct au_ren_args *a)
24047 + unsigned char always;
24048 + struct dentry *d;
24051 + d = a->dst_dentry; /* already renamed on the branch */
24052 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24053 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24054 + && !au_ftest_ren(a->auren_flags, DIRREN)
24055 + && a->btgt != au_dbdiropq(a->src_dentry)
24056 + && (a->dst_wh_dentry
24057 + || a->btgt <= au_dbdiropq(d)
24058 + /* hide the lower to keep xino */
24059 + /* the lowers may not be a dir, but we hide them anyway */
24060 + || a->btgt < au_dbbot(d)
24063 + err = au_ren_do_diropq(a, AuSRC);
24064 + if (unlikely(err))
24066 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24068 + if (!a->exchange)
24069 + goto out; /* success */
24071 + d = a->src_dentry; /* already renamed on the branch */
24072 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24073 + && a->btgt != au_dbdiropq(a->dst_dentry)
24074 + && (a->btgt < au_dbdiropq(d)
24075 + || a->btgt < au_dbbot(d)
24077 + AuDbgDentry(a->src_dentry);
24078 + AuDbgDentry(a->dst_dentry);
24079 + err = au_ren_do_diropq(a, AuDST);
24080 + if (unlikely(err))
24081 + goto out_rev_src;
24082 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24084 + goto out; /* success */
24087 + AuDbg("err %d, reverting src\n", err);
24088 + au_ren_rev_diropq(err, a);
24093 +static int do_rename(struct au_ren_args *a)
24096 + struct dentry *d, *h_d;
24098 + if (!a->exchange) {
24099 + /* prepare workqueue args for asynchronous rmdir */
24100 + h_d = a->dst_h_dentry;
24101 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24102 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24103 + && d_is_positive(h_d)) {
24105 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24107 + if (unlikely(!a->thargs))
24109 + a->h_dst = dget(h_d);
24112 + /* create whiteout for src_dentry */
24113 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24114 + a->src_bwh = au_dbwh(a->src_dentry);
24115 + AuDebugOn(a->src_bwh >= 0);
24116 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24117 + a->src_h_parent);
24118 + err = PTR_ERR(a->src_wh_dentry);
24119 + if (IS_ERR(a->src_wh_dentry))
24123 + /* lookup whiteout for dentry */
24124 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24125 + h_d = au_wh_lkup(a->dst_h_parent,
24126 + &a->dst_dentry->d_name, a->br);
24127 + err = PTR_ERR(h_d);
24130 + if (d_is_negative(h_d))
24133 + a->dst_wh_dentry = h_d;
24136 + /* rename dentry to tmpwh */
24138 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24139 + if (unlikely(err))
24142 + d = a->dst_dentry;
24143 + au_set_h_dptr(d, a->btgt, NULL);
24144 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24145 + if (unlikely(err))
24147 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24151 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24152 +#if 0 /* debugging */
24153 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24154 + && d_is_positive(a->dst_h_dentry)
24155 + && a->src_btop != a->btgt);
24158 + /* rename by vfs_rename or cpup */
24159 + err = au_ren_or_cpup(a);
24160 + if (unlikely(err))
24161 + /* leave the copied-up one */
24164 + /* make dir opaque */
24165 + err = au_ren_diropq(a);
24166 + if (unlikely(err))
24169 + /* update target timestamps */
24170 + if (a->exchange) {
24171 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24172 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24173 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24174 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24176 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24177 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24178 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24179 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24181 + if (!a->exchange) {
24182 + /* remove whiteout for dentry */
24183 + if (a->dst_wh_dentry) {
24184 + a->h_path.dentry = a->dst_wh_dentry;
24185 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24187 + if (unlikely(err))
24191 + /* remove whtmp */
24193 + au_ren_del_whtmp(a); /* ignore this error */
24195 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24198 + goto out_success;
24201 + au_ren_rev_diropq(err, a);
24203 + au_ren_rev_rename(err, a);
24207 + au_ren_rev_whtmp(err, a);
24209 + dput(a->dst_wh_dentry);
24210 + a->dst_wh_dentry = NULL;
24212 + if (a->src_wh_dentry)
24213 + au_ren_rev_whsrc(err, a);
24215 + dput(a->src_wh_dentry);
24216 + dput(a->dst_wh_dentry);
24220 + au_whtmp_rmdir_free(a->thargs);
24221 + a->thargs = NULL;
24227 +/* ---------------------------------------------------------------------- */
24230 + * test if @dentry dir can be rename destination or not.
24231 + * success means, it is a logically empty dir.
24233 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24235 + return au_test_empty(dentry, whlist);
24239 + * test if @a->src_dentry dir can be rename source or not.
24240 + * if it can, return 0.
24242 + * - it is a logically empty dir.
24243 + * - or, it exists on writable branch and has no children including whiteouts
24244 + * on the lower branch unless DIRREN is on.
24246 +static int may_rename_srcdir(struct au_ren_args *a)
24249 + unsigned int rdhash;
24250 + aufs_bindex_t btop, btgt;
24251 + struct dentry *dentry;
24252 + struct super_block *sb;
24253 + struct au_sbinfo *sbinfo;
24255 + dentry = a->src_dentry;
24256 + sb = dentry->d_sb;
24257 + sbinfo = au_sbi(sb);
24258 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24259 + au_fset_ren(a->auren_flags, DIRREN);
24262 + btop = au_dbtop(dentry);
24263 + if (btop != btgt) {
24264 + struct au_nhash whlist;
24266 + SiMustAnyLock(sb);
24267 + rdhash = sbinfo->si_rdhash;
24269 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24271 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24272 + if (unlikely(err))
24274 + err = au_test_empty(dentry, &whlist);
24275 + au_nhash_wh_free(&whlist);
24279 + if (btop == au_dbtaildir(dentry))
24280 + return 0; /* success */
24282 + err = au_test_empty_lower(dentry);
24285 + if (err == -ENOTEMPTY) {
24286 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24289 + AuWarn1("renaming dir who has child(ren) on multiple "
24290 + "branches, is not supported\n");
24297 +/* side effect: sets whlist and h_dentry */
24298 +static int au_ren_may_dir(struct au_ren_args *a)
24301 + unsigned int rdhash;
24302 + struct dentry *d;
24304 + d = a->dst_dentry;
24305 + SiMustAnyLock(d->d_sb);
24308 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24309 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24311 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24312 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24313 + if (unlikely(err))
24316 + if (!a->exchange) {
24317 + au_set_dbtop(d, a->dst_btop);
24318 + err = may_rename_dstdir(d, &a->whlist);
24319 + au_set_dbtop(d, a->btgt);
24321 + err = may_rename_srcdir(a);
24323 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24324 + if (unlikely(err))
24327 + d = a->src_dentry;
24328 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24329 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24330 + err = may_rename_srcdir(a);
24331 + if (unlikely(err)) {
24332 + au_nhash_wh_free(&a->whlist);
24333 + a->whlist.nh_num = 0;
24340 +/* ---------------------------------------------------------------------- */
24343 + * simple tests for rename.
24344 + * following the checks in vfs, plus the parent-child relationship.
24346 +static int au_may_ren(struct au_ren_args *a)
24349 + struct inode *h_inode;
24351 + if (a->src_btop == a->btgt) {
24352 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24353 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24354 + if (unlikely(err))
24357 + if (unlikely(a->src_h_dentry == a->h_trap))
24362 + if (a->dst_btop != a->btgt)
24365 + err = -ENOTEMPTY;
24366 + if (unlikely(a->dst_h_dentry == a->h_trap))
24370 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24371 + if (d_really_is_negative(a->dst_dentry)) {
24372 + if (d_is_negative(a->dst_h_dentry))
24373 + err = au_may_add(a->dst_dentry, a->btgt,
24374 + a->dst_h_parent, isdir);
24376 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24378 + h_inode = d_inode(a->dst_h_dentry);
24379 + if (h_inode->i_nlink)
24380 + err = au_may_del(a->dst_dentry, a->btgt,
24381 + a->dst_h_parent, isdir);
24385 + if (unlikely(err == -ENOENT || err == -EEXIST))
24391 +/* ---------------------------------------------------------------------- */
24396 + * - src_dir and dir by lock_rename()
24397 + * - inode if exists
24400 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24402 + * + di_write_lock2_child()
24403 + * + di_write_lock_child()
24404 + * + ii_write_lock_child()
24405 + * + di_write_lock_child2()
24406 + * + ii_write_lock_child2()
24407 + * + src_parent and parent
24408 + * + di_write_lock_parent()
24409 + * + ii_write_lock_parent()
24410 + * + di_write_lock_parent2()
24411 + * + ii_write_lock_parent2()
24412 + * + lower src_dir and dir by vfsub_lock_rename()
24413 + * + verify the every relationships between child and parent. if any
24414 + * of them failed, unlock all and return -EBUSY.
24416 +static void au_ren_unlock(struct au_ren_args *a)
24418 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24419 + a->dst_h_parent, a->dst_hdir);
24420 + if (au_ftest_ren(a->auren_flags, DIRREN)
24422 + au_hn_inode_unlock(a->h_root);
24423 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24424 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24427 +static int au_ren_lock(struct au_ren_args *a)
24430 + unsigned int udba;
24433 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24434 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24435 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24436 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24438 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24439 + if (unlikely(err))
24441 + au_fset_ren(a->auren_flags, MNT_WRITE);
24442 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24443 + struct dentry *root;
24444 + struct inode *dir;
24447 + * sbinfo is already locked, so this ii_read_lock is
24448 + * unnecessary. but our debugging feature checks it.
24450 + root = a->src_inode->i_sb->s_root;
24451 + if (root != a->src_parent && root != a->dst_parent) {
24452 + dir = d_inode(root);
24453 + ii_read_lock_parent3(dir);
24454 + a->h_root = au_hi(dir, a->btgt);
24455 + ii_read_unlock(dir);
24456 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24459 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24460 + a->dst_h_parent, a->dst_hdir);
24461 + udba = au_opt_udba(a->src_dentry->d_sb);
24462 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24463 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24464 + err = au_busy_or_stale();
24465 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24466 + err = au_h_verify(a->src_h_dentry, udba,
24467 + d_inode(a->src_h_parent), a->src_h_parent,
24469 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24470 + err = au_h_verify(a->dst_h_dentry, udba,
24471 + d_inode(a->dst_h_parent), a->dst_h_parent,
24474 + goto out; /* success */
24476 + err = au_busy_or_stale();
24477 + au_ren_unlock(a);
24483 +/* ---------------------------------------------------------------------- */
24485 +static void au_ren_refresh_dir(struct au_ren_args *a)
24487 + struct inode *dir;
24489 + dir = a->dst_dir;
24490 + inode_inc_iversion(dir);
24491 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24492 + /* is this updating defined in POSIX? */
24493 + au_cpup_attr_timesizes(a->src_inode);
24494 + au_cpup_attr_nlink(dir, /*force*/1);
24496 + au_dir_ts(dir, a->btgt);
24498 + if (a->exchange) {
24499 + dir = a->src_dir;
24500 + inode_inc_iversion(dir);
24501 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24502 + /* is this updating defined in POSIX? */
24503 + au_cpup_attr_timesizes(a->dst_inode);
24504 + au_cpup_attr_nlink(dir, /*force*/1);
24506 + au_dir_ts(dir, a->btgt);
24509 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24512 + dir = a->src_dir;
24513 + inode_inc_iversion(dir);
24514 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24515 + au_cpup_attr_nlink(dir, /*force*/1);
24516 + au_dir_ts(dir, a->btgt);
24519 +static void au_ren_refresh(struct au_ren_args *a)
24521 + aufs_bindex_t bbot, bindex;
24522 + struct dentry *d, *h_d;
24523 + struct inode *i, *h_i;
24524 + struct super_block *sb;
24526 + d = a->dst_dentry;
24529 + /* already dget-ed by au_ren_or_cpup() */
24530 + au_set_h_dptr(d, a->btgt, a->h_dst);
24532 + i = a->dst_inode;
24534 + if (!a->exchange) {
24535 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24536 + vfsub_drop_nlink(i);
24538 + vfsub_dead_dir(i);
24539 + au_cpup_attr_timesizes(i);
24541 + au_update_dbrange(d, /*do_put_zero*/1);
24543 + au_cpup_attr_nlink(i, /*force*/1);
24546 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24547 + au_set_h_dptr(d, bindex, NULL);
24548 + bbot = au_dbbot(d);
24549 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24550 + au_set_h_dptr(d, bindex, NULL);
24551 + au_update_dbrange(d, /*do_put_zero*/0);
24555 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24556 + d_drop(a->src_dentry);
24557 + if (au_ftest_ren(a->auren_flags, DIRREN))
24558 + au_set_dbwh(a->src_dentry, -1);
24562 + d = a->src_dentry;
24563 + au_set_dbwh(d, -1);
24564 + bbot = au_dbbot(d);
24565 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24566 + h_d = au_h_dptr(d, bindex);
24568 + au_set_h_dptr(d, bindex, NULL);
24570 + au_set_dbbot(d, a->btgt);
24573 + i = a->src_inode;
24574 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24575 + return; /* success */
24577 + bbot = au_ibbot(i);
24578 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24579 + h_i = au_h_iptr(i, bindex);
24581 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24582 + /* ignore this error */
24583 + au_set_h_iptr(i, bindex, NULL, 0);
24586 + au_set_ibbot(i, a->btgt);
24589 +/* ---------------------------------------------------------------------- */
24591 +/* mainly for link(2) and rename(2) */
24592 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24594 + aufs_bindex_t bdiropq, bwh;
24595 + struct dentry *parent;
24596 + struct au_branch *br;
24598 + parent = dentry->d_parent;
24599 + IMustLock(d_inode(parent)); /* dir is locked */
24601 + bdiropq = au_dbdiropq(parent);
24602 + bwh = au_dbwh(dentry);
24603 + br = au_sbr(dentry->d_sb, btgt);
24604 + if (au_br_rdonly(br)
24605 + || (0 <= bdiropq && bdiropq < btgt)
24606 + || (0 <= bwh && bwh < btgt))
24609 + AuDbg("btgt %d\n", btgt);
24613 +/* sets src_btop, dst_btop and btgt */
24614 +static int au_ren_wbr(struct au_ren_args *a)
24617 + struct au_wr_dir_args wr_dir_args = {
24618 + /* .force_btgt = -1, */
24619 + .flags = AuWrDir_ADD_ENTRY
24622 + a->src_btop = au_dbtop(a->src_dentry);
24623 + a->dst_btop = au_dbtop(a->dst_dentry);
24624 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24625 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24626 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24627 + wr_dir_args.force_btgt = a->src_btop;
24628 + if (a->dst_inode && a->dst_btop < a->src_btop)
24629 + wr_dir_args.force_btgt = a->dst_btop;
24630 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24631 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24634 + au_update_dbtop(a->dst_dentry);
24639 +static void au_ren_dt(struct au_ren_args *a)
24641 + a->h_path.dentry = a->src_h_parent;
24642 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24643 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24644 + a->h_path.dentry = a->dst_h_parent;
24645 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24648 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24649 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24653 + a->h_path.dentry = a->src_h_dentry;
24654 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24655 + if (d_is_positive(a->dst_h_dentry)) {
24656 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24657 + a->h_path.dentry = a->dst_h_dentry;
24658 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24662 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24664 + struct dentry *h_d;
24665 + struct inode *h_inode;
24667 + au_dtime_revert(a->src_dt + AuPARENT);
24668 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24669 + au_dtime_revert(a->dst_dt + AuPARENT);
24671 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24672 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24673 + h_inode = d_inode(h_d);
24674 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24675 + au_dtime_revert(a->src_dt + AuCHILD);
24676 + inode_unlock(h_inode);
24678 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24679 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24680 + h_inode = d_inode(h_d);
24681 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24682 + au_dtime_revert(a->dst_dt + AuCHILD);
24683 + inode_unlock(h_inode);
24688 +/* ---------------------------------------------------------------------- */
24690 +int aufs_rename(struct user_namespace *userns,
24691 + struct inode *_src_dir, struct dentry *_src_dentry,
24692 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24693 + unsigned int _flags)
24695 + int err, lock_flags;
24697 + /* reduce stack space */
24698 + struct au_ren_args *a;
24699 + struct au_pin pin;
24701 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24702 + IMustLock(_src_dir);
24703 + IMustLock(_dst_dir);
24706 + if (unlikely(_flags & RENAME_WHITEOUT))
24710 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24711 + a = kzalloc(sizeof(*a), GFP_NOFS);
24712 + if (unlikely(!a))
24715 + a->flags = _flags;
24716 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24717 + && RENAME_EXCHANGE > U8_MAX);
24718 + a->exchange = _flags & RENAME_EXCHANGE;
24719 + a->src_dir = _src_dir;
24720 + a->src_dentry = _src_dentry;
24721 + a->src_inode = NULL;
24722 + if (d_really_is_positive(a->src_dentry))
24723 + a->src_inode = d_inode(a->src_dentry);
24724 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24725 + a->dst_dir = _dst_dir;
24726 + a->dst_dentry = _dst_dentry;
24727 + a->dst_inode = NULL;
24728 + if (d_really_is_positive(a->dst_dentry))
24729 + a->dst_inode = d_inode(a->dst_dentry);
24730 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24731 + if (a->dst_inode) {
24733 + * if EXCHANGE && src is non-dir && dst is dir,
24734 + * dst is not locked.
24736 + /* IMustLock(a->dst_inode); */
24737 + au_igrab(a->dst_inode);
24741 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24742 + if (d_is_dir(a->src_dentry)) {
24743 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24744 + if (unlikely(!a->exchange
24745 + && d_really_is_positive(a->dst_dentry)
24746 + && !d_is_dir(a->dst_dentry)))
24748 + lock_flags |= AuLock_DIRS;
24750 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24751 + au_fset_ren(a->auren_flags, ISDIR_DST);
24752 + if (unlikely(!a->exchange
24753 + && d_really_is_positive(a->src_dentry)
24754 + && !d_is_dir(a->src_dentry)))
24756 + lock_flags |= AuLock_DIRS;
24758 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24760 + if (unlikely(err))
24763 + err = au_d_hashed_positive(a->src_dentry);
24764 + if (unlikely(err))
24767 + if (a->dst_inode) {
24769 + * If it is a dir, VFS unhash it before this
24770 + * function. It means we cannot rely upon d_unhashed().
24772 + if (unlikely(!a->dst_inode->i_nlink))
24774 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24775 + err = au_d_hashed_positive(a->dst_dentry);
24776 + if (unlikely(err && !a->exchange))
24778 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24780 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24784 + * is it possible?
24785 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24786 + * there may exist a problem somewhere else.
24789 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24792 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24793 + di_write_lock_parent(a->dst_parent);
24795 + /* which branch we process */
24796 + err = au_ren_wbr(a);
24797 + if (unlikely(err < 0))
24799 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24800 + a->h_path.mnt = au_br_mnt(a->br);
24802 + /* are they available to be renamed */
24803 + err = au_ren_may_dir(a);
24804 + if (unlikely(err))
24805 + goto out_children;
24807 + /* prepare the writable parent dir on the same branch */
24808 + if (a->dst_btop == a->btgt) {
24809 + au_fset_ren(a->auren_flags, WHDST);
24811 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24812 + if (unlikely(err))
24813 + goto out_children;
24817 + if (!a->exchange) {
24818 + if (a->src_dir != a->dst_dir) {
24820 + * this temporary unlock is safe,
24821 + * because both dir->i_mutex are locked.
24823 + di_write_unlock(a->dst_parent);
24824 + di_write_lock_parent(a->src_parent);
24825 + err = au_wr_dir_need_wh(a->src_dentry,
24826 + au_ftest_ren(a->auren_flags,
24829 + di_write_unlock(a->src_parent);
24830 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24832 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24834 + err = au_wr_dir_need_wh(a->src_dentry,
24835 + au_ftest_ren(a->auren_flags,
24839 + if (unlikely(err < 0))
24840 + goto out_children;
24842 + au_fset_ren(a->auren_flags, WHSRC);
24845 + if (a->src_btop != a->btgt) {
24846 + err = au_pin(&pin, a->src_dentry, a->btgt,
24847 + au_opt_udba(a->src_dentry->d_sb),
24848 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24850 + struct au_cp_generic cpg = {
24851 + .dentry = a->src_dentry,
24853 + .bsrc = a->src_btop,
24856 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24858 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24859 + err = au_sio_cpup_simple(&cpg);
24862 + if (unlikely(err))
24863 + goto out_children;
24864 + a->src_btop = a->btgt;
24865 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24866 + if (!a->exchange)
24867 + au_fset_ren(a->auren_flags, WHSRC);
24871 + if (a->exchange && a->dst_inode
24872 + && a->dst_btop != a->btgt) {
24873 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24874 + au_opt_udba(a->dst_dentry->d_sb),
24875 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24877 + struct au_cp_generic cpg = {
24878 + .dentry = a->dst_dentry,
24880 + .bsrc = a->dst_btop,
24883 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24885 + err = au_sio_cpup_simple(&cpg);
24888 + if (unlikely(err))
24889 + goto out_children;
24890 + a->dst_btop = a->btgt;
24891 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24894 + /* lock them all */
24895 + err = au_ren_lock(a);
24896 + if (unlikely(err))
24897 + /* leave the copied-up one */
24898 + goto out_children;
24900 + if (!a->exchange) {
24901 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24902 + err = au_may_ren(a);
24903 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24904 + err = -ENAMETOOLONG;
24905 + if (unlikely(err))
24909 + /* store timestamps to be revertible */
24912 + /* store dirren info */
24913 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24914 + err = au_dr_rename(a->src_dentry, a->btgt,
24915 + &a->dst_dentry->d_name, &rev);
24917 + if (unlikely(err))
24922 + err = do_rename(a);
24923 + if (unlikely(err))
24926 + if (au_ftest_ren(a->auren_flags, DIRREN))
24927 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24929 + /* update dir attributes */
24930 + au_ren_refresh_dir(a);
24932 + /* dput/iput all lower dentries */
24933 + au_ren_refresh(a);
24935 + goto out_hdir; /* success */
24938 + if (au_ftest_ren(a->auren_flags, DIRREN))
24939 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24941 + au_ren_rev_dt(err, a);
24943 + au_ren_unlock(a);
24945 + au_nhash_wh_free(&a->whlist);
24946 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24947 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24948 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24949 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24953 + if (d_unhashed(a->src_dentry))
24954 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24955 + if (d_unhashed(a->dst_dentry))
24956 + au_fset_ren(a->auren_flags, DROPPED_DST);
24957 + if (!a->exchange)
24958 + d_move(a->src_dentry, a->dst_dentry);
24960 + d_exchange(a->src_dentry, a->dst_dentry);
24961 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
24962 + d_drop(a->dst_dentry);
24964 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
24965 + d_drop(a->src_dentry);
24967 + au_update_dbtop(a->dst_dentry);
24968 + if (!a->dst_inode)
24969 + d_drop(a->dst_dentry);
24971 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24972 + di_write_unlock(a->dst_parent);
24974 + di_write_unlock2(a->src_parent, a->dst_parent);
24976 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
24978 + iput(a->dst_inode);
24980 + au_whtmp_rmdir_free(a->thargs);
24986 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
24987 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
24988 +++ linux/fs/aufs/Kconfig 2022-10-26 22:30:38.459315526 +0200
24990 +# SPDX-License-Identifier: GPL-2.0
24992 + tristate "Aufs (Advanced multi layered unification filesystem) support"
24994 + Aufs is a stackable unification filesystem such as Unionfs,
24995 + which unifies several directories and provides a merged single
24997 + In the early days, aufs was entirely re-designed and
24998 + re-implemented Unionfs Version 1.x series. Introducing many
24999 + original ideas, approaches and improvements, it becomes totally
25000 + different from Unionfs while keeping the basic features.
25004 + prompt "Maximum number of branches"
25005 + default AUFS_BRANCH_MAX_127
25007 + Specifies the maximum number of branches (or member directories)
25008 + in a single aufs. The larger value consumes more system
25009 + resources and has a minor impact to performance.
25010 +config AUFS_BRANCH_MAX_127
25013 + Specifies the maximum number of branches (or member directories)
25014 + in a single aufs. The larger value consumes more system
25015 + resources and has a minor impact to performance.
25016 +config AUFS_BRANCH_MAX_511
25019 + Specifies the maximum number of branches (or member directories)
25020 + in a single aufs. The larger value consumes more system
25021 + resources and has a minor impact to performance.
25022 +config AUFS_BRANCH_MAX_1023
25025 + Specifies the maximum number of branches (or member directories)
25026 + in a single aufs. The larger value consumes more system
25027 + resources and has a minor impact to performance.
25028 +config AUFS_BRANCH_MAX_32767
25031 + Specifies the maximum number of branches (or member directories)
25032 + in a single aufs. The larger value consumes more system
25033 + resources and has a minor impact to performance.
25036 +config AUFS_SBILIST
25038 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25041 + Automatic configuration for internal use.
25042 + When aufs supports Magic SysRq or /proc, enabled automatically.
25044 +config AUFS_HNOTIFY
25045 + bool "Detect direct branch access (bypassing aufs)"
25047 + If you want to modify files on branches directly, eg. bypassing aufs,
25048 + and want aufs to detect the changes of them fully, then enable this
25049 + option and use 'udba=notify' mount option.
25050 + Currently there is only one available configuration, "fsnotify".
25051 + It will have a negative impact to the performance.
25052 + See detail in aufs.5.
25055 + prompt "method" if AUFS_HNOTIFY
25056 + default AUFS_HFSNOTIFY
25057 +config AUFS_HFSNOTIFY
25062 +config AUFS_EXPORT
25063 + bool "NFS-exportable aufs"
25064 + depends on EXPORTFS
25066 + If you want to export your mounted aufs via NFS, then enable this
25067 + option. There are several requirements for this configuration.
25068 + See detail in aufs.5.
25070 +config AUFS_INO_T_64
25072 + depends on AUFS_EXPORT
25073 + depends on 64BIT && !(ALPHA || S390)
25076 + Automatic configuration for internal use.
25077 + /* typedef unsigned long/int __kernel_ino_t */
25078 + /* alpha and s390x are int */
25081 + bool "support for XATTR/EA (including Security Labels)"
25083 + If your branch fs supports XATTR/EA and you want to make them
25084 + available in aufs too, then enable this opsion and specify the
25085 + branch attributes for EA.
25086 + See detail in aufs.5.
25089 + bool "File-based Hierarchical Storage Management"
25091 + Hierarchical Storage Management (or HSM) is a well-known feature
25092 + in the storage world. Aufs provides this feature as file-based.
25093 + with multiple branches.
25094 + These multiple branches are prioritized, ie. the topmost one
25095 + should be the fastest drive and be used heavily.
25098 + bool "Readdir in userspace"
25100 + Aufs has two methods to provide a merged view for a directory,
25101 + by a user-space library and by kernel-space natively. The latter
25102 + is always enabled but sometimes large and slow.
25103 + If you enable this option, install the library in aufs2-util
25104 + package, and set some environment variables for your readdir(3),
25105 + then the work will be handled in user-space which generally
25106 + shows better performance in most cases.
25107 + See detail in aufs.5.
25109 +config AUFS_DIRREN
25110 + bool "Workaround for rename(2)-ing a directory"
25112 + By default, aufs returns EXDEV error in renameing a dir who has
25113 + his child on the lower branch, since it is a bad idea to issue
25114 + rename(2) internally for every lower branch. But user may not
25115 + accept this behaviour. So here is a workaround to allow such
25116 + rename(2) and store some extra information on the writable
25117 + branch. Obviously this costs high (and I don't like it).
25118 + To use this feature, you need to enable this configuration AND
25119 + to specify the mount option `dirren.'
25120 + See details in aufs.5 and the design documents.
25123 + bool "Show whiteouts"
25125 + If you want to make the whiteouts in aufs visible, then enable
25126 + this option and specify 'shwh' mount option. Although it may
25127 + sounds like philosophy or something, but in technically it
25128 + simply shows the name of whiteout with keeping its behaviour.
25130 +config AUFS_BR_RAMFS
25131 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25133 + If you want to use ramfs as an aufs branch fs, then enable this
25134 + option. Generally tmpfs is recommended.
25135 + Aufs prohibited them to be a branch fs by default, because
25136 + initramfs becomes unusable after switch_root or something
25137 + generally. If you sets initramfs as an aufs branch and boot your
25138 + system by switch_root, you will meet a problem easily since the
25139 + files in initramfs may be inaccessible.
25140 + Unless you are going to use ramfs as an aufs branch fs without
25141 + switch_root or something, leave it N.
25143 +config AUFS_BR_FUSE
25144 + bool "Fuse fs as an aufs branch"
25145 + depends on FUSE_FS
25148 + If you want to use fuse-based userspace filesystem as an aufs
25149 + branch fs, then enable this option.
25150 + It implements the internal poll(2) operation which is
25151 + implemented by fuse only (curretnly).
25156 + Automatic configuration for internal use.
25158 +config AUFS_BR_HFSPLUS
25159 + bool "Hfsplus as an aufs branch"
25160 + depends on HFSPLUS_FS
25163 + If you want to use hfsplus fs as an aufs branch fs, then enable
25164 + this option. This option introduces a small overhead at
25165 + copying-up a file on hfsplus.
25167 +config AUFS_BDEV_LOOP
25169 + depends on BLK_DEV_LOOP
25172 + Automatic configuration for internal use.
25173 + Convert =[ym] into =y.
25176 + bool "Debug aufs"
25178 + Enable this to compile aufs internal debug code.
25179 + It will have a negative impact to the performance.
25181 +config AUFS_MAGIC_SYSRQ
25183 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25186 + Automatic configuration for internal use.
25187 + When aufs supports Magic SysRq, enabled automatically.
25189 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25190 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25191 +++ linux/fs/aufs/lcnt.h 2022-10-26 22:30:38.469315525 +0200
25193 +/* SPDX-License-Identifier: GPL-2.0 */
25195 + * Copyright (C) 2018-2021 Junjiro R. Okajima
25197 + * This program, aufs is free software; you can redistribute it and/or modify
25198 + * it under the terms of the GNU General Public License as published by
25199 + * the Free Software Foundation; either version 2 of the License, or
25200 + * (at your option) any later version.
25202 + * This program is distributed in the hope that it will be useful,
25203 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25204 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25205 + * GNU General Public License for more details.
25207 + * You should have received a copy of the GNU General Public License
25208 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25212 + * simple long counter wrapper
25215 +#ifndef __AUFS_LCNT_H__
25216 +#define __AUFS_LCNT_H__
25220 +#include "debug.h"
25222 +#define AuLCntATOMIC 1
25223 +#define AuLCntPCPUCNT 2
25225 + * why does percpu_refcount require extra synchronize_rcu()s in
25226 + * au_br_do_free()
25228 +#define AuLCntPCPUREF 3
25230 +/* #define AuLCntChosen AuLCntATOMIC */
25231 +#define AuLCntChosen AuLCntPCPUCNT
25232 +/* #define AuLCntChosen AuLCntPCPUREF */
25234 +#if AuLCntChosen == AuLCntATOMIC
25235 +#include <linux/atomic.h>
25237 +typedef atomic_long_t au_lcnt_t;
25239 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25241 + atomic_long_set(cnt, 0);
25245 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25250 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25251 + int do_sync __maybe_unused)
25256 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25258 + atomic_long_inc(cnt);
25261 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25263 + atomic_long_dec(cnt);
25266 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25268 + return atomic_long_read(cnt);
25272 +#if AuLCntChosen == AuLCntPCPUCNT
25273 +#include <linux/percpu_counter.h>
25275 +typedef struct percpu_counter au_lcnt_t;
25277 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25279 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25282 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25287 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25289 + percpu_counter_destroy(cnt);
25292 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25294 + percpu_counter_inc(cnt);
25297 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25299 + percpu_counter_dec(cnt);
25302 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25306 + n = percpu_counter_sum(cnt);
25308 + if (LONG_MAX != LLONG_MAX
25310 + AuWarn1("%s\n", "wrap-around");
25316 +#if AuLCntChosen == AuLCntPCPUREF
25317 +#include <linux/percpu-refcount.h>
25319 +typedef struct percpu_ref au_lcnt_t;
25321 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25324 + release = percpu_ref_exit;
25325 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25328 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25330 + synchronize_rcu();
25333 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25335 + percpu_ref_kill(cnt);
25337 + au_lcnt_wait_for_fin(cnt);
25340 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25342 + percpu_ref_get(cnt);
25345 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25347 + percpu_ref_put(cnt);
25351 + * avoid calling this func as possible.
25353 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25357 + percpu_ref_switch_to_atomic_sync(cnt);
25358 + l = atomic_long_read(&cnt->count);
25360 + percpu_ref_switch_to_percpu(cnt);
25362 + /* percpu_ref is initialized by 1 instead of 0 */
25367 +#ifdef CONFIG_AUFS_DEBUG
25368 +#define AuLCntZero(val) do { \
25371 + AuDbg("%s = %ld\n", #val, l); \
25374 +#define AuLCntZero(val) do {} while (0)
25377 +#endif /* __KERNEL__ */
25378 +#endif /* __AUFS_LCNT_H__ */
25379 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25380 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25381 +++ linux/fs/aufs/loop.c 2022-10-26 22:30:38.469315525 +0200
25383 +// SPDX-License-Identifier: GPL-2.0
25385 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25387 + * This program, aufs is free software; you can redistribute it and/or modify
25388 + * it under the terms of the GNU General Public License as published by
25389 + * the Free Software Foundation; either version 2 of the License, or
25390 + * (at your option) any later version.
25392 + * This program is distributed in the hope that it will be useful,
25393 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25394 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25395 + * GNU General Public License for more details.
25397 + * You should have received a copy of the GNU General Public License
25398 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25402 + * support for loopback block device as a branch
25407 +/* added into drivers/block/loop.c */
25408 +static struct file *(*backing_file_func)(struct super_block *sb);
25411 + * test if two lower dentries have overlapping branches.
25413 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25415 + struct super_block *h_sb;
25416 + struct file *backing_file;
25418 + if (unlikely(!backing_file_func)) {
25419 + /* don't load "loop" module here */
25420 + backing_file_func = symbol_get(loop_backing_file);
25421 + if (unlikely(!backing_file_func))
25422 + /* "loop" module is not loaded */
25426 + h_sb = h_adding->d_sb;
25427 + backing_file = backing_file_func(h_sb);
25428 + if (!backing_file)
25431 + h_adding = backing_file->f_path.dentry;
25433 + * h_adding can be local NFS.
25434 + * in this case aufs cannot detect the loop.
25436 + if (unlikely(h_adding->d_sb == sb))
25438 + return !!au_test_subdir(h_adding, sb->s_root);
25441 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25442 +int au_test_loopback_kthread(void)
25445 + struct task_struct *tsk = current;
25446 + char c, comm[sizeof(tsk->comm)];
25449 + if (tsk->flags & PF_KTHREAD) {
25450 + get_task_comm(comm, tsk);
25452 + ret = ('0' <= c && c <= '9'
25453 + && !strncmp(comm, "loop", 4));
25459 +/* ---------------------------------------------------------------------- */
25461 +#define au_warn_loopback_step 16
25462 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25463 +static unsigned long *au_warn_loopback_array;
25465 +void au_warn_loopback(struct super_block *h_sb)
25467 + int i, new_nelem;
25468 + unsigned long *a, magic;
25469 + static DEFINE_SPINLOCK(spin);
25471 + magic = h_sb->s_magic;
25472 + spin_lock(&spin);
25473 + a = au_warn_loopback_array;
25474 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25475 + if (a[i] == magic) {
25476 + spin_unlock(&spin);
25480 + /* h_sb is new to us, print it */
25481 + if (i < au_warn_loopback_nelem) {
25486 + /* expand the array */
25487 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25488 + a = au_kzrealloc(au_warn_loopback_array,
25489 + au_warn_loopback_nelem * sizeof(unsigned long),
25490 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25491 + /*may_shrink*/0);
25493 + au_warn_loopback_nelem = new_nelem;
25494 + au_warn_loopback_array = a;
25499 + spin_unlock(&spin);
25500 + AuWarn1("realloc failed, ignored\n");
25504 + spin_unlock(&spin);
25505 + pr_warn("you may want to try another patch for loopback file "
25506 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25509 +int au_loopback_init(void)
25512 + struct super_block *sb __maybe_unused;
25514 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25517 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25518 + sizeof(unsigned long), GFP_NOFS);
25519 + if (unlikely(!au_warn_loopback_array))
25525 +void au_loopback_fin(void)
25527 + if (backing_file_func)
25528 + symbol_put(loop_backing_file);
25529 + au_kfree_try_rcu(au_warn_loopback_array);
25531 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25532 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25533 +++ linux/fs/aufs/loop.h 2022-10-26 22:30:38.469315525 +0200
25535 +/* SPDX-License-Identifier: GPL-2.0 */
25537 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25539 + * This program, aufs is free software; you can redistribute it and/or modify
25540 + * it under the terms of the GNU General Public License as published by
25541 + * the Free Software Foundation; either version 2 of the License, or
25542 + * (at your option) any later version.
25544 + * This program is distributed in the hope that it will be useful,
25545 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25546 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25547 + * GNU General Public License for more details.
25549 + * You should have received a copy of the GNU General Public License
25550 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25554 + * support for loopback mount as a branch
25557 +#ifndef __AUFS_LOOP_H__
25558 +#define __AUFS_LOOP_H__
25563 +struct super_block;
25565 +#ifdef CONFIG_AUFS_BDEV_LOOP
25566 +/* drivers/block/loop.c */
25567 +struct file *loop_backing_file(struct super_block *sb);
25570 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25571 +int au_test_loopback_kthread(void);
25572 +void au_warn_loopback(struct super_block *h_sb);
25574 +int au_loopback_init(void);
25575 +void au_loopback_fin(void);
25577 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25579 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25580 + struct dentry *h_adding)
25581 +AuStubInt0(au_test_loopback_kthread, void)
25582 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25584 +AuStubInt0(au_loopback_init, void)
25585 +AuStubVoid(au_loopback_fin, void)
25586 +#endif /* BLK_DEV_LOOP */
25588 +#endif /* __KERNEL__ */
25589 +#endif /* __AUFS_LOOP_H__ */
25590 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25591 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25592 +++ linux/fs/aufs/magic.mk 2022-10-26 22:30:38.469315525 +0200
25594 +# SPDX-License-Identifier: GPL-2.0
25596 +# defined in ${srctree}/fs/fuse/inode.c
25598 +ifdef CONFIG_FUSE_FS
25599 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25602 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25604 +ifdef CONFIG_XFS_FS
25605 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25608 +# defined in ${srctree}/fs/configfs/mount.c
25610 +ifdef CONFIG_CONFIGFS_FS
25611 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25614 +# defined in ${srctree}/fs/ubifs/ubifs.h
25616 +ifdef CONFIG_UBIFS_FS
25617 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25620 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25622 +ifdef CONFIG_HFSPLUS_FS
25623 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25625 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25626 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25627 +++ linux/fs/aufs/Makefile 2022-10-26 22:30:38.459315526 +0200
25629 +# SPDX-License-Identifier: GPL-2.0
25631 +include ${src}/magic.mk
25632 +ifeq (${CONFIG_AUFS_FS},m)
25633 +include ${src}/conf.mk
25635 +-include ${src}/priv_def.mk
25637 +# cf. include/linux/kernel.h
25639 +ccflags-y += -DDEBUG
25640 +# sparse requires the full pathname
25642 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25644 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25647 +obj-$(CONFIG_AUFS_FS) += aufs.o
25648 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25649 + wkq.o vfsub.o dcsub.o \
25650 + cpup.o whout.o wbr_policy.o \
25651 + dinfo.o dentry.o \
25653 + finfo.o file.o f_op.o \
25655 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25659 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25660 +aufs-$(CONFIG_SYSFS) += sysfs.o
25661 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25662 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25663 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25664 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25665 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25666 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25667 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25668 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25669 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25670 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25671 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25672 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25673 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25674 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25675 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25676 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25677 +++ linux/fs/aufs/module.c 2022-10-26 22:30:38.469315525 +0200
25679 +// SPDX-License-Identifier: GPL-2.0
25681 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25683 + * This program, aufs is free software; you can redistribute it and/or modify
25684 + * it under the terms of the GNU General Public License as published by
25685 + * the Free Software Foundation; either version 2 of the License, or
25686 + * (at your option) any later version.
25688 + * This program is distributed in the hope that it will be useful,
25689 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25690 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25691 + * GNU General Public License for more details.
25693 + * You should have received a copy of the GNU General Public License
25694 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25698 + * module global variables and operations
25701 +#include <linux/module.h>
25702 +#include <linux/seq_file.h>
25705 +/* shrinkable realloc */
25706 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25714 +#if 0 /* unused */
25721 + AuDebugOn(!new_sz);
25724 + diff = au_kmidx_sub(sz, new_sz);
25730 + /* expand or SLOB */
25731 + p = krealloc(p, new_sz, gfp);
25732 + else if (new_sz < sz && may_shrink) {
25736 + q = kmalloc(new_sz, gfp);
25739 + memcpy(q, p, new_sz);
25740 + au_kfree_try_rcu(p);
25751 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25754 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25755 + if (p && new_sz > nused)
25756 + memset(p + nused, 0, new_sz - nused);
25760 +/* ---------------------------------------------------------------------- */
25764 +struct kmem_cache *au_cache[AuCache_Last];
25766 +static void au_cache_fin(void)
25771 + * Make sure all delayed rcu free inodes are flushed before we
25776 + /* excluding AuCache_HNOTIFY */
25777 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25778 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25779 + kmem_cache_destroy(au_cache[i]);
25780 + au_cache[i] = NULL;
25784 +static int __init au_cache_init(void)
25786 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25787 + if (au_cache[AuCache_DINFO])
25788 + /* SLAB_DESTROY_BY_RCU */
25789 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25790 + au_icntnr_init_once);
25791 + if (au_cache[AuCache_ICNTNR])
25792 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25793 + au_fi_init_once);
25794 + if (au_cache[AuCache_FINFO])
25795 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25796 + if (au_cache[AuCache_VDIR])
25797 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25798 + if (au_cache[AuCache_DEHSTR])
25805 +/* ---------------------------------------------------------------------- */
25807 +int au_dir_roflags;
25809 +#ifdef CONFIG_AUFS_SBILIST
25811 + * iterate_supers_type() doesn't protect us from
25812 + * remounting (branch management)
25814 +struct hlist_bl_head au_sbilist;
25818 + * functions for module interface.
25820 +MODULE_LICENSE("GPL");
25821 +/* MODULE_LICENSE("GPL v2"); */
25822 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25823 +MODULE_DESCRIPTION(AUFS_NAME
25824 + " -- Advanced multi layered unification filesystem");
25825 +MODULE_VERSION(AUFS_VERSION);
25826 +MODULE_ALIAS_FS(AUFS_NAME);
25828 +/* this module parameter has no meaning when SYSFS is disabled */
25829 +int sysaufs_brs = 1;
25830 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25831 +module_param_named(brs, sysaufs_brs, int, 0444);
25833 +/* this module parameter has no meaning when USER_NS is disabled */
25835 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25836 +module_param_named(allow_userns, au_userns, bool, 0444);
25838 +/* ---------------------------------------------------------------------- */
25840 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25842 +int au_seq_path(struct seq_file *seq, struct path *path)
25846 + err = seq_path(seq, path, au_esc_chars);
25855 +/* ---------------------------------------------------------------------- */
25857 +static int __init aufs_init(void)
25862 + p = au_esc_chars;
25863 + for (i = 1; i <= ' '; i++)
25869 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25871 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25872 + for (i = 0; i < AuIop_Last; i++)
25873 + aufs_iop_nogetattr[i].getattr = NULL;
25875 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25877 + au_sbilist_init();
25878 + sysaufs_brs_init();
25881 + err = sysaufs_init();
25882 + if (unlikely(err))
25884 + err = dbgaufs_init();
25885 + if (unlikely(err))
25886 + goto out_sysaufs;
25887 + err = au_procfs_init();
25888 + if (unlikely(err))
25889 + goto out_dbgaufs;
25890 + err = au_wkq_init();
25891 + if (unlikely(err))
25893 + err = au_loopback_init();
25894 + if (unlikely(err))
25896 + err = au_hnotify_init();
25897 + if (unlikely(err))
25898 + goto out_loopback;
25899 + err = au_sysrq_init();
25900 + if (unlikely(err))
25902 + err = au_cache_init();
25903 + if (unlikely(err))
25906 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25907 + err = register_filesystem(&aufs_fs_type);
25908 + if (unlikely(err))
25911 + /* since we define pr_fmt, call printk directly */
25912 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25913 + goto out; /* success */
25920 + au_hnotify_fin();
25922 + au_loopback_fin();
25936 +static void __exit aufs_exit(void)
25938 + unregister_filesystem(&aufs_fs_type);
25941 + au_hnotify_fin();
25942 + au_loopback_fin();
25950 +module_init(aufs_init);
25951 +module_exit(aufs_exit);
25952 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25953 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25954 +++ linux/fs/aufs/module.h 2022-10-26 22:30:38.469315525 +0200
25956 +/* SPDX-License-Identifier: GPL-2.0 */
25958 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25960 + * This program, aufs is free software; you can redistribute it and/or modify
25961 + * it under the terms of the GNU General Public License as published by
25962 + * the Free Software Foundation; either version 2 of the License, or
25963 + * (at your option) any later version.
25965 + * This program is distributed in the hope that it will be useful,
25966 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25967 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25968 + * GNU General Public License for more details.
25970 + * You should have received a copy of the GNU General Public License
25971 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25975 + * module initialization and module-global
25978 +#ifndef __AUFS_MODULE_H__
25979 +#define __AUFS_MODULE_H__
25983 +#include <linux/slab.h>
25984 +#include "debug.h"
25985 +#include "dentry.h"
25988 +#include "inode.h"
25993 +/* module parameters */
25994 +extern int sysaufs_brs;
25995 +extern bool au_userns;
25997 +/* ---------------------------------------------------------------------- */
25999 +extern int au_dir_roflags;
26001 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26002 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26006 + * Comparing the size of the object with sizeof(struct rcu_head)
26007 + * case 1: object is always larger
26008 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26009 + * case 2: object is always smaller
26010 + * --> au_kfree_small()
26011 + * case 3: object can be any size
26012 + * --> au_kfree_try_rcu()
26015 +static inline void au_kfree_do_rcu(const void *p)
26018 + struct rcu_head rcu;
26019 + } *a = (void *)p;
26021 + kfree_rcu(a, rcu);
26024 +#define au_kfree_rcu(_p) do { \
26025 + typeof(_p) p = (_p); \
26026 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26028 + au_kfree_do_rcu(p); \
26031 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26032 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26034 +static inline void au_kfree_try_rcu(const void *p)
26038 + if (au_kfree_sz_test(p))
26039 + au_kfree_do_rcu(p);
26044 +static inline void au_kfree_small(const void *p)
26048 + AuDebugOn(au_kfree_sz_test(p));
26052 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26054 +#ifndef CONFIG_SLOB
26055 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26057 + return -1; /* SLOB is untested */
26061 +int au_seq_path(struct seq_file *seq, struct path *path);
26063 +#ifdef CONFIG_PROC_FS
26065 +int __init au_procfs_init(void);
26066 +void au_procfs_fin(void);
26068 +AuStubInt0(au_procfs_init, void);
26069 +AuStubVoid(au_procfs_fin, void);
26072 +/* ---------------------------------------------------------------------- */
26081 + AuCache_HNOTIFY, /* must be last */
26085 +extern struct kmem_cache *au_cache[AuCache_Last];
26087 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26088 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26089 +#define AuCacheCtor(type, ctor) \
26090 + kmem_cache_create(#type, sizeof(struct type), \
26091 + __alignof__(struct type), AuCacheFlags, ctor)
26093 +#define AuCacheFuncs(name, index) \
26094 + static inline struct au_##name *au_cache_alloc_##name(void) \
26095 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
26096 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26097 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26099 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26100 + { void *p = rcu; \
26101 + p -= offsetof(struct au_##name, rcu); \
26102 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26103 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26104 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26105 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26107 + static inline void au_cache_free_##name(struct au_##name *p) \
26108 + { /* au_cache_free_##name##_norcu(p); */ \
26109 + au_cache_free_##name##_rcu(p); }
26111 +AuCacheFuncs(dinfo, DINFO);
26112 +AuCacheFuncs(icntnr, ICNTNR);
26113 +AuCacheFuncs(finfo, FINFO);
26114 +AuCacheFuncs(vdir, VDIR);
26115 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26116 +#ifdef CONFIG_AUFS_HNOTIFY
26117 +AuCacheFuncs(hnotify, HNOTIFY);
26120 +#endif /* __KERNEL__ */
26121 +#endif /* __AUFS_MODULE_H__ */
26122 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26123 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26124 +++ linux/fs/aufs/mvdown.c 2022-10-26 22:30:38.469315525 +0200
26126 +// SPDX-License-Identifier: GPL-2.0
26128 + * Copyright (C) 2011-2021 Junjiro R. Okajima
26130 + * This program, aufs is free software; you can redistribute it and/or modify
26131 + * it under the terms of the GNU General Public License as published by
26132 + * the Free Software Foundation; either version 2 of the License, or
26133 + * (at your option) any later version.
26135 + * This program is distributed in the hope that it will be useful,
26136 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26137 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26138 + * GNU General Public License for more details.
26140 + * You should have received a copy of the GNU General Public License
26141 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26145 + * move-down, opposite of copy-up
26150 +struct au_mvd_args {
26152 + struct super_block *h_sb;
26153 + struct dentry *h_parent;
26154 + struct au_hinode *hdir;
26155 + struct inode *h_dir, *h_inode;
26156 + struct au_pin pin;
26157 + } info[AUFS_MVDOWN_NARRAY];
26159 + struct aufs_mvdown mvdown;
26160 + struct dentry *dentry, *parent;
26161 + struct inode *inode, *dir;
26162 + struct super_block *sb;
26163 + aufs_bindex_t bopq, bwh, bfound;
26164 + unsigned char rename_lock;
26167 +#define mvd_errno mvdown.au_errno
26168 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26169 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26170 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26171 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26173 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26174 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26175 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26176 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26177 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26178 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26180 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26181 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26182 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26183 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26184 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26185 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26187 +#define AU_MVD_PR(flag, ...) do { \
26189 + pr_err(__VA_ARGS__); \
26192 +static int find_lower_writable(struct au_mvd_args *a)
26194 + struct super_block *sb;
26195 + aufs_bindex_t bindex, bbot;
26196 + struct au_branch *br;
26199 + bindex = a->mvd_bsrc;
26200 + bbot = au_sbbot(sb);
26201 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26202 + for (bindex++; bindex <= bbot; bindex++) {
26203 + br = au_sbr(sb, bindex);
26204 + if (au_br_fhsm(br->br_perm)
26205 + && !sb_rdonly(au_br_sb(br)))
26208 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26209 + for (bindex++; bindex <= bbot; bindex++) {
26210 + br = au_sbr(sb, bindex);
26211 + if (!au_br_rdonly(br))
26215 + for (bindex++; bindex <= bbot; bindex++) {
26216 + br = au_sbr(sb, bindex);
26217 + if (!sb_rdonly(au_br_sb(br))) {
26218 + if (au_br_rdonly(br))
26220 + |= AUFS_MVDOWN_ROLOWER_R;
26228 +/* make the parent dir on bdst */
26229 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26234 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26235 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26236 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26237 + a->mvd_h_dst_parent = NULL;
26238 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26239 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26240 + if (!a->mvd_h_dst_parent) {
26241 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26242 + if (unlikely(err)) {
26243 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26246 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26254 +/* lock them all */
26255 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26258 + struct dentry *h_trap;
26260 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26261 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26262 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26263 + au_opt_udba(a->sb),
26264 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26266 + if (unlikely(err)) {
26267 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26271 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26272 + a->rename_lock = 0;
26273 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26274 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26275 + au_opt_udba(a->sb),
26276 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26277 + err = au_do_pin(&a->mvd_pin_src);
26279 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26280 + if (unlikely(err)) {
26281 + AU_MVD_PR(dmsg, "pin_src failed\n");
26284 + goto out; /* success */
26287 + a->rename_lock = 1;
26288 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26289 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26290 + au_opt_udba(a->sb),
26291 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26293 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26294 + if (unlikely(err)) {
26295 + AU_MVD_PR(dmsg, "pin_src failed\n");
26296 + au_pin_hdir_lock(&a->mvd_pin_dst);
26299 + au_pin_hdir_unlock(&a->mvd_pin_src);
26300 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26301 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26303 + err = (h_trap != a->mvd_h_src_parent);
26305 + err = (h_trap != a->mvd_h_dst_parent);
26307 + BUG_ON(err); /* it should never happen */
26308 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26311 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26312 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26313 + au_pin_hdir_lock(&a->mvd_pin_src);
26314 + au_unpin(&a->mvd_pin_src);
26315 + au_pin_hdir_lock(&a->mvd_pin_dst);
26318 + goto out; /* success */
26321 + au_unpin(&a->mvd_pin_dst);
26327 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26329 + if (!a->rename_lock)
26330 + au_unpin(&a->mvd_pin_src);
26332 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26333 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26334 + au_pin_hdir_lock(&a->mvd_pin_src);
26335 + au_unpin(&a->mvd_pin_src);
26336 + au_pin_hdir_lock(&a->mvd_pin_dst);
26338 + au_unpin(&a->mvd_pin_dst);
26341 +/* copy-down the file */
26342 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26345 + struct au_cp_generic cpg = {
26346 + .dentry = a->dentry,
26347 + .bdst = a->mvd_bdst,
26348 + .bsrc = a->mvd_bsrc,
26350 + .pin = &a->mvd_pin_dst,
26351 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26354 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26355 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26356 + au_fset_cpup(cpg.flags, OVERWRITE);
26357 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26358 + au_fset_cpup(cpg.flags, RWDST);
26359 + err = au_sio_cpdown_simple(&cpg);
26360 + if (unlikely(err))
26361 + AU_MVD_PR(dmsg, "cpdown failed\n");
26368 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26371 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26374 + struct path h_path;
26375 + struct au_branch *br;
26376 + struct inode *delegated;
26378 + br = au_sbr(a->sb, a->mvd_bdst);
26379 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26380 + err = PTR_ERR(h_path.dentry);
26381 + if (IS_ERR(h_path.dentry)) {
26382 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26387 + if (d_is_positive(h_path.dentry)) {
26388 + h_path.mnt = au_br_mnt(br);
26389 + delegated = NULL;
26390 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26391 + &delegated, /*force*/0);
26392 + if (unlikely(err == -EWOULDBLOCK)) {
26393 + pr_warn("cannot retry for NFSv4 delegation"
26394 + " for an internal unlink\n");
26397 + if (unlikely(err))
26398 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26400 + dput(h_path.dentry);
26408 + * unlink the topmost h_dentry
26410 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26413 + struct path h_path;
26414 + struct inode *delegated;
26416 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26417 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26418 + delegated = NULL;
26419 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26420 + if (unlikely(err == -EWOULDBLOCK)) {
26421 + pr_warn("cannot retry for NFSv4 delegation"
26422 + " for an internal unlink\n");
26425 + if (unlikely(err))
26426 + AU_MVD_PR(dmsg, "unlink failed\n");
26432 +/* Since mvdown succeeded, we ignore an error of this function */
26433 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26436 + struct au_branch *br;
26438 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26439 + br = au_sbr(a->sb, a->mvd_bsrc);
26440 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26442 + br = au_sbr(a->sb, a->mvd_bdst);
26443 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26444 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26447 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26449 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26453 + * copy-down the file and unlink the bsrc file.
26454 + * - unlink the bdst whout if exist
26455 + * - copy-down the file (with whtmp name and rename)
26456 + * - unlink the bsrc file
26458 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26462 + err = au_do_mkdir(dmsg, a);
26464 + err = au_do_lock(dmsg, a);
26465 + if (unlikely(err))
26469 + * do not revert the activities we made on bdst since they should be
26470 + * harmless in aufs.
26473 + err = au_do_cpdown(dmsg, a);
26475 + err = au_do_unlink_wh(dmsg, a);
26476 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26477 + err = au_do_unlink(dmsg, a);
26478 + if (unlikely(err))
26481 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26482 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26483 + if (find_lower_writable(a) < 0)
26484 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26486 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26487 + au_do_stfs(dmsg, a);
26489 + /* maintain internal array */
26490 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26491 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26492 + au_set_dbtop(a->dentry, a->mvd_bdst);
26493 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26494 + au_set_ibtop(a->inode, a->mvd_bdst);
26496 + /* hide the lower */
26497 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26498 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26499 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26500 + au_set_ibbot(a->inode, a->mvd_bsrc);
26502 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26503 + au_set_dbbot(a->dentry, a->mvd_bdst);
26504 + if (au_ibbot(a->inode) < a->mvd_bdst)
26505 + au_set_ibbot(a->inode, a->mvd_bdst);
26508 + au_do_unlock(dmsg, a);
26514 +/* ---------------------------------------------------------------------- */
26516 +/* make sure the file is idle */
26517 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26519 + int err, plinked;
26522 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26523 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26524 + && au_dcount(a->dentry) == 1
26525 + && atomic_read(&a->inode->i_count) == 1
26526 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26527 + && (!plinked || !au_plink_test(a->inode))
26528 + && a->inode->i_nlink == 1)
26533 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26534 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26535 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26536 + a->mvd_h_src_inode->i_nlink,
26537 + plinked, plinked ? au_plink_test(a->inode) : 0);
26544 +/* make sure the parent dir is fine */
26545 +static int au_mvd_args_parent(const unsigned char dmsg,
26546 + struct au_mvd_args *a)
26549 + aufs_bindex_t bindex;
26552 + if (unlikely(au_alive_dir(a->parent))) {
26554 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26558 + a->bopq = au_dbdiropq(a->parent);
26559 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26560 + AuDbg("b%d\n", bindex);
26561 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26562 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26564 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26565 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26566 + a->bopq, a->mvd_bdst);
26574 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26575 + struct au_mvd_args *a)
26578 + struct au_dinfo *dinfo, *tmp;
26580 + /* lookup the next lower positive entry */
26582 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26583 + if (unlikely(!tmp))
26588 + dinfo = au_di(a->dentry);
26589 + au_di_cp(tmp, dinfo);
26590 + au_di_swap(tmp, dinfo);
26592 + /* returns the number of positive dentries */
26593 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26594 + /* AuLkup_IGNORE_PERM */ 0);
26596 + a->bwh = au_dbwh(a->dentry);
26597 + else if (err > 0)
26598 + a->bfound = au_dbtop(a->dentry);
26600 + au_di_swap(tmp, dinfo);
26601 + au_rw_write_unlock(&tmp->di_rwsem);
26603 + if (unlikely(err < 0))
26604 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26607 + * here, we have these cases.
26609 + * no positive dentry under bsrc. there are more sub-cases.
26611 + * there no whiteout, we can safely move-down.
26614 + * bsrc < bwh && bwh < bdst
26615 + * there is a whiteout on RO branch. cannot proceed.
26617 + * there is a whiteout on the RW target branch. it should
26620 + * there is a whiteout somewhere unrelated branch.
26621 + * -1 < bfound && bfound <= bsrc
26624 + * found, but it is on RO branch between bsrc and bdst. cannot
26627 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26630 + * found, after we create the file on bdst, it will be hidden.
26633 + AuDebugOn(a->bfound == -1
26635 + && a->bwh <= a->mvd_bsrc);
26636 + AuDebugOn(-1 < a->bfound
26637 + && a->bfound <= a->mvd_bsrc);
26640 + if (a->bfound == -1
26641 + && a->mvd_bsrc < a->bwh
26643 + && a->bwh < a->mvd_bdst) {
26644 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26645 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26646 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26648 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26649 + a->mvd_errno = EAU_MVDOWN_UPPER;
26650 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26651 + a->mvd_bdst, a->bfound);
26655 + err = 0; /* success */
26662 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26667 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26668 + && a->bfound == a->mvd_bdst)
26674 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26677 + struct au_branch *br;
26680 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26684 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26685 + a->mvd_bsrc = au_ibtop(a->inode);
26687 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26688 + if (unlikely(a->mvd_bsrc < 0
26689 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26690 + || au_dbbot(a->dentry) < a->mvd_bsrc
26691 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26692 + || (a->mvd_bsrc < au_ibtop(a->inode)
26693 + || au_ibbot(a->inode) < a->mvd_bsrc
26694 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26695 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26696 + AU_MVD_PR(dmsg, "no upper\n");
26700 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26701 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26702 + AU_MVD_PR(dmsg, "on the bottom\n");
26705 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26706 + br = au_sbr(a->sb, a->mvd_bsrc);
26707 + err = au_br_rdonly(br);
26708 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26709 + if (unlikely(err))
26711 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26712 + || IS_APPEND(a->mvd_h_src_inode))) {
26714 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26720 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26721 + a->mvd_bdst = find_lower_writable(a);
26722 + if (unlikely(a->mvd_bdst < 0)) {
26723 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26724 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26728 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26729 + if (unlikely(a->mvd_bdst < 0
26730 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26731 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26732 + AU_MVD_PR(dmsg, "no lower brid\n");
26737 + err = au_mvd_args_busy(dmsg, a);
26739 + err = au_mvd_args_parent(dmsg, a);
26741 + err = au_mvd_args_intermediate(dmsg, a);
26743 + err = au_mvd_args_exist(dmsg, a);
26745 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26752 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26755 + unsigned char dmsg;
26756 + struct au_mvd_args *args;
26757 + struct inode *inode;
26759 + inode = d_inode(dentry);
26761 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26765 + args = kmalloc(sizeof(*args), GFP_NOFS);
26766 + if (unlikely(!args))
26769 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26771 + /* VERIFY_WRITE */
26772 + err = !access_ok(uarg, sizeof(*uarg));
26773 + if (unlikely(err)) {
26778 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26779 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26780 + args->mvdown.au_errno = 0;
26781 + args->dentry = dentry;
26782 + args->inode = inode;
26783 + args->sb = dentry->d_sb;
26786 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26787 + args->parent = dget_parent(dentry);
26788 + args->dir = d_inode(args->parent);
26789 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26790 + dput(args->parent);
26791 + if (unlikely(args->parent != dentry->d_parent)) {
26792 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26796 + inode_lock_nested(inode, I_MUTEX_CHILD);
26797 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26798 + if (unlikely(err))
26801 + di_write_lock_parent(args->parent);
26802 + err = au_mvd_args(dmsg, args);
26803 + if (unlikely(err))
26806 + err = au_do_mvdown(dmsg, args);
26807 + if (unlikely(err))
26810 + au_cpup_attr_timesizes(args->dir);
26811 + au_cpup_attr_timesizes(inode);
26812 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26813 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26814 + /* au_digen_dec(dentry); */
26817 + di_write_unlock(args->parent);
26818 + aufs_read_unlock(dentry, AuLock_DW);
26820 + inode_unlock(inode);
26822 + inode_unlock(args->dir);
26824 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26827 + au_kfree_rcu(args);
26832 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26833 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26834 +++ linux/fs/aufs/opts.c 2022-10-26 22:30:38.469315525 +0200
26836 +// SPDX-License-Identifier: GPL-2.0
26838 + * Copyright (C) 2005-2021 Junjiro R. Okajima
26840 + * This program, aufs is free software; you can redistribute it and/or modify
26841 + * it under the terms of the GNU General Public License as published by
26842 + * the Free Software Foundation; either version 2 of the License, or
26843 + * (at your option) any later version.
26845 + * This program is distributed in the hope that it will be useful,
26846 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26847 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26848 + * GNU General Public License for more details.
26850 + * You should have received a copy of the GNU General Public License
26851 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26855 + * mount options/flags
26858 +#include <linux/types.h> /* a distribution requires */
26859 +#include <linux/parser.h>
26862 +/* ---------------------------------------------------------------------- */
26864 +static const char *au_parser_pattern(int val, match_table_t tbl)
26866 + struct match_token *p;
26869 + while (p->pattern) {
26870 + if (p->token == val)
26871 + return p->pattern;
26878 +static const char *au_optstr(int *val, match_table_t tbl)
26880 + struct match_token *p;
26887 + while (p->pattern) {
26889 + && (v & p->token) == p->token) {
26890 + *val &= ~p->token;
26891 + return p->pattern;
26900 +/* ---------------------------------------------------------------------- */
26902 +static match_table_t brperm = {
26903 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26904 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26905 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26909 +static match_table_t brattr = {
26911 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26912 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26913 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26914 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26915 +#ifdef CONFIG_AUFS_FHSM
26916 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26918 +#ifdef CONFIG_AUFS_XATTR
26919 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26920 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26921 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26922 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26923 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26924 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26927 + /* ro/rr branch */
26928 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26931 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26932 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26937 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26944 + p = strchr(str, '+');
26947 + v = match_token(str, table, args);
26949 + if (v & AuBrAttr_CMOO_Mask)
26950 + attr &= ~AuBrAttr_CMOO_Mask;
26955 + pr_warn("ignored branch attribute %s\n", str);
26965 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
26973 + p = au_optstr(&perm, brattr);
26976 + memcpy(q, p, sz + 1);
26982 + p = au_optstr(&perm, brattr);
26986 + memcpy(q, p, sz + 1);
26992 + return q - str->a;
26995 +int au_br_perm_val(char *perm)
26997 + int val, bad, sz;
26999 + substring_t args[MAX_OPT_ARGS];
27000 + au_br_perm_str_t attr;
27002 + p = strchr(perm, '+');
27005 + val = match_token(perm, brperm, args);
27009 + pr_warn("ignored branch permission %s\n", perm);
27010 + val = AuBrPerm_RO;
27016 + val |= br_attr_val(p + 1, brattr, args);
27019 + switch (val & AuBrPerm_Mask) {
27020 + case AuBrPerm_RO:
27021 + case AuBrPerm_RR:
27022 + bad = val & AuBrWAttr_Mask;
27023 + val &= ~AuBrWAttr_Mask;
27025 + case AuBrPerm_RW:
27026 + bad = val & AuBrRAttr_Mask;
27027 + val &= ~AuBrRAttr_Mask;
27032 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27033 + * does not treat it as an error, just warning.
27034 + * this is a tiny guard for the user operation.
27036 + if (val & AuBrAttr_UNPIN) {
27037 + bad |= AuBrAttr_UNPIN;
27038 + val &= ~AuBrAttr_UNPIN;
27041 + if (unlikely(bad)) {
27042 + sz = au_do_optstr_br_attr(&attr, bad);
27044 + pr_warn("ignored branch attribute %s\n", attr.a);
27051 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27053 + au_br_perm_str_t attr;
27059 + p = au_optstr(&perm, brperm);
27060 + AuDebugOn(!p || !*p);
27062 + memcpy(q, p, sz + 1);
27065 + sz = au_do_optstr_br_attr(&attr, perm);
27068 + memcpy(q, attr.a, sz + 1);
27071 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27074 +/* ---------------------------------------------------------------------- */
27076 +static match_table_t udbalevel = {
27077 + {AuOpt_UDBA_REVAL, "reval"},
27078 + {AuOpt_UDBA_NONE, "none"},
27079 +#ifdef CONFIG_AUFS_HNOTIFY
27080 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27081 +#ifdef CONFIG_AUFS_HFSNOTIFY
27082 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27088 +int au_udba_val(char *str)
27090 + substring_t args[MAX_OPT_ARGS];
27092 + return match_token(str, udbalevel, args);
27095 +const char *au_optstr_udba(int udba)
27097 + return au_parser_pattern(udba, udbalevel);
27100 +/* ---------------------------------------------------------------------- */
27102 +static match_table_t au_wbr_create_policy = {
27103 + {AuWbrCreate_TDP, "tdp"},
27104 + {AuWbrCreate_TDP, "top-down-parent"},
27105 + {AuWbrCreate_RR, "rr"},
27106 + {AuWbrCreate_RR, "round-robin"},
27107 + {AuWbrCreate_MFS, "mfs"},
27108 + {AuWbrCreate_MFS, "most-free-space"},
27109 + {AuWbrCreate_MFSV, "mfs:%d"},
27110 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27112 + /* top-down regardless the parent, and then mfs */
27113 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27114 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27116 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27117 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27118 + {AuWbrCreate_PMFS, "pmfs"},
27119 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27120 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27121 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27126 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27127 + struct au_opt_wbr_create *create)
27130 + unsigned long long ull;
27133 + if (!match_u64(arg, &ull))
27134 + create->mfsrr_watermark = ull;
27136 + pr_err("bad integer in %s\n", str);
27143 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27144 + struct au_opt_wbr_create *create)
27149 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27150 + create->mfs_second = n;
27152 + pr_err("bad integer in %s\n", str);
27159 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27162 + substring_t args[MAX_OPT_ARGS];
27164 + err = match_token(str, au_wbr_create_policy, args);
27165 + create->wbr_create = err;
27167 + case AuWbrCreate_MFSRRV:
27168 + case AuWbrCreate_TDMFSV:
27169 + case AuWbrCreate_PMFSRRV:
27170 + e = au_wbr_mfs_wmark(&args[0], str, create);
27172 + e = au_wbr_mfs_sec(&args[1], str, create);
27176 + case AuWbrCreate_MFSRR:
27177 + case AuWbrCreate_TDMFS:
27178 + case AuWbrCreate_PMFSRR:
27179 + e = au_wbr_mfs_wmark(&args[0], str, create);
27180 + if (unlikely(e)) {
27185 + case AuWbrCreate_MFS:
27186 + case AuWbrCreate_PMFS:
27187 + create->mfs_second = AUFS_MFS_DEF_SEC;
27189 + case AuWbrCreate_MFSV:
27190 + case AuWbrCreate_PMFSV:
27191 + e = au_wbr_mfs_sec(&args[0], str, create);
27200 +const char *au_optstr_wbr_create(int wbr_create)
27202 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27205 +static match_table_t au_wbr_copyup_policy = {
27206 + {AuWbrCopyup_TDP, "tdp"},
27207 + {AuWbrCopyup_TDP, "top-down-parent"},
27208 + {AuWbrCopyup_BUP, "bup"},
27209 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27210 + {AuWbrCopyup_BU, "bu"},
27211 + {AuWbrCopyup_BU, "bottom-up"},
27215 +int au_wbr_copyup_val(char *str)
27217 + substring_t args[MAX_OPT_ARGS];
27219 + return match_token(str, au_wbr_copyup_policy, args);
27222 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27224 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27227 +/* ---------------------------------------------------------------------- */
27229 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27230 + aufs_bindex_t bindex)
27233 + struct au_opt_add *add = &opt->add;
27236 + add->bindex = bindex;
27237 + add->perm = AuBrPerm_RO;
27238 + add->pathname = opt_str;
27239 + p = strchr(opt_str, '=');
27243 + add->perm = au_br_perm_val(p);
27246 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27249 + add->perm = AuBrPerm_RO;
27250 + if (au_test_fs_rr(add->path.dentry->d_sb))
27251 + add->perm = AuBrPerm_RR;
27252 + else if (!bindex && !(sb_flags & SB_RDONLY))
27253 + add->perm = AuBrPerm_RW;
27255 + opt->type = Opt_add;
27258 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27265 +static int au_opt_wbr_create(struct super_block *sb,
27266 + struct au_opt_wbr_create *create)
27269 + struct au_sbinfo *sbinfo;
27271 + SiMustWriteLock(sb);
27273 + err = 1; /* handled */
27274 + sbinfo = au_sbi(sb);
27275 + if (sbinfo->si_wbr_create_ops->fin) {
27276 + err = sbinfo->si_wbr_create_ops->fin(sb);
27281 + sbinfo->si_wbr_create = create->wbr_create;
27282 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27283 + switch (create->wbr_create) {
27284 + case AuWbrCreate_MFSRRV:
27285 + case AuWbrCreate_MFSRR:
27286 + case AuWbrCreate_TDMFS:
27287 + case AuWbrCreate_TDMFSV:
27288 + case AuWbrCreate_PMFSRR:
27289 + case AuWbrCreate_PMFSRRV:
27290 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27292 + case AuWbrCreate_MFS:
27293 + case AuWbrCreate_MFSV:
27294 + case AuWbrCreate_PMFS:
27295 + case AuWbrCreate_PMFSV:
27296 + sbinfo->si_wbr_mfs.mfs_expire
27297 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27301 + if (sbinfo->si_wbr_create_ops->init)
27302 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27309 + * plus: processed without an error
27310 + * zero: unprocessed
27312 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27313 + struct au_opts *opts)
27316 + struct au_sbinfo *sbinfo;
27318 + SiMustWriteLock(sb);
27320 + err = 1; /* handled */
27321 + sbinfo = au_sbi(sb);
27322 + switch (opt->type) {
27324 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27325 + sbinfo->si_mntflags |= opt->udba;
27326 + opts->given_udba |= opt->udba;
27331 + au_opt_set(sbinfo->si_mntflags, PLINK);
27333 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27334 + au_plink_put(sb, /*verbose*/1);
27335 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27338 + case Opt_list_plink:
27339 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27340 + au_plink_list(sb);
27345 + au_opt_set(sbinfo->si_mntflags, DIO);
27346 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27348 + au_opt_clr(sbinfo->si_mntflags, DIO);
27349 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27353 + case Opt_fhsm_sec:
27354 + au_fhsm_set(sbinfo, opt->fhsm_second);
27357 + case Opt_diropq_a:
27358 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27360 + case Opt_diropq_w:
27361 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27364 + case Opt_warn_perm:
27366 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27368 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27371 + case Opt_verbose:
27373 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27375 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27380 + au_opt_set(sbinfo->si_mntflags, SUM);
27382 + au_opt_clr(sbinfo->si_mntflags, SUM);
27383 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27387 + au_opt_clr(sbinfo->si_mntflags, SUM);
27388 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27391 + case Opt_wbr_create:
27392 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27394 + case Opt_wbr_copyup:
27395 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27396 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27400 + sbinfo->si_dirwh = opt->dirwh;
27403 + case Opt_rdcache:
27404 + sbinfo->si_rdcache
27405 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27408 + sbinfo->si_rdblk = opt->rdblk;
27411 + sbinfo->si_rdhash = opt->rdhash;
27416 + au_opt_set(sbinfo->si_mntflags, SHWH);
27418 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27421 + case Opt_dirperm1:
27423 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27425 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27428 + case Opt_trunc_xino:
27430 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27432 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27435 + case Opt_trunc_xino_path:
27436 + case Opt_itrunc_xino:
27437 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27443 + case Opt_trunc_xib:
27445 + au_fset_opts(opts->flags, TRUNC_XIB);
27447 + au_fclr_opts(opts->flags, TRUNC_XIB);
27453 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27454 + err = au_dr_opt_set(sb);
27459 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27461 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27462 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27468 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27474 + sb->s_flags |= SB_POSIXACL;
27476 + sb->s_flags &= ~SB_POSIXACL;
27488 + * returns tri-state.
27489 + * plus: processed without an error
27490 + * zero: unprocessed
27493 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27494 + struct au_opts *opts)
27496 + int err, do_refresh;
27499 + switch (opt->type) {
27501 + opt->add.bindex = au_sbbot(sb) + 1;
27502 + if (opt->add.bindex < 0)
27503 + opt->add.bindex = 0;
27505 + /* Always goto add, not fallthrough */
27506 + case Opt_prepend:
27507 + opt->add.bindex = 0;
27509 + add: /* indented label */
27511 + err = au_br_add(sb, &opt->add,
27512 + au_ftest_opts(opts->flags, REMOUNT));
27515 + au_fset_opts(opts->flags, REFRESH);
27521 + err = au_br_del(sb, &opt->del,
27522 + au_ftest_opts(opts->flags, REMOUNT));
27525 + au_fset_opts(opts->flags, TRUNC_XIB);
27526 + au_fset_opts(opts->flags, REFRESH);
27532 + err = au_br_mod(sb, &opt->mod,
27533 + au_ftest_opts(opts->flags, REMOUNT),
27538 + au_fset_opts(opts->flags, REFRESH);
27545 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27546 + struct au_opt_xino **opt_xino,
27547 + struct au_opts *opts)
27552 + switch (opt->type) {
27554 + err = au_xino_set(sb, &opt->xino,
27555 + !!au_ftest_opts(opts->flags, REMOUNT));
27557 + *opt_xino = &opt->xino;
27561 + *opt_xino = (void *)-1;
27568 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27569 + unsigned int pending)
27572 + aufs_bindex_t bindex, bbot;
27573 + unsigned char do_plink, skip, do_free, can_no_dreval;
27574 + struct au_branch *br;
27575 + struct au_wbr *wbr;
27576 + struct dentry *root, *dentry;
27577 + struct inode *dir, *h_dir;
27578 + struct au_sbinfo *sbinfo;
27579 + struct au_hinode *hdir;
27581 + SiMustAnyLock(sb);
27583 + sbinfo = au_sbi(sb);
27584 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27586 + if (!(sb_flags & SB_RDONLY)) {
27587 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27588 + pr_warn("first branch should be rw\n");
27589 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27590 + pr_warn_once("shwh should be used with ro\n");
27593 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27594 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27595 + pr_warn_once("udba=*notify requires xino\n");
27597 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27598 + pr_warn_once("dirperm1 breaks the protection"
27599 + " by the permission bits on the lower branch\n");
27603 + root = sb->s_root;
27604 + dir = d_inode(root);
27605 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27606 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27608 + bbot = au_sbbot(sb);
27609 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27611 + h_dir = au_h_iptr(dir, bindex);
27612 + br = au_sbr(sb, bindex);
27614 + if ((br->br_perm & AuBrAttr_ICEX)
27615 + && !h_dir->i_op->listxattr)
27616 + br->br_perm &= ~AuBrAttr_ICEX;
27617 +#if 0 /* untested */
27618 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27619 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27620 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27624 + wbr = br->br_wbr;
27626 + wbr_wh_read_lock(wbr);
27628 + if (!au_br_writable(br->br_perm)) {
27631 + || (!wbr->wbr_whbase
27632 + && !wbr->wbr_plink
27633 + && !wbr->wbr_orph));
27634 + } else if (!au_br_wh_linkable(br->br_perm)) {
27635 + /* skip = (!br->br_whbase && !br->br_orph); */
27636 + skip = (!wbr || !wbr->wbr_whbase);
27637 + if (skip && wbr) {
27639 + skip = !!wbr->wbr_plink;
27641 + skip = !wbr->wbr_plink;
27644 + /* skip = (br->br_whbase && br->br_ohph); */
27645 + skip = (wbr && wbr->wbr_whbase);
27648 + skip = !!wbr->wbr_plink;
27650 + skip = !wbr->wbr_plink;
27654 + wbr_wh_read_unlock(wbr);
27656 + if (can_no_dreval) {
27657 + dentry = br->br_path.dentry;
27658 + spin_lock(&dentry->d_lock);
27659 + if (dentry->d_flags &
27660 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27661 + can_no_dreval = 0;
27662 + spin_unlock(&dentry->d_lock);
27665 + if (au_br_fhsm(br->br_perm)) {
27667 + AuDebugOn(!br->br_fhsm);
27673 + hdir = au_hi(dir, bindex);
27674 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27676 + wbr_wh_write_lock(wbr);
27677 + err = au_wh_init(br, sb);
27679 + wbr_wh_write_unlock(wbr);
27680 + au_hn_inode_unlock(hdir);
27682 + if (!err && do_free) {
27683 + au_kfree_rcu(wbr);
27684 + br->br_wbr = NULL;
27688 + if (can_no_dreval)
27689 + au_fset_si(sbinfo, NO_DREVAL);
27691 + au_fclr_si(sbinfo, NO_DREVAL);
27694 + au_fset_si(sbinfo, FHSM);
27695 + for (bindex = bbot; bindex >= 0; bindex--) {
27696 + br = au_sbr(sb, bindex);
27697 + if (au_br_fhsm(br->br_perm)) {
27698 + au_fhsm_set_bottom(sb, bindex);
27703 + au_fclr_si(sbinfo, FHSM);
27704 + au_fhsm_set_bottom(sb, -1);
27710 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27713 + unsigned int tmp;
27714 + aufs_bindex_t bindex, bbot;
27715 + struct au_opt *opt;
27716 + struct au_opt_xino *opt_xino, xino;
27717 + struct au_sbinfo *sbinfo;
27718 + struct au_branch *br;
27719 + struct inode *dir;
27721 + SiMustWriteLock(sb);
27726 + while (err >= 0 && opt->type != Opt_tail)
27727 + err = au_opt_simple(sb, opt++, opts);
27730 + else if (unlikely(err < 0))
27733 + /* disable xino and udba temporary */
27734 + sbinfo = au_sbi(sb);
27735 + tmp = sbinfo->si_mntflags;
27736 + au_opt_clr(sbinfo->si_mntflags, XINO);
27737 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27740 + while (err >= 0 && opt->type != Opt_tail)
27741 + err = au_opt_br(sb, opt++, opts);
27744 + else if (unlikely(err < 0))
27747 + bbot = au_sbbot(sb);
27748 + if (unlikely(bbot < 0)) {
27750 + pr_err("no branches\n");
27754 + if (au_opt_test(tmp, XINO))
27755 + au_opt_set(sbinfo->si_mntflags, XINO);
27757 + while (!err && opt->type != Opt_tail)
27758 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27759 + if (unlikely(err))
27762 + err = au_opts_verify(sb, sb->s_flags, tmp);
27763 + if (unlikely(err))
27766 + /* restore xino */
27767 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27768 + xino.file = au_xino_def(sb);
27769 + err = PTR_ERR(xino.file);
27770 + if (IS_ERR(xino.file))
27773 + err = au_xino_set(sb, &xino, /*remount*/0);
27775 + if (unlikely(err))
27779 + /* restore udba */
27780 + tmp &= AuOptMask_UDBA;
27781 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27782 + sbinfo->si_mntflags |= tmp;
27783 + bbot = au_sbbot(sb);
27784 + for (bindex = 0; bindex <= bbot; bindex++) {
27785 + br = au_sbr(sb, bindex);
27786 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27787 + if (unlikely(err))
27788 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27790 + /* go on even if err */
27792 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27793 + dir = d_inode(sb->s_root);
27794 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27801 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27804 + unsigned char no_dreval;
27805 + struct inode *dir;
27806 + struct au_opt_xino *opt_xino;
27807 + struct au_opt *opt;
27808 + struct au_sbinfo *sbinfo;
27810 + SiMustWriteLock(sb);
27812 + err = au_dr_opt_flush(sb);
27813 + if (unlikely(err))
27815 + au_fset_opts(opts->flags, DR_FLUSHED);
27817 + dir = d_inode(sb->s_root);
27818 + sbinfo = au_sbi(sb);
27821 + while (err >= 0 && opt->type != Opt_tail) {
27822 + err = au_opt_simple(sb, opt, opts);
27824 + err = au_opt_br(sb, opt, opts);
27826 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27832 + /* go on even err */
27834 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27835 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27836 + if (unlikely(rerr && !err))
27839 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27840 + au_fset_opts(opts->flags, REFRESH_IDOP);
27842 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27843 + rerr = au_xib_trunc(sb);
27844 + if (unlikely(rerr && !err))
27848 + /* will be handled by the caller */
27849 + if (!au_ftest_opts(opts->flags, REFRESH)
27850 + && (opts->given_udba
27851 + || au_opt_test(sbinfo->si_mntflags, XINO)
27852 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27854 + au_fset_opts(opts->flags, REFRESH);
27856 + AuDbg("status 0x%x\n", opts->flags);
27862 +/* ---------------------------------------------------------------------- */
27864 +unsigned int au_opt_udba(struct super_block *sb)
27866 + return au_mntflags(sb) & AuOptMask_UDBA;
27868 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27869 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27870 +++ linux/fs/aufs/opts.h 2022-10-26 22:30:38.469315525 +0200
27872 +/* SPDX-License-Identifier: GPL-2.0 */
27874 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27876 + * This program, aufs is free software; you can redistribute it and/or modify
27877 + * it under the terms of the GNU General Public License as published by
27878 + * the Free Software Foundation; either version 2 of the License, or
27879 + * (at your option) any later version.
27881 + * This program is distributed in the hope that it will be useful,
27882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27884 + * GNU General Public License for more details.
27886 + * You should have received a copy of the GNU General Public License
27887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27891 + * mount options/flags
27894 +#ifndef __AUFS_OPTS_H__
27895 +#define __AUFS_OPTS_H__
27899 +#include <linux/fs_parser.h>
27900 +#include <linux/namei.h>
27901 +#include <linux/path.h>
27905 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27906 + Opt_idel, Opt_imod,
27907 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27908 + Opt_xino, Opt_noxino,
27909 + Opt_trunc_xino, Opt_trunc_xino_v,
27910 + Opt_trunc_xino_path, Opt_itrunc_xino,
27913 + Opt_plink, Opt_list_plink,
27916 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27918 + Opt_wbr_copyup, Opt_wbr_create,
27920 + Opt_verbose, Opt_noverbose,
27921 + Opt_sum, Opt_wsum,
27925 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27928 +/* ---------------------------------------------------------------------- */
27931 +#define AuOpt_XINO 1 /* external inode number bitmap
27932 + and translation table */
27933 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27934 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27935 +#define AuOpt_UDBA_REVAL (1 << 3)
27936 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27937 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27938 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27939 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27941 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27942 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27943 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27944 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27945 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27946 +#define AuOpt_DIO (1 << 14) /* direct io */
27947 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27949 +#ifndef CONFIG_AUFS_HNOTIFY
27950 +#undef AuOpt_UDBA_HNOTIFY
27951 +#define AuOpt_UDBA_HNOTIFY 0
27953 +#ifndef CONFIG_AUFS_DIRREN
27954 +#undef AuOpt_DIRREN
27955 +#define AuOpt_DIRREN 0
27957 +#ifndef CONFIG_AUFS_SHWH
27959 +#define AuOpt_SHWH 0
27962 +#define AuOpt_Def (AuOpt_XINO \
27963 + | AuOpt_UDBA_REVAL \
27965 + /* | AuOpt_DIRPERM1 */ \
27966 + | AuOpt_WARN_PERM)
27967 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27968 + | AuOpt_UDBA_REVAL \
27969 + | AuOpt_UDBA_HNOTIFY)
27971 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
27973 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27974 +#define au_opt_set(flags, name) do { \
27975 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27976 + ((flags) |= AuOpt_##name); \
27978 +#define au_opt_set_udba(flags, name) do { \
27979 + (flags) &= ~AuOptMask_UDBA; \
27980 + ((flags) |= AuOpt_##name); \
27982 +#define au_opt_clr(flags, name) do { \
27983 + ((flags) &= ~AuOpt_##name); \
27986 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27988 +#ifdef CONFIG_PROC_FS
27991 + return mntflags & ~AuOpt_PLINK;
27995 +/* ---------------------------------------------------------------------- */
27997 +/* policies to select one among multiple writable branches */
27999 + AuWbrCreate_TDP, /* top down parent */
28000 + AuWbrCreate_RR, /* round robin */
28001 + AuWbrCreate_MFS, /* most free space */
28002 + AuWbrCreate_MFSV, /* mfs with seconds */
28003 + AuWbrCreate_MFSRR, /* mfs then rr */
28004 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28005 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28006 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28007 + AuWbrCreate_PMFS, /* parent and mfs */
28008 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28009 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28010 + AuWbrCreate_PMFSRRV, /* plus seconds */
28012 + AuWbrCreate_Def = AuWbrCreate_TDP
28016 + AuWbrCopyup_TDP, /* top down parent */
28017 + AuWbrCopyup_BUP, /* bottom up parent */
28018 + AuWbrCopyup_BU, /* bottom up */
28020 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28023 +/* ---------------------------------------------------------------------- */
28027 +struct au_opt_add {
28028 + aufs_bindex_t bindex;
28031 + struct path path;
28034 +struct au_opt_del {
28036 + struct path h_path;
28039 +struct au_opt_mod {
28042 + struct dentry *h_root;
28045 +struct au_opt_xino {
28047 + struct file *file;
28050 +struct au_opt_xino_itrunc {
28051 + aufs_bindex_t bindex;
28054 +struct au_opt_wbr_create {
28057 + unsigned long long mfsrr_watermark;
28063 + struct au_opt_xino xino;
28064 + struct au_opt_xino_itrunc xino_itrunc;
28065 + struct au_opt_add add;
28066 + struct au_opt_del del;
28067 + struct au_opt_mod mod;
28070 + unsigned int rdblk;
28071 + unsigned int rdhash;
28073 + struct au_opt_wbr_create wbr_create;
28075 + unsigned int fhsm_second;
28076 + bool tf; /* generic flag, true or false */
28081 +#define AuOpts_REMOUNT 1
28082 +#define AuOpts_REFRESH (1 << 1)
28083 +#define AuOpts_TRUNC_XIB (1 << 2)
28084 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28085 +#define AuOpts_REFRESH_IDOP (1 << 4)
28086 +#define AuOpts_DR_FLUSHED (1 << 5)
28087 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28088 +#define au_fset_opts(flags, name) \
28089 + do { (flags) |= AuOpts_##name; } while (0)
28090 +#define au_fclr_opts(flags, name) \
28091 + do { (flags) &= ~AuOpts_##name; } while (0)
28093 +#ifndef CONFIG_AUFS_DIRREN
28094 +#undef AuOpts_DR_FLUSHED
28095 +#define AuOpts_DR_FLUSHED 0
28099 + struct au_opt *opt;
28102 + unsigned int given_udba;
28103 + unsigned int flags;
28104 + unsigned long sb_flags;
28107 +/* ---------------------------------------------------------------------- */
28110 +int au_br_perm_val(char *perm);
28111 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28112 +int au_udba_val(char *str);
28113 +const char *au_optstr_udba(int udba);
28114 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28115 +const char *au_optstr_wbr_create(int wbr_create);
28116 +int au_wbr_copyup_val(char *str);
28117 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28119 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28120 + aufs_bindex_t bindex);
28121 +struct super_block;
28122 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28123 + unsigned int pending);
28124 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28125 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28127 +unsigned int au_opt_udba(struct super_block *sb);
28130 +int aufs_fsctx_init(struct fs_context *fc);
28131 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28133 +#endif /* __KERNEL__ */
28134 +#endif /* __AUFS_OPTS_H__ */
28135 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28136 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28137 +++ linux/fs/aufs/plink.c 2022-10-26 22:30:38.469315525 +0200
28139 +// SPDX-License-Identifier: GPL-2.0
28141 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28143 + * This program, aufs is free software; you can redistribute it and/or modify
28144 + * it under the terms of the GNU General Public License as published by
28145 + * the Free Software Foundation; either version 2 of the License, or
28146 + * (at your option) any later version.
28148 + * This program is distributed in the hope that it will be useful,
28149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28151 + * GNU General Public License for more details.
28153 + * You should have received a copy of the GNU General Public License
28154 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28164 + * the pseudo-link maintenance mode.
28165 + * during a user process maintains the pseudo-links,
28166 + * prohibit adding a new plink and branch manipulation.
28170 + * For entry functions which will handle plink, and i_mutex is already held
28172 + * They cannot wait and should return an error at once.
28173 + * Callers has to check the error.
28175 + * For entry functions which will handle plink, but i_mutex is not held
28177 + * They can wait the plink maintenance mode to finish.
28179 + * They behave like F_SETLK and F_SETLKW.
28180 + * If the caller never handle plink, then both flags are unnecessary.
28183 +int au_plink_maint(struct super_block *sb, int flags)
28187 + struct task_struct *parent, *prev;
28188 + struct au_sbinfo *sbi;
28190 + SiMustAnyLock(sb);
28193 + if (!au_opt_test(au_mntflags(sb), PLINK))
28196 + sbi = au_sbi(sb);
28197 + pid = sbi->si_plink_maint_pid;
28198 + if (!pid || pid == current->pid)
28201 + /* todo: it highly depends upon /sbin/mount.aufs */
28203 + parent = current;
28207 + parent = rcu_dereference(parent->real_parent);
28208 + if (parent == prev)
28210 + ppid = task_pid_vnr(parent);
28211 + if (pid == ppid) {
28212 + rcu_read_unlock();
28217 + rcu_read_unlock();
28219 + if (au_ftest_lock(flags, NOPLMW)) {
28220 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28221 + /* AuDebugOn(!lockdep_depth(current)); */
28222 + while (sbi->si_plink_maint_pid) {
28223 + si_read_unlock(sb);
28224 + /* gave up wake_up_bit() */
28225 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28227 + if (au_ftest_lock(flags, FLUSH))
28228 + au_nwt_flush(&sbi->si_nowait);
28229 + si_noflush_read_lock(sb);
28231 + } else if (au_ftest_lock(flags, NOPLM)) {
28232 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28240 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28242 + spin_lock(&sbinfo->si_plink_maint_lock);
28243 + sbinfo->si_plink_maint_pid = 0;
28244 + spin_unlock(&sbinfo->si_plink_maint_lock);
28245 + wake_up_all(&sbinfo->si_plink_wq);
28248 +int au_plink_maint_enter(struct super_block *sb)
28251 + struct au_sbinfo *sbinfo;
28254 + sbinfo = au_sbi(sb);
28255 + /* make sure i am the only one in this fs */
28256 + si_write_lock(sb, AuLock_FLUSH);
28257 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28258 + spin_lock(&sbinfo->si_plink_maint_lock);
28259 + if (!sbinfo->si_plink_maint_pid)
28260 + sbinfo->si_plink_maint_pid = current->pid;
28263 + spin_unlock(&sbinfo->si_plink_maint_lock);
28265 + si_write_unlock(sb);
28270 +/* ---------------------------------------------------------------------- */
28272 +#ifdef CONFIG_AUFS_DEBUG
28273 +void au_plink_list(struct super_block *sb)
28276 + struct au_sbinfo *sbinfo;
28277 + struct hlist_bl_head *hbl;
28278 + struct hlist_bl_node *pos;
28279 + struct au_icntnr *icntnr;
28281 + SiMustAnyLock(sb);
28283 + sbinfo = au_sbi(sb);
28284 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28285 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28287 + for (i = 0; i < AuPlink_NHASH; i++) {
28288 + hbl = sbinfo->si_plink + i;
28289 + hlist_bl_lock(hbl);
28290 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28291 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28292 + hlist_bl_unlock(hbl);
28297 +/* is the inode pseudo-linked? */
28298 +int au_plink_test(struct inode *inode)
28301 + struct au_sbinfo *sbinfo;
28302 + struct hlist_bl_head *hbl;
28303 + struct hlist_bl_node *pos;
28304 + struct au_icntnr *icntnr;
28306 + sbinfo = au_sbi(inode->i_sb);
28307 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28308 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28309 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28312 + i = au_plink_hash(inode->i_ino);
28313 + hbl = sbinfo->si_plink + i;
28314 + hlist_bl_lock(hbl);
28315 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28316 + if (&icntnr->vfs_inode == inode) {
28320 + hlist_bl_unlock(hbl);
28324 +/* ---------------------------------------------------------------------- */
28327 + * generate a name for plink.
28328 + * the file will be stored under AUFS_WH_PLINKDIR.
28330 +/* 20 is max digits length of ulong 64 */
28331 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28333 +static int plink_name(char *name, int len, struct inode *inode,
28334 + aufs_bindex_t bindex)
28337 + struct inode *h_inode;
28339 + h_inode = au_h_iptr(inode, bindex);
28340 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28344 +struct au_do_plink_lkup_args {
28345 + struct dentry **errp;
28346 + struct qstr *tgtname;
28347 + struct path *h_ppath;
28350 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28351 + struct path *h_ppath)
28353 + struct dentry *h_dentry;
28354 + struct inode *h_inode;
28356 + h_inode = d_inode(h_ppath->dentry);
28357 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28358 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28359 + inode_unlock_shared(h_inode);
28364 +static void au_call_do_plink_lkup(void *args)
28366 + struct au_do_plink_lkup_args *a = args;
28367 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28370 +/* lookup the plink-ed @inode under the branch at @bindex */
28371 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28373 + struct dentry *h_dentry;
28374 + struct au_branch *br;
28375 + struct path h_ppath;
28377 + char a[PLINK_NAME_LEN];
28378 + struct qstr tgtname = QSTR_INIT(a, 0);
28380 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28382 + br = au_sbr(inode->i_sb, bindex);
28383 + h_ppath.dentry = br->br_wbr->wbr_plink;
28384 + h_ppath.mnt = au_br_mnt(br);
28385 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28387 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28388 + struct au_do_plink_lkup_args args = {
28389 + .errp = &h_dentry,
28390 + .tgtname = &tgtname,
28391 + .h_ppath = &h_ppath
28394 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28395 + if (unlikely(wkq_err))
28396 + h_dentry = ERR_PTR(wkq_err);
28398 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28403 +/* create a pseudo-link */
28404 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28405 + struct dentry *h_dentry)
28408 + struct path h_path;
28409 + struct inode *h_dir, *delegated;
28411 + h_dir = d_inode(h_ppath->dentry);
28412 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28413 + h_path.mnt = h_ppath->mnt;
28415 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28416 + err = PTR_ERR(h_path.dentry);
28417 + if (IS_ERR(h_path.dentry))
28421 + /* wh.plink dir is not monitored */
28422 + /* todo: is it really safe? */
28423 + if (d_is_positive(h_path.dentry)
28424 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28425 + delegated = NULL;
28426 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28427 + if (unlikely(err == -EWOULDBLOCK)) {
28428 + pr_warn("cannot retry for NFSv4 delegation"
28429 + " for an internal unlink\n");
28432 + dput(h_path.dentry);
28433 + h_path.dentry = NULL;
28437 + if (!err && d_is_negative(h_path.dentry)) {
28438 + delegated = NULL;
28439 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28440 + if (unlikely(err == -EWOULDBLOCK)) {
28441 + pr_warn("cannot retry for NFSv4 delegation"
28442 + " for an internal link\n");
28446 + dput(h_path.dentry);
28449 + inode_unlock(h_dir);
28453 +struct do_whplink_args {
28455 + struct qstr *tgt;
28456 + struct path *h_ppath;
28457 + struct dentry *h_dentry;
28460 +static void call_do_whplink(void *args)
28462 + struct do_whplink_args *a = args;
28463 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28466 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28467 + aufs_bindex_t bindex)
28469 + int err, wkq_err;
28470 + struct au_branch *br;
28471 + struct au_wbr *wbr;
28472 + struct path h_ppath;
28473 + char a[PLINK_NAME_LEN];
28474 + struct qstr tgtname = QSTR_INIT(a, 0);
28476 + br = au_sbr(inode->i_sb, bindex);
28477 + wbr = br->br_wbr;
28478 + h_ppath.dentry = wbr->wbr_plink;
28479 + h_ppath.mnt = au_br_mnt(br);
28480 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28482 + /* always superio. */
28483 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28484 + struct do_whplink_args args = {
28487 + .h_ppath = &h_ppath,
28488 + .h_dentry = h_dentry
28490 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28491 + if (unlikely(wkq_err))
28494 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28500 + * create a new pseudo-link for @h_dentry on @bindex.
28501 + * the linked inode is held in aufs @inode.
28503 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28504 + struct dentry *h_dentry)
28506 + struct super_block *sb;
28507 + struct au_sbinfo *sbinfo;
28508 + struct hlist_bl_head *hbl;
28509 + struct hlist_bl_node *pos;
28510 + struct au_icntnr *icntnr;
28511 + int found, err, cnt, i;
28513 + sb = inode->i_sb;
28514 + sbinfo = au_sbi(sb);
28515 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28516 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28518 + found = au_plink_test(inode);
28522 + i = au_plink_hash(inode->i_ino);
28523 + hbl = sbinfo->si_plink + i;
28526 + hlist_bl_lock(hbl);
28527 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28528 + if (&icntnr->vfs_inode == inode) {
28534 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28535 + hlist_bl_add_head(&icntnr->plink, hbl);
28537 + hlist_bl_unlock(hbl);
28539 + cnt = au_hbl_count(hbl);
28540 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28541 + if (cnt > AUFS_PLINK_WARN)
28542 + AuWarn1(msg ", %d\n", cnt);
28544 + err = whplink(h_dentry, inode, bindex);
28545 + if (unlikely(err)) {
28546 + pr_warn("err %d, damaged pseudo link.\n", err);
28547 + au_hbl_del(&icntnr->plink, hbl);
28548 + iput(&icntnr->vfs_inode);
28551 + iput(&icntnr->vfs_inode);
28554 +/* free all plinks */
28555 +void au_plink_put(struct super_block *sb, int verbose)
28558 + struct au_sbinfo *sbinfo;
28559 + struct hlist_bl_head *hbl;
28560 + struct hlist_bl_node *pos, *tmp;
28561 + struct au_icntnr *icntnr;
28563 + SiMustWriteLock(sb);
28565 + sbinfo = au_sbi(sb);
28566 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28567 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28569 + /* no spin_lock since sbinfo is write-locked */
28571 + for (i = 0; i < AuPlink_NHASH; i++) {
28572 + hbl = sbinfo->si_plink + i;
28573 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28574 + pr_warn("pseudo-link is not flushed");
28577 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28578 + iput(&icntnr->vfs_inode);
28579 + INIT_HLIST_BL_HEAD(hbl);
28583 +void au_plink_clean(struct super_block *sb, int verbose)
28585 + struct dentry *root;
28587 + root = sb->s_root;
28588 + aufs_write_lock(root);
28589 + if (au_opt_test(au_mntflags(sb), PLINK))
28590 + au_plink_put(sb, verbose);
28591 + aufs_write_unlock(root);
28594 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28597 + aufs_bindex_t btop, bbot, bindex;
28600 + btop = au_ibtop(inode);
28601 + bbot = au_ibbot(inode);
28603 + for (bindex = btop; bindex <= bbot; bindex++) {
28604 + if (!au_h_iptr(inode, bindex)
28605 + || au_ii_br_id(inode, bindex) != br_id)
28607 + au_set_h_iptr(inode, bindex, NULL, 0);
28612 + for (bindex = btop; bindex <= bbot; bindex++)
28613 + if (au_h_iptr(inode, bindex)) {
28623 +/* free the plinks on a branch specified by @br_id */
28624 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28626 + struct au_sbinfo *sbinfo;
28627 + struct hlist_bl_head *hbl;
28628 + struct hlist_bl_node *pos, *tmp;
28629 + struct au_icntnr *icntnr;
28630 + struct inode *inode;
28633 + SiMustWriteLock(sb);
28635 + sbinfo = au_sbi(sb);
28636 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28637 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28639 + /* no bit_lock since sbinfo is write-locked */
28640 + for (i = 0; i < AuPlink_NHASH; i++) {
28641 + hbl = sbinfo->si_plink + i;
28642 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28643 + inode = au_igrab(&icntnr->vfs_inode);
28644 + ii_write_lock_child(inode);
28645 + do_put = au_plink_do_half_refresh(inode, br_id);
28647 + hlist_bl_del(&icntnr->plink);
28650 + ii_write_unlock(inode);
28655 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28656 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28657 +++ linux/fs/aufs/poll.c 2022-10-26 22:30:38.469315525 +0200
28659 +// SPDX-License-Identifier: GPL-2.0
28661 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28663 + * This program, aufs is free software; you can redistribute it and/or modify
28664 + * it under the terms of the GNU General Public License as published by
28665 + * the Free Software Foundation; either version 2 of the License, or
28666 + * (at your option) any later version.
28668 + * This program is distributed in the hope that it will be useful,
28669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28671 + * GNU General Public License for more details.
28673 + * You should have received a copy of the GNU General Public License
28674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28679 + * There is only one filesystem which implements ->poll operation, currently.
28684 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28687 + struct file *h_file;
28688 + struct super_block *sb;
28690 + /* We should pretend an error happened. */
28691 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28692 + sb = file->f_path.dentry->d_sb;
28693 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28695 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28696 + if (IS_ERR(h_file)) {
28697 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28701 + mask = vfs_poll(h_file, pt);
28702 + fput(h_file); /* instead of au_read_post() */
28705 + si_read_unlock(sb);
28706 + if (mask & EPOLLERR)
28707 + AuDbg("mask 0x%x\n", mask);
28710 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28711 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28712 +++ linux/fs/aufs/posix_acl.c 2022-10-26 22:30:38.469315525 +0200
28714 +// SPDX-License-Identifier: GPL-2.0
28716 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28718 + * This program, aufs is free software; you can redistribute it and/or modify
28719 + * it under the terms of the GNU General Public License as published by
28720 + * the Free Software Foundation; either version 2 of the License, or
28721 + * (at your option) any later version.
28723 + * This program is distributed in the hope that it will be useful,
28724 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28725 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28726 + * GNU General Public License for more details.
28728 + * You should have received a copy of the GNU General Public License
28729 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28733 + * posix acl operations
28736 +#include <linux/fs.h>
28739 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28741 + struct posix_acl *acl;
28743 + aufs_bindex_t bindex;
28744 + struct inode *h_inode;
28745 + struct super_block *sb;
28747 + acl = ERR_PTR(-ECHILD);
28752 + sb = inode->i_sb;
28753 + si_read_lock(sb, AuLock_FLUSH);
28754 + ii_read_lock_child(inode);
28755 + if (!(sb->s_flags & SB_POSIXACL))
28758 + bindex = au_ibtop(inode);
28759 + h_inode = au_h_iptr(inode, bindex);
28760 + if (unlikely(!h_inode
28761 + || ((h_inode->i_mode & S_IFMT)
28762 + != (inode->i_mode & S_IFMT)))) {
28763 + err = au_busy_or_stale();
28764 + acl = ERR_PTR(err);
28768 + /* always topmost only */
28769 + acl = get_acl(h_inode, type);
28771 + forget_cached_acl(inode, type);
28773 + set_cached_acl(inode, type, acl);
28776 + ii_read_unlock(inode);
28777 + si_read_unlock(sb);
28780 + AuTraceErrPtr(acl);
28784 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28785 + struct posix_acl *acl, int type)
28789 + struct dentry *dentry;
28790 + struct au_sxattr arg = {
28791 + .type = AU_ACL_SET,
28798 + IMustLock(inode);
28800 + if (inode->i_ino == AUFS_ROOT_INO)
28801 + dentry = dget(inode->i_sb->s_root);
28803 + dentry = d_find_alias(inode);
28805 + dentry = d_find_any_alias(inode);
28807 + pr_warn("cannot handle this inode, "
28808 + "please report to aufs-users ML\n");
28814 + ssz = au_sxattr(dentry, inode, &arg);
28815 + /* forget even it if succeeds since the branch might set differently */
28816 + forget_cached_acl(inode, type);
28825 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28826 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28827 +++ linux/fs/aufs/procfs.c 2022-10-26 22:30:38.469315525 +0200
28829 +// SPDX-License-Identifier: GPL-2.0
28831 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28833 + * This program, aufs is free software; you can redistribute it and/or modify
28834 + * it under the terms of the GNU General Public License as published by
28835 + * the Free Software Foundation; either version 2 of the License, or
28836 + * (at your option) any later version.
28838 + * This program is distributed in the hope that it will be useful,
28839 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28840 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28841 + * GNU General Public License for more details.
28843 + * You should have received a copy of the GNU General Public License
28844 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28848 + * procfs interfaces
28851 +#include <linux/proc_fs.h>
28854 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28856 + struct au_sbinfo *sbinfo;
28858 + sbinfo = file->private_data;
28860 + au_plink_maint_leave(sbinfo);
28861 + kobject_put(&sbinfo->si_kobj);
28867 +static void au_procfs_plm_write_clean(struct file *file)
28869 + struct au_sbinfo *sbinfo;
28871 + sbinfo = file->private_data;
28873 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28876 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28879 + struct super_block *sb;
28880 + struct au_sbinfo *sbinfo;
28881 + struct hlist_bl_node *pos;
28884 + if (unlikely(file->private_data))
28888 + /* don't use au_sbilist_lock() here */
28889 + hlist_bl_lock(&au_sbilist);
28890 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28891 + if (id == sysaufs_si_id(sbinfo)) {
28892 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28893 + sb = sbinfo->si_sb;
28896 + hlist_bl_unlock(&au_sbilist);
28899 + if (unlikely(!sb))
28902 + err = au_plink_maint_enter(sb);
28904 + /* keep kobject_get() */
28905 + file->private_data = sbinfo;
28907 + kobject_put(&sbinfo->si_kobj);
28913 + * Accept a valid "si=xxxx" only.
28914 + * Once it is accepted successfully, accept "clean" too.
28916 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28917 + size_t count, loff_t *ppos)
28920 + unsigned long id;
28921 + /* last newline is allowed */
28922 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28925 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28929 + if (unlikely(count > sizeof(buf)))
28932 + err = copy_from_user(buf, ubuf, count);
28933 + if (unlikely(err)) {
28940 + if (!strcmp("clean", buf)) {
28941 + au_procfs_plm_write_clean(file);
28942 + goto out_success;
28943 + } else if (unlikely(strncmp("si=", buf, 3)))
28946 + err = kstrtoul(buf + 3, 16, &id);
28947 + if (unlikely(err))
28950 + err = au_procfs_plm_write_si(file, id);
28951 + if (unlikely(err))
28955 + err = count; /* success */
28960 +static const struct proc_ops au_procfs_plm_op = {
28961 + .proc_write = au_procfs_plm_write,
28962 + .proc_release = au_procfs_plm_release
28965 +/* ---------------------------------------------------------------------- */
28967 +static struct proc_dir_entry *au_procfs_dir;
28969 +void au_procfs_fin(void)
28971 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28972 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28975 +int __init au_procfs_init(void)
28978 + struct proc_dir_entry *entry;
28981 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28982 + if (unlikely(!au_procfs_dir))
28985 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28986 + au_procfs_dir, &au_procfs_plm_op);
28987 + if (unlikely(!entry))
28991 + goto out; /* success */
28995 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28999 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29000 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29001 +++ linux/fs/aufs/rdu.c 2022-10-26 22:30:38.472648858 +0200
29003 +// SPDX-License-Identifier: GPL-2.0
29005 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29007 + * This program, aufs is free software; you can redistribute it and/or modify
29008 + * it under the terms of the GNU General Public License as published by
29009 + * the Free Software Foundation; either version 2 of the License, or
29010 + * (at your option) any later version.
29012 + * This program is distributed in the hope that it will be useful,
29013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29015 + * GNU General Public License for more details.
29017 + * You should have received a copy of the GNU General Public License
29018 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29022 + * readdir in userspace.
29025 +#include <linux/compat.h>
29026 +#include <linux/fs_stack.h>
29027 +#include <linux/security.h>
29030 +/* bits for struct aufs_rdu.flags */
29031 +#define AuRdu_CALLED 1
29032 +#define AuRdu_CONT (1 << 1)
29033 +#define AuRdu_FULL (1 << 2)
29034 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29035 +#define au_fset_rdu(flags, name) \
29036 + do { (flags) |= AuRdu_##name; } while (0)
29037 +#define au_fclr_rdu(flags, name) \
29038 + do { (flags) &= ~AuRdu_##name; } while (0)
29040 +struct au_rdu_arg {
29041 + struct dir_context ctx;
29042 + struct aufs_rdu *rdu;
29043 + union au_rdu_ent_ul ent;
29044 + unsigned long end;
29046 + struct super_block *sb;
29050 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29051 + loff_t offset, u64 h_ino, unsigned int d_type)
29054 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29055 + struct aufs_rdu *rdu = arg->rdu;
29056 + struct au_rdu_ent ent;
29060 + au_fset_rdu(rdu->cookie.flags, CALLED);
29061 + len = au_rdu_len(nlen);
29062 + if (arg->ent.ul + len < arg->end) {
29064 + ent.bindex = rdu->cookie.bindex;
29065 + ent.type = d_type;
29067 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29068 + ent.type = DT_UNKNOWN;
29070 + /* unnecessary to support mmap_sem since this is a dir */
29072 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29074 + if (copy_to_user(arg->ent.e->name, name, nlen))
29076 + /* the terminating NULL */
29077 + if (__put_user(0, arg->ent.e->name + nlen))
29080 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29081 + arg->ent.ul += len;
29085 + au_fset_rdu(rdu->cookie.flags, FULL);
29087 + rdu->tail = arg->ent;
29091 + /* AuTraceErr(err); */
29095 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29099 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29101 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29102 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29104 + if (unlikely(offset != cookie->h_pos))
29110 + au_fclr_rdu(cookie->flags, CALLED);
29112 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29116 + && au_ftest_rdu(cookie->flags, CALLED)
29117 + && !au_ftest_rdu(cookie->flags, FULL));
29118 + cookie->h_pos = h_file->f_pos;
29125 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29128 + aufs_bindex_t bbot;
29129 + struct au_rdu_arg arg = {
29131 + .actor = au_rdu_fill
29134 + struct dentry *dentry;
29135 + struct inode *inode;
29136 + struct file *h_file;
29137 + struct au_rdu_cookie *cookie = &rdu->cookie;
29139 + /* VERIFY_WRITE */
29140 + err = !access_ok(rdu->ent.e, rdu->sz);
29141 + if (unlikely(err)) {
29147 + rdu->tail = rdu->ent;
29150 + arg.ent = rdu->ent;
29151 + arg.end = arg.ent.ul;
29152 + arg.end += rdu->sz;
29155 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29158 + err = security_file_permission(file, MAY_READ);
29160 + if (unlikely(err))
29163 + dentry = file->f_path.dentry;
29164 + inode = d_inode(dentry);
29165 + inode_lock_shared(inode);
29167 + arg.sb = inode->i_sb;
29168 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29169 + if (unlikely(err))
29171 + err = au_alive_dir(dentry);
29172 + if (unlikely(err))
29174 + /* todo: reval? */
29175 + fi_read_lock(file);
29178 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29179 + && cookie->generation != au_figen(file)))
29184 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29186 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29188 + bbot = au_fbtop(file);
29189 + if (cookie->bindex < bbot)
29190 + cookie->bindex = bbot;
29191 + bbot = au_fbbot_dir(file);
29192 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29193 + for (; !err && cookie->bindex <= bbot;
29194 + cookie->bindex++, cookie->h_pos = 0) {
29195 + h_file = au_hf_dir(file, cookie->bindex);
29199 + au_fclr_rdu(cookie->flags, FULL);
29200 + err = au_rdu_do(h_file, &arg);
29202 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29205 + AuDbg("rent %llu\n", rdu->rent);
29207 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29208 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29209 + au_fset_rdu(cookie->flags, CONT);
29210 + cookie->generation = au_figen(file);
29213 + ii_read_lock_child(inode);
29214 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29215 + ii_read_unlock(inode);
29218 + fi_read_unlock(file);
29220 + si_read_unlock(arg.sb);
29222 + inode_unlock_shared(inode);
29228 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29232 + unsigned long long nent;
29233 + union au_rdu_ent_ul *u;
29234 + struct au_rdu_ent ent;
29235 + struct super_block *sb;
29238 + nent = rdu->nent;
29240 + sb = file->f_path.dentry->d_sb;
29241 + si_read_lock(sb, AuLock_FLUSH);
29242 + while (nent-- > 0) {
29243 + /* unnecessary to support mmap_sem since this is a dir */
29244 + err = copy_from_user(&ent, u->e, sizeof(ent));
29246 + /* VERIFY_WRITE */
29247 + err = !access_ok(&u->e->ino, sizeof(ino));
29248 + if (unlikely(err)) {
29254 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29256 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29258 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29260 + if (unlikely(err)) {
29265 + err = __put_user(ino, &u->e->ino);
29266 + if (unlikely(err)) {
29271 + u->ul += au_rdu_len(ent.nlen);
29273 + si_read_unlock(sb);
29278 +/* ---------------------------------------------------------------------- */
29280 +static int au_rdu_verify(struct aufs_rdu *rdu)
29282 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29283 + "%llu, b%d, 0x%x, g%u}\n",
29284 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29286 + rdu->rent, rdu->shwh, rdu->full,
29287 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29288 + rdu->cookie.generation);
29290 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29294 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29298 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29301 + struct aufs_rdu rdu;
29302 + void __user *p = (void __user *)arg;
29304 + err = copy_from_user(&rdu, p, sizeof(rdu));
29305 + if (unlikely(err)) {
29310 + err = au_rdu_verify(&rdu);
29311 + if (unlikely(err))
29315 + case AUFS_CTL_RDU:
29316 + err = au_rdu(file, &rdu);
29317 + if (unlikely(err))
29320 + e = copy_to_user(p, &rdu, sizeof(rdu));
29321 + if (unlikely(e)) {
29326 + case AUFS_CTL_RDU_INO:
29327 + err = au_rdu_ino(file, &rdu);
29331 + /* err = -ENOTTY; */
29340 +#ifdef CONFIG_COMPAT
29341 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29344 + struct aufs_rdu rdu;
29345 + void __user *p = compat_ptr(arg);
29347 + /* todo: get_user()? */
29348 + err = copy_from_user(&rdu, p, sizeof(rdu));
29349 + if (unlikely(err)) {
29354 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29355 + err = au_rdu_verify(&rdu);
29356 + if (unlikely(err))
29360 + case AUFS_CTL_RDU:
29361 + err = au_rdu(file, &rdu);
29362 + if (unlikely(err))
29365 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29366 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29367 + e = copy_to_user(p, &rdu, sizeof(rdu));
29368 + if (unlikely(e)) {
29373 + case AUFS_CTL_RDU_INO:
29374 + err = au_rdu_ino(file, &rdu);
29378 + /* err = -ENOTTY; */
29387 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29388 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29389 +++ linux/fs/aufs/rwsem.h 2022-10-26 22:30:38.472648858 +0200
29391 +/* SPDX-License-Identifier: GPL-2.0 */
29393 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29395 + * This program, aufs is free software; you can redistribute it and/or modify
29396 + * it under the terms of the GNU General Public License as published by
29397 + * the Free Software Foundation; either version 2 of the License, or
29398 + * (at your option) any later version.
29400 + * This program is distributed in the hope that it will be useful,
29401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29403 + * GNU General Public License for more details.
29405 + * You should have received a copy of the GNU General Public License
29406 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29410 + * simple read-write semaphore wrappers
29413 +#ifndef __AUFS_RWSEM_H__
29414 +#define __AUFS_RWSEM_H__
29418 +#include "debug.h"
29420 +/* in the future, the name 'au_rwsem' will be totally gone */
29421 +#define au_rwsem rw_semaphore
29423 +/* to debug easier, do not make them inlined functions */
29424 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29426 +#ifdef CONFIG_LOCKDEP
29427 +/* rwsem_is_locked() is unusable */
29428 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29429 + && !lockdep_recursing(current) \
29431 + && !lockdep_is_held_type(rw, 1))
29432 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29433 + && !lockdep_recursing(current) \
29435 + && !lockdep_is_held_type(rw, 0))
29436 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29437 + && !lockdep_recursing(current) \
29439 + && !lockdep_is_held(rw))
29440 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29441 + && !lockdep_recursing(current) \
29443 + && lockdep_is_held(rw))
29445 +#define AuRwMustReadLock(rw) do {} while (0)
29446 +#define AuRwMustWriteLock(rw) do {} while (0)
29447 +#define AuRwMustAnyLock(rw) do {} while (0)
29448 +#define AuRwDestroy(rw) do {} while (0)
29451 +#define au_rw_init(rw) init_rwsem(rw)
29453 +#define au_rw_init_wlock(rw) do { \
29454 + au_rw_init(rw); \
29455 + down_write(rw); \
29458 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29459 + au_rw_init(rw); \
29460 + down_write_nested(rw, lsc); \
29463 +#define au_rw_read_lock(rw) down_read(rw)
29464 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29465 +#define au_rw_read_unlock(rw) up_read(rw)
29466 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29467 +#define au_rw_write_lock(rw) down_write(rw)
29468 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29469 +#define au_rw_write_unlock(rw) up_write(rw)
29470 +/* why is not _nested version defined? */
29471 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29472 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29474 +#endif /* __KERNEL__ */
29475 +#endif /* __AUFS_RWSEM_H__ */
29476 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29477 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29478 +++ linux/fs/aufs/sbinfo.c 2022-10-26 22:30:38.472648858 +0200
29480 +// SPDX-License-Identifier: GPL-2.0
29482 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29484 + * This program, aufs is free software; you can redistribute it and/or modify
29485 + * it under the terms of the GNU General Public License as published by
29486 + * the Free Software Foundation; either version 2 of the License, or
29487 + * (at your option) any later version.
29489 + * This program is distributed in the hope that it will be useful,
29490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29492 + * GNU General Public License for more details.
29494 + * You should have received a copy of the GNU General Public License
29495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29499 + * superblock private data
29502 +#include <linux/iversion.h>
29506 + * they are necessary regardless sysfs is disabled.
29508 +void au_si_free(struct kobject *kobj)
29511 + struct au_sbinfo *sbinfo;
29512 + char *locked __maybe_unused; /* debug only */
29514 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29515 + for (i = 0; i < AuPlink_NHASH; i++)
29516 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29517 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29519 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29520 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29521 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29522 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29524 + dbgaufs_si_fin(sbinfo);
29525 + au_rw_write_lock(&sbinfo->si_rwsem);
29526 + au_br_free(sbinfo);
29527 + au_rw_write_unlock(&sbinfo->si_rwsem);
29529 + au_kfree_try_rcu(sbinfo->si_branch);
29530 + mutex_destroy(&sbinfo->si_xib_mtx);
29531 + AuRwDestroy(&sbinfo->si_rwsem);
29533 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29534 + /* si_nfiles is waited too */
29535 + au_kfree_rcu(sbinfo);
29538 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29540 + struct au_sbinfo *sbinfo;
29544 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29545 + if (unlikely(!sbinfo))
29548 + /* will be reallocated separately */
29549 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29550 + if (unlikely(!sbinfo->si_branch))
29553 + err = sysaufs_si_init(sbinfo);
29555 + dbgaufs_si_null(sbinfo);
29556 + err = dbgaufs_si_init(sbinfo);
29557 + if (unlikely(err))
29558 + kobject_put(&sbinfo->si_kobj);
29560 + if (unlikely(err))
29563 + au_nwt_init(&sbinfo->si_nowait);
29564 + au_rw_init_wlock(&sbinfo->si_rwsem);
29566 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29567 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29569 + sbinfo->si_bbot = -1;
29570 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29572 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29573 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29574 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29575 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29577 + au_fhsm_init(sbinfo);
29579 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29581 + sbinfo->si_xino_jiffy = jiffies;
29582 + sbinfo->si_xino_expire
29583 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29584 + mutex_init(&sbinfo->si_xib_mtx);
29585 + /* leave si_xib_last_pindex and si_xib_next_bit */
29587 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29589 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29590 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29591 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29592 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29594 + for (i = 0; i < AuPlink_NHASH; i++)
29595 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29596 + init_waitqueue_head(&sbinfo->si_plink_wq);
29597 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29599 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29601 + /* with getattr by default */
29602 + sbinfo->si_iop_array = aufs_iop;
29604 + /* leave other members for sysaufs and si_mnt. */
29605 + sbinfo->si_sb = sb;
29607 + sb->s_fs_info = sbinfo;
29610 + return sbinfo; /* success */
29613 + au_kfree_try_rcu(sbinfo->si_branch);
29615 + au_kfree_rcu(sbinfo);
29617 + return ERR_PTR(err);
29620 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29623 + struct au_branch **brp;
29625 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29628 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29629 + if (unlikely(!sz))
29630 + sz = sizeof(*brp);
29631 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29634 + sbinfo->si_branch = brp;
29641 +/* ---------------------------------------------------------------------- */
29643 +unsigned int au_sigen_inc(struct super_block *sb)
29645 + unsigned int gen;
29646 + struct inode *inode;
29648 + SiMustWriteLock(sb);
29650 + gen = ++au_sbi(sb)->si_generation;
29651 + au_update_digen(sb->s_root);
29652 + inode = d_inode(sb->s_root);
29653 + au_update_iigen(inode, /*half*/0);
29654 + inode_inc_iversion(inode);
29658 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29660 + aufs_bindex_t br_id;
29662 + struct au_sbinfo *sbinfo;
29664 + SiMustWriteLock(sb);
29666 + sbinfo = au_sbi(sb);
29667 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29668 + br_id = ++sbinfo->si_last_br_id;
29669 + AuDebugOn(br_id < 0);
29670 + if (br_id && au_br_index(sb, br_id) < 0)
29677 +/* ---------------------------------------------------------------------- */
29679 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29680 +int si_read_lock(struct super_block *sb, int flags)
29685 + if (au_ftest_lock(flags, FLUSH))
29686 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29688 + si_noflush_read_lock(sb);
29689 + err = au_plink_maint(sb, flags);
29690 + if (unlikely(err))
29691 + si_read_unlock(sb);
29696 +int si_write_lock(struct super_block *sb, int flags)
29700 + if (au_ftest_lock(flags, FLUSH))
29701 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29703 + si_noflush_write_lock(sb);
29704 + err = au_plink_maint(sb, flags);
29705 + if (unlikely(err))
29706 + si_write_unlock(sb);
29711 +/* dentry and super_block lock. call at entry point */
29712 +int aufs_read_lock(struct dentry *dentry, int flags)
29715 + struct super_block *sb;
29717 + sb = dentry->d_sb;
29718 + err = si_read_lock(sb, flags);
29719 + if (unlikely(err))
29722 + if (au_ftest_lock(flags, DW))
29723 + di_write_lock_child(dentry);
29725 + di_read_lock_child(dentry, flags);
29727 + if (au_ftest_lock(flags, GEN)) {
29728 + err = au_digen_test(dentry, au_sigen(sb));
29729 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29730 + AuDebugOn(!err && au_dbrange_test(dentry));
29732 + err = au_dbrange_test(dentry);
29733 + if (unlikely(err))
29734 + aufs_read_unlock(dentry, flags);
29741 +void aufs_read_unlock(struct dentry *dentry, int flags)
29743 + if (au_ftest_lock(flags, DW))
29744 + di_write_unlock(dentry);
29746 + di_read_unlock(dentry, flags);
29747 + si_read_unlock(dentry->d_sb);
29750 +void aufs_write_lock(struct dentry *dentry)
29752 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29753 + di_write_lock_child(dentry);
29756 +void aufs_write_unlock(struct dentry *dentry)
29758 + di_write_unlock(dentry);
29759 + si_write_unlock(dentry->d_sb);
29762 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29765 + unsigned int sigen;
29766 + struct super_block *sb;
29769 + err = si_read_lock(sb, flags);
29770 + if (unlikely(err))
29773 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29775 + if (au_ftest_lock(flags, GEN)) {
29776 + sigen = au_sigen(sb);
29777 + err = au_digen_test(d1, sigen);
29778 + AuDebugOn(!err && au_dbrange_test(d1));
29780 + err = au_digen_test(d2, sigen);
29781 + AuDebugOn(!err && au_dbrange_test(d2));
29783 + if (unlikely(err))
29784 + aufs_read_and_write_unlock2(d1, d2);
29791 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29793 + di_write_unlock2(d1, d2);
29794 + si_read_unlock(d1->d_sb);
29796 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29797 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29798 +++ linux/fs/aufs/super.c 2022-10-26 22:30:38.472648858 +0200
29800 +// SPDX-License-Identifier: GPL-2.0
29802 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29804 + * This program, aufs is free software; you can redistribute it and/or modify
29805 + * it under the terms of the GNU General Public License as published by
29806 + * the Free Software Foundation; either version 2 of the License, or
29807 + * (at your option) any later version.
29809 + * This program is distributed in the hope that it will be useful,
29810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29812 + * GNU General Public License for more details.
29814 + * You should have received a copy of the GNU General Public License
29815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29819 + * mount and super_block operations
29822 +#include <linux/iversion.h>
29823 +#include <linux/mm.h>
29824 +#include <linux/seq_file.h>
29825 +#include <linux/statfs.h>
29826 +#include <linux/vmalloc.h>
29830 + * super_operations
29832 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29834 + struct au_icntnr *c;
29836 + c = au_cache_alloc_icntnr();
29838 + au_icntnr_init(c);
29839 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29840 + c->iinfo.ii_hinode = NULL;
29841 + return &c->vfs_inode;
29846 +static void aufs_destroy_inode(struct inode *inode)
29848 + if (!au_is_bad_inode(inode))
29849 + au_iinfo_fin(inode);
29852 +static void aufs_free_inode(struct inode *inode)
29854 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29857 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29859 + struct inode *inode;
29862 + inode = iget_locked(sb, ino);
29863 + if (unlikely(!inode)) {
29864 + inode = ERR_PTR(-ENOMEM);
29867 + if (!(inode->i_state & I_NEW))
29870 + err = au_xigen_new(inode);
29872 + err = au_iinfo_init(inode);
29874 + inode_inc_iversion(inode);
29876 + iget_failed(inode);
29877 + inode = ERR_PTR(err);
29881 + /* never return NULL */
29882 + AuDebugOn(!inode);
29883 + AuTraceErrPtr(inode);
29887 +/* lock free root dinfo */
29888 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29891 + aufs_bindex_t bindex, bbot;
29892 + struct path path;
29893 + struct au_hdentry *hdp;
29894 + struct au_branch *br;
29895 + au_br_perm_str_t perm;
29898 + bbot = au_sbbot(sb);
29900 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29901 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29902 + br = au_sbr(sb, bindex);
29903 + path.mnt = au_br_mnt(br);
29904 + path.dentry = hdp->hd_dentry;
29905 + err = au_seq_path(seq, &path);
29907 + au_optstr_br_perm(&perm, br->br_perm);
29908 + seq_printf(seq, "=%s", perm.a);
29909 + if (bindex != bbot)
29910 + seq_putc(seq, ':');
29913 + if (unlikely(err || seq_has_overflowed(seq)))
29919 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29920 + const char *append)
29925 + while (*pat != ':')
29928 + strcpy(p, append);
29929 + AuDebugOn(strlen(fmt) >= len);
29932 +static void au_show_wbr_create(struct seq_file *m, int v,
29933 + struct au_sbinfo *sbinfo)
29937 + struct au_wbr_mfs *mfs;
29939 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29941 + seq_puts(m, ",create=");
29942 + pat = au_optstr_wbr_create(v);
29943 + mfs = &sbinfo->si_wbr_mfs;
29945 + case AuWbrCreate_TDP:
29946 + case AuWbrCreate_RR:
29947 + case AuWbrCreate_MFS:
29948 + case AuWbrCreate_PMFS:
29949 + seq_puts(m, pat);
29951 + case AuWbrCreate_MFSRR:
29952 + case AuWbrCreate_TDMFS:
29953 + case AuWbrCreate_PMFSRR:
29954 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29955 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29957 + case AuWbrCreate_MFSV:
29958 + case AuWbrCreate_PMFSV:
29959 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29960 + seq_printf(m, fmt,
29961 + jiffies_to_msecs(mfs->mfs_expire)
29964 + case AuWbrCreate_MFSRRV:
29965 + case AuWbrCreate_TDMFSV:
29966 + case AuWbrCreate_PMFSRRV:
29967 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29968 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29969 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29976 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29978 +#ifdef CONFIG_SYSFS
29982 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29983 + aufs_bindex_t bindex, brid;
29984 + struct qstr *name;
29986 + struct dentry *d, *h_root;
29987 + struct au_branch *br;
29989 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29992 + f = au_sbi(sb)->si_xib;
29996 + /* stop printing the default xino path on the first writable branch */
29998 + bindex = au_xi_root(sb, f->f_path.dentry);
29999 + if (bindex >= 0) {
30000 + br = au_sbr_sb(sb, bindex);
30001 + h_root = au_br_dentry(br);
30004 + d = f->f_path.dentry;
30005 + name = &d->d_name;
30006 + /* safe ->d_parent because the file is unlinked */
30007 + if (d->d_parent == h_root
30008 + && name->len == len
30009 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30012 + seq_puts(seq, ",xino=");
30013 + err = au_xino_path(seq, f);
30020 +/* seq_file will re-call me in case of too long string */
30021 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30024 + unsigned int mnt_flags, v;
30025 + struct super_block *sb;
30026 + struct au_sbinfo *sbinfo;
30028 +#define AuBool(name, str) do { \
30029 + v = au_opt_test(mnt_flags, name); \
30030 + if (v != au_opt_test(AuOpt_Def, name)) \
30031 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30034 +#define AuStr(name, str) do { \
30035 + v = mnt_flags & AuOptMask_##name; \
30036 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30037 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30040 +#define AuUInt(name, str, val) do { \
30041 + if (val != AUFS_##name##_DEF) \
30042 + seq_printf(m, "," #str "=%u", val); \
30045 + sb = dentry->d_sb;
30046 + if (sb->s_flags & SB_POSIXACL)
30047 + seq_puts(m, ",acl");
30048 +#if 0 /* reserved for future use */
30049 + if (sb->s_flags & SB_I_VERSION)
30050 + seq_puts(m, ",i_version");
30053 + /* lock free root dinfo */
30054 + si_noflush_read_lock(sb);
30055 + sbinfo = au_sbi(sb);
30056 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30058 + mnt_flags = au_mntflags(sb);
30059 + if (au_opt_test(mnt_flags, XINO)) {
30060 + err = au_show_xino(m, sb);
30061 + if (unlikely(err))
30064 + seq_puts(m, ",noxino");
30066 + AuBool(TRUNC_XINO, trunc_xino);
30067 + AuStr(UDBA, udba);
30068 + AuBool(SHWH, shwh);
30069 + AuBool(PLINK, plink);
30070 + AuBool(DIO, dio);
30071 + AuBool(DIRPERM1, dirperm1);
30073 + v = sbinfo->si_wbr_create;
30074 + if (v != AuWbrCreate_Def)
30075 + au_show_wbr_create(m, v, sbinfo);
30077 + v = sbinfo->si_wbr_copyup;
30078 + if (v != AuWbrCopyup_Def)
30079 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30081 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30082 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30083 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30085 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30087 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30088 + AuUInt(RDCACHE, rdcache, v);
30090 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30091 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30093 + au_fhsm_show(m, sbinfo);
30095 + AuBool(DIRREN, dirren);
30096 + AuBool(SUM, sum);
30097 + /* AuBool(SUM_W, wsum); */
30098 + AuBool(WARN_PERM, warn_perm);
30099 + AuBool(VERBOSE, verbose);
30102 + /* be sure to print "br:" last */
30103 + if (!sysaufs_brs) {
30104 + seq_puts(m, ",br:");
30105 + au_show_brs(m, sb);
30107 + si_read_unlock(sb);
30115 +/* ---------------------------------------------------------------------- */
30117 +/* sum mode which returns the summation for statfs(2) */
30119 +static u64 au_add_till_max(u64 a, u64 b)
30127 + return ULLONG_MAX;
30130 +static u64 au_mul_till_max(u64 a, long mul)
30138 + return ULLONG_MAX;
30141 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30144 + long bsize, factor;
30145 + u64 blocks, bfree, bavail, files, ffree;
30146 + aufs_bindex_t bbot, bindex, i;
30147 + unsigned char shared;
30148 + struct path h_path;
30149 + struct super_block *h_sb;
30152 + bsize = LONG_MAX;
30158 + bbot = au_sbbot(sb);
30159 + for (bindex = 0; bindex <= bbot; bindex++) {
30160 + h_path.mnt = au_sbr_mnt(sb, bindex);
30161 + h_sb = h_path.mnt->mnt_sb;
30163 + for (i = 0; !shared && i < bindex; i++)
30164 + shared = (au_sbr_sb(sb, i) == h_sb);
30168 + /* sb->s_root for NFS is unreliable */
30169 + h_path.dentry = h_path.mnt->mnt_root;
30170 + err = vfs_statfs(&h_path, buf);
30171 + if (unlikely(err))
30174 + if (bsize > buf->f_bsize) {
30176 + * we will reduce bsize, so we have to expand blocks
30177 + * etc. to match them again
30179 + factor = (bsize / buf->f_bsize);
30180 + blocks = au_mul_till_max(blocks, factor);
30181 + bfree = au_mul_till_max(bfree, factor);
30182 + bavail = au_mul_till_max(bavail, factor);
30183 + bsize = buf->f_bsize;
30186 + factor = (buf->f_bsize / bsize);
30187 + blocks = au_add_till_max(blocks,
30188 + au_mul_till_max(buf->f_blocks, factor));
30189 + bfree = au_add_till_max(bfree,
30190 + au_mul_till_max(buf->f_bfree, factor));
30191 + bavail = au_add_till_max(bavail,
30192 + au_mul_till_max(buf->f_bavail, factor));
30193 + files = au_add_till_max(files, buf->f_files);
30194 + ffree = au_add_till_max(ffree, buf->f_ffree);
30197 + buf->f_bsize = bsize;
30198 + buf->f_blocks = blocks;
30199 + buf->f_bfree = bfree;
30200 + buf->f_bavail = bavail;
30201 + buf->f_files = files;
30202 + buf->f_ffree = ffree;
30203 + buf->f_frsize = 0;
30209 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30212 + struct path h_path;
30213 + struct super_block *sb;
30215 + /* lock free root dinfo */
30216 + sb = dentry->d_sb;
30217 + si_noflush_read_lock(sb);
30218 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30219 + /* sb->s_root for NFS is unreliable */
30220 + h_path.mnt = au_sbr_mnt(sb, 0);
30221 + h_path.dentry = h_path.mnt->mnt_root;
30222 + err = vfs_statfs(&h_path, buf);
30224 + err = au_statfs_sum(sb, buf);
30225 + si_read_unlock(sb);
30228 + buf->f_type = AUFS_SUPER_MAGIC;
30229 + buf->f_namelen = AUFS_MAX_NAMELEN;
30230 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30232 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30237 +/* ---------------------------------------------------------------------- */
30239 +static int aufs_sync_fs(struct super_block *sb, int wait)
30242 + aufs_bindex_t bbot, bindex;
30243 + struct au_branch *br;
30244 + struct super_block *h_sb;
30247 + si_noflush_read_lock(sb);
30248 + bbot = au_sbbot(sb);
30249 + for (bindex = 0; bindex <= bbot; bindex++) {
30250 + br = au_sbr(sb, bindex);
30251 + if (!au_br_writable(br->br_perm))
30254 + h_sb = au_sbr_sb(sb, bindex);
30255 + e = vfsub_sync_filesystem(h_sb);
30256 + if (unlikely(e && !err))
30258 + /* go on even if an error happens */
30260 + si_read_unlock(sb);
30265 +/* ---------------------------------------------------------------------- */
30267 +/* final actions when unmounting a file system */
30268 +static void aufs_put_super(struct super_block *sb)
30270 + struct au_sbinfo *sbinfo;
30272 + sbinfo = au_sbi(sb);
30274 + kobject_put(&sbinfo->si_kobj);
30277 +/* ---------------------------------------------------------------------- */
30279 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30280 + struct super_block *sb, void *arg)
30283 + unsigned long long n, sz;
30290 + if (*hint > ULLONG_MAX / sizeof(array)) {
30291 + array = ERR_PTR(-EMFILE);
30292 + pr_err("hint %llu\n", *hint);
30296 + sz = sizeof(array) * *hint;
30297 + array = kzalloc(sz, GFP_NOFS);
30298 + if (unlikely(!array))
30299 + array = vzalloc(sz);
30300 + if (unlikely(!array)) {
30301 + array = ERR_PTR(-ENOMEM);
30305 + n = cb(sb, array, *hint, arg);
30306 + AuDebugOn(n > *hint);
30313 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30314 + unsigned long long max __maybe_unused,
30317 + unsigned long long n;
30318 + struct inode **p, *inode;
30319 + struct list_head *head;
30324 + spin_lock(&sb->s_inode_list_lock);
30325 + list_for_each_entry(inode, head, i_sb_list) {
30326 + if (!au_is_bad_inode(inode)
30327 + && au_ii(inode)->ii_btop >= 0) {
30328 + spin_lock(&inode->i_lock);
30329 + if (atomic_read(&inode->i_count)) {
30333 + AuDebugOn(n > max);
30335 + spin_unlock(&inode->i_lock);
30338 + spin_unlock(&sb->s_inode_list_lock);
30343 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30345 + struct au_sbinfo *sbi;
30347 + sbi = au_sbi(sb);
30348 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30349 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30352 +void au_iarray_free(struct inode **a, unsigned long long max)
30354 + unsigned long long ull;
30356 + for (ull = 0; ull < max; ull++)
30361 +/* ---------------------------------------------------------------------- */
30364 + * refresh dentry and inode at remount time.
30366 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30367 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30368 + struct dentry *parent)
30372 + di_write_lock_child(dentry);
30373 + di_read_lock_parent(parent, AuLock_IR);
30374 + err = au_refresh_dentry(dentry, parent);
30375 + if (!err && dir_flags)
30376 + au_hn_reset(d_inode(dentry), dir_flags);
30377 + di_read_unlock(parent, AuLock_IR);
30378 + di_write_unlock(dentry);
30383 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30384 + struct au_sbinfo *sbinfo,
30385 + const unsigned int dir_flags, unsigned int do_idop)
30388 + struct dentry *parent;
30391 + parent = dget_parent(dentry);
30392 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30393 + if (d_really_is_positive(dentry)) {
30394 + if (!d_is_dir(dentry))
30395 + err = au_do_refresh(dentry, /*dir_flags*/0,
30398 + err = au_do_refresh(dentry, dir_flags, parent);
30399 + if (unlikely(err))
30400 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30403 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30404 + AuDbgDentry(dentry);
30410 + au_refresh_dop(dentry, /*force_reval*/0);
30412 + au_refresh_dop(dentry, /*force_reval*/1);
30418 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30420 + int err, i, j, ndentry, e;
30421 + unsigned int sigen;
30422 + struct au_dcsub_pages dpages;
30423 + struct au_dpage *dpage;
30424 + struct dentry **dentries, *d;
30425 + struct au_sbinfo *sbinfo;
30426 + struct dentry *root = sb->s_root;
30427 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30430 + au_refresh_dop(root, /*force_reval*/0);
30432 + err = au_dpages_init(&dpages, GFP_NOFS);
30433 + if (unlikely(err))
30435 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30436 + if (unlikely(err))
30439 + sigen = au_sigen(sb);
30440 + sbinfo = au_sbi(sb);
30441 + for (i = 0; i < dpages.ndpage; i++) {
30442 + dpage = dpages.dpages + i;
30443 + dentries = dpage->dentries;
30444 + ndentry = dpage->ndentry;
30445 + for (j = 0; j < ndentry; j++) {
30447 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30449 + if (unlikely(e && !err))
30451 + /* go on even err */
30456 + au_dpages_free(&dpages);
30461 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30464 + unsigned int sigen;
30465 + unsigned long long max, ull;
30466 + struct inode *inode, **array;
30468 + array = au_iarray_alloc(sb, &max);
30469 + err = PTR_ERR(array);
30470 + if (IS_ERR(array))
30474 + sigen = au_sigen(sb);
30475 + for (ull = 0; ull < max; ull++) {
30476 + inode = array[ull];
30477 + if (unlikely(!inode))
30481 + ii_write_lock_child(inode);
30482 + if (au_iigen(inode, NULL) != sigen) {
30483 + e = au_refresh_hinode_self(inode);
30484 + if (unlikely(e)) {
30485 + au_refresh_iop(inode, /*force_getattr*/1);
30486 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30489 + /* go on even if err */
30492 + if (!e && do_idop)
30493 + au_refresh_iop(inode, /*force_getattr*/0);
30494 + ii_write_unlock(inode);
30497 + au_iarray_free(array, max);
30503 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30506 + unsigned int udba;
30507 + aufs_bindex_t bindex, bbot;
30508 + struct dentry *root;
30509 + struct inode *inode;
30510 + struct au_branch *br;
30511 + struct au_sbinfo *sbi;
30513 + au_sigen_inc(sb);
30514 + sbi = au_sbi(sb);
30515 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30517 + root = sb->s_root;
30518 + DiMustNoWaiters(root);
30519 + inode = d_inode(root);
30520 + IiMustNoWaiters(inode);
30522 + udba = au_opt_udba(sb);
30523 + bbot = au_sbbot(sb);
30524 + for (bindex = 0; bindex <= bbot; bindex++) {
30525 + br = au_sbr(sb, bindex);
30526 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30527 + if (unlikely(err))
30528 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30530 + /* go on even if err */
30532 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30535 + if (au_ftest_si(sbi, NO_DREVAL)) {
30536 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30537 + sb->s_d_op = &aufs_dop_noreval;
30538 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30539 + sbi->si_iop_array = aufs_iop_nogetattr;
30541 + AuDebugOn(sb->s_d_op == &aufs_dop);
30542 + sb->s_d_op = &aufs_dop;
30543 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30544 + sbi->si_iop_array = aufs_iop;
30546 + pr_info("reset to %ps and %ps\n",
30547 + sb->s_d_op, sbi->si_iop_array);
30550 + di_write_unlock(root);
30551 + err = au_refresh_d(sb, do_idop);
30552 + e = au_refresh_i(sb, do_idop);
30553 + if (unlikely(e && !err))
30555 + /* aufs_write_lock() calls ..._child() */
30556 + di_write_lock_child(root);
30558 + au_cpup_attr_all(inode, /*force*/1);
30560 + if (unlikely(err))
30561 + AuIOErr("refresh failed, ignored, %d\n", err);
30564 +const struct super_operations aufs_sop = {
30565 + .alloc_inode = aufs_alloc_inode,
30566 + .destroy_inode = aufs_destroy_inode,
30567 + .free_inode = aufs_free_inode,
30568 + /* always deleting, no clearing */
30569 + .drop_inode = generic_delete_inode,
30570 + .show_options = aufs_show_options,
30571 + .statfs = aufs_statfs,
30572 + .put_super = aufs_put_super,
30573 + .sync_fs = aufs_sync_fs
30576 +/* ---------------------------------------------------------------------- */
30578 +int au_alloc_root(struct super_block *sb)
30581 + struct inode *inode;
30582 + struct dentry *root;
30585 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30586 + err = PTR_ERR(inode);
30587 + if (IS_ERR(inode))
30590 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30591 + inode->i_fop = &aufs_dir_fop;
30592 + inode->i_mode = S_IFDIR;
30593 + set_nlink(inode, 2);
30594 + unlock_new_inode(inode);
30596 + root = d_make_root(inode);
30597 + if (unlikely(!root))
30599 + err = PTR_ERR(root);
30600 + if (IS_ERR(root))
30603 + err = au_di_init(root);
30605 + sb->s_root = root;
30606 + return 0; /* success */
30614 +/* ---------------------------------------------------------------------- */
30616 +static void aufs_kill_sb(struct super_block *sb)
30618 + struct au_sbinfo *sbinfo;
30619 + struct dentry *root;
30621 + sbinfo = au_sbi(sb);
30625 + au_sbilist_del(sb);
30627 + root = sb->s_root;
30629 + aufs_write_lock(root);
30631 + __si_write_lock(sb);
30634 + if (sbinfo->si_wbr_create_ops->fin)
30635 + sbinfo->si_wbr_create_ops->fin(sb);
30636 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30637 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30638 + au_remount_refresh(sb, /*do_idop*/0);
30640 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30641 + au_plink_put(sb, /*verbose*/1);
30644 + au_dr_opt_flush(sb);
30647 + aufs_write_unlock(root);
30649 + __si_write_unlock(sb);
30651 + sbinfo->si_sb = NULL;
30652 + au_nwt_flush(&sbinfo->si_nowait);
30655 + kill_anon_super(sb);
30658 +struct file_system_type aufs_fs_type = {
30659 + .name = AUFS_FSTYPE,
30660 + /* a race between rename and others */
30661 + .fs_flags = FS_RENAME_DOES_D_MOVE
30663 + /*| FS_ALLOW_IDMAP*/
30665 + .init_fs_context = aufs_fsctx_init,
30666 + .parameters = aufs_fsctx_paramspec,
30667 + .kill_sb = aufs_kill_sb,
30668 + /* no need to __module_get() and module_put(). */
30669 + .owner = THIS_MODULE,
30671 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30672 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30673 +++ linux/fs/aufs/super.h 2022-10-26 22:30:38.472648858 +0200
30675 +/* SPDX-License-Identifier: GPL-2.0 */
30677 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30679 + * This program, aufs is free software; you can redistribute it and/or modify
30680 + * it under the terms of the GNU General Public License as published by
30681 + * the Free Software Foundation; either version 2 of the License, or
30682 + * (at your option) any later version.
30684 + * This program is distributed in the hope that it will be useful,
30685 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30686 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30687 + * GNU General Public License for more details.
30689 + * You should have received a copy of the GNU General Public License
30690 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30694 + * super_block operations
30697 +#ifndef __AUFS_SUPER_H__
30698 +#define __AUFS_SUPER_H__
30702 +#include <linux/fs.h>
30703 +#include <linux/kobject.h>
30706 +#include "rwsem.h"
30709 +/* policies to select one among multiple writable branches */
30710 +struct au_wbr_copyup_operations {
30711 + int (*copyup)(struct dentry *dentry);
30714 +#define AuWbr_DIR 1 /* target is a dir */
30715 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30717 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30718 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30719 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30721 +struct au_wbr_create_operations {
30722 + int (*create)(struct dentry *dentry, unsigned int flags);
30723 + int (*init)(struct super_block *sb);
30724 + int (*fin)(struct super_block *sb);
30727 +struct au_wbr_mfs {
30728 + struct mutex mfs_lock; /* protect this structure */
30729 + unsigned long mfs_jiffy;
30730 + unsigned long mfs_expire;
30731 + aufs_bindex_t mfs_bindex;
30733 + unsigned long long mfsrr_bytes;
30734 + unsigned long long mfsrr_watermark;
30737 +#define AuPlink_NHASH 100
30738 +static inline int au_plink_hash(ino_t ino)
30740 + return ino % AuPlink_NHASH;
30743 +/* File-based Hierarchical Storage Management */
30745 +#ifdef CONFIG_AUFS_FHSM
30746 + /* allow only one process who can receive the notification */
30747 + spinlock_t fhsm_spin;
30749 + wait_queue_head_t fhsm_wqh;
30750 + atomic_t fhsm_readable;
30752 + /* these are protected by si_rwsem */
30753 + unsigned long fhsm_expire;
30754 + aufs_bindex_t fhsm_bottom;
30759 +struct au_sbinfo {
30760 + /* nowait tasks in the system-wide workqueue */
30761 + struct au_nowait_tasks si_nowait;
30764 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30765 + * rwsem for au_sbinfo is necessary.
30767 + struct au_rwsem si_rwsem;
30770 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30773 + au_lcnt_t si_ninodes, si_nfiles;
30775 + /* branch management */
30776 + unsigned int si_generation;
30778 + /* see AuSi_ flags */
30779 + unsigned char au_si_status;
30781 + aufs_bindex_t si_bbot;
30783 + /* dirty trick to keep br_id plus */
30784 + unsigned int si_last_br_id :
30785 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30786 + struct au_branch **si_branch;
30788 + /* policy to select a writable branch */
30789 + unsigned char si_wbr_copyup;
30790 + unsigned char si_wbr_create;
30791 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30792 + struct au_wbr_create_operations *si_wbr_create_ops;
30794 + /* round robin */
30795 + atomic_t si_wbr_rr_next;
30797 + /* most free space */
30798 + struct au_wbr_mfs si_wbr_mfs;
30800 + /* File-based Hierarchical Storage Management */
30801 + struct au_fhsm si_fhsm;
30803 + /* mount flags */
30804 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30805 + unsigned int si_mntflags;
30807 + /* external inode number (bitmap and translation table) */
30808 + loff_t si_ximaxent; /* max entries in a xino */
30810 + struct file *si_xib;
30811 + struct mutex si_xib_mtx; /* protect xib members */
30812 + unsigned long *si_xib_buf;
30813 + unsigned long si_xib_last_pindex;
30814 + int si_xib_next_bit;
30816 + unsigned long si_xino_jiffy;
30817 + unsigned long si_xino_expire;
30818 + /* reserved for future use */
30819 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30821 +#ifdef CONFIG_AUFS_EXPORT
30822 + /* i_generation */
30823 + /* todo: make xigen file an array to support many inode numbers */
30824 + struct file *si_xigen;
30825 + atomic_t si_xigen_next;
30828 + /* dirty trick to support atomic_open */
30829 + struct hlist_bl_head si_aopen;
30831 + /* vdir parameters */
30832 + unsigned long si_rdcache; /* max cache time in jiffies */
30833 + unsigned int si_rdblk; /* deblk size */
30834 + unsigned int si_rdhash; /* hash size */
30837 + * If the number of whiteouts are larger than si_dirwh, leave all of
30838 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30839 + * future fsck.aufs or kernel thread will remove them later.
30840 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30842 + unsigned int si_dirwh;
30844 + /* pseudo_link list */
30845 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30846 + wait_queue_head_t si_plink_wq;
30847 + spinlock_t si_plink_maint_lock;
30848 + pid_t si_plink_maint_pid;
30851 + struct hlist_bl_head si_files;
30853 + /* with/without getattr, brother of sb->s_d_op */
30854 + const struct inode_operations *si_iop_array;
30857 + * sysfs and lifetime management.
30858 + * this is not a small structure and it may be a waste of memory in case
30859 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30860 + * but using sysfs is majority.
30862 + struct kobject si_kobj;
30863 +#ifdef CONFIG_DEBUG_FS
30864 + struct dentry *si_dbgaufs;
30865 + struct dentry *si_dbgaufs_plink;
30866 + struct dentry *si_dbgaufs_xib;
30867 +#ifdef CONFIG_AUFS_EXPORT
30868 + struct dentry *si_dbgaufs_xigen;
30872 +#ifdef CONFIG_AUFS_SBILIST
30873 + struct hlist_bl_node si_list;
30876 + /* dirty, necessary for unmounting, sysfs and sysrq */
30877 + struct super_block *si_sb;
30880 +/* sbinfo status flags */
30882 + * set true when refresh_dirs() failed at remount time.
30883 + * then try refreshing dirs at access time again.
30884 + * if it is false, refreshing dirs at access time is unnecessary
30886 +#define AuSi_FAILED_REFRESH_DIR 1
30887 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30888 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30890 +#ifndef CONFIG_AUFS_FHSM
30892 +#define AuSi_FHSM 0
30895 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30896 + unsigned int flag)
30898 + AuRwMustAnyLock(&sbi->si_rwsem);
30899 + return sbi->au_si_status & flag;
30901 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30902 +#define au_fset_si(sbinfo, name) do { \
30903 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30904 + (sbinfo)->au_si_status |= AuSi_##name; \
30906 +#define au_fclr_si(sbinfo, name) do { \
30907 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30908 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30911 +/* ---------------------------------------------------------------------- */
30913 +/* policy to select one among writable branches */
30914 +#define AuWbrCopyup(sbinfo, ...) \
30915 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30916 +#define AuWbrCreate(sbinfo, ...) \
30917 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30919 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30920 +#define AuLock_DW 1 /* write-lock dentry */
30921 +#define AuLock_IR (1 << 1) /* read-lock inode */
30922 +#define AuLock_IW (1 << 2) /* write-lock inode */
30923 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30924 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30925 + /* except RENAME_EXCHANGE */
30926 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30927 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30928 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30929 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30930 +#define au_fset_lock(flags, name) \
30931 + do { (flags) |= AuLock_##name; } while (0)
30932 +#define au_fclr_lock(flags, name) \
30933 + do { (flags) &= ~AuLock_##name; } while (0)
30935 +/* ---------------------------------------------------------------------- */
30938 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30940 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30941 + unsigned long long max, void *arg);
30942 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30943 + struct super_block *sb, void *arg);
30944 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30945 +void au_iarray_free(struct inode **a, unsigned long long max);
30947 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
30948 +extern const struct super_operations aufs_sop;
30949 +int au_alloc_root(struct super_block *sb);
30950 +extern struct file_system_type aufs_fs_type;
30953 +void au_si_free(struct kobject *kobj);
30954 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
30955 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30957 +unsigned int au_sigen_inc(struct super_block *sb);
30958 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30960 +int si_read_lock(struct super_block *sb, int flags);
30961 +int si_write_lock(struct super_block *sb, int flags);
30962 +int aufs_read_lock(struct dentry *dentry, int flags);
30963 +void aufs_read_unlock(struct dentry *dentry, int flags);
30964 +void aufs_write_lock(struct dentry *dentry);
30965 +void aufs_write_unlock(struct dentry *dentry);
30966 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30967 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30969 +/* wbr_policy.c */
30970 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30971 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30972 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30973 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30974 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30977 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30979 +#ifdef CONFIG_AUFS_FHSM
30982 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30986 + spin_lock(&fhsm->fhsm_spin);
30987 + pid = fhsm->fhsm_pid;
30988 + spin_unlock(&fhsm->fhsm_spin);
30993 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30994 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30995 +int au_fhsm_fd(struct super_block *sb, int oflags);
30996 +int au_fhsm_br_alloc(struct au_branch *br);
30997 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30998 +void au_fhsm_fin(struct super_block *sb);
30999 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31000 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31001 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31003 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31005 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31006 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31007 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31008 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31009 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31010 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31011 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31012 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31013 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31016 +/* ---------------------------------------------------------------------- */
31018 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31020 + return sb->s_fs_info;
31023 +/* ---------------------------------------------------------------------- */
31025 +#ifdef CONFIG_AUFS_EXPORT
31026 +int au_test_nfsd(void);
31027 +void au_export_init(struct super_block *sb);
31028 +void au_xigen_inc(struct inode *inode);
31029 +int au_xigen_new(struct inode *inode);
31030 +int au_xigen_set(struct super_block *sb, struct path *path);
31031 +void au_xigen_clr(struct super_block *sb);
31033 +static inline int au_busy_or_stale(void)
31035 + if (!au_test_nfsd())
31040 +AuStubInt0(au_test_nfsd, void)
31041 +AuStubVoid(au_export_init, struct super_block *sb)
31042 +AuStubVoid(au_xigen_inc, struct inode *inode)
31043 +AuStubInt0(au_xigen_new, struct inode *inode)
31044 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31045 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31046 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31047 +#endif /* CONFIG_AUFS_EXPORT */
31049 +/* ---------------------------------------------------------------------- */
31051 +#ifdef CONFIG_AUFS_SBILIST
31053 +extern struct hlist_bl_head au_sbilist;
31055 +static inline void au_sbilist_init(void)
31057 + INIT_HLIST_BL_HEAD(&au_sbilist);
31060 +static inline void au_sbilist_add(struct super_block *sb)
31062 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31065 +static inline void au_sbilist_del(struct super_block *sb)
31067 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31070 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31071 +static inline void au_sbilist_lock(void)
31073 + hlist_bl_lock(&au_sbilist);
31076 +static inline void au_sbilist_unlock(void)
31078 + hlist_bl_unlock(&au_sbilist);
31080 +#define AuGFP_SBILIST GFP_ATOMIC
31082 +AuStubVoid(au_sbilist_lock, void)
31083 +AuStubVoid(au_sbilist_unlock, void)
31084 +#define AuGFP_SBILIST GFP_NOFS
31085 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31087 +AuStubVoid(au_sbilist_init, void)
31088 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31089 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31090 +AuStubVoid(au_sbilist_lock, void)
31091 +AuStubVoid(au_sbilist_unlock, void)
31092 +#define AuGFP_SBILIST GFP_NOFS
31095 +/* ---------------------------------------------------------------------- */
31097 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31100 + * This function is a dynamic '__init' function actually,
31101 + * so the tiny check for si_rwsem is unnecessary.
31103 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31104 +#ifdef CONFIG_DEBUG_FS
31105 + sbinfo->si_dbgaufs = NULL;
31106 + sbinfo->si_dbgaufs_plink = NULL;
31107 + sbinfo->si_dbgaufs_xib = NULL;
31108 +#ifdef CONFIG_AUFS_EXPORT
31109 + sbinfo->si_dbgaufs_xigen = NULL;
31114 +/* ---------------------------------------------------------------------- */
31116 +/* current->atomic_flags */
31117 +/* this value should never corrupt the ones defined in linux/sched.h */
31118 +#define PFA_AUFS 0x10
31120 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31121 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31122 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31124 +static inline int si_pid_test(struct super_block *sb)
31126 + return !!task_test_aufs(current);
31129 +static inline void si_pid_clr(struct super_block *sb)
31131 + AuDebugOn(!task_test_aufs(current));
31132 + task_clear_aufs(current);
31135 +static inline void si_pid_set(struct super_block *sb)
31137 + AuDebugOn(task_test_aufs(current));
31138 + task_set_aufs(current);
31141 +/* ---------------------------------------------------------------------- */
31143 +/* lock superblock. mainly for entry point functions */
31144 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31145 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31146 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31147 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31149 +#define __si_read_trylock_nested(sb) \
31150 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31151 +#define __si_write_trylock_nested(sb) \
31152 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31155 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31156 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31157 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31159 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31160 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31161 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31163 +static inline void si_noflush_read_lock(struct super_block *sb)
31165 + __si_read_lock(sb);
31169 +static inline int si_noflush_read_trylock(struct super_block *sb)
31173 + locked = __si_read_trylock(sb);
31179 +static inline void si_noflush_write_lock(struct super_block *sb)
31181 + __si_write_lock(sb);
31185 +static inline int si_noflush_write_trylock(struct super_block *sb)
31189 + locked = __si_write_trylock(sb);
31195 +#if 0 /* reserved */
31196 +static inline int si_read_trylock(struct super_block *sb, int flags)
31198 + if (au_ftest_lock(flags, FLUSH))
31199 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31200 + return si_noflush_read_trylock(sb);
31204 +static inline void si_read_unlock(struct super_block *sb)
31207 + __si_read_unlock(sb);
31210 +#if 0 /* reserved */
31211 +static inline int si_write_trylock(struct super_block *sb, int flags)
31213 + if (au_ftest_lock(flags, FLUSH))
31214 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31215 + return si_noflush_write_trylock(sb);
31219 +static inline void si_write_unlock(struct super_block *sb)
31222 + __si_write_unlock(sb);
31225 +#if 0 /* reserved */
31226 +static inline void si_downgrade_lock(struct super_block *sb)
31228 + __si_downgrade_lock(sb);
31232 +/* ---------------------------------------------------------------------- */
31234 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31236 + SiMustAnyLock(sb);
31237 + return au_sbi(sb)->si_bbot;
31240 +static inline unsigned int au_mntflags(struct super_block *sb)
31242 + SiMustAnyLock(sb);
31243 + return au_sbi(sb)->si_mntflags;
31246 +static inline unsigned int au_sigen(struct super_block *sb)
31248 + SiMustAnyLock(sb);
31249 + return au_sbi(sb)->si_generation;
31252 +static inline struct au_branch *au_sbr(struct super_block *sb,
31253 + aufs_bindex_t bindex)
31255 + SiMustAnyLock(sb);
31256 + return au_sbi(sb)->si_branch[0 + bindex];
31259 +static inline loff_t au_xi_maxent(struct super_block *sb)
31261 + SiMustAnyLock(sb);
31262 + return au_sbi(sb)->si_ximaxent;
31265 +#endif /* __KERNEL__ */
31266 +#endif /* __AUFS_SUPER_H__ */
31267 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31268 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31269 +++ linux/fs/aufs/sysaufs.c 2022-10-26 22:30:38.472648858 +0200
31271 +// SPDX-License-Identifier: GPL-2.0
31273 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31275 + * This program, aufs is free software; you can redistribute it and/or modify
31276 + * it under the terms of the GNU General Public License as published by
31277 + * the Free Software Foundation; either version 2 of the License, or
31278 + * (at your option) any later version.
31280 + * This program is distributed in the hope that it will be useful,
31281 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31282 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31283 + * GNU General Public License for more details.
31285 + * You should have received a copy of the GNU General Public License
31286 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31290 + * sysfs interface and lifetime management
31291 + * they are necessary regardless sysfs is disabled.
31294 +#include <linux/random.h>
31297 +unsigned long sysaufs_si_mask;
31298 +struct kset *sysaufs_kset;
31300 +#define AuSiAttr(_name) { \
31301 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31302 + .show = sysaufs_si_##_name, \
31305 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31306 +struct attribute *sysaufs_si_attrs[] = {
31307 + &sysaufs_si_attr_xi_path.attr,
31311 +static const struct sysfs_ops au_sbi_ops = {
31312 + .show = sysaufs_si_show
31315 +static struct kobj_type au_sbi_ktype = {
31316 + .release = au_si_free,
31317 + .sysfs_ops = &au_sbi_ops,
31318 + .default_attrs = sysaufs_si_attrs
31321 +/* ---------------------------------------------------------------------- */
31323 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31327 + sbinfo->si_kobj.kset = sysaufs_kset;
31328 + /* cf. sysaufs_name() */
31329 + err = kobject_init_and_add
31330 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31331 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31336 +void sysaufs_fin(void)
31338 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31339 + kset_unregister(sysaufs_kset);
31342 +int __init sysaufs_init(void)
31347 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31348 + } while (!sysaufs_si_mask);
31351 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31352 + if (unlikely(!sysaufs_kset))
31354 + err = PTR_ERR(sysaufs_kset);
31355 + if (IS_ERR(sysaufs_kset))
31357 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31358 + if (unlikely(err))
31359 + kset_unregister(sysaufs_kset);
31364 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31365 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31366 +++ linux/fs/aufs/sysaufs.h 2022-10-26 22:30:38.472648858 +0200
31368 +/* SPDX-License-Identifier: GPL-2.0 */
31370 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31372 + * This program, aufs is free software; you can redistribute it and/or modify
31373 + * it under the terms of the GNU General Public License as published by
31374 + * the Free Software Foundation; either version 2 of the License, or
31375 + * (at your option) any later version.
31377 + * This program is distributed in the hope that it will be useful,
31378 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31379 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31380 + * GNU General Public License for more details.
31382 + * You should have received a copy of the GNU General Public License
31383 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31387 + * sysfs interface and mount lifetime management
31390 +#ifndef __SYSAUFS_H__
31391 +#define __SYSAUFS_H__
31395 +#include <linux/sysfs.h>
31396 +#include "module.h"
31398 +struct super_block;
31401 +struct sysaufs_si_attr {
31402 + struct attribute attr;
31403 + int (*show)(struct seq_file *seq, struct super_block *sb);
31406 +/* ---------------------------------------------------------------------- */
31409 +extern unsigned long sysaufs_si_mask;
31410 +extern struct kset *sysaufs_kset;
31411 +extern struct attribute *sysaufs_si_attrs[];
31412 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31413 +int __init sysaufs_init(void);
31414 +void sysaufs_fin(void);
31416 +/* ---------------------------------------------------------------------- */
31418 +/* some people doesn't like to show a pointer in kernel */
31419 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31421 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31424 +#define SysaufsSiNamePrefix "si_"
31425 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31426 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31428 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31429 + sysaufs_si_id(sbinfo));
31433 +#ifdef CONFIG_SYSFS
31435 +extern struct attribute_group *sysaufs_attr_group;
31437 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31438 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31440 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31441 +#ifdef CONFIG_COMPAT
31442 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31445 +void sysaufs_br_init(struct au_branch *br);
31446 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31447 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31449 +#define sysaufs_brs_init() do {} while (0)
31452 +#define sysaufs_attr_group NULL
31454 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31455 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31456 + struct attribute *attr, char *buf)
31457 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31458 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31459 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31461 +static inline void sysaufs_brs_init(void)
31466 +#endif /* CONFIG_SYSFS */
31468 +#endif /* __KERNEL__ */
31469 +#endif /* __SYSAUFS_H__ */
31470 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31471 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31472 +++ linux/fs/aufs/sysfs.c 2022-10-26 22:30:38.472648858 +0200
31474 +// SPDX-License-Identifier: GPL-2.0
31476 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31478 + * This program, aufs is free software; you can redistribute it and/or modify
31479 + * it under the terms of the GNU General Public License as published by
31480 + * the Free Software Foundation; either version 2 of the License, or
31481 + * (at your option) any later version.
31483 + * This program is distributed in the hope that it will be useful,
31484 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31485 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31486 + * GNU General Public License for more details.
31488 + * You should have received a copy of the GNU General Public License
31489 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31493 + * sysfs interface
31496 +#include <linux/compat.h>
31497 +#include <linux/seq_file.h>
31500 +#ifdef CONFIG_AUFS_FS_MODULE
31501 +/* this entry violates the "one line per file" policy of sysfs */
31502 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31506 + static char *conf =
31507 +/* this file is generated at compiling */
31508 +#include "conf.str"
31511 + err = snprintf(buf, PAGE_SIZE, conf);
31512 + if (unlikely(err >= PAGE_SIZE))
31517 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31520 +static struct attribute *au_attr[] = {
31521 +#ifdef CONFIG_AUFS_FS_MODULE
31522 + &au_config_attr.attr,
31524 + NULL, /* need to NULL terminate the list of attributes */
31527 +static struct attribute_group sysaufs_attr_group_body = {
31531 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31533 +/* ---------------------------------------------------------------------- */
31535 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31539 + SiMustAnyLock(sb);
31542 + if (au_opt_test(au_mntflags(sb), XINO)) {
31543 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31544 + seq_putc(seq, '\n');
31550 + * the lifetime of branch is independent from the entry under sysfs.
31551 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31554 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31555 + aufs_bindex_t bindex, int idx)
31558 + struct path path;
31559 + struct dentry *root;
31560 + struct au_branch *br;
31561 + au_br_perm_str_t perm;
31563 + AuDbg("b%d\n", bindex);
31566 + root = sb->s_root;
31567 + di_read_lock_parent(root, !AuLock_IR);
31568 + br = au_sbr(sb, bindex);
31571 + case AuBrSysfs_BR:
31572 + path.mnt = au_br_mnt(br);
31573 + path.dentry = au_h_dptr(root, bindex);
31574 + err = au_seq_path(seq, &path);
31576 + au_optstr_br_perm(&perm, br->br_perm);
31577 + seq_printf(seq, "=%s\n", perm.a);
31580 + case AuBrSysfs_BRID:
31581 + seq_printf(seq, "%d\n", br->br_id);
31584 + di_read_unlock(root, !AuLock_IR);
31585 + if (unlikely(err || seq_has_overflowed(seq)))
31591 +/* ---------------------------------------------------------------------- */
31593 +static struct seq_file *au_seq(char *p, ssize_t len)
31595 + struct seq_file *seq;
31597 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31599 + /* mutex_init(&seq.lock); */
31602 + return seq; /* success */
31605 + seq = ERR_PTR(-ENOMEM);
31609 +#define SysaufsBr_PREFIX "br"
31610 +#define SysaufsBrid_PREFIX "brid"
31612 +/* todo: file size may exceed PAGE_SIZE */
31613 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31619 + aufs_bindex_t bbot;
31620 + struct au_sbinfo *sbinfo;
31621 + struct super_block *sb;
31622 + struct seq_file *seq;
31624 + struct attribute **cattr;
31626 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31627 + sb = sbinfo->si_sb;
31630 + * prevent a race condition between sysfs and aufs.
31631 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31632 + * prohibits maintaining the sysfs entries.
31633 + * hew we acquire read lock after sysfs_get_active_two().
31634 + * on the other hand, the remount process may maintain the sysfs/aufs
31635 + * entries after acquiring write lock.
31636 + * it can cause a deadlock.
31637 + * simply we gave up processing read here.
31640 + if (unlikely(!si_noflush_read_trylock(sb)))
31643 + seq = au_seq(buf, PAGE_SIZE);
31644 + err = PTR_ERR(seq);
31648 + name = (void *)attr->name;
31649 + cattr = sysaufs_si_attrs;
31651 + if (!strcmp(name, (*cattr)->name)) {
31652 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31659 + if (!strncmp(name, SysaufsBrid_PREFIX,
31660 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31661 + idx = AuBrSysfs_BRID;
31662 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31663 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31664 + sizeof(SysaufsBr_PREFIX) - 1)) {
31665 + idx = AuBrSysfs_BR;
31666 + name += sizeof(SysaufsBr_PREFIX) - 1;
31670 + err = kstrtol(name, 10, &l);
31672 + bbot = au_sbbot(sb);
31674 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31681 + err = seq->count;
31682 + /* sysfs limit */
31683 + if (unlikely(err == PAGE_SIZE))
31686 + au_kfree_rcu(seq);
31688 + si_read_unlock(sb);
31693 +/* ---------------------------------------------------------------------- */
31695 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31699 + aufs_bindex_t bindex, bbot;
31702 + struct seq_file *seq;
31703 + struct au_branch *br;
31705 + si_read_lock(sb, AuLock_FLUSH);
31706 + bbot = au_sbbot(sb);
31712 + buf = (void *)__get_free_page(GFP_NOFS);
31713 + if (unlikely(!buf))
31716 + seq = au_seq(buf, PAGE_SIZE);
31717 + err = PTR_ERR(seq);
31721 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31722 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31723 + /* VERIFY_WRITE */
31724 + err = !access_ok(arg, sizeof(*arg));
31725 + if (unlikely(err))
31728 + br = au_sbr(sb, bindex);
31729 + brid = br->br_id;
31730 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31731 + err = __put_user(brid, &arg->id);
31732 + if (unlikely(err))
31735 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31736 + err = __put_user(br->br_perm, &arg->perm);
31737 + if (unlikely(err))
31740 + err = au_seq_path(seq, &br->br_path);
31741 + if (unlikely(err))
31743 + seq_putc(seq, '\0');
31744 + if (!seq_has_overflowed(seq)) {
31745 + err = copy_to_user(arg->path, seq->buf, seq->count);
31747 + if (unlikely(err))
31754 + if (unlikely(err))
31758 + au_kfree_rcu(seq);
31760 + free_page((unsigned long)buf);
31762 + si_read_unlock(sb);
31766 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31768 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31771 +#ifdef CONFIG_COMPAT
31772 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31774 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31778 +/* ---------------------------------------------------------------------- */
31780 +void sysaufs_br_init(struct au_branch *br)
31783 + struct au_brsysfs *br_sysfs;
31784 + struct attribute *attr;
31786 + br_sysfs = br->br_sysfs;
31787 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31788 + attr = &br_sysfs->attr;
31789 + sysfs_attr_init(attr);
31790 + attr->name = br_sysfs->name;
31791 + attr->mode = 0444;
31796 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31798 + struct au_branch *br;
31799 + struct kobject *kobj;
31800 + struct au_brsysfs *br_sysfs;
31802 + aufs_bindex_t bbot;
31804 + if (!sysaufs_brs)
31807 + kobj = &au_sbi(sb)->si_kobj;
31808 + bbot = au_sbbot(sb);
31809 + for (; bindex <= bbot; bindex++) {
31810 + br = au_sbr(sb, bindex);
31811 + br_sysfs = br->br_sysfs;
31812 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31813 + sysfs_remove_file(kobj, &br_sysfs->attr);
31819 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31822 + aufs_bindex_t bbot;
31823 + struct kobject *kobj;
31824 + struct au_branch *br;
31825 + struct au_brsysfs *br_sysfs;
31827 + if (!sysaufs_brs)
31830 + kobj = &au_sbi(sb)->si_kobj;
31831 + bbot = au_sbbot(sb);
31832 + for (; bindex <= bbot; bindex++) {
31833 + br = au_sbr(sb, bindex);
31834 + br_sysfs = br->br_sysfs;
31835 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31836 + SysaufsBr_PREFIX "%d", bindex);
31837 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31838 + SysaufsBrid_PREFIX "%d", bindex);
31839 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31840 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31841 + if (unlikely(err))
31842 + pr_warn("failed %s under sysfs(%d)\n",
31843 + br_sysfs->name, err);
31848 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31849 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31850 +++ linux/fs/aufs/sysrq.c 2022-10-26 22:30:38.472648858 +0200
31852 +// SPDX-License-Identifier: GPL-2.0
31854 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31856 + * This program, aufs is free software; you can redistribute it and/or modify
31857 + * it under the terms of the GNU General Public License as published by
31858 + * the Free Software Foundation; either version 2 of the License, or
31859 + * (at your option) any later version.
31861 + * This program is distributed in the hope that it will be useful,
31862 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31863 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31864 + * GNU General Public License for more details.
31866 + * You should have received a copy of the GNU General Public License
31867 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31871 + * magic sysrq handler
31874 +/* #include <linux/sysrq.h> */
31875 +#include <linux/writeback.h>
31878 +/* ---------------------------------------------------------------------- */
31880 +static void sysrq_sb(struct super_block *sb)
31883 + struct au_sbinfo *sbinfo;
31884 + struct file *file;
31885 + struct hlist_bl_head *files;
31886 + struct hlist_bl_node *pos;
31887 + struct au_finfo *finfo;
31890 + plevel = au_plevel;
31891 + au_plevel = KERN_WARNING;
31893 + /* since we define pr_fmt, call printk directly */
31894 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31896 + sbinfo = au_sbi(sb);
31897 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31898 + pr("superblock\n");
31901 +#if 0 /* reserved */
31903 + int err, i, j, ndentry;
31904 + struct au_dcsub_pages dpages;
31905 + struct au_dpage *dpage;
31907 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31908 + if (unlikely(err))
31910 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31912 + for (i = 0; i < dpages.ndpage; i++) {
31913 + dpage = dpages.dpages + i;
31914 + ndentry = dpage->ndentry;
31915 + for (j = 0; j < ndentry; j++)
31916 + au_dpri_dentry(dpage->dentries[j]);
31918 + au_dpages_free(&dpages);
31922 + pr("isolated inode\n");
31923 + spin_lock(&sb->s_inode_list_lock);
31924 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31925 + spin_lock(&i->i_lock);
31926 + if (hlist_empty(&i->i_dentry))
31927 + au_dpri_inode(i);
31928 + spin_unlock(&i->i_lock);
31930 + spin_unlock(&sb->s_inode_list_lock);
31933 + files = &au_sbi(sb)->si_files;
31934 + hlist_bl_lock(files);
31935 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31938 + file = finfo->fi_file;
31939 + mode = file_inode(file)->i_mode;
31940 + if (!special_file(mode))
31941 + au_dpri_file(file);
31943 + hlist_bl_unlock(files);
31947 + au_plevel = plevel;
31950 +/* ---------------------------------------------------------------------- */
31952 +/* module parameter */
31953 +static char *aufs_sysrq_key = "a";
31954 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31955 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31957 +static void au_sysrq(int key __maybe_unused)
31959 + struct au_sbinfo *sbinfo;
31960 + struct hlist_bl_node *pos;
31963 + au_sbilist_lock();
31964 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31965 + sysrq_sb(sbinfo->si_sb);
31966 + au_sbilist_unlock();
31970 +static struct sysrq_key_op au_sysrq_op = {
31971 + .handler = au_sysrq,
31972 + .help_msg = "Aufs",
31973 + .action_msg = "Aufs",
31974 + .enable_mask = SYSRQ_ENABLE_DUMP
31977 +/* ---------------------------------------------------------------------- */
31979 +int __init au_sysrq_init(void)
31985 + key = *aufs_sysrq_key;
31986 + if ('a' <= key && key <= 'z')
31987 + err = register_sysrq_key(key, &au_sysrq_op);
31988 + if (unlikely(err))
31989 + pr_err("err %d, sysrq=%c\n", err, key);
31993 +void au_sysrq_fin(void)
31997 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31998 + if (unlikely(err))
31999 + pr_err("err %d (ignored)\n", err);
32001 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32002 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32003 +++ linux/fs/aufs/vdir.c 2022-10-26 22:30:38.472648858 +0200
32005 +// SPDX-License-Identifier: GPL-2.0
32007 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32009 + * This program, aufs is free software; you can redistribute it and/or modify
32010 + * it under the terms of the GNU General Public License as published by
32011 + * the Free Software Foundation; either version 2 of the License, or
32012 + * (at your option) any later version.
32014 + * This program is distributed in the hope that it will be useful,
32015 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32016 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32017 + * GNU General Public License for more details.
32019 + * You should have received a copy of the GNU General Public License
32020 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32024 + * virtual or vertical directory
32027 +#include <linux/iversion.h>
32030 +static unsigned int calc_size(int nlen)
32032 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32035 +static int set_deblk_end(union au_vdir_deblk_p *p,
32036 + union au_vdir_deblk_p *deblk_end)
32038 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32039 + p->de->de_str.len = 0;
32043 + return -1; /* error */
32046 +/* returns true or false */
32047 +static int is_deblk_end(union au_vdir_deblk_p *p,
32048 + union au_vdir_deblk_p *deblk_end)
32050 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32051 + return !p->de->de_str.len;
32055 +static unsigned char *last_deblk(struct au_vdir *vdir)
32057 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32060 +/* ---------------------------------------------------------------------- */
32062 +/* estimate the appropriate size for name hash table */
32063 +unsigned int au_rdhash_est(loff_t sz)
32071 + if (sz < AUFS_RDHASH_DEF)
32072 + n = AUFS_RDHASH_DEF;
32073 + /* pr_info("n %u\n", n); */
32078 + * the allocated memory has to be freed by
32079 + * au_nhash_wh_free() or au_nhash_de_free().
32081 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32083 + struct hlist_head *head;
32087 + sz = sizeof(*nhash->nh_head) * num_hash;
32088 + head = kmalloc(sz, gfp);
32090 + nhash->nh_num = num_hash;
32091 + nhash->nh_head = head;
32092 + for (u = 0; u < num_hash; u++)
32093 + INIT_HLIST_HEAD(head++);
32094 + return 0; /* success */
32100 +static void nhash_count(struct hlist_head *head)
32102 +#if 0 /* debugging */
32104 + struct hlist_node *pos;
32107 + hlist_for_each(pos, head)
32109 + pr_info("%lu\n", n);
32113 +static void au_nhash_wh_do_free(struct hlist_head *head)
32115 + struct au_vdir_wh *pos;
32116 + struct hlist_node *node;
32118 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32119 + au_kfree_rcu(pos);
32122 +static void au_nhash_de_do_free(struct hlist_head *head)
32124 + struct au_vdir_dehstr *pos;
32125 + struct hlist_node *node;
32127 + hlist_for_each_entry_safe(pos, node, head, hash)
32128 + au_cache_free_vdir_dehstr(pos);
32131 +static void au_nhash_do_free(struct au_nhash *nhash,
32132 + void (*free)(struct hlist_head *head))
32135 + struct hlist_head *head;
32137 + n = nhash->nh_num;
32141 + head = nhash->nh_head;
32142 + while (n-- > 0) {
32143 + nhash_count(head);
32146 + au_kfree_try_rcu(nhash->nh_head);
32149 +void au_nhash_wh_free(struct au_nhash *whlist)
32151 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32154 +static void au_nhash_de_free(struct au_nhash *delist)
32156 + au_nhash_do_free(delist, au_nhash_de_do_free);
32159 +/* ---------------------------------------------------------------------- */
32161 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32165 + unsigned int u, n;
32166 + struct hlist_head *head;
32167 + struct au_vdir_wh *pos;
32170 + n = whlist->nh_num;
32171 + head = whlist->nh_head;
32172 + for (u = 0; u < n; u++, head++)
32173 + hlist_for_each_entry(pos, head, wh_hash)
32174 + if (pos->wh_bindex == btgt && ++num > limit)
32179 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32180 + unsigned char *name,
32181 + unsigned int len)
32184 + /* const unsigned int magic_bit = 12; */
32186 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32193 + /* v = hash_long(v, magic_bit); */
32194 + v %= nhash->nh_num;
32195 + return nhash->nh_head + v;
32198 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32201 + return str->len == nlen && !memcmp(str->name, name, nlen);
32204 +/* returns found or not */
32205 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32207 + struct hlist_head *head;
32208 + struct au_vdir_wh *pos;
32209 + struct au_vdir_destr *str;
32211 + head = au_name_hash(whlist, name, nlen);
32212 + hlist_for_each_entry(pos, head, wh_hash) {
32213 + str = &pos->wh_str;
32214 + AuDbg("%.*s\n", str->len, str->name);
32215 + if (au_nhash_test_name(str, name, nlen))
32221 +/* returns found(true) or not */
32222 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32224 + struct hlist_head *head;
32225 + struct au_vdir_dehstr *pos;
32226 + struct au_vdir_destr *str;
32228 + head = au_name_hash(delist, name, nlen);
32229 + hlist_for_each_entry(pos, head, hash) {
32231 + AuDbg("%.*s\n", str->len, str->name);
32232 + if (au_nhash_test_name(str, name, nlen))
32238 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32239 + unsigned char d_type)
32241 +#ifdef CONFIG_AUFS_SHWH
32242 + wh->wh_ino = ino;
32243 + wh->wh_type = d_type;
32247 +/* ---------------------------------------------------------------------- */
32249 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32250 + unsigned int d_type, aufs_bindex_t bindex,
32251 + unsigned char shwh)
32254 + struct au_vdir_destr *str;
32255 + struct au_vdir_wh *wh;
32257 + AuDbg("%.*s\n", nlen, name);
32258 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32261 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32262 + if (unlikely(!wh))
32266 + wh->wh_bindex = bindex;
32268 + au_shwh_init_wh(wh, ino, d_type);
32269 + str = &wh->wh_str;
32271 + memcpy(str->name, name, nlen);
32272 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32279 +static int append_deblk(struct au_vdir *vdir)
32282 + unsigned long ul;
32283 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32284 + union au_vdir_deblk_p p, deblk_end;
32285 + unsigned char **o;
32288 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32289 + GFP_NOFS, /*may_shrink*/0);
32290 + if (unlikely(!o))
32293 + vdir->vd_deblk = o;
32294 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32296 + ul = vdir->vd_nblk++;
32297 + vdir->vd_deblk[ul] = p.deblk;
32298 + vdir->vd_last.ul = ul;
32299 + vdir->vd_last.p.deblk = p.deblk;
32300 + deblk_end.deblk = p.deblk + deblk_sz;
32301 + err = set_deblk_end(&p, &deblk_end);
32308 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32309 + unsigned int d_type, struct au_nhash *delist)
32313 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32314 + union au_vdir_deblk_p p, *room, deblk_end;
32315 + struct au_vdir_dehstr *dehstr;
32317 + p.deblk = last_deblk(vdir);
32318 + deblk_end.deblk = p.deblk + deblk_sz;
32319 + room = &vdir->vd_last.p;
32320 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32321 + || !is_deblk_end(room, &deblk_end));
32323 + sz = calc_size(nlen);
32324 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32325 + err = append_deblk(vdir);
32326 + if (unlikely(err))
32329 + p.deblk = last_deblk(vdir);
32330 + deblk_end.deblk = p.deblk + deblk_sz;
32332 + AuDebugOn(room->deblk != p.deblk);
32336 + dehstr = au_cache_alloc_vdir_dehstr();
32337 + if (unlikely(!dehstr))
32340 + dehstr->str = &room->de->de_str;
32341 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32342 + room->de->de_ino = ino;
32343 + room->de->de_type = d_type;
32344 + room->de->de_str.len = nlen;
32345 + memcpy(room->de->de_str.name, name, nlen);
32348 + room->deblk += sz;
32349 + if (unlikely(set_deblk_end(room, &deblk_end)))
32350 + err = append_deblk(vdir);
32357 +/* ---------------------------------------------------------------------- */
32359 +void au_vdir_free(struct au_vdir *vdir)
32361 + unsigned char **deblk;
32363 + deblk = vdir->vd_deblk;
32364 + while (vdir->vd_nblk--)
32365 + au_kfree_try_rcu(*deblk++);
32366 + au_kfree_try_rcu(vdir->vd_deblk);
32367 + au_cache_free_vdir(vdir);
32370 +static struct au_vdir *alloc_vdir(struct file *file)
32372 + struct au_vdir *vdir;
32373 + struct super_block *sb;
32376 + sb = file->f_path.dentry->d_sb;
32377 + SiMustAnyLock(sb);
32380 + vdir = au_cache_alloc_vdir();
32381 + if (unlikely(!vdir))
32384 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32385 + if (unlikely(!vdir->vd_deblk))
32388 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32389 + if (!vdir->vd_deblk_sz) {
32390 + /* estimate the appropriate size for deblk */
32391 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32392 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32394 + vdir->vd_nblk = 0;
32395 + vdir->vd_version = 0;
32396 + vdir->vd_jiffy = 0;
32397 + err = append_deblk(vdir);
32399 + return vdir; /* success */
32401 + au_kfree_try_rcu(vdir->vd_deblk);
32404 + au_cache_free_vdir(vdir);
32406 + vdir = ERR_PTR(err);
32410 +static int reinit_vdir(struct au_vdir *vdir)
32413 + union au_vdir_deblk_p p, deblk_end;
32415 + while (vdir->vd_nblk > 1) {
32416 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32417 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32420 + p.deblk = vdir->vd_deblk[0];
32421 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32422 + err = set_deblk_end(&p, &deblk_end);
32423 + /* keep vd_dblk_sz */
32424 + vdir->vd_last.ul = 0;
32425 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32426 + vdir->vd_version = 0;
32427 + vdir->vd_jiffy = 0;
32432 +/* ---------------------------------------------------------------------- */
32434 +#define AuFillVdir_CALLED 1
32435 +#define AuFillVdir_WHABLE (1 << 1)
32436 +#define AuFillVdir_SHWH (1 << 2)
32437 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32438 +#define au_fset_fillvdir(flags, name) \
32439 + do { (flags) |= AuFillVdir_##name; } while (0)
32440 +#define au_fclr_fillvdir(flags, name) \
32441 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32443 +#ifndef CONFIG_AUFS_SHWH
32444 +#undef AuFillVdir_SHWH
32445 +#define AuFillVdir_SHWH 0
32448 +struct fillvdir_arg {
32449 + struct dir_context ctx;
32450 + struct file *file;
32451 + struct au_vdir *vdir;
32452 + struct au_nhash delist;
32453 + struct au_nhash whlist;
32454 + aufs_bindex_t bindex;
32455 + unsigned int flags;
32459 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32460 + loff_t offset __maybe_unused, u64 h_ino,
32461 + unsigned int d_type)
32463 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32464 + char *name = (void *)__name;
32465 + struct super_block *sb;
32467 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32470 + sb = arg->file->f_path.dentry->d_sb;
32471 + au_fset_fillvdir(arg->flags, CALLED);
32473 + if (nlen <= AUFS_WH_PFX_LEN
32474 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32475 + if (test_known(&arg->delist, name, nlen)
32476 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32477 + goto out; /* already exists or whiteouted */
32479 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32481 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32482 + d_type = DT_UNKNOWN;
32483 + arg->err = append_de(arg->vdir, name, nlen, ino,
32484 + d_type, &arg->delist);
32486 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32487 + name += AUFS_WH_PFX_LEN;
32488 + nlen -= AUFS_WH_PFX_LEN;
32489 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32490 + goto out; /* already whiteouted */
32492 + ino = 0; /* just to suppress a warning */
32494 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32497 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32498 + d_type = DT_UNKNOWN;
32499 + arg->err = au_nhash_append_wh
32500 + (&arg->whlist, name, nlen, ino, d_type,
32501 + arg->bindex, shwh);
32507 + arg->vdir->vd_jiffy = jiffies;
32509 + AuTraceErr(arg->err);
32513 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32514 + struct au_nhash *whlist, struct au_nhash *delist)
32516 +#ifdef CONFIG_AUFS_SHWH
32518 + unsigned int nh, u;
32519 + struct hlist_head *head;
32520 + struct au_vdir_wh *pos;
32521 + struct hlist_node *n;
32523 + struct au_vdir_destr *destr;
32525 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32528 + o = p = (void *)__get_free_page(GFP_NOFS);
32529 + if (unlikely(!p))
32533 + nh = whlist->nh_num;
32534 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32535 + p += AUFS_WH_PFX_LEN;
32536 + for (u = 0; u < nh; u++) {
32537 + head = whlist->nh_head + u;
32538 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32539 + destr = &pos->wh_str;
32540 + memcpy(p, destr->name, destr->len);
32541 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32542 + pos->wh_ino, pos->wh_type, delist);
32543 + if (unlikely(err))
32548 + free_page((unsigned long)o);
32558 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32561 + unsigned int rdhash;
32563 + aufs_bindex_t bbot, bindex, btop;
32564 + unsigned char shwh;
32565 + struct file *hf, *file;
32566 + struct super_block *sb;
32568 + file = arg->file;
32569 + sb = file->f_path.dentry->d_sb;
32570 + SiMustAnyLock(sb);
32572 + rdhash = au_sbi(sb)->si_rdhash;
32574 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32575 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32576 + if (unlikely(err))
32578 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32579 + if (unlikely(err))
32585 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32587 + au_fset_fillvdir(arg->flags, SHWH);
32589 + btop = au_fbtop(file);
32590 + bbot = au_fbbot_dir(file);
32591 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32592 + hf = au_hf_dir(file, bindex);
32596 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32598 + if (unlikely(offset))
32601 + arg->bindex = bindex;
32602 + au_fclr_fillvdir(arg->flags, WHABLE);
32604 + || (bindex != bbot
32605 + && au_br_whable(au_sbr_perm(sb, bindex))))
32606 + au_fset_fillvdir(arg->flags, WHABLE);
32609 + au_fclr_fillvdir(arg->flags, CALLED);
32611 + err = vfsub_iterate_dir(hf, &arg->ctx);
32614 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32617 + * dir_relax() may be good for concurrency, but aufs should not
32618 + * use it since it will cause a lockdep problem.
32622 + if (!err && shwh)
32623 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32625 + au_nhash_wh_free(&arg->whlist);
32628 + au_nhash_de_free(&arg->delist);
32633 +static int read_vdir(struct file *file, int may_read)
32636 + unsigned long expire;
32637 + unsigned char do_read;
32638 + struct fillvdir_arg arg = {
32640 + .actor = fillvdir
32643 + struct inode *inode;
32644 + struct au_vdir *vdir, *allocated;
32647 + inode = file_inode(file);
32648 + IMustLock(inode);
32649 + IiMustWriteLock(inode);
32650 + SiMustAnyLock(inode->i_sb);
32652 + allocated = NULL;
32654 + expire = au_sbi(inode->i_sb)->si_rdcache;
32655 + vdir = au_ivdir(inode);
32658 + vdir = alloc_vdir(file);
32659 + err = PTR_ERR(vdir);
32660 + if (IS_ERR(vdir))
32663 + allocated = vdir;
32664 + } else if (may_read
32665 + && (!inode_eq_iversion(inode, vdir->vd_version)
32666 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32668 + err = reinit_vdir(vdir);
32669 + if (unlikely(err))
32674 + return 0; /* success */
32678 + err = au_do_read_vdir(&arg);
32680 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32681 + vdir->vd_version = inode_query_iversion(inode);
32682 + vdir->vd_last.ul = 0;
32683 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32685 + au_set_ivdir(inode, allocated);
32686 + } else if (allocated)
32687 + au_vdir_free(allocated);
32693 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32696 + unsigned long ul, n;
32697 + const unsigned int deblk_sz = src->vd_deblk_sz;
32699 + AuDebugOn(tgt->vd_nblk != 1);
32702 + if (tgt->vd_nblk < src->vd_nblk) {
32703 + unsigned char **p;
32705 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32706 + GFP_NOFS, /*may_shrink*/0);
32707 + if (unlikely(!p))
32709 + tgt->vd_deblk = p;
32712 + if (tgt->vd_deblk_sz != deblk_sz) {
32713 + unsigned char *p;
32715 + tgt->vd_deblk_sz = deblk_sz;
32716 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32717 + /*may_shrink*/1);
32718 + if (unlikely(!p))
32720 + tgt->vd_deblk[0] = p;
32722 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32723 + tgt->vd_version = src->vd_version;
32724 + tgt->vd_jiffy = src->vd_jiffy;
32726 + n = src->vd_nblk;
32727 + for (ul = 1; ul < n; ul++) {
32728 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32730 + if (unlikely(!tgt->vd_deblk[ul]))
32734 + tgt->vd_nblk = n;
32735 + tgt->vd_last.ul = tgt->vd_last.ul;
32736 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32737 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32738 + - src->vd_deblk[src->vd_last.ul];
32740 + return 0; /* success */
32743 + rerr = reinit_vdir(tgt);
32748 +int au_vdir_init(struct file *file)
32751 + struct inode *inode;
32752 + struct au_vdir *vdir_cache, *allocated;
32754 + /* test file->f_pos here instead of ctx->pos */
32755 + err = read_vdir(file, !file->f_pos);
32756 + if (unlikely(err))
32759 + allocated = NULL;
32760 + vdir_cache = au_fvdir_cache(file);
32761 + if (!vdir_cache) {
32762 + vdir_cache = alloc_vdir(file);
32763 + err = PTR_ERR(vdir_cache);
32764 + if (IS_ERR(vdir_cache))
32766 + allocated = vdir_cache;
32767 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32768 + /* test file->f_pos here instead of ctx->pos */
32769 + err = reinit_vdir(vdir_cache);
32770 + if (unlikely(err))
32773 + return 0; /* success */
32775 + inode = file_inode(file);
32776 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32778 + file->f_version = inode_query_iversion(inode);
32780 + au_set_fvdir_cache(file, allocated);
32781 + } else if (allocated)
32782 + au_vdir_free(allocated);
32788 +static loff_t calc_offset(struct au_vdir *vdir)
32791 + union au_vdir_deblk_p p;
32793 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32794 + offset = vdir->vd_last.p.deblk - p.deblk;
32795 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32799 +/* returns true or false */
32800 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32803 + unsigned int deblk_sz;
32804 + unsigned long ul, n;
32806 + union au_vdir_deblk_p p, deblk_end;
32807 + struct au_vdir *vdir_cache;
32810 + vdir_cache = au_fvdir_cache(file);
32811 + offset = calc_offset(vdir_cache);
32812 + AuDbg("offset %lld\n", offset);
32813 + if (ctx->pos == offset)
32816 + vdir_cache->vd_last.ul = 0;
32817 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32822 + deblk_sz = vdir_cache->vd_deblk_sz;
32823 + ul = div64_u64(ctx->pos, deblk_sz);
32824 + AuDbg("ul %lu\n", ul);
32825 + if (ul >= vdir_cache->vd_nblk)
32828 + n = vdir_cache->vd_nblk;
32829 + for (; ul < n; ul++) {
32830 + p.deblk = vdir_cache->vd_deblk[ul];
32831 + deblk_end.deblk = p.deblk + deblk_sz;
32833 + offset *= deblk_sz;
32834 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32837 + l = calc_size(p.de->de_str.len);
32841 + if (!is_deblk_end(&p, &deblk_end)) {
32843 + vdir_cache->vd_last.ul = ul;
32844 + vdir_cache->vd_last.p = p;
32852 + AuDbg("valid %d\n", !valid);
32856 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32858 + unsigned int l, deblk_sz;
32859 + union au_vdir_deblk_p deblk_end;
32860 + struct au_vdir *vdir_cache;
32861 + struct au_vdir_de *de;
32863 + if (!seek_vdir(file, ctx))
32866 + vdir_cache = au_fvdir_cache(file);
32867 + deblk_sz = vdir_cache->vd_deblk_sz;
32869 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32870 + deblk_end.deblk += deblk_sz;
32871 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32872 + de = vdir_cache->vd_last.p.de;
32873 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32874 + de->de_str.len, de->de_str.name, ctx->pos,
32875 + (unsigned long)de->de_ino, de->de_type);
32876 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32877 + de->de_str.len, de->de_ino,
32879 + /* todo: ignore the error caused by udba? */
32880 + /* return err; */
32884 + l = calc_size(de->de_str.len);
32885 + vdir_cache->vd_last.p.deblk += l;
32888 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32889 + vdir_cache->vd_last.ul++;
32890 + vdir_cache->vd_last.p.deblk
32891 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32892 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32901 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32902 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32903 +++ linux/fs/aufs/vfsub.c 2022-10-26 22:30:38.472648858 +0200
32905 +// SPDX-License-Identifier: GPL-2.0
32907 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32909 + * This program, aufs is free software; you can redistribute it and/or modify
32910 + * it under the terms of the GNU General Public License as published by
32911 + * the Free Software Foundation; either version 2 of the License, or
32912 + * (at your option) any later version.
32914 + * This program is distributed in the hope that it will be useful,
32915 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32916 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32917 + * GNU General Public License for more details.
32919 + * You should have received a copy of the GNU General Public License
32920 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32924 + * sub-routines for VFS
32927 +#include <linux/mnt_namespace.h>
32928 +#include <linux/nsproxy.h>
32929 +#include <linux/security.h>
32930 +#include <linux/splice.h>
32933 +#ifdef CONFIG_AUFS_BR_FUSE
32934 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32936 + if (!au_test_fuse(h_sb) || !au_userns)
32939 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32943 +int vfsub_sync_filesystem(struct super_block *h_sb)
32948 + down_read(&h_sb->s_umount);
32949 + err = sync_filesystem(h_sb);
32950 + up_read(&h_sb->s_umount);
32956 +/* ---------------------------------------------------------------------- */
32958 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32962 + struct super_block *h_sb;
32965 + * Always needs h_path->mnt for LSM or FUSE branch.
32967 + AuDebugOn(!h_path->mnt);
32969 + /* for remote fs, leave work for its getattr or d_revalidate */
32970 + /* for bad i_attr fs, handle them in aufs_getattr() */
32971 + /* still some fs may acquire i_mutex. we need to skip them */
32975 + h_sb = h_path->dentry->d_sb;
32976 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32978 + err = vfsub_getattr(h_path, &st);
32983 +/* ---------------------------------------------------------------------- */
32985 +struct file *vfsub_dentry_open(struct path *path, int flags)
32987 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32991 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32993 + struct file *file;
32996 + file = filp_open(path,
32997 + oflags /* | __FMODE_NONOTIFY */,
33000 + if (IS_ERR(file))
33002 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33009 + * Ideally this function should call VFS:do_last() in order to keep all its
33010 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33011 + * structure such as nameidata. This is a second (or third) best approach.
33012 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33014 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33015 + struct vfsub_aopen_args *args)
33018 + struct au_branch *br = args->br;
33019 + struct file *file = args->file;
33020 + /* copied from linux/fs/namei.c:atomic_open() */
33021 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33024 + AuDebugOn(!dir->i_op->atomic_open);
33026 + err = au_br_test_oflag(args->open_flag, br);
33027 + if (unlikely(err))
33030 + au_lcnt_inc(&br->br_nfiles);
33031 + file->f_path.dentry = DENTRY_NOT_SET;
33032 + file->f_path.mnt = au_br_mnt(br);
33033 + AuDbg("%ps\n", dir->i_op->atomic_open);
33034 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33035 + args->create_mode);
33036 + if (unlikely(err < 0)) {
33037 + au_lcnt_dec(&br->br_nfiles);
33041 + /* temporary workaround for nfsv4 branch */
33042 + if (au_test_nfs(dir->i_sb))
33043 + nfs_mark_for_revalidate(dir);
33045 + if (file->f_mode & FMODE_CREATED)
33046 + fsnotify_create(dir, dentry);
33047 + if (!(file->f_mode & FMODE_OPENED)) {
33048 + au_lcnt_dec(&br->br_nfiles);
33052 + /* todo: call VFS:may_open() here */
33053 + /* todo: ima_file_check() too? */
33054 + if (!err && (args->open_flag & __FMODE_EXEC))
33055 + err = deny_write_access(file);
33057 + fsnotify_open(file);
33059 + au_lcnt_dec(&br->br_nfiles);
33060 + /* note that the file is created and still opened */
33066 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33070 + err = kern_path(name, flags, path);
33071 + if (!err && d_is_positive(path->dentry))
33072 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33076 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33077 + struct path *ppath, int len)
33079 + struct path path;
33081 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33082 + if (IS_ERR(path.dentry))
33084 + if (d_is_positive(path.dentry)) {
33085 + path.mnt = ppath->mnt;
33086 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33090 + AuTraceErrPtr(path.dentry);
33091 + return path.dentry;
33094 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33097 + struct path path;
33099 + /* VFS checks it too, but by WARN_ON_ONCE() */
33100 + IMustLock(d_inode(ppath->dentry));
33102 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33103 + if (IS_ERR(path.dentry))
33105 + if (d_is_positive(path.dentry)) {
33106 + path.mnt = ppath->mnt;
33107 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33111 + AuTraceErrPtr(path.dentry);
33112 + return path.dentry;
33115 +void vfsub_call_lkup_one(void *args)
33117 + struct vfsub_lkup_one_args *a = args;
33118 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33121 +/* ---------------------------------------------------------------------- */
33123 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33124 + struct dentry *d2, struct au_hinode *hdir2)
33126 + struct dentry *d;
33129 + d = lock_rename(d1, d2);
33131 + au_hn_suspend(hdir1);
33132 + if (hdir1 != hdir2)
33133 + au_hn_suspend(hdir2);
33138 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33139 + struct dentry *d2, struct au_hinode *hdir2)
33141 + au_hn_resume(hdir1);
33142 + if (hdir1 != hdir2)
33143 + au_hn_resume(hdir2);
33145 + unlock_rename(d1, d2);
33149 +/* ---------------------------------------------------------------------- */
33151 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33154 + struct dentry *d;
33155 + struct user_namespace *userns;
33159 + d = path->dentry;
33160 + path->dentry = d->d_parent;
33161 + err = security_path_mknod(path, d, mode, 0);
33162 + path->dentry = d;
33163 + if (unlikely(err))
33165 + userns = mnt_user_ns(path->mnt);
33168 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
33171 + struct path tmp = *path;
33174 + vfsub_update_h_iattr(&tmp, &did);
33176 + tmp.dentry = path->dentry->d_parent;
33177 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33186 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33189 + struct dentry *d;
33190 + struct user_namespace *userns;
33194 + d = path->dentry;
33195 + path->dentry = d->d_parent;
33196 + err = security_path_symlink(path, d, symname);
33197 + path->dentry = d;
33198 + if (unlikely(err))
33200 + userns = mnt_user_ns(path->mnt);
33203 + err = vfs_symlink(userns, dir, path->dentry, symname);
33206 + struct path tmp = *path;
33209 + vfsub_update_h_iattr(&tmp, &did);
33211 + tmp.dentry = path->dentry->d_parent;
33212 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33221 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33224 + struct dentry *d;
33225 + struct user_namespace *userns;
33229 + d = path->dentry;
33230 + path->dentry = d->d_parent;
33231 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33232 + path->dentry = d;
33233 + if (unlikely(err))
33235 + userns = mnt_user_ns(path->mnt);
33238 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
33241 + struct path tmp = *path;
33244 + vfsub_update_h_iattr(&tmp, &did);
33246 + tmp.dentry = path->dentry->d_parent;
33247 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33256 +static int au_test_nlink(struct inode *inode)
33258 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33260 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33261 + || inode->i_nlink < link_max)
33266 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33267 + struct inode **delegated_inode)
33270 + struct dentry *d;
33271 + struct user_namespace *userns;
33275 + err = au_test_nlink(d_inode(src_dentry));
33276 + if (unlikely(err))
33279 + /* we don't call may_linkat() */
33280 + d = path->dentry;
33281 + path->dentry = d->d_parent;
33282 + err = security_path_link(src_dentry, path, d);
33283 + path->dentry = d;
33284 + if (unlikely(err))
33286 + userns = mnt_user_ns(path->mnt);
33289 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33292 + struct path tmp = *path;
33295 + /* fuse has different memory inode for the same inumber */
33296 + vfsub_update_h_iattr(&tmp, &did);
33298 + tmp.dentry = path->dentry->d_parent;
33299 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33300 + tmp.dentry = src_dentry;
33301 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33310 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33311 + struct inode *dir, struct path *path,
33312 + struct inode **delegated_inode, unsigned int flags)
33315 + struct renamedata rd;
33316 + struct path tmp = {
33319 + struct dentry *d;
33322 + IMustLock(src_dir);
33324 + d = path->dentry;
33325 + path->dentry = d->d_parent;
33326 + tmp.dentry = src_dentry->d_parent;
33327 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33328 + path->dentry = d;
33329 + if (unlikely(err))
33332 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33333 + rd.old_dir = src_dir;
33334 + rd.old_dentry = src_dentry;
33335 + rd.new_mnt_userns = rd.old_mnt_userns;
33336 + rd.new_dir = dir;
33337 + rd.new_dentry = path->dentry;
33338 + rd.delegated_inode = delegated_inode;
33339 + rd.flags = flags;
33341 + err = vfs_rename(&rd);
33346 + tmp.dentry = d->d_parent;
33347 + vfsub_update_h_iattr(&tmp, &did);
33349 + tmp.dentry = src_dentry;
33350 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33351 + tmp.dentry = src_dentry->d_parent;
33352 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33361 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33364 + struct dentry *d;
33365 + struct user_namespace *userns;
33369 + d = path->dentry;
33370 + path->dentry = d->d_parent;
33371 + err = security_path_mkdir(path, d, mode);
33372 + path->dentry = d;
33373 + if (unlikely(err))
33375 + userns = mnt_user_ns(path->mnt);
33378 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33381 + struct path tmp = *path;
33384 + vfsub_update_h_iattr(&tmp, &did);
33386 + tmp.dentry = path->dentry->d_parent;
33387 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33396 +int vfsub_rmdir(struct inode *dir, struct path *path)
33399 + struct dentry *d;
33400 + struct user_namespace *userns;
33404 + d = path->dentry;
33405 + path->dentry = d->d_parent;
33406 + err = security_path_rmdir(path, d);
33407 + path->dentry = d;
33408 + if (unlikely(err))
33410 + userns = mnt_user_ns(path->mnt);
33413 + err = vfs_rmdir(userns, dir, path->dentry);
33416 + struct path tmp = {
33417 + .dentry = path->dentry->d_parent,
33421 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33428 +/* ---------------------------------------------------------------------- */
33430 +/* todo: support mmap_sem? */
33431 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33437 + err = vfs_read(file, ubuf, count, ppos);
33440 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33444 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33450 + err = kernel_read(file, kbuf, count, ppos);
33454 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33458 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33464 + err = vfs_write(file, ubuf, count, ppos);
33467 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33471 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33476 + err = kernel_write(file, kbuf, count, ppos);
33479 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33483 +int vfsub_flush(struct file *file, fl_owner_t id)
33488 + if (file->f_op->flush) {
33489 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33490 + err = file->f_op->flush(file, id);
33493 + err = file->f_op->flush(file, id);
33497 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33503 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33507 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33510 + err = iterate_dir(file, ctx);
33513 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33518 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33519 + struct pipe_inode_info *pipe, size_t len,
33520 + unsigned int flags)
33525 + err = do_splice_to(in, ppos, pipe, len, flags);
33527 + file_accessed(in);
33529 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33533 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33534 + loff_t *ppos, size_t len, unsigned int flags)
33539 + err = do_splice_from(pipe, out, ppos, len, flags);
33542 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33546 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33550 + /* file can be NULL */
33552 + err = vfs_fsync(file, datasync);
33556 + AuDebugOn(!file);
33557 + path = &file->f_path;
33559 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33564 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33565 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33566 + struct file *h_file)
33569 + struct inode *h_inode;
33570 + struct super_block *h_sb;
33571 + struct user_namespace *h_userns;
33574 + err = vfsub_truncate(h_path, length);
33578 + h_inode = d_inode(h_path->dentry);
33579 + h_sb = h_inode->i_sb;
33581 + sb_start_write(h_sb);
33583 + err = security_path_truncate(h_path);
33585 + h_userns = mnt_user_ns(h_path->mnt);
33587 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33592 + sb_end_write(h_sb);
33599 +/* ---------------------------------------------------------------------- */
33601 +struct au_vfsub_mkdir_args {
33603 + struct inode *dir;
33604 + struct path *path;
33608 +static void au_call_vfsub_mkdir(void *args)
33610 + struct au_vfsub_mkdir_args *a = args;
33611 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33614 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33616 + int err, do_sio, wkq_err;
33617 + struct user_namespace *userns;
33619 + userns = mnt_user_ns(path->mnt);
33620 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33623 + err = vfsub_mkdir(dir, path, mode);
33626 + struct au_vfsub_mkdir_args args = {
33632 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33633 + if (unlikely(wkq_err))
33640 +struct au_vfsub_rmdir_args {
33642 + struct inode *dir;
33643 + struct path *path;
33646 +static void au_call_vfsub_rmdir(void *args)
33648 + struct au_vfsub_rmdir_args *a = args;
33649 + *a->errp = vfsub_rmdir(a->dir, a->path);
33652 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33654 + int err, do_sio, wkq_err;
33655 + struct user_namespace *userns;
33657 + userns = mnt_user_ns(path->mnt);
33658 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33661 + err = vfsub_rmdir(dir, path);
33664 + struct au_vfsub_rmdir_args args = {
33669 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33670 + if (unlikely(wkq_err))
33677 +/* ---------------------------------------------------------------------- */
33679 +struct notify_change_args {
33681 + struct path *path;
33682 + struct iattr *ia;
33683 + struct inode **delegated_inode;
33686 +static void call_notify_change(void *args)
33688 + struct notify_change_args *a = args;
33689 + struct inode *h_inode;
33690 + struct user_namespace *userns;
33692 + h_inode = d_inode(a->path->dentry);
33693 + IMustLock(h_inode);
33695 + *a->errp = -EPERM;
33696 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33697 + userns = mnt_user_ns(a->path->mnt);
33699 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33700 + a->delegated_inode);
33703 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33705 + AuTraceErr(*a->errp);
33708 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33709 + struct inode **delegated_inode)
33712 + struct notify_change_args args = {
33716 + .delegated_inode = delegated_inode
33719 + call_notify_change(&args);
33724 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33725 + struct inode **delegated_inode)
33727 + int err, wkq_err;
33728 + struct notify_change_args args = {
33732 + .delegated_inode = delegated_inode
33735 + wkq_err = au_wkq_wait(call_notify_change, &args);
33736 + if (unlikely(wkq_err))
33742 +/* ---------------------------------------------------------------------- */
33744 +struct unlink_args {
33746 + struct inode *dir;
33747 + struct path *path;
33748 + struct inode **delegated_inode;
33751 +static void call_unlink(void *args)
33753 + struct unlink_args *a = args;
33754 + struct dentry *d = a->path->dentry;
33755 + struct inode *h_inode;
33756 + struct user_namespace *userns;
33757 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33758 + && au_dcount(d) == 1);
33760 + IMustLock(a->dir);
33762 + a->path->dentry = d->d_parent;
33763 + *a->errp = security_path_unlink(a->path, d);
33764 + a->path->dentry = d;
33765 + if (unlikely(*a->errp))
33768 + if (!stop_sillyrename)
33771 + if (d_is_positive(d)) {
33772 + h_inode = d_inode(d);
33776 + userns = mnt_user_ns(a->path->mnt);
33778 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33781 + struct path tmp = {
33782 + .dentry = d->d_parent,
33783 + .mnt = a->path->mnt
33785 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33788 + if (!stop_sillyrename)
33793 + AuTraceErr(*a->errp);
33797 + * @dir: must be locked.
33798 + * @dentry: target dentry.
33800 +int vfsub_unlink(struct inode *dir, struct path *path,
33801 + struct inode **delegated_inode, int force)
33804 + struct unlink_args args = {
33808 + .delegated_inode = delegated_inode
33812 + call_unlink(&args);
33816 + wkq_err = au_wkq_wait(call_unlink, &args);
33817 + if (unlikely(wkq_err))
33823 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33824 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33825 +++ linux/fs/aufs/vfsub.h 2022-10-26 22:30:38.472648858 +0200
33827 +/* SPDX-License-Identifier: GPL-2.0 */
33829 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33831 + * This program, aufs is free software; you can redistribute it and/or modify
33832 + * it under the terms of the GNU General Public License as published by
33833 + * the Free Software Foundation; either version 2 of the License, or
33834 + * (at your option) any later version.
33836 + * This program is distributed in the hope that it will be useful,
33837 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33838 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33839 + * GNU General Public License for more details.
33841 + * You should have received a copy of the GNU General Public License
33842 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33846 + * sub-routines for VFS
33849 +#ifndef __AUFS_VFSUB_H__
33850 +#define __AUFS_VFSUB_H__
33854 +#include <linux/fs.h>
33855 +#include <linux/mount.h>
33856 +#include <linux/posix_acl.h>
33857 +#include <linux/xattr.h>
33858 +#include "debug.h"
33860 +/* copied from linux/fs/internal.h */
33861 +/* todo: BAD approach!! */
33862 +extern void __mnt_drop_write(struct vfsmount *);
33863 +extern struct file *alloc_empty_file(int, const struct cred *);
33865 +/* ---------------------------------------------------------------------- */
33867 +/* lock subclass for lower inode */
33868 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33869 +/* reduce? gave up. */
33871 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33872 + AuLsc_I_PARENT, /* lower inode, parent first */
33873 + AuLsc_I_PARENT2, /* copyup dirs */
33874 + AuLsc_I_PARENT3, /* copyup wh */
33880 +/* to debug easier, do not make them inlined functions */
33881 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33882 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33884 +/* ---------------------------------------------------------------------- */
33886 +static inline void vfsub_drop_nlink(struct inode *inode)
33888 + AuDebugOn(!inode->i_nlink);
33889 + drop_nlink(inode);
33892 +static inline void vfsub_dead_dir(struct inode *inode)
33894 + AuDebugOn(!S_ISDIR(inode->i_mode));
33895 + inode->i_flags |= S_DEAD;
33896 + clear_nlink(inode);
33899 +static inline int vfsub_native_ro(struct inode *inode)
33901 + return sb_rdonly(inode->i_sb)
33902 + || IS_RDONLY(inode)
33903 + /* || IS_APPEND(inode) */
33904 + || IS_IMMUTABLE(inode);
33907 +#ifdef CONFIG_AUFS_BR_FUSE
33908 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33910 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33913 +int vfsub_sync_filesystem(struct super_block *h_sb);
33915 +/* ---------------------------------------------------------------------- */
33917 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33918 +struct file *vfsub_dentry_open(struct path *path, int flags);
33919 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33921 +struct vfsub_aopen_args {
33922 + struct file *file;
33923 + unsigned int open_flag;
33924 + umode_t create_mode;
33925 + struct au_branch *br;
33927 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33928 + struct vfsub_aopen_args *args);
33929 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33931 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33932 + struct path *ppath, int len);
33933 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33936 +struct vfsub_lkup_one_args {
33937 + struct dentry **errp;
33938 + struct qstr *name;
33939 + struct path *ppath;
33942 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33943 + struct path *ppath)
33945 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33948 +void vfsub_call_lkup_one(void *args);
33950 +/* ---------------------------------------------------------------------- */
33952 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33957 + err = mnt_want_write(mnt);
33962 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33965 + mnt_drop_write(mnt);
33969 +#if 0 /* reserved */
33970 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33973 + mnt_drop_write_file(file);
33978 +/* ---------------------------------------------------------------------- */
33981 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33982 + struct dentry *d2, struct au_hinode *hdir2);
33983 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33984 + struct dentry *d2, struct au_hinode *hdir2);
33986 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33988 +int vfsub_symlink(struct inode *dir, struct path *path,
33989 + const char *symname);
33990 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33991 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33992 + struct path *path, struct inode **delegated_inode);
33993 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33994 + struct inode *hdir, struct path *path,
33995 + struct inode **delegated_inode, unsigned int flags);
33996 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33997 +int vfsub_rmdir(struct inode *dir, struct path *path);
33999 +/* ---------------------------------------------------------------------- */
34001 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34003 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34005 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34007 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34009 +int vfsub_flush(struct file *file, fl_owner_t id);
34010 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34012 +static inline loff_t vfsub_f_size_read(struct file *file)
34014 + return i_size_read(file_inode(file));
34017 +static inline unsigned int vfsub_file_flags(struct file *file)
34019 + unsigned int flags;
34021 + spin_lock(&file->f_lock);
34022 + flags = file->f_flags;
34023 + spin_unlock(&file->f_lock);
34028 +static inline int vfsub_file_execed(struct file *file)
34030 + /* todo: direct access f_flags */
34031 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34034 +#if 0 /* reserved */
34035 +static inline void vfsub_file_accessed(struct file *h_file)
34037 + file_accessed(h_file);
34038 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34042 +#if 0 /* reserved */
34043 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34044 + struct dentry *h_dentry)
34046 + struct path h_path = {
34047 + .dentry = h_dentry,
34050 + touch_atime(&h_path);
34051 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34055 +static inline int vfsub_update_time(struct inode *h_inode,
34056 + struct timespec64 *ts, int flags)
34058 + return inode_update_time(h_inode, ts, flags);
34059 + /* no vfsub_update_h_iattr() since we don't have struct path */
34062 +#ifdef CONFIG_FS_POSIX_ACL
34063 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
34064 + struct inode *h_inode, umode_t h_mode)
34068 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
34069 + if (err == -EOPNOTSUPP)
34074 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
34075 + struct inode *h_inode, umode_t h_mode);
34078 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34079 + struct pipe_inode_info *pipe, size_t len,
34080 + unsigned int flags);
34081 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34082 + loff_t *ppos, size_t len, unsigned int flags);
34084 +static inline long vfsub_truncate(struct path *path, loff_t length)
34089 + err = vfs_truncate(path, length);
34094 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34095 + struct file *h_file);
34096 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34099 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34102 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34108 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34114 +/* copy_file_range(2) is a systemcall */
34115 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34116 + struct file *dst, loff_t dst_pos,
34117 + size_t len, unsigned int flags)
34122 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34128 +/* ---------------------------------------------------------------------- */
34130 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34135 + err = vfs_llseek(file, offset, origin);
34140 +/* ---------------------------------------------------------------------- */
34142 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34143 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34144 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34145 + struct inode **delegated_inode);
34146 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34147 + struct inode **delegated_inode);
34148 +int vfsub_unlink(struct inode *dir, struct path *path,
34149 + struct inode **delegated_inode, int force);
34151 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34153 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34156 +/* ---------------------------------------------------------------------- */
34158 +static inline int vfsub_setxattr(struct user_namespace *userns,
34159 + struct dentry *dentry, const char *name,
34160 + const void *value, size_t size, int flags)
34165 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
34171 +static inline int vfsub_removexattr(struct user_namespace *userns,
34172 + struct dentry *dentry, const char *name)
34177 + err = vfs_removexattr(userns, dentry, name);
34183 +#endif /* __KERNEL__ */
34184 +#endif /* __AUFS_VFSUB_H__ */
34185 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34186 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34187 +++ linux/fs/aufs/wbr_policy.c 2022-10-26 22:30:38.472648858 +0200
34189 +// SPDX-License-Identifier: GPL-2.0
34191 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34193 + * This program, aufs is free software; you can redistribute it and/or modify
34194 + * it under the terms of the GNU General Public License as published by
34195 + * the Free Software Foundation; either version 2 of the License, or
34196 + * (at your option) any later version.
34198 + * This program is distributed in the hope that it will be useful,
34199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34201 + * GNU General Public License for more details.
34203 + * You should have received a copy of the GNU General Public License
34204 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34208 + * policies for selecting one among multiple writable branches
34211 +#include <linux/statfs.h>
34214 +/* subset of cpup_attr() */
34215 +static noinline_for_stack
34216 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34220 + struct inode *h_isrc;
34222 + h_isrc = d_inode(h_src);
34223 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34224 + ia.ia_mode = h_isrc->i_mode;
34225 + ia.ia_uid = h_isrc->i_uid;
34226 + ia.ia_gid = h_isrc->i_gid;
34227 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34228 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34229 + /* no delegation since it is just created */
34230 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34232 + /* is this nfs only? */
34233 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34234 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34235 + ia.ia_mode = h_isrc->i_mode;
34236 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34242 +#define AuCpdown_PARENT_OPQ 1
34243 +#define AuCpdown_WHED (1 << 1)
34244 +#define AuCpdown_MADE_DIR (1 << 2)
34245 +#define AuCpdown_DIROPQ (1 << 3)
34246 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34247 +#define au_fset_cpdown(flags, name) \
34248 + do { (flags) |= AuCpdown_##name; } while (0)
34249 +#define au_fclr_cpdown(flags, name) \
34250 + do { (flags) &= ~AuCpdown_##name; } while (0)
34252 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34253 + unsigned int *flags)
34256 + struct dentry *opq_dentry;
34258 + opq_dentry = au_diropq_create(dentry, bdst);
34259 + err = PTR_ERR(opq_dentry);
34260 + if (IS_ERR(opq_dentry))
34262 + dput(opq_dentry);
34263 + au_fset_cpdown(*flags, DIROPQ);
34269 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34270 + struct inode *dir, aufs_bindex_t bdst)
34273 + struct path h_path;
34274 + struct au_branch *br;
34276 + br = au_sbr(dentry->d_sb, bdst);
34277 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34278 + err = PTR_ERR(h_path.dentry);
34279 + if (IS_ERR(h_path.dentry))
34283 + if (d_is_positive(h_path.dentry)) {
34284 + h_path.mnt = au_br_mnt(br);
34285 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34288 + dput(h_path.dentry);
34294 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34295 + struct au_pin *pin,
34296 + struct dentry *h_parent, void *arg)
34299 + aufs_bindex_t bopq, btop;
34300 + struct path h_path;
34301 + struct dentry *parent;
34302 + struct inode *h_dir, *h_inode, *inode, *dir;
34303 + unsigned int *flags = arg;
34305 + btop = au_dbtop(dentry);
34306 + /* dentry is di-locked */
34307 + parent = dget_parent(dentry);
34308 + dir = d_inode(parent);
34309 + h_dir = d_inode(h_parent);
34310 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34311 + IMustLock(h_dir);
34313 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34314 + if (unlikely(err < 0))
34316 + h_path.dentry = au_h_dptr(dentry, bdst);
34317 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34318 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34319 + if (unlikely(err))
34321 + au_fset_cpdown(*flags, MADE_DIR);
34323 + bopq = au_dbdiropq(dentry);
34324 + au_fclr_cpdown(*flags, WHED);
34325 + au_fclr_cpdown(*flags, DIROPQ);
34326 + if (au_dbwh(dentry) == bdst)
34327 + au_fset_cpdown(*flags, WHED);
34328 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34329 + au_fset_cpdown(*flags, PARENT_OPQ);
34330 + h_inode = d_inode(h_path.dentry);
34331 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34332 + if (au_ftest_cpdown(*flags, WHED)) {
34333 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34334 + if (unlikely(err)) {
34335 + inode_unlock(h_inode);
34340 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34341 + inode_unlock(h_inode);
34342 + if (unlikely(err))
34345 + if (au_ftest_cpdown(*flags, WHED)) {
34346 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34347 + if (unlikely(err))
34351 + inode = d_inode(dentry);
34352 + if (au_ibbot(inode) < bdst)
34353 + au_set_ibbot(inode, bdst);
34354 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34355 + au_hi_flags(inode, /*isdir*/1));
34356 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34357 + goto out; /* success */
34361 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34362 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34363 + rerr = au_diropq_remove(dentry, bdst);
34364 + inode_unlock(h_inode);
34365 + if (unlikely(rerr)) {
34366 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34367 + dentry, bdst, rerr);
34373 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34374 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34375 + if (unlikely(rerr)) {
34376 + AuIOErr("failed removing %pd b%d (%d)\n",
34377 + dentry, bdst, rerr);
34382 + au_set_h_dptr(dentry, bdst, NULL);
34383 + if (au_dbbot(dentry) == bdst)
34384 + au_update_dbbot(dentry);
34390 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34393 + unsigned int flags;
34396 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34401 +/* ---------------------------------------------------------------------- */
34403 +/* policies for create */
34405 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34407 + int err, i, j, ndentry;
34408 + aufs_bindex_t bopq;
34409 + struct au_dcsub_pages dpages;
34410 + struct au_dpage *dpage;
34411 + struct dentry **dentries, *parent, *d;
34413 + err = au_dpages_init(&dpages, GFP_NOFS);
34414 + if (unlikely(err))
34416 + parent = dget_parent(dentry);
34417 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34418 + if (unlikely(err))
34422 + for (i = 0; i < dpages.ndpage; i++) {
34423 + dpage = dpages.dpages + i;
34424 + dentries = dpage->dentries;
34425 + ndentry = dpage->ndentry;
34426 + for (j = 0; j < ndentry; j++) {
34428 + di_read_lock_parent2(d, !AuLock_IR);
34429 + bopq = au_dbdiropq(d);
34430 + di_read_unlock(d, !AuLock_IR);
34431 + if (bopq >= 0 && bopq < err)
34438 + au_dpages_free(&dpages);
34443 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34445 + for (; bindex >= 0; bindex--)
34446 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34451 +/* top down parent */
34452 +static int au_wbr_create_tdp(struct dentry *dentry,
34453 + unsigned int flags __maybe_unused)
34456 + aufs_bindex_t btop, bindex;
34457 + struct super_block *sb;
34458 + struct dentry *parent, *h_parent;
34460 + sb = dentry->d_sb;
34461 + btop = au_dbtop(dentry);
34463 + if (!au_br_rdonly(au_sbr(sb, btop)))
34467 + parent = dget_parent(dentry);
34468 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34469 + h_parent = au_h_dptr(parent, bindex);
34470 + if (!h_parent || d_is_negative(h_parent))
34473 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34480 + /* bottom up here */
34481 + if (unlikely(err < 0)) {
34482 + err = au_wbr_bu(sb, btop - 1);
34484 + err = au_wbr_nonopq(dentry, err);
34488 + AuDbg("b%d\n", err);
34492 +/* ---------------------------------------------------------------------- */
34494 +/* an exception for the policy other than tdp */
34495 +static int au_wbr_create_exp(struct dentry *dentry)
34498 + aufs_bindex_t bwh, bdiropq;
34499 + struct dentry *parent;
34502 + bwh = au_dbwh(dentry);
34503 + parent = dget_parent(dentry);
34504 + bdiropq = au_dbdiropq(parent);
34506 + if (bdiropq >= 0)
34507 + err = min(bdiropq, bwh);
34510 + AuDbg("%d\n", err);
34511 + } else if (bdiropq >= 0) {
34513 + AuDbg("%d\n", err);
34518 + err = au_wbr_nonopq(dentry, err);
34520 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34523 + AuDbg("%d\n", err);
34527 +/* ---------------------------------------------------------------------- */
34530 +static int au_wbr_create_init_rr(struct super_block *sb)
34534 + err = au_wbr_bu(sb, au_sbbot(sb));
34535 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34538 + AuDbg("b%d\n", err);
34542 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34546 + aufs_bindex_t bindex, bbot;
34547 + struct super_block *sb;
34550 + err = au_wbr_create_exp(dentry);
34554 + sb = dentry->d_sb;
34555 + next = &au_sbi(sb)->si_wbr_rr_next;
34556 + bbot = au_sbbot(sb);
34558 + for (bindex = 0; bindex <= bbot; bindex++) {
34559 + if (!au_ftest_wbr(flags, DIR)) {
34560 + err = atomic_dec_return(next) + 1;
34561 + /* modulo for 0 is meaningless */
34562 + if (unlikely(!err))
34563 + err = atomic_dec_return(next) + 1;
34565 + err = atomic_read(next);
34566 + AuDbg("%d\n", err);
34569 + AuDbg("%d\n", err);
34570 + if (!au_br_rdonly(au_sbr(sb, err)))
34576 + err = au_wbr_nonopq(dentry, err);
34579 + AuDbg("%d\n", err);
34583 +/* ---------------------------------------------------------------------- */
34585 +/* most free space */
34586 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34588 + struct super_block *sb;
34589 + struct au_branch *br;
34590 + struct au_wbr_mfs *mfs;
34591 + struct dentry *h_parent;
34592 + aufs_bindex_t bindex, bbot;
34594 + unsigned long long b, bavail;
34595 + struct path h_path;
34596 + /* reduce the stack usage */
34597 + struct kstatfs *st;
34599 + st = kmalloc(sizeof(*st), GFP_NOFS);
34600 + if (unlikely(!st)) {
34601 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34606 + sb = dentry->d_sb;
34607 + mfs = &au_sbi(sb)->si_wbr_mfs;
34608 + MtxMustLock(&mfs->mfs_lock);
34609 + mfs->mfs_bindex = -EROFS;
34610 + mfs->mfsrr_bytes = 0;
34613 + bbot = au_sbbot(sb);
34615 + bindex = au_dbtop(parent);
34616 + bbot = au_dbtaildir(parent);
34619 + for (; bindex <= bbot; bindex++) {
34621 + h_parent = au_h_dptr(parent, bindex);
34622 + if (!h_parent || d_is_negative(h_parent))
34625 + br = au_sbr(sb, bindex);
34626 + if (au_br_rdonly(br))
34629 + /* sb->s_root for NFS is unreliable */
34630 + h_path.mnt = au_br_mnt(br);
34631 + h_path.dentry = h_path.mnt->mnt_root;
34632 + err = vfs_statfs(&h_path, st);
34633 + if (unlikely(err)) {
34634 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34638 + /* when the available size is equal, select the lower one */
34639 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34640 + || sizeof(b) < sizeof(st->f_bsize));
34641 + b = st->f_bavail * st->f_bsize;
34642 + br->br_wbr->wbr_bytes = b;
34643 + if (b >= bavail) {
34645 + mfs->mfs_bindex = bindex;
34646 + mfs->mfs_jiffy = jiffies;
34650 + mfs->mfsrr_bytes = bavail;
34651 + AuDbg("b%d\n", mfs->mfs_bindex);
34652 + au_kfree_rcu(st);
34655 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34658 + struct dentry *parent;
34659 + struct super_block *sb;
34660 + struct au_wbr_mfs *mfs;
34662 + err = au_wbr_create_exp(dentry);
34666 + sb = dentry->d_sb;
34668 + if (au_ftest_wbr(flags, PARENT))
34669 + parent = dget_parent(dentry);
34670 + mfs = &au_sbi(sb)->si_wbr_mfs;
34671 + mutex_lock(&mfs->mfs_lock);
34672 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34673 + || mfs->mfs_bindex < 0
34674 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34675 + au_mfs(dentry, parent);
34676 + mutex_unlock(&mfs->mfs_lock);
34677 + err = mfs->mfs_bindex;
34681 + err = au_wbr_nonopq(dentry, err);
34684 + AuDbg("b%d\n", err);
34688 +static int au_wbr_create_init_mfs(struct super_block *sb)
34690 + struct au_wbr_mfs *mfs;
34692 + mfs = &au_sbi(sb)->si_wbr_mfs;
34693 + mutex_init(&mfs->mfs_lock);
34694 + mfs->mfs_jiffy = 0;
34695 + mfs->mfs_bindex = -EROFS;
34700 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34702 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34706 +/* ---------------------------------------------------------------------- */
34708 +/* top down regardless parent, and then mfs */
34709 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34710 + unsigned int flags __maybe_unused)
34713 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34714 + unsigned long long watermark;
34715 + struct super_block *sb;
34716 + struct au_wbr_mfs *mfs;
34717 + struct au_branch *br;
34718 + struct dentry *parent;
34720 + sb = dentry->d_sb;
34721 + mfs = &au_sbi(sb)->si_wbr_mfs;
34722 + mutex_lock(&mfs->mfs_lock);
34723 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34724 + || mfs->mfs_bindex < 0)
34725 + au_mfs(dentry, /*parent*/NULL);
34726 + watermark = mfs->mfsrr_watermark;
34727 + bmfs = mfs->mfs_bindex;
34728 + mutex_unlock(&mfs->mfs_lock);
34730 + /* another style of au_wbr_create_exp() */
34731 + bwh = au_dbwh(dentry);
34732 + parent = dget_parent(dentry);
34733 + btail = au_dbtaildir(parent);
34734 + if (bwh >= 0 && bwh < btail)
34737 + err = au_wbr_nonopq(dentry, btail);
34738 + if (unlikely(err < 0))
34742 + for (bindex = 0; bindex <= btail; bindex++) {
34743 + br = au_sbr(sb, bindex);
34744 + if (au_br_rdonly(br))
34746 + if (br->br_wbr->wbr_bytes > watermark) {
34757 + AuDbg("b%d\n", err);
34761 +/* ---------------------------------------------------------------------- */
34763 +/* most free space and then round robin */
34764 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34767 + struct au_wbr_mfs *mfs;
34769 + err = au_wbr_create_mfs(dentry, flags);
34771 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34772 + mutex_lock(&mfs->mfs_lock);
34773 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34774 + err = au_wbr_create_rr(dentry, flags);
34775 + mutex_unlock(&mfs->mfs_lock);
34778 + AuDbg("b%d\n", err);
34782 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34786 + au_wbr_create_init_mfs(sb); /* ignore */
34787 + err = au_wbr_create_init_rr(sb);
34792 +/* ---------------------------------------------------------------------- */
34794 +/* top down parent and most free space */
34795 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34798 + unsigned long long b;
34799 + aufs_bindex_t bindex, btop, bbot;
34800 + struct super_block *sb;
34801 + struct dentry *parent, *h_parent;
34802 + struct au_branch *br;
34804 + err = au_wbr_create_tdp(dentry, flags);
34805 + if (unlikely(err < 0))
34807 + parent = dget_parent(dentry);
34808 + btop = au_dbtop(parent);
34809 + bbot = au_dbtaildir(parent);
34810 + if (btop == bbot)
34811 + goto out_parent; /* success */
34813 + e2 = au_wbr_create_mfs(dentry, flags);
34815 + goto out_parent; /* success */
34817 + /* when the available size is equal, select upper one */
34818 + sb = dentry->d_sb;
34819 + br = au_sbr(sb, err);
34820 + b = br->br_wbr->wbr_bytes;
34821 + AuDbg("b%d, %llu\n", err, b);
34823 + for (bindex = btop; bindex <= bbot; bindex++) {
34824 + h_parent = au_h_dptr(parent, bindex);
34825 + if (!h_parent || d_is_negative(h_parent))
34828 + br = au_sbr(sb, bindex);
34829 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34830 + b = br->br_wbr->wbr_bytes;
34832 + AuDbg("b%d, %llu\n", err, b);
34837 + err = au_wbr_nonopq(dentry, err);
34842 + AuDbg("b%d\n", err);
34846 +/* ---------------------------------------------------------------------- */
34849 + * - top down parent
34850 + * - most free space with parent
34851 + * - most free space round-robin regardless parent
34853 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34856 + unsigned long long watermark;
34857 + struct super_block *sb;
34858 + struct au_branch *br;
34859 + struct au_wbr_mfs *mfs;
34861 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34862 + if (unlikely(err < 0))
34865 + sb = dentry->d_sb;
34866 + br = au_sbr(sb, err);
34867 + mfs = &au_sbi(sb)->si_wbr_mfs;
34868 + mutex_lock(&mfs->mfs_lock);
34869 + watermark = mfs->mfsrr_watermark;
34870 + mutex_unlock(&mfs->mfs_lock);
34871 + if (br->br_wbr->wbr_bytes < watermark)
34872 + /* regardless the parent dir */
34873 + err = au_wbr_create_mfsrr(dentry, flags);
34876 + AuDbg("b%d\n", err);
34880 +/* ---------------------------------------------------------------------- */
34882 +/* policies for copyup */
34884 +/* top down parent */
34885 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34887 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34890 +/* bottom up parent */
34891 +static int au_wbr_copyup_bup(struct dentry *dentry)
34894 + aufs_bindex_t bindex, btop;
34895 + struct dentry *parent, *h_parent;
34896 + struct super_block *sb;
34899 + sb = dentry->d_sb;
34900 + parent = dget_parent(dentry);
34901 + btop = au_dbtop(parent);
34902 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34903 + h_parent = au_h_dptr(parent, bindex);
34904 + if (!h_parent || d_is_negative(h_parent))
34907 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34914 + /* bottom up here */
34915 + if (unlikely(err < 0))
34916 + err = au_wbr_bu(sb, btop - 1);
34918 + AuDbg("b%d\n", err);
34923 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34927 + err = au_wbr_bu(dentry->d_sb, btop);
34928 + AuDbg("b%d\n", err);
34930 + err = au_wbr_nonopq(dentry, err);
34932 + AuDbg("b%d\n", err);
34936 +static int au_wbr_copyup_bu(struct dentry *dentry)
34939 + aufs_bindex_t btop;
34941 + btop = au_dbtop(dentry);
34942 + err = au_wbr_do_copyup_bu(dentry, btop);
34946 +/* ---------------------------------------------------------------------- */
34948 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34949 + [AuWbrCopyup_TDP] = {
34950 + .copyup = au_wbr_copyup_tdp
34952 + [AuWbrCopyup_BUP] = {
34953 + .copyup = au_wbr_copyup_bup
34955 + [AuWbrCopyup_BU] = {
34956 + .copyup = au_wbr_copyup_bu
34960 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34961 + [AuWbrCreate_TDP] = {
34962 + .create = au_wbr_create_tdp
34964 + [AuWbrCreate_RR] = {
34965 + .create = au_wbr_create_rr,
34966 + .init = au_wbr_create_init_rr
34968 + [AuWbrCreate_MFS] = {
34969 + .create = au_wbr_create_mfs,
34970 + .init = au_wbr_create_init_mfs,
34971 + .fin = au_wbr_create_fin_mfs
34973 + [AuWbrCreate_MFSV] = {
34974 + .create = au_wbr_create_mfs,
34975 + .init = au_wbr_create_init_mfs,
34976 + .fin = au_wbr_create_fin_mfs
34978 + [AuWbrCreate_MFSRR] = {
34979 + .create = au_wbr_create_mfsrr,
34980 + .init = au_wbr_create_init_mfsrr,
34981 + .fin = au_wbr_create_fin_mfs
34983 + [AuWbrCreate_MFSRRV] = {
34984 + .create = au_wbr_create_mfsrr,
34985 + .init = au_wbr_create_init_mfsrr,
34986 + .fin = au_wbr_create_fin_mfs
34988 + [AuWbrCreate_TDMFS] = {
34989 + .create = au_wbr_create_tdmfs,
34990 + .init = au_wbr_create_init_mfs,
34991 + .fin = au_wbr_create_fin_mfs
34993 + [AuWbrCreate_TDMFSV] = {
34994 + .create = au_wbr_create_tdmfs,
34995 + .init = au_wbr_create_init_mfs,
34996 + .fin = au_wbr_create_fin_mfs
34998 + [AuWbrCreate_PMFS] = {
34999 + .create = au_wbr_create_pmfs,
35000 + .init = au_wbr_create_init_mfs,
35001 + .fin = au_wbr_create_fin_mfs
35003 + [AuWbrCreate_PMFSV] = {
35004 + .create = au_wbr_create_pmfs,
35005 + .init = au_wbr_create_init_mfs,
35006 + .fin = au_wbr_create_fin_mfs
35008 + [AuWbrCreate_PMFSRR] = {
35009 + .create = au_wbr_create_pmfsrr,
35010 + .init = au_wbr_create_init_mfsrr,
35011 + .fin = au_wbr_create_fin_mfs
35013 + [AuWbrCreate_PMFSRRV] = {
35014 + .create = au_wbr_create_pmfsrr,
35015 + .init = au_wbr_create_init_mfsrr,
35016 + .fin = au_wbr_create_fin_mfs
35019 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35020 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35021 +++ linux/fs/aufs/whout.c 2022-10-26 22:30:38.472648858 +0200
35023 +// SPDX-License-Identifier: GPL-2.0
35025 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35027 + * This program, aufs is free software; you can redistribute it and/or modify
35028 + * it under the terms of the GNU General Public License as published by
35029 + * the Free Software Foundation; either version 2 of the License, or
35030 + * (at your option) any later version.
35032 + * This program is distributed in the hope that it will be useful,
35033 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35034 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35035 + * GNU General Public License for more details.
35037 + * You should have received a copy of the GNU General Public License
35038 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35042 + * whiteout for logical deletion and opaque directory
35047 +#define WH_MASK 0444
35050 + * If a directory contains this file, then it is opaque. We start with the
35051 + * .wh. flag so that it is blocked by lookup.
35053 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35054 + sizeof(AUFS_WH_DIROPQ) - 1);
35057 + * generate whiteout name, which is NOT terminated by NULL.
35058 + * @name: original d_name.name
35059 + * @len: original d_name.len
35060 + * @wh: whiteout qstr
35061 + * returns zero when succeeds, otherwise error.
35062 + * succeeded value as wh->name should be freed by kfree().
35064 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35068 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35069 + return -ENAMETOOLONG;
35071 + wh->len = name->len + AUFS_WH_PFX_LEN;
35072 + p = kmalloc(wh->len, GFP_NOFS);
35075 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35076 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35083 +/* ---------------------------------------------------------------------- */
35086 + * test if the @wh_name exists under @h_ppath.
35087 + * @try_sio specifies the necessary of super-io.
35089 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35090 + struct qstr *wh_name, int try_sio)
35093 + struct dentry *wh_dentry;
35096 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35098 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
35099 + err = PTR_ERR(wh_dentry);
35100 + if (IS_ERR(wh_dentry)) {
35101 + if (err == -ENAMETOOLONG)
35107 + if (d_is_negative(wh_dentry))
35108 + goto out_wh; /* success */
35111 + if (d_is_reg(wh_dentry))
35112 + goto out_wh; /* success */
35115 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35116 + wh_dentry, d_inode(wh_dentry)->i_mode);
35125 + * test if the @h_path->dentry sets opaque or not.
35127 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
35130 + struct inode *h_dir;
35132 + h_dir = d_inode(h_path->dentry);
35133 + err = au_wh_test(h_userns, h_path, &diropq_name,
35134 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
35139 + * returns a negative dentry whose name is unique and temporary.
35141 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35142 + struct qstr *prefix)
35144 + struct dentry *dentry;
35146 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35148 + /* strict atomic_t is unnecessary here */
35149 + static unsigned short cnt;
35151 + struct path h_ppath;
35152 + struct user_namespace *h_userns;
35154 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35157 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35158 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35159 + dentry = ERR_PTR(-ENAMETOOLONG);
35160 + if (unlikely(qs.len > NAME_MAX))
35162 + dentry = ERR_PTR(-ENOMEM);
35163 + name = kmalloc(qs.len + 1, GFP_NOFS);
35164 + if (unlikely(!name))
35168 + /* doubly whiteout-ed */
35169 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35170 + p = name + AUFS_WH_PFX_LEN * 2;
35171 + memcpy(p, prefix->name, prefix->len);
35172 + p += prefix->len;
35174 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35176 + h_ppath.dentry = h_parent;
35177 + h_ppath.mnt = au_br_mnt(br);
35178 + h_userns = au_br_userns(br);
35180 + for (i = 0; i < 3; i++) {
35181 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35182 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
35183 + if (IS_ERR(dentry) || d_is_negative(dentry))
35187 + /* pr_warn("could not get random name\n"); */
35188 + dentry = ERR_PTR(-EEXIST);
35189 + AuDbg("%.*s\n", AuLNPair(&qs));
35193 + if (name != defname)
35194 + au_kfree_try_rcu(name);
35196 + AuTraceErrPtr(dentry);
35201 + * rename the @h_dentry on @br to the whiteouted temporary name.
35203 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35206 + struct path h_path = {
35207 + .mnt = au_br_mnt(br)
35209 + struct inode *h_dir, *delegated;
35210 + struct dentry *h_parent;
35212 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35213 + h_dir = d_inode(h_parent);
35214 + IMustLock(h_dir);
35216 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35217 + err = PTR_ERR(h_path.dentry);
35218 + if (IS_ERR(h_path.dentry))
35221 + /* under the same dir, no need to lock_rename() */
35222 + delegated = NULL;
35223 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35226 + if (unlikely(err == -EWOULDBLOCK)) {
35227 + pr_warn("cannot retry for NFSv4 delegation"
35228 + " for an internal rename\n");
35231 + dput(h_path.dentry);
35238 +/* ---------------------------------------------------------------------- */
35240 + * functions for removing a whiteout
35243 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35246 + struct inode *delegated;
35249 + * forces superio when the dir has a sticky bit.
35250 + * this may be a violation of unix fs semantics.
35252 + force = (h_dir->i_mode & S_ISVTX)
35253 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35254 + delegated = NULL;
35255 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35256 + if (unlikely(err == -EWOULDBLOCK)) {
35257 + pr_warn("cannot retry for NFSv4 delegation"
35258 + " for an internal unlink\n");
35264 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35265 + struct dentry *dentry)
35269 + err = do_unlink_wh(h_dir, h_path);
35270 + if (!err && dentry)
35271 + au_set_dbwh(dentry, -1);
35276 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35279 + struct path h_path;
35282 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35283 + if (IS_ERR(h_path.dentry))
35284 + err = PTR_ERR(h_path.dentry);
35286 + if (d_is_reg(h_path.dentry)) {
35287 + h_path.mnt = h_ppath->mnt;
35288 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35290 + dput(h_path.dentry);
35296 +/* ---------------------------------------------------------------------- */
35298 + * initialize/clean whiteout for a branch
35301 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35305 + struct inode *delegated;
35307 + if (d_is_negative(whpath->dentry))
35311 + err = vfsub_rmdir(h_dir, whpath);
35313 + delegated = NULL;
35314 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35315 + if (unlikely(err == -EWOULDBLOCK)) {
35316 + pr_warn("cannot retry for NFSv4 delegation"
35317 + " for an internal unlink\n");
35321 + if (unlikely(err))
35322 + pr_warn("failed removing %pd (%d), ignored.\n",
35323 + whpath->dentry, err);
35326 +static int test_linkable(struct dentry *h_root)
35328 + struct inode *h_dir = d_inode(h_root);
35330 + if (h_dir->i_op->link)
35333 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35334 + h_root, au_sbtype(h_root->d_sb));
35335 + return -ENOSYS; /* the branch doesn't have its ->link() */
35338 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35339 +static int au_whdir(struct inode *h_dir, struct path *path)
35344 + if (d_is_negative(path->dentry)) {
35347 + if (au_test_nfs(path->dentry->d_sb))
35349 + err = vfsub_mkdir(h_dir, path, mode);
35350 + } else if (d_is_dir(path->dentry))
35353 + pr_err("unknown %pd exists\n", path->dentry);
35358 +struct au_wh_base {
35359 + const struct qstr *name;
35360 + struct dentry *dentry;
35363 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35364 + struct path *h_path)
35366 + h_path->dentry = base[AuBrWh_BASE].dentry;
35367 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35368 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35369 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35370 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35371 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35375 + * returns tri-state,
35376 + * minus: error, caller should print the message
35378 + * plus: error, caller should NOT print the message
35380 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35381 + int do_plink, struct au_wh_base base[],
35382 + struct path *h_path)
35385 + struct inode *h_dir;
35387 + h_dir = d_inode(h_root);
35388 + h_path->dentry = base[AuBrWh_BASE].dentry;
35389 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35390 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35392 + err = test_linkable(h_root);
35393 + if (unlikely(err)) {
35398 + err = au_whdir(h_dir, h_path);
35399 + if (unlikely(err))
35401 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35403 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35404 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35405 + err = au_whdir(h_dir, h_path);
35406 + if (unlikely(err))
35408 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35415 + * for the moment, aufs supports the branch filesystem which does not support
35416 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35417 + * copyup failed. finally, such filesystem will not be used as the writable
35420 + * returns tri-state, see above.
35422 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35423 + int do_plink, struct au_wh_base base[],
35424 + struct path *h_path)
35427 + struct inode *h_dir;
35429 + WbrWhMustWriteLock(wbr);
35431 + err = test_linkable(h_root);
35432 + if (unlikely(err)) {
35438 + * todo: should this create be done in /sbin/mount.aufs helper?
35441 + h_dir = d_inode(h_root);
35442 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35443 + h_path->dentry = base[AuBrWh_BASE].dentry;
35444 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35445 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35448 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35449 + if (unlikely(err))
35452 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35454 + err = au_whdir(h_dir, h_path);
35455 + if (unlikely(err))
35457 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35459 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35460 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35462 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35463 + err = au_whdir(h_dir, h_path);
35464 + if (unlikely(err))
35466 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35473 + * initialize the whiteout base file/dir for @br.
35475 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35478 + const unsigned char do_plink
35479 + = !!au_opt_test(au_mntflags(sb), PLINK);
35480 + struct inode *h_dir;
35481 + struct path path = br->br_path;
35482 + struct dentry *h_root = path.dentry;
35483 + struct au_wbr *wbr = br->br_wbr;
35484 + static const struct qstr base_name[] = {
35485 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35486 + sizeof(AUFS_BASE_NAME) - 1),
35487 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35488 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35489 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35490 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35492 + struct au_wh_base base[] = {
35493 + [AuBrWh_BASE] = {
35494 + .name = base_name + AuBrWh_BASE,
35497 + [AuBrWh_PLINK] = {
35498 + .name = base_name + AuBrWh_PLINK,
35501 + [AuBrWh_ORPH] = {
35502 + .name = base_name + AuBrWh_ORPH,
35508 + WbrWhMustWriteLock(wbr);
35510 + for (i = 0; i < AuBrWh_Last; i++) {
35511 + /* doubly whiteouted */
35512 + struct dentry *d;
35514 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35515 + err = PTR_ERR(d);
35519 + base[i].dentry = d;
35521 + && wbr->wbr_wh[i]
35522 + && wbr->wbr_wh[i] != base[i].dentry);
35526 + for (i = 0; i < AuBrWh_Last; i++) {
35527 + dput(wbr->wbr_wh[i]);
35528 + wbr->wbr_wh[i] = NULL;
35532 + if (!au_br_writable(br->br_perm)) {
35533 + h_dir = d_inode(h_root);
35534 + au_wh_init_ro(h_dir, base, &path);
35535 + } else if (!au_br_wh_linkable(br->br_perm)) {
35536 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35542 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35548 + goto out; /* success */
35551 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35552 + err, h_root, au_sbtype(h_root->d_sb));
35554 + for (i = 0; i < AuBrWh_Last; i++)
35555 + dput(base[i].dentry);
35559 +/* ---------------------------------------------------------------------- */
35561 + * whiteouts are all hard-linked usually.
35562 + * when its link count reaches a ceiling, we create a new whiteout base
35563 + * asynchronously.
35566 +struct reinit_br_wh {
35567 + struct super_block *sb;
35568 + struct au_branch *br;
35571 +static void reinit_br_wh(void *arg)
35574 + aufs_bindex_t bindex;
35575 + struct path h_path;
35576 + struct reinit_br_wh *a = arg;
35577 + struct au_wbr *wbr;
35578 + struct inode *dir, *delegated;
35579 + struct dentry *h_root;
35580 + struct au_hinode *hdir;
35583 + wbr = a->br->br_wbr;
35584 + /* big aufs lock */
35585 + si_noflush_write_lock(a->sb);
35586 + if (!au_br_writable(a->br->br_perm))
35588 + bindex = au_br_index(a->sb, a->br->br_id);
35589 + if (unlikely(bindex < 0))
35592 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35593 + dir = d_inode(a->sb->s_root);
35594 + hdir = au_hi(dir, bindex);
35595 + h_root = au_h_dptr(a->sb->s_root, bindex);
35596 + AuDebugOn(h_root != au_br_dentry(a->br));
35598 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35599 + wbr_wh_write_lock(wbr);
35600 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35603 + h_path.dentry = wbr->wbr_whbase;
35604 + h_path.mnt = au_br_mnt(a->br);
35605 + delegated = NULL;
35606 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35608 + if (unlikely(err == -EWOULDBLOCK)) {
35609 + pr_warn("cannot retry for NFSv4 delegation"
35610 + " for an internal unlink\n");
35614 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35617 + dput(wbr->wbr_whbase);
35618 + wbr->wbr_whbase = NULL;
35620 + err = au_wh_init(a->br, a->sb);
35621 + wbr_wh_write_unlock(wbr);
35622 + au_hn_inode_unlock(hdir);
35623 + di_read_unlock(a->sb->s_root, AuLock_IR);
35625 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35629 + atomic_dec(&wbr->wbr_wh_running);
35630 + au_lcnt_dec(&a->br->br_count);
35631 + si_write_unlock(a->sb);
35632 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35634 + if (unlikely(err))
35635 + AuIOErr("err %d\n", err);
35638 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35640 + int do_dec, wkq_err;
35641 + struct reinit_br_wh *arg;
35644 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35647 + /* ignore ENOMEM */
35648 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35651 + * dec(wh_running), kfree(arg) and dec(br_count)
35652 + * in reinit function
35656 + au_lcnt_inc(&br->br_count);
35657 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35658 + if (unlikely(wkq_err)) {
35659 + atomic_dec(&br->br_wbr->wbr_wh_running);
35660 + au_lcnt_dec(&br->br_count);
35661 + au_kfree_rcu(arg);
35668 + atomic_dec(&br->br_wbr->wbr_wh_running);
35671 +/* ---------------------------------------------------------------------- */
35674 + * create the whiteout @wh.
35676 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35677 + struct dentry *wh)
35680 + struct path h_path = {
35683 + struct au_branch *br;
35684 + struct au_wbr *wbr;
35685 + struct dentry *h_parent;
35686 + struct inode *h_dir, *delegated;
35688 + h_parent = wh->d_parent; /* dir inode is locked */
35689 + h_dir = d_inode(h_parent);
35690 + IMustLock(h_dir);
35692 + br = au_sbr(sb, bindex);
35693 + h_path.mnt = au_br_mnt(br);
35694 + wbr = br->br_wbr;
35695 + wbr_wh_read_lock(wbr);
35696 + if (wbr->wbr_whbase) {
35697 + delegated = NULL;
35698 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35699 + if (unlikely(err == -EWOULDBLOCK)) {
35700 + pr_warn("cannot retry for NFSv4 delegation"
35701 + " for an internal link\n");
35704 + if (!err || err != -EMLINK)
35707 + /* link count full. re-initialize br_whbase. */
35708 + kick_reinit_br_wh(sb, br);
35711 + /* return this error in this context */
35712 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35714 + au_fhsm_wrote(sb, bindex, /*force*/0);
35717 + wbr_wh_read_unlock(wbr);
35721 +/* ---------------------------------------------------------------------- */
35724 + * create or remove the diropq.
35726 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35727 + unsigned int flags)
35729 + struct dentry *opq_dentry;
35730 + struct super_block *sb;
35731 + struct au_branch *br;
35732 + struct path h_path;
35735 + sb = dentry->d_sb;
35736 + br = au_sbr(sb, bindex);
35737 + h_path.dentry = au_h_dptr(dentry, bindex);
35738 + h_path.mnt = au_br_mnt(br);
35739 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35740 + if (IS_ERR(opq_dentry))
35743 + if (au_ftest_diropq(flags, CREATE)) {
35744 + err = link_or_create_wh(sb, bindex, opq_dentry);
35746 + au_set_dbdiropq(dentry, bindex);
35747 + goto out; /* success */
35750 + h_path.dentry = opq_dentry;
35751 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35753 + au_set_dbdiropq(dentry, -1);
35755 + dput(opq_dentry);
35756 + opq_dentry = ERR_PTR(err);
35759 + return opq_dentry;
35762 +struct do_diropq_args {
35763 + struct dentry **errp;
35764 + struct dentry *dentry;
35765 + aufs_bindex_t bindex;
35766 + unsigned int flags;
35769 +static void call_do_diropq(void *args)
35771 + struct do_diropq_args *a = args;
35772 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35775 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35776 + unsigned int flags)
35778 + struct dentry *diropq, *h_dentry;
35779 + struct user_namespace *h_userns;
35781 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35782 + h_dentry = au_h_dptr(dentry, bindex);
35783 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35784 + MAY_EXEC | MAY_WRITE))
35785 + diropq = do_diropq(dentry, bindex, flags);
35788 + struct do_diropq_args args = {
35790 + .dentry = dentry,
35791 + .bindex = bindex,
35795 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35796 + if (unlikely(wkq_err))
35797 + diropq = ERR_PTR(wkq_err);
35803 +/* ---------------------------------------------------------------------- */
35806 + * lookup whiteout dentry.
35807 + * @h_parent: lower parent dentry which must exist and be locked
35808 + * @base_name: name of dentry which will be whiteouted
35809 + * returns dentry for whiteout.
35811 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35812 + struct au_branch *br)
35815 + struct qstr wh_name;
35816 + struct dentry *wh_dentry;
35817 + struct path h_path;
35819 + err = au_wh_name_alloc(&wh_name, base_name);
35820 + wh_dentry = ERR_PTR(err);
35822 + h_path.dentry = h_parent;
35823 + h_path.mnt = au_br_mnt(br);
35824 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35825 + au_kfree_try_rcu(wh_name.name);
35827 + return wh_dentry;
35831 + * link/create a whiteout for @dentry on @bindex.
35833 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35834 + struct dentry *h_parent)
35836 + struct dentry *wh_dentry;
35837 + struct super_block *sb;
35840 + sb = dentry->d_sb;
35841 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35842 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35843 + err = link_or_create_wh(sb, bindex, wh_dentry);
35845 + au_set_dbwh(dentry, bindex);
35846 + au_fhsm_wrote(sb, bindex, /*force*/0);
35849 + wh_dentry = ERR_PTR(err);
35853 + return wh_dentry;
35856 +/* ---------------------------------------------------------------------- */
35858 +/* Delete all whiteouts in this directory on branch bindex. */
35859 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35860 + aufs_bindex_t bindex)
35863 + unsigned long ul, n;
35864 + struct qstr wh_name;
35866 + struct hlist_head *head;
35867 + struct au_vdir_wh *pos;
35868 + struct au_vdir_destr *str;
35871 + p = (void *)__get_free_page(GFP_NOFS);
35872 + wh_name.name = p;
35873 + if (unlikely(!wh_name.name))
35877 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35878 + p += AUFS_WH_PFX_LEN;
35879 + n = whlist->nh_num;
35880 + head = whlist->nh_head;
35881 + for (ul = 0; !err && ul < n; ul++, head++) {
35882 + hlist_for_each_entry(pos, head, wh_hash) {
35883 + if (pos->wh_bindex != bindex)
35886 + str = &pos->wh_str;
35887 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35888 + memcpy(p, str->name, str->len);
35889 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35890 + err = unlink_wh_name(h_path, &wh_name);
35895 + AuIOErr("whiteout name too long %.*s\n",
35896 + str->len, str->name);
35901 + free_page((unsigned long)wh_name.name);
35907 +struct del_wh_children_args {
35909 + struct path *h_path;
35910 + struct au_nhash *whlist;
35911 + aufs_bindex_t bindex;
35914 +static void call_del_wh_children(void *args)
35916 + struct del_wh_children_args *a = args;
35917 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35920 +/* ---------------------------------------------------------------------- */
35922 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35924 + struct au_whtmp_rmdir *whtmp;
35926 + unsigned int rdhash;
35928 + SiMustAnyLock(sb);
35930 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35931 + if (unlikely(!whtmp)) {
35932 + whtmp = ERR_PTR(-ENOMEM);
35936 + /* no estimation for dir size */
35937 + rdhash = au_sbi(sb)->si_rdhash;
35939 + rdhash = AUFS_RDHASH_DEF;
35940 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35941 + if (unlikely(err)) {
35942 + au_kfree_rcu(whtmp);
35943 + whtmp = ERR_PTR(err);
35950 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35953 + au_lcnt_dec(&whtmp->br->br_count);
35954 + dput(whtmp->wh_dentry);
35955 + iput(whtmp->dir);
35956 + au_nhash_wh_free(&whtmp->whlist);
35957 + au_kfree_rcu(whtmp);
35961 + * rmdir the whiteouted temporary named dir @h_dentry.
35962 + * @whlist: whiteouted children.
35964 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35965 + struct dentry *wh_dentry, struct au_nhash *whlist)
35968 + unsigned int h_nlink;
35969 + struct path wh_path;
35970 + struct inode *wh_inode, *h_dir;
35971 + struct au_branch *br;
35972 + struct user_namespace *h_userns;
35974 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35975 + IMustLock(h_dir);
35977 + br = au_sbr(dir->i_sb, bindex);
35978 + wh_path.dentry = wh_dentry;
35979 + wh_path.mnt = au_br_mnt(br);
35980 + h_userns = au_br_userns(br);
35981 + wh_inode = d_inode(wh_dentry);
35982 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35985 + * someone else might change some whiteouts while we were sleeping.
35986 + * it means this whlist may have an obsoleted entry.
35988 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35989 + err = del_wh_children(&wh_path, whlist, bindex);
35992 + struct del_wh_children_args args = {
35994 + .h_path = &wh_path,
35995 + .whlist = whlist,
35999 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36000 + if (unlikely(wkq_err))
36003 + inode_unlock(wh_inode);
36006 + h_nlink = h_dir->i_nlink;
36007 + err = vfsub_rmdir(h_dir, &wh_path);
36008 + /* some fs doesn't change the parent nlink in some cases */
36009 + h_nlink -= h_dir->i_nlink;
36013 + if (au_ibtop(dir) == bindex) {
36014 + /* todo: dir->i_mutex is necessary */
36015 + au_cpup_attr_timesizes(dir);
36017 + vfsub_drop_nlink(dir);
36019 + return 0; /* success */
36022 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36026 +static void call_rmdir_whtmp(void *args)
36029 + aufs_bindex_t bindex;
36030 + struct au_whtmp_rmdir *a = args;
36031 + struct super_block *sb;
36032 + struct dentry *h_parent;
36033 + struct inode *h_dir;
36034 + struct au_hinode *hdir;
36036 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36037 + /* inode_lock(a->dir); */
36039 + sb = a->dir->i_sb;
36040 + si_read_lock(sb, !AuLock_FLUSH);
36041 + if (!au_br_writable(a->br->br_perm))
36043 + bindex = au_br_index(sb, a->br->br_id);
36044 + if (unlikely(bindex < 0))
36048 + ii_write_lock_parent(a->dir);
36049 + h_parent = dget_parent(a->wh_dentry);
36050 + h_dir = d_inode(h_parent);
36051 + hdir = au_hi(a->dir, bindex);
36052 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36053 + if (unlikely(err))
36055 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36056 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36059 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36060 + au_hn_inode_unlock(hdir);
36061 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36065 + ii_write_unlock(a->dir);
36067 + /* inode_unlock(a->dir); */
36068 + au_whtmp_rmdir_free(a);
36069 + si_read_unlock(sb);
36070 + au_nwt_done(&au_sbi(sb)->si_nowait);
36071 + if (unlikely(err))
36072 + AuIOErr("err %d\n", err);
36075 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36076 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36079 + struct super_block *sb;
36083 + /* all post-process will be done in do_rmdir_whtmp(). */
36085 + args->dir = au_igrab(dir);
36086 + args->br = au_sbr(sb, bindex);
36087 + au_lcnt_inc(&args->br->br_count);
36088 + args->wh_dentry = dget(wh_dentry);
36089 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36090 + if (unlikely(wkq_err)) {
36091 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36092 + au_whtmp_rmdir_free(args);
36095 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36096 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36097 +++ linux/fs/aufs/whout.h 2022-10-26 22:30:38.472648858 +0200
36099 +/* SPDX-License-Identifier: GPL-2.0 */
36101 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36103 + * This program, aufs is free software; you can redistribute it and/or modify
36104 + * it under the terms of the GNU General Public License as published by
36105 + * the Free Software Foundation; either version 2 of the License, or
36106 + * (at your option) any later version.
36108 + * This program is distributed in the hope that it will be useful,
36109 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36110 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36111 + * GNU General Public License for more details.
36113 + * You should have received a copy of the GNU General Public License
36114 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36118 + * whiteout for logical deletion and opaque directory
36121 +#ifndef __AUFS_WHOUT_H__
36122 +#define __AUFS_WHOUT_H__
36129 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36130 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
36131 + struct qstr *wh_name, int try_sio);
36132 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
36134 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36135 + struct qstr *prefix);
36136 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36137 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36138 + struct dentry *dentry);
36139 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36141 +/* diropq flags */
36142 +#define AuDiropq_CREATE 1
36143 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36144 +#define au_fset_diropq(flags, name) \
36145 + do { (flags) |= AuDiropq_##name; } while (0)
36146 +#define au_fclr_diropq(flags, name) \
36147 + do { (flags) &= ~AuDiropq_##name; } while (0)
36149 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36150 + unsigned int flags);
36151 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36152 + struct au_branch *br);
36153 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36154 + struct dentry *h_parent);
36156 +/* real rmdir for the whiteout-ed dir */
36157 +struct au_whtmp_rmdir {
36158 + struct inode *dir;
36159 + struct au_branch *br;
36160 + struct dentry *wh_dentry;
36161 + struct au_nhash whlist;
36164 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36165 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36166 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36167 + struct dentry *wh_dentry, struct au_nhash *whlist);
36168 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36169 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36171 +/* ---------------------------------------------------------------------- */
36173 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36174 + aufs_bindex_t bindex)
36176 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36179 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36181 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36184 +#endif /* __KERNEL__ */
36185 +#endif /* __AUFS_WHOUT_H__ */
36186 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36187 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36188 +++ linux/fs/aufs/wkq.c 2022-10-26 22:30:38.472648858 +0200
36190 +// SPDX-License-Identifier: GPL-2.0
36192 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36194 + * This program, aufs is free software; you can redistribute it and/or modify
36195 + * it under the terms of the GNU General Public License as published by
36196 + * the Free Software Foundation; either version 2 of the License, or
36197 + * (at your option) any later version.
36199 + * This program is distributed in the hope that it will be useful,
36200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36202 + * GNU General Public License for more details.
36204 + * You should have received a copy of the GNU General Public License
36205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36209 + * workqueue for asynchronous/super-io operations
36210 + * todo: try new credential scheme
36213 +#include <linux/module.h>
36216 +/* internal workqueue named AUFS_WKQ_NAME */
36218 +static struct workqueue_struct *au_wkq;
36220 +struct au_wkinfo {
36221 + struct work_struct wk;
36222 + struct kobject *kobj;
36224 + unsigned int flags; /* see wkq.h */
36226 + au_wkq_func_t func;
36229 +#ifdef CONFIG_LOCKDEP
36231 + struct held_lock **hlock;
36234 + struct completion *comp;
36237 +/* ---------------------------------------------------------------------- */
36239 + * Aufs passes some operations to the workqueue such as the internal copyup.
36240 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36241 + * job run by workqueue depends upon the locks acquired in the other task.
36242 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36243 + * information too. And the job in the workqueue restores the info in order to
36244 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36245 + * correctly and expectedly.
36248 +#ifndef CONFIG_LOCKDEP
36249 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36250 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36251 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36252 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36253 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36255 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36257 + wkinfo->hlock = NULL;
36258 + wkinfo->dont_check = 0;
36265 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36267 + static DEFINE_SPINLOCK(spin);
36270 + struct lock_class_key *key;
36272 + { .name = "&sbinfo->si_rwsem" },
36273 + { .name = "&finfo->fi_rwsem" },
36274 + { .name = "&dinfo->di_rwsem" },
36275 + { .name = "&iinfo->ii_rwsem" }
36280 + /* lockless read from 'set.' see below */
36281 + if (set == ARRAY_SIZE(a)) {
36282 + for (i = 0; i < ARRAY_SIZE(a); i++)
36283 + if (a[i].key == key)
36288 + spin_lock(&spin);
36290 + for (i = 0; i < ARRAY_SIZE(a); i++)
36291 + if (a[i].key == key) {
36292 + spin_unlock(&spin);
36295 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36297 + if (unlikely(a[i].key == key)) { /* rare but possible */
36298 + spin_unlock(&spin);
36303 + if (strstr(a[i].name, name)) {
36305 + * the order of these three lines is important for the
36306 + * lockless read above.
36309 + spin_unlock(&spin);
36311 + /* AuDbg("%d, %s\n", set, name); */
36315 + spin_unlock(&spin);
36324 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36327 + struct task_struct *curr;
36328 + struct held_lock **hl, *held_locks, *p;
36332 + wkinfo->dont_check = lockdep_recursing(curr);
36333 + if (wkinfo->dont_check)
36335 + n = curr->lockdep_depth;
36340 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36341 + if (unlikely(!wkinfo->hlock))
36345 +#if 0 /* left for debugging */
36346 + if (0 && au_debug_test())
36347 + lockdep_print_held_locks(curr);
36349 + held_locks = curr->held_locks;
36350 + hl = wkinfo->hlock;
36352 + p = held_locks++;
36353 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36362 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36364 + au_kfree_try_rcu(wkinfo->hlock);
36367 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36369 + struct held_lock *p, **hl = wkinfo->hlock;
36372 + if (wkinfo->dont_check)
36376 + while ((p = *hl++)) { /* assignment */
36377 + subclass = lockdep_hlock_class(p)->subclass;
36378 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36380 + rwsem_acquire_read(p->instance, subclass, 0,
36381 + /*p->acquire_ip*/_RET_IP_);
36383 + rwsem_acquire(p->instance, subclass, 0,
36384 + /*p->acquire_ip*/_RET_IP_);
36388 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36390 + struct held_lock *p, **hl = wkinfo->hlock;
36392 + if (wkinfo->dont_check)
36396 + while ((p = *hl++)) /* assignment */
36397 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36401 +static void wkq_func(struct work_struct *wk)
36403 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36405 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36406 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36408 + au_wkq_lockdep_pre(wkinfo);
36409 + wkinfo->func(wkinfo->args);
36410 + au_wkq_lockdep_post(wkinfo);
36411 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36412 + complete(wkinfo->comp);
36414 + kobject_put(wkinfo->kobj);
36415 + module_put(THIS_MODULE); /* todo: ?? */
36416 + au_kfree_rcu(wkinfo);
36421 + * Since struct completion is large, try allocating it dynamically.
36423 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36425 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36427 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36429 + init_completion(*comp);
36430 + wkinfo->comp = *comp;
36436 +static void au_wkq_comp_free(struct completion *comp)
36438 + au_kfree_rcu(comp);
36441 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36443 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36444 + if (au_wkq_test()) {
36445 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36446 + " due to a dead dir by UDBA,"
36447 + " or async xino write?\n");
36448 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36451 + au_dbg_verify_kthread();
36453 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36454 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36455 + queue_work(au_wkq, &wkinfo->wk);
36457 + INIT_WORK(&wkinfo->wk, wkq_func);
36458 + schedule_work(&wkinfo->wk);
36463 + * Be careful. It is easy to make deadlock happen.
36464 + * processA: lock, wkq and wait
36465 + * processB: wkq and wait, lock in wkq
36468 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36471 + AuWkqCompDeclare(comp);
36472 + struct au_wkinfo wkinfo = {
36478 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36479 + if (unlikely(err))
36481 + err = au_wkq_lockdep_alloc(&wkinfo);
36482 + if (unlikely(err))
36485 + au_wkq_run(&wkinfo);
36486 + /* no timeout, no interrupt */
36487 + wait_for_completion(wkinfo.comp);
36489 + au_wkq_lockdep_free(&wkinfo);
36492 + au_wkq_comp_free(comp);
36494 + destroy_work_on_stack(&wkinfo.wk);
36499 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36500 + * problem in a concurrent umounting.
36502 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36503 + unsigned int flags)
36506 + struct au_wkinfo *wkinfo;
36508 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36511 + * wkq_func() must free this wkinfo.
36512 + * it highly depends upon the implementation of workqueue.
36515 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36517 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36518 + wkinfo->flags = flags & ~AuWkq_WAIT;
36519 + wkinfo->func = func;
36520 + wkinfo->args = args;
36521 + wkinfo->comp = NULL;
36522 + au_wkq_lockdep_init(wkinfo);
36523 + kobject_get(wkinfo->kobj);
36524 + __module_get(THIS_MODULE); /* todo: ?? */
36526 + au_wkq_run(wkinfo);
36529 + au_nwt_done(&au_sbi(sb)->si_nowait);
36535 +/* ---------------------------------------------------------------------- */
36537 +void au_nwt_init(struct au_nowait_tasks *nwt)
36539 + atomic_set(&nwt->nw_len, 0);
36540 + /* smp_mb(); */ /* atomic_set */
36541 + init_waitqueue_head(&nwt->nw_wq);
36544 +void au_wkq_fin(void)
36546 + destroy_workqueue(au_wkq);
36549 +int __init au_wkq_init(void)
36554 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36555 + if (IS_ERR(au_wkq))
36556 + err = PTR_ERR(au_wkq);
36557 + else if (!au_wkq)
36562 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36563 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36564 +++ linux/fs/aufs/wkq.h 2022-10-26 22:30:38.472648858 +0200
36566 +/* SPDX-License-Identifier: GPL-2.0 */
36568 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36570 + * This program, aufs is free software; you can redistribute it and/or modify
36571 + * it under the terms of the GNU General Public License as published by
36572 + * the Free Software Foundation; either version 2 of the License, or
36573 + * (at your option) any later version.
36575 + * This program is distributed in the hope that it will be useful,
36576 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36577 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36578 + * GNU General Public License for more details.
36580 + * You should have received a copy of the GNU General Public License
36581 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36585 + * workqueue for asynchronous/super-io operations
36586 + * todo: try new credentials management scheme
36589 +#ifndef __AUFS_WKQ_H__
36590 +#define __AUFS_WKQ_H__
36594 +#include <linux/wait.h>
36596 +struct super_block;
36598 +/* ---------------------------------------------------------------------- */
36601 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36603 +struct au_nowait_tasks {
36605 + wait_queue_head_t nw_wq;
36608 +/* ---------------------------------------------------------------------- */
36610 +typedef void (*au_wkq_func_t)(void *args);
36613 +#define AuWkq_WAIT 1
36614 +#define AuWkq_NEST (1 << 1)
36615 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36616 +#define au_fset_wkq(flags, name) \
36617 + do { (flags) |= AuWkq_##name; } while (0)
36618 +#define au_fclr_wkq(flags, name) \
36619 + do { (flags) &= ~AuWkq_##name; } while (0)
36622 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36623 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36624 + unsigned int flags);
36625 +void au_nwt_init(struct au_nowait_tasks *nwt);
36626 +int __init au_wkq_init(void);
36627 +void au_wkq_fin(void);
36629 +/* ---------------------------------------------------------------------- */
36631 +static inline int au_wkq_test(void)
36633 + return current->flags & PF_WQ_WORKER;
36636 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36638 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36641 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36643 + if (atomic_dec_and_test(&nwt->nw_len))
36644 + wake_up_all(&nwt->nw_wq);
36647 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36649 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36653 +#endif /* __KERNEL__ */
36654 +#endif /* __AUFS_WKQ_H__ */
36655 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36656 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36657 +++ linux/fs/aufs/xattr.c 2022-10-26 22:30:38.475982192 +0200
36659 +// SPDX-License-Identifier: GPL-2.0
36661 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36663 + * This program, aufs is free software; you can redistribute it and/or modify
36664 + * it under the terms of the GNU General Public License as published by
36665 + * the Free Software Foundation; either version 2 of the License, or
36666 + * (at your option) any later version.
36668 + * This program is distributed in the hope that it will be useful,
36669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36671 + * GNU General Public License for more details.
36673 + * You should have received a copy of the GNU General Public License
36674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36678 + * handling xattr functions
36681 +#include <linux/fs.h>
36682 +#include <linux/posix_acl_xattr.h>
36683 +#include <linux/xattr.h>
36686 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36688 + if (!ignore_flags)
36696 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36701 +#define cmp(brattr, prefix) do { \
36702 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36703 + XATTR_##prefix##_PREFIX_LEN)) { \
36704 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36710 + cmp(SEC, SECURITY);
36711 + cmp(SYS, SYSTEM);
36712 + cmp(TR, TRUSTED);
36716 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36723 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36725 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36726 + char *name, char **buf, unsigned int ignore_flags,
36727 + unsigned int verbose)
36731 + struct inode *h_idst;
36732 + struct dentry *h_dst_dentry, *h_src_dentry;
36733 + struct user_namespace *h_dst_userns, *h_src_userns;
36735 + h_src_userns = mnt_user_ns(h_src->mnt);
36736 + h_src_dentry = h_src->dentry;
36737 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36740 + if (unlikely(err <= 0)) {
36741 + if (err == -ENODATA
36742 + || (err == -EOPNOTSUPP
36743 + && ((ignore_flags & au_xattr_out_of_list)
36744 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36745 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36747 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36750 + if (err && (verbose || au_debug_test()))
36751 + pr_err("%s, err %d\n", name, err);
36755 + /* unlock it temporary */
36756 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36757 + h_dst_dentry = h_dst->dentry;
36758 + h_idst = d_inode(h_dst_dentry);
36759 + inode_unlock(h_idst);
36760 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36762 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36763 + if (unlikely(err)) {
36764 + if (verbose || au_debug_test())
36765 + pr_err("%s, err %d\n", name, err);
36766 + err = au_xattr_ignore(err, name, ignore_flags);
36773 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36774 + unsigned int verbose)
36776 + int err, unlocked, acl_access, acl_default;
36778 + struct dentry *h_dst_dentry, *h_src_dentry;
36779 + struct inode *h_isrc, *h_idst;
36780 + char *value, *p, *o, *e;
36782 + /* try stopping to update the source inode while we are referencing */
36783 + /* there should not be the parent-child relationship between them */
36784 + h_dst_dentry = h_dst->dentry;
36785 + h_idst = d_inode(h_dst_dentry);
36786 + h_src_dentry = h_src->dentry;
36787 + h_isrc = d_inode(h_src_dentry);
36788 + inode_unlock(h_idst);
36789 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36790 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36793 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36794 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36796 + if (unlikely(err < 0)) {
36798 + if (err == -ENODATA
36799 + || err == -EOPNOTSUPP)
36800 + err = 0; /* ignore */
36809 + p = kmalloc(ssz, GFP_NOFS);
36811 + if (unlikely(!p))
36813 + err = vfs_listxattr(h_src_dentry, p, ssz);
36815 + inode_unlock_shared(h_isrc);
36817 + AuDbg("err %d, ssz %zd\n", err, ssz);
36818 + if (unlikely(err < 0))
36826 + while (!err && p < e) {
36827 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36828 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36829 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36830 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36832 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36834 + p += strlen(p) + 1;
36837 + ignore_flags |= au_xattr_out_of_list;
36838 + if (!err && !acl_access) {
36839 + err = au_do_cpup_xattr(h_dst, h_src,
36840 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36841 + ignore_flags, verbose);
36844 + if (!err && !acl_default) {
36845 + err = au_do_cpup_xattr(h_dst, h_src,
36846 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36847 + ignore_flags, verbose);
36851 + au_kfree_try_rcu(value);
36854 + au_kfree_try_rcu(o);
36857 + inode_unlock_shared(h_isrc);
36862 +/* ---------------------------------------------------------------------- */
36864 +static int au_smack_reentering(struct super_block *sb)
36866 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36868 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36869 + * i_op->getxattr(). ouch.
36871 + return si_pid_test(sb);
36882 +struct au_lgxattr {
36890 + const char *name;
36897 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36898 + struct au_lgxattr *arg)
36902 + struct path h_path;
36903 + struct super_block *sb;
36905 + sb = dentry->d_sb;
36906 + reenter = au_smack_reentering(sb);
36908 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36909 + if (unlikely(err))
36912 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36913 + if (unlikely(err))
36915 + if (unlikely(!h_path.dentry))
36916 + /* illegally overlapped or something */
36917 + goto out_di; /* pretending success */
36919 + /* always topmost entry only */
36920 + switch (arg->type) {
36921 + case AU_XATTR_LIST:
36922 + err = vfs_listxattr(h_path.dentry,
36923 + arg->u.list.list, arg->u.list.size);
36925 + case AU_XATTR_GET:
36926 + AuDebugOn(d_is_negative(h_path.dentry));
36927 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36928 + arg->u.get.name, arg->u.get.value,
36929 + arg->u.get.size);
36935 + di_read_unlock(dentry, AuLock_IR);
36938 + si_read_unlock(sb);
36944 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36946 + struct au_lgxattr arg = {
36947 + .type = AU_XATTR_LIST,
36954 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36957 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36958 + const char *name, void *value, size_t size)
36960 + struct au_lgxattr arg = {
36961 + .type = AU_XATTR_GET,
36969 + return au_lgxattr(dentry, inode, &arg);
36972 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36973 + const char *name, const void *value, size_t size,
36976 + struct au_sxattr arg = {
36977 + .type = AU_XATTR_SET,
36986 + return au_sxattr(dentry, inode, &arg);
36989 +/* ---------------------------------------------------------------------- */
36991 +static int au_xattr_get(const struct xattr_handler *handler,
36992 + struct dentry *dentry, struct inode *inode,
36993 + const char *name, void *buffer, size_t size)
36995 + return au_getxattr(dentry, inode, name, buffer, size);
36998 +static int au_xattr_set(const struct xattr_handler *handler,
36999 + struct user_namespace *userns,
37000 + struct dentry *dentry, struct inode *inode,
37001 + const char *name, const void *value, size_t size,
37004 + return au_setxattr(dentry, inode, name, value, size, flags);
37007 +static const struct xattr_handler au_xattr_handler = {
37010 + .get = au_xattr_get,
37011 + .set = au_xattr_set
37014 +static const struct xattr_handler *au_xattr_handlers[] = {
37015 +#ifdef CONFIG_FS_POSIX_ACL
37016 + &posix_acl_access_xattr_handler,
37017 + &posix_acl_default_xattr_handler,
37019 + &au_xattr_handler, /* must be last */
37023 +void au_xattr_init(struct super_block *sb)
37025 + sb->s_xattr = au_xattr_handlers;
37027 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37028 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37029 +++ linux/fs/aufs/xino.c 2022-10-26 22:30:38.475982192 +0200
37031 +// SPDX-License-Identifier: GPL-2.0
37033 + * Copyright (C) 2005-2021 Junjiro R. Okajima
37035 + * This program, aufs is free software; you can redistribute it and/or modify
37036 + * it under the terms of the GNU General Public License as published by
37037 + * the Free Software Foundation; either version 2 of the License, or
37038 + * (at your option) any later version.
37040 + * This program is distributed in the hope that it will be useful,
37041 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37042 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37043 + * GNU General Public License for more details.
37045 + * You should have received a copy of the GNU General Public License
37046 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37050 + * external inode number translation table and bitmap
37052 + * things to consider
37054 + * + au_xino object
37055 + * + XINO files (xino, xib, xigen)
37056 + * + dynamic debugfs entries (xiN)
37057 + * + static debugfs entries (xib, xigen)
37058 + * + static sysfs entry (xi_path)
37059 + * - several entry points to handle them.
37060 + * + mount(2) without xino option (default)
37061 + * + mount(2) with xino option
37062 + * + mount(2) with noxino option
37064 + * + remount with add/del branches
37065 + * + remount with xino/noxino options
37068 +#include <linux/seq_file.h>
37069 +#include <linux/statfs.h>
37072 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37073 + aufs_bindex_t bbot,
37074 + struct super_block *h_sb)
37076 + /* todo: try binary-search if the branches are many */
37077 + for (; btop <= bbot; btop++)
37078 + if (h_sb == au_sbr_sb(sb, btop))
37084 + * find another branch who is on the same filesystem of the specified
37085 + * branch{@btgt}. search until @bbot.
37087 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37088 + aufs_bindex_t bbot)
37090 + aufs_bindex_t bindex;
37091 + struct super_block *tgt_sb;
37093 + tgt_sb = au_sbr_sb(sb, btgt);
37094 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37096 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37101 +/* ---------------------------------------------------------------------- */
37104 + * stop unnecessary notify events at creating xino files
37107 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37109 + aufs_bindex_t bfound, bindex, bbot;
37110 + struct dentry *parent;
37111 + struct au_branch *br;
37114 + parent = dentry->d_parent; /* safe d_parent access */
37115 + bbot = au_sbbot(sb);
37116 + for (bindex = 0; bindex <= bbot; bindex++) {
37117 + br = au_sbr(sb, bindex);
37118 + if (au_br_dentry(br) == parent) {
37124 + AuDbg("bfound b%d\n", bfound);
37128 +struct au_xino_lock_dir {
37129 + struct au_hinode *hdir;
37130 + struct dentry *parent;
37131 + struct inode *dir;
37134 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37135 + unsigned int lsc)
37137 + struct dentry *parent;
37138 + struct inode *dir;
37140 + parent = dget_parent(dentry);
37141 + dir = d_inode(parent);
37142 + inode_lock_nested(dir, lsc);
37143 +#if 0 /* it should not happen */
37144 + spin_lock(&dentry->d_lock);
37145 + if (unlikely(dentry->d_parent != parent)) {
37146 + spin_unlock(&dentry->d_lock);
37147 + inode_unlock(dir);
37152 + spin_unlock(&dentry->d_lock);
37159 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37160 + struct au_xino_lock_dir *ldir)
37162 + aufs_bindex_t bindex;
37164 + ldir->hdir = NULL;
37165 + bindex = au_xi_root(sb, xipath->dentry);
37166 + if (bindex >= 0) {
37167 + /* rw branch root */
37168 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37169 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37172 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37174 + ldir->dir = d_inode(ldir->parent);
37178 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37181 + au_hn_inode_unlock(ldir->hdir);
37183 + inode_unlock(ldir->dir);
37184 + dput(ldir->parent);
37188 +/* ---------------------------------------------------------------------- */
37191 + * create and set a new xino file
37193 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37196 + struct file *file;
37197 + struct dentry *h_parent, *d;
37198 + struct inode *h_dir, *inode;
37200 + static DEFINE_MUTEX(mtx);
37203 + * at mount-time, and the xino file is the default path,
37204 + * hnotify is disabled so we have no notify events to ignore.
37205 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37208 + mutex_lock(&mtx);
37209 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37210 + /* | __FMODE_NONOTIFY */,
37212 + if (IS_ERR(file)) {
37214 + mutex_unlock(&mtx);
37216 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37220 + /* keep file count */
37222 + d = file->f_path.dentry;
37223 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37225 + mutex_unlock(&mtx);
37226 + /* mnt_want_write() is unnecessary here */
37227 + h_dir = d_inode(h_parent);
37228 + inode = file_inode(file);
37229 + /* no delegation since it is just created */
37230 + if (inode->i_nlink)
37231 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37233 + inode_unlock(h_dir);
37235 + if (unlikely(err)) {
37237 + pr_err("unlink %s(%d)\n", fpath, err);
37242 + if (unlikely(sb && sb == d->d_sb)) {
37244 + pr_err("%s must be outside\n", fpath);
37247 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37249 + pr_err("xino doesn't support %s(%s)\n",
37250 + fpath, au_sbtype(d->d_sb));
37253 + return file; /* success */
37257 + file = ERR_PTR(err);
37262 + * create a new xinofile at the same place/path as @base.
37264 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37265 + struct file *copy_src)
37267 + struct file *file;
37268 + struct dentry *dentry;
37269 + struct inode *dir, *delegated;
37270 + struct qstr *name;
37271 + struct path ppath, path;
37272 + int err, do_unlock;
37273 + struct au_xino_lock_dir ldir;
37276 + au_xino_lock_dir(sb, base, &ldir);
37277 + dentry = base->dentry;
37278 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37279 + ppath.mnt = base->mnt;
37280 + dir = d_inode(ppath.dentry);
37283 + name = &dentry->d_name;
37284 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37285 + if (IS_ERR(path.dentry)) {
37286 + file = (void *)path.dentry;
37287 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37291 + /* no need to mnt_want_write() since we call dentry_open() later */
37292 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37293 + if (unlikely(err)) {
37294 + file = ERR_PTR(err);
37295 + pr_err("%pd create err %d\n", dentry, err);
37299 + path.mnt = base->mnt;
37300 + file = vfsub_dentry_open(&path,
37301 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37302 + /* | __FMODE_NONOTIFY */);
37303 + if (IS_ERR(file)) {
37304 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37308 + delegated = NULL;
37309 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37310 + au_xino_unlock_dir(&ldir);
37312 + if (unlikely(err == -EWOULDBLOCK)) {
37313 + pr_warn("cannot retry for NFSv4 delegation"
37314 + " for an internal unlink\n");
37317 + if (unlikely(err)) {
37318 + pr_err("%pd unlink err %d\n", dentry, err);
37323 + /* no one can touch copy_src xino */
37324 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37325 + if (unlikely(err)) {
37326 + pr_err("%pd copy err %d\n", dentry, err);
37330 + goto out_dput; /* success */
37334 + file = ERR_PTR(err);
37336 + dput(path.dentry);
37339 + au_xino_unlock_dir(&ldir);
37343 +struct file *au_xino_file1(struct au_xino *xi)
37345 + struct file *file;
37346 + unsigned int u, nfile;
37349 + nfile = xi->xi_nfile;
37350 + for (u = 0; u < nfile; u++) {
37351 + file = xi->xi_file[u];
37359 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37370 + if (idx < xi->xi_nfile) {
37371 + f = xi->xi_file[idx];
37375 + p = au_kzrealloc(xi->xi_file,
37376 + sizeof(*xi->xi_file) * xi->xi_nfile,
37377 + sizeof(*xi->xi_file) * (idx + 1),
37378 + GFP_NOFS, /*may_shrink*/0);
37380 + MtxMustLock(&xi->xi_mtx);
37382 + xi->xi_nfile = idx + 1;
37390 + xi->xi_file[idx] = file;
37397 + * if @xinew->xi is not set, then create new xigen file.
37399 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37401 + struct file *file;
37404 + SiMustAnyLock(sb);
37406 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37407 + if (IS_ERR(file)) {
37408 + err = PTR_ERR(file);
37409 + pr_err("%s[%d], err %d\n",
37410 + xinew->xi ? "xino" : "xigen",
37411 + xinew->idx, err);
37416 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37419 + /* todo: make xigen file an array */
37420 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37423 + if (unlikely(err))
37424 + file = ERR_PTR(err);
37430 +/* ---------------------------------------------------------------------- */
37433 + * truncate xino files
37435 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37436 + int idx, struct kstatfs *st)
37440 + struct file *file, *new_xino;
37441 + struct au_xi_new xinew = {
37446 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37447 + file = au_xino_file(xinew.xi, idx);
37451 + xinew.base = &file->f_path;
37452 + err = vfs_statfs(xinew.base, st);
37453 + if (unlikely(err)) {
37454 + AuErr1("statfs err %d, ignored\n", err);
37459 + blocks = file_inode(file)->i_blocks;
37460 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37461 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37463 + xinew.copy_src = file;
37464 + new_xino = au_xi_new(sb, &xinew);
37465 + if (IS_ERR(new_xino)) {
37466 + err = PTR_ERR(new_xino);
37467 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37471 + err = vfs_statfs(&new_xino->f_path, st);
37473 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37474 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37475 + st->f_bfree, st->f_blocks);
37477 + AuErr1("statfs err %d, ignored\n", err);
37485 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37488 + unsigned long jiffy;
37489 + aufs_bindex_t bbot;
37490 + struct kstatfs *st;
37491 + struct au_branch *br;
37492 + struct au_xino *xi;
37495 + st = kmalloc(sizeof(*st), GFP_NOFS);
37496 + if (unlikely(!st))
37500 + bbot = au_sbbot(sb);
37501 + if (unlikely(bindex < 0 || bbot < bindex))
37506 + br = au_sbr(sb, bindex);
37507 + xi = br->br_xino;
37508 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37509 + err = au_xino_do_trunc(sb, bindex, i, st);
37511 + au_sbi(sb)->si_xino_jiffy = jiffy;
37514 + au_kfree_rcu(st);
37519 +struct xino_do_trunc_args {
37520 + struct super_block *sb;
37521 + struct au_branch *br;
37525 +static void xino_do_trunc(void *_args)
37527 + struct xino_do_trunc_args *args = _args;
37528 + struct super_block *sb;
37529 + struct au_branch *br;
37530 + struct inode *dir;
37532 + aufs_bindex_t bindex;
37536 + dir = d_inode(sb->s_root);
37540 + si_noflush_write_lock(sb);
37541 + ii_read_lock_parent(dir);
37542 + bindex = au_br_index(sb, br->br_id);
37543 + err = au_xino_trunc(sb, bindex, idx);
37544 + ii_read_unlock(dir);
37545 + if (unlikely(err))
37546 + pr_warn("err b%d, (%d)\n", bindex, err);
37547 + atomic_dec(&br->br_xino->xi_truncating);
37548 + au_lcnt_dec(&br->br_count);
37549 + si_write_unlock(sb);
37550 + au_nwt_done(&au_sbi(sb)->si_nowait);
37551 + au_kfree_rcu(args);
37555 + * returns the index in the xi_file array whose corresponding file is necessary
37556 + * to truncate, or -1 which means no need to truncate.
37558 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37562 + struct kstatfs st;
37563 + struct au_sbinfo *sbinfo;
37564 + struct au_xino *xi;
37565 + struct file *file;
37567 + /* todo: si_xino_expire and the ratio should be customizable */
37568 + sbinfo = au_sbi(sb);
37569 + if (time_before(jiffies,
37570 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37573 + /* truncation border */
37574 + xi = br->br_xino;
37575 + for (u = 0; u < xi->xi_nfile; u++) {
37576 + file = au_xino_file(xi, u);
37580 + err = vfs_statfs(&file->f_path, &st);
37581 + if (unlikely(err)) {
37582 + AuErr1("statfs err %d, ignored\n", err);
37585 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37586 + >= AUFS_XINO_DEF_TRUNC)
37593 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37596 + struct xino_do_trunc_args *args;
37599 + idx = xino_trunc_test(sb, br);
37603 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37606 + /* lock and kfree() will be called in trunc_xino() */
37607 + args = kmalloc(sizeof(*args), GFP_NOFS);
37608 + if (unlikely(!args)) {
37609 + AuErr1("no memory\n");
37613 + au_lcnt_inc(&br->br_count);
37617 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37619 + return; /* success */
37621 + pr_err("wkq %d\n", wkq_err);
37622 + au_lcnt_dec(&br->br_count);
37623 + au_kfree_rcu(args);
37626 + atomic_dec(&br->br_xino->xi_truncating);
37629 +/* ---------------------------------------------------------------------- */
37631 +struct au_xi_calc {
37636 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37637 + struct au_xi_calc *calc)
37641 + maxent = au_xi_maxent(sb);
37642 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37643 + calc->pos *= sizeof(ino_t);
37646 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37647 + struct au_xi_calc *calc)
37650 + struct file *file;
37651 + struct au_xino *xi = br->br_xino;
37652 + struct au_xi_new xinew = {
37656 + SiMustAnyLock(sb);
37662 + mutex_lock(&xi->xi_mtx);
37663 + file = au_xino_file(xi, calc->idx);
37667 + file = au_xino_file(xi, /*idx*/-1);
37668 + AuDebugOn(!file);
37669 + xinew.idx = calc->idx;
37670 + xinew.base = &file->f_path;
37671 + /* xinew.copy_src = NULL; */
37672 + file = au_xi_new(sb, &xinew);
37673 + if (IS_ERR(file))
37674 + err = PTR_ERR(file);
37677 + mutex_unlock(&xi->xi_mtx);
37682 +struct au_xino_do_new_async_args {
37683 + struct super_block *sb;
37684 + struct au_branch *br;
37685 + struct au_xi_calc calc;
37689 +struct au_xi_writing {
37690 + struct hlist_bl_node node;
37691 + ino_t h_ino, ino;
37694 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37697 +static void au_xino_call_do_new_async(void *args)
37699 + struct au_xino_do_new_async_args *a = args;
37700 + struct au_branch *br;
37701 + struct super_block *sb;
37702 + struct au_sbinfo *sbi;
37703 + struct inode *root;
37704 + struct file *file;
37705 + struct au_xi_writing *del, *p;
37706 + struct hlist_bl_head *hbl;
37707 + struct hlist_bl_node *pos;
37712 + sbi = au_sbi(sb);
37713 + si_noflush_read_lock(sb);
37714 + root = d_inode(sb->s_root);
37715 + ii_read_lock_child(root);
37716 + err = au_xino_do_new_async(sb, br, &a->calc);
37717 + if (unlikely(err)) {
37718 + AuIOErr("err %d\n", err);
37722 + file = au_xino_file(br->br_xino, a->calc.idx);
37723 + AuDebugOn(!file);
37724 + err = au_xino_do_write(file, &a->calc, a->ino);
37725 + if (unlikely(err)) {
37726 + AuIOErr("err %d\n", err);
37731 + hbl = &br->br_xino->xi_writing;
37732 + hlist_bl_lock(hbl);
37733 + au_hbl_for_each(pos, hbl) {
37734 + p = container_of(pos, struct au_xi_writing, node);
37735 + if (p->ino == a->ino) {
37737 + hlist_bl_del(&p->node);
37741 + hlist_bl_unlock(hbl);
37742 + au_kfree_rcu(del);
37745 + au_lcnt_dec(&br->br_count);
37746 + ii_read_unlock(root);
37747 + si_read_unlock(sb);
37748 + au_nwt_done(&sbi->si_nowait);
37753 + * create a new xino file asynchronously
37755 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37756 + struct au_xi_calc *calc, ino_t ino)
37759 + struct au_xino_do_new_async_args *arg;
37762 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37763 + if (unlikely(!arg))
37768 + arg->calc = *calc;
37770 + au_lcnt_inc(&br->br_count);
37771 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37772 + if (unlikely(err)) {
37773 + pr_err("wkq %d\n", err);
37774 + au_lcnt_dec(&br->br_count);
37775 + au_kfree_rcu(arg);
37783 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37784 + * at the position of @h_ino.
37786 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37791 + struct au_xi_calc calc;
37792 + struct au_sbinfo *sbinfo;
37793 + struct file *file;
37794 + struct au_xino *xi;
37795 + struct hlist_bl_head *hbl;
37796 + struct hlist_bl_node *pos;
37797 + struct au_xi_writing *p;
37800 + if (!au_opt_test(au_mntflags(sb), XINO))
37801 + return 0; /* no xino */
37804 + au_xi_calc(sb, h_ino, &calc);
37805 + xi = au_sbr(sb, bindex)->br_xino;
37806 + file = au_xino_file(xi, calc.idx);
37808 + hbl = &xi->xi_writing;
37809 + hlist_bl_lock(hbl);
37810 + au_hbl_for_each(pos, hbl) {
37811 + p = container_of(pos, struct au_xi_writing, node);
37812 + if (p->h_ino == h_ino) {
37813 + AuDbg("hi%llu, i%llu, found\n",
37814 + (u64)p->h_ino, (u64)p->ino);
37819 + hlist_bl_unlock(hbl);
37821 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37822 + return 0; /* no xino */
37824 + sbinfo = au_sbi(sb);
37825 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37826 + if (sz == sizeof(*ino))
37827 + return 0; /* success */
37830 + if (unlikely(sz >= 0)) {
37832 + AuIOErr("xino read error (%zd)\n", sz);
37837 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37842 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37843 + if (sz == sizeof(ino))
37844 + return 0; /* success */
37846 + AuIOErr("write failed (%zd)\n", sz);
37851 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37852 + * at the position of @h_ino.
37853 + * even if @ino is zero, it is written to the xinofile and means no entry.
37854 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37855 + * try truncating it.
37857 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37861 + unsigned int mnt_flags;
37862 + struct au_xi_calc calc;
37863 + struct file *file;
37864 + struct au_branch *br;
37865 + struct au_xino *xi;
37866 + struct au_xi_writing *p;
37868 + SiMustAnyLock(sb);
37870 + mnt_flags = au_mntflags(sb);
37871 + if (!au_opt_test(mnt_flags, XINO))
37874 + au_xi_calc(sb, h_ino, &calc);
37875 + br = au_sbr(sb, bindex);
37876 + xi = br->br_xino;
37877 + file = au_xino_file(xi, calc.idx);
37879 + /* store the inum pair into the list */
37880 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37881 + p->h_ino = h_ino;
37883 + au_hbl_add(&p->node, &xi->xi_writing);
37885 + /* create and write a new xino file asynchronously */
37886 + err = au_xino_new_async(sb, br, &calc, ino);
37888 + return 0; /* success */
37892 + err = au_xino_do_write(file, &calc, ino);
37894 + br = au_sbr(sb, bindex);
37895 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37896 + && au_test_fs_trunc_xino(au_br_sb(br)))
37897 + xino_try_trunc(sb, br);
37898 + return 0; /* success */
37902 + AuIOErr("write failed (%d)\n", err);
37906 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37909 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37910 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37914 + const int prevent_endless = 10;
37918 + err = vfsub_read_k(file, kbuf, size, pos);
37919 + if (err == -EINTR
37920 + && !au_wkq_test()
37921 + && fatal_signal_pending(current)) {
37922 + err = xino_fread_wkq(file, kbuf, size, pos);
37923 + BUG_ON(err == -EINTR);
37925 + } while (i++ < prevent_endless
37926 + && (err == -EAGAIN || err == -EINTR));
37928 +#if 0 /* reserved for future use */
37930 + fsnotify_access(file->f_path.dentry);
37936 +struct xino_fread_args {
37938 + struct file *file;
37944 +static void call_xino_fread(void *args)
37946 + struct xino_fread_args *a = args;
37947 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37950 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37955 + struct xino_fread_args args = {
37963 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37964 + if (unlikely(wkq_err))
37970 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37973 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37978 + const int prevent_endless = 10;
37982 + err = vfsub_write_k(file, kbuf, size, pos);
37983 + if (err == -EINTR
37984 + && !au_wkq_test()
37985 + && fatal_signal_pending(current)) {
37986 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37987 + BUG_ON(err == -EINTR);
37989 + } while (i++ < prevent_endless
37990 + && (err == -EAGAIN || err == -EINTR));
37992 +#if 0 /* reserved for future use */
37994 + fsnotify_modify(file->f_path.dentry);
38000 +struct do_xino_fwrite_args {
38002 + struct file *file;
38008 +static void call_do_xino_fwrite(void *args)
38010 + struct do_xino_fwrite_args *a = args;
38011 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38014 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38019 + struct do_xino_fwrite_args args = {
38028 + * it breaks RLIMIT_FSIZE and normal user's limit,
38029 + * users should care about quota and real 'filesystem full.'
38031 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38032 + if (unlikely(wkq_err))
38038 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38042 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38044 + err = do_xino_fwrite(file, buf, size, pos);
38048 + err = xino_fwrite_wkq(file, buf, size, pos);
38055 +/* ---------------------------------------------------------------------- */
38058 + * inode number bitmap
38060 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38061 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38065 + AuDebugOn(bit < 0 || page_bits <= bit);
38066 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38070 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38072 + AuDebugOn(ino < AUFS_FIRST_INO);
38073 + ino -= AUFS_FIRST_INO;
38074 + *pindex = ino / page_bits;
38075 + *bit = ino % page_bits;
38078 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38083 + struct au_sbinfo *sbinfo;
38084 + struct file *xib;
38085 + unsigned long *p;
38087 + sbinfo = au_sbi(sb);
38088 + MtxMustLock(&sbinfo->si_xib_mtx);
38089 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38090 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38092 + if (pindex == sbinfo->si_xib_last_pindex)
38095 + xib = sbinfo->si_xib;
38096 + p = sbinfo->si_xib_buf;
38097 + pos = sbinfo->si_xib_last_pindex;
38098 + pos *= PAGE_SIZE;
38099 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38100 + if (unlikely(sz != PAGE_SIZE))
38104 + pos *= PAGE_SIZE;
38105 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38106 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38108 + memset(p, 0, PAGE_SIZE);
38109 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38111 + if (sz == PAGE_SIZE) {
38112 + sbinfo->si_xib_last_pindex = pindex;
38113 + return 0; /* success */
38117 + AuIOErr1("write failed (%zd)\n", sz);
38124 +static void au_xib_clear_bit(struct inode *inode)
38127 + unsigned long pindex;
38128 + struct super_block *sb;
38129 + struct au_sbinfo *sbinfo;
38131 + AuDebugOn(inode->i_nlink);
38133 + sb = inode->i_sb;
38134 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38135 + AuDebugOn(page_bits <= bit);
38136 + sbinfo = au_sbi(sb);
38137 + mutex_lock(&sbinfo->si_xib_mtx);
38138 + err = xib_pindex(sb, pindex);
38140 + clear_bit(bit, sbinfo->si_xib_buf);
38141 + sbinfo->si_xib_next_bit = bit;
38143 + mutex_unlock(&sbinfo->si_xib_mtx);
38146 +/* ---------------------------------------------------------------------- */
38149 + * truncate a xino bitmap file
38153 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38157 + unsigned long pindex;
38158 + loff_t pos, pend;
38159 + struct au_sbinfo *sbinfo;
38161 + unsigned long *p;
38164 + sbinfo = au_sbi(sb);
38165 + MtxMustLock(&sbinfo->si_xib_mtx);
38166 + p = sbinfo->si_xib_buf;
38167 + pend = vfsub_f_size_read(file);
38169 + while (pos < pend) {
38170 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38172 + if (unlikely(sz <= 0))
38176 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38177 + if (unlikely(*ino < AUFS_FIRST_INO))
38180 + xib_calc_bit(*ino, &pindex, &bit);
38181 + AuDebugOn(page_bits <= bit);
38182 + err = xib_pindex(sb, pindex);
38194 +static int xib_restore(struct super_block *sb)
38197 + unsigned int nfile;
38198 + aufs_bindex_t bindex, bbot;
38200 + struct au_branch *br;
38201 + struct au_xino *xi;
38202 + struct file *file;
38205 + page = (void *)__get_free_page(GFP_NOFS);
38206 + if (unlikely(!page))
38210 + bbot = au_sbbot(sb);
38211 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38212 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38213 + br = au_sbr(sb, bindex);
38214 + xi = br->br_xino;
38215 + nfile = xi->xi_nfile;
38216 + for (i = 0; i < nfile; i++) {
38217 + file = au_xino_file(xi, i);
38219 + err = do_xib_restore(sb, file, page);
38222 + AuDbg("skip shared b%d\n", bindex);
38223 + free_page((unsigned long)page);
38229 +int au_xib_trunc(struct super_block *sb)
38234 + struct au_sbinfo *sbinfo;
38235 + unsigned long *p;
38236 + struct file *file;
38238 + SiMustWriteLock(sb);
38241 + sbinfo = au_sbi(sb);
38242 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38245 + file = sbinfo->si_xib;
38246 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38249 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38250 + err = PTR_ERR(file);
38251 + if (IS_ERR(file))
38253 + fput(sbinfo->si_xib);
38254 + sbinfo->si_xib = file;
38256 + p = sbinfo->si_xib_buf;
38257 + memset(p, 0, PAGE_SIZE);
38259 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38260 + if (unlikely(sz != PAGE_SIZE)) {
38262 + AuIOErr("err %d\n", err);
38268 + mutex_lock(&sbinfo->si_xib_mtx);
38269 + /* mnt_want_write() is unnecessary here */
38270 + err = xib_restore(sb);
38271 + mutex_unlock(&sbinfo->si_xib_mtx);
38277 +/* ---------------------------------------------------------------------- */
38279 +struct au_xino *au_xino_alloc(unsigned int nfile)
38281 + struct au_xino *xi;
38283 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38284 + if (unlikely(!xi))
38286 + xi->xi_nfile = nfile;
38287 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38288 + if (unlikely(!xi->xi_file))
38291 + xi->xi_nondir.total = 8; /* initial size */
38292 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38294 + if (unlikely(!xi->xi_nondir.array))
38297 + spin_lock_init(&xi->xi_nondir.spin);
38298 + init_waitqueue_head(&xi->xi_nondir.wqh);
38299 + mutex_init(&xi->xi_mtx);
38300 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38301 + atomic_set(&xi->xi_truncating, 0);
38302 + kref_init(&xi->xi_kref);
38303 + goto out; /* success */
38306 + au_kfree_try_rcu(xi->xi_file);
38308 + au_kfree_rcu(xi);
38314 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38317 + struct au_xino *xi;
38320 + xi = au_xino_alloc(idx + 1);
38321 + if (unlikely(!xi)) {
38328 + xi->xi_file[idx] = file;
38329 + AuDebugOn(br->br_xino);
38330 + br->br_xino = xi;
38336 +static void au_xino_release(struct kref *kref)
38338 + struct au_xino *xi;
38340 + unsigned long ul;
38341 + struct hlist_bl_head *hbl;
38342 + struct hlist_bl_node *pos, *n;
38343 + struct au_xi_writing *p;
38345 + xi = container_of(kref, struct au_xino, xi_kref);
38346 + for (i = 0; i < xi->xi_nfile; i++)
38347 + if (xi->xi_file[i])
38348 + fput(xi->xi_file[i]);
38349 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38350 + AuDebugOn(xi->xi_nondir.array[i]);
38351 + mutex_destroy(&xi->xi_mtx);
38352 + hbl = &xi->xi_writing;
38353 + ul = au_hbl_count(hbl);
38354 + if (unlikely(ul)) {
38355 + pr_warn("xi_writing %lu\n", ul);
38356 + hlist_bl_lock(hbl);
38357 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38358 + hlist_bl_del(&p->node);
38359 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38362 + hlist_bl_unlock(hbl);
38364 + au_kfree_try_rcu(xi->xi_file);
38365 + au_kfree_try_rcu(xi->xi_nondir.array);
38366 + au_kfree_rcu(xi);
38369 +int au_xino_put(struct au_branch *br)
38372 + struct au_xino *xi;
38375 + xi = br->br_xino;
38377 + br->br_xino = NULL;
38378 + ret = kref_put(&xi->xi_kref, au_xino_release);
38384 +/* ---------------------------------------------------------------------- */
38387 + * xino mount option handlers
38391 +static void xino_clear_xib(struct super_block *sb)
38393 + struct au_sbinfo *sbinfo;
38395 + SiMustWriteLock(sb);
38397 + sbinfo = au_sbi(sb);
38398 + if (sbinfo->si_xib)
38399 + fput(sbinfo->si_xib);
38400 + sbinfo->si_xib = NULL;
38401 + if (sbinfo->si_xib_buf)
38402 + free_page((unsigned long)sbinfo->si_xib_buf);
38403 + sbinfo->si_xib_buf = NULL;
38406 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38410 + struct au_sbinfo *sbinfo;
38411 + struct file *file;
38412 + struct super_block *xi_sb;
38414 + SiMustWriteLock(sb);
38416 + sbinfo = au_sbi(sb);
38417 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38418 + err = PTR_ERR(file);
38419 + if (IS_ERR(file))
38421 + if (sbinfo->si_xib)
38422 + fput(sbinfo->si_xib);
38423 + sbinfo->si_xib = file;
38424 + xi_sb = file_inode(file)->i_sb;
38425 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38426 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38428 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38429 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38432 + sbinfo->si_ximaxent /= sizeof(ino_t);
38435 + if (!sbinfo->si_xib_buf)
38436 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38437 + if (unlikely(!sbinfo->si_xib_buf))
38440 + sbinfo->si_xib_last_pindex = 0;
38441 + sbinfo->si_xib_next_bit = 0;
38442 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38444 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38445 + if (unlikely(err != PAGE_SIZE))
38449 + goto out; /* success */
38452 + if (sbinfo->si_xib_buf)
38453 + free_page((unsigned long)sbinfo->si_xib_buf);
38454 + sbinfo->si_xib_buf = NULL;
38458 + fput(sbinfo->si_xib);
38459 + sbinfo->si_xib = NULL;
38465 +/* xino for each branch */
38466 +static void xino_clear_br(struct super_block *sb)
38468 + aufs_bindex_t bindex, bbot;
38469 + struct au_branch *br;
38471 + bbot = au_sbbot(sb);
38472 + for (bindex = 0; bindex <= bbot; bindex++) {
38473 + br = au_sbr(sb, bindex);
38479 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38480 + aufs_bindex_t bshared)
38482 + struct au_branch *brshared;
38484 + brshared = au_sbr(sb, bshared);
38485 + AuDebugOn(!brshared->br_xino);
38486 + AuDebugOn(!brshared->br_xino->xi_file);
38487 + if (br->br_xino != brshared->br_xino) {
38488 + au_xino_get(brshared);
38490 + br->br_xino = brshared->br_xino;
38494 +struct au_xino_do_set_br {
38495 + struct au_branch *br;
38497 + aufs_bindex_t bshared;
38500 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38501 + struct au_xino_do_set_br *args)
38504 + struct au_xi_calc calc;
38505 + struct file *file;
38506 + struct au_branch *br;
38507 + struct au_xi_new xinew = {
38512 + xinew.xi = br->br_xino;
38513 + au_xi_calc(sb, args->h_ino, &calc);
38514 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38515 + if (args->bshared >= 0)
38516 + /* shared xino */
38517 + au_xino_set_br_shared(sb, br, args->bshared);
38518 + else if (!xinew.xi) {
38520 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38521 + if (unlikely(err))
38525 + /* force re-creating */
38526 + xinew.xi = br->br_xino;
38527 + xinew.idx = calc.idx;
38528 + mutex_lock(&xinew.xi->xi_mtx);
38529 + file = au_xi_new(sb, &xinew);
38530 + mutex_unlock(&xinew.xi->xi_mtx);
38531 + err = PTR_ERR(file);
38532 + if (IS_ERR(file))
38534 + AuDebugOn(!file);
38536 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38537 + if (unlikely(err))
38545 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38548 + aufs_bindex_t bindex, bbot;
38549 + struct au_xino_do_set_br args;
38550 + struct inode *inode;
38552 + SiMustWriteLock(sb);
38554 + bbot = au_sbbot(sb);
38555 + inode = d_inode(sb->s_root);
38556 + for (bindex = 0; bindex <= bbot; bindex++) {
38557 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38558 + args.br = au_sbr(sb, bindex);
38559 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38560 + err = au_xino_do_set_br(sb, path, &args);
38561 + if (unlikely(err))
38569 +void au_xino_clr(struct super_block *sb)
38571 + struct au_sbinfo *sbinfo;
38573 + au_xigen_clr(sb);
38574 + xino_clear_xib(sb);
38575 + xino_clear_br(sb);
38576 + dbgaufs_brs_del(sb, 0);
38577 + sbinfo = au_sbi(sb);
38578 + /* lvalue, do not call au_mntflags() */
38579 + au_opt_clr(sbinfo->si_mntflags, XINO);
38582 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38585 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38586 + struct qstr *dname, *cur_name;
38587 + struct file *cur_xino;
38588 + struct au_sbinfo *sbinfo;
38589 + struct path *path, *cur_path;
38591 + SiMustWriteLock(sb);
38594 + sbinfo = au_sbi(sb);
38595 + path = &xiopt->file->f_path;
38596 + dentry = path->dentry;
38597 + parent = dget_parent(dentry);
38600 + cur_xino = sbinfo->si_xib;
38602 + cur_path = &cur_xino->f_path;
38603 + cur_dentry = cur_path->dentry;
38604 + cur_parent = dget_parent(cur_dentry);
38605 + cur_name = &cur_dentry->d_name;
38606 + dname = &dentry->d_name;
38607 + skip = (cur_parent == parent
38608 + && au_qstreq(dname, cur_name));
38609 + dput(cur_parent);
38615 + au_opt_set(sbinfo->si_mntflags, XINO);
38616 + err = au_xino_set_xib(sb, path);
38617 + /* si_x{read,write} are set */
38619 + err = au_xigen_set(sb, path);
38621 + err = au_xino_set_br(sb, path);
38623 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38624 + goto out; /* success */
38628 + AuIOErr("failed setting xino(%d).\n", err);
38637 + * create a xinofile at the default place/path.
38639 +struct file *au_xino_def(struct super_block *sb)
38641 + struct file *file;
38643 + struct au_branch *br;
38644 + struct super_block *h_sb;
38645 + struct path path;
38646 + aufs_bindex_t bbot, bindex, bwr;
38649 + bbot = au_sbbot(sb);
38651 + for (bindex = 0; bindex <= bbot; bindex++) {
38652 + br = au_sbr(sb, bindex);
38653 + if (au_br_writable(br->br_perm)
38654 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38661 + file = ERR_PTR(-ENOMEM);
38662 + page = (void *)__get_free_page(GFP_NOFS);
38663 + if (unlikely(!page))
38665 + path.mnt = au_br_mnt(br);
38666 + path.dentry = au_h_dptr(sb->s_root, bwr);
38667 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38668 + file = (void *)p;
38669 + if (!IS_ERR(p)) {
38670 + strcat(p, "/" AUFS_XINO_FNAME);
38671 + AuDbg("%s\n", p);
38672 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38674 + free_page((unsigned long)page);
38676 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38678 + if (IS_ERR(file))
38680 + h_sb = file->f_path.dentry->d_sb;
38681 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38682 + pr_err("xino doesn't support %s(%s)\n",
38683 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38685 + file = ERR_PTR(-EINVAL);
38693 +/* ---------------------------------------------------------------------- */
38696 + * initialize the xinofile for the specified branch @br
38697 + * at the place/path where @base_file indicates.
38698 + * test whether another branch is on the same filesystem or not,
38699 + * if found then share the xinofile with another branch.
38701 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38702 + struct path *base)
38705 + struct au_xino_do_set_br args = {
38710 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38712 + err = au_xino_do_set_br(sb, base, &args);
38713 + if (unlikely(err))
38719 +/* ---------------------------------------------------------------------- */
38722 + * get an unused inode number from bitmap
38724 +ino_t au_xino_new_ino(struct super_block *sb)
38727 + unsigned long *p, pindex, ul, pend;
38728 + struct au_sbinfo *sbinfo;
38729 + struct file *file;
38730 + int free_bit, err;
38732 + if (!au_opt_test(au_mntflags(sb), XINO))
38733 + return iunique(sb, AUFS_FIRST_INO);
38735 + sbinfo = au_sbi(sb);
38736 + mutex_lock(&sbinfo->si_xib_mtx);
38737 + p = sbinfo->si_xib_buf;
38738 + free_bit = sbinfo->si_xib_next_bit;
38739 + if (free_bit < page_bits && !test_bit(free_bit, p))
38740 + goto out; /* success */
38741 + free_bit = find_first_zero_bit(p, page_bits);
38742 + if (free_bit < page_bits)
38743 + goto out; /* success */
38745 + pindex = sbinfo->si_xib_last_pindex;
38746 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38747 + err = xib_pindex(sb, ul);
38748 + if (unlikely(err))
38750 + free_bit = find_first_zero_bit(p, page_bits);
38751 + if (free_bit < page_bits)
38752 + goto out; /* success */
38755 + file = sbinfo->si_xib;
38756 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38757 + for (ul = pindex + 1; ul <= pend; ul++) {
38758 + err = xib_pindex(sb, ul);
38759 + if (unlikely(err))
38761 + free_bit = find_first_zero_bit(p, page_bits);
38762 + if (free_bit < page_bits)
38763 + goto out; /* success */
38768 + set_bit(free_bit, p);
38769 + sbinfo->si_xib_next_bit = free_bit + 1;
38770 + pindex = sbinfo->si_xib_last_pindex;
38771 + mutex_unlock(&sbinfo->si_xib_mtx);
38772 + ino = xib_calc_ino(pindex, free_bit);
38773 + AuDbg("i%lu\n", (unsigned long)ino);
38776 + mutex_unlock(&sbinfo->si_xib_mtx);
38781 +/* for s_op->delete_inode() */
38782 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38785 + unsigned int mnt_flags;
38786 + aufs_bindex_t bindex, bbot, bi;
38787 + unsigned char try_trunc;
38788 + struct au_iinfo *iinfo;
38789 + struct super_block *sb;
38790 + struct au_hinode *hi;
38791 + struct inode *h_inode;
38792 + struct au_branch *br;
38793 + struct au_xi_calc calc;
38794 + struct file *file;
38796 + AuDebugOn(au_is_bad_inode(inode));
38798 + sb = inode->i_sb;
38799 + mnt_flags = au_mntflags(sb);
38800 + if (!au_opt_test(mnt_flags, XINO)
38801 + || inode->i_ino == AUFS_ROOT_INO)
38805 + au_xigen_inc(inode);
38806 + au_xib_clear_bit(inode);
38809 + iinfo = au_ii(inode);
38810 + bindex = iinfo->ii_btop;
38814 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38815 + hi = au_hinode(iinfo, bindex);
38816 + bbot = iinfo->ii_bbot;
38817 + for (; bindex <= bbot; bindex++, hi++) {
38818 + h_inode = hi->hi_inode;
38820 + || (!unlinked && h_inode->i_nlink))
38823 + /* inode may not be revalidated */
38824 + bi = au_br_index(sb, hi->hi_id);
38828 + br = au_sbr(sb, bi);
38829 + au_xi_calc(sb, h_inode->i_ino, &calc);
38830 + file = au_xino_file(br->br_xino, calc.idx);
38831 + if (IS_ERR_OR_NULL(file))
38834 + err = au_xino_do_write(file, &calc, /*ino*/0);
38835 + if (!err && try_trunc
38836 + && au_test_fs_trunc_xino(au_br_sb(br)))
38837 + xino_try_trunc(sb, br);
38841 +/* ---------------------------------------------------------------------- */
38843 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38845 + int found, total, i;
38848 + total = xi->xi_nondir.total;
38849 + for (i = 0; i < total; i++) {
38850 + if (xi->xi_nondir.array[i] != h_ino)
38859 +static int au_xinondir_expand(struct au_xino *xi)
38864 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38867 + sz = xi->xi_nondir.total * sizeof(ino_t);
38868 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38870 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38871 + /*may_shrink*/0);
38873 + xi->xi_nondir.array = p;
38874 + xi->xi_nondir.total <<= 1;
38875 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38883 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38884 + ino_t h_ino, int idx)
38886 + struct au_xino *xi;
38888 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38889 + xi = au_sbr(sb, bindex)->br_xino;
38890 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38892 + spin_lock(&xi->xi_nondir.spin);
38893 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38894 + xi->xi_nondir.array[idx] = 0;
38895 + spin_unlock(&xi->xi_nondir.spin);
38896 + wake_up_all(&xi->xi_nondir.wqh);
38899 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38902 + int err, found, empty;
38903 + struct au_xino *xi;
38907 + if (!au_opt_test(au_mntflags(sb), XINO))
38908 + goto out; /* no xino */
38910 + xi = au_sbr(sb, bindex)->br_xino;
38913 + spin_lock(&xi->xi_nondir.spin);
38914 + found = au_xinondir_find(xi, h_ino);
38915 + if (found == -1) {
38916 + empty = au_xinondir_find(xi, /*h_ino*/0);
38917 + if (empty == -1) {
38918 + empty = xi->xi_nondir.total;
38919 + err = au_xinondir_expand(xi);
38920 + if (unlikely(err))
38923 + xi->xi_nondir.array[empty] = h_ino;
38926 + spin_unlock(&xi->xi_nondir.spin);
38927 + wait_event(xi->xi_nondir.wqh,
38928 + xi->xi_nondir.array[found] != h_ino);
38933 + spin_unlock(&xi->xi_nondir.spin);
38938 +/* ---------------------------------------------------------------------- */
38940 +int au_xino_path(struct seq_file *seq, struct file *file)
38944 + err = au_seq_path(seq, &file->f_path);
38945 + if (unlikely(err))
38948 +#define Deleted "\\040(deleted)"
38949 + seq->count -= sizeof(Deleted) - 1;
38950 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38951 + sizeof(Deleted) - 1));
38957 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38958 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38959 +++ linux/include/uapi/linux/aufs_type.h 2022-10-26 22:30:38.475982192 +0200
38961 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38963 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38965 + * This program, aufs is free software; you can redistribute it and/or modify
38966 + * it under the terms of the GNU General Public License as published by
38967 + * the Free Software Foundation; either version 2 of the License, or
38968 + * (at your option) any later version.
38970 + * This program is distributed in the hope that it will be useful,
38971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38973 + * GNU General Public License for more details.
38975 + * You should have received a copy of the GNU General Public License
38976 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38979 +#ifndef __AUFS_TYPE_H__
38980 +#define __AUFS_TYPE_H__
38982 +#define AUFS_NAME "aufs"
38986 + * define it before including all other headers.
38987 + * sched.h may use pr_* macros before defining "current", so define the
38988 + * no-current version first, and re-define later.
38990 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38991 +#include <linux/sched.h>
38993 +#define pr_fmt(fmt) \
38994 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38995 + (int)sizeof(current->comm), current->comm, current->pid
38996 +#include <linux/limits.h>
38998 +#include <stdint.h>
38999 +#include <sys/types.h>
39000 +#include <limits.h>
39001 +#endif /* __KERNEL__ */
39003 +#define AUFS_VERSION "5.15.41-20220620"
39005 +/* todo? move this to linux-2.6.19/include/magic.h */
39006 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39008 +/* ---------------------------------------------------------------------- */
39011 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39012 +typedef int8_t aufs_bindex_t;
39013 +#define AUFS_BRANCH_MAX 127
39015 +typedef int16_t aufs_bindex_t;
39016 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39017 +#define AUFS_BRANCH_MAX 511
39018 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39019 +#define AUFS_BRANCH_MAX 1023
39020 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39021 +#define AUFS_BRANCH_MAX 32767
39025 +#ifndef AUFS_BRANCH_MAX
39026 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39028 +#endif /* __KERNEL__ */
39030 +/* ---------------------------------------------------------------------- */
39032 +#define AUFS_FSTYPE AUFS_NAME
39034 +#define AUFS_ROOT_INO 2
39035 +#define AUFS_FIRST_INO 11
39037 +#define AUFS_WH_PFX ".wh."
39038 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39039 +#define AUFS_WH_TMP_LEN 4
39040 +/* a limit for rmdir/rename a dir and copyup */
39041 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39042 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39044 + - AUFS_WH_TMP_LEN) /* hex */
39045 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39046 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39047 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39048 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39049 +#define AUFS_DIRWH_DEF 3
39050 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39051 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39052 +#define AUFS_RDBLK_DEF 512 /* bytes */
39053 +#define AUFS_RDHASH_DEF 32
39054 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39055 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39056 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39057 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39058 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39060 +/* pseudo-link maintenace under /proc */
39061 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39062 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39063 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39065 +/* dirren, renamed dir */
39066 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39067 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39068 +/* whiteouted doubly */
39069 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39070 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39072 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39073 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39075 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39076 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39077 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39079 +/* doubly whiteouted */
39080 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39081 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39082 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39084 +/* branch permissions and attributes */
39085 +#define AUFS_BRPERM_RW "rw"
39086 +#define AUFS_BRPERM_RO "ro"
39087 +#define AUFS_BRPERM_RR "rr"
39088 +#define AUFS_BRATTR_COO_REG "coo_reg"
39089 +#define AUFS_BRATTR_COO_ALL "coo_all"
39090 +#define AUFS_BRATTR_FHSM "fhsm"
39091 +#define AUFS_BRATTR_UNPIN "unpin"
39092 +#define AUFS_BRATTR_ICEX "icex"
39093 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39094 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39095 +#define AUFS_BRATTR_ICEX_TR "icextr"
39096 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39097 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39098 +#define AUFS_BRRATTR_WH "wh"
39099 +#define AUFS_BRWATTR_NLWH "nolwh"
39100 +#define AUFS_BRWATTR_MOO "moo"
39102 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39103 +#define AuBrPerm_RO (1 << 1) /* readonly */
39104 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39105 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39107 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39108 +#define AuBrAttr_COO_ALL (1 << 4)
39109 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39111 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39112 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39113 + branch. meaningless since
39114 + linux-3.18-rc1 */
39116 +/* ignore error in copying XATTR */
39117 +#define AuBrAttr_ICEX_SEC (1 << 7)
39118 +#define AuBrAttr_ICEX_SYS (1 << 8)
39119 +#define AuBrAttr_ICEX_TR (1 << 9)
39120 +#define AuBrAttr_ICEX_USR (1 << 10)
39121 +#define AuBrAttr_ICEX_OTH (1 << 11)
39122 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39123 + | AuBrAttr_ICEX_SYS \
39124 + | AuBrAttr_ICEX_TR \
39125 + | AuBrAttr_ICEX_USR \
39126 + | AuBrAttr_ICEX_OTH)
39128 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39129 +#define AuBrRAttr_Mask AuBrRAttr_WH
39131 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39132 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39133 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39135 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39137 +/* #warning test userspace */
39139 +#ifndef CONFIG_AUFS_FHSM
39140 +#undef AuBrAttr_FHSM
39141 +#define AuBrAttr_FHSM 0
39143 +#ifndef CONFIG_AUFS_XATTR
39144 +#undef AuBrAttr_ICEX
39145 +#define AuBrAttr_ICEX 0
39146 +#undef AuBrAttr_ICEX_SEC
39147 +#define AuBrAttr_ICEX_SEC 0
39148 +#undef AuBrAttr_ICEX_SYS
39149 +#define AuBrAttr_ICEX_SYS 0
39150 +#undef AuBrAttr_ICEX_TR
39151 +#define AuBrAttr_ICEX_TR 0
39152 +#undef AuBrAttr_ICEX_USR
39153 +#define AuBrAttr_ICEX_USR 0
39154 +#undef AuBrAttr_ICEX_OTH
39155 +#define AuBrAttr_ICEX_OTH 0
39159 +/* the longest combination */
39160 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39161 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39162 + "+" AUFS_BRATTR_COO_REG \
39163 + "+" AUFS_BRATTR_FHSM \
39164 + "+" AUFS_BRATTR_UNPIN \
39165 + "+" AUFS_BRATTR_ICEX_SEC \
39166 + "+" AUFS_BRATTR_ICEX_SYS \
39167 + "+" AUFS_BRATTR_ICEX_USR \
39168 + "+" AUFS_BRATTR_ICEX_OTH \
39169 + "+" AUFS_BRWATTR_NLWH)
39172 + char a[AuBrPermStrSz];
39173 +} au_br_perm_str_t;
39175 +static inline int au_br_writable(int brperm)
39177 + return brperm & AuBrPerm_RW;
39180 +static inline int au_br_whable(int brperm)
39182 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39185 +static inline int au_br_wh_linkable(int brperm)
39187 + return !(brperm & AuBrWAttr_NoLinkWH);
39190 +static inline int au_br_cmoo(int brperm)
39192 + return brperm & AuBrAttr_CMOO_Mask;
39195 +static inline int au_br_fhsm(int brperm)
39197 + return brperm & AuBrAttr_FHSM;
39200 +/* ---------------------------------------------------------------------- */
39204 + /* readdir in userspace */
39208 + AuCtl_WBR_FD, /* pathconf wrapper */
39209 + AuCtl_IBUSY, /* busy inode */
39210 + AuCtl_MVDOWN, /* move-down */
39211 + AuCtl_BR, /* info about branches */
39212 + AuCtl_FHSM_FD /* connection for fhsm */
39215 +/* borrowed from linux/include/linux/kernel.h */
39217 +#ifdef _GNU_SOURCE
39218 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39220 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39222 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39225 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39227 +#define __aligned(x) __attribute__((aligned(x)))
39232 +#define __packed __attribute__((packed))
39236 +struct au_rdu_cookie {
39241 + uint32_t generation;
39244 +struct au_rdu_ent {
39253 +static inline int au_rdu_len(int nlen)
39255 + /* include the terminating NULL */
39256 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39257 + sizeof(uint64_t));
39260 +union au_rdu_ent_ul {
39261 + struct au_rdu_ent __user *e;
39273 + uint64_t sz; /* AuCtl_RDU */
39274 + uint64_t nent; /* AuCtl_RDU_INO */
39276 + union au_rdu_ent_ul ent;
39277 + uint16_t verify[AufsCtlRduV_End];
39279 + /* input/output */
39283 + union au_rdu_ent_ul tail;
39284 + /* number of entries which were added in a single call */
39289 + struct au_rdu_cookie cookie;
39292 +/* ---------------------------------------------------------------------- */
39294 +/* dirren. the branch is identified by the filename who contains this */
39295 +struct au_drinfo {
39298 + uint8_t oldnamelen;
39299 + uint64_t _padding;
39301 + uint8_t oldname[];
39304 +struct au_drinfo_fdata {
39306 + struct au_drinfo drinfo;
39309 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39311 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39313 +/* ---------------------------------------------------------------------- */
39315 +struct aufs_wbr_fd {
39320 +/* ---------------------------------------------------------------------- */
39322 +struct aufs_ibusy {
39323 + uint64_t ino, h_ino;
39327 +/* ---------------------------------------------------------------------- */
39329 +/* error code for move-down */
39330 +/* the actual message strings are implemented in aufs-util.git */
39332 + EAU_MVDOWN_OPAQUE = 1,
39333 + EAU_MVDOWN_WHITEOUT,
39334 + EAU_MVDOWN_UPPER,
39335 + EAU_MVDOWN_BOTTOM,
39336 + EAU_MVDOWN_NOUPPER,
39337 + EAU_MVDOWN_NOLOWERBR,
39341 +/* flags for move-down */
39342 +#define AUFS_MVDOWN_DMSG 1
39343 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39344 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39345 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39346 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39347 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39348 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39349 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39350 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39351 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39352 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39353 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39354 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39356 +/* index for move-down */
39358 + AUFS_MVDOWN_UPPER,
39359 + AUFS_MVDOWN_LOWER,
39360 + AUFS_MVDOWN_NARRAY
39364 + * additional info of move-down
39365 + * number of free blocks and inodes.
39366 + * subset of struct kstatfs, but smaller and always 64bit.
39368 +struct aufs_stfs {
39369 + uint64_t f_blocks;
39370 + uint64_t f_bavail;
39371 + uint64_t f_files;
39372 + uint64_t f_ffree;
39375 +struct aufs_stbr {
39376 + int16_t brid; /* optional input */
39377 + int16_t bindex; /* output */
39378 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39381 +struct aufs_mvdown {
39382 + uint32_t flags; /* input/output */
39383 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39384 + int8_t au_errno; /* output */
39387 +/* ---------------------------------------------------------------------- */
39389 +union aufs_brinfo {
39390 + /* PATH_MAX may differ between kernel-space and user-space */
39391 + char _spacer[4096];
39399 +/* ---------------------------------------------------------------------- */
39401 +#define AuCtlType 'A'
39402 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39403 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39404 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39405 + struct aufs_wbr_fd)
39406 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39407 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39408 + struct aufs_mvdown)
39409 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39410 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39412 +#endif /* __AUFS_TYPE_H__ */
39413 SPDX-License-Identifier: GPL-2.0
39414 aufs5.15.41 loopback patch
39416 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39417 index 7a9e40b97831..5ed06240cc9c 100644
39418 --- a/drivers/block/loop.c
39419 +++ b/drivers/block/loop.c
39420 @@ -673,6 +673,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39424 +static struct file *loop_real_file(struct file *file)
39426 + struct file *f = NULL;
39428 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39429 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39433 static void loop_reread_partitions(struct loop_device *lo)
39436 @@ -730,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39438 struct file *file = fget(arg);
39439 struct file *old_file;
39440 + struct file *f, *virt_file = NULL, *old_virt_file;
39444 @@ -749,11 +759,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39445 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39448 + f = loop_real_file(file);
39450 + virt_file = file;
39455 error = loop_validate_file(file, bdev);
39459 old_file = lo->lo_backing_file;
39460 + old_virt_file = lo->lo_backing_virt_file;
39464 @@ -766,6 +784,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39465 blk_mq_freeze_queue(lo->lo_queue);
39466 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39467 lo->lo_backing_file = file;
39468 + lo->lo_backing_virt_file = virt_file;
39469 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39470 mapping_set_gfp_mask(file->f_mapping,
39471 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39472 @@ -788,6 +807,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39476 + if (old_virt_file)
39477 + fput(old_virt_file);
39479 loop_reread_partitions(lo);
39481 @@ -796,6 +817,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39482 loop_global_unlock(lo, is_loop);
39490 @@ -1201,6 +1224,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39491 const struct loop_config *config)
39493 struct file *file = fget(config->fd);
39494 + struct file *f, *virt_file = NULL;
39495 struct inode *inode;
39496 struct address_space *mapping;
39498 @@ -1216,6 +1240,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39499 /* This is safe, since we have a reference from open(). */
39500 __module_get(THIS_MODULE);
39502 + f = loop_real_file(file);
39504 + virt_file = file;
39510 * If we don't hold exclusive handle for the device, upgrade to it
39511 * here to avoid changing device under exclusive owner.
39512 @@ -1281,6 +1312,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39513 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39514 lo->lo_device = bdev;
39515 lo->lo_backing_file = file;
39516 + lo->lo_backing_virt_file = virt_file;
39517 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39518 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39520 @@ -1331,6 +1363,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39521 bd_abort_claiming(bdev, loop_configure);
39526 /* This is safe: open() is still holding a reference. */
39527 module_put(THIS_MODULE);
39529 @@ -1339,6 +1373,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39530 static int __loop_clr_fd(struct loop_device *lo, bool release)
39532 struct file *filp = NULL;
39533 + struct file *virt_filp = lo->lo_backing_virt_file;
39534 gfp_t gfp = lo->old_gfp_mask;
39535 struct block_device *bdev = lo->lo_device;
39537 @@ -1390,6 +1425,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39539 spin_lock_irq(&lo->lo_lock);
39540 lo->lo_backing_file = NULL;
39541 + lo->lo_backing_virt_file = NULL;
39542 spin_unlock_irq(&lo->lo_lock);
39544 loop_release_xfer(lo);
39545 @@ -1470,6 +1506,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39554 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39555 index 04c88dd6eabd..0ff3ba22ee17 100644
39556 --- a/drivers/block/loop.h
39557 +++ b/drivers/block/loop.h
39558 @@ -46,7 +46,7 @@ struct loop_device {
39559 int (*ioctl)(struct loop_device *, int cmd,
39560 unsigned long arg);
39562 - struct file * lo_backing_file;
39563 + struct file *lo_backing_file, *lo_backing_virt_file;
39564 struct block_device *lo_device;
39567 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39568 index 99ceca144044..e49dfe855032 100644
39569 --- a/fs/aufs/f_op.c
39570 +++ b/fs/aufs/f_op.c
39571 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39572 if (IS_ERR(h_file))
39575 - if (au_test_loopback_kthread()) {
39576 + if (0 && au_test_loopback_kthread()) {
39577 au_warn_loopback(h_file->f_path.dentry->d_sb);
39578 if (file->f_mapping != h_file->f_mapping) {
39579 file->f_mapping = h_file->f_mapping;
39580 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39581 index 74347bd75b38..5ef888a1d53f 100644
39582 --- a/fs/aufs/loop.c
39583 +++ b/fs/aufs/loop.c
39584 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39585 symbol_put(loop_backing_file);
39586 au_kfree_try_rcu(au_warn_loopback_array);
39589 +/* ---------------------------------------------------------------------- */
39591 +/* support the loopback block device insude aufs */
39593 +struct file *aufs_real_loop(struct file *file)
39597 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39598 + fi_read_lock(file);
39599 + f = au_hf_top(file);
39600 + fi_read_unlock(file);
39604 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39605 index 7293bee427f9..3345c098d0d4 100644
39606 --- a/fs/aufs/loop.h
39607 +++ b/fs/aufs/loop.h
39608 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39610 int au_loopback_init(void);
39611 void au_loopback_fin(void);
39613 +struct file *aufs_real_loop(struct file *file);
39615 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39617 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39619 AuStubInt0(au_loopback_init, void)
39620 AuStubVoid(au_loopback_fin, void)
39622 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39623 #endif /* BLK_DEV_LOOP */
39625 #endif /* __KERNEL__ */
39626 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39627 index 90043afec51c..0835f6da42d9 100644
39628 --- a/fs/aufs/super.c
39629 +++ b/fs/aufs/super.c
39630 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39631 .show_options = aufs_show_options,
39632 .statfs = aufs_statfs,
39633 .put_super = aufs_put_super,
39634 - .sync_fs = aufs_sync_fs
39635 + .sync_fs = aufs_sync_fs,
39636 +#ifdef CONFIG_AUFS_BDEV_LOOP
39637 + .real_loop = aufs_real_loop
39641 /* ---------------------------------------------------------------------- */
39642 diff --git a/include/linux/fs.h b/include/linux/fs.h
39643 index e60d8ad85400..2ac5317f9b79 100644
39644 --- a/include/linux/fs.h
39645 +++ b/include/linux/fs.h
39646 @@ -2226,6 +2226,10 @@ struct super_operations {
39647 struct shrink_control *);
39648 long (*free_cached_objects)(struct super_block *,
39649 struct shrink_control *);
39650 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39652 + struct file *(*real_loop)(struct file *);