1 SPDX-License-Identifier: GPL-2.0
2 aufs5.10.82 kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index da524c4d7b7e0..50ab89368c2b5 100644
8 @@ -288,6 +288,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 999d1a23f036c..0cd76857ca764 100644
20 @@ -136,3 +136,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.10.82 base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 4fef10dd29753..e013880d69f33 100644
32 @@ -3009,6 +3009,19 @@ F: include/linux/audit.h
33 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 Sandonis <miguel.ojeda.sandonis@gmail.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index ee537a9f1d1a4..d09b1ef4a2b56 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -752,6 +752,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 ea0485861d937..ddca6240e0db4 100644
85 @@ -1285,7 +1285,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 71b43538fa44c..7cd57fb4e8646 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 @@ -63,6 +63,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 046b084136c51..a256f0f9c6c09 100644
120 @@ -792,6 +792,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 866d5c2367b23..55b5356262085 100644
137 @@ -756,8 +756,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 @@ -767,9 +767,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)
161 diff --git a/include/linux/fs.h b/include/linux/fs.h
162 index 42d246a942283..2cc1a02e444c4 100644
163 --- a/include/linux/fs.h
164 +++ b/include/linux/fs.h
165 @@ -1332,6 +1332,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 @@ -1843,6 +1844,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 @@ -2330,6 +2332,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 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
190 index 20b6797babe2c..7888c04c3ffaf 100644
191 --- a/include/linux/lockdep.h
192 +++ b/include/linux/lockdep.h
193 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
194 return lock->key == key;
197 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
202 @@ -384,6 +386,7 @@ static inline void lockdep_unregister_key(struct lock_class_key *key)
204 #define lockdep_depth(tsk) (0)
206 +#define lockdep_is_held(lock) (1)
207 #define lockdep_is_held_type(l, r) (1)
209 #define lockdep_assert_held(l) do { (void)(l); } while (0)
210 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
211 index 8f882f5881e87..6b9808f098435 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 a55179fd60fc3..8e21c53cf8831 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 1f6a2f1226fa9..4550f7a021178 100644
247 --- a/kernel/locking/lockdep.c
248 +++ b/kernel/locking/lockdep.c
249 @@ -188,7 +188,7 @@ static
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 @@ -209,6 +209,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.10.82 mmap patch
269 diff --git a/fs/proc/base.c b/fs/proc/base.c
270 index 5d52aea8d7e7d..2fbf0ad30eaa9 100644
273 @@ -2184,7 +2184,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 13452b32e2bd5..38acccfef9d49 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 3931f60e421f7..e5bf27de3f0bc 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 @@ -1863,7 +1866,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 a6d21fc0033c6..02c2de31196e0 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 289c26f055cdd..63f3dca76b2eb 100644
341 --- a/include/linux/mm.h
342 +++ b/include/linux/mm.h
343 @@ -1730,6 +1730,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
344 unmap_mapping_range(mapping, holebegin, holelen, 0);
347 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
348 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
350 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
351 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
353 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
355 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
357 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
358 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
361 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
362 +extern void vmr_do_fput(struct vm_region *, const char[], int);
364 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
366 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
367 +#endif /* !CONFIG_MMU */
369 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
370 void *buf, int len, unsigned int gup_flags);
371 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
372 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
373 index 4eb38918da8f8..facc9741d5701 100644
374 --- a/include/linux/mm_types.h
375 +++ b/include/linux/mm_types.h
376 @@ -282,6 +282,7 @@ struct vm_region {
377 unsigned long vm_top; /* region allocated to here */
378 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
379 struct file *vm_file; /* the backing file or NULL */
380 + struct file *vm_prfile; /* the virtual backing file or NULL */
382 int vm_usage; /* region usage count (access under nommu_region_sem) */
383 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
384 @@ -361,6 +362,7 @@ struct vm_area_struct {
385 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
387 struct file * vm_file; /* File we map to (can be NULL). */
388 + struct file *vm_prfile; /* shadow of vm_file */
389 void * vm_private_data; /* was vm_pte (shared mem) */
392 diff --git a/kernel/fork.c b/kernel/fork.c
393 index e465903abed9e..d1f00eaf675af 100644
396 @@ -554,7 +554,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
397 struct inode *inode = file_inode(file);
398 struct address_space *mapping = file->f_mapping;
402 if (tmp->vm_flags & VM_DENYWRITE)
403 put_write_access(inode);
404 i_mmap_lock_write(mapping);
405 diff --git a/mm/Makefile b/mm/Makefile
406 index d73aed0fc99c1..93076a66ad6a5 100644
409 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
410 mm_init.o percpu.o slab_common.o \
411 compaction.o vmacache.o \
412 interval_tree.o list_lru.o workingset.o \
413 - debug.o gup.o $(mmu-y)
414 + prfile.o debug.o gup.o $(mmu-y)
416 # Give 'page_alloc' its own module-parameter namespace
417 page-alloc-y := page_alloc.o
418 diff --git a/mm/filemap.c b/mm/filemap.c
419 index 125b69f59caad..00bfb23c599fd 100644
422 @@ -2913,7 +2913,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
423 vm_fault_t ret = VM_FAULT_LOCKED;
425 sb_start_pagefault(inode->i_sb);
426 - file_update_time(vmf->vma->vm_file);
427 + vma_file_update_time(vmf->vma);
429 if (page->mapping != inode->i_mapping) {
431 diff --git a/mm/mmap.c b/mm/mmap.c
432 index 5c8b4485860de..59f2f758d77e5 100644
435 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
436 if (vma->vm_ops && vma->vm_ops->close)
437 vma->vm_ops->close(vma);
439 - fput(vma->vm_file);
441 mpol_put(vma_policy(vma));
444 @@ -951,7 +951,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
447 uprobe_munmap(next, next->vm_start, next->vm_end);
452 anon_vma_merge(vma, next);
453 @@ -1897,8 +1897,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
454 if (vma->vm_ops && vma->vm_ops->close)
455 vma->vm_ops->close(vma);
461 /* Undo any partial mapping done by a device driver. */
462 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
463 @@ -2757,7 +2757,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
467 - get_file(new->vm_file);
470 if (new->vm_ops && new->vm_ops->open)
471 new->vm_ops->open(new);
472 @@ -2776,7 +2776,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
473 if (new->vm_ops && new->vm_ops->close)
474 new->vm_ops->close(new);
476 - fput(new->vm_file);
478 unlink_anon_vmas(new);
480 mpol_put(vma_policy(new));
481 @@ -2969,7 +2969,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
482 struct vm_area_struct *vma;
483 unsigned long populate = 0;
484 unsigned long ret = -EINVAL;
486 + struct file *file, *prfile;
488 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
489 current->comm, current->pid);
490 @@ -3044,10 +3044,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
494 - file = get_file(vma->vm_file);
496 + file = vma->vm_file;
497 + prfile = vma->vm_prfile;
498 ret = do_mmap(vma->vm_file, start, size,
499 prot, flags, pgoff, &populate, NULL);
500 + if (!IS_ERR_VALUE(ret) && file && prfile) {
501 + struct vm_area_struct *new_vma;
503 + new_vma = find_vma(mm, ret);
504 + if (!new_vma->vm_prfile)
505 + new_vma->vm_prfile = prfile;
506 + if (new_vma != vma)
510 + * two fput()s instead of vma_fput(vma),
511 + * coz vma may not be available anymore.
517 mmap_write_unlock(mm);
519 @@ -3334,7 +3351,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
520 if (anon_vma_clone(new_vma, vma))
521 goto out_free_mempol;
522 if (new_vma->vm_file)
523 - get_file(new_vma->vm_file);
524 + vma_get_file(new_vma);
525 if (new_vma->vm_ops && new_vma->vm_ops->open)
526 new_vma->vm_ops->open(new_vma);
527 vma_link(mm, new_vma, prev, rb_link, rb_parent);
528 diff --git a/mm/nommu.c b/mm/nommu.c
529 index 0faf39b32cdb9..78ecad7204c86 100644
532 @@ -533,7 +533,7 @@ static void __put_nommu_region(struct vm_region *region)
533 up_write(&nommu_region_sem);
536 - fput(region->vm_file);
539 /* IO memory and memory shared directly out of the pagecache
540 * from ramfs/tmpfs mustn't be released here */
541 @@ -665,7 +665,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
542 if (vma->vm_ops && vma->vm_ops->close)
543 vma->vm_ops->close(vma);
545 - fput(vma->vm_file);
547 put_nommu_region(vma->vm_region);
550 @@ -1188,7 +1188,7 @@ unsigned long do_mmap(struct file *file,
551 goto error_just_free;
554 - fput(region->vm_file);
556 kmem_cache_free(vm_region_jar, region);
559 @@ -1265,10 +1265,10 @@ unsigned long do_mmap(struct file *file,
560 up_write(&nommu_region_sem);
563 - fput(region->vm_file);
565 kmem_cache_free(vm_region_jar, region);
567 - fput(vma->vm_file);
572 diff --git a/mm/prfile.c b/mm/prfile.c
574 index 0000000000000..511543ab1b418
578 +// SPDX-License-Identifier: GPL-2.0
580 + * Mainly for aufs which mmap(2) different file and wants to print different
581 + * path in /proc/PID/maps.
582 + * Call these functions via macros defined in linux/mm.h.
584 + * See Documentation/filesystems/aufs/design/06mmap.txt
586 + * Copyright (c) 2014-2021 Junjro R. Okajima
587 + * Copyright (c) 2014 Ian Campbell
590 +#include <linux/mm.h>
591 +#include <linux/file.h>
592 +#include <linux/fs.h>
594 +/* #define PRFILE_TRACE */
595 +static inline void prfile_trace(struct file *f, struct file *pr,
596 + const char func[], int line, const char func2[])
600 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
604 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
607 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
609 + prfile_trace(f, pr, func, line, __func__);
610 + file_update_time(f);
612 + file_update_time(pr);
615 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
618 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
620 + prfile_trace(f, pr, func, line, __func__);
621 + return (f && pr) ? pr : f;
624 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
626 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
628 + prfile_trace(f, pr, func, line, __func__);
634 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
636 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
638 + prfile_trace(f, pr, func, line, __func__);
645 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
648 + struct file *f = region->vm_file, *pr = region->vm_prfile;
650 + prfile_trace(f, pr, func, line, __func__);
651 + return (f && pr) ? pr : f;
654 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
656 + struct file *f = region->vm_file, *pr = region->vm_prfile;
658 + prfile_trace(f, pr, func, line, __func__);
663 +#endif /* !CONFIG_MMU */
664 SPDX-License-Identifier: GPL-2.0
665 aufs5.10.82 standalone patch
667 diff --git a/fs/dcache.c b/fs/dcache.c
668 index ddca6240e0db4..30dec552278dc 100644
671 @@ -1390,6 +1390,7 @@ void d_walk(struct dentry *parent, void *data,
675 +EXPORT_SYMBOL_GPL(d_walk);
678 struct vfsmount *mnt;
679 @@ -2935,6 +2936,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
681 write_sequnlock(&rename_lock);
683 +EXPORT_SYMBOL_GPL(d_exchange);
686 * d_ancestor - search for an ancestor
687 diff --git a/fs/exec.c b/fs/exec.c
688 index ca89e0e3ef10f..666565bb411f6 100644
691 @@ -113,6 +113,7 @@ bool path_noexec(const struct path *path)
692 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
693 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
695 +EXPORT_SYMBOL_GPL(path_noexec);
699 diff --git a/fs/fcntl.c b/fs/fcntl.c
700 index 7cd57fb4e8646..96bc0e48b7467 100644
703 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
707 +EXPORT_SYMBOL_GPL(setfl);
709 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
711 diff --git a/fs/file_table.c b/fs/file_table.c
712 index 709ada3151da5..27a3e3c9f2a82 100644
713 --- a/fs/file_table.c
714 +++ b/fs/file_table.c
715 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
717 return ERR_PTR(-ENFILE);
719 +EXPORT_SYMBOL_GPL(alloc_empty_file);
722 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
723 diff --git a/fs/namespace.c b/fs/namespace.c
724 index a256f0f9c6c09..5d6b3e723e913 100644
727 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
728 mnt_dec_writers(real_mount(mnt));
731 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
734 * mnt_drop_write - give up write access to a mount
735 @@ -797,6 +798,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
737 return check_mnt(real_mount(mnt));
739 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
742 * vfsmount lock must be held for write
743 @@ -1998,6 +2000,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
747 +EXPORT_SYMBOL_GPL(iterate_mounts);
749 static void lock_mnt_tree(struct mount *mnt)
751 diff --git a/fs/notify/group.c b/fs/notify/group.c
752 index a4a4b1c64d32a..86dc2efb1850c 100644
753 --- a/fs/notify/group.c
754 +++ b/fs/notify/group.c
755 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
757 refcount_inc(&group->refcnt);
759 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
762 * Drop a reference to a group. Free it if it's through.
763 diff --git a/fs/open.c b/fs/open.c
764 index 3aaaad47d9cac..60ae17e35e125 100644
767 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
768 inode_unlock(dentry->d_inode);
771 +EXPORT_SYMBOL_GPL(do_truncate);
773 long vfs_truncate(const struct path *path, loff_t length)
775 diff --git a/fs/read_write.c b/fs/read_write.c
776 index 75f764b434184..7582bb3fb634b 100644
777 --- a/fs/read_write.c
778 +++ b/fs/read_write.c
779 @@ -503,6 +503,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
783 +EXPORT_SYMBOL_GPL(vfs_read);
785 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
787 @@ -613,6 +614,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
788 file_end_write(file);
791 +EXPORT_SYMBOL_GPL(vfs_write);
793 /* file_ppos returns &file->f_pos or NULL if file is stream */
794 static inline loff_t *file_ppos(struct file *file)
795 diff --git a/fs/splice.c b/fs/splice.c
796 index 55b5356262085..c13ac0fbac318 100644
799 @@ -763,6 +763,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
800 return warn_unsupported(out, "write");
801 return out->f_op->splice_write(pipe, out, ppos, len, flags);
803 +EXPORT_SYMBOL_GPL(do_splice_from);
806 * Attempt to initiate a splice from a file to a pipe.
807 @@ -787,6 +788,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
808 return warn_unsupported(in, "read");
809 return in->f_op->splice_read(in, ppos, pipe, len, flags);
811 +EXPORT_SYMBOL_GPL(do_splice_to);
814 * splice_direct_to_actor - splices data directly between two non-pipes
815 diff --git a/fs/xattr.c b/fs/xattr.c
816 index cd7a563e8bcd4..7d989d57b0f0d 100644
819 @@ -360,6 +360,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
820 *xattr_value = value;
823 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
826 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
827 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
828 index 4550f7a021178..efc579b9a36d9 100644
829 --- a/kernel/locking/lockdep.c
830 +++ b/kernel/locking/lockdep.c
831 @@ -209,6 +209,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
833 return lock_classes + class_idx;
835 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
836 #define hlock_class(hlock) lockdep_hlock_class(hlock)
838 #ifdef CONFIG_LOCK_STAT
839 diff --git a/kernel/task_work.c b/kernel/task_work.c
840 index 8d6e1217c451c..0e73637adda86 100644
841 --- a/kernel/task_work.c
842 +++ b/kernel/task_work.c
843 @@ -154,3 +154,4 @@ void task_work_run(void)
847 +EXPORT_SYMBOL_GPL(task_work_run);
848 diff --git a/security/security.c b/security/security.c
849 index a864ff824dd3b..d919d763ade5a 100644
850 --- a/security/security.c
851 +++ b/security/security.c
852 @@ -1094,6 +1094,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
854 return call_int_hook(path_rmdir, 0, dir, dentry);
856 +EXPORT_SYMBOL_GPL(security_path_rmdir);
858 int security_path_unlink(const struct path *dir, struct dentry *dentry)
860 @@ -1110,6 +1111,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
862 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
864 +EXPORT_SYMBOL_GPL(security_path_symlink);
866 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
867 struct dentry *new_dentry)
868 @@ -1118,6 +1120,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
870 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
872 +EXPORT_SYMBOL_GPL(security_path_link);
874 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
875 const struct path *new_dir, struct dentry *new_dentry,
876 @@ -1145,6 +1148,7 @@ int security_path_truncate(const struct path *path)
878 return call_int_hook(path_truncate, 0, path);
880 +EXPORT_SYMBOL_GPL(security_path_truncate);
882 int security_path_chmod(const struct path *path, umode_t mode)
884 @@ -1152,6 +1156,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
886 return call_int_hook(path_chmod, 0, path, mode);
888 +EXPORT_SYMBOL_GPL(security_path_chmod);
890 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
892 @@ -1159,6 +1164,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
894 return call_int_hook(path_chown, 0, path, uid, gid);
896 +EXPORT_SYMBOL_GPL(security_path_chown);
898 int security_path_chroot(const struct path *path)
900 @@ -1259,6 +1265,7 @@ int security_inode_permission(struct inode *inode, int mask)
902 return call_int_hook(inode_permission, 0, inode, mask);
904 +EXPORT_SYMBOL_GPL(security_inode_permission);
906 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
908 @@ -1451,6 +1458,7 @@ int security_file_permission(struct file *file, int mask)
910 return fsnotify_perm(file, mask);
912 +EXPORT_SYMBOL_GPL(security_file_permission);
914 int security_file_alloc(struct file *file)
916 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
917 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
918 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-12-03 15:38:59.926647310 +0100
920 +What: /debug/aufs/si_<id>/
922 +Contact: J. R. Okajima <hooanon05g@gmail.com>
924 + Under /debug/aufs, a directory named si_<id> is created
925 + per aufs mount, where <id> is a unique id generated
928 +What: /debug/aufs/si_<id>/plink
930 +Contact: J. R. Okajima <hooanon05g@gmail.com>
932 + It has three lines and shows the information about the
933 + pseudo-link. The first line is a single number
934 + representing a number of buckets. The second line is a
935 + number of pseudo-links per buckets (separated by a
936 + blank). The last line is a single number representing a
937 + total number of psedo-links.
938 + When the aufs mount option 'noplink' is specified, it
939 + will show "1\n0\n0\n".
941 +What: /debug/aufs/si_<id>/xib
943 +Contact: J. R. Okajima <hooanon05g@gmail.com>
945 + It shows the consumed blocks by xib (External Inode Number
946 + Bitmap), its block size and file size.
947 + When the aufs mount option 'noxino' is specified, it
948 + will be empty. About XINO files, see the aufs manual.
950 +What: /debug/aufs/si_<id>/xi<branch-index>
952 +Contact: J. R. Okajima <hooanon05g@gmail.com>
954 + It shows the consumed blocks by xino (External Inode Number
955 + Translation Table), its link count, block size and file
957 + Due to the file size limit, there may exist multiple
958 + xino files per branch. In this case, "-N" is added to
959 + the filename and it corresponds to the index of the
960 + internal xino array. "-0" is omitted.
961 + When the aufs mount option 'noxino' is specified, Those
962 + entries won't exist. About XINO files, see the aufs
965 +What: /debug/aufs/si_<id>/xigen
967 +Contact: J. R. Okajima <hooanon05g@gmail.com>
969 + It shows the consumed blocks by xigen (External Inode
970 + Generation Table), its block size and file size.
971 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
973 + When the aufs mount option 'noxino' is specified, it
974 + will be empty. About XINO files, see the aufs manual.
975 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
976 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
977 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-12-03 15:38:59.926647310 +0100
979 +What: /sys/fs/aufs/si_<id>/
981 +Contact: J. R. Okajima <hooanon05g@gmail.com>
983 + Under /sys/fs/aufs, a directory named si_<id> is created
984 + per aufs mount, where <id> is a unique id generated
987 +What: /sys/fs/aufs/si_<id>/br<idx>
989 +Contact: J. R. Okajima <hooanon05g@gmail.com>
991 + It shows the abolute path of a member directory (which
992 + is called branch) in aufs, and its permission.
994 +What: /sys/fs/aufs/si_<id>/brid<idx>
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It shows the id of a member directory (which is called
1001 +What: /sys/fs/aufs/si_<id>/xi_path
1003 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1005 + It shows the abolute path of XINO (External Inode Number
1006 + Bitmap, Translation Table and Generation Table) file
1007 + even if it is the default path.
1008 + When the aufs mount option 'noxino' is specified, it
1009 + will be empty. About XINO files, see the aufs manual.
1010 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1011 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1012 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-12-03 15:38:59.929980643 +0100
1015 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1017 +# This program is free software; you can redistribute it and/or modify
1018 +# it under the terms of the GNU General Public License as published by
1019 +# the Free Software Foundation; either version 2 of the License, or
1020 +# (at your option) any later version.
1022 +# This program is distributed in the hope that it will be useful,
1023 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1024 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1025 +# GNU General Public License for more details.
1027 +# You should have received a copy of the GNU General Public License
1028 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1031 +----------------------------------------
1033 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1034 +1. abbrev. for "advanced multi-layered unification filesystem".
1035 +2. abbrev. for "another unionfs".
1036 +3. abbrev. for "auf das" in German which means "on the" in English.
1037 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1038 + But "Filesystem aufs Filesystem" is hard to understand.
1039 +4. abbrev. for "African Urban Fashion Show".
1041 +AUFS is a filesystem with features:
1042 +- multi layered stackable unification filesystem, the member directory
1043 + is called as a branch.
1044 +- branch permission and attribute, 'readonly', 'real-readonly',
1045 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1047 +- internal "file copy-on-write".
1048 +- logical deletion, whiteout.
1049 +- dynamic branch manipulation, adding, deleting and changing permission.
1050 +- allow bypassing aufs, user's direct branch access.
1051 +- external inode number translation table and bitmap which maintains the
1052 + persistent aufs inode number.
1053 +- seekable directory, including NFS readdir.
1054 +- file mapping, mmap and sharing pages.
1055 +- pseudo-link, hardlink over branches.
1056 +- loopback mounted filesystem as a branch.
1057 +- several policies to select one among multiple writable branches.
1058 +- revert a single systemcall when an error occurs in aufs.
1062 +Multi Layered Stackable Unification Filesystem
1063 +----------------------------------------------------------------------
1064 +Most people already knows what it is.
1065 +It is a filesystem which unifies several directories and provides a
1066 +merged single directory. When users access a file, the access will be
1067 +passed/re-directed/converted (sorry, I am not sure which English word is
1068 +correct) to the real file on the member filesystem. The member
1069 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1070 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1071 +readonly branch is handled by creating 'whiteout' on the upper writable
1074 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1075 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1076 +different approaches to implement the merged-view.
1077 +The former tries putting it into VFS, and the latter implements as a
1078 +separate filesystem.
1079 +(If I misunderstand about these implementations, please let me know and
1080 +I shall correct it. Because it is a long time ago when I read their
1081 +source files last time).
1083 +UnionMount's approach will be able to small, but may be hard to share
1084 +branches between several UnionMount since the whiteout in it is
1085 +implemented in the inode on branch filesystem and always
1086 +shared. According to Bharata's post, readdir does not seems to be
1088 +There are several missing features known in this implementations such as
1089 +- for users, the inode number may change silently. eg. copy-up.
1090 +- link(2) may break by copy-up.
1091 +- read(2) may get an obsoleted filedata (fstat(2) too).
1092 +- fcntl(F_SETLK) may be broken by copy-up.
1093 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1096 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1097 +merged into mainline. This is another implementation of UnionMount as a
1098 +separated filesystem. All the limitations and known problems which
1099 +UnionMount are equally inherited to "overlay" filesystem.
1101 +Unionfs has a longer history. When I started implementing a stackable
1102 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1103 +inode, dentry and file objects and they have an array pointing lower
1104 +same kind objects. After contributing many patches for Unionfs, I
1105 +re-started my project AUFS (Jun 2006).
1107 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1108 +implemented my own ideas, approaches and enhancements and it became
1109 +totally different one.
1111 +Comparing DM snapshot and fs based implementation
1112 +- the number of bytes to be copied between devices is much smaller.
1113 +- the type of filesystem must be one and only.
1114 +- the fs must be writable, no readonly fs, even for the lower original
1115 + device. so the compression fs will not be usable. but if we use
1116 + loopback mount, we may address this issue.
1118 + mount /cdrom/squashfs.img /sq
1119 + losetup /sq/ext2.img
1120 + losetup /somewhere/cow
1121 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1122 +- it will be difficult (or needs more operations) to extract the
1123 + difference between the original device and COW.
1124 +- DM snapshot-merge may help a lot when users try merging. in the
1125 + fs-layer union, users will use rsync(1).
1127 +You may want to read my old paper "Filesystems in LiveCD"
1128 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1131 +Several characters/aspects/persona of aufs
1132 +----------------------------------------------------------------------
1134 +Aufs has several characters, aspects or persona.
1135 +1. a filesystem, callee of VFS helper
1136 +2. sub-VFS, caller of VFS helper for branches
1137 +3. a virtual filesystem which maintains persistent inode number
1138 +4. reader/writer of files on branches such like an application
1140 +1. Callee of VFS Helper
1141 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1142 +unlink(2) from an application reaches sys_unlink() kernel function and
1143 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1144 +calls filesystem specific unlink operation. Actually aufs implements the
1145 +unlink operation but it behaves like a redirector.
1147 +2. Caller of VFS Helper for Branches
1148 +aufs_unlink() passes the unlink request to the branch filesystem as if
1149 +it were called from VFS. So the called unlink operation of the branch
1150 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1151 +every necessary pre/post operation for the branch filesystem.
1152 +- acquire the lock for the parent dir on a branch
1153 +- lookup in a branch
1154 +- revalidate dentry on a branch
1155 +- mnt_want_write() for a branch
1156 +- vfs_unlink() for a branch
1157 +- mnt_drop_write() for a branch
1158 +- release the lock on a branch
1160 +3. Persistent Inode Number
1161 +One of the most important issue for a filesystem is to maintain inode
1162 +numbers. This is particularly important to support exporting a
1163 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1164 +backend block device for its own. But some storage is necessary to
1165 +keep and maintain the inode numbers. It may be a large space and may not
1166 +suit to keep in memory. Aufs rents some space from its first writable
1167 +branch filesystem (by default) and creates file(s) on it. These files
1168 +are created by aufs internally and removed soon (currently) keeping
1170 +Note: Because these files are removed, they are totally gone after
1171 + unmounting aufs. It means the inode numbers are not persistent
1172 + across unmount or reboot. I have a plan to make them really
1173 + persistent which will be important for aufs on NFS server.
1175 +4. Read/Write Files Internally (copy-on-write)
1176 +Because a branch can be readonly, when you write a file on it, aufs will
1177 +"copy-up" it to the upper writable branch internally. And then write the
1178 +originally requested thing to the file. Generally kernel doesn't
1179 +open/read/write file actively. In aufs, even a single write may cause a
1180 +internal "file copy". This behaviour is very similar to cp(1) command.
1182 +Some people may think it is better to pass such work to user space
1183 +helper, instead of doing in kernel space. Actually I am still thinking
1184 +about it. But currently I have implemented it in kernel space.
1185 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1186 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1187 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-12-03 15:38:59.929980643 +0100
1190 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1192 +# This program is free software; you can redistribute it and/or modify
1193 +# it under the terms of the GNU General Public License as published by
1194 +# the Free Software Foundation; either version 2 of the License, or
1195 +# (at your option) any later version.
1197 +# This program is distributed in the hope that it will be useful,
1198 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1199 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1200 +# GNU General Public License for more details.
1202 +# You should have received a copy of the GNU General Public License
1203 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1205 +Basic Aufs Internal Structure
1207 +Superblock/Inode/Dentry/File Objects
1208 +----------------------------------------------------------------------
1209 +As like an ordinary filesystem, aufs has its own
1210 +superblock/inode/dentry/file objects. All these objects have a
1211 +dynamically allocated array and store the same kind of pointers to the
1212 +lower filesystem, branch.
1213 +For example, when you build a union with one readwrite branch and one
1214 +readonly, mounted /au, /rw and /ro respectively.
1216 +- /ro/fileA exists but /rw/fileA
1218 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1219 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1220 +- [0] = NULL (because /rw/fileA doesn't exist)
1223 +This style of an array is essentially same to the aufs
1224 +superblock/inode/dentry/file objects.
1226 +Because aufs supports manipulating branches, ie. add/delete/change
1227 +branches dynamically, these objects has its own generation. When
1228 +branches are changed, the generation in aufs superblock is
1229 +incremented. And a generation in other object are compared when it is
1230 +accessed. When a generation in other objects are obsoleted, aufs
1231 +refreshes the internal array.
1235 +----------------------------------------------------------------------
1236 +Additionally aufs superblock has some data for policies to select one
1237 +among multiple writable branches, XIB files, pseudo-links and kobject.
1238 +See below in detail.
1239 +About the policies which supports copy-down a directory, see
1240 +wbr_policy.txt too.
1243 +Branch and XINO(External Inode Number Translation Table)
1244 +----------------------------------------------------------------------
1245 +Every branch has its own xino (external inode number translation table)
1246 +file. The xino file is created and unlinked by aufs internally. When two
1247 +members of a union exist on the same filesystem, they share the single
1249 +The struct of a xino file is simple, just a sequence of aufs inode
1250 +numbers which is indexed by the lower inode number.
1251 +In the above sample, assume the inode number of /ro/fileA is i111 and
1252 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1253 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1255 +When the inode numbers are not contiguous, the xino file will be sparse
1256 +which has a hole in it and doesn't consume as much disk space as it
1257 +might appear. If your branch filesystem consumes disk space for such
1258 +holes, then you should specify 'xino=' option at mounting aufs.
1260 +Aufs has a mount option to free the disk blocks for such holes in XINO
1261 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1262 +meet a problem of disk shortage due to XINO files, then you should try
1263 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1264 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1265 +the holes in XINO files.
1267 +Also a writable branch has three kinds of "whiteout bases". All these
1268 +are existed when the branch is joined to aufs, and their names are
1269 +whiteout-ed doubly, so that users will never see their names in aufs
1271 +1. a regular file which will be hardlinked to all whiteouts.
1272 +2. a directory to store a pseudo-link.
1273 +3. a directory to store an "orphan"-ed file temporary.
1276 + When you remove a file on a readonly branch, aufs handles it as a
1277 + logical deletion and creates a whiteout on the upper writable branch
1278 + as a hardlink of this file in order not to consume inode on the
1281 + See below, Pseudo-link.
1283 + When "fileC" exists on the lower readonly branch only and it is
1284 + opened and removed with its parent dir, and then user writes
1285 + something into it, then aufs copies-up fileC to this
1286 + directory. Because there is no other dir to store fileC. After
1287 + creating a file under this dir, the file is unlinked.
1289 +Because aufs supports manipulating branches, ie. add/delete/change
1290 +dynamically, a branch has its own id. When the branch order changes,
1291 +aufs finds the new index by searching the branch id.
1295 +----------------------------------------------------------------------
1296 +Assume "fileA" exists on the lower readonly branch only and it is
1297 +hardlinked to "fileB" on the branch. When you write something to fileA,
1298 +aufs copies-up it to the upper writable branch. Additionally aufs
1299 +creates a hardlink under the Pseudo-link Directory of the writable
1300 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1301 +simple list. If fileB is read after unlinking fileA, aufs returns
1302 +filedata from the pseudo-link instead of the lower readonly
1303 +branch. Because the pseudo-link is based upon the inode, to keep the
1304 +inode number by xino (see above) is essentially necessary.
1306 +All the hardlinks under the Pseudo-link Directory of the writable branch
1307 +should be restored in a proper location later. Aufs provides a utility
1308 +to do this. The userspace helpers executed at remounting and unmounting
1310 +During this utility is running, it puts aufs into the pseudo-link
1311 +maintenance mode. In this mode, only the process which began the
1312 +maintenance mode (and its child processes) is allowed to operate in
1313 +aufs. Some other processes which are not related to the pseudo-link will
1314 +be allowed to run too, but the rest have to return an error or wait
1315 +until the maintenance mode ends. If a process already acquires an inode
1316 +mutex (in VFS), it has to return an error.
1319 +XIB(external inode number bitmap)
1320 +----------------------------------------------------------------------
1321 +Addition to the xino file per a branch, aufs has an external inode number
1322 +bitmap in a superblock object. It is also an internal file such like a
1324 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1326 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1328 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1329 +reduce the number of consumed disk blocks for these files.
1332 +Virtual or Vertical Dir, and Readdir in Userspace
1333 +----------------------------------------------------------------------
1334 +In order to support multiple layers (branches), aufs readdir operation
1335 +constructs a virtual dir block on memory. For readdir, aufs calls
1336 +vfs_readdir() internally for each dir on branches, merges their entries
1337 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1338 +object. So the file object has its entry list until it is closed. The
1339 +entry list will be updated when the file position is zero and becomes
1340 +obsoleted. This decision is made in aufs automatically.
1342 +The dynamically allocated memory block for the name of entries has a
1343 +unit of 512 bytes (by default) and stores the names contiguously (no
1344 +padding). Another block for each entry is handled by kmem_cache too.
1345 +During building dir blocks, aufs creates hash list and judging whether
1346 +the entry is whiteouted by its upper branch or already listed.
1347 +The merged result is cached in the corresponding inode object and
1348 +maintained by a customizable life-time option.
1350 +Some people may call it can be a security hole or invite DoS attack
1351 +since the opened and once readdir-ed dir (file object) holds its entry
1352 +list and becomes a pressure for system memory. But I'd say it is similar
1353 +to files under /proc or /sys. The virtual files in them also holds a
1354 +memory page (generally) while they are opened. When an idea to reduce
1355 +memory for them is introduced, it will be applied to aufs too.
1356 +For those who really hate this situation, I've developed readdir(3)
1357 +library which operates this merging in userspace. You just need to set
1358 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1359 +kernel space for readdir(3).
1363 +----------------------------------------------------------------------
1364 +Aufs sometimes requires privilege access to a branch. For instance,
1365 +in copy-up/down operation. When a user process is going to make changes
1366 +to a file which exists in the lower readonly branch only, and the mode
1367 +of one of ancestor directories may not be writable by a user
1368 +process. Here aufs copy-up the file with its ancestors and they may
1369 +require privilege to set its owner/group/mode/etc.
1370 +This is a typical case of a application character of aufs (see
1373 +Aufs uses workqueue synchronously for this case. It creates its own
1374 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1375 +passes the request to call mkdir or write (for example), and wait for
1376 +its completion. This approach solves a problem of a signal handler
1378 +If aufs didn't adopt the workqueue and changed the privilege of the
1379 +process, then the process may receive the unexpected SIGXFSZ or other
1382 +Also aufs uses the system global workqueue ("events" kernel thread) too
1383 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1384 +whiteout base and etc. This is unrelated to a privilege.
1385 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1386 +superblock at the beginning, at the same time waits for the completion
1387 +of all queued asynchronous tasks.
1391 +----------------------------------------------------------------------
1392 +The whiteout in aufs is very similar to Unionfs's. That is represented
1393 +by its filename. UnionMount takes an approach of a file mode, but I am
1394 +afraid several utilities (find(1) or something) will have to support it.
1396 +Basically the whiteout represents "logical deletion" which stops aufs to
1397 +lookup further, but also it represents "dir is opaque" which also stop
1400 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1401 +In order to make several functions in a single systemcall to be
1402 +revertible, aufs adopts an approach to rename a directory to a temporary
1403 +unique whiteouted name.
1404 +For example, in rename(2) dir where the target dir already existed, aufs
1405 +renames the target dir to a temporary unique whiteouted name before the
1406 +actual rename on a branch, and then handles other actions (make it opaque,
1407 +update the attributes, etc). If an error happens in these actions, aufs
1408 +simply renames the whiteouted name back and returns an error. If all are
1409 +succeeded, aufs registers a function to remove the whiteouted unique
1410 +temporary name completely and asynchronously to the system global
1415 +----------------------------------------------------------------------
1416 +It is a well-known feature or concept.
1417 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1418 +internally and makes change to the new file on the upper writable branch.
1419 +When the trigger systemcall does not update the timestamps of the parent
1420 +dir, aufs reverts it after copy-up.
1423 +Move-down (aufs3.9 and later)
1424 +----------------------------------------------------------------------
1425 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1426 +the lower readonly branch to the upper writable branch when a user
1427 +changes something about the file.
1428 +"Move-down" is an opposite action of copy-up. Basically this action is
1429 +ran manually instead of automatically and internally.
1430 +For desgin and implementation, aufs has to consider these issues.
1431 +- whiteout for the file may exist on the lower branch.
1432 +- ancestor directories may not exist on the lower branch.
1433 +- diropq for the ancestor directories may exist on the upper branch.
1434 +- free space on the lower branch will reduce.
1435 +- another access to the file may happen during moving-down, including
1436 + UDBA (see "Revalidate Dentry and UDBA").
1437 +- the file should not be hard-linked nor pseudo-linked. they should be
1438 + handled by auplink utility later.
1440 +Sometimes users want to move-down a file from the upper writable branch
1441 +to the lower readonly or writable branch. For instance,
1442 +- the free space of the upper writable branch is going to run out.
1443 +- create a new intermediate branch between the upper and lower branch.
1446 +For this purpose, use "aumvdown" command in aufs-util.git.
1447 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1448 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1449 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-12-03 15:38:59.929980643 +0100
1452 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1454 +# This program is free software; you can redistribute it and/or modify
1455 +# it under the terms of the GNU General Public License as published by
1456 +# the Free Software Foundation; either version 2 of the License, or
1457 +# (at your option) any later version.
1459 +# This program is distributed in the hope that it will be useful,
1460 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1461 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1462 +# GNU General Public License for more details.
1464 +# You should have received a copy of the GNU General Public License
1465 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1467 +Support for a branch who has its ->atomic_open()
1468 +----------------------------------------------------------------------
1469 +The filesystems who implement its ->atomic_open() are not majority. For
1470 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1471 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1472 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1473 +sure whether all filesystems who have ->atomic_open() behave like this,
1474 +but NFSv4 surely returns the error.
1476 +In order to support ->atomic_open() for aufs, there are a few
1479 +A. Introduce aufs_atomic_open()
1480 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1482 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1483 + an aufs user Pip Cet's approach
1484 + - calls aufs_create(), VFS finish_open() and notify_change().
1485 + - pass fake-mode to finish_open(), and then correct the mode by
1487 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1488 + - no aufs_atomic_open().
1489 + - aufs_lookup() registers the TID to an aufs internal object.
1490 + - aufs_create() does nothing when the matching TID is registered, but
1491 + registers the mode.
1492 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1493 + TID is registered.
1494 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1496 + - no aufs_atomic_open().
1497 + - aufs_create() registers the TID to an internal object. this info
1498 + represents "this process created this file just now."
1499 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1500 + registered TID and re-try open() with superuser's credential.
1502 +Pros and cons for each approach.
1505 + - straightforward but highly depends upon VFS internal.
1506 + - the atomic behavaiour is kept.
1507 + - some of parameters such as nameidata are hard to reproduce for
1511 + - easy to implement.
1512 + - the atomic behavaiour is lost.
1514 + - the atomic behavaiour is kept.
1515 + - dirty and tricky.
1516 + - VFS checks whether the file is created correctly after calling
1517 + ->create(), which means this approach doesn't work.
1519 + - easy to implement.
1520 + - the atomic behavaiour is lost.
1521 + - to open a file with superuser's credential and give it to a user
1522 + process is a bad idea, since the file object keeps the credential
1523 + in it. It may affect LSM or something. This approach doesn't work
1526 +The approach A is ideal, but it hard to implement. So here is a
1527 +variation of A, which is to be implemented.
1529 +A-1. Introduce aufs_atomic_open()
1530 + - calls branch fs ->atomic_open() if exists. otherwise calls
1531 + vfs_create() and finish_open().
1532 + - the demerit is that the several checks after branch fs
1533 + ->atomic_open() are lost. in the ordinary case, the checks are
1534 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1535 + be implemented in aufs, but not all I am afraid.
1536 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1537 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1538 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-12-03 15:38:59.929980643 +0100
1541 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1543 +# This program is free software; you can redistribute it and/or modify
1544 +# it under the terms of the GNU General Public License as published by
1545 +# the Free Software Foundation; either version 2 of the License, or
1546 +# (at your option) any later version.
1548 +# This program is distributed in the hope that it will be useful,
1549 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1550 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1551 +# GNU General Public License for more details.
1553 +# You should have received a copy of the GNU General Public License
1554 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1557 +----------------------------------------------------------------------
1558 +Since aufs has a character of sub-VFS (see Introduction), it operates
1559 +lookup for branches as VFS does. It may be a heavy work. But almost all
1560 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1561 +directly connected to its parent. Digging down the directory hierarchy
1562 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1565 +When a branch is a remote filesystem, aufs basically relies upon its
1566 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1568 +For d_revalidate, aufs implements three levels of revalidate tests. See
1569 +"Revalidate Dentry and UDBA" in detail.
1572 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1573 +----------------------------------------------------------------------
1574 +Let's try case study.
1575 +- aufs has two branches, upper readwrite and lower readonly.
1577 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1578 +- user invoked "chmod a+rx /au/dirA"
1579 +- the internal copy-up is activated and "/rw/dirA" is created and its
1580 + permission bits are set to world readable.
1581 +- then "/au/dirA" becomes world readable?
1583 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1584 +or it may be a natively readonly filesystem. If aufs respects the lower
1585 +branch, it should not respond readdir request from other users. But user
1586 +allowed it by chmod. Should really aufs rejects showing the entries
1589 +To be honest, I don't have a good solution for this case. So aufs
1590 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1592 +When dirperm1 is specified, aufs checks only the highest one for the
1593 +directory permission, and shows the entries. Otherwise, as usual, checks
1594 +every dir existing on all branches and rejects the request.
1596 +As a side effect, dirperm1 option improves the performance of aufs
1597 +because the number of permission check is reduced when the number of
1601 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1602 +----------------------------------------------------------------------
1603 +Generally VFS helpers re-validate a dentry as a part of lookup.
1604 +0. digging down the directory hierarchy.
1605 +1. lock the parent dir by its i_mutex.
1606 +2. lookup the final (child) entry.
1608 +4. call the actual operation (create, unlink, etc.)
1609 +5. unlock the parent dir
1611 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1612 +called. Actually aufs implements it and checks the dentry on a branch is
1614 +But it is not enough. Because aufs has to release the lock for the
1615 +parent dir on a branch at the end of ->lookup() (step 2) and
1616 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1618 +If the file on a branch is changed directly, eg. bypassing aufs, after
1619 +aufs released the lock, then the subsequent operation may cause
1620 +something unpleasant result.
1622 +This situation is a result of VFS architecture, ->lookup() and
1623 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1624 +design from VFS's point of view. It is just not suitable for sub-VFS
1627 +Aufs supports such case by three level of revalidation which is
1628 +selectable by user.
1629 +1. Simple Revalidate
1630 + Addition to the native flow in VFS's, confirm the child-parent
1631 + relationship on the branch just after locking the parent dir on the
1632 + branch in the "actual operation" (step 4). When this validation
1633 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1634 + checks the validation of the dentry on branches.
1635 +2. Monitor Changes Internally by Inotify/Fsnotify
1636 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1637 + the dentry on the branch, and returns EBUSY if it finds different
1639 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1640 + during it is in cache. When the event is notified, aufs registers a
1641 + function to kernel 'events' thread by schedule_work(). And the
1642 + function sets some special status to the cached aufs dentry and inode
1643 + private data. If they are not cached, then aufs has nothing to
1644 + do. When the same file is accessed through aufs (step 0-3) later,
1645 + aufs will detect the status and refresh all necessary data.
1646 + In this mode, aufs has to ignore the event which is fired by aufs
1648 +3. No Extra Validation
1649 + This is the simplest test and doesn't add any additional revalidation
1650 + test, and skip the revalidation in step 4. It is useful and improves
1651 + aufs performance when system surely hide the aufs branches from user,
1652 + by over-mounting something (or another method).
1653 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1654 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1655 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-12-03 15:38:59.929980643 +0100
1658 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1660 +# This program is free software; you can redistribute it and/or modify
1661 +# it under the terms of the GNU General Public License as published by
1662 +# the Free Software Foundation; either version 2 of the License, or
1663 +# (at your option) any later version.
1665 +# This program is distributed in the hope that it will be useful,
1666 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1667 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1668 +# GNU General Public License for more details.
1670 +# You should have received a copy of the GNU General Public License
1671 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1673 +Branch Manipulation
1675 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1676 +and changing its permission/attribute, there are a lot of works to do.
1680 +----------------------------------------------------------------------
1681 +o Confirm the adding dir exists outside of aufs, including loopback
1682 + mount, and its various attributes.
1683 +o Initialize the xino file and whiteout bases if necessary.
1686 +o Check the owner/group/mode of the directory
1687 + When the owner/group/mode of the adding directory differs from the
1688 + existing branch, aufs issues a warning because it may impose a
1690 + For example, when a upper writable branch has a world writable empty
1691 + top directory, a malicious user can create any files on the writable
1692 + branch directly, like copy-up and modify manually. If something like
1693 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1694 + writable branch, and the writable branch is world-writable, then a
1695 + malicious guy may create /etc/passwd on the writable branch directly
1696 + and the infected file will be valid in aufs.
1697 + I am afraid it can be a security issue, but aufs can do nothing except
1698 + producing a warning.
1702 +----------------------------------------------------------------------
1703 +o Confirm the deleting branch is not busy
1704 + To be general, there is one merit to adopt "remount" interface to
1705 + manipulate branches. It is to discard caches. At deleting a branch,
1706 + aufs checks the still cached (and connected) dentries and inodes. If
1707 + there are any, then they are all in-use. An inode without its
1708 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1710 + For the cached one, aufs checks whether the same named entry exists on
1712 + If the cached one is a directory, because aufs provides a merged view
1713 + to users, as long as one dir is left on any branch aufs can show the
1714 + dir to users. In this case, the branch can be removed from aufs.
1715 + Otherwise aufs rejects deleting the branch.
1717 + If any file on the deleting branch is opened by aufs, then aufs
1721 +Modify the Permission of a Branch
1722 +----------------------------------------------------------------------
1723 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1726 +o rw --> ro: Confirm the modifying branch is not busy
1727 + Aufs rejects the request if any of these conditions are true.
1728 + - a file on the branch is mmap-ed.
1729 + - a regular file on the branch is opened for write and there is no
1730 + same named entry on the upper branch.
1731 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1732 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1733 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-12-03 15:38:59.929980643 +0100
1736 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1738 +# This program is free software; you can redistribute it and/or modify
1739 +# it under the terms of the GNU General Public License as published by
1740 +# the Free Software Foundation; either version 2 of the License, or
1741 +# (at your option) any later version.
1743 +# This program is distributed in the hope that it will be useful,
1744 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1745 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1746 +# GNU General Public License for more details.
1748 +# You should have received a copy of the GNU General Public License
1749 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1751 +Policies to Select One among Multiple Writable Branches
1752 +----------------------------------------------------------------------
1753 +When the number of writable branch is more than one, aufs has to decide
1754 +the target branch for file creation or copy-up. By default, the highest
1755 +writable branch which has the parent (or ancestor) dir of the target
1756 +file is chosen (top-down-parent policy).
1757 +By user's request, aufs implements some other policies to select the
1758 +writable branch, for file creation several policies, round-robin,
1759 +most-free-space, and other policies. For copy-up, top-down-parent,
1760 +bottom-up-parent, bottom-up and others.
1762 +As expected, the round-robin policy selects the branch in circular. When
1763 +you have two writable branches and creates 10 new files, 5 files will be
1764 +created for each branch. mkdir(2) systemcall is an exception. When you
1765 +create 10 new directories, all will be created on the same branch.
1766 +And the most-free-space policy selects the one which has most free
1767 +space among the writable branches. The amount of free space will be
1768 +checked by aufs internally, and users can specify its time interval.
1770 +The policies for copy-up is more simple,
1771 +top-down-parent is equivalent to the same named on in create policy,
1772 +bottom-up-parent selects the writable branch where the parent dir
1773 +exists and the nearest upper one from the copyup-source,
1774 +bottom-up selects the nearest upper writable branch from the
1775 +copyup-source, regardless the existence of the parent dir.
1777 +There are some rules or exceptions to apply these policies.
1778 +- If there is a readonly branch above the policy-selected branch and
1779 + the parent dir is marked as opaque (a variation of whiteout), or the
1780 + target (creating) file is whiteout-ed on the upper readonly branch,
1781 + then the result of the policy is ignored and the target file will be
1782 + created on the nearest upper writable branch than the readonly branch.
1783 +- If there is a writable branch above the policy-selected branch and
1784 + the parent dir is marked as opaque or the target file is whiteouted
1785 + on the branch, then the result of the policy is ignored and the target
1786 + file will be created on the highest one among the upper writable
1787 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1789 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1790 + They try selecting the branch where the source exists as possible
1791 + since copyup a large file will take long time. If it can't be,
1792 + ie. the branch where the source exists is readonly, then they will
1793 + follow the copyup policy.
1794 +- There is an exception for rename(2) when the target exists.
1795 + If the rename target exists, aufs compares the index of the branches
1796 + where the source and the target exists and selects the higher
1797 + one. If the selected branch is readonly, then aufs follows the
1799 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1800 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1801 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-12-03 15:38:59.929980643 +0100
1804 +// to view this graph, run dot(1) command in GRAPHVIZ.
1808 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1812 +aufs_rename -> whinfo [label="store/remove"];
1815 +inode_list [label="h_inum list in branch\ncache"];
1818 +whinode [label="h_inum list file"];
1821 +brmgmt [label="br_add/del/mod/umount"];
1823 +brmgmt -> inode_list [label="create/remove"];
1824 +brmgmt -> whinode [label="load/store"];
1826 +inode_list -> whinode [style=dashed,dir=both];
1828 +aufs_rename -> inode_list [label="add/del"];
1830 +aufs_lookup -> inode_list [label="search"];
1832 +aufs_lookup -> whinfo [label="load/remove"];
1834 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1835 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1836 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-12-03 15:38:59.929980643 +0100
1839 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1841 +# This program is free software; you can redistribute it and/or modify
1842 +# it under the terms of the GNU General Public License as published by
1843 +# the Free Software Foundation; either version 2 of the License, or
1844 +# (at your option) any later version.
1846 +# This program is distributed in the hope that it will be useful,
1847 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1848 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1849 +# GNU General Public License for more details.
1851 +# You should have received a copy of the GNU General Public License
1852 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1854 +Special handling for renaming a directory (DIRREN)
1855 +----------------------------------------------------------------------
1856 +First, let's assume we have a simple usecase.
1860 +- /ro/dirA and /ro/dirA/file exist too
1861 +- there is no dirB on both branches
1862 +- a user issues rename("dirA", "dirB")
1864 +Now, what should aufs behave against this rename(2)?
1865 +There are a few possible cases.
1868 + since dirA exists on a readonly branch which cannot be renamed.
1870 + it is possible to copy-up dirA (only the dir itself), but the child
1871 + entries ("file" in this case) should not be. it must be a bad
1872 + approach to copy-up recursively.
1873 +C. returns a success.
1874 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1875 + is a violation of aufs' policy.
1876 +D. construct an extra information which indicates that /ro/dirA should
1877 + be handled as the name of dirB.
1878 + overlayfs has a similar feature called REDIRECT.
1880 +Until now, aufs implements the case B only which returns EXDEV, and
1881 +expects the userspace application behaves like mv(1) which tries
1882 +issueing rename(2) recursively.
1884 +A new aufs feature called DIRREN is introduced which implements the case
1885 +D. There are several "extra information" added.
1887 +1. detailed info per renamed directory
1888 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1889 +2. the inode-number list of directories on a branch
1890 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1892 +The filename of "detailed info per directory" represents the lower
1893 +branch, and its format is
1894 +- a type of the branch id
1896 + + uuid (not implemented yet)
1899 +- the inode-number of the branch root dir
1901 +And it contains these info in a single regular file.
1903 +- branch's inode-number of the logically renamed dir
1904 +- the name of the before-renamed dir
1906 +The "detailed info per directory" file is created in aufs rename(2), and
1907 +loaded in any lookup.
1908 +The info is considered in lookup for the matching case only. Here
1909 +"matching" means that the root of branch (in the info filename) is same
1910 +to the current looking-up branch. After looking-up the before-renamed
1911 +name, the inode-number is compared. And the matched dentry is used.
1913 +The "inode-number list of directories" is a regular file which contains
1914 +simply the inode-numbers on the branch. The file is created or updated
1915 +in removing the branch, and loaded in adding the branch. Its lifetime is
1916 +equal to the branch.
1917 +The list is refered in lookup, and when the current target inode is
1918 +found in the list, the aufs tries loading the "detailed info per
1919 +directory" and get the changed and valid name of the dir.
1921 +Theoretically these "extra informaiton" may be able to be put into XATTR
1922 +in the dir inode. But aufs doesn't choose this way because
1923 +1. XATTR may not be supported by the branch (or its configuration)
1924 +2. XATTR may have its size limit.
1925 +3. XATTR may be less easy to convert than a regular file, when the
1926 + format of the info is changed in the future.
1927 +At the same time, I agree that the regular file approach is much slower
1928 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1931 +This DIRREN feature is enabled by aufs configuration, and is activated
1932 +by a new mount option.
1934 +For the more complicated case, there is a work with UDBA option, which
1935 +is to dected the direct access to the branches (by-passing aufs) and to
1936 +maintain the cashes in aufs. Since a single cached aufs dentry may
1937 +contains two names, before- and after-rename, the name comparision in
1938 +UDBA handler may not work correctly. In this case, the behaviour will be
1939 +equivalen to udba=reval case.
1940 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1941 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1942 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-12-03 15:38:59.929980643 +0100
1945 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1947 +# This program is free software; you can redistribute it and/or modify
1948 +# it under the terms of the GNU General Public License as published by
1949 +# the Free Software Foundation; either version 2 of the License, or
1950 +# (at your option) any later version.
1952 +# This program is distributed in the hope that it will be useful,
1953 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1954 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1955 +# GNU General Public License for more details.
1957 +# You should have received a copy of the GNU General Public License
1958 +# along with this program; if not, write to the Free Software
1959 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1962 +File-based Hierarchical Storage Management (FHSM)
1963 +----------------------------------------------------------------------
1964 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1965 +storage world. Aufs provides this feature as file-based with multiple
1966 +writable branches, based upon the principle of "Colder, the Lower".
1967 +Here the word "colder" means that the less used files, and "lower" means
1968 +that the position in the order of the stacked branches vertically.
1969 +These multiple writable branches are prioritized, ie. the topmost one
1970 +should be the fastest drive and be used heavily.
1972 +o Characters in aufs FHSM story
1973 +- aufs itself and a new branch attribute.
1974 +- a new ioctl interface to move-down and to establish a connection with
1975 + the daemon ("move-down" is a converse of "copy-up").
1976 +- userspace tool and daemon.
1978 +The userspace daemon establishes a connection with aufs and waits for
1979 +the notification. The notified information is very similar to struct
1980 +statfs containing the number of consumed blocks and inodes.
1981 +When the consumed blocks/inodes of a branch exceeds the user-specified
1982 +upper watermark, the daemon activates its move-down process until the
1983 +consumed blocks/inodes reaches the user-specified lower watermark.
1985 +The actual move-down is done by aufs based upon the request from
1986 +user-space since we need to maintain the inode number and the internal
1987 +pointer arrays in aufs.
1989 +Currently aufs FHSM handles the regular files only. Additionally they
1990 +must not be hard-linked nor pseudo-linked.
1993 +o Cowork of aufs and the user-space daemon
1994 + During the userspace daemon established the connection, aufs sends a
1995 + small notification to it whenever aufs writes something into the
1996 + writable branch. But it may cost high since aufs issues statfs(2)
1997 + internally. So user can specify a new option to cache the
1998 + info. Actually the notification is controlled by these factors.
1999 + + the specified cache time.
2000 + + classified as "force" by aufs internally.
2001 + Until the specified time expires, aufs doesn't send the info
2002 + except the forced cases. When aufs decide forcing, the info is always
2003 + notified to userspace.
2004 + For example, the number of free inodes is generally large enough and
2005 + the shortage of it happens rarely. So aufs doesn't force the
2006 + notification when creating a new file, directory and others. This is
2007 + the typical case which aufs doesn't force.
2008 + When aufs writes the actual filedata and the files consumes any of new
2009 + blocks, the aufs forces notifying.
2012 +o Interfaces in aufs
2013 +- New branch attribute.
2015 + Specifies that the branch is managed by FHSM feature. In other word,
2016 + participant in the FHSM.
2017 + When nofhsm is set to the branch, it will not be the source/target
2018 + branch of the move-down operation. This attribute is set
2019 + independently from coo and moo attributes, and if you want full
2020 + FHSM, you should specify them as well.
2021 +- New mount option.
2023 + Specifies a second to suppress many less important info to be
2026 + + AUFS_CTL_FHSM_FD
2027 + create a new file descriptor which userspace can read the notification
2028 + (a subset of struct statfs) from aufs.
2029 +- Module parameter 'brs'
2030 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2032 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2033 + When there are two or more branches with fhsm attributes,
2034 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2035 + terminates it. As a result of remounting and branch-manipulation, the
2036 + number of branches with fhsm attribute can be one. In this case,
2037 + /sbin/mount.aufs will terminate the user-space daemon.
2040 +Finally the operation is done as these steps in kernel-space.
2042 + + no one else is using the file.
2043 + + the file is not hard-linked.
2044 + + the file is not pseudo-linked.
2045 + + the file is a regular file.
2046 + + the parent dir is not opaqued.
2047 +- find the target writable branch.
2048 +- make sure the file is not whiteout-ed by the upper (than the target)
2050 +- make the parent dir on the target branch.
2051 +- mutex lock the inode on the branch.
2052 +- unlink the whiteout on the target branch (if exists).
2053 +- lookup and create the whiteout-ed temporary name on the target branch.
2054 +- copy the file as the whiteout-ed temporary name on the target branch.
2055 +- rename the whiteout-ed temporary name to the original name.
2056 +- unlink the file on the source branch.
2057 +- maintain the internal pointer array and the external inode number
2059 +- maintain the timestamps and other attributes of the parent dir and the
2062 +And of course, in every step, an error may happen. So the operation
2063 +should restore the original file state after an error happens.
2064 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2065 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2066 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-12-03 15:38:59.929980643 +0100
2069 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2071 +# This program is free software; you can redistribute it and/or modify
2072 +# it under the terms of the GNU General Public License as published by
2073 +# the Free Software Foundation; either version 2 of the License, or
2074 +# (at your option) any later version.
2076 +# This program is distributed in the hope that it will be useful,
2077 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2078 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2079 +# GNU General Public License for more details.
2081 +# You should have received a copy of the GNU General Public License
2082 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2084 +mmap(2) -- File Memory Mapping
2085 +----------------------------------------------------------------------
2086 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2087 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2089 +This approach is simple and good, but there is one problem.
2090 +Under /proc, several entries show the mmapped files by its path (with
2091 +device and inode number), and the printed path will be the path on the
2092 +branch fs's instead of virtual aufs's.
2093 +This is not a problem in most cases, but some utilities lsof(1) (and its
2094 +user) may expect the path on aufs.
2096 +To address this issue, aufs adds a new member called vm_prfile in struct
2097 +vm_area_struct (and struct vm_region). The original vm_file points to
2098 +the file on the branch fs in order to handle everything correctly as
2099 +usual. The new vm_prfile points to a virtual file in aufs, and the
2100 +show-functions in procfs refers to vm_prfile if it is set.
2101 +Also we need to maintain several other places where touching vm_file
2103 +- fork()/clone() copies vma and the reference count of vm_file is
2105 +- merging vma maintains the ref count too.
2107 +This is not a good approach. It just fakes the printed path. But it
2108 +leaves all behaviour around f_mapping unchanged. This is surely an
2110 +Actually aufs had adopted another complicated approach which calls
2111 +generic_file_mmap() and handles struct vm_operations_struct. In this
2112 +approach, aufs met a hard problem and I could not solve it without
2113 +switching the approach.
2115 +There may be one more another approach which is
2116 +- bind-mount the branch-root onto the aufs-root internally
2117 +- grab the new vfsmount (ie. struct mount)
2118 +- lazy-umount the branch-root internally
2119 +- in open(2) the aufs-file, open the branch-file with the hidden
2120 + vfsmount (instead of the original branch's vfsmount)
2121 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2122 + but it may be possible from userspace by the mount helper.
2124 +Adding the internal hidden vfsmount and using it in opening a file, the
2125 +file path under /proc will be printed correctly. This approach looks
2126 +smarter, but is not possible I am afraid.
2127 +- aufs-root may be bind-mount later. when it happens, another hidden
2128 + vfsmount will be required.
2129 +- it is hard to get the chance to bind-mount and lazy-umount
2130 + + in kernel-space, FS can have vfsmount in open(2) via
2131 + file->f_path, and aufs can know its vfsmount. But several locks are
2132 + already acquired, and if aufs tries to bind-mount and lazy-umount
2133 + here, then it may cause a deadlock.
2134 + + in user-space, bind-mount doesn't invoke the mount helper.
2135 +- since /proc shows dev and ino, aufs has to give vma these info. it
2136 + means a new member vm_prinode will be necessary. this is essentially
2137 + equivalent to vm_prfile described above.
2139 +I have to give up this "looks-smater" approach.
2140 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2141 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2142 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-12-03 15:38:59.929980643 +0100
2145 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2147 +# This program is free software; you can redistribute it and/or modify
2148 +# it under the terms of the GNU General Public License as published by
2149 +# the Free Software Foundation; either version 2 of the License, or
2150 +# (at your option) any later version.
2152 +# This program is distributed in the hope that it will be useful,
2153 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2154 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2155 +# GNU General Public License for more details.
2157 +# You should have received a copy of the GNU General Public License
2158 +# along with this program; if not, write to the Free Software
2159 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2162 +Listing XATTR/EA and getting the value
2163 +----------------------------------------------------------------------
2164 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2165 +shows the values from the topmost existing file. This behaviour is good
2166 +for the non-dir entries since the bahaviour exactly matches the shown
2167 +information. But for the directories, aufs considers all the same named
2168 +entries on the lower branches. Which means, if one of the lower entry
2169 +rejects readdir call, then aufs returns an error even if the topmost
2170 +entry allows it. This behaviour is necessary to respect the branch fs's
2171 +security, but can make users confused since the user-visible standard
2172 +attributes don't match the behaviour.
2173 +To address this issue, aufs has a mount option called dirperm1 which
2174 +checks the permission for the topmost entry only, and ignores the lower
2175 +entry's permission.
2177 +A similar issue can happen around XATTR.
2178 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2179 +always set. Otherwise these very unpleasant situation would happen.
2180 +- listxattr(2) may return the duplicated entries.
2181 +- users may not be able to remove or reset the XATTR forever,
2184 +XATTR/EA support in the internal (copy,move)-(up,down)
2185 +----------------------------------------------------------------------
2186 +Generally the extended attributes of inode are categorized as these.
2187 +- "security" for LSM and capability.
2188 +- "system" for posix ACL, 'acl' mount option is required for the branch
2190 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2191 +- "user" for userspace, 'user_xattr' mount option is required for the
2192 + branch fs generally.
2194 +Moreover there are some other categories. Aufs handles these rather
2195 +unpopular categories as the ordinary ones, ie. there is no special
2196 +condition nor exception.
2198 +In copy-up, the support for XATTR on the dst branch may differ from the
2199 +src branch. In this case, the copy-up operation will get an error and
2200 +the original user operation which triggered the copy-up will fail. It
2201 +can happen that even all copy-up will fail.
2202 +When both of src and dst branches support XATTR and if an error occurs
2203 +during copying XATTR, then the copy-up should fail obviously. That is a
2204 +good reason and aufs should return an error to userspace. But when only
2205 +the src branch support that XATTR, aufs should not return an error.
2206 +For example, the src branch supports ACL but the dst branch doesn't
2207 +because the dst branch may natively un-support it or temporary
2208 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2209 +may NOT return an error even if the XATTR is not supported. It is
2210 +totally up to the branch fs.
2212 +Anyway when the aufs internal copy-up gets an error from the dst branch
2213 +fs, then aufs tries removing the just copied entry and returns the error
2214 +to the userspace. The worst case of this situation will be all copy-up
2217 +For the copy-up operation, there two basic approaches.
2218 +- copy the specified XATTR only (by category above), and return the
2219 + error unconditionally if it happens.
2220 +- copy all XATTR, and ignore the error on the specified category only.
2222 +In order to support XATTR and to implement the correct behaviour, aufs
2223 +chooses the latter approach and introduces some new branch attributes,
2224 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2225 +They correspond to the XATTR namespaces (see above). Additionally, to be
2226 +convenient, "icex" is also provided which means all "icex*" attributes
2227 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2229 +The meaning of these attributes is to ignore the error from setting
2230 +XATTR on that branch.
2231 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2232 +error from the dst branch according to the specified attributes.
2234 +Some XATTR may have its default value. The default value may come from
2235 +the parent dir or the environment. If the default value is set at the
2236 +file creating-time, it will be overwritten by copy-up.
2237 +Some contradiction may happen I am afraid.
2238 +Do we need another attribute to stop copying XATTR? I am unsure. For
2239 +now, aufs implements the branch attributes to ignore the error.
2240 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2241 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2242 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-12-03 15:38:59.929980643 +0100
2245 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2247 +# This program is free software; you can redistribute it and/or modify
2248 +# it under the terms of the GNU General Public License as published by
2249 +# the Free Software Foundation; either version 2 of the License, or
2250 +# (at your option) any later version.
2252 +# This program is distributed in the hope that it will be useful,
2253 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2254 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2255 +# GNU General Public License for more details.
2257 +# You should have received a copy of the GNU General Public License
2258 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2260 +Export Aufs via NFS
2261 +----------------------------------------------------------------------
2262 +Here is an approach.
2263 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2265 +- iget_locked(): initialize aufs inode generation for a new inode, and
2266 + store it in xigen file.
2267 +- destroy_inode(): increment aufs inode generation and store it in xigen
2268 + file. it is necessary even if it is not unlinked, because any data of
2269 + inode may be changed by UDBA.
2270 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2271 + build file handle by
2272 + + branch id (4 bytes)
2273 + + superblock generation (4 bytes)
2274 + + inode number (4 or 8 bytes)
2275 + + parent dir inode number (4 or 8 bytes)
2276 + + inode generation (4 bytes))
2277 + + return value of exportfs_encode_fh() for the parent on a branch (4
2279 + + file handle for a branch (by exportfs_encode_fh())
2281 + + find the index of a branch from its id in handle, and check it is
2282 + still exist in aufs.
2283 + + 1st level: get the inode number from handle and search it in cache.
2284 + + 2nd level: if not found in cache, get the parent inode number from
2285 + the handle and search it in cache. and then open the found parent
2286 + dir, find the matching inode number by vfs_readdir() and get its
2287 + name, and call lookup_one_len() for the target dentry.
2288 + + 3rd level: if the parent dir is not cached, call
2289 + exportfs_decode_fh() for a branch and get the parent on a branch,
2290 + build a pathname of it, convert it a pathname in aufs, call
2291 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2293 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2294 + for every branch, but not itself. to get this, (currently) aufs
2295 + searches in current->nsproxy->mnt_ns list. it may not be a good
2296 + idea, but I didn't get other approach.
2297 + + test the generation of the gotten inode.
2298 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2299 + convert it into ESTALE for NFSD.
2300 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2301 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2302 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2303 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2304 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-12-03 15:38:59.929980643 +0100
2307 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2309 +# This program is free software; you can redistribute it and/or modify
2310 +# it under the terms of the GNU General Public License as published by
2311 +# the Free Software Foundation; either version 2 of the License, or
2312 +# (at your option) any later version.
2314 +# This program is distributed in the hope that it will be useful,
2315 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2316 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2317 +# GNU General Public License for more details.
2319 +# You should have received a copy of the GNU General Public License
2320 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2322 +Show Whiteout Mode (shwh)
2323 +----------------------------------------------------------------------
2324 +Generally aufs hides the name of whiteouts. But in some cases, to show
2325 +them is very useful for users. For instance, creating a new middle layer
2326 +(branch) by merging existing layers.
2328 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2329 +When you have three branches,
2330 +- Bottom: 'system', squashfs (underlying base system), read-only
2331 +- Middle: 'mods', squashfs, read-only
2332 +- Top: 'overlay', ram (tmpfs), read-write
2334 +The top layer is loaded at boot time and saved at shutdown, to preserve
2335 +the changes made to the system during the session.
2336 +When larger changes have been made, or smaller changes have accumulated,
2337 +the size of the saved top layer data grows. At this point, it would be
2338 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2339 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2340 +restoring save and load speed.
2342 +This merging is simplified by the use of another aufs mount, of just the
2343 +two overlay branches using the 'shwh' option.
2344 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2345 + aufs /livesys/merge_union
2347 +A merged view of these two branches is then available at
2348 +/livesys/merge_union, and the new feature is that the whiteouts are
2350 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2351 +writing to all branches. Also the default mode for all branches is 'ro'.
2352 +It is now possible to save the combined contents of the two overlay
2353 +branches to a new squashfs, e.g.:
2354 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2356 +This new squashfs archive can be stored on the boot device and the
2357 +initramfs will use it to replace the old one at the next boot.
2358 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2359 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2360 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-12-03 15:38:59.929980643 +0100
2363 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2365 +# This program is free software; you can redistribute it and/or modify
2366 +# it under the terms of the GNU General Public License as published by
2367 +# the Free Software Foundation; either version 2 of the License, or
2368 +# (at your option) any later version.
2370 +# This program is distributed in the hope that it will be useful,
2371 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2372 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2373 +# GNU General Public License for more details.
2375 +# You should have received a copy of the GNU General Public License
2376 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2378 +Dynamically customizable FS operations
2379 +----------------------------------------------------------------------
2380 +Generally FS operations (struct inode_operations, struct
2381 +address_space_operations, struct file_operations, etc.) are defined as
2382 +"static const", but it never means that FS have only one set of
2383 +operation. Some FS have multiple sets of them. For instance, ext2 has
2384 +three sets, one for XIP, for NOBH, and for normal.
2385 +Since aufs overrides and redirects these operations, sometimes aufs has
2386 +to change its behaviour according to the branch FS type. More importantly
2387 +VFS acts differently if a function (member in the struct) is set or
2388 +not. It means aufs should have several sets of operations and select one
2389 +among them according to the branch FS definition.
2391 +In order to solve this problem and not to affect the behaviour of VFS,
2392 +aufs defines these operations dynamically. For instance, aufs defines
2393 +dummy direct_IO function for struct address_space_operations, but it may
2394 +not be set to the address_space_operations actually. When the branch FS
2395 +doesn't have it, aufs doesn't set it to its address_space_operations
2396 +while the function definition itself is still alive. So the behaviour
2397 +itself will not change, and it will return an error when direct_IO is
2400 +The lifetime of these dynamically generated operation object is
2401 +maintained by aufs branch object. When the branch is removed from aufs,
2402 +the reference counter of the object is decremented. When it reaches
2403 +zero, the dynamically generated operation object will be freed.
2405 +This approach is designed to support AIO (io_submit), Direct I/O and
2407 +Currently this approach is applied to address_space_operations for
2408 +regular files only.
2409 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2410 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2411 +++ linux/Documentation/filesystems/aufs/README 2021-12-03 15:38:59.929980643 +0100
2414 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2420 +----------------------------------------
2421 +In the early days, aufs was entirely re-designed and re-implemented
2422 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2423 +improvements and implementations, it became totally different from
2424 +Unionfs while keeping the basic features.
2425 +Later, Unionfs Version 2.x series began taking some of the same
2426 +approaches to aufs1's.
2427 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2428 +University and his team.
2430 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2432 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2433 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2434 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2435 + or aufs1 from CVS on SourceForge.
2437 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2438 + According to Christoph Hellwig, linux rejects all union-type
2439 + filesystems but UnionMount.
2440 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2442 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2443 + UnionMount, and he pointed out an issue around a directory mutex
2444 + lock and aufs addressed it. But it is still unsure whether aufs will
2445 + be merged (or any other union solution).
2446 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2450 +----------------------------------------
2451 +- unite several directories into a single virtual filesystem. The member
2452 + directory is called as a branch.
2453 +- you can specify the permission flags to the branch, which are 'readonly',
2454 + 'readwrite' and 'whiteout-able.'
2455 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2456 + readonly branch are modifiable logically.
2457 +- dynamic branch manipulation, add, del.
2460 +Also there are many enhancements in aufs, such as:
2461 +- test only the highest one for the directory permission (dirperm1)
2462 +- copyup on open (coo=)
2463 +- 'move' policy for copy-up between two writable branches, after
2464 + checking free space.
2466 +- readdir(3) in userspace.
2467 +- keep inode number by external inode number table
2468 +- keep the timestamps of file/dir in internal copyup operation
2469 +- seekable directory, supporting NFS readdir.
2470 +- whiteout is hardlinked in order to reduce the consumption of inodes
2472 +- do not copyup, nor create a whiteout when it is unnecessary
2473 +- revert a single systemcall when an error occurs in aufs
2474 +- remount interface instead of ioctl
2475 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2476 +- loopback mounted filesystem as a branch
2477 +- kernel thread for removing the dir who has a plenty of whiteouts
2478 +- support copyup sparse file (a file which has a 'hole' in it)
2479 +- default permission flags for branches
2480 +- selectable permission flags for ro branch, whether whiteout can
2483 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2484 +- support multiple writable branches, some policies to select one
2485 + among multiple writable branches.
2486 +- a new semantics for link(2) and rename(2) to support multiple
2487 + writable branches.
2488 +- no glibc changes are required.
2489 +- pseudo hardlink (hardlink over branches)
2490 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2491 + including NFS or remote filesystem branch.
2492 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2495 +Currently these features are dropped temporary from aufs5.
2496 +See design/08plan.txt in detail.
2497 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2499 +- statistics of aufs thread (/sys/fs/aufs/stat)
2501 +Features or just an idea in the future (see also design/*.txt),
2502 +- reorder the branch index without del/re-add.
2503 +- permanent xino files for NFSD
2504 +- an option for refreshing the opened files after add/del branches
2505 +- light version, without branch manipulation. (unnecessary?)
2506 +- copyup in userspace
2507 +- inotify in userspace
2512 +----------------------------------------
2513 +There are three GIT trees for aufs5, aufs5-linux.git,
2514 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2516 +While the aufs-util is always necessary, you need either of aufs5-linux
2517 +or aufs5-standalone.
2519 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2520 +git://git.kernel.org/.../torvalds/linux.git.
2521 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2522 +build aufs5 as an external kernel module.
2523 +Several extra patches are not included in this tree. Only
2524 +aufs5-standalone tree contains them. They are described in the later
2525 +section "Configuration and Compilation."
2527 +On the other hand, the aufs5-standalone tree has only aufs source files
2528 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2529 +But you need to apply all aufs patches manually.
2531 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2532 +represents the linux kernel version, "linux-5.x". For instance,
2533 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2534 +"aufs5.x-rcN" branch.
2537 +$ git clone --reference /your/linux/git/tree \
2538 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2539 +- if you don't have linux GIT tree, then remove "--reference ..."
2540 +$ cd aufs5-linux.git
2541 +$ git checkout origin/aufs5.0
2543 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2544 +leave the patch-work to GIT.
2545 +$ cd /your/linux/git/tree
2546 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2548 +$ git checkout -b my5.0 v5.0
2549 +$ (add your local change...)
2550 +$ git pull aufs5 aufs5.0
2551 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2552 +- you may need to solve some conflicts between your_changes and
2553 + aufs5.0. in this case, git-rerere is recommended so that you can
2554 + solve the similar conflicts automatically when you upgrade to 5.1 or
2555 + later in the future.
2557 +o aufs5-standalone tree
2558 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2559 +$ cd aufs5-standalone.git
2560 +$ git checkout origin/aufs5.0
2563 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2564 +- note that the public aufs-util.git is on SourceForge instead of
2567 +$ git checkout origin/aufs5.0
2569 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2570 +The minor version number, 'x' in '5.x', of aufs may not always
2571 +follow the minor version number of the kernel.
2572 +Because changes in the kernel that cause the use of a new
2573 +minor version number do not always require changes to aufs-util.
2575 +Since aufs-util has its own minor version number, you may not be
2576 +able to find a GIT branch in aufs-util for your kernel's
2577 +exact minor version number.
2578 +In this case, you should git-checkout the branch for the
2579 +nearest lower number.
2581 +For (an unreleased) example:
2582 +If you are using "linux-5.10" and the "aufs5.10" branch
2583 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2584 +or something numerically smaller is the branch for your kernel.
2586 +Also you can view all branches by
2590 +3. Configuration and Compilation
2591 +----------------------------------------
2592 +Make sure you have git-checkout'ed the correct branch.
2594 +For aufs5-linux tree,
2595 +- enable CONFIG_AUFS_FS.
2596 +- set other aufs configurations if necessary.
2598 +For aufs5-standalone tree,
2599 +There are several ways to build.
2602 +- apply ./aufs5-kbuild.patch to your kernel source files.
2603 +- apply ./aufs5-base.patch too.
2604 +- apply ./aufs5-mmap.patch too.
2605 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2606 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2607 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2608 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2609 +- enable CONFIG_AUFS_FS, you can select either
2611 +- and build your kernel as usual.
2612 +- install the built kernel.
2613 +- install the header files too by "make headers_install" to the
2614 + directory where you specify. By default, it is $PWD/usr.
2615 + "make help" shows a brief note for headers_install.
2616 +- and reboot your system.
2619 +- module only (CONFIG_AUFS_FS=m).
2620 +- apply ./aufs5-base.patch to your kernel source files.
2621 +- apply ./aufs5-mmap.patch too.
2622 +- apply ./aufs5-standalone.patch too.
2623 +- build your kernel, don't forget "make headers_install", and reboot.
2624 +- edit ./config.mk and set other aufs configurations if necessary.
2625 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2626 + every aufs configurations.
2627 +- build the module by simple "make".
2628 +- you can specify ${KDIR} make variable which points to your kernel
2630 +- install the files
2631 + + run "make install" to install the aufs module, or copy the built
2632 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2633 + + run "make install_headers" (instead of headers_install) to install
2634 + the modified aufs header file (you can specify DESTDIR which is
2635 + available in aufs standalone version's Makefile only), or copy
2636 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2637 + you like manually. By default, the target directory is $PWD/usr.
2638 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2639 + kernel source tree.
2641 +Note: The header file aufs_type.h is necessary to build aufs-util
2642 + as well as "make headers_install" in the kernel source tree.
2643 + headers_install is subject to be forgotten, but it is essentially
2644 + necessary, not only for building aufs-util.
2645 + You may not meet problems without headers_install in some older
2649 +- read README in aufs-util, build and install it
2650 +- note that your distribution may contain an obsoleted version of
2651 + aufs_type.h in /usr/include/linux or something. When you build aufs
2652 + utilities, make sure that your compiler refers the correct aufs header
2653 + file which is built by "make headers_install."
2654 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2655 + then run "make install_ulib" too. And refer to the aufs manual in
2658 +There several other patches in aufs5-standalone.git. They are all
2659 +optional. When you meet some problems, they will help you.
2660 +- aufs5-loopback.patch
2661 + Supports a nested loopback mount in a branch-fs. This patch is
2662 + unnecessary until aufs produces a message like "you may want to try
2663 + another patch for loopback file".
2665 + Modifies a system global kernel internal function get_next_ino() in
2666 + order to stop assigning 0 for an inode-number. Not directly related to
2667 + aufs, but recommended generally.
2669 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2670 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2671 + duplication of inode number, which is important for backup tools and
2672 + other utilities. When you find aufs XINO files for tmpfs branch
2673 + growing too much, try this patch.
2674 +- lockdep-debug.patch
2675 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2676 + also a caller of VFS functions for branch filesystems, subclassing of
2677 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2678 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2679 + need to apply this debug patch to expand several constant values.
2680 + If you don't know what LOCKDEP is, then you don't have apply this
2685 +----------------------------------------
2686 +At first, make sure aufs-util are installed, and please read the aufs
2687 +manual, aufs.5 in aufs-util.git tree.
2691 +$ mkdir /tmp/rw /tmp/aufs
2692 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2694 +Here is another example. The result is equivalent.
2695 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2697 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2698 +# mount -o remount,append:${HOME} /tmp/aufs
2700 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2701 +you modify a file under /tmp/aufs, the one on your home directory is
2702 +not affected, instead the same named file will be newly created under
2703 +/tmp/rw. And all of your modification to a file will be applied to
2704 +the one under /tmp/rw. This is called the file based Copy on Write
2706 +Aufs mount options are described in aufs.5.
2707 +If you run chroot or something and make your aufs as a root directory,
2708 +then you need to customize the shutdown script. See the aufs manual in
2711 +Additionally, there are some sample usages of aufs which are a
2712 +diskless system with network booting, and LiveCD over NFS.
2713 +See sample dir in CVS tree on SourceForge.
2717 +----------------------------------------
2718 +When you have any problems or strange behaviour in aufs, please let me
2720 +- /proc/mounts (instead of the output of mount(8))
2721 +- /sys/module/aufs/*
2722 +- /sys/fs/aufs/* (if you have them)
2723 +- /debug/aufs/* (if you have them)
2724 +- linux kernel version
2725 + if your kernel is not plain, for example modified by distributor,
2726 + the url where i can download its source is necessary too.
2727 +- aufs version which was printed at loading the module or booting the
2728 + system, instead of the date you downloaded.
2729 +- configuration (define/undefine CONFIG_AUFS_xxx)
2730 +- kernel configuration or /proc/config.gz (if you have it)
2731 +- LSM (linux security module, if you are using)
2732 +- behaviour which you think to be incorrect
2733 +- actual operation, reproducible one is better
2734 +- mailto: aufs-users at lists.sourceforge.net
2736 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2737 +and Feature Requests) on SourceForge. Please join and write to
2741 +6. Acknowledgements
2742 +----------------------------------------
2743 +Thanks to everyone who have tried and are using aufs, whoever
2744 +have reported a bug or any feedback.
2746 +Especially donators:
2747 +Tomas Matejicek(slax.org) made a donation (much more than once).
2748 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2749 + scripts) is making "doubling" donations.
2750 + Unfortunately I cannot list all of the donators, but I really
2752 + It ends Aug 2010, but the ordinary donation URL is still available.
2753 + <http://sourceforge.net/donate/index.php?group_id=167503>
2754 +Dai Itasaka made a donation (2007/8).
2755 +Chuck Smith made a donation (2008/4, 10 and 12).
2756 +Henk Schoneveld made a donation (2008/9).
2757 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2758 +Francois Dupoux made a donation (2008/11).
2759 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2760 + aufs2 GIT tree (2009/2).
2761 +William Grant made a donation (2009/3).
2762 +Patrick Lane made a donation (2009/4).
2763 +The Mail Archive (mail-archive.com) made donations (2009/5).
2764 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2765 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2766 +Pavel Pronskiy made a donation (2011/2).
2767 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2768 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2769 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2771 +Sam Liddicott made a donation (2011/9).
2772 +Era Scarecrow made a donation (2013/4).
2773 +Bor Ratajc made a donation (2013/4).
2774 +Alessandro Gorreta made a donation (2013/4).
2775 +POIRETTE Marc made a donation (2013/4).
2776 +Alessandro Gorreta made a donation (2013/4).
2777 +lauri kasvandik made a donation (2013/5).
2778 +"pemasu from Finland" made a donation (2013/7).
2779 +The Parted Magic Project made a donation (2013/9 and 11).
2780 +Pavel Barta made a donation (2013/10).
2781 +Nikolay Pertsev made a donation (2014/5).
2782 +James B made a donation (2014/7 and 2015/7).
2783 +Stefano Di Biase made a donation (2014/8).
2784 +Daniel Epellei made a donation (2015/1).
2785 +OmegaPhil made a donation (2016/1, 2018/4).
2786 +Tomasz Szewczyk made a donation (2016/4).
2787 +James Burry made a donation (2016/12).
2788 +Carsten Rose made a donation (2018/9).
2789 +Porteus Kiosk made a donation (2018/10).
2791 +Thank you very much.
2792 +Donations are always, including future donations, very important and
2793 +helpful for me to keep on developing aufs.
2797 +----------------------------------------
2798 +If you are an experienced user, no explanation is needed. Aufs is
2799 +just a linux filesystem.
2804 +# Local variables: ;
2807 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2808 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2809 +++ linux/fs/aufs/aufs.h 2021-12-03 15:38:59.929980643 +0100
2811 +/* SPDX-License-Identifier: GPL-2.0 */
2813 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2815 + * This program, aufs is free software; you can redistribute it and/or modify
2816 + * it under the terms of the GNU General Public License as published by
2817 + * the Free Software Foundation; either version 2 of the License, or
2818 + * (at your option) any later version.
2820 + * This program is distributed in the hope that it will be useful,
2821 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2822 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2823 + * GNU General Public License for more details.
2825 + * You should have received a copy of the GNU General Public License
2826 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2830 + * all header files
2838 +#define AuStub(type, name, body, ...) \
2839 + static inline type name(__VA_ARGS__) { body; }
2841 +#define AuStubVoid(name, ...) \
2842 + AuStub(void, name, , __VA_ARGS__)
2843 +#define AuStubInt0(name, ...) \
2844 + AuStub(int, name, return 0, __VA_ARGS__)
2848 +#include "branch.h"
2851 +#include "dbgaufs.h"
2852 +#include "dentry.h"
2854 +#include "dirren.h"
2857 +#include "fstype.h"
2862 +#include "module.h"
2866 +#include "sysaufs.h"
2871 +#endif /* __KERNEL__ */
2872 +#endif /* __AUFS_H__ */
2873 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2874 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2875 +++ linux/fs/aufs/branch.c 2021-12-03 15:38:59.933313976 +0100
2877 +// SPDX-License-Identifier: GPL-2.0
2879 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2881 + * This program, aufs is free software; you can redistribute it and/or modify
2882 + * it under the terms of the GNU General Public License as published by
2883 + * the Free Software Foundation; either version 2 of the License, or
2884 + * (at your option) any later version.
2886 + * This program is distributed in the hope that it will be useful,
2887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2889 + * GNU General Public License for more details.
2891 + * You should have received a copy of the GNU General Public License
2892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2896 + * branch management
2899 +#include <linux/compat.h>
2900 +#include <linux/statfs.h>
2904 + * free a single branch
2906 +static void au_br_do_free(struct au_branch *br)
2909 + struct au_wbr *wbr;
2910 + struct au_dykey **key;
2912 + au_hnotify_fin_br(br);
2913 + /* always, regardless the mount option */
2914 + au_dr_hino_free(&br->br_dirren);
2917 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2918 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2919 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2920 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2924 + for (i = 0; i < AuBrWh_Last; i++)
2925 + dput(wbr->wbr_wh[i]);
2926 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2927 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2930 + if (br->br_fhsm) {
2931 + au_br_fhsm_fin(br->br_fhsm);
2932 + au_kfree_try_rcu(br->br_fhsm);
2935 + key = br->br_dykey;
2936 + for (i = 0; i < AuBrDynOp; i++, key++)
2942 + /* recursive lock, s_umount of branch's */
2943 + /* synchronize_rcu(); */ /* why? */
2945 + path_put(&br->br_path);
2947 + au_kfree_rcu(wbr);
2948 + au_lcnt_wait_for_fin(&br->br_nfiles);
2949 + au_lcnt_wait_for_fin(&br->br_count);
2950 + /* I don't know why, but percpu_refcount requires this */
2951 + /* synchronize_rcu(); */
2956 + * frees all branches
2958 +void au_br_free(struct au_sbinfo *sbinfo)
2960 + aufs_bindex_t bmax;
2961 + struct au_branch **br;
2963 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2965 + bmax = sbinfo->si_bbot + 1;
2966 + br = sbinfo->si_branch;
2968 + au_br_do_free(*br++);
2972 + * find the index of a branch which is specified by @br_id.
2974 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2976 + aufs_bindex_t bindex, bbot;
2978 + bbot = au_sbbot(sb);
2979 + for (bindex = 0; bindex <= bbot; bindex++)
2980 + if (au_sbr_id(sb, bindex) == br_id)
2985 +/* ---------------------------------------------------------------------- */
2991 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2992 + struct dentry *h_root)
2994 + if (unlikely(h_adding == h_root
2995 + || au_test_loopback_overlap(sb, h_adding)))
2997 + if (h_adding->d_sb != h_root->d_sb)
2999 + return au_test_subdir(h_adding, h_root)
3000 + || au_test_subdir(h_root, h_adding);
3004 + * returns a newly allocated branch. @new_nbranch is a number of branches
3005 + * after adding a branch.
3007 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3010 + struct au_branch *add_branch;
3011 + struct dentry *root;
3012 + struct inode *inode;
3016 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3017 + if (unlikely(!add_branch))
3019 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3020 + if (unlikely(!add_branch->br_xino))
3022 + err = au_hnotify_init_br(add_branch, perm);
3023 + if (unlikely(err))
3026 + if (au_br_writable(perm)) {
3027 + /* may be freed separately at changing the branch permission */
3028 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3030 + if (unlikely(!add_branch->br_wbr))
3034 + if (au_br_fhsm(perm)) {
3035 + err = au_fhsm_br_alloc(add_branch);
3036 + if (unlikely(err))
3040 + root = sb->s_root;
3041 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3043 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3045 + inode = d_inode(root);
3046 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3050 + return add_branch; /* success */
3053 + au_kfree_rcu(add_branch->br_wbr);
3055 + au_hnotify_fin_br(add_branch);
3057 + au_xino_put(add_branch);
3059 + au_kfree_rcu(add_branch);
3061 + return ERR_PTR(err);
3065 + * test if the branch permission is legal or not.
3067 +static int test_br(struct inode *inode, int brperm, char *path)
3071 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3076 + pr_err("write permission for readonly mount or inode, %s\n", path);
3084 + * 0: success, the caller will add it
3085 + * plus: success, it is already unified, the caller should ignore it
3088 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3091 + aufs_bindex_t bbot, bindex;
3092 + struct dentry *root, *h_dentry;
3093 + struct inode *inode, *h_inode;
3095 + root = sb->s_root;
3096 + bbot = au_sbbot(sb);
3097 + if (unlikely(bbot >= 0
3098 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3102 + pr_err("%s duplicated\n", add->pathname);
3107 + err = -ENOSPC; /* -E2BIG; */
3108 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3109 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3110 + pr_err("number of branches exceeded %s\n", add->pathname);
3115 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3116 + pr_err("bad index %d\n", add->bindex);
3120 + inode = d_inode(add->path.dentry);
3122 + if (unlikely(!inode->i_nlink)) {
3123 + pr_err("no existence %s\n", add->pathname);
3128 + if (unlikely(inode->i_sb == sb)) {
3129 + pr_err("%s must be outside\n", add->pathname);
3133 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3134 + pr_err("unsupported filesystem, %s (%s)\n",
3135 + add->pathname, au_sbtype(inode->i_sb));
3139 + if (unlikely(inode->i_sb->s_stack_depth)) {
3140 + pr_err("already stacked, %s (%s)\n",
3141 + add->pathname, au_sbtype(inode->i_sb));
3145 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3146 + if (unlikely(err))
3150 + return 0; /* success */
3153 + for (bindex = 0; bindex <= bbot; bindex++)
3154 + if (unlikely(test_overlap(sb, add->path.dentry,
3155 + au_h_dptr(root, bindex)))) {
3156 + pr_err("%s is overlapped\n", add->pathname);
3161 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3162 + h_dentry = au_h_dptr(root, 0);
3163 + h_inode = d_inode(h_dentry);
3164 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3165 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3166 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3167 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3169 + i_uid_read(inode), i_gid_read(inode),
3170 + (inode->i_mode & S_IALLUGO),
3171 + i_uid_read(h_inode), i_gid_read(h_inode),
3172 + (h_inode->i_mode & S_IALLUGO));
3180 + * initialize or clean the whiteouts for an adding branch
3182 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3185 + int err, old_perm;
3186 + aufs_bindex_t bindex;
3187 + struct inode *h_inode;
3188 + struct au_wbr *wbr;
3189 + struct au_hinode *hdir;
3190 + struct dentry *h_dentry;
3192 + err = vfsub_mnt_want_write(au_br_mnt(br));
3193 + if (unlikely(err))
3197 + old_perm = br->br_perm;
3198 + br->br_perm = new_perm;
3201 + bindex = au_br_index(sb, br->br_id);
3202 + if (0 <= bindex) {
3203 + hdir = au_hi(d_inode(sb->s_root), bindex);
3204 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3206 + h_dentry = au_br_dentry(br);
3207 + h_inode = d_inode(h_dentry);
3208 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3211 + err = au_wh_init(br, sb);
3213 + wbr_wh_write_lock(wbr);
3214 + err = au_wh_init(br, sb);
3215 + wbr_wh_write_unlock(wbr);
3218 + au_hn_inode_unlock(hdir);
3220 + inode_unlock(h_inode);
3221 + vfsub_mnt_drop_write(au_br_mnt(br));
3222 + br->br_perm = old_perm;
3224 + if (!err && wbr && !au_br_writable(new_perm)) {
3225 + au_kfree_rcu(wbr);
3226 + br->br_wbr = NULL;
3233 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3237 + struct kstatfs kst;
3238 + struct au_wbr *wbr;
3241 + au_rw_init(&wbr->wbr_wh_rwsem);
3242 + atomic_set(&wbr->wbr_wh_running, 0);
3245 + * a limit for rmdir/rename a dir
3246 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3248 + err = vfs_statfs(&br->br_path, &kst);
3249 + if (unlikely(err))
3252 + if (kst.f_namelen >= NAME_MAX)
3253 + err = au_br_init_wh(sb, br, perm);
3255 + pr_err("%pd(%s), unsupported namelen %ld\n",
3257 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3263 +/* initialize a new branch */
3264 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3265 + struct au_opt_add *add)
3268 + struct au_branch *brbase;
3270 + struct inode *h_inode;
3273 + br->br_perm = add->perm;
3274 + br->br_path = add->path; /* set first, path_get() later */
3275 + spin_lock_init(&br->br_dykey_lock);
3276 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3277 + au_lcnt_init(&br->br_count, /*release*/NULL);
3278 + br->br_id = au_new_br_id(sb);
3279 + AuDebugOn(br->br_id < 0);
3281 + /* always, regardless the given option */
3282 + err = au_dr_br_init(sb, br, &add->path);
3283 + if (unlikely(err))
3286 + if (au_br_writable(add->perm)) {
3287 + err = au_wbr_init(br, sb, add->perm);
3288 + if (unlikely(err))
3292 + if (au_opt_test(au_mntflags(sb), XINO)) {
3293 + brbase = au_sbr(sb, 0);
3294 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3296 + h_inode = d_inode(add->path.dentry);
3297 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3298 + if (unlikely(err)) {
3299 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3304 + sysaufs_br_init(br);
3305 + path_get(&br->br_path);
3306 + goto out; /* success */
3309 + memset(&br->br_path, 0, sizeof(br->br_path));
3314 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3315 + struct au_branch *br, aufs_bindex_t bbot,
3316 + aufs_bindex_t amount)
3318 + struct au_branch **brp;
3320 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3322 + brp = sbinfo->si_branch + bindex;
3323 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3325 + sbinfo->si_bbot++;
3326 + if (unlikely(bbot < 0))
3327 + sbinfo->si_bbot = 0;
3330 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3331 + aufs_bindex_t bbot, aufs_bindex_t amount)
3333 + struct au_hdentry *hdp;
3335 + AuRwMustWriteLock(&dinfo->di_rwsem);
3337 + hdp = au_hdentry(dinfo, bindex);
3338 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3339 + au_h_dentry_init(hdp);
3341 + if (unlikely(bbot < 0))
3342 + dinfo->di_btop = 0;
3345 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3346 + aufs_bindex_t bbot, aufs_bindex_t amount)
3348 + struct au_hinode *hip;
3350 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3352 + hip = au_hinode(iinfo, bindex);
3353 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3354 + au_hinode_init(hip);
3356 + if (unlikely(bbot < 0))
3357 + iinfo->ii_btop = 0;
3360 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3361 + aufs_bindex_t bindex)
3363 + struct dentry *root, *h_dentry;
3364 + struct inode *root_inode, *h_inode;
3365 + aufs_bindex_t bbot, amount;
3367 + root = sb->s_root;
3368 + root_inode = d_inode(root);
3369 + bbot = au_sbbot(sb);
3370 + amount = bbot + 1 - bindex;
3371 + h_dentry = au_br_dentry(br);
3372 + au_sbilist_lock();
3373 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3374 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3375 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3376 + au_set_h_dptr(root, bindex, dget(h_dentry));
3377 + h_inode = d_inode(h_dentry);
3378 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3379 + au_sbilist_unlock();
3382 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3385 + aufs_bindex_t bbot, add_bindex;
3386 + struct dentry *root, *h_dentry;
3387 + struct inode *root_inode;
3388 + struct au_branch *add_branch;
3390 + root = sb->s_root;
3391 + root_inode = d_inode(root);
3392 + IMustLock(root_inode);
3393 + IiMustWriteLock(root_inode);
3394 + err = test_add(sb, add, remount);
3395 + if (unlikely(err < 0))
3399 + goto out; /* success */
3402 + bbot = au_sbbot(sb);
3403 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3404 + err = PTR_ERR(add_branch);
3405 + if (IS_ERR(add_branch))
3408 + err = au_br_init(add_branch, sb, add);
3409 + if (unlikely(err)) {
3410 + au_br_do_free(add_branch);
3414 + add_bindex = add->bindex;
3415 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3416 + au_br_do_add(sb, add_branch, add_bindex);
3417 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3418 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3420 + h_dentry = add->path.dentry;
3421 + if (!add_bindex) {
3422 + au_cpup_attr_all(root_inode, /*force*/1);
3423 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3425 + au_add_nlink(root_inode, d_inode(h_dentry));
3431 +/* ---------------------------------------------------------------------- */
3433 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3434 + unsigned long long max __maybe_unused,
3437 + unsigned long long n;
3438 + struct file **p, *f;
3439 + struct hlist_bl_head *files;
3440 + struct hlist_bl_node *pos;
3441 + struct au_finfo *finfo;
3445 + files = &au_sbi(sb)->si_files;
3446 + hlist_bl_lock(files);
3447 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3448 + f = finfo->fi_file;
3450 + && !special_file(file_inode(f)->i_mode)) {
3454 + AuDebugOn(n > max);
3457 + hlist_bl_unlock(files);
3462 +static struct file **au_farray_alloc(struct super_block *sb,
3463 + unsigned long long *max)
3465 + struct au_sbinfo *sbi;
3468 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3469 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3472 +static void au_farray_free(struct file **a, unsigned long long max)
3474 + unsigned long long ull;
3476 + for (ull = 0; ull < max; ull++)
3482 +/* ---------------------------------------------------------------------- */
3488 +/* to show the line number, do not make it inlined function */
3489 +#define AuVerbose(do_info, fmt, ...) do { \
3491 + pr_info(fmt, ##__VA_ARGS__); \
3494 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3495 + aufs_bindex_t bbot)
3497 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3500 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3501 + aufs_bindex_t bbot)
3503 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3507 + * test if the branch is deletable or not.
3509 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3510 + unsigned int sigen, const unsigned int verbose)
3512 + int err, i, j, ndentry;
3513 + aufs_bindex_t btop, bbot;
3514 + struct au_dcsub_pages dpages;
3515 + struct au_dpage *dpage;
3518 + err = au_dpages_init(&dpages, GFP_NOFS);
3519 + if (unlikely(err))
3521 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3522 + if (unlikely(err))
3525 + for (i = 0; !err && i < dpages.ndpage; i++) {
3526 + dpage = dpages.dpages + i;
3527 + ndentry = dpage->ndentry;
3528 + for (j = 0; !err && j < ndentry; j++) {
3529 + d = dpage->dentries[j];
3530 + AuDebugOn(au_dcount(d) <= 0);
3531 + if (!au_digen_test(d, sigen)) {
3532 + di_read_lock_child(d, AuLock_IR);
3533 + if (unlikely(au_dbrange_test(d))) {
3534 + di_read_unlock(d, AuLock_IR);
3538 + di_write_lock_child(d);
3539 + if (unlikely(au_dbrange_test(d))) {
3540 + di_write_unlock(d);
3543 + err = au_reval_dpath(d, sigen);
3545 + di_downgrade_lock(d, AuLock_IR);
3547 + di_write_unlock(d);
3552 + /* AuDbgDentry(d); */
3553 + btop = au_dbtop(d);
3554 + bbot = au_dbbot(d);
3555 + if (btop <= bindex
3557 + && au_h_dptr(d, bindex)
3558 + && au_test_dbusy(d, btop, bbot)) {
3560 + AuVerbose(verbose, "busy %pd\n", d);
3563 + di_read_unlock(d, AuLock_IR);
3568 + au_dpages_free(&dpages);
3573 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3574 + unsigned int sigen, const unsigned int verbose)
3577 + unsigned long long max, ull;
3578 + struct inode *i, **array;
3579 + aufs_bindex_t btop, bbot;
3581 + array = au_iarray_alloc(sb, &max);
3582 + err = PTR_ERR(array);
3583 + if (IS_ERR(array))
3587 + AuDbg("b%d\n", bindex);
3588 + for (ull = 0; !err && ull < max; ull++) {
3592 + if (i->i_ino == AUFS_ROOT_INO)
3595 + /* AuDbgInode(i); */
3596 + if (au_iigen(i, NULL) == sigen)
3597 + ii_read_lock_child(i);
3599 + ii_write_lock_child(i);
3600 + err = au_refresh_hinode_self(i);
3603 + ii_downgrade_lock(i);
3605 + ii_write_unlock(i);
3610 + btop = au_ibtop(i);
3611 + bbot = au_ibbot(i);
3612 + if (btop <= bindex
3614 + && au_h_iptr(i, bindex)
3615 + && au_test_ibusy(i, btop, bbot)) {
3617 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3620 + ii_read_unlock(i);
3622 + au_iarray_free(array, max);
3628 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3629 + const unsigned int verbose)
3632 + unsigned int sigen;
3634 + sigen = au_sigen(root->d_sb);
3635 + DiMustNoWaiters(root);
3636 + IiMustNoWaiters(d_inode(root));
3637 + di_write_unlock(root);
3638 + err = test_dentry_busy(root, bindex, sigen, verbose);
3640 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3641 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3646 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3647 + struct file **to_free, int *idx)
3650 + unsigned char matched, root;
3651 + aufs_bindex_t bindex, bbot;
3652 + struct au_fidir *fidir;
3653 + struct au_hfile *hfile;
3656 + root = IS_ROOT(file->f_path.dentry);
3659 + to_free[*idx] = file;
3665 + fidir = au_fi(file)->fi_hdir;
3666 + AuDebugOn(!fidir);
3667 + bbot = au_fbbot_dir(file);
3668 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3669 + hfile = fidir->fd_hfile + bindex;
3670 + if (!hfile->hf_file)
3673 + if (hfile->hf_br->br_id == br_id) {
3685 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3686 + struct file **to_free, int opened)
3689 + unsigned long long ull, max;
3690 + aufs_bindex_t btop;
3691 + struct file *file, **array;
3692 + struct dentry *root;
3693 + struct au_hfile *hfile;
3695 + array = au_farray_alloc(sb, &max);
3696 + err = PTR_ERR(array);
3697 + if (IS_ERR(array))
3702 + root = sb->s_root;
3703 + di_write_unlock(root);
3704 + for (ull = 0; ull < max; ull++) {
3705 + file = array[ull];
3706 + if (unlikely(!file))
3709 + /* AuDbg("%pD\n", file); */
3710 + fi_read_lock(file);
3711 + btop = au_fbtop(file);
3712 + if (!d_is_dir(file->f_path.dentry)) {
3713 + hfile = &au_fi(file)->fi_htop;
3714 + if (hfile->hf_br->br_id == br_id)
3717 + err = test_dir_busy(file, br_id, to_free, &idx);
3718 + fi_read_unlock(file);
3719 + if (unlikely(err))
3722 + di_write_lock_child(root);
3723 + au_farray_free(array, max);
3724 + AuDebugOn(idx > opened);
3730 +static void br_del_file(struct file **to_free, unsigned long long opened,
3731 + aufs_bindex_t br_id)
3733 + unsigned long long ull;
3734 + aufs_bindex_t bindex, btop, bbot, bfound;
3735 + struct file *file;
3736 + struct au_fidir *fidir;
3737 + struct au_hfile *hfile;
3739 + for (ull = 0; ull < opened; ull++) {
3740 + file = to_free[ull];
3741 + if (unlikely(!file))
3744 + /* AuDbg("%pD\n", file); */
3745 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3747 + fidir = au_fi(file)->fi_hdir;
3748 + AuDebugOn(!fidir);
3749 + fi_write_lock(file);
3750 + btop = au_fbtop(file);
3751 + bbot = au_fbbot_dir(file);
3752 + for (bindex = btop; bindex <= bbot; bindex++) {
3753 + hfile = fidir->fd_hfile + bindex;
3754 + if (!hfile->hf_file)
3757 + if (hfile->hf_br->br_id == br_id) {
3762 + AuDebugOn(bfound < 0);
3763 + au_set_h_fptr(file, bfound, NULL);
3764 + if (bfound == btop) {
3765 + for (btop++; btop <= bbot; btop++)
3766 + if (au_hf_dir(file, btop)) {
3767 + au_set_fbtop(file, btop);
3771 + fi_write_unlock(file);
3775 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3776 + const aufs_bindex_t bindex,
3777 + const aufs_bindex_t bbot)
3779 + struct au_branch **brp, **p;
3781 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3783 + brp = sbinfo->si_branch + bindex;
3784 + if (bindex < bbot)
3785 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3786 + sbinfo->si_branch[0 + bbot] = NULL;
3787 + sbinfo->si_bbot--;
3789 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3792 + sbinfo->si_branch = p;
3793 + /* harmless error */
3796 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3797 + const aufs_bindex_t bbot)
3799 + struct au_hdentry *hdp, *p;
3801 + AuRwMustWriteLock(&dinfo->di_rwsem);
3803 + hdp = au_hdentry(dinfo, bindex);
3804 + if (bindex < bbot)
3805 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3806 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3809 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3812 + dinfo->di_hdentry = p;
3813 + /* harmless error */
3816 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3817 + const aufs_bindex_t bbot)
3819 + struct au_hinode *hip, *p;
3821 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3823 + hip = au_hinode(iinfo, bindex);
3824 + if (bindex < bbot)
3825 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3826 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3829 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3832 + iinfo->ii_hinode = p;
3833 + /* harmless error */
3836 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3837 + struct au_branch *br)
3839 + aufs_bindex_t bbot;
3840 + struct au_sbinfo *sbinfo;
3841 + struct dentry *root, *h_root;
3842 + struct inode *inode, *h_inode;
3843 + struct au_hinode *hinode;
3845 + SiMustWriteLock(sb);
3847 + root = sb->s_root;
3848 + inode = d_inode(root);
3849 + sbinfo = au_sbi(sb);
3850 + bbot = sbinfo->si_bbot;
3852 + h_root = au_h_dptr(root, bindex);
3853 + hinode = au_hi(inode, bindex);
3854 + h_inode = au_igrab(hinode->hi_inode);
3857 + au_sbilist_lock();
3858 + au_br_do_del_brp(sbinfo, bindex, bbot);
3859 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3860 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3861 + au_sbilist_unlock();
3863 + /* ignore an error */
3864 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3868 + au_br_do_free(br);
3871 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3872 + unsigned long long max, void *arg)
3877 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3880 + unsigned long long opened;
3881 + unsigned int mnt_flags;
3882 + aufs_bindex_t bindex, bbot, br_id;
3883 + unsigned char do_wh, verbose;
3884 + struct au_branch *br;
3885 + struct au_wbr *wbr;
3886 + struct dentry *root;
3887 + struct file **to_free;
3892 + root = sb->s_root;
3893 + bindex = au_find_dbindex(root, del->h_path.dentry);
3896 + goto out; /* success */
3898 + pr_err("%s no such branch\n", del->pathname);
3901 + AuDbg("bindex b%d\n", bindex);
3904 + mnt_flags = au_mntflags(sb);
3905 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3906 + bbot = au_sbbot(sb);
3907 + if (unlikely(!bbot)) {
3908 + AuVerbose(verbose, "no more branches left\n");
3912 + br = au_sbr(sb, bindex);
3913 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3914 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3915 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3919 + br_id = br->br_id;
3920 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3921 + if (unlikely(opened)) {
3922 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3923 + err = PTR_ERR(to_free);
3924 + if (IS_ERR(to_free))
3927 + err = test_file_busy(sb, br_id, to_free, opened);
3928 + if (unlikely(err)) {
3929 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3935 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3937 + /* instead of WbrWhMustWriteLock(wbr) */
3938 + SiMustWriteLock(sb);
3939 + for (i = 0; i < AuBrWh_Last; i++) {
3940 + dput(wbr->wbr_wh[i]);
3941 + wbr->wbr_wh[i] = NULL;
3945 + err = test_children_busy(root, bindex, verbose);
3946 + if (unlikely(err)) {
3955 + * now we confirmed the branch is deletable.
3956 + * let's free the remaining opened dirs on the branch.
3958 + di_write_unlock(root);
3959 + br_del_file(to_free, opened, br_id);
3960 + di_write_lock_child(root);
3963 + sysaufs_brs_del(sb, bindex); /* remove successors */
3964 + dbgaufs_xino_del(br); /* remove one */
3965 + au_br_do_del(sb, bindex, br);
3966 + sysaufs_brs_add(sb, bindex); /* append successors */
3967 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3970 + au_cpup_attr_all(d_inode(root), /*force*/1);
3971 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3973 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3974 + if (au_opt_test(mnt_flags, PLINK))
3975 + au_plink_half_refresh(sb, br_id);
3977 + goto out; /* success */
3981 + rerr = au_br_init_wh(sb, br, br->br_perm);
3983 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3984 + del->pathname, rerr);
3987 + au_farray_free(to_free, opened);
3991 +/* ---------------------------------------------------------------------- */
3993 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3996 + aufs_bindex_t btop, bbot;
3997 + struct aufs_ibusy ibusy;
3998 + struct inode *inode, *h_inode;
4001 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4004 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4006 + /* VERIFY_WRITE */
4007 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4008 + if (unlikely(err)) {
4015 + si_read_lock(sb, AuLock_FLUSH);
4016 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4020 + ibusy.h_ino = 0; /* invalid */
4021 + inode = ilookup(sb, ibusy.ino);
4023 + || inode->i_ino == AUFS_ROOT_INO
4024 + || au_is_bad_inode(inode))
4027 + ii_read_lock_child(inode);
4028 + btop = au_ibtop(inode);
4029 + bbot = au_ibbot(inode);
4030 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4031 + h_inode = au_h_iptr(inode, ibusy.bindex);
4032 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4033 + ibusy.h_ino = h_inode->i_ino;
4035 + ii_read_unlock(inode);
4039 + si_read_unlock(sb);
4041 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4042 + if (unlikely(err)) {
4051 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4053 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4056 +#ifdef CONFIG_COMPAT
4057 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4059 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4063 +/* ---------------------------------------------------------------------- */
4066 + * change a branch permission
4069 +static void au_warn_ima(void)
4072 + /* since it doesn't support mark_files_ro() */
4073 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4077 +static int do_need_sigen_inc(int a, int b)
4079 + return au_br_whable(a) && !au_br_whable(b);
4082 +static int need_sigen_inc(int old, int new)
4084 + return do_need_sigen_inc(old, new)
4085 + || do_need_sigen_inc(new, old);
4088 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4091 + unsigned int mnt_flags;
4092 + unsigned long long ull, max;
4093 + aufs_bindex_t br_id;
4094 + unsigned char verbose, writer;
4095 + struct file *file, *hf, **array;
4096 + struct au_hfile *hfile;
4097 + struct inode *h_inode;
4099 + mnt_flags = au_mntflags(sb);
4100 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4102 + array = au_farray_alloc(sb, &max);
4103 + err = PTR_ERR(array);
4104 + if (IS_ERR(array))
4108 + br_id = au_sbr_id(sb, bindex);
4109 + for (ull = 0; ull < max; ull++) {
4110 + file = array[ull];
4111 + if (unlikely(!file))
4114 + /* AuDbg("%pD\n", file); */
4115 + fi_read_lock(file);
4116 + if (unlikely(au_test_mmapped(file))) {
4118 + AuVerbose(verbose, "mmapped %pD\n", file);
4120 + FiMustNoWaiters(file);
4121 + fi_read_unlock(file);
4125 + hfile = &au_fi(file)->fi_htop;
4126 + hf = hfile->hf_file;
4127 + if (!d_is_reg(file->f_path.dentry)
4128 + || !(file->f_mode & FMODE_WRITE)
4129 + || hfile->hf_br->br_id != br_id
4130 + || !(hf->f_mode & FMODE_WRITE))
4131 + array[ull] = NULL;
4137 + FiMustNoWaiters(file);
4138 + fi_read_unlock(file);
4146 + for (ull = 0; ull < max; ull++) {
4147 + file = array[ull];
4151 + /* todo: already flushed? */
4153 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4154 + * approach which resets f_mode and calls mnt_drop_write() and
4155 + * file_release_write() for each file, because the branch
4156 + * attribute in aufs world is totally different from the native
4159 + /* fi_read_lock(file); */
4160 + hfile = &au_fi(file)->fi_htop;
4161 + hf = hfile->hf_file;
4162 + /* fi_read_unlock(file); */
4163 + spin_lock(&hf->f_lock);
4164 + writer = !!(hf->f_mode & FMODE_WRITER);
4165 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4166 + spin_unlock(&hf->f_lock);
4168 + h_inode = file_inode(hf);
4169 + if (hf->f_mode & FMODE_READ)
4170 + i_readcount_inc(h_inode);
4171 + put_write_access(h_inode);
4172 + __mnt_drop_write(hf->f_path.mnt);
4177 + au_farray_free(array, max);
4183 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4187 + aufs_bindex_t bindex;
4188 + struct dentry *root;
4189 + struct au_branch *br;
4190 + struct au_br_fhsm *bf;
4192 + root = sb->s_root;
4193 + bindex = au_find_dbindex(root, mod->h_root);
4196 + return 0; /* success */
4198 + pr_err("%s no such branch\n", mod->path);
4201 + AuDbg("bindex b%d\n", bindex);
4203 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4204 + if (unlikely(err))
4207 + br = au_sbr(sb, bindex);
4208 + AuDebugOn(mod->h_root != au_br_dentry(br));
4209 + if (br->br_perm == mod->perm)
4210 + return 0; /* success */
4212 + /* pre-allocate for non-fhsm --> fhsm */
4214 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4215 + err = au_fhsm_br_alloc(br);
4216 + if (unlikely(err))
4219 + br->br_fhsm = NULL;
4222 + if (au_br_writable(br->br_perm)) {
4223 + /* remove whiteout base */
4224 + err = au_br_init_wh(sb, br, mod->perm);
4225 + if (unlikely(err))
4228 + if (!au_br_writable(mod->perm)) {
4229 + /* rw --> ro, file might be mmapped */
4230 + DiMustNoWaiters(root);
4231 + IiMustNoWaiters(d_inode(root));
4232 + di_write_unlock(root);
4233 + err = au_br_mod_files_ro(sb, bindex);
4234 + /* aufs_write_lock() calls ..._child() */
4235 + di_write_lock_child(root);
4237 + if (unlikely(err)) {
4239 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4242 + rerr = au_wbr_init(br, sb, br->br_perm);
4243 + if (unlikely(rerr)) {
4244 + AuIOErr("nested error %d (%d)\n",
4246 + br->br_perm = mod->perm;
4250 + } else if (au_br_writable(mod->perm)) {
4253 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4255 + err = au_wbr_init(br, sb, mod->perm);
4256 + if (unlikely(err)) {
4257 + au_kfree_rcu(br->br_wbr);
4258 + br->br_wbr = NULL;
4262 + if (unlikely(err))
4265 + if (au_br_fhsm(br->br_perm)) {
4266 + if (!au_br_fhsm(mod->perm)) {
4267 + /* fhsm --> non-fhsm */
4268 + au_br_fhsm_fin(br->br_fhsm);
4269 + au_kfree_rcu(br->br_fhsm);
4270 + br->br_fhsm = NULL;
4272 + } else if (au_br_fhsm(mod->perm))
4273 + /* non-fhsm --> fhsm */
4276 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4277 + br->br_perm = mod->perm;
4278 + goto out; /* success */
4281 + au_kfree_try_rcu(bf);
4287 +/* ---------------------------------------------------------------------- */
4289 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4292 + struct kstatfs kstfs;
4294 + err = vfs_statfs(&br->br_path, &kstfs);
4296 + stfs->f_blocks = kstfs.f_blocks;
4297 + stfs->f_bavail = kstfs.f_bavail;
4298 + stfs->f_files = kstfs.f_files;
4299 + stfs->f_ffree = kstfs.f_ffree;
4304 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4305 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4306 +++ linux/fs/aufs/branch.h 2021-12-03 15:38:59.933313976 +0100
4308 +/* SPDX-License-Identifier: GPL-2.0 */
4310 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4312 + * This program, aufs is free software; you can redistribute it and/or modify
4313 + * it under the terms of the GNU General Public License as published by
4314 + * the Free Software Foundation; either version 2 of the License, or
4315 + * (at your option) any later version.
4317 + * This program is distributed in the hope that it will be useful,
4318 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4319 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4320 + * GNU General Public License for more details.
4322 + * You should have received a copy of the GNU General Public License
4323 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4327 + * branch filesystems and xino for them
4330 +#ifndef __AUFS_BRANCH_H__
4331 +#define __AUFS_BRANCH_H__
4335 +#include <linux/mount.h>
4336 +#include "dirren.h"
4342 +/* ---------------------------------------------------------------------- */
4346 + struct file **xi_file;
4347 + unsigned int xi_nfile;
4353 + /* reserved for future use */
4354 + /* unsigned long *bitmap; */
4355 + wait_queue_head_t wqh;
4358 + struct mutex xi_mtx; /* protects xi_file array */
4359 + struct hlist_bl_head xi_writing;
4361 + atomic_t xi_truncating;
4363 + struct kref xi_kref;
4366 +/* File-based Hierarchical Storage Management */
4367 +struct au_br_fhsm {
4368 +#ifdef CONFIG_AUFS_FHSM
4369 + struct mutex bf_lock;
4370 + unsigned long bf_jiffy;
4371 + struct aufs_stfs bf_stfs;
4376 +/* members for writable branch only */
4377 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4379 + struct au_rwsem wbr_wh_rwsem;
4380 + struct dentry *wbr_wh[AuBrWh_Last];
4381 + atomic_t wbr_wh_running;
4382 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4383 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4384 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4387 + unsigned long long wbr_bytes;
4390 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4391 +#define AuBrDynOp (AuDyLast * 4)
4393 +#ifdef CONFIG_AUFS_HFSNOTIFY
4394 +/* support for asynchronous destruction */
4395 +struct au_br_hfsnotify {
4396 + struct fsnotify_group *hfsn_group;
4400 +/* sysfs entries */
4401 +struct au_brsysfs {
4403 + struct attribute attr;
4412 +/* protected by superblock rwsem */
4414 + struct au_xino *br_xino;
4416 + aufs_bindex_t br_id;
4419 + struct path br_path;
4420 + spinlock_t br_dykey_lock;
4421 + struct au_dykey *br_dykey[AuBrDynOp];
4422 + au_lcnt_t br_nfiles; /* opened files */
4423 + au_lcnt_t br_count; /* in-use for other */
4425 + struct au_wbr *br_wbr;
4426 + struct au_br_fhsm *br_fhsm;
4428 +#ifdef CONFIG_AUFS_HFSNOTIFY
4429 + struct au_br_hfsnotify *br_hfsn;
4432 +#ifdef CONFIG_SYSFS
4433 + /* entries under sysfs per mount-point */
4434 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4437 +#ifdef CONFIG_DEBUG_FS
4438 + struct dentry *br_dbgaufs; /* xino */
4441 + struct au_dr_br br_dirren;
4444 +/* ---------------------------------------------------------------------- */
4446 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4448 + return br->br_path.mnt;
4451 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4453 + return br->br_path.dentry;
4456 +static inline struct super_block *au_br_sb(struct au_branch *br)
4458 + return au_br_mnt(br)->mnt_sb;
4461 +static inline int au_br_rdonly(struct au_branch *br)
4463 + return (sb_rdonly(au_br_sb(br))
4464 + || !au_br_writable(br->br_perm))
4468 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4470 +#ifdef CONFIG_AUFS_HNOTIFY
4471 + return !(brperm & AuBrPerm_RR);
4477 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4479 + int err, exec_flag;
4482 + exec_flag = oflag & __FMODE_EXEC;
4483 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4489 +static inline void au_xino_get(struct au_branch *br)
4491 + struct au_xino *xi;
4495 + kref_get(&xi->xi_kref);
4498 +static inline int au_xino_count(struct au_branch *br)
4501 + struct au_xino *xi;
4506 + v = kref_read(&xi->xi_kref);
4511 +/* ---------------------------------------------------------------------- */
4515 +void au_br_free(struct au_sbinfo *sinfo);
4516 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4518 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4520 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4521 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4522 +#ifdef CONFIG_COMPAT
4523 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4526 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4529 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4532 +static const loff_t au_loff_max = LLONG_MAX;
4534 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4535 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4537 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4538 + struct file *copy_src);
4540 + struct au_xino *xi; /* switch between xino and xigen */
4542 + struct path *base;
4543 + struct file *copy_src;
4545 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4547 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4549 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4551 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4552 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4554 +int au_xib_trunc(struct super_block *sb);
4555 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4557 +struct au_xino *au_xino_alloc(unsigned int nfile);
4558 +int au_xino_put(struct au_branch *br);
4559 +struct file *au_xino_file1(struct au_xino *xi);
4561 +struct au_opt_xino;
4562 +void au_xino_clr(struct super_block *sb);
4563 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4564 +struct file *au_xino_def(struct super_block *sb);
4565 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4566 + struct path *base);
4568 +ino_t au_xino_new_ino(struct super_block *sb);
4569 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4571 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4572 + ino_t h_ino, int idx);
4573 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4576 +int au_xino_path(struct seq_file *seq, struct file *file);
4578 +/* ---------------------------------------------------------------------- */
4580 +/* @idx is signed to accept -1 meaning the first file */
4581 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4583 + struct file *file;
4590 + if (idx < xi->xi_nfile)
4591 + file = xi->xi_file[idx];
4593 + file = au_xino_file1(xi);
4599 +/* ---------------------------------------------------------------------- */
4601 +/* Superblock to branch */
4603 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4605 + return au_sbr(sb, bindex)->br_id;
4609 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4611 + return au_br_mnt(au_sbr(sb, bindex));
4615 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4617 + return au_br_sb(au_sbr(sb, bindex));
4620 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4622 + return au_sbr(sb, bindex)->br_perm;
4625 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4627 + return au_br_whable(au_sbr_perm(sb, bindex));
4630 +/* ---------------------------------------------------------------------- */
4632 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4633 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4634 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4635 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4637 +#define wbr_wh_read_trylock_nested(wbr) \
4638 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4639 +#define wbr_wh_write_trylock_nested(wbr) \
4640 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4643 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4644 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4645 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4647 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4648 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4649 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4651 +/* ---------------------------------------------------------------------- */
4653 +#ifdef CONFIG_AUFS_FHSM
4654 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4656 + mutex_init(&brfhsm->bf_lock);
4657 + brfhsm->bf_jiffy = 0;
4658 + brfhsm->bf_readable = 0;
4661 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4663 + mutex_destroy(&brfhsm->bf_lock);
4666 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4667 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4670 +#endif /* __KERNEL__ */
4671 +#endif /* __AUFS_BRANCH_H__ */
4672 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4673 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4674 +++ linux/fs/aufs/conf.mk 2021-12-03 15:38:59.933313976 +0100
4676 +# SPDX-License-Identifier: GPL-2.0
4678 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4682 +AuConfStr += ${1}=${${1}}
4686 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4688 + HNOTIFY HFSNOTIFY \
4700 +$(foreach i, ${AuConfAll}, \
4701 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4703 +AuConfName = ${obj}/conf.str
4704 +${AuConfName}.tmp: FORCE
4705 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4706 +${AuConfName}: ${AuConfName}.tmp
4707 + @diff -q $< $@ > /dev/null 2>&1 || { \
4708 + echo ' GEN ' $@; \
4712 +clean-files += ${AuConfName} ${AuConfName}.tmp
4713 +${obj}/sysfs.o: ${AuConfName}
4715 +-include ${srctree}/${src}/conf_priv.mk
4716 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4717 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4718 +++ linux/fs/aufs/cpup.c 2021-12-03 15:38:59.933313976 +0100
4720 +// SPDX-License-Identifier: GPL-2.0
4722 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4724 + * This program, aufs is free software; you can redistribute it and/or modify
4725 + * it under the terms of the GNU General Public License as published by
4726 + * the Free Software Foundation; either version 2 of the License, or
4727 + * (at your option) any later version.
4729 + * This program is distributed in the hope that it will be useful,
4730 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4731 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4732 + * GNU General Public License for more details.
4734 + * You should have received a copy of the GNU General Public License
4735 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4739 + * copy-up functions, see wbr_policy.c for copy-down
4742 +#include <linux/fs_stack.h>
4743 +#include <linux/mm.h>
4744 +#include <linux/task_work.h>
4747 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4749 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4750 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4752 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4754 + dst->i_flags |= iflags & ~mask;
4755 + if (au_test_fs_notime(dst->i_sb))
4756 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4759 +void au_cpup_attr_timesizes(struct inode *inode)
4761 + struct inode *h_inode;
4763 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4764 + fsstack_copy_attr_times(inode, h_inode);
4765 + fsstack_copy_inode_size(inode, h_inode);
4768 +void au_cpup_attr_nlink(struct inode *inode, int force)
4770 + struct inode *h_inode;
4771 + struct super_block *sb;
4772 + aufs_bindex_t bindex, bbot;
4775 + bindex = au_ibtop(inode);
4776 + h_inode = au_h_iptr(inode, bindex);
4778 + && !S_ISDIR(h_inode->i_mode)
4779 + && au_opt_test(au_mntflags(sb), PLINK)
4780 + && au_plink_test(inode))
4784 + * 0 can happen in revalidating.
4785 + * h_inode->i_mutex may not be held here, but it is harmless since once
4786 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4788 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4789 + * the incorrect link count.
4791 + set_nlink(inode, h_inode->i_nlink);
4794 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4795 + * it may includes whplink directory.
4797 + if (S_ISDIR(h_inode->i_mode)) {
4798 + bbot = au_ibbot(inode);
4799 + for (bindex++; bindex <= bbot; bindex++) {
4800 + h_inode = au_h_iptr(inode, bindex);
4802 + au_add_nlink(inode, h_inode);
4807 +void au_cpup_attr_changeable(struct inode *inode)
4809 + struct inode *h_inode;
4811 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4812 + inode->i_mode = h_inode->i_mode;
4813 + inode->i_uid = h_inode->i_uid;
4814 + inode->i_gid = h_inode->i_gid;
4815 + au_cpup_attr_timesizes(inode);
4816 + au_cpup_attr_flags(inode, h_inode->i_flags);
4819 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4821 + struct au_iinfo *iinfo = au_ii(inode);
4823 + IiMustWriteLock(inode);
4825 + iinfo->ii_higen = h_inode->i_generation;
4826 + iinfo->ii_hsb1 = h_inode->i_sb;
4829 +void au_cpup_attr_all(struct inode *inode, int force)
4831 + struct inode *h_inode;
4833 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4834 + au_cpup_attr_changeable(inode);
4835 + if (inode->i_nlink > 0)
4836 + au_cpup_attr_nlink(inode, force);
4837 + inode->i_rdev = h_inode->i_rdev;
4838 + inode->i_blkbits = h_inode->i_blkbits;
4839 + au_cpup_igen(inode, h_inode);
4842 +/* ---------------------------------------------------------------------- */
4844 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4846 +/* keep the timestamps of the parent dir when cpup */
4847 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4848 + struct path *h_path)
4850 + struct inode *h_inode;
4852 + dt->dt_dentry = dentry;
4853 + dt->dt_h_path = *h_path;
4854 + h_inode = d_inode(h_path->dentry);
4855 + dt->dt_atime = h_inode->i_atime;
4856 + dt->dt_mtime = h_inode->i_mtime;
4860 +void au_dtime_revert(struct au_dtime *dt)
4862 + struct iattr attr;
4865 + attr.ia_atime = dt->dt_atime;
4866 + attr.ia_mtime = dt->dt_mtime;
4867 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4868 + | ATTR_ATIME | ATTR_ATIME_SET;
4870 + /* no delegation since this is a directory */
4871 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4872 + if (unlikely(err))
4873 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4876 +/* ---------------------------------------------------------------------- */
4878 +/* internal use only */
4879 +struct au_cpup_reg_attr {
4882 + unsigned int iflags; /* inode->i_flags */
4885 +static noinline_for_stack
4886 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4887 + struct au_cpup_reg_attr *h_src_attr)
4889 + int err, sbits, icex;
4890 + unsigned int mnt_flags;
4891 + unsigned char verbose;
4893 + struct path h_path;
4894 + struct inode *h_isrc, *h_idst;
4895 + struct kstat *h_st;
4896 + struct au_branch *br;
4898 + h_path.dentry = au_h_dptr(dst, bindex);
4899 + h_idst = d_inode(h_path.dentry);
4900 + br = au_sbr(dst->d_sb, bindex);
4901 + h_path.mnt = au_br_mnt(br);
4902 + h_isrc = d_inode(h_src);
4903 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4904 + | ATTR_ATIME | ATTR_MTIME
4905 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4906 + if (h_src_attr && h_src_attr->valid) {
4907 + h_st = &h_src_attr->st;
4908 + ia.ia_uid = h_st->uid;
4909 + ia.ia_gid = h_st->gid;
4910 + ia.ia_atime = h_st->atime;
4911 + ia.ia_mtime = h_st->mtime;
4912 + if (h_idst->i_mode != h_st->mode
4913 + && !S_ISLNK(h_idst->i_mode)) {
4914 + ia.ia_valid |= ATTR_MODE;
4915 + ia.ia_mode = h_st->mode;
4917 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4918 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4920 + ia.ia_uid = h_isrc->i_uid;
4921 + ia.ia_gid = h_isrc->i_gid;
4922 + ia.ia_atime = h_isrc->i_atime;
4923 + ia.ia_mtime = h_isrc->i_mtime;
4924 + if (h_idst->i_mode != h_isrc->i_mode
4925 + && !S_ISLNK(h_idst->i_mode)) {
4926 + ia.ia_valid |= ATTR_MODE;
4927 + ia.ia_mode = h_isrc->i_mode;
4929 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4930 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4932 + /* no delegation since it is just created */
4933 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4935 + /* is this nfs only? */
4936 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4937 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4938 + ia.ia_mode = h_isrc->i_mode;
4939 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4942 + icex = br->br_perm & AuBrAttr_ICEX;
4944 + mnt_flags = au_mntflags(dst->d_sb);
4945 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4946 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4952 +/* ---------------------------------------------------------------------- */
4954 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4955 + char *buf, unsigned long blksize)
4958 + size_t sz, rbytes, wbytes;
4959 + unsigned char all_zero;
4961 + struct inode *h_inode;
4962 + /* reduce stack usage */
4965 + zp = page_address(ZERO_PAGE(0));
4966 + if (unlikely(!zp))
4967 + return -ENOMEM; /* possible? */
4972 + AuDbg("len %lld\n", len);
4974 + if (len < blksize)
4978 + /* todo: signal_pending? */
4979 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4980 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4983 + if (unlikely(err < 0))
4987 + if (len >= rbytes && rbytes == blksize)
4988 + all_zero = !memcmp(buf, zp, rbytes);
4995 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4997 + /* todo: signal_pending? */
4998 + if (unlikely(err == -EAGAIN || err == -EINTR))
5000 + if (unlikely(err < 0))
5005 + if (unlikely(err < 0))
5011 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5013 + if (unlikely(res < 0))
5020 + /* the last block may be a hole */
5021 + if (!err && all_zero) {
5022 + AuLabel(last hole);
5025 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5026 + /* nfs requires this step to make last hole */
5027 + /* is this only nfs? */
5029 + /* todo: signal_pending? */
5030 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5031 + } while (err == -EAGAIN || err == -EINTR);
5038 + ia->ia_size = dst->f_pos;
5039 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5040 + ia->ia_file = dst;
5041 + h_inode = file_inode(dst);
5042 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5043 + /* no delegation since it is just created */
5044 + err = vfsub_notify_change(&dst->f_path, ia,
5045 + /*delegated*/NULL);
5046 + inode_unlock(h_inode);
5053 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5056 + unsigned long blksize;
5057 + unsigned char do_kfree;
5059 + struct super_block *h_sb;
5062 + h_sb = file_inode(dst)->i_sb;
5063 + blksize = h_sb->s_blocksize;
5064 + if (!blksize || PAGE_SIZE < blksize)
5065 + blksize = PAGE_SIZE;
5066 + AuDbg("blksize %lu\n", blksize);
5067 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5069 + buf = kmalloc(blksize, GFP_NOFS);
5071 + buf = (void *)__get_free_page(GFP_NOFS);
5072 + if (unlikely(!buf))
5075 + if (len > (1 << 22))
5076 + AuDbg("copying a large file %lld\n", (long long)len);
5080 + err = au_do_copy_file(dst, src, len, buf, blksize);
5082 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5083 + au_kfree_do_rcu(buf);
5085 + free_page((unsigned long)buf);
5091 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5094 + struct super_block *h_src_sb;
5095 + struct inode *h_src_inode;
5097 + h_src_inode = file_inode(src);
5098 + h_src_sb = h_src_inode->i_sb;
5100 + /* XFS acquires inode_lock */
5101 + if (!au_test_xfs(h_src_sb))
5102 + err = au_copy_file(dst, src, len);
5104 + inode_unlock_shared(h_src_inode);
5105 + err = au_copy_file(dst, src, len);
5106 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5112 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5116 + struct super_block *h_src_sb;
5117 + struct inode *h_src_inode;
5119 + h_src_inode = file_inode(src);
5120 + h_src_sb = h_src_inode->i_sb;
5121 + if (h_src_sb != file_inode(dst)->i_sb
5122 + || !dst->f_op->remap_file_range) {
5123 + err = au_do_copy(dst, src, len);
5127 + if (!au_test_nfs(h_src_sb)) {
5128 + inode_unlock_shared(h_src_inode);
5129 + lo = vfsub_clone_file_range(src, dst, len);
5130 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5132 + lo = vfsub_clone_file_range(src, dst, len);
5135 + goto out; /* success */
5136 + } else if (lo >= 0)
5137 + /* todo: possible? */
5138 + /* paritially succeeded */
5139 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5140 + else if (lo != -EOPNOTSUPP) {
5141 + /* older XFS has a condition in cloning */
5146 + /* the backend fs on NFS may not support cloning */
5147 + err = au_do_copy(dst, src, len);
5155 + * to support a sparse file which is opened with O_APPEND,
5156 + * we need to close the file.
5158 +static int au_cp_regular(struct au_cp_generic *cpg)
5161 + enum { SRC, DST };
5163 + aufs_bindex_t bindex;
5164 + unsigned int flags;
5165 + struct dentry *dentry;
5167 + struct file *file;
5170 + .bindex = cpg->bsrc,
5171 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5174 + .bindex = cpg->bdst,
5175 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5176 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5179 + struct au_branch *br;
5180 + struct super_block *sb, *h_src_sb;
5181 + struct inode *h_src_inode;
5182 + struct task_struct *tsk = current;
5184 + /* bsrc branch can be ro/rw. */
5185 + sb = cpg->dentry->d_sb;
5187 + for (i = 0; i < 2; i++, f++) {
5188 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5189 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5190 + /*file*/NULL, f->force_wr);
5191 + if (IS_ERR(f->file)) {
5192 + err = PTR_ERR(f->file);
5200 + /* try stopping to update while we copyup */
5201 + h_src_inode = d_inode(file[SRC].dentry);
5202 + h_src_sb = h_src_inode->i_sb;
5203 + if (!au_test_nfs(h_src_sb))
5204 + IMustLock(h_src_inode);
5205 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5207 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5208 + if (tsk->flags & PF_KTHREAD)
5209 + __fput_sync(file[DST].file);
5211 + /* it happened actually */
5212 + fput(file[DST].file);
5215 + * we have to call both since we don't know which place the file
5219 + flush_delayed_fput();
5221 + br = au_sbr(sb, file[DST].bindex);
5222 + au_lcnt_dec(&br->br_nfiles);
5225 + fput(file[SRC].file);
5226 + br = au_sbr(sb, file[SRC].bindex);
5227 + au_lcnt_dec(&br->br_nfiles);
5232 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5233 + struct au_cpup_reg_attr *h_src_attr)
5237 + struct path h_path;
5238 + struct inode *h_src_inode, *h_dst_inode;
5241 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5242 + l = i_size_read(h_src_inode);
5243 + if (cpg->len == -1 || l < cpg->len)
5246 + /* try stopping to update while we are referencing */
5247 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5248 + au_pin_hdir_unlock(cpg->pin);
5250 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5251 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5252 + h_src_attr->iflags = h_src_inode->i_flags;
5253 + if (!au_test_nfs(h_src_inode->i_sb))
5254 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5256 + inode_unlock_shared(h_src_inode);
5257 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5258 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5260 + if (unlikely(err)) {
5261 + inode_unlock_shared(h_src_inode);
5264 + h_src_attr->valid = 1;
5265 + if (!au_test_nfs(h_src_inode->i_sb)) {
5266 + err = au_cp_regular(cpg);
5267 + inode_unlock_shared(h_src_inode);
5269 + inode_unlock_shared(h_src_inode);
5270 + err = au_cp_regular(cpg);
5272 + rerr = au_pin_hdir_relock(cpg->pin);
5276 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5277 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5278 + h_dst_inode = d_inode(h_path.dentry);
5279 + spin_lock(&h_dst_inode->i_lock);
5280 + h_dst_inode->i_state |= I_LINKABLE;
5281 + spin_unlock(&h_dst_inode->i_lock);
5288 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5289 + struct inode *h_dir)
5292 + DEFINE_DELAYED_CALL(done);
5295 + sym = vfs_get_link(h_src, &done);
5296 + err = PTR_ERR(sym);
5300 + err = vfsub_symlink(h_dir, h_path, sym);
5303 + do_delayed_call(&done);
5308 + * regardless 'acl' option, reset all ACL.
5309 + * All ACL will be copied up later from the original entry on the lower branch.
5311 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5314 + struct dentry *h_dentry;
5315 + struct inode *h_inode;
5317 + h_dentry = h_path->dentry;
5318 + h_inode = d_inode(h_dentry);
5319 + /* forget_all_cached_acls(h_inode)); */
5320 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5322 + if (err == -EOPNOTSUPP)
5325 + err = vfsub_acl_chmod(h_inode, mode);
5331 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5332 + struct inode *h_dir, struct path *h_path)
5335 + struct inode *dir, *inode;
5337 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5339 + if (err == -EOPNOTSUPP)
5341 + if (unlikely(err))
5345 + * strange behaviour from the users view,
5346 + * particularly setattr case
5348 + dir = d_inode(dst_parent);
5349 + if (au_ibtop(dir) == cpg->bdst)
5350 + au_cpup_attr_nlink(dir, /*force*/1);
5351 + inode = d_inode(cpg->dentry);
5352 + au_cpup_attr_nlink(inode, /*force*/1);
5358 +static noinline_for_stack
5359 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5360 + struct au_cpup_reg_attr *h_src_attr)
5364 + unsigned int mnt_flags;
5365 + unsigned char isdir, isreg, force;
5366 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5367 + struct au_dtime dt;
5368 + struct path h_path;
5369 + struct dentry *h_src, *h_dst, *h_parent;
5370 + struct inode *h_inode, *h_dir;
5371 + struct super_block *sb;
5373 + /* bsrc branch can be ro/rw. */
5374 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5375 + h_inode = d_inode(h_src);
5376 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5378 + /* try stopping to be referenced while we are creating */
5379 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5380 + if (au_ftest_cpup(cpg->flags, RENAME))
5381 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5382 + AUFS_WH_PFX_LEN));
5383 + h_parent = h_dst->d_parent; /* dir inode is locked */
5384 + h_dir = d_inode(h_parent);
5386 + AuDebugOn(h_parent != h_dst->d_parent);
5388 + sb = cpg->dentry->d_sb;
5389 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5391 + h_path.dentry = h_parent;
5392 + au_dtime_store(&dt, dst_parent, &h_path);
5394 + h_path.dentry = h_dst;
5398 + mode = h_inode->i_mode;
5399 + switch (mode & S_IFMT) {
5402 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5404 + err = au_do_cpup_regular(cpg, h_src_attr);
5408 + err = vfsub_mkdir(h_dir, &h_path, mode);
5410 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5413 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5417 + AuDebugOn(!capable(CAP_MKNOD));
5421 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5424 + AuIOErr("Unknown inode type 0%o\n", mode);
5428 + err = au_reset_acl(h_dir, &h_path, mode);
5430 + mnt_flags = au_mntflags(sb);
5431 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5433 + && au_opt_test(mnt_flags, XINO)
5434 + && (h_inode->i_nlink == 1
5435 + || (h_inode->i_state & I_LINKABLE))
5436 + /* todo: unnecessary? */
5437 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5438 + && cpg->bdst < cpg->bsrc
5439 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5440 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5441 + /* ignore this error */
5446 + force = !!cpg->len;
5447 + if (cpg->len == -1)
5448 + force = !!i_size_read(h_inode);
5450 + au_fhsm_wrote(sb, cpg->bdst, force);
5454 + au_dtime_revert(&dt);
5458 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5461 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5462 + struct path h_ppath;
5463 + struct inode *h_dir;
5464 + aufs_bindex_t bdst;
5466 + dentry = cpg->dentry;
5468 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5469 + h_dentry = au_h_dptr(dentry, bdst);
5470 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5472 + au_set_h_dptr(dentry, bdst, NULL);
5473 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5475 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5476 + au_set_h_dptr(dentry, bdst, h_dentry);
5479 + parent = dget_parent(dentry);
5480 + h_ppath.dentry = au_h_dptr(parent, bdst);
5482 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5483 + if (IS_ERR(h_path->dentry))
5484 + err = PTR_ERR(h_path->dentry);
5486 + if (unlikely(err))
5489 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5490 + h_dir = d_inode(h_parent);
5492 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5493 + /* no delegation since it is just created */
5494 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5496 + dput(h_path->dentry);
5503 + * copyup the @dentry from @bsrc to @bdst.
5504 + * the caller must set the both of lower dentries.
5505 + * @len is for truncating when it is -1 copyup the entire file.
5506 + * in link/rename cases, @dst_parent may be different from the real one.
5507 + * basic->bsrc can be larger than basic->bdst.
5508 + * aufs doesn't touch the credential so
5509 + * security_inode_copy_up{,_xattr}() are unnecessary.
5511 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5514 + aufs_bindex_t old_ibtop;
5515 + unsigned char isdir, plink;
5516 + struct dentry *h_src, *h_dst, *h_parent;
5517 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5518 + struct super_block *sb;
5519 + struct au_branch *br;
5520 + /* to reduce stack size */
5522 + struct au_dtime dt;
5523 + struct path h_path;
5524 + struct au_cpup_reg_attr h_src_attr;
5528 + a = kmalloc(sizeof(*a), GFP_NOFS);
5531 + a->h_src_attr.valid = 0;
5533 + sb = cpg->dentry->d_sb;
5534 + br = au_sbr(sb, cpg->bdst);
5535 + a->h_path.mnt = au_br_mnt(br);
5536 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5537 + h_parent = h_dst->d_parent; /* dir inode is locked */
5538 + h_dir = d_inode(h_parent);
5541 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5542 + inode = d_inode(cpg->dentry);
5545 + dst_parent = dget_parent(cpg->dentry);
5549 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5550 + dst_inode = au_h_iptr(inode, cpg->bdst);
5552 + if (unlikely(!plink)) {
5554 + AuIOErr("hi%lu(i%lu) exists on b%d "
5555 + "but plink is disabled\n",
5556 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5560 + if (dst_inode->i_nlink) {
5561 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5563 + h_src = au_plink_lkup(inode, cpg->bdst);
5564 + err = PTR_ERR(h_src);
5565 + if (IS_ERR(h_src))
5567 + if (unlikely(d_is_negative(h_src))) {
5569 + AuIOErr("i%lu exists on b%d "
5570 + "but not pseudo-linked\n",
5571 + inode->i_ino, cpg->bdst);
5577 + a->h_path.dentry = h_parent;
5578 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5581 + a->h_path.dentry = h_dst;
5583 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5584 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5585 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5587 + au_dtime_revert(&a->dt);
5588 + if (unlikely(err == -EWOULDBLOCK)) {
5589 + pr_warn("cannot retry for NFSv4 delegation"
5590 + " for an internal link\n");
5596 + /* todo: cpup_wh_file? */
5598 + au_update_ibrange(inode, /*do_put_zero*/1);
5601 + isdir = S_ISDIR(inode->i_mode);
5602 + old_ibtop = au_ibtop(inode);
5603 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5604 + if (unlikely(err))
5606 + dst_inode = d_inode(h_dst);
5607 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5608 + /* todo: necessary? */
5609 + /* au_pin_hdir_unlock(cpg->pin); */
5611 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5612 + if (unlikely(err)) {
5613 + /* todo: necessary? */
5614 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5615 + inode_unlock(dst_inode);
5619 + if (cpg->bdst < old_ibtop) {
5620 + if (S_ISREG(inode->i_mode)) {
5621 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5622 + if (unlikely(err)) {
5623 + /* ignore an error */
5624 + /* au_pin_hdir_relock(cpg->pin); */
5625 + inode_unlock(dst_inode);
5629 + au_set_ibtop(inode, cpg->bdst);
5631 + au_set_ibbot(inode, cpg->bdst);
5632 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5633 + au_hi_flags(inode, isdir));
5635 + /* todo: necessary? */
5636 + /* err = au_pin_hdir_relock(cpg->pin); */
5637 + inode_unlock(dst_inode);
5638 + if (unlikely(err))
5641 + src_inode = d_inode(h_src);
5643 + && (src_inode->i_nlink > 1
5644 + || src_inode->i_state & I_LINKABLE)
5646 + au_plink_append(inode, cpg->bdst, h_dst);
5648 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5649 + a->h_path.dentry = h_dst;
5650 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5653 + goto out_parent; /* success */
5657 + a->h_path.dentry = h_parent;
5658 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5659 + a->h_path.dentry = h_dst;
5661 + if (d_is_positive(h_dst)) {
5663 + /* no delegation since it is just created */
5664 + rerr = vfsub_unlink(h_dir, &a->h_path,
5665 + /*delegated*/NULL, /*force*/0);
5667 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5669 + au_dtime_revert(&a->dt);
5671 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5681 +#if 0 /* reserved */
5682 +struct au_cpup_single_args {
5684 + struct au_cp_generic *cpg;
5685 + struct dentry *dst_parent;
5688 +static void au_call_cpup_single(void *args)
5690 + struct au_cpup_single_args *a = args;
5692 + au_pin_hdir_acquire_nest(a->cpg->pin);
5693 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5694 + au_pin_hdir_release(a->cpg->pin);
5699 + * prevent SIGXFSZ in copy-up.
5700 + * testing CAP_MKNOD is for generic fs,
5701 + * but CAP_FSETID is for xfs only, currently.
5703 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5706 + struct super_block *sb;
5707 + struct inode *h_dir;
5710 + sb = au_pinned_parent(pin)->d_sb;
5711 + if (!au_wkq_test()
5712 + && (!au_sbi(sb)->si_plink_maint_pid
5713 + || au_plink_maint(sb, AuLock_NOPLM))) {
5714 + switch (mode & S_IFMT) {
5716 + /* no condition about RLIMIT_FSIZE and the file size */
5721 + do_sio = !capable(CAP_MKNOD);
5725 + do_sio = ((mode & (S_ISUID | S_ISGID))
5726 + && !capable(CAP_FSETID));
5727 + /* this workaround may be removed in the future */
5729 + h_dir = au_pinned_h_dir(pin);
5730 + do_sio = h_dir->i_mode & S_ISVTX;
5737 +#if 0 /* reserved */
5738 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5741 + struct dentry *h_dentry;
5743 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5744 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5745 + err = au_cpup_single(cpg, dst_parent);
5747 + struct au_cpup_single_args args = {
5750 + .dst_parent = dst_parent
5752 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5753 + if (unlikely(wkq_err))
5762 + * copyup the @dentry from the first active lower branch to @bdst,
5763 + * using au_cpup_single().
5765 +static int au_cpup_simple(struct au_cp_generic *cpg)
5768 + unsigned int flags_orig;
5769 + struct dentry *dentry;
5771 + AuDebugOn(cpg->bsrc < 0);
5773 + dentry = cpg->dentry;
5774 + DiMustWriteLock(dentry);
5776 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5778 + flags_orig = cpg->flags;
5779 + au_fset_cpup(cpg->flags, RENAME);
5780 + err = au_cpup_single(cpg, NULL);
5781 + cpg->flags = flags_orig;
5783 + return 0; /* success */
5786 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5787 + au_set_dbtop(dentry, cpg->bsrc);
5793 +struct au_cpup_simple_args {
5795 + struct au_cp_generic *cpg;
5798 +static void au_call_cpup_simple(void *args)
5800 + struct au_cpup_simple_args *a = args;
5802 + au_pin_hdir_acquire_nest(a->cpg->pin);
5803 + *a->errp = au_cpup_simple(a->cpg);
5804 + au_pin_hdir_release(a->cpg->pin);
5807 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5810 + struct dentry *dentry, *parent;
5811 + struct file *h_file;
5812 + struct inode *h_dir;
5814 + dentry = cpg->dentry;
5816 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5817 + AuDebugOn(cpg->bsrc < 0);
5818 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5819 + err = PTR_ERR(h_file);
5820 + if (IS_ERR(h_file))
5824 + parent = dget_parent(dentry);
5825 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5826 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5827 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5828 + err = au_cpup_simple(cpg);
5830 + struct au_cpup_simple_args args = {
5834 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5835 + if (unlikely(wkq_err))
5841 + au_h_open_post(dentry, cpg->bsrc, h_file);
5847 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5849 + aufs_bindex_t bsrc, bbot;
5850 + struct dentry *dentry, *h_dentry;
5852 + if (cpg->bsrc < 0) {
5853 + dentry = cpg->dentry;
5854 + bbot = au_dbbot(dentry);
5855 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5856 + h_dentry = au_h_dptr(dentry, bsrc);
5858 + AuDebugOn(d_is_negative(h_dentry));
5862 + AuDebugOn(bsrc > bbot);
5865 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5866 + return au_do_sio_cpup_simple(cpg);
5869 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5871 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5872 + return au_do_sio_cpup_simple(cpg);
5875 +/* ---------------------------------------------------------------------- */
5878 + * copyup the deleted file for writing.
5880 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5881 + struct file *file)
5884 + unsigned int flags_orig;
5885 + aufs_bindex_t bsrc_orig;
5886 + struct au_dinfo *dinfo;
5888 + struct au_hdentry *hd;
5889 + struct dentry *h_dentry;
5892 + dinfo = au_di(cpg->dentry);
5893 + AuRwMustWriteLock(&dinfo->di_rwsem);
5895 + bsrc_orig = cpg->bsrc;
5896 + cpg->bsrc = dinfo->di_btop;
5897 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5898 + hdst.h_dentry = hdst.hd->hd_dentry;
5899 + hdst.hd->hd_dentry = wh_dentry;
5900 + dinfo->di_btop = cpg->bdst;
5902 + hsrc.h_dentry = NULL;
5904 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5905 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5906 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5908 + flags_orig = cpg->flags;
5909 + cpg->flags = !AuCpup_DTIME;
5910 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5911 + cpg->flags = flags_orig;
5914 + err = au_reopen_nondir(file);
5915 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5917 + hdst.hd->hd_dentry = hdst.h_dentry;
5918 + dinfo->di_btop = cpg->bsrc;
5919 + cpg->bsrc = bsrc_orig;
5924 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5927 + aufs_bindex_t bdst;
5928 + struct au_dtime dt;
5929 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5930 + struct au_branch *br;
5931 + struct path h_path;
5933 + dentry = cpg->dentry;
5935 + br = au_sbr(dentry->d_sb, bdst);
5936 + parent = dget_parent(dentry);
5937 + h_parent = au_h_dptr(parent, bdst);
5938 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5939 + err = PTR_ERR(wh_dentry);
5940 + if (IS_ERR(wh_dentry))
5943 + h_path.dentry = h_parent;
5944 + h_path.mnt = au_br_mnt(br);
5945 + au_dtime_store(&dt, parent, &h_path);
5946 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5947 + if (unlikely(err))
5951 + h_path.dentry = wh_dentry;
5952 + if (!d_is_dir(wh_dentry)) {
5953 + /* no delegation since it is just created */
5954 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5955 + /*delegated*/NULL, /*force*/0);
5957 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5958 + if (unlikely(err)) {
5959 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5963 + au_dtime_revert(&dt);
5964 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5973 +struct au_cpup_wh_args {
5975 + struct au_cp_generic *cpg;
5976 + struct file *file;
5979 +static void au_call_cpup_wh(void *args)
5981 + struct au_cpup_wh_args *a = args;
5983 + au_pin_hdir_acquire_nest(a->cpg->pin);
5984 + *a->errp = au_cpup_wh(a->cpg, a->file);
5985 + au_pin_hdir_release(a->cpg->pin);
5988 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5991 + aufs_bindex_t bdst;
5992 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5993 + struct inode *dir, *h_dir, *h_tmpdir;
5994 + struct au_wbr *wbr;
5995 + struct au_pin wh_pin, *pin_orig;
5997 + dentry = cpg->dentry;
5999 + parent = dget_parent(dentry);
6000 + dir = d_inode(parent);
6003 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6006 + if (!h_dir->i_nlink) {
6007 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6008 + h_orph = wbr->wbr_orph;
6010 + h_parent = dget(au_h_dptr(parent, bdst));
6011 + au_set_h_dptr(parent, bdst, dget(h_orph));
6012 + h_tmpdir = d_inode(h_orph);
6013 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6015 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6016 + /* todo: au_h_open_pre()? */
6018 + pin_orig = cpg->pin;
6019 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6020 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6021 + cpg->pin = &wh_pin;
6024 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6025 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6026 + err = au_cpup_wh(cpg, file);
6028 + struct au_cpup_wh_args args = {
6033 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6034 + if (unlikely(wkq_err))
6039 + inode_unlock(h_tmpdir);
6040 + /* todo: au_h_open_post()? */
6041 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6042 + au_set_h_dptr(parent, bdst, h_parent);
6043 + AuDebugOn(!pin_orig);
6044 + cpg->pin = pin_orig;
6052 +/* ---------------------------------------------------------------------- */
6055 + * generic routine for both of copy-up and copy-down.
6057 +/* cf. revalidate function in file.c */
6058 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6059 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6060 + struct au_pin *pin,
6061 + struct dentry *h_parent, void *arg),
6065 + struct au_pin pin;
6066 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6069 + parent = dget_parent(dentry);
6070 + if (IS_ROOT(parent))
6073 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6074 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6076 + /* do not use au_dpage */
6077 + real_parent = parent;
6080 + parent = dget_parent(dentry);
6081 + h_parent = au_h_dptr(parent, bdst);
6083 + goto out; /* success */
6085 + /* find top dir which is necessary to cpup */
6089 + parent = dget_parent(d);
6090 + di_read_lock_parent3(parent, !AuLock_IR);
6091 + h_parent = au_h_dptr(parent, bdst);
6092 + di_read_unlock(parent, !AuLock_IR);
6093 + } while (!h_parent);
6095 + if (d != real_parent)
6096 + di_write_lock_child3(d);
6098 + /* somebody else might create while we were sleeping */
6099 + h_dentry = au_h_dptr(d, bdst);
6100 + if (!h_dentry || d_is_negative(h_dentry)) {
6102 + au_update_dbtop(d);
6104 + au_pin_set_dentry(&pin, d);
6105 + err = au_do_pin(&pin);
6107 + err = cp(d, bdst, &pin, h_parent, arg);
6112 + if (d != real_parent)
6113 + di_write_unlock(d);
6114 + if (unlikely(err))
6123 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6124 + struct au_pin *pin,
6125 + struct dentry *h_parent __maybe_unused,
6126 + void *arg __maybe_unused)
6128 + struct au_cp_generic cpg = {
6134 + .flags = AuCpup_DTIME
6136 + return au_sio_cpup_simple(&cpg);
6139 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6141 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6144 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6147 + struct dentry *parent;
6148 + struct inode *dir;
6150 + parent = dget_parent(dentry);
6151 + dir = d_inode(parent);
6153 + if (au_h_iptr(dir, bdst))
6156 + di_read_unlock(parent, AuLock_IR);
6157 + di_write_lock_parent(parent);
6158 + /* someone else might change our inode while we were sleeping */
6159 + if (!au_h_iptr(dir, bdst))
6160 + err = au_cpup_dirs(dentry, bdst);
6161 + di_downgrade_lock(parent, AuLock_IR);
6167 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6168 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6169 +++ linux/fs/aufs/cpup.h 2021-12-03 15:38:59.933313976 +0100
6171 +/* SPDX-License-Identifier: GPL-2.0 */
6173 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6175 + * This program, aufs is free software; you can redistribute it and/or modify
6176 + * it under the terms of the GNU General Public License as published by
6177 + * the Free Software Foundation; either version 2 of the License, or
6178 + * (at your option) any later version.
6180 + * This program is distributed in the hope that it will be useful,
6181 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6182 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6183 + * GNU General Public License for more details.
6185 + * You should have received a copy of the GNU General Public License
6186 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6190 + * copy-up/down functions
6193 +#ifndef __AUFS_CPUP_H__
6194 +#define __AUFS_CPUP_H__
6198 +#include <linux/path.h>
6204 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6205 +void au_cpup_attr_timesizes(struct inode *inode);
6206 +void au_cpup_attr_nlink(struct inode *inode, int force);
6207 +void au_cpup_attr_changeable(struct inode *inode);
6208 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6209 +void au_cpup_attr_all(struct inode *inode, int force);
6211 +/* ---------------------------------------------------------------------- */
6213 +struct au_cp_generic {
6214 + struct dentry *dentry;
6215 + aufs_bindex_t bdst, bsrc;
6217 + struct au_pin *pin;
6218 + unsigned int flags;
6222 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6223 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6225 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6226 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6228 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6230 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6231 + the branch is marked as RO */
6233 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6234 +#undef AuCpup_HOPEN
6235 +#define AuCpup_HOPEN 0
6238 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6239 +#define au_fset_cpup(flags, name) \
6240 + do { (flags) |= AuCpup_##name; } while (0)
6241 +#define au_fclr_cpup(flags, name) \
6242 + do { (flags) &= ~AuCpup_##name; } while (0)
6244 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6245 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6246 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6247 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6249 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6250 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6251 + struct au_pin *pin,
6252 + struct dentry *h_parent, void *arg),
6254 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6255 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6257 +/* ---------------------------------------------------------------------- */
6259 +/* keep timestamps when copyup */
6261 + struct dentry *dt_dentry;
6262 + struct path dt_h_path;
6263 + struct timespec64 dt_atime, dt_mtime;
6265 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6266 + struct path *h_path);
6267 +void au_dtime_revert(struct au_dtime *dt);
6269 +#endif /* __KERNEL__ */
6270 +#endif /* __AUFS_CPUP_H__ */
6271 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6272 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6273 +++ linux/fs/aufs/dbgaufs.c 2021-12-03 15:38:59.933313976 +0100
6275 +// SPDX-License-Identifier: GPL-2.0
6277 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6279 + * This program, aufs is free software; you can redistribute it and/or modify
6280 + * it under the terms of the GNU General Public License as published by
6281 + * the Free Software Foundation; either version 2 of the License, or
6282 + * (at your option) any later version.
6284 + * This program is distributed in the hope that it will be useful,
6285 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6286 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6287 + * GNU General Public License for more details.
6289 + * You should have received a copy of the GNU General Public License
6290 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6294 + * debugfs interface
6297 +#include <linux/debugfs.h>
6300 +#ifndef CONFIG_SYSFS
6301 +#error DEBUG_FS depends upon SYSFS
6304 +static struct dentry *dbgaufs;
6305 +static const mode_t dbgaufs_mode = 0444;
6307 +/* 20 is max digits length of ulong 64 */
6308 +struct dbgaufs_arg {
6314 + * common function for all XINO files
6316 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6317 + struct file *file)
6321 + p = file->private_data;
6323 + /* this is struct dbgaufs_arg */
6324 + AuDebugOn(!au_kfree_sz_test(p));
6325 + au_kfree_do_rcu(p);
6330 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6335 + struct dbgaufs_arg *p;
6338 + p = kmalloc(sizeof(*p), GFP_NOFS);
6344 + file->private_data = p;
6348 + err = vfsub_getattr(&xf->f_path, &st);
6352 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6353 + cnt, st.blocks, st.blksize,
6354 + (long long)st.size);
6356 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6357 + st.blocks, st.blksize,
6358 + (long long)st.size);
6359 + AuDebugOn(p->n >= sizeof(p->a));
6361 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6369 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6370 + size_t count, loff_t *ppos)
6372 + struct dbgaufs_arg *p;
6374 + p = file->private_data;
6375 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6378 +/* ---------------------------------------------------------------------- */
6380 +struct dbgaufs_plink_arg {
6385 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6386 + struct file *file)
6388 + free_page((unsigned long)file->private_data);
6392 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6394 + int err, i, limit;
6395 + unsigned long n, sum;
6396 + struct dbgaufs_plink_arg *p;
6397 + struct au_sbinfo *sbinfo;
6398 + struct super_block *sb;
6399 + struct hlist_bl_head *hbl;
6402 + p = (void *)get_zeroed_page(GFP_NOFS);
6407 + sbinfo = inode->i_private;
6408 + sb = sbinfo->si_sb;
6409 + si_noflush_read_lock(sb);
6410 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6411 + limit = PAGE_SIZE - sizeof(p->n);
6413 + /* the number of buckets */
6414 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6419 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6421 + n = au_hbl_count(hbl);
6424 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6427 + if (unlikely(limit <= 0))
6430 + p->a[p->n - 1] = '\n';
6432 + /* the sum of plinks */
6433 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6436 + if (unlikely(limit <= 0))
6439 +#define str "1\n0\n0\n"
6440 + p->n = sizeof(str) - 1;
6441 + strcpy(p->a, str);
6444 + si_read_unlock(sb);
6447 + file->private_data = p;
6448 + goto out; /* success */
6451 + free_page((unsigned long)p);
6456 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6457 + size_t count, loff_t *ppos)
6459 + struct dbgaufs_plink_arg *p;
6461 + p = file->private_data;
6462 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6465 +static const struct file_operations dbgaufs_plink_fop = {
6466 + .owner = THIS_MODULE,
6467 + .open = dbgaufs_plink_open,
6468 + .release = dbgaufs_plink_release,
6469 + .read = dbgaufs_plink_read
6472 +/* ---------------------------------------------------------------------- */
6474 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6477 + struct au_sbinfo *sbinfo;
6478 + struct super_block *sb;
6480 + sbinfo = inode->i_private;
6481 + sb = sbinfo->si_sb;
6482 + si_noflush_read_lock(sb);
6483 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6484 + si_read_unlock(sb);
6488 +static const struct file_operations dbgaufs_xib_fop = {
6489 + .owner = THIS_MODULE,
6490 + .open = dbgaufs_xib_open,
6491 + .release = dbgaufs_xi_release,
6492 + .read = dbgaufs_xi_read
6495 +/* ---------------------------------------------------------------------- */
6497 +#define DbgaufsXi_PREFIX "xi"
6499 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6503 + aufs_bindex_t bindex;
6504 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6505 + struct au_sbinfo *sbinfo;
6506 + struct super_block *sb;
6507 + struct au_xino *xi;
6509 + struct qstr *name;
6510 + struct au_branch *br;
6513 + name = &file->f_path.dentry->d_name;
6514 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6515 + || memcmp(name->name, DbgaufsXi_PREFIX,
6516 + sizeof(DbgaufsXi_PREFIX) - 1)))
6519 + AuDebugOn(name->len >= sizeof(a));
6520 + memcpy(a, name->name, name->len);
6521 + a[name->len] = '\0';
6522 + p = strchr(a, '-');
6525 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6526 + if (unlikely(err))
6531 + err = kstrtol(p + 1, 10, &l);
6532 + if (unlikely(err))
6538 + sbinfo = inode->i_private;
6539 + sb = sbinfo->si_sb;
6540 + si_noflush_read_lock(sb);
6541 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6543 + br = au_sbr(sb, bindex);
6545 + if (unlikely(idx >= xi->xi_nfile))
6547 + xf = au_xino_file(xi, idx);
6549 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6550 + au_xino_count(br));
6553 + si_read_unlock(sb);
6559 +static const struct file_operations dbgaufs_xino_fop = {
6560 + .owner = THIS_MODULE,
6561 + .open = dbgaufs_xino_open,
6562 + .release = dbgaufs_xi_release,
6563 + .read = dbgaufs_xi_read
6566 +void dbgaufs_xino_del(struct au_branch *br)
6568 + struct dentry *dbgaufs;
6570 + dbgaufs = br->br_dbgaufs;
6574 + br->br_dbgaufs = NULL;
6575 + /* debugfs acquires the parent i_mutex */
6577 + debugfs_remove(dbgaufs);
6581 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6583 + aufs_bindex_t bbot;
6584 + struct au_branch *br;
6586 + if (!au_sbi(sb)->si_dbgaufs)
6589 + bbot = au_sbbot(sb);
6590 + for (; bindex <= bbot; bindex++) {
6591 + br = au_sbr(sb, bindex);
6592 + dbgaufs_xino_del(br);
6596 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6597 + unsigned int idx, struct dentry *parent,
6598 + struct au_sbinfo *sbinfo)
6600 + struct au_branch *br;
6602 + /* "xi" bindex(5) "-" idx(2) NULL */
6603 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6606 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6608 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6610 + br = au_sbr(sb, bindex);
6611 + if (br->br_dbgaufs) {
6612 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6614 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6615 + /* debugfs acquires the parent i_mutex */
6617 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6621 + pr_warn("failed renaming %pd/%s, ignored.\n",
6626 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6627 + sbinfo, &dbgaufs_xino_fop);
6629 + if (unlikely(!br->br_dbgaufs))
6630 + pr_warn("failed creating %pd/%s, ignored.\n",
6635 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6636 + struct dentry *parent, struct au_sbinfo *sbinfo)
6638 + struct au_branch *br;
6639 + struct au_xino *xi;
6642 + br = au_sbr(sb, bindex);
6644 + for (u = 0; u < xi->xi_nfile; u++)
6645 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6648 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6650 + struct au_sbinfo *sbinfo;
6651 + struct dentry *parent;
6652 + aufs_bindex_t bbot;
6654 + if (!au_opt_test(au_mntflags(sb), XINO))
6657 + sbinfo = au_sbi(sb);
6658 + parent = sbinfo->si_dbgaufs;
6662 + bbot = au_sbbot(sb);
6664 + for (; bindex <= bbot; bindex++)
6665 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6667 + for (; bbot >= bindex; bbot--)
6668 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6671 +/* ---------------------------------------------------------------------- */
6673 +#ifdef CONFIG_AUFS_EXPORT
6674 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6677 + struct au_sbinfo *sbinfo;
6678 + struct super_block *sb;
6680 + sbinfo = inode->i_private;
6681 + sb = sbinfo->si_sb;
6682 + si_noflush_read_lock(sb);
6683 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6684 + si_read_unlock(sb);
6688 +static const struct file_operations dbgaufs_xigen_fop = {
6689 + .owner = THIS_MODULE,
6690 + .open = dbgaufs_xigen_open,
6691 + .release = dbgaufs_xi_release,
6692 + .read = dbgaufs_xi_read
6695 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6700 + * This function is a dynamic '__init' function actually,
6701 + * so the tiny check for si_rwsem is unnecessary.
6703 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6706 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6707 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6708 + &dbgaufs_xigen_fop);
6709 + if (sbinfo->si_dbgaufs_xigen)
6715 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6719 +#endif /* CONFIG_AUFS_EXPORT */
6721 +/* ---------------------------------------------------------------------- */
6723 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6726 + * This function is a dynamic '__fin' function actually,
6727 + * so the tiny check for si_rwsem is unnecessary.
6729 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6731 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6732 + sbinfo->si_dbgaufs = NULL;
6735 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6738 + char name[SysaufsSiNameLen];
6741 + * This function is a dynamic '__init' function actually,
6742 + * so the tiny check for si_rwsem is unnecessary.
6744 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6748 + AuErr1("/debug/aufs is uninitialized\n");
6753 + sysaufs_name(sbinfo, name);
6754 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6755 + if (unlikely(!sbinfo->si_dbgaufs))
6758 + /* regardless plink/noplink option */
6759 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6760 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6761 + &dbgaufs_plink_fop);
6762 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6765 + /* regardless xino/noxino option */
6766 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6767 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6768 + &dbgaufs_xib_fop);
6769 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6772 + err = dbgaufs_xigen_init(sbinfo);
6774 + goto out; /* success */
6777 + dbgaufs_si_fin(sbinfo);
6779 + if (unlikely(err))
6780 + pr_err("debugfs/aufs failed\n");
6784 +/* ---------------------------------------------------------------------- */
6786 +void dbgaufs_fin(void)
6788 + debugfs_remove(dbgaufs);
6791 +int __init dbgaufs_init(void)
6796 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6801 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6802 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6803 +++ linux/fs/aufs/dbgaufs.h 2021-12-03 15:38:59.933313976 +0100
6805 +/* SPDX-License-Identifier: GPL-2.0 */
6807 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6809 + * This program, aufs is free software; you can redistribute it and/or modify
6810 + * it under the terms of the GNU General Public License as published by
6811 + * the Free Software Foundation; either version 2 of the License, or
6812 + * (at your option) any later version.
6814 + * This program is distributed in the hope that it will be useful,
6815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6817 + * GNU General Public License for more details.
6819 + * You should have received a copy of the GNU General Public License
6820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6824 + * debugfs interface
6827 +#ifndef __DBGAUFS_H__
6828 +#define __DBGAUFS_H__
6832 +struct super_block;
6836 +#ifdef CONFIG_DEBUG_FS
6838 +void dbgaufs_xino_del(struct au_branch *br);
6839 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6840 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6841 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6842 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6843 +void dbgaufs_fin(void);
6844 +int __init dbgaufs_init(void);
6846 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6847 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6848 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6850 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6851 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6852 +AuStubVoid(dbgaufs_fin, void)
6853 +AuStubInt0(__init dbgaufs_init, void)
6854 +#endif /* CONFIG_DEBUG_FS */
6856 +#endif /* __KERNEL__ */
6857 +#endif /* __DBGAUFS_H__ */
6858 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6859 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6860 +++ linux/fs/aufs/dcsub.c 2021-12-03 15:38:59.933313976 +0100
6862 +// SPDX-License-Identifier: GPL-2.0
6864 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6866 + * This program, aufs is free software; you can redistribute it and/or modify
6867 + * it under the terms of the GNU General Public License as published by
6868 + * the Free Software Foundation; either version 2 of the License, or
6869 + * (at your option) any later version.
6871 + * This program is distributed in the hope that it will be useful,
6872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6874 + * GNU General Public License for more details.
6876 + * You should have received a copy of the GNU General Public License
6877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6881 + * sub-routines for dentry cache
6886 +static void au_dpage_free(struct au_dpage *dpage)
6889 + struct dentry **p;
6891 + p = dpage->dentries;
6892 + for (i = 0; i < dpage->ndentry; i++)
6894 + free_page((unsigned long)dpage->dentries);
6897 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6903 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6904 + if (unlikely(!dpages->dpages))
6907 + p = (void *)__get_free_page(gfp);
6911 + dpages->dpages[0].ndentry = 0;
6912 + dpages->dpages[0].dentries = p;
6913 + dpages->ndpage = 1;
6914 + return 0; /* success */
6917 + au_kfree_try_rcu(dpages->dpages);
6922 +void au_dpages_free(struct au_dcsub_pages *dpages)
6925 + struct au_dpage *p;
6927 + p = dpages->dpages;
6928 + for (i = 0; i < dpages->ndpage; i++)
6929 + au_dpage_free(p++);
6930 + au_kfree_try_rcu(dpages->dpages);
6933 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6934 + struct dentry *dentry, gfp_t gfp)
6937 + struct au_dpage *dpage;
6940 + dpage = dpages->dpages + dpages->ndpage - 1;
6941 + sz = PAGE_SIZE / sizeof(dentry);
6942 + if (unlikely(dpage->ndentry >= sz)) {
6943 + AuLabel(new dpage);
6945 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6946 + p = au_kzrealloc(dpages->dpages, sz,
6947 + sz + sizeof(*dpages->dpages), gfp,
6952 + dpages->dpages = p;
6953 + dpage = dpages->dpages + dpages->ndpage;
6954 + p = (void *)__get_free_page(gfp);
6958 + dpage->ndentry = 0;
6959 + dpage->dentries = p;
6963 + AuDebugOn(au_dcount(dentry) <= 0);
6964 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6965 + return 0; /* success */
6971 +/* todo: BAD approach */
6972 +/* copied from linux/fs/dcache.c */
6980 +extern void d_walk(struct dentry *parent, void *data,
6981 + enum d_walk_ret (*enter)(void *, struct dentry *));
6983 +struct ac_dpages_arg {
6985 + struct au_dcsub_pages *dpages;
6986 + struct super_block *sb;
6987 + au_dpages_test test;
6991 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6993 + enum d_walk_ret ret;
6994 + struct ac_dpages_arg *arg = _arg;
6996 + ret = D_WALK_CONTINUE;
6997 + if (dentry->d_sb == arg->sb
6998 + && !IS_ROOT(dentry)
6999 + && au_dcount(dentry) > 0
7001 + && (!arg->test || arg->test(dentry, arg->arg))) {
7002 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7003 + if (unlikely(arg->err))
7004 + ret = D_WALK_QUIT;
7010 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7011 + au_dpages_test test, void *arg)
7013 + struct ac_dpages_arg args = {
7021 + d_walk(root, &args, au_call_dpages_append);
7026 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7027 + int do_include, au_dpages_test test, void *arg)
7032 + write_seqlock(&rename_lock);
7033 + spin_lock(&dentry->d_lock);
7035 + && au_dcount(dentry) > 0
7036 + && (!test || test(dentry, arg)))
7037 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7038 + spin_unlock(&dentry->d_lock);
7039 + if (unlikely(err))
7043 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7046 + while (!IS_ROOT(dentry)) {
7047 + dentry = dentry->d_parent; /* rename_lock is locked */
7048 + spin_lock(&dentry->d_lock);
7049 + if (au_dcount(dentry) > 0
7050 + && (!test || test(dentry, arg)))
7051 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7052 + spin_unlock(&dentry->d_lock);
7053 + if (unlikely(err))
7058 + write_sequnlock(&rename_lock);
7062 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7064 + return au_di(dentry) && dentry->d_sb == arg;
7067 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7068 + struct dentry *dentry, int do_include)
7070 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7071 + au_dcsub_dpages_aufs, dentry->d_sb);
7074 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7076 + struct path path[2] = {
7085 + return path_is_under(path + 0, path + 1);
7087 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7088 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7089 +++ linux/fs/aufs/dcsub.h 2021-12-03 15:38:59.933313976 +0100
7091 +/* SPDX-License-Identifier: GPL-2.0 */
7093 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7095 + * This program, aufs is free software; you can redistribute it and/or modify
7096 + * it under the terms of the GNU General Public License as published by
7097 + * the Free Software Foundation; either version 2 of the License, or
7098 + * (at your option) any later version.
7100 + * This program is distributed in the hope that it will be useful,
7101 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7102 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7103 + * GNU General Public License for more details.
7105 + * You should have received a copy of the GNU General Public License
7106 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7110 + * sub-routines for dentry cache
7113 +#ifndef __AUFS_DCSUB_H__
7114 +#define __AUFS_DCSUB_H__
7118 +#include <linux/dcache.h>
7119 +#include <linux/fs.h>
7123 + struct dentry **dentries;
7126 +struct au_dcsub_pages {
7128 + struct au_dpage *dpages;
7131 +/* ---------------------------------------------------------------------- */
7134 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7135 +void au_dpages_free(struct au_dcsub_pages *dpages);
7136 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7137 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7138 + au_dpages_test test, void *arg);
7139 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7140 + int do_include, au_dpages_test test, void *arg);
7141 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7142 + struct dentry *dentry, int do_include);
7143 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7145 +/* ---------------------------------------------------------------------- */
7148 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7149 + * include/linux/dcache.h. Try them (in the future).
7152 +static inline int au_d_hashed_positive(struct dentry *d)
7155 + struct inode *inode = d_inode(d);
7158 + if (unlikely(d_unhashed(d)
7159 + || d_is_negative(d)
7160 + || !inode->i_nlink))
7165 +static inline int au_d_linkable(struct dentry *d)
7168 + struct inode *inode = d_inode(d);
7170 + err = au_d_hashed_positive(d);
7172 + && d_is_positive(d)
7173 + && (inode->i_state & I_LINKABLE))
7178 +static inline int au_d_alive(struct dentry *d)
7181 + struct inode *inode;
7185 + err = au_d_hashed_positive(d);
7187 + inode = d_inode(d);
7188 + if (unlikely(d_unlinked(d)
7189 + || d_is_negative(d)
7190 + || !inode->i_nlink))
7196 +static inline int au_alive_dir(struct dentry *d)
7200 + err = au_d_alive(d);
7201 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7206 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7208 + return a->len == b->len
7209 + && !memcmp(a->name, b->name, a->len);
7214 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7216 + * the type of d_lockref.count became int, but the inlined function d_count()
7217 + * still returns unsigned int.
7218 + * I don't know why. Maybe it is for every d_count() users?
7219 + * Anyway au_dcount() lives on.
7221 +static inline int au_dcount(struct dentry *d)
7223 + return (int)d_count(d);
7226 +#endif /* __KERNEL__ */
7227 +#endif /* __AUFS_DCSUB_H__ */
7228 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7229 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7230 +++ linux/fs/aufs/debug.c 2021-12-03 15:38:59.933313976 +0100
7232 +// SPDX-License-Identifier: GPL-2.0
7234 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7236 + * This program, aufs is free software; you can redistribute it and/or modify
7237 + * it under the terms of the GNU General Public License as published by
7238 + * the Free Software Foundation; either version 2 of the License, or
7239 + * (at your option) any later version.
7241 + * This program is distributed in the hope that it will be useful,
7242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7244 + * GNU General Public License for more details.
7246 + * You should have received a copy of the GNU General Public License
7247 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7251 + * debug print functions
7254 +#include <linux/iversion.h>
7257 +/* Returns 0, or -errno. arg is in kp->arg. */
7258 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7262 + err = kstrtoint(val, 0, &n);
7272 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7273 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7278 + return sprintf(buffer, "%d", atomic_read(a));
7281 +static struct kernel_param_ops param_ops_atomic_t = {
7282 + .set = param_atomic_t_set,
7283 + .get = param_atomic_t_get
7284 + /* void (*free)(void *arg) */
7287 +atomic_t aufs_debug = ATOMIC_INIT(0);
7288 +MODULE_PARM_DESC(debug, "debug print");
7289 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7291 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7292 +char *au_plevel = KERN_DEBUG;
7293 +#define dpri(fmt, ...) do { \
7295 + && strcmp(au_plevel, KERN_DEBUG)) \
7296 + || au_debug_test()) \
7297 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7300 +/* ---------------------------------------------------------------------- */
7302 +void au_dpri_whlist(struct au_nhash *whlist)
7304 + unsigned long ul, n;
7305 + struct hlist_head *head;
7306 + struct au_vdir_wh *pos;
7308 + n = whlist->nh_num;
7309 + head = whlist->nh_head;
7310 + for (ul = 0; ul < n; ul++) {
7311 + hlist_for_each_entry(pos, head, wh_hash)
7312 + dpri("b%d, %.*s, %d\n",
7314 + pos->wh_str.len, pos->wh_str.name,
7320 +void au_dpri_vdir(struct au_vdir *vdir)
7323 + union au_vdir_deblk_p p;
7326 + if (!vdir || IS_ERR(vdir)) {
7327 + dpri("err %ld\n", PTR_ERR(vdir));
7331 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7332 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7333 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7334 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7335 + p.deblk = vdir->vd_deblk[ul];
7337 + dpri("[%lu]: %p\n", ul, o);
7341 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7342 + struct dentry *wh)
7347 + if (!inode || IS_ERR(inode)) {
7348 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7352 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7353 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7354 + && sizeof(inode->i_blocks) != sizeof(u64));
7356 + n = (void *)wh->d_name.name;
7357 + l = wh->d_name.len;
7360 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7361 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7363 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7364 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7365 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7366 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7367 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7368 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7369 + inode->i_generation,
7370 + l ? ", wh " : "", l, n);
7374 +void au_dpri_inode(struct inode *inode)
7376 + struct au_iinfo *iinfo;
7377 + struct au_hinode *hi;
7378 + aufs_bindex_t bindex;
7381 + err = do_pri_inode(-1, inode, -1, NULL);
7382 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7385 + iinfo = au_ii(inode);
7386 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7387 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7388 + if (iinfo->ii_btop < 0)
7391 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7392 + hi = au_hinode(iinfo, bindex);
7394 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7398 +void au_dpri_dalias(struct inode *inode)
7402 + spin_lock(&inode->i_lock);
7403 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7404 + au_dpri_dentry(d);
7405 + spin_unlock(&inode->i_lock);
7408 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7410 + struct dentry *wh = NULL;
7412 + struct inode *inode;
7413 + struct au_iinfo *iinfo;
7414 + struct au_hinode *hi;
7416 + if (!dentry || IS_ERR(dentry)) {
7417 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7420 + /* do not call dget_parent() here */
7421 + /* note: access d_xxx without d_lock */
7422 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7423 + bindex, dentry, dentry,
7424 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7425 + au_dcount(dentry), dentry->d_flags,
7426 + d_unhashed(dentry) ? "un" : "");
7429 + if (d_is_positive(dentry))
7430 + inode = d_inode(dentry);
7432 + && au_test_aufs(dentry->d_sb)
7434 + && !au_is_bad_inode(inode)) {
7435 + iinfo = au_ii(inode);
7436 + hi = au_hinode(iinfo, bindex);
7438 + wh = hi->hi_whdentry;
7440 + do_pri_inode(bindex, inode, hn, wh);
7444 +void au_dpri_dentry(struct dentry *dentry)
7446 + struct au_dinfo *dinfo;
7447 + aufs_bindex_t bindex;
7450 + err = do_pri_dentry(-1, dentry);
7451 + if (err || !au_test_aufs(dentry->d_sb))
7454 + dinfo = au_di(dentry);
7457 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7458 + dinfo->di_btop, dinfo->di_bbot,
7459 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7460 + dinfo->di_tmpfile);
7461 + if (dinfo->di_btop < 0)
7463 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7464 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7467 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7471 + if (!file || IS_ERR(file)) {
7472 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7477 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7478 + && au_test_aufs(file->f_path.dentry->d_sb)
7480 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7481 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7482 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7483 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7484 + file->f_version, file->f_pos, a);
7485 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7486 + do_pri_dentry(bindex, file->f_path.dentry);
7490 +void au_dpri_file(struct file *file)
7492 + struct au_finfo *finfo;
7493 + struct au_fidir *fidir;
7494 + struct au_hfile *hfile;
7495 + aufs_bindex_t bindex;
7498 + err = do_pri_file(-1, file);
7500 + || IS_ERR_OR_NULL(file->f_path.dentry)
7501 + || !au_test_aufs(file->f_path.dentry->d_sb))
7504 + finfo = au_fi(file);
7507 + if (finfo->fi_btop < 0)
7509 + fidir = finfo->fi_hdir;
7511 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7513 + for (bindex = finfo->fi_btop;
7514 + bindex >= 0 && bindex <= fidir->fd_bbot;
7516 + hfile = fidir->fd_hfile + bindex;
7517 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7521 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7523 + struct vfsmount *mnt;
7524 + struct super_block *sb;
7526 + if (!br || IS_ERR(br))
7528 + mnt = au_br_mnt(br);
7529 + if (!mnt || IS_ERR(mnt))
7532 + if (!sb || IS_ERR(sb))
7535 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7536 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7538 + bindex, br->br_perm, br->br_id, br->br_wbr,
7539 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7540 + sb->s_flags, sb->s_count,
7541 + atomic_read(&sb->s_active),
7542 + !!au_xino_file(br->br_xino, /*idx*/-1));
7546 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7550 +void au_dpri_sb(struct super_block *sb)
7552 + struct au_sbinfo *sbinfo;
7553 + aufs_bindex_t bindex;
7555 + /* to reduce stack size */
7557 + struct vfsmount mnt;
7558 + struct au_branch fake;
7561 + /* this function can be called from magic sysrq */
7562 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7563 + if (unlikely(!a)) {
7564 + dpri("no memory\n");
7568 + a->mnt.mnt_sb = sb;
7569 + a->fake.br_path.mnt = &a->mnt;
7570 + err = do_pri_br(-1, &a->fake);
7572 + dpri("dev 0x%x\n", sb->s_dev);
7573 + if (err || !au_test_aufs(sb))
7576 + sbinfo = au_sbi(sb);
7579 + dpri("nw %d, gen %u, kobj %d\n",
7580 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7581 + kref_read(&sbinfo->si_kobj.kref));
7582 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7583 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7586 +/* ---------------------------------------------------------------------- */
7588 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7590 + struct inode *h_inode, *inode = d_inode(dentry);
7591 + struct dentry *h_dentry;
7592 + aufs_bindex_t bindex, bbot, bi;
7594 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7597 + bbot = au_dbbot(dentry);
7598 + bi = au_ibbot(inode);
7601 + bindex = au_dbtop(dentry);
7602 + bi = au_ibtop(inode);
7606 + for (; bindex <= bbot; bindex++) {
7607 + h_dentry = au_h_dptr(dentry, bindex);
7610 + h_inode = au_h_iptr(inode, bindex);
7611 + if (unlikely(h_inode != d_inode(h_dentry))) {
7613 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7614 + AuDbgDentry(dentry);
7615 + AuDbgInode(inode);
7617 + if (au_test_fuse(h_inode->i_sb))
7625 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7628 + struct au_dcsub_pages dpages;
7629 + struct au_dpage *dpage;
7630 + struct dentry **dentries;
7632 + err = au_dpages_init(&dpages, GFP_NOFS);
7634 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7636 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7637 + dpage = dpages.dpages + i;
7638 + dentries = dpage->dentries;
7639 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7640 + AuDebugOn(au_digen_test(dentries[j], sigen));
7642 + au_dpages_free(&dpages);
7645 +void au_dbg_verify_kthread(void)
7647 + if (au_wkq_test()) {
7650 + * It may be recursive, but udba=notify between two aufs mounts,
7651 + * where a single ro branch is shared, is not a problem.
7657 +/* ---------------------------------------------------------------------- */
7659 +int __init au_debug_init(void)
7661 + aufs_bindex_t bindex;
7662 + struct au_vdir_destr destr;
7665 + AuDebugOn(bindex >= 0);
7668 + AuDebugOn(destr.len < NAME_MAX);
7670 +#ifdef CONFIG_4KSTACKS
7671 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7676 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7677 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7678 +++ linux/fs/aufs/debug.h 2021-12-03 15:38:59.933313976 +0100
7680 +/* SPDX-License-Identifier: GPL-2.0 */
7682 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7684 + * This program, aufs is free software; you can redistribute it and/or modify
7685 + * it under the terms of the GNU General Public License as published by
7686 + * the Free Software Foundation; either version 2 of the License, or
7687 + * (at your option) any later version.
7689 + * This program is distributed in the hope that it will be useful,
7690 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7691 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7692 + * GNU General Public License for more details.
7694 + * You should have received a copy of the GNU General Public License
7695 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7699 + * debug print functions
7702 +#ifndef __AUFS_DEBUG_H__
7703 +#define __AUFS_DEBUG_H__
7707 +#include <linux/atomic.h>
7708 +#include <linux/module.h>
7709 +#include <linux/kallsyms.h>
7710 +#include <linux/sysrq.h>
7712 +#ifdef CONFIG_AUFS_DEBUG
7713 +#define AuDebugOn(a) BUG_ON(a)
7715 +/* module parameter */
7716 +extern atomic_t aufs_debug;
7717 +static inline void au_debug_on(void)
7719 + atomic_inc(&aufs_debug);
7721 +static inline void au_debug_off(void)
7723 + atomic_dec_if_positive(&aufs_debug);
7726 +static inline int au_debug_test(void)
7728 + return atomic_read(&aufs_debug) > 0;
7731 +#define AuDebugOn(a) do {} while (0)
7732 +AuStubVoid(au_debug_on, void)
7733 +AuStubVoid(au_debug_off, void)
7734 +AuStubInt0(au_debug_test, void)
7735 +#endif /* CONFIG_AUFS_DEBUG */
7737 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7739 +/* ---------------------------------------------------------------------- */
7743 +#define AuDbg(fmt, ...) do { \
7744 + if (au_debug_test()) \
7745 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7747 +#define AuLabel(l) AuDbg(#l "\n")
7748 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7749 +#define AuWarn1(fmt, ...) do { \
7750 + static unsigned char _c; \
7752 + pr_warn(fmt, ##__VA_ARGS__); \
7755 +#define AuErr1(fmt, ...) do { \
7756 + static unsigned char _c; \
7758 + pr_err(fmt, ##__VA_ARGS__); \
7761 +#define AuIOErr1(fmt, ...) do { \
7762 + static unsigned char _c; \
7764 + AuIOErr(fmt, ##__VA_ARGS__); \
7767 +#define AuUnsupportMsg "This operation is not supported." \
7768 + " Please report this application to aufs-users ML."
7769 +#define AuUnsupport(fmt, ...) do { \
7770 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7774 +#define AuTraceErr(e) do { \
7775 + if (unlikely((e) < 0)) \
7776 + AuDbg("err %d\n", (int)(e)); \
7779 +#define AuTraceErrPtr(p) do { \
7781 + AuDbg("err %ld\n", PTR_ERR(p)); \
7784 +/* dirty macros for debug print, use with "%.*s" and caution */
7785 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7787 +/* ---------------------------------------------------------------------- */
7790 +#ifdef CONFIG_AUFS_DEBUG
7791 +extern struct mutex au_dbg_mtx;
7792 +extern char *au_plevel;
7794 +void au_dpri_whlist(struct au_nhash *whlist);
7796 +void au_dpri_vdir(struct au_vdir *vdir);
7798 +void au_dpri_inode(struct inode *inode);
7799 +void au_dpri_dalias(struct inode *inode);
7800 +void au_dpri_dentry(struct dentry *dentry);
7802 +void au_dpri_file(struct file *filp);
7803 +struct super_block;
7804 +void au_dpri_sb(struct super_block *sb);
7806 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7807 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7808 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7809 +void au_dbg_verify_kthread(void);
7811 +int __init au_debug_init(void);
7813 +#define AuDbgWhlist(w) do { \
7814 + mutex_lock(&au_dbg_mtx); \
7816 + au_dpri_whlist(w); \
7817 + mutex_unlock(&au_dbg_mtx); \
7820 +#define AuDbgVdir(v) do { \
7821 + mutex_lock(&au_dbg_mtx); \
7823 + au_dpri_vdir(v); \
7824 + mutex_unlock(&au_dbg_mtx); \
7827 +#define AuDbgInode(i) do { \
7828 + mutex_lock(&au_dbg_mtx); \
7830 + au_dpri_inode(i); \
7831 + mutex_unlock(&au_dbg_mtx); \
7834 +#define AuDbgDAlias(i) do { \
7835 + mutex_lock(&au_dbg_mtx); \
7837 + au_dpri_dalias(i); \
7838 + mutex_unlock(&au_dbg_mtx); \
7841 +#define AuDbgDentry(d) do { \
7842 + mutex_lock(&au_dbg_mtx); \
7844 + au_dpri_dentry(d); \
7845 + mutex_unlock(&au_dbg_mtx); \
7848 +#define AuDbgFile(f) do { \
7849 + mutex_lock(&au_dbg_mtx); \
7851 + au_dpri_file(f); \
7852 + mutex_unlock(&au_dbg_mtx); \
7855 +#define AuDbgSb(sb) do { \
7856 + mutex_lock(&au_dbg_mtx); \
7857 + AuDbg(#sb "\n"); \
7859 + mutex_unlock(&au_dbg_mtx); \
7862 +#define AuDbgSym(addr) do { \
7863 + char sym[KSYM_SYMBOL_LEN]; \
7864 + sprint_symbol(sym, (unsigned long)addr); \
7865 + AuDbg("%s\n", sym); \
7868 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7869 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7870 +AuStubVoid(au_dbg_verify_kthread, void)
7871 +AuStubInt0(__init au_debug_init, void)
7873 +#define AuDbgWhlist(w) do {} while (0)
7874 +#define AuDbgVdir(v) do {} while (0)
7875 +#define AuDbgInode(i) do {} while (0)
7876 +#define AuDbgDAlias(i) do {} while (0)
7877 +#define AuDbgDentry(d) do {} while (0)
7878 +#define AuDbgFile(f) do {} while (0)
7879 +#define AuDbgSb(sb) do {} while (0)
7880 +#define AuDbgSym(addr) do {} while (0)
7881 +#endif /* CONFIG_AUFS_DEBUG */
7883 +/* ---------------------------------------------------------------------- */
7885 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7886 +int __init au_sysrq_init(void);
7887 +void au_sysrq_fin(void);
7889 +#ifdef CONFIG_HW_CONSOLE
7890 +#define au_dbg_blocked() do { \
7892 + handle_sysrq('w'); \
7895 +AuStubVoid(au_dbg_blocked, void)
7899 +AuStubInt0(__init au_sysrq_init, void)
7900 +AuStubVoid(au_sysrq_fin, void)
7901 +AuStubVoid(au_dbg_blocked, void)
7902 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7904 +#endif /* __KERNEL__ */
7905 +#endif /* __AUFS_DEBUG_H__ */
7906 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7907 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7908 +++ linux/fs/aufs/dentry.c 2021-12-03 15:38:59.933313976 +0100
7910 +// SPDX-License-Identifier: GPL-2.0
7912 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7914 + * This program, aufs is free software; you can redistribute it and/or modify
7915 + * it under the terms of the GNU General Public License as published by
7916 + * the Free Software Foundation; either version 2 of the License, or
7917 + * (at your option) any later version.
7919 + * This program is distributed in the hope that it will be useful,
7920 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7921 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7922 + * GNU General Public License for more details.
7924 + * You should have received a copy of the GNU General Public License
7925 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7929 + * lookup and dentry operations
7932 +#include <linux/iversion.h>
7933 +#include <linux/namei.h>
7937 + * returns positive/negative dentry, NULL or an error.
7938 + * NULL means whiteout-ed or not-found.
7940 +static struct dentry*
7941 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7942 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7944 + struct dentry *h_dentry;
7945 + struct inode *h_inode;
7946 + struct au_branch *br;
7947 + struct path h_path;
7948 + int wh_found, opq;
7949 + unsigned char wh_able;
7950 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7951 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7955 + br = au_sbr(dentry->d_sb, bindex);
7956 + h_path.dentry = h_parent;
7957 + h_path.mnt = au_br_mnt(br);
7958 + wh_able = !!au_br_whable(br->br_perm);
7960 + wh_found = au_wh_test(&h_path, &args->whname, ignore_perm);
7961 + h_dentry = ERR_PTR(wh_found);
7964 + if (unlikely(wh_found < 0))
7967 + /* We found a whiteout */
7968 + /* au_set_dbbot(dentry, bindex); */
7969 + au_set_dbwh(dentry, bindex);
7971 + return NULL; /* success */
7975 + h_dentry = vfsub_lkup_one(args->name, &h_path);
7977 + h_dentry = au_sio_lkup_one(args->name, &h_path);
7978 + if (IS_ERR(h_dentry)) {
7979 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7985 + h_inode = d_inode(h_dentry);
7986 + if (d_is_negative(h_dentry)) {
7989 + } else if (wh_found
7990 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7992 + else if (au_ftest_lkup(args->flags, DIRREN)
7994 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
7995 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
7996 + (unsigned long long)h_inode->i_ino);
8000 + if (au_dbbot(dentry) <= bindex)
8001 + au_set_dbbot(dentry, bindex);
8002 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8003 + au_set_dbtop(dentry, bindex);
8004 + au_set_h_dptr(dentry, bindex, h_dentry);
8006 + if (!d_is_dir(h_dentry)
8008 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8009 + goto out; /* success */
8011 + h_path.dentry = h_dentry;
8012 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8013 + opq = au_diropq_test(&h_path);
8014 + inode_unlock_shared(h_inode);
8016 + au_set_dbdiropq(dentry, bindex);
8017 + else if (unlikely(opq < 0)) {
8018 + au_set_h_dptr(dentry, bindex, NULL);
8019 + h_dentry = ERR_PTR(opq);
8030 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8032 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8033 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8039 + * returns the number of lower positive dentries,
8040 + * otherwise an error.
8041 + * can be called at unlinking with @type is zero.
8043 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8044 + unsigned int flags)
8046 + int npositive, err;
8047 + aufs_bindex_t bindex, btail, bdiropq;
8048 + unsigned char isdir, dirperm1, dirren;
8049 + struct au_do_lookup_args args = {
8051 + .name = &dentry->d_name
8053 + struct dentry *parent;
8054 + struct super_block *sb;
8056 + sb = dentry->d_sb;
8057 + err = au_test_shwh(sb, args.name);
8058 + if (unlikely(err))
8061 + err = au_wh_name_alloc(&args.whname, args.name);
8062 + if (unlikely(err))
8065 + isdir = !!d_is_dir(dentry);
8066 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8067 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8069 + au_fset_lkup(args.flags, DIRREN);
8072 + parent = dget_parent(dentry);
8073 + btail = au_dbtaildir(parent);
8074 + for (bindex = btop; bindex <= btail; bindex++) {
8075 + struct dentry *h_parent, *h_dentry;
8076 + struct inode *h_inode, *h_dir;
8077 + struct au_branch *br;
8079 + h_dentry = au_h_dptr(dentry, bindex);
8081 + if (d_is_positive(h_dentry))
8085 + h_parent = au_h_dptr(parent, bindex);
8086 + if (!h_parent || !d_is_dir(h_parent))
8090 + /* if the inum matches, then use the prepared name */
8091 + err = au_dr_lkup_name(&args, bindex);
8092 + if (unlikely(err))
8096 + h_dir = d_inode(h_parent);
8097 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8098 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8099 + inode_unlock_shared(h_dir);
8100 + err = PTR_ERR(h_dentry);
8101 + if (IS_ERR(h_dentry))
8104 + au_fclr_lkup(args.flags, ALLOW_NEG);
8106 + au_fset_lkup(args.flags, IGNORE_PERM);
8108 + if (au_dbwh(dentry) == bindex)
8112 + if (d_is_negative(h_dentry))
8114 + h_inode = d_inode(h_dentry);
8117 + args.type = h_inode->i_mode & S_IFMT;
8118 + if (args.type != S_IFDIR)
8121 + /* the type of lower may be different */
8122 + bdiropq = au_dbdiropq(dentry);
8123 + if (bdiropq >= 0 && bdiropq <= bindex)
8126 + br = au_sbr(sb, bindex);
8128 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8129 + /*add_ent*/NULL)) {
8130 + /* prepare next name to lookup */
8131 + err = au_dr_lkup(&args, dentry, bindex);
8132 + if (unlikely(err))
8138 + AuLabel(positive);
8139 + au_update_dbtop(dentry);
8142 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8143 + && au_dbtop(dentry) < 0)) {
8145 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8151 + au_kfree_try_rcu(args.whname.name);
8153 + au_dr_lkup_fin(&args);
8158 +struct dentry *au_sio_lkup_one(struct qstr *name, struct path *ppath)
8160 + struct dentry *dentry;
8163 + if (!au_test_h_perm_sio(d_inode(ppath->dentry), MAY_EXEC))
8164 + dentry = vfsub_lkup_one(name, ppath);
8166 + struct vfsub_lkup_one_args args = {
8172 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8173 + if (unlikely(wkq_err))
8174 + dentry = ERR_PTR(wkq_err);
8181 + * lookup @dentry on @bindex which should be negative.
8183 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8186 + struct dentry *parent, *h_dentry;
8187 + struct au_branch *br;
8188 + struct path h_ppath;
8190 + parent = dget_parent(dentry);
8191 + br = au_sbr(dentry->d_sb, bindex);
8192 + h_ppath.dentry = au_h_dptr(parent, bindex);
8193 + h_ppath.mnt = au_br_mnt(br);
8195 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8197 + h_dentry = au_sio_lkup_one(&dentry->d_name, &h_ppath);
8198 + err = PTR_ERR(h_dentry);
8199 + if (IS_ERR(h_dentry))
8201 + if (unlikely(d_is_positive(h_dentry))) {
8203 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8209 + if (bindex < au_dbtop(dentry))
8210 + au_set_dbtop(dentry, bindex);
8211 + if (au_dbbot(dentry) < bindex)
8212 + au_set_dbbot(dentry, bindex);
8213 + au_set_h_dptr(dentry, bindex, h_dentry);
8220 +/* ---------------------------------------------------------------------- */
8222 +/* subset of struct inode */
8224 + unsigned long i_ino;
8225 + /* unsigned int i_nlink; */
8231 + blkcnt_t i_blocks;
8236 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8238 + ia->i_ino = h_inode->i_ino;
8239 + /* ia->i_nlink = h_inode->i_nlink; */
8240 + ia->i_uid = h_inode->i_uid;
8241 + ia->i_gid = h_inode->i_gid;
8242 + ia->i_version = inode_query_iversion(h_inode);
8244 + ia->i_size = h_inode->i_size;
8245 + ia->i_blocks = h_inode->i_blocks;
8247 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8250 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8252 + return ia->i_ino != h_inode->i_ino
8253 + /* || ia->i_nlink != h_inode->i_nlink */
8254 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8255 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8256 + || !inode_eq_iversion(h_inode, ia->i_version)
8258 + || ia->i_size != h_inode->i_size
8259 + || ia->i_blocks != h_inode->i_blocks
8261 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8264 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8265 + struct au_branch *br)
8268 + struct au_iattr ia;
8269 + struct inode *h_inode;
8270 + struct dentry *h_d;
8271 + struct super_block *h_sb;
8272 + struct path h_ppath;
8275 + memset(&ia, -1, sizeof(ia));
8276 + h_sb = h_dentry->d_sb;
8278 + if (d_is_positive(h_dentry)) {
8279 + h_inode = d_inode(h_dentry);
8280 + au_iattr_save(&ia, h_inode);
8281 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8282 + /* nfs d_revalidate may return 0 for negative dentry */
8283 + /* fuse d_revalidate always return 0 for negative dentry */
8286 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8287 + h_ppath.dentry = h_parent;
8288 + h_ppath.mnt = au_br_mnt(br);
8289 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8290 + err = PTR_ERR(h_d);
8295 + if (unlikely(h_d != h_dentry
8296 + || d_inode(h_d) != h_inode
8297 + || (h_inode && au_iattr_test(&ia, h_inode))))
8298 + err = au_busy_or_stale();
8306 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8307 + struct dentry *h_parent, struct au_branch *br)
8312 + if (udba == AuOpt_UDBA_REVAL
8313 + && !au_test_fs_remote(h_dentry->d_sb)) {
8315 + err = (d_inode(h_dentry->d_parent) != h_dir);
8316 + } else if (udba != AuOpt_UDBA_NONE)
8317 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8322 +/* ---------------------------------------------------------------------- */
8324 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8327 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8328 + struct au_hdentry tmp, *p, *q;
8329 + struct au_dinfo *dinfo;
8330 + struct super_block *sb;
8332 + DiMustWriteLock(dentry);
8334 + sb = dentry->d_sb;
8335 + dinfo = au_di(dentry);
8336 + bbot = dinfo->di_bbot;
8337 + bwh = dinfo->di_bwh;
8338 + bdiropq = dinfo->di_bdiropq;
8339 + bindex = dinfo->di_btop;
8340 + p = au_hdentry(dinfo, bindex);
8341 + for (; bindex <= bbot; bindex++, p++) {
8342 + if (!p->hd_dentry)
8345 + new_bindex = au_br_index(sb, p->hd_id);
8346 + if (new_bindex == bindex)
8349 + if (dinfo->di_bwh == bindex)
8351 + if (dinfo->di_bdiropq == bindex)
8352 + bdiropq = new_bindex;
8353 + if (new_bindex < 0) {
8355 + p->hd_dentry = NULL;
8359 + /* swap two lower dentries, and loop again */
8360 + q = au_hdentry(dinfo, new_bindex);
8364 + if (tmp.hd_dentry) {
8370 + dinfo->di_bwh = -1;
8371 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8372 + dinfo->di_bwh = bwh;
8374 + dinfo->di_bdiropq = -1;
8376 + && bdiropq <= au_sbbot(sb)
8377 + && au_sbr_whable(sb, bdiropq))
8378 + dinfo->di_bdiropq = bdiropq;
8381 + dinfo->di_btop = -1;
8382 + dinfo->di_bbot = -1;
8383 + bbot = au_dbbot(parent);
8385 + p = au_hdentry(dinfo, bindex);
8386 + for (; bindex <= bbot; bindex++, p++)
8387 + if (p->hd_dentry) {
8388 + dinfo->di_btop = bindex;
8392 + if (dinfo->di_btop >= 0) {
8394 + p = au_hdentry(dinfo, bindex);
8395 + for (; bindex >= 0; bindex--, p--)
8396 + if (p->hd_dentry) {
8397 + dinfo->di_bbot = bindex;
8406 +static void au_do_hide(struct dentry *dentry)
8408 + struct inode *inode;
8410 + if (d_really_is_positive(dentry)) {
8411 + inode = d_inode(dentry);
8412 + if (!d_is_dir(dentry)) {
8413 + if (inode->i_nlink && !d_unhashed(dentry))
8414 + drop_nlink(inode);
8416 + clear_nlink(inode);
8417 + /* stop next lookup */
8418 + inode->i_flags |= S_DEAD;
8420 + smp_mb(); /* necessary? */
8425 +static int au_hide_children(struct dentry *parent)
8427 + int err, i, j, ndentry;
8428 + struct au_dcsub_pages dpages;
8429 + struct au_dpage *dpage;
8430 + struct dentry *dentry;
8432 + err = au_dpages_init(&dpages, GFP_NOFS);
8433 + if (unlikely(err))
8435 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8436 + if (unlikely(err))
8439 + /* in reverse order */
8440 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8441 + dpage = dpages.dpages + i;
8442 + ndentry = dpage->ndentry;
8443 + for (j = ndentry - 1; j >= 0; j--) {
8444 + dentry = dpage->dentries[j];
8445 + if (dentry != parent)
8446 + au_do_hide(dentry);
8451 + au_dpages_free(&dpages);
8456 +static void au_hide(struct dentry *dentry)
8460 + AuDbgDentry(dentry);
8461 + if (d_is_dir(dentry)) {
8462 + /* shrink_dcache_parent(dentry); */
8463 + err = au_hide_children(dentry);
8464 + if (unlikely(err))
8465 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8468 + au_do_hide(dentry);
8472 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8474 + * a dirty branch is added
8475 + * - on the top of layers
8476 + * - in the middle of layers
8477 + * - to the bottom of layers
8479 + * on the added branch there exists
8482 + * - a same named entry
8484 + * * negative --> positive
8485 + * * positive --> positive
8486 + * - type is unchanged
8487 + * - type is changed
8489 + * * negative --> negative
8490 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8493 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8494 + struct au_dinfo *tmp)
8497 + aufs_bindex_t bindex, bbot;
8499 + struct dentry *dentry;
8500 + struct inode *inode;
8502 + } orig_h, tmp_h = {
8505 + struct au_hdentry *hd;
8506 + struct inode *inode, *h_inode;
8507 + struct dentry *h_dentry;
8510 + AuDebugOn(dinfo->di_btop < 0);
8512 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8513 + orig_h.inode = NULL;
8514 + if (d_is_positive(orig_h.dentry)) {
8515 + orig_h.inode = d_inode(orig_h.dentry);
8516 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8518 + if (tmp->di_btop >= 0) {
8519 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8520 + if (d_is_positive(tmp_h.dentry)) {
8521 + tmp_h.inode = d_inode(tmp_h.dentry);
8522 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8527 + if (d_really_is_positive(dentry))
8528 + inode = d_inode(dentry);
8529 + if (!orig_h.inode) {
8530 + AuDbg("negative originally\n");
8536 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8537 + AuDebugOn(dinfo->di_bdiropq != -1);
8539 + if (!tmp_h.inode) {
8540 + AuDbg("negative --> negative\n");
8541 + /* should have only one negative lower */
8542 + if (tmp->di_btop >= 0
8543 + && tmp->di_btop < dinfo->di_btop) {
8544 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8545 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8546 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8547 + au_di_cp(dinfo, tmp);
8548 + hd = au_hdentry(tmp, tmp->di_btop);
8549 + au_set_h_dptr(dentry, tmp->di_btop,
8550 + dget(hd->hd_dentry));
8552 + au_dbg_verify_dinode(dentry);
8554 + AuDbg("negative --> positive\n");
8556 + * similar to the behaviour of creating with bypassing
8558 + * unhash it in order to force an error in the
8559 + * succeeding create operation.
8560 + * we should not set S_DEAD here.
8563 + /* au_di_swap(tmp, dinfo); */
8564 + au_dbg_verify_dinode(dentry);
8567 + AuDbg("positive originally\n");
8568 + /* inode may be NULL */
8569 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8570 + if (!tmp_h.inode) {
8571 + AuDbg("positive --> negative\n");
8572 + /* or bypassing aufs */
8574 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8575 + dinfo->di_bwh = tmp->di_bwh;
8577 + err = au_refresh_hinode_self(inode);
8578 + au_dbg_verify_dinode(dentry);
8579 + } else if (orig_h.mode == tmp_h.mode) {
8580 + AuDbg("positive --> positive, same type\n");
8581 + if (!S_ISDIR(orig_h.mode)
8582 + && dinfo->di_btop > tmp->di_btop) {
8584 + * similar to the behaviour of removing and
8589 + err = au_refresh_hinode_self(inode);
8590 + au_dbg_verify_dinode(dentry);
8592 + /* fill empty slots */
8593 + if (dinfo->di_btop > tmp->di_btop)
8594 + dinfo->di_btop = tmp->di_btop;
8595 + if (dinfo->di_bbot < tmp->di_bbot)
8596 + dinfo->di_bbot = tmp->di_bbot;
8597 + dinfo->di_bwh = tmp->di_bwh;
8598 + dinfo->di_bdiropq = tmp->di_bdiropq;
8599 + bbot = dinfo->di_bbot;
8600 + bindex = tmp->di_btop;
8601 + hd = au_hdentry(tmp, bindex);
8602 + for (; bindex <= bbot; bindex++, hd++) {
8603 + if (au_h_dptr(dentry, bindex))
8605 + h_dentry = hd->hd_dentry;
8608 + AuDebugOn(d_is_negative(h_dentry));
8609 + h_inode = d_inode(h_dentry);
8610 + AuDebugOn(orig_h.mode
8611 + != (h_inode->i_mode
8613 + au_set_h_dptr(dentry, bindex,
8617 + err = au_refresh_hinode(inode, dentry);
8618 + au_dbg_verify_dinode(dentry);
8621 + AuDbg("positive --> positive, different type\n");
8622 + /* similar to the behaviour of removing and creating */
8625 + err = au_refresh_hinode_self(inode);
8626 + au_dbg_verify_dinode(dentry);
8634 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8636 + const struct dentry_operations *dop
8637 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8638 + static const unsigned int mask
8639 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8641 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8643 + if (dentry->d_op == dop)
8646 + AuDbg("%pd\n", dentry);
8647 + spin_lock(&dentry->d_lock);
8648 + if (dop == &aufs_dop)
8649 + dentry->d_flags |= mask;
8651 + dentry->d_flags &= ~mask;
8652 + dentry->d_op = dop;
8653 + spin_unlock(&dentry->d_lock);
8656 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8658 + int err, ebrange, nbr;
8659 + unsigned int sigen;
8660 + struct au_dinfo *dinfo, *tmp;
8661 + struct super_block *sb;
8662 + struct inode *inode;
8664 + DiMustWriteLock(dentry);
8665 + AuDebugOn(IS_ROOT(dentry));
8666 + AuDebugOn(d_really_is_negative(parent));
8668 + sb = dentry->d_sb;
8669 + sigen = au_sigen(sb);
8670 + err = au_digen_test(parent, sigen);
8671 + if (unlikely(err))
8674 + nbr = au_sbbot(sb) + 1;
8675 + dinfo = au_di(dentry);
8676 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8677 + if (unlikely(err))
8679 + ebrange = au_dbrange_test(dentry);
8681 + ebrange = au_do_refresh_hdentry(dentry, parent);
8683 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8684 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8685 + if (d_really_is_positive(dentry)) {
8686 + inode = d_inode(dentry);
8687 + err = au_refresh_hinode_self(inode);
8689 + au_dbg_verify_dinode(dentry);
8691 + goto out_dgen; /* success */
8695 + /* temporary dinfo */
8696 + AuDbgDentry(dentry);
8698 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8699 + if (unlikely(!tmp))
8701 + au_di_swap(tmp, dinfo);
8702 + /* returns the number of positive dentries */
8704 + * if current working dir is removed, it returns an error.
8705 + * but the dentry is legal.
8707 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8708 + AuDbgDentry(dentry);
8709 + au_di_swap(tmp, dinfo);
8710 + if (err == -ENOENT)
8713 + /* compare/refresh by dinfo */
8714 + AuDbgDentry(dentry);
8715 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8716 + au_dbg_verify_dinode(dentry);
8719 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8720 + au_rw_write_unlock(&tmp->di_rwsem);
8722 + if (unlikely(err))
8726 + au_update_digen(dentry);
8728 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8729 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8730 + AuDbgDentry(dentry);
8736 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8737 + struct dentry *dentry, aufs_bindex_t bindex)
8742 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8745 + AuDbg("b%d\n", bindex);
8747 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8748 + * due to whiteout and branch permission.
8750 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8751 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8752 + /* it may return tri-state */
8753 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8755 + if (unlikely(valid < 0))
8765 +/* todo: remove this */
8766 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8767 + unsigned int flags, int do_udba, int dirren)
8770 + umode_t mode, h_mode;
8771 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8772 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8773 + struct inode *h_inode, *h_cached_inode;
8774 + struct dentry *h_dentry;
8775 + struct qstr *name, *h_name;
8782 + unhashed = !!d_unhashed(dentry);
8783 + is_root = !!IS_ROOT(dentry);
8784 + name = &dentry->d_name;
8785 + tmpfile = au_di(dentry)->di_tmpfile;
8788 + * Theoretically, REVAL test should be unnecessary in case of
8790 + * But {fs,i}notify doesn't fire some necessary events,
8791 + * IN_ATTRIB for atime/nlink/pageio
8792 + * Let's do REVAL test too.
8794 + if (do_udba && inode) {
8795 + mode = (inode->i_mode & S_IFMT);
8796 + plus = (inode->i_nlink > 0);
8797 + ibs = au_ibtop(inode);
8798 + ibe = au_ibbot(inode);
8801 + btop = au_dbtop(dentry);
8803 + if (inode && S_ISDIR(inode->i_mode))
8804 + btail = au_dbtaildir(dentry);
8805 + for (bindex = btop; bindex <= btail; bindex++) {
8806 + h_dentry = au_h_dptr(dentry, bindex);
8810 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8811 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8812 + spin_lock(&h_dentry->d_lock);
8813 + h_name = &h_dentry->d_name;
8814 + if (unlikely(do_udba
8817 + && (unhashed != !!d_unhashed(h_dentry)
8818 + || (!tmpfile && !dirren
8819 + && !au_qstreq(name, h_name))
8822 + && !(flags & LOOKUP_OPEN)
8823 + && (h_dentry->d_flags
8824 + & DCACHE_NFSFS_RENAMED)))
8828 + h_unhashed = d_unhashed(h_dentry);
8829 + spin_unlock(&h_dentry->d_lock);
8830 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8831 + unhashed, h_unhashed, dentry, h_dentry);
8834 + spin_unlock(&h_dentry->d_lock);
8836 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8837 + if (unlikely(err))
8838 + /* do not goto err, to keep the errno */
8841 + /* todo: plink too? */
8846 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8850 + if (d_is_positive(h_dentry))
8851 + h_inode = d_inode(h_dentry);
8854 + h_cached_inode = h_inode;
8856 + h_mode = (h_inode->i_mode & S_IFMT);
8857 + h_plus = (h_inode->i_nlink > 0);
8859 + if (inode && ibs <= bindex && bindex <= ibe)
8860 + h_cached_inode = au_h_iptr(inode, bindex);
8863 + if (unlikely(plus != h_plus && !tmpfile))
8866 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8868 + && !IS_ROOT(h_dentry)
8869 + && unhashed != d_unhashed(h_dentry)))
8872 + if (unlikely(mode != h_mode
8873 + || h_cached_inode != h_inode))
8886 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8887 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8890 + struct dentry *parent;
8892 + if (!au_digen_test(dentry, sigen))
8895 + parent = dget_parent(dentry);
8896 + di_read_lock_parent(parent, AuLock_IR);
8897 + AuDebugOn(au_digen_test(parent, sigen));
8898 + au_dbg_verify_gen(parent, sigen);
8899 + err = au_refresh_dentry(dentry, parent);
8900 + di_read_unlock(parent, AuLock_IR);
8906 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8909 + struct dentry *d, *parent;
8911 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8912 + return simple_reval_dpath(dentry, sigen);
8914 + /* slow loop, keep it simple and stupid */
8915 + /* cf: au_cpup_dirs() */
8918 + while (au_digen_test(dentry, sigen)) {
8922 + parent = dget_parent(d);
8923 + if (!au_digen_test(parent, sigen))
8929 + di_write_lock_child2(d);
8931 + /* someone might update our dentry while we were sleeping */
8932 + if (au_digen_test(d, sigen)) {
8934 + * todo: consolidate with simple_reval_dpath(),
8935 + * do_refresh() and au_reval_for_attr().
8937 + di_read_lock_parent(parent, AuLock_IR);
8938 + err = au_refresh_dentry(d, parent);
8939 + di_read_unlock(parent, AuLock_IR);
8943 + di_write_unlock(d);
8945 + if (unlikely(err))
8953 + * if valid returns 1, otherwise 0.
8955 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8958 + unsigned int sigen;
8959 + unsigned char do_udba, dirren;
8960 + struct super_block *sb;
8961 + struct inode *inode;
8963 + /* todo: support rcu-walk? */
8964 + if (flags & LOOKUP_RCU)
8968 + if (unlikely(!au_di(dentry)))
8972 + sb = dentry->d_sb;
8975 + * i_mutex of parent dir may be held,
8976 + * but we should not return 'invalid' due to busy.
8978 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8979 + if (unlikely(err)) {
8985 + if (d_really_is_positive(dentry))
8986 + inode = d_inode(dentry);
8987 + if (unlikely(inode && au_is_bad_inode(inode))) {
8992 + if (unlikely(au_dbrange_test(dentry))) {
8998 + sigen = au_sigen(sb);
8999 + if (au_digen_test(dentry, sigen)) {
9000 + AuDebugOn(IS_ROOT(dentry));
9001 + err = au_reval_dpath(dentry, sigen);
9002 + if (unlikely(err)) {
9007 + di_downgrade_lock(dentry, AuLock_IR);
9010 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9012 + && !(inode->i_state && I_LINKABLE)
9013 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9018 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9019 + if (do_udba && inode) {
9020 + aufs_bindex_t btop = au_ibtop(inode);
9021 + struct inode *h_inode;
9024 + h_inode = au_h_iptr(inode, btop);
9025 + if (h_inode && au_test_higen(inode, h_inode)) {
9032 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9033 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9034 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9036 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9042 + di_downgrade_lock(dentry, AuLock_IR);
9044 + aufs_read_unlock(dentry, AuLock_IR);
9049 + AuDbg("%pd invalid, %d\n", dentry, valid);
9055 +static void aufs_d_release(struct dentry *dentry)
9057 + if (au_di(dentry)) {
9058 + au_di_fin(dentry);
9059 + au_hn_di_reinit(dentry);
9063 +const struct dentry_operations aufs_dop = {
9064 + .d_revalidate = aufs_d_revalidate,
9065 + .d_weak_revalidate = aufs_d_revalidate,
9066 + .d_release = aufs_d_release
9069 +/* aufs_dop without d_revalidate */
9070 +const struct dentry_operations aufs_dop_noreval = {
9071 + .d_release = aufs_d_release
9073 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9074 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9075 +++ linux/fs/aufs/dentry.h 2021-12-03 15:38:59.933313976 +0100
9077 +/* SPDX-License-Identifier: GPL-2.0 */
9079 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9081 + * This program, aufs is free software; you can redistribute it and/or modify
9082 + * it under the terms of the GNU General Public License as published by
9083 + * the Free Software Foundation; either version 2 of the License, or
9084 + * (at your option) any later version.
9086 + * This program is distributed in the hope that it will be useful,
9087 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9088 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9089 + * GNU General Public License for more details.
9091 + * You should have received a copy of the GNU General Public License
9092 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9096 + * lookup and dentry operations
9099 +#ifndef __AUFS_DENTRY_H__
9100 +#define __AUFS_DENTRY_H__
9104 +#include <linux/dcache.h>
9105 +#include "dirren.h"
9108 +struct au_hdentry {
9109 + struct dentry *hd_dentry;
9110 + aufs_bindex_t hd_id;
9114 + atomic_t di_generation;
9116 + struct au_rwsem di_rwsem;
9117 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9118 + unsigned char di_tmpfile; /* to allow the different name */
9119 + struct au_hdentry *di_hdentry;
9120 + struct rcu_head rcu;
9121 +} ____cacheline_aligned_in_smp;
9123 +/* ---------------------------------------------------------------------- */
9125 +/* flags for au_lkup_dentry() */
9126 +#define AuLkup_ALLOW_NEG 1
9127 +#define AuLkup_IGNORE_PERM (1 << 1)
9128 +#define AuLkup_DIRREN (1 << 2)
9129 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9130 +#define au_fset_lkup(flags, name) \
9131 + do { (flags) |= AuLkup_##name; } while (0)
9132 +#define au_fclr_lkup(flags, name) \
9133 + do { (flags) &= ~AuLkup_##name; } while (0)
9135 +#ifndef CONFIG_AUFS_DIRREN
9136 +#undef AuLkup_DIRREN
9137 +#define AuLkup_DIRREN 0
9140 +struct au_do_lookup_args {
9141 + unsigned int flags;
9143 + struct qstr whname, *name;
9144 + struct au_dr_lookup dirren;
9147 +/* ---------------------------------------------------------------------- */
9150 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9152 +struct dentry *au_sio_lkup_one(struct qstr *name, struct path *ppath);
9153 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9154 + struct dentry *h_parent, struct au_branch *br);
9156 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9157 + unsigned int flags);
9158 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9159 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9160 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9161 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9164 +void au_di_init_once(void *_di);
9165 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9166 +void au_di_free(struct au_dinfo *dinfo);
9167 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9168 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9169 +int au_di_init(struct dentry *dentry);
9170 +void au_di_fin(struct dentry *dentry);
9171 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9173 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9174 +void di_read_unlock(struct dentry *d, int flags);
9175 +void di_downgrade_lock(struct dentry *d, int flags);
9176 +void di_write_lock(struct dentry *d, unsigned int lsc);
9177 +void di_write_unlock(struct dentry *d);
9178 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9179 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9180 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9182 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9183 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9184 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9185 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9187 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9188 + struct dentry *h_dentry);
9189 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9190 +int au_dbrange_test(struct dentry *dentry);
9191 +void au_update_digen(struct dentry *dentry);
9192 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9193 +void au_update_dbtop(struct dentry *dentry);
9194 +void au_update_dbbot(struct dentry *dentry);
9195 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9197 +/* ---------------------------------------------------------------------- */
9199 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9201 + return dentry->d_fsdata;
9204 +/* ---------------------------------------------------------------------- */
9206 +/* lock subclass for dinfo */
9208 + AuLsc_DI_CHILD, /* child first */
9209 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9210 + AuLsc_DI_CHILD3, /* copyup dirs */
9214 + AuLsc_DI_TMP /* temp for replacing dinfo */
9218 + * di_read_lock_child, di_write_lock_child,
9219 + * di_read_lock_child2, di_write_lock_child2,
9220 + * di_read_lock_child3, di_write_lock_child3,
9221 + * di_read_lock_parent, di_write_lock_parent,
9222 + * di_read_lock_parent2, di_write_lock_parent2,
9223 + * di_read_lock_parent3, di_write_lock_parent3,
9225 +#define AuReadLockFunc(name, lsc) \
9226 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9227 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9229 +#define AuWriteLockFunc(name, lsc) \
9230 +static inline void di_write_lock_##name(struct dentry *d) \
9231 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9233 +#define AuRWLockFuncs(name, lsc) \
9234 + AuReadLockFunc(name, lsc) \
9235 + AuWriteLockFunc(name, lsc)
9237 +AuRWLockFuncs(child, CHILD);
9238 +AuRWLockFuncs(child2, CHILD2);
9239 +AuRWLockFuncs(child3, CHILD3);
9240 +AuRWLockFuncs(parent, PARENT);
9241 +AuRWLockFuncs(parent2, PARENT2);
9242 +AuRWLockFuncs(parent3, PARENT3);
9244 +#undef AuReadLockFunc
9245 +#undef AuWriteLockFunc
9246 +#undef AuRWLockFuncs
9248 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9249 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9250 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9252 +/* ---------------------------------------------------------------------- */
9254 +/* todo: memory barrier? */
9255 +static inline unsigned int au_digen(struct dentry *d)
9257 + return atomic_read(&au_di(d)->di_generation);
9260 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9262 + hdentry->hd_dentry = NULL;
9265 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9266 + aufs_bindex_t bindex)
9268 + return di->di_hdentry + bindex;
9271 +static inline void au_hdput(struct au_hdentry *hd)
9274 + dput(hd->hd_dentry);
9277 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9279 + DiMustAnyLock(dentry);
9280 + return au_di(dentry)->di_btop;
9283 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9285 + DiMustAnyLock(dentry);
9286 + return au_di(dentry)->di_bbot;
9289 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9291 + DiMustAnyLock(dentry);
9292 + return au_di(dentry)->di_bwh;
9295 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9297 + DiMustAnyLock(dentry);
9298 + return au_di(dentry)->di_bdiropq;
9301 +/* todo: hard/soft set? */
9302 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9304 + DiMustWriteLock(dentry);
9305 + au_di(dentry)->di_btop = bindex;
9308 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9310 + DiMustWriteLock(dentry);
9311 + au_di(dentry)->di_bbot = bindex;
9314 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9316 + DiMustWriteLock(dentry);
9317 + /* dbwh can be outside of btop - bbot range */
9318 + au_di(dentry)->di_bwh = bindex;
9321 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9323 + DiMustWriteLock(dentry);
9324 + au_di(dentry)->di_bdiropq = bindex;
9327 +/* ---------------------------------------------------------------------- */
9329 +#ifdef CONFIG_AUFS_HNOTIFY
9330 +static inline void au_digen_dec(struct dentry *d)
9332 + atomic_dec(&au_di(d)->di_generation);
9335 +static inline void au_hn_di_reinit(struct dentry *dentry)
9337 + dentry->d_fsdata = NULL;
9340 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9341 +#endif /* CONFIG_AUFS_HNOTIFY */
9343 +#endif /* __KERNEL__ */
9344 +#endif /* __AUFS_DENTRY_H__ */
9345 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9346 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9347 +++ linux/fs/aufs/dinfo.c 2021-12-03 15:38:59.933313976 +0100
9349 +// SPDX-License-Identifier: GPL-2.0
9351 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9353 + * This program, aufs is free software; you can redistribute it and/or modify
9354 + * it under the terms of the GNU General Public License as published by
9355 + * the Free Software Foundation; either version 2 of the License, or
9356 + * (at your option) any later version.
9358 + * This program is distributed in the hope that it will be useful,
9359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9361 + * GNU General Public License for more details.
9363 + * You should have received a copy of the GNU General Public License
9364 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9368 + * dentry private data
9373 +void au_di_init_once(void *_dinfo)
9375 + struct au_dinfo *dinfo = _dinfo;
9377 + au_rw_init(&dinfo->di_rwsem);
9380 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9382 + struct au_dinfo *dinfo;
9385 + dinfo = au_cache_alloc_dinfo();
9386 + if (unlikely(!dinfo))
9389 + nbr = au_sbbot(sb) + 1;
9392 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9393 + if (dinfo->di_hdentry) {
9394 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9395 + dinfo->di_btop = -1;
9396 + dinfo->di_bbot = -1;
9397 + dinfo->di_bwh = -1;
9398 + dinfo->di_bdiropq = -1;
9399 + dinfo->di_tmpfile = 0;
9400 + for (i = 0; i < nbr; i++)
9401 + dinfo->di_hdentry[i].hd_id = -1;
9405 + au_cache_free_dinfo(dinfo);
9412 +void au_di_free(struct au_dinfo *dinfo)
9414 + struct au_hdentry *p;
9415 + aufs_bindex_t bbot, bindex;
9417 + /* dentry may not be revalidated */
9418 + bindex = dinfo->di_btop;
9419 + if (bindex >= 0) {
9420 + bbot = dinfo->di_bbot;
9421 + p = au_hdentry(dinfo, bindex);
9422 + while (bindex++ <= bbot)
9425 + au_kfree_try_rcu(dinfo->di_hdentry);
9426 + au_cache_free_dinfo(dinfo);
9429 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9431 + struct au_hdentry *p;
9434 + AuRwMustWriteLock(&a->di_rwsem);
9435 + AuRwMustWriteLock(&b->di_rwsem);
9437 +#define DiSwap(v, name) \
9439 + v = a->di_##name; \
9440 + a->di_##name = b->di_##name; \
9441 + b->di_##name = v; \
9444 + DiSwap(p, hdentry);
9448 + DiSwap(bi, bdiropq);
9454 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9456 + AuRwMustWriteLock(&dst->di_rwsem);
9457 + AuRwMustWriteLock(&src->di_rwsem);
9459 + dst->di_btop = src->di_btop;
9460 + dst->di_bbot = src->di_bbot;
9461 + dst->di_bwh = src->di_bwh;
9462 + dst->di_bdiropq = src->di_bdiropq;
9466 +int au_di_init(struct dentry *dentry)
9469 + struct super_block *sb;
9470 + struct au_dinfo *dinfo;
9473 + sb = dentry->d_sb;
9474 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9476 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9477 + /* smp_mb(); */ /* atomic_set */
9478 + dentry->d_fsdata = dinfo;
9485 +void au_di_fin(struct dentry *dentry)
9487 + struct au_dinfo *dinfo;
9489 + dinfo = au_di(dentry);
9490 + AuRwDestroy(&dinfo->di_rwsem);
9491 + au_di_free(dinfo);
9494 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9497 + struct au_hdentry *hdp;
9499 + AuRwMustWriteLock(&dinfo->di_rwsem);
9502 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9504 + sz = sizeof(*hdp);
9505 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9508 + dinfo->di_hdentry = hdp;
9515 +/* ---------------------------------------------------------------------- */
9517 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9520 + case AuLsc_DI_CHILD:
9521 + ii_write_lock_child(inode);
9523 + case AuLsc_DI_CHILD2:
9524 + ii_write_lock_child2(inode);
9526 + case AuLsc_DI_CHILD3:
9527 + ii_write_lock_child3(inode);
9529 + case AuLsc_DI_PARENT:
9530 + ii_write_lock_parent(inode);
9532 + case AuLsc_DI_PARENT2:
9533 + ii_write_lock_parent2(inode);
9535 + case AuLsc_DI_PARENT3:
9536 + ii_write_lock_parent3(inode);
9543 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9546 + case AuLsc_DI_CHILD:
9547 + ii_read_lock_child(inode);
9549 + case AuLsc_DI_CHILD2:
9550 + ii_read_lock_child2(inode);
9552 + case AuLsc_DI_CHILD3:
9553 + ii_read_lock_child3(inode);
9555 + case AuLsc_DI_PARENT:
9556 + ii_read_lock_parent(inode);
9558 + case AuLsc_DI_PARENT2:
9559 + ii_read_lock_parent2(inode);
9561 + case AuLsc_DI_PARENT3:
9562 + ii_read_lock_parent3(inode);
9569 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9571 + struct inode *inode;
9573 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9574 + if (d_really_is_positive(d)) {
9575 + inode = d_inode(d);
9576 + if (au_ftest_lock(flags, IW))
9577 + do_ii_write_lock(inode, lsc);
9578 + else if (au_ftest_lock(flags, IR))
9579 + do_ii_read_lock(inode, lsc);
9583 +void di_read_unlock(struct dentry *d, int flags)
9585 + struct inode *inode;
9587 + if (d_really_is_positive(d)) {
9588 + inode = d_inode(d);
9589 + if (au_ftest_lock(flags, IW)) {
9590 + au_dbg_verify_dinode(d);
9591 + ii_write_unlock(inode);
9592 + } else if (au_ftest_lock(flags, IR)) {
9593 + au_dbg_verify_dinode(d);
9594 + ii_read_unlock(inode);
9597 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9600 +void di_downgrade_lock(struct dentry *d, int flags)
9602 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9603 + ii_downgrade_lock(d_inode(d));
9604 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9607 +void di_write_lock(struct dentry *d, unsigned int lsc)
9609 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9610 + if (d_really_is_positive(d))
9611 + do_ii_write_lock(d_inode(d), lsc);
9614 +void di_write_unlock(struct dentry *d)
9616 + au_dbg_verify_dinode(d);
9617 + if (d_really_is_positive(d))
9618 + ii_write_unlock(d_inode(d));
9619 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9622 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9624 + AuDebugOn(d1 == d2
9625 + || d_inode(d1) == d_inode(d2)
9626 + || d1->d_sb != d2->d_sb);
9628 + if ((isdir && au_test_subdir(d1, d2))
9630 + di_write_lock_child(d1);
9631 + di_write_lock_child2(d2);
9633 + di_write_lock_child(d2);
9634 + di_write_lock_child2(d1);
9638 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9640 + AuDebugOn(d1 == d2
9641 + || d_inode(d1) == d_inode(d2)
9642 + || d1->d_sb != d2->d_sb);
9644 + if ((isdir && au_test_subdir(d1, d2))
9646 + di_write_lock_parent(d1);
9647 + di_write_lock_parent2(d2);
9649 + di_write_lock_parent(d2);
9650 + di_write_lock_parent2(d1);
9654 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9656 + di_write_unlock(d1);
9657 + if (d_inode(d1) == d_inode(d2))
9658 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9660 + di_write_unlock(d2);
9663 +/* ---------------------------------------------------------------------- */
9665 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9669 + DiMustAnyLock(dentry);
9671 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9673 + AuDebugOn(bindex < 0);
9674 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9675 + AuDebugOn(d && au_dcount(d) <= 0);
9680 + * extended version of au_h_dptr().
9681 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9684 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9686 + struct dentry *h_dentry;
9687 + struct inode *inode, *h_inode;
9689 + AuDebugOn(d_really_is_negative(dentry));
9692 + if (au_dbtop(dentry) <= bindex
9693 + && bindex <= au_dbbot(dentry))
9694 + h_dentry = au_h_dptr(dentry, bindex);
9695 + if (h_dentry && !au_d_linkable(h_dentry)) {
9697 + goto out; /* success */
9700 + inode = d_inode(dentry);
9701 + AuDebugOn(bindex < au_ibtop(inode));
9702 + AuDebugOn(au_ibbot(inode) < bindex);
9703 + h_inode = au_h_iptr(inode, bindex);
9704 + h_dentry = d_find_alias(h_inode);
9706 + if (!IS_ERR(h_dentry)) {
9707 + if (!au_d_linkable(h_dentry))
9708 + goto out; /* success */
9714 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9715 + h_dentry = au_plink_lkup(inode, bindex);
9716 + AuDebugOn(!h_dentry);
9717 + if (!IS_ERR(h_dentry)) {
9718 + if (!au_d_hashed_positive(h_dentry))
9719 + goto out; /* success */
9726 + AuDbgDentry(h_dentry);
9730 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9732 + aufs_bindex_t bbot, bwh;
9734 + bbot = au_dbbot(dentry);
9736 + bwh = au_dbwh(dentry);
9739 + if (0 < bwh && bwh < bbot)
9745 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9747 + aufs_bindex_t bbot, bopq;
9749 + bbot = au_dbtail(dentry);
9751 + bopq = au_dbdiropq(dentry);
9752 + if (0 <= bopq && bopq < bbot)
9758 +/* ---------------------------------------------------------------------- */
9760 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9761 + struct dentry *h_dentry)
9763 + struct au_dinfo *dinfo;
9764 + struct au_hdentry *hd;
9765 + struct au_branch *br;
9767 + DiMustWriteLock(dentry);
9769 + dinfo = au_di(dentry);
9770 + hd = au_hdentry(dinfo, bindex);
9772 + hd->hd_dentry = h_dentry;
9774 + br = au_sbr(dentry->d_sb, bindex);
9775 + hd->hd_id = br->br_id;
9779 +int au_dbrange_test(struct dentry *dentry)
9782 + aufs_bindex_t btop, bbot;
9785 + btop = au_dbtop(dentry);
9786 + bbot = au_dbbot(dentry);
9788 + AuDebugOn(bbot < 0 && btop > bbot);
9791 + AuDebugOn(bbot >= 0);
9797 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9802 + if (unlikely(au_digen(dentry) != sigen
9803 + || au_iigen_test(d_inode(dentry), sigen)))
9809 +void au_update_digen(struct dentry *dentry)
9811 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9812 + /* smp_mb(); */ /* atomic_set */
9815 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9817 + struct au_dinfo *dinfo;
9818 + struct dentry *h_d;
9819 + struct au_hdentry *hdp;
9820 + aufs_bindex_t bindex, bbot;
9822 + DiMustWriteLock(dentry);
9824 + dinfo = au_di(dentry);
9825 + if (!dinfo || dinfo->di_btop < 0)
9828 + if (do_put_zero) {
9829 + bbot = dinfo->di_bbot;
9830 + bindex = dinfo->di_btop;
9831 + hdp = au_hdentry(dinfo, bindex);
9832 + for (; bindex <= bbot; bindex++, hdp++) {
9833 + h_d = hdp->hd_dentry;
9834 + if (h_d && d_is_negative(h_d))
9835 + au_set_h_dptr(dentry, bindex, NULL);
9839 + dinfo->di_btop = 0;
9840 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9841 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9842 + if (hdp->hd_dentry)
9844 + if (dinfo->di_btop > dinfo->di_bbot) {
9845 + dinfo->di_btop = -1;
9846 + dinfo->di_bbot = -1;
9850 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9851 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9852 + if (hdp->hd_dentry)
9854 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9857 +void au_update_dbtop(struct dentry *dentry)
9859 + aufs_bindex_t bindex, bbot;
9860 + struct dentry *h_dentry;
9862 + bbot = au_dbbot(dentry);
9863 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9864 + h_dentry = au_h_dptr(dentry, bindex);
9867 + if (d_is_positive(h_dentry)) {
9868 + au_set_dbtop(dentry, bindex);
9871 + au_set_h_dptr(dentry, bindex, NULL);
9875 +void au_update_dbbot(struct dentry *dentry)
9877 + aufs_bindex_t bindex, btop;
9878 + struct dentry *h_dentry;
9880 + btop = au_dbtop(dentry);
9881 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9882 + h_dentry = au_h_dptr(dentry, bindex);
9885 + if (d_is_positive(h_dentry)) {
9886 + au_set_dbbot(dentry, bindex);
9889 + au_set_h_dptr(dentry, bindex, NULL);
9893 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9895 + aufs_bindex_t bindex, bbot;
9897 + bbot = au_dbbot(dentry);
9898 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9899 + if (au_h_dptr(dentry, bindex) == h_dentry)
9903 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9904 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9905 +++ linux/fs/aufs/dir.c 2021-12-03 15:38:59.933313976 +0100
9907 +// SPDX-License-Identifier: GPL-2.0
9909 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9911 + * This program, aufs is free software; you can redistribute it and/or modify
9912 + * it under the terms of the GNU General Public License as published by
9913 + * the Free Software Foundation; either version 2 of the License, or
9914 + * (at your option) any later version.
9916 + * This program is distributed in the hope that it will be useful,
9917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9919 + * GNU General Public License for more details.
9921 + * You should have received a copy of the GNU General Public License
9922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9926 + * directory operations
9929 +#include <linux/fs_stack.h>
9930 +#include <linux/iversion.h>
9933 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9935 + unsigned int nlink;
9937 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9939 + nlink = dir->i_nlink;
9940 + nlink += h_dir->i_nlink - 2;
9941 + if (h_dir->i_nlink < 2)
9943 + smp_mb(); /* for i_nlink */
9944 + /* 0 can happen in revaliding */
9945 + set_nlink(dir, nlink);
9948 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9950 + unsigned int nlink;
9952 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9954 + nlink = dir->i_nlink;
9955 + nlink -= h_dir->i_nlink - 2;
9956 + if (h_dir->i_nlink < 2)
9958 + smp_mb(); /* for i_nlink */
9959 + /* nlink == 0 means the branch-fs is broken */
9960 + set_nlink(dir, nlink);
9963 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9966 + aufs_bindex_t bindex, bbot;
9967 + struct file *h_file;
9968 + struct dentry *h_dentry;
9972 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9974 + bbot = au_fbbot_dir(file);
9975 + for (bindex = au_fbtop(file);
9976 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9978 + h_file = au_hf_dir(file, bindex);
9979 + if (h_file && file_inode(h_file))
9980 + sz += vfsub_f_size_read(h_file);
9983 + AuDebugOn(!dentry);
9984 + AuDebugOn(!d_is_dir(dentry));
9986 + bbot = au_dbtaildir(dentry);
9987 + for (bindex = au_dbtop(dentry);
9988 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9990 + h_dentry = au_h_dptr(dentry, bindex);
9991 + if (h_dentry && d_is_positive(h_dentry))
9992 + sz += i_size_read(d_inode(h_dentry));
9995 + if (sz < KMALLOC_MAX_SIZE)
9996 + sz = roundup_pow_of_two(sz);
9997 + if (sz > KMALLOC_MAX_SIZE)
9998 + sz = KMALLOC_MAX_SIZE;
9999 + else if (sz < NAME_MAX) {
10000 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10001 + sz = AUFS_RDBLK_DEF;
10006 +struct au_dir_ts_arg {
10007 + struct dentry *dentry;
10008 + aufs_bindex_t brid;
10011 +static void au_do_dir_ts(void *arg)
10013 + struct au_dir_ts_arg *a = arg;
10014 + struct au_dtime dt;
10015 + struct path h_path;
10016 + struct inode *dir, *h_dir;
10017 + struct super_block *sb;
10018 + struct au_branch *br;
10019 + struct au_hinode *hdir;
10021 + aufs_bindex_t btop, bindex;
10023 + sb = a->dentry->d_sb;
10024 + if (d_really_is_negative(a->dentry))
10026 + /* no dir->i_mutex lock */
10027 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10029 + dir = d_inode(a->dentry);
10030 + btop = au_ibtop(dir);
10031 + bindex = au_br_index(sb, a->brid);
10032 + if (bindex < btop)
10035 + br = au_sbr(sb, bindex);
10036 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10037 + if (!h_path.dentry)
10039 + h_path.mnt = au_br_mnt(br);
10040 + au_dtime_store(&dt, a->dentry, &h_path);
10042 + br = au_sbr(sb, btop);
10043 + if (!au_br_writable(br->br_perm))
10045 + h_path.dentry = au_h_dptr(a->dentry, btop);
10046 + h_path.mnt = au_br_mnt(br);
10047 + err = vfsub_mnt_want_write(h_path.mnt);
10050 + hdir = au_hi(dir, btop);
10051 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10052 + h_dir = au_h_iptr(dir, btop);
10053 + if (h_dir->i_nlink
10054 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10055 + dt.dt_h_path = h_path;
10056 + au_dtime_revert(&dt);
10058 + au_hn_inode_unlock(hdir);
10059 + vfsub_mnt_drop_write(h_path.mnt);
10060 + au_cpup_attr_timesizes(dir);
10063 + aufs_read_unlock(a->dentry, AuLock_DW);
10066 + au_nwt_done(&au_sbi(sb)->si_nowait);
10067 + au_kfree_try_rcu(arg);
10070 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10072 + int perm, wkq_err;
10073 + aufs_bindex_t btop;
10074 + struct au_dir_ts_arg *arg;
10075 + struct dentry *dentry;
10076 + struct super_block *sb;
10080 + dentry = d_find_any_alias(dir);
10081 + AuDebugOn(!dentry);
10082 + sb = dentry->d_sb;
10083 + btop = au_ibtop(dir);
10084 + if (btop == bindex) {
10085 + au_cpup_attr_timesizes(dir);
10089 + perm = au_sbr_perm(sb, btop);
10090 + if (!au_br_writable(perm))
10093 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10097 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10098 + arg->brid = au_sbr_id(sb, bindex);
10099 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10100 + if (unlikely(wkq_err)) {
10101 + pr_err("wkq %d\n", wkq_err);
10103 + au_kfree_try_rcu(arg);
10110 +/* ---------------------------------------------------------------------- */
10112 +static int reopen_dir(struct file *file)
10115 + unsigned int flags;
10116 + aufs_bindex_t bindex, btail, btop;
10117 + struct dentry *dentry, *h_dentry;
10118 + struct file *h_file;
10120 + /* open all lower dirs */
10121 + dentry = file->f_path.dentry;
10122 + btop = au_dbtop(dentry);
10123 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10124 + au_set_h_fptr(file, bindex, NULL);
10125 + au_set_fbtop(file, btop);
10127 + btail = au_dbtaildir(dentry);
10128 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10129 + au_set_h_fptr(file, bindex, NULL);
10130 + au_set_fbbot_dir(file, btail);
10132 + flags = vfsub_file_flags(file);
10133 + for (bindex = btop; bindex <= btail; bindex++) {
10134 + h_dentry = au_h_dptr(dentry, bindex);
10137 + h_file = au_hf_dir(file, bindex);
10141 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10142 + err = PTR_ERR(h_file);
10143 + if (IS_ERR(h_file))
10144 + goto out; /* close all? */
10145 + au_set_h_fptr(file, bindex, h_file);
10147 + au_update_figen(file);
10148 + /* todo: necessary? */
10149 + /* file->f_ra = h_file->f_ra; */
10156 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10159 + aufs_bindex_t bindex, btail;
10160 + struct dentry *dentry, *h_dentry;
10161 + struct vfsmount *mnt;
10163 + FiMustWriteLock(file);
10164 + AuDebugOn(h_file);
10167 + mnt = file->f_path.mnt;
10168 + dentry = file->f_path.dentry;
10169 + file->f_version = inode_query_iversion(d_inode(dentry));
10170 + bindex = au_dbtop(dentry);
10171 + au_set_fbtop(file, bindex);
10172 + btail = au_dbtaildir(dentry);
10173 + au_set_fbbot_dir(file, btail);
10174 + for (; !err && bindex <= btail; bindex++) {
10175 + h_dentry = au_h_dptr(dentry, bindex);
10179 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10180 + if (unlikely(err))
10182 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10183 + if (IS_ERR(h_file)) {
10184 + err = PTR_ERR(h_file);
10187 + au_set_h_fptr(file, bindex, h_file);
10189 + au_update_figen(file);
10190 + /* todo: necessary? */
10191 + /* file->f_ra = h_file->f_ra; */
10193 + return 0; /* success */
10196 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10197 + au_set_h_fptr(file, bindex, NULL);
10198 + au_set_fbtop(file, -1);
10199 + au_set_fbbot_dir(file, -1);
10204 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10205 + struct file *file)
10208 + struct super_block *sb;
10209 + struct au_fidir *fidir;
10212 + sb = file->f_path.dentry->d_sb;
10213 + si_read_lock(sb, AuLock_FLUSH);
10214 + fidir = au_fidir_alloc(sb);
10216 + struct au_do_open_args args = {
10217 + .open = do_open_dir,
10220 + err = au_do_open(file, &args);
10221 + if (unlikely(err))
10222 + au_kfree_rcu(fidir);
10224 + si_read_unlock(sb);
10228 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10229 + struct file *file)
10231 + struct au_vdir *vdir_cache;
10232 + struct au_finfo *finfo;
10233 + struct au_fidir *fidir;
10234 + struct au_hfile *hf;
10235 + aufs_bindex_t bindex, bbot;
10237 + finfo = au_fi(file);
10238 + fidir = finfo->fi_hdir;
10240 + au_hbl_del(&finfo->fi_hlist,
10241 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10242 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10244 + au_vdir_free(vdir_cache);
10246 + bindex = finfo->fi_btop;
10247 + if (bindex >= 0) {
10248 + hf = fidir->fd_hfile + bindex;
10250 + * calls fput() instead of filp_close(),
10251 + * since no dnotify or lock for the lower file.
10253 + bbot = fidir->fd_bbot;
10254 + for (; bindex <= bbot; bindex++, hf++)
10256 + au_hfput(hf, /*execed*/0);
10258 + au_kfree_rcu(fidir);
10259 + finfo->fi_hdir = NULL;
10261 + au_finfo_fin(file);
10265 +/* ---------------------------------------------------------------------- */
10267 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10270 + aufs_bindex_t bindex, bbot;
10271 + struct file *h_file;
10274 + bbot = au_fbbot_dir(file);
10275 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10276 + h_file = au_hf_dir(file, bindex);
10278 + err = vfsub_flush(h_file, id);
10283 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10285 + return au_do_flush(file, id, au_do_flush_dir);
10288 +/* ---------------------------------------------------------------------- */
10290 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10293 + aufs_bindex_t bbot, bindex;
10294 + struct inode *inode;
10295 + struct super_block *sb;
10298 + sb = dentry->d_sb;
10299 + inode = d_inode(dentry);
10300 + IMustLock(inode);
10301 + bbot = au_dbbot(dentry);
10302 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10303 + struct path h_path;
10305 + if (au_test_ro(sb, bindex, inode))
10307 + h_path.dentry = au_h_dptr(dentry, bindex);
10308 + if (!h_path.dentry)
10311 + h_path.mnt = au_sbr_mnt(sb, bindex);
10312 + err = vfsub_fsync(NULL, &h_path, datasync);
10318 +static int au_do_fsync_dir(struct file *file, int datasync)
10321 + aufs_bindex_t bbot, bindex;
10322 + struct file *h_file;
10323 + struct super_block *sb;
10324 + struct inode *inode;
10326 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10327 + if (unlikely(err))
10330 + inode = file_inode(file);
10331 + sb = inode->i_sb;
10332 + bbot = au_fbbot_dir(file);
10333 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10334 + h_file = au_hf_dir(file, bindex);
10335 + if (!h_file || au_test_ro(sb, bindex, inode))
10338 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10346 + * @file may be NULL
10348 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10352 + struct dentry *dentry;
10353 + struct inode *inode;
10354 + struct super_block *sb;
10357 + dentry = file->f_path.dentry;
10358 + inode = d_inode(dentry);
10359 + inode_lock(inode);
10360 + sb = dentry->d_sb;
10361 + si_noflush_read_lock(sb);
10363 + err = au_do_fsync_dir(file, datasync);
10365 + di_write_lock_child(dentry);
10366 + err = au_do_fsync_dir_no_file(dentry, datasync);
10368 + au_cpup_attr_timesizes(inode);
10369 + di_write_unlock(dentry);
10371 + fi_write_unlock(file);
10373 + si_read_unlock(sb);
10374 + inode_unlock(inode);
10378 +/* ---------------------------------------------------------------------- */
10380 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10383 + struct dentry *dentry;
10384 + struct inode *inode, *h_inode;
10385 + struct super_block *sb;
10387 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10389 + dentry = file->f_path.dentry;
10390 + inode = d_inode(dentry);
10391 + IMustLock(inode);
10393 + sb = dentry->d_sb;
10394 + si_read_lock(sb, AuLock_FLUSH);
10395 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10396 + if (unlikely(err))
10398 + err = au_alive_dir(dentry);
10400 + err = au_vdir_init(file);
10401 + di_downgrade_lock(dentry, AuLock_IR);
10402 + if (unlikely(err))
10405 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10406 + if (!au_test_nfsd()) {
10407 + err = au_vdir_fill_de(file, ctx);
10408 + fsstack_copy_attr_atime(inode, h_inode);
10411 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10412 + * encode_fh() and others.
10414 + atomic_inc(&h_inode->i_count);
10415 + di_read_unlock(dentry, AuLock_IR);
10416 + si_read_unlock(sb);
10417 + err = au_vdir_fill_de(file, ctx);
10418 + fsstack_copy_attr_atime(inode, h_inode);
10419 + fi_write_unlock(file);
10427 + di_read_unlock(dentry, AuLock_IR);
10428 + fi_write_unlock(file);
10430 + si_read_unlock(sb);
10434 +/* ---------------------------------------------------------------------- */
10436 +#define AuTestEmpty_WHONLY 1
10437 +#define AuTestEmpty_CALLED (1 << 1)
10438 +#define AuTestEmpty_SHWH (1 << 2)
10439 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10440 +#define au_fset_testempty(flags, name) \
10441 + do { (flags) |= AuTestEmpty_##name; } while (0)
10442 +#define au_fclr_testempty(flags, name) \
10443 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10445 +#ifndef CONFIG_AUFS_SHWH
10446 +#undef AuTestEmpty_SHWH
10447 +#define AuTestEmpty_SHWH 0
10450 +struct test_empty_arg {
10451 + struct dir_context ctx;
10452 + struct au_nhash *whlist;
10453 + unsigned int flags;
10455 + aufs_bindex_t bindex;
10458 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10459 + int namelen, loff_t offset __maybe_unused, u64 ino,
10460 + unsigned int d_type)
10462 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10464 + char *name = (void *)__name;
10467 + au_fset_testempty(arg->flags, CALLED);
10469 + if (name[0] == '.'
10470 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10471 + goto out; /* success */
10473 + if (namelen <= AUFS_WH_PFX_LEN
10474 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10475 + if (au_ftest_testempty(arg->flags, WHONLY)
10476 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10477 + arg->err = -ENOTEMPTY;
10481 + name += AUFS_WH_PFX_LEN;
10482 + namelen -= AUFS_WH_PFX_LEN;
10483 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10484 + arg->err = au_nhash_append_wh
10485 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10486 + au_ftest_testempty(arg->flags, SHWH));
10490 + AuTraceErr(arg->err);
10494 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10497 + struct file *h_file;
10498 + struct au_branch *br;
10500 + h_file = au_h_open(dentry, arg->bindex,
10501 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10502 + /*file*/NULL, /*force_wr*/0);
10503 + err = PTR_ERR(h_file);
10504 + if (IS_ERR(h_file))
10508 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10509 + && !file_inode(h_file)->i_nlink)
10514 + au_fclr_testempty(arg->flags, CALLED);
10516 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10519 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10523 + br = au_sbr(dentry->d_sb, arg->bindex);
10524 + au_lcnt_dec(&br->br_nfiles);
10529 +struct do_test_empty_args {
10531 + struct dentry *dentry;
10532 + struct test_empty_arg *arg;
10535 +static void call_do_test_empty(void *args)
10537 + struct do_test_empty_args *a = args;
10538 + *a->errp = do_test_empty(a->dentry, a->arg);
10541 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10543 + int err, wkq_err;
10544 + struct dentry *h_dentry;
10545 + struct inode *h_inode;
10547 + h_dentry = au_h_dptr(dentry, arg->bindex);
10548 + h_inode = d_inode(h_dentry);
10549 + /* todo: i_mode changes anytime? */
10550 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10551 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10552 + inode_unlock_shared(h_inode);
10554 + err = do_test_empty(dentry, arg);
10556 + struct do_test_empty_args args = {
10558 + .dentry = dentry,
10561 + unsigned int flags = arg->flags;
10563 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10564 + if (unlikely(wkq_err))
10566 + arg->flags = flags;
10572 +int au_test_empty_lower(struct dentry *dentry)
10575 + unsigned int rdhash;
10576 + aufs_bindex_t bindex, btop, btail;
10577 + struct au_nhash whlist;
10578 + struct test_empty_arg arg = {
10580 + .actor = test_empty_cb
10583 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10585 + SiMustAnyLock(dentry->d_sb);
10587 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10589 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10590 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10591 + if (unlikely(err))
10595 + arg.whlist = &whlist;
10596 + btop = au_dbtop(dentry);
10597 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10598 + au_fset_testempty(arg.flags, SHWH);
10599 + test_empty = do_test_empty;
10600 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10601 + test_empty = sio_test_empty;
10602 + arg.bindex = btop;
10603 + err = test_empty(dentry, &arg);
10604 + if (unlikely(err))
10607 + au_fset_testempty(arg.flags, WHONLY);
10608 + btail = au_dbtaildir(dentry);
10609 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10610 + struct dentry *h_dentry;
10612 + h_dentry = au_h_dptr(dentry, bindex);
10613 + if (h_dentry && d_is_positive(h_dentry)) {
10614 + arg.bindex = bindex;
10615 + err = test_empty(dentry, &arg);
10620 + au_nhash_wh_free(&whlist);
10625 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10628 + struct test_empty_arg arg = {
10630 + .actor = test_empty_cb
10633 + aufs_bindex_t bindex, btail;
10636 + arg.whlist = whlist;
10637 + arg.flags = AuTestEmpty_WHONLY;
10638 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10639 + au_fset_testempty(arg.flags, SHWH);
10640 + btail = au_dbtaildir(dentry);
10641 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10642 + struct dentry *h_dentry;
10644 + h_dentry = au_h_dptr(dentry, bindex);
10645 + if (h_dentry && d_is_positive(h_dentry)) {
10646 + arg.bindex = bindex;
10647 + err = sio_test_empty(dentry, &arg);
10654 +/* ---------------------------------------------------------------------- */
10656 +const struct file_operations aufs_dir_fop = {
10657 + .owner = THIS_MODULE,
10658 + .llseek = default_llseek,
10659 + .read = generic_read_dir,
10660 + .iterate_shared = aufs_iterate_shared,
10661 + .unlocked_ioctl = aufs_ioctl_dir,
10662 +#ifdef CONFIG_COMPAT
10663 + .compat_ioctl = aufs_compat_ioctl_dir,
10665 + .open = aufs_open_dir,
10666 + .release = aufs_release_dir,
10667 + .flush = aufs_flush_dir,
10668 + .fsync = aufs_fsync_dir
10670 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10671 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10672 +++ linux/fs/aufs/dir.h 2021-12-03 15:38:59.933313976 +0100
10674 +/* SPDX-License-Identifier: GPL-2.0 */
10676 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10678 + * This program, aufs is free software; you can redistribute it and/or modify
10679 + * it under the terms of the GNU General Public License as published by
10680 + * the Free Software Foundation; either version 2 of the License, or
10681 + * (at your option) any later version.
10683 + * This program is distributed in the hope that it will be useful,
10684 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10685 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10686 + * GNU General Public License for more details.
10688 + * You should have received a copy of the GNU General Public License
10689 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10693 + * directory operations
10696 +#ifndef __AUFS_DIR_H__
10697 +#define __AUFS_DIR_H__
10701 +#include <linux/fs.h>
10703 +/* ---------------------------------------------------------------------- */
10705 +/* need to be faster and smaller */
10708 + unsigned int nh_num;
10709 + struct hlist_head *nh_head;
10712 +struct au_vdir_destr {
10713 + unsigned char len;
10714 + unsigned char name[];
10717 +struct au_vdir_dehstr {
10718 + struct hlist_node hash;
10719 + struct au_vdir_destr *str;
10720 + struct rcu_head rcu;
10721 +} ____cacheline_aligned_in_smp;
10723 +struct au_vdir_de {
10725 + unsigned char de_type;
10726 + /* caution: packed */
10727 + struct au_vdir_destr de_str;
10730 +struct au_vdir_wh {
10731 + struct hlist_node wh_hash;
10732 +#ifdef CONFIG_AUFS_SHWH
10734 + aufs_bindex_t wh_bindex;
10735 + unsigned char wh_type;
10737 + aufs_bindex_t wh_bindex;
10739 + /* caution: packed */
10740 + struct au_vdir_destr wh_str;
10743 +union au_vdir_deblk_p {
10744 + unsigned char *deblk;
10745 + struct au_vdir_de *de;
10749 + unsigned char **vd_deblk;
10750 + unsigned long vd_nblk;
10752 + unsigned long ul;
10753 + union au_vdir_deblk_p p;
10757 + unsigned int vd_deblk_sz;
10758 + unsigned long vd_jiffy;
10759 + struct rcu_head rcu;
10760 +} ____cacheline_aligned_in_smp;
10762 +/* ---------------------------------------------------------------------- */
10765 +extern const struct file_operations aufs_dir_fop;
10766 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10767 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10768 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10769 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10770 +int au_test_empty_lower(struct dentry *dentry);
10771 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10774 +unsigned int au_rdhash_est(loff_t sz);
10775 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10776 +void au_nhash_wh_free(struct au_nhash *whlist);
10777 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10779 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10780 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10781 + unsigned int d_type, aufs_bindex_t bindex,
10782 + unsigned char shwh);
10783 +void au_vdir_free(struct au_vdir *vdir);
10784 +int au_vdir_init(struct file *file);
10785 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10788 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10790 +#ifdef CONFIG_AUFS_RDU
10792 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10793 +#ifdef CONFIG_COMPAT
10794 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10795 + unsigned long arg);
10798 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10799 + unsigned int cmd, unsigned long arg)
10800 +#ifdef CONFIG_COMPAT
10801 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10802 + unsigned int cmd, unsigned long arg)
10806 +#endif /* __KERNEL__ */
10807 +#endif /* __AUFS_DIR_H__ */
10808 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10809 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10810 +++ linux/fs/aufs/dirren.c 2021-12-03 15:38:59.933313976 +0100
10812 +// SPDX-License-Identifier: GPL-2.0
10814 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10816 + * This program, aufs is free software; you can redistribute it and/or modify
10817 + * it under the terms of the GNU General Public License as published by
10818 + * the Free Software Foundation; either version 2 of the License, or
10819 + * (at your option) any later version.
10821 + * This program is distributed in the hope that it will be useful,
10822 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10823 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10824 + * GNU General Public License for more details.
10826 + * You should have received a copy of the GNU General Public License
10827 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10831 + * special handling in renaming a directory
10832 + * in order to support looking-up the before-renamed name on the lower readonly
10836 +#include <linux/byteorder/generic.h>
10839 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10843 + idx = au_dr_ihash(ent->dr_h_ino);
10844 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10847 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10850 + struct hlist_bl_head *hbl;
10853 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10854 + hbl = dr->dr_h_ino + i;
10855 + hlist_bl_lock(hbl);
10856 + ret &= hlist_bl_empty(hbl);
10857 + hlist_bl_unlock(hbl);
10863 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10865 + struct au_dr_hino *found, *ent;
10866 + struct hlist_bl_head *hbl;
10867 + struct hlist_bl_node *pos;
10871 + idx = au_dr_ihash(ino);
10872 + hbl = dr->dr_h_ino + idx;
10873 + hlist_bl_lock(hbl);
10874 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10875 + if (ent->dr_h_ino == ino) {
10879 + hlist_bl_unlock(hbl);
10884 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10885 + struct au_dr_hino *add_ent)
10888 + struct hlist_bl_head *hbl;
10889 + struct hlist_bl_node *pos;
10890 + struct au_dr_hino *ent;
10893 + idx = au_dr_ihash(ino);
10894 + hbl = dr->dr_h_ino + idx;
10895 +#if 0 /* debug print */
10897 + struct hlist_bl_node *tmp;
10899 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10900 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10903 + hlist_bl_lock(hbl);
10904 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10905 + if (ent->dr_h_ino == ino) {
10909 + if (!found && add_ent)
10910 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10911 + hlist_bl_unlock(hbl);
10913 + if (!found && add_ent)
10914 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10919 +void au_dr_hino_free(struct au_dr_br *dr)
10922 + struct hlist_bl_head *hbl;
10923 + struct hlist_bl_node *pos, *tmp;
10924 + struct au_dr_hino *ent;
10926 + /* SiMustWriteLock(sb); */
10928 + for (i = 0; i < AuDirren_NHASH; i++) {
10929 + hbl = dr->dr_h_ino + i;
10930 + /* no spinlock since sbinfo must be write-locked */
10931 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10932 + au_kfree_rcu(ent);
10933 + INIT_HLIST_BL_HEAD(hbl);
10937 +/* returns the number of inodes or an error */
10938 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10939 + struct file *hinofile)
10943 + loff_t pos, oldsize;
10945 + struct inode *hinoinode;
10946 + struct hlist_bl_head *hbl;
10947 + struct hlist_bl_node *n1, *n2;
10948 + struct au_dr_hino *ent;
10950 + SiMustWriteLock(sb);
10951 + AuDebugOn(!au_br_writable(br->br_perm));
10953 + hinoinode = file_inode(hinofile);
10954 + oldsize = i_size_read(hinoinode);
10958 + hbl = br->br_dirren.dr_h_ino;
10959 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
10960 + /* no bit-lock since sbinfo must be write-locked */
10961 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
10962 + AuDbg("hi%llu, %pD2\n",
10963 + (unsigned long long)ent->dr_h_ino, hinofile);
10964 + u64 = cpu_to_be64(ent->dr_h_ino);
10965 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
10966 + if (ssz == sizeof(u64))
10969 + /* write error */
10970 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
10977 + /* regardless the error */
10978 + if (pos < oldsize) {
10979 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
10987 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
10994 + struct au_dr_hino *ent;
10995 + struct inode *hinoinode;
10996 + struct hlist_bl_head *hbl;
11000 + hbl = dr->dr_h_ino;
11001 + hinoinode = file_inode(hinofile);
11002 + sz = i_size_read(hinoinode);
11003 + AuDebugOn(sz % sizeof(u64));
11004 + n = sz / sizeof(u64);
11006 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11007 + if (unlikely(ssz != sizeof(u64))) {
11008 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11015 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11021 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11022 + AuDbg("hi%llu, %pD2\n",
11023 + (unsigned long long)ent->dr_h_ino, hinofile);
11024 + hidx = au_dr_ihash(ent->dr_h_ino);
11025 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11027 + goto out; /* success */
11030 + au_dr_hino_free(dr);
11037 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11038 + * @path is a switch to distinguish load and store.
11040 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11041 + struct au_branch *br, const struct path *path)
11044 + unsigned char load, suspend;
11045 + struct file *hinofile;
11046 + struct au_hinode *hdir;
11047 + struct inode *dir, *delegated;
11048 + struct path hinopath;
11049 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11050 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11052 + AuDebugOn(bindex < 0 && !br);
11053 + AuDebugOn(bindex >= 0 && br);
11058 + br = au_sbr(sb, bindex);
11061 + path = &br->br_path;
11062 + AuDebugOn(!au_br_writable(br->br_perm));
11063 + if (unlikely(!au_br_writable(br->br_perm)))
11069 + dir = d_inode(sb->s_root);
11070 + hdir = au_hinode(au_ii(dir), bindex);
11071 + dir = hdir->hi_inode;
11072 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11074 + dir = d_inode(path->dentry);
11075 + inode_lock_nested(dir, AuLsc_I_CHILD);
11077 + hinopath.mnt = path->mnt;
11078 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11079 + err = PTR_ERR(hinopath.dentry);
11080 + if (IS_ERR(hinopath.dentry))
11084 + flags = O_RDONLY;
11086 + if (d_is_negative(hinopath.dentry))
11087 + goto out_dput; /* success */
11089 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11090 + if (d_is_positive(hinopath.dentry)) {
11091 + delegated = NULL;
11092 + err = vfsub_unlink(dir, &hinopath, &delegated,
11095 + if (unlikely(err))
11096 + pr_err("ignored err %d, %pd2\n",
11097 + err, hinopath.dentry);
11098 + if (unlikely(err == -EWOULDBLOCK))
11103 + } else if (!d_is_positive(hinopath.dentry)) {
11104 + err = vfsub_create(dir, &hinopath, 0600,
11105 + /*want_excl*/false);
11107 + if (unlikely(err))
11110 + flags = O_WRONLY;
11112 + hinofile = vfsub_dentry_open(&hinopath, flags);
11114 + au_hn_inode_unlock(hdir);
11116 + inode_unlock(dir);
11117 + dput(hinopath.dentry);
11118 + AuTraceErrPtr(hinofile);
11119 + if (IS_ERR(hinofile)) {
11120 + err = PTR_ERR(hinofile);
11125 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11127 + err = au_dr_hino_store(sb, br, hinofile);
11132 + dput(hinopath.dentry);
11135 + au_hn_inode_unlock(hdir);
11137 + inode_unlock(dir);
11143 +/* ---------------------------------------------------------------------- */
11145 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11148 + struct kstatfs kstfs;
11150 + struct dentry *dentry;
11151 + struct super_block *sb;
11153 + err = vfs_statfs((void *)path, &kstfs);
11155 + if (unlikely(err))
11158 + /* todo: support for UUID */
11160 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11161 + brid->type = AuBrid_FSID;
11162 + brid->fsid = kstfs.f_fsid;
11164 + dentry = path->dentry;
11165 + sb = dentry->d_sb;
11168 + brid->type = AuBrid_DEV;
11177 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11178 + const struct path *path)
11181 + struct au_dr_br *dr;
11182 + struct hlist_bl_head *hbl;
11184 + dr = &br->br_dirren;
11185 + hbl = dr->dr_h_ino;
11186 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11187 + INIT_HLIST_BL_HEAD(hbl);
11189 + err = au_dr_brid_init(&dr->dr_brid, path);
11190 + if (unlikely(err))
11193 + if (au_opt_test(au_mntflags(sb), DIRREN))
11194 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11201 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11206 + if (au_br_writable(br->br_perm))
11207 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11209 + au_dr_hino_free(&br->br_dirren);
11214 +/* ---------------------------------------------------------------------- */
11216 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11217 + char *buf, size_t sz)
11220 + unsigned int major, minor;
11224 + err = snprintf(p, sz, "%d_", brid->type);
11225 + AuDebugOn(err > sz);
11228 + switch (brid->type) {
11229 + case AuBrid_Unset:
11231 + case AuBrid_UUID:
11232 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11234 + case AuBrid_FSID:
11235 + err = snprintf(p, sz, "%08x-%08x",
11236 + brid->fsid.val[0], brid->fsid.val[1]);
11239 + major = MAJOR(brid->dev);
11240 + minor = MINOR(brid->dev);
11241 + if (major <= 0xff && minor <= 0xff)
11242 + err = snprintf(p, sz, "%02x%02x", major, minor);
11244 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11247 + AuDebugOn(err > sz);
11250 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11251 + AuDebugOn(err > sz);
11258 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11261 + struct dentry *br_dentry;
11262 + struct inode *br_inode;
11264 + br_dentry = au_br_dentry(br);
11265 + br_inode = d_inode(br_dentry);
11266 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11267 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11268 + AuDebugOn(rlen > len);
11273 +/* ---------------------------------------------------------------------- */
11276 + * from the given @h_dentry, construct drinfo at @*fdata.
11277 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11280 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11281 + struct dentry *h_dentry,
11282 + unsigned char *allocated)
11285 + struct au_drinfo_fdata *f, *p;
11286 + struct au_drinfo *drinfo;
11287 + struct inode *h_inode;
11288 + struct qstr *qname;
11292 + h_inode = d_inode(h_dentry);
11293 + qname = &h_dentry->d_name;
11294 + drinfo = &f->drinfo;
11295 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11296 + drinfo->oldnamelen = qname->len;
11297 + if (*allocated < sizeof(*f) + qname->len) {
11298 + v = roundup_pow_of_two(*allocated + qname->len);
11299 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11300 + if (unlikely(!p)) {
11308 + drinfo = &f->drinfo;
11310 + memcpy(drinfo->oldname, qname->name, qname->len);
11311 + AuDbg("i%llu, %.*s\n",
11312 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11313 + drinfo->oldname);
11320 +/* callers have to free the return value */
11321 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11323 + struct au_drinfo *ret, *drinfo;
11324 + struct au_drinfo_fdata fdata;
11329 + ret = ERR_PTR(-EIO);
11331 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11332 + if (unlikely(ssz != sizeof(fdata))) {
11333 + AuIOErr("ssz %zd, %u, %pD2\n",
11334 + ssz, (unsigned int)sizeof(fdata), file);
11338 + fdata.magic = ntohl((__force __be32)fdata.magic);
11339 + switch (fdata.magic) {
11340 + case AUFS_DRINFO_MAGIC_V1:
11343 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11344 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11348 + drinfo = &fdata.drinfo;
11349 + len = drinfo->oldnamelen;
11351 + AuIOErr("broken drinfo %pD2\n", file);
11356 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11357 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11358 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11359 + (unsigned long long)drinfo->ino,
11360 + (unsigned long long)h_ino, file);
11361 + goto out; /* success */
11364 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11365 + if (unlikely(!ret)) {
11366 + ret = ERR_PTR(-ENOMEM);
11367 + AuTraceErrPtr(ret);
11372 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11373 + if (unlikely(ssz != len)) {
11374 + au_kfree_rcu(ret);
11375 + ret = ERR_PTR(-EIO);
11376 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11380 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11386 +/* ---------------------------------------------------------------------- */
11388 +/* in order to be revertible */
11389 +struct au_drinfo_rev_elm {
11391 + struct dentry *info_dentry;
11392 + struct au_drinfo *info_last;
11395 +struct au_drinfo_rev {
11396 + unsigned char already;
11397 + aufs_bindex_t nelm;
11398 + struct au_drinfo_rev_elm elm[];
11401 +/* todo: isn't it too large? */
11402 +struct au_drinfo_store {
11403 + struct path h_ppath;
11404 + struct dentry *h_dentry;
11405 + struct au_drinfo_fdata *fdata;
11406 + char *infoname; /* inside of whname, just after PFX */
11407 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11408 + aufs_bindex_t btgt, btail;
11409 + unsigned char no_sio,
11410 + allocated, /* current size of *fdata */
11411 + infonamelen, /* room size for p */
11412 + whnamelen, /* length of the generated name */
11413 + renameback; /* renamed back */
11416 +/* on rename(2) error, the caller should revert it using @elm */
11417 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11418 + struct au_drinfo_rev_elm *elm)
11423 + struct path infopath = {
11424 + .mnt = w->h_ppath.mnt
11426 + struct inode *h_dir, *h_inode, *delegated;
11427 + struct file *infofile;
11428 + struct qstr *qname;
11431 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11433 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11435 + AuTraceErrPtr(infopath.dentry);
11436 + if (IS_ERR(infopath.dentry)) {
11437 + err = PTR_ERR(infopath.dentry);
11442 + h_dir = d_inode(w->h_ppath.dentry);
11443 + if (elm && d_is_negative(infopath.dentry)) {
11444 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11446 + if (unlikely(err))
11448 + elm->created = 1;
11449 + elm->info_dentry = dget(infopath.dentry);
11452 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11453 + AuTraceErrPtr(infofile);
11454 + if (IS_ERR(infofile)) {
11455 + err = PTR_ERR(infofile);
11459 + h_inode = d_inode(infopath.dentry);
11460 + if (elm && i_size_read(h_inode)) {
11461 + h_inode = d_inode(w->h_dentry);
11462 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11463 + AuTraceErrPtr(elm->info_last);
11464 + if (IS_ERR(elm->info_last)) {
11465 + err = PTR_ERR(elm->info_last);
11466 + elm->info_last = NULL;
11467 + AuDebugOn(elm->info_dentry);
11472 + if (elm && w->renameback) {
11473 + delegated = NULL;
11474 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11476 + if (unlikely(err == -EWOULDBLOCK))
11482 + qname = &w->h_dentry->d_name;
11483 + len = sizeof(*w->fdata) + qname->len;
11485 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11486 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11487 + if (ssz == len) {
11488 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11489 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11490 + goto out_fput; /* success */
11495 + /* the caller should revert it using @elm */
11501 + dput(infopath.dentry);
11507 +struct au_call_drinfo_do_store_args {
11509 + struct au_drinfo_store *w;
11510 + struct au_drinfo_rev_elm *elm;
11513 +static void au_call_drinfo_do_store(void *args)
11515 + struct au_call_drinfo_do_store_args *a = args;
11517 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11520 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11521 + struct au_drinfo_rev_elm *elm)
11523 + int err, wkq_err;
11526 + err = au_drinfo_do_store(w, elm);
11528 + struct au_call_drinfo_do_store_args a = {
11533 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11534 + if (unlikely(wkq_err))
11542 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11543 + aufs_bindex_t btgt)
11547 + memset(w, 0, sizeof(*w));
11548 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11549 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11550 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11551 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11553 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11556 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11557 + if (unlikely(!w->fdata)) {
11561 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11568 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11570 + au_kfree_rcu(w->fdata);
11573 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11574 + struct au_drinfo_store *w)
11576 + struct au_drinfo_rev_elm *elm;
11577 + struct inode *h_dir, *delegated;
11579 + struct path infopath = {
11580 + .mnt = w->h_ppath.mnt
11583 + h_dir = d_inode(w->h_ppath.dentry);
11584 + IMustLock(h_dir);
11588 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11589 + AuDebugOn(elm->created && elm->info_last);
11590 + if (elm->created) {
11592 + delegated = NULL;
11593 + infopath.dentry = elm->info_dentry;
11594 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11597 + if (unlikely(err == -EWOULDBLOCK))
11599 + dput(elm->info_dentry);
11600 + } else if (elm->info_last) {
11602 + w->fdata->drinfo = *elm->info_last;
11603 + memcpy(w->fdata->drinfo.oldname,
11604 + elm->info_last->oldname,
11605 + elm->info_last->oldnamelen);
11606 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11607 + au_kfree_rcu(elm->info_last);
11609 + if (unlikely(err))
11610 + AuIOErr("%d, %s\n", err, w->whname);
11611 + /* go on even if err */
11615 +/* caller has to call au_dr_rename_fin() later */
11616 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11617 + struct qstr *dst_name, void *_rev)
11619 + int err, sz, nelm;
11620 + aufs_bindex_t bindex, btail;
11621 + struct au_drinfo_store work;
11622 + struct au_drinfo_rev *rev, **p;
11623 + struct au_drinfo_rev_elm *elm;
11624 + struct super_block *sb;
11625 + struct au_branch *br;
11626 + struct au_hinode *hdir;
11628 + err = au_drinfo_store_work_init(&work, btgt);
11630 + if (unlikely(err))
11634 + btail = au_dbtaildir(dentry);
11635 + nelm = btail - btgt;
11636 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11637 + rev = kcalloc(1, sz, GFP_NOFS);
11638 + if (unlikely(!rev)) {
11642 + rev->nelm = nelm;
11648 + sb = dentry->d_sb;
11649 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11650 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11651 + hdir = au_hi(d_inode(dentry), btgt);
11652 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11653 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11654 + work.h_dentry = au_h_dptr(dentry, bindex);
11655 + if (!work.h_dentry)
11658 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11659 + &work.allocated);
11661 + if (unlikely(err))
11664 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11665 + br = au_sbr(sb, bindex);
11666 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11667 + work.whnamelen += au_drinfo_name(br, work.infoname,
11668 + work.infonamelen);
11669 + AuDbg("whname %.*s, i%llu, %.*s\n",
11670 + work.whnamelen, work.whname,
11671 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11672 + work.fdata->drinfo.oldnamelen,
11673 + work.fdata->drinfo.oldname);
11675 + err = au_drinfo_store_sio(&work, elm);
11677 + if (unlikely(err))
11680 + if (unlikely(err)) {
11681 + /* revert all drinfo */
11682 + au_drinfo_store_rev(rev, &work);
11683 + au_kfree_try_rcu(rev);
11686 + au_hn_inode_unlock(hdir);
11689 + au_drinfo_store_work_fin(&work);
11694 +/* ---------------------------------------------------------------------- */
11696 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11697 + struct qstr *dst_name, void *_rev)
11699 + int err, already;
11701 + struct super_block *sb;
11702 + struct au_branch *br;
11703 + struct au_dr_br *dr;
11704 + struct dentry *h_dentry;
11705 + struct inode *h_inode;
11706 + struct au_dr_hino *ent;
11707 + struct au_drinfo_rev *rev, **p;
11709 + AuDbg("bindex %d\n", bindex);
11712 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11713 + if (unlikely(!ent))
11717 + br = au_sbr(sb, bindex);
11718 + dr = &br->br_dirren;
11719 + h_dentry = au_h_dptr(src, bindex);
11720 + h_inode = d_inode(h_dentry);
11721 + ino = h_inode->i_ino;
11722 + ent->dr_h_ino = ino;
11723 + already = au_dr_hino_test_add(dr, ino, ent);
11724 + AuDbg("b%d, hi%llu, already %d\n",
11725 + bindex, (unsigned long long)ino, already);
11727 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11732 + rev->already = already;
11733 + goto out; /* success */
11738 + au_dr_hino_del(dr, ent);
11739 + au_kfree_rcu(ent);
11746 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11748 + struct au_drinfo_rev *rev;
11749 + struct au_drinfo_rev_elm *elm;
11754 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11755 + dput(elm->info_dentry);
11756 + au_kfree_rcu(elm->info_last);
11758 + au_kfree_try_rcu(rev);
11761 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11764 + struct au_drinfo_store work;
11765 + struct au_drinfo_rev *rev = _rev;
11766 + struct super_block *sb;
11767 + struct au_branch *br;
11768 + struct inode *h_inode;
11769 + struct au_dr_br *dr;
11770 + struct au_dr_hino *ent;
11772 + err = au_drinfo_store_work_init(&work, btgt);
11773 + if (unlikely(err))
11777 + br = au_sbr(sb, btgt);
11778 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11779 + work.h_ppath.mnt = au_br_mnt(br);
11780 + au_drinfo_store_rev(rev, &work);
11781 + au_drinfo_store_work_fin(&work);
11782 + if (rev->already)
11785 + dr = &br->br_dirren;
11786 + h_inode = d_inode(work.h_ppath.dentry);
11787 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11789 + au_dr_hino_del(dr, ent);
11790 + au_kfree_rcu(ent);
11793 + au_kfree_try_rcu(rev);
11794 + if (unlikely(err))
11795 + pr_err("failed to remove dirren info\n");
11798 +/* ---------------------------------------------------------------------- */
11800 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11801 + char *whname, int whnamelen,
11802 + struct dentry **info_dentry)
11804 + struct au_drinfo *drinfo;
11806 + struct inode *h_dir;
11807 + struct path infopath;
11810 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11812 + *info_dentry = NULL;
11815 + h_dir = d_inode(h_ppath->dentry);
11816 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11817 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11818 + if (IS_ERR(infopath.dentry)) {
11819 + drinfo = (void *)infopath.dentry;
11823 + if (d_is_negative(infopath.dentry))
11824 + goto out_dput; /* success */
11826 + infopath.mnt = h_ppath->mnt;
11827 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11828 + inode_unlock_shared(h_dir);
11831 + drinfo = (void *)f;
11835 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11836 + if (IS_ERR_OR_NULL(drinfo))
11839 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11840 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11845 + dput(infopath.dentry);
11848 + inode_unlock_shared(h_dir);
11849 + AuTraceErrPtr(drinfo);
11853 +struct au_drinfo_do_load_args {
11854 + struct au_drinfo **drinfop;
11855 + struct path *h_ppath;
11858 + struct dentry **info_dentry;
11861 +static void au_call_drinfo_do_load(void *args)
11863 + struct au_drinfo_do_load_args *a = args;
11865 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11869 +struct au_drinfo_load {
11870 + struct path h_ppath;
11871 + struct qstr *qname;
11872 + unsigned char no_sio;
11874 + aufs_bindex_t ninfo;
11875 + struct au_drinfo **drinfo;
11878 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11879 + struct au_branch *br)
11881 + int err, wkq_err, whnamelen, e;
11882 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11883 + = AUFS_WH_DR_INFO_PFX;
11884 + struct au_drinfo *drinfo;
11885 + struct qstr oldname;
11886 + struct inode *h_dir, *delegated;
11887 + struct dentry *info_dentry;
11888 + struct path infopath;
11890 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11891 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11892 + sizeof(whname) - whnamelen);
11894 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11897 + struct au_drinfo_do_load_args args = {
11898 + .drinfop = &drinfo,
11899 + .h_ppath = &w->h_ppath,
11900 + .whname = whname,
11901 + .whnamelen = whnamelen,
11902 + .info_dentry = &info_dentry
11904 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11905 + if (unlikely(wkq_err))
11906 + drinfo = ERR_PTR(wkq_err);
11908 + err = PTR_ERR(drinfo);
11909 + if (IS_ERR_OR_NULL(drinfo))
11913 + oldname.len = drinfo->oldnamelen;
11914 + oldname.name = drinfo->oldname;
11915 + if (au_qstreq(w->qname, &oldname)) {
11916 + /* the name is renamed back */
11917 + au_kfree_rcu(drinfo);
11920 + infopath.dentry = info_dentry;
11921 + infopath.mnt = w->h_ppath.mnt;
11922 + h_dir = d_inode(w->h_ppath.dentry);
11923 + delegated = NULL;
11924 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11925 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11926 + inode_unlock(h_dir);
11928 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11929 + if (unlikely(e == -EWOULDBLOCK))
11932 + au_kfree_rcu(w->drinfo[bindex]);
11933 + w->drinfo[bindex] = drinfo;
11934 + dput(info_dentry);
11941 +/* ---------------------------------------------------------------------- */
11943 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11945 + struct au_drinfo **p = drinfo;
11948 + au_kfree_rcu(*drinfo++);
11949 + au_kfree_try_rcu(p);
11952 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
11953 + aufs_bindex_t btgt)
11956 + struct au_drinfo_load w;
11957 + aufs_bindex_t bindex, bbot;
11958 + struct au_branch *br;
11959 + struct inode *h_dir;
11960 + struct au_dr_hino *ent;
11961 + struct super_block *sb;
11963 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
11964 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
11965 + AuLNPair(&lkup->whname), btgt);
11967 + sb = dentry->d_sb;
11968 + bbot = au_sbbot(sb);
11969 + w.ninfo = bbot + 1;
11970 + if (!lkup->dirren.drinfo) {
11971 + lkup->dirren.drinfo = kcalloc(w.ninfo,
11972 + sizeof(*lkup->dirren.drinfo),
11974 + if (unlikely(!lkup->dirren.drinfo)) {
11978 + lkup->dirren.ninfo = w.ninfo;
11980 + w.drinfo = lkup->dirren.drinfo;
11981 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11982 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
11983 + AuDebugOn(!w.h_ppath.dentry);
11984 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11985 + w.qname = &dentry->d_name;
11988 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
11989 + br = au_sbr(sb, bindex);
11990 + err = au_drinfo_load(&w, bindex, br);
11991 + if (unlikely(err))
11993 + if (w.drinfo[bindex])
11997 + br = au_sbr(sb, btgt);
11998 + h_dir = d_inode(w.h_ppath.dentry);
11999 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12001 + au_dr_hino_del(&br->br_dirren, ent);
12002 + au_kfree_rcu(ent);
12004 + goto out; /* success */
12007 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12008 + lkup->dirren.ninfo = 0;
12009 + lkup->dirren.drinfo = NULL;
12015 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12017 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12020 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12023 + struct au_drinfo *drinfo;
12026 + if (!lkup->dirren.drinfo)
12028 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12029 + drinfo = lkup->dirren.drinfo[btgt];
12033 + au_kfree_try_rcu(lkup->whname.name);
12034 + lkup->whname.name = NULL;
12035 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12036 + lkup->dirren.dr_name.name = drinfo->oldname;
12037 + lkup->name = &lkup->dirren.dr_name;
12038 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12040 + AuDbg("name %.*s, whname %.*s, b%d\n",
12041 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12049 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12053 + struct au_drinfo *drinfo;
12056 + if (!lkup->dirren.drinfo)
12058 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12059 + drinfo = lkup->dirren.drinfo[bindex];
12063 + match = (drinfo->ino == h_ino);
12064 + AuDbg("match %d\n", match);
12070 +/* ---------------------------------------------------------------------- */
12072 +int au_dr_opt_set(struct super_block *sb)
12075 + aufs_bindex_t bindex, bbot;
12076 + struct au_branch *br;
12079 + bbot = au_sbbot(sb);
12080 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12081 + br = au_sbr(sb, bindex);
12082 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12088 +int au_dr_opt_flush(struct super_block *sb)
12091 + aufs_bindex_t bindex, bbot;
12092 + struct au_branch *br;
12095 + bbot = au_sbbot(sb);
12096 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12097 + br = au_sbr(sb, bindex);
12098 + if (au_br_writable(br->br_perm))
12099 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12105 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12108 + aufs_bindex_t bindex, bbot;
12109 + struct au_branch *br;
12113 + err = au_dr_opt_flush(sb);
12114 + if (unlikely(err))
12118 + bbot = au_sbbot(sb);
12119 + for (bindex = 0; bindex <= bbot; bindex++) {
12120 + br = au_sbr(sb, bindex);
12121 + au_dr_hino_free(&br->br_dirren);
12127 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12128 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12129 +++ linux/fs/aufs/dirren.h 2021-12-03 15:38:59.933313976 +0100
12131 +/* SPDX-License-Identifier: GPL-2.0 */
12133 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12135 + * This program, aufs is free software; you can redistribute it and/or modify
12136 + * it under the terms of the GNU General Public License as published by
12137 + * the Free Software Foundation; either version 2 of the License, or
12138 + * (at your option) any later version.
12140 + * This program is distributed in the hope that it will be useful,
12141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12143 + * GNU General Public License for more details.
12145 + * You should have received a copy of the GNU General Public License
12146 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12150 + * renamed dir info
12153 +#ifndef __AUFS_DIRREN_H__
12154 +#define __AUFS_DIRREN_H__
12158 +#include <linux/dcache.h>
12159 +#include <linux/statfs.h>
12160 +#include <linux/uuid.h>
12163 +#define AuDirren_NHASH 100
12165 +#ifdef CONFIG_AUFS_DIRREN
12166 +enum au_brid_type {
12173 +struct au_dr_brid {
12174 + enum au_brid_type type;
12176 + uuid_t uuid; /* unimplemented yet */
12182 +/* 20 is the max digits length of ulong 64 */
12183 +/* brid-type "_" uuid "_" inum */
12184 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12185 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12187 +struct au_dr_hino {
12188 + struct hlist_bl_node dr_hnode;
12193 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12194 + struct au_dr_brid dr_brid;
12197 +struct au_dr_lookup {
12198 + /* dr_name is pointed by struct au_do_lookup_args.name */
12199 + struct qstr dr_name; /* subset of dr_info */
12200 + aufs_bindex_t ninfo;
12201 + struct au_drinfo **drinfo;
12204 +struct au_dr_hino;
12206 +struct au_dr_br { };
12207 +struct au_dr_lookup { };
12210 +/* ---------------------------------------------------------------------- */
12213 +struct au_do_lookup_args;
12215 +#ifdef CONFIG_AUFS_DIRREN
12216 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12217 + struct au_dr_hino *add_ent);
12218 +void au_dr_hino_free(struct au_dr_br *dr);
12219 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12220 + const struct path *path);
12221 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12222 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12223 + struct qstr *dst_name, void *_rev);
12224 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12225 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12226 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12227 + aufs_bindex_t bindex);
12228 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12229 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12231 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12232 +int au_dr_opt_set(struct super_block *sb);
12233 +int au_dr_opt_flush(struct super_block *sb);
12234 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12236 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12237 + struct au_dr_hino *add_ent);
12238 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12239 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12240 + const struct path *path);
12241 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12242 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12243 + struct qstr *dst_name, void *_rev);
12244 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12245 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12247 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12248 + aufs_bindex_t bindex);
12249 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12250 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12251 + aufs_bindex_t bindex, ino_t h_ino);
12252 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12253 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12254 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12255 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12258 +/* ---------------------------------------------------------------------- */
12260 +#ifdef CONFIG_AUFS_DIRREN
12261 +static inline int au_dr_ihash(ino_t h_ino)
12263 + return h_ino % AuDirren_NHASH;
12266 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12269 +#endif /* __KERNEL__ */
12270 +#endif /* __AUFS_DIRREN_H__ */
12271 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12272 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12273 +++ linux/fs/aufs/dynop.c 2021-12-03 15:38:59.933313976 +0100
12275 +// SPDX-License-Identifier: GPL-2.0
12277 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12279 + * This program, aufs is free software; you can redistribute it and/or modify
12280 + * it under the terms of the GNU General Public License as published by
12281 + * the Free Software Foundation; either version 2 of the License, or
12282 + * (at your option) any later version.
12284 + * This program is distributed in the hope that it will be useful,
12285 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12286 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12287 + * GNU General Public License for more details.
12289 + * You should have received a copy of the GNU General Public License
12290 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12294 + * dynamically customizable operations for regular files
12299 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12302 + * How large will these lists be?
12303 + * Usually just a few elements, 20-30 at most for each, I guess.
12305 +static struct hlist_bl_head dynop[AuDyLast];
12307 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12308 + const void *h_op)
12310 + struct au_dykey *key, *tmp;
12311 + struct hlist_bl_node *pos;
12314 + hlist_bl_lock(hbl);
12315 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12316 + if (tmp->dk_op.dy_hop == h_op) {
12317 + if (kref_get_unless_zero(&tmp->dk_kref))
12321 + hlist_bl_unlock(hbl);
12326 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12328 + struct au_dykey **k, *found;
12329 + const void *h_op = key->dk_op.dy_hop;
12333 + k = br->br_dykey;
12334 + for (i = 0; i < AuBrDynOp; i++)
12336 + if (k[i]->dk_op.dy_hop == h_op) {
12343 + spin_lock(&br->br_dykey_lock);
12344 + for (; i < AuBrDynOp; i++)
12346 + if (k[i]->dk_op.dy_hop == h_op) {
12354 + spin_unlock(&br->br_dykey_lock);
12355 + BUG_ON(i == AuBrDynOp); /* expand the array */
12361 +/* kref_get() if @key is already added */
12362 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12364 + struct au_dykey *tmp, *found;
12365 + struct hlist_bl_node *pos;
12366 + const void *h_op = key->dk_op.dy_hop;
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))
12377 + hlist_bl_add_head(&key->dk_hnode, hbl);
12378 + hlist_bl_unlock(hbl);
12385 +static void dy_free_rcu(struct rcu_head *rcu)
12387 + struct au_dykey *key;
12389 + key = container_of(rcu, struct au_dykey, dk_rcu);
12394 +static void dy_free(struct kref *kref)
12396 + struct au_dykey *key;
12397 + struct hlist_bl_head *hbl;
12399 + key = container_of(kref, struct au_dykey, dk_kref);
12400 + hbl = dynop + key->dk_op.dy_type;
12401 + au_hbl_del(&key->dk_hnode, hbl);
12402 + call_rcu(&key->dk_rcu, dy_free_rcu);
12405 +void au_dy_put(struct au_dykey *key)
12407 + kref_put(&key->dk_kref, dy_free);
12410 +/* ---------------------------------------------------------------------- */
12412 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12414 +#ifdef CONFIG_AUFS_DEBUG
12415 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12416 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12418 +#define DyDbgDeclare(cnt) do {} while (0)
12419 +#define DyDbgInc(cnt) do {} while (0)
12422 +#define DySet(func, dst, src, h_op, h_sb) do { \
12424 + if (h_op->func) { \
12426 + dst.func = src.func; \
12428 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12432 +#define DySetForce(func, dst, src) do { \
12433 + AuDebugOn(!src.func); \
12435 + dst.func = src.func; \
12438 +#define DySetAop(func) \
12439 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12440 +#define DySetAopForce(func) \
12441 + DySetForce(func, dyaop->da_op, aufs_aop)
12443 +static void dy_aop(struct au_dykey *key, const void *h_op,
12444 + struct super_block *h_sb __maybe_unused)
12446 + struct au_dyaop *dyaop = (void *)key;
12447 + const struct address_space_operations *h_aop = h_op;
12448 + DyDbgDeclare(cnt);
12450 + AuDbg("%s\n", au_sbtype(h_sb));
12452 + DySetAop(writepage);
12453 + DySetAopForce(readpage); /* force */
12454 + DySetAop(writepages);
12455 + DySetAop(set_page_dirty);
12456 + DySetAop(readpages);
12457 + DySetAop(readahead);
12458 + DySetAop(write_begin);
12459 + DySetAop(write_end);
12461 + DySetAop(invalidatepage);
12462 + DySetAop(releasepage);
12463 + DySetAop(freepage);
12464 + /* this one will be changed according to an aufs mount option */
12465 + DySetAop(direct_IO);
12466 + DySetAop(migratepage);
12467 + DySetAop(isolate_page);
12468 + DySetAop(putback_page);
12469 + DySetAop(launder_page);
12470 + DySetAop(is_partially_uptodate);
12471 + DySetAop(is_dirty_writeback);
12472 + DySetAop(error_remove_page);
12473 + DySetAop(swap_activate);
12474 + DySetAop(swap_deactivate);
12476 + DyDbgSize(cnt, *h_aop);
12479 +/* ---------------------------------------------------------------------- */
12481 +static void dy_bug(struct kref *kref)
12486 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12488 + struct au_dykey *key, *old;
12489 + struct hlist_bl_head *hbl;
12492 + void (*set)(struct au_dykey *key, const void *h_op,
12493 + struct super_block *h_sb __maybe_unused);
12495 + static const struct op a[] = {
12497 + .sz = sizeof(struct au_dyaop),
12501 + const struct op *p;
12503 + hbl = dynop + op->dy_type;
12504 + key = dy_gfind_get(hbl, op->dy_hop);
12506 + goto out_add; /* success */
12508 + p = a + op->dy_type;
12509 + key = kzalloc(p->sz, GFP_NOFS);
12510 + if (unlikely(!key)) {
12511 + key = ERR_PTR(-ENOMEM);
12515 + key->dk_op.dy_hop = op->dy_hop;
12516 + kref_init(&key->dk_kref);
12517 + p->set(key, op->dy_hop, au_br_sb(br));
12518 + old = dy_gadd(hbl, key);
12520 + au_kfree_rcu(key);
12525 + old = dy_bradd(br, key);
12527 + /* its ref-count should never be zero here */
12528 + kref_put(&key->dk_kref, dy_bug);
12533 +/* ---------------------------------------------------------------------- */
12535 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12536 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12537 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12538 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12539 + * See the aufs manual in detail.
12541 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12544 + dyaop->da_op.direct_IO = NULL;
12546 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12549 +static struct au_dyaop *dy_aget(struct au_branch *br,
12550 + const struct address_space_operations *h_aop,
12553 + struct au_dyaop *dyaop;
12554 + struct au_dynop op;
12556 + op.dy_type = AuDy_AOP;
12557 + op.dy_haop = h_aop;
12558 + dyaop = (void *)dy_get(&op, br);
12559 + if (IS_ERR(dyaop))
12561 + dy_adx(dyaop, do_dx);
12567 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12568 + struct inode *h_inode)
12571 + struct super_block *sb;
12572 + struct au_branch *br;
12573 + struct au_dyaop *dyaop;
12575 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12576 + IiMustWriteLock(inode);
12578 + sb = inode->i_sb;
12579 + br = au_sbr(sb, bindex);
12580 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12581 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12582 + err = PTR_ERR(dyaop);
12583 + if (IS_ERR(dyaop))
12584 + /* unnecessary to call dy_fput() */
12588 + inode->i_mapping->a_ops = &dyaop->da_op;
12595 + * Is it safe to replace a_ops during the inode/file is in operation?
12596 + * Yes, I hope so.
12598 +int au_dy_irefresh(struct inode *inode)
12601 + aufs_bindex_t btop;
12602 + struct inode *h_inode;
12605 + if (S_ISREG(inode->i_mode)) {
12606 + btop = au_ibtop(inode);
12607 + h_inode = au_h_iptr(inode, btop);
12608 + err = au_dy_iaop(inode, btop, h_inode);
12613 +void au_dy_arefresh(int do_dx)
12615 + struct hlist_bl_head *hbl;
12616 + struct hlist_bl_node *pos;
12617 + struct au_dykey *key;
12619 + hbl = dynop + AuDy_AOP;
12620 + hlist_bl_lock(hbl);
12621 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12622 + dy_adx((void *)key, do_dx);
12623 + hlist_bl_unlock(hbl);
12626 +/* ---------------------------------------------------------------------- */
12628 +void __init au_dy_init(void)
12632 + for (i = 0; i < AuDyLast; i++)
12633 + INIT_HLIST_BL_HEAD(dynop + i);
12636 +void au_dy_fin(void)
12640 + for (i = 0; i < AuDyLast; i++)
12641 + WARN_ON(!hlist_bl_empty(dynop + i));
12643 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12644 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12645 +++ linux/fs/aufs/dynop.h 2021-12-03 15:38:59.933313976 +0100
12647 +/* SPDX-License-Identifier: GPL-2.0 */
12649 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12651 + * This program, aufs is free software; you can redistribute it and/or modify
12652 + * it under the terms of the GNU General Public License as published by
12653 + * the Free Software Foundation; either version 2 of the License, or
12654 + * (at your option) any later version.
12656 + * This program is distributed in the hope that it will be useful,
12657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12659 + * GNU General Public License for more details.
12661 + * You should have received a copy of the GNU General Public License
12662 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12666 + * dynamically customizable operations (for regular files only)
12669 +#ifndef __AUFS_DYNOP_H__
12670 +#define __AUFS_DYNOP_H__
12674 +#include <linux/fs.h>
12675 +#include <linux/kref.h>
12677 +enum {AuDy_AOP, AuDyLast};
12682 + const void *dy_hop;
12683 + const struct address_space_operations *dy_haop;
12689 + struct hlist_bl_node dk_hnode;
12690 + struct rcu_head dk_rcu;
12692 + struct au_dynop dk_op;
12695 + * during I am in the branch local array, kref is gotten. when the
12696 + * branch is removed, kref is put.
12698 + struct kref dk_kref;
12701 +/* stop unioning since their sizes are very different from each other */
12703 + struct au_dykey da_key;
12704 + struct address_space_operations da_op; /* not const */
12706 +/* make sure that 'struct au_dykey *' can be any type */
12707 +static_assert(!offsetof(struct au_dyaop, da_key));
12709 +/* ---------------------------------------------------------------------- */
12713 +void au_dy_put(struct au_dykey *key);
12714 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12715 + struct inode *h_inode);
12716 +int au_dy_irefresh(struct inode *inode);
12717 +void au_dy_arefresh(int do_dio);
12719 +void __init au_dy_init(void);
12720 +void au_dy_fin(void);
12722 +#endif /* __KERNEL__ */
12723 +#endif /* __AUFS_DYNOP_H__ */
12724 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12725 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12726 +++ linux/fs/aufs/export.c 2021-12-03 15:38:59.933313976 +0100
12728 +// SPDX-License-Identifier: GPL-2.0
12730 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12732 + * This program, aufs is free software; you can redistribute it and/or modify
12733 + * it under the terms of the GNU General Public License as published by
12734 + * the Free Software Foundation; either version 2 of the License, or
12735 + * (at your option) any later version.
12737 + * This program is distributed in the hope that it will be useful,
12738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12740 + * GNU General Public License for more details.
12742 + * You should have received a copy of the GNU General Public License
12743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12750 +#include <linux/exportfs.h>
12751 +#include <linux/fs_struct.h>
12752 +#include <linux/namei.h>
12753 +#include <linux/nsproxy.h>
12754 +#include <linux/random.h>
12755 +#include <linux/writeback.h>
12759 +#ifdef CONFIG_AUFS_INO_T_64
12767 +static ino_t decode_ino(__u32 *a)
12771 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12773 +#ifdef CONFIG_AUFS_INO_T_64
12779 +static void encode_ino(__u32 *a, ino_t ino)
12785 +#ifdef CONFIG_AUFS_INO_T_64
12790 +/* NFS file handle */
12794 +#ifdef CONFIG_AUFS_INO_T_64
12795 + /* support 64bit inode number */
12808 + Fh_ino = Fh_ino1,
12809 + Fh_dir_ino = Fh_dir_ino1
12812 +static int au_test_anon(struct dentry *dentry)
12814 + /* note: read d_flags without d_lock */
12815 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12818 +int au_test_nfsd(void)
12821 + struct task_struct *tsk = current;
12822 + char comm[sizeof(tsk->comm)];
12825 + if (tsk->flags & PF_KTHREAD) {
12826 + get_task_comm(comm, tsk);
12827 + ret = !strcmp(comm, "nfsd");
12833 +/* ---------------------------------------------------------------------- */
12834 +/* inode generation external table */
12836 +void au_xigen_inc(struct inode *inode)
12841 + struct super_block *sb;
12842 + struct au_sbinfo *sbinfo;
12844 + sb = inode->i_sb;
12845 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12847 + sbinfo = au_sbi(sb);
12848 + pos = inode->i_ino;
12849 + pos *= sizeof(igen);
12850 + igen = inode->i_generation + 1;
12851 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12852 + if (sz == sizeof(igen))
12853 + return; /* success */
12855 + if (unlikely(sz >= 0))
12856 + AuIOErr("xigen error (%zd)\n", sz);
12859 +int au_xigen_new(struct inode *inode)
12864 + struct super_block *sb;
12865 + struct au_sbinfo *sbinfo;
12866 + struct file *file;
12869 + /* todo: dirty, at mount time */
12870 + if (inode->i_ino == AUFS_ROOT_INO)
12872 + sb = inode->i_sb;
12873 + SiMustAnyLock(sb);
12874 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12878 + pos = inode->i_ino;
12879 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12880 + AuIOErr1("too large i%lld\n", pos);
12883 + pos *= sizeof(inode->i_generation);
12886 + sbinfo = au_sbi(sb);
12887 + file = sbinfo->si_xigen;
12890 + if (vfsub_f_size_read(file)
12891 + < pos + sizeof(inode->i_generation)) {
12892 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12893 + sz = xino_fwrite(file, &inode->i_generation,
12894 + sizeof(inode->i_generation), &pos);
12896 + sz = xino_fread(file, &inode->i_generation,
12897 + sizeof(inode->i_generation), &pos);
12898 + if (sz == sizeof(inode->i_generation))
12899 + goto out; /* success */
12902 + if (unlikely(sz >= 0)) {
12904 + AuIOErr("xigen error (%zd)\n", sz);
12911 +int au_xigen_set(struct super_block *sb, struct path *path)
12914 + struct au_sbinfo *sbinfo;
12915 + struct file *file;
12917 + SiMustWriteLock(sb);
12919 + sbinfo = au_sbi(sb);
12920 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12921 + err = PTR_ERR(file);
12922 + if (IS_ERR(file))
12925 + if (sbinfo->si_xigen)
12926 + fput(sbinfo->si_xigen);
12927 + sbinfo->si_xigen = file;
12934 +void au_xigen_clr(struct super_block *sb)
12936 + struct au_sbinfo *sbinfo;
12938 + SiMustWriteLock(sb);
12940 + sbinfo = au_sbi(sb);
12941 + if (sbinfo->si_xigen) {
12942 + fput(sbinfo->si_xigen);
12943 + sbinfo->si_xigen = NULL;
12947 +/* ---------------------------------------------------------------------- */
12949 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12952 + struct dentry *dentry, *d;
12953 + struct inode *inode;
12954 + unsigned int sigen;
12957 + inode = ilookup(sb, ino);
12961 + dentry = ERR_PTR(-ESTALE);
12962 + sigen = au_sigen(sb);
12963 + if (unlikely(au_is_bad_inode(inode)
12964 + || IS_DEADDIR(inode)
12965 + || sigen != au_iigen(inode, NULL)))
12969 + if (!dir_ino || S_ISDIR(inode->i_mode))
12970 + dentry = d_find_alias(inode);
12972 + spin_lock(&inode->i_lock);
12973 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
12974 + spin_lock(&d->d_lock);
12975 + if (!au_test_anon(d)
12976 + && d_inode(d->d_parent)->i_ino == dir_ino) {
12977 + dentry = dget_dlock(d);
12978 + spin_unlock(&d->d_lock);
12981 + spin_unlock(&d->d_lock);
12983 + spin_unlock(&inode->i_lock);
12985 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
12986 + /* need to refresh */
12994 + AuTraceErrPtr(dentry);
12998 +/* ---------------------------------------------------------------------- */
13000 +/* todo: dirty? */
13001 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13003 +struct au_compare_mnt_args {
13005 + struct super_block *sb;
13008 + struct vfsmount *mnt;
13011 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13013 + struct au_compare_mnt_args *a = arg;
13015 + if (mnt->mnt_sb != a->sb)
13017 + a->mnt = mntget(mnt);
13021 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13024 + struct path root;
13025 + struct au_compare_mnt_args args = {
13029 + get_fs_root(current->fs, &root);
13031 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13032 + rcu_read_unlock();
13035 + AuDebugOn(!args.mnt);
13039 +struct au_nfsd_si_lock {
13040 + unsigned int sigen;
13041 + aufs_bindex_t bindex, br_id;
13042 + unsigned char force_lock;
13045 +static int si_nfsd_read_lock(struct super_block *sb,
13046 + struct au_nfsd_si_lock *nsi_lock)
13049 + aufs_bindex_t bindex;
13051 + si_read_lock(sb, AuLock_FLUSH);
13053 + /* branch id may be wrapped around */
13055 + bindex = au_br_index(sb, nsi_lock->br_id);
13056 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13057 + goto out; /* success */
13061 + if (!nsi_lock->force_lock)
13062 + si_read_unlock(sb);
13065 + nsi_lock->bindex = bindex;
13069 +struct find_name_by_ino {
13070 + struct dir_context ctx;
13071 + int called, found;
13078 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13079 + loff_t offset, u64 ino, unsigned int d_type)
13081 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13085 + if (a->ino != ino)
13088 + memcpy(a->name, name, namelen);
13089 + a->namelen = namelen;
13094 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13095 + struct au_nfsd_si_lock *nsi_lock)
13097 + struct dentry *dentry, *parent;
13098 + struct file *file;
13099 + struct inode *dir;
13100 + struct find_name_by_ino arg = {
13102 + .actor = find_name_by_ino
13107 + parent = path->dentry;
13109 + si_read_unlock(parent->d_sb);
13110 + file = vfsub_dentry_open(path, au_dir_roflags);
13111 + dentry = (void *)file;
13112 + if (IS_ERR(file))
13115 + dentry = ERR_PTR(-ENOMEM);
13116 + arg.name = (void *)__get_free_page(GFP_NOFS);
13117 + if (unlikely(!arg.name))
13124 + err = vfsub_iterate_dir(file, &arg.ctx);
13125 + } while (!err && !arg.found && arg.called);
13126 + dentry = ERR_PTR(err);
13127 + if (unlikely(err))
13129 + /* instead of ENOENT */
13130 + dentry = ERR_PTR(-ESTALE);
13134 + /* do not call vfsub_lkup_one() */
13135 + dir = d_inode(parent);
13136 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13137 + AuTraceErrPtr(dentry);
13138 + if (IS_ERR(dentry))
13140 + AuDebugOn(au_test_anon(dentry));
13141 + if (unlikely(d_really_is_negative(dentry))) {
13143 + dentry = ERR_PTR(-ENOENT);
13147 + free_page((unsigned long)arg.name);
13151 + if (unlikely(nsi_lock
13152 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13153 + if (!IS_ERR(dentry)) {
13155 + dentry = ERR_PTR(-ESTALE);
13157 + AuTraceErrPtr(dentry);
13161 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13163 + struct au_nfsd_si_lock *nsi_lock)
13165 + struct dentry *dentry;
13166 + struct path path;
13168 + if (dir_ino != AUFS_ROOT_INO) {
13169 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13170 + dentry = path.dentry;
13171 + if (!path.dentry || IS_ERR(path.dentry))
13173 + AuDebugOn(au_test_anon(path.dentry));
13175 + path.dentry = dget(sb->s_root);
13177 + path.mnt = au_mnt_get(sb);
13178 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13182 + AuTraceErrPtr(dentry);
13186 +/* ---------------------------------------------------------------------- */
13188 +static int h_acceptable(void *expv, struct dentry *dentry)
13193 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13194 + char *buf, int len, struct super_block *sb)
13198 + struct path path;
13200 + p = d_path(h_rootpath, buf, len);
13205 + path.mnt = h_rootpath->mnt;
13206 + path.dentry = h_parent;
13207 + p = d_path(&path, buf, len);
13213 + path.mnt = au_mnt_get(sb);
13214 + path.dentry = sb->s_root;
13215 + p = d_path(&path, buf, len - strlen(p));
13216 + mntput(path.mnt);
13220 + p[strlen(p)] = '/';
13223 + AuTraceErrPtr(p);
13228 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13229 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13231 + struct dentry *dentry, *h_parent, *root;
13232 + struct super_block *h_sb;
13233 + char *pathname, *p;
13234 + struct vfsmount *h_mnt;
13235 + struct au_branch *br;
13237 + struct path path;
13239 + br = au_sbr(sb, nsi_lock->bindex);
13240 + h_mnt = au_br_mnt(br);
13241 + h_sb = h_mnt->mnt_sb;
13242 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13244 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13245 + fh_len - Fh_tail, fh[Fh_h_type],
13246 + h_acceptable, /*context*/NULL);
13248 + dentry = h_parent;
13249 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13250 + AuWarn1("%s decode_fh failed, %ld\n",
13251 + au_sbtype(h_sb), PTR_ERR(h_parent));
13255 + if (unlikely(au_test_anon(h_parent))) {
13256 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13257 + au_sbtype(h_sb));
13258 + goto out_h_parent;
13261 + dentry = ERR_PTR(-ENOMEM);
13262 + pathname = (void *)__get_free_page(GFP_NOFS);
13263 + if (unlikely(!pathname))
13264 + goto out_h_parent;
13266 + root = sb->s_root;
13267 + path.mnt = h_mnt;
13268 + di_read_lock_parent(root, !AuLock_IR);
13269 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13270 + di_read_unlock(root, !AuLock_IR);
13271 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13272 + dentry = (void *)p;
13274 + goto out_pathname;
13276 + si_read_unlock(sb);
13277 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13278 + dentry = ERR_PTR(err);
13279 + if (unlikely(err))
13282 + dentry = ERR_PTR(-ENOENT);
13283 + AuDebugOn(au_test_anon(path.dentry));
13284 + if (unlikely(d_really_is_negative(path.dentry)))
13287 + if (ino != d_inode(path.dentry)->i_ino)
13288 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13290 + dentry = dget(path.dentry);
13295 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13296 + if (!IS_ERR(dentry)) {
13298 + dentry = ERR_PTR(-ESTALE);
13301 + free_page((unsigned long)pathname);
13305 + AuTraceErrPtr(dentry);
13309 +/* ---------------------------------------------------------------------- */
13311 +static struct dentry *
13312 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13315 + struct dentry *dentry;
13316 + __u32 *fh = fid->raw;
13317 + struct au_branch *br;
13318 + ino_t ino, dir_ino;
13319 + struct au_nfsd_si_lock nsi_lock = {
13323 + dentry = ERR_PTR(-ESTALE);
13324 + /* it should never happen, but the file handle is unreliable */
13325 + if (unlikely(fh_len < Fh_tail))
13327 + nsi_lock.sigen = fh[Fh_sigen];
13328 + nsi_lock.br_id = fh[Fh_br_id];
13330 + /* branch id may be wrapped around */
13332 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13334 + nsi_lock.force_lock = 1;
13336 + /* is this inode still cached? */
13337 + ino = decode_ino(fh + Fh_ino);
13338 + /* it should never happen */
13339 + if (unlikely(ino == AUFS_ROOT_INO))
13342 + dir_ino = decode_ino(fh + Fh_dir_ino);
13343 + dentry = decode_by_ino(sb, ino, dir_ino);
13344 + if (IS_ERR(dentry))
13349 + /* is the parent dir cached? */
13350 + br = au_sbr(sb, nsi_lock.bindex);
13351 + au_lcnt_inc(&br->br_nfiles);
13352 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13353 + if (IS_ERR(dentry))
13358 + /* lookup path */
13359 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13360 + if (IS_ERR(dentry))
13362 + if (unlikely(!dentry))
13363 + /* todo?: make it ESTALE */
13367 + if (!au_digen_test(dentry, au_sigen(sb))
13368 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13369 + goto out_unlock; /* success */
13372 + dentry = ERR_PTR(-ESTALE);
13375 + au_lcnt_dec(&br->br_nfiles);
13376 + si_read_unlock(sb);
13378 + AuTraceErrPtr(dentry);
13382 +#if 0 /* reserved for future use */
13383 +/* support subtreecheck option */
13384 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13385 + int fh_len, int fh_type)
13387 + struct dentry *parent;
13388 + __u32 *fh = fid->raw;
13391 + dir_ino = decode_ino(fh + Fh_dir_ino);
13392 + parent = decode_by_ino(sb, dir_ino, 0);
13393 + if (IS_ERR(parent))
13396 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13397 + dir_ino, fh, fh_len);
13400 + AuTraceErrPtr(parent);
13405 +/* ---------------------------------------------------------------------- */
13407 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13408 + struct inode *dir)
13411 + aufs_bindex_t bindex;
13412 + struct super_block *sb, *h_sb;
13413 + struct dentry *dentry, *parent, *h_parent;
13414 + struct inode *h_dir;
13415 + struct au_branch *br;
13418 + if (unlikely(*max_len <= Fh_tail)) {
13419 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13423 + err = FILEID_ROOT;
13424 + if (inode->i_ino == AUFS_ROOT_INO) {
13425 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13430 + sb = inode->i_sb;
13431 + err = si_read_lock(sb, AuLock_FLUSH);
13432 + if (unlikely(err))
13435 +#ifdef CONFIG_AUFS_DEBUG
13436 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13437 + AuWarn1("NFS-exporting requires xino\n");
13441 + ii_read_lock_child(inode);
13442 + bindex = au_ibtop(inode);
13444 + dentry = d_find_any_alias(inode);
13445 + if (unlikely(!dentry))
13447 + AuDebugOn(au_test_anon(dentry));
13448 + parent = dget_parent(dentry);
13450 + if (unlikely(!parent))
13452 + if (d_really_is_positive(parent))
13453 + dir = d_inode(parent);
13456 + ii_read_lock_parent(dir);
13457 + h_dir = au_h_iptr(dir, bindex);
13458 + ii_read_unlock(dir);
13459 + if (unlikely(!h_dir))
13461 + h_parent = d_find_any_alias(h_dir);
13462 + if (unlikely(!h_parent))
13463 + goto out_hparent;
13466 + br = au_sbr(sb, bindex);
13467 + h_sb = au_br_sb(br);
13468 + if (unlikely(!h_sb->s_export_op)) {
13469 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13470 + goto out_hparent;
13473 + fh[Fh_br_id] = br->br_id;
13474 + fh[Fh_sigen] = au_sigen(sb);
13475 + encode_ino(fh + Fh_ino, inode->i_ino);
13476 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13477 + fh[Fh_igen] = inode->i_generation;
13479 + *max_len -= Fh_tail;
13480 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13482 + /*connectable or subtreecheck*/0);
13483 + err = fh[Fh_h_type];
13484 + *max_len += Fh_tail;
13485 + /* todo: macros? */
13486 + if (err != FILEID_INVALID)
13489 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13496 + ii_read_unlock(inode);
13497 + si_read_unlock(sb);
13499 + if (unlikely(err < 0))
13500 + err = FILEID_INVALID;
13504 +/* ---------------------------------------------------------------------- */
13506 +static int aufs_commit_metadata(struct inode *inode)
13509 + aufs_bindex_t bindex;
13510 + struct super_block *sb;
13511 + struct inode *h_inode;
13512 + int (*f)(struct inode *inode);
13514 + sb = inode->i_sb;
13515 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13516 + ii_write_lock_child(inode);
13517 + bindex = au_ibtop(inode);
13518 + AuDebugOn(bindex < 0);
13519 + h_inode = au_h_iptr(inode, bindex);
13521 + f = h_inode->i_sb->s_export_op->commit_metadata;
13523 + err = f(h_inode);
13525 + struct writeback_control wbc = {
13526 + .sync_mode = WB_SYNC_ALL,
13527 + .nr_to_write = 0 /* metadata only */
13530 + err = sync_inode(h_inode, &wbc);
13533 + au_cpup_attr_timesizes(inode);
13534 + ii_write_unlock(inode);
13535 + si_read_unlock(sb);
13539 +/* ---------------------------------------------------------------------- */
13541 +static struct export_operations aufs_export_op = {
13542 + .fh_to_dentry = aufs_fh_to_dentry,
13543 + /* .fh_to_parent = aufs_fh_to_parent, */
13544 + .encode_fh = aufs_encode_fh,
13545 + .commit_metadata = aufs_commit_metadata
13548 +void au_export_init(struct super_block *sb)
13550 + struct au_sbinfo *sbinfo;
13553 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13554 + && IS_MODULE(CONFIG_EXPORTFS),
13555 + AUFS_NAME ": unsupported configuration "
13556 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13558 + sb->s_export_op = &aufs_export_op;
13559 + sbinfo = au_sbi(sb);
13560 + sbinfo->si_xigen = NULL;
13561 + get_random_bytes(&u, sizeof(u));
13562 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13563 + atomic_set(&sbinfo->si_xigen_next, u);
13565 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13566 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13567 +++ linux/fs/aufs/fhsm.c 2021-12-03 15:38:59.933313976 +0100
13569 +// SPDX-License-Identifier: GPL-2.0
13571 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13573 + * This program, aufs is free software; you can redistribute it and/or modify
13574 + * it under the terms of the GNU General Public License as published by
13575 + * the Free Software Foundation; either version 2 of the License, or
13576 + * (at your option) any later version.
13578 + * This program is distributed in the hope that it will be useful,
13579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13581 + * GNU General Public License for more details.
13583 + * You should have received a copy of the GNU General Public License
13584 + * along with this program; if not, write to the Free Software
13585 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13589 + * File-based Hierarchy Storage Management
13592 +#include <linux/anon_inodes.h>
13593 +#include <linux/poll.h>
13594 +#include <linux/seq_file.h>
13595 +#include <linux/statfs.h>
13598 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13600 + struct au_sbinfo *sbinfo;
13601 + struct au_fhsm *fhsm;
13603 + SiMustAnyLock(sb);
13605 + sbinfo = au_sbi(sb);
13606 + fhsm = &sbinfo->si_fhsm;
13607 + AuDebugOn(!fhsm);
13608 + return fhsm->fhsm_bottom;
13611 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13613 + struct au_sbinfo *sbinfo;
13614 + struct au_fhsm *fhsm;
13616 + SiMustWriteLock(sb);
13618 + sbinfo = au_sbi(sb);
13619 + fhsm = &sbinfo->si_fhsm;
13620 + AuDebugOn(!fhsm);
13621 + fhsm->fhsm_bottom = bindex;
13624 +/* ---------------------------------------------------------------------- */
13626 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13628 + struct au_br_fhsm *bf;
13630 + bf = br->br_fhsm;
13631 + MtxMustLock(&bf->bf_lock);
13633 + return !bf->bf_readable
13634 + || time_after(jiffies,
13635 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13638 +/* ---------------------------------------------------------------------- */
13640 +static void au_fhsm_notify(struct super_block *sb, int val)
13642 + struct au_sbinfo *sbinfo;
13643 + struct au_fhsm *fhsm;
13645 + SiMustAnyLock(sb);
13647 + sbinfo = au_sbi(sb);
13648 + fhsm = &sbinfo->si_fhsm;
13649 + if (au_fhsm_pid(fhsm)
13650 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13651 + atomic_set(&fhsm->fhsm_readable, val);
13653 + wake_up(&fhsm->fhsm_wqh);
13657 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13658 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13661 + struct au_branch *br;
13662 + struct au_br_fhsm *bf;
13664 + br = au_sbr(sb, bindex);
13665 + AuDebugOn(au_br_rdonly(br));
13666 + bf = br->br_fhsm;
13670 + mutex_lock(&bf->bf_lock);
13672 + MtxMustLock(&bf->bf_lock);
13674 + /* sb->s_root for NFS is unreliable */
13675 + err = au_br_stfs(br, &bf->bf_stfs);
13676 + if (unlikely(err)) {
13677 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13681 + bf->bf_jiffy = jiffies;
13682 + bf->bf_readable = 1;
13684 + au_fhsm_notify(sb, /*val*/1);
13686 + *rstfs = bf->bf_stfs;
13690 + mutex_unlock(&bf->bf_lock);
13691 + au_fhsm_notify(sb, /*val*/1);
13696 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13699 + struct au_sbinfo *sbinfo;
13700 + struct au_fhsm *fhsm;
13701 + struct au_branch *br;
13702 + struct au_br_fhsm *bf;
13704 + AuDbg("b%d, force %d\n", bindex, force);
13705 + SiMustAnyLock(sb);
13707 + sbinfo = au_sbi(sb);
13708 + fhsm = &sbinfo->si_fhsm;
13709 + if (!au_ftest_si(sbinfo, FHSM)
13710 + || fhsm->fhsm_bottom == bindex)
13713 + br = au_sbr(sb, bindex);
13714 + bf = br->br_fhsm;
13716 + mutex_lock(&bf->bf_lock);
13718 + || au_fhsm_pid(fhsm)
13719 + || au_fhsm_test_jiffy(sbinfo, br))
13720 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13722 + mutex_unlock(&bf->bf_lock);
13725 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13727 + aufs_bindex_t bindex, bbot;
13728 + struct au_branch *br;
13730 + /* exclude the bottom */
13731 + bbot = au_fhsm_bottom(sb);
13732 + for (bindex = 0; bindex < bbot; bindex++) {
13733 + br = au_sbr(sb, bindex);
13734 + if (au_br_fhsm(br->br_perm))
13735 + au_fhsm_wrote(sb, bindex, force);
13739 +/* ---------------------------------------------------------------------- */
13741 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13744 + struct au_sbinfo *sbinfo;
13745 + struct au_fhsm *fhsm;
13748 + sbinfo = file->private_data;
13749 + fhsm = &sbinfo->si_fhsm;
13750 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13751 + if (atomic_read(&fhsm->fhsm_readable))
13752 + mask = EPOLLIN /* | EPOLLRDNORM */;
13755 + AuDbg("mask 0x%x\n", mask);
13759 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13760 + struct aufs_stfs *stfs, __s16 brid)
13764 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13766 + err = __put_user(brid, &stbr->brid);
13767 + if (unlikely(err))
13773 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13774 + struct aufs_stbr __user *stbr, size_t count)
13778 + aufs_bindex_t bindex, bbot;
13779 + struct au_branch *br;
13780 + struct au_br_fhsm *bf;
13782 + /* except the bottom branch */
13785 + bbot = au_fhsm_bottom(sb);
13786 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13787 + br = au_sbr(sb, bindex);
13788 + if (!au_br_fhsm(br->br_perm))
13791 + bf = br->br_fhsm;
13792 + mutex_lock(&bf->bf_lock);
13793 + if (bf->bf_readable) {
13795 + if (count >= sizeof(*stbr))
13796 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13799 + bf->bf_readable = 0;
13800 + count -= sizeof(*stbr);
13804 + mutex_unlock(&bf->bf_lock);
13807 + err = sizeof(*stbr) * nstbr;
13812 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13817 + aufs_bindex_t nfhsm, bindex, bbot;
13818 + struct au_sbinfo *sbinfo;
13819 + struct au_fhsm *fhsm;
13820 + struct au_branch *br;
13821 + struct super_block *sb;
13824 + sbinfo = file->private_data;
13825 + fhsm = &sbinfo->si_fhsm;
13827 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13828 + if (!atomic_read(&fhsm->fhsm_readable)) {
13829 + if (vfsub_file_flags(file) & O_NONBLOCK)
13832 + err = wait_event_interruptible_locked_irq
13834 + atomic_read(&fhsm->fhsm_readable));
13836 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13837 + if (unlikely(err))
13840 + /* sb may already be dead */
13841 + au_rw_read_lock(&sbinfo->si_rwsem);
13842 + readable = atomic_read(&fhsm->fhsm_readable);
13843 + if (readable > 0) {
13844 + sb = sbinfo->si_sb;
13846 + /* exclude the bottom branch */
13848 + bbot = au_fhsm_bottom(sb);
13849 + for (bindex = 0; bindex < bbot; bindex++) {
13850 + br = au_sbr(sb, bindex);
13851 + if (au_br_fhsm(br->br_perm))
13855 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13856 + atomic_set(&fhsm->fhsm_readable, 0);
13857 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13861 + au_rw_read_unlock(&sbinfo->si_rwsem);
13869 +static int au_fhsm_release(struct inode *inode, struct file *file)
13871 + struct au_sbinfo *sbinfo;
13872 + struct au_fhsm *fhsm;
13874 + /* sb may already be dead */
13875 + sbinfo = file->private_data;
13876 + fhsm = &sbinfo->si_fhsm;
13877 + spin_lock(&fhsm->fhsm_spin);
13878 + fhsm->fhsm_pid = 0;
13879 + spin_unlock(&fhsm->fhsm_spin);
13880 + kobject_put(&sbinfo->si_kobj);
13885 +static const struct file_operations au_fhsm_fops = {
13886 + .owner = THIS_MODULE,
13887 + .llseek = noop_llseek,
13888 + .read = au_fhsm_read,
13889 + .poll = au_fhsm_poll,
13890 + .release = au_fhsm_release
13893 +int au_fhsm_fd(struct super_block *sb, int oflags)
13896 + struct au_sbinfo *sbinfo;
13897 + struct au_fhsm *fhsm;
13900 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13904 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13908 + sbinfo = au_sbi(sb);
13909 + fhsm = &sbinfo->si_fhsm;
13910 + spin_lock(&fhsm->fhsm_spin);
13911 + if (!fhsm->fhsm_pid)
13912 + fhsm->fhsm_pid = current->pid;
13915 + spin_unlock(&fhsm->fhsm_spin);
13916 + if (unlikely(err))
13919 + oflags |= O_RDONLY;
13920 + /* oflags |= FMODE_NONOTIFY; */
13921 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13923 + if (unlikely(fd < 0))
13926 + /* succeed regardless 'fhsm' status */
13927 + kobject_get(&sbinfo->si_kobj);
13928 + si_noflush_read_lock(sb);
13929 + if (au_ftest_si(sbinfo, FHSM))
13930 + au_fhsm_wrote_all(sb, /*force*/0);
13931 + si_read_unlock(sb);
13932 + goto out; /* success */
13935 + spin_lock(&fhsm->fhsm_spin);
13936 + fhsm->fhsm_pid = 0;
13937 + spin_unlock(&fhsm->fhsm_spin);
13943 +/* ---------------------------------------------------------------------- */
13945 +int au_fhsm_br_alloc(struct au_branch *br)
13950 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13952 + au_br_fhsm_init(br->br_fhsm);
13959 +/* ---------------------------------------------------------------------- */
13961 +void au_fhsm_fin(struct super_block *sb)
13963 + au_fhsm_notify(sb, /*val*/-1);
13966 +void au_fhsm_init(struct au_sbinfo *sbinfo)
13968 + struct au_fhsm *fhsm;
13970 + fhsm = &sbinfo->si_fhsm;
13971 + spin_lock_init(&fhsm->fhsm_spin);
13972 + init_waitqueue_head(&fhsm->fhsm_wqh);
13973 + atomic_set(&fhsm->fhsm_readable, 0);
13974 + fhsm->fhsm_expire
13975 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
13976 + fhsm->fhsm_bottom = -1;
13979 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
13981 + sbinfo->si_fhsm.fhsm_expire
13982 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
13985 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
13989 + if (!au_ftest_si(sbinfo, FHSM))
13992 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
13993 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
13994 + seq_printf(seq, ",fhsm_sec=%u", u);
13996 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
13997 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
13998 +++ linux/fs/aufs/file.c 2021-12-03 15:38:59.936647310 +0100
14000 +// SPDX-License-Identifier: GPL-2.0
14002 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14004 + * This program, aufs is free software; you can redistribute it and/or modify
14005 + * it under the terms of the GNU General Public License as published by
14006 + * the Free Software Foundation; either version 2 of the License, or
14007 + * (at your option) any later version.
14009 + * This program is distributed in the hope that it will be useful,
14010 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14011 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14012 + * GNU General Public License for more details.
14014 + * You should have received a copy of the GNU General Public License
14015 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14019 + * handling file/dir, and address_space operation
14022 +#ifdef CONFIG_AUFS_DEBUG
14023 +#include <linux/migrate.h>
14025 +#include <linux/pagemap.h>
14028 +/* drop flags for writing */
14029 +unsigned int au_file_roflags(unsigned int flags)
14031 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14032 + flags |= O_RDONLY | O_NOATIME;
14036 +/* common functions to regular file and dir */
14037 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14038 + struct file *file, int force_wr)
14040 + struct file *h_file;
14041 + struct dentry *h_dentry;
14042 + struct inode *h_inode;
14043 + struct super_block *sb;
14044 + struct au_branch *br;
14045 + struct path h_path;
14048 + /* a race condition can happen between open and unlink/rmdir */
14049 + h_file = ERR_PTR(-ENOENT);
14050 + h_dentry = au_h_dptr(dentry, bindex);
14051 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14053 + h_inode = d_inode(h_dentry);
14054 + spin_lock(&h_dentry->d_lock);
14055 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14056 + /* || !d_inode(dentry)->i_nlink */
14058 + spin_unlock(&h_dentry->d_lock);
14059 + if (unlikely(err))
14062 + sb = dentry->d_sb;
14063 + br = au_sbr(sb, bindex);
14064 + err = au_br_test_oflag(flags, br);
14065 + h_file = ERR_PTR(err);
14066 + if (unlikely(err))
14069 + /* drop flags for writing */
14070 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14071 + if (force_wr && !(flags & O_WRONLY))
14073 + flags = au_file_roflags(flags);
14075 + h_file = ERR_PTR(-EROFS);
14076 + flags = au_file_roflags(flags);
14077 + if (unlikely(vfsub_native_ro(h_inode)
14078 + || IS_APPEND(h_inode)))
14080 + flags &= ~O_ACCMODE;
14081 + flags |= O_WRONLY;
14084 + flags &= ~O_CREAT;
14085 + au_lcnt_inc(&br->br_nfiles);
14086 + h_path.dentry = h_dentry;
14087 + h_path.mnt = au_br_mnt(br);
14088 + h_file = vfsub_dentry_open(&h_path, flags);
14089 + if (IS_ERR(h_file))
14092 + if (flags & __FMODE_EXEC) {
14093 + err = deny_write_access(h_file);
14094 + if (unlikely(err)) {
14096 + h_file = ERR_PTR(err);
14100 + fsnotify_open(h_file);
14101 + goto out; /* success */
14104 + au_lcnt_dec(&br->br_nfiles);
14109 +static int au_cmoo(struct dentry *dentry)
14111 + int err, cmoo, matched;
14112 + unsigned int udba;
14113 + struct path h_path;
14114 + struct au_pin pin;
14115 + struct au_cp_generic cpg = {
14116 + .dentry = dentry,
14121 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14123 + struct inode *delegated;
14124 + struct super_block *sb;
14125 + struct au_sbinfo *sbinfo;
14126 + struct au_fhsm *fhsm;
14128 + struct au_branch *br;
14129 + struct dentry *parent;
14130 + struct au_hinode *hdir;
14132 + DiMustWriteLock(dentry);
14133 + IiMustWriteLock(d_inode(dentry));
14136 + if (IS_ROOT(dentry))
14138 + cpg.bsrc = au_dbtop(dentry);
14142 + sb = dentry->d_sb;
14143 + sbinfo = au_sbi(sb);
14144 + fhsm = &sbinfo->si_fhsm;
14145 + pid = au_fhsm_pid(fhsm);
14148 + && (current->pid == pid
14149 + || rcu_dereference(current->real_parent)->pid == pid));
14150 + rcu_read_unlock();
14154 + br = au_sbr(sb, cpg.bsrc);
14155 + cmoo = au_br_cmoo(br->br_perm);
14158 + if (!d_is_reg(dentry))
14159 + cmoo &= AuBrAttr_COO_ALL;
14163 + parent = dget_parent(dentry);
14164 + di_write_lock_parent(parent);
14165 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14167 + if (unlikely(err < 0)) {
14168 + err = 0; /* there is no upper writable branch */
14171 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14173 + /* do not respect the coo attrib for the target branch */
14174 + err = au_cpup_dirs(dentry, cpg.bdst);
14175 + if (unlikely(err))
14178 + di_downgrade_lock(parent, AuLock_IR);
14179 + udba = au_opt_udba(sb);
14180 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14181 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14182 + if (unlikely(err))
14185 + err = au_sio_cpup_simple(&cpg);
14187 + if (unlikely(err))
14189 + if (!(cmoo & AuBrWAttr_MOO))
14190 + goto out_parent; /* success */
14192 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14193 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14194 + if (unlikely(err))
14197 + h_path.mnt = au_br_mnt(br);
14198 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14199 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14200 + delegated = NULL;
14201 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14203 + /* todo: keep h_dentry or not? */
14204 + if (unlikely(err == -EWOULDBLOCK)) {
14205 + pr_warn("cannot retry for NFSv4 delegation"
14206 + " for an internal unlink\n");
14209 + if (unlikely(err)) {
14210 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14214 + goto out_parent; /* success */
14217 + di_downgrade_lock(parent, AuLock_IR);
14219 + di_read_unlock(parent, AuLock_IR);
14226 +int au_do_open(struct file *file, struct au_do_open_args *args)
14228 + int err, aopen = args->aopen;
14229 + struct dentry *dentry;
14230 + struct au_finfo *finfo;
14233 + err = au_finfo_init(file, args->fidir);
14236 + err = au_finfo_init(file, args->fidir);
14239 + if (unlikely(err))
14242 + dentry = file->f_path.dentry;
14243 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14244 + di_write_lock_child(dentry);
14245 + err = au_cmoo(dentry);
14246 + di_downgrade_lock(dentry, AuLock_IR);
14249 + err = args->open(file, vfsub_file_flags(file), NULL);
14252 + err = args->open(file, vfsub_file_flags(file),
14257 + di_read_unlock(dentry, AuLock_IR);
14259 + finfo = au_fi(file);
14261 + finfo->fi_file = file;
14262 + au_hbl_add(&finfo->fi_hlist,
14263 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14266 + fi_write_unlock(file);
14269 + fi_write_unlock(file);
14272 + if (unlikely(err)) {
14273 + finfo->fi_hdir = NULL;
14274 + au_finfo_fin(file);
14282 +int au_reopen_nondir(struct file *file)
14285 + aufs_bindex_t btop;
14286 + struct dentry *dentry;
14287 + struct au_branch *br;
14288 + struct file *h_file, *h_file_tmp;
14290 + dentry = file->f_path.dentry;
14291 + btop = au_dbtop(dentry);
14292 + br = au_sbr(dentry->d_sb, btop);
14293 + h_file_tmp = NULL;
14294 + if (au_fbtop(file) == btop) {
14295 + h_file = au_hf_top(file);
14296 + if (file->f_mode == h_file->f_mode)
14297 + return 0; /* success */
14298 + h_file_tmp = h_file;
14299 + get_file(h_file_tmp);
14300 + au_lcnt_inc(&br->br_nfiles);
14301 + au_set_h_fptr(file, btop, NULL);
14303 + AuDebugOn(au_fi(file)->fi_hdir);
14306 + * file exists on both of rw and ro
14307 + * open --> dbtop and fbtop are both 0
14308 + * prepend a branch as rw, "rw" become ro
14310 + * delete the top branch, "rw" becomes rw again
14311 + * --> dbtop is 1, fbtop is still 0
14312 + * write --> fbtop is 0 but dbtop is 1
14314 + /* AuDebugOn(au_fbtop(file) < btop); */
14316 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14317 + file, /*force_wr*/0);
14318 + err = PTR_ERR(h_file);
14319 + if (IS_ERR(h_file)) {
14320 + if (h_file_tmp) {
14322 + au_set_h_fptr(file, btop, h_file_tmp);
14323 + h_file_tmp = NULL;
14325 + goto out; /* todo: close all? */
14329 + au_set_fbtop(file, btop);
14330 + au_set_h_fptr(file, btop, h_file);
14331 + au_update_figen(file);
14332 + /* todo: necessary? */
14333 + /* file->f_ra = h_file->f_ra; */
14336 + if (h_file_tmp) {
14337 + fput(h_file_tmp);
14338 + au_lcnt_dec(&br->br_nfiles);
14343 +/* ---------------------------------------------------------------------- */
14345 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14346 + struct dentry *hi_wh)
14349 + aufs_bindex_t btop;
14350 + struct au_dinfo *dinfo;
14351 + struct dentry *h_dentry;
14352 + struct au_hdentry *hdp;
14354 + dinfo = au_di(file->f_path.dentry);
14355 + AuRwMustWriteLock(&dinfo->di_rwsem);
14357 + btop = dinfo->di_btop;
14358 + dinfo->di_btop = btgt;
14359 + hdp = au_hdentry(dinfo, btgt);
14360 + h_dentry = hdp->hd_dentry;
14361 + hdp->hd_dentry = hi_wh;
14362 + err = au_reopen_nondir(file);
14363 + hdp->hd_dentry = h_dentry;
14364 + dinfo->di_btop = btop;
14369 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14370 + aufs_bindex_t bcpup, struct au_pin *pin)
14373 + struct inode *inode, *h_inode;
14374 + struct dentry *h_dentry, *hi_wh;
14375 + struct au_cp_generic cpg = {
14376 + .dentry = file->f_path.dentry,
14383 + au_update_dbtop(cpg.dentry);
14384 + inode = d_inode(cpg.dentry);
14386 + if (au_dbtop(cpg.dentry) <= bcpup
14387 + && au_dbbot(cpg.dentry) >= bcpup) {
14388 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14389 + if (h_dentry && d_is_positive(h_dentry))
14390 + h_inode = d_inode(h_dentry);
14392 + hi_wh = au_hi_wh(inode, bcpup);
14393 + if (!hi_wh && !h_inode)
14394 + err = au_sio_cpup_wh(&cpg, file);
14396 + /* already copied-up after unlink */
14397 + err = au_reopen_wh(file, bcpup, hi_wh);
14400 + && (inode->i_nlink > 1
14401 + || (inode->i_state & I_LINKABLE))
14402 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14403 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14409 + * prepare the @file for writing.
14411 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14414 + aufs_bindex_t dbtop;
14415 + struct dentry *parent;
14416 + struct inode *inode;
14417 + struct super_block *sb;
14418 + struct file *h_file;
14419 + struct au_cp_generic cpg = {
14420 + .dentry = file->f_path.dentry,
14425 + .flags = AuCpup_DTIME
14428 + sb = cpg.dentry->d_sb;
14429 + inode = d_inode(cpg.dentry);
14430 + cpg.bsrc = au_fbtop(file);
14431 + err = au_test_ro(sb, cpg.bsrc, inode);
14432 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14433 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14438 + /* need to cpup or reopen */
14439 + parent = dget_parent(cpg.dentry);
14440 + di_write_lock_parent(parent);
14441 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14443 + if (unlikely(err < 0))
14447 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14448 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14449 + if (unlikely(err))
14453 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14454 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14455 + if (unlikely(err))
14458 + dbtop = au_dbtop(cpg.dentry);
14459 + if (dbtop <= cpg.bdst)
14460 + cpg.bsrc = cpg.bdst;
14462 + if (dbtop <= cpg.bdst /* just reopen */
14463 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14465 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14466 + if (IS_ERR(h_file))
14467 + err = PTR_ERR(h_file);
14469 + di_downgrade_lock(parent, AuLock_IR);
14470 + if (dbtop > cpg.bdst)
14471 + err = au_sio_cpup_simple(&cpg);
14473 + err = au_reopen_nondir(file);
14474 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14476 + } else { /* copyup as wh and reopen */
14478 + * since writable hfsplus branch is not supported,
14479 + * h_open_pre/post() are unnecessary.
14481 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14482 + di_downgrade_lock(parent, AuLock_IR);
14486 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14487 + goto out_dput; /* success */
14493 + di_downgrade_lock(parent, AuLock_IR);
14495 + di_read_unlock(parent, AuLock_IR);
14502 +/* ---------------------------------------------------------------------- */
14504 +int au_do_flush(struct file *file, fl_owner_t id,
14505 + int (*flush)(struct file *file, fl_owner_t id))
14508 + struct super_block *sb;
14509 + struct inode *inode;
14511 + inode = file_inode(file);
14512 + sb = inode->i_sb;
14513 + si_noflush_read_lock(sb);
14514 + fi_read_lock(file);
14515 + ii_read_lock_child(inode);
14517 + err = flush(file, id);
14518 + au_cpup_attr_timesizes(inode);
14520 + ii_read_unlock(inode);
14521 + fi_read_unlock(file);
14522 + si_read_unlock(sb);
14526 +/* ---------------------------------------------------------------------- */
14528 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14531 + struct au_pin pin;
14532 + struct au_finfo *finfo;
14533 + struct dentry *parent, *hi_wh;
14534 + struct inode *inode;
14535 + struct super_block *sb;
14536 + struct au_cp_generic cpg = {
14537 + .dentry = file->f_path.dentry,
14542 + .flags = AuCpup_DTIME
14545 + FiMustWriteLock(file);
14548 + finfo = au_fi(file);
14549 + sb = cpg.dentry->d_sb;
14550 + inode = d_inode(cpg.dentry);
14551 + cpg.bdst = au_ibtop(inode);
14552 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14555 + parent = dget_parent(cpg.dentry);
14556 + if (au_test_ro(sb, cpg.bdst, inode)) {
14557 + di_read_lock_parent(parent, !AuLock_IR);
14558 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14560 + di_read_unlock(parent, !AuLock_IR);
14561 + if (unlikely(err < 0))
14566 + di_read_lock_parent(parent, AuLock_IR);
14567 + hi_wh = au_hi_wh(inode, cpg.bdst);
14568 + if (!S_ISDIR(inode->i_mode)
14569 + && au_opt_test(au_mntflags(sb), PLINK)
14570 + && au_plink_test(inode)
14571 + && !d_unhashed(cpg.dentry)
14572 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14573 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14574 + if (unlikely(err))
14577 + /* always superio. */
14578 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14579 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14581 + err = au_sio_cpup_simple(&cpg);
14584 + } else if (hi_wh) {
14585 + /* already copied-up after unlink */
14586 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14587 + *need_reopen = 0;
14591 + di_read_unlock(parent, AuLock_IR);
14598 +static void au_do_refresh_dir(struct file *file)
14600 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14601 + struct au_hfile *p, tmp, *q;
14602 + struct au_finfo *finfo;
14603 + struct super_block *sb;
14604 + struct au_fidir *fidir;
14606 + FiMustWriteLock(file);
14608 + sb = file->f_path.dentry->d_sb;
14609 + finfo = au_fi(file);
14610 + fidir = finfo->fi_hdir;
14611 + AuDebugOn(!fidir);
14612 + p = fidir->fd_hfile + finfo->fi_btop;
14613 + brid = p->hf_br->br_id;
14614 + bbot = fidir->fd_bbot;
14615 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14619 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14620 + if (new_bindex == bindex)
14622 + if (new_bindex < 0) {
14623 + au_set_h_fptr(file, bindex, NULL);
14627 + /* swap two lower inode, and loop again */
14628 + q = fidir->fd_hfile + new_bindex;
14632 + if (tmp.hf_file) {
14638 + p = fidir->fd_hfile;
14639 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14640 + bbot = au_sbbot(sb);
14641 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14642 + finfo->fi_btop++, p++)
14643 + if (p->hf_file) {
14644 + if (file_inode(p->hf_file))
14646 + au_hfput(p, /*execed*/0);
14649 + bbot = au_br_index(sb, brid);
14650 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14651 + finfo->fi_btop++, p++)
14653 + au_hfput(p, /*execed*/0);
14654 + bbot = au_sbbot(sb);
14657 + p = fidir->fd_hfile + bbot;
14658 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14659 + fidir->fd_bbot--, p--)
14660 + if (p->hf_file) {
14661 + if (file_inode(p->hf_file))
14663 + au_hfput(p, /*execed*/0);
14665 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14669 + * after branch manipulating, refresh the file.
14671 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14673 + int err, need_reopen, nbr;
14674 + aufs_bindex_t bbot, bindex;
14675 + struct dentry *dentry;
14676 + struct super_block *sb;
14677 + struct au_finfo *finfo;
14678 + struct au_hfile *hfile;
14680 + dentry = file->f_path.dentry;
14681 + sb = dentry->d_sb;
14682 + nbr = au_sbbot(sb) + 1;
14683 + finfo = au_fi(file);
14684 + if (!finfo->fi_hdir) {
14685 + hfile = &finfo->fi_htop;
14686 + AuDebugOn(!hfile->hf_file);
14687 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14688 + AuDebugOn(bindex < 0);
14689 + if (bindex != finfo->fi_btop)
14690 + au_set_fbtop(file, bindex);
14692 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14693 + if (unlikely(err))
14695 + au_do_refresh_dir(file);
14700 + if (!au_test_mmapped(file))
14701 + err = au_file_refresh_by_inode(file, &need_reopen);
14702 + if (finfo->fi_hdir)
14703 + /* harmless if err */
14704 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14705 + if (!err && need_reopen && !d_unlinked(dentry))
14706 + err = reopen(file);
14708 + au_update_figen(file);
14709 + goto out; /* success */
14712 + /* error, close all lower files */
14713 + if (finfo->fi_hdir) {
14714 + bbot = au_fbbot_dir(file);
14715 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14716 + au_set_h_fptr(file, bindex, NULL);
14723 +/* common function to regular file and dir */
14724 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14725 + int wlock, unsigned int fi_lsc)
14728 + unsigned int sigen, figen;
14729 + aufs_bindex_t btop;
14730 + unsigned char pseudo_link;
14731 + struct dentry *dentry;
14732 + struct inode *inode;
14735 + dentry = file->f_path.dentry;
14736 + inode = d_inode(dentry);
14737 + sigen = au_sigen(dentry->d_sb);
14738 + fi_write_lock_nested(file, fi_lsc);
14739 + figen = au_figen(file);
14741 + di_write_lock_child(dentry);
14743 + di_write_lock_child2(dentry);
14744 + btop = au_dbtop(dentry);
14745 + pseudo_link = (btop != au_ibtop(inode));
14746 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14748 + di_downgrade_lock(dentry, AuLock_IR);
14749 + fi_downgrade_lock(file);
14751 + goto out; /* success */
14754 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14755 + if (au_digen_test(dentry, sigen)) {
14756 + err = au_reval_dpath(dentry, sigen);
14757 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14761 + err = refresh_file(file, reopen);
14764 + di_downgrade_lock(dentry, AuLock_IR);
14765 + fi_downgrade_lock(file);
14768 + di_write_unlock(dentry);
14769 + fi_write_unlock(file);
14776 +/* ---------------------------------------------------------------------- */
14778 +/* cf. aufs_nopage() */
14779 +/* for madvise(2) */
14780 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14782 + unlock_page(page);
14786 +/* it will never be called, but necessary to support O_DIRECT */
14787 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14788 +{ BUG(); return 0; }
14790 +/* they will never be called. */
14791 +#ifdef CONFIG_AUFS_DEBUG
14792 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14793 + loff_t pos, unsigned len, unsigned flags,
14794 + struct page **pagep, void **fsdata)
14795 +{ AuUnsupport(); return 0; }
14796 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14797 + loff_t pos, unsigned len, unsigned copied,
14798 + struct page *page, void *fsdata)
14799 +{ AuUnsupport(); return 0; }
14800 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14801 +{ AuUnsupport(); return 0; }
14803 +static int aufs_set_page_dirty(struct page *page)
14804 +{ AuUnsupport(); return 0; }
14805 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14806 + unsigned int length)
14807 +{ AuUnsupport(); }
14808 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14809 +{ AuUnsupport(); return 0; }
14810 +#if 0 /* called by memory compaction regardless file */
14811 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14812 + struct page *page, enum migrate_mode mode)
14813 +{ AuUnsupport(); return 0; }
14815 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14816 +{ AuUnsupport(); return true; }
14817 +static void aufs_putback_page(struct page *page)
14818 +{ AuUnsupport(); }
14819 +static int aufs_launder_page(struct page *page)
14820 +{ AuUnsupport(); return 0; }
14821 +static int aufs_is_partially_uptodate(struct page *page,
14822 + unsigned long from,
14823 + unsigned long count)
14824 +{ AuUnsupport(); return 0; }
14825 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14827 +{ AuUnsupport(); }
14828 +static int aufs_error_remove_page(struct address_space *mapping,
14829 + struct page *page)
14830 +{ AuUnsupport(); return 0; }
14831 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14833 +{ AuUnsupport(); return 0; }
14834 +static void aufs_swap_deactivate(struct file *file)
14835 +{ AuUnsupport(); }
14836 +#endif /* CONFIG_AUFS_DEBUG */
14838 +const struct address_space_operations aufs_aop = {
14839 + .readpage = aufs_readpage,
14840 + .direct_IO = aufs_direct_IO,
14841 +#ifdef CONFIG_AUFS_DEBUG
14842 + .writepage = aufs_writepage,
14843 + /* no writepages, because of writepage */
14844 + .set_page_dirty = aufs_set_page_dirty,
14845 + /* no readpages, because of readpage */
14846 + .write_begin = aufs_write_begin,
14847 + .write_end = aufs_write_end,
14848 + /* no bmap, no block device */
14849 + .invalidatepage = aufs_invalidatepage,
14850 + .releasepage = aufs_releasepage,
14851 + /* is fallback_migrate_page ok? */
14852 + /* .migratepage = aufs_migratepage, */
14853 + .isolate_page = aufs_isolate_page,
14854 + .putback_page = aufs_putback_page,
14855 + .launder_page = aufs_launder_page,
14856 + .is_partially_uptodate = aufs_is_partially_uptodate,
14857 + .is_dirty_writeback = aufs_is_dirty_writeback,
14858 + .error_remove_page = aufs_error_remove_page,
14859 + .swap_activate = aufs_swap_activate,
14860 + .swap_deactivate = aufs_swap_deactivate
14861 +#endif /* CONFIG_AUFS_DEBUG */
14863 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14864 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14865 +++ linux/fs/aufs/file.h 2021-12-03 15:38:59.936647310 +0100
14867 +/* SPDX-License-Identifier: GPL-2.0 */
14869 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14871 + * This program, aufs is free software; you can redistribute it and/or modify
14872 + * it under the terms of the GNU General Public License as published by
14873 + * the Free Software Foundation; either version 2 of the License, or
14874 + * (at your option) any later version.
14876 + * This program is distributed in the hope that it will be useful,
14877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14879 + * GNU General Public License for more details.
14881 + * You should have received a copy of the GNU General Public License
14882 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14886 + * file operations
14889 +#ifndef __AUFS_FILE_H__
14890 +#define __AUFS_FILE_H__
14894 +#include <linux/file.h>
14895 +#include <linux/fs.h>
14896 +#include <linux/mm_types.h>
14897 +#include <linux/poll.h>
14898 +#include "rwsem.h"
14902 + struct file *hf_file;
14903 + struct au_branch *hf_br;
14908 + aufs_bindex_t fd_bbot;
14909 + aufs_bindex_t fd_nent;
14910 + struct au_vdir *fd_vdir_cache;
14911 + struct au_hfile fd_hfile[];
14914 +static inline int au_fidir_sz(int nent)
14916 + AuDebugOn(nent < 0);
14917 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14921 + atomic_t fi_generation;
14923 + struct au_rwsem fi_rwsem;
14924 + aufs_bindex_t fi_btop;
14926 + /* do not union them */
14927 + struct { /* for non-dir */
14928 + struct au_hfile fi_htop;
14929 + atomic_t fi_mmapped;
14931 + struct au_fidir *fi_hdir; /* for dir only */
14933 + struct hlist_bl_node fi_hlist;
14934 + struct file *fi_file; /* very ugly */
14935 + struct rcu_head rcu;
14936 +} ____cacheline_aligned_in_smp;
14938 +/* ---------------------------------------------------------------------- */
14941 +extern const struct address_space_operations aufs_aop;
14942 +unsigned int au_file_roflags(unsigned int flags);
14943 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14944 + struct file *file, int force_wr);
14945 +struct au_do_open_args {
14947 + int (*open)(struct file *file, int flags,
14948 + struct file *h_file);
14949 + struct au_fidir *fidir;
14950 + struct file *h_file;
14952 +int au_do_open(struct file *file, struct au_do_open_args *args);
14953 +int au_reopen_nondir(struct file *file);
14955 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14956 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14957 + int wlock, unsigned int fi_lsc);
14958 +int au_do_flush(struct file *file, fl_owner_t id,
14959 + int (*flush)(struct file *file, fl_owner_t id));
14962 +#ifdef CONFIG_AUFS_POLL
14963 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
14966 +#ifdef CONFIG_AUFS_BR_HFSPLUS
14968 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14970 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14971 + struct file *h_file);
14973 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
14974 + aufs_bindex_t bindex, int force_wr)
14975 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
14976 + struct file *h_file);
14980 +extern const struct file_operations aufs_file_fop;
14981 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
14982 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
14983 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
14986 +void au_hfput(struct au_hfile *hf, int execed);
14987 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
14988 + struct file *h_file);
14990 +void au_update_figen(struct file *file);
14991 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
14992 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
14994 +void au_fi_init_once(void *_fi);
14995 +void au_finfo_fin(struct file *file);
14996 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
14999 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15000 +#ifdef CONFIG_COMPAT
15001 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15002 + unsigned long arg);
15003 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15004 + unsigned long arg);
15007 +/* ---------------------------------------------------------------------- */
15009 +static inline struct au_finfo *au_fi(struct file *file)
15011 + return file->private_data;
15014 +/* ---------------------------------------------------------------------- */
15016 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15017 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15018 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15019 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15021 +#define fi_read_trylock_nested(f) \
15022 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15023 +#define fi_write_trylock_nested(f) \
15024 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15027 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15028 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15029 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15031 +/* lock subclass for finfo */
15037 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15039 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15042 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15044 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15048 + * fi_read_lock_1, fi_write_lock_1,
15049 + * fi_read_lock_2, fi_write_lock_2
15051 +#define AuReadLockFunc(name) \
15052 +static inline void fi_read_lock_##name(struct file *f) \
15053 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15055 +#define AuWriteLockFunc(name) \
15056 +static inline void fi_write_lock_##name(struct file *f) \
15057 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15059 +#define AuRWLockFuncs(name) \
15060 + AuReadLockFunc(name) \
15061 + AuWriteLockFunc(name)
15066 +#undef AuReadLockFunc
15067 +#undef AuWriteLockFunc
15068 +#undef AuRWLockFuncs
15070 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15071 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15072 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15074 +/* ---------------------------------------------------------------------- */
15076 +/* todo: hard/soft set? */
15077 +static inline aufs_bindex_t au_fbtop(struct file *file)
15079 + FiMustAnyLock(file);
15080 + return au_fi(file)->fi_btop;
15083 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15085 + FiMustAnyLock(file);
15086 + AuDebugOn(!au_fi(file)->fi_hdir);
15087 + return au_fi(file)->fi_hdir->fd_bbot;
15090 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15092 + FiMustAnyLock(file);
15093 + AuDebugOn(!au_fi(file)->fi_hdir);
15094 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15097 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15099 + FiMustWriteLock(file);
15100 + au_fi(file)->fi_btop = bindex;
15103 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15105 + FiMustWriteLock(file);
15106 + AuDebugOn(!au_fi(file)->fi_hdir);
15107 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15110 +static inline void au_set_fvdir_cache(struct file *file,
15111 + struct au_vdir *vdir_cache)
15113 + FiMustWriteLock(file);
15114 + AuDebugOn(!au_fi(file)->fi_hdir);
15115 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15118 +static inline struct file *au_hf_top(struct file *file)
15120 + FiMustAnyLock(file);
15121 + AuDebugOn(au_fi(file)->fi_hdir);
15122 + return au_fi(file)->fi_htop.hf_file;
15125 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15127 + FiMustAnyLock(file);
15128 + AuDebugOn(!au_fi(file)->fi_hdir);
15129 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15132 +/* todo: memory barrier? */
15133 +static inline unsigned int au_figen(struct file *f)
15135 + return atomic_read(&au_fi(f)->fi_generation);
15138 +static inline void au_set_mmapped(struct file *f)
15140 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15142 + pr_warn("fi_mmapped wrapped around\n");
15143 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15147 +static inline void au_unset_mmapped(struct file *f)
15149 + atomic_dec(&au_fi(f)->fi_mmapped);
15152 +static inline int au_test_mmapped(struct file *f)
15154 + return atomic_read(&au_fi(f)->fi_mmapped);
15157 +/* customize vma->vm_file */
15159 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15160 + struct file *file)
15164 + f = vma->vm_file;
15166 + vma->vm_file = file;
15171 +#define AuDbgVmRegion(file, vma) do {} while (0)
15173 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15174 + struct file *file)
15176 + au_do_vm_file_reset(vma, file);
15179 +#define AuDbgVmRegion(file, vma) \
15180 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15182 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15183 + struct file *file)
15187 + au_do_vm_file_reset(vma, file);
15188 + f = vma->vm_region->vm_file;
15190 + vma->vm_region->vm_file = file;
15193 +#endif /* CONFIG_MMU */
15195 +/* handle vma->vm_prfile */
15196 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15197 + struct file *file)
15200 + vma->vm_prfile = file;
15201 +#ifndef CONFIG_MMU
15203 + vma->vm_region->vm_prfile = file;
15207 +#endif /* __KERNEL__ */
15208 +#endif /* __AUFS_FILE_H__ */
15209 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15210 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15211 +++ linux/fs/aufs/finfo.c 2021-12-03 15:38:59.936647310 +0100
15213 +// SPDX-License-Identifier: GPL-2.0
15215 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15217 + * This program, aufs is free software; you can redistribute it and/or modify
15218 + * it under the terms of the GNU General Public License as published by
15219 + * the Free Software Foundation; either version 2 of the License, or
15220 + * (at your option) any later version.
15222 + * This program is distributed in the hope that it will be useful,
15223 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15224 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15225 + * GNU General Public License for more details.
15227 + * You should have received a copy of the GNU General Public License
15228 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15232 + * file private data
15237 +void au_hfput(struct au_hfile *hf, int execed)
15240 + allow_write_access(hf->hf_file);
15241 + fput(hf->hf_file);
15242 + hf->hf_file = NULL;
15243 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15244 + hf->hf_br = NULL;
15247 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15249 + struct au_finfo *finfo = au_fi(file);
15250 + struct au_hfile *hf;
15251 + struct au_fidir *fidir;
15253 + fidir = finfo->fi_hdir;
15255 + AuDebugOn(finfo->fi_btop != bindex);
15256 + hf = &finfo->fi_htop;
15258 + hf = fidir->fd_hfile + bindex;
15260 + if (hf && hf->hf_file)
15261 + au_hfput(hf, vfsub_file_execed(file));
15263 + FiMustWriteLock(file);
15264 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15265 + hf->hf_file = val;
15266 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15270 +void au_update_figen(struct file *file)
15272 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15273 + /* smp_mb(); */ /* atomic_set */
15276 +/* ---------------------------------------------------------------------- */
15278 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15280 + struct au_fidir *fidir;
15283 + nbr = au_sbbot(sb) + 1;
15285 + nbr = 2; /* initial allocate for 2 branches */
15286 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15288 + fidir->fd_bbot = -1;
15289 + fidir->fd_nent = nbr;
15295 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15298 + struct au_fidir *fidir, *p;
15300 + AuRwMustWriteLock(&finfo->fi_rwsem);
15301 + fidir = finfo->fi_hdir;
15302 + AuDebugOn(!fidir);
15305 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15306 + GFP_NOFS, may_shrink);
15308 + p->fd_nent = nbr;
15309 + finfo->fi_hdir = p;
15316 +/* ---------------------------------------------------------------------- */
15318 +void au_finfo_fin(struct file *file)
15320 + struct au_finfo *finfo;
15322 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15324 + finfo = au_fi(file);
15325 + AuDebugOn(finfo->fi_hdir);
15326 + AuRwDestroy(&finfo->fi_rwsem);
15327 + au_cache_free_finfo(finfo);
15330 +void au_fi_init_once(void *_finfo)
15332 + struct au_finfo *finfo = _finfo;
15334 + au_rw_init(&finfo->fi_rwsem);
15337 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15340 + struct au_finfo *finfo;
15341 + struct dentry *dentry;
15344 + dentry = file->f_path.dentry;
15345 + finfo = au_cache_alloc_finfo();
15346 + if (unlikely(!finfo))
15350 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15351 + au_rw_write_lock(&finfo->fi_rwsem);
15352 + finfo->fi_btop = -1;
15353 + finfo->fi_hdir = fidir;
15354 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15355 + /* smp_mb(); */ /* atomic_set */
15357 + file->private_data = finfo;
15362 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15363 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15364 +++ linux/fs/aufs/f_op.c 2021-12-03 15:38:59.933313976 +0100
15366 +// SPDX-License-Identifier: GPL-2.0
15368 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15370 + * This program, aufs is free software; you can redistribute it and/or modify
15371 + * it under the terms of the GNU General Public License as published by
15372 + * the Free Software Foundation; either version 2 of the License, or
15373 + * (at your option) any later version.
15375 + * This program is distributed in the hope that it will be useful,
15376 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15377 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15378 + * GNU General Public License for more details.
15380 + * You should have received a copy of the GNU General Public License
15381 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15385 + * file and vm operations
15388 +#include <linux/aio.h>
15389 +#include <linux/fs_stack.h>
15390 +#include <linux/mman.h>
15391 +#include <linux/security.h>
15394 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15397 + aufs_bindex_t bindex;
15398 + struct dentry *dentry, *h_dentry;
15399 + struct au_finfo *finfo;
15400 + struct inode *h_inode;
15402 + FiMustWriteLock(file);
15405 + dentry = file->f_path.dentry;
15406 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15407 + finfo = au_fi(file);
15408 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15409 + atomic_set(&finfo->fi_mmapped, 0);
15410 + bindex = au_dbtop(dentry);
15412 + h_dentry = au_h_dptr(dentry, bindex);
15413 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15414 + if (unlikely(err))
15416 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15417 + if (IS_ERR(h_file)) {
15418 + err = PTR_ERR(h_file);
15422 + h_dentry = h_file->f_path.dentry;
15423 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15424 + if (unlikely(err))
15426 + /* br ref is already inc-ed */
15429 + if ((flags & __O_TMPFILE)
15430 + && !(flags & O_EXCL)) {
15431 + h_inode = file_inode(h_file);
15432 + spin_lock(&h_inode->i_lock);
15433 + h_inode->i_state |= I_LINKABLE;
15434 + spin_unlock(&h_inode->i_lock);
15436 + au_set_fbtop(file, bindex);
15437 + au_set_h_fptr(file, bindex, h_file);
15438 + au_update_figen(file);
15439 + /* todo: necessary? */
15440 + /* file->f_ra = h_file->f_ra; */
15446 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15447 + struct file *file)
15450 + struct super_block *sb;
15451 + struct au_do_open_args args = {
15452 + .open = au_do_open_nondir
15455 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15456 + file, vfsub_file_flags(file), file->f_mode);
15458 + sb = file->f_path.dentry->d_sb;
15459 + si_read_lock(sb, AuLock_FLUSH);
15460 + err = au_do_open(file, &args);
15461 + si_read_unlock(sb);
15465 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15467 + struct au_finfo *finfo;
15468 + aufs_bindex_t bindex;
15470 + finfo = au_fi(file);
15471 + au_hbl_del(&finfo->fi_hlist,
15472 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15473 + bindex = finfo->fi_btop;
15475 + au_set_h_fptr(file, bindex, NULL);
15477 + au_finfo_fin(file);
15481 +/* ---------------------------------------------------------------------- */
15483 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15486 + struct file *h_file;
15489 + h_file = au_hf_top(file);
15491 + err = vfsub_flush(h_file, id);
15495 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15497 + return au_do_flush(file, id, au_do_flush_nondir);
15500 +/* ---------------------------------------------------------------------- */
15502 + * read and write functions acquire [fdi]_rwsem once, but release before
15503 + * mmap_sem. This is because to stop a race condition between mmap(2).
15504 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15505 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15506 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15509 +/* Callers should call au_read_post() or fput() in the end */
15510 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15512 + struct file *h_file;
15515 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15517 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15518 + h_file = au_hf_top(file);
15519 + get_file(h_file);
15521 + fi_read_unlock(file);
15523 + h_file = ERR_PTR(err);
15528 +static void au_read_post(struct inode *inode, struct file *h_file)
15530 + /* update without lock, I don't think it a problem */
15531 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15535 +struct au_write_pre {
15537 + unsigned int lsc;
15541 + aufs_bindex_t btop;
15545 + * return with iinfo is write-locked
15546 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15549 +static struct file *au_write_pre(struct file *file, int do_ready,
15550 + struct au_write_pre *wpre)
15552 + struct file *h_file;
15553 + struct dentry *dentry;
15555 + unsigned int lsc;
15556 + struct au_pin pin;
15561 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15562 + h_file = ERR_PTR(err);
15563 + if (unlikely(err))
15566 + dentry = file->f_path.dentry;
15568 + err = au_ready_to_write(file, -1, &pin);
15569 + if (unlikely(err)) {
15570 + h_file = ERR_PTR(err);
15571 + di_write_unlock(dentry);
15576 + di_downgrade_lock(dentry, /*flags*/0);
15578 + wpre->btop = au_fbtop(file);
15579 + h_file = au_hf_top(file);
15580 + get_file(h_file);
15582 + wpre->blks = file_inode(h_file)->i_blocks;
15585 + di_read_unlock(dentry, /*flags*/0);
15588 + fi_write_unlock(file);
15593 +static void au_write_post(struct inode *inode, struct file *h_file,
15594 + struct au_write_pre *wpre, ssize_t written)
15596 + struct inode *h_inode;
15598 + au_cpup_attr_timesizes(inode);
15599 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15600 + h_inode = file_inode(h_file);
15601 + inode->i_mode = h_inode->i_mode;
15602 + ii_write_unlock(inode);
15603 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15605 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15606 + /*force*/h_inode->i_blocks > wpre->blks);
15611 + * todo: very ugly
15612 + * it locks both of i_mutex and si_rwsem for read in safe.
15613 + * if the plink maintenance mode continues forever (that is the problem),
15614 + * may loop forever.
15616 +static void au_mtx_and_read_lock(struct inode *inode)
15619 + struct super_block *sb = inode->i_sb;
15622 + inode_lock(inode);
15623 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15626 + inode_unlock(inode);
15627 + si_read_lock(sb, AuLock_NOPLMW);
15628 + si_read_unlock(sb);
15632 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15633 + struct iov_iter *iov_iter)
15636 + struct file *file;
15637 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15639 + err = security_file_permission(h_file, rw);
15640 + if (unlikely(err))
15643 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15645 + if (rw == MAY_READ)
15646 + iter = h_file->f_op->read_iter;
15647 + else if (rw == MAY_WRITE)
15648 + iter = h_file->f_op->write_iter;
15650 + file = kio->ki_filp;
15651 + kio->ki_filp = h_file;
15654 + err = iter(kio, iov_iter);
15657 + /* currently there is no such fs */
15659 + kio->ki_filp = file;
15665 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15668 + struct file *file, *h_file;
15669 + struct inode *inode;
15670 + struct super_block *sb;
15672 + file = kio->ki_filp;
15673 + inode = file_inode(file);
15674 + sb = inode->i_sb;
15675 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15677 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15678 + err = PTR_ERR(h_file);
15679 + if (IS_ERR(h_file))
15682 + if (au_test_loopback_kthread()) {
15683 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15684 + if (file->f_mapping != h_file->f_mapping) {
15685 + file->f_mapping = h_file->f_mapping;
15686 + smp_mb(); /* unnecessary? */
15689 + fi_read_unlock(file);
15691 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15692 + /* todo: necessary? */
15693 + /* file->f_ra = h_file->f_ra; */
15694 + au_read_post(inode, h_file);
15697 + si_read_unlock(sb);
15701 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15704 + struct au_write_pre wpre;
15705 + struct inode *inode;
15706 + struct file *file, *h_file;
15708 + file = kio->ki_filp;
15709 + inode = file_inode(file);
15710 + au_mtx_and_read_lock(inode);
15713 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15714 + err = PTR_ERR(h_file);
15715 + if (IS_ERR(h_file))
15718 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15719 + au_write_post(inode, h_file, &wpre, err);
15722 + si_read_unlock(inode->i_sb);
15723 + inode_unlock(inode);
15728 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15729 + * don't have their own .splice_{read,write} implimentations, and they use
15730 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15731 + * simple converters to f_op->iter_read() and ->iter_write().
15732 + * But we keep our own implementations because some non-mainlined FSes may have
15733 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15734 + * away an opportunity to co-work with aufs from them.
15736 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15737 + struct pipe_inode_info *pipe, size_t len,
15738 + unsigned int flags)
15741 + struct file *h_file;
15742 + struct inode *inode;
15743 + struct super_block *sb;
15745 + inode = file_inode(file);
15746 + sb = inode->i_sb;
15747 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15749 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15750 + err = PTR_ERR(h_file);
15751 + if (IS_ERR(h_file))
15754 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15755 + /* todo: necessary? */
15756 + /* file->f_ra = h_file->f_ra; */
15757 + au_read_post(inode, h_file);
15760 + si_read_unlock(sb);
15765 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15766 + size_t len, unsigned int flags)
15769 + struct au_write_pre wpre;
15770 + struct inode *inode;
15771 + struct file *h_file;
15773 + inode = file_inode(file);
15774 + au_mtx_and_read_lock(inode);
15777 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15778 + err = PTR_ERR(h_file);
15779 + if (IS_ERR(h_file))
15782 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15783 + au_write_post(inode, h_file, &wpre, err);
15786 + si_read_unlock(inode->i_sb);
15787 + inode_unlock(inode);
15791 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15795 + struct au_write_pre wpre;
15796 + struct inode *inode;
15797 + struct file *h_file;
15799 + inode = file_inode(file);
15800 + au_mtx_and_read_lock(inode);
15803 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15804 + err = PTR_ERR(h_file);
15805 + if (IS_ERR(h_file))
15809 + err = vfs_fallocate(h_file, mode, offset, len);
15811 + au_write_post(inode, h_file, &wpre, /*written*/1);
15814 + si_read_unlock(inode->i_sb);
15815 + inode_unlock(inode);
15819 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15820 + struct file *dst, loff_t dst_pos,
15821 + size_t len, unsigned int flags)
15824 + struct au_write_pre wpre;
15825 + enum { SRC, DST };
15827 + struct inode *inode;
15828 + struct file *h_file;
15829 + struct super_block *h_sb;
15831 +#define a_src a[SRC]
15832 +#define a_dst a[DST]
15835 + a_src.inode = file_inode(src);
15836 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15838 + a_dst.inode = file_inode(dst);
15839 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15842 + au_mtx_and_read_lock(a_dst.inode);
15844 + * in order to match the order in di_write_lock2_{child,parent}(),
15845 + * use f_path.dentry for this comparison.
15847 + if (src->f_path.dentry < dst->f_path.dentry) {
15848 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15849 + err = PTR_ERR(a_src.h_file);
15850 + if (IS_ERR(a_src.h_file))
15853 + wpre.lsc = AuLsc_FI_2;
15854 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15855 + err = PTR_ERR(a_dst.h_file);
15856 + if (IS_ERR(a_dst.h_file)) {
15857 + au_read_post(a_src.inode, a_src.h_file);
15861 + wpre.lsc = AuLsc_FI_1;
15862 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15863 + err = PTR_ERR(a_dst.h_file);
15864 + if (IS_ERR(a_dst.h_file))
15867 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15868 + err = PTR_ERR(a_src.h_file);
15869 + if (IS_ERR(a_src.h_file)) {
15870 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15877 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15878 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15879 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15885 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15886 + dst_pos, len, flags);
15889 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15890 + fi_read_unlock(src);
15891 + au_read_post(a_src.inode, a_src.h_file);
15893 + si_read_unlock(a_dst.inode->i_sb);
15894 + inode_unlock(a_dst.inode);
15901 +/* ---------------------------------------------------------------------- */
15904 + * The locking order around current->mmap_sem.
15905 + * - in most and regular cases
15906 + * file I/O syscall -- aufs_read() or something
15907 + * -- si_rwsem for read -- mmap_sem
15908 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15910 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15911 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15912 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15913 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15914 + * It means that when aufs acquires si_rwsem for write, the process should never
15915 + * acquire mmap_sem.
15917 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15918 + * problem either since any directory is not able to be mmap-ed.
15919 + * The similar scenario is applied to aufs_readlink() too.
15922 +#if 0 /* stop calling security_file_mmap() */
15923 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15924 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15926 +static unsigned long au_arch_prot_conv(unsigned long flags)
15928 + /* currently ppc64 only */
15929 +#ifdef CONFIG_PPC64
15930 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15931 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15932 + return AuConv_VM_PROT(flags, SAO);
15934 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15939 +static unsigned long au_prot_conv(unsigned long flags)
15941 + return AuConv_VM_PROT(flags, READ)
15942 + | AuConv_VM_PROT(flags, WRITE)
15943 + | AuConv_VM_PROT(flags, EXEC)
15944 + | au_arch_prot_conv(flags);
15947 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15948 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15950 +static unsigned long au_flag_conv(unsigned long flags)
15952 + return AuConv_VM_MAP(flags, GROWSDOWN)
15953 + | AuConv_VM_MAP(flags, DENYWRITE)
15954 + | AuConv_VM_MAP(flags, LOCKED);
15958 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
15961 + const unsigned char wlock
15962 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
15963 + struct super_block *sb;
15964 + struct file *h_file;
15965 + struct inode *inode;
15967 + AuDbgVmRegion(file, vma);
15969 + inode = file_inode(file);
15970 + sb = inode->i_sb;
15972 + si_read_lock(sb, AuLock_NOPLMW);
15974 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
15976 + err = PTR_ERR(h_file);
15977 + if (IS_ERR(h_file))
15981 + au_set_mmapped(file);
15982 + au_vm_file_reset(vma, h_file);
15984 + * we cannot call security_mmap_file() here since it may acquire
15985 + * mmap_sem or i_mutex.
15987 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
15988 + * au_flag_conv(vma->vm_flags));
15991 + err = call_mmap(h_file, vma);
15993 + au_vm_prfile_set(vma, file);
15994 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15995 + goto out_fput; /* success */
15997 + au_unset_mmapped(file);
15998 + au_vm_file_reset(vma, file);
16002 + ii_write_unlock(inode);
16007 + si_read_unlock(sb);
16013 +/* ---------------------------------------------------------------------- */
16015 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16019 + struct au_write_pre wpre;
16020 + struct inode *inode;
16021 + struct file *h_file;
16023 + err = 0; /* -EBADF; */ /* posix? */
16024 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16027 + inode = file_inode(file);
16028 + au_mtx_and_read_lock(inode);
16031 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16032 + err = PTR_ERR(h_file);
16033 + if (IS_ERR(h_file))
16036 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16037 + au_write_post(inode, h_file, &wpre, /*written*/0);
16040 + si_read_unlock(inode->i_sb);
16041 + inode_unlock(inode);
16046 +static int aufs_fasync(int fd, struct file *file, int flag)
16049 + struct file *h_file;
16050 + struct super_block *sb;
16052 + sb = file->f_path.dentry->d_sb;
16053 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16055 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16056 + err = PTR_ERR(h_file);
16057 + if (IS_ERR(h_file))
16060 + if (h_file->f_op->fasync)
16061 + err = h_file->f_op->fasync(fd, h_file, flag);
16062 + fput(h_file); /* instead of au_read_post() */
16065 + si_read_unlock(sb);
16069 +static int aufs_setfl(struct file *file, unsigned long arg)
16072 + struct file *h_file;
16073 + struct super_block *sb;
16075 + sb = file->f_path.dentry->d_sb;
16076 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16078 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16079 + err = PTR_ERR(h_file);
16080 + if (IS_ERR(h_file))
16083 + /* stop calling h_file->fasync */
16084 + arg |= vfsub_file_flags(file) & FASYNC;
16085 + err = setfl(/*unused fd*/-1, h_file, arg);
16086 + fput(h_file); /* instead of au_read_post() */
16089 + si_read_unlock(sb);
16093 +/* ---------------------------------------------------------------------- */
16095 +/* no one supports this operation, currently */
16096 +#if 0 /* reserved for future use */
16097 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16098 + size_t len, loff_t *pos, int more)
16103 +/* ---------------------------------------------------------------------- */
16105 +const struct file_operations aufs_file_fop = {
16106 + .owner = THIS_MODULE,
16108 + .llseek = default_llseek,
16110 + .read_iter = aufs_read_iter,
16111 + .write_iter = aufs_write_iter,
16113 +#ifdef CONFIG_AUFS_POLL
16114 + .poll = aufs_poll,
16116 + .unlocked_ioctl = aufs_ioctl_nondir,
16117 +#ifdef CONFIG_COMPAT
16118 + .compat_ioctl = aufs_compat_ioctl_nondir,
16120 + .mmap = aufs_mmap,
16121 + .open = aufs_open_nondir,
16122 + .flush = aufs_flush_nondir,
16123 + .release = aufs_release_nondir,
16124 + .fsync = aufs_fsync_nondir,
16125 + .fasync = aufs_fasync,
16126 + /* .sendpage = aufs_sendpage, */
16127 + .setfl = aufs_setfl,
16128 + .splice_write = aufs_splice_write,
16129 + .splice_read = aufs_splice_read,
16130 +#if 0 /* reserved for future use */
16131 + .aio_splice_write = aufs_aio_splice_write,
16132 + .aio_splice_read = aufs_aio_splice_read,
16134 + .fallocate = aufs_fallocate,
16135 + .copy_file_range = aufs_copy_file_range
16137 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16138 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16139 +++ linux/fs/aufs/fstype.h 2021-12-03 15:38:59.936647310 +0100
16141 +/* SPDX-License-Identifier: GPL-2.0 */
16143 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16145 + * This program, aufs is free software; you can redistribute it and/or modify
16146 + * it under the terms of the GNU General Public License as published by
16147 + * the Free Software Foundation; either version 2 of the License, or
16148 + * (at your option) any later version.
16150 + * This program is distributed in the hope that it will be useful,
16151 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16152 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16153 + * GNU General Public License for more details.
16155 + * You should have received a copy of the GNU General Public License
16156 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16160 + * judging filesystem type
16163 +#ifndef __AUFS_FSTYPE_H__
16164 +#define __AUFS_FSTYPE_H__
16168 +#include <linux/fs.h>
16169 +#include <linux/magic.h>
16170 +#include <linux/nfs_fs.h>
16171 +#include <linux/romfs_fs.h>
16173 +static inline int au_test_aufs(struct super_block *sb)
16175 + return sb->s_magic == AUFS_SUPER_MAGIC;
16178 +static inline const char *au_sbtype(struct super_block *sb)
16180 + return sb->s_type->name;
16183 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16185 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16186 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16192 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16194 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16195 + return sb->s_magic == ROMFS_MAGIC;
16201 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16203 +#if IS_ENABLED(CONFIG_CRAMFS)
16204 + return sb->s_magic == CRAMFS_MAGIC;
16209 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16211 +#if IS_ENABLED(CONFIG_NFS_FS)
16212 + return sb->s_magic == NFS_SUPER_MAGIC;
16218 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16220 +#if IS_ENABLED(CONFIG_FUSE_FS)
16221 + return sb->s_magic == FUSE_SUPER_MAGIC;
16227 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16229 +#if IS_ENABLED(CONFIG_XFS_FS)
16230 + return sb->s_magic == XFS_SB_MAGIC;
16236 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16238 +#ifdef CONFIG_TMPFS
16239 + return sb->s_magic == TMPFS_MAGIC;
16245 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16247 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16248 + return !strcmp(au_sbtype(sb), "ecryptfs");
16254 +static inline int au_test_ramfs(struct super_block *sb)
16256 + return sb->s_magic == RAMFS_MAGIC;
16259 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16261 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16262 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16268 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16270 +#ifdef CONFIG_PROC_FS
16271 + return sb->s_magic == PROC_SUPER_MAGIC;
16277 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16279 +#ifdef CONFIG_SYSFS
16280 + return sb->s_magic == SYSFS_MAGIC;
16286 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16288 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16289 + return sb->s_magic == CONFIGFS_MAGIC;
16295 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16297 +#if IS_ENABLED(CONFIG_MINIX_FS)
16298 + return sb->s_magic == MINIX3_SUPER_MAGIC
16299 + || sb->s_magic == MINIX2_SUPER_MAGIC
16300 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16301 + || sb->s_magic == MINIX_SUPER_MAGIC
16302 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16308 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16310 +#if IS_ENABLED(CONFIG_FAT_FS)
16311 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16317 +static inline int au_test_msdos(struct super_block *sb)
16319 + return au_test_fat(sb);
16322 +static inline int au_test_vfat(struct super_block *sb)
16324 + return au_test_fat(sb);
16327 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16329 +#ifdef CONFIG_SECURITYFS
16330 + return sb->s_magic == SECURITYFS_MAGIC;
16336 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16338 +#if IS_ENABLED(CONFIG_SQUASHFS)
16339 + return sb->s_magic == SQUASHFS_MAGIC;
16345 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16347 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16348 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16354 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16356 +#if IS_ENABLED(CONFIG_XENFS)
16357 + return sb->s_magic == XENFS_SUPER_MAGIC;
16363 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16365 +#ifdef CONFIG_DEBUG_FS
16366 + return sb->s_magic == DEBUGFS_MAGIC;
16372 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16374 +#if IS_ENABLED(CONFIG_NILFS)
16375 + return sb->s_magic == NILFS_SUPER_MAGIC;
16381 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16383 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16384 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16390 +/* ---------------------------------------------------------------------- */
16392 + * they can't be an aufs branch.
16394 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16397 +#ifndef CONFIG_AUFS_BR_RAMFS
16398 + au_test_ramfs(sb) ||
16400 + au_test_procfs(sb)
16401 + || au_test_sysfs(sb)
16402 + || au_test_configfs(sb)
16403 + || au_test_debugfs(sb)
16404 + || au_test_securityfs(sb)
16405 + || au_test_xenfs(sb)
16406 + || au_test_ecryptfs(sb)
16407 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16408 + || au_test_aufs(sb); /* will be supported in next version */
16411 +static inline int au_test_fs_remote(struct super_block *sb)
16413 + return !au_test_tmpfs(sb)
16414 +#ifdef CONFIG_AUFS_BR_RAMFS
16415 + && !au_test_ramfs(sb)
16417 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16420 +/* ---------------------------------------------------------------------- */
16423 + * Note: these functions (below) are created after reading ->getattr() in all
16424 + * filesystems under linux/fs. it means we have to do so in every update...
16428 + * some filesystems require getattr to refresh the inode attributes before
16430 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16431 + * and leave the work for d_revalidate()
16433 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16435 + return au_test_nfs(sb)
16436 + || au_test_fuse(sb)
16437 + /* || au_test_btrfs(sb) */ /* untested */
16442 + * filesystems which don't maintain i_size or i_blocks.
16444 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16446 + return au_test_xfs(sb)
16447 + || au_test_btrfs(sb)
16448 + || au_test_ubifs(sb)
16449 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16450 + /* || au_test_minix(sb) */ /* untested */
16455 + * filesystems which don't store the correct value in some of their inode
16458 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16460 + return au_test_fs_bad_iattr_size(sb)
16461 + || au_test_fat(sb)
16462 + || au_test_msdos(sb)
16463 + || au_test_vfat(sb);
16466 +/* they don't check i_nlink in link(2) */
16467 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16469 + return au_test_tmpfs(sb)
16470 +#ifdef CONFIG_AUFS_BR_RAMFS
16471 + || au_test_ramfs(sb)
16473 + || au_test_ubifs(sb)
16474 + || au_test_hfsplus(sb);
16478 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16480 +static inline int au_test_fs_notime(struct super_block *sb)
16482 + return au_test_nfs(sb)
16483 + || au_test_fuse(sb)
16484 + || au_test_ubifs(sb)
16488 +/* temporary support for i#1 in cramfs */
16489 +static inline int au_test_fs_unique_ino(struct inode *inode)
16491 + if (au_test_cramfs(inode->i_sb))
16492 + return inode->i_ino != 1;
16496 +/* ---------------------------------------------------------------------- */
16499 + * the filesystem where the xino files placed must support i/o after unlink and
16500 + * maintain i_size and i_blocks.
16502 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16504 + return au_test_fs_remote(sb)
16505 + || au_test_fs_bad_iattr_size(sb)
16506 + /* don't want unnecessary work for xino */
16507 + || au_test_aufs(sb)
16508 + || au_test_ecryptfs(sb)
16509 + || au_test_nilfs(sb);
16512 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16514 + return au_test_tmpfs(sb)
16515 + || au_test_ramfs(sb);
16519 + * test if the @sb is real-readonly.
16521 +static inline int au_test_fs_rr(struct super_block *sb)
16523 + return au_test_squashfs(sb)
16524 + || au_test_iso9660(sb)
16525 + || au_test_cramfs(sb)
16526 + || au_test_romfs(sb);
16530 + * test if the @inode is nfs with 'noacl' option
16531 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16533 +static inline int au_test_nfs_noacl(struct inode *inode)
16535 + return au_test_nfs(inode->i_sb)
16536 + /* && IS_POSIXACL(inode) */
16537 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16540 +#endif /* __KERNEL__ */
16541 +#endif /* __AUFS_FSTYPE_H__ */
16542 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16543 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16544 +++ linux/fs/aufs/hbl.h 2021-12-03 15:38:59.936647310 +0100
16546 +/* SPDX-License-Identifier: GPL-2.0 */
16548 + * Copyright (C) 2017-2021 Junjiro R. Okajima
16550 + * This program, aufs is free software; you can redistribute it and/or modify
16551 + * it under the terms of the GNU General Public License as published by
16552 + * the Free Software Foundation; either version 2 of the License, or
16553 + * (at your option) any later version.
16555 + * This program is distributed in the hope that it will be useful,
16556 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16557 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16558 + * GNU General Public License for more details.
16560 + * You should have received a copy of the GNU General Public License
16561 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16565 + * helpers for hlist_bl.h
16568 +#ifndef __AUFS_HBL_H__
16569 +#define __AUFS_HBL_H__
16573 +#include <linux/list_bl.h>
16575 +static inline void au_hbl_add(struct hlist_bl_node *node,
16576 + struct hlist_bl_head *hbl)
16578 + hlist_bl_lock(hbl);
16579 + hlist_bl_add_head(node, hbl);
16580 + hlist_bl_unlock(hbl);
16583 +static inline void au_hbl_del(struct hlist_bl_node *node,
16584 + struct hlist_bl_head *hbl)
16586 + hlist_bl_lock(hbl);
16587 + hlist_bl_del(node);
16588 + hlist_bl_unlock(hbl);
16591 +#define au_hbl_for_each(pos, head) \
16592 + for (pos = hlist_bl_first(head); \
16596 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16598 + unsigned long cnt;
16599 + struct hlist_bl_node *pos;
16602 + hlist_bl_lock(hbl);
16603 + au_hbl_for_each(pos, hbl)
16605 + hlist_bl_unlock(hbl);
16609 +#endif /* __KERNEL__ */
16610 +#endif /* __AUFS_HBL_H__ */
16611 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16612 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16613 +++ linux/fs/aufs/hfsnotify.c 2021-12-03 15:38:59.936647310 +0100
16615 +// SPDX-License-Identifier: GPL-2.0
16617 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16619 + * This program, aufs is free software; you can redistribute it and/or modify
16620 + * it under the terms of the GNU General Public License as published by
16621 + * the Free Software Foundation; either version 2 of the License, or
16622 + * (at your option) any later version.
16624 + * This program is distributed in the hope that it will be useful,
16625 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16626 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16627 + * GNU General Public License for more details.
16629 + * You should have received a copy of the GNU General Public License
16630 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16634 + * fsnotify for the lower directories
16639 +/* FS_IN_IGNORED is unnecessary */
16640 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16641 + | FS_CREATE | FS_EVENT_ON_CHILD);
16642 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16643 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16645 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16647 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16649 + /* AuDbg("here\n"); */
16650 + au_cache_free_hnotify(hn);
16651 + smp_mb__before_atomic(); /* for atomic64_dec */
16652 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16653 + wake_up(&au_hfsn_wq);
16656 +static int au_hfsn_alloc(struct au_hinode *hinode)
16659 + struct au_hnotify *hn;
16660 + struct super_block *sb;
16661 + struct au_branch *br;
16662 + struct fsnotify_mark *mark;
16663 + aufs_bindex_t bindex;
16665 + hn = hinode->hi_notify;
16666 + sb = hn->hn_aufs_inode->i_sb;
16667 + bindex = au_br_index(sb, hinode->hi_id);
16668 + br = au_sbr(sb, bindex);
16669 + AuDebugOn(!br->br_hfsn);
16671 + mark = &hn->hn_mark;
16672 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16673 + mark->mask = AuHfsnMask;
16675 + * by udba rename or rmdir, aufs assign a new inode to the known
16676 + * h_inode, so specify 1 to allow dups.
16679 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16685 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16687 + struct fsnotify_mark *mark;
16688 + unsigned long long ull;
16689 + struct fsnotify_group *group;
16691 + ull = atomic64_inc_return(&au_hfsn_ifree);
16694 + mark = &hn->hn_mark;
16695 + spin_lock(&mark->lock);
16696 + group = mark->group;
16697 + fsnotify_get_group(group);
16698 + spin_unlock(&mark->lock);
16700 + fsnotify_destroy_mark(mark, group);
16701 + fsnotify_put_mark(mark);
16702 + fsnotify_put_group(group);
16705 + /* free hn by myself */
16709 +/* ---------------------------------------------------------------------- */
16711 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16713 + struct fsnotify_mark *mark;
16715 + mark = &hinode->hi_notify->hn_mark;
16716 + spin_lock(&mark->lock);
16718 + AuDebugOn(mark->mask & AuHfsnMask);
16719 + mark->mask |= AuHfsnMask;
16721 + AuDebugOn(!(mark->mask & AuHfsnMask));
16722 + mark->mask &= ~AuHfsnMask;
16724 + spin_unlock(&mark->lock);
16725 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16728 +/* ---------------------------------------------------------------------- */
16730 +/* #define AuDbgHnotify */
16731 +#ifdef AuDbgHnotify
16732 +static char *au_hfsn_name(u32 mask)
16734 +#ifdef CONFIG_AUFS_DEBUG
16735 +#define test_ret(flag) \
16737 + if (mask & flag) \
16740 + test_ret(FS_ACCESS);
16741 + test_ret(FS_MODIFY);
16742 + test_ret(FS_ATTRIB);
16743 + test_ret(FS_CLOSE_WRITE);
16744 + test_ret(FS_CLOSE_NOWRITE);
16745 + test_ret(FS_OPEN);
16746 + test_ret(FS_MOVED_FROM);
16747 + test_ret(FS_MOVED_TO);
16748 + test_ret(FS_CREATE);
16749 + test_ret(FS_DELETE);
16750 + test_ret(FS_DELETE_SELF);
16751 + test_ret(FS_MOVE_SELF);
16752 + test_ret(FS_UNMOUNT);
16753 + test_ret(FS_Q_OVERFLOW);
16754 + test_ret(FS_IN_IGNORED);
16755 + test_ret(FS_ISDIR);
16756 + test_ret(FS_IN_ONESHOT);
16757 + test_ret(FS_EVENT_ON_CHILD);
16766 +/* ---------------------------------------------------------------------- */
16768 +static void au_hfsn_free_group(struct fsnotify_group *group)
16770 + struct au_br_hfsnotify *hfsn = group->private;
16772 + /* AuDbg("here\n"); */
16773 + au_kfree_try_rcu(hfsn);
16776 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16777 + u32 mask, const void *data, int data_type,
16778 + struct inode *dir,
16779 + const struct qstr *file_name, u32 cookie,
16780 + struct fsnotify_iter_info *iter_info)
16783 + struct au_hnotify *hnotify;
16784 + struct inode *h_dir, *h_inode;
16785 + struct fsnotify_mark *inode_mark;
16787 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16790 + /* if FS_UNMOUNT happens, there must be another bug */
16791 + AuDebugOn(mask & FS_UNMOUNT);
16792 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16797 +#ifdef AuDbgHnotify
16799 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16800 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16801 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16802 + h_dir->i_ino, mask, au_hfsn_name(mask),
16803 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16804 + /* WARN_ON(1); */
16809 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16810 + AuDebugOn(!inode_mark);
16811 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16812 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16818 +static struct fsnotify_ops au_hfsn_ops = {
16819 + .handle_event = au_hfsn_handle_event,
16820 + .free_group_priv = au_hfsn_free_group,
16821 + .free_mark = au_hfsn_free_mark
16824 +/* ---------------------------------------------------------------------- */
16826 +static void au_hfsn_fin_br(struct au_branch *br)
16828 + struct au_br_hfsnotify *hfsn;
16830 + hfsn = br->br_hfsn;
16833 + fsnotify_put_group(hfsn->hfsn_group);
16838 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16841 + struct fsnotify_group *group;
16842 + struct au_br_hfsnotify *hfsn;
16845 + br->br_hfsn = NULL;
16846 + if (!au_br_hnotifyable(perm))
16850 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16851 + if (unlikely(!hfsn))
16855 + group = fsnotify_alloc_group(&au_hfsn_ops);
16856 + if (IS_ERR(group)) {
16857 + err = PTR_ERR(group);
16858 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16862 + group->private = hfsn;
16863 + hfsn->hfsn_group = group;
16864 + br->br_hfsn = hfsn;
16865 + goto out; /* success */
16868 + au_kfree_try_rcu(hfsn);
16873 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16878 + if (!br->br_hfsn)
16879 + err = au_hfsn_init_br(br, perm);
16884 +/* ---------------------------------------------------------------------- */
16886 +static void au_hfsn_fin(void)
16888 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16889 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16892 +const struct au_hnotify_op au_hnotify_op = {
16893 + .ctl = au_hfsn_ctl,
16894 + .alloc = au_hfsn_alloc,
16895 + .free = au_hfsn_free,
16897 + .fin = au_hfsn_fin,
16899 + .reset_br = au_hfsn_reset_br,
16900 + .fin_br = au_hfsn_fin_br,
16901 + .init_br = au_hfsn_init_br
16903 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16904 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16905 +++ linux/fs/aufs/hfsplus.c 2021-12-03 15:38:59.936647310 +0100
16907 +// SPDX-License-Identifier: GPL-2.0
16909 + * Copyright (C) 2010-2021 Junjiro R. Okajima
16911 + * This program, aufs is free software; you can redistribute it and/or modify
16912 + * it under the terms of the GNU General Public License as published by
16913 + * the Free Software Foundation; either version 2 of the License, or
16914 + * (at your option) any later version.
16916 + * This program is distributed in the hope that it will be useful,
16917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16919 + * GNU General Public License for more details.
16921 + * You should have received a copy of the GNU General Public License
16922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16926 + * special support for filesystems which acquires an inode mutex
16927 + * at final closing a file, eg, hfsplus.
16929 + * This trick is very simple and stupid, just to open the file before really
16930 + * necessary open to tell hfsplus that this is not the final closing.
16931 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16932 + * and au_h_open_post() after releasing it.
16937 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16940 + struct file *h_file;
16941 + struct dentry *h_dentry;
16943 + h_dentry = au_h_dptr(dentry, bindex);
16944 + AuDebugOn(!h_dentry);
16945 + AuDebugOn(d_is_negative(h_dentry));
16948 + if (au_test_hfsplus(h_dentry->d_sb)
16949 + && d_is_reg(h_dentry))
16950 + h_file = au_h_open(dentry, bindex,
16951 + O_RDONLY | O_NOATIME | O_LARGEFILE,
16952 + /*file*/NULL, force_wr);
16956 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
16957 + struct file *h_file)
16959 + struct au_branch *br;
16963 + br = au_sbr(dentry->d_sb, bindex);
16964 + au_lcnt_dec(&br->br_nfiles);
16967 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
16968 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
16969 +++ linux/fs/aufs/hnotify.c 2021-12-03 15:38:59.936647310 +0100
16971 +// SPDX-License-Identifier: GPL-2.0
16973 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16975 + * This program, aufs is free software; you can redistribute it and/or modify
16976 + * it under the terms of the GNU General Public License as published by
16977 + * the Free Software Foundation; either version 2 of the License, or
16978 + * (at your option) any later version.
16980 + * This program is distributed in the hope that it will be useful,
16981 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16982 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16983 + * GNU General Public License for more details.
16985 + * You should have received a copy of the GNU General Public License
16986 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16990 + * abstraction to notify the direct changes on lower directories
16993 +/* #include <linux/iversion.h> */
16996 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
16999 + struct au_hnotify *hn;
17002 + hn = au_cache_alloc_hnotify();
17004 + hn->hn_aufs_inode = inode;
17005 + hinode->hi_notify = hn;
17006 + err = au_hnotify_op.alloc(hinode);
17008 + if (unlikely(err)) {
17009 + hinode->hi_notify = NULL;
17010 + au_cache_free_hnotify(hn);
17012 + * The upper dir was removed by udba, but the same named
17013 + * dir left. In this case, aufs assigns a new inode
17014 + * number and set the monitor again.
17015 + * For the lower dir, the old monitor is still left.
17017 + if (err == -EEXIST)
17026 +void au_hn_free(struct au_hinode *hinode)
17028 + struct au_hnotify *hn;
17030 + hn = hinode->hi_notify;
17032 + hinode->hi_notify = NULL;
17033 + if (au_hnotify_op.free(hinode, hn))
17034 + au_cache_free_hnotify(hn);
17038 +/* ---------------------------------------------------------------------- */
17040 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17042 + if (hinode->hi_notify)
17043 + au_hnotify_op.ctl(hinode, do_set);
17046 +void au_hn_reset(struct inode *inode, unsigned int flags)
17048 + aufs_bindex_t bindex, bbot;
17049 + struct inode *hi;
17050 + struct dentry *iwhdentry;
17052 + bbot = au_ibbot(inode);
17053 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17054 + hi = au_h_iptr(inode, bindex);
17058 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17059 + iwhdentry = au_hi_wh(inode, bindex);
17063 + au_set_h_iptr(inode, bindex, NULL, 0);
17064 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17065 + flags & ~AuHi_XINO);
17068 + /* inode_unlock(hi); */
17072 +/* ---------------------------------------------------------------------- */
17074 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17077 + aufs_bindex_t bindex, bbot, bfound, btop;
17078 + struct inode *h_i;
17081 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17082 + pr_warn("branch root dir was changed\n");
17087 + bbot = au_ibbot(inode);
17088 + btop = au_ibtop(inode);
17089 +#if 0 /* reserved for future use */
17090 + if (bindex == bbot) {
17091 + /* keep this ino in rename case */
17095 + for (bindex = btop; bindex <= bbot; bindex++)
17096 + if (au_h_iptr(inode, bindex) == h_inode) {
17103 + for (bindex = btop; bindex <= bbot; bindex++) {
17104 + h_i = au_h_iptr(inode, bindex);
17108 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17109 + /* ignore this error */
17110 + /* bad action? */
17113 + /* children inode number will be broken */
17120 +static int hn_gen_tree(struct dentry *dentry)
17122 + int err, i, j, ndentry;
17123 + struct au_dcsub_pages dpages;
17124 + struct au_dpage *dpage;
17125 + struct dentry **dentries;
17127 + err = au_dpages_init(&dpages, GFP_NOFS);
17128 + if (unlikely(err))
17130 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17131 + if (unlikely(err))
17134 + for (i = 0; i < dpages.ndpage; i++) {
17135 + dpage = dpages.dpages + i;
17136 + dentries = dpage->dentries;
17137 + ndentry = dpage->ndentry;
17138 + for (j = 0; j < ndentry; j++) {
17139 + struct dentry *d;
17146 + if (d_really_is_positive(d))
17147 + /* todo: reset children xino?
17148 + cached children only? */
17149 + au_iigen_dec(d_inode(d));
17154 + au_dpages_free(&dpages);
17160 + * return 0 if processed.
17162 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17163 + const unsigned int isdir)
17166 + struct dentry *d;
17167 + struct qstr *dname;
17170 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17171 + pr_warn("branch root dir was changed\n");
17177 + AuDebugOn(!name);
17178 + au_iigen_dec(inode);
17179 + spin_lock(&inode->i_lock);
17180 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17181 + spin_lock(&d->d_lock);
17182 + dname = &d->d_name;
17183 + if (dname->len != nlen
17184 + && memcmp(dname->name, name, nlen)) {
17185 + spin_unlock(&d->d_lock);
17190 + spin_unlock(&d->d_lock);
17193 + spin_unlock(&inode->i_lock);
17195 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17196 + d = d_find_any_alias(inode);
17198 + au_iigen_dec(inode);
17202 + spin_lock(&d->d_lock);
17203 + dname = &d->d_name;
17204 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17205 + spin_unlock(&d->d_lock);
17206 + err = hn_gen_tree(d);
17207 + spin_lock(&d->d_lock);
17209 + spin_unlock(&d->d_lock);
17218 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17222 + if (IS_ROOT(dentry)) {
17223 + pr_warn("branch root dir was changed\n");
17229 + au_digen_dec(dentry);
17230 + if (d_really_is_positive(dentry))
17231 + au_iigen_dec(d_inode(dentry));
17233 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17234 + if (d_really_is_positive(dentry))
17235 + err = hn_gen_tree(dentry);
17242 +/* ---------------------------------------------------------------------- */
17244 +/* hnotify job flags */
17245 +#define AuHnJob_XINO0 1
17246 +#define AuHnJob_GEN (1 << 1)
17247 +#define AuHnJob_DIRENT (1 << 2)
17248 +#define AuHnJob_ISDIR (1 << 3)
17249 +#define AuHnJob_TRYXINO0 (1 << 4)
17250 +#define AuHnJob_MNTPNT (1 << 5)
17251 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17252 +#define au_fset_hnjob(flags, name) \
17253 + do { (flags) |= AuHnJob_##name; } while (0)
17254 +#define au_fclr_hnjob(flags, name) \
17255 + do { (flags) &= ~AuHnJob_##name; } while (0)
17263 +struct au_hnotify_args {
17264 + struct inode *h_dir, *dir, *h_child_inode;
17266 + unsigned int flags[AuHnLast];
17267 + unsigned int h_child_nlen;
17268 + char h_child_name[];
17271 +struct hn_job_args {
17272 + unsigned int flags;
17273 + struct inode *inode, *h_inode, *dir, *h_dir;
17274 + struct dentry *dentry;
17279 +static int hn_job(struct hn_job_args *a)
17281 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17285 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17286 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17288 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17291 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17292 + if (!a->h_inode->i_nlink
17293 + && !(a->h_inode->i_state & I_LINKABLE))
17294 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17295 + inode_unlock_shared(a->h_inode);
17298 + /* make the generation obsolete */
17299 + if (au_ftest_hnjob(a->flags, GEN)) {
17302 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17304 + if (e && a->dentry)
17305 + hn_gen_by_name(a->dentry, isdir);
17306 + /* ignore this error */
17309 + /* make dir entries obsolete */
17310 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17311 + struct au_vdir *vdir;
17313 + vdir = au_ivdir(a->inode);
17315 + vdir->vd_jiffy = 0;
17316 + /* IMustLock(a->inode); */
17317 + /* inode_inc_iversion(a->inode); */
17320 + /* can do nothing but warn */
17321 + if (au_ftest_hnjob(a->flags, MNTPNT)
17323 + && d_mountpoint(a->dentry))
17324 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17329 +/* ---------------------------------------------------------------------- */
17331 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17332 + struct inode *dir)
17334 + struct dentry *dentry, *d, *parent;
17335 + struct qstr *dname;
17337 + parent = d_find_any_alias(dir);
17342 + spin_lock(&parent->d_lock);
17343 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17344 + /* AuDbg("%pd\n", d); */
17345 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17346 + dname = &d->d_name;
17347 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17348 + goto cont_unlock;
17352 + goto cont_unlock;
17353 + if (au_dcount(d) > 0) {
17354 + dentry = dget_dlock(d);
17355 + spin_unlock(&d->d_lock);
17360 + spin_unlock(&d->d_lock);
17362 + spin_unlock(&parent->d_lock);
17366 + di_write_lock_child(dentry);
17371 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17372 + aufs_bindex_t bindex, ino_t h_ino)
17374 + struct inode *inode;
17379 + err = au_xino_read(sb, bindex, h_ino, &ino);
17381 + inode = ilookup(sb, ino);
17385 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17386 + pr_warn("wrong root branch\n");
17392 + ii_write_lock_child(inode);
17398 +static void au_hn_bh(void *_args)
17400 + struct au_hnotify_args *a = _args;
17401 + struct super_block *sb;
17402 + aufs_bindex_t bindex, bbot, bfound;
17403 + unsigned char xino, try_iput;
17405 + struct inode *inode;
17407 + struct hn_job_args args;
17408 + struct dentry *dentry;
17409 + struct au_sbinfo *sbinfo;
17411 + AuDebugOn(!_args);
17412 + AuDebugOn(!a->h_dir);
17413 + AuDebugOn(!a->dir);
17414 + AuDebugOn(!a->mask);
17415 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17416 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17417 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17422 + * do not lock a->dir->i_mutex here
17423 + * because of d_revalidate() may cause a deadlock.
17425 + sb = a->dir->i_sb;
17427 + sbinfo = au_sbi(sb);
17428 + AuDebugOn(!sbinfo);
17429 + si_write_lock(sb, AuLock_NOPLMW);
17431 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17432 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17433 + case FS_MOVED_FROM:
17434 + case FS_MOVED_TO:
17435 + AuWarn1("DIRREN with UDBA may not work correctly "
17436 + "for the direct rename(2)\n");
17439 + ii_read_lock_parent(a->dir);
17441 + bbot = au_ibbot(a->dir);
17442 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17443 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17447 + ii_read_unlock(a->dir);
17448 + if (unlikely(bfound < 0))
17451 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17453 + if (a->h_child_inode)
17454 + h_ino = a->h_child_inode->i_ino;
17456 + if (a->h_child_nlen
17457 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17458 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17459 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17462 + if (dentry && d_really_is_positive(dentry))
17463 + inode = d_inode(dentry);
17464 + if (xino && !inode && h_ino
17465 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17466 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17467 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17468 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17472 + args.flags = a->flags[AuHn_CHILD];
17473 + args.dentry = dentry;
17474 + args.inode = inode;
17475 + args.h_inode = a->h_child_inode;
17476 + args.dir = a->dir;
17477 + args.h_dir = a->h_dir;
17478 + args.h_name = a->h_child_name;
17479 + args.h_nlen = a->h_child_nlen;
17480 + err = hn_job(&args);
17482 + if (au_di(dentry))
17483 + di_write_unlock(dentry);
17486 + if (inode && try_iput) {
17487 + ii_write_unlock(inode);
17491 + ii_write_lock_parent(a->dir);
17492 + args.flags = a->flags[AuHn_PARENT];
17493 + args.dentry = NULL;
17494 + args.inode = a->dir;
17495 + args.h_inode = a->h_dir;
17497 + args.h_dir = NULL;
17498 + args.h_name = NULL;
17500 + err = hn_job(&args);
17501 + ii_write_unlock(a->dir);
17504 + iput(a->h_child_inode);
17507 + si_write_unlock(sb);
17508 + au_nwt_done(&sbinfo->si_nowait);
17512 +/* ---------------------------------------------------------------------- */
17514 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17515 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17518 + unsigned int flags[AuHnLast], f;
17519 + unsigned char isdir, isroot, wh;
17520 + struct inode *dir;
17521 + struct au_hnotify_args *args;
17522 + char *p, *h_child_name;
17525 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17526 + dir = igrab(hnotify->hn_aufs_inode);
17530 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17532 + h_child_name = (void *)h_child_qstr->name;
17533 + len = h_child_qstr->len;
17534 + if (h_child_name) {
17535 + if (len > AUFS_WH_PFX_LEN
17536 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17537 + h_child_name += AUFS_WH_PFX_LEN;
17538 + len -= AUFS_WH_PFX_LEN;
17544 + if (h_child_inode)
17545 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17546 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17547 + flags[AuHn_CHILD] = 0;
17549 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17550 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17551 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17552 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17553 + case FS_MOVED_FROM:
17554 + case FS_MOVED_TO:
17555 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17556 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17559 + AuDebugOn(!h_child_name);
17564 + * aufs never be able to get this child inode.
17565 + * revalidation should be in d_revalidate()
17566 + * by checking i_nlink, i_generation or d_unhashed().
17568 + AuDebugOn(!h_child_name);
17569 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17570 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17578 + h_child_inode = NULL;
17581 + /* iput() and kfree() will be called in au_hnotify() */
17582 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17583 + if (unlikely(!args)) {
17584 + AuErr1("no memory\n");
17588 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17589 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17590 + args->mask = mask;
17592 + args->h_dir = igrab(h_dir);
17593 + if (h_child_inode)
17594 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17595 + args->h_child_inode = h_child_inode;
17596 + args->h_child_nlen = len;
17598 + p = (void *)args;
17599 + p += sizeof(*args);
17600 + memcpy(p, h_child_name, len);
17604 + /* NFS fires the event for silly-renamed one from kworker */
17606 + if (!dir->i_nlink
17607 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17609 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17610 + if (unlikely(err)) {
17611 + pr_err("wkq %d\n", err);
17612 + iput(args->h_child_inode);
17613 + iput(args->h_dir);
17615 + au_kfree_rcu(args);
17622 +/* ---------------------------------------------------------------------- */
17624 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17628 + AuDebugOn(!(udba & AuOptMask_UDBA));
17631 + if (au_hnotify_op.reset_br)
17632 + err = au_hnotify_op.reset_br(udba, br, perm);
17637 +int au_hnotify_init_br(struct au_branch *br, int perm)
17642 + if (au_hnotify_op.init_br)
17643 + err = au_hnotify_op.init_br(br, perm);
17648 +void au_hnotify_fin_br(struct au_branch *br)
17650 + if (au_hnotify_op.fin_br)
17651 + au_hnotify_op.fin_br(br);
17654 +static void au_hn_destroy_cache(void)
17656 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17657 + au_cache[AuCache_HNOTIFY] = NULL;
17660 +int __init au_hnotify_init(void)
17665 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17666 + if (au_cache[AuCache_HNOTIFY]) {
17668 + if (au_hnotify_op.init)
17669 + err = au_hnotify_op.init();
17670 + if (unlikely(err))
17671 + au_hn_destroy_cache();
17677 +void au_hnotify_fin(void)
17679 + if (au_hnotify_op.fin)
17680 + au_hnotify_op.fin();
17682 + /* cf. au_cache_fin() */
17683 + if (au_cache[AuCache_HNOTIFY])
17684 + au_hn_destroy_cache();
17686 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17687 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17688 +++ linux/fs/aufs/iinfo.c 2021-12-03 15:38:59.936647310 +0100
17690 +// SPDX-License-Identifier: GPL-2.0
17692 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17694 + * This program, aufs is free software; you can redistribute it and/or modify
17695 + * it under the terms of the GNU General Public License as published by
17696 + * the Free Software Foundation; either version 2 of the License, or
17697 + * (at your option) any later version.
17699 + * This program is distributed in the hope that it will be useful,
17700 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17701 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17702 + * GNU General Public License for more details.
17704 + * You should have received a copy of the GNU General Public License
17705 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17709 + * inode private data
17714 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17716 + struct inode *h_inode;
17717 + struct au_hinode *hinode;
17719 + IiMustAnyLock(inode);
17721 + hinode = au_hinode(au_ii(inode), bindex);
17722 + h_inode = hinode->hi_inode;
17723 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17727 +/* todo: hard/soft set? */
17728 +void au_hiput(struct au_hinode *hinode)
17730 + au_hn_free(hinode);
17731 + dput(hinode->hi_whdentry);
17732 + iput(hinode->hi_inode);
17735 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17737 + unsigned int flags;
17738 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17741 + if (au_opt_test(mnt_flags, XINO))
17742 + au_fset_hi(flags, XINO);
17743 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17744 + au_fset_hi(flags, HNOTIFY);
17748 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17749 + struct inode *h_inode, unsigned int flags)
17751 + struct au_hinode *hinode;
17752 + struct inode *hi;
17753 + struct au_iinfo *iinfo = au_ii(inode);
17755 + IiMustWriteLock(inode);
17757 + hinode = au_hinode(iinfo, bindex);
17758 + hi = hinode->hi_inode;
17759 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17762 + au_hiput(hinode);
17763 + hinode->hi_inode = h_inode;
17766 + struct super_block *sb = inode->i_sb;
17767 + struct au_branch *br;
17769 + AuDebugOn(inode->i_mode
17770 + && (h_inode->i_mode & S_IFMT)
17771 + != (inode->i_mode & S_IFMT));
17772 + if (bindex == iinfo->ii_btop)
17773 + au_cpup_igen(inode, h_inode);
17774 + br = au_sbr(sb, bindex);
17775 + hinode->hi_id = br->br_id;
17776 + if (au_ftest_hi(flags, XINO)) {
17777 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17779 + if (unlikely(err))
17780 + AuIOErr1("failed au_xino_write() %d\n", err);
17783 + if (au_ftest_hi(flags, HNOTIFY)
17784 + && au_br_hnotifyable(br->br_perm)) {
17785 + err = au_hn_alloc(hinode, inode);
17786 + if (unlikely(err))
17787 + AuIOErr1("au_hn_alloc() %d\n", err);
17792 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17793 + struct dentry *h_wh)
17795 + struct au_hinode *hinode;
17797 + IiMustWriteLock(inode);
17799 + hinode = au_hinode(au_ii(inode), bindex);
17800 + AuDebugOn(hinode->hi_whdentry);
17801 + hinode->hi_whdentry = h_wh;
17804 +void au_update_iigen(struct inode *inode, int half)
17806 + struct au_iinfo *iinfo;
17807 + struct au_iigen *iigen;
17808 + unsigned int sigen;
17810 + sigen = au_sigen(inode->i_sb);
17811 + iinfo = au_ii(inode);
17812 + iigen = &iinfo->ii_generation;
17813 + spin_lock(&iigen->ig_spin);
17814 + iigen->ig_generation = sigen;
17816 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17818 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17819 + spin_unlock(&iigen->ig_spin);
17822 +/* it may be called at remount time, too */
17823 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17825 + struct au_iinfo *iinfo;
17826 + aufs_bindex_t bindex, bbot;
17828 + AuDebugOn(au_is_bad_inode(inode));
17829 + IiMustWriteLock(inode);
17831 + iinfo = au_ii(inode);
17832 + if (do_put_zero && iinfo->ii_btop >= 0) {
17833 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17835 + struct inode *h_i;
17837 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17840 + && !(h_i->i_state & I_LINKABLE))
17841 + au_set_h_iptr(inode, bindex, NULL, 0);
17845 + iinfo->ii_btop = -1;
17846 + iinfo->ii_bbot = -1;
17847 + bbot = au_sbbot(inode->i_sb);
17848 + for (bindex = 0; bindex <= bbot; bindex++)
17849 + if (au_hinode(iinfo, bindex)->hi_inode) {
17850 + iinfo->ii_btop = bindex;
17853 + if (iinfo->ii_btop >= 0)
17854 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17855 + if (au_hinode(iinfo, bindex)->hi_inode) {
17856 + iinfo->ii_bbot = bindex;
17859 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17862 +/* ---------------------------------------------------------------------- */
17864 +void au_icntnr_init_once(void *_c)
17866 + struct au_icntnr *c = _c;
17867 + struct au_iinfo *iinfo = &c->iinfo;
17869 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17870 + au_rw_init(&iinfo->ii_rwsem);
17871 + inode_init_once(&c->vfs_inode);
17874 +void au_hinode_init(struct au_hinode *hinode)
17876 + hinode->hi_inode = NULL;
17877 + hinode->hi_id = -1;
17878 + au_hn_init(hinode);
17879 + hinode->hi_whdentry = NULL;
17882 +int au_iinfo_init(struct inode *inode)
17884 + struct au_iinfo *iinfo;
17885 + struct super_block *sb;
17886 + struct au_hinode *hi;
17889 + sb = inode->i_sb;
17890 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17891 + nbr = au_sbbot(sb) + 1;
17892 + if (unlikely(nbr <= 0))
17894 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17896 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17898 + iinfo->ii_hinode = hi;
17899 + for (i = 0; i < nbr; i++, hi++)
17900 + au_hinode_init(hi);
17902 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17903 + iinfo->ii_btop = -1;
17904 + iinfo->ii_bbot = -1;
17905 + iinfo->ii_vdir = NULL;
17911 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17914 + struct au_hinode *hip;
17916 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17919 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17922 + iinfo->ii_hinode = hip;
17923 + i = iinfo->ii_bbot + 1;
17925 + for (; i < nbr; i++, hip++)
17926 + au_hinode_init(hip);
17933 +void au_iinfo_fin(struct inode *inode)
17935 + struct au_iinfo *iinfo;
17936 + struct au_hinode *hi;
17937 + struct super_block *sb;
17938 + aufs_bindex_t bindex, bbot;
17939 + const unsigned char unlinked = !inode->i_nlink;
17941 + AuDebugOn(au_is_bad_inode(inode));
17943 + sb = inode->i_sb;
17944 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
17945 + if (si_pid_test(sb))
17946 + au_xino_delete_inode(inode, unlinked);
17949 + * it is safe to hide the dependency between sbinfo and
17953 + si_noflush_read_lock(sb);
17954 + au_xino_delete_inode(inode, unlinked);
17955 + si_read_unlock(sb);
17959 + iinfo = au_ii(inode);
17960 + if (iinfo->ii_vdir)
17961 + au_vdir_free(iinfo->ii_vdir);
17963 + bindex = iinfo->ii_btop;
17964 + if (bindex >= 0) {
17965 + hi = au_hinode(iinfo, bindex);
17966 + bbot = iinfo->ii_bbot;
17967 + while (bindex++ <= bbot) {
17968 + if (hi->hi_inode)
17973 + au_kfree_rcu(iinfo->ii_hinode);
17974 + AuRwDestroy(&iinfo->ii_rwsem);
17976 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
17977 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
17978 +++ linux/fs/aufs/inode.c 2021-12-03 15:38:59.936647310 +0100
17980 +// SPDX-License-Identifier: GPL-2.0
17982 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17984 + * This program, aufs is free software; you can redistribute it and/or modify
17985 + * it under the terms of the GNU General Public License as published by
17986 + * the Free Software Foundation; either version 2 of the License, or
17987 + * (at your option) any later version.
17989 + * This program is distributed in the hope that it will be useful,
17990 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17991 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17992 + * GNU General Public License for more details.
17994 + * You should have received a copy of the GNU General Public License
17995 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17999 + * inode functions
18002 +#include <linux/iversion.h>
18005 +struct inode *au_igrab(struct inode *inode)
18008 + AuDebugOn(!atomic_read(&inode->i_count));
18014 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18016 + au_cpup_attr_all(inode, /*force*/0);
18017 + au_update_iigen(inode, /*half*/1);
18019 + inode_inc_iversion(inode);
18022 +static int au_ii_refresh(struct inode *inode, int *update)
18026 + aufs_bindex_t bindex, new_bindex;
18027 + struct super_block *sb;
18028 + struct au_iinfo *iinfo;
18029 + struct au_hinode *p, *q, tmp;
18031 + AuDebugOn(au_is_bad_inode(inode));
18032 + IiMustWriteLock(inode);
18035 + sb = inode->i_sb;
18036 + nbr = au_sbbot(sb) + 1;
18037 + type = inode->i_mode & S_IFMT;
18038 + iinfo = au_ii(inode);
18039 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18040 + if (unlikely(err))
18043 + AuDebugOn(iinfo->ii_btop < 0);
18044 + p = au_hinode(iinfo, iinfo->ii_btop);
18045 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18047 + if (!p->hi_inode)
18050 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18051 + new_bindex = au_br_index(sb, p->hi_id);
18052 + if (new_bindex == bindex)
18055 + if (new_bindex < 0) {
18058 + p->hi_inode = NULL;
18062 + if (new_bindex < iinfo->ii_btop)
18063 + iinfo->ii_btop = new_bindex;
18064 + if (iinfo->ii_bbot < new_bindex)
18065 + iinfo->ii_bbot = new_bindex;
18066 + /* swap two lower inode, and loop again */
18067 + q = au_hinode(iinfo, new_bindex);
18071 + if (tmp.hi_inode) {
18076 + au_update_ibrange(inode, /*do_put_zero*/0);
18077 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18078 + e = au_dy_irefresh(inode);
18079 + if (unlikely(e && !err))
18087 +void au_refresh_iop(struct inode *inode, int force_getattr)
18090 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18091 + const struct inode_operations *iop
18092 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18094 + if (inode->i_op == iop)
18097 + switch (inode->i_mode & S_IFMT) {
18099 + type = AuIop_DIR;
18102 + type = AuIop_SYMLINK;
18105 + type = AuIop_OTHER;
18109 + inode->i_op = iop + type;
18110 + /* unnecessary smp_wmb() */
18113 +int au_refresh_hinode_self(struct inode *inode)
18117 + err = au_ii_refresh(inode, &update);
18119 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18125 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18127 + int err, e, update;
18128 + unsigned int flags;
18130 + aufs_bindex_t bindex, bbot;
18131 + unsigned char isdir;
18132 + struct au_hinode *p;
18133 + struct au_iinfo *iinfo;
18135 + err = au_ii_refresh(inode, &update);
18136 + if (unlikely(err))
18140 + iinfo = au_ii(inode);
18141 + p = au_hinode(iinfo, iinfo->ii_btop);
18142 + mode = (inode->i_mode & S_IFMT);
18143 + isdir = S_ISDIR(mode);
18144 + flags = au_hi_flags(inode, isdir);
18145 + bbot = au_dbbot(dentry);
18146 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18147 + struct inode *h_i, *h_inode;
18148 + struct dentry *h_d;
18150 + h_d = au_h_dptr(dentry, bindex);
18151 + if (!h_d || d_is_negative(h_d))
18154 + h_inode = d_inode(h_d);
18155 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18156 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18157 + h_i = au_h_iptr(inode, bindex);
18159 + if (h_i == h_inode)
18165 + if (bindex < iinfo->ii_btop)
18166 + iinfo->ii_btop = bindex;
18167 + if (iinfo->ii_bbot < bindex)
18168 + iinfo->ii_bbot = bindex;
18169 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18172 + au_update_ibrange(inode, /*do_put_zero*/0);
18173 + e = au_dy_irefresh(inode);
18174 + if (unlikely(e && !err))
18177 + au_refresh_hinode_attr(inode, update && isdir);
18184 +static int set_inode(struct inode *inode, struct dentry *dentry)
18187 + unsigned int flags;
18189 + aufs_bindex_t bindex, btop, btail;
18190 + unsigned char isdir;
18191 + struct dentry *h_dentry;
18192 + struct inode *h_inode;
18193 + struct au_iinfo *iinfo;
18194 + const struct inode_operations *iop;
18196 + IiMustWriteLock(inode);
18200 + iop = au_sbi(inode->i_sb)->si_iop_array;
18201 + btop = au_dbtop(dentry);
18202 + h_dentry = au_h_dptr(dentry, btop);
18203 + h_inode = d_inode(h_dentry);
18204 + mode = h_inode->i_mode;
18205 + switch (mode & S_IFMT) {
18207 + btail = au_dbtail(dentry);
18208 + inode->i_op = iop + AuIop_OTHER;
18209 + inode->i_fop = &aufs_file_fop;
18210 + err = au_dy_iaop(inode, btop, h_inode);
18211 + if (unlikely(err))
18216 + btail = au_dbtaildir(dentry);
18217 + inode->i_op = iop + AuIop_DIR;
18218 + inode->i_fop = &aufs_dir_fop;
18221 + btail = au_dbtail(dentry);
18222 + inode->i_op = iop + AuIop_SYMLINK;
18228 + btail = au_dbtail(dentry);
18229 + inode->i_op = iop + AuIop_OTHER;
18230 + init_special_inode(inode, mode, h_inode->i_rdev);
18233 + AuIOErr("Unknown file type 0%o\n", mode);
18238 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18239 + flags = au_hi_flags(inode, isdir);
18240 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18241 + && au_ftest_hi(flags, HNOTIFY)
18242 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18243 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18244 + au_fclr_hi(flags, HNOTIFY);
18245 + iinfo = au_ii(inode);
18246 + iinfo->ii_btop = btop;
18247 + iinfo->ii_bbot = btail;
18248 + for (bindex = btop; bindex <= btail; bindex++) {
18249 + h_dentry = au_h_dptr(dentry, bindex);
18251 + au_set_h_iptr(inode, bindex,
18252 + au_igrab(d_inode(h_dentry)), flags);
18254 + au_cpup_attr_all(inode, /*force*/1);
18256 + * to force calling aufs_get_acl() every time,
18257 + * do not call cache_no_acl() for aufs inode.
18265 + * successful returns with iinfo write_locked
18267 + * zero: success, matched
18268 + * plus: no error, but unmatched
18270 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18273 + unsigned int gen, igflags;
18274 + aufs_bindex_t bindex, bbot;
18275 + struct inode *h_inode, *h_dinode;
18276 + struct dentry *h_dentry;
18279 + * before this function, if aufs got any iinfo lock, it must be only
18280 + * one, the parent dir.
18281 + * it can happen by UDBA and the obsoleted inode number.
18284 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18288 + ii_write_lock_new_child(inode);
18289 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18290 + h_dinode = d_inode(h_dentry);
18291 + bbot = au_ibbot(inode);
18292 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18293 + h_inode = au_h_iptr(inode, bindex);
18294 + if (!h_inode || h_inode != h_dinode)
18298 + gen = au_iigen(inode, &igflags);
18299 + if (gen == au_digen(dentry)
18300 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18303 + /* fully refresh inode using dentry */
18304 + err = au_refresh_hinode(inode, dentry);
18306 + au_update_iigen(inode, /*half*/0);
18310 + if (unlikely(err))
18311 + ii_write_unlock(inode);
18316 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18317 + unsigned int d_type, ino_t *ino)
18320 + const int isnondir = d_type != DT_DIR;
18322 + /* prevent hardlinked inode number from race condition */
18324 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18325 + if (unlikely(err))
18329 + err = au_xino_read(sb, bindex, h_ino, ino);
18330 + if (unlikely(err))
18331 + goto out_xinondir;
18335 + *ino = au_xino_new_ino(sb);
18336 + if (unlikely(!*ino))
18337 + goto out_xinondir;
18338 + err = au_xino_write(sb, bindex, h_ino, *ino);
18339 + if (unlikely(err))
18340 + goto out_xinondir;
18344 + if (isnondir && idx >= 0)
18345 + au_xinondir_leave(sb, bindex, h_ino, idx);
18350 +/* successful returns with iinfo write_locked */
18351 +/* todo: return with unlocked? */
18352 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18354 + struct inode *inode, *h_inode;
18355 + struct dentry *h_dentry;
18356 + struct super_block *sb;
18357 + ino_t h_ino, ino;
18358 + int err, idx, hlinked;
18359 + aufs_bindex_t btop;
18361 + sb = dentry->d_sb;
18362 + btop = au_dbtop(dentry);
18363 + h_dentry = au_h_dptr(dentry, btop);
18364 + h_inode = d_inode(h_dentry);
18365 + h_ino = h_inode->i_ino;
18366 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18370 + * stop 'race'-ing between hardlinks under different
18374 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18375 + inode = ERR_PTR(err);
18376 + if (unlikely(err))
18380 + err = au_xino_read(sb, btop, h_ino, &ino);
18381 + inode = ERR_PTR(err);
18382 + if (unlikely(err))
18383 + goto out_xinondir;
18386 + ino = au_xino_new_ino(sb);
18387 + if (unlikely(!ino)) {
18388 + inode = ERR_PTR(-EIO);
18389 + goto out_xinondir;
18393 + AuDbg("i%lu\n", (unsigned long)ino);
18394 + inode = au_iget_locked(sb, ino);
18395 + err = PTR_ERR(inode);
18396 + if (IS_ERR(inode))
18397 + goto out_xinondir;
18399 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18400 + if (inode->i_state & I_NEW) {
18401 + ii_write_lock_new_child(inode);
18402 + err = set_inode(inode, dentry);
18404 + unlock_new_inode(inode);
18405 + goto out_xinondir; /* success */
18409 + * iget_failed() calls iput(), but we need to call
18410 + * ii_write_unlock() after iget_failed(). so dirty hack for
18413 + atomic_inc(&inode->i_count);
18414 + iget_failed(inode);
18415 + ii_write_unlock(inode);
18416 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18417 + /* ignore this error */
18419 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18421 + * horrible race condition between lookup, readdir and copyup
18422 + * (or something).
18424 + if (hlinked && idx >= 0)
18425 + au_xinondir_leave(sb, btop, h_ino, idx);
18426 + err = reval_inode(inode, dentry);
18427 + if (unlikely(err < 0)) {
18432 + goto out; /* success */
18433 + else if (hlinked && idx >= 0) {
18434 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18435 + if (unlikely(err)) {
18437 + inode = ERR_PTR(err);
18443 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18444 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18445 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18446 + btop, au_sbtype(h_dentry->d_sb), dentry,
18447 + (unsigned long)h_ino, (unsigned long)ino);
18449 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18452 + if (hlinked && idx >= 0)
18453 + au_xinondir_leave(sb, btop, h_ino, idx);
18459 + inode = ERR_PTR(err);
18461 + if (hlinked && idx >= 0)
18462 + au_xinondir_leave(sb, btop, h_ino, idx);
18467 +/* ---------------------------------------------------------------------- */
18469 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18470 + struct inode *inode)
18473 + struct inode *hi;
18475 + err = au_br_rdonly(au_sbr(sb, bindex));
18477 + /* pseudo-link after flushed may happen out of bounds */
18480 + && au_ibtop(inode) <= bindex
18481 + && bindex <= au_ibbot(inode)) {
18483 + * permission check is unnecessary since vfsub routine
18484 + * will be called later
18486 + hi = au_h_iptr(inode, bindex);
18488 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18494 +int au_test_h_perm(struct inode *h_inode, int mask)
18496 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18498 + return inode_permission(h_inode, mask);
18501 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18503 + if (au_test_nfs(h_inode->i_sb)
18504 + && (mask & MAY_WRITE)
18505 + && S_ISDIR(h_inode->i_mode))
18506 + mask |= MAY_READ; /* force permission check */
18507 + return au_test_h_perm(h_inode, mask);
18509 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18510 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18511 +++ linux/fs/aufs/inode.h 2021-12-03 15:38:59.936647310 +0100
18513 +/* SPDX-License-Identifier: GPL-2.0 */
18515 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18517 + * This program, aufs is free software; you can redistribute it and/or modify
18518 + * it under the terms of the GNU General Public License as published by
18519 + * the Free Software Foundation; either version 2 of the License, or
18520 + * (at your option) any later version.
18522 + * This program is distributed in the hope that it will be useful,
18523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18525 + * GNU General Public License for more details.
18527 + * You should have received a copy of the GNU General Public License
18528 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18532 + * inode operations
18535 +#ifndef __AUFS_INODE_H__
18536 +#define __AUFS_INODE_H__
18540 +#include <linux/fsnotify.h>
18541 +#include "rwsem.h"
18545 +struct au_hnotify {
18546 +#ifdef CONFIG_AUFS_HNOTIFY
18547 +#ifdef CONFIG_AUFS_HFSNOTIFY
18548 + /* never use fsnotify_add_vfsmount_mark() */
18549 + struct fsnotify_mark hn_mark;
18551 + struct inode *hn_aufs_inode; /* no get/put */
18552 + struct rcu_head rcu;
18554 +} ____cacheline_aligned_in_smp;
18556 +struct au_hinode {
18557 + struct inode *hi_inode;
18558 + aufs_bindex_t hi_id;
18559 +#ifdef CONFIG_AUFS_HNOTIFY
18560 + struct au_hnotify *hi_notify;
18563 + /* reference to the copied-up whiteout with get/put */
18564 + struct dentry *hi_whdentry;
18568 +#define AuIG_HALF_REFRESHED 1
18569 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18570 +#define au_ig_fset(flags, name) \
18571 + do { (flags) |= AuIG_##name; } while (0)
18572 +#define au_ig_fclr(flags, name) \
18573 + do { (flags) &= ~AuIG_##name; } while (0)
18576 + spinlock_t ig_spin;
18577 + __u32 ig_generation, ig_flags;
18582 + struct au_iigen ii_generation;
18583 + struct super_block *ii_hsb1; /* no get/put */
18585 + struct au_rwsem ii_rwsem;
18586 + aufs_bindex_t ii_btop, ii_bbot;
18588 + struct au_hinode *ii_hinode;
18589 + struct au_vdir *ii_vdir;
18592 +struct au_icntnr {
18593 + struct au_iinfo iinfo;
18594 + struct inode vfs_inode;
18595 + struct hlist_bl_node plink;
18596 + struct rcu_head rcu;
18597 +} ____cacheline_aligned_in_smp;
18599 +/* au_pin flags */
18600 +#define AuPin_DI_LOCKED 1
18601 +#define AuPin_MNT_WRITE (1 << 1)
18602 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18603 +#define au_fset_pin(flags, name) \
18604 + do { (flags) |= AuPin_##name; } while (0)
18605 +#define au_fclr_pin(flags, name) \
18606 + do { (flags) &= ~AuPin_##name; } while (0)
18610 + struct dentry *dentry;
18611 + unsigned int udba;
18612 + unsigned char lsc_di, lsc_hi, flags;
18613 + aufs_bindex_t bindex;
18616 + struct dentry *parent;
18617 + struct au_hinode *hdir;
18618 + struct vfsmount *h_mnt;
18620 + /* temporary unlock/relock for copyup */
18621 + struct dentry *h_dentry, *h_parent;
18622 + struct au_branch *br;
18623 + struct task_struct *task;
18626 +void au_pin_hdir_unlock(struct au_pin *p);
18627 +int au_pin_hdir_lock(struct au_pin *p);
18628 +int au_pin_hdir_relock(struct au_pin *p);
18629 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18630 +void au_pin_hdir_release(struct au_pin *p);
18632 +/* ---------------------------------------------------------------------- */
18634 +static inline struct au_iinfo *au_ii(struct inode *inode)
18636 + BUG_ON(is_bad_inode(inode));
18637 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18640 +/* ---------------------------------------------------------------------- */
18643 +struct inode *au_igrab(struct inode *inode);
18644 +void au_refresh_iop(struct inode *inode, int force_getattr);
18645 +int au_refresh_hinode_self(struct inode *inode);
18646 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18647 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18648 + unsigned int d_type, ino_t *ino);
18649 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18650 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18651 + struct inode *inode);
18652 +int au_test_h_perm(struct inode *h_inode, int mask);
18653 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18655 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18656 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18658 +#ifdef CONFIG_AUFS_SHWH
18659 + return au_ino(sb, bindex, h_ino, d_type, ino);
18672 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18673 + aufs_iop_nogetattr[AuIop_Last];
18675 +/* au_wr_dir flags */
18676 +#define AuWrDir_ADD_ENTRY 1
18677 +#define AuWrDir_ISDIR (1 << 1)
18678 +#define AuWrDir_TMPFILE (1 << 2)
18679 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18680 +#define au_fset_wrdir(flags, name) \
18681 + do { (flags) |= AuWrDir_##name; } while (0)
18682 +#define au_fclr_wrdir(flags, name) \
18683 + do { (flags) &= ~AuWrDir_##name; } while (0)
18685 +struct au_wr_dir_args {
18686 + aufs_bindex_t force_btgt;
18687 + unsigned char flags;
18689 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18690 + struct au_wr_dir_args *args);
18692 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18693 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18694 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18695 + unsigned int udba, unsigned char flags);
18696 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18697 + unsigned int udba, unsigned char flags) __must_check;
18698 +int au_do_pin(struct au_pin *pin) __must_check;
18699 +void au_unpin(struct au_pin *pin);
18700 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18702 +#define AuIcpup_DID_CPUP 1
18703 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18704 +#define au_fset_icpup(flags, name) \
18705 + do { (flags) |= AuIcpup_##name; } while (0)
18706 +#define au_fclr_icpup(flags, name) \
18707 + do { (flags) &= ~AuIcpup_##name; } while (0)
18709 +struct au_icpup_args {
18710 + unsigned char flags;
18711 + unsigned char pin_flags;
18712 + aufs_bindex_t btgt;
18713 + unsigned int udba;
18714 + struct au_pin pin;
18715 + struct path h_path;
18716 + struct inode *h_inode;
18719 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18720 + struct au_icpup_args *a);
18722 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18723 + struct path *h_path, int locked);
18726 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18727 + struct dentry *h_parent, int isdir);
18728 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18730 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18731 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18733 +struct vfsub_aopen_args;
18734 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18735 + struct vfsub_aopen_args *args);
18736 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18737 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18738 + struct dentry *dentry);
18739 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18742 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18743 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18744 + struct dentry *h_parent, int isdir);
18745 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18746 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18749 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18750 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18751 + struct inode *dir, struct dentry *dentry,
18752 + unsigned int flags);
18755 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18756 +void au_hiput(struct au_hinode *hinode);
18757 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18758 + struct dentry *h_wh);
18759 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18761 +/* hinode flags */
18762 +#define AuHi_XINO 1
18763 +#define AuHi_HNOTIFY (1 << 1)
18764 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18765 +#define au_fset_hi(flags, name) \
18766 + do { (flags) |= AuHi_##name; } while (0)
18767 +#define au_fclr_hi(flags, name) \
18768 + do { (flags) &= ~AuHi_##name; } while (0)
18770 +#ifndef CONFIG_AUFS_HNOTIFY
18771 +#undef AuHi_HNOTIFY
18772 +#define AuHi_HNOTIFY 0
18775 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18776 + struct inode *h_inode, unsigned int flags);
18778 +void au_update_iigen(struct inode *inode, int half);
18779 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18781 +void au_icntnr_init_once(void *_c);
18782 +void au_hinode_init(struct au_hinode *hinode);
18783 +int au_iinfo_init(struct inode *inode);
18784 +void au_iinfo_fin(struct inode *inode);
18785 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18787 +#ifdef CONFIG_PROC_FS
18789 +int au_plink_maint(struct super_block *sb, int flags);
18791 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18792 +int au_plink_maint_enter(struct super_block *sb);
18793 +#ifdef CONFIG_AUFS_DEBUG
18794 +void au_plink_list(struct super_block *sb);
18796 +AuStubVoid(au_plink_list, struct super_block *sb)
18798 +int au_plink_test(struct inode *inode);
18799 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18800 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18801 + struct dentry *h_dentry);
18802 +void au_plink_put(struct super_block *sb, int verbose);
18803 +void au_plink_clean(struct super_block *sb, int verbose);
18804 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18806 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18807 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18808 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18809 +AuStubVoid(au_plink_list, struct super_block *sb);
18810 +AuStubInt0(au_plink_test, struct inode *inode);
18811 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18812 + struct inode *inode, aufs_bindex_t bindex);
18813 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18814 + struct dentry *h_dentry);
18815 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18816 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18817 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18818 +#endif /* CONFIG_PROC_FS */
18820 +#ifdef CONFIG_AUFS_XATTR
18822 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18823 + unsigned int verbose);
18824 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18825 +void au_xattr_init(struct super_block *sb);
18827 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18828 + int ignore_flags, unsigned int verbose);
18829 +AuStubVoid(au_xattr_init, struct super_block *sb);
18832 +#ifdef CONFIG_FS_POSIX_ACL
18833 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18834 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18837 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18843 +struct au_sxattr {
18847 + const char *name;
18848 + const void *value;
18853 + struct posix_acl *acl;
18858 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18859 + struct au_sxattr *arg);
18862 +/* ---------------------------------------------------------------------- */
18864 +/* lock subclass for iinfo */
18866 + AuLsc_II_CHILD, /* child first */
18867 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18868 + AuLsc_II_CHILD3, /* copyup dirs */
18869 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18870 + AuLsc_II_PARENT2,
18871 + AuLsc_II_PARENT3, /* copyup dirs */
18872 + AuLsc_II_NEW_CHILD
18876 + * ii_read_lock_child, ii_write_lock_child,
18877 + * ii_read_lock_child2, ii_write_lock_child2,
18878 + * ii_read_lock_child3, ii_write_lock_child3,
18879 + * ii_read_lock_parent, ii_write_lock_parent,
18880 + * ii_read_lock_parent2, ii_write_lock_parent2,
18881 + * ii_read_lock_parent3, ii_write_lock_parent3,
18882 + * ii_read_lock_new_child, ii_write_lock_new_child,
18884 +#define AuReadLockFunc(name, lsc) \
18885 +static inline void ii_read_lock_##name(struct inode *i) \
18887 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18890 +#define AuWriteLockFunc(name, lsc) \
18891 +static inline void ii_write_lock_##name(struct inode *i) \
18893 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18896 +#define AuRWLockFuncs(name, lsc) \
18897 + AuReadLockFunc(name, lsc) \
18898 + AuWriteLockFunc(name, lsc)
18900 +AuRWLockFuncs(child, CHILD);
18901 +AuRWLockFuncs(child2, CHILD2);
18902 +AuRWLockFuncs(child3, CHILD3);
18903 +AuRWLockFuncs(parent, PARENT);
18904 +AuRWLockFuncs(parent2, PARENT2);
18905 +AuRWLockFuncs(parent3, PARENT3);
18906 +AuRWLockFuncs(new_child, NEW_CHILD);
18908 +#undef AuReadLockFunc
18909 +#undef AuWriteLockFunc
18910 +#undef AuRWLockFuncs
18912 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18913 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18914 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18916 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18917 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18918 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18920 +/* ---------------------------------------------------------------------- */
18922 +static inline void au_icntnr_init(struct au_icntnr *c)
18924 +#ifdef CONFIG_AUFS_DEBUG
18925 + c->vfs_inode.i_mode = 0;
18929 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18931 + unsigned int gen;
18932 + struct au_iinfo *iinfo;
18933 + struct au_iigen *iigen;
18935 + iinfo = au_ii(inode);
18936 + iigen = &iinfo->ii_generation;
18937 + spin_lock(&iigen->ig_spin);
18939 + *igflags = iigen->ig_flags;
18940 + gen = iigen->ig_generation;
18941 + spin_unlock(&iigen->ig_spin);
18946 +/* tiny test for inode number */
18947 +/* tmpfs generation is too rough */
18948 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
18950 + struct au_iinfo *iinfo;
18952 + iinfo = au_ii(inode);
18953 + AuRwMustAnyLock(&iinfo->ii_rwsem);
18954 + return !(iinfo->ii_hsb1 == h_inode->i_sb
18955 + && iinfo->ii_higen == h_inode->i_generation);
18958 +static inline void au_iigen_dec(struct inode *inode)
18960 + struct au_iinfo *iinfo;
18961 + struct au_iigen *iigen;
18963 + iinfo = au_ii(inode);
18964 + iigen = &iinfo->ii_generation;
18965 + spin_lock(&iigen->ig_spin);
18966 + iigen->ig_generation--;
18967 + spin_unlock(&iigen->ig_spin);
18970 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
18975 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
18981 +/* ---------------------------------------------------------------------- */
18983 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
18984 + aufs_bindex_t bindex)
18986 + return iinfo->ii_hinode + bindex;
18989 +static inline int au_is_bad_inode(struct inode *inode)
18991 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
18994 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
18995 + aufs_bindex_t bindex)
18997 + IiMustAnyLock(inode);
18998 + return au_hinode(au_ii(inode), bindex)->hi_id;
19001 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19003 + IiMustAnyLock(inode);
19004 + return au_ii(inode)->ii_btop;
19007 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19009 + IiMustAnyLock(inode);
19010 + return au_ii(inode)->ii_bbot;
19013 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19015 + IiMustAnyLock(inode);
19016 + return au_ii(inode)->ii_vdir;
19019 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19021 + IiMustAnyLock(inode);
19022 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19025 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19027 + IiMustWriteLock(inode);
19028 + au_ii(inode)->ii_btop = bindex;
19031 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19033 + IiMustWriteLock(inode);
19034 + au_ii(inode)->ii_bbot = bindex;
19037 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19039 + IiMustWriteLock(inode);
19040 + au_ii(inode)->ii_vdir = vdir;
19043 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19045 + IiMustAnyLock(inode);
19046 + return au_hinode(au_ii(inode), bindex);
19049 +/* ---------------------------------------------------------------------- */
19051 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19054 + return pin->parent;
19058 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19060 + if (pin && pin->hdir)
19061 + return pin->hdir->hi_inode;
19065 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19068 + return pin->hdir;
19072 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19075 + pin->dentry = dentry;
19078 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19079 + unsigned char lflag)
19083 + au_fset_pin(pin->flags, DI_LOCKED);
19085 + au_fclr_pin(pin->flags, DI_LOCKED);
19089 +#if 0 /* reserved */
19090 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19093 + dput(pin->parent);
19094 + pin->parent = dget(parent);
19099 +/* ---------------------------------------------------------------------- */
19102 +#ifdef CONFIG_AUFS_HNOTIFY
19103 +struct au_hnotify_op {
19104 + void (*ctl)(struct au_hinode *hinode, int do_set);
19105 + int (*alloc)(struct au_hinode *hinode);
19108 + * if it returns true, the caller should free hinode->hi_notify,
19109 + * otherwise ->free() frees it.
19111 + int (*free)(struct au_hinode *hinode,
19112 + struct au_hnotify *hn) __must_check;
19114 + void (*fin)(void);
19115 + int (*init)(void);
19117 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19118 + void (*fin_br)(struct au_branch *br);
19119 + int (*init_br)(struct au_branch *br, int perm);
19123 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19124 +void au_hn_free(struct au_hinode *hinode);
19125 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19126 +void au_hn_reset(struct inode *inode, unsigned int flags);
19127 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19128 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19129 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19130 +int au_hnotify_init_br(struct au_branch *br, int perm);
19131 +void au_hnotify_fin_br(struct au_branch *br);
19132 +int __init au_hnotify_init(void);
19133 +void au_hnotify_fin(void);
19136 +extern const struct au_hnotify_op au_hnotify_op;
19139 +void au_hn_init(struct au_hinode *hinode)
19141 + hinode->hi_notify = NULL;
19144 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19146 + return hinode->hi_notify;
19150 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19151 + struct au_hinode *hinode __maybe_unused,
19152 + struct inode *inode __maybe_unused)
19153 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19154 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19155 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19156 + int do_set __maybe_unused)
19157 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19158 + unsigned int flags __maybe_unused)
19159 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19160 + struct au_branch *br __maybe_unused,
19161 + int perm __maybe_unused)
19162 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19163 + int perm __maybe_unused)
19164 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19165 +AuStubInt0(__init au_hnotify_init, void)
19166 +AuStubVoid(au_hnotify_fin, void)
19167 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19168 +#endif /* CONFIG_AUFS_HNOTIFY */
19170 +static inline void au_hn_suspend(struct au_hinode *hdir)
19172 + au_hn_ctl(hdir, /*do_set*/0);
19175 +static inline void au_hn_resume(struct au_hinode *hdir)
19177 + au_hn_ctl(hdir, /*do_set*/1);
19180 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19182 + inode_lock(hdir->hi_inode);
19183 + au_hn_suspend(hdir);
19186 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19187 + unsigned int sc __maybe_unused)
19189 + inode_lock_nested(hdir->hi_inode, sc);
19190 + au_hn_suspend(hdir);
19193 +#if 0 /* unused */
19194 +#include "vfsub.h"
19195 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19198 + inode_lock_shared_nested(hdir->hi_inode, sc);
19199 + au_hn_suspend(hdir);
19203 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19205 + au_hn_resume(hdir);
19206 + inode_unlock(hdir->hi_inode);
19209 +#endif /* __KERNEL__ */
19210 +#endif /* __AUFS_INODE_H__ */
19211 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19212 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19213 +++ linux/fs/aufs/ioctl.c 2021-12-03 15:38:59.936647310 +0100
19215 +// SPDX-License-Identifier: GPL-2.0
19217 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19219 + * This program, aufs is free software; you can redistribute it and/or modify
19220 + * it under the terms of the GNU General Public License as published by
19221 + * the Free Software Foundation; either version 2 of the License, or
19222 + * (at your option) any later version.
19224 + * This program is distributed in the hope that it will be useful,
19225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19227 + * GNU General Public License for more details.
19229 + * You should have received a copy of the GNU General Public License
19230 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19235 + * plink-management and readdir in userspace.
19236 + * assist the pathconf(3) wrapper library.
19238 + * File-based Hierarchical Storage Management.
19241 +#include <linux/compat.h>
19242 +#include <linux/file.h>
19245 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19248 + aufs_bindex_t wbi, bindex, bbot;
19249 + struct file *h_file;
19250 + struct super_block *sb;
19251 + struct dentry *root;
19252 + struct au_branch *br;
19253 + struct aufs_wbr_fd wbrfd = {
19254 + .oflags = au_dir_roflags,
19257 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19258 + | O_NOATIME | O_CLOEXEC;
19260 + AuDebugOn(wbrfd.oflags & ~valid);
19263 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19264 + if (unlikely(err)) {
19270 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19271 + wbrfd.oflags |= au_dir_roflags;
19272 + AuDbg("0%o\n", wbrfd.oflags);
19273 + if (unlikely(wbrfd.oflags & ~valid))
19277 + fd = get_unused_fd_flags(0);
19279 + if (unlikely(fd < 0))
19282 + h_file = ERR_PTR(-EINVAL);
19285 + sb = path->dentry->d_sb;
19286 + root = sb->s_root;
19287 + aufs_read_lock(root, AuLock_IR);
19288 + bbot = au_sbbot(sb);
19289 + if (wbrfd.brid >= 0) {
19290 + wbi = au_br_index(sb, wbrfd.brid);
19291 + if (unlikely(wbi < 0 || wbi > bbot))
19295 + h_file = ERR_PTR(-ENOENT);
19296 + br = au_sbr(sb, wbi);
19297 + if (!au_br_writable(br->br_perm)) {
19301 + bindex = wbi + 1;
19303 + for (; bindex <= bbot; bindex++) {
19304 + br = au_sbr(sb, bindex);
19305 + if (au_br_writable(br->br_perm)) {
19307 + br = au_sbr(sb, wbi);
19312 + AuDbg("wbi %d\n", wbi);
19314 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19318 + aufs_read_unlock(root, AuLock_IR);
19319 + err = PTR_ERR(h_file);
19320 + if (IS_ERR(h_file))
19323 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19324 + fd_install(fd, h_file);
19326 + goto out; /* success */
19329 + put_unused_fd(fd);
19335 +/* ---------------------------------------------------------------------- */
19337 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19340 + struct dentry *dentry;
19343 + case AUFS_CTL_RDU:
19344 + case AUFS_CTL_RDU_INO:
19345 + err = au_rdu_ioctl(file, cmd, arg);
19348 + case AUFS_CTL_WBR_FD:
19349 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19352 + case AUFS_CTL_IBUSY:
19353 + err = au_ibusy_ioctl(file, arg);
19356 + case AUFS_CTL_BRINFO:
19357 + err = au_brinfo_ioctl(file, arg);
19360 + case AUFS_CTL_FHSM_FD:
19361 + dentry = file->f_path.dentry;
19362 + if (IS_ROOT(dentry))
19363 + err = au_fhsm_fd(dentry->d_sb, arg);
19369 + /* do not call the lower */
19370 + AuDbg("0x%x\n", cmd);
19378 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19383 + case AUFS_CTL_MVDOWN:
19384 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19387 + case AUFS_CTL_WBR_FD:
19388 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19392 + /* do not call the lower */
19393 + AuDbg("0x%x\n", cmd);
19401 +#ifdef CONFIG_COMPAT
19402 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19403 + unsigned long arg)
19408 + case AUFS_CTL_RDU:
19409 + case AUFS_CTL_RDU_INO:
19410 + err = au_rdu_compat_ioctl(file, cmd, arg);
19413 + case AUFS_CTL_IBUSY:
19414 + err = au_ibusy_compat_ioctl(file, arg);
19417 + case AUFS_CTL_BRINFO:
19418 + err = au_brinfo_compat_ioctl(file, arg);
19422 + err = aufs_ioctl_dir(file, cmd, arg);
19429 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19430 + unsigned long arg)
19432 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19435 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19436 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19437 +++ linux/fs/aufs/i_op_add.c 2021-12-03 15:38:59.936647310 +0100
19439 +// SPDX-License-Identifier: GPL-2.0
19441 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19443 + * This program, aufs is free software; you can redistribute it and/or modify
19444 + * it under the terms of the GNU General Public License as published by
19445 + * the Free Software Foundation; either version 2 of the License, or
19446 + * (at your option) any later version.
19448 + * This program is distributed in the hope that it will be useful,
19449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19451 + * GNU General Public License for more details.
19453 + * You should have received a copy of the GNU General Public License
19454 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19458 + * inode operations (add entry)
19461 +#include <linux/iversion.h>
19465 + * final procedure of adding a new entry, except link(2).
19466 + * remove whiteout, instantiate, copyup the parent dir's times and size
19467 + * and update version.
19468 + * if it failed, re-create the removed whiteout.
19470 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19471 + struct dentry *wh_dentry, struct dentry *dentry)
19474 + aufs_bindex_t bwh;
19475 + struct path h_path;
19476 + struct super_block *sb;
19477 + struct inode *inode, *h_dir;
19478 + struct dentry *wh;
19483 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19484 + IMustLock(h_dir);
19485 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19486 + bwh = au_dbwh(dentry);
19487 + h_path.dentry = wh_dentry;
19488 + h_path.mnt = au_sbr_mnt(sb, bindex);
19489 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19491 + if (unlikely(err))
19495 + inode = au_new_inode(dentry, /*must_new*/1);
19496 + if (!IS_ERR(inode)) {
19497 + d_instantiate(dentry, inode);
19498 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19500 + au_dir_ts(dir, bindex);
19501 + inode_inc_iversion(dir);
19502 + au_fhsm_wrote(sb, bindex, /*force*/0);
19503 + return 0; /* success */
19506 + err = PTR_ERR(inode);
19511 + /* dir inode is locked */
19512 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19513 + rerr = PTR_ERR(wh);
19514 + if (IS_ERR(wh)) {
19515 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19516 + dentry, err, rerr);
19525 +static int au_d_may_add(struct dentry *dentry)
19530 + if (unlikely(d_unhashed(dentry)))
19532 + if (unlikely(d_really_is_positive(dentry)))
19538 + * simple tests for the adding inode operations.
19539 + * following the checks in vfs, plus the parent-child relationship.
19541 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19542 + struct dentry *h_parent, int isdir)
19546 + struct dentry *h_dentry;
19547 + struct inode *h_inode;
19549 + err = -ENAMETOOLONG;
19550 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19553 + h_dentry = au_h_dptr(dentry, bindex);
19554 + if (d_really_is_negative(dentry)) {
19556 + if (unlikely(d_is_positive(h_dentry)))
19559 + /* rename(2) case */
19561 + if (unlikely(d_is_negative(h_dentry)))
19563 + h_inode = d_inode(h_dentry);
19564 + if (unlikely(!h_inode->i_nlink))
19567 + h_mode = h_inode->i_mode;
19570 + if (unlikely(S_ISDIR(h_mode)))
19572 + } else if (unlikely(!S_ISDIR(h_mode))) {
19579 + /* expected parent dir is locked */
19580 + if (unlikely(h_parent != h_dentry->d_parent))
19589 + * initial procedure of adding a new entry.
19590 + * prepare writable branch and the parent dir, lock it,
19591 + * and lookup whiteout for the new entry.
19593 +static struct dentry*
19594 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19595 + struct dentry *src_dentry, struct au_pin *pin,
19596 + struct au_wr_dir_args *wr_dir_args)
19598 + struct dentry *wh_dentry, *h_parent;
19599 + struct super_block *sb;
19600 + struct au_branch *br;
19602 + unsigned int udba;
19603 + aufs_bindex_t bcpup;
19605 + AuDbg("%pd\n", dentry);
19607 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19609 + wh_dentry = ERR_PTR(err);
19610 + if (unlikely(err < 0))
19613 + sb = dentry->d_sb;
19614 + udba = au_opt_udba(sb);
19615 + err = au_pin(pin, dentry, bcpup, udba,
19616 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19617 + wh_dentry = ERR_PTR(err);
19618 + if (unlikely(err))
19621 + h_parent = au_pinned_h_parent(pin);
19622 + if (udba != AuOpt_UDBA_NONE
19623 + && au_dbtop(dentry) == bcpup)
19624 + err = au_may_add(dentry, bcpup, h_parent,
19625 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19626 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19627 + err = -ENAMETOOLONG;
19628 + wh_dentry = ERR_PTR(err);
19629 + if (unlikely(err))
19632 + br = au_sbr(sb, bcpup);
19634 + struct path tmp = {
19635 + .dentry = h_parent,
19636 + .mnt = au_br_mnt(br)
19638 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19641 + wh_dentry = NULL;
19642 + if (bcpup != au_dbwh(dentry))
19643 + goto out; /* success */
19646 + * ENAMETOOLONG here means that if we allowed create such name, then it
19647 + * would not be able to removed in the future. So we don't allow such
19648 + * name here and we don't handle ENAMETOOLONG differently here.
19650 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19653 + if (IS_ERR(wh_dentry))
19656 + return wh_dentry;
19659 +/* ---------------------------------------------------------------------- */
19661 +enum { Mknod, Symlink, Creat };
19662 +struct simple_arg {
19669 + struct vfsub_aopen_args *aopen;
19672 + const char *symname;
19681 +static int add_simple(struct inode *dir, struct dentry *dentry,
19682 + struct simple_arg *arg)
19685 + aufs_bindex_t btop;
19686 + unsigned char created;
19687 + const unsigned char try_aopen
19688 + = (arg->type == Creat && arg->u.c.try_aopen);
19689 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19690 + struct dentry *wh_dentry, *parent;
19691 + struct inode *h_dir;
19692 + struct super_block *sb;
19693 + struct au_branch *br;
19694 + /* to reduce stack size */
19696 + struct au_dtime dt;
19697 + struct au_pin pin;
19698 + struct path h_path;
19699 + struct au_wr_dir_args wr_dir_args;
19702 + AuDbg("%pd\n", dentry);
19706 + a = kmalloc(sizeof(*a), GFP_NOFS);
19707 + if (unlikely(!a))
19709 + a->wr_dir_args.force_btgt = -1;
19710 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19712 + parent = dentry->d_parent; /* dir inode is locked */
19713 + if (!try_aopen) {
19714 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19715 + if (unlikely(err))
19718 + err = au_d_may_add(dentry);
19719 + if (unlikely(err))
19722 + di_write_lock_parent(parent);
19723 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19724 + &a->pin, &a->wr_dir_args);
19725 + err = PTR_ERR(wh_dentry);
19726 + if (IS_ERR(wh_dentry))
19729 + btop = au_dbtop(dentry);
19730 + sb = dentry->d_sb;
19731 + br = au_sbr(sb, btop);
19732 + a->h_path.dentry = au_h_dptr(dentry, btop);
19733 + a->h_path.mnt = au_br_mnt(br);
19734 + h_dir = au_pinned_h_dir(&a->pin);
19735 + switch (arg->type) {
19737 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19738 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19739 + arg->u.c.want_excl);
19741 + if (!err && try_aopen)
19742 + aopen->file->f_mode |= FMODE_CREATED;
19745 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19746 + AuDbg("err %d\n", err);
19747 + AuDbgFile(aopen->file);
19748 + created = err >= 0
19749 + && !!(aopen->file->f_mode & FMODE_CREATED);
19753 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19757 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19764 + if (unlikely(err < 0))
19767 + err = epilog(dir, btop, wh_dentry, dentry);
19769 + goto out_unpin; /* success */
19772 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19773 + /* no delegation since it is just created */
19774 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19777 + AuIOErr("%pd revert failure(%d, %d)\n",
19778 + dentry, err, rerr);
19781 + au_dtime_revert(&a->dt);
19783 + if (try_aopen && h_dir->i_op->atomic_open
19784 + && (aopen->file->f_mode & FMODE_OPENED))
19785 + /* aopen->file is still opened */
19786 + au_lcnt_dec(&aopen->br->br_nfiles);
19789 + au_unpin(&a->pin);
19793 + di_write_unlock(parent);
19795 + if (unlikely(err)) {
19796 + au_update_dbtop(dentry);
19800 + aufs_read_unlock(dentry, AuLock_DW);
19807 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19810 + struct simple_arg arg = {
19817 + return add_simple(dir, dentry, &arg);
19820 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19822 + struct simple_arg arg = {
19824 + .u.s.symname = symname
19826 + return add_simple(dir, dentry, &arg);
19829 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19832 + struct simple_arg arg = {
19836 + .want_excl = want_excl
19839 + return add_simple(dir, dentry, &arg);
19842 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19843 + struct vfsub_aopen_args *aopen_args)
19845 + struct simple_arg arg = {
19848 + .mode = aopen_args->create_mode,
19849 + .want_excl = aopen_args->open_flag & O_EXCL,
19850 + .try_aopen = true,
19851 + .aopen = aopen_args
19854 + return add_simple(dir, dentry, &arg);
19857 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19860 + aufs_bindex_t bindex;
19861 + struct super_block *sb;
19862 + struct dentry *parent, *h_parent, *h_dentry;
19863 + struct inode *h_dir, *inode;
19864 + struct vfsmount *h_mnt;
19865 + struct au_wr_dir_args wr_dir_args = {
19866 + .force_btgt = -1,
19867 + .flags = AuWrDir_TMPFILE
19870 + /* copy-up may happen */
19874 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19875 + if (unlikely(err))
19878 + err = au_di_init(dentry);
19879 + if (unlikely(err))
19883 + parent = d_find_any_alias(dir);
19884 + AuDebugOn(!parent);
19885 + di_write_lock_parent(parent);
19886 + if (unlikely(d_inode(parent) != dir))
19889 + err = au_digen_test(parent, au_sigen(sb));
19890 + if (unlikely(err))
19893 + bindex = au_dbtop(parent);
19894 + au_set_dbtop(dentry, bindex);
19895 + au_set_dbbot(dentry, bindex);
19896 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19898 + if (unlikely(err < 0))
19901 + err = -EOPNOTSUPP;
19902 + h_dir = au_h_iptr(dir, bindex);
19903 + if (unlikely(!h_dir->i_op->tmpfile))
19906 + h_mnt = au_sbr_mnt(sb, bindex);
19907 + err = vfsub_mnt_want_write(h_mnt);
19908 + if (unlikely(err))
19911 + h_parent = au_h_dptr(parent, bindex);
19912 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
19913 + if (IS_ERR(h_dentry)) {
19914 + err = PTR_ERR(h_dentry);
19918 + au_set_dbtop(dentry, bindex);
19919 + au_set_dbbot(dentry, bindex);
19920 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19921 + inode = au_new_inode(dentry, /*must_new*/1);
19922 + if (IS_ERR(inode)) {
19923 + err = PTR_ERR(inode);
19924 + au_set_h_dptr(dentry, bindex, NULL);
19925 + au_set_dbtop(dentry, -1);
19926 + au_set_dbbot(dentry, -1);
19928 + if (!inode->i_nlink)
19929 + set_nlink(inode, 1);
19930 + d_tmpfile(dentry, inode);
19931 + au_di(dentry)->di_tmpfile = 1;
19933 + /* update without i_mutex */
19934 + if (au_ibtop(dir) == au_dbtop(dentry))
19935 + au_cpup_attr_timesizes(dir);
19940 + vfsub_mnt_drop_write(h_mnt);
19942 + di_write_unlock(parent);
19944 + di_write_unlock(dentry);
19945 + if (unlikely(err)) {
19946 + au_di_fin(dentry);
19947 + dentry->d_fsdata = NULL;
19950 + si_read_unlock(sb);
19952 + inode_unlock(dir);
19956 +/* ---------------------------------------------------------------------- */
19958 +struct au_link_args {
19959 + aufs_bindex_t bdst, bsrc;
19960 + struct au_pin pin;
19961 + struct path h_path;
19962 + struct dentry *src_parent, *parent;
19965 +static int au_cpup_before_link(struct dentry *src_dentry,
19966 + struct au_link_args *a)
19969 + struct dentry *h_src_dentry;
19970 + struct au_cp_generic cpg = {
19971 + .dentry = src_dentry,
19976 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
19979 + di_read_lock_parent(a->src_parent, AuLock_IR);
19980 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
19981 + if (unlikely(err))
19984 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
19985 + err = au_pin(&a->pin, src_dentry, a->bdst,
19986 + au_opt_udba(src_dentry->d_sb),
19987 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19988 + if (unlikely(err))
19991 + err = au_sio_cpup_simple(&cpg);
19992 + au_unpin(&a->pin);
19995 + di_read_unlock(a->src_parent, AuLock_IR);
19999 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20000 + struct au_link_args *a)
20003 + unsigned char plink;
20004 + aufs_bindex_t bbot;
20005 + struct dentry *h_src_dentry;
20006 + struct inode *h_inode, *inode, *delegated;
20007 + struct super_block *sb;
20008 + struct file *h_file;
20012 + sb = src_dentry->d_sb;
20013 + inode = d_inode(src_dentry);
20014 + if (au_ibtop(inode) <= a->bdst)
20015 + h_inode = au_h_iptr(inode, a->bdst);
20016 + if (!h_inode || !h_inode->i_nlink) {
20017 + /* copyup src_dentry as the name of dentry. */
20018 + bbot = au_dbbot(dentry);
20019 + if (bbot < a->bsrc)
20020 + au_set_dbbot(dentry, a->bsrc);
20021 + au_set_h_dptr(dentry, a->bsrc,
20022 + dget(au_h_dptr(src_dentry, a->bsrc)));
20023 + dget(a->h_path.dentry);
20024 + au_set_h_dptr(dentry, a->bdst, NULL);
20025 + AuDbg("temporary d_inode...\n");
20026 + spin_lock(&dentry->d_lock);
20027 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20028 + spin_unlock(&dentry->d_lock);
20029 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20030 + if (IS_ERR(h_file))
20031 + err = PTR_ERR(h_file);
20033 + struct au_cp_generic cpg = {
20034 + .dentry = dentry,
20039 + .flags = AuCpup_KEEPLINO
20041 + err = au_sio_cpup_simple(&cpg);
20042 + au_h_open_post(dentry, a->bsrc, h_file);
20044 + dput(a->h_path.dentry);
20045 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20047 + au_set_h_dptr(dentry, a->bdst,
20048 + a->h_path.dentry);
20050 + spin_lock(&dentry->d_lock);
20051 + dentry->d_inode = NULL; /* restore */
20052 + spin_unlock(&dentry->d_lock);
20053 + AuDbg("temporary d_inode...done\n");
20054 + au_set_h_dptr(dentry, a->bsrc, NULL);
20055 + au_set_dbbot(dentry, bbot);
20057 + /* the inode of src_dentry already exists on a.bdst branch */
20058 + h_src_dentry = d_find_alias(h_inode);
20059 + if (!h_src_dentry && au_plink_test(inode)) {
20061 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20062 + err = PTR_ERR(h_src_dentry);
20063 + if (IS_ERR(h_src_dentry))
20066 + if (unlikely(d_is_negative(h_src_dentry))) {
20067 + dput(h_src_dentry);
20068 + h_src_dentry = NULL;
20072 + if (h_src_dentry) {
20073 + delegated = NULL;
20074 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20075 + &a->h_path, &delegated);
20076 + if (unlikely(err == -EWOULDBLOCK)) {
20077 + pr_warn("cannot retry for NFSv4 delegation"
20078 + " for an internal link\n");
20081 + dput(h_src_dentry);
20083 + AuIOErr("no dentry found for hi%lu on b%d\n",
20084 + h_inode->i_ino, a->bdst);
20089 + if (!err && !plink)
20090 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20097 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20098 + struct dentry *dentry)
20101 + struct au_dtime dt;
20102 + struct au_link_args *a;
20103 + struct dentry *wh_dentry, *h_src_dentry;
20104 + struct inode *inode, *delegated;
20105 + struct super_block *sb;
20106 + struct au_wr_dir_args wr_dir_args = {
20107 + /* .force_btgt = -1, */
20108 + .flags = AuWrDir_ADD_ENTRY
20112 + inode = d_inode(src_dentry);
20113 + IMustLock(inode);
20116 + a = kzalloc(sizeof(*a), GFP_NOFS);
20117 + if (unlikely(!a))
20120 + a->parent = dentry->d_parent; /* dir inode is locked */
20121 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20122 + AuLock_NOPLM | AuLock_GEN);
20123 + if (unlikely(err))
20125 + err = au_d_linkable(src_dentry);
20126 + if (unlikely(err))
20128 + err = au_d_may_add(dentry);
20129 + if (unlikely(err))
20132 + a->src_parent = dget_parent(src_dentry);
20133 + wr_dir_args.force_btgt = au_ibtop(inode);
20135 + di_write_lock_parent(a->parent);
20136 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20137 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20139 + err = PTR_ERR(wh_dentry);
20140 + if (IS_ERR(wh_dentry))
20144 + sb = dentry->d_sb;
20145 + a->bdst = au_dbtop(dentry);
20146 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20147 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20148 + a->bsrc = au_ibtop(inode);
20149 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20150 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20151 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20152 + if (!h_src_dentry) {
20153 + a->bsrc = au_dbtop(src_dentry);
20154 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20155 + AuDebugOn(!h_src_dentry);
20156 + } else if (IS_ERR(h_src_dentry)) {
20157 + err = PTR_ERR(h_src_dentry);
20162 + * aufs doesn't touch the credential so
20163 + * security_dentry_create_files_as() is unnecessary.
20165 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20166 + if (a->bdst < a->bsrc
20167 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20168 + err = au_cpup_or_link(src_dentry, dentry, a);
20170 + delegated = NULL;
20171 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20172 + &a->h_path, &delegated);
20173 + if (unlikely(err == -EWOULDBLOCK)) {
20174 + pr_warn("cannot retry for NFSv4 delegation"
20175 + " for an internal link\n");
20179 + dput(h_src_dentry);
20182 + * copyup src_dentry to the branch we process,
20183 + * and then link(2) to it.
20185 + dput(h_src_dentry);
20186 + if (a->bdst < a->bsrc
20187 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20188 + au_unpin(&a->pin);
20189 + di_write_unlock(a->parent);
20190 + err = au_cpup_before_link(src_dentry, a);
20191 + di_write_lock_parent(a->parent);
20193 + err = au_pin(&a->pin, dentry, a->bdst,
20195 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20196 + if (unlikely(err))
20200 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20202 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20203 + delegated = NULL;
20204 + err = vfsub_link(h_src_dentry,
20205 + au_pinned_h_dir(&a->pin),
20206 + &a->h_path, &delegated);
20207 + if (unlikely(err == -EWOULDBLOCK)) {
20208 + pr_warn("cannot retry"
20209 + " for NFSv4 delegation"
20210 + " for an internal link\n");
20216 + if (unlikely(err))
20220 + a->h_path.dentry = wh_dentry;
20221 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20223 + if (unlikely(err))
20227 + au_dir_ts(dir, a->bdst);
20228 + inode_inc_iversion(dir);
20229 + inc_nlink(inode);
20230 + inode->i_ctime = dir->i_ctime;
20231 + d_instantiate(dentry, au_igrab(inode));
20232 + if (d_unhashed(a->h_path.dentry))
20233 + /* some filesystem calls d_drop() */
20235 + /* some filesystems consume an inode even hardlink */
20236 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20237 + goto out_unpin; /* success */
20240 + /* no delegation since it is just created */
20241 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20242 + /*delegated*/NULL, /*force*/0);
20243 + if (unlikely(rerr)) {
20244 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20247 + au_dtime_revert(&dt);
20249 + au_unpin(&a->pin);
20253 + di_write_unlock(a->parent);
20254 + dput(a->src_parent);
20256 + if (unlikely(err)) {
20257 + au_update_dbtop(dentry);
20260 + aufs_read_and_write_unlock2(dentry, src_dentry);
20268 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20271 + aufs_bindex_t bindex;
20272 + unsigned char diropq;
20273 + struct path h_path;
20274 + struct dentry *wh_dentry, *parent, *opq_dentry;
20275 + struct inode *h_inode;
20276 + struct super_block *sb;
20278 + struct au_pin pin;
20279 + struct au_dtime dt;
20280 + } *a; /* reduce the stack usage */
20281 + struct au_wr_dir_args wr_dir_args = {
20282 + .force_btgt = -1,
20283 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20289 + a = kmalloc(sizeof(*a), GFP_NOFS);
20290 + if (unlikely(!a))
20293 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20294 + if (unlikely(err))
20296 + err = au_d_may_add(dentry);
20297 + if (unlikely(err))
20300 + parent = dentry->d_parent; /* dir inode is locked */
20301 + di_write_lock_parent(parent);
20302 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20303 + &a->pin, &wr_dir_args);
20304 + err = PTR_ERR(wh_dentry);
20305 + if (IS_ERR(wh_dentry))
20308 + sb = dentry->d_sb;
20309 + bindex = au_dbtop(dentry);
20310 + h_path.dentry = au_h_dptr(dentry, bindex);
20311 + h_path.mnt = au_sbr_mnt(sb, bindex);
20312 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20313 + if (unlikely(err))
20316 + /* make the dir opaque */
20318 + h_inode = d_inode(h_path.dentry);
20320 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20321 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20322 + opq_dentry = au_diropq_create(dentry, bindex);
20323 + inode_unlock(h_inode);
20324 + err = PTR_ERR(opq_dentry);
20325 + if (IS_ERR(opq_dentry))
20327 + dput(opq_dentry);
20331 + err = epilog(dir, bindex, wh_dentry, dentry);
20334 + goto out_unpin; /* success */
20339 + AuLabel(revert opq);
20340 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20341 + rerr = au_diropq_remove(dentry, bindex);
20342 + inode_unlock(h_inode);
20344 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20345 + dentry, err, rerr);
20351 + AuLabel(revert dir);
20352 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20354 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20355 + dentry, err, rerr);
20358 + au_dtime_revert(&a->dt);
20360 + au_unpin(&a->pin);
20363 + di_write_unlock(parent);
20365 + if (unlikely(err)) {
20366 + au_update_dbtop(dentry);
20369 + aufs_read_unlock(dentry, AuLock_DW);
20375 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20376 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20377 +++ linux/fs/aufs/i_op.c 2021-12-03 15:38:59.936647310 +0100
20379 +// SPDX-License-Identifier: GPL-2.0
20381 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20383 + * This program, aufs is free software; you can redistribute it and/or modify
20384 + * it under the terms of the GNU General Public License as published by
20385 + * the Free Software Foundation; either version 2 of the License, or
20386 + * (at your option) any later version.
20388 + * This program is distributed in the hope that it will be useful,
20389 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20390 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20391 + * GNU General Public License for more details.
20393 + * You should have received a copy of the GNU General Public License
20394 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20398 + * inode operations (except add/del/rename)
20401 +#include <linux/device_cgroup.h>
20402 +#include <linux/fs_stack.h>
20403 +#include <linux/iversion.h>
20404 +#include <linux/namei.h>
20405 +#include <linux/security.h>
20408 +static int h_permission(struct inode *h_inode, int mask,
20409 + struct path *h_path, int brperm)
20412 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20415 + if (write_mask && IS_IMMUTABLE(h_inode))
20419 + if (((mask & MAY_EXEC)
20420 + && S_ISREG(h_inode->i_mode)
20421 + && (path_noexec(h_path)
20422 + || !(h_inode->i_mode & 0111))))
20426 + * - skip the lower fs test in the case of write to ro branch.
20427 + * - nfs dir permission write check is optimized, but a policy for
20428 + * link/rename requires a real check.
20429 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20430 + * in this case, generic_permission() returns -EOPNOTSUPP.
20432 + if ((write_mask && !au_br_writable(brperm))
20433 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20434 + && write_mask && !(mask & MAY_READ))
20435 + || !h_inode->i_op->permission) {
20436 + /* AuLabel(generic_permission); */
20437 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20438 + err = generic_permission(h_inode, mask);
20439 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20440 + err = h_inode->i_op->permission(h_inode, mask);
20443 + /* AuLabel(h_inode->permission); */
20444 + err = h_inode->i_op->permission(h_inode, mask);
20449 + err = devcgroup_inode_permission(h_inode, mask);
20451 + err = security_inode_permission(h_inode, mask);
20457 +static int aufs_permission(struct inode *inode, int mask)
20460 + aufs_bindex_t bindex, bbot;
20461 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20462 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20463 + struct inode *h_inode;
20464 + struct super_block *sb;
20465 + struct au_branch *br;
20467 + /* todo: support rcu-walk? */
20468 + if (mask & MAY_NOT_BLOCK)
20471 + sb = inode->i_sb;
20472 + si_read_lock(sb, AuLock_FLUSH);
20473 + ii_read_lock_child(inode);
20474 +#if 0 /* reserved for future use */
20476 + * This test may be rather 'too much' since the test is essentially done
20477 + * in the aufs_lookup(). Theoretically it is possible that the inode
20478 + * generation doesn't match to the superblock's here. But it isn't a
20479 + * big deal I suppose.
20481 + err = au_iigen_test(inode, au_sigen(sb));
20482 + if (unlikely(err))
20488 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20489 + err = au_busy_or_stale();
20490 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20491 + if (unlikely(!h_inode
20492 + || (h_inode->i_mode & S_IFMT)
20493 + != (inode->i_mode & S_IFMT)))
20497 + bindex = au_ibtop(inode);
20498 + br = au_sbr(sb, bindex);
20499 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20502 + && !special_file(h_inode->i_mode)) {
20503 + /* test whether the upper writable branch exists */
20505 + for (; bindex >= 0; bindex--)
20506 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20514 + /* non-write to dir */
20516 + bbot = au_ibbot(inode);
20517 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20518 + h_inode = au_h_iptr(inode, bindex);
20520 + err = au_busy_or_stale();
20521 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20524 + br = au_sbr(sb, bindex);
20525 + err = h_permission(h_inode, mask, &br->br_path,
20531 + ii_read_unlock(inode);
20532 + si_read_unlock(sb);
20536 +/* ---------------------------------------------------------------------- */
20538 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20539 + unsigned int flags)
20541 + struct dentry *ret, *parent;
20542 + struct inode *inode;
20543 + struct super_block *sb;
20544 + int err, npositive;
20548 + /* todo: support rcu-walk? */
20549 + ret = ERR_PTR(-ECHILD);
20550 + if (flags & LOOKUP_RCU)
20553 + ret = ERR_PTR(-ENAMETOOLONG);
20554 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20558 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20559 + ret = ERR_PTR(err);
20560 + if (unlikely(err))
20563 + err = au_di_init(dentry);
20564 + ret = ERR_PTR(err);
20565 + if (unlikely(err))
20569 + npositive = 0; /* suppress a warning */
20570 + parent = dentry->d_parent; /* dir inode is locked */
20571 + di_read_lock_parent(parent, AuLock_IR);
20572 + err = au_alive_dir(parent);
20574 + err = au_digen_test(parent, au_sigen(sb));
20576 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20577 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20578 + AuLkup_ALLOW_NEG);
20581 + di_read_unlock(parent, AuLock_IR);
20582 + ret = ERR_PTR(err);
20583 + if (unlikely(err < 0))
20587 + inode = au_new_inode(dentry, /*must_new*/0);
20588 + if (IS_ERR(inode)) {
20589 + ret = (void *)inode;
20596 + atomic_inc(&inode->i_count);
20597 + ret = d_splice_alias(inode, dentry);
20598 +#if 0 /* reserved for future use */
20599 + if (unlikely(d_need_lookup(dentry))) {
20600 + spin_lock(&dentry->d_lock);
20601 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20602 + spin_unlock(&dentry->d_lock);
20606 + if (!IS_ERR(ret)) {
20608 + if (ret && ret != dentry)
20609 + ii_write_unlock(inode);
20611 + ii_write_unlock(inode);
20618 + di_write_unlock(dentry);
20620 + si_read_unlock(sb);
20625 +/* ---------------------------------------------------------------------- */
20628 + * very dirty and complicated aufs ->atomic_open().
20629 + * aufs_atomic_open()
20630 + * + au_aopen_or_create()
20632 + * + vfsub_atomic_open()
20633 + * + branch fs ->atomic_open()
20634 + * may call the actual 'open' for h_file
20635 + * + inc br_nfiles only if opened
20636 + * + au_aopen_no_open() or au_aopen_do_open()
20638 + * au_aopen_do_open()
20639 + * + finish_open()
20640 + * + au_do_aopen()
20641 + * + au_do_open() the body of all 'open'
20642 + * + au_do_open_nondir()
20643 + * set the passed h_file
20645 + * au_aopen_no_open()
20646 + * + finish_no_open()
20649 +struct aopen_node {
20650 + struct hlist_bl_node hblist;
20651 + struct file *file, *h_file;
20654 +static int au_do_aopen(struct inode *inode, struct file *file)
20656 + struct hlist_bl_head *aopen;
20657 + struct hlist_bl_node *pos;
20658 + struct aopen_node *node;
20659 + struct au_do_open_args args = {
20661 + .open = au_do_open_nondir
20664 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20665 + hlist_bl_lock(aopen);
20666 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20667 + if (node->file == file) {
20668 + args.h_file = node->h_file;
20671 + hlist_bl_unlock(aopen);
20672 + /* AuDebugOn(!args.h_file); */
20674 + return au_do_open(file, &args);
20677 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20678 + struct aopen_node *aopen_node)
20681 + struct hlist_bl_head *aopen;
20684 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20685 + au_hbl_add(&aopen_node->hblist, aopen);
20686 + err = finish_open(file, dentry, au_do_aopen);
20687 + au_hbl_del(&aopen_node->hblist, aopen);
20688 + /* AuDbgFile(file); */
20689 + AuDbg("%pd%s%s\n", dentry,
20690 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20691 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20697 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20703 + err = finish_no_open(file, dentry);
20709 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20710 + struct file *file, unsigned int open_flag,
20711 + umode_t create_mode)
20713 + int err, did_open;
20714 + unsigned int lkup_flags;
20715 + aufs_bindex_t bindex;
20716 + struct super_block *sb;
20717 + struct dentry *parent, *d;
20718 + struct vfsub_aopen_args args = {
20719 + .open_flag = open_flag,
20720 + .create_mode = create_mode
20722 + struct aopen_node aopen_node = {
20727 + AuDbg("open_flag 0%o\n", open_flag);
20728 + AuDbgDentry(dentry);
20731 + if (!au_di(dentry)) {
20732 + lkup_flags = LOOKUP_OPEN;
20733 + if (open_flag & O_CREAT)
20734 + lkup_flags |= LOOKUP_CREATE;
20735 + d = aufs_lookup(dir, dentry, lkup_flags);
20737 + err = PTR_ERR(d);
20742 + * obsoleted dentry found.
20743 + * another error will be returned later.
20749 + AuDbgDentry(dentry);
20752 + if (d_is_positive(dentry)
20753 + || d_unhashed(dentry)
20754 + || d_unlinked(dentry)
20755 + || !(open_flag & O_CREAT)) {
20756 + err = au_aopen_no_open(file, dentry);
20757 + goto out; /* success */
20760 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20761 + if (unlikely(err))
20764 + sb = dentry->d_sb;
20765 + parent = dentry->d_parent; /* dir is locked */
20766 + di_write_lock_parent(parent);
20767 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20768 + if (unlikely(err < 0))
20771 + AuDbgDentry(dentry);
20772 + if (d_is_positive(dentry)) {
20773 + err = au_aopen_no_open(file, dentry);
20774 + goto out_parent; /* success */
20777 + args.file = alloc_empty_file(file->f_flags, current_cred());
20778 + err = PTR_ERR(args.file);
20779 + if (IS_ERR(args.file))
20782 + bindex = au_dbtop(dentry);
20783 + err = au_aopen_or_create(dir, dentry, &args);
20785 + AuDbgFile(args.file);
20786 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20787 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20790 + args.file = NULL;
20792 + di_write_unlock(parent);
20793 + di_write_unlock(dentry);
20794 + if (unlikely(err < 0)) {
20801 + err = au_aopen_no_open(file, dentry);
20803 + aopen_node.h_file = args.file;
20804 + err = au_aopen_do_open(file, dentry, &aopen_node);
20806 + if (unlikely(err < 0)) {
20810 + au_lcnt_dec(&args.br->br_nfiles);
20812 + goto out_sb; /* success */
20815 + di_write_unlock(parent);
20816 + di_write_unlock(dentry);
20818 + si_read_unlock(sb);
20826 +/* ---------------------------------------------------------------------- */
20828 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20829 + const unsigned char add_entry, aufs_bindex_t bcpup,
20830 + aufs_bindex_t btop)
20833 + struct dentry *h_parent;
20834 + struct inode *h_dir;
20837 + IMustLock(d_inode(parent));
20839 + di_write_lock_parent(parent);
20842 + if (!au_h_dptr(parent, bcpup)) {
20843 + if (btop > bcpup)
20844 + err = au_cpup_dirs(dentry, bcpup);
20845 + else if (btop < bcpup)
20846 + err = au_cpdown_dirs(dentry, bcpup);
20850 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20851 + h_parent = au_h_dptr(parent, bcpup);
20852 + h_dir = d_inode(h_parent);
20853 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20854 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20855 + /* todo: no unlock here */
20856 + inode_unlock_shared(h_dir);
20858 + AuDbg("bcpup %d\n", bcpup);
20860 + if (d_really_is_negative(dentry))
20861 + au_set_h_dptr(dentry, btop, NULL);
20862 + au_update_dbrange(dentry, /*do_put_zero*/0);
20867 + di_write_unlock(parent);
20869 + err = bcpup; /* success */
20876 + * decide the branch and the parent dir where we will create a new entry.
20877 + * returns new bindex or an error.
20878 + * copyup the parent dir if needed.
20880 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20881 + struct au_wr_dir_args *args)
20884 + unsigned int flags;
20885 + aufs_bindex_t bcpup, btop, src_btop;
20886 + const unsigned char add_entry
20887 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20888 + | au_ftest_wrdir(args->flags, TMPFILE);
20889 + struct super_block *sb;
20890 + struct dentry *parent;
20891 + struct au_sbinfo *sbinfo;
20893 + sb = dentry->d_sb;
20894 + sbinfo = au_sbi(sb);
20895 + parent = dget_parent(dentry);
20896 + btop = au_dbtop(dentry);
20898 + if (args->force_btgt < 0) {
20899 + if (src_dentry) {
20900 + src_btop = au_dbtop(src_dentry);
20901 + if (src_btop < btop)
20902 + bcpup = src_btop;
20903 + } else if (add_entry) {
20905 + if (au_ftest_wrdir(args->flags, ISDIR))
20906 + au_fset_wbr(flags, DIR);
20907 + err = AuWbrCreate(sbinfo, dentry, flags);
20911 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20913 + err = AuWbrCopyup(sbinfo, dentry);
20915 + if (!IS_ROOT(dentry)) {
20916 + di_read_lock_parent(parent, !AuLock_IR);
20917 + err = AuWbrCopyup(sbinfo, dentry);
20918 + di_read_unlock(parent, !AuLock_IR);
20920 + err = AuWbrCopyup(sbinfo, dentry);
20923 + if (unlikely(err < 0))
20927 + bcpup = args->force_btgt;
20928 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20931 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20933 + if (bcpup == btop)
20934 + goto out; /* success */
20936 + /* copyup the new parent into the branch we process */
20937 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20939 + if (d_really_is_negative(dentry)) {
20940 + au_set_h_dptr(dentry, btop, NULL);
20941 + au_set_dbtop(dentry, bcpup);
20942 + au_set_dbbot(dentry, bcpup);
20944 + AuDebugOn(add_entry
20945 + && !au_ftest_wrdir(args->flags, TMPFILE)
20946 + && !au_h_dptr(dentry, bcpup));
20954 +/* ---------------------------------------------------------------------- */
20956 +void au_pin_hdir_unlock(struct au_pin *p)
20959 + au_hn_inode_unlock(p->hdir);
20962 +int au_pin_hdir_lock(struct au_pin *p)
20970 + /* even if an error happens later, keep this lock */
20971 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
20974 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
20979 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
20980 + p->h_parent, p->br);
20986 +int au_pin_hdir_relock(struct au_pin *p)
20989 + struct inode *h_i;
20990 + struct dentry *h_d[] = {
20995 + err = au_pin_hdir_lock(p);
20996 + if (unlikely(err))
20999 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21002 + if (d_is_positive(h_d[i])) {
21003 + h_i = d_inode(h_d[i]);
21004 + err = !h_i->i_nlink;
21012 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21014 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21017 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21020 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21021 + p->lsc_hi, 0, NULL, _RET_IP_);
21022 + au_pin_hdir_set_owner(p, current);
21026 +void au_pin_hdir_release(struct au_pin *p)
21029 + au_pin_hdir_set_owner(p, p->task);
21030 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21034 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21036 + if (pin && pin->parent)
21037 + return au_h_dptr(pin->parent, pin->bindex);
21041 +void au_unpin(struct au_pin *p)
21044 + au_pin_hdir_unlock(p);
21045 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21046 + vfsub_mnt_drop_write(p->h_mnt);
21050 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21051 + di_read_unlock(p->parent, AuLock_IR);
21052 + iput(p->hdir->hi_inode);
21054 + p->parent = NULL;
21057 + /* do not clear p->task */
21060 +int au_do_pin(struct au_pin *p)
21063 + struct super_block *sb;
21064 + struct inode *h_dir;
21067 + sb = p->dentry->d_sb;
21068 + p->br = au_sbr(sb, p->bindex);
21069 + if (IS_ROOT(p->dentry)) {
21070 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21071 + p->h_mnt = au_br_mnt(p->br);
21072 + err = vfsub_mnt_want_write(p->h_mnt);
21073 + if (unlikely(err)) {
21074 + au_fclr_pin(p->flags, MNT_WRITE);
21081 + p->h_dentry = NULL;
21082 + if (p->bindex <= au_dbbot(p->dentry))
21083 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21085 + p->parent = dget_parent(p->dentry);
21086 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21087 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21090 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21091 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21093 + h_dir = p->hdir->hi_inode;
21097 + * if DI_LOCKED is not set, then p->parent may be different
21098 + * and h_parent can be NULL.
21100 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21102 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21103 + di_read_unlock(p->parent, AuLock_IR);
21105 + p->parent = NULL;
21109 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21110 + p->h_mnt = au_br_mnt(p->br);
21111 + err = vfsub_mnt_want_write(p->h_mnt);
21112 + if (unlikely(err)) {
21113 + au_fclr_pin(p->flags, MNT_WRITE);
21114 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21115 + di_read_unlock(p->parent, AuLock_IR);
21117 + p->parent = NULL;
21123 + err = au_pin_hdir_lock(p);
21125 + goto out; /* success */
21130 + pr_err("err %d\n", err);
21131 + err = au_busy_or_stale();
21136 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21137 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21138 + unsigned int udba, unsigned char flags)
21140 + p->dentry = dentry;
21142 + p->lsc_di = lsc_di;
21143 + p->lsc_hi = lsc_hi;
21144 + p->flags = flags;
21145 + p->bindex = bindex;
21147 + p->parent = NULL;
21151 + p->h_dentry = NULL;
21152 + p->h_parent = NULL;
21154 + p->task = current;
21157 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21158 + unsigned int udba, unsigned char flags)
21160 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21162 + return au_do_pin(pin);
21165 +/* ---------------------------------------------------------------------- */
21168 + * ->setattr() and ->getattr() are called in various cases.
21169 + * chmod, stat: dentry is revalidated.
21170 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21172 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21174 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21175 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21178 + struct dentry *parent;
21181 + if (au_digen_test(dentry, sigen)) {
21182 + parent = dget_parent(dentry);
21183 + di_read_lock_parent(parent, AuLock_IR);
21184 + err = au_refresh_dentry(dentry, parent);
21185 + di_read_unlock(parent, AuLock_IR);
21193 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21194 + struct au_icpup_args *a)
21198 + aufs_bindex_t btop, ibtop;
21199 + struct dentry *hi_wh, *parent;
21200 + struct inode *inode;
21201 + struct au_wr_dir_args wr_dir_args = {
21202 + .force_btgt = -1,
21206 + if (d_is_dir(dentry))
21207 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21208 + /* plink or hi_wh() case */
21209 + btop = au_dbtop(dentry);
21210 + inode = d_inode(dentry);
21211 + ibtop = au_ibtop(inode);
21212 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21213 + wr_dir_args.force_btgt = ibtop;
21214 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21215 + if (unlikely(err < 0))
21219 + au_fset_icpup(a->flags, DID_CPUP);
21222 + a->pin_flags = AuPin_MNT_WRITE;
21224 + if (!IS_ROOT(dentry)) {
21225 + au_fset_pin(a->pin_flags, DI_LOCKED);
21226 + parent = dget_parent(dentry);
21227 + di_write_lock_parent(parent);
21230 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21231 + if (unlikely(err))
21235 + a->h_path.dentry = au_h_dptr(dentry, btop);
21236 + a->h_inode = d_inode(a->h_path.dentry);
21237 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21238 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21239 + if (ia->ia_size < i_size_read(a->h_inode))
21240 + sz = ia->ia_size;
21241 + inode_unlock_shared(a->h_inode);
21245 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21246 + hi_wh = au_hi_wh(inode, a->btgt);
21248 + struct au_cp_generic cpg = {
21249 + .dentry = dentry,
21255 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21256 + if (unlikely(err))
21258 + hi_wh = au_hi_wh(inode, a->btgt);
21259 + /* todo: revalidate hi_wh? */
21264 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21265 + di_downgrade_lock(parent, AuLock_IR);
21269 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21270 + goto out; /* success */
21272 + if (!d_unhashed(dentry)) {
21273 + struct au_cp_generic cpg = {
21274 + .dentry = dentry,
21279 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21281 + err = au_sio_cpup_simple(&cpg);
21283 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21284 + } else if (!hi_wh)
21285 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21287 + a->h_path.dentry = hi_wh; /* do not dget here */
21290 + a->h_inode = d_inode(a->h_path.dentry);
21292 + goto out; /* success */
21293 + au_unpin(&a->pin);
21296 + di_write_unlock(parent);
21301 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21305 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21308 + struct inode *inode, *delegated;
21309 + struct super_block *sb;
21310 + struct file *file;
21311 + struct au_icpup_args *a;
21313 + inode = d_inode(dentry);
21314 + IMustLock(inode);
21316 + err = setattr_prepare(dentry, ia);
21317 + if (unlikely(err))
21321 + a = kzalloc(sizeof(*a), GFP_NOFS);
21322 + if (unlikely(!a))
21325 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21326 + ia->ia_valid &= ~ATTR_MODE;
21329 + sb = dentry->d_sb;
21330 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21331 + if (unlikely(err))
21334 + if (ia->ia_valid & ATTR_FILE) {
21335 + /* currently ftruncate(2) only */
21336 + AuDebugOn(!d_is_reg(dentry));
21337 + file = ia->ia_file;
21338 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21340 + if (unlikely(err))
21342 + ia->ia_file = au_hf_top(file);
21343 + a->udba = AuOpt_UDBA_NONE;
21345 + /* fchmod() doesn't pass ia_file */
21346 + a->udba = au_opt_udba(sb);
21347 + di_write_lock_child(dentry);
21348 + /* no d_unlinked(), to set UDBA_NONE for root */
21349 + if (d_unhashed(dentry))
21350 + a->udba = AuOpt_UDBA_NONE;
21351 + if (a->udba != AuOpt_UDBA_NONE) {
21352 + AuDebugOn(IS_ROOT(dentry));
21353 + err = au_reval_for_attr(dentry, au_sigen(sb));
21354 + if (unlikely(err))
21359 + err = au_pin_and_icpup(dentry, ia, a);
21360 + if (unlikely(err < 0))
21362 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21363 + ia->ia_file = NULL;
21364 + ia->ia_valid &= ~ATTR_FILE;
21367 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21368 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21369 + == (ATTR_MODE | ATTR_CTIME)) {
21370 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21371 + if (unlikely(err))
21373 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21374 + && (ia->ia_valid & ATTR_CTIME)) {
21375 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21376 + if (unlikely(err))
21380 + if (ia->ia_valid & ATTR_SIZE) {
21383 + if (ia->ia_size < i_size_read(inode))
21385 + truncate_setsize(inode, ia->ia_size);
21388 + if (ia->ia_valid & ATTR_FILE)
21390 + inode_unlock(a->h_inode);
21391 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21392 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21394 + delegated = NULL;
21396 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21398 + err = break_deleg_wait(&delegated);
21406 + * regardless aufs 'acl' option setting.
21407 + * why don't all acl-aware fs call this func from their ->setattr()?
21409 + if (!err && (ia->ia_valid & ATTR_MODE))
21410 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21412 + au_cpup_attr_changeable(inode);
21415 + inode_unlock(a->h_inode);
21416 + au_unpin(&a->pin);
21417 + if (unlikely(err))
21418 + au_update_dbtop(dentry);
21420 + di_write_unlock(dentry);
21422 + fi_write_unlock(file);
21423 + ia->ia_file = file;
21424 + ia->ia_valid |= ATTR_FILE;
21427 + si_read_unlock(sb);
21435 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21436 +static int au_h_path_to_set_attr(struct dentry *dentry,
21437 + struct au_icpup_args *a, struct path *h_path)
21440 + struct super_block *sb;
21442 + sb = dentry->d_sb;
21443 + a->udba = au_opt_udba(sb);
21444 + /* no d_unlinked(), to set UDBA_NONE for root */
21445 + if (d_unhashed(dentry))
21446 + a->udba = AuOpt_UDBA_NONE;
21447 + if (a->udba != AuOpt_UDBA_NONE) {
21448 + AuDebugOn(IS_ROOT(dentry));
21449 + err = au_reval_for_attr(dentry, au_sigen(sb));
21450 + if (unlikely(err))
21453 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21454 + if (unlikely(err < 0))
21457 + h_path->dentry = a->h_path.dentry;
21458 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21464 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21465 + struct au_sxattr *arg)
21468 + struct path h_path;
21469 + struct super_block *sb;
21470 + struct au_icpup_args *a;
21471 + struct inode *h_inode;
21473 + IMustLock(inode);
21476 + a = kzalloc(sizeof(*a), GFP_NOFS);
21477 + if (unlikely(!a))
21480 + sb = dentry->d_sb;
21481 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21482 + if (unlikely(err))
21485 + h_path.dentry = NULL; /* silence gcc */
21486 + di_write_lock_child(dentry);
21487 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21488 + if (unlikely(err))
21491 + inode_unlock(a->h_inode);
21492 + switch (arg->type) {
21493 + case AU_XATTR_SET:
21494 + AuDebugOn(d_is_negative(h_path.dentry));
21495 + err = vfsub_setxattr(h_path.dentry,
21496 + arg->u.set.name, arg->u.set.value,
21497 + arg->u.set.size, arg->u.set.flags);
21500 + err = -EOPNOTSUPP;
21501 + h_inode = d_inode(h_path.dentry);
21502 + if (h_inode->i_op->set_acl)
21503 + /* this will call posix_acl_update_mode */
21504 + err = h_inode->i_op->set_acl(h_inode,
21505 + arg->u.acl_set.acl,
21506 + arg->u.acl_set.type);
21510 + au_cpup_attr_timesizes(inode);
21512 + au_unpin(&a->pin);
21513 + if (unlikely(err))
21514 + au_update_dbtop(dentry);
21517 + di_write_unlock(dentry);
21518 + si_read_unlock(sb);
21527 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21528 + unsigned int nlink)
21532 + inode->i_mode = st->mode;
21533 + /* don't i_[ug]id_write() here */
21534 + inode->i_uid = st->uid;
21535 + inode->i_gid = st->gid;
21536 + inode->i_atime = st->atime;
21537 + inode->i_mtime = st->mtime;
21538 + inode->i_ctime = st->ctime;
21540 + au_cpup_attr_nlink(inode, /*force*/0);
21541 + if (S_ISDIR(inode->i_mode)) {
21542 + n = inode->i_nlink;
21545 + smp_mb(); /* for i_nlink */
21546 + /* 0 can happen */
21547 + set_nlink(inode, n);
21550 + spin_lock(&inode->i_lock);
21551 + inode->i_blocks = st->blocks;
21552 + i_size_write(inode, st->size);
21553 + spin_unlock(&inode->i_lock);
21557 + * common routine for aufs_getattr() and au_getxattr().
21558 + * returns zero or negative (an error).
21559 + * @dentry will be read-locked in success.
21561 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21562 + struct path *h_path, int locked)
21565 + unsigned int mnt_flags, sigen;
21566 + unsigned char udba_none;
21567 + aufs_bindex_t bindex;
21568 + struct super_block *sb, *h_sb;
21570 + h_path->mnt = NULL;
21571 + h_path->dentry = NULL;
21574 + sb = dentry->d_sb;
21575 + mnt_flags = au_mntflags(sb);
21576 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21578 + if (unlikely(locked))
21579 + goto body; /* skip locking dinfo */
21581 + /* support fstat(2) */
21582 + if (!d_unlinked(dentry) && !udba_none) {
21583 + sigen = au_sigen(sb);
21584 + err = au_digen_test(dentry, sigen);
21586 + di_read_lock_child(dentry, AuLock_IR);
21587 + err = au_dbrange_test(dentry);
21588 + if (unlikely(err)) {
21589 + di_read_unlock(dentry, AuLock_IR);
21593 + AuDebugOn(IS_ROOT(dentry));
21594 + di_write_lock_child(dentry);
21595 + err = au_dbrange_test(dentry);
21597 + err = au_reval_for_attr(dentry, sigen);
21599 + di_downgrade_lock(dentry, AuLock_IR);
21601 + di_write_unlock(dentry);
21606 + di_read_lock_child(dentry, AuLock_IR);
21610 + inode = d_inode(dentry);
21611 + if (unlikely(!inode))
21614 + bindex = au_ibtop(inode);
21615 + h_path->mnt = au_sbr_mnt(sb, bindex);
21616 + h_sb = h_path->mnt->mnt_sb;
21618 + && !au_test_fs_bad_iattr(h_sb)
21620 + goto out; /* success */
21622 + if (au_dbtop(dentry) == bindex)
21623 + h_path->dentry = au_h_dptr(dentry, bindex);
21624 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21625 + h_path->dentry = au_plink_lkup(inode, bindex);
21626 + if (IS_ERR(h_path->dentry))
21627 + /* pretending success */
21628 + h_path->dentry = NULL;
21630 + dput(h_path->dentry);
21637 +static int aufs_getattr(const struct path *path, struct kstat *st,
21638 + u32 request, unsigned int query)
21641 + unsigned char positive;
21642 + struct path h_path;
21643 + struct dentry *dentry;
21644 + struct inode *inode;
21645 + struct super_block *sb;
21647 + dentry = path->dentry;
21648 + inode = d_inode(dentry);
21649 + sb = dentry->d_sb;
21650 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21651 + if (unlikely(err))
21653 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21655 + if (unlikely(err))
21657 + if (unlikely(!h_path.dentry))
21658 + /* illegally overlapped or something */
21659 + goto out_fill; /* pretending success */
21661 + positive = d_is_positive(h_path.dentry);
21663 + /* no vfsub version */
21664 + err = vfs_getattr(&h_path, st, request, query);
21667 + au_refresh_iattr(inode, st,
21668 + d_inode(h_path.dentry)->i_nlink);
21669 + goto out_fill; /* success */
21675 + generic_fillattr(inode, st);
21677 + di_read_unlock(dentry, AuLock_IR);
21679 + si_read_unlock(sb);
21685 +/* ---------------------------------------------------------------------- */
21687 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21688 + struct delayed_call *done)
21691 + struct dentry *h_dentry;
21692 + struct inode *h_inode;
21694 + aufs_bindex_t bindex;
21696 + ret = NULL; /* suppress a warning */
21701 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21702 + if (unlikely(err))
21705 + err = au_d_hashed_positive(dentry);
21706 + if (unlikely(err))
21710 + inode = d_inode(dentry);
21711 + bindex = au_ibtop(inode);
21712 + h_inode = au_h_iptr(inode, bindex);
21713 + if (unlikely(!h_inode->i_op->get_link))
21718 + if (au_dbtop(dentry) <= bindex) {
21719 + h_dentry = au_h_dptr(dentry, bindex);
21724 + h_dentry = d_find_any_alias(h_inode);
21725 + if (IS_ERR(h_dentry)) {
21726 + err = PTR_ERR(h_dentry);
21730 + if (unlikely(!h_dentry))
21734 + AuDbg("%ps\n", h_inode->i_op->get_link);
21735 + AuDbgDentry(h_dentry);
21736 + ret = vfs_get_link(h_dentry, done);
21739 + err = PTR_ERR(ret);
21742 + aufs_read_unlock(dentry, AuLock_IR);
21744 + if (unlikely(err))
21745 + ret = ERR_PTR(err);
21746 + AuTraceErrPtr(ret);
21750 +/* ---------------------------------------------------------------------- */
21752 +static int au_is_special(struct inode *inode)
21754 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21757 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21761 + aufs_bindex_t bindex;
21762 + struct super_block *sb;
21763 + struct inode *h_inode;
21764 + struct vfsmount *h_mnt;
21766 + sb = inode->i_sb;
21767 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21768 + "unexpected s_flags 0x%lx", sb->s_flags);
21770 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21772 + si_read_lock(sb, AuLock_FLUSH);
21773 + ii_write_lock_child(inode);
21776 + bindex = au_ibtop(inode);
21777 + h_inode = au_h_iptr(inode, bindex);
21778 + if (!au_test_ro(sb, bindex, inode)) {
21779 + h_mnt = au_sbr_mnt(sb, bindex);
21780 + err = vfsub_mnt_want_write(h_mnt);
21782 + err = vfsub_update_time(h_inode, ts, flags);
21783 + vfsub_mnt_drop_write(h_mnt);
21785 + } else if (au_is_special(h_inode)) {
21787 + * Never copy-up here.
21788 + * These special files may already be opened and used for
21789 + * communicating. If we copied it up, then the communication
21790 + * would be corrupted.
21792 + AuWarn1("timestamps for i%lu are ignored "
21793 + "since it is on readonly branch (hi%lu).\n",
21794 + inode->i_ino, h_inode->i_ino);
21795 + } else if (flags & ~S_ATIME) {
21797 + AuIOErr1("unexpected flags 0x%x\n", flags);
21802 + au_cpup_attr_timesizes(inode);
21803 + ii_write_unlock(inode);
21804 + si_read_unlock(sb);
21807 + if (!err && (flags & S_VERSION))
21808 + inode_inc_iversion(inode);
21813 +/* ---------------------------------------------------------------------- */
21815 +/* no getattr version will be set by module.c:aufs_init() */
21816 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21818 + [AuIop_SYMLINK] = {
21819 + .permission = aufs_permission,
21820 +#ifdef CONFIG_FS_POSIX_ACL
21821 + .get_acl = aufs_get_acl,
21822 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21825 + .setattr = aufs_setattr,
21826 + .getattr = aufs_getattr,
21828 +#ifdef CONFIG_AUFS_XATTR
21829 + .listxattr = aufs_listxattr,
21832 + .get_link = aufs_get_link,
21834 + /* .update_time = aufs_update_time */
21837 + .create = aufs_create,
21838 + .lookup = aufs_lookup,
21839 + .link = aufs_link,
21840 + .unlink = aufs_unlink,
21841 + .symlink = aufs_symlink,
21842 + .mkdir = aufs_mkdir,
21843 + .rmdir = aufs_rmdir,
21844 + .mknod = aufs_mknod,
21845 + .rename = aufs_rename,
21847 + .permission = aufs_permission,
21848 +#ifdef CONFIG_FS_POSIX_ACL
21849 + .get_acl = aufs_get_acl,
21850 + .set_acl = aufs_set_acl,
21853 + .setattr = aufs_setattr,
21854 + .getattr = aufs_getattr,
21856 +#ifdef CONFIG_AUFS_XATTR
21857 + .listxattr = aufs_listxattr,
21860 + .update_time = aufs_update_time,
21861 + .atomic_open = aufs_atomic_open,
21862 + .tmpfile = aufs_tmpfile
21864 + [AuIop_OTHER] = {
21865 + .permission = aufs_permission,
21866 +#ifdef CONFIG_FS_POSIX_ACL
21867 + .get_acl = aufs_get_acl,
21868 + .set_acl = aufs_set_acl,
21871 + .setattr = aufs_setattr,
21872 + .getattr = aufs_getattr,
21874 +#ifdef CONFIG_AUFS_XATTR
21875 + .listxattr = aufs_listxattr,
21878 + .update_time = aufs_update_time
21881 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21882 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21883 +++ linux/fs/aufs/i_op_del.c 2021-12-03 15:38:59.936647310 +0100
21885 +// SPDX-License-Identifier: GPL-2.0
21887 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21889 + * This program, aufs is free software; you can redistribute it and/or modify
21890 + * it under the terms of the GNU General Public License as published by
21891 + * the Free Software Foundation; either version 2 of the License, or
21892 + * (at your option) any later version.
21894 + * This program is distributed in the hope that it will be useful,
21895 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21896 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21897 + * GNU General Public License for more details.
21899 + * You should have received a copy of the GNU General Public License
21900 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21904 + * inode operations (del entry)
21907 +#include <linux/iversion.h>
21911 + * decide if a new whiteout for @dentry is necessary or not.
21912 + * when it is necessary, prepare the parent dir for the upper branch whose
21913 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21914 + * be done by caller.
21916 + * 0: wh is unnecessary
21917 + * plus: wh is necessary
21920 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21922 + int need_wh, err;
21923 + aufs_bindex_t btop;
21924 + struct super_block *sb;
21926 + sb = dentry->d_sb;
21927 + btop = au_dbtop(dentry);
21928 + if (*bcpup < 0) {
21930 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21931 + err = AuWbrCopyup(au_sbi(sb), dentry);
21933 + if (unlikely(err < 0))
21937 + AuDebugOn(btop < *bcpup
21938 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
21939 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
21941 + if (*bcpup != btop) {
21942 + err = au_cpup_dirs(dentry, *bcpup);
21943 + if (unlikely(err))
21947 + struct au_dinfo *dinfo, *tmp;
21949 + need_wh = -ENOMEM;
21950 + dinfo = au_di(dentry);
21951 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
21953 + au_di_cp(tmp, dinfo);
21954 + au_di_swap(tmp, dinfo);
21955 + /* returns the number of positive dentries */
21956 + need_wh = au_lkup_dentry(dentry, btop + 1,
21957 + /* AuLkup_IGNORE_PERM */ 0);
21958 + au_di_swap(tmp, dinfo);
21959 + au_rw_write_unlock(&tmp->di_rwsem);
21963 + AuDbg("need_wh %d\n", need_wh);
21971 + * simple tests for the del-entry operations.
21972 + * following the checks in vfs, plus the parent-child relationship.
21974 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
21975 + struct dentry *h_parent, int isdir)
21979 + struct dentry *h_dentry, *h_latest;
21980 + struct inode *h_inode;
21981 + struct path h_ppath;
21982 + struct super_block *sb;
21983 + struct au_branch *br;
21985 + h_dentry = au_h_dptr(dentry, bindex);
21986 + if (d_really_is_positive(dentry)) {
21988 + if (unlikely(d_is_negative(h_dentry)))
21990 + h_inode = d_inode(h_dentry);
21991 + if (unlikely(!h_inode->i_nlink))
21994 + h_mode = h_inode->i_mode;
21997 + if (unlikely(S_ISDIR(h_mode)))
21999 + } else if (unlikely(!S_ISDIR(h_mode))) {
22004 + /* rename(2) case */
22006 + if (unlikely(d_is_positive(h_dentry)))
22011 + /* expected parent dir is locked */
22012 + if (unlikely(h_parent != h_dentry->d_parent))
22017 + * rmdir a dir may break the consistency on some filesystem.
22018 + * let's try heavy test.
22021 + sb = dentry->d_sb;
22022 + br = au_sbr(sb, bindex);
22023 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
22024 + && au_test_h_perm(d_inode(h_parent),
22025 + MAY_EXEC | MAY_WRITE)))
22028 + h_ppath.dentry = h_parent;
22029 + h_ppath.mnt = au_br_mnt(br);
22030 + h_latest = au_sio_lkup_one(&dentry->d_name, &h_ppath);
22032 + if (IS_ERR(h_latest))
22034 + if (h_latest == h_dentry)
22043 + * decide the branch where we operate for @dentry. the branch index will be set
22044 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22045 + * dir for reverting.
22046 + * when a new whiteout is necessary, create it.
22048 +static struct dentry*
22049 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22050 + struct au_dtime *dt, struct au_pin *pin)
22052 + struct dentry *wh_dentry;
22053 + struct super_block *sb;
22054 + struct path h_path;
22055 + int err, need_wh;
22056 + unsigned int udba;
22057 + aufs_bindex_t bcpup;
22059 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22060 + wh_dentry = ERR_PTR(need_wh);
22061 + if (unlikely(need_wh < 0))
22064 + sb = dentry->d_sb;
22065 + udba = au_opt_udba(sb);
22067 + err = au_pin(pin, dentry, bcpup, udba,
22068 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22069 + wh_dentry = ERR_PTR(err);
22070 + if (unlikely(err))
22073 + h_path.dentry = au_pinned_h_parent(pin);
22074 + if (udba != AuOpt_UDBA_NONE
22075 + && au_dbtop(dentry) == bcpup) {
22076 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22077 + wh_dentry = ERR_PTR(err);
22078 + if (unlikely(err))
22082 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22083 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22084 + wh_dentry = NULL;
22086 + goto out; /* success, no need to create whiteout */
22088 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22089 + if (IS_ERR(wh_dentry))
22092 + /* returns with the parent is locked and wh_dentry is dget-ed */
22093 + goto out; /* success */
22098 + return wh_dentry;
22102 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22103 + * in order to be revertible and save time for removing many child whiteouts
22105 + * returns 1 when there are too many child whiteout and caller should remove
22106 + * them asynchronously. returns 0 when the number of children is enough small to
22107 + * remove now or the branch fs is a remote fs.
22108 + * otherwise return an error.
22110 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22111 + struct au_nhash *whlist, struct inode *dir)
22113 + int rmdir_later, err, dirwh;
22114 + struct dentry *h_dentry;
22115 + struct super_block *sb;
22116 + struct inode *inode;
22118 + sb = dentry->d_sb;
22119 + SiMustAnyLock(sb);
22120 + h_dentry = au_h_dptr(dentry, bindex);
22121 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22122 + if (unlikely(err))
22125 + /* stop monitoring */
22126 + inode = d_inode(dentry);
22127 + au_hn_free(au_hi(inode, bindex));
22129 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22130 + dirwh = au_sbi(sb)->si_dirwh;
22131 + rmdir_later = (dirwh <= 1);
22132 + if (!rmdir_later)
22133 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22136 + return rmdir_later;
22139 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22140 + if (unlikely(err)) {
22141 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22142 + h_dentry, bindex, err);
22152 + * final procedure for deleting a entry.
22153 + * maintain dentry and iattr.
22155 +static void epilog(struct inode *dir, struct dentry *dentry,
22156 + aufs_bindex_t bindex)
22158 + struct inode *inode;
22160 + inode = d_inode(dentry);
22162 + inode->i_ctime = dir->i_ctime;
22164 + au_dir_ts(dir, bindex);
22165 + inode_inc_iversion(dir);
22169 + * when an error happened, remove the created whiteout and revert everything.
22171 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22172 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22173 + struct dentry *dentry, struct au_dtime *dt)
22176 + struct path h_path = {
22177 + .dentry = wh_dentry,
22178 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22181 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22183 + au_set_dbwh(dentry, bwh);
22184 + au_dtime_revert(dt);
22188 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22192 +/* ---------------------------------------------------------------------- */
22194 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22197 + aufs_bindex_t bwh, bindex, btop;
22198 + struct inode *inode, *h_dir, *delegated;
22199 + struct dentry *parent, *wh_dentry;
22200 + /* to reduce stack size */
22202 + struct au_dtime dt;
22203 + struct au_pin pin;
22204 + struct path h_path;
22210 + a = kmalloc(sizeof(*a), GFP_NOFS);
22211 + if (unlikely(!a))
22214 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22215 + if (unlikely(err))
22217 + err = au_d_hashed_positive(dentry);
22218 + if (unlikely(err))
22220 + inode = d_inode(dentry);
22221 + IMustLock(inode);
22223 + if (unlikely(d_is_dir(dentry)))
22224 + goto out_unlock; /* possible? */
22226 + btop = au_dbtop(dentry);
22227 + bwh = au_dbwh(dentry);
22229 + parent = dentry->d_parent; /* dir inode is locked */
22230 + di_write_lock_parent(parent);
22231 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22233 + err = PTR_ERR(wh_dentry);
22234 + if (IS_ERR(wh_dentry))
22237 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22238 + a->h_path.dentry = au_h_dptr(dentry, btop);
22239 + dget(a->h_path.dentry);
22240 + if (bindex == btop) {
22241 + h_dir = au_pinned_h_dir(&a->pin);
22242 + delegated = NULL;
22243 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22244 + if (unlikely(err == -EWOULDBLOCK)) {
22245 + pr_warn("cannot retry for NFSv4 delegation"
22246 + " for an internal unlink\n");
22250 + /* dir inode is locked */
22251 + h_dir = d_inode(wh_dentry->d_parent);
22252 + IMustLock(h_dir);
22257 + vfsub_drop_nlink(inode);
22258 + epilog(dir, dentry, bindex);
22260 + /* update target timestamps */
22261 + if (bindex == btop) {
22262 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22264 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22266 + /* todo: this timestamp may be reverted later */
22267 + inode->i_ctime = h_dir->i_ctime;
22268 + goto out_unpin; /* success */
22275 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22282 + au_unpin(&a->pin);
22284 + dput(a->h_path.dentry);
22286 + di_write_unlock(parent);
22288 + aufs_read_unlock(dentry, AuLock_DW);
22295 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22297 + int err, rmdir_later;
22298 + aufs_bindex_t bwh, bindex, btop;
22299 + struct inode *inode;
22300 + struct dentry *parent, *wh_dentry, *h_dentry;
22301 + struct au_whtmp_rmdir *args;
22302 + /* to reduce stack size */
22304 + struct au_dtime dt;
22305 + struct au_pin pin;
22311 + a = kmalloc(sizeof(*a), GFP_NOFS);
22312 + if (unlikely(!a))
22315 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22316 + if (unlikely(err))
22318 + err = au_alive_dir(dentry);
22319 + if (unlikely(err))
22321 + inode = d_inode(dentry);
22322 + IMustLock(inode);
22324 + if (unlikely(!d_is_dir(dentry)))
22325 + goto out_unlock; /* possible? */
22328 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22329 + if (unlikely(!args))
22332 + parent = dentry->d_parent; /* dir inode is locked */
22333 + di_write_lock_parent(parent);
22334 + err = au_test_empty(dentry, &args->whlist);
22335 + if (unlikely(err))
22338 + btop = au_dbtop(dentry);
22339 + bwh = au_dbwh(dentry);
22341 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22343 + err = PTR_ERR(wh_dentry);
22344 + if (IS_ERR(wh_dentry))
22347 + h_dentry = au_h_dptr(dentry, btop);
22350 + if (bindex == btop) {
22351 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22353 + rmdir_later = err;
22357 + /* stop monitoring */
22358 + au_hn_free(au_hi(inode, btop));
22360 + /* dir inode is locked */
22361 + IMustLock(d_inode(wh_dentry->d_parent));
22366 + vfsub_dead_dir(inode);
22367 + au_set_dbdiropq(dentry, -1);
22368 + epilog(dir, dentry, bindex);
22370 + if (rmdir_later) {
22371 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22375 + goto out_unpin; /* success */
22383 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22390 + au_unpin(&a->pin);
22394 + di_write_unlock(parent);
22396 + au_whtmp_rmdir_free(args);
22398 + aufs_read_unlock(dentry, AuLock_DW);
22405 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22406 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22407 +++ linux/fs/aufs/i_op_ren.c 2021-12-03 15:38:59.936647310 +0100
22409 +// SPDX-License-Identifier: GPL-2.0
22411 + * Copyright (C) 2005-2021 Junjiro R. Okajima
22413 + * This program, aufs is free software; you can redistribute it and/or modify
22414 + * it under the terms of the GNU General Public License as published by
22415 + * the Free Software Foundation; either version 2 of the License, or
22416 + * (at your option) any later version.
22418 + * This program is distributed in the hope that it will be useful,
22419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22421 + * GNU General Public License for more details.
22423 + * You should have received a copy of the GNU General Public License
22424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22428 + * inode operation (rename entry)
22429 + * todo: this is crazy monster
22432 +#include <linux/iversion.h>
22435 +enum { AuSRC, AuDST, AuSrcDst };
22436 +enum { AuPARENT, AuCHILD, AuParentChild };
22438 +#define AuRen_ISDIR_SRC 1
22439 +#define AuRen_ISDIR_DST (1 << 1)
22440 +#define AuRen_ISSAMEDIR (1 << 2)
22441 +#define AuRen_WHSRC (1 << 3)
22442 +#define AuRen_WHDST (1 << 4)
22443 +#define AuRen_MNT_WRITE (1 << 5)
22444 +#define AuRen_DT_DSTDIR (1 << 6)
22445 +#define AuRen_DIROPQ_SRC (1 << 7)
22446 +#define AuRen_DIROPQ_DST (1 << 8)
22447 +#define AuRen_DIRREN (1 << 9)
22448 +#define AuRen_DROPPED_SRC (1 << 10)
22449 +#define AuRen_DROPPED_DST (1 << 11)
22450 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22451 +#define au_fset_ren(flags, name) \
22452 + do { (flags) |= AuRen_##name; } while (0)
22453 +#define au_fclr_ren(flags, name) \
22454 + do { (flags) &= ~AuRen_##name; } while (0)
22456 +#ifndef CONFIG_AUFS_DIRREN
22457 +#undef AuRen_DIRREN
22458 +#define AuRen_DIRREN 0
22461 +struct au_ren_args {
22463 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22465 + struct inode *dir, *inode;
22466 + struct au_hinode *hdir, *hinode;
22467 + struct au_dtime dt[AuParentChild];
22468 + aufs_bindex_t btop, bdiropq;
22471 +#define src_dentry sd[AuSRC].dentry
22472 +#define src_dir sd[AuSRC].dir
22473 +#define src_inode sd[AuSRC].inode
22474 +#define src_h_dentry sd[AuSRC].h_dentry
22475 +#define src_parent sd[AuSRC].parent
22476 +#define src_h_parent sd[AuSRC].h_parent
22477 +#define src_wh_dentry sd[AuSRC].wh_dentry
22478 +#define src_hdir sd[AuSRC].hdir
22479 +#define src_hinode sd[AuSRC].hinode
22480 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22481 +#define src_dt sd[AuSRC].dt
22482 +#define src_btop sd[AuSRC].btop
22483 +#define src_bdiropq sd[AuSRC].bdiropq
22485 +#define dst_dentry sd[AuDST].dentry
22486 +#define dst_dir sd[AuDST].dir
22487 +#define dst_inode sd[AuDST].inode
22488 +#define dst_h_dentry sd[AuDST].h_dentry
22489 +#define dst_parent sd[AuDST].parent
22490 +#define dst_h_parent sd[AuDST].h_parent
22491 +#define dst_wh_dentry sd[AuDST].wh_dentry
22492 +#define dst_hdir sd[AuDST].hdir
22493 +#define dst_hinode sd[AuDST].hinode
22494 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22495 +#define dst_dt sd[AuDST].dt
22496 +#define dst_btop sd[AuDST].btop
22497 +#define dst_bdiropq sd[AuDST].bdiropq
22499 + struct dentry *h_trap;
22500 + struct au_branch *br;
22501 + struct path h_path;
22502 + struct au_nhash whlist;
22503 + aufs_bindex_t btgt, src_bwh;
22506 + unsigned short auren_flags;
22507 + unsigned char flags; /* syscall parameter */
22508 + unsigned char exchange;
22511 + struct au_whtmp_rmdir *thargs;
22512 + struct dentry *h_dst;
22513 + struct au_hinode *h_root;
22516 +/* ---------------------------------------------------------------------- */
22519 + * functions for reverting.
22520 + * when an error happened in a single rename systemcall, we should revert
22521 + * everything as if nothing happened.
22522 + * we don't need to revert the copied-up/down the parent dir since they are
22526 +#define RevertFailure(fmt, ...) do { \
22527 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22528 + ##__VA_ARGS__, err, rerr); \
22532 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22535 + struct dentry *d;
22536 +#define src_or_dst(member) a->sd[idx].member
22538 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22539 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22540 + rerr = au_diropq_remove(d, a->btgt);
22541 + au_hn_inode_unlock(src_or_dst(hinode));
22542 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22544 + RevertFailure("remove diropq %pd", d);
22546 +#undef src_or_dst_
22549 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22551 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22552 + au_ren_do_rev_diropq(err, a, AuSRC);
22553 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22554 + au_ren_do_rev_diropq(err, a, AuDST);
22557 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22560 + struct inode *delegated;
22561 + struct path h_ppath = {
22562 + .dentry = a->src_h_parent,
22563 + .mnt = a->h_path.mnt
22566 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
22567 + rerr = PTR_ERR(a->h_path.dentry);
22568 + if (IS_ERR(a->h_path.dentry)) {
22569 + RevertFailure("lkup one %pd", a->src_dentry);
22573 + delegated = NULL;
22574 + rerr = vfsub_rename(a->dst_h_dir,
22575 + au_h_dptr(a->src_dentry, a->btgt),
22576 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22577 + if (unlikely(rerr == -EWOULDBLOCK)) {
22578 + pr_warn("cannot retry for NFSv4 delegation"
22579 + " for an internal rename\n");
22582 + d_drop(a->h_path.dentry);
22583 + dput(a->h_path.dentry);
22584 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22586 + RevertFailure("rename %pd", a->src_dentry);
22589 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22592 + struct inode *delegated;
22593 + struct path h_ppath = {
22594 + .dentry = a->dst_h_parent,
22595 + .mnt = a->h_path.mnt
22598 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
22599 + rerr = PTR_ERR(a->h_path.dentry);
22600 + if (IS_ERR(a->h_path.dentry)) {
22601 + RevertFailure("lkup one %pd", a->dst_dentry);
22604 + if (d_is_positive(a->h_path.dentry)) {
22605 + d_drop(a->h_path.dentry);
22606 + dput(a->h_path.dentry);
22610 + delegated = NULL;
22611 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22612 + &delegated, a->flags);
22613 + if (unlikely(rerr == -EWOULDBLOCK)) {
22614 + pr_warn("cannot retry for NFSv4 delegation"
22615 + " for an internal rename\n");
22618 + d_drop(a->h_path.dentry);
22619 + dput(a->h_path.dentry);
22621 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22623 + RevertFailure("rename %pd", a->h_dst);
22626 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22630 + a->h_path.dentry = a->src_wh_dentry;
22631 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22632 + au_set_dbwh(a->src_dentry, a->src_bwh);
22634 + RevertFailure("unlink %pd", a->src_wh_dentry);
22636 +#undef RevertFailure
22638 +/* ---------------------------------------------------------------------- */
22641 + * when we have to copyup the renaming entry, do it with the rename-target name
22642 + * in order to minimize the cost (the later actual rename is unnecessary).
22643 + * otherwise rename it on the target branch.
22645 +static int au_ren_or_cpup(struct au_ren_args *a)
22648 + struct dentry *d;
22649 + struct inode *delegated;
22651 + d = a->src_dentry;
22652 + if (au_dbtop(d) == a->btgt) {
22653 + a->h_path.dentry = a->dst_h_dentry;
22654 + AuDebugOn(au_dbtop(d) != a->btgt);
22655 + delegated = NULL;
22656 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22657 + a->dst_h_dir, &a->h_path, &delegated,
22659 + if (unlikely(err == -EWOULDBLOCK)) {
22660 + pr_warn("cannot retry for NFSv4 delegation"
22661 + " for an internal rename\n");
22667 + if (!err && a->h_dst)
22668 + /* it will be set to dinfo later */
22674 +/* cf. aufs_rmdir() */
22675 +static int au_ren_del_whtmp(struct au_ren_args *a)
22678 + struct inode *dir;
22680 + dir = a->dst_dir;
22681 + SiMustAnyLock(dir->i_sb);
22682 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22683 + au_sbi(dir->i_sb)->si_dirwh)
22684 + || au_test_fs_remote(a->h_dst->d_sb)) {
22685 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22686 + if (unlikely(err))
22687 + pr_warn("failed removing whtmp dir %pd (%d), "
22688 + "ignored.\n", a->h_dst, err);
22690 + au_nhash_wh_free(&a->thargs->whlist);
22691 + a->thargs->whlist = a->whlist;
22692 + a->whlist.nh_num = 0;
22693 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22695 + a->thargs = NULL;
22701 +/* make it 'opaque' dir. */
22702 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22705 + struct dentry *d, *diropq;
22706 +#define src_or_dst(member) a->sd[idx].member
22709 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22710 + src_or_dst(bdiropq) = au_dbdiropq(d);
22711 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22712 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22713 + diropq = au_diropq_create(d, a->btgt);
22714 + au_hn_inode_unlock(src_or_dst(hinode));
22715 + if (IS_ERR(diropq))
22716 + err = PTR_ERR(diropq);
22720 +#undef src_or_dst_
22724 +static int au_ren_diropq(struct au_ren_args *a)
22727 + unsigned char always;
22728 + struct dentry *d;
22731 + d = a->dst_dentry; /* already renamed on the branch */
22732 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22733 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22734 + && !au_ftest_ren(a->auren_flags, DIRREN)
22735 + && a->btgt != au_dbdiropq(a->src_dentry)
22736 + && (a->dst_wh_dentry
22737 + || a->btgt <= au_dbdiropq(d)
22738 + /* hide the lower to keep xino */
22739 + /* the lowers may not be a dir, but we hide them anyway */
22740 + || a->btgt < au_dbbot(d)
22743 + err = au_ren_do_diropq(a, AuSRC);
22744 + if (unlikely(err))
22746 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22748 + if (!a->exchange)
22749 + goto out; /* success */
22751 + d = a->src_dentry; /* already renamed on the branch */
22752 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22753 + && a->btgt != au_dbdiropq(a->dst_dentry)
22754 + && (a->btgt < au_dbdiropq(d)
22755 + || a->btgt < au_dbbot(d)
22757 + AuDbgDentry(a->src_dentry);
22758 + AuDbgDentry(a->dst_dentry);
22759 + err = au_ren_do_diropq(a, AuDST);
22760 + if (unlikely(err))
22761 + goto out_rev_src;
22762 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22764 + goto out; /* success */
22767 + AuDbg("err %d, reverting src\n", err);
22768 + au_ren_rev_diropq(err, a);
22773 +static int do_rename(struct au_ren_args *a)
22776 + struct dentry *d, *h_d;
22778 + if (!a->exchange) {
22779 + /* prepare workqueue args for asynchronous rmdir */
22780 + h_d = a->dst_h_dentry;
22781 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22782 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22783 + && d_is_positive(h_d)) {
22785 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22787 + if (unlikely(!a->thargs))
22789 + a->h_dst = dget(h_d);
22792 + /* create whiteout for src_dentry */
22793 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22794 + a->src_bwh = au_dbwh(a->src_dentry);
22795 + AuDebugOn(a->src_bwh >= 0);
22796 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22797 + a->src_h_parent);
22798 + err = PTR_ERR(a->src_wh_dentry);
22799 + if (IS_ERR(a->src_wh_dentry))
22803 + /* lookup whiteout for dentry */
22804 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22805 + h_d = au_wh_lkup(a->dst_h_parent,
22806 + &a->dst_dentry->d_name, a->br);
22807 + err = PTR_ERR(h_d);
22810 + if (d_is_negative(h_d))
22813 + a->dst_wh_dentry = h_d;
22816 + /* rename dentry to tmpwh */
22818 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22819 + if (unlikely(err))
22822 + d = a->dst_dentry;
22823 + au_set_h_dptr(d, a->btgt, NULL);
22824 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22825 + if (unlikely(err))
22827 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22831 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22832 +#if 0 /* debugging */
22833 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22834 + && d_is_positive(a->dst_h_dentry)
22835 + && a->src_btop != a->btgt);
22838 + /* rename by vfs_rename or cpup */
22839 + err = au_ren_or_cpup(a);
22840 + if (unlikely(err))
22841 + /* leave the copied-up one */
22844 + /* make dir opaque */
22845 + err = au_ren_diropq(a);
22846 + if (unlikely(err))
22849 + /* update target timestamps */
22850 + if (a->exchange) {
22851 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22852 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22853 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22854 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22856 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22857 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22858 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22859 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22861 + if (!a->exchange) {
22862 + /* remove whiteout for dentry */
22863 + if (a->dst_wh_dentry) {
22864 + a->h_path.dentry = a->dst_wh_dentry;
22865 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22867 + if (unlikely(err))
22871 + /* remove whtmp */
22873 + au_ren_del_whtmp(a); /* ignore this error */
22875 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22878 + goto out_success;
22881 + au_ren_rev_diropq(err, a);
22883 + au_ren_rev_rename(err, a);
22887 + au_ren_rev_whtmp(err, a);
22889 + dput(a->dst_wh_dentry);
22890 + a->dst_wh_dentry = NULL;
22892 + if (a->src_wh_dentry)
22893 + au_ren_rev_whsrc(err, a);
22895 + dput(a->src_wh_dentry);
22896 + dput(a->dst_wh_dentry);
22900 + au_whtmp_rmdir_free(a->thargs);
22901 + a->thargs = NULL;
22907 +/* ---------------------------------------------------------------------- */
22910 + * test if @dentry dir can be rename destination or not.
22911 + * success means, it is a logically empty dir.
22913 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22915 + return au_test_empty(dentry, whlist);
22919 + * test if @a->src_dentry dir can be rename source or not.
22920 + * if it can, return 0.
22922 + * - it is a logically empty dir.
22923 + * - or, it exists on writable branch and has no children including whiteouts
22924 + * on the lower branch unless DIRREN is on.
22926 +static int may_rename_srcdir(struct au_ren_args *a)
22929 + unsigned int rdhash;
22930 + aufs_bindex_t btop, btgt;
22931 + struct dentry *dentry;
22932 + struct super_block *sb;
22933 + struct au_sbinfo *sbinfo;
22935 + dentry = a->src_dentry;
22936 + sb = dentry->d_sb;
22937 + sbinfo = au_sbi(sb);
22938 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22939 + au_fset_ren(a->auren_flags, DIRREN);
22942 + btop = au_dbtop(dentry);
22943 + if (btop != btgt) {
22944 + struct au_nhash whlist;
22946 + SiMustAnyLock(sb);
22947 + rdhash = sbinfo->si_rdhash;
22949 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
22951 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
22952 + if (unlikely(err))
22954 + err = au_test_empty(dentry, &whlist);
22955 + au_nhash_wh_free(&whlist);
22959 + if (btop == au_dbtaildir(dentry))
22960 + return 0; /* success */
22962 + err = au_test_empty_lower(dentry);
22965 + if (err == -ENOTEMPTY) {
22966 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
22969 + AuWarn1("renaming dir who has child(ren) on multiple "
22970 + "branches, is not supported\n");
22977 +/* side effect: sets whlist and h_dentry */
22978 +static int au_ren_may_dir(struct au_ren_args *a)
22981 + unsigned int rdhash;
22982 + struct dentry *d;
22984 + d = a->dst_dentry;
22985 + SiMustAnyLock(d->d_sb);
22988 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
22989 + rdhash = au_sbi(d->d_sb)->si_rdhash;
22991 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
22992 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
22993 + if (unlikely(err))
22996 + if (!a->exchange) {
22997 + au_set_dbtop(d, a->dst_btop);
22998 + err = may_rename_dstdir(d, &a->whlist);
22999 + au_set_dbtop(d, a->btgt);
23001 + err = may_rename_srcdir(a);
23003 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23004 + if (unlikely(err))
23007 + d = a->src_dentry;
23008 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23009 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23010 + err = may_rename_srcdir(a);
23011 + if (unlikely(err)) {
23012 + au_nhash_wh_free(&a->whlist);
23013 + a->whlist.nh_num = 0;
23020 +/* ---------------------------------------------------------------------- */
23023 + * simple tests for rename.
23024 + * following the checks in vfs, plus the parent-child relationship.
23026 +static int au_may_ren(struct au_ren_args *a)
23029 + struct inode *h_inode;
23031 + if (a->src_btop == a->btgt) {
23032 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23033 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23034 + if (unlikely(err))
23037 + if (unlikely(a->src_h_dentry == a->h_trap))
23042 + if (a->dst_btop != a->btgt)
23045 + err = -ENOTEMPTY;
23046 + if (unlikely(a->dst_h_dentry == a->h_trap))
23050 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23051 + if (d_really_is_negative(a->dst_dentry)) {
23052 + if (d_is_negative(a->dst_h_dentry))
23053 + err = au_may_add(a->dst_dentry, a->btgt,
23054 + a->dst_h_parent, isdir);
23056 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23058 + h_inode = d_inode(a->dst_h_dentry);
23059 + if (h_inode->i_nlink)
23060 + err = au_may_del(a->dst_dentry, a->btgt,
23061 + a->dst_h_parent, isdir);
23065 + if (unlikely(err == -ENOENT || err == -EEXIST))
23071 +/* ---------------------------------------------------------------------- */
23076 + * - src_dir and dir by lock_rename()
23077 + * - inode if exists
23080 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23082 + * + di_write_lock2_child()
23083 + * + di_write_lock_child()
23084 + * + ii_write_lock_child()
23085 + * + di_write_lock_child2()
23086 + * + ii_write_lock_child2()
23087 + * + src_parent and parent
23088 + * + di_write_lock_parent()
23089 + * + ii_write_lock_parent()
23090 + * + di_write_lock_parent2()
23091 + * + ii_write_lock_parent2()
23092 + * + lower src_dir and dir by vfsub_lock_rename()
23093 + * + verify the every relationships between child and parent. if any
23094 + * of them failed, unlock all and return -EBUSY.
23096 +static void au_ren_unlock(struct au_ren_args *a)
23098 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23099 + a->dst_h_parent, a->dst_hdir);
23100 + if (au_ftest_ren(a->auren_flags, DIRREN)
23102 + au_hn_inode_unlock(a->h_root);
23103 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23104 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23107 +static int au_ren_lock(struct au_ren_args *a)
23110 + unsigned int udba;
23113 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23114 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23115 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23116 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23118 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23119 + if (unlikely(err))
23121 + au_fset_ren(a->auren_flags, MNT_WRITE);
23122 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23123 + struct dentry *root;
23124 + struct inode *dir;
23127 + * sbinfo is already locked, so this ii_read_lock is
23128 + * unnecessary. but our debugging feature checks it.
23130 + root = a->src_inode->i_sb->s_root;
23131 + if (root != a->src_parent && root != a->dst_parent) {
23132 + dir = d_inode(root);
23133 + ii_read_lock_parent3(dir);
23134 + a->h_root = au_hi(dir, a->btgt);
23135 + ii_read_unlock(dir);
23136 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23139 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23140 + a->dst_h_parent, a->dst_hdir);
23141 + udba = au_opt_udba(a->src_dentry->d_sb);
23142 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23143 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23144 + err = au_busy_or_stale();
23145 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23146 + err = au_h_verify(a->src_h_dentry, udba,
23147 + d_inode(a->src_h_parent), a->src_h_parent,
23149 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23150 + err = au_h_verify(a->dst_h_dentry, udba,
23151 + d_inode(a->dst_h_parent), a->dst_h_parent,
23154 + goto out; /* success */
23156 + err = au_busy_or_stale();
23157 + au_ren_unlock(a);
23163 +/* ---------------------------------------------------------------------- */
23165 +static void au_ren_refresh_dir(struct au_ren_args *a)
23167 + struct inode *dir;
23169 + dir = a->dst_dir;
23170 + inode_inc_iversion(dir);
23171 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23172 + /* is this updating defined in POSIX? */
23173 + au_cpup_attr_timesizes(a->src_inode);
23174 + au_cpup_attr_nlink(dir, /*force*/1);
23176 + au_dir_ts(dir, a->btgt);
23178 + if (a->exchange) {
23179 + dir = a->src_dir;
23180 + inode_inc_iversion(dir);
23181 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23182 + /* is this updating defined in POSIX? */
23183 + au_cpup_attr_timesizes(a->dst_inode);
23184 + au_cpup_attr_nlink(dir, /*force*/1);
23186 + au_dir_ts(dir, a->btgt);
23189 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23192 + dir = a->src_dir;
23193 + inode_inc_iversion(dir);
23194 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23195 + au_cpup_attr_nlink(dir, /*force*/1);
23196 + au_dir_ts(dir, a->btgt);
23199 +static void au_ren_refresh(struct au_ren_args *a)
23201 + aufs_bindex_t bbot, bindex;
23202 + struct dentry *d, *h_d;
23203 + struct inode *i, *h_i;
23204 + struct super_block *sb;
23206 + d = a->dst_dentry;
23209 + /* already dget-ed by au_ren_or_cpup() */
23210 + au_set_h_dptr(d, a->btgt, a->h_dst);
23212 + i = a->dst_inode;
23214 + if (!a->exchange) {
23215 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23216 + vfsub_drop_nlink(i);
23218 + vfsub_dead_dir(i);
23219 + au_cpup_attr_timesizes(i);
23221 + au_update_dbrange(d, /*do_put_zero*/1);
23223 + au_cpup_attr_nlink(i, /*force*/1);
23226 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23227 + au_set_h_dptr(d, bindex, NULL);
23228 + bbot = au_dbbot(d);
23229 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23230 + au_set_h_dptr(d, bindex, NULL);
23231 + au_update_dbrange(d, /*do_put_zero*/0);
23235 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23236 + d_drop(a->src_dentry);
23237 + if (au_ftest_ren(a->auren_flags, DIRREN))
23238 + au_set_dbwh(a->src_dentry, -1);
23242 + d = a->src_dentry;
23243 + au_set_dbwh(d, -1);
23244 + bbot = au_dbbot(d);
23245 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23246 + h_d = au_h_dptr(d, bindex);
23248 + au_set_h_dptr(d, bindex, NULL);
23250 + au_set_dbbot(d, a->btgt);
23253 + i = a->src_inode;
23254 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23255 + return; /* success */
23257 + bbot = au_ibbot(i);
23258 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23259 + h_i = au_h_iptr(i, bindex);
23261 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23262 + /* ignore this error */
23263 + au_set_h_iptr(i, bindex, NULL, 0);
23266 + au_set_ibbot(i, a->btgt);
23269 +/* ---------------------------------------------------------------------- */
23271 +/* mainly for link(2) and rename(2) */
23272 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23274 + aufs_bindex_t bdiropq, bwh;
23275 + struct dentry *parent;
23276 + struct au_branch *br;
23278 + parent = dentry->d_parent;
23279 + IMustLock(d_inode(parent)); /* dir is locked */
23281 + bdiropq = au_dbdiropq(parent);
23282 + bwh = au_dbwh(dentry);
23283 + br = au_sbr(dentry->d_sb, btgt);
23284 + if (au_br_rdonly(br)
23285 + || (0 <= bdiropq && bdiropq < btgt)
23286 + || (0 <= bwh && bwh < btgt))
23289 + AuDbg("btgt %d\n", btgt);
23293 +/* sets src_btop, dst_btop and btgt */
23294 +static int au_ren_wbr(struct au_ren_args *a)
23297 + struct au_wr_dir_args wr_dir_args = {
23298 + /* .force_btgt = -1, */
23299 + .flags = AuWrDir_ADD_ENTRY
23302 + a->src_btop = au_dbtop(a->src_dentry);
23303 + a->dst_btop = au_dbtop(a->dst_dentry);
23304 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23305 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23306 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23307 + wr_dir_args.force_btgt = a->src_btop;
23308 + if (a->dst_inode && a->dst_btop < a->src_btop)
23309 + wr_dir_args.force_btgt = a->dst_btop;
23310 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23311 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23314 + au_update_dbtop(a->dst_dentry);
23319 +static void au_ren_dt(struct au_ren_args *a)
23321 + a->h_path.dentry = a->src_h_parent;
23322 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23323 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23324 + a->h_path.dentry = a->dst_h_parent;
23325 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23328 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23329 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23333 + a->h_path.dentry = a->src_h_dentry;
23334 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23335 + if (d_is_positive(a->dst_h_dentry)) {
23336 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23337 + a->h_path.dentry = a->dst_h_dentry;
23338 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23342 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23344 + struct dentry *h_d;
23345 + struct inode *h_inode;
23347 + au_dtime_revert(a->src_dt + AuPARENT);
23348 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23349 + au_dtime_revert(a->dst_dt + AuPARENT);
23351 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23352 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23353 + h_inode = d_inode(h_d);
23354 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23355 + au_dtime_revert(a->src_dt + AuCHILD);
23356 + inode_unlock(h_inode);
23358 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23359 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23360 + h_inode = d_inode(h_d);
23361 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23362 + au_dtime_revert(a->dst_dt + AuCHILD);
23363 + inode_unlock(h_inode);
23368 +/* ---------------------------------------------------------------------- */
23370 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23371 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23372 + unsigned int _flags)
23374 + int err, lock_flags;
23376 + /* reduce stack space */
23377 + struct au_ren_args *a;
23378 + struct au_pin pin;
23380 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23381 + IMustLock(_src_dir);
23382 + IMustLock(_dst_dir);
23385 + if (unlikely(_flags & RENAME_WHITEOUT))
23389 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23390 + a = kzalloc(sizeof(*a), GFP_NOFS);
23391 + if (unlikely(!a))
23394 + a->flags = _flags;
23395 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23396 + && RENAME_EXCHANGE > U8_MAX);
23397 + a->exchange = _flags & RENAME_EXCHANGE;
23398 + a->src_dir = _src_dir;
23399 + a->src_dentry = _src_dentry;
23400 + a->src_inode = NULL;
23401 + if (d_really_is_positive(a->src_dentry))
23402 + a->src_inode = d_inode(a->src_dentry);
23403 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23404 + a->dst_dir = _dst_dir;
23405 + a->dst_dentry = _dst_dentry;
23406 + a->dst_inode = NULL;
23407 + if (d_really_is_positive(a->dst_dentry))
23408 + a->dst_inode = d_inode(a->dst_dentry);
23409 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23410 + if (a->dst_inode) {
23412 + * if EXCHANGE && src is non-dir && dst is dir,
23413 + * dst is not locked.
23415 + /* IMustLock(a->dst_inode); */
23416 + au_igrab(a->dst_inode);
23420 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23421 + if (d_is_dir(a->src_dentry)) {
23422 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23423 + if (unlikely(!a->exchange
23424 + && d_really_is_positive(a->dst_dentry)
23425 + && !d_is_dir(a->dst_dentry)))
23427 + lock_flags |= AuLock_DIRS;
23429 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23430 + au_fset_ren(a->auren_flags, ISDIR_DST);
23431 + if (unlikely(!a->exchange
23432 + && d_really_is_positive(a->src_dentry)
23433 + && !d_is_dir(a->src_dentry)))
23435 + lock_flags |= AuLock_DIRS;
23437 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23439 + if (unlikely(err))
23442 + err = au_d_hashed_positive(a->src_dentry);
23443 + if (unlikely(err))
23446 + if (a->dst_inode) {
23448 + * If it is a dir, VFS unhash it before this
23449 + * function. It means we cannot rely upon d_unhashed().
23451 + if (unlikely(!a->dst_inode->i_nlink))
23453 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23454 + err = au_d_hashed_positive(a->dst_dentry);
23455 + if (unlikely(err && !a->exchange))
23457 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23459 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23463 + * is it possible?
23464 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23465 + * there may exist a problem somewhere else.
23468 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23471 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23472 + di_write_lock_parent(a->dst_parent);
23474 + /* which branch we process */
23475 + err = au_ren_wbr(a);
23476 + if (unlikely(err < 0))
23478 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23479 + a->h_path.mnt = au_br_mnt(a->br);
23481 + /* are they available to be renamed */
23482 + err = au_ren_may_dir(a);
23483 + if (unlikely(err))
23484 + goto out_children;
23486 + /* prepare the writable parent dir on the same branch */
23487 + if (a->dst_btop == a->btgt) {
23488 + au_fset_ren(a->auren_flags, WHDST);
23490 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23491 + if (unlikely(err))
23492 + goto out_children;
23496 + if (!a->exchange) {
23497 + if (a->src_dir != a->dst_dir) {
23499 + * this temporary unlock is safe,
23500 + * because both dir->i_mutex are locked.
23502 + di_write_unlock(a->dst_parent);
23503 + di_write_lock_parent(a->src_parent);
23504 + err = au_wr_dir_need_wh(a->src_dentry,
23505 + au_ftest_ren(a->auren_flags,
23508 + di_write_unlock(a->src_parent);
23509 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23511 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23513 + err = au_wr_dir_need_wh(a->src_dentry,
23514 + au_ftest_ren(a->auren_flags,
23518 + if (unlikely(err < 0))
23519 + goto out_children;
23521 + au_fset_ren(a->auren_flags, WHSRC);
23524 + if (a->src_btop != a->btgt) {
23525 + err = au_pin(&pin, a->src_dentry, a->btgt,
23526 + au_opt_udba(a->src_dentry->d_sb),
23527 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23529 + struct au_cp_generic cpg = {
23530 + .dentry = a->src_dentry,
23532 + .bsrc = a->src_btop,
23535 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23537 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23538 + err = au_sio_cpup_simple(&cpg);
23541 + if (unlikely(err))
23542 + goto out_children;
23543 + a->src_btop = a->btgt;
23544 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23545 + if (!a->exchange)
23546 + au_fset_ren(a->auren_flags, WHSRC);
23550 + if (a->exchange && a->dst_inode
23551 + && a->dst_btop != a->btgt) {
23552 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23553 + au_opt_udba(a->dst_dentry->d_sb),
23554 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23556 + struct au_cp_generic cpg = {
23557 + .dentry = a->dst_dentry,
23559 + .bsrc = a->dst_btop,
23562 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23564 + err = au_sio_cpup_simple(&cpg);
23567 + if (unlikely(err))
23568 + goto out_children;
23569 + a->dst_btop = a->btgt;
23570 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23573 + /* lock them all */
23574 + err = au_ren_lock(a);
23575 + if (unlikely(err))
23576 + /* leave the copied-up one */
23577 + goto out_children;
23579 + if (!a->exchange) {
23580 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23581 + err = au_may_ren(a);
23582 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23583 + err = -ENAMETOOLONG;
23584 + if (unlikely(err))
23588 + /* store timestamps to be revertible */
23591 + /* store dirren info */
23592 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23593 + err = au_dr_rename(a->src_dentry, a->btgt,
23594 + &a->dst_dentry->d_name, &rev);
23596 + if (unlikely(err))
23601 + err = do_rename(a);
23602 + if (unlikely(err))
23605 + if (au_ftest_ren(a->auren_flags, DIRREN))
23606 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23608 + /* update dir attributes */
23609 + au_ren_refresh_dir(a);
23611 + /* dput/iput all lower dentries */
23612 + au_ren_refresh(a);
23614 + goto out_hdir; /* success */
23617 + if (au_ftest_ren(a->auren_flags, DIRREN))
23618 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23620 + au_ren_rev_dt(err, a);
23622 + au_ren_unlock(a);
23624 + au_nhash_wh_free(&a->whlist);
23625 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23626 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23627 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23628 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23632 + if (d_unhashed(a->src_dentry))
23633 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23634 + if (d_unhashed(a->dst_dentry))
23635 + au_fset_ren(a->auren_flags, DROPPED_DST);
23636 + if (!a->exchange)
23637 + d_move(a->src_dentry, a->dst_dentry);
23639 + d_exchange(a->src_dentry, a->dst_dentry);
23640 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23641 + d_drop(a->dst_dentry);
23643 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23644 + d_drop(a->src_dentry);
23646 + au_update_dbtop(a->dst_dentry);
23647 + if (!a->dst_inode)
23648 + d_drop(a->dst_dentry);
23650 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23651 + di_write_unlock(a->dst_parent);
23653 + di_write_unlock2(a->src_parent, a->dst_parent);
23655 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23657 + iput(a->dst_inode);
23659 + au_whtmp_rmdir_free(a->thargs);
23665 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23666 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23667 +++ linux/fs/aufs/Kconfig 2021-12-03 15:38:59.929980643 +0100
23669 +# SPDX-License-Identifier: GPL-2.0
23671 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23673 + Aufs is a stackable unification filesystem such as Unionfs,
23674 + which unifies several directories and provides a merged single
23676 + In the early days, aufs was entirely re-designed and
23677 + re-implemented Unionfs Version 1.x series. Introducing many
23678 + original ideas, approaches and improvements, it becomes totally
23679 + different from Unionfs while keeping the basic features.
23683 + prompt "Maximum number of branches"
23684 + default AUFS_BRANCH_MAX_127
23686 + Specifies the maximum number of branches (or member directories)
23687 + in a single aufs. The larger value consumes more system
23688 + resources and has a minor impact to performance.
23689 +config AUFS_BRANCH_MAX_127
23692 + Specifies the maximum number of branches (or member directories)
23693 + in a single aufs. The larger value consumes more system
23694 + resources and has a minor impact to performance.
23695 +config AUFS_BRANCH_MAX_511
23698 + Specifies the maximum number of branches (or member directories)
23699 + in a single aufs. The larger value consumes more system
23700 + resources and has a minor impact to performance.
23701 +config AUFS_BRANCH_MAX_1023
23704 + Specifies the maximum number of branches (or member directories)
23705 + in a single aufs. The larger value consumes more system
23706 + resources and has a minor impact to performance.
23707 +config AUFS_BRANCH_MAX_32767
23710 + Specifies the maximum number of branches (or member directories)
23711 + in a single aufs. The larger value consumes more system
23712 + resources and has a minor impact to performance.
23715 +config AUFS_SBILIST
23717 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23720 + Automatic configuration for internal use.
23721 + When aufs supports Magic SysRq or /proc, enabled automatically.
23723 +config AUFS_HNOTIFY
23724 + bool "Detect direct branch access (bypassing aufs)"
23726 + If you want to modify files on branches directly, eg. bypassing aufs,
23727 + and want aufs to detect the changes of them fully, then enable this
23728 + option and use 'udba=notify' mount option.
23729 + Currently there is only one available configuration, "fsnotify".
23730 + It will have a negative impact to the performance.
23731 + See detail in aufs.5.
23734 + prompt "method" if AUFS_HNOTIFY
23735 + default AUFS_HFSNOTIFY
23736 +config AUFS_HFSNOTIFY
23741 +config AUFS_EXPORT
23742 + bool "NFS-exportable aufs"
23743 + depends on EXPORTFS
23745 + If you want to export your mounted aufs via NFS, then enable this
23746 + option. There are several requirements for this configuration.
23747 + See detail in aufs.5.
23749 +config AUFS_INO_T_64
23751 + depends on AUFS_EXPORT
23752 + depends on 64BIT && !(ALPHA || S390)
23755 + Automatic configuration for internal use.
23756 + /* typedef unsigned long/int __kernel_ino_t */
23757 + /* alpha and s390x are int */
23760 + bool "support for XATTR/EA (including Security Labels)"
23762 + If your branch fs supports XATTR/EA and you want to make them
23763 + available in aufs too, then enable this opsion and specify the
23764 + branch attributes for EA.
23765 + See detail in aufs.5.
23768 + bool "File-based Hierarchical Storage Management"
23770 + Hierarchical Storage Management (or HSM) is a well-known feature
23771 + in the storage world. Aufs provides this feature as file-based.
23772 + with multiple branches.
23773 + These multiple branches are prioritized, ie. the topmost one
23774 + should be the fastest drive and be used heavily.
23777 + bool "Readdir in userspace"
23779 + Aufs has two methods to provide a merged view for a directory,
23780 + by a user-space library and by kernel-space natively. The latter
23781 + is always enabled but sometimes large and slow.
23782 + If you enable this option, install the library in aufs2-util
23783 + package, and set some environment variables for your readdir(3),
23784 + then the work will be handled in user-space which generally
23785 + shows better performance in most cases.
23786 + See detail in aufs.5.
23788 +config AUFS_DIRREN
23789 + bool "Workaround for rename(2)-ing a directory"
23791 + By default, aufs returns EXDEV error in renameing a dir who has
23792 + his child on the lower branch, since it is a bad idea to issue
23793 + rename(2) internally for every lower branch. But user may not
23794 + accept this behaviour. So here is a workaround to allow such
23795 + rename(2) and store some extra infromation on the writable
23796 + branch. Obviously this costs high (and I don't like it).
23797 + To use this feature, you need to enable this configuration AND
23798 + to specify the mount option `dirren.'
23799 + See details in aufs.5 and the design documents.
23802 + bool "Show whiteouts"
23804 + If you want to make the whiteouts in aufs visible, then enable
23805 + this option and specify 'shwh' mount option. Although it may
23806 + sounds like philosophy or something, but in technically it
23807 + simply shows the name of whiteout with keeping its behaviour.
23809 +config AUFS_BR_RAMFS
23810 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23812 + If you want to use ramfs as an aufs branch fs, then enable this
23813 + option. Generally tmpfs is recommended.
23814 + Aufs prohibited them to be a branch fs by default, because
23815 + initramfs becomes unusable after switch_root or something
23816 + generally. If you sets initramfs as an aufs branch and boot your
23817 + system by switch_root, you will meet a problem easily since the
23818 + files in initramfs may be inaccessible.
23819 + Unless you are going to use ramfs as an aufs branch fs without
23820 + switch_root or something, leave it N.
23822 +config AUFS_BR_FUSE
23823 + bool "Fuse fs as an aufs branch"
23824 + depends on FUSE_FS
23827 + If you want to use fuse-based userspace filesystem as an aufs
23828 + branch fs, then enable this option.
23829 + It implements the internal poll(2) operation which is
23830 + implemented by fuse only (curretnly).
23835 + Automatic configuration for internal use.
23837 +config AUFS_BR_HFSPLUS
23838 + bool "Hfsplus as an aufs branch"
23839 + depends on HFSPLUS_FS
23842 + If you want to use hfsplus fs as an aufs branch fs, then enable
23843 + this option. This option introduces a small overhead at
23844 + copying-up a file on hfsplus.
23846 +config AUFS_BDEV_LOOP
23848 + depends on BLK_DEV_LOOP
23851 + Automatic configuration for internal use.
23852 + Convert =[ym] into =y.
23855 + bool "Debug aufs"
23857 + Enable this to compile aufs internal debug code.
23858 + It will have a negative impact to the performance.
23860 +config AUFS_MAGIC_SYSRQ
23862 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23865 + Automatic configuration for internal use.
23866 + When aufs supports Magic SysRq, enabled automatically.
23868 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23869 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23870 +++ linux/fs/aufs/lcnt.h 2021-12-03 15:38:59.936647310 +0100
23872 +/* SPDX-License-Identifier: GPL-2.0 */
23874 + * Copyright (C) 2018-2021 Junjiro R. Okajima
23876 + * This program, aufs is free software; you can redistribute it and/or modify
23877 + * it under the terms of the GNU General Public License as published by
23878 + * the Free Software Foundation; either version 2 of the License, or
23879 + * (at your option) any later version.
23881 + * This program is distributed in the hope that it will be useful,
23882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23884 + * GNU General Public License for more details.
23886 + * You should have received a copy of the GNU General Public License
23887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23891 + * simple long counter wrapper
23894 +#ifndef __AUFS_LCNT_H__
23895 +#define __AUFS_LCNT_H__
23899 +#include "debug.h"
23901 +#define AuLCntATOMIC 1
23902 +#define AuLCntPCPUCNT 2
23904 + * why does percpu_refcount require extra synchronize_rcu()s in
23905 + * au_br_do_free()
23907 +#define AuLCntPCPUREF 3
23909 +/* #define AuLCntChosen AuLCntATOMIC */
23910 +#define AuLCntChosen AuLCntPCPUCNT
23911 +/* #define AuLCntChosen AuLCntPCPUREF */
23913 +#if AuLCntChosen == AuLCntATOMIC
23914 +#include <linux/atomic.h>
23916 +typedef atomic_long_t au_lcnt_t;
23918 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23920 + atomic_long_set(cnt, 0);
23924 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23929 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
23930 + int do_sync __maybe_unused)
23935 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
23937 + atomic_long_inc(cnt);
23940 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
23942 + atomic_long_dec(cnt);
23945 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
23947 + return atomic_long_read(cnt);
23951 +#if AuLCntChosen == AuLCntPCPUCNT
23952 +#include <linux/percpu_counter.h>
23954 +typedef struct percpu_counter au_lcnt_t;
23956 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23958 + return percpu_counter_init(cnt, 0, GFP_NOFS);
23961 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23966 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
23968 + percpu_counter_destroy(cnt);
23971 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
23973 + percpu_counter_inc(cnt);
23976 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
23978 + percpu_counter_dec(cnt);
23981 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
23985 + n = percpu_counter_sum(cnt);
23987 + if (LONG_MAX != LLONG_MAX
23989 + AuWarn1("%s\n", "wrap-around");
23995 +#if AuLCntChosen == AuLCntPCPUREF
23996 +#include <linux/percpu-refcount.h>
23998 +typedef struct percpu_ref au_lcnt_t;
24000 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24003 + release = percpu_ref_exit;
24004 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24007 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24009 + synchronize_rcu();
24012 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24014 + percpu_ref_kill(cnt);
24016 + au_lcnt_wait_for_fin(cnt);
24019 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24021 + percpu_ref_get(cnt);
24024 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24026 + percpu_ref_put(cnt);
24030 + * avoid calling this func as possible.
24032 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24036 + percpu_ref_switch_to_atomic_sync(cnt);
24037 + l = atomic_long_read(&cnt->count);
24039 + percpu_ref_switch_to_percpu(cnt);
24041 + /* percpu_ref is initialized by 1 instead of 0 */
24046 +#ifdef CONFIG_AUFS_DEBUG
24047 +#define AuLCntZero(val) do { \
24050 + AuDbg("%s = %ld\n", #val, l); \
24053 +#define AuLCntZero(val) do {} while (0)
24056 +#endif /* __KERNEL__ */
24057 +#endif /* __AUFS_LCNT_H__ */
24058 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24059 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24060 +++ linux/fs/aufs/loop.c 2021-12-03 15:38:59.936647310 +0100
24062 +// SPDX-License-Identifier: GPL-2.0
24064 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24066 + * This program, aufs is free software; you can redistribute it and/or modify
24067 + * it under the terms of the GNU General Public License as published by
24068 + * the Free Software Foundation; either version 2 of the License, or
24069 + * (at your option) any later version.
24071 + * This program is distributed in the hope that it will be useful,
24072 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24073 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24074 + * GNU General Public License for more details.
24076 + * You should have received a copy of the GNU General Public License
24077 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24081 + * support for loopback block device as a branch
24086 +/* added into drivers/block/loop.c */
24087 +static struct file *(*backing_file_func)(struct super_block *sb);
24090 + * test if two lower dentries have overlapping branches.
24092 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24094 + struct super_block *h_sb;
24095 + struct file *backing_file;
24097 + if (unlikely(!backing_file_func)) {
24098 + /* don't load "loop" module here */
24099 + backing_file_func = symbol_get(loop_backing_file);
24100 + if (unlikely(!backing_file_func))
24101 + /* "loop" module is not loaded */
24105 + h_sb = h_adding->d_sb;
24106 + backing_file = backing_file_func(h_sb);
24107 + if (!backing_file)
24110 + h_adding = backing_file->f_path.dentry;
24112 + * h_adding can be local NFS.
24113 + * in this case aufs cannot detect the loop.
24115 + if (unlikely(h_adding->d_sb == sb))
24117 + return !!au_test_subdir(h_adding, sb->s_root);
24120 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24121 +int au_test_loopback_kthread(void)
24124 + struct task_struct *tsk = current;
24125 + char c, comm[sizeof(tsk->comm)];
24128 + if (tsk->flags & PF_KTHREAD) {
24129 + get_task_comm(comm, tsk);
24131 + ret = ('0' <= c && c <= '9'
24132 + && !strncmp(comm, "loop", 4));
24138 +/* ---------------------------------------------------------------------- */
24140 +#define au_warn_loopback_step 16
24141 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24142 +static unsigned long *au_warn_loopback_array;
24144 +void au_warn_loopback(struct super_block *h_sb)
24146 + int i, new_nelem;
24147 + unsigned long *a, magic;
24148 + static DEFINE_SPINLOCK(spin);
24150 + magic = h_sb->s_magic;
24151 + spin_lock(&spin);
24152 + a = au_warn_loopback_array;
24153 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24154 + if (a[i] == magic) {
24155 + spin_unlock(&spin);
24159 + /* h_sb is new to us, print it */
24160 + if (i < au_warn_loopback_nelem) {
24165 + /* expand the array */
24166 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24167 + a = au_kzrealloc(au_warn_loopback_array,
24168 + au_warn_loopback_nelem * sizeof(unsigned long),
24169 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24170 + /*may_shrink*/0);
24172 + au_warn_loopback_nelem = new_nelem;
24173 + au_warn_loopback_array = a;
24178 + spin_unlock(&spin);
24179 + AuWarn1("realloc failed, ignored\n");
24183 + spin_unlock(&spin);
24184 + pr_warn("you may want to try another patch for loopback file "
24185 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24188 +int au_loopback_init(void)
24191 + struct super_block *sb __maybe_unused;
24193 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24196 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24197 + sizeof(unsigned long), GFP_NOFS);
24198 + if (unlikely(!au_warn_loopback_array))
24204 +void au_loopback_fin(void)
24206 + if (backing_file_func)
24207 + symbol_put(loop_backing_file);
24208 + au_kfree_try_rcu(au_warn_loopback_array);
24210 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24211 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24212 +++ linux/fs/aufs/loop.h 2021-12-03 15:38:59.936647310 +0100
24214 +/* SPDX-License-Identifier: GPL-2.0 */
24216 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24218 + * This program, aufs is free software; you can redistribute it and/or modify
24219 + * it under the terms of the GNU General Public License as published by
24220 + * the Free Software Foundation; either version 2 of the License, or
24221 + * (at your option) any later version.
24223 + * This program is distributed in the hope that it will be useful,
24224 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24225 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24226 + * GNU General Public License for more details.
24228 + * You should have received a copy of the GNU General Public License
24229 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24233 + * support for loopback mount as a branch
24236 +#ifndef __AUFS_LOOP_H__
24237 +#define __AUFS_LOOP_H__
24242 +struct super_block;
24244 +#ifdef CONFIG_AUFS_BDEV_LOOP
24245 +/* drivers/block/loop.c */
24246 +struct file *loop_backing_file(struct super_block *sb);
24249 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24250 +int au_test_loopback_kthread(void);
24251 +void au_warn_loopback(struct super_block *h_sb);
24253 +int au_loopback_init(void);
24254 +void au_loopback_fin(void);
24256 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24258 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24259 + struct dentry *h_adding)
24260 +AuStubInt0(au_test_loopback_kthread, void)
24261 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24263 +AuStubInt0(au_loopback_init, void)
24264 +AuStubVoid(au_loopback_fin, void)
24265 +#endif /* BLK_DEV_LOOP */
24267 +#endif /* __KERNEL__ */
24268 +#endif /* __AUFS_LOOP_H__ */
24269 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24270 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24271 +++ linux/fs/aufs/magic.mk 2021-12-03 15:38:59.936647310 +0100
24273 +# SPDX-License-Identifier: GPL-2.0
24275 +# defined in ${srctree}/fs/fuse/inode.c
24277 +ifdef CONFIG_FUSE_FS
24278 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24281 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24283 +ifdef CONFIG_XFS_FS
24284 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24287 +# defined in ${srctree}/fs/configfs/mount.c
24289 +ifdef CONFIG_CONFIGFS_FS
24290 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24293 +# defined in ${srctree}/fs/ubifs/ubifs.h
24295 +ifdef CONFIG_UBIFS_FS
24296 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24299 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24301 +ifdef CONFIG_HFSPLUS_FS
24302 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24304 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24305 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24306 +++ linux/fs/aufs/Makefile 2021-12-03 15:38:59.929980643 +0100
24308 +# SPDX-License-Identifier: GPL-2.0
24310 +include ${src}/magic.mk
24311 +ifeq (${CONFIG_AUFS_FS},m)
24312 +include ${src}/conf.mk
24314 +-include ${src}/priv_def.mk
24316 +# cf. include/linux/kernel.h
24318 +ccflags-y += -DDEBUG
24319 +# sparse requires the full pathname
24321 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24323 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24326 +obj-$(CONFIG_AUFS_FS) += aufs.o
24327 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24328 + wkq.o vfsub.o dcsub.o \
24329 + cpup.o whout.o wbr_policy.o \
24330 + dinfo.o dentry.o \
24332 + finfo.o file.o f_op.o \
24334 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24338 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24339 +aufs-$(CONFIG_SYSFS) += sysfs.o
24340 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24341 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24342 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24343 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24344 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24345 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24346 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24347 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24348 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24349 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24350 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24351 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24352 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24353 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24354 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24355 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24356 +++ linux/fs/aufs/module.c 2021-12-03 15:38:59.936647310 +0100
24358 +// SPDX-License-Identifier: GPL-2.0
24360 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24362 + * This program, aufs is free software; you can redistribute it and/or modify
24363 + * it under the terms of the GNU General Public License as published by
24364 + * the Free Software Foundation; either version 2 of the License, or
24365 + * (at your option) any later version.
24367 + * This program is distributed in the hope that it will be useful,
24368 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24369 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24370 + * GNU General Public License for more details.
24372 + * You should have received a copy of the GNU General Public License
24373 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24377 + * module global variables and operations
24380 +#include <linux/module.h>
24381 +#include <linux/seq_file.h>
24384 +/* shrinkable realloc */
24385 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24393 +#if 0 /* unused */
24400 + AuDebugOn(!new_sz);
24403 + diff = au_kmidx_sub(sz, new_sz);
24409 + /* expand or SLOB */
24410 + p = krealloc(p, new_sz, gfp);
24411 + else if (new_sz < sz && may_shrink) {
24415 + q = kmalloc(new_sz, gfp);
24418 + memcpy(q, p, new_sz);
24419 + au_kfree_try_rcu(p);
24430 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24433 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24434 + if (p && new_sz > nused)
24435 + memset(p + nused, 0, new_sz - nused);
24439 +/* ---------------------------------------------------------------------- */
24443 +struct kmem_cache *au_cache[AuCache_Last];
24445 +static void au_cache_fin(void)
24450 + * Make sure all delayed rcu free inodes are flushed before we
24455 + /* excluding AuCache_HNOTIFY */
24456 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24457 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24458 + kmem_cache_destroy(au_cache[i]);
24459 + au_cache[i] = NULL;
24463 +static int __init au_cache_init(void)
24465 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24466 + if (au_cache[AuCache_DINFO])
24467 + /* SLAB_DESTROY_BY_RCU */
24468 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24469 + au_icntnr_init_once);
24470 + if (au_cache[AuCache_ICNTNR])
24471 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24472 + au_fi_init_once);
24473 + if (au_cache[AuCache_FINFO])
24474 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24475 + if (au_cache[AuCache_VDIR])
24476 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24477 + if (au_cache[AuCache_DEHSTR])
24484 +/* ---------------------------------------------------------------------- */
24486 +int au_dir_roflags;
24488 +#ifdef CONFIG_AUFS_SBILIST
24490 + * iterate_supers_type() doesn't protect us from
24491 + * remounting (branch management)
24493 +struct hlist_bl_head au_sbilist;
24497 + * functions for module interface.
24499 +MODULE_LICENSE("GPL");
24500 +/* MODULE_LICENSE("GPL v2"); */
24501 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24502 +MODULE_DESCRIPTION(AUFS_NAME
24503 + " -- Advanced multi layered unification filesystem");
24504 +MODULE_VERSION(AUFS_VERSION);
24505 +MODULE_ALIAS_FS(AUFS_NAME);
24507 +/* this module parameter has no meaning when SYSFS is disabled */
24508 +int sysaufs_brs = 1;
24509 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24510 +module_param_named(brs, sysaufs_brs, int, 0444);
24512 +/* this module parameter has no meaning when USER_NS is disabled */
24514 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24515 +module_param_named(allow_userns, au_userns, bool, 0444);
24517 +/* ---------------------------------------------------------------------- */
24519 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24521 +int au_seq_path(struct seq_file *seq, struct path *path)
24525 + err = seq_path(seq, path, au_esc_chars);
24534 +/* ---------------------------------------------------------------------- */
24536 +static int __init aufs_init(void)
24541 + p = au_esc_chars;
24542 + for (i = 1; i <= ' '; i++)
24548 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24550 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24551 + for (i = 0; i < AuIop_Last; i++)
24552 + aufs_iop_nogetattr[i].getattr = NULL;
24554 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24556 + au_sbilist_init();
24557 + sysaufs_brs_init();
24560 + err = sysaufs_init();
24561 + if (unlikely(err))
24563 + err = dbgaufs_init();
24564 + if (unlikely(err))
24565 + goto out_sysaufs;
24566 + err = au_procfs_init();
24567 + if (unlikely(err))
24568 + goto out_dbgaufs;
24569 + err = au_wkq_init();
24570 + if (unlikely(err))
24572 + err = au_loopback_init();
24573 + if (unlikely(err))
24575 + err = au_hnotify_init();
24576 + if (unlikely(err))
24577 + goto out_loopback;
24578 + err = au_sysrq_init();
24579 + if (unlikely(err))
24581 + err = au_cache_init();
24582 + if (unlikely(err))
24585 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24586 + err = register_filesystem(&aufs_fs_type);
24587 + if (unlikely(err))
24590 + /* since we define pr_fmt, call printk directly */
24591 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24592 + goto out; /* success */
24599 + au_hnotify_fin();
24601 + au_loopback_fin();
24615 +static void __exit aufs_exit(void)
24617 + unregister_filesystem(&aufs_fs_type);
24620 + au_hnotify_fin();
24621 + au_loopback_fin();
24629 +module_init(aufs_init);
24630 +module_exit(aufs_exit);
24631 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24632 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24633 +++ linux/fs/aufs/module.h 2021-12-03 15:38:59.936647310 +0100
24635 +/* SPDX-License-Identifier: GPL-2.0 */
24637 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24639 + * This program, aufs is free software; you can redistribute it and/or modify
24640 + * it under the terms of the GNU General Public License as published by
24641 + * the Free Software Foundation; either version 2 of the License, or
24642 + * (at your option) any later version.
24644 + * This program is distributed in the hope that it will be useful,
24645 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24646 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24647 + * GNU General Public License for more details.
24649 + * You should have received a copy of the GNU General Public License
24650 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24654 + * module initialization and module-global
24657 +#ifndef __AUFS_MODULE_H__
24658 +#define __AUFS_MODULE_H__
24662 +#include <linux/slab.h>
24663 +#include "debug.h"
24664 +#include "dentry.h"
24667 +#include "inode.h"
24672 +/* module parameters */
24673 +extern int sysaufs_brs;
24674 +extern bool au_userns;
24676 +/* ---------------------------------------------------------------------- */
24678 +extern int au_dir_roflags;
24680 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24681 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24685 + * Comparing the size of the object with sizeof(struct rcu_head)
24686 + * case 1: object is always larger
24687 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24688 + * case 2: object is always smaller
24689 + * --> au_kfree_small()
24690 + * case 3: object can be any size
24691 + * --> au_kfree_try_rcu()
24694 +static inline void au_kfree_do_rcu(const void *p)
24697 + struct rcu_head rcu;
24698 + } *a = (void *)p;
24700 + kfree_rcu(a, rcu);
24703 +#define au_kfree_rcu(_p) do { \
24704 + typeof(_p) p = (_p); \
24705 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24707 + au_kfree_do_rcu(p); \
24710 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24711 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24713 +static inline void au_kfree_try_rcu(const void *p)
24717 + if (au_kfree_sz_test(p))
24718 + au_kfree_do_rcu(p);
24723 +static inline void au_kfree_small(const void *p)
24727 + AuDebugOn(au_kfree_sz_test(p));
24731 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24733 +#ifndef CONFIG_SLOB
24734 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24736 + return -1; /* SLOB is untested */
24740 +int au_seq_path(struct seq_file *seq, struct path *path);
24742 +#ifdef CONFIG_PROC_FS
24744 +int __init au_procfs_init(void);
24745 +void au_procfs_fin(void);
24747 +AuStubInt0(au_procfs_init, void);
24748 +AuStubVoid(au_procfs_fin, void);
24751 +/* ---------------------------------------------------------------------- */
24760 + AuCache_HNOTIFY, /* must be last */
24764 +extern struct kmem_cache *au_cache[AuCache_Last];
24766 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24767 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24768 +#define AuCacheCtor(type, ctor) \
24769 + kmem_cache_create(#type, sizeof(struct type), \
24770 + __alignof__(struct type), AuCacheFlags, ctor)
24772 +#define AuCacheFuncs(name, index) \
24773 + static inline struct au_##name *au_cache_alloc_##name(void) \
24774 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24775 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24776 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24778 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24779 + { void *p = rcu; \
24780 + p -= offsetof(struct au_##name, rcu); \
24781 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24782 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24783 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24784 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24786 + static inline void au_cache_free_##name(struct au_##name *p) \
24787 + { /* au_cache_free_##name##_norcu(p); */ \
24788 + au_cache_free_##name##_rcu(p); }
24790 +AuCacheFuncs(dinfo, DINFO);
24791 +AuCacheFuncs(icntnr, ICNTNR);
24792 +AuCacheFuncs(finfo, FINFO);
24793 +AuCacheFuncs(vdir, VDIR);
24794 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24795 +#ifdef CONFIG_AUFS_HNOTIFY
24796 +AuCacheFuncs(hnotify, HNOTIFY);
24799 +#endif /* __KERNEL__ */
24800 +#endif /* __AUFS_MODULE_H__ */
24801 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24802 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24803 +++ linux/fs/aufs/mvdown.c 2021-12-03 15:38:59.939980643 +0100
24805 +// SPDX-License-Identifier: GPL-2.0
24807 + * Copyright (C) 2011-2021 Junjiro R. Okajima
24809 + * This program, aufs is free software; you can redistribute it and/or modify
24810 + * it under the terms of the GNU General Public License as published by
24811 + * the Free Software Foundation; either version 2 of the License, or
24812 + * (at your option) any later version.
24814 + * This program is distributed in the hope that it will be useful,
24815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24817 + * GNU General Public License for more details.
24819 + * You should have received a copy of the GNU General Public License
24820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24824 + * move-down, opposite of copy-up
24829 +struct au_mvd_args {
24831 + struct super_block *h_sb;
24832 + struct dentry *h_parent;
24833 + struct au_hinode *hdir;
24834 + struct inode *h_dir, *h_inode;
24835 + struct au_pin pin;
24836 + } info[AUFS_MVDOWN_NARRAY];
24838 + struct aufs_mvdown mvdown;
24839 + struct dentry *dentry, *parent;
24840 + struct inode *inode, *dir;
24841 + struct super_block *sb;
24842 + aufs_bindex_t bopq, bwh, bfound;
24843 + unsigned char rename_lock;
24846 +#define mvd_errno mvdown.au_errno
24847 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24848 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24849 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24850 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24852 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24853 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24854 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24855 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24856 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24857 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24859 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24860 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24861 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24862 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24863 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24864 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24866 +#define AU_MVD_PR(flag, ...) do { \
24868 + pr_err(__VA_ARGS__); \
24871 +static int find_lower_writable(struct au_mvd_args *a)
24873 + struct super_block *sb;
24874 + aufs_bindex_t bindex, bbot;
24875 + struct au_branch *br;
24878 + bindex = a->mvd_bsrc;
24879 + bbot = au_sbbot(sb);
24880 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24881 + for (bindex++; bindex <= bbot; bindex++) {
24882 + br = au_sbr(sb, bindex);
24883 + if (au_br_fhsm(br->br_perm)
24884 + && !sb_rdonly(au_br_sb(br)))
24887 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24888 + for (bindex++; bindex <= bbot; bindex++) {
24889 + br = au_sbr(sb, bindex);
24890 + if (!au_br_rdonly(br))
24894 + for (bindex++; bindex <= bbot; bindex++) {
24895 + br = au_sbr(sb, bindex);
24896 + if (!sb_rdonly(au_br_sb(br))) {
24897 + if (au_br_rdonly(br))
24899 + |= AUFS_MVDOWN_ROLOWER_R;
24907 +/* make the parent dir on bdst */
24908 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24913 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24914 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24915 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24916 + a->mvd_h_dst_parent = NULL;
24917 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24918 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24919 + if (!a->mvd_h_dst_parent) {
24920 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24921 + if (unlikely(err)) {
24922 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24925 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24933 +/* lock them all */
24934 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24937 + struct dentry *h_trap;
24939 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24940 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24941 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24942 + au_opt_udba(a->sb),
24943 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24945 + if (unlikely(err)) {
24946 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24950 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24951 + a->rename_lock = 0;
24952 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24953 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24954 + au_opt_udba(a->sb),
24955 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24956 + err = au_do_pin(&a->mvd_pin_src);
24958 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24959 + if (unlikely(err)) {
24960 + AU_MVD_PR(dmsg, "pin_src failed\n");
24963 + goto out; /* success */
24966 + a->rename_lock = 1;
24967 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24968 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24969 + au_opt_udba(a->sb),
24970 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24972 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24973 + if (unlikely(err)) {
24974 + AU_MVD_PR(dmsg, "pin_src failed\n");
24975 + au_pin_hdir_lock(&a->mvd_pin_dst);
24978 + au_pin_hdir_unlock(&a->mvd_pin_src);
24979 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24980 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24982 + err = (h_trap != a->mvd_h_src_parent);
24984 + err = (h_trap != a->mvd_h_dst_parent);
24986 + BUG_ON(err); /* it should never happen */
24987 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
24990 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
24991 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
24992 + au_pin_hdir_lock(&a->mvd_pin_src);
24993 + au_unpin(&a->mvd_pin_src);
24994 + au_pin_hdir_lock(&a->mvd_pin_dst);
24997 + goto out; /* success */
25000 + au_unpin(&a->mvd_pin_dst);
25006 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25008 + if (!a->rename_lock)
25009 + au_unpin(&a->mvd_pin_src);
25011 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25012 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25013 + au_pin_hdir_lock(&a->mvd_pin_src);
25014 + au_unpin(&a->mvd_pin_src);
25015 + au_pin_hdir_lock(&a->mvd_pin_dst);
25017 + au_unpin(&a->mvd_pin_dst);
25020 +/* copy-down the file */
25021 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25024 + struct au_cp_generic cpg = {
25025 + .dentry = a->dentry,
25026 + .bdst = a->mvd_bdst,
25027 + .bsrc = a->mvd_bsrc,
25029 + .pin = &a->mvd_pin_dst,
25030 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25033 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25034 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25035 + au_fset_cpup(cpg.flags, OVERWRITE);
25036 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25037 + au_fset_cpup(cpg.flags, RWDST);
25038 + err = au_sio_cpdown_simple(&cpg);
25039 + if (unlikely(err))
25040 + AU_MVD_PR(dmsg, "cpdown failed\n");
25047 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25050 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25053 + struct path h_path;
25054 + struct au_branch *br;
25055 + struct inode *delegated;
25057 + br = au_sbr(a->sb, a->mvd_bdst);
25058 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25059 + err = PTR_ERR(h_path.dentry);
25060 + if (IS_ERR(h_path.dentry)) {
25061 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25066 + if (d_is_positive(h_path.dentry)) {
25067 + h_path.mnt = au_br_mnt(br);
25068 + delegated = NULL;
25069 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25070 + &delegated, /*force*/0);
25071 + if (unlikely(err == -EWOULDBLOCK)) {
25072 + pr_warn("cannot retry for NFSv4 delegation"
25073 + " for an internal unlink\n");
25076 + if (unlikely(err))
25077 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25079 + dput(h_path.dentry);
25087 + * unlink the topmost h_dentry
25089 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25092 + struct path h_path;
25093 + struct inode *delegated;
25095 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25096 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25097 + delegated = NULL;
25098 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25099 + if (unlikely(err == -EWOULDBLOCK)) {
25100 + pr_warn("cannot retry for NFSv4 delegation"
25101 + " for an internal unlink\n");
25104 + if (unlikely(err))
25105 + AU_MVD_PR(dmsg, "unlink failed\n");
25111 +/* Since mvdown succeeded, we ignore an error of this function */
25112 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25115 + struct au_branch *br;
25117 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25118 + br = au_sbr(a->sb, a->mvd_bsrc);
25119 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25121 + br = au_sbr(a->sb, a->mvd_bdst);
25122 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25123 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25126 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25128 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25132 + * copy-down the file and unlink the bsrc file.
25133 + * - unlink the bdst whout if exist
25134 + * - copy-down the file (with whtmp name and rename)
25135 + * - unlink the bsrc file
25137 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25141 + err = au_do_mkdir(dmsg, a);
25143 + err = au_do_lock(dmsg, a);
25144 + if (unlikely(err))
25148 + * do not revert the activities we made on bdst since they should be
25149 + * harmless in aufs.
25152 + err = au_do_cpdown(dmsg, a);
25154 + err = au_do_unlink_wh(dmsg, a);
25155 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25156 + err = au_do_unlink(dmsg, a);
25157 + if (unlikely(err))
25160 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25161 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25162 + if (find_lower_writable(a) < 0)
25163 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25165 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25166 + au_do_stfs(dmsg, a);
25168 + /* maintain internal array */
25169 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25170 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25171 + au_set_dbtop(a->dentry, a->mvd_bdst);
25172 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25173 + au_set_ibtop(a->inode, a->mvd_bdst);
25175 + /* hide the lower */
25176 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25177 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25178 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25179 + au_set_ibbot(a->inode, a->mvd_bsrc);
25181 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25182 + au_set_dbbot(a->dentry, a->mvd_bdst);
25183 + if (au_ibbot(a->inode) < a->mvd_bdst)
25184 + au_set_ibbot(a->inode, a->mvd_bdst);
25187 + au_do_unlock(dmsg, a);
25193 +/* ---------------------------------------------------------------------- */
25195 +/* make sure the file is idle */
25196 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25198 + int err, plinked;
25201 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25202 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25203 + && au_dcount(a->dentry) == 1
25204 + && atomic_read(&a->inode->i_count) == 1
25205 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25206 + && (!plinked || !au_plink_test(a->inode))
25207 + && a->inode->i_nlink == 1)
25212 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25213 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25214 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25215 + a->mvd_h_src_inode->i_nlink,
25216 + plinked, plinked ? au_plink_test(a->inode) : 0);
25223 +/* make sure the parent dir is fine */
25224 +static int au_mvd_args_parent(const unsigned char dmsg,
25225 + struct au_mvd_args *a)
25228 + aufs_bindex_t bindex;
25231 + if (unlikely(au_alive_dir(a->parent))) {
25233 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25237 + a->bopq = au_dbdiropq(a->parent);
25238 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25239 + AuDbg("b%d\n", bindex);
25240 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25241 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25243 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25244 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25245 + a->bopq, a->mvd_bdst);
25253 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25254 + struct au_mvd_args *a)
25257 + struct au_dinfo *dinfo, *tmp;
25259 + /* lookup the next lower positive entry */
25261 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25262 + if (unlikely(!tmp))
25267 + dinfo = au_di(a->dentry);
25268 + au_di_cp(tmp, dinfo);
25269 + au_di_swap(tmp, dinfo);
25271 + /* returns the number of positive dentries */
25272 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25273 + /* AuLkup_IGNORE_PERM */ 0);
25275 + a->bwh = au_dbwh(a->dentry);
25276 + else if (err > 0)
25277 + a->bfound = au_dbtop(a->dentry);
25279 + au_di_swap(tmp, dinfo);
25280 + au_rw_write_unlock(&tmp->di_rwsem);
25282 + if (unlikely(err < 0))
25283 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25286 + * here, we have these cases.
25288 + * no positive dentry under bsrc. there are more sub-cases.
25290 + * there no whiteout, we can safely move-down.
25293 + * bsrc < bwh && bwh < bdst
25294 + * there is a whiteout on RO branch. cannot proceed.
25296 + * there is a whiteout on the RW target branch. it should
25299 + * there is a whiteout somewhere unrelated branch.
25300 + * -1 < bfound && bfound <= bsrc
25303 + * found, but it is on RO branch between bsrc and bdst. cannot
25306 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25309 + * found, after we create the file on bdst, it will be hidden.
25312 + AuDebugOn(a->bfound == -1
25314 + && a->bwh <= a->mvd_bsrc);
25315 + AuDebugOn(-1 < a->bfound
25316 + && a->bfound <= a->mvd_bsrc);
25319 + if (a->bfound == -1
25320 + && a->mvd_bsrc < a->bwh
25322 + && a->bwh < a->mvd_bdst) {
25323 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25324 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25325 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25327 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25328 + a->mvd_errno = EAU_MVDOWN_UPPER;
25329 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25330 + a->mvd_bdst, a->bfound);
25334 + err = 0; /* success */
25341 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25346 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25347 + && a->bfound == a->mvd_bdst)
25353 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25356 + struct au_branch *br;
25359 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25363 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25364 + a->mvd_bsrc = au_ibtop(a->inode);
25366 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25367 + if (unlikely(a->mvd_bsrc < 0
25368 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25369 + || au_dbbot(a->dentry) < a->mvd_bsrc
25370 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25371 + || (a->mvd_bsrc < au_ibtop(a->inode)
25372 + || au_ibbot(a->inode) < a->mvd_bsrc
25373 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25374 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25375 + AU_MVD_PR(dmsg, "no upper\n");
25379 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25380 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25381 + AU_MVD_PR(dmsg, "on the bottom\n");
25384 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25385 + br = au_sbr(a->sb, a->mvd_bsrc);
25386 + err = au_br_rdonly(br);
25387 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25388 + if (unlikely(err))
25390 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25391 + || IS_APPEND(a->mvd_h_src_inode))) {
25393 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25399 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25400 + a->mvd_bdst = find_lower_writable(a);
25401 + if (unlikely(a->mvd_bdst < 0)) {
25402 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25403 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25407 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25408 + if (unlikely(a->mvd_bdst < 0
25409 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25410 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25411 + AU_MVD_PR(dmsg, "no lower brid\n");
25416 + err = au_mvd_args_busy(dmsg, a);
25418 + err = au_mvd_args_parent(dmsg, a);
25420 + err = au_mvd_args_intermediate(dmsg, a);
25422 + err = au_mvd_args_exist(dmsg, a);
25424 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25431 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25434 + unsigned char dmsg;
25435 + struct au_mvd_args *args;
25436 + struct inode *inode;
25438 + inode = d_inode(dentry);
25440 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25444 + args = kmalloc(sizeof(*args), GFP_NOFS);
25445 + if (unlikely(!args))
25448 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25450 + /* VERIFY_WRITE */
25451 + err = !access_ok(uarg, sizeof(*uarg));
25452 + if (unlikely(err)) {
25457 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25458 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25459 + args->mvdown.au_errno = 0;
25460 + args->dentry = dentry;
25461 + args->inode = inode;
25462 + args->sb = dentry->d_sb;
25465 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25466 + args->parent = dget_parent(dentry);
25467 + args->dir = d_inode(args->parent);
25468 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25469 + dput(args->parent);
25470 + if (unlikely(args->parent != dentry->d_parent)) {
25471 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25475 + inode_lock_nested(inode, I_MUTEX_CHILD);
25476 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25477 + if (unlikely(err))
25480 + di_write_lock_parent(args->parent);
25481 + err = au_mvd_args(dmsg, args);
25482 + if (unlikely(err))
25485 + err = au_do_mvdown(dmsg, args);
25486 + if (unlikely(err))
25489 + au_cpup_attr_timesizes(args->dir);
25490 + au_cpup_attr_timesizes(inode);
25491 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25492 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25493 + /* au_digen_dec(dentry); */
25496 + di_write_unlock(args->parent);
25497 + aufs_read_unlock(dentry, AuLock_DW);
25499 + inode_unlock(inode);
25501 + inode_unlock(args->dir);
25503 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25506 + au_kfree_rcu(args);
25511 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25512 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25513 +++ linux/fs/aufs/opts.c 2021-12-03 15:38:59.939980643 +0100
25515 +// SPDX-License-Identifier: GPL-2.0
25517 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25519 + * This program, aufs is free software; you can redistribute it and/or modify
25520 + * it under the terms of the GNU General Public License as published by
25521 + * the Free Software Foundation; either version 2 of the License, or
25522 + * (at your option) any later version.
25524 + * This program is distributed in the hope that it will be useful,
25525 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25526 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25527 + * GNU General Public License for more details.
25529 + * You should have received a copy of the GNU General Public License
25530 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25534 + * mount options/flags
25537 +#include <linux/namei.h>
25538 +#include <linux/types.h> /* a distribution requires */
25539 +#include <linux/parser.h>
25542 +/* ---------------------------------------------------------------------- */
25546 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25547 + Opt_idel, Opt_imod,
25548 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25549 + Opt_rdblk_def, Opt_rdhash_def,
25550 + Opt_xino, Opt_noxino,
25551 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25552 + Opt_trunc_xino_path, Opt_itrunc_xino,
25553 + Opt_trunc_xib, Opt_notrunc_xib,
25554 + Opt_shwh, Opt_noshwh,
25555 + Opt_plink, Opt_noplink, Opt_list_plink,
25557 + Opt_dio, Opt_nodio,
25558 + Opt_diropq_a, Opt_diropq_w,
25559 + Opt_warn_perm, Opt_nowarn_perm,
25560 + Opt_wbr_copyup, Opt_wbr_create,
25562 + Opt_verbose, Opt_noverbose,
25563 + Opt_sum, Opt_nosum, Opt_wsum,
25564 + Opt_dirperm1, Opt_nodirperm1,
25565 + Opt_dirren, Opt_nodirren,
25566 + Opt_acl, Opt_noacl,
25567 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25570 +static match_table_t options = {
25571 + {Opt_br, "br=%s"},
25572 + {Opt_br, "br:%s"},
25574 + {Opt_add, "add=%d:%s"},
25575 + {Opt_add, "add:%d:%s"},
25576 + {Opt_add, "ins=%d:%s"},
25577 + {Opt_add, "ins:%d:%s"},
25578 + {Opt_append, "append=%s"},
25579 + {Opt_append, "append:%s"},
25580 + {Opt_prepend, "prepend=%s"},
25581 + {Opt_prepend, "prepend:%s"},
25583 + {Opt_del, "del=%s"},
25584 + {Opt_del, "del:%s"},
25585 + /* {Opt_idel, "idel:%d"}, */
25586 + {Opt_mod, "mod=%s"},
25587 + {Opt_mod, "mod:%s"},
25588 + /* {Opt_imod, "imod:%d:%s"}, */
25590 + {Opt_dirwh, "dirwh=%d"},
25592 + {Opt_xino, "xino=%s"},
25593 + {Opt_noxino, "noxino"},
25594 + {Opt_trunc_xino, "trunc_xino"},
25595 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25596 + {Opt_notrunc_xino, "notrunc_xino"},
25597 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25598 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25599 + /* {Opt_zxino, "zxino=%s"}, */
25600 + {Opt_trunc_xib, "trunc_xib"},
25601 + {Opt_notrunc_xib, "notrunc_xib"},
25603 +#ifdef CONFIG_PROC_FS
25604 + {Opt_plink, "plink"},
25606 + {Opt_ignore_silent, "plink"},
25609 + {Opt_noplink, "noplink"},
25611 +#ifdef CONFIG_AUFS_DEBUG
25612 + {Opt_list_plink, "list_plink"},
25615 + {Opt_udba, "udba=%s"},
25617 + {Opt_dio, "dio"},
25618 + {Opt_nodio, "nodio"},
25620 +#ifdef CONFIG_AUFS_DIRREN
25621 + {Opt_dirren, "dirren"},
25622 + {Opt_nodirren, "nodirren"},
25624 + {Opt_ignore, "dirren"},
25625 + {Opt_ignore_silent, "nodirren"},
25628 +#ifdef CONFIG_AUFS_FHSM
25629 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25631 + {Opt_ignore, "fhsm_sec=%d"},
25634 + {Opt_diropq_a, "diropq=always"},
25635 + {Opt_diropq_a, "diropq=a"},
25636 + {Opt_diropq_w, "diropq=whiteouted"},
25637 + {Opt_diropq_w, "diropq=w"},
25639 + {Opt_warn_perm, "warn_perm"},
25640 + {Opt_nowarn_perm, "nowarn_perm"},
25642 + /* keep them temporary */
25643 + {Opt_ignore_silent, "nodlgt"},
25644 + {Opt_ignore, "clean_plink"},
25646 +#ifdef CONFIG_AUFS_SHWH
25647 + {Opt_shwh, "shwh"},
25649 + {Opt_noshwh, "noshwh"},
25651 + {Opt_dirperm1, "dirperm1"},
25652 + {Opt_nodirperm1, "nodirperm1"},
25654 + {Opt_verbose, "verbose"},
25655 + {Opt_verbose, "v"},
25656 + {Opt_noverbose, "noverbose"},
25657 + {Opt_noverbose, "quiet"},
25658 + {Opt_noverbose, "q"},
25659 + {Opt_noverbose, "silent"},
25661 + {Opt_sum, "sum"},
25662 + {Opt_nosum, "nosum"},
25663 + {Opt_wsum, "wsum"},
25665 + {Opt_rdcache, "rdcache=%d"},
25666 + {Opt_rdblk, "rdblk=%d"},
25667 + {Opt_rdblk_def, "rdblk=def"},
25668 + {Opt_rdhash, "rdhash=%d"},
25669 + {Opt_rdhash_def, "rdhash=def"},
25671 + {Opt_wbr_create, "create=%s"},
25672 + {Opt_wbr_create, "create_policy=%s"},
25673 + {Opt_wbr_copyup, "cpup=%s"},
25674 + {Opt_wbr_copyup, "copyup=%s"},
25675 + {Opt_wbr_copyup, "copyup_policy=%s"},
25677 + /* generic VFS flag */
25678 +#ifdef CONFIG_FS_POSIX_ACL
25679 + {Opt_acl, "acl"},
25680 + {Opt_noacl, "noacl"},
25682 + {Opt_ignore, "acl"},
25683 + {Opt_ignore_silent, "noacl"},
25686 + /* internal use for the scripts */
25687 + {Opt_ignore_silent, "si=%s"},
25689 + {Opt_br, "dirs=%s"},
25690 + {Opt_ignore, "debug=%d"},
25691 + {Opt_ignore, "delete=whiteout"},
25692 + {Opt_ignore, "delete=all"},
25693 + {Opt_ignore, "imap=%s"},
25695 + /* temporary workaround, due to old mount(8)? */
25696 + {Opt_ignore_silent, "relatime"},
25701 +/* ---------------------------------------------------------------------- */
25703 +static const char *au_parser_pattern(int val, match_table_t tbl)
25705 + struct match_token *p;
25708 + while (p->pattern) {
25709 + if (p->token == val)
25710 + return p->pattern;
25717 +static const char *au_optstr(int *val, match_table_t tbl)
25719 + struct match_token *p;
25726 + while (p->pattern) {
25728 + && (v & p->token) == p->token) {
25729 + *val &= ~p->token;
25730 + return p->pattern;
25739 +/* ---------------------------------------------------------------------- */
25741 +static match_table_t brperm = {
25742 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25743 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25744 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25748 +static match_table_t brattr = {
25750 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25751 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25752 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25753 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25754 +#ifdef CONFIG_AUFS_FHSM
25755 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25757 +#ifdef CONFIG_AUFS_XATTR
25758 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25759 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25760 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25761 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25762 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25763 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25766 + /* ro/rr branch */
25767 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25770 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25771 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25776 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25783 + p = strchr(str, '+');
25786 + v = match_token(str, table, args);
25788 + if (v & AuBrAttr_CMOO_Mask)
25789 + attr &= ~AuBrAttr_CMOO_Mask;
25794 + pr_warn("ignored branch attribute %s\n", str);
25804 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25812 + p = au_optstr(&perm, brattr);
25815 + memcpy(q, p, sz + 1);
25821 + p = au_optstr(&perm, brattr);
25825 + memcpy(q, p, sz + 1);
25831 + return q - str->a;
25834 +static int noinline_for_stack br_perm_val(char *perm)
25836 + int val, bad, sz;
25838 + substring_t args[MAX_OPT_ARGS];
25839 + au_br_perm_str_t attr;
25841 + p = strchr(perm, '+');
25844 + val = match_token(perm, brperm, args);
25848 + pr_warn("ignored branch permission %s\n", perm);
25849 + val = AuBrPerm_RO;
25855 + val |= br_attr_val(p + 1, brattr, args);
25858 + switch (val & AuBrPerm_Mask) {
25859 + case AuBrPerm_RO:
25860 + case AuBrPerm_RR:
25861 + bad = val & AuBrWAttr_Mask;
25862 + val &= ~AuBrWAttr_Mask;
25864 + case AuBrPerm_RW:
25865 + bad = val & AuBrRAttr_Mask;
25866 + val &= ~AuBrRAttr_Mask;
25871 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25872 + * does not treat it as an error, just warning.
25873 + * this is a tiny guard for the user operation.
25875 + if (val & AuBrAttr_UNPIN) {
25876 + bad |= AuBrAttr_UNPIN;
25877 + val &= ~AuBrAttr_UNPIN;
25880 + if (unlikely(bad)) {
25881 + sz = au_do_optstr_br_attr(&attr, bad);
25883 + pr_warn("ignored branch attribute %s\n", attr.a);
25890 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25892 + au_br_perm_str_t attr;
25898 + p = au_optstr(&perm, brperm);
25899 + AuDebugOn(!p || !*p);
25901 + memcpy(q, p, sz + 1);
25904 + sz = au_do_optstr_br_attr(&attr, perm);
25907 + memcpy(q, attr.a, sz + 1);
25910 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25913 +/* ---------------------------------------------------------------------- */
25915 +static match_table_t udbalevel = {
25916 + {AuOpt_UDBA_REVAL, "reval"},
25917 + {AuOpt_UDBA_NONE, "none"},
25918 +#ifdef CONFIG_AUFS_HNOTIFY
25919 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25920 +#ifdef CONFIG_AUFS_HFSNOTIFY
25921 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25927 +static int noinline_for_stack udba_val(char *str)
25929 + substring_t args[MAX_OPT_ARGS];
25931 + return match_token(str, udbalevel, args);
25934 +const char *au_optstr_udba(int udba)
25936 + return au_parser_pattern(udba, udbalevel);
25939 +/* ---------------------------------------------------------------------- */
25941 +static match_table_t au_wbr_create_policy = {
25942 + {AuWbrCreate_TDP, "tdp"},
25943 + {AuWbrCreate_TDP, "top-down-parent"},
25944 + {AuWbrCreate_RR, "rr"},
25945 + {AuWbrCreate_RR, "round-robin"},
25946 + {AuWbrCreate_MFS, "mfs"},
25947 + {AuWbrCreate_MFS, "most-free-space"},
25948 + {AuWbrCreate_MFSV, "mfs:%d"},
25949 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25951 + /* top-down regardless the parent, and then mfs */
25952 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25953 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25955 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25956 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25957 + {AuWbrCreate_PMFS, "pmfs"},
25958 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25959 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25960 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25965 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25966 + struct au_opt_wbr_create *create)
25969 + unsigned long long ull;
25972 + if (!match_u64(arg, &ull))
25973 + create->mfsrr_watermark = ull;
25975 + pr_err("bad integer in %s\n", str);
25982 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
25983 + struct au_opt_wbr_create *create)
25988 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
25989 + create->mfs_second = n;
25991 + pr_err("bad integer in %s\n", str);
25998 +static int noinline_for_stack
25999 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26002 + substring_t args[MAX_OPT_ARGS];
26004 + err = match_token(str, au_wbr_create_policy, args);
26005 + create->wbr_create = err;
26007 + case AuWbrCreate_MFSRRV:
26008 + case AuWbrCreate_TDMFSV:
26009 + case AuWbrCreate_PMFSRRV:
26010 + e = au_wbr_mfs_wmark(&args[0], str, create);
26012 + e = au_wbr_mfs_sec(&args[1], str, create);
26016 + case AuWbrCreate_MFSRR:
26017 + case AuWbrCreate_TDMFS:
26018 + case AuWbrCreate_PMFSRR:
26019 + e = au_wbr_mfs_wmark(&args[0], str, create);
26020 + if (unlikely(e)) {
26025 + case AuWbrCreate_MFS:
26026 + case AuWbrCreate_PMFS:
26027 + create->mfs_second = AUFS_MFS_DEF_SEC;
26029 + case AuWbrCreate_MFSV:
26030 + case AuWbrCreate_PMFSV:
26031 + e = au_wbr_mfs_sec(&args[0], str, create);
26040 +const char *au_optstr_wbr_create(int wbr_create)
26042 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26045 +static match_table_t au_wbr_copyup_policy = {
26046 + {AuWbrCopyup_TDP, "tdp"},
26047 + {AuWbrCopyup_TDP, "top-down-parent"},
26048 + {AuWbrCopyup_BUP, "bup"},
26049 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26050 + {AuWbrCopyup_BU, "bu"},
26051 + {AuWbrCopyup_BU, "bottom-up"},
26055 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26057 + substring_t args[MAX_OPT_ARGS];
26059 + return match_token(str, au_wbr_copyup_policy, args);
26062 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26064 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26067 +/* ---------------------------------------------------------------------- */
26069 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26071 +static void dump_opts(struct au_opts *opts)
26073 +#ifdef CONFIG_AUFS_DEBUG
26074 + /* reduce stack space */
26076 + struct au_opt_add *add;
26077 + struct au_opt_del *del;
26078 + struct au_opt_mod *mod;
26079 + struct au_opt_xino *xino;
26080 + struct au_opt_xino_itrunc *xino_itrunc;
26081 + struct au_opt_wbr_create *create;
26083 + struct au_opt *opt;
26086 + while (opt->type != Opt_tail) {
26087 + switch (opt->type) {
26089 + u.add = &opt->add;
26090 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26091 + u.add->bindex, u.add->pathname, u.add->perm,
26092 + u.add->path.dentry);
26096 + u.del = &opt->del;
26097 + AuDbg("del {%s, %p}\n",
26098 + u.del->pathname, u.del->h_path.dentry);
26102 + u.mod = &opt->mod;
26103 + AuDbg("mod {%s, 0x%x, %p}\n",
26104 + u.mod->path, u.mod->perm, u.mod->h_root);
26107 + u.add = &opt->add;
26108 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26109 + u.add->bindex, u.add->pathname, u.add->perm,
26110 + u.add->path.dentry);
26112 + case Opt_prepend:
26113 + u.add = &opt->add;
26114 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26115 + u.add->bindex, u.add->pathname, u.add->perm,
26116 + u.add->path.dentry);
26119 + AuDbg("dirwh %d\n", opt->dirwh);
26121 + case Opt_rdcache:
26122 + AuDbg("rdcache %d\n", opt->rdcache);
26125 + AuDbg("rdblk %u\n", opt->rdblk);
26127 + case Opt_rdblk_def:
26128 + AuDbg("rdblk_def\n");
26131 + AuDbg("rdhash %u\n", opt->rdhash);
26133 + case Opt_rdhash_def:
26134 + AuDbg("rdhash_def\n");
26137 + u.xino = &opt->xino;
26138 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26140 + case Opt_trunc_xino:
26141 + AuLabel(trunc_xino);
26143 + case Opt_notrunc_xino:
26144 + AuLabel(notrunc_xino);
26146 + case Opt_trunc_xino_path:
26147 + case Opt_itrunc_xino:
26148 + u.xino_itrunc = &opt->xino_itrunc;
26149 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26154 + case Opt_trunc_xib:
26155 + AuLabel(trunc_xib);
26157 + case Opt_notrunc_xib:
26158 + AuLabel(notrunc_xib);
26166 + case Opt_dirperm1:
26167 + AuLabel(dirperm1);
26169 + case Opt_nodirperm1:
26170 + AuLabel(nodirperm1);
26175 + case Opt_noplink:
26176 + AuLabel(noplink);
26178 + case Opt_list_plink:
26179 + AuLabel(list_plink);
26182 + AuDbg("udba %d, %s\n",
26183 + opt->udba, au_optstr_udba(opt->udba));
26191 + case Opt_diropq_a:
26192 + AuLabel(diropq_a);
26194 + case Opt_diropq_w:
26195 + AuLabel(diropq_w);
26197 + case Opt_warn_perm:
26198 + AuLabel(warn_perm);
26200 + case Opt_nowarn_perm:
26201 + AuLabel(nowarn_perm);
26203 + case Opt_verbose:
26204 + AuLabel(verbose);
26206 + case Opt_noverbose:
26207 + AuLabel(noverbose);
26218 + case Opt_wbr_create:
26219 + u.create = &opt->wbr_create;
26220 + AuDbg("create %d, %s\n", u.create->wbr_create,
26221 + au_optstr_wbr_create(u.create->wbr_create));
26222 + switch (u.create->wbr_create) {
26223 + case AuWbrCreate_MFSV:
26224 + case AuWbrCreate_PMFSV:
26225 + AuDbg("%d sec\n", u.create->mfs_second);
26227 + case AuWbrCreate_MFSRR:
26228 + case AuWbrCreate_TDMFS:
26229 + AuDbg("%llu watermark\n",
26230 + u.create->mfsrr_watermark);
26232 + case AuWbrCreate_MFSRRV:
26233 + case AuWbrCreate_TDMFSV:
26234 + case AuWbrCreate_PMFSRRV:
26235 + AuDbg("%llu watermark, %d sec\n",
26236 + u.create->mfsrr_watermark,
26237 + u.create->mfs_second);
26241 + case Opt_wbr_copyup:
26242 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26243 + au_optstr_wbr_copyup(opt->wbr_copyup));
26245 + case Opt_fhsm_sec:
26246 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26251 + case Opt_nodirren:
26252 + AuLabel(nodirren);
26268 +void au_opts_free(struct au_opts *opts)
26270 + struct au_opt *opt;
26273 + while (opt->type != Opt_tail) {
26274 + switch (opt->type) {
26277 + case Opt_prepend:
26278 + path_put(&opt->add.path);
26282 + path_put(&opt->del.h_path);
26286 + dput(opt->mod.h_root);
26289 + fput(opt->xino.file);
26296 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26297 + aufs_bindex_t bindex)
26300 + struct au_opt_add *add = &opt->add;
26303 + add->bindex = bindex;
26304 + add->perm = AuBrPerm_RO;
26305 + add->pathname = opt_str;
26306 + p = strchr(opt_str, '=');
26310 + add->perm = br_perm_val(p);
26313 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26316 + add->perm = AuBrPerm_RO;
26317 + if (au_test_fs_rr(add->path.dentry->d_sb))
26318 + add->perm = AuBrPerm_RR;
26319 + else if (!bindex && !(sb_flags & SB_RDONLY))
26320 + add->perm = AuBrPerm_RW;
26322 + opt->type = Opt_add;
26325 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26332 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26336 + del->pathname = args[0].from;
26337 + AuDbg("del path %s\n", del->pathname);
26339 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26340 + if (unlikely(err))
26341 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26346 +#if 0 /* reserved for future use */
26347 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26348 + struct au_opt_del *del, substring_t args[])
26351 + struct dentry *root;
26354 + root = sb->s_root;
26355 + aufs_read_lock(root, AuLock_FLUSH);
26356 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26357 + pr_err("out of bounds, %d\n", bindex);
26362 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26363 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26366 + aufs_read_unlock(root, !AuLock_IR);
26371 +static int noinline_for_stack
26372 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26375 + struct path path;
26379 + mod->path = args[0].from;
26380 + p = strchr(mod->path, '=');
26381 + if (unlikely(!p)) {
26382 + pr_err("no permission %s\n", args[0].from);
26387 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26388 + if (unlikely(err)) {
26389 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26393 + mod->perm = br_perm_val(p);
26394 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26395 + mod->h_root = dget(path.dentry);
26402 +#if 0 /* reserved for future use */
26403 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26404 + struct au_opt_mod *mod, substring_t args[])
26407 + struct dentry *root;
26410 + root = sb->s_root;
26411 + aufs_read_lock(root, AuLock_FLUSH);
26412 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26413 + pr_err("out of bounds, %d\n", bindex);
26418 + mod->perm = br_perm_val(args[1].from);
26419 + AuDbg("mod path %s, perm 0x%x, %s\n",
26420 + mod->path, mod->perm, args[1].from);
26421 + mod->h_root = dget(au_h_dptr(root, bindex));
26424 + aufs_read_unlock(root, !AuLock_IR);
26429 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26430 + substring_t args[])
26433 + struct file *file;
26435 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26436 + err = PTR_ERR(file);
26437 + if (IS_ERR(file))
26441 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26443 + pr_err("%s must be outside\n", args[0].from);
26448 + xino->file = file;
26449 + xino->path = args[0].from;
26455 +static int noinline_for_stack
26456 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26457 + struct au_opt_xino_itrunc *xino_itrunc,
26458 + substring_t args[])
26461 + aufs_bindex_t bbot, bindex;
26462 + struct path path;
26463 + struct dentry *root;
26465 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26466 + if (unlikely(err)) {
26467 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26471 + xino_itrunc->bindex = -1;
26472 + root = sb->s_root;
26473 + aufs_read_lock(root, AuLock_FLUSH);
26474 + bbot = au_sbbot(sb);
26475 + for (bindex = 0; bindex <= bbot; bindex++) {
26476 + if (au_h_dptr(root, bindex) == path.dentry) {
26477 + xino_itrunc->bindex = bindex;
26481 + aufs_read_unlock(root, !AuLock_IR);
26484 + if (unlikely(xino_itrunc->bindex < 0)) {
26485 + pr_err("no such branch %s\n", args[0].from);
26493 +/* called without aufs lock */
26494 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26496 + int err, n, token;
26497 + aufs_bindex_t bindex;
26498 + unsigned char skipped;
26499 + struct dentry *root;
26500 + struct au_opt *opt, *opt_tail;
26502 + /* reduce the stack space */
26504 + struct au_opt_xino_itrunc *xino_itrunc;
26505 + struct au_opt_wbr_create *create;
26508 + substring_t args[MAX_OPT_ARGS];
26512 + a = kmalloc(sizeof(*a), GFP_NOFS);
26513 + if (unlikely(!a))
26516 + root = sb->s_root;
26520 + opt_tail = opt + opts->max_opt - 1;
26521 + opt->type = Opt_tail;
26522 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26525 + token = match_token(opt_str, options, a->args);
26529 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26531 + err = opt_add(opt, opt_str, opts->sb_flags,
26533 + if (unlikely(!err && ++opt > opt_tail)) {
26537 + opt->type = Opt_tail;
26542 + if (unlikely(match_int(&a->args[0], &n))) {
26543 + pr_err("bad integer in %s\n", opt_str);
26547 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26550 + opt->type = token;
26553 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26554 + /*dummy bindex*/1);
26556 + opt->type = token;
26558 + case Opt_prepend:
26559 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26562 + opt->type = token;
26565 + err = au_opts_parse_del(&opt->del, a->args);
26567 + opt->type = token;
26569 +#if 0 /* reserved for future use */
26571 + del->pathname = "(indexed)";
26572 + if (unlikely(match_int(&args[0], &n))) {
26573 + pr_err("bad integer in %s\n", opt_str);
26576 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26578 + opt->type = token;
26582 + err = au_opts_parse_mod(&opt->mod, a->args);
26584 + opt->type = token;
26586 +#ifdef IMOD /* reserved for future use */
26588 + u.mod->path = "(indexed)";
26589 + if (unlikely(match_int(&a->args[0], &n))) {
26590 + pr_err("bad integer in %s\n", opt_str);
26593 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26595 + opt->type = token;
26599 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26601 + opt->type = token;
26604 + case Opt_trunc_xino_path:
26605 + err = au_opts_parse_xino_itrunc_path
26606 + (sb, &opt->xino_itrunc, a->args);
26608 + opt->type = token;
26611 + case Opt_itrunc_xino:
26612 + u.xino_itrunc = &opt->xino_itrunc;
26613 + if (unlikely(match_int(&a->args[0], &n))) {
26614 + pr_err("bad integer in %s\n", opt_str);
26617 + u.xino_itrunc->bindex = n;
26618 + aufs_read_lock(root, AuLock_FLUSH);
26619 + if (n < 0 || au_sbbot(sb) < n) {
26620 + pr_err("out of bounds, %d\n", n);
26621 + aufs_read_unlock(root, !AuLock_IR);
26624 + aufs_read_unlock(root, !AuLock_IR);
26626 + opt->type = token;
26630 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26633 + opt->type = token;
26636 + case Opt_rdcache:
26637 + if (unlikely(match_int(&a->args[0], &n))) {
26638 + pr_err("bad integer in %s\n", opt_str);
26641 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26642 + pr_err("rdcache must be smaller than %d\n",
26643 + AUFS_RDCACHE_MAX);
26646 + opt->rdcache = n;
26648 + opt->type = token;
26651 + if (unlikely(match_int(&a->args[0], &n)
26653 + || n > KMALLOC_MAX_SIZE)) {
26654 + pr_err("bad integer in %s\n", opt_str);
26657 + if (unlikely(n && n < NAME_MAX)) {
26658 + pr_err("rdblk must be larger than %d\n",
26664 + opt->type = token;
26667 + if (unlikely(match_int(&a->args[0], &n)
26669 + || n * sizeof(struct hlist_head)
26670 + > KMALLOC_MAX_SIZE)) {
26671 + pr_err("bad integer in %s\n", opt_str);
26676 + opt->type = token;
26679 + case Opt_trunc_xino:
26680 + case Opt_notrunc_xino:
26682 + case Opt_trunc_xib:
26683 + case Opt_notrunc_xib:
26686 + case Opt_dirperm1:
26687 + case Opt_nodirperm1:
26689 + case Opt_noplink:
26690 + case Opt_list_plink:
26693 + case Opt_diropq_a:
26694 + case Opt_diropq_w:
26695 + case Opt_warn_perm:
26696 + case Opt_nowarn_perm:
26697 + case Opt_verbose:
26698 + case Opt_noverbose:
26702 + case Opt_rdblk_def:
26703 + case Opt_rdhash_def:
26705 + case Opt_nodirren:
26709 + opt->type = token;
26713 + opt->udba = udba_val(a->args[0].from);
26714 + if (opt->udba >= 0) {
26716 + opt->type = token;
26718 + pr_err("wrong value, %s\n", opt_str);
26721 + case Opt_wbr_create:
26722 + u.create = &opt->wbr_create;
26723 + u.create->wbr_create
26724 + = au_wbr_create_val(a->args[0].from, u.create);
26725 + if (u.create->wbr_create >= 0) {
26727 + opt->type = token;
26729 + pr_err("wrong value, %s\n", opt_str);
26731 + case Opt_wbr_copyup:
26732 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26733 + if (opt->wbr_copyup >= 0) {
26735 + opt->type = token;
26737 + pr_err("wrong value, %s\n", opt_str);
26740 + case Opt_fhsm_sec:
26741 + if (unlikely(match_int(&a->args[0], &n)
26743 + pr_err("bad integer in %s\n", opt_str);
26746 + if (sysaufs_brs) {
26747 + opt->fhsm_second = n;
26748 + opt->type = token;
26750 + pr_warn("ignored %s\n", opt_str);
26755 + pr_warn("ignored %s\n", opt_str);
26757 + case Opt_ignore_silent:
26762 + pr_err("unknown option %s\n", opt_str);
26766 + if (!err && !skipped) {
26767 + if (unlikely(++opt > opt_tail)) {
26770 + opt->type = Opt_tail;
26773 + opt->type = Opt_tail;
26779 + if (unlikely(err))
26780 + au_opts_free(opts);
26786 +static int au_opt_wbr_create(struct super_block *sb,
26787 + struct au_opt_wbr_create *create)
26790 + struct au_sbinfo *sbinfo;
26792 + SiMustWriteLock(sb);
26794 + err = 1; /* handled */
26795 + sbinfo = au_sbi(sb);
26796 + if (sbinfo->si_wbr_create_ops->fin) {
26797 + err = sbinfo->si_wbr_create_ops->fin(sb);
26802 + sbinfo->si_wbr_create = create->wbr_create;
26803 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26804 + switch (create->wbr_create) {
26805 + case AuWbrCreate_MFSRRV:
26806 + case AuWbrCreate_MFSRR:
26807 + case AuWbrCreate_TDMFS:
26808 + case AuWbrCreate_TDMFSV:
26809 + case AuWbrCreate_PMFSRR:
26810 + case AuWbrCreate_PMFSRRV:
26811 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26813 + case AuWbrCreate_MFS:
26814 + case AuWbrCreate_MFSV:
26815 + case AuWbrCreate_PMFS:
26816 + case AuWbrCreate_PMFSV:
26817 + sbinfo->si_wbr_mfs.mfs_expire
26818 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26822 + if (sbinfo->si_wbr_create_ops->init)
26823 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26830 + * plus: processed without an error
26831 + * zero: unprocessed
26833 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26834 + struct au_opts *opts)
26837 + struct au_sbinfo *sbinfo;
26839 + SiMustWriteLock(sb);
26841 + err = 1; /* handled */
26842 + sbinfo = au_sbi(sb);
26843 + switch (opt->type) {
26845 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26846 + sbinfo->si_mntflags |= opt->udba;
26847 + opts->given_udba |= opt->udba;
26851 + au_opt_set(sbinfo->si_mntflags, PLINK);
26853 + case Opt_noplink:
26854 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26855 + au_plink_put(sb, /*verbose*/1);
26856 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26858 + case Opt_list_plink:
26859 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26860 + au_plink_list(sb);
26864 + au_opt_set(sbinfo->si_mntflags, DIO);
26865 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26868 + au_opt_clr(sbinfo->si_mntflags, DIO);
26869 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26872 + case Opt_fhsm_sec:
26873 + au_fhsm_set(sbinfo, opt->fhsm_second);
26876 + case Opt_diropq_a:
26877 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26879 + case Opt_diropq_w:
26880 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26883 + case Opt_warn_perm:
26884 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26886 + case Opt_nowarn_perm:
26887 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26890 + case Opt_verbose:
26891 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26893 + case Opt_noverbose:
26894 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26898 + au_opt_set(sbinfo->si_mntflags, SUM);
26901 + au_opt_clr(sbinfo->si_mntflags, SUM);
26902 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26905 + au_opt_clr(sbinfo->si_mntflags, SUM);
26906 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26909 + case Opt_wbr_create:
26910 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26912 + case Opt_wbr_copyup:
26913 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26914 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26918 + sbinfo->si_dirwh = opt->dirwh;
26921 + case Opt_rdcache:
26922 + sbinfo->si_rdcache
26923 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26926 + sbinfo->si_rdblk = opt->rdblk;
26928 + case Opt_rdblk_def:
26929 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26932 + sbinfo->si_rdhash = opt->rdhash;
26934 + case Opt_rdhash_def:
26935 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26939 + au_opt_set(sbinfo->si_mntflags, SHWH);
26942 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26945 + case Opt_dirperm1:
26946 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26948 + case Opt_nodirperm1:
26949 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26952 + case Opt_trunc_xino:
26953 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26955 + case Opt_notrunc_xino:
26956 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26959 + case Opt_trunc_xino_path:
26960 + case Opt_itrunc_xino:
26961 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
26967 + case Opt_trunc_xib:
26968 + au_fset_opts(opts->flags, TRUNC_XIB);
26970 + case Opt_notrunc_xib:
26971 + au_fclr_opts(opts->flags, TRUNC_XIB);
26976 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26977 + err = au_dr_opt_set(sb);
26982 + au_opt_set(sbinfo->si_mntflags, DIRREN);
26984 + case Opt_nodirren:
26986 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
26987 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
26993 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
26997 + sb->s_flags |= SB_POSIXACL;
27000 + sb->s_flags &= ~SB_POSIXACL;
27012 + * returns tri-state.
27013 + * plus: processed without an error
27014 + * zero: unprocessed
27017 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27018 + struct au_opts *opts)
27020 + int err, do_refresh;
27023 + switch (opt->type) {
27025 + opt->add.bindex = au_sbbot(sb) + 1;
27026 + if (opt->add.bindex < 0)
27027 + opt->add.bindex = 0;
27029 + /* Always goto add, not fallthrough */
27030 + case Opt_prepend:
27031 + opt->add.bindex = 0;
27033 + add: /* indented label */
27035 + err = au_br_add(sb, &opt->add,
27036 + au_ftest_opts(opts->flags, REMOUNT));
27039 + au_fset_opts(opts->flags, REFRESH);
27045 + err = au_br_del(sb, &opt->del,
27046 + au_ftest_opts(opts->flags, REMOUNT));
27049 + au_fset_opts(opts->flags, TRUNC_XIB);
27050 + au_fset_opts(opts->flags, REFRESH);
27056 + err = au_br_mod(sb, &opt->mod,
27057 + au_ftest_opts(opts->flags, REMOUNT),
27062 + au_fset_opts(opts->flags, REFRESH);
27069 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27070 + struct au_opt_xino **opt_xino,
27071 + struct au_opts *opts)
27076 + switch (opt->type) {
27078 + err = au_xino_set(sb, &opt->xino,
27079 + !!au_ftest_opts(opts->flags, REMOUNT));
27080 + if (unlikely(err))
27083 + *opt_xino = &opt->xino;
27088 + *opt_xino = (void *)-1;
27095 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27096 + unsigned int pending)
27099 + aufs_bindex_t bindex, bbot;
27100 + unsigned char do_plink, skip, do_free, can_no_dreval;
27101 + struct au_branch *br;
27102 + struct au_wbr *wbr;
27103 + struct dentry *root, *dentry;
27104 + struct inode *dir, *h_dir;
27105 + struct au_sbinfo *sbinfo;
27106 + struct au_hinode *hdir;
27108 + SiMustAnyLock(sb);
27110 + sbinfo = au_sbi(sb);
27111 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27113 + if (!(sb_flags & SB_RDONLY)) {
27114 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27115 + pr_warn("first branch should be rw\n");
27116 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27117 + pr_warn_once("shwh should be used with ro\n");
27120 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27121 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27122 + pr_warn_once("udba=*notify requires xino\n");
27124 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27125 + pr_warn_once("dirperm1 breaks the protection"
27126 + " by the permission bits on the lower branch\n");
27130 + root = sb->s_root;
27131 + dir = d_inode(root);
27132 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27133 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27135 + bbot = au_sbbot(sb);
27136 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27138 + h_dir = au_h_iptr(dir, bindex);
27139 + br = au_sbr(sb, bindex);
27141 + if ((br->br_perm & AuBrAttr_ICEX)
27142 + && !h_dir->i_op->listxattr)
27143 + br->br_perm &= ~AuBrAttr_ICEX;
27144 +#if 0 /* untested */
27145 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27146 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27147 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27151 + wbr = br->br_wbr;
27153 + wbr_wh_read_lock(wbr);
27155 + if (!au_br_writable(br->br_perm)) {
27158 + || (!wbr->wbr_whbase
27159 + && !wbr->wbr_plink
27160 + && !wbr->wbr_orph));
27161 + } else if (!au_br_wh_linkable(br->br_perm)) {
27162 + /* skip = (!br->br_whbase && !br->br_orph); */
27163 + skip = (!wbr || !wbr->wbr_whbase);
27164 + if (skip && wbr) {
27166 + skip = !!wbr->wbr_plink;
27168 + skip = !wbr->wbr_plink;
27171 + /* skip = (br->br_whbase && br->br_ohph); */
27172 + skip = (wbr && wbr->wbr_whbase);
27175 + skip = !!wbr->wbr_plink;
27177 + skip = !wbr->wbr_plink;
27181 + wbr_wh_read_unlock(wbr);
27183 + if (can_no_dreval) {
27184 + dentry = br->br_path.dentry;
27185 + spin_lock(&dentry->d_lock);
27186 + if (dentry->d_flags &
27187 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27188 + can_no_dreval = 0;
27189 + spin_unlock(&dentry->d_lock);
27192 + if (au_br_fhsm(br->br_perm)) {
27194 + AuDebugOn(!br->br_fhsm);
27200 + hdir = au_hi(dir, bindex);
27201 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27203 + wbr_wh_write_lock(wbr);
27204 + err = au_wh_init(br, sb);
27206 + wbr_wh_write_unlock(wbr);
27207 + au_hn_inode_unlock(hdir);
27209 + if (!err && do_free) {
27210 + au_kfree_rcu(wbr);
27211 + br->br_wbr = NULL;
27215 + if (can_no_dreval)
27216 + au_fset_si(sbinfo, NO_DREVAL);
27218 + au_fclr_si(sbinfo, NO_DREVAL);
27221 + au_fset_si(sbinfo, FHSM);
27222 + for (bindex = bbot; bindex >= 0; bindex--) {
27223 + br = au_sbr(sb, bindex);
27224 + if (au_br_fhsm(br->br_perm)) {
27225 + au_fhsm_set_bottom(sb, bindex);
27230 + au_fclr_si(sbinfo, FHSM);
27231 + au_fhsm_set_bottom(sb, -1);
27237 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27240 + unsigned int tmp;
27241 + aufs_bindex_t bindex, bbot;
27242 + struct au_opt *opt;
27243 + struct au_opt_xino *opt_xino, xino;
27244 + struct au_sbinfo *sbinfo;
27245 + struct au_branch *br;
27246 + struct inode *dir;
27248 + SiMustWriteLock(sb);
27253 + while (err >= 0 && opt->type != Opt_tail)
27254 + err = au_opt_simple(sb, opt++, opts);
27257 + else if (unlikely(err < 0))
27260 + /* disable xino and udba temporary */
27261 + sbinfo = au_sbi(sb);
27262 + tmp = sbinfo->si_mntflags;
27263 + au_opt_clr(sbinfo->si_mntflags, XINO);
27264 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27267 + while (err >= 0 && opt->type != Opt_tail)
27268 + err = au_opt_br(sb, opt++, opts);
27271 + else if (unlikely(err < 0))
27274 + bbot = au_sbbot(sb);
27275 + if (unlikely(bbot < 0)) {
27277 + pr_err("no branches\n");
27281 + if (au_opt_test(tmp, XINO))
27282 + au_opt_set(sbinfo->si_mntflags, XINO);
27284 + while (!err && opt->type != Opt_tail)
27285 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27286 + if (unlikely(err))
27289 + err = au_opts_verify(sb, sb->s_flags, tmp);
27290 + if (unlikely(err))
27293 + /* restore xino */
27294 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27295 + xino.file = au_xino_def(sb);
27296 + err = PTR_ERR(xino.file);
27297 + if (IS_ERR(xino.file))
27300 + err = au_xino_set(sb, &xino, /*remount*/0);
27302 + if (unlikely(err))
27306 + /* restore udba */
27307 + tmp &= AuOptMask_UDBA;
27308 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27309 + sbinfo->si_mntflags |= tmp;
27310 + bbot = au_sbbot(sb);
27311 + for (bindex = 0; bindex <= bbot; bindex++) {
27312 + br = au_sbr(sb, bindex);
27313 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27314 + if (unlikely(err))
27315 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27317 + /* go on even if err */
27319 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27320 + dir = d_inode(sb->s_root);
27321 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27328 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27331 + unsigned char no_dreval;
27332 + struct inode *dir;
27333 + struct au_opt_xino *opt_xino;
27334 + struct au_opt *opt;
27335 + struct au_sbinfo *sbinfo;
27337 + SiMustWriteLock(sb);
27339 + err = au_dr_opt_flush(sb);
27340 + if (unlikely(err))
27342 + au_fset_opts(opts->flags, DR_FLUSHED);
27344 + dir = d_inode(sb->s_root);
27345 + sbinfo = au_sbi(sb);
27348 + while (err >= 0 && opt->type != Opt_tail) {
27349 + err = au_opt_simple(sb, opt, opts);
27351 + err = au_opt_br(sb, opt, opts);
27353 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27359 + /* go on even err */
27361 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27362 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27363 + if (unlikely(rerr && !err))
27366 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27367 + au_fset_opts(opts->flags, REFRESH_IDOP);
27369 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27370 + rerr = au_xib_trunc(sb);
27371 + if (unlikely(rerr && !err))
27375 + /* will be handled by the caller */
27376 + if (!au_ftest_opts(opts->flags, REFRESH)
27377 + && (opts->given_udba
27378 + || au_opt_test(sbinfo->si_mntflags, XINO)
27379 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27381 + au_fset_opts(opts->flags, REFRESH);
27383 + AuDbg("status 0x%x\n", opts->flags);
27389 +/* ---------------------------------------------------------------------- */
27391 +unsigned int au_opt_udba(struct super_block *sb)
27393 + return au_mntflags(sb) & AuOptMask_UDBA;
27395 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27396 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27397 +++ linux/fs/aufs/opts.h 2021-12-03 15:38:59.939980643 +0100
27399 +/* SPDX-License-Identifier: GPL-2.0 */
27401 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27403 + * This program, aufs is free software; you can redistribute it and/or modify
27404 + * it under the terms of the GNU General Public License as published by
27405 + * the Free Software Foundation; either version 2 of the License, or
27406 + * (at your option) any later version.
27408 + * This program is distributed in the hope that it will be useful,
27409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27411 + * GNU General Public License for more details.
27413 + * You should have received a copy of the GNU General Public License
27414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27418 + * mount options/flags
27421 +#ifndef __AUFS_OPTS_H__
27422 +#define __AUFS_OPTS_H__
27426 +#include <linux/path.h>
27430 +/* ---------------------------------------------------------------------- */
27433 +#define AuOpt_XINO 1 /* external inode number bitmap
27434 + and translation table */
27435 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27436 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27437 +#define AuOpt_UDBA_REVAL (1 << 3)
27438 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27439 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27440 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27441 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27443 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27444 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27445 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27446 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27447 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27448 +#define AuOpt_DIO (1 << 14) /* direct io */
27449 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27451 +#ifndef CONFIG_AUFS_HNOTIFY
27452 +#undef AuOpt_UDBA_HNOTIFY
27453 +#define AuOpt_UDBA_HNOTIFY 0
27455 +#ifndef CONFIG_AUFS_DIRREN
27456 +#undef AuOpt_DIRREN
27457 +#define AuOpt_DIRREN 0
27459 +#ifndef CONFIG_AUFS_SHWH
27461 +#define AuOpt_SHWH 0
27464 +#define AuOpt_Def (AuOpt_XINO \
27465 + | AuOpt_UDBA_REVAL \
27467 + /* | AuOpt_DIRPERM1 */ \
27468 + | AuOpt_WARN_PERM)
27469 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27470 + | AuOpt_UDBA_REVAL \
27471 + | AuOpt_UDBA_HNOTIFY)
27473 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27474 +#define au_opt_set(flags, name) do { \
27475 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27476 + ((flags) |= AuOpt_##name); \
27478 +#define au_opt_set_udba(flags, name) do { \
27479 + (flags) &= ~AuOptMask_UDBA; \
27480 + ((flags) |= AuOpt_##name); \
27482 +#define au_opt_clr(flags, name) do { \
27483 + ((flags) &= ~AuOpt_##name); \
27486 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27488 +#ifdef CONFIG_PROC_FS
27491 + return mntflags & ~AuOpt_PLINK;
27495 +/* ---------------------------------------------------------------------- */
27497 +/* policies to select one among multiple writable branches */
27499 + AuWbrCreate_TDP, /* top down parent */
27500 + AuWbrCreate_RR, /* round robin */
27501 + AuWbrCreate_MFS, /* most free space */
27502 + AuWbrCreate_MFSV, /* mfs with seconds */
27503 + AuWbrCreate_MFSRR, /* mfs then rr */
27504 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27505 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27506 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27507 + AuWbrCreate_PMFS, /* parent and mfs */
27508 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27509 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27510 + AuWbrCreate_PMFSRRV, /* plus seconds */
27512 + AuWbrCreate_Def = AuWbrCreate_TDP
27516 + AuWbrCopyup_TDP, /* top down parent */
27517 + AuWbrCopyup_BUP, /* bottom up parent */
27518 + AuWbrCopyup_BU, /* bottom up */
27520 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27523 +/* ---------------------------------------------------------------------- */
27525 +struct au_opt_add {
27526 + aufs_bindex_t bindex;
27529 + struct path path;
27532 +struct au_opt_del {
27534 + struct path h_path;
27537 +struct au_opt_mod {
27540 + struct dentry *h_root;
27543 +struct au_opt_xino {
27545 + struct file *file;
27548 +struct au_opt_xino_itrunc {
27549 + aufs_bindex_t bindex;
27552 +struct au_opt_wbr_create {
27555 + unsigned long long mfsrr_watermark;
27561 + struct au_opt_xino xino;
27562 + struct au_opt_xino_itrunc xino_itrunc;
27563 + struct au_opt_add add;
27564 + struct au_opt_del del;
27565 + struct au_opt_mod mod;
27568 + unsigned int rdblk;
27569 + unsigned int rdhash;
27571 + struct au_opt_wbr_create wbr_create;
27573 + unsigned int fhsm_second;
27578 +#define AuOpts_REMOUNT 1
27579 +#define AuOpts_REFRESH (1 << 1)
27580 +#define AuOpts_TRUNC_XIB (1 << 2)
27581 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27582 +#define AuOpts_REFRESH_IDOP (1 << 4)
27583 +#define AuOpts_DR_FLUSHED (1 << 5)
27584 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27585 +#define au_fset_opts(flags, name) \
27586 + do { (flags) |= AuOpts_##name; } while (0)
27587 +#define au_fclr_opts(flags, name) \
27588 + do { (flags) &= ~AuOpts_##name; } while (0)
27590 +#ifndef CONFIG_AUFS_DIRREN
27591 +#undef AuOpts_DR_FLUSHED
27592 +#define AuOpts_DR_FLUSHED 0
27596 + struct au_opt *opt;
27599 + unsigned int given_udba;
27600 + unsigned int flags;
27601 + unsigned long sb_flags;
27604 +/* ---------------------------------------------------------------------- */
27607 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27608 +const char *au_optstr_udba(int udba);
27609 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27610 +const char *au_optstr_wbr_create(int wbr_create);
27612 +void au_opts_free(struct au_opts *opts);
27613 +struct super_block;
27614 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27615 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27616 + unsigned int pending);
27617 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27618 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27620 +unsigned int au_opt_udba(struct super_block *sb);
27622 +#endif /* __KERNEL__ */
27623 +#endif /* __AUFS_OPTS_H__ */
27624 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27625 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27626 +++ linux/fs/aufs/plink.c 2021-12-03 15:38:59.939980643 +0100
27628 +// SPDX-License-Identifier: GPL-2.0
27630 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27632 + * This program, aufs is free software; you can redistribute it and/or modify
27633 + * it under the terms of the GNU General Public License as published by
27634 + * the Free Software Foundation; either version 2 of the License, or
27635 + * (at your option) any later version.
27637 + * This program is distributed in the hope that it will be useful,
27638 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27639 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27640 + * GNU General Public License for more details.
27642 + * You should have received a copy of the GNU General Public License
27643 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27653 + * the pseudo-link maintenance mode.
27654 + * during a user process maintains the pseudo-links,
27655 + * prohibit adding a new plink and branch manipulation.
27659 + * For entry functions which will handle plink, and i_mutex is already held
27661 + * They cannot wait and should return an error at once.
27662 + * Callers has to check the error.
27664 + * For entry functions which will handle plink, but i_mutex is not held
27666 + * They can wait the plink maintenance mode to finish.
27668 + * They behave like F_SETLK and F_SETLKW.
27669 + * If the caller never handle plink, then both flags are unnecessary.
27672 +int au_plink_maint(struct super_block *sb, int flags)
27676 + struct task_struct *parent, *prev;
27677 + struct au_sbinfo *sbi;
27679 + SiMustAnyLock(sb);
27682 + if (!au_opt_test(au_mntflags(sb), PLINK))
27685 + sbi = au_sbi(sb);
27686 + pid = sbi->si_plink_maint_pid;
27687 + if (!pid || pid == current->pid)
27690 + /* todo: it highly depends upon /sbin/mount.aufs */
27692 + parent = current;
27696 + parent = rcu_dereference(parent->real_parent);
27697 + if (parent == prev)
27699 + ppid = task_pid_vnr(parent);
27700 + if (pid == ppid) {
27701 + rcu_read_unlock();
27706 + rcu_read_unlock();
27708 + if (au_ftest_lock(flags, NOPLMW)) {
27709 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27710 + /* AuDebugOn(!lockdep_depth(current)); */
27711 + while (sbi->si_plink_maint_pid) {
27712 + si_read_unlock(sb);
27713 + /* gave up wake_up_bit() */
27714 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27716 + if (au_ftest_lock(flags, FLUSH))
27717 + au_nwt_flush(&sbi->si_nowait);
27718 + si_noflush_read_lock(sb);
27720 + } else if (au_ftest_lock(flags, NOPLM)) {
27721 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27729 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27731 + spin_lock(&sbinfo->si_plink_maint_lock);
27732 + sbinfo->si_plink_maint_pid = 0;
27733 + spin_unlock(&sbinfo->si_plink_maint_lock);
27734 + wake_up_all(&sbinfo->si_plink_wq);
27737 +int au_plink_maint_enter(struct super_block *sb)
27740 + struct au_sbinfo *sbinfo;
27743 + sbinfo = au_sbi(sb);
27744 + /* make sure i am the only one in this fs */
27745 + si_write_lock(sb, AuLock_FLUSH);
27746 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27747 + spin_lock(&sbinfo->si_plink_maint_lock);
27748 + if (!sbinfo->si_plink_maint_pid)
27749 + sbinfo->si_plink_maint_pid = current->pid;
27752 + spin_unlock(&sbinfo->si_plink_maint_lock);
27754 + si_write_unlock(sb);
27759 +/* ---------------------------------------------------------------------- */
27761 +#ifdef CONFIG_AUFS_DEBUG
27762 +void au_plink_list(struct super_block *sb)
27765 + struct au_sbinfo *sbinfo;
27766 + struct hlist_bl_head *hbl;
27767 + struct hlist_bl_node *pos;
27768 + struct au_icntnr *icntnr;
27770 + SiMustAnyLock(sb);
27772 + sbinfo = au_sbi(sb);
27773 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27774 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27776 + for (i = 0; i < AuPlink_NHASH; i++) {
27777 + hbl = sbinfo->si_plink + i;
27778 + hlist_bl_lock(hbl);
27779 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27780 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27781 + hlist_bl_unlock(hbl);
27786 +/* is the inode pseudo-linked? */
27787 +int au_plink_test(struct inode *inode)
27790 + struct au_sbinfo *sbinfo;
27791 + struct hlist_bl_head *hbl;
27792 + struct hlist_bl_node *pos;
27793 + struct au_icntnr *icntnr;
27795 + sbinfo = au_sbi(inode->i_sb);
27796 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27797 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27798 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27801 + i = au_plink_hash(inode->i_ino);
27802 + hbl = sbinfo->si_plink + i;
27803 + hlist_bl_lock(hbl);
27804 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27805 + if (&icntnr->vfs_inode == inode) {
27809 + hlist_bl_unlock(hbl);
27813 +/* ---------------------------------------------------------------------- */
27816 + * generate a name for plink.
27817 + * the file will be stored under AUFS_WH_PLINKDIR.
27819 +/* 20 is max digits length of ulong 64 */
27820 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27822 +static int plink_name(char *name, int len, struct inode *inode,
27823 + aufs_bindex_t bindex)
27826 + struct inode *h_inode;
27828 + h_inode = au_h_iptr(inode, bindex);
27829 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27833 +struct au_do_plink_lkup_args {
27834 + struct dentry **errp;
27835 + struct qstr *tgtname;
27836 + struct path *h_ppath;
27839 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27840 + struct path *h_ppath)
27842 + struct dentry *h_dentry;
27843 + struct inode *h_inode;
27845 + h_inode = d_inode(h_ppath->dentry);
27846 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27847 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
27848 + inode_unlock_shared(h_inode);
27853 +static void au_call_do_plink_lkup(void *args)
27855 + struct au_do_plink_lkup_args *a = args;
27856 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
27859 +/* lookup the plink-ed @inode under the branch at @bindex */
27860 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27862 + struct dentry *h_dentry;
27863 + struct au_branch *br;
27864 + struct path h_ppath;
27866 + char a[PLINK_NAME_LEN];
27867 + struct qstr tgtname = QSTR_INIT(a, 0);
27869 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27871 + br = au_sbr(inode->i_sb, bindex);
27872 + h_ppath.dentry = br->br_wbr->wbr_plink;
27873 + h_ppath.mnt = au_br_mnt(br);
27874 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27876 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27877 + struct au_do_plink_lkup_args args = {
27878 + .errp = &h_dentry,
27879 + .tgtname = &tgtname,
27880 + .h_ppath = &h_ppath
27883 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27884 + if (unlikely(wkq_err))
27885 + h_dentry = ERR_PTR(wkq_err);
27887 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
27892 +/* create a pseudo-link */
27893 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
27894 + struct dentry *h_dentry)
27897 + struct path h_path;
27898 + struct inode *h_dir, *delegated;
27900 + h_dir = d_inode(h_ppath->dentry);
27901 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27902 + h_path.mnt = h_ppath->mnt;
27904 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
27905 + err = PTR_ERR(h_path.dentry);
27906 + if (IS_ERR(h_path.dentry))
27910 + /* wh.plink dir is not monitored */
27911 + /* todo: is it really safe? */
27912 + if (d_is_positive(h_path.dentry)
27913 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27914 + delegated = NULL;
27915 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27916 + if (unlikely(err == -EWOULDBLOCK)) {
27917 + pr_warn("cannot retry for NFSv4 delegation"
27918 + " for an internal unlink\n");
27921 + dput(h_path.dentry);
27922 + h_path.dentry = NULL;
27926 + if (!err && d_is_negative(h_path.dentry)) {
27927 + delegated = NULL;
27928 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27929 + if (unlikely(err == -EWOULDBLOCK)) {
27930 + pr_warn("cannot retry for NFSv4 delegation"
27931 + " for an internal link\n");
27935 + dput(h_path.dentry);
27938 + inode_unlock(h_dir);
27942 +struct do_whplink_args {
27944 + struct qstr *tgt;
27945 + struct path *h_ppath;
27946 + struct dentry *h_dentry;
27949 +static void call_do_whplink(void *args)
27951 + struct do_whplink_args *a = args;
27952 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
27955 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27956 + aufs_bindex_t bindex)
27958 + int err, wkq_err;
27959 + struct au_branch *br;
27960 + struct au_wbr *wbr;
27961 + struct path h_ppath;
27962 + char a[PLINK_NAME_LEN];
27963 + struct qstr tgtname = QSTR_INIT(a, 0);
27965 + br = au_sbr(inode->i_sb, bindex);
27966 + wbr = br->br_wbr;
27967 + h_ppath.dentry = wbr->wbr_plink;
27968 + h_ppath.mnt = au_br_mnt(br);
27969 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27971 + /* always superio. */
27972 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27973 + struct do_whplink_args args = {
27976 + .h_ppath = &h_ppath,
27977 + .h_dentry = h_dentry
27979 + wkq_err = au_wkq_wait(call_do_whplink, &args);
27980 + if (unlikely(wkq_err))
27983 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
27989 + * create a new pseudo-link for @h_dentry on @bindex.
27990 + * the linked inode is held in aufs @inode.
27992 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
27993 + struct dentry *h_dentry)
27995 + struct super_block *sb;
27996 + struct au_sbinfo *sbinfo;
27997 + struct hlist_bl_head *hbl;
27998 + struct hlist_bl_node *pos;
27999 + struct au_icntnr *icntnr;
28000 + int found, err, cnt, i;
28002 + sb = inode->i_sb;
28003 + sbinfo = au_sbi(sb);
28004 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28005 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28007 + found = au_plink_test(inode);
28011 + i = au_plink_hash(inode->i_ino);
28012 + hbl = sbinfo->si_plink + i;
28015 + hlist_bl_lock(hbl);
28016 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28017 + if (&icntnr->vfs_inode == inode) {
28023 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28024 + hlist_bl_add_head(&icntnr->plink, hbl);
28026 + hlist_bl_unlock(hbl);
28028 + cnt = au_hbl_count(hbl);
28029 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28030 + if (cnt > AUFS_PLINK_WARN)
28031 + AuWarn1(msg ", %d\n", cnt);
28033 + err = whplink(h_dentry, inode, bindex);
28034 + if (unlikely(err)) {
28035 + pr_warn("err %d, damaged pseudo link.\n", err);
28036 + au_hbl_del(&icntnr->plink, hbl);
28037 + iput(&icntnr->vfs_inode);
28040 + iput(&icntnr->vfs_inode);
28043 +/* free all plinks */
28044 +void au_plink_put(struct super_block *sb, int verbose)
28047 + struct au_sbinfo *sbinfo;
28048 + struct hlist_bl_head *hbl;
28049 + struct hlist_bl_node *pos, *tmp;
28050 + struct au_icntnr *icntnr;
28052 + SiMustWriteLock(sb);
28054 + sbinfo = au_sbi(sb);
28055 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28056 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28058 + /* no spin_lock since sbinfo is write-locked */
28060 + for (i = 0; i < AuPlink_NHASH; i++) {
28061 + hbl = sbinfo->si_plink + i;
28062 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28063 + pr_warn("pseudo-link is not flushed");
28066 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28067 + iput(&icntnr->vfs_inode);
28068 + INIT_HLIST_BL_HEAD(hbl);
28072 +void au_plink_clean(struct super_block *sb, int verbose)
28074 + struct dentry *root;
28076 + root = sb->s_root;
28077 + aufs_write_lock(root);
28078 + if (au_opt_test(au_mntflags(sb), PLINK))
28079 + au_plink_put(sb, verbose);
28080 + aufs_write_unlock(root);
28083 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28086 + aufs_bindex_t btop, bbot, bindex;
28089 + btop = au_ibtop(inode);
28090 + bbot = au_ibbot(inode);
28092 + for (bindex = btop; bindex <= bbot; bindex++) {
28093 + if (!au_h_iptr(inode, bindex)
28094 + || au_ii_br_id(inode, bindex) != br_id)
28096 + au_set_h_iptr(inode, bindex, NULL, 0);
28101 + for (bindex = btop; bindex <= bbot; bindex++)
28102 + if (au_h_iptr(inode, bindex)) {
28112 +/* free the plinks on a branch specified by @br_id */
28113 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28115 + struct au_sbinfo *sbinfo;
28116 + struct hlist_bl_head *hbl;
28117 + struct hlist_bl_node *pos, *tmp;
28118 + struct au_icntnr *icntnr;
28119 + struct inode *inode;
28122 + SiMustWriteLock(sb);
28124 + sbinfo = au_sbi(sb);
28125 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28126 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28128 + /* no bit_lock since sbinfo is write-locked */
28129 + for (i = 0; i < AuPlink_NHASH; i++) {
28130 + hbl = sbinfo->si_plink + i;
28131 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28132 + inode = au_igrab(&icntnr->vfs_inode);
28133 + ii_write_lock_child(inode);
28134 + do_put = au_plink_do_half_refresh(inode, br_id);
28136 + hlist_bl_del(&icntnr->plink);
28139 + ii_write_unlock(inode);
28144 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28145 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28146 +++ linux/fs/aufs/poll.c 2021-12-03 15:38:59.939980643 +0100
28148 +// SPDX-License-Identifier: GPL-2.0
28150 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28152 + * This program, aufs is free software; you can redistribute it and/or modify
28153 + * it under the terms of the GNU General Public License as published by
28154 + * the Free Software Foundation; either version 2 of the License, or
28155 + * (at your option) any later version.
28157 + * This program is distributed in the hope that it will be useful,
28158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28160 + * GNU General Public License for more details.
28162 + * You should have received a copy of the GNU General Public License
28163 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28168 + * There is only one filesystem which implements ->poll operation, currently.
28173 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28176 + struct file *h_file;
28177 + struct super_block *sb;
28179 + /* We should pretend an error happened. */
28180 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28181 + sb = file->f_path.dentry->d_sb;
28182 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28184 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28185 + if (IS_ERR(h_file)) {
28186 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28190 + mask = vfs_poll(h_file, pt);
28191 + fput(h_file); /* instead of au_read_post() */
28194 + si_read_unlock(sb);
28195 + if (mask & EPOLLERR)
28196 + AuDbg("mask 0x%x\n", mask);
28199 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28200 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28201 +++ linux/fs/aufs/posix_acl.c 2021-12-03 15:38:59.939980643 +0100
28203 +// SPDX-License-Identifier: GPL-2.0
28205 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28207 + * This program, aufs is free software; you can redistribute it and/or modify
28208 + * it under the terms of the GNU General Public License as published by
28209 + * the Free Software Foundation; either version 2 of the License, or
28210 + * (at your option) any later version.
28212 + * This program is distributed in the hope that it will be useful,
28213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28215 + * GNU General Public License for more details.
28217 + * You should have received a copy of the GNU General Public License
28218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28222 + * posix acl operations
28225 +#include <linux/fs.h>
28228 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28230 + struct posix_acl *acl;
28232 + aufs_bindex_t bindex;
28233 + struct inode *h_inode;
28234 + struct super_block *sb;
28237 + sb = inode->i_sb;
28238 + si_read_lock(sb, AuLock_FLUSH);
28239 + ii_read_lock_child(inode);
28240 + if (!(sb->s_flags & SB_POSIXACL))
28243 + bindex = au_ibtop(inode);
28244 + h_inode = au_h_iptr(inode, bindex);
28245 + if (unlikely(!h_inode
28246 + || ((h_inode->i_mode & S_IFMT)
28247 + != (inode->i_mode & S_IFMT)))) {
28248 + err = au_busy_or_stale();
28249 + acl = ERR_PTR(err);
28253 + /* always topmost only */
28254 + acl = get_acl(h_inode, type);
28256 + forget_cached_acl(inode, type);
28258 + set_cached_acl(inode, type, acl);
28261 + ii_read_unlock(inode);
28262 + si_read_unlock(sb);
28264 + AuTraceErrPtr(acl);
28268 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28272 + struct dentry *dentry;
28273 + struct au_sxattr arg = {
28274 + .type = AU_ACL_SET,
28281 + IMustLock(inode);
28283 + if (inode->i_ino == AUFS_ROOT_INO)
28284 + dentry = dget(inode->i_sb->s_root);
28286 + dentry = d_find_alias(inode);
28288 + dentry = d_find_any_alias(inode);
28290 + pr_warn("cannot handle this inode, "
28291 + "please report to aufs-users ML\n");
28297 + ssz = au_sxattr(dentry, inode, &arg);
28298 + /* forget even it if succeeds since the branch might set differently */
28299 + forget_cached_acl(inode, type);
28308 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28309 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28310 +++ linux/fs/aufs/procfs.c 2021-12-03 15:38:59.939980643 +0100
28312 +// SPDX-License-Identifier: GPL-2.0
28314 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28316 + * This program, aufs is free software; you can redistribute it and/or modify
28317 + * it under the terms of the GNU General Public License as published by
28318 + * the Free Software Foundation; either version 2 of the License, or
28319 + * (at your option) any later version.
28321 + * This program is distributed in the hope that it will be useful,
28322 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28323 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28324 + * GNU General Public License for more details.
28326 + * You should have received a copy of the GNU General Public License
28327 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28331 + * procfs interfaces
28334 +#include <linux/proc_fs.h>
28337 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28339 + struct au_sbinfo *sbinfo;
28341 + sbinfo = file->private_data;
28343 + au_plink_maint_leave(sbinfo);
28344 + kobject_put(&sbinfo->si_kobj);
28350 +static void au_procfs_plm_write_clean(struct file *file)
28352 + struct au_sbinfo *sbinfo;
28354 + sbinfo = file->private_data;
28356 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28359 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28362 + struct super_block *sb;
28363 + struct au_sbinfo *sbinfo;
28364 + struct hlist_bl_node *pos;
28367 + if (unlikely(file->private_data))
28371 + /* don't use au_sbilist_lock() here */
28372 + hlist_bl_lock(&au_sbilist);
28373 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28374 + if (id == sysaufs_si_id(sbinfo)) {
28375 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28376 + sb = sbinfo->si_sb;
28379 + hlist_bl_unlock(&au_sbilist);
28382 + if (unlikely(!sb))
28385 + err = au_plink_maint_enter(sb);
28387 + /* keep kobject_get() */
28388 + file->private_data = sbinfo;
28390 + kobject_put(&sbinfo->si_kobj);
28396 + * Accept a valid "si=xxxx" only.
28397 + * Once it is accepted successfully, accept "clean" too.
28399 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28400 + size_t count, loff_t *ppos)
28403 + unsigned long id;
28404 + /* last newline is allowed */
28405 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28408 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28412 + if (unlikely(count > sizeof(buf)))
28415 + err = copy_from_user(buf, ubuf, count);
28416 + if (unlikely(err)) {
28423 + if (!strcmp("clean", buf)) {
28424 + au_procfs_plm_write_clean(file);
28425 + goto out_success;
28426 + } else if (unlikely(strncmp("si=", buf, 3)))
28429 + err = kstrtoul(buf + 3, 16, &id);
28430 + if (unlikely(err))
28433 + err = au_procfs_plm_write_si(file, id);
28434 + if (unlikely(err))
28438 + err = count; /* success */
28443 +static const struct proc_ops au_procfs_plm_op = {
28444 + .proc_write = au_procfs_plm_write,
28445 + .proc_release = au_procfs_plm_release
28448 +/* ---------------------------------------------------------------------- */
28450 +static struct proc_dir_entry *au_procfs_dir;
28452 +void au_procfs_fin(void)
28454 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28455 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28458 +int __init au_procfs_init(void)
28461 + struct proc_dir_entry *entry;
28464 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28465 + if (unlikely(!au_procfs_dir))
28468 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28469 + au_procfs_dir, &au_procfs_plm_op);
28470 + if (unlikely(!entry))
28474 + goto out; /* success */
28478 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28482 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28483 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28484 +++ linux/fs/aufs/rdu.c 2021-12-03 15:38:59.939980643 +0100
28486 +// SPDX-License-Identifier: GPL-2.0
28488 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28490 + * This program, aufs is free software; you can redistribute it and/or modify
28491 + * it under the terms of the GNU General Public License as published by
28492 + * the Free Software Foundation; either version 2 of the License, or
28493 + * (at your option) any later version.
28495 + * This program is distributed in the hope that it will be useful,
28496 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28497 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28498 + * GNU General Public License for more details.
28500 + * You should have received a copy of the GNU General Public License
28501 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28505 + * readdir in userspace.
28508 +#include <linux/compat.h>
28509 +#include <linux/fs_stack.h>
28510 +#include <linux/security.h>
28513 +/* bits for struct aufs_rdu.flags */
28514 +#define AuRdu_CALLED 1
28515 +#define AuRdu_CONT (1 << 1)
28516 +#define AuRdu_FULL (1 << 2)
28517 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28518 +#define au_fset_rdu(flags, name) \
28519 + do { (flags) |= AuRdu_##name; } while (0)
28520 +#define au_fclr_rdu(flags, name) \
28521 + do { (flags) &= ~AuRdu_##name; } while (0)
28523 +struct au_rdu_arg {
28524 + struct dir_context ctx;
28525 + struct aufs_rdu *rdu;
28526 + union au_rdu_ent_ul ent;
28527 + unsigned long end;
28529 + struct super_block *sb;
28533 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28534 + loff_t offset, u64 h_ino, unsigned int d_type)
28537 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28538 + struct aufs_rdu *rdu = arg->rdu;
28539 + struct au_rdu_ent ent;
28543 + au_fset_rdu(rdu->cookie.flags, CALLED);
28544 + len = au_rdu_len(nlen);
28545 + if (arg->ent.ul + len < arg->end) {
28547 + ent.bindex = rdu->cookie.bindex;
28548 + ent.type = d_type;
28550 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28551 + ent.type = DT_UNKNOWN;
28553 + /* unnecessary to support mmap_sem since this is a dir */
28555 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28557 + if (copy_to_user(arg->ent.e->name, name, nlen))
28559 + /* the terminating NULL */
28560 + if (__put_user(0, arg->ent.e->name + nlen))
28563 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28564 + arg->ent.ul += len;
28568 + au_fset_rdu(rdu->cookie.flags, FULL);
28570 + rdu->tail = arg->ent;
28574 + /* AuTraceErr(err); */
28578 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28582 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28584 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28585 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28587 + if (unlikely(offset != cookie->h_pos))
28593 + au_fclr_rdu(cookie->flags, CALLED);
28595 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28599 + && au_ftest_rdu(cookie->flags, CALLED)
28600 + && !au_ftest_rdu(cookie->flags, FULL));
28601 + cookie->h_pos = h_file->f_pos;
28608 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28611 + aufs_bindex_t bbot;
28612 + struct au_rdu_arg arg = {
28614 + .actor = au_rdu_fill
28617 + struct dentry *dentry;
28618 + struct inode *inode;
28619 + struct file *h_file;
28620 + struct au_rdu_cookie *cookie = &rdu->cookie;
28622 + /* VERIFY_WRITE */
28623 + err = !access_ok(rdu->ent.e, rdu->sz);
28624 + if (unlikely(err)) {
28630 + rdu->tail = rdu->ent;
28633 + arg.ent = rdu->ent;
28634 + arg.end = arg.ent.ul;
28635 + arg.end += rdu->sz;
28638 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28641 + err = security_file_permission(file, MAY_READ);
28643 + if (unlikely(err))
28646 + dentry = file->f_path.dentry;
28647 + inode = d_inode(dentry);
28648 + inode_lock_shared(inode);
28650 + arg.sb = inode->i_sb;
28651 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28652 + if (unlikely(err))
28654 + err = au_alive_dir(dentry);
28655 + if (unlikely(err))
28657 + /* todo: reval? */
28658 + fi_read_lock(file);
28661 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28662 + && cookie->generation != au_figen(file)))
28667 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28669 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28671 + bbot = au_fbtop(file);
28672 + if (cookie->bindex < bbot)
28673 + cookie->bindex = bbot;
28674 + bbot = au_fbbot_dir(file);
28675 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28676 + for (; !err && cookie->bindex <= bbot;
28677 + cookie->bindex++, cookie->h_pos = 0) {
28678 + h_file = au_hf_dir(file, cookie->bindex);
28682 + au_fclr_rdu(cookie->flags, FULL);
28683 + err = au_rdu_do(h_file, &arg);
28685 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28688 + AuDbg("rent %llu\n", rdu->rent);
28690 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28691 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28692 + au_fset_rdu(cookie->flags, CONT);
28693 + cookie->generation = au_figen(file);
28696 + ii_read_lock_child(inode);
28697 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28698 + ii_read_unlock(inode);
28701 + fi_read_unlock(file);
28703 + si_read_unlock(arg.sb);
28705 + inode_unlock_shared(inode);
28711 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28715 + unsigned long long nent;
28716 + union au_rdu_ent_ul *u;
28717 + struct au_rdu_ent ent;
28718 + struct super_block *sb;
28721 + nent = rdu->nent;
28723 + sb = file->f_path.dentry->d_sb;
28724 + si_read_lock(sb, AuLock_FLUSH);
28725 + while (nent-- > 0) {
28726 + /* unnecessary to support mmap_sem since this is a dir */
28727 + err = copy_from_user(&ent, u->e, sizeof(ent));
28729 + /* VERIFY_WRITE */
28730 + err = !access_ok(&u->e->ino, sizeof(ino));
28731 + if (unlikely(err)) {
28737 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28739 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28741 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28743 + if (unlikely(err)) {
28748 + err = __put_user(ino, &u->e->ino);
28749 + if (unlikely(err)) {
28754 + u->ul += au_rdu_len(ent.nlen);
28756 + si_read_unlock(sb);
28761 +/* ---------------------------------------------------------------------- */
28763 +static int au_rdu_verify(struct aufs_rdu *rdu)
28765 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28766 + "%llu, b%d, 0x%x, g%u}\n",
28767 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28769 + rdu->rent, rdu->shwh, rdu->full,
28770 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28771 + rdu->cookie.generation);
28773 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28777 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28781 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28784 + struct aufs_rdu rdu;
28785 + void __user *p = (void __user *)arg;
28787 + err = copy_from_user(&rdu, p, sizeof(rdu));
28788 + if (unlikely(err)) {
28793 + err = au_rdu_verify(&rdu);
28794 + if (unlikely(err))
28798 + case AUFS_CTL_RDU:
28799 + err = au_rdu(file, &rdu);
28800 + if (unlikely(err))
28803 + e = copy_to_user(p, &rdu, sizeof(rdu));
28804 + if (unlikely(e)) {
28809 + case AUFS_CTL_RDU_INO:
28810 + err = au_rdu_ino(file, &rdu);
28814 + /* err = -ENOTTY; */
28823 +#ifdef CONFIG_COMPAT
28824 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28827 + struct aufs_rdu rdu;
28828 + void __user *p = compat_ptr(arg);
28830 + /* todo: get_user()? */
28831 + err = copy_from_user(&rdu, p, sizeof(rdu));
28832 + if (unlikely(err)) {
28837 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28838 + err = au_rdu_verify(&rdu);
28839 + if (unlikely(err))
28843 + case AUFS_CTL_RDU:
28844 + err = au_rdu(file, &rdu);
28845 + if (unlikely(err))
28848 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28849 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28850 + e = copy_to_user(p, &rdu, sizeof(rdu));
28851 + if (unlikely(e)) {
28856 + case AUFS_CTL_RDU_INO:
28857 + err = au_rdu_ino(file, &rdu);
28861 + /* err = -ENOTTY; */
28870 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28871 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28872 +++ linux/fs/aufs/rwsem.h 2021-12-03 15:38:59.939980643 +0100
28874 +/* SPDX-License-Identifier: GPL-2.0 */
28876 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28878 + * This program, aufs is free software; you can redistribute it and/or modify
28879 + * it under the terms of the GNU General Public License as published by
28880 + * the Free Software Foundation; either version 2 of the License, or
28881 + * (at your option) any later version.
28883 + * This program is distributed in the hope that it will be useful,
28884 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28885 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28886 + * GNU General Public License for more details.
28888 + * You should have received a copy of the GNU General Public License
28889 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28893 + * simple read-write semaphore wrappers
28896 +#ifndef __AUFS_RWSEM_H__
28897 +#define __AUFS_RWSEM_H__
28901 +#include "debug.h"
28903 +/* in the future, the name 'au_rwsem' will be totally gone */
28904 +#define au_rwsem rw_semaphore
28906 +/* to debug easier, do not make them inlined functions */
28907 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28908 +/* rwsem_is_locked() is unusable */
28909 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28910 + && !lockdep_recursing(current) \
28912 + && !lockdep_is_held_type(rw, 1))
28913 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28914 + && !lockdep_recursing(current) \
28916 + && !lockdep_is_held_type(rw, 0))
28917 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28918 + && !lockdep_recursing(current) \
28920 + && !lockdep_is_held(rw))
28921 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28922 + && !lockdep_recursing(current) \
28924 + && lockdep_is_held(rw))
28926 +#define au_rw_init(rw) init_rwsem(rw)
28928 +#define au_rw_init_wlock(rw) do { \
28929 + au_rw_init(rw); \
28930 + down_write(rw); \
28933 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28934 + au_rw_init(rw); \
28935 + down_write_nested(rw, lsc); \
28938 +#define au_rw_read_lock(rw) down_read(rw)
28939 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28940 +#define au_rw_read_unlock(rw) up_read(rw)
28941 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28942 +#define au_rw_write_lock(rw) down_write(rw)
28943 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28944 +#define au_rw_write_unlock(rw) up_write(rw)
28945 +/* why is not _nested version defined? */
28946 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28947 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28949 +#endif /* __KERNEL__ */
28950 +#endif /* __AUFS_RWSEM_H__ */
28951 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28952 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28953 +++ linux/fs/aufs/sbinfo.c 2021-12-03 15:38:59.939980643 +0100
28955 +// SPDX-License-Identifier: GPL-2.0
28957 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28959 + * This program, aufs is free software; you can redistribute it and/or modify
28960 + * it under the terms of the GNU General Public License as published by
28961 + * the Free Software Foundation; either version 2 of the License, or
28962 + * (at your option) any later version.
28964 + * This program is distributed in the hope that it will be useful,
28965 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28966 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28967 + * GNU General Public License for more details.
28969 + * You should have received a copy of the GNU General Public License
28970 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28974 + * superblock private data
28977 +#include <linux/iversion.h>
28981 + * they are necessary regardless sysfs is disabled.
28983 +void au_si_free(struct kobject *kobj)
28986 + struct au_sbinfo *sbinfo;
28987 + char *locked __maybe_unused; /* debug only */
28989 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28990 + for (i = 0; i < AuPlink_NHASH; i++)
28991 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
28992 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
28994 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
28995 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
28996 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
28997 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
28999 + dbgaufs_si_fin(sbinfo);
29000 + au_rw_write_lock(&sbinfo->si_rwsem);
29001 + au_br_free(sbinfo);
29002 + au_rw_write_unlock(&sbinfo->si_rwsem);
29004 + au_kfree_try_rcu(sbinfo->si_branch);
29005 + mutex_destroy(&sbinfo->si_xib_mtx);
29006 + AuRwDestroy(&sbinfo->si_rwsem);
29008 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29009 + /* si_nfiles is waited too */
29010 + au_kfree_rcu(sbinfo);
29013 +int au_si_alloc(struct super_block *sb)
29016 + struct au_sbinfo *sbinfo;
29019 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29020 + if (unlikely(!sbinfo))
29023 + /* will be reallocated separately */
29024 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29025 + if (unlikely(!sbinfo->si_branch))
29028 + err = sysaufs_si_init(sbinfo);
29030 + dbgaufs_si_null(sbinfo);
29031 + err = dbgaufs_si_init(sbinfo);
29032 + if (unlikely(err))
29033 + kobject_put(&sbinfo->si_kobj);
29035 + if (unlikely(err))
29038 + au_nwt_init(&sbinfo->si_nowait);
29039 + au_rw_init_wlock(&sbinfo->si_rwsem);
29041 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29042 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29044 + sbinfo->si_bbot = -1;
29045 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29047 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29048 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29049 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29050 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29052 + au_fhsm_init(sbinfo);
29054 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29056 + sbinfo->si_xino_jiffy = jiffies;
29057 + sbinfo->si_xino_expire
29058 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29059 + mutex_init(&sbinfo->si_xib_mtx);
29060 + /* leave si_xib_last_pindex and si_xib_next_bit */
29062 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29064 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29065 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29066 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29067 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29069 + for (i = 0; i < AuPlink_NHASH; i++)
29070 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29071 + init_waitqueue_head(&sbinfo->si_plink_wq);
29072 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29074 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29076 + /* with getattr by default */
29077 + sbinfo->si_iop_array = aufs_iop;
29079 + /* leave other members for sysaufs and si_mnt. */
29080 + sbinfo->si_sb = sb;
29081 + sb->s_fs_info = sbinfo;
29083 + return 0; /* success */
29086 + au_kfree_try_rcu(sbinfo->si_branch);
29088 + au_kfree_rcu(sbinfo);
29093 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29096 + struct au_branch **brp;
29098 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29101 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29102 + if (unlikely(!sz))
29103 + sz = sizeof(*brp);
29104 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29107 + sbinfo->si_branch = brp;
29114 +/* ---------------------------------------------------------------------- */
29116 +unsigned int au_sigen_inc(struct super_block *sb)
29118 + unsigned int gen;
29119 + struct inode *inode;
29121 + SiMustWriteLock(sb);
29123 + gen = ++au_sbi(sb)->si_generation;
29124 + au_update_digen(sb->s_root);
29125 + inode = d_inode(sb->s_root);
29126 + au_update_iigen(inode, /*half*/0);
29127 + inode_inc_iversion(inode);
29131 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29133 + aufs_bindex_t br_id;
29135 + struct au_sbinfo *sbinfo;
29137 + SiMustWriteLock(sb);
29139 + sbinfo = au_sbi(sb);
29140 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29141 + br_id = ++sbinfo->si_last_br_id;
29142 + AuDebugOn(br_id < 0);
29143 + if (br_id && au_br_index(sb, br_id) < 0)
29150 +/* ---------------------------------------------------------------------- */
29152 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29153 +int si_read_lock(struct super_block *sb, int flags)
29158 + if (au_ftest_lock(flags, FLUSH))
29159 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29161 + si_noflush_read_lock(sb);
29162 + err = au_plink_maint(sb, flags);
29163 + if (unlikely(err))
29164 + si_read_unlock(sb);
29169 +int si_write_lock(struct super_block *sb, int flags)
29173 + if (au_ftest_lock(flags, FLUSH))
29174 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29176 + si_noflush_write_lock(sb);
29177 + err = au_plink_maint(sb, flags);
29178 + if (unlikely(err))
29179 + si_write_unlock(sb);
29184 +/* dentry and super_block lock. call at entry point */
29185 +int aufs_read_lock(struct dentry *dentry, int flags)
29188 + struct super_block *sb;
29190 + sb = dentry->d_sb;
29191 + err = si_read_lock(sb, flags);
29192 + if (unlikely(err))
29195 + if (au_ftest_lock(flags, DW))
29196 + di_write_lock_child(dentry);
29198 + di_read_lock_child(dentry, flags);
29200 + if (au_ftest_lock(flags, GEN)) {
29201 + err = au_digen_test(dentry, au_sigen(sb));
29202 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29203 + AuDebugOn(!err && au_dbrange_test(dentry));
29205 + err = au_dbrange_test(dentry);
29206 + if (unlikely(err))
29207 + aufs_read_unlock(dentry, flags);
29214 +void aufs_read_unlock(struct dentry *dentry, int flags)
29216 + if (au_ftest_lock(flags, DW))
29217 + di_write_unlock(dentry);
29219 + di_read_unlock(dentry, flags);
29220 + si_read_unlock(dentry->d_sb);
29223 +void aufs_write_lock(struct dentry *dentry)
29225 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29226 + di_write_lock_child(dentry);
29229 +void aufs_write_unlock(struct dentry *dentry)
29231 + di_write_unlock(dentry);
29232 + si_write_unlock(dentry->d_sb);
29235 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29238 + unsigned int sigen;
29239 + struct super_block *sb;
29242 + err = si_read_lock(sb, flags);
29243 + if (unlikely(err))
29246 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29248 + if (au_ftest_lock(flags, GEN)) {
29249 + sigen = au_sigen(sb);
29250 + err = au_digen_test(d1, sigen);
29251 + AuDebugOn(!err && au_dbrange_test(d1));
29253 + err = au_digen_test(d2, sigen);
29254 + AuDebugOn(!err && au_dbrange_test(d2));
29256 + if (unlikely(err))
29257 + aufs_read_and_write_unlock2(d1, d2);
29264 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29266 + di_write_unlock2(d1, d2);
29267 + si_read_unlock(d1->d_sb);
29269 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29270 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29271 +++ linux/fs/aufs/super.c 2021-12-03 15:38:59.939980643 +0100
29273 +// SPDX-License-Identifier: GPL-2.0
29275 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29277 + * This program, aufs is free software; you can redistribute it and/or modify
29278 + * it under the terms of the GNU General Public License as published by
29279 + * the Free Software Foundation; either version 2 of the License, or
29280 + * (at your option) any later version.
29282 + * This program is distributed in the hope that it will be useful,
29283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29285 + * GNU General Public License for more details.
29287 + * You should have received a copy of the GNU General Public License
29288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29292 + * mount and super_block operations
29295 +#include <linux/iversion.h>
29296 +#include <linux/mm.h>
29297 +#include <linux/seq_file.h>
29298 +#include <linux/statfs.h>
29299 +#include <linux/vmalloc.h>
29303 + * super_operations
29305 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29307 + struct au_icntnr *c;
29309 + c = au_cache_alloc_icntnr();
29311 + au_icntnr_init(c);
29312 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29313 + c->iinfo.ii_hinode = NULL;
29314 + return &c->vfs_inode;
29319 +static void aufs_destroy_inode(struct inode *inode)
29321 + if (!au_is_bad_inode(inode))
29322 + au_iinfo_fin(inode);
29325 +static void aufs_free_inode(struct inode *inode)
29327 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29330 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29332 + struct inode *inode;
29335 + inode = iget_locked(sb, ino);
29336 + if (unlikely(!inode)) {
29337 + inode = ERR_PTR(-ENOMEM);
29340 + if (!(inode->i_state & I_NEW))
29343 + err = au_xigen_new(inode);
29345 + err = au_iinfo_init(inode);
29347 + inode_inc_iversion(inode);
29349 + iget_failed(inode);
29350 + inode = ERR_PTR(err);
29354 + /* never return NULL */
29355 + AuDebugOn(!inode);
29356 + AuTraceErrPtr(inode);
29360 +/* lock free root dinfo */
29361 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29364 + aufs_bindex_t bindex, bbot;
29365 + struct path path;
29366 + struct au_hdentry *hdp;
29367 + struct au_branch *br;
29368 + au_br_perm_str_t perm;
29371 + bbot = au_sbbot(sb);
29373 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29374 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29375 + br = au_sbr(sb, bindex);
29376 + path.mnt = au_br_mnt(br);
29377 + path.dentry = hdp->hd_dentry;
29378 + err = au_seq_path(seq, &path);
29380 + au_optstr_br_perm(&perm, br->br_perm);
29381 + seq_printf(seq, "=%s", perm.a);
29382 + if (bindex != bbot)
29383 + seq_putc(seq, ':');
29386 + if (unlikely(err || seq_has_overflowed(seq)))
29392 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29393 + const char *append)
29398 + while (*pat != ':')
29401 + strcpy(p, append);
29402 + AuDebugOn(strlen(fmt) >= len);
29405 +static void au_show_wbr_create(struct seq_file *m, int v,
29406 + struct au_sbinfo *sbinfo)
29410 + struct au_wbr_mfs *mfs;
29412 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29414 + seq_puts(m, ",create=");
29415 + pat = au_optstr_wbr_create(v);
29416 + mfs = &sbinfo->si_wbr_mfs;
29418 + case AuWbrCreate_TDP:
29419 + case AuWbrCreate_RR:
29420 + case AuWbrCreate_MFS:
29421 + case AuWbrCreate_PMFS:
29422 + seq_puts(m, pat);
29424 + case AuWbrCreate_MFSRR:
29425 + case AuWbrCreate_TDMFS:
29426 + case AuWbrCreate_PMFSRR:
29427 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29428 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29430 + case AuWbrCreate_MFSV:
29431 + case AuWbrCreate_PMFSV:
29432 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29433 + seq_printf(m, fmt,
29434 + jiffies_to_msecs(mfs->mfs_expire)
29437 + case AuWbrCreate_MFSRRV:
29438 + case AuWbrCreate_TDMFSV:
29439 + case AuWbrCreate_PMFSRRV:
29440 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29441 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29442 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29449 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29451 +#ifdef CONFIG_SYSFS
29455 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29456 + aufs_bindex_t bindex, brid;
29457 + struct qstr *name;
29459 + struct dentry *d, *h_root;
29460 + struct au_branch *br;
29462 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29465 + f = au_sbi(sb)->si_xib;
29469 + /* stop printing the default xino path on the first writable branch */
29471 + bindex = au_xi_root(sb, f->f_path.dentry);
29472 + if (bindex >= 0) {
29473 + br = au_sbr_sb(sb, bindex);
29474 + h_root = au_br_dentry(br);
29477 + d = f->f_path.dentry;
29478 + name = &d->d_name;
29479 + /* safe ->d_parent because the file is unlinked */
29480 + if (d->d_parent == h_root
29481 + && name->len == len
29482 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29485 + seq_puts(seq, ",xino=");
29486 + err = au_xino_path(seq, f);
29493 +/* seq_file will re-call me in case of too long string */
29494 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29497 + unsigned int mnt_flags, v;
29498 + struct super_block *sb;
29499 + struct au_sbinfo *sbinfo;
29501 +#define AuBool(name, str) do { \
29502 + v = au_opt_test(mnt_flags, name); \
29503 + if (v != au_opt_test(AuOpt_Def, name)) \
29504 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29507 +#define AuStr(name, str) do { \
29508 + v = mnt_flags & AuOptMask_##name; \
29509 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29510 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29513 +#define AuUInt(name, str, val) do { \
29514 + if (val != AUFS_##name##_DEF) \
29515 + seq_printf(m, "," #str "=%u", val); \
29518 + sb = dentry->d_sb;
29519 + if (sb->s_flags & SB_POSIXACL)
29520 + seq_puts(m, ",acl");
29521 +#if 0 /* reserved for future use */
29522 + if (sb->s_flags & SB_I_VERSION)
29523 + seq_puts(m, ",i_version");
29526 + /* lock free root dinfo */
29527 + si_noflush_read_lock(sb);
29528 + sbinfo = au_sbi(sb);
29529 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29531 + mnt_flags = au_mntflags(sb);
29532 + if (au_opt_test(mnt_flags, XINO)) {
29533 + err = au_show_xino(m, sb);
29534 + if (unlikely(err))
29537 + seq_puts(m, ",noxino");
29539 + AuBool(TRUNC_XINO, trunc_xino);
29540 + AuStr(UDBA, udba);
29541 + AuBool(SHWH, shwh);
29542 + AuBool(PLINK, plink);
29543 + AuBool(DIO, dio);
29544 + AuBool(DIRPERM1, dirperm1);
29546 + v = sbinfo->si_wbr_create;
29547 + if (v != AuWbrCreate_Def)
29548 + au_show_wbr_create(m, v, sbinfo);
29550 + v = sbinfo->si_wbr_copyup;
29551 + if (v != AuWbrCopyup_Def)
29552 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29554 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29555 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29556 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29558 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29560 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29561 + AuUInt(RDCACHE, rdcache, v);
29563 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29564 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29566 + au_fhsm_show(m, sbinfo);
29568 + AuBool(DIRREN, dirren);
29569 + AuBool(SUM, sum);
29570 + /* AuBool(SUM_W, wsum); */
29571 + AuBool(WARN_PERM, warn_perm);
29572 + AuBool(VERBOSE, verbose);
29575 + /* be sure to print "br:" last */
29576 + if (!sysaufs_brs) {
29577 + seq_puts(m, ",br:");
29578 + au_show_brs(m, sb);
29580 + si_read_unlock(sb);
29588 +/* ---------------------------------------------------------------------- */
29590 +/* sum mode which returns the summation for statfs(2) */
29592 +static u64 au_add_till_max(u64 a, u64 b)
29600 + return ULLONG_MAX;
29603 +static u64 au_mul_till_max(u64 a, long mul)
29611 + return ULLONG_MAX;
29614 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29617 + long bsize, factor;
29618 + u64 blocks, bfree, bavail, files, ffree;
29619 + aufs_bindex_t bbot, bindex, i;
29620 + unsigned char shared;
29621 + struct path h_path;
29622 + struct super_block *h_sb;
29625 + bsize = LONG_MAX;
29631 + bbot = au_sbbot(sb);
29632 + for (bindex = 0; bindex <= bbot; bindex++) {
29633 + h_path.mnt = au_sbr_mnt(sb, bindex);
29634 + h_sb = h_path.mnt->mnt_sb;
29636 + for (i = 0; !shared && i < bindex; i++)
29637 + shared = (au_sbr_sb(sb, i) == h_sb);
29641 + /* sb->s_root for NFS is unreliable */
29642 + h_path.dentry = h_path.mnt->mnt_root;
29643 + err = vfs_statfs(&h_path, buf);
29644 + if (unlikely(err))
29647 + if (bsize > buf->f_bsize) {
29649 + * we will reduce bsize, so we have to expand blocks
29650 + * etc. to match them again
29652 + factor = (bsize / buf->f_bsize);
29653 + blocks = au_mul_till_max(blocks, factor);
29654 + bfree = au_mul_till_max(bfree, factor);
29655 + bavail = au_mul_till_max(bavail, factor);
29656 + bsize = buf->f_bsize;
29659 + factor = (buf->f_bsize / bsize);
29660 + blocks = au_add_till_max(blocks,
29661 + au_mul_till_max(buf->f_blocks, factor));
29662 + bfree = au_add_till_max(bfree,
29663 + au_mul_till_max(buf->f_bfree, factor));
29664 + bavail = au_add_till_max(bavail,
29665 + au_mul_till_max(buf->f_bavail, factor));
29666 + files = au_add_till_max(files, buf->f_files);
29667 + ffree = au_add_till_max(ffree, buf->f_ffree);
29670 + buf->f_bsize = bsize;
29671 + buf->f_blocks = blocks;
29672 + buf->f_bfree = bfree;
29673 + buf->f_bavail = bavail;
29674 + buf->f_files = files;
29675 + buf->f_ffree = ffree;
29676 + buf->f_frsize = 0;
29682 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29685 + struct path h_path;
29686 + struct super_block *sb;
29688 + /* lock free root dinfo */
29689 + sb = dentry->d_sb;
29690 + si_noflush_read_lock(sb);
29691 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29692 + /* sb->s_root for NFS is unreliable */
29693 + h_path.mnt = au_sbr_mnt(sb, 0);
29694 + h_path.dentry = h_path.mnt->mnt_root;
29695 + err = vfs_statfs(&h_path, buf);
29697 + err = au_statfs_sum(sb, buf);
29698 + si_read_unlock(sb);
29701 + buf->f_type = AUFS_SUPER_MAGIC;
29702 + buf->f_namelen = AUFS_MAX_NAMELEN;
29703 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29705 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29710 +/* ---------------------------------------------------------------------- */
29712 +static int aufs_sync_fs(struct super_block *sb, int wait)
29715 + aufs_bindex_t bbot, bindex;
29716 + struct au_branch *br;
29717 + struct super_block *h_sb;
29720 + si_noflush_read_lock(sb);
29721 + bbot = au_sbbot(sb);
29722 + for (bindex = 0; bindex <= bbot; bindex++) {
29723 + br = au_sbr(sb, bindex);
29724 + if (!au_br_writable(br->br_perm))
29727 + h_sb = au_sbr_sb(sb, bindex);
29728 + e = vfsub_sync_filesystem(h_sb, wait);
29729 + if (unlikely(e && !err))
29731 + /* go on even if an error happens */
29733 + si_read_unlock(sb);
29738 +/* ---------------------------------------------------------------------- */
29740 +/* final actions when unmounting a file system */
29741 +static void aufs_put_super(struct super_block *sb)
29743 + struct au_sbinfo *sbinfo;
29745 + sbinfo = au_sbi(sb);
29747 + kobject_put(&sbinfo->si_kobj);
29750 +/* ---------------------------------------------------------------------- */
29752 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29753 + struct super_block *sb, void *arg)
29756 + unsigned long long n, sz;
29763 + if (*hint > ULLONG_MAX / sizeof(array)) {
29764 + array = ERR_PTR(-EMFILE);
29765 + pr_err("hint %llu\n", *hint);
29769 + sz = sizeof(array) * *hint;
29770 + array = kzalloc(sz, GFP_NOFS);
29771 + if (unlikely(!array))
29772 + array = vzalloc(sz);
29773 + if (unlikely(!array)) {
29774 + array = ERR_PTR(-ENOMEM);
29778 + n = cb(sb, array, *hint, arg);
29779 + AuDebugOn(n > *hint);
29786 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29787 + unsigned long long max __maybe_unused,
29790 + unsigned long long n;
29791 + struct inode **p, *inode;
29792 + struct list_head *head;
29797 + spin_lock(&sb->s_inode_list_lock);
29798 + list_for_each_entry(inode, head, i_sb_list) {
29799 + if (!au_is_bad_inode(inode)
29800 + && au_ii(inode)->ii_btop >= 0) {
29801 + spin_lock(&inode->i_lock);
29802 + if (atomic_read(&inode->i_count)) {
29806 + AuDebugOn(n > max);
29808 + spin_unlock(&inode->i_lock);
29811 + spin_unlock(&sb->s_inode_list_lock);
29816 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29818 + struct au_sbinfo *sbi;
29820 + sbi = au_sbi(sb);
29821 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29822 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29825 +void au_iarray_free(struct inode **a, unsigned long long max)
29827 + unsigned long long ull;
29829 + for (ull = 0; ull < max; ull++)
29834 +/* ---------------------------------------------------------------------- */
29837 + * refresh dentry and inode at remount time.
29839 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29840 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29841 + struct dentry *parent)
29845 + di_write_lock_child(dentry);
29846 + di_read_lock_parent(parent, AuLock_IR);
29847 + err = au_refresh_dentry(dentry, parent);
29848 + if (!err && dir_flags)
29849 + au_hn_reset(d_inode(dentry), dir_flags);
29850 + di_read_unlock(parent, AuLock_IR);
29851 + di_write_unlock(dentry);
29856 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29857 + struct au_sbinfo *sbinfo,
29858 + const unsigned int dir_flags, unsigned int do_idop)
29861 + struct dentry *parent;
29864 + parent = dget_parent(dentry);
29865 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29866 + if (d_really_is_positive(dentry)) {
29867 + if (!d_is_dir(dentry))
29868 + err = au_do_refresh(dentry, /*dir_flags*/0,
29871 + err = au_do_refresh(dentry, dir_flags, parent);
29872 + if (unlikely(err))
29873 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29876 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29877 + AuDbgDentry(dentry);
29883 + au_refresh_dop(dentry, /*force_reval*/0);
29885 + au_refresh_dop(dentry, /*force_reval*/1);
29891 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29893 + int err, i, j, ndentry, e;
29894 + unsigned int sigen;
29895 + struct au_dcsub_pages dpages;
29896 + struct au_dpage *dpage;
29897 + struct dentry **dentries, *d;
29898 + struct au_sbinfo *sbinfo;
29899 + struct dentry *root = sb->s_root;
29900 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29903 + au_refresh_dop(root, /*force_reval*/0);
29905 + err = au_dpages_init(&dpages, GFP_NOFS);
29906 + if (unlikely(err))
29908 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29909 + if (unlikely(err))
29912 + sigen = au_sigen(sb);
29913 + sbinfo = au_sbi(sb);
29914 + for (i = 0; i < dpages.ndpage; i++) {
29915 + dpage = dpages.dpages + i;
29916 + dentries = dpage->dentries;
29917 + ndentry = dpage->ndentry;
29918 + for (j = 0; j < ndentry; j++) {
29920 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29922 + if (unlikely(e && !err))
29924 + /* go on even err */
29929 + au_dpages_free(&dpages);
29934 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29937 + unsigned int sigen;
29938 + unsigned long long max, ull;
29939 + struct inode *inode, **array;
29941 + array = au_iarray_alloc(sb, &max);
29942 + err = PTR_ERR(array);
29943 + if (IS_ERR(array))
29947 + sigen = au_sigen(sb);
29948 + for (ull = 0; ull < max; ull++) {
29949 + inode = array[ull];
29950 + if (unlikely(!inode))
29954 + ii_write_lock_child(inode);
29955 + if (au_iigen(inode, NULL) != sigen) {
29956 + e = au_refresh_hinode_self(inode);
29957 + if (unlikely(e)) {
29958 + au_refresh_iop(inode, /*force_getattr*/1);
29959 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29962 + /* go on even if err */
29965 + if (!e && do_idop)
29966 + au_refresh_iop(inode, /*force_getattr*/0);
29967 + ii_write_unlock(inode);
29970 + au_iarray_free(array, max);
29976 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
29979 + unsigned int udba;
29980 + aufs_bindex_t bindex, bbot;
29981 + struct dentry *root;
29982 + struct inode *inode;
29983 + struct au_branch *br;
29984 + struct au_sbinfo *sbi;
29986 + au_sigen_inc(sb);
29987 + sbi = au_sbi(sb);
29988 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
29990 + root = sb->s_root;
29991 + DiMustNoWaiters(root);
29992 + inode = d_inode(root);
29993 + IiMustNoWaiters(inode);
29995 + udba = au_opt_udba(sb);
29996 + bbot = au_sbbot(sb);
29997 + for (bindex = 0; bindex <= bbot; bindex++) {
29998 + br = au_sbr(sb, bindex);
29999 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30000 + if (unlikely(err))
30001 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30003 + /* go on even if err */
30005 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30008 + if (au_ftest_si(sbi, NO_DREVAL)) {
30009 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30010 + sb->s_d_op = &aufs_dop_noreval;
30011 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30012 + sbi->si_iop_array = aufs_iop_nogetattr;
30014 + AuDebugOn(sb->s_d_op == &aufs_dop);
30015 + sb->s_d_op = &aufs_dop;
30016 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30017 + sbi->si_iop_array = aufs_iop;
30019 + pr_info("reset to %ps and %ps\n",
30020 + sb->s_d_op, sbi->si_iop_array);
30023 + di_write_unlock(root);
30024 + err = au_refresh_d(sb, do_idop);
30025 + e = au_refresh_i(sb, do_idop);
30026 + if (unlikely(e && !err))
30028 + /* aufs_write_lock() calls ..._child() */
30029 + di_write_lock_child(root);
30031 + au_cpup_attr_all(inode, /*force*/1);
30033 + if (unlikely(err))
30034 + AuIOErr("refresh failed, ignored, %d\n", err);
30037 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30038 +static int cvt_err(int err)
30052 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30055 + unsigned int mntflags;
30056 + struct au_opts opts = {
30059 + struct dentry *root;
30060 + struct inode *inode;
30061 + struct au_sbinfo *sbinfo;
30064 + root = sb->s_root;
30065 + if (!data || !*data) {
30066 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30068 + di_write_lock_child(root);
30069 + err = au_opts_verify(sb, *flags, /*pending*/0);
30070 + aufs_write_unlock(root);
30076 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30077 + if (unlikely(!opts.opt))
30079 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30080 + opts.flags = AuOpts_REMOUNT;
30081 + opts.sb_flags = *flags;
30083 + /* parse it before aufs lock */
30084 + err = au_opts_parse(sb, data, &opts);
30085 + if (unlikely(err))
30088 + sbinfo = au_sbi(sb);
30089 + inode = d_inode(root);
30090 + inode_lock(inode);
30091 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30092 + if (unlikely(err))
30094 + di_write_lock_child(root);
30096 + /* au_opts_remount() may return an error */
30097 + err = au_opts_remount(sb, &opts);
30098 + au_opts_free(&opts);
30100 + if (au_ftest_opts(opts.flags, REFRESH))
30101 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30103 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30104 + mntflags = au_mntflags(sb);
30105 + do_dx = !!au_opt_test(mntflags, DIO);
30106 + au_dy_arefresh(do_dx);
30109 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30110 + aufs_write_unlock(root);
30113 + inode_unlock(inode);
30115 + free_page((unsigned long)opts.opt);
30117 + err = cvt_err(err);
30122 +static const struct super_operations aufs_sop = {
30123 + .alloc_inode = aufs_alloc_inode,
30124 + .destroy_inode = aufs_destroy_inode,
30125 + .free_inode = aufs_free_inode,
30126 + /* always deleting, no clearing */
30127 + .drop_inode = generic_delete_inode,
30128 + .show_options = aufs_show_options,
30129 + .statfs = aufs_statfs,
30130 + .put_super = aufs_put_super,
30131 + .sync_fs = aufs_sync_fs,
30132 + .remount_fs = aufs_remount_fs
30135 +/* ---------------------------------------------------------------------- */
30137 +static int alloc_root(struct super_block *sb)
30140 + struct inode *inode;
30141 + struct dentry *root;
30144 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30145 + err = PTR_ERR(inode);
30146 + if (IS_ERR(inode))
30149 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30150 + inode->i_fop = &aufs_dir_fop;
30151 + inode->i_mode = S_IFDIR;
30152 + set_nlink(inode, 2);
30153 + unlock_new_inode(inode);
30155 + root = d_make_root(inode);
30156 + if (unlikely(!root))
30158 + err = PTR_ERR(root);
30159 + if (IS_ERR(root))
30162 + err = au_di_init(root);
30164 + sb->s_root = root;
30165 + return 0; /* success */
30173 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30174 + int silent __maybe_unused)
30177 + struct au_opts opts = {
30180 + struct au_sbinfo *sbinfo;
30181 + struct dentry *root;
30182 + struct inode *inode;
30183 + char *arg = raw_data;
30185 + if (unlikely(!arg || !*arg)) {
30187 + pr_err("no arg\n");
30192 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30193 + if (unlikely(!opts.opt))
30195 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30196 + opts.sb_flags = sb->s_flags;
30198 + err = au_si_alloc(sb);
30199 + if (unlikely(err))
30201 + sbinfo = au_sbi(sb);
30203 + /* all timestamps always follow the ones on the branch */
30204 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30205 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30206 + sb->s_op = &aufs_sop;
30207 + sb->s_d_op = &aufs_dop;
30208 + sb->s_magic = AUFS_SUPER_MAGIC;
30209 + sb->s_maxbytes = 0;
30210 + sb->s_stack_depth = 1;
30211 + au_export_init(sb);
30212 + au_xattr_init(sb);
30214 + err = alloc_root(sb);
30215 + if (unlikely(err)) {
30216 + si_write_unlock(sb);
30219 + root = sb->s_root;
30220 + inode = d_inode(root);
30223 + * actually we can parse options regardless aufs lock here.
30224 + * but at remount time, parsing must be done before aufs lock.
30225 + * so we follow the same rule.
30227 + ii_write_lock_parent(inode);
30228 + aufs_write_unlock(root);
30229 + err = au_opts_parse(sb, arg, &opts);
30230 + if (unlikely(err))
30233 + /* lock vfs_inode first, then aufs. */
30234 + inode_lock(inode);
30235 + aufs_write_lock(root);
30236 + err = au_opts_mount(sb, &opts);
30237 + au_opts_free(&opts);
30238 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30239 + sb->s_d_op = &aufs_dop_noreval;
30240 + pr_info("%ps\n", sb->s_d_op);
30241 + au_refresh_dop(root, /*force_reval*/0);
30242 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30243 + au_refresh_iop(inode, /*force_getattr*/0);
30245 + aufs_write_unlock(root);
30246 + inode_unlock(inode);
30248 + goto out_opts; /* success */
30252 + sb->s_root = NULL;
30254 + kobject_put(&sbinfo->si_kobj);
30255 + sb->s_fs_info = NULL;
30257 + free_page((unsigned long)opts.opt);
30260 + err = cvt_err(err);
30265 +/* ---------------------------------------------------------------------- */
30267 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30268 + const char *dev_name __maybe_unused,
30271 + struct dentry *root;
30273 + /* all timestamps always follow the ones on the branch */
30274 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30275 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30276 + if (IS_ERR(root))
30279 + au_sbilist_add(root->d_sb);
30285 +static void aufs_kill_sb(struct super_block *sb)
30287 + struct au_sbinfo *sbinfo;
30289 + sbinfo = au_sbi(sb);
30291 + au_sbilist_del(sb);
30292 + aufs_write_lock(sb->s_root);
30294 + if (sbinfo->si_wbr_create_ops->fin)
30295 + sbinfo->si_wbr_create_ops->fin(sb);
30296 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30297 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30298 + au_remount_refresh(sb, /*do_idop*/0);
30300 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30301 + au_plink_put(sb, /*verbose*/1);
30303 + au_dr_opt_flush(sb);
30304 + sbinfo->si_sb = NULL;
30305 + aufs_write_unlock(sb->s_root);
30306 + au_nwt_flush(&sbinfo->si_nowait);
30308 + kill_anon_super(sb);
30311 +struct file_system_type aufs_fs_type = {
30312 + .name = AUFS_FSTYPE,
30313 + /* a race between rename and others */
30314 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30315 + .mount = aufs_mount,
30316 + .kill_sb = aufs_kill_sb,
30317 + /* no need to __module_get() and module_put(). */
30318 + .owner = THIS_MODULE,
30320 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30321 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30322 +++ linux/fs/aufs/super.h 2021-12-03 15:38:59.939980643 +0100
30324 +/* SPDX-License-Identifier: GPL-2.0 */
30326 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30328 + * This program, aufs is free software; you can redistribute it and/or modify
30329 + * it under the terms of the GNU General Public License as published by
30330 + * the Free Software Foundation; either version 2 of the License, or
30331 + * (at your option) any later version.
30333 + * This program is distributed in the hope that it will be useful,
30334 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30335 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30336 + * GNU General Public License for more details.
30338 + * You should have received a copy of the GNU General Public License
30339 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30343 + * super_block operations
30346 +#ifndef __AUFS_SUPER_H__
30347 +#define __AUFS_SUPER_H__
30351 +#include <linux/fs.h>
30352 +#include <linux/kobject.h>
30355 +#include "rwsem.h"
30358 +/* policies to select one among multiple writable branches */
30359 +struct au_wbr_copyup_operations {
30360 + int (*copyup)(struct dentry *dentry);
30363 +#define AuWbr_DIR 1 /* target is a dir */
30364 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30366 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30367 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30368 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30370 +struct au_wbr_create_operations {
30371 + int (*create)(struct dentry *dentry, unsigned int flags);
30372 + int (*init)(struct super_block *sb);
30373 + int (*fin)(struct super_block *sb);
30376 +struct au_wbr_mfs {
30377 + struct mutex mfs_lock; /* protect this structure */
30378 + unsigned long mfs_jiffy;
30379 + unsigned long mfs_expire;
30380 + aufs_bindex_t mfs_bindex;
30382 + unsigned long long mfsrr_bytes;
30383 + unsigned long long mfsrr_watermark;
30386 +#define AuPlink_NHASH 100
30387 +static inline int au_plink_hash(ino_t ino)
30389 + return ino % AuPlink_NHASH;
30392 +/* File-based Hierarchical Storage Management */
30394 +#ifdef CONFIG_AUFS_FHSM
30395 + /* allow only one process who can receive the notification */
30396 + spinlock_t fhsm_spin;
30398 + wait_queue_head_t fhsm_wqh;
30399 + atomic_t fhsm_readable;
30401 + /* these are protected by si_rwsem */
30402 + unsigned long fhsm_expire;
30403 + aufs_bindex_t fhsm_bottom;
30408 +struct au_sbinfo {
30409 + /* nowait tasks in the system-wide workqueue */
30410 + struct au_nowait_tasks si_nowait;
30413 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30414 + * rwsem for au_sbinfo is necessary.
30416 + struct au_rwsem si_rwsem;
30419 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30422 + au_lcnt_t si_ninodes, si_nfiles;
30424 + /* branch management */
30425 + unsigned int si_generation;
30427 + /* see AuSi_ flags */
30428 + unsigned char au_si_status;
30430 + aufs_bindex_t si_bbot;
30432 + /* dirty trick to keep br_id plus */
30433 + unsigned int si_last_br_id :
30434 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30435 + struct au_branch **si_branch;
30437 + /* policy to select a writable branch */
30438 + unsigned char si_wbr_copyup;
30439 + unsigned char si_wbr_create;
30440 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30441 + struct au_wbr_create_operations *si_wbr_create_ops;
30443 + /* round robin */
30444 + atomic_t si_wbr_rr_next;
30446 + /* most free space */
30447 + struct au_wbr_mfs si_wbr_mfs;
30449 + /* File-based Hierarchical Storage Management */
30450 + struct au_fhsm si_fhsm;
30452 + /* mount flags */
30453 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30454 + unsigned int si_mntflags;
30456 + /* external inode number (bitmap and translation table) */
30457 + loff_t si_ximaxent; /* max entries in a xino */
30459 + struct file *si_xib;
30460 + struct mutex si_xib_mtx; /* protect xib members */
30461 + unsigned long *si_xib_buf;
30462 + unsigned long si_xib_last_pindex;
30463 + int si_xib_next_bit;
30465 + unsigned long si_xino_jiffy;
30466 + unsigned long si_xino_expire;
30467 + /* reserved for future use */
30468 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30470 +#ifdef CONFIG_AUFS_EXPORT
30471 + /* i_generation */
30472 + /* todo: make xigen file an array to support many inode numbers */
30473 + struct file *si_xigen;
30474 + atomic_t si_xigen_next;
30477 + /* dirty trick to support atomic_open */
30478 + struct hlist_bl_head si_aopen;
30480 + /* vdir parameters */
30481 + unsigned long si_rdcache; /* max cache time in jiffies */
30482 + unsigned int si_rdblk; /* deblk size */
30483 + unsigned int si_rdhash; /* hash size */
30486 + * If the number of whiteouts are larger than si_dirwh, leave all of
30487 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30488 + * future fsck.aufs or kernel thread will remove them later.
30489 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30491 + unsigned int si_dirwh;
30493 + /* pseudo_link list */
30494 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30495 + wait_queue_head_t si_plink_wq;
30496 + spinlock_t si_plink_maint_lock;
30497 + pid_t si_plink_maint_pid;
30500 + struct hlist_bl_head si_files;
30502 + /* with/without getattr, brother of sb->s_d_op */
30503 + const struct inode_operations *si_iop_array;
30506 + * sysfs and lifetime management.
30507 + * this is not a small structure and it may be a waste of memory in case
30508 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30509 + * but using sysfs is majority.
30511 + struct kobject si_kobj;
30512 +#ifdef CONFIG_DEBUG_FS
30513 + struct dentry *si_dbgaufs;
30514 + struct dentry *si_dbgaufs_plink;
30515 + struct dentry *si_dbgaufs_xib;
30516 +#ifdef CONFIG_AUFS_EXPORT
30517 + struct dentry *si_dbgaufs_xigen;
30521 +#ifdef CONFIG_AUFS_SBILIST
30522 + struct hlist_bl_node si_list;
30525 + /* dirty, necessary for unmounting, sysfs and sysrq */
30526 + struct super_block *si_sb;
30529 +/* sbinfo status flags */
30531 + * set true when refresh_dirs() failed at remount time.
30532 + * then try refreshing dirs at access time again.
30533 + * if it is false, refreshing dirs at access time is unnecessary
30535 +#define AuSi_FAILED_REFRESH_DIR 1
30536 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30537 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30539 +#ifndef CONFIG_AUFS_FHSM
30541 +#define AuSi_FHSM 0
30544 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30545 + unsigned int flag)
30547 + AuRwMustAnyLock(&sbi->si_rwsem);
30548 + return sbi->au_si_status & flag;
30550 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30551 +#define au_fset_si(sbinfo, name) do { \
30552 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30553 + (sbinfo)->au_si_status |= AuSi_##name; \
30555 +#define au_fclr_si(sbinfo, name) do { \
30556 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30557 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30560 +/* ---------------------------------------------------------------------- */
30562 +/* policy to select one among writable branches */
30563 +#define AuWbrCopyup(sbinfo, ...) \
30564 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30565 +#define AuWbrCreate(sbinfo, ...) \
30566 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30568 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30569 +#define AuLock_DW 1 /* write-lock dentry */
30570 +#define AuLock_IR (1 << 1) /* read-lock inode */
30571 +#define AuLock_IW (1 << 2) /* write-lock inode */
30572 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30573 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30574 + /* except RENAME_EXCHANGE */
30575 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30576 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30577 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30578 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30579 +#define au_fset_lock(flags, name) \
30580 + do { (flags) |= AuLock_##name; } while (0)
30581 +#define au_fclr_lock(flags, name) \
30582 + do { (flags) &= ~AuLock_##name; } while (0)
30584 +/* ---------------------------------------------------------------------- */
30587 +extern struct file_system_type aufs_fs_type;
30588 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30589 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30590 + unsigned long long max, void *arg);
30591 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30592 + struct super_block *sb, void *arg);
30593 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30594 +void au_iarray_free(struct inode **a, unsigned long long max);
30597 +void au_si_free(struct kobject *kobj);
30598 +int au_si_alloc(struct super_block *sb);
30599 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30601 +unsigned int au_sigen_inc(struct super_block *sb);
30602 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30604 +int si_read_lock(struct super_block *sb, int flags);
30605 +int si_write_lock(struct super_block *sb, int flags);
30606 +int aufs_read_lock(struct dentry *dentry, int flags);
30607 +void aufs_read_unlock(struct dentry *dentry, int flags);
30608 +void aufs_write_lock(struct dentry *dentry);
30609 +void aufs_write_unlock(struct dentry *dentry);
30610 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30611 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30613 +/* wbr_policy.c */
30614 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30615 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30616 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30617 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30618 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30621 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30623 +#ifdef CONFIG_AUFS_FHSM
30626 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30630 + spin_lock(&fhsm->fhsm_spin);
30631 + pid = fhsm->fhsm_pid;
30632 + spin_unlock(&fhsm->fhsm_spin);
30637 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30638 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30639 +int au_fhsm_fd(struct super_block *sb, int oflags);
30640 +int au_fhsm_br_alloc(struct au_branch *br);
30641 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30642 +void au_fhsm_fin(struct super_block *sb);
30643 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30644 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30645 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30647 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30649 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30650 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30651 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30652 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30653 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30654 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30655 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30656 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30657 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30660 +/* ---------------------------------------------------------------------- */
30662 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30664 + return sb->s_fs_info;
30667 +/* ---------------------------------------------------------------------- */
30669 +#ifdef CONFIG_AUFS_EXPORT
30670 +int au_test_nfsd(void);
30671 +void au_export_init(struct super_block *sb);
30672 +void au_xigen_inc(struct inode *inode);
30673 +int au_xigen_new(struct inode *inode);
30674 +int au_xigen_set(struct super_block *sb, struct path *path);
30675 +void au_xigen_clr(struct super_block *sb);
30677 +static inline int au_busy_or_stale(void)
30679 + if (!au_test_nfsd())
30684 +AuStubInt0(au_test_nfsd, void)
30685 +AuStubVoid(au_export_init, struct super_block *sb)
30686 +AuStubVoid(au_xigen_inc, struct inode *inode)
30687 +AuStubInt0(au_xigen_new, struct inode *inode)
30688 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30689 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30690 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30691 +#endif /* CONFIG_AUFS_EXPORT */
30693 +/* ---------------------------------------------------------------------- */
30695 +#ifdef CONFIG_AUFS_SBILIST
30697 +extern struct hlist_bl_head au_sbilist;
30699 +static inline void au_sbilist_init(void)
30701 + INIT_HLIST_BL_HEAD(&au_sbilist);
30704 +static inline void au_sbilist_add(struct super_block *sb)
30706 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30709 +static inline void au_sbilist_del(struct super_block *sb)
30711 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30714 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30715 +static inline void au_sbilist_lock(void)
30717 + hlist_bl_lock(&au_sbilist);
30720 +static inline void au_sbilist_unlock(void)
30722 + hlist_bl_unlock(&au_sbilist);
30724 +#define AuGFP_SBILIST GFP_ATOMIC
30726 +AuStubVoid(au_sbilist_lock, void)
30727 +AuStubVoid(au_sbilist_unlock, void)
30728 +#define AuGFP_SBILIST GFP_NOFS
30729 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30731 +AuStubVoid(au_sbilist_init, void)
30732 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30733 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30734 +AuStubVoid(au_sbilist_lock, void)
30735 +AuStubVoid(au_sbilist_unlock, void)
30736 +#define AuGFP_SBILIST GFP_NOFS
30739 +/* ---------------------------------------------------------------------- */
30741 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30744 + * This function is a dynamic '__init' function actually,
30745 + * so the tiny check for si_rwsem is unnecessary.
30747 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30748 +#ifdef CONFIG_DEBUG_FS
30749 + sbinfo->si_dbgaufs = NULL;
30750 + sbinfo->si_dbgaufs_plink = NULL;
30751 + sbinfo->si_dbgaufs_xib = NULL;
30752 +#ifdef CONFIG_AUFS_EXPORT
30753 + sbinfo->si_dbgaufs_xigen = NULL;
30758 +/* ---------------------------------------------------------------------- */
30760 +/* current->atomic_flags */
30761 +/* this value should never corrupt the ones defined in linux/sched.h */
30762 +#define PFA_AUFS 0x10
30764 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30765 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30766 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30768 +static inline int si_pid_test(struct super_block *sb)
30770 + return !!task_test_aufs(current);
30773 +static inline void si_pid_clr(struct super_block *sb)
30775 + AuDebugOn(!task_test_aufs(current));
30776 + task_clear_aufs(current);
30779 +static inline void si_pid_set(struct super_block *sb)
30781 + AuDebugOn(task_test_aufs(current));
30782 + task_set_aufs(current);
30785 +/* ---------------------------------------------------------------------- */
30787 +/* lock superblock. mainly for entry point functions */
30788 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30789 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30790 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30791 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30793 +#define __si_read_trylock_nested(sb) \
30794 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30795 +#define __si_write_trylock_nested(sb) \
30796 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30799 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30800 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30801 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30803 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30804 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30805 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30807 +static inline void si_noflush_read_lock(struct super_block *sb)
30809 + __si_read_lock(sb);
30813 +static inline int si_noflush_read_trylock(struct super_block *sb)
30817 + locked = __si_read_trylock(sb);
30823 +static inline void si_noflush_write_lock(struct super_block *sb)
30825 + __si_write_lock(sb);
30829 +static inline int si_noflush_write_trylock(struct super_block *sb)
30833 + locked = __si_write_trylock(sb);
30839 +#if 0 /* reserved */
30840 +static inline int si_read_trylock(struct super_block *sb, int flags)
30842 + if (au_ftest_lock(flags, FLUSH))
30843 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30844 + return si_noflush_read_trylock(sb);
30848 +static inline void si_read_unlock(struct super_block *sb)
30851 + __si_read_unlock(sb);
30854 +#if 0 /* reserved */
30855 +static inline int si_write_trylock(struct super_block *sb, int flags)
30857 + if (au_ftest_lock(flags, FLUSH))
30858 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30859 + return si_noflush_write_trylock(sb);
30863 +static inline void si_write_unlock(struct super_block *sb)
30866 + __si_write_unlock(sb);
30869 +#if 0 /* reserved */
30870 +static inline void si_downgrade_lock(struct super_block *sb)
30872 + __si_downgrade_lock(sb);
30876 +/* ---------------------------------------------------------------------- */
30878 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30880 + SiMustAnyLock(sb);
30881 + return au_sbi(sb)->si_bbot;
30884 +static inline unsigned int au_mntflags(struct super_block *sb)
30886 + SiMustAnyLock(sb);
30887 + return au_sbi(sb)->si_mntflags;
30890 +static inline unsigned int au_sigen(struct super_block *sb)
30892 + SiMustAnyLock(sb);
30893 + return au_sbi(sb)->si_generation;
30896 +static inline struct au_branch *au_sbr(struct super_block *sb,
30897 + aufs_bindex_t bindex)
30899 + SiMustAnyLock(sb);
30900 + return au_sbi(sb)->si_branch[0 + bindex];
30903 +static inline loff_t au_xi_maxent(struct super_block *sb)
30905 + SiMustAnyLock(sb);
30906 + return au_sbi(sb)->si_ximaxent;
30909 +#endif /* __KERNEL__ */
30910 +#endif /* __AUFS_SUPER_H__ */
30911 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30912 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30913 +++ linux/fs/aufs/sysaufs.c 2021-12-03 15:38:59.939980643 +0100
30915 +// SPDX-License-Identifier: GPL-2.0
30917 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30919 + * This program, aufs is free software; you can redistribute it and/or modify
30920 + * it under the terms of the GNU General Public License as published by
30921 + * the Free Software Foundation; either version 2 of the License, or
30922 + * (at your option) any later version.
30924 + * This program is distributed in the hope that it will be useful,
30925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30927 + * GNU General Public License for more details.
30929 + * You should have received a copy of the GNU General Public License
30930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30934 + * sysfs interface and lifetime management
30935 + * they are necessary regardless sysfs is disabled.
30938 +#include <linux/random.h>
30941 +unsigned long sysaufs_si_mask;
30942 +struct kset *sysaufs_kset;
30944 +#define AuSiAttr(_name) { \
30945 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30946 + .show = sysaufs_si_##_name, \
30949 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30950 +struct attribute *sysaufs_si_attrs[] = {
30951 + &sysaufs_si_attr_xi_path.attr,
30955 +static const struct sysfs_ops au_sbi_ops = {
30956 + .show = sysaufs_si_show
30959 +static struct kobj_type au_sbi_ktype = {
30960 + .release = au_si_free,
30961 + .sysfs_ops = &au_sbi_ops,
30962 + .default_attrs = sysaufs_si_attrs
30965 +/* ---------------------------------------------------------------------- */
30967 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
30971 + sbinfo->si_kobj.kset = sysaufs_kset;
30972 + /* cf. sysaufs_name() */
30973 + err = kobject_init_and_add
30974 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
30975 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
30980 +void sysaufs_fin(void)
30982 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
30983 + kset_unregister(sysaufs_kset);
30986 +int __init sysaufs_init(void)
30991 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
30992 + } while (!sysaufs_si_mask);
30995 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
30996 + if (unlikely(!sysaufs_kset))
30998 + err = PTR_ERR(sysaufs_kset);
30999 + if (IS_ERR(sysaufs_kset))
31001 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31002 + if (unlikely(err))
31003 + kset_unregister(sysaufs_kset);
31008 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31009 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31010 +++ linux/fs/aufs/sysaufs.h 2021-12-03 15:38:59.939980643 +0100
31012 +/* SPDX-License-Identifier: GPL-2.0 */
31014 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31016 + * This program, aufs is free software; you can redistribute it and/or modify
31017 + * it under the terms of the GNU General Public License as published by
31018 + * the Free Software Foundation; either version 2 of the License, or
31019 + * (at your option) any later version.
31021 + * This program is distributed in the hope that it will be useful,
31022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31024 + * GNU General Public License for more details.
31026 + * You should have received a copy of the GNU General Public License
31027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31031 + * sysfs interface and mount lifetime management
31034 +#ifndef __SYSAUFS_H__
31035 +#define __SYSAUFS_H__
31039 +#include <linux/sysfs.h>
31040 +#include "module.h"
31042 +struct super_block;
31045 +struct sysaufs_si_attr {
31046 + struct attribute attr;
31047 + int (*show)(struct seq_file *seq, struct super_block *sb);
31050 +/* ---------------------------------------------------------------------- */
31053 +extern unsigned long sysaufs_si_mask;
31054 +extern struct kset *sysaufs_kset;
31055 +extern struct attribute *sysaufs_si_attrs[];
31056 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31057 +int __init sysaufs_init(void);
31058 +void sysaufs_fin(void);
31060 +/* ---------------------------------------------------------------------- */
31062 +/* some people doesn't like to show a pointer in kernel */
31063 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31065 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31068 +#define SysaufsSiNamePrefix "si_"
31069 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31070 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31072 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31073 + sysaufs_si_id(sbinfo));
31077 +#ifdef CONFIG_SYSFS
31079 +extern struct attribute_group *sysaufs_attr_group;
31081 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31082 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31084 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31085 +#ifdef CONFIG_COMPAT
31086 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31089 +void sysaufs_br_init(struct au_branch *br);
31090 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31091 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31093 +#define sysaufs_brs_init() do {} while (0)
31096 +#define sysaufs_attr_group NULL
31098 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31099 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31100 + struct attribute *attr, char *buf)
31101 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31102 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31103 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31105 +static inline void sysaufs_brs_init(void)
31110 +#endif /* CONFIG_SYSFS */
31112 +#endif /* __KERNEL__ */
31113 +#endif /* __SYSAUFS_H__ */
31114 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31115 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31116 +++ linux/fs/aufs/sysfs.c 2021-12-03 15:38:59.939980643 +0100
31118 +// SPDX-License-Identifier: GPL-2.0
31120 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31122 + * This program, aufs is free software; you can redistribute it and/or modify
31123 + * it under the terms of the GNU General Public License as published by
31124 + * the Free Software Foundation; either version 2 of the License, or
31125 + * (at your option) any later version.
31127 + * This program is distributed in the hope that it will be useful,
31128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31130 + * GNU General Public License for more details.
31132 + * You should have received a copy of the GNU General Public License
31133 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31137 + * sysfs interface
31140 +#include <linux/compat.h>
31141 +#include <linux/seq_file.h>
31144 +#ifdef CONFIG_AUFS_FS_MODULE
31145 +/* this entry violates the "one line per file" policy of sysfs */
31146 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31150 + static char *conf =
31151 +/* this file is generated at compiling */
31152 +#include "conf.str"
31155 + err = snprintf(buf, PAGE_SIZE, conf);
31156 + if (unlikely(err >= PAGE_SIZE))
31161 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31164 +static struct attribute *au_attr[] = {
31165 +#ifdef CONFIG_AUFS_FS_MODULE
31166 + &au_config_attr.attr,
31168 + NULL, /* need to NULL terminate the list of attributes */
31171 +static struct attribute_group sysaufs_attr_group_body = {
31175 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31177 +/* ---------------------------------------------------------------------- */
31179 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31183 + SiMustAnyLock(sb);
31186 + if (au_opt_test(au_mntflags(sb), XINO)) {
31187 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31188 + seq_putc(seq, '\n');
31194 + * the lifetime of branch is independent from the entry under sysfs.
31195 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31198 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31199 + aufs_bindex_t bindex, int idx)
31202 + struct path path;
31203 + struct dentry *root;
31204 + struct au_branch *br;
31205 + au_br_perm_str_t perm;
31207 + AuDbg("b%d\n", bindex);
31210 + root = sb->s_root;
31211 + di_read_lock_parent(root, !AuLock_IR);
31212 + br = au_sbr(sb, bindex);
31215 + case AuBrSysfs_BR:
31216 + path.mnt = au_br_mnt(br);
31217 + path.dentry = au_h_dptr(root, bindex);
31218 + err = au_seq_path(seq, &path);
31220 + au_optstr_br_perm(&perm, br->br_perm);
31221 + seq_printf(seq, "=%s\n", perm.a);
31224 + case AuBrSysfs_BRID:
31225 + seq_printf(seq, "%d\n", br->br_id);
31228 + di_read_unlock(root, !AuLock_IR);
31229 + if (unlikely(err || seq_has_overflowed(seq)))
31235 +/* ---------------------------------------------------------------------- */
31237 +static struct seq_file *au_seq(char *p, ssize_t len)
31239 + struct seq_file *seq;
31241 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31243 + /* mutex_init(&seq.lock); */
31246 + return seq; /* success */
31249 + seq = ERR_PTR(-ENOMEM);
31253 +#define SysaufsBr_PREFIX "br"
31254 +#define SysaufsBrid_PREFIX "brid"
31256 +/* todo: file size may exceed PAGE_SIZE */
31257 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31263 + aufs_bindex_t bbot;
31264 + struct au_sbinfo *sbinfo;
31265 + struct super_block *sb;
31266 + struct seq_file *seq;
31268 + struct attribute **cattr;
31270 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31271 + sb = sbinfo->si_sb;
31274 + * prevent a race condition between sysfs and aufs.
31275 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31276 + * prohibits maintaining the sysfs entries.
31277 + * hew we acquire read lock after sysfs_get_active_two().
31278 + * on the other hand, the remount process may maintain the sysfs/aufs
31279 + * entries after acquiring write lock.
31280 + * it can cause a deadlock.
31281 + * simply we gave up processing read here.
31284 + if (unlikely(!si_noflush_read_trylock(sb)))
31287 + seq = au_seq(buf, PAGE_SIZE);
31288 + err = PTR_ERR(seq);
31292 + name = (void *)attr->name;
31293 + cattr = sysaufs_si_attrs;
31295 + if (!strcmp(name, (*cattr)->name)) {
31296 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31303 + if (!strncmp(name, SysaufsBrid_PREFIX,
31304 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31305 + idx = AuBrSysfs_BRID;
31306 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31307 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31308 + sizeof(SysaufsBr_PREFIX) - 1)) {
31309 + idx = AuBrSysfs_BR;
31310 + name += sizeof(SysaufsBr_PREFIX) - 1;
31314 + err = kstrtol(name, 10, &l);
31316 + bbot = au_sbbot(sb);
31318 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31325 + err = seq->count;
31326 + /* sysfs limit */
31327 + if (unlikely(err == PAGE_SIZE))
31330 + au_kfree_rcu(seq);
31332 + si_read_unlock(sb);
31337 +/* ---------------------------------------------------------------------- */
31339 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31343 + aufs_bindex_t bindex, bbot;
31346 + struct seq_file *seq;
31347 + struct au_branch *br;
31349 + si_read_lock(sb, AuLock_FLUSH);
31350 + bbot = au_sbbot(sb);
31356 + buf = (void *)__get_free_page(GFP_NOFS);
31357 + if (unlikely(!buf))
31360 + seq = au_seq(buf, PAGE_SIZE);
31361 + err = PTR_ERR(seq);
31365 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31366 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31367 + /* VERIFY_WRITE */
31368 + err = !access_ok(arg, sizeof(*arg));
31369 + if (unlikely(err))
31372 + br = au_sbr(sb, bindex);
31373 + brid = br->br_id;
31374 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31375 + err = __put_user(brid, &arg->id);
31376 + if (unlikely(err))
31379 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31380 + err = __put_user(br->br_perm, &arg->perm);
31381 + if (unlikely(err))
31384 + err = au_seq_path(seq, &br->br_path);
31385 + if (unlikely(err))
31387 + seq_putc(seq, '\0');
31388 + if (!seq_has_overflowed(seq)) {
31389 + err = copy_to_user(arg->path, seq->buf, seq->count);
31391 + if (unlikely(err))
31398 + if (unlikely(err))
31402 + au_kfree_rcu(seq);
31404 + free_page((unsigned long)buf);
31406 + si_read_unlock(sb);
31410 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31412 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31415 +#ifdef CONFIG_COMPAT
31416 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31418 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31422 +/* ---------------------------------------------------------------------- */
31424 +void sysaufs_br_init(struct au_branch *br)
31427 + struct au_brsysfs *br_sysfs;
31428 + struct attribute *attr;
31430 + br_sysfs = br->br_sysfs;
31431 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31432 + attr = &br_sysfs->attr;
31433 + sysfs_attr_init(attr);
31434 + attr->name = br_sysfs->name;
31435 + attr->mode = 0444;
31440 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31442 + struct au_branch *br;
31443 + struct kobject *kobj;
31444 + struct au_brsysfs *br_sysfs;
31446 + aufs_bindex_t bbot;
31448 + if (!sysaufs_brs)
31451 + kobj = &au_sbi(sb)->si_kobj;
31452 + bbot = au_sbbot(sb);
31453 + for (; bindex <= bbot; bindex++) {
31454 + br = au_sbr(sb, bindex);
31455 + br_sysfs = br->br_sysfs;
31456 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31457 + sysfs_remove_file(kobj, &br_sysfs->attr);
31463 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31466 + aufs_bindex_t bbot;
31467 + struct kobject *kobj;
31468 + struct au_branch *br;
31469 + struct au_brsysfs *br_sysfs;
31471 + if (!sysaufs_brs)
31474 + kobj = &au_sbi(sb)->si_kobj;
31475 + bbot = au_sbbot(sb);
31476 + for (; bindex <= bbot; bindex++) {
31477 + br = au_sbr(sb, bindex);
31478 + br_sysfs = br->br_sysfs;
31479 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31480 + SysaufsBr_PREFIX "%d", bindex);
31481 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31482 + SysaufsBrid_PREFIX "%d", bindex);
31483 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31484 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31485 + if (unlikely(err))
31486 + pr_warn("failed %s under sysfs(%d)\n",
31487 + br_sysfs->name, err);
31492 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31493 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31494 +++ linux/fs/aufs/sysrq.c 2021-12-03 15:38:59.939980643 +0100
31496 +// SPDX-License-Identifier: GPL-2.0
31498 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31500 + * This program, aufs is free software; you can redistribute it and/or modify
31501 + * it under the terms of the GNU General Public License as published by
31502 + * the Free Software Foundation; either version 2 of the License, or
31503 + * (at your option) any later version.
31505 + * This program is distributed in the hope that it will be useful,
31506 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31507 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31508 + * GNU General Public License for more details.
31510 + * You should have received a copy of the GNU General Public License
31511 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31515 + * magic sysrq handler
31518 +/* #include <linux/sysrq.h> */
31519 +#include <linux/writeback.h>
31522 +/* ---------------------------------------------------------------------- */
31524 +static void sysrq_sb(struct super_block *sb)
31527 + struct au_sbinfo *sbinfo;
31528 + struct file *file;
31529 + struct hlist_bl_head *files;
31530 + struct hlist_bl_node *pos;
31531 + struct au_finfo *finfo;
31534 + plevel = au_plevel;
31535 + au_plevel = KERN_WARNING;
31537 + /* since we define pr_fmt, call printk directly */
31538 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31540 + sbinfo = au_sbi(sb);
31541 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31542 + pr("superblock\n");
31545 +#if 0 /* reserved */
31547 + int err, i, j, ndentry;
31548 + struct au_dcsub_pages dpages;
31549 + struct au_dpage *dpage;
31551 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31552 + if (unlikely(err))
31554 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31556 + for (i = 0; i < dpages.ndpage; i++) {
31557 + dpage = dpages.dpages + i;
31558 + ndentry = dpage->ndentry;
31559 + for (j = 0; j < ndentry; j++)
31560 + au_dpri_dentry(dpage->dentries[j]);
31562 + au_dpages_free(&dpages);
31566 + pr("isolated inode\n");
31567 + spin_lock(&sb->s_inode_list_lock);
31568 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31569 + spin_lock(&i->i_lock);
31570 + if (hlist_empty(&i->i_dentry))
31571 + au_dpri_inode(i);
31572 + spin_unlock(&i->i_lock);
31574 + spin_unlock(&sb->s_inode_list_lock);
31577 + files = &au_sbi(sb)->si_files;
31578 + hlist_bl_lock(files);
31579 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31582 + file = finfo->fi_file;
31583 + mode = file_inode(file)->i_mode;
31584 + if (!special_file(mode))
31585 + au_dpri_file(file);
31587 + hlist_bl_unlock(files);
31591 + au_plevel = plevel;
31594 +/* ---------------------------------------------------------------------- */
31596 +/* module parameter */
31597 +static char *aufs_sysrq_key = "a";
31598 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31599 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31601 +static void au_sysrq(int key __maybe_unused)
31603 + struct au_sbinfo *sbinfo;
31604 + struct hlist_bl_node *pos;
31607 + au_sbilist_lock();
31608 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31609 + sysrq_sb(sbinfo->si_sb);
31610 + au_sbilist_unlock();
31614 +static struct sysrq_key_op au_sysrq_op = {
31615 + .handler = au_sysrq,
31616 + .help_msg = "Aufs",
31617 + .action_msg = "Aufs",
31618 + .enable_mask = SYSRQ_ENABLE_DUMP
31621 +/* ---------------------------------------------------------------------- */
31623 +int __init au_sysrq_init(void)
31629 + key = *aufs_sysrq_key;
31630 + if ('a' <= key && key <= 'z')
31631 + err = register_sysrq_key(key, &au_sysrq_op);
31632 + if (unlikely(err))
31633 + pr_err("err %d, sysrq=%c\n", err, key);
31637 +void au_sysrq_fin(void)
31641 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31642 + if (unlikely(err))
31643 + pr_err("err %d (ignored)\n", err);
31645 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31646 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31647 +++ linux/fs/aufs/vdir.c 2021-12-03 15:38:59.939980643 +0100
31649 +// SPDX-License-Identifier: GPL-2.0
31651 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31653 + * This program, aufs is free software; you can redistribute it and/or modify
31654 + * it under the terms of the GNU General Public License as published by
31655 + * the Free Software Foundation; either version 2 of the License, or
31656 + * (at your option) any later version.
31658 + * This program is distributed in the hope that it will be useful,
31659 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31660 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31661 + * GNU General Public License for more details.
31663 + * You should have received a copy of the GNU General Public License
31664 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31668 + * virtual or vertical directory
31671 +#include <linux/iversion.h>
31674 +static unsigned int calc_size(int nlen)
31676 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31679 +static int set_deblk_end(union au_vdir_deblk_p *p,
31680 + union au_vdir_deblk_p *deblk_end)
31682 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31683 + p->de->de_str.len = 0;
31687 + return -1; /* error */
31690 +/* returns true or false */
31691 +static int is_deblk_end(union au_vdir_deblk_p *p,
31692 + union au_vdir_deblk_p *deblk_end)
31694 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31695 + return !p->de->de_str.len;
31699 +static unsigned char *last_deblk(struct au_vdir *vdir)
31701 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31704 +/* ---------------------------------------------------------------------- */
31706 +/* estimate the appropriate size for name hash table */
31707 +unsigned int au_rdhash_est(loff_t sz)
31715 + if (sz < AUFS_RDHASH_DEF)
31716 + n = AUFS_RDHASH_DEF;
31717 + /* pr_info("n %u\n", n); */
31722 + * the allocated memory has to be freed by
31723 + * au_nhash_wh_free() or au_nhash_de_free().
31725 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31727 + struct hlist_head *head;
31731 + sz = sizeof(*nhash->nh_head) * num_hash;
31732 + head = kmalloc(sz, gfp);
31734 + nhash->nh_num = num_hash;
31735 + nhash->nh_head = head;
31736 + for (u = 0; u < num_hash; u++)
31737 + INIT_HLIST_HEAD(head++);
31738 + return 0; /* success */
31744 +static void nhash_count(struct hlist_head *head)
31746 +#if 0 /* debugging */
31748 + struct hlist_node *pos;
31751 + hlist_for_each(pos, head)
31753 + pr_info("%lu\n", n);
31757 +static void au_nhash_wh_do_free(struct hlist_head *head)
31759 + struct au_vdir_wh *pos;
31760 + struct hlist_node *node;
31762 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31763 + au_kfree_rcu(pos);
31766 +static void au_nhash_de_do_free(struct hlist_head *head)
31768 + struct au_vdir_dehstr *pos;
31769 + struct hlist_node *node;
31771 + hlist_for_each_entry_safe(pos, node, head, hash)
31772 + au_cache_free_vdir_dehstr(pos);
31775 +static void au_nhash_do_free(struct au_nhash *nhash,
31776 + void (*free)(struct hlist_head *head))
31779 + struct hlist_head *head;
31781 + n = nhash->nh_num;
31785 + head = nhash->nh_head;
31786 + while (n-- > 0) {
31787 + nhash_count(head);
31790 + au_kfree_try_rcu(nhash->nh_head);
31793 +void au_nhash_wh_free(struct au_nhash *whlist)
31795 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31798 +static void au_nhash_de_free(struct au_nhash *delist)
31800 + au_nhash_do_free(delist, au_nhash_de_do_free);
31803 +/* ---------------------------------------------------------------------- */
31805 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31809 + unsigned int u, n;
31810 + struct hlist_head *head;
31811 + struct au_vdir_wh *pos;
31814 + n = whlist->nh_num;
31815 + head = whlist->nh_head;
31816 + for (u = 0; u < n; u++, head++)
31817 + hlist_for_each_entry(pos, head, wh_hash)
31818 + if (pos->wh_bindex == btgt && ++num > limit)
31823 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31824 + unsigned char *name,
31825 + unsigned int len)
31828 + /* const unsigned int magic_bit = 12; */
31830 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31837 + /* v = hash_long(v, magic_bit); */
31838 + v %= nhash->nh_num;
31839 + return nhash->nh_head + v;
31842 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31845 + return str->len == nlen && !memcmp(str->name, name, nlen);
31848 +/* returns found or not */
31849 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31851 + struct hlist_head *head;
31852 + struct au_vdir_wh *pos;
31853 + struct au_vdir_destr *str;
31855 + head = au_name_hash(whlist, name, nlen);
31856 + hlist_for_each_entry(pos, head, wh_hash) {
31857 + str = &pos->wh_str;
31858 + AuDbg("%.*s\n", str->len, str->name);
31859 + if (au_nhash_test_name(str, name, nlen))
31865 +/* returns found(true) or not */
31866 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31868 + struct hlist_head *head;
31869 + struct au_vdir_dehstr *pos;
31870 + struct au_vdir_destr *str;
31872 + head = au_name_hash(delist, name, nlen);
31873 + hlist_for_each_entry(pos, head, hash) {
31875 + AuDbg("%.*s\n", str->len, str->name);
31876 + if (au_nhash_test_name(str, name, nlen))
31882 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31883 + unsigned char d_type)
31885 +#ifdef CONFIG_AUFS_SHWH
31886 + wh->wh_ino = ino;
31887 + wh->wh_type = d_type;
31891 +/* ---------------------------------------------------------------------- */
31893 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31894 + unsigned int d_type, aufs_bindex_t bindex,
31895 + unsigned char shwh)
31898 + struct au_vdir_destr *str;
31899 + struct au_vdir_wh *wh;
31901 + AuDbg("%.*s\n", nlen, name);
31902 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31905 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31906 + if (unlikely(!wh))
31910 + wh->wh_bindex = bindex;
31912 + au_shwh_init_wh(wh, ino, d_type);
31913 + str = &wh->wh_str;
31915 + memcpy(str->name, name, nlen);
31916 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31923 +static int append_deblk(struct au_vdir *vdir)
31926 + unsigned long ul;
31927 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31928 + union au_vdir_deblk_p p, deblk_end;
31929 + unsigned char **o;
31932 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31933 + GFP_NOFS, /*may_shrink*/0);
31934 + if (unlikely(!o))
31937 + vdir->vd_deblk = o;
31938 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31940 + ul = vdir->vd_nblk++;
31941 + vdir->vd_deblk[ul] = p.deblk;
31942 + vdir->vd_last.ul = ul;
31943 + vdir->vd_last.p.deblk = p.deblk;
31944 + deblk_end.deblk = p.deblk + deblk_sz;
31945 + err = set_deblk_end(&p, &deblk_end);
31952 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31953 + unsigned int d_type, struct au_nhash *delist)
31957 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31958 + union au_vdir_deblk_p p, *room, deblk_end;
31959 + struct au_vdir_dehstr *dehstr;
31961 + p.deblk = last_deblk(vdir);
31962 + deblk_end.deblk = p.deblk + deblk_sz;
31963 + room = &vdir->vd_last.p;
31964 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
31965 + || !is_deblk_end(room, &deblk_end));
31967 + sz = calc_size(nlen);
31968 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
31969 + err = append_deblk(vdir);
31970 + if (unlikely(err))
31973 + p.deblk = last_deblk(vdir);
31974 + deblk_end.deblk = p.deblk + deblk_sz;
31976 + AuDebugOn(room->deblk != p.deblk);
31980 + dehstr = au_cache_alloc_vdir_dehstr();
31981 + if (unlikely(!dehstr))
31984 + dehstr->str = &room->de->de_str;
31985 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
31986 + room->de->de_ino = ino;
31987 + room->de->de_type = d_type;
31988 + room->de->de_str.len = nlen;
31989 + memcpy(room->de->de_str.name, name, nlen);
31992 + room->deblk += sz;
31993 + if (unlikely(set_deblk_end(room, &deblk_end)))
31994 + err = append_deblk(vdir);
32001 +/* ---------------------------------------------------------------------- */
32003 +void au_vdir_free(struct au_vdir *vdir)
32005 + unsigned char **deblk;
32007 + deblk = vdir->vd_deblk;
32008 + while (vdir->vd_nblk--)
32009 + au_kfree_try_rcu(*deblk++);
32010 + au_kfree_try_rcu(vdir->vd_deblk);
32011 + au_cache_free_vdir(vdir);
32014 +static struct au_vdir *alloc_vdir(struct file *file)
32016 + struct au_vdir *vdir;
32017 + struct super_block *sb;
32020 + sb = file->f_path.dentry->d_sb;
32021 + SiMustAnyLock(sb);
32024 + vdir = au_cache_alloc_vdir();
32025 + if (unlikely(!vdir))
32028 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32029 + if (unlikely(!vdir->vd_deblk))
32032 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32033 + if (!vdir->vd_deblk_sz) {
32034 + /* estimate the appropriate size for deblk */
32035 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32036 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32038 + vdir->vd_nblk = 0;
32039 + vdir->vd_version = 0;
32040 + vdir->vd_jiffy = 0;
32041 + err = append_deblk(vdir);
32043 + return vdir; /* success */
32045 + au_kfree_try_rcu(vdir->vd_deblk);
32048 + au_cache_free_vdir(vdir);
32050 + vdir = ERR_PTR(err);
32054 +static int reinit_vdir(struct au_vdir *vdir)
32057 + union au_vdir_deblk_p p, deblk_end;
32059 + while (vdir->vd_nblk > 1) {
32060 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32061 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32064 + p.deblk = vdir->vd_deblk[0];
32065 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32066 + err = set_deblk_end(&p, &deblk_end);
32067 + /* keep vd_dblk_sz */
32068 + vdir->vd_last.ul = 0;
32069 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32070 + vdir->vd_version = 0;
32071 + vdir->vd_jiffy = 0;
32076 +/* ---------------------------------------------------------------------- */
32078 +#define AuFillVdir_CALLED 1
32079 +#define AuFillVdir_WHABLE (1 << 1)
32080 +#define AuFillVdir_SHWH (1 << 2)
32081 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32082 +#define au_fset_fillvdir(flags, name) \
32083 + do { (flags) |= AuFillVdir_##name; } while (0)
32084 +#define au_fclr_fillvdir(flags, name) \
32085 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32087 +#ifndef CONFIG_AUFS_SHWH
32088 +#undef AuFillVdir_SHWH
32089 +#define AuFillVdir_SHWH 0
32092 +struct fillvdir_arg {
32093 + struct dir_context ctx;
32094 + struct file *file;
32095 + struct au_vdir *vdir;
32096 + struct au_nhash delist;
32097 + struct au_nhash whlist;
32098 + aufs_bindex_t bindex;
32099 + unsigned int flags;
32103 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32104 + loff_t offset __maybe_unused, u64 h_ino,
32105 + unsigned int d_type)
32107 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32108 + char *name = (void *)__name;
32109 + struct super_block *sb;
32111 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32114 + sb = arg->file->f_path.dentry->d_sb;
32115 + au_fset_fillvdir(arg->flags, CALLED);
32117 + if (nlen <= AUFS_WH_PFX_LEN
32118 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32119 + if (test_known(&arg->delist, name, nlen)
32120 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32121 + goto out; /* already exists or whiteouted */
32123 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32125 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32126 + d_type = DT_UNKNOWN;
32127 + arg->err = append_de(arg->vdir, name, nlen, ino,
32128 + d_type, &arg->delist);
32130 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32131 + name += AUFS_WH_PFX_LEN;
32132 + nlen -= AUFS_WH_PFX_LEN;
32133 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32134 + goto out; /* already whiteouted */
32136 + ino = 0; /* just to suppress a warning */
32138 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32141 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32142 + d_type = DT_UNKNOWN;
32143 + arg->err = au_nhash_append_wh
32144 + (&arg->whlist, name, nlen, ino, d_type,
32145 + arg->bindex, shwh);
32151 + arg->vdir->vd_jiffy = jiffies;
32153 + AuTraceErr(arg->err);
32157 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32158 + struct au_nhash *whlist, struct au_nhash *delist)
32160 +#ifdef CONFIG_AUFS_SHWH
32162 + unsigned int nh, u;
32163 + struct hlist_head *head;
32164 + struct au_vdir_wh *pos;
32165 + struct hlist_node *n;
32167 + struct au_vdir_destr *destr;
32169 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32172 + o = p = (void *)__get_free_page(GFP_NOFS);
32173 + if (unlikely(!p))
32177 + nh = whlist->nh_num;
32178 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32179 + p += AUFS_WH_PFX_LEN;
32180 + for (u = 0; u < nh; u++) {
32181 + head = whlist->nh_head + u;
32182 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32183 + destr = &pos->wh_str;
32184 + memcpy(p, destr->name, destr->len);
32185 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32186 + pos->wh_ino, pos->wh_type, delist);
32187 + if (unlikely(err))
32192 + free_page((unsigned long)o);
32202 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32205 + unsigned int rdhash;
32207 + aufs_bindex_t bbot, bindex, btop;
32208 + unsigned char shwh;
32209 + struct file *hf, *file;
32210 + struct super_block *sb;
32212 + file = arg->file;
32213 + sb = file->f_path.dentry->d_sb;
32214 + SiMustAnyLock(sb);
32216 + rdhash = au_sbi(sb)->si_rdhash;
32218 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32219 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32220 + if (unlikely(err))
32222 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32223 + if (unlikely(err))
32229 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32231 + au_fset_fillvdir(arg->flags, SHWH);
32233 + btop = au_fbtop(file);
32234 + bbot = au_fbbot_dir(file);
32235 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32236 + hf = au_hf_dir(file, bindex);
32240 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32242 + if (unlikely(offset))
32245 + arg->bindex = bindex;
32246 + au_fclr_fillvdir(arg->flags, WHABLE);
32248 + || (bindex != bbot
32249 + && au_br_whable(au_sbr_perm(sb, bindex))))
32250 + au_fset_fillvdir(arg->flags, WHABLE);
32253 + au_fclr_fillvdir(arg->flags, CALLED);
32255 + err = vfsub_iterate_dir(hf, &arg->ctx);
32258 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32261 + * dir_relax() may be good for concurrency, but aufs should not
32262 + * use it since it will cause a lockdep problem.
32266 + if (!err && shwh)
32267 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32269 + au_nhash_wh_free(&arg->whlist);
32272 + au_nhash_de_free(&arg->delist);
32277 +static int read_vdir(struct file *file, int may_read)
32280 + unsigned long expire;
32281 + unsigned char do_read;
32282 + struct fillvdir_arg arg = {
32284 + .actor = fillvdir
32287 + struct inode *inode;
32288 + struct au_vdir *vdir, *allocated;
32291 + inode = file_inode(file);
32292 + IMustLock(inode);
32293 + IiMustWriteLock(inode);
32294 + SiMustAnyLock(inode->i_sb);
32296 + allocated = NULL;
32298 + expire = au_sbi(inode->i_sb)->si_rdcache;
32299 + vdir = au_ivdir(inode);
32302 + vdir = alloc_vdir(file);
32303 + err = PTR_ERR(vdir);
32304 + if (IS_ERR(vdir))
32307 + allocated = vdir;
32308 + } else if (may_read
32309 + && (!inode_eq_iversion(inode, vdir->vd_version)
32310 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32312 + err = reinit_vdir(vdir);
32313 + if (unlikely(err))
32318 + return 0; /* success */
32322 + err = au_do_read_vdir(&arg);
32324 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32325 + vdir->vd_version = inode_query_iversion(inode);
32326 + vdir->vd_last.ul = 0;
32327 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32329 + au_set_ivdir(inode, allocated);
32330 + } else if (allocated)
32331 + au_vdir_free(allocated);
32337 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32340 + unsigned long ul, n;
32341 + const unsigned int deblk_sz = src->vd_deblk_sz;
32343 + AuDebugOn(tgt->vd_nblk != 1);
32346 + if (tgt->vd_nblk < src->vd_nblk) {
32347 + unsigned char **p;
32349 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32350 + GFP_NOFS, /*may_shrink*/0);
32351 + if (unlikely(!p))
32353 + tgt->vd_deblk = p;
32356 + if (tgt->vd_deblk_sz != deblk_sz) {
32357 + unsigned char *p;
32359 + tgt->vd_deblk_sz = deblk_sz;
32360 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32361 + /*may_shrink*/1);
32362 + if (unlikely(!p))
32364 + tgt->vd_deblk[0] = p;
32366 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32367 + tgt->vd_version = src->vd_version;
32368 + tgt->vd_jiffy = src->vd_jiffy;
32370 + n = src->vd_nblk;
32371 + for (ul = 1; ul < n; ul++) {
32372 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32374 + if (unlikely(!tgt->vd_deblk[ul]))
32378 + tgt->vd_nblk = n;
32379 + tgt->vd_last.ul = tgt->vd_last.ul;
32380 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32381 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32382 + - src->vd_deblk[src->vd_last.ul];
32384 + return 0; /* success */
32387 + rerr = reinit_vdir(tgt);
32392 +int au_vdir_init(struct file *file)
32395 + struct inode *inode;
32396 + struct au_vdir *vdir_cache, *allocated;
32398 + /* test file->f_pos here instead of ctx->pos */
32399 + err = read_vdir(file, !file->f_pos);
32400 + if (unlikely(err))
32403 + allocated = NULL;
32404 + vdir_cache = au_fvdir_cache(file);
32405 + if (!vdir_cache) {
32406 + vdir_cache = alloc_vdir(file);
32407 + err = PTR_ERR(vdir_cache);
32408 + if (IS_ERR(vdir_cache))
32410 + allocated = vdir_cache;
32411 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32412 + /* test file->f_pos here instead of ctx->pos */
32413 + err = reinit_vdir(vdir_cache);
32414 + if (unlikely(err))
32417 + return 0; /* success */
32419 + inode = file_inode(file);
32420 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32422 + file->f_version = inode_query_iversion(inode);
32424 + au_set_fvdir_cache(file, allocated);
32425 + } else if (allocated)
32426 + au_vdir_free(allocated);
32432 +static loff_t calc_offset(struct au_vdir *vdir)
32435 + union au_vdir_deblk_p p;
32437 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32438 + offset = vdir->vd_last.p.deblk - p.deblk;
32439 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32443 +/* returns true or false */
32444 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32447 + unsigned int deblk_sz;
32448 + unsigned long ul, n;
32450 + union au_vdir_deblk_p p, deblk_end;
32451 + struct au_vdir *vdir_cache;
32454 + vdir_cache = au_fvdir_cache(file);
32455 + offset = calc_offset(vdir_cache);
32456 + AuDbg("offset %lld\n", offset);
32457 + if (ctx->pos == offset)
32460 + vdir_cache->vd_last.ul = 0;
32461 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32466 + deblk_sz = vdir_cache->vd_deblk_sz;
32467 + ul = div64_u64(ctx->pos, deblk_sz);
32468 + AuDbg("ul %lu\n", ul);
32469 + if (ul >= vdir_cache->vd_nblk)
32472 + n = vdir_cache->vd_nblk;
32473 + for (; ul < n; ul++) {
32474 + p.deblk = vdir_cache->vd_deblk[ul];
32475 + deblk_end.deblk = p.deblk + deblk_sz;
32477 + offset *= deblk_sz;
32478 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32481 + l = calc_size(p.de->de_str.len);
32485 + if (!is_deblk_end(&p, &deblk_end)) {
32487 + vdir_cache->vd_last.ul = ul;
32488 + vdir_cache->vd_last.p = p;
32496 + AuDbg("valid %d\n", !valid);
32500 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32502 + unsigned int l, deblk_sz;
32503 + union au_vdir_deblk_p deblk_end;
32504 + struct au_vdir *vdir_cache;
32505 + struct au_vdir_de *de;
32507 + if (!seek_vdir(file, ctx))
32510 + vdir_cache = au_fvdir_cache(file);
32511 + deblk_sz = vdir_cache->vd_deblk_sz;
32513 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32514 + deblk_end.deblk += deblk_sz;
32515 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32516 + de = vdir_cache->vd_last.p.de;
32517 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32518 + de->de_str.len, de->de_str.name, ctx->pos,
32519 + (unsigned long)de->de_ino, de->de_type);
32520 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32521 + de->de_str.len, de->de_ino,
32523 + /* todo: ignore the error caused by udba? */
32524 + /* return err; */
32528 + l = calc_size(de->de_str.len);
32529 + vdir_cache->vd_last.p.deblk += l;
32532 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32533 + vdir_cache->vd_last.ul++;
32534 + vdir_cache->vd_last.p.deblk
32535 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32536 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32545 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32546 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32547 +++ linux/fs/aufs/vfsub.c 2021-12-03 15:38:59.939980643 +0100
32549 +// SPDX-License-Identifier: GPL-2.0
32551 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32553 + * This program, aufs is free software; you can redistribute it and/or modify
32554 + * it under the terms of the GNU General Public License as published by
32555 + * the Free Software Foundation; either version 2 of the License, or
32556 + * (at your option) any later version.
32558 + * This program is distributed in the hope that it will be useful,
32559 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32560 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32561 + * GNU General Public License for more details.
32563 + * You should have received a copy of the GNU General Public License
32564 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32568 + * sub-routines for VFS
32571 +#include <linux/mnt_namespace.h>
32572 +#include <linux/namei.h>
32573 +#include <linux/nsproxy.h>
32574 +#include <linux/security.h>
32575 +#include <linux/splice.h>
32578 +#ifdef CONFIG_AUFS_BR_FUSE
32579 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32581 + if (!au_test_fuse(h_sb) || !au_userns)
32584 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32588 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32593 + down_read(&h_sb->s_umount);
32594 + err = sync_filesystem(h_sb);
32595 + up_read(&h_sb->s_umount);
32601 +/* ---------------------------------------------------------------------- */
32603 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32607 + struct super_block *h_sb;
32610 + * Always needs h_path->mnt for LSM or FUSE branch.
32612 + AuDebugOn(!h_path->mnt);
32614 + /* for remote fs, leave work for its getattr or d_revalidate */
32615 + /* for bad i_attr fs, handle them in aufs_getattr() */
32616 + /* still some fs may acquire i_mutex. we need to skip them */
32620 + h_sb = h_path->dentry->d_sb;
32621 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32623 + err = vfsub_getattr(h_path, &st);
32628 +/* ---------------------------------------------------------------------- */
32630 +struct file *vfsub_dentry_open(struct path *path, int flags)
32632 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32636 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32638 + struct file *file;
32641 + file = filp_open(path,
32642 + oflags /* | __FMODE_NONOTIFY */,
32645 + if (IS_ERR(file))
32647 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32654 + * Ideally this function should call VFS:do_last() in order to keep all its
32655 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32656 + * structure such as nameidata. This is a second (or third) best approach.
32657 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32659 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32660 + struct vfsub_aopen_args *args)
32663 + struct au_branch *br = args->br;
32664 + struct file *file = args->file;
32665 + /* copied from linux/fs/namei.c:atomic_open() */
32666 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32669 + AuDebugOn(!dir->i_op->atomic_open);
32671 + err = au_br_test_oflag(args->open_flag, br);
32672 + if (unlikely(err))
32675 + au_lcnt_inc(&br->br_nfiles);
32676 + file->f_path.dentry = DENTRY_NOT_SET;
32677 + file->f_path.mnt = au_br_mnt(br);
32678 + AuDbg("%ps\n", dir->i_op->atomic_open);
32679 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32680 + args->create_mode);
32681 + if (unlikely(err < 0)) {
32682 + au_lcnt_dec(&br->br_nfiles);
32686 + /* temporary workaround for nfsv4 branch */
32687 + if (au_test_nfs(dir->i_sb))
32688 + nfs_mark_for_revalidate(dir);
32690 + if (file->f_mode & FMODE_CREATED)
32691 + fsnotify_create(dir, dentry);
32692 + if (!(file->f_mode & FMODE_OPENED)) {
32693 + au_lcnt_dec(&br->br_nfiles);
32697 + /* todo: call VFS:may_open() here */
32698 + /* todo: ima_file_check() too? */
32699 + if (!err && (args->open_flag & __FMODE_EXEC))
32700 + err = deny_write_access(file);
32702 + fsnotify_open(file);
32704 + au_lcnt_dec(&br->br_nfiles);
32705 + /* note that the file is created and still opened */
32711 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32715 + err = kern_path(name, flags, path);
32716 + if (!err && d_is_positive(path->dentry))
32717 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32721 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32722 + struct path *ppath, int len)
32724 + struct path path;
32726 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
32727 + if (IS_ERR(path.dentry))
32729 + if (d_is_positive(path.dentry)) {
32730 + path.mnt = ppath->mnt;
32731 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32735 + AuTraceErrPtr(path.dentry);
32736 + return path.dentry;
32739 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
32742 + struct path path;
32744 + /* VFS checks it too, but by WARN_ON_ONCE() */
32745 + IMustLock(d_inode(ppath->dentry));
32747 + path.dentry = lookup_one_len(name, ppath->dentry, len);
32748 + if (IS_ERR(path.dentry))
32750 + if (d_is_positive(path.dentry)) {
32751 + path.mnt = ppath->mnt;
32752 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32756 + AuTraceErrPtr(path.dentry);
32757 + return path.dentry;
32760 +void vfsub_call_lkup_one(void *args)
32762 + struct vfsub_lkup_one_args *a = args;
32763 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
32766 +/* ---------------------------------------------------------------------- */
32768 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32769 + struct dentry *d2, struct au_hinode *hdir2)
32771 + struct dentry *d;
32774 + d = lock_rename(d1, d2);
32776 + au_hn_suspend(hdir1);
32777 + if (hdir1 != hdir2)
32778 + au_hn_suspend(hdir2);
32783 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32784 + struct dentry *d2, struct au_hinode *hdir2)
32786 + au_hn_resume(hdir1);
32787 + if (hdir1 != hdir2)
32788 + au_hn_resume(hdir2);
32790 + unlock_rename(d1, d2);
32794 +/* ---------------------------------------------------------------------- */
32796 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32799 + struct dentry *d;
32803 + d = path->dentry;
32804 + path->dentry = d->d_parent;
32805 + err = security_path_mknod(path, d, mode, 0);
32806 + path->dentry = d;
32807 + if (unlikely(err))
32811 + err = vfs_create(dir, path->dentry, mode, want_excl);
32814 + struct path tmp = *path;
32817 + vfsub_update_h_iattr(&tmp, &did);
32819 + tmp.dentry = path->dentry->d_parent;
32820 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32829 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32832 + struct dentry *d;
32836 + d = path->dentry;
32837 + path->dentry = d->d_parent;
32838 + err = security_path_symlink(path, d, symname);
32839 + path->dentry = d;
32840 + if (unlikely(err))
32844 + err = vfs_symlink(dir, path->dentry, symname);
32847 + struct path tmp = *path;
32850 + vfsub_update_h_iattr(&tmp, &did);
32852 + tmp.dentry = path->dentry->d_parent;
32853 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32862 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32865 + struct dentry *d;
32869 + d = path->dentry;
32870 + path->dentry = d->d_parent;
32871 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32872 + path->dentry = d;
32873 + if (unlikely(err))
32877 + err = vfs_mknod(dir, path->dentry, mode, dev);
32880 + struct path tmp = *path;
32883 + vfsub_update_h_iattr(&tmp, &did);
32885 + tmp.dentry = path->dentry->d_parent;
32886 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32895 +static int au_test_nlink(struct inode *inode)
32897 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32899 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32900 + || inode->i_nlink < link_max)
32905 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32906 + struct inode **delegated_inode)
32909 + struct dentry *d;
32913 + err = au_test_nlink(d_inode(src_dentry));
32914 + if (unlikely(err))
32917 + /* we don't call may_linkat() */
32918 + d = path->dentry;
32919 + path->dentry = d->d_parent;
32920 + err = security_path_link(src_dentry, path, d);
32921 + path->dentry = d;
32922 + if (unlikely(err))
32926 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32929 + struct path tmp = *path;
32932 + /* fuse has different memory inode for the same inumber */
32933 + vfsub_update_h_iattr(&tmp, &did);
32935 + tmp.dentry = path->dentry->d_parent;
32936 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32937 + tmp.dentry = src_dentry;
32938 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32947 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32948 + struct inode *dir, struct path *path,
32949 + struct inode **delegated_inode, unsigned int flags)
32952 + struct path tmp = {
32955 + struct dentry *d;
32958 + IMustLock(src_dir);
32960 + d = path->dentry;
32961 + path->dentry = d->d_parent;
32962 + tmp.dentry = src_dentry->d_parent;
32963 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32964 + path->dentry = d;
32965 + if (unlikely(err))
32969 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
32970 + delegated_inode, flags);
32975 + tmp.dentry = d->d_parent;
32976 + vfsub_update_h_iattr(&tmp, &did);
32978 + tmp.dentry = src_dentry;
32979 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32980 + tmp.dentry = src_dentry->d_parent;
32981 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32990 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
32993 + struct dentry *d;
32997 + d = path->dentry;
32998 + path->dentry = d->d_parent;
32999 + err = security_path_mkdir(path, d, mode);
33000 + path->dentry = d;
33001 + if (unlikely(err))
33005 + err = vfs_mkdir(dir, path->dentry, mode);
33008 + struct path tmp = *path;
33011 + vfsub_update_h_iattr(&tmp, &did);
33013 + tmp.dentry = path->dentry->d_parent;
33014 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33023 +int vfsub_rmdir(struct inode *dir, struct path *path)
33026 + struct dentry *d;
33030 + d = path->dentry;
33031 + path->dentry = d->d_parent;
33032 + err = security_path_rmdir(path, d);
33033 + path->dentry = d;
33034 + if (unlikely(err))
33038 + err = vfs_rmdir(dir, path->dentry);
33041 + struct path tmp = {
33042 + .dentry = path->dentry->d_parent,
33046 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33053 +/* ---------------------------------------------------------------------- */
33055 +/* todo: support mmap_sem? */
33056 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33062 + err = vfs_read(file, ubuf, count, ppos);
33065 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33069 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33075 + err = kernel_read(file, kbuf, count, ppos);
33079 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33083 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33089 + err = vfs_write(file, ubuf, count, ppos);
33092 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33096 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33101 + err = kernel_write(file, kbuf, count, ppos);
33104 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33108 +int vfsub_flush(struct file *file, fl_owner_t id)
33113 + if (file->f_op->flush) {
33114 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33115 + err = file->f_op->flush(file, id);
33118 + err = file->f_op->flush(file, id);
33122 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33128 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33132 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33135 + err = iterate_dir(file, ctx);
33138 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33143 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33144 + struct pipe_inode_info *pipe, size_t len,
33145 + unsigned int flags)
33150 + err = do_splice_to(in, ppos, pipe, len, flags);
33152 + file_accessed(in);
33154 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33158 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33159 + loff_t *ppos, size_t len, unsigned int flags)
33164 + err = do_splice_from(pipe, out, ppos, len, flags);
33167 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33171 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33175 + /* file can be NULL */
33177 + err = vfs_fsync(file, datasync);
33181 + AuDebugOn(!file);
33182 + path = &file->f_path;
33184 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33189 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33190 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33191 + struct file *h_file)
33194 + struct inode *h_inode;
33195 + struct super_block *h_sb;
33198 + err = vfsub_truncate(h_path, length);
33202 + h_inode = d_inode(h_path->dentry);
33203 + h_sb = h_inode->i_sb;
33205 + sb_start_write(h_sb);
33207 + err = locks_verify_truncate(h_inode, h_file, length);
33209 + err = security_path_truncate(h_path);
33212 + err = do_truncate(h_path->dentry, length, attr, h_file);
33216 + sb_end_write(h_sb);
33223 +/* ---------------------------------------------------------------------- */
33225 +struct au_vfsub_mkdir_args {
33227 + struct inode *dir;
33228 + struct path *path;
33232 +static void au_call_vfsub_mkdir(void *args)
33234 + struct au_vfsub_mkdir_args *a = args;
33235 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33238 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33240 + int err, do_sio, wkq_err;
33242 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33245 + err = vfsub_mkdir(dir, path, mode);
33248 + struct au_vfsub_mkdir_args args = {
33254 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33255 + if (unlikely(wkq_err))
33262 +struct au_vfsub_rmdir_args {
33264 + struct inode *dir;
33265 + struct path *path;
33268 +static void au_call_vfsub_rmdir(void *args)
33270 + struct au_vfsub_rmdir_args *a = args;
33271 + *a->errp = vfsub_rmdir(a->dir, a->path);
33274 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33276 + int err, do_sio, wkq_err;
33278 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33281 + err = vfsub_rmdir(dir, path);
33284 + struct au_vfsub_rmdir_args args = {
33289 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33290 + if (unlikely(wkq_err))
33297 +/* ---------------------------------------------------------------------- */
33299 +struct notify_change_args {
33301 + struct path *path;
33302 + struct iattr *ia;
33303 + struct inode **delegated_inode;
33306 +static void call_notify_change(void *args)
33308 + struct notify_change_args *a = args;
33309 + struct inode *h_inode;
33311 + h_inode = d_inode(a->path->dentry);
33312 + IMustLock(h_inode);
33314 + *a->errp = -EPERM;
33315 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33317 + *a->errp = notify_change(a->path->dentry, a->ia,
33318 + a->delegated_inode);
33321 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33323 + AuTraceErr(*a->errp);
33326 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33327 + struct inode **delegated_inode)
33330 + struct notify_change_args args = {
33334 + .delegated_inode = delegated_inode
33337 + call_notify_change(&args);
33342 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33343 + struct inode **delegated_inode)
33345 + int err, wkq_err;
33346 + struct notify_change_args args = {
33350 + .delegated_inode = delegated_inode
33353 + wkq_err = au_wkq_wait(call_notify_change, &args);
33354 + if (unlikely(wkq_err))
33360 +/* ---------------------------------------------------------------------- */
33362 +struct unlink_args {
33364 + struct inode *dir;
33365 + struct path *path;
33366 + struct inode **delegated_inode;
33369 +static void call_unlink(void *args)
33371 + struct unlink_args *a = args;
33372 + struct dentry *d = a->path->dentry;
33373 + struct inode *h_inode;
33374 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33375 + && au_dcount(d) == 1);
33377 + IMustLock(a->dir);
33379 + a->path->dentry = d->d_parent;
33380 + *a->errp = security_path_unlink(a->path, d);
33381 + a->path->dentry = d;
33382 + if (unlikely(*a->errp))
33385 + if (!stop_sillyrename)
33388 + if (d_is_positive(d)) {
33389 + h_inode = d_inode(d);
33394 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33397 + struct path tmp = {
33398 + .dentry = d->d_parent,
33399 + .mnt = a->path->mnt
33401 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33404 + if (!stop_sillyrename)
33409 + AuTraceErr(*a->errp);
33413 + * @dir: must be locked.
33414 + * @dentry: target dentry.
33416 +int vfsub_unlink(struct inode *dir, struct path *path,
33417 + struct inode **delegated_inode, int force)
33420 + struct unlink_args args = {
33424 + .delegated_inode = delegated_inode
33428 + call_unlink(&args);
33432 + wkq_err = au_wkq_wait(call_unlink, &args);
33433 + if (unlikely(wkq_err))
33439 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33440 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33441 +++ linux/fs/aufs/vfsub.h 2021-12-03 15:38:59.939980643 +0100
33443 +/* SPDX-License-Identifier: GPL-2.0 */
33445 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33447 + * This program, aufs is free software; you can redistribute it and/or modify
33448 + * it under the terms of the GNU General Public License as published by
33449 + * the Free Software Foundation; either version 2 of the License, or
33450 + * (at your option) any later version.
33452 + * This program is distributed in the hope that it will be useful,
33453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33455 + * GNU General Public License for more details.
33457 + * You should have received a copy of the GNU General Public License
33458 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33462 + * sub-routines for VFS
33465 +#ifndef __AUFS_VFSUB_H__
33466 +#define __AUFS_VFSUB_H__
33470 +#include <linux/fs.h>
33471 +#include <linux/mount.h>
33472 +#include <linux/posix_acl.h>
33473 +#include <linux/xattr.h>
33474 +#include "debug.h"
33476 +/* copied from linux/fs/internal.h */
33477 +/* todo: BAD approach!! */
33478 +extern void __mnt_drop_write(struct vfsmount *);
33479 +extern struct file *alloc_empty_file(int, const struct cred *);
33481 +/* ---------------------------------------------------------------------- */
33483 +/* lock subclass for lower inode */
33484 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33485 +/* reduce? gave up. */
33487 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33488 + AuLsc_I_PARENT, /* lower inode, parent first */
33489 + AuLsc_I_PARENT2, /* copyup dirs */
33490 + AuLsc_I_PARENT3, /* copyup wh */
33496 +/* to debug easier, do not make them inlined functions */
33497 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33498 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33500 +/* ---------------------------------------------------------------------- */
33502 +static inline void vfsub_drop_nlink(struct inode *inode)
33504 + AuDebugOn(!inode->i_nlink);
33505 + drop_nlink(inode);
33508 +static inline void vfsub_dead_dir(struct inode *inode)
33510 + AuDebugOn(!S_ISDIR(inode->i_mode));
33511 + inode->i_flags |= S_DEAD;
33512 + clear_nlink(inode);
33515 +static inline int vfsub_native_ro(struct inode *inode)
33517 + return sb_rdonly(inode->i_sb)
33518 + || IS_RDONLY(inode)
33519 + /* || IS_APPEND(inode) */
33520 + || IS_IMMUTABLE(inode);
33523 +#ifdef CONFIG_AUFS_BR_FUSE
33524 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33526 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33529 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33531 +/* ---------------------------------------------------------------------- */
33533 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33534 +struct file *vfsub_dentry_open(struct path *path, int flags);
33535 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33537 +struct vfsub_aopen_args {
33538 + struct file *file;
33539 + unsigned int open_flag;
33540 + umode_t create_mode;
33541 + struct au_branch *br;
33543 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33544 + struct vfsub_aopen_args *args);
33545 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33547 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33548 + struct path *ppath, int len);
33549 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33552 +struct vfsub_lkup_one_args {
33553 + struct dentry **errp;
33554 + struct qstr *name;
33555 + struct path *ppath;
33558 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33559 + struct path *ppath)
33561 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33564 +void vfsub_call_lkup_one(void *args);
33566 +/* ---------------------------------------------------------------------- */
33568 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33573 + err = mnt_want_write(mnt);
33578 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33581 + mnt_drop_write(mnt);
33585 +#if 0 /* reserved */
33586 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33589 + mnt_drop_write_file(file);
33594 +/* ---------------------------------------------------------------------- */
33597 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33598 + struct dentry *d2, struct au_hinode *hdir2);
33599 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33600 + struct dentry *d2, struct au_hinode *hdir2);
33602 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33604 +int vfsub_symlink(struct inode *dir, struct path *path,
33605 + const char *symname);
33606 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33607 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33608 + struct path *path, struct inode **delegated_inode);
33609 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33610 + struct inode *hdir, struct path *path,
33611 + struct inode **delegated_inode, unsigned int flags);
33612 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33613 +int vfsub_rmdir(struct inode *dir, struct path *path);
33615 +/* ---------------------------------------------------------------------- */
33617 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33619 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33621 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33623 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33625 +int vfsub_flush(struct file *file, fl_owner_t id);
33626 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33628 +static inline loff_t vfsub_f_size_read(struct file *file)
33630 + return i_size_read(file_inode(file));
33633 +static inline unsigned int vfsub_file_flags(struct file *file)
33635 + unsigned int flags;
33637 + spin_lock(&file->f_lock);
33638 + flags = file->f_flags;
33639 + spin_unlock(&file->f_lock);
33644 +static inline int vfsub_file_execed(struct file *file)
33646 + /* todo: direct access f_flags */
33647 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33650 +#if 0 /* reserved */
33651 +static inline void vfsub_file_accessed(struct file *h_file)
33653 + file_accessed(h_file);
33654 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33658 +#if 0 /* reserved */
33659 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33660 + struct dentry *h_dentry)
33662 + struct path h_path = {
33663 + .dentry = h_dentry,
33666 + touch_atime(&h_path);
33667 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33671 +static inline int vfsub_update_time(struct inode *h_inode,
33672 + struct timespec64 *ts, int flags)
33674 + return inode_update_time(h_inode, ts, flags);
33675 + /* no vfsub_update_h_iattr() since we don't have struct path */
33678 +#ifdef CONFIG_FS_POSIX_ACL
33679 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33683 + err = posix_acl_chmod(h_inode, h_mode);
33684 + if (err == -EOPNOTSUPP)
33689 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33692 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33693 + struct pipe_inode_info *pipe, size_t len,
33694 + unsigned int flags);
33695 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33696 + loff_t *ppos, size_t len, unsigned int flags);
33698 +static inline long vfsub_truncate(struct path *path, loff_t length)
33703 + err = vfs_truncate(path, length);
33708 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33709 + struct file *h_file);
33710 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33713 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33716 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33722 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33728 +/* copy_file_range(2) is a systemcall */
33729 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33730 + struct file *dst, loff_t dst_pos,
33731 + size_t len, unsigned int flags)
33736 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33742 +/* ---------------------------------------------------------------------- */
33744 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33749 + err = vfs_llseek(file, offset, origin);
33754 +/* ---------------------------------------------------------------------- */
33756 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33757 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33758 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33759 + struct inode **delegated_inode);
33760 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33761 + struct inode **delegated_inode);
33762 +int vfsub_unlink(struct inode *dir, struct path *path,
33763 + struct inode **delegated_inode, int force);
33765 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33767 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33770 +/* ---------------------------------------------------------------------- */
33772 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33773 + const void *value, size_t size, int flags)
33778 + err = vfs_setxattr(dentry, name, value, size, flags);
33784 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33789 + err = vfs_removexattr(dentry, name);
33795 +#endif /* __KERNEL__ */
33796 +#endif /* __AUFS_VFSUB_H__ */
33797 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33798 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33799 +++ linux/fs/aufs/wbr_policy.c 2021-12-03 15:38:59.939980643 +0100
33801 +// SPDX-License-Identifier: GPL-2.0
33803 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33805 + * This program, aufs is free software; you can redistribute it and/or modify
33806 + * it under the terms of the GNU General Public License as published by
33807 + * the Free Software Foundation; either version 2 of the License, or
33808 + * (at your option) any later version.
33810 + * This program is distributed in the hope that it will be useful,
33811 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33812 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33813 + * GNU General Public License for more details.
33815 + * You should have received a copy of the GNU General Public License
33816 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33820 + * policies for selecting one among multiple writable branches
33823 +#include <linux/statfs.h>
33826 +/* subset of cpup_attr() */
33827 +static noinline_for_stack
33828 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33832 + struct inode *h_isrc;
33834 + h_isrc = d_inode(h_src);
33835 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33836 + ia.ia_mode = h_isrc->i_mode;
33837 + ia.ia_uid = h_isrc->i_uid;
33838 + ia.ia_gid = h_isrc->i_gid;
33839 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33840 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33841 + /* no delegation since it is just created */
33842 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33844 + /* is this nfs only? */
33845 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33846 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33847 + ia.ia_mode = h_isrc->i_mode;
33848 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33854 +#define AuCpdown_PARENT_OPQ 1
33855 +#define AuCpdown_WHED (1 << 1)
33856 +#define AuCpdown_MADE_DIR (1 << 2)
33857 +#define AuCpdown_DIROPQ (1 << 3)
33858 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33859 +#define au_fset_cpdown(flags, name) \
33860 + do { (flags) |= AuCpdown_##name; } while (0)
33861 +#define au_fclr_cpdown(flags, name) \
33862 + do { (flags) &= ~AuCpdown_##name; } while (0)
33864 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33865 + unsigned int *flags)
33868 + struct dentry *opq_dentry;
33870 + opq_dentry = au_diropq_create(dentry, bdst);
33871 + err = PTR_ERR(opq_dentry);
33872 + if (IS_ERR(opq_dentry))
33874 + dput(opq_dentry);
33875 + au_fset_cpdown(*flags, DIROPQ);
33881 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33882 + struct inode *dir, aufs_bindex_t bdst)
33885 + struct path h_path;
33886 + struct au_branch *br;
33888 + br = au_sbr(dentry->d_sb, bdst);
33889 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33890 + err = PTR_ERR(h_path.dentry);
33891 + if (IS_ERR(h_path.dentry))
33895 + if (d_is_positive(h_path.dentry)) {
33896 + h_path.mnt = au_br_mnt(br);
33897 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33900 + dput(h_path.dentry);
33906 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33907 + struct au_pin *pin,
33908 + struct dentry *h_parent, void *arg)
33911 + aufs_bindex_t bopq, btop;
33912 + struct path h_path;
33913 + struct dentry *parent;
33914 + struct inode *h_dir, *h_inode, *inode, *dir;
33915 + unsigned int *flags = arg;
33917 + btop = au_dbtop(dentry);
33918 + /* dentry is di-locked */
33919 + parent = dget_parent(dentry);
33920 + dir = d_inode(parent);
33921 + h_dir = d_inode(h_parent);
33922 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33923 + IMustLock(h_dir);
33925 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33926 + if (unlikely(err < 0))
33928 + h_path.dentry = au_h_dptr(dentry, bdst);
33929 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33930 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
33931 + if (unlikely(err))
33933 + au_fset_cpdown(*flags, MADE_DIR);
33935 + bopq = au_dbdiropq(dentry);
33936 + au_fclr_cpdown(*flags, WHED);
33937 + au_fclr_cpdown(*flags, DIROPQ);
33938 + if (au_dbwh(dentry) == bdst)
33939 + au_fset_cpdown(*flags, WHED);
33940 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33941 + au_fset_cpdown(*flags, PARENT_OPQ);
33942 + h_inode = d_inode(h_path.dentry);
33943 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33944 + if (au_ftest_cpdown(*flags, WHED)) {
33945 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33946 + if (unlikely(err)) {
33947 + inode_unlock(h_inode);
33952 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33953 + inode_unlock(h_inode);
33954 + if (unlikely(err))
33957 + if (au_ftest_cpdown(*flags, WHED)) {
33958 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33959 + if (unlikely(err))
33963 + inode = d_inode(dentry);
33964 + if (au_ibbot(inode) < bdst)
33965 + au_set_ibbot(inode, bdst);
33966 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33967 + au_hi_flags(inode, /*isdir*/1));
33968 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
33969 + goto out; /* success */
33973 + if (au_ftest_cpdown(*flags, DIROPQ)) {
33974 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33975 + rerr = au_diropq_remove(dentry, bdst);
33976 + inode_unlock(h_inode);
33977 + if (unlikely(rerr)) {
33978 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
33979 + dentry, bdst, rerr);
33985 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
33986 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
33987 + if (unlikely(rerr)) {
33988 + AuIOErr("failed removing %pd b%d (%d)\n",
33989 + dentry, bdst, rerr);
33994 + au_set_h_dptr(dentry, bdst, NULL);
33995 + if (au_dbbot(dentry) == bdst)
33996 + au_update_dbbot(dentry);
34002 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34005 + unsigned int flags;
34008 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34013 +/* ---------------------------------------------------------------------- */
34015 +/* policies for create */
34017 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34019 + int err, i, j, ndentry;
34020 + aufs_bindex_t bopq;
34021 + struct au_dcsub_pages dpages;
34022 + struct au_dpage *dpage;
34023 + struct dentry **dentries, *parent, *d;
34025 + err = au_dpages_init(&dpages, GFP_NOFS);
34026 + if (unlikely(err))
34028 + parent = dget_parent(dentry);
34029 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34030 + if (unlikely(err))
34034 + for (i = 0; i < dpages.ndpage; i++) {
34035 + dpage = dpages.dpages + i;
34036 + dentries = dpage->dentries;
34037 + ndentry = dpage->ndentry;
34038 + for (j = 0; j < ndentry; j++) {
34040 + di_read_lock_parent2(d, !AuLock_IR);
34041 + bopq = au_dbdiropq(d);
34042 + di_read_unlock(d, !AuLock_IR);
34043 + if (bopq >= 0 && bopq < err)
34050 + au_dpages_free(&dpages);
34055 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34057 + for (; bindex >= 0; bindex--)
34058 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34063 +/* top down parent */
34064 +static int au_wbr_create_tdp(struct dentry *dentry,
34065 + unsigned int flags __maybe_unused)
34068 + aufs_bindex_t btop, bindex;
34069 + struct super_block *sb;
34070 + struct dentry *parent, *h_parent;
34072 + sb = dentry->d_sb;
34073 + btop = au_dbtop(dentry);
34075 + if (!au_br_rdonly(au_sbr(sb, btop)))
34079 + parent = dget_parent(dentry);
34080 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34081 + h_parent = au_h_dptr(parent, bindex);
34082 + if (!h_parent || d_is_negative(h_parent))
34085 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34092 + /* bottom up here */
34093 + if (unlikely(err < 0)) {
34094 + err = au_wbr_bu(sb, btop - 1);
34096 + err = au_wbr_nonopq(dentry, err);
34100 + AuDbg("b%d\n", err);
34104 +/* ---------------------------------------------------------------------- */
34106 +/* an exception for the policy other than tdp */
34107 +static int au_wbr_create_exp(struct dentry *dentry)
34110 + aufs_bindex_t bwh, bdiropq;
34111 + struct dentry *parent;
34114 + bwh = au_dbwh(dentry);
34115 + parent = dget_parent(dentry);
34116 + bdiropq = au_dbdiropq(parent);
34118 + if (bdiropq >= 0)
34119 + err = min(bdiropq, bwh);
34122 + AuDbg("%d\n", err);
34123 + } else if (bdiropq >= 0) {
34125 + AuDbg("%d\n", err);
34130 + err = au_wbr_nonopq(dentry, err);
34132 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34135 + AuDbg("%d\n", err);
34139 +/* ---------------------------------------------------------------------- */
34142 +static int au_wbr_create_init_rr(struct super_block *sb)
34146 + err = au_wbr_bu(sb, au_sbbot(sb));
34147 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34150 + AuDbg("b%d\n", err);
34154 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34158 + aufs_bindex_t bindex, bbot;
34159 + struct super_block *sb;
34162 + err = au_wbr_create_exp(dentry);
34166 + sb = dentry->d_sb;
34167 + next = &au_sbi(sb)->si_wbr_rr_next;
34168 + bbot = au_sbbot(sb);
34170 + for (bindex = 0; bindex <= bbot; bindex++) {
34171 + if (!au_ftest_wbr(flags, DIR)) {
34172 + err = atomic_dec_return(next) + 1;
34173 + /* modulo for 0 is meaningless */
34174 + if (unlikely(!err))
34175 + err = atomic_dec_return(next) + 1;
34177 + err = atomic_read(next);
34178 + AuDbg("%d\n", err);
34181 + AuDbg("%d\n", err);
34182 + if (!au_br_rdonly(au_sbr(sb, err)))
34188 + err = au_wbr_nonopq(dentry, err);
34191 + AuDbg("%d\n", err);
34195 +/* ---------------------------------------------------------------------- */
34197 +/* most free space */
34198 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34200 + struct super_block *sb;
34201 + struct au_branch *br;
34202 + struct au_wbr_mfs *mfs;
34203 + struct dentry *h_parent;
34204 + aufs_bindex_t bindex, bbot;
34206 + unsigned long long b, bavail;
34207 + struct path h_path;
34208 + /* reduce the stack usage */
34209 + struct kstatfs *st;
34211 + st = kmalloc(sizeof(*st), GFP_NOFS);
34212 + if (unlikely(!st)) {
34213 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34218 + sb = dentry->d_sb;
34219 + mfs = &au_sbi(sb)->si_wbr_mfs;
34220 + MtxMustLock(&mfs->mfs_lock);
34221 + mfs->mfs_bindex = -EROFS;
34222 + mfs->mfsrr_bytes = 0;
34225 + bbot = au_sbbot(sb);
34227 + bindex = au_dbtop(parent);
34228 + bbot = au_dbtaildir(parent);
34231 + for (; bindex <= bbot; bindex++) {
34233 + h_parent = au_h_dptr(parent, bindex);
34234 + if (!h_parent || d_is_negative(h_parent))
34237 + br = au_sbr(sb, bindex);
34238 + if (au_br_rdonly(br))
34241 + /* sb->s_root for NFS is unreliable */
34242 + h_path.mnt = au_br_mnt(br);
34243 + h_path.dentry = h_path.mnt->mnt_root;
34244 + err = vfs_statfs(&h_path, st);
34245 + if (unlikely(err)) {
34246 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34250 + /* when the available size is equal, select the lower one */
34251 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34252 + || sizeof(b) < sizeof(st->f_bsize));
34253 + b = st->f_bavail * st->f_bsize;
34254 + br->br_wbr->wbr_bytes = b;
34255 + if (b >= bavail) {
34257 + mfs->mfs_bindex = bindex;
34258 + mfs->mfs_jiffy = jiffies;
34262 + mfs->mfsrr_bytes = bavail;
34263 + AuDbg("b%d\n", mfs->mfs_bindex);
34264 + au_kfree_rcu(st);
34267 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34270 + struct dentry *parent;
34271 + struct super_block *sb;
34272 + struct au_wbr_mfs *mfs;
34274 + err = au_wbr_create_exp(dentry);
34278 + sb = dentry->d_sb;
34280 + if (au_ftest_wbr(flags, PARENT))
34281 + parent = dget_parent(dentry);
34282 + mfs = &au_sbi(sb)->si_wbr_mfs;
34283 + mutex_lock(&mfs->mfs_lock);
34284 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34285 + || mfs->mfs_bindex < 0
34286 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34287 + au_mfs(dentry, parent);
34288 + mutex_unlock(&mfs->mfs_lock);
34289 + err = mfs->mfs_bindex;
34293 + err = au_wbr_nonopq(dentry, err);
34296 + AuDbg("b%d\n", err);
34300 +static int au_wbr_create_init_mfs(struct super_block *sb)
34302 + struct au_wbr_mfs *mfs;
34304 + mfs = &au_sbi(sb)->si_wbr_mfs;
34305 + mutex_init(&mfs->mfs_lock);
34306 + mfs->mfs_jiffy = 0;
34307 + mfs->mfs_bindex = -EROFS;
34312 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34314 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34318 +/* ---------------------------------------------------------------------- */
34320 +/* top down regardless parent, and then mfs */
34321 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34322 + unsigned int flags __maybe_unused)
34325 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34326 + unsigned long long watermark;
34327 + struct super_block *sb;
34328 + struct au_wbr_mfs *mfs;
34329 + struct au_branch *br;
34330 + struct dentry *parent;
34332 + sb = dentry->d_sb;
34333 + mfs = &au_sbi(sb)->si_wbr_mfs;
34334 + mutex_lock(&mfs->mfs_lock);
34335 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34336 + || mfs->mfs_bindex < 0)
34337 + au_mfs(dentry, /*parent*/NULL);
34338 + watermark = mfs->mfsrr_watermark;
34339 + bmfs = mfs->mfs_bindex;
34340 + mutex_unlock(&mfs->mfs_lock);
34342 + /* another style of au_wbr_create_exp() */
34343 + bwh = au_dbwh(dentry);
34344 + parent = dget_parent(dentry);
34345 + btail = au_dbtaildir(parent);
34346 + if (bwh >= 0 && bwh < btail)
34349 + err = au_wbr_nonopq(dentry, btail);
34350 + if (unlikely(err < 0))
34354 + for (bindex = 0; bindex <= btail; bindex++) {
34355 + br = au_sbr(sb, bindex);
34356 + if (au_br_rdonly(br))
34358 + if (br->br_wbr->wbr_bytes > watermark) {
34369 + AuDbg("b%d\n", err);
34373 +/* ---------------------------------------------------------------------- */
34375 +/* most free space and then round robin */
34376 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34379 + struct au_wbr_mfs *mfs;
34381 + err = au_wbr_create_mfs(dentry, flags);
34383 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34384 + mutex_lock(&mfs->mfs_lock);
34385 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34386 + err = au_wbr_create_rr(dentry, flags);
34387 + mutex_unlock(&mfs->mfs_lock);
34390 + AuDbg("b%d\n", err);
34394 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34398 + au_wbr_create_init_mfs(sb); /* ignore */
34399 + err = au_wbr_create_init_rr(sb);
34404 +/* ---------------------------------------------------------------------- */
34406 +/* top down parent and most free space */
34407 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34410 + unsigned long long b;
34411 + aufs_bindex_t bindex, btop, bbot;
34412 + struct super_block *sb;
34413 + struct dentry *parent, *h_parent;
34414 + struct au_branch *br;
34416 + err = au_wbr_create_tdp(dentry, flags);
34417 + if (unlikely(err < 0))
34419 + parent = dget_parent(dentry);
34420 + btop = au_dbtop(parent);
34421 + bbot = au_dbtaildir(parent);
34422 + if (btop == bbot)
34423 + goto out_parent; /* success */
34425 + e2 = au_wbr_create_mfs(dentry, flags);
34427 + goto out_parent; /* success */
34429 + /* when the available size is equal, select upper one */
34430 + sb = dentry->d_sb;
34431 + br = au_sbr(sb, err);
34432 + b = br->br_wbr->wbr_bytes;
34433 + AuDbg("b%d, %llu\n", err, b);
34435 + for (bindex = btop; bindex <= bbot; bindex++) {
34436 + h_parent = au_h_dptr(parent, bindex);
34437 + if (!h_parent || d_is_negative(h_parent))
34440 + br = au_sbr(sb, bindex);
34441 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34442 + b = br->br_wbr->wbr_bytes;
34444 + AuDbg("b%d, %llu\n", err, b);
34449 + err = au_wbr_nonopq(dentry, err);
34454 + AuDbg("b%d\n", err);
34458 +/* ---------------------------------------------------------------------- */
34461 + * - top down parent
34462 + * - most free space with parent
34463 + * - most free space round-robin regardless parent
34465 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34468 + unsigned long long watermark;
34469 + struct super_block *sb;
34470 + struct au_branch *br;
34471 + struct au_wbr_mfs *mfs;
34473 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34474 + if (unlikely(err < 0))
34477 + sb = dentry->d_sb;
34478 + br = au_sbr(sb, err);
34479 + mfs = &au_sbi(sb)->si_wbr_mfs;
34480 + mutex_lock(&mfs->mfs_lock);
34481 + watermark = mfs->mfsrr_watermark;
34482 + mutex_unlock(&mfs->mfs_lock);
34483 + if (br->br_wbr->wbr_bytes < watermark)
34484 + /* regardless the parent dir */
34485 + err = au_wbr_create_mfsrr(dentry, flags);
34488 + AuDbg("b%d\n", err);
34492 +/* ---------------------------------------------------------------------- */
34494 +/* policies for copyup */
34496 +/* top down parent */
34497 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34499 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34502 +/* bottom up parent */
34503 +static int au_wbr_copyup_bup(struct dentry *dentry)
34506 + aufs_bindex_t bindex, btop;
34507 + struct dentry *parent, *h_parent;
34508 + struct super_block *sb;
34511 + sb = dentry->d_sb;
34512 + parent = dget_parent(dentry);
34513 + btop = au_dbtop(parent);
34514 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34515 + h_parent = au_h_dptr(parent, bindex);
34516 + if (!h_parent || d_is_negative(h_parent))
34519 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34526 + /* bottom up here */
34527 + if (unlikely(err < 0))
34528 + err = au_wbr_bu(sb, btop - 1);
34530 + AuDbg("b%d\n", err);
34535 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34539 + err = au_wbr_bu(dentry->d_sb, btop);
34540 + AuDbg("b%d\n", err);
34542 + err = au_wbr_nonopq(dentry, err);
34544 + AuDbg("b%d\n", err);
34548 +static int au_wbr_copyup_bu(struct dentry *dentry)
34551 + aufs_bindex_t btop;
34553 + btop = au_dbtop(dentry);
34554 + err = au_wbr_do_copyup_bu(dentry, btop);
34558 +/* ---------------------------------------------------------------------- */
34560 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34561 + [AuWbrCopyup_TDP] = {
34562 + .copyup = au_wbr_copyup_tdp
34564 + [AuWbrCopyup_BUP] = {
34565 + .copyup = au_wbr_copyup_bup
34567 + [AuWbrCopyup_BU] = {
34568 + .copyup = au_wbr_copyup_bu
34572 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34573 + [AuWbrCreate_TDP] = {
34574 + .create = au_wbr_create_tdp
34576 + [AuWbrCreate_RR] = {
34577 + .create = au_wbr_create_rr,
34578 + .init = au_wbr_create_init_rr
34580 + [AuWbrCreate_MFS] = {
34581 + .create = au_wbr_create_mfs,
34582 + .init = au_wbr_create_init_mfs,
34583 + .fin = au_wbr_create_fin_mfs
34585 + [AuWbrCreate_MFSV] = {
34586 + .create = au_wbr_create_mfs,
34587 + .init = au_wbr_create_init_mfs,
34588 + .fin = au_wbr_create_fin_mfs
34590 + [AuWbrCreate_MFSRR] = {
34591 + .create = au_wbr_create_mfsrr,
34592 + .init = au_wbr_create_init_mfsrr,
34593 + .fin = au_wbr_create_fin_mfs
34595 + [AuWbrCreate_MFSRRV] = {
34596 + .create = au_wbr_create_mfsrr,
34597 + .init = au_wbr_create_init_mfsrr,
34598 + .fin = au_wbr_create_fin_mfs
34600 + [AuWbrCreate_TDMFS] = {
34601 + .create = au_wbr_create_tdmfs,
34602 + .init = au_wbr_create_init_mfs,
34603 + .fin = au_wbr_create_fin_mfs
34605 + [AuWbrCreate_TDMFSV] = {
34606 + .create = au_wbr_create_tdmfs,
34607 + .init = au_wbr_create_init_mfs,
34608 + .fin = au_wbr_create_fin_mfs
34610 + [AuWbrCreate_PMFS] = {
34611 + .create = au_wbr_create_pmfs,
34612 + .init = au_wbr_create_init_mfs,
34613 + .fin = au_wbr_create_fin_mfs
34615 + [AuWbrCreate_PMFSV] = {
34616 + .create = au_wbr_create_pmfs,
34617 + .init = au_wbr_create_init_mfs,
34618 + .fin = au_wbr_create_fin_mfs
34620 + [AuWbrCreate_PMFSRR] = {
34621 + .create = au_wbr_create_pmfsrr,
34622 + .init = au_wbr_create_init_mfsrr,
34623 + .fin = au_wbr_create_fin_mfs
34625 + [AuWbrCreate_PMFSRRV] = {
34626 + .create = au_wbr_create_pmfsrr,
34627 + .init = au_wbr_create_init_mfsrr,
34628 + .fin = au_wbr_create_fin_mfs
34631 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34632 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34633 +++ linux/fs/aufs/whout.c 2021-12-03 15:38:59.939980643 +0100
34635 +// SPDX-License-Identifier: GPL-2.0
34637 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34639 + * This program, aufs is free software; you can redistribute it and/or modify
34640 + * it under the terms of the GNU General Public License as published by
34641 + * the Free Software Foundation; either version 2 of the License, or
34642 + * (at your option) any later version.
34644 + * This program is distributed in the hope that it will be useful,
34645 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34646 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34647 + * GNU General Public License for more details.
34649 + * You should have received a copy of the GNU General Public License
34650 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34654 + * whiteout for logical deletion and opaque directory
34659 +#define WH_MASK 0444
34662 + * If a directory contains this file, then it is opaque. We start with the
34663 + * .wh. flag so that it is blocked by lookup.
34665 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34666 + sizeof(AUFS_WH_DIROPQ) - 1);
34669 + * generate whiteout name, which is NOT terminated by NULL.
34670 + * @name: original d_name.name
34671 + * @len: original d_name.len
34672 + * @wh: whiteout qstr
34673 + * returns zero when succeeds, otherwise error.
34674 + * succeeded value as wh->name should be freed by kfree().
34676 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34680 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34681 + return -ENAMETOOLONG;
34683 + wh->len = name->len + AUFS_WH_PFX_LEN;
34684 + p = kmalloc(wh->len, GFP_NOFS);
34687 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34688 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34695 +/* ---------------------------------------------------------------------- */
34698 + * test if the @wh_name exists under @h_ppath.
34699 + * @try_sio specifies the necessary of super-io.
34701 +int au_wh_test(struct path *h_ppath, struct qstr *wh_name, int try_sio)
34704 + struct dentry *wh_dentry;
34707 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
34709 + wh_dentry = au_sio_lkup_one(wh_name, h_ppath);
34710 + err = PTR_ERR(wh_dentry);
34711 + if (IS_ERR(wh_dentry)) {
34712 + if (err == -ENAMETOOLONG)
34718 + if (d_is_negative(wh_dentry))
34719 + goto out_wh; /* success */
34722 + if (d_is_reg(wh_dentry))
34723 + goto out_wh; /* success */
34726 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34727 + wh_dentry, d_inode(wh_dentry)->i_mode);
34736 + * test if the @h_path->dentry sets opaque or not.
34738 +int au_diropq_test(struct path *h_path)
34741 + struct inode *h_dir;
34743 + h_dir = d_inode(h_path->dentry);
34744 + err = au_wh_test(h_path, &diropq_name,
34745 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34750 + * returns a negative dentry whose name is unique and temporary.
34752 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34753 + struct qstr *prefix)
34755 + struct dentry *dentry;
34757 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34759 + /* strict atomic_t is unnecessary here */
34760 + static unsigned short cnt;
34762 + struct path h_ppath;
34764 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34767 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34768 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34769 + dentry = ERR_PTR(-ENAMETOOLONG);
34770 + if (unlikely(qs.len > NAME_MAX))
34772 + dentry = ERR_PTR(-ENOMEM);
34773 + name = kmalloc(qs.len + 1, GFP_NOFS);
34774 + if (unlikely(!name))
34778 + /* doubly whiteout-ed */
34779 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34780 + p = name + AUFS_WH_PFX_LEN * 2;
34781 + memcpy(p, prefix->name, prefix->len);
34782 + p += prefix->len;
34784 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34786 + h_ppath.dentry = h_parent;
34787 + h_ppath.mnt = au_br_mnt(br);
34789 + for (i = 0; i < 3; i++) {
34790 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34791 + dentry = au_sio_lkup_one(&qs, &h_ppath);
34792 + if (IS_ERR(dentry) || d_is_negative(dentry))
34796 + /* pr_warn("could not get random name\n"); */
34797 + dentry = ERR_PTR(-EEXIST);
34798 + AuDbg("%.*s\n", AuLNPair(&qs));
34802 + if (name != defname)
34803 + au_kfree_try_rcu(name);
34805 + AuTraceErrPtr(dentry);
34810 + * rename the @h_dentry on @br to the whiteouted temporary name.
34812 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34815 + struct path h_path = {
34816 + .mnt = au_br_mnt(br)
34818 + struct inode *h_dir, *delegated;
34819 + struct dentry *h_parent;
34821 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34822 + h_dir = d_inode(h_parent);
34823 + IMustLock(h_dir);
34825 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34826 + err = PTR_ERR(h_path.dentry);
34827 + if (IS_ERR(h_path.dentry))
34830 + /* under the same dir, no need to lock_rename() */
34831 + delegated = NULL;
34832 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34835 + if (unlikely(err == -EWOULDBLOCK)) {
34836 + pr_warn("cannot retry for NFSv4 delegation"
34837 + " for an internal rename\n");
34840 + dput(h_path.dentry);
34847 +/* ---------------------------------------------------------------------- */
34849 + * functions for removing a whiteout
34852 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34855 + struct inode *delegated;
34858 + * forces superio when the dir has a sticky bit.
34859 + * this may be a violation of unix fs semantics.
34861 + force = (h_dir->i_mode & S_ISVTX)
34862 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34863 + delegated = NULL;
34864 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34865 + if (unlikely(err == -EWOULDBLOCK)) {
34866 + pr_warn("cannot retry for NFSv4 delegation"
34867 + " for an internal unlink\n");
34873 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34874 + struct dentry *dentry)
34878 + err = do_unlink_wh(h_dir, h_path);
34879 + if (!err && dentry)
34880 + au_set_dbwh(dentry, -1);
34885 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
34888 + struct path h_path;
34891 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
34892 + if (IS_ERR(h_path.dentry))
34893 + err = PTR_ERR(h_path.dentry);
34895 + if (d_is_reg(h_path.dentry)) {
34896 + h_path.mnt = h_ppath->mnt;
34897 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
34899 + dput(h_path.dentry);
34905 +/* ---------------------------------------------------------------------- */
34907 + * initialize/clean whiteout for a branch
34910 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34914 + struct inode *delegated;
34916 + if (d_is_negative(whpath->dentry))
34920 + err = vfsub_rmdir(h_dir, whpath);
34922 + delegated = NULL;
34923 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34924 + if (unlikely(err == -EWOULDBLOCK)) {
34925 + pr_warn("cannot retry for NFSv4 delegation"
34926 + " for an internal unlink\n");
34930 + if (unlikely(err))
34931 + pr_warn("failed removing %pd (%d), ignored.\n",
34932 + whpath->dentry, err);
34935 +static int test_linkable(struct dentry *h_root)
34937 + struct inode *h_dir = d_inode(h_root);
34939 + if (h_dir->i_op->link)
34942 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34943 + h_root, au_sbtype(h_root->d_sb));
34944 + return -ENOSYS; /* the branch doesn't have its ->link() */
34947 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34948 +static int au_whdir(struct inode *h_dir, struct path *path)
34953 + if (d_is_negative(path->dentry)) {
34956 + if (au_test_nfs(path->dentry->d_sb))
34958 + err = vfsub_mkdir(h_dir, path, mode);
34959 + } else if (d_is_dir(path->dentry))
34962 + pr_err("unknown %pd exists\n", path->dentry);
34967 +struct au_wh_base {
34968 + const struct qstr *name;
34969 + struct dentry *dentry;
34972 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
34973 + struct path *h_path)
34975 + h_path->dentry = base[AuBrWh_BASE].dentry;
34976 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34977 + h_path->dentry = base[AuBrWh_PLINK].dentry;
34978 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34979 + h_path->dentry = base[AuBrWh_ORPH].dentry;
34980 + au_wh_clean(h_dir, h_path, /*isdir*/1);
34984 + * returns tri-state,
34985 + * minus: error, caller should print the message
34987 + * plus: error, caller should NOT print the message
34989 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
34990 + int do_plink, struct au_wh_base base[],
34991 + struct path *h_path)
34994 + struct inode *h_dir;
34996 + h_dir = d_inode(h_root);
34997 + h_path->dentry = base[AuBrWh_BASE].dentry;
34998 + au_wh_clean(h_dir, h_path, /*isdir*/0);
34999 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35001 + err = test_linkable(h_root);
35002 + if (unlikely(err)) {
35007 + err = au_whdir(h_dir, h_path);
35008 + if (unlikely(err))
35010 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35012 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35013 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35014 + err = au_whdir(h_dir, h_path);
35015 + if (unlikely(err))
35017 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35024 + * for the moment, aufs supports the branch filesystem which does not support
35025 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35026 + * copyup failed. finally, such filesystem will not be used as the writable
35029 + * returns tri-state, see above.
35031 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35032 + int do_plink, struct au_wh_base base[],
35033 + struct path *h_path)
35036 + struct inode *h_dir;
35038 + WbrWhMustWriteLock(wbr);
35040 + err = test_linkable(h_root);
35041 + if (unlikely(err)) {
35047 + * todo: should this create be done in /sbin/mount.aufs helper?
35050 + h_dir = d_inode(h_root);
35051 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35052 + h_path->dentry = base[AuBrWh_BASE].dentry;
35053 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35054 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35057 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35058 + if (unlikely(err))
35061 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35063 + err = au_whdir(h_dir, h_path);
35064 + if (unlikely(err))
35066 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35068 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35069 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35071 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35072 + err = au_whdir(h_dir, h_path);
35073 + if (unlikely(err))
35075 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35082 + * initialize the whiteout base file/dir for @br.
35084 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35087 + const unsigned char do_plink
35088 + = !!au_opt_test(au_mntflags(sb), PLINK);
35089 + struct inode *h_dir;
35090 + struct path path = br->br_path;
35091 + struct dentry *h_root = path.dentry;
35092 + struct au_wbr *wbr = br->br_wbr;
35093 + static const struct qstr base_name[] = {
35094 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35095 + sizeof(AUFS_BASE_NAME) - 1),
35096 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35097 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35098 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35099 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35101 + struct au_wh_base base[] = {
35102 + [AuBrWh_BASE] = {
35103 + .name = base_name + AuBrWh_BASE,
35106 + [AuBrWh_PLINK] = {
35107 + .name = base_name + AuBrWh_PLINK,
35110 + [AuBrWh_ORPH] = {
35111 + .name = base_name + AuBrWh_ORPH,
35117 + WbrWhMustWriteLock(wbr);
35119 + for (i = 0; i < AuBrWh_Last; i++) {
35120 + /* doubly whiteouted */
35121 + struct dentry *d;
35123 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35124 + err = PTR_ERR(d);
35128 + base[i].dentry = d;
35130 + && wbr->wbr_wh[i]
35131 + && wbr->wbr_wh[i] != base[i].dentry);
35135 + for (i = 0; i < AuBrWh_Last; i++) {
35136 + dput(wbr->wbr_wh[i]);
35137 + wbr->wbr_wh[i] = NULL;
35141 + if (!au_br_writable(br->br_perm)) {
35142 + h_dir = d_inode(h_root);
35143 + au_wh_init_ro(h_dir, base, &path);
35144 + } else if (!au_br_wh_linkable(br->br_perm)) {
35145 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35151 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35157 + goto out; /* success */
35160 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35161 + err, h_root, au_sbtype(h_root->d_sb));
35163 + for (i = 0; i < AuBrWh_Last; i++)
35164 + dput(base[i].dentry);
35168 +/* ---------------------------------------------------------------------- */
35170 + * whiteouts are all hard-linked usually.
35171 + * when its link count reaches a ceiling, we create a new whiteout base
35172 + * asynchronously.
35175 +struct reinit_br_wh {
35176 + struct super_block *sb;
35177 + struct au_branch *br;
35180 +static void reinit_br_wh(void *arg)
35183 + aufs_bindex_t bindex;
35184 + struct path h_path;
35185 + struct reinit_br_wh *a = arg;
35186 + struct au_wbr *wbr;
35187 + struct inode *dir, *delegated;
35188 + struct dentry *h_root;
35189 + struct au_hinode *hdir;
35192 + wbr = a->br->br_wbr;
35193 + /* big aufs lock */
35194 + si_noflush_write_lock(a->sb);
35195 + if (!au_br_writable(a->br->br_perm))
35197 + bindex = au_br_index(a->sb, a->br->br_id);
35198 + if (unlikely(bindex < 0))
35201 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35202 + dir = d_inode(a->sb->s_root);
35203 + hdir = au_hi(dir, bindex);
35204 + h_root = au_h_dptr(a->sb->s_root, bindex);
35205 + AuDebugOn(h_root != au_br_dentry(a->br));
35207 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35208 + wbr_wh_write_lock(wbr);
35209 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35212 + h_path.dentry = wbr->wbr_whbase;
35213 + h_path.mnt = au_br_mnt(a->br);
35214 + delegated = NULL;
35215 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35217 + if (unlikely(err == -EWOULDBLOCK)) {
35218 + pr_warn("cannot retry for NFSv4 delegation"
35219 + " for an internal unlink\n");
35223 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35226 + dput(wbr->wbr_whbase);
35227 + wbr->wbr_whbase = NULL;
35229 + err = au_wh_init(a->br, a->sb);
35230 + wbr_wh_write_unlock(wbr);
35231 + au_hn_inode_unlock(hdir);
35232 + di_read_unlock(a->sb->s_root, AuLock_IR);
35234 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35238 + atomic_dec(&wbr->wbr_wh_running);
35239 + au_lcnt_dec(&a->br->br_count);
35240 + si_write_unlock(a->sb);
35241 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35243 + if (unlikely(err))
35244 + AuIOErr("err %d\n", err);
35247 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35249 + int do_dec, wkq_err;
35250 + struct reinit_br_wh *arg;
35253 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35256 + /* ignore ENOMEM */
35257 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35260 + * dec(wh_running), kfree(arg) and dec(br_count)
35261 + * in reinit function
35265 + au_lcnt_inc(&br->br_count);
35266 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35267 + if (unlikely(wkq_err)) {
35268 + atomic_dec(&br->br_wbr->wbr_wh_running);
35269 + au_lcnt_dec(&br->br_count);
35270 + au_kfree_rcu(arg);
35277 + atomic_dec(&br->br_wbr->wbr_wh_running);
35280 +/* ---------------------------------------------------------------------- */
35283 + * create the whiteout @wh.
35285 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35286 + struct dentry *wh)
35289 + struct path h_path = {
35292 + struct au_branch *br;
35293 + struct au_wbr *wbr;
35294 + struct dentry *h_parent;
35295 + struct inode *h_dir, *delegated;
35297 + h_parent = wh->d_parent; /* dir inode is locked */
35298 + h_dir = d_inode(h_parent);
35299 + IMustLock(h_dir);
35301 + br = au_sbr(sb, bindex);
35302 + h_path.mnt = au_br_mnt(br);
35303 + wbr = br->br_wbr;
35304 + wbr_wh_read_lock(wbr);
35305 + if (wbr->wbr_whbase) {
35306 + delegated = NULL;
35307 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35308 + if (unlikely(err == -EWOULDBLOCK)) {
35309 + pr_warn("cannot retry for NFSv4 delegation"
35310 + " for an internal link\n");
35313 + if (!err || err != -EMLINK)
35316 + /* link count full. re-initialize br_whbase. */
35317 + kick_reinit_br_wh(sb, br);
35320 + /* return this error in this context */
35321 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35323 + au_fhsm_wrote(sb, bindex, /*force*/0);
35326 + wbr_wh_read_unlock(wbr);
35330 +/* ---------------------------------------------------------------------- */
35333 + * create or remove the diropq.
35335 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35336 + unsigned int flags)
35338 + struct dentry *opq_dentry;
35339 + struct super_block *sb;
35340 + struct au_branch *br;
35341 + struct path h_path;
35344 + sb = dentry->d_sb;
35345 + br = au_sbr(sb, bindex);
35346 + h_path.dentry = au_h_dptr(dentry, bindex);
35347 + h_path.mnt = au_br_mnt(br);
35348 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35349 + if (IS_ERR(opq_dentry))
35352 + if (au_ftest_diropq(flags, CREATE)) {
35353 + err = link_or_create_wh(sb, bindex, opq_dentry);
35355 + au_set_dbdiropq(dentry, bindex);
35356 + goto out; /* success */
35359 + h_path.dentry = opq_dentry;
35360 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35362 + au_set_dbdiropq(dentry, -1);
35364 + dput(opq_dentry);
35365 + opq_dentry = ERR_PTR(err);
35368 + return opq_dentry;
35371 +struct do_diropq_args {
35372 + struct dentry **errp;
35373 + struct dentry *dentry;
35374 + aufs_bindex_t bindex;
35375 + unsigned int flags;
35378 +static void call_do_diropq(void *args)
35380 + struct do_diropq_args *a = args;
35381 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35384 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35385 + unsigned int flags)
35387 + struct dentry *diropq, *h_dentry;
35389 + h_dentry = au_h_dptr(dentry, bindex);
35390 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35391 + diropq = do_diropq(dentry, bindex, flags);
35394 + struct do_diropq_args args = {
35396 + .dentry = dentry,
35397 + .bindex = bindex,
35401 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35402 + if (unlikely(wkq_err))
35403 + diropq = ERR_PTR(wkq_err);
35409 +/* ---------------------------------------------------------------------- */
35412 + * lookup whiteout dentry.
35413 + * @h_parent: lower parent dentry which must exist and be locked
35414 + * @base_name: name of dentry which will be whiteouted
35415 + * returns dentry for whiteout.
35417 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35418 + struct au_branch *br)
35421 + struct qstr wh_name;
35422 + struct dentry *wh_dentry;
35423 + struct path h_path;
35425 + err = au_wh_name_alloc(&wh_name, base_name);
35426 + wh_dentry = ERR_PTR(err);
35428 + h_path.dentry = h_parent;
35429 + h_path.mnt = au_br_mnt(br);
35430 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35431 + au_kfree_try_rcu(wh_name.name);
35433 + return wh_dentry;
35437 + * link/create a whiteout for @dentry on @bindex.
35439 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35440 + struct dentry *h_parent)
35442 + struct dentry *wh_dentry;
35443 + struct super_block *sb;
35446 + sb = dentry->d_sb;
35447 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35448 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35449 + err = link_or_create_wh(sb, bindex, wh_dentry);
35451 + au_set_dbwh(dentry, bindex);
35452 + au_fhsm_wrote(sb, bindex, /*force*/0);
35455 + wh_dentry = ERR_PTR(err);
35459 + return wh_dentry;
35462 +/* ---------------------------------------------------------------------- */
35464 +/* Delete all whiteouts in this directory on branch bindex. */
35465 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35466 + aufs_bindex_t bindex)
35469 + unsigned long ul, n;
35470 + struct qstr wh_name;
35472 + struct hlist_head *head;
35473 + struct au_vdir_wh *pos;
35474 + struct au_vdir_destr *str;
35477 + p = (void *)__get_free_page(GFP_NOFS);
35478 + wh_name.name = p;
35479 + if (unlikely(!wh_name.name))
35483 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35484 + p += AUFS_WH_PFX_LEN;
35485 + n = whlist->nh_num;
35486 + head = whlist->nh_head;
35487 + for (ul = 0; !err && ul < n; ul++, head++) {
35488 + hlist_for_each_entry(pos, head, wh_hash) {
35489 + if (pos->wh_bindex != bindex)
35492 + str = &pos->wh_str;
35493 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35494 + memcpy(p, str->name, str->len);
35495 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35496 + err = unlink_wh_name(h_path, &wh_name);
35501 + AuIOErr("whiteout name too long %.*s\n",
35502 + str->len, str->name);
35507 + free_page((unsigned long)wh_name.name);
35513 +struct del_wh_children_args {
35515 + struct path *h_path;
35516 + struct au_nhash *whlist;
35517 + aufs_bindex_t bindex;
35520 +static void call_del_wh_children(void *args)
35522 + struct del_wh_children_args *a = args;
35523 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35526 +/* ---------------------------------------------------------------------- */
35528 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35530 + struct au_whtmp_rmdir *whtmp;
35532 + unsigned int rdhash;
35534 + SiMustAnyLock(sb);
35536 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35537 + if (unlikely(!whtmp)) {
35538 + whtmp = ERR_PTR(-ENOMEM);
35542 + /* no estimation for dir size */
35543 + rdhash = au_sbi(sb)->si_rdhash;
35545 + rdhash = AUFS_RDHASH_DEF;
35546 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35547 + if (unlikely(err)) {
35548 + au_kfree_rcu(whtmp);
35549 + whtmp = ERR_PTR(err);
35556 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35559 + au_lcnt_dec(&whtmp->br->br_count);
35560 + dput(whtmp->wh_dentry);
35561 + iput(whtmp->dir);
35562 + au_nhash_wh_free(&whtmp->whlist);
35563 + au_kfree_rcu(whtmp);
35567 + * rmdir the whiteouted temporary named dir @h_dentry.
35568 + * @whlist: whiteouted children.
35570 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35571 + struct dentry *wh_dentry, struct au_nhash *whlist)
35574 + unsigned int h_nlink;
35575 + struct path wh_path;
35576 + struct inode *wh_inode, *h_dir;
35577 + struct au_branch *br;
35579 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35580 + IMustLock(h_dir);
35582 + br = au_sbr(dir->i_sb, bindex);
35583 + wh_path.dentry = wh_dentry;
35584 + wh_path.mnt = au_br_mnt(br);
35585 + wh_inode = d_inode(wh_dentry);
35586 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35589 + * someone else might change some whiteouts while we were sleeping.
35590 + * it means this whlist may have an obsoleted entry.
35592 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35593 + err = del_wh_children(&wh_path, whlist, bindex);
35596 + struct del_wh_children_args args = {
35598 + .h_path = &wh_path,
35599 + .whlist = whlist,
35603 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35604 + if (unlikely(wkq_err))
35607 + inode_unlock(wh_inode);
35610 + h_nlink = h_dir->i_nlink;
35611 + err = vfsub_rmdir(h_dir, &wh_path);
35612 + /* some fs doesn't change the parent nlink in some cases */
35613 + h_nlink -= h_dir->i_nlink;
35617 + if (au_ibtop(dir) == bindex) {
35618 + /* todo: dir->i_mutex is necessary */
35619 + au_cpup_attr_timesizes(dir);
35621 + vfsub_drop_nlink(dir);
35623 + return 0; /* success */
35626 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35630 +static void call_rmdir_whtmp(void *args)
35633 + aufs_bindex_t bindex;
35634 + struct au_whtmp_rmdir *a = args;
35635 + struct super_block *sb;
35636 + struct dentry *h_parent;
35637 + struct inode *h_dir;
35638 + struct au_hinode *hdir;
35640 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35641 + /* inode_lock(a->dir); */
35643 + sb = a->dir->i_sb;
35644 + si_read_lock(sb, !AuLock_FLUSH);
35645 + if (!au_br_writable(a->br->br_perm))
35647 + bindex = au_br_index(sb, a->br->br_id);
35648 + if (unlikely(bindex < 0))
35652 + ii_write_lock_parent(a->dir);
35653 + h_parent = dget_parent(a->wh_dentry);
35654 + h_dir = d_inode(h_parent);
35655 + hdir = au_hi(a->dir, bindex);
35656 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35657 + if (unlikely(err))
35659 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35660 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35663 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35664 + au_hn_inode_unlock(hdir);
35665 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35669 + ii_write_unlock(a->dir);
35671 + /* inode_unlock(a->dir); */
35672 + au_whtmp_rmdir_free(a);
35673 + si_read_unlock(sb);
35674 + au_nwt_done(&au_sbi(sb)->si_nowait);
35675 + if (unlikely(err))
35676 + AuIOErr("err %d\n", err);
35679 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35680 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35683 + struct super_block *sb;
35687 + /* all post-process will be done in do_rmdir_whtmp(). */
35689 + args->dir = au_igrab(dir);
35690 + args->br = au_sbr(sb, bindex);
35691 + au_lcnt_inc(&args->br->br_count);
35692 + args->wh_dentry = dget(wh_dentry);
35693 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35694 + if (unlikely(wkq_err)) {
35695 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35696 + au_whtmp_rmdir_free(args);
35699 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35700 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35701 +++ linux/fs/aufs/whout.h 2021-12-03 15:38:59.943313977 +0100
35703 +/* SPDX-License-Identifier: GPL-2.0 */
35705 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35707 + * This program, aufs is free software; you can redistribute it and/or modify
35708 + * it under the terms of the GNU General Public License as published by
35709 + * the Free Software Foundation; either version 2 of the License, or
35710 + * (at your option) any later version.
35712 + * This program is distributed in the hope that it will be useful,
35713 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35714 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35715 + * GNU General Public License for more details.
35717 + * You should have received a copy of the GNU General Public License
35718 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35722 + * whiteout for logical deletion and opaque directory
35725 +#ifndef __AUFS_WHOUT_H__
35726 +#define __AUFS_WHOUT_H__
35733 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35734 +int au_wh_test(struct path *h_ppath, struct qstr *wh_name, int try_sio);
35735 +int au_diropq_test(struct path *h_path);
35737 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35738 + struct qstr *prefix);
35739 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35740 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35741 + struct dentry *dentry);
35742 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35744 +/* diropq flags */
35745 +#define AuDiropq_CREATE 1
35746 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35747 +#define au_fset_diropq(flags, name) \
35748 + do { (flags) |= AuDiropq_##name; } while (0)
35749 +#define au_fclr_diropq(flags, name) \
35750 + do { (flags) &= ~AuDiropq_##name; } while (0)
35752 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35753 + unsigned int flags);
35754 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35755 + struct au_branch *br);
35756 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35757 + struct dentry *h_parent);
35759 +/* real rmdir for the whiteout-ed dir */
35760 +struct au_whtmp_rmdir {
35761 + struct inode *dir;
35762 + struct au_branch *br;
35763 + struct dentry *wh_dentry;
35764 + struct au_nhash whlist;
35767 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35768 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35769 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35770 + struct dentry *wh_dentry, struct au_nhash *whlist);
35771 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35772 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35774 +/* ---------------------------------------------------------------------- */
35776 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35777 + aufs_bindex_t bindex)
35779 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35782 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35784 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35787 +#endif /* __KERNEL__ */
35788 +#endif /* __AUFS_WHOUT_H__ */
35789 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35790 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35791 +++ linux/fs/aufs/wkq.c 2021-12-03 15:38:59.943313977 +0100
35793 +// SPDX-License-Identifier: GPL-2.0
35795 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35797 + * This program, aufs is free software; you can redistribute it and/or modify
35798 + * it under the terms of the GNU General Public License as published by
35799 + * the Free Software Foundation; either version 2 of the License, or
35800 + * (at your option) any later version.
35802 + * This program is distributed in the hope that it will be useful,
35803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35805 + * GNU General Public License for more details.
35807 + * You should have received a copy of the GNU General Public License
35808 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35812 + * workqueue for asynchronous/super-io operations
35813 + * todo: try new credential scheme
35816 +#include <linux/module.h>
35819 +/* internal workqueue named AUFS_WKQ_NAME */
35821 +static struct workqueue_struct *au_wkq;
35823 +struct au_wkinfo {
35824 + struct work_struct wk;
35825 + struct kobject *kobj;
35827 + unsigned int flags; /* see wkq.h */
35829 + au_wkq_func_t func;
35832 +#ifdef CONFIG_LOCKDEP
35834 + struct held_lock **hlock;
35837 + struct completion *comp;
35840 +/* ---------------------------------------------------------------------- */
35842 + * Aufs passes some operations to the workqueue such as the internal copyup.
35843 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35844 + * job run by workqueue depends upon the locks acquired in the other task.
35845 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35846 + * information too. And the job in the workqueue restores the info in order to
35847 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35848 + * correctly and expectedly.
35851 +#ifndef CONFIG_LOCKDEP
35852 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35853 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35854 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35855 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35856 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35858 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35860 + wkinfo->hlock = NULL;
35861 + wkinfo->dont_check = 0;
35868 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35870 + static DEFINE_SPINLOCK(spin);
35873 + struct lock_class_key *key;
35875 + { .name = "&sbinfo->si_rwsem" },
35876 + { .name = "&finfo->fi_rwsem" },
35877 + { .name = "&dinfo->di_rwsem" },
35878 + { .name = "&iinfo->ii_rwsem" }
35883 + /* lockless read from 'set.' see below */
35884 + if (set == ARRAY_SIZE(a)) {
35885 + for (i = 0; i < ARRAY_SIZE(a); i++)
35886 + if (a[i].key == key)
35891 + spin_lock(&spin);
35893 + for (i = 0; i < ARRAY_SIZE(a); i++)
35894 + if (a[i].key == key) {
35895 + spin_unlock(&spin);
35898 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35900 + if (unlikely(a[i].key == key)) { /* rare but possible */
35901 + spin_unlock(&spin);
35906 + if (strstr(a[i].name, name)) {
35908 + * the order of these three lines is important for the
35909 + * lockless read above.
35912 + spin_unlock(&spin);
35914 + /* AuDbg("%d, %s\n", set, name); */
35918 + spin_unlock(&spin);
35927 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35930 + struct task_struct *curr;
35931 + struct held_lock **hl, *held_locks, *p;
35935 + wkinfo->dont_check = lockdep_recursing(curr);
35936 + if (wkinfo->dont_check)
35938 + n = curr->lockdep_depth;
35943 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35944 + if (unlikely(!wkinfo->hlock))
35948 +#if 0 /* left for debugging */
35949 + if (0 && au_debug_test())
35950 + lockdep_print_held_locks(curr);
35952 + held_locks = curr->held_locks;
35953 + hl = wkinfo->hlock;
35955 + p = held_locks++;
35956 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35965 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35967 + au_kfree_try_rcu(wkinfo->hlock);
35970 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
35972 + struct held_lock *p, **hl = wkinfo->hlock;
35975 + if (wkinfo->dont_check)
35979 + while ((p = *hl++)) { /* assignment */
35980 + subclass = lockdep_hlock_class(p)->subclass;
35981 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
35983 + rwsem_acquire_read(p->instance, subclass, 0,
35984 + /*p->acquire_ip*/_RET_IP_);
35986 + rwsem_acquire(p->instance, subclass, 0,
35987 + /*p->acquire_ip*/_RET_IP_);
35991 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
35993 + struct held_lock *p, **hl = wkinfo->hlock;
35995 + if (wkinfo->dont_check)
35999 + while ((p = *hl++)) /* assignment */
36000 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36004 +static void wkq_func(struct work_struct *wk)
36006 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36008 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36009 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36011 + au_wkq_lockdep_pre(wkinfo);
36012 + wkinfo->func(wkinfo->args);
36013 + au_wkq_lockdep_post(wkinfo);
36014 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36015 + complete(wkinfo->comp);
36017 + kobject_put(wkinfo->kobj);
36018 + module_put(THIS_MODULE); /* todo: ?? */
36019 + au_kfree_rcu(wkinfo);
36024 + * Since struct completion is large, try allocating it dynamically.
36026 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36028 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36030 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36032 + init_completion(*comp);
36033 + wkinfo->comp = *comp;
36039 +static void au_wkq_comp_free(struct completion *comp)
36041 + au_kfree_rcu(comp);
36044 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36046 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36047 + if (au_wkq_test()) {
36048 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36049 + " due to a dead dir by UDBA,"
36050 + " or async xino write?\n");
36051 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36054 + au_dbg_verify_kthread();
36056 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36057 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36058 + queue_work(au_wkq, &wkinfo->wk);
36060 + INIT_WORK(&wkinfo->wk, wkq_func);
36061 + schedule_work(&wkinfo->wk);
36066 + * Be careful. It is easy to make deadlock happen.
36067 + * processA: lock, wkq and wait
36068 + * processB: wkq and wait, lock in wkq
36071 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36074 + AuWkqCompDeclare(comp);
36075 + struct au_wkinfo wkinfo = {
36081 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36082 + if (unlikely(err))
36084 + err = au_wkq_lockdep_alloc(&wkinfo);
36085 + if (unlikely(err))
36088 + au_wkq_run(&wkinfo);
36089 + /* no timeout, no interrupt */
36090 + wait_for_completion(wkinfo.comp);
36092 + au_wkq_lockdep_free(&wkinfo);
36095 + au_wkq_comp_free(comp);
36097 + destroy_work_on_stack(&wkinfo.wk);
36102 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36103 + * problem in a concurrent umounting.
36105 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36106 + unsigned int flags)
36109 + struct au_wkinfo *wkinfo;
36111 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36114 + * wkq_func() must free this wkinfo.
36115 + * it highly depends upon the implementation of workqueue.
36118 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36120 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36121 + wkinfo->flags = flags & ~AuWkq_WAIT;
36122 + wkinfo->func = func;
36123 + wkinfo->args = args;
36124 + wkinfo->comp = NULL;
36125 + au_wkq_lockdep_init(wkinfo);
36126 + kobject_get(wkinfo->kobj);
36127 + __module_get(THIS_MODULE); /* todo: ?? */
36129 + au_wkq_run(wkinfo);
36132 + au_nwt_done(&au_sbi(sb)->si_nowait);
36138 +/* ---------------------------------------------------------------------- */
36140 +void au_nwt_init(struct au_nowait_tasks *nwt)
36142 + atomic_set(&nwt->nw_len, 0);
36143 + /* smp_mb(); */ /* atomic_set */
36144 + init_waitqueue_head(&nwt->nw_wq);
36147 +void au_wkq_fin(void)
36149 + destroy_workqueue(au_wkq);
36152 +int __init au_wkq_init(void)
36157 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36158 + if (IS_ERR(au_wkq))
36159 + err = PTR_ERR(au_wkq);
36160 + else if (!au_wkq)
36165 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36166 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36167 +++ linux/fs/aufs/wkq.h 2021-12-03 15:38:59.943313977 +0100
36169 +/* SPDX-License-Identifier: GPL-2.0 */
36171 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36173 + * This program, aufs is free software; you can redistribute it and/or modify
36174 + * it under the terms of the GNU General Public License as published by
36175 + * the Free Software Foundation; either version 2 of the License, or
36176 + * (at your option) any later version.
36178 + * This program is distributed in the hope that it will be useful,
36179 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36180 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36181 + * GNU General Public License for more details.
36183 + * You should have received a copy of the GNU General Public License
36184 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36188 + * workqueue for asynchronous/super-io operations
36189 + * todo: try new credentials management scheme
36192 +#ifndef __AUFS_WKQ_H__
36193 +#define __AUFS_WKQ_H__
36197 +#include <linux/wait.h>
36199 +struct super_block;
36201 +/* ---------------------------------------------------------------------- */
36204 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36206 +struct au_nowait_tasks {
36208 + wait_queue_head_t nw_wq;
36211 +/* ---------------------------------------------------------------------- */
36213 +typedef void (*au_wkq_func_t)(void *args);
36216 +#define AuWkq_WAIT 1
36217 +#define AuWkq_NEST (1 << 1)
36218 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36219 +#define au_fset_wkq(flags, name) \
36220 + do { (flags) |= AuWkq_##name; } while (0)
36221 +#define au_fclr_wkq(flags, name) \
36222 + do { (flags) &= ~AuWkq_##name; } while (0)
36225 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36226 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36227 + unsigned int flags);
36228 +void au_nwt_init(struct au_nowait_tasks *nwt);
36229 +int __init au_wkq_init(void);
36230 +void au_wkq_fin(void);
36232 +/* ---------------------------------------------------------------------- */
36234 +static inline int au_wkq_test(void)
36236 + return current->flags & PF_WQ_WORKER;
36239 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36241 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36244 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36246 + if (atomic_dec_and_test(&nwt->nw_len))
36247 + wake_up_all(&nwt->nw_wq);
36250 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36252 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36256 +#endif /* __KERNEL__ */
36257 +#endif /* __AUFS_WKQ_H__ */
36258 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36259 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36260 +++ linux/fs/aufs/xattr.c 2021-12-03 15:38:59.943313977 +0100
36262 +// SPDX-License-Identifier: GPL-2.0
36264 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36266 + * This program, aufs is free software; you can redistribute it and/or modify
36267 + * it under the terms of the GNU General Public License as published by
36268 + * the Free Software Foundation; either version 2 of the License, or
36269 + * (at your option) any later version.
36271 + * This program is distributed in the hope that it will be useful,
36272 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36273 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36274 + * GNU General Public License for more details.
36276 + * You should have received a copy of the GNU General Public License
36277 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36281 + * handling xattr functions
36284 +#include <linux/fs.h>
36285 +#include <linux/posix_acl_xattr.h>
36286 +#include <linux/xattr.h>
36289 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36291 + if (!ignore_flags)
36299 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36304 +#define cmp(brattr, prefix) do { \
36305 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36306 + XATTR_##prefix##_PREFIX_LEN)) { \
36307 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36313 + cmp(SEC, SECURITY);
36314 + cmp(SYS, SYSTEM);
36315 + cmp(TR, TRUSTED);
36319 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36326 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36328 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36329 + char *name, char **buf, unsigned int ignore_flags,
36330 + unsigned int verbose)
36334 + struct inode *h_idst;
36336 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36338 + if (unlikely(err <= 0)) {
36339 + if (err == -ENODATA
36340 + || (err == -EOPNOTSUPP
36341 + && ((ignore_flags & au_xattr_out_of_list)
36342 + || (au_test_nfs_noacl(d_inode(h_src))
36343 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36345 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36348 + if (err && (verbose || au_debug_test()))
36349 + pr_err("%s, err %d\n", name, err);
36353 + /* unlock it temporary */
36354 + h_idst = d_inode(h_dst);
36355 + inode_unlock(h_idst);
36356 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36357 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36358 + if (unlikely(err)) {
36359 + if (verbose || au_debug_test())
36360 + pr_err("%s, err %d\n", name, err);
36361 + err = au_xattr_ignore(err, name, ignore_flags);
36368 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36369 + unsigned int verbose)
36371 + int err, unlocked, acl_access, acl_default;
36373 + struct inode *h_isrc, *h_idst;
36374 + char *value, *p, *o, *e;
36376 + /* try stopping to update the source inode while we are referencing */
36377 + /* there should not be the parent-child relationship between them */
36378 + h_isrc = d_inode(h_src);
36379 + h_idst = d_inode(h_dst);
36380 + inode_unlock(h_idst);
36381 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36382 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36385 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36386 + ssz = vfs_listxattr(h_src, NULL, 0);
36388 + if (unlikely(err < 0)) {
36390 + if (err == -ENODATA
36391 + || err == -EOPNOTSUPP)
36392 + err = 0; /* ignore */
36401 + p = kmalloc(ssz, GFP_NOFS);
36403 + if (unlikely(!p))
36405 + err = vfs_listxattr(h_src, p, ssz);
36407 + inode_unlock_shared(h_isrc);
36409 + AuDbg("err %d, ssz %zd\n", err, ssz);
36410 + if (unlikely(err < 0))
36418 + while (!err && p < e) {
36419 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36420 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36421 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36422 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36424 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36426 + p += strlen(p) + 1;
36429 + ignore_flags |= au_xattr_out_of_list;
36430 + if (!err && !acl_access) {
36431 + err = au_do_cpup_xattr(h_dst, h_src,
36432 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36433 + ignore_flags, verbose);
36436 + if (!err && !acl_default) {
36437 + err = au_do_cpup_xattr(h_dst, h_src,
36438 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36439 + ignore_flags, verbose);
36443 + au_kfree_try_rcu(value);
36446 + au_kfree_try_rcu(o);
36449 + inode_unlock_shared(h_isrc);
36454 +/* ---------------------------------------------------------------------- */
36456 +static int au_smack_reentering(struct super_block *sb)
36458 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36460 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36461 + * i_op->getxattr(). ouch.
36463 + return si_pid_test(sb);
36474 +struct au_lgxattr {
36482 + const char *name;
36489 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36490 + struct au_lgxattr *arg)
36494 + struct path h_path;
36495 + struct super_block *sb;
36497 + sb = dentry->d_sb;
36498 + reenter = au_smack_reentering(sb);
36500 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36501 + if (unlikely(err))
36504 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36505 + if (unlikely(err))
36507 + if (unlikely(!h_path.dentry))
36508 + /* illegally overlapped or something */
36509 + goto out_di; /* pretending success */
36511 + /* always topmost entry only */
36512 + switch (arg->type) {
36513 + case AU_XATTR_LIST:
36514 + err = vfs_listxattr(h_path.dentry,
36515 + arg->u.list.list, arg->u.list.size);
36517 + case AU_XATTR_GET:
36518 + AuDebugOn(d_is_negative(h_path.dentry));
36519 + err = vfs_getxattr(h_path.dentry,
36520 + arg->u.get.name, arg->u.get.value,
36521 + arg->u.get.size);
36527 + di_read_unlock(dentry, AuLock_IR);
36530 + si_read_unlock(sb);
36536 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36538 + struct au_lgxattr arg = {
36539 + .type = AU_XATTR_LIST,
36546 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36549 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36550 + const char *name, void *value, size_t size)
36552 + struct au_lgxattr arg = {
36553 + .type = AU_XATTR_GET,
36561 + return au_lgxattr(dentry, inode, &arg);
36564 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36565 + const char *name, const void *value, size_t size,
36568 + struct au_sxattr arg = {
36569 + .type = AU_XATTR_SET,
36578 + return au_sxattr(dentry, inode, &arg);
36581 +/* ---------------------------------------------------------------------- */
36583 +static int au_xattr_get(const struct xattr_handler *handler,
36584 + struct dentry *dentry, struct inode *inode,
36585 + const char *name, void *buffer, size_t size)
36587 + return au_getxattr(dentry, inode, name, buffer, size);
36590 +static int au_xattr_set(const struct xattr_handler *handler,
36591 + struct dentry *dentry, struct inode *inode,
36592 + const char *name, const void *value, size_t size,
36595 + return au_setxattr(dentry, inode, name, value, size, flags);
36598 +static const struct xattr_handler au_xattr_handler = {
36601 + .get = au_xattr_get,
36602 + .set = au_xattr_set
36605 +static const struct xattr_handler *au_xattr_handlers[] = {
36606 +#ifdef CONFIG_FS_POSIX_ACL
36607 + &posix_acl_access_xattr_handler,
36608 + &posix_acl_default_xattr_handler,
36610 + &au_xattr_handler, /* must be last */
36614 +void au_xattr_init(struct super_block *sb)
36616 + sb->s_xattr = au_xattr_handlers;
36618 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36619 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36620 +++ linux/fs/aufs/xino.c 2021-12-03 15:38:59.943313977 +0100
36622 +// SPDX-License-Identifier: GPL-2.0
36624 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36626 + * This program, aufs is free software; you can redistribute it and/or modify
36627 + * it under the terms of the GNU General Public License as published by
36628 + * the Free Software Foundation; either version 2 of the License, or
36629 + * (at your option) any later version.
36631 + * This program is distributed in the hope that it will be useful,
36632 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36633 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36634 + * GNU General Public License for more details.
36636 + * You should have received a copy of the GNU General Public License
36637 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36641 + * external inode number translation table and bitmap
36643 + * things to consider
36645 + * + au_xino object
36646 + * + XINO files (xino, xib, xigen)
36647 + * + dynamic debugfs entries (xiN)
36648 + * + static debugfs entries (xib, xigen)
36649 + * + static sysfs entry (xi_path)
36650 + * - several entry points to handle them.
36651 + * + mount(2) without xino option (default)
36652 + * + mount(2) with xino option
36653 + * + mount(2) with noxino option
36655 + * + remount with add/del branches
36656 + * + remount with xino/noxino options
36659 +#include <linux/seq_file.h>
36660 +#include <linux/statfs.h>
36663 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36664 + aufs_bindex_t bbot,
36665 + struct super_block *h_sb)
36667 + /* todo: try binary-search if the branches are many */
36668 + for (; btop <= bbot; btop++)
36669 + if (h_sb == au_sbr_sb(sb, btop))
36675 + * find another branch who is on the same filesystem of the specified
36676 + * branch{@btgt}. search until @bbot.
36678 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36679 + aufs_bindex_t bbot)
36681 + aufs_bindex_t bindex;
36682 + struct super_block *tgt_sb;
36684 + tgt_sb = au_sbr_sb(sb, btgt);
36685 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36687 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36692 +/* ---------------------------------------------------------------------- */
36695 + * stop unnecessary notify events at creating xino files
36698 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36700 + aufs_bindex_t bfound, bindex, bbot;
36701 + struct dentry *parent;
36702 + struct au_branch *br;
36705 + parent = dentry->d_parent; /* safe d_parent access */
36706 + bbot = au_sbbot(sb);
36707 + for (bindex = 0; bindex <= bbot; bindex++) {
36708 + br = au_sbr(sb, bindex);
36709 + if (au_br_dentry(br) == parent) {
36715 + AuDbg("bfound b%d\n", bfound);
36719 +struct au_xino_lock_dir {
36720 + struct au_hinode *hdir;
36721 + struct dentry *parent;
36722 + struct inode *dir;
36725 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36726 + unsigned int lsc)
36728 + struct dentry *parent;
36729 + struct inode *dir;
36731 + parent = dget_parent(dentry);
36732 + dir = d_inode(parent);
36733 + inode_lock_nested(dir, lsc);
36734 +#if 0 /* it should not happen */
36735 + spin_lock(&dentry->d_lock);
36736 + if (unlikely(dentry->d_parent != parent)) {
36737 + spin_unlock(&dentry->d_lock);
36738 + inode_unlock(dir);
36743 + spin_unlock(&dentry->d_lock);
36750 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36751 + struct au_xino_lock_dir *ldir)
36753 + aufs_bindex_t bindex;
36755 + ldir->hdir = NULL;
36756 + bindex = au_xi_root(sb, xipath->dentry);
36757 + if (bindex >= 0) {
36758 + /* rw branch root */
36759 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36760 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36763 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36765 + ldir->dir = d_inode(ldir->parent);
36769 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36772 + au_hn_inode_unlock(ldir->hdir);
36774 + inode_unlock(ldir->dir);
36775 + dput(ldir->parent);
36779 +/* ---------------------------------------------------------------------- */
36782 + * create and set a new xino file
36784 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36787 + struct file *file;
36788 + struct dentry *h_parent, *d;
36789 + struct inode *h_dir, *inode;
36791 + static DEFINE_MUTEX(mtx);
36794 + * at mount-time, and the xino file is the default path,
36795 + * hnotify is disabled so we have no notify events to ignore.
36796 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36799 + mutex_lock(&mtx);
36800 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36801 + /* | __FMODE_NONOTIFY */,
36803 + if (IS_ERR(file)) {
36805 + mutex_unlock(&mtx);
36807 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36811 + /* keep file count */
36813 + d = file->f_path.dentry;
36814 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36816 + mutex_unlock(&mtx);
36817 + /* mnt_want_write() is unnecessary here */
36818 + h_dir = d_inode(h_parent);
36819 + inode = file_inode(file);
36820 + /* no delegation since it is just created */
36821 + if (inode->i_nlink)
36822 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36824 + inode_unlock(h_dir);
36826 + if (unlikely(err)) {
36828 + pr_err("unlink %s(%d)\n", fpath, err);
36833 + if (unlikely(sb == d->d_sb)) {
36835 + pr_err("%s must be outside\n", fpath);
36838 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36840 + pr_err("xino doesn't support %s(%s)\n",
36841 + fpath, au_sbtype(d->d_sb));
36844 + return file; /* success */
36848 + file = ERR_PTR(err);
36853 + * create a new xinofile at the same place/path as @base.
36855 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36856 + struct file *copy_src)
36858 + struct file *file;
36859 + struct dentry *dentry;
36860 + struct inode *dir, *delegated;
36861 + struct qstr *name;
36862 + struct path ppath, path;
36863 + int err, do_unlock;
36864 + struct au_xino_lock_dir ldir;
36867 + au_xino_lock_dir(sb, base, &ldir);
36868 + dentry = base->dentry;
36869 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
36870 + ppath.mnt = base->mnt;
36871 + dir = d_inode(ppath.dentry);
36874 + name = &dentry->d_name;
36875 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
36876 + if (IS_ERR(path.dentry)) {
36877 + file = (void *)path.dentry;
36878 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36882 + /* no need to mnt_want_write() since we call dentry_open() later */
36883 + err = vfs_create(dir, path.dentry, 0666, NULL);
36884 + if (unlikely(err)) {
36885 + file = ERR_PTR(err);
36886 + pr_err("%pd create err %d\n", dentry, err);
36890 + path.mnt = base->mnt;
36891 + file = vfsub_dentry_open(&path,
36892 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36893 + /* | __FMODE_NONOTIFY */);
36894 + if (IS_ERR(file)) {
36895 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36899 + delegated = NULL;
36900 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36901 + au_xino_unlock_dir(&ldir);
36903 + if (unlikely(err == -EWOULDBLOCK)) {
36904 + pr_warn("cannot retry for NFSv4 delegation"
36905 + " for an internal unlink\n");
36908 + if (unlikely(err)) {
36909 + pr_err("%pd unlink err %d\n", dentry, err);
36914 + /* no one can touch copy_src xino */
36915 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36916 + if (unlikely(err)) {
36917 + pr_err("%pd copy err %d\n", dentry, err);
36921 + goto out_dput; /* success */
36925 + file = ERR_PTR(err);
36927 + dput(path.dentry);
36930 + au_xino_unlock_dir(&ldir);
36934 +struct file *au_xino_file1(struct au_xino *xi)
36936 + struct file *file;
36937 + unsigned int u, nfile;
36940 + nfile = xi->xi_nfile;
36941 + for (u = 0; u < nfile; u++) {
36942 + file = xi->xi_file[u];
36950 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
36961 + if (idx < xi->xi_nfile) {
36962 + f = xi->xi_file[idx];
36966 + p = au_kzrealloc(xi->xi_file,
36967 + sizeof(*xi->xi_file) * xi->xi_nfile,
36968 + sizeof(*xi->xi_file) * (idx + 1),
36969 + GFP_NOFS, /*may_shrink*/0);
36971 + MtxMustLock(&xi->xi_mtx);
36973 + xi->xi_nfile = idx + 1;
36981 + xi->xi_file[idx] = file;
36988 + * if @xinew->xi is not set, then create new xigen file.
36990 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
36992 + struct file *file;
36995 + SiMustAnyLock(sb);
36997 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
36998 + if (IS_ERR(file)) {
36999 + err = PTR_ERR(file);
37000 + pr_err("%s[%d], err %d\n",
37001 + xinew->xi ? "xino" : "xigen",
37002 + xinew->idx, err);
37007 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37010 + /* todo: make xigen file an array */
37011 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37014 + if (unlikely(err))
37015 + file = ERR_PTR(err);
37021 +/* ---------------------------------------------------------------------- */
37024 + * truncate xino files
37026 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37027 + int idx, struct kstatfs *st)
37031 + struct file *file, *new_xino;
37032 + struct au_xi_new xinew = {
37037 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37038 + file = au_xino_file(xinew.xi, idx);
37042 + xinew.base = &file->f_path;
37043 + err = vfs_statfs(xinew.base, st);
37044 + if (unlikely(err)) {
37045 + AuErr1("statfs err %d, ignored\n", err);
37050 + blocks = file_inode(file)->i_blocks;
37051 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37052 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37054 + xinew.copy_src = file;
37055 + new_xino = au_xi_new(sb, &xinew);
37056 + if (IS_ERR(new_xino)) {
37057 + err = PTR_ERR(new_xino);
37058 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37062 + err = vfs_statfs(&new_xino->f_path, st);
37064 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37065 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37066 + st->f_bfree, st->f_blocks);
37068 + AuErr1("statfs err %d, ignored\n", err);
37076 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37079 + unsigned long jiffy;
37080 + aufs_bindex_t bbot;
37081 + struct kstatfs *st;
37082 + struct au_branch *br;
37083 + struct au_xino *xi;
37086 + st = kmalloc(sizeof(*st), GFP_NOFS);
37087 + if (unlikely(!st))
37091 + bbot = au_sbbot(sb);
37092 + if (unlikely(bindex < 0 || bbot < bindex))
37097 + br = au_sbr(sb, bindex);
37098 + xi = br->br_xino;
37099 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37100 + err = au_xino_do_trunc(sb, bindex, i, st);
37102 + au_sbi(sb)->si_xino_jiffy = jiffy;
37105 + au_kfree_rcu(st);
37110 +struct xino_do_trunc_args {
37111 + struct super_block *sb;
37112 + struct au_branch *br;
37116 +static void xino_do_trunc(void *_args)
37118 + struct xino_do_trunc_args *args = _args;
37119 + struct super_block *sb;
37120 + struct au_branch *br;
37121 + struct inode *dir;
37123 + aufs_bindex_t bindex;
37127 + dir = d_inode(sb->s_root);
37131 + si_noflush_write_lock(sb);
37132 + ii_read_lock_parent(dir);
37133 + bindex = au_br_index(sb, br->br_id);
37134 + err = au_xino_trunc(sb, bindex, idx);
37135 + ii_read_unlock(dir);
37136 + if (unlikely(err))
37137 + pr_warn("err b%d, (%d)\n", bindex, err);
37138 + atomic_dec(&br->br_xino->xi_truncating);
37139 + au_lcnt_dec(&br->br_count);
37140 + si_write_unlock(sb);
37141 + au_nwt_done(&au_sbi(sb)->si_nowait);
37142 + au_kfree_rcu(args);
37146 + * returns the index in the xi_file array whose corresponding file is necessary
37147 + * to truncate, or -1 which means no need to truncate.
37149 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37153 + struct kstatfs st;
37154 + struct au_sbinfo *sbinfo;
37155 + struct au_xino *xi;
37156 + struct file *file;
37158 + /* todo: si_xino_expire and the ratio should be customizable */
37159 + sbinfo = au_sbi(sb);
37160 + if (time_before(jiffies,
37161 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37164 + /* truncation border */
37165 + xi = br->br_xino;
37166 + for (u = 0; u < xi->xi_nfile; u++) {
37167 + file = au_xino_file(xi, u);
37171 + err = vfs_statfs(&file->f_path, &st);
37172 + if (unlikely(err)) {
37173 + AuErr1("statfs err %d, ignored\n", err);
37176 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37177 + >= AUFS_XINO_DEF_TRUNC)
37184 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37187 + struct xino_do_trunc_args *args;
37190 + idx = xino_trunc_test(sb, br);
37194 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37197 + /* lock and kfree() will be called in trunc_xino() */
37198 + args = kmalloc(sizeof(*args), GFP_NOFS);
37199 + if (unlikely(!args)) {
37200 + AuErr1("no memory\n");
37204 + au_lcnt_inc(&br->br_count);
37208 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37210 + return; /* success */
37212 + pr_err("wkq %d\n", wkq_err);
37213 + au_lcnt_dec(&br->br_count);
37214 + au_kfree_rcu(args);
37217 + atomic_dec(&br->br_xino->xi_truncating);
37220 +/* ---------------------------------------------------------------------- */
37222 +struct au_xi_calc {
37227 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37228 + struct au_xi_calc *calc)
37232 + maxent = au_xi_maxent(sb);
37233 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37234 + calc->pos *= sizeof(ino_t);
37237 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37238 + struct au_xi_calc *calc)
37241 + struct file *file;
37242 + struct au_xino *xi = br->br_xino;
37243 + struct au_xi_new xinew = {
37247 + SiMustAnyLock(sb);
37253 + mutex_lock(&xi->xi_mtx);
37254 + file = au_xino_file(xi, calc->idx);
37258 + file = au_xino_file(xi, /*idx*/-1);
37259 + AuDebugOn(!file);
37260 + xinew.idx = calc->idx;
37261 + xinew.base = &file->f_path;
37262 + /* xinew.copy_src = NULL; */
37263 + file = au_xi_new(sb, &xinew);
37264 + if (IS_ERR(file))
37265 + err = PTR_ERR(file);
37268 + mutex_unlock(&xi->xi_mtx);
37273 +struct au_xino_do_new_async_args {
37274 + struct super_block *sb;
37275 + struct au_branch *br;
37276 + struct au_xi_calc calc;
37280 +struct au_xi_writing {
37281 + struct hlist_bl_node node;
37282 + ino_t h_ino, ino;
37285 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37288 +static void au_xino_call_do_new_async(void *args)
37290 + struct au_xino_do_new_async_args *a = args;
37291 + struct au_branch *br;
37292 + struct super_block *sb;
37293 + struct au_sbinfo *sbi;
37294 + struct inode *root;
37295 + struct file *file;
37296 + struct au_xi_writing *del, *p;
37297 + struct hlist_bl_head *hbl;
37298 + struct hlist_bl_node *pos;
37303 + sbi = au_sbi(sb);
37304 + si_noflush_read_lock(sb);
37305 + root = d_inode(sb->s_root);
37306 + ii_read_lock_child(root);
37307 + err = au_xino_do_new_async(sb, br, &a->calc);
37308 + if (unlikely(err)) {
37309 + AuIOErr("err %d\n", err);
37313 + file = au_xino_file(br->br_xino, a->calc.idx);
37314 + AuDebugOn(!file);
37315 + err = au_xino_do_write(file, &a->calc, a->ino);
37316 + if (unlikely(err)) {
37317 + AuIOErr("err %d\n", err);
37322 + hbl = &br->br_xino->xi_writing;
37323 + hlist_bl_lock(hbl);
37324 + au_hbl_for_each(pos, hbl) {
37325 + p = container_of(pos, struct au_xi_writing, node);
37326 + if (p->ino == a->ino) {
37328 + hlist_bl_del(&p->node);
37332 + hlist_bl_unlock(hbl);
37333 + au_kfree_rcu(del);
37336 + au_lcnt_dec(&br->br_count);
37337 + ii_read_unlock(root);
37338 + si_read_unlock(sb);
37339 + au_nwt_done(&sbi->si_nowait);
37344 + * create a new xino file asynchronously
37346 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37347 + struct au_xi_calc *calc, ino_t ino)
37350 + struct au_xino_do_new_async_args *arg;
37353 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37354 + if (unlikely(!arg))
37359 + arg->calc = *calc;
37361 + au_lcnt_inc(&br->br_count);
37362 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37363 + if (unlikely(err)) {
37364 + pr_err("wkq %d\n", err);
37365 + au_lcnt_dec(&br->br_count);
37366 + au_kfree_rcu(arg);
37374 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37375 + * at the position of @h_ino.
37377 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37382 + struct au_xi_calc calc;
37383 + struct au_sbinfo *sbinfo;
37384 + struct file *file;
37385 + struct au_xino *xi;
37386 + struct hlist_bl_head *hbl;
37387 + struct hlist_bl_node *pos;
37388 + struct au_xi_writing *p;
37391 + if (!au_opt_test(au_mntflags(sb), XINO))
37392 + return 0; /* no xino */
37395 + au_xi_calc(sb, h_ino, &calc);
37396 + xi = au_sbr(sb, bindex)->br_xino;
37397 + file = au_xino_file(xi, calc.idx);
37399 + hbl = &xi->xi_writing;
37400 + hlist_bl_lock(hbl);
37401 + au_hbl_for_each(pos, hbl) {
37402 + p = container_of(pos, struct au_xi_writing, node);
37403 + if (p->h_ino == h_ino) {
37404 + AuDbg("hi%llu, i%llu, found\n",
37405 + (u64)p->h_ino, (u64)p->ino);
37410 + hlist_bl_unlock(hbl);
37412 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37413 + return 0; /* no xino */
37415 + sbinfo = au_sbi(sb);
37416 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37417 + if (sz == sizeof(*ino))
37418 + return 0; /* success */
37421 + if (unlikely(sz >= 0)) {
37423 + AuIOErr("xino read error (%zd)\n", sz);
37428 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37433 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37434 + if (sz == sizeof(ino))
37435 + return 0; /* success */
37437 + AuIOErr("write failed (%zd)\n", sz);
37442 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37443 + * at the position of @h_ino.
37444 + * even if @ino is zero, it is written to the xinofile and means no entry.
37445 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37446 + * try truncating it.
37448 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37452 + unsigned int mnt_flags;
37453 + struct au_xi_calc calc;
37454 + struct file *file;
37455 + struct au_branch *br;
37456 + struct au_xino *xi;
37457 + struct au_xi_writing *p;
37459 + SiMustAnyLock(sb);
37461 + mnt_flags = au_mntflags(sb);
37462 + if (!au_opt_test(mnt_flags, XINO))
37465 + au_xi_calc(sb, h_ino, &calc);
37466 + br = au_sbr(sb, bindex);
37467 + xi = br->br_xino;
37468 + file = au_xino_file(xi, calc.idx);
37470 + /* store the inum pair into the list */
37471 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37472 + p->h_ino = h_ino;
37474 + au_hbl_add(&p->node, &xi->xi_writing);
37476 + /* create and write a new xino file asynchronously */
37477 + err = au_xino_new_async(sb, br, &calc, ino);
37479 + return 0; /* success */
37483 + err = au_xino_do_write(file, &calc, ino);
37485 + br = au_sbr(sb, bindex);
37486 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37487 + && au_test_fs_trunc_xino(au_br_sb(br)))
37488 + xino_try_trunc(sb, br);
37489 + return 0; /* success */
37493 + AuIOErr("write failed (%d)\n", err);
37497 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37500 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37501 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37505 + const int prevent_endless = 10;
37509 + err = vfsub_read_k(file, kbuf, size, pos);
37510 + if (err == -EINTR
37511 + && !au_wkq_test()
37512 + && fatal_signal_pending(current)) {
37513 + err = xino_fread_wkq(file, kbuf, size, pos);
37514 + BUG_ON(err == -EINTR);
37516 + } while (i++ < prevent_endless
37517 + && (err == -EAGAIN || err == -EINTR));
37519 +#if 0 /* reserved for future use */
37521 + fsnotify_access(file->f_path.dentry);
37527 +struct xino_fread_args {
37529 + struct file *file;
37535 +static void call_xino_fread(void *args)
37537 + struct xino_fread_args *a = args;
37538 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37541 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37546 + struct xino_fread_args args = {
37554 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37555 + if (unlikely(wkq_err))
37561 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37564 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37569 + const int prevent_endless = 10;
37573 + err = vfsub_write_k(file, kbuf, size, pos);
37574 + if (err == -EINTR
37575 + && !au_wkq_test()
37576 + && fatal_signal_pending(current)) {
37577 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37578 + BUG_ON(err == -EINTR);
37580 + } while (i++ < prevent_endless
37581 + && (err == -EAGAIN || err == -EINTR));
37583 +#if 0 /* reserved for future use */
37585 + fsnotify_modify(file->f_path.dentry);
37591 +struct do_xino_fwrite_args {
37593 + struct file *file;
37599 +static void call_do_xino_fwrite(void *args)
37601 + struct do_xino_fwrite_args *a = args;
37602 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37605 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37610 + struct do_xino_fwrite_args args = {
37619 + * it breaks RLIMIT_FSIZE and normal user's limit,
37620 + * users should care about quota and real 'filesystem full.'
37622 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37623 + if (unlikely(wkq_err))
37629 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37633 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37635 + err = do_xino_fwrite(file, buf, size, pos);
37639 + err = xino_fwrite_wkq(file, buf, size, pos);
37646 +/* ---------------------------------------------------------------------- */
37649 + * inode number bitmap
37651 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37652 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37656 + AuDebugOn(bit < 0 || page_bits <= bit);
37657 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37661 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37663 + AuDebugOn(ino < AUFS_FIRST_INO);
37664 + ino -= AUFS_FIRST_INO;
37665 + *pindex = ino / page_bits;
37666 + *bit = ino % page_bits;
37669 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37674 + struct au_sbinfo *sbinfo;
37675 + struct file *xib;
37676 + unsigned long *p;
37678 + sbinfo = au_sbi(sb);
37679 + MtxMustLock(&sbinfo->si_xib_mtx);
37680 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37681 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37683 + if (pindex == sbinfo->si_xib_last_pindex)
37686 + xib = sbinfo->si_xib;
37687 + p = sbinfo->si_xib_buf;
37688 + pos = sbinfo->si_xib_last_pindex;
37689 + pos *= PAGE_SIZE;
37690 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37691 + if (unlikely(sz != PAGE_SIZE))
37695 + pos *= PAGE_SIZE;
37696 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37697 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37699 + memset(p, 0, PAGE_SIZE);
37700 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37702 + if (sz == PAGE_SIZE) {
37703 + sbinfo->si_xib_last_pindex = pindex;
37704 + return 0; /* success */
37708 + AuIOErr1("write failed (%zd)\n", sz);
37715 +static void au_xib_clear_bit(struct inode *inode)
37718 + unsigned long pindex;
37719 + struct super_block *sb;
37720 + struct au_sbinfo *sbinfo;
37722 + AuDebugOn(inode->i_nlink);
37724 + sb = inode->i_sb;
37725 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37726 + AuDebugOn(page_bits <= bit);
37727 + sbinfo = au_sbi(sb);
37728 + mutex_lock(&sbinfo->si_xib_mtx);
37729 + err = xib_pindex(sb, pindex);
37731 + clear_bit(bit, sbinfo->si_xib_buf);
37732 + sbinfo->si_xib_next_bit = bit;
37734 + mutex_unlock(&sbinfo->si_xib_mtx);
37737 +/* ---------------------------------------------------------------------- */
37740 + * truncate a xino bitmap file
37744 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37748 + unsigned long pindex;
37749 + loff_t pos, pend;
37750 + struct au_sbinfo *sbinfo;
37752 + unsigned long *p;
37755 + sbinfo = au_sbi(sb);
37756 + MtxMustLock(&sbinfo->si_xib_mtx);
37757 + p = sbinfo->si_xib_buf;
37758 + pend = vfsub_f_size_read(file);
37760 + while (pos < pend) {
37761 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37763 + if (unlikely(sz <= 0))
37767 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37768 + if (unlikely(*ino < AUFS_FIRST_INO))
37771 + xib_calc_bit(*ino, &pindex, &bit);
37772 + AuDebugOn(page_bits <= bit);
37773 + err = xib_pindex(sb, pindex);
37785 +static int xib_restore(struct super_block *sb)
37788 + unsigned int nfile;
37789 + aufs_bindex_t bindex, bbot;
37791 + struct au_branch *br;
37792 + struct au_xino *xi;
37793 + struct file *file;
37796 + page = (void *)__get_free_page(GFP_NOFS);
37797 + if (unlikely(!page))
37801 + bbot = au_sbbot(sb);
37802 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37803 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37804 + br = au_sbr(sb, bindex);
37805 + xi = br->br_xino;
37806 + nfile = xi->xi_nfile;
37807 + for (i = 0; i < nfile; i++) {
37808 + file = au_xino_file(xi, i);
37810 + err = do_xib_restore(sb, file, page);
37813 + AuDbg("skip shared b%d\n", bindex);
37814 + free_page((unsigned long)page);
37820 +int au_xib_trunc(struct super_block *sb)
37825 + struct au_sbinfo *sbinfo;
37826 + unsigned long *p;
37827 + struct file *file;
37829 + SiMustWriteLock(sb);
37832 + sbinfo = au_sbi(sb);
37833 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37836 + file = sbinfo->si_xib;
37837 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37840 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37841 + err = PTR_ERR(file);
37842 + if (IS_ERR(file))
37844 + fput(sbinfo->si_xib);
37845 + sbinfo->si_xib = file;
37847 + p = sbinfo->si_xib_buf;
37848 + memset(p, 0, PAGE_SIZE);
37850 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
37851 + if (unlikely(sz != PAGE_SIZE)) {
37853 + AuIOErr("err %d\n", err);
37859 + mutex_lock(&sbinfo->si_xib_mtx);
37860 + /* mnt_want_write() is unnecessary here */
37861 + err = xib_restore(sb);
37862 + mutex_unlock(&sbinfo->si_xib_mtx);
37868 +/* ---------------------------------------------------------------------- */
37870 +struct au_xino *au_xino_alloc(unsigned int nfile)
37872 + struct au_xino *xi;
37874 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37875 + if (unlikely(!xi))
37877 + xi->xi_nfile = nfile;
37878 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
37879 + if (unlikely(!xi->xi_file))
37882 + xi->xi_nondir.total = 8; /* initial size */
37883 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37885 + if (unlikely(!xi->xi_nondir.array))
37888 + spin_lock_init(&xi->xi_nondir.spin);
37889 + init_waitqueue_head(&xi->xi_nondir.wqh);
37890 + mutex_init(&xi->xi_mtx);
37891 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
37892 + atomic_set(&xi->xi_truncating, 0);
37893 + kref_init(&xi->xi_kref);
37894 + goto out; /* success */
37897 + au_kfree_try_rcu(xi->xi_file);
37899 + au_kfree_rcu(xi);
37905 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
37908 + struct au_xino *xi;
37911 + xi = au_xino_alloc(idx + 1);
37912 + if (unlikely(!xi)) {
37919 + xi->xi_file[idx] = file;
37920 + AuDebugOn(br->br_xino);
37921 + br->br_xino = xi;
37927 +static void au_xino_release(struct kref *kref)
37929 + struct au_xino *xi;
37931 + unsigned long ul;
37932 + struct hlist_bl_head *hbl;
37933 + struct hlist_bl_node *pos, *n;
37934 + struct au_xi_writing *p;
37936 + xi = container_of(kref, struct au_xino, xi_kref);
37937 + for (i = 0; i < xi->xi_nfile; i++)
37938 + if (xi->xi_file[i])
37939 + fput(xi->xi_file[i]);
37940 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37941 + AuDebugOn(xi->xi_nondir.array[i]);
37942 + mutex_destroy(&xi->xi_mtx);
37943 + hbl = &xi->xi_writing;
37944 + ul = au_hbl_count(hbl);
37945 + if (unlikely(ul)) {
37946 + pr_warn("xi_writing %lu\n", ul);
37947 + hlist_bl_lock(hbl);
37948 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
37949 + hlist_bl_del(&p->node);
37950 + /* kmemleak reported au_kfree_rcu() doesn't free it */
37953 + hlist_bl_unlock(hbl);
37955 + au_kfree_try_rcu(xi->xi_file);
37956 + au_kfree_try_rcu(xi->xi_nondir.array);
37957 + au_kfree_rcu(xi);
37960 +int au_xino_put(struct au_branch *br)
37963 + struct au_xino *xi;
37966 + xi = br->br_xino;
37968 + br->br_xino = NULL;
37969 + ret = kref_put(&xi->xi_kref, au_xino_release);
37975 +/* ---------------------------------------------------------------------- */
37978 + * xino mount option handlers
37982 +static void xino_clear_xib(struct super_block *sb)
37984 + struct au_sbinfo *sbinfo;
37986 + SiMustWriteLock(sb);
37988 + sbinfo = au_sbi(sb);
37989 + if (sbinfo->si_xib)
37990 + fput(sbinfo->si_xib);
37991 + sbinfo->si_xib = NULL;
37992 + if (sbinfo->si_xib_buf)
37993 + free_page((unsigned long)sbinfo->si_xib_buf);
37994 + sbinfo->si_xib_buf = NULL;
37997 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38001 + struct au_sbinfo *sbinfo;
38002 + struct file *file;
38003 + struct super_block *xi_sb;
38005 + SiMustWriteLock(sb);
38007 + sbinfo = au_sbi(sb);
38008 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38009 + err = PTR_ERR(file);
38010 + if (IS_ERR(file))
38012 + if (sbinfo->si_xib)
38013 + fput(sbinfo->si_xib);
38014 + sbinfo->si_xib = file;
38015 + xi_sb = file_inode(file)->i_sb;
38016 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38017 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38019 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38020 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38023 + sbinfo->si_ximaxent /= sizeof(ino_t);
38026 + if (!sbinfo->si_xib_buf)
38027 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38028 + if (unlikely(!sbinfo->si_xib_buf))
38031 + sbinfo->si_xib_last_pindex = 0;
38032 + sbinfo->si_xib_next_bit = 0;
38033 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38035 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38036 + if (unlikely(err != PAGE_SIZE))
38040 + goto out; /* success */
38043 + if (sbinfo->si_xib_buf)
38044 + free_page((unsigned long)sbinfo->si_xib_buf);
38045 + sbinfo->si_xib_buf = NULL;
38049 + fput(sbinfo->si_xib);
38050 + sbinfo->si_xib = NULL;
38056 +/* xino for each branch */
38057 +static void xino_clear_br(struct super_block *sb)
38059 + aufs_bindex_t bindex, bbot;
38060 + struct au_branch *br;
38062 + bbot = au_sbbot(sb);
38063 + for (bindex = 0; bindex <= bbot; bindex++) {
38064 + br = au_sbr(sb, bindex);
38070 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38071 + aufs_bindex_t bshared)
38073 + struct au_branch *brshared;
38075 + brshared = au_sbr(sb, bshared);
38076 + AuDebugOn(!brshared->br_xino);
38077 + AuDebugOn(!brshared->br_xino->xi_file);
38078 + if (br->br_xino != brshared->br_xino) {
38079 + au_xino_get(brshared);
38081 + br->br_xino = brshared->br_xino;
38085 +struct au_xino_do_set_br {
38086 + struct au_branch *br;
38088 + aufs_bindex_t bshared;
38091 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38092 + struct au_xino_do_set_br *args)
38095 + struct au_xi_calc calc;
38096 + struct file *file;
38097 + struct au_branch *br;
38098 + struct au_xi_new xinew = {
38103 + xinew.xi = br->br_xino;
38104 + au_xi_calc(sb, args->h_ino, &calc);
38105 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38106 + if (args->bshared >= 0)
38107 + /* shared xino */
38108 + au_xino_set_br_shared(sb, br, args->bshared);
38109 + else if (!xinew.xi) {
38111 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38112 + if (unlikely(err))
38116 + /* force re-creating */
38117 + xinew.xi = br->br_xino;
38118 + xinew.idx = calc.idx;
38119 + mutex_lock(&xinew.xi->xi_mtx);
38120 + file = au_xi_new(sb, &xinew);
38121 + mutex_unlock(&xinew.xi->xi_mtx);
38122 + err = PTR_ERR(file);
38123 + if (IS_ERR(file))
38125 + AuDebugOn(!file);
38127 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38128 + if (unlikely(err))
38136 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38139 + aufs_bindex_t bindex, bbot;
38140 + struct au_xino_do_set_br args;
38141 + struct inode *inode;
38143 + SiMustWriteLock(sb);
38145 + bbot = au_sbbot(sb);
38146 + inode = d_inode(sb->s_root);
38147 + for (bindex = 0; bindex <= bbot; bindex++) {
38148 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38149 + args.br = au_sbr(sb, bindex);
38150 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38151 + err = au_xino_do_set_br(sb, path, &args);
38152 + if (unlikely(err))
38160 +void au_xino_clr(struct super_block *sb)
38162 + struct au_sbinfo *sbinfo;
38164 + au_xigen_clr(sb);
38165 + xino_clear_xib(sb);
38166 + xino_clear_br(sb);
38167 + dbgaufs_brs_del(sb, 0);
38168 + sbinfo = au_sbi(sb);
38169 + /* lvalue, do not call au_mntflags() */
38170 + au_opt_clr(sbinfo->si_mntflags, XINO);
38173 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38176 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38177 + struct qstr *dname, *cur_name;
38178 + struct file *cur_xino;
38179 + struct au_sbinfo *sbinfo;
38180 + struct path *path, *cur_path;
38182 + SiMustWriteLock(sb);
38185 + sbinfo = au_sbi(sb);
38186 + path = &xiopt->file->f_path;
38187 + dentry = path->dentry;
38188 + parent = dget_parent(dentry);
38191 + cur_xino = sbinfo->si_xib;
38193 + cur_path = &cur_xino->f_path;
38194 + cur_dentry = cur_path->dentry;
38195 + cur_parent = dget_parent(cur_dentry);
38196 + cur_name = &cur_dentry->d_name;
38197 + dname = &dentry->d_name;
38198 + skip = (cur_parent == parent
38199 + && au_qstreq(dname, cur_name));
38200 + dput(cur_parent);
38206 + au_opt_set(sbinfo->si_mntflags, XINO);
38207 + err = au_xino_set_xib(sb, path);
38208 + /* si_x{read,write} are set */
38210 + err = au_xigen_set(sb, path);
38212 + err = au_xino_set_br(sb, path);
38214 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38215 + goto out; /* success */
38219 + AuIOErr("failed setting xino(%d).\n", err);
38228 + * create a xinofile at the default place/path.
38230 +struct file *au_xino_def(struct super_block *sb)
38232 + struct file *file;
38234 + struct au_branch *br;
38235 + struct super_block *h_sb;
38236 + struct path path;
38237 + aufs_bindex_t bbot, bindex, bwr;
38240 + bbot = au_sbbot(sb);
38242 + for (bindex = 0; bindex <= bbot; bindex++) {
38243 + br = au_sbr(sb, bindex);
38244 + if (au_br_writable(br->br_perm)
38245 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38252 + file = ERR_PTR(-ENOMEM);
38253 + page = (void *)__get_free_page(GFP_NOFS);
38254 + if (unlikely(!page))
38256 + path.mnt = au_br_mnt(br);
38257 + path.dentry = au_h_dptr(sb->s_root, bwr);
38258 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38259 + file = (void *)p;
38260 + if (!IS_ERR(p)) {
38261 + strcat(p, "/" AUFS_XINO_FNAME);
38262 + AuDbg("%s\n", p);
38263 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38265 + free_page((unsigned long)page);
38267 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38269 + if (IS_ERR(file))
38271 + h_sb = file->f_path.dentry->d_sb;
38272 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38273 + pr_err("xino doesn't support %s(%s)\n",
38274 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38276 + file = ERR_PTR(-EINVAL);
38284 +/* ---------------------------------------------------------------------- */
38287 + * initialize the xinofile for the specified branch @br
38288 + * at the place/path where @base_file indicates.
38289 + * test whether another branch is on the same filesystem or not,
38290 + * if found then share the xinofile with another branch.
38292 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38293 + struct path *base)
38296 + struct au_xino_do_set_br args = {
38301 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38303 + err = au_xino_do_set_br(sb, base, &args);
38304 + if (unlikely(err))
38310 +/* ---------------------------------------------------------------------- */
38313 + * get an unused inode number from bitmap
38315 +ino_t au_xino_new_ino(struct super_block *sb)
38318 + unsigned long *p, pindex, ul, pend;
38319 + struct au_sbinfo *sbinfo;
38320 + struct file *file;
38321 + int free_bit, err;
38323 + if (!au_opt_test(au_mntflags(sb), XINO))
38324 + return iunique(sb, AUFS_FIRST_INO);
38326 + sbinfo = au_sbi(sb);
38327 + mutex_lock(&sbinfo->si_xib_mtx);
38328 + p = sbinfo->si_xib_buf;
38329 + free_bit = sbinfo->si_xib_next_bit;
38330 + if (free_bit < page_bits && !test_bit(free_bit, p))
38331 + goto out; /* success */
38332 + free_bit = find_first_zero_bit(p, page_bits);
38333 + if (free_bit < page_bits)
38334 + goto out; /* success */
38336 + pindex = sbinfo->si_xib_last_pindex;
38337 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38338 + err = xib_pindex(sb, ul);
38339 + if (unlikely(err))
38341 + free_bit = find_first_zero_bit(p, page_bits);
38342 + if (free_bit < page_bits)
38343 + goto out; /* success */
38346 + file = sbinfo->si_xib;
38347 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38348 + for (ul = pindex + 1; ul <= pend; ul++) {
38349 + err = xib_pindex(sb, ul);
38350 + if (unlikely(err))
38352 + free_bit = find_first_zero_bit(p, page_bits);
38353 + if (free_bit < page_bits)
38354 + goto out; /* success */
38359 + set_bit(free_bit, p);
38360 + sbinfo->si_xib_next_bit = free_bit + 1;
38361 + pindex = sbinfo->si_xib_last_pindex;
38362 + mutex_unlock(&sbinfo->si_xib_mtx);
38363 + ino = xib_calc_ino(pindex, free_bit);
38364 + AuDbg("i%lu\n", (unsigned long)ino);
38367 + mutex_unlock(&sbinfo->si_xib_mtx);
38372 +/* for s_op->delete_inode() */
38373 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38376 + unsigned int mnt_flags;
38377 + aufs_bindex_t bindex, bbot, bi;
38378 + unsigned char try_trunc;
38379 + struct au_iinfo *iinfo;
38380 + struct super_block *sb;
38381 + struct au_hinode *hi;
38382 + struct inode *h_inode;
38383 + struct au_branch *br;
38384 + struct au_xi_calc calc;
38385 + struct file *file;
38387 + AuDebugOn(au_is_bad_inode(inode));
38389 + sb = inode->i_sb;
38390 + mnt_flags = au_mntflags(sb);
38391 + if (!au_opt_test(mnt_flags, XINO)
38392 + || inode->i_ino == AUFS_ROOT_INO)
38396 + au_xigen_inc(inode);
38397 + au_xib_clear_bit(inode);
38400 + iinfo = au_ii(inode);
38401 + bindex = iinfo->ii_btop;
38405 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38406 + hi = au_hinode(iinfo, bindex);
38407 + bbot = iinfo->ii_bbot;
38408 + for (; bindex <= bbot; bindex++, hi++) {
38409 + h_inode = hi->hi_inode;
38411 + || (!unlinked && h_inode->i_nlink))
38414 + /* inode may not be revalidated */
38415 + bi = au_br_index(sb, hi->hi_id);
38419 + br = au_sbr(sb, bi);
38420 + au_xi_calc(sb, h_inode->i_ino, &calc);
38421 + file = au_xino_file(br->br_xino, calc.idx);
38422 + if (IS_ERR_OR_NULL(file))
38425 + err = au_xino_do_write(file, &calc, /*ino*/0);
38426 + if (!err && try_trunc
38427 + && au_test_fs_trunc_xino(au_br_sb(br)))
38428 + xino_try_trunc(sb, br);
38432 +/* ---------------------------------------------------------------------- */
38434 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38436 + int found, total, i;
38439 + total = xi->xi_nondir.total;
38440 + for (i = 0; i < total; i++) {
38441 + if (xi->xi_nondir.array[i] != h_ino)
38450 +static int au_xinondir_expand(struct au_xino *xi)
38455 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38458 + sz = xi->xi_nondir.total * sizeof(ino_t);
38459 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38461 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38462 + /*may_shrink*/0);
38464 + xi->xi_nondir.array = p;
38465 + xi->xi_nondir.total <<= 1;
38466 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38474 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38475 + ino_t h_ino, int idx)
38477 + struct au_xino *xi;
38479 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38480 + xi = au_sbr(sb, bindex)->br_xino;
38481 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38483 + spin_lock(&xi->xi_nondir.spin);
38484 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38485 + xi->xi_nondir.array[idx] = 0;
38486 + spin_unlock(&xi->xi_nondir.spin);
38487 + wake_up_all(&xi->xi_nondir.wqh);
38490 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38493 + int err, found, empty;
38494 + struct au_xino *xi;
38498 + if (!au_opt_test(au_mntflags(sb), XINO))
38499 + goto out; /* no xino */
38501 + xi = au_sbr(sb, bindex)->br_xino;
38504 + spin_lock(&xi->xi_nondir.spin);
38505 + found = au_xinondir_find(xi, h_ino);
38506 + if (found == -1) {
38507 + empty = au_xinondir_find(xi, /*h_ino*/0);
38508 + if (empty == -1) {
38509 + empty = xi->xi_nondir.total;
38510 + err = au_xinondir_expand(xi);
38511 + if (unlikely(err))
38514 + xi->xi_nondir.array[empty] = h_ino;
38517 + spin_unlock(&xi->xi_nondir.spin);
38518 + wait_event(xi->xi_nondir.wqh,
38519 + xi->xi_nondir.array[found] != h_ino);
38524 + spin_unlock(&xi->xi_nondir.spin);
38529 +/* ---------------------------------------------------------------------- */
38531 +int au_xino_path(struct seq_file *seq, struct file *file)
38535 + err = au_seq_path(seq, &file->f_path);
38536 + if (unlikely(err))
38539 +#define Deleted "\\040(deleted)"
38540 + seq->count -= sizeof(Deleted) - 1;
38541 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38542 + sizeof(Deleted) - 1));
38548 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38549 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38550 +++ linux/include/uapi/linux/aufs_type.h 2021-12-03 15:38:59.943313977 +0100
38552 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38554 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38556 + * This program, aufs is free software; you can redistribute it and/or modify
38557 + * it under the terms of the GNU General Public License as published by
38558 + * the Free Software Foundation; either version 2 of the License, or
38559 + * (at your option) any later version.
38561 + * This program is distributed in the hope that it will be useful,
38562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38564 + * GNU General Public License for more details.
38566 + * You should have received a copy of the GNU General Public License
38567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38570 +#ifndef __AUFS_TYPE_H__
38571 +#define __AUFS_TYPE_H__
38573 +#define AUFS_NAME "aufs"
38577 + * define it before including all other headers.
38578 + * sched.h may use pr_* macros before defining "current", so define the
38579 + * no-current version first, and re-define later.
38581 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38582 +#include <linux/sched.h>
38584 +#define pr_fmt(fmt) \
38585 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38586 + (int)sizeof(current->comm), current->comm, current->pid
38587 +#include <linux/limits.h>
38589 +#include <stdint.h>
38590 +#include <sys/types.h>
38591 +#include <limits.h>
38592 +#endif /* __KERNEL__ */
38594 +#define AUFS_VERSION "5.10.82-20211129"
38596 +/* todo? move this to linux-2.6.19/include/magic.h */
38597 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38599 +/* ---------------------------------------------------------------------- */
38602 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38603 +typedef int8_t aufs_bindex_t;
38604 +#define AUFS_BRANCH_MAX 127
38606 +typedef int16_t aufs_bindex_t;
38607 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38608 +#define AUFS_BRANCH_MAX 511
38609 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38610 +#define AUFS_BRANCH_MAX 1023
38611 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38612 +#define AUFS_BRANCH_MAX 32767
38616 +#ifndef AUFS_BRANCH_MAX
38617 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38619 +#endif /* __KERNEL__ */
38621 +/* ---------------------------------------------------------------------- */
38623 +#define AUFS_FSTYPE AUFS_NAME
38625 +#define AUFS_ROOT_INO 2
38626 +#define AUFS_FIRST_INO 11
38628 +#define AUFS_WH_PFX ".wh."
38629 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38630 +#define AUFS_WH_TMP_LEN 4
38631 +/* a limit for rmdir/rename a dir and copyup */
38632 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38633 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38635 + - AUFS_WH_TMP_LEN) /* hex */
38636 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38637 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38638 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38639 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38640 +#define AUFS_DIRWH_DEF 3
38641 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38642 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38643 +#define AUFS_RDBLK_DEF 512 /* bytes */
38644 +#define AUFS_RDHASH_DEF 32
38645 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38646 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38647 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38648 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38649 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38651 +/* pseudo-link maintenace under /proc */
38652 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38653 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38654 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38656 +/* dirren, renamed dir */
38657 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38658 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38659 +/* whiteouted doubly */
38660 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38661 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38663 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38664 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38666 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38667 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38668 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38670 +/* doubly whiteouted */
38671 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38672 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38673 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38675 +/* branch permissions and attributes */
38676 +#define AUFS_BRPERM_RW "rw"
38677 +#define AUFS_BRPERM_RO "ro"
38678 +#define AUFS_BRPERM_RR "rr"
38679 +#define AUFS_BRATTR_COO_REG "coo_reg"
38680 +#define AUFS_BRATTR_COO_ALL "coo_all"
38681 +#define AUFS_BRATTR_FHSM "fhsm"
38682 +#define AUFS_BRATTR_UNPIN "unpin"
38683 +#define AUFS_BRATTR_ICEX "icex"
38684 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38685 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38686 +#define AUFS_BRATTR_ICEX_TR "icextr"
38687 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38688 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38689 +#define AUFS_BRRATTR_WH "wh"
38690 +#define AUFS_BRWATTR_NLWH "nolwh"
38691 +#define AUFS_BRWATTR_MOO "moo"
38693 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38694 +#define AuBrPerm_RO (1 << 1) /* readonly */
38695 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38696 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38698 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38699 +#define AuBrAttr_COO_ALL (1 << 4)
38700 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38702 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38703 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38704 + branch. meaningless since
38705 + linux-3.18-rc1 */
38707 +/* ignore error in copying XATTR */
38708 +#define AuBrAttr_ICEX_SEC (1 << 7)
38709 +#define AuBrAttr_ICEX_SYS (1 << 8)
38710 +#define AuBrAttr_ICEX_TR (1 << 9)
38711 +#define AuBrAttr_ICEX_USR (1 << 10)
38712 +#define AuBrAttr_ICEX_OTH (1 << 11)
38713 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38714 + | AuBrAttr_ICEX_SYS \
38715 + | AuBrAttr_ICEX_TR \
38716 + | AuBrAttr_ICEX_USR \
38717 + | AuBrAttr_ICEX_OTH)
38719 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38720 +#define AuBrRAttr_Mask AuBrRAttr_WH
38722 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38723 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38724 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38726 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38728 +/* #warning test userspace */
38730 +#ifndef CONFIG_AUFS_FHSM
38731 +#undef AuBrAttr_FHSM
38732 +#define AuBrAttr_FHSM 0
38734 +#ifndef CONFIG_AUFS_XATTR
38735 +#undef AuBrAttr_ICEX
38736 +#define AuBrAttr_ICEX 0
38737 +#undef AuBrAttr_ICEX_SEC
38738 +#define AuBrAttr_ICEX_SEC 0
38739 +#undef AuBrAttr_ICEX_SYS
38740 +#define AuBrAttr_ICEX_SYS 0
38741 +#undef AuBrAttr_ICEX_TR
38742 +#define AuBrAttr_ICEX_TR 0
38743 +#undef AuBrAttr_ICEX_USR
38744 +#define AuBrAttr_ICEX_USR 0
38745 +#undef AuBrAttr_ICEX_OTH
38746 +#define AuBrAttr_ICEX_OTH 0
38750 +/* the longest combination */
38751 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38752 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38753 + "+" AUFS_BRATTR_COO_REG \
38754 + "+" AUFS_BRATTR_FHSM \
38755 + "+" AUFS_BRATTR_UNPIN \
38756 + "+" AUFS_BRATTR_ICEX_SEC \
38757 + "+" AUFS_BRATTR_ICEX_SYS \
38758 + "+" AUFS_BRATTR_ICEX_USR \
38759 + "+" AUFS_BRATTR_ICEX_OTH \
38760 + "+" AUFS_BRWATTR_NLWH)
38763 + char a[AuBrPermStrSz];
38764 +} au_br_perm_str_t;
38766 +static inline int au_br_writable(int brperm)
38768 + return brperm & AuBrPerm_RW;
38771 +static inline int au_br_whable(int brperm)
38773 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38776 +static inline int au_br_wh_linkable(int brperm)
38778 + return !(brperm & AuBrWAttr_NoLinkWH);
38781 +static inline int au_br_cmoo(int brperm)
38783 + return brperm & AuBrAttr_CMOO_Mask;
38786 +static inline int au_br_fhsm(int brperm)
38788 + return brperm & AuBrAttr_FHSM;
38791 +/* ---------------------------------------------------------------------- */
38795 + /* readdir in userspace */
38799 + AuCtl_WBR_FD, /* pathconf wrapper */
38800 + AuCtl_IBUSY, /* busy inode */
38801 + AuCtl_MVDOWN, /* move-down */
38802 + AuCtl_BR, /* info about branches */
38803 + AuCtl_FHSM_FD /* connection for fhsm */
38806 +/* borrowed from linux/include/linux/kernel.h */
38808 +#ifdef _GNU_SOURCE
38809 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38811 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38813 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38816 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38818 +#define __aligned(x) __attribute__((aligned(x)))
38823 +#define __packed __attribute__((packed))
38827 +struct au_rdu_cookie {
38832 + uint32_t generation;
38835 +struct au_rdu_ent {
38844 +static inline int au_rdu_len(int nlen)
38846 + /* include the terminating NULL */
38847 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38848 + sizeof(uint64_t));
38851 +union au_rdu_ent_ul {
38852 + struct au_rdu_ent __user *e;
38864 + uint64_t sz; /* AuCtl_RDU */
38865 + uint64_t nent; /* AuCtl_RDU_INO */
38867 + union au_rdu_ent_ul ent;
38868 + uint16_t verify[AufsCtlRduV_End];
38870 + /* input/output */
38874 + union au_rdu_ent_ul tail;
38875 + /* number of entries which were added in a single call */
38880 + struct au_rdu_cookie cookie;
38883 +/* ---------------------------------------------------------------------- */
38885 +/* dirren. the branch is identified by the filename who contains this */
38886 +struct au_drinfo {
38889 + uint8_t oldnamelen;
38890 + uint64_t _padding;
38892 + uint8_t oldname[];
38895 +struct au_drinfo_fdata {
38897 + struct au_drinfo drinfo;
38900 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38902 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38904 +/* ---------------------------------------------------------------------- */
38906 +struct aufs_wbr_fd {
38911 +/* ---------------------------------------------------------------------- */
38913 +struct aufs_ibusy {
38914 + uint64_t ino, h_ino;
38918 +/* ---------------------------------------------------------------------- */
38920 +/* error code for move-down */
38921 +/* the actual message strings are implemented in aufs-util.git */
38923 + EAU_MVDOWN_OPAQUE = 1,
38924 + EAU_MVDOWN_WHITEOUT,
38925 + EAU_MVDOWN_UPPER,
38926 + EAU_MVDOWN_BOTTOM,
38927 + EAU_MVDOWN_NOUPPER,
38928 + EAU_MVDOWN_NOLOWERBR,
38932 +/* flags for move-down */
38933 +#define AUFS_MVDOWN_DMSG 1
38934 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38935 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38936 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38937 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38938 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38939 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38940 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38941 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38942 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38943 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38944 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38945 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38947 +/* index for move-down */
38949 + AUFS_MVDOWN_UPPER,
38950 + AUFS_MVDOWN_LOWER,
38951 + AUFS_MVDOWN_NARRAY
38955 + * additional info of move-down
38956 + * number of free blocks and inodes.
38957 + * subset of struct kstatfs, but smaller and always 64bit.
38959 +struct aufs_stfs {
38960 + uint64_t f_blocks;
38961 + uint64_t f_bavail;
38962 + uint64_t f_files;
38963 + uint64_t f_ffree;
38966 +struct aufs_stbr {
38967 + int16_t brid; /* optional input */
38968 + int16_t bindex; /* output */
38969 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
38972 +struct aufs_mvdown {
38973 + uint32_t flags; /* input/output */
38974 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
38975 + int8_t au_errno; /* output */
38978 +/* ---------------------------------------------------------------------- */
38980 +union aufs_brinfo {
38981 + /* PATH_MAX may differ between kernel-space and user-space */
38982 + char _spacer[4096];
38990 +/* ---------------------------------------------------------------------- */
38992 +#define AuCtlType 'A'
38993 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
38994 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
38995 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
38996 + struct aufs_wbr_fd)
38997 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
38998 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
38999 + struct aufs_mvdown)
39000 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39001 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39003 +#endif /* __AUFS_TYPE_H__ */
39004 SPDX-License-Identifier: GPL-2.0
39005 aufs5.10.82 loopback patch
39007 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39008 index d09b1ef4a2b56..ee27ab8e34898 100644
39009 --- a/drivers/block/loop.c
39010 +++ b/drivers/block/loop.c
39011 @@ -637,6 +637,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39015 +static struct file *loop_real_file(struct file *file)
39017 + struct file *f = NULL;
39019 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39020 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39024 static void loop_reread_partitions(struct loop_device *lo,
39025 struct block_device *bdev)
39027 @@ -692,6 +701,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39030 struct file *file = NULL, *old_file;
39031 + struct file *f, *virt_file = NULL, *old_virt_file;
39035 @@ -711,12 +721,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39039 + f = loop_real_file(file);
39041 + virt_file = file;
39046 error = loop_validate_file(file, bdev);
39050 old_file = lo->lo_backing_file;
39051 + old_virt_file = lo->lo_backing_virt_file;
39055 @@ -728,6 +745,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39056 blk_mq_freeze_queue(lo->lo_queue);
39057 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39058 lo->lo_backing_file = file;
39059 + lo->lo_backing_virt_file = virt_file;
39060 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39061 mapping_set_gfp_mask(file->f_mapping,
39062 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39063 @@ -741,6 +759,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39067 + if (old_virt_file)
39068 + fput(old_virt_file);
39070 loop_reread_partitions(lo, bdev);
39072 @@ -749,6 +769,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39073 mutex_unlock(&loop_ctl_mutex);
39081 @@ -1077,7 +1099,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39082 struct block_device *bdev,
39083 const struct loop_config *config)
39085 - struct file *file;
39086 + struct file *file, *f, *virt_file = NULL;
39087 struct inode *inode;
39088 struct address_space *mapping;
39089 struct block_device *claimed_bdev = NULL;
39090 @@ -1093,6 +1115,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39091 file = fget(config->fd);
39094 + f = loop_real_file(file);
39096 + virt_file = file;
39102 * If we don't hold exclusive handle for the device, upgrade to it
39103 @@ -1148,6 +1176,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39104 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39105 lo->lo_device = bdev;
39106 lo->lo_backing_file = file;
39107 + lo->lo_backing_virt_file = virt_file;
39108 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39109 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39111 @@ -1202,6 +1231,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39112 bd_abort_claiming(bdev, claimed_bdev, loop_configure);
39118 /* This is safe: open() is still holding a reference. */
39119 module_put(THIS_MODULE);
39120 @@ -1211,6 +1242,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39121 static int __loop_clr_fd(struct loop_device *lo, bool release)
39123 struct file *filp = NULL;
39124 + struct file *virt_filp = lo->lo_backing_virt_file;
39125 gfp_t gfp = lo->old_gfp_mask;
39126 struct block_device *bdev = lo->lo_device;
39128 @@ -1237,6 +1269,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39130 spin_lock_irq(&lo->lo_lock);
39131 lo->lo_backing_file = NULL;
39132 + lo->lo_backing_virt_file = NULL;
39133 spin_unlock_irq(&lo->lo_lock);
39135 loop_release_xfer(lo);
39136 @@ -1320,6 +1353,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39145 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39146 index af75a5ee40944..1d847cb194ff6 100644
39147 --- a/drivers/block/loop.h
39148 +++ b/drivers/block/loop.h
39149 @@ -46,7 +46,7 @@ struct loop_device {
39150 int (*ioctl)(struct loop_device *, int cmd,
39151 unsigned long arg);
39153 - struct file * lo_backing_file;
39154 + struct file *lo_backing_file, *lo_backing_virt_file;
39155 struct block_device *lo_device;
39158 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39159 index 99ceca1440449..e49dfe8550329 100644
39160 --- a/fs/aufs/f_op.c
39161 +++ b/fs/aufs/f_op.c
39162 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39163 if (IS_ERR(h_file))
39166 - if (au_test_loopback_kthread()) {
39167 + if (0 && au_test_loopback_kthread()) {
39168 au_warn_loopback(h_file->f_path.dentry->d_sb);
39169 if (file->f_mapping != h_file->f_mapping) {
39170 file->f_mapping = h_file->f_mapping;
39171 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39172 index 74347bd75b380..5ef888a1d53f4 100644
39173 --- a/fs/aufs/loop.c
39174 +++ b/fs/aufs/loop.c
39175 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39176 symbol_put(loop_backing_file);
39177 au_kfree_try_rcu(au_warn_loopback_array);
39180 +/* ---------------------------------------------------------------------- */
39182 +/* support the loopback block device insude aufs */
39184 +struct file *aufs_real_loop(struct file *file)
39188 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39189 + fi_read_lock(file);
39190 + f = au_hf_top(file);
39191 + fi_read_unlock(file);
39195 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39196 index 7293bee427f96..3345c098d0d47 100644
39197 --- a/fs/aufs/loop.h
39198 +++ b/fs/aufs/loop.h
39199 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39201 int au_loopback_init(void);
39202 void au_loopback_fin(void);
39204 +struct file *aufs_real_loop(struct file *file);
39206 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39208 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39210 AuStubInt0(au_loopback_init, void)
39211 AuStubVoid(au_loopback_fin, void)
39213 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39214 #endif /* BLK_DEV_LOOP */
39216 #endif /* __KERNEL__ */
39217 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39218 index 8e2d8464dac0e..ab6e940aac7ab 100644
39219 --- a/fs/aufs/super.c
39220 +++ b/fs/aufs/super.c
39221 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39222 .statfs = aufs_statfs,
39223 .put_super = aufs_put_super,
39224 .sync_fs = aufs_sync_fs,
39225 - .remount_fs = aufs_remount_fs
39226 + .remount_fs = aufs_remount_fs,
39227 +#ifdef CONFIG_AUFS_BDEV_LOOP
39228 + .real_loop = aufs_real_loop
39232 /* ---------------------------------------------------------------------- */
39233 diff --git a/include/linux/fs.h b/include/linux/fs.h
39234 index 2cc1a02e444c4..e53241a43d244 100644
39235 --- a/include/linux/fs.h
39236 +++ b/include/linux/fs.h
39237 @@ -1967,6 +1967,10 @@ struct super_operations {
39238 struct shrink_control *);
39239 long (*free_cached_objects)(struct super_block *,
39240 struct shrink_control *);
39241 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39243 + struct file *(*real_loop)(struct file *);