1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a55bda4233bbe..c4984b5bf340f 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 3215fe205256d..7218277473b8f 100644
20 @@ -135,3 +135,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
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 9450e052f1b13..f7db6edba5a37 100644
32 @@ -2992,6 +2992,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 <ojeda@kernel.org>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index a370cde3ddd49..01ca256575fb2 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -761,6 +761,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 7d24ff7eb2068..3caa7ab4b84f1 100644
85 @@ -1318,7 +1318,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 dfc72f15be7fc..d8a12eb63961d 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -64,6 +64,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index a047ab306f9a8..ba1df0895b69f 100644
120 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
124 -static int update_time(struct inode *inode, struct timespec64 *time, int flags)
125 +int update_time(struct inode *inode, struct timespec64 *time, int flags)
127 if (inode->i_op->update_time)
128 return inode->i_op->update_time(inode, time, flags);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 56bb5a5fdc0d0..540679d7e0434 100644
133 @@ -807,6 +807,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/splice.c b/fs/splice.c
147 index 5dbce4dcc1a7d..3e6ba363b7775 100644
150 @@ -759,8 +759,8 @@ static int warn_unsupported(struct file *file, const char *op)
152 * Attempt to initiate a splice from pipe to file.
154 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
155 - loff_t *ppos, size_t len, unsigned int flags)
156 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
157 + loff_t *ppos, size_t len, unsigned int flags)
159 if (unlikely(!out->f_op->splice_write))
160 return warn_unsupported(out, "write");
161 @@ -770,9 +770,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
163 * Attempt to initiate a splice from a file to a pipe.
165 -static long do_splice_to(struct file *in, loff_t *ppos,
166 - struct pipe_inode_info *pipe, size_t len,
167 - unsigned int flags)
168 +long do_splice_to(struct file *in, loff_t *ppos,
169 + struct pipe_inode_info *pipe, size_t len,
170 + unsigned int flags)
172 unsigned int p_space;
174 diff --git a/fs/sync.c b/fs/sync.c
175 index 1373a610dc784..b7b5a0a0df6ff 100644
179 * wait == 1 case since in that case write_inode() functions do
180 * sync_dirty_buffer() and thus effectively write one block at a time.
182 -static int __sync_filesystem(struct super_block *sb, int wait)
183 +int __sync_filesystem(struct super_block *sb, int wait)
187 diff --git a/include/linux/fs.h b/include/linux/fs.h
188 index ec8f3ddf4a6aa..4fa4b24535fde 100644
189 --- a/include/linux/fs.h
190 +++ b/include/linux/fs.h
191 @@ -1332,6 +1332,7 @@ extern void fasync_free(struct fasync_struct *);
192 /* can be called from interrupts */
193 extern void kill_fasync(struct fasync_struct **, int, int);
195 +extern int setfl(int fd, struct file *filp, unsigned long arg);
196 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
197 extern int f_setown(struct file *filp, unsigned long arg, int force);
198 extern void f_delown(struct file *filp);
199 @@ -1909,6 +1910,7 @@ struct file_operations {
200 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
201 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
202 int (*check_flags)(int);
203 + int (*setfl)(struct file *, unsigned long);
204 int (*flock) (struct file *, int, struct file_lock *);
205 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
206 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
207 @@ -2428,6 +2430,7 @@ extern int current_umask(void);
208 extern void ihold(struct inode * inode);
209 extern void iput(struct inode *);
210 extern int generic_update_time(struct inode *, struct timespec64 *, int);
211 +extern int update_time(struct inode *, struct timespec64 *, int);
214 extern struct kobject *fs_kobj;
215 @@ -2668,6 +2671,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
218 void emergency_thaw_all(void);
219 +extern int __sync_filesystem(struct super_block *, int);
220 extern int sync_filesystem(struct super_block *);
221 extern const struct file_operations def_blk_fops;
222 extern const struct file_operations def_chr_fops;
223 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
224 index 7b7ebf2e28ec5..20c46305e057e 100644
225 --- a/include/linux/lockdep.h
226 +++ b/include/linux/lockdep.h
227 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
228 return lock->key == key;
231 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
236 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
237 index 8f882f5881e87..6b9808f098435 100644
238 --- a/include/linux/mnt_namespace.h
239 +++ b/include/linux/mnt_namespace.h
240 @@ -7,12 +7,15 @@ struct mnt_namespace;
242 struct user_namespace;
246 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
247 struct user_namespace *, struct fs_struct *);
248 extern void put_mnt_ns(struct mnt_namespace *ns);
249 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
251 +extern int is_current_mnt_ns(struct vfsmount *mnt);
253 extern const struct file_operations proc_mounts_operations;
254 extern const struct file_operations proc_mountinfo_operations;
255 extern const struct file_operations proc_mountstats_operations;
256 diff --git a/include/linux/splice.h b/include/linux/splice.h
257 index a55179fd60fc3..8e21c53cf8831 100644
258 --- a/include/linux/splice.h
259 +++ b/include/linux/splice.h
260 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
262 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
263 extern const struct pipe_buf_operations default_pipe_buf_ops;
265 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
266 + loff_t *ppos, size_t len, unsigned int flags);
267 +extern long do_splice_to(struct file *in, loff_t *ppos,
268 + struct pipe_inode_info *pipe, size_t len,
269 + unsigned int flags);
271 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
272 index f160f1c97ca1e..fe71c2737eb9e 100644
273 --- a/kernel/locking/lockdep.c
274 +++ b/kernel/locking/lockdep.c
275 @@ -188,7 +188,7 @@ static
276 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
277 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
279 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
280 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
282 unsigned int class_idx = hlock->class_idx;
284 @@ -209,6 +209,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
286 return lock_classes + class_idx;
288 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
290 #ifdef CONFIG_LOCK_STAT
291 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
292 SPDX-License-Identifier: GPL-2.0
295 diff --git a/fs/proc/base.c b/fs/proc/base.c
296 index 3851bfcdba56e..d632ddd5f5ee8 100644
299 @@ -2183,7 +2183,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
301 vma = find_exact_vma(mm, vm_start, vm_end);
302 if (vma && vma->vm_file) {
303 - *path = vma->vm_file->f_path;
304 + *path = vma_pr_or_file(vma)->f_path;
308 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
309 index 13452b32e2bd5..38acccfef9d49 100644
310 --- a/fs/proc/nommu.c
311 +++ b/fs/proc/nommu.c
312 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
313 file = region->vm_file;
316 - struct inode *inode = file_inode(region->vm_file);
317 + struct inode *inode;
319 + file = vmr_pr_or_file(region);
320 + inode = file_inode(file);
321 dev = inode->i_sb->s_dev;
324 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
325 index e862cab695838..5c45041943a6f 100644
326 --- a/fs/proc/task_mmu.c
327 +++ b/fs/proc/task_mmu.c
328 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
329 const char *name = NULL;
332 - struct inode *inode = file_inode(vma->vm_file);
333 + struct inode *inode;
335 + file = vma_pr_or_file(vma);
336 + inode = file_inode(file);
337 dev = inode->i_sb->s_dev;
339 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
340 @@ -1861,7 +1864,7 @@ static int show_numa_map(struct seq_file *m, void *v)
341 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
342 struct vm_area_struct *vma = v;
343 struct numa_maps *md = &numa_priv->md;
344 - struct file *file = vma->vm_file;
345 + struct file *file = vma_pr_or_file(vma);
346 struct mm_struct *mm = vma->vm_mm;
347 struct mempolicy *pol;
349 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
350 index a6d21fc0033c6..02c2de31196e0 100644
351 --- a/fs/proc/task_nommu.c
352 +++ b/fs/proc/task_nommu.c
353 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
357 - struct inode *inode = file_inode(vma->vm_file);
358 + struct inode *inode;
360 + file = vma_pr_or_file(vma);
361 + inode = file_inode(file);
362 dev = inode->i_sb->s_dev;
364 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
365 diff --git a/include/linux/mm.h b/include/linux/mm.h
366 index 8ba434287387b..6d23d40ad1523 100644
367 --- a/include/linux/mm.h
368 +++ b/include/linux/mm.h
369 @@ -1759,6 +1759,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
370 unmap_mapping_range(mapping, holebegin, holelen, 0);
373 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
374 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
376 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
377 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
379 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
381 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
383 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
384 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
387 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
388 +extern void vmr_do_fput(struct vm_region *, const char[], int);
390 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
392 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
393 +#endif /* !CONFIG_MMU */
395 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
396 void *buf, int len, unsigned int gup_flags);
397 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
398 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
399 index 6613b26a88946..e94df45b5483a 100644
400 --- a/include/linux/mm_types.h
401 +++ b/include/linux/mm_types.h
402 @@ -279,6 +279,7 @@ struct vm_region {
403 unsigned long vm_top; /* region allocated to here */
404 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
405 struct file *vm_file; /* the backing file or NULL */
406 + struct file *vm_prfile; /* the virtual backing file or NULL */
408 int vm_usage; /* region usage count (access under nommu_region_sem) */
409 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
410 @@ -358,6 +359,7 @@ struct vm_area_struct {
411 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
413 struct file * vm_file; /* File we map to (can be NULL). */
414 + struct file *vm_prfile; /* shadow of vm_file */
415 void * vm_private_data; /* was vm_pte (shared mem) */
418 diff --git a/kernel/fork.c b/kernel/fork.c
419 index 426cd0c51f9eb..ea0ae494c6dde 100644
422 @@ -555,7 +555,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
423 struct inode *inode = file_inode(file);
424 struct address_space *mapping = file->f_mapping;
428 if (tmp->vm_flags & VM_DENYWRITE)
429 put_write_access(inode);
430 i_mmap_lock_write(mapping);
431 diff --git a/mm/Makefile b/mm/Makefile
432 index 72227b24a6168..5d03943b08e03 100644
435 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
436 mm_init.o percpu.o slab_common.o \
437 compaction.o vmacache.o \
438 interval_tree.o list_lru.o workingset.o \
439 - debug.o gup.o mmap_lock.o $(mmu-y)
440 + prfile.o debug.o gup.o mmap_lock.o $(mmu-y)
442 # Give 'page_alloc' its own module-parameter namespace
443 page-alloc-y := page_alloc.o
444 diff --git a/mm/filemap.c b/mm/filemap.c
445 index 6ce832dc59e73..8b7a71b6f0e6c 100644
448 @@ -3162,7 +3162,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
449 vm_fault_t ret = VM_FAULT_LOCKED;
451 sb_start_pagefault(mapping->host->i_sb);
452 - file_update_time(vmf->vma->vm_file);
453 + vma_file_update_time(vmf->vma);
455 if (page->mapping != mapping) {
457 diff --git a/mm/mmap.c b/mm/mmap.c
458 index 3f287599a7a30..eb36f1b18f048 100644
461 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
462 if (vma->vm_ops && vma->vm_ops->close)
463 vma->vm_ops->close(vma);
465 - fput(vma->vm_file);
467 mpol_put(vma_policy(vma));
470 @@ -949,7 +949,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
473 uprobe_munmap(next, next->vm_start, next->vm_end);
478 anon_vma_merge(vma, next);
479 @@ -1895,7 +1895,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
483 - fput(vma->vm_file);
487 /* Undo any partial mapping done by a device driver. */
488 @@ -2755,7 +2755,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
492 - get_file(new->vm_file);
495 if (new->vm_ops && new->vm_ops->open)
496 new->vm_ops->open(new);
497 @@ -2774,7 +2774,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
498 if (new->vm_ops && new->vm_ops->close)
499 new->vm_ops->close(new);
501 - fput(new->vm_file);
503 unlink_anon_vmas(new);
505 mpol_put(vma_policy(new));
506 @@ -2967,7 +2967,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
507 struct vm_area_struct *vma;
508 unsigned long populate = 0;
509 unsigned long ret = -EINVAL;
511 + struct file *file, *prfile;
513 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
514 current->comm, current->pid);
515 @@ -3042,10 +3042,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
519 - file = get_file(vma->vm_file);
521 + file = vma->vm_file;
522 + prfile = vma->vm_prfile;
523 ret = do_mmap(vma->vm_file, start, size,
524 prot, flags, pgoff, &populate, NULL);
525 + if (!IS_ERR_VALUE(ret) && file && prfile) {
526 + struct vm_area_struct *new_vma;
528 + new_vma = find_vma(mm, ret);
529 + if (!new_vma->vm_prfile)
530 + new_vma->vm_prfile = prfile;
531 + if (new_vma != vma)
535 + * two fput()s instead of vma_fput(vma),
536 + * coz vma may not be available anymore.
542 mmap_write_unlock(mm);
544 @@ -3332,7 +3349,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
545 if (anon_vma_clone(new_vma, vma))
546 goto out_free_mempol;
547 if (new_vma->vm_file)
548 - get_file(new_vma->vm_file);
549 + vma_get_file(new_vma);
550 if (new_vma->vm_ops && new_vma->vm_ops->open)
551 new_vma->vm_ops->open(new_vma);
552 vma_link(mm, new_vma, prev, rb_link, rb_parent);
553 diff --git a/mm/nommu.c b/mm/nommu.c
554 index 5c9ab799c0e63..dd78905704c12 100644
557 @@ -533,7 +533,7 @@ static void __put_nommu_region(struct vm_region *region)
558 up_write(&nommu_region_sem);
561 - fput(region->vm_file);
564 /* IO memory and memory shared directly out of the pagecache
565 * from ramfs/tmpfs mustn't be released here */
566 @@ -665,7 +665,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
567 if (vma->vm_ops && vma->vm_ops->close)
568 vma->vm_ops->close(vma);
570 - fput(vma->vm_file);
572 put_nommu_region(vma->vm_region);
575 @@ -1188,7 +1188,7 @@ unsigned long do_mmap(struct file *file,
576 goto error_just_free;
579 - fput(region->vm_file);
581 kmem_cache_free(vm_region_jar, region);
584 @@ -1265,10 +1265,10 @@ unsigned long do_mmap(struct file *file,
585 up_write(&nommu_region_sem);
588 - fput(region->vm_file);
590 kmem_cache_free(vm_region_jar, region);
592 - fput(vma->vm_file);
597 diff --git a/mm/prfile.c b/mm/prfile.c
599 index 0000000000000..00d51187c3250
603 +// SPDX-License-Identifier: GPL-2.0
605 + * Mainly for aufs which mmap(2) different file and wants to print different
606 + * path in /proc/PID/maps.
607 + * Call these functions via macros defined in linux/mm.h.
609 + * See Documentation/filesystems/aufs/design/06mmap.txt
611 + * Copyright (c) 2014-2020 Junjro R. Okajima
612 + * Copyright (c) 2014 Ian Campbell
615 +#include <linux/mm.h>
616 +#include <linux/file.h>
617 +#include <linux/fs.h>
619 +/* #define PRFILE_TRACE */
620 +static inline void prfile_trace(struct file *f, struct file *pr,
621 + const char func[], int line, const char func2[])
625 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
629 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
632 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
635 + file_update_time(f);
637 + file_update_time(pr);
640 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
643 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
645 + prfile_trace(f, pr, func, line, __func__);
646 + return (f && pr) ? pr : f;
649 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
651 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
653 + prfile_trace(f, pr, func, line, __func__);
659 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
661 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
663 + prfile_trace(f, pr, func, line, __func__);
670 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
673 + struct file *f = region->vm_file, *pr = region->vm_prfile;
675 + prfile_trace(f, pr, func, line, __func__);
676 + return (f && pr) ? pr : f;
679 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
681 + struct file *f = region->vm_file, *pr = region->vm_prfile;
683 + prfile_trace(f, pr, func, line, __func__);
688 +#endif /* !CONFIG_MMU */
689 SPDX-License-Identifier: GPL-2.0
690 aufs5.12 standalone patch
692 diff --git a/fs/dcache.c b/fs/dcache.c
693 index 3caa7ab4b84f1..00e97c9ae7c45 100644
696 @@ -1423,6 +1423,7 @@ void d_walk(struct dentry *parent, void *data,
700 +EXPORT_SYMBOL_GPL(d_walk);
703 struct vfsmount *mnt;
704 @@ -2968,6 +2969,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
706 write_sequnlock(&rename_lock);
708 +EXPORT_SYMBOL_GPL(d_exchange);
711 * d_ancestor - search for an ancestor
712 diff --git a/fs/exec.c b/fs/exec.c
713 index 18594f11c31fe..ac38c0424d2a3 100644
716 @@ -114,6 +114,7 @@ bool path_noexec(const struct path *path)
717 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
718 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
720 +EXPORT_SYMBOL_GPL(path_noexec);
724 diff --git a/fs/fcntl.c b/fs/fcntl.c
725 index d8a12eb63961d..0532996186311 100644
728 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
732 +EXPORT_SYMBOL_GPL(setfl);
734 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
736 diff --git a/fs/file_table.c b/fs/file_table.c
737 index 45437f8e1003e..786af52904fcf 100644
738 --- a/fs/file_table.c
739 +++ b/fs/file_table.c
740 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
742 return ERR_PTR(-ENFILE);
744 +EXPORT_SYMBOL_GPL(alloc_empty_file);
747 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
748 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
752 +EXPORT_SYMBOL_GPL(__fput_sync);
754 void __init files_init(void)
756 diff --git a/fs/inode.c b/fs/inode.c
757 index ba1df0895b69f..0672530acf7dd 100644
760 @@ -1778,6 +1778,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
761 return inode->i_op->update_time(inode, time, flags);
762 return generic_update_time(inode, time, flags);
764 +EXPORT_SYMBOL_GPL(update_time);
767 * atime_needs_update - update the access time
768 diff --git a/fs/namespace.c b/fs/namespace.c
769 index 540679d7e0434..74957d5edaa86 100644
772 @@ -438,6 +438,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
773 mnt_dec_writers(real_mount(mnt));
776 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
779 * mnt_drop_write - give up write access to a mount
780 @@ -812,6 +813,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
782 return check_mnt(real_mount(mnt));
784 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
787 * vfsmount lock must be held for write
788 @@ -1985,6 +1987,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
792 +EXPORT_SYMBOL_GPL(iterate_mounts);
794 static void lock_mnt_tree(struct mount *mnt)
796 diff --git a/fs/notify/group.c b/fs/notify/group.c
797 index ffd723ffe46de..ec6172836b6f6 100644
798 --- a/fs/notify/group.c
799 +++ b/fs/notify/group.c
800 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
802 refcount_inc(&group->refcnt);
804 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
807 * Drop a reference to a group. Free it if it's through.
808 diff --git a/fs/open.c b/fs/open.c
809 index e53af13b5835f..f37da065e6544 100644
812 @@ -65,6 +65,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
813 inode_unlock(dentry->d_inode);
816 +EXPORT_SYMBOL_GPL(do_truncate);
818 long vfs_truncate(const struct path *path, loff_t length)
820 diff --git a/fs/read_write.c b/fs/read_write.c
821 index 9db7adf160d20..8dc93a57a933f 100644
822 --- a/fs/read_write.c
823 +++ b/fs/read_write.c
824 @@ -503,6 +503,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
828 +EXPORT_SYMBOL_GPL(vfs_read);
830 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
832 @@ -613,6 +614,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
833 file_end_write(file);
836 +EXPORT_SYMBOL_GPL(vfs_write);
838 /* file_ppos returns &file->f_pos or NULL if file is stream */
839 static inline loff_t *file_ppos(struct file *file)
840 diff --git a/fs/splice.c b/fs/splice.c
841 index 3e6ba363b7775..7c1be373eb7cd 100644
844 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
845 return warn_unsupported(out, "write");
846 return out->f_op->splice_write(pipe, out, ppos, len, flags);
848 +EXPORT_SYMBOL_GPL(do_splice_from);
851 * Attempt to initiate a splice from a file to a pipe.
852 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
853 return warn_unsupported(in, "read");
854 return in->f_op->splice_read(in, ppos, pipe, len, flags);
856 +EXPORT_SYMBOL_GPL(do_splice_to);
859 * splice_direct_to_actor - splices data directly between two non-pipes
860 diff --git a/fs/sync.c b/fs/sync.c
861 index b7b5a0a0df6ff..fa5c7fba7f1ba 100644
864 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
865 sb->s_op->sync_fs(sb, wait);
866 return __sync_blockdev(sb->s_bdev, wait);
868 +EXPORT_SYMBOL_GPL(__sync_filesystem);
871 * Write out and wait upon all dirty data associated with this
872 diff --git a/fs/xattr.c b/fs/xattr.c
873 index b3444e06cded4..7b0f851b63d75 100644
876 @@ -383,6 +383,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
877 *xattr_value = value;
880 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
883 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
884 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
885 index fe71c2737eb9e..185531f89239a 100644
886 --- a/kernel/locking/lockdep.c
887 +++ b/kernel/locking/lockdep.c
888 @@ -209,6 +209,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
890 return lock_classes + class_idx;
892 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
893 #define hlock_class(hlock) lockdep_hlock_class(hlock)
895 #ifdef CONFIG_LOCK_STAT
896 diff --git a/kernel/task_work.c b/kernel/task_work.c
897 index 9cde961875c0a..ac8c79dc81813 100644
898 --- a/kernel/task_work.c
899 +++ b/kernel/task_work.c
900 @@ -143,3 +143,4 @@ void task_work_run(void)
904 +EXPORT_SYMBOL_GPL(task_work_run);
905 diff --git a/security/security.c b/security/security.c
906 index 5ac96b16f8fab..46d334d6ac1f6 100644
907 --- a/security/security.c
908 +++ b/security/security.c
909 @@ -1102,6 +1102,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
911 return call_int_hook(path_rmdir, 0, dir, dentry);
913 +EXPORT_SYMBOL_GPL(security_path_rmdir);
915 int security_path_unlink(const struct path *dir, struct dentry *dentry)
917 @@ -1118,6 +1119,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
919 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
921 +EXPORT_SYMBOL_GPL(security_path_symlink);
923 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
924 struct dentry *new_dentry)
925 @@ -1126,6 +1128,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
927 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
929 +EXPORT_SYMBOL_GPL(security_path_link);
931 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
932 const struct path *new_dir, struct dentry *new_dentry,
933 @@ -1153,6 +1156,7 @@ int security_path_truncate(const struct path *path)
935 return call_int_hook(path_truncate, 0, path);
937 +EXPORT_SYMBOL_GPL(security_path_truncate);
939 int security_path_chmod(const struct path *path, umode_t mode)
941 @@ -1160,6 +1164,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
943 return call_int_hook(path_chmod, 0, path, mode);
945 +EXPORT_SYMBOL_GPL(security_path_chmod);
947 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
949 @@ -1167,6 +1172,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
951 return call_int_hook(path_chown, 0, path, uid, gid);
953 +EXPORT_SYMBOL_GPL(security_path_chown);
955 int security_path_chroot(const struct path *path)
957 @@ -1267,6 +1273,7 @@ int security_inode_permission(struct inode *inode, int mask)
959 return call_int_hook(inode_permission, 0, inode, mask);
961 +EXPORT_SYMBOL_GPL(security_inode_permission);
963 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
965 @@ -1464,6 +1471,7 @@ int security_file_permission(struct file *file, int mask)
967 return fsnotify_perm(file, mask);
969 +EXPORT_SYMBOL_GPL(security_file_permission);
971 int security_file_alloc(struct file *file)
973 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
974 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
975 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-05-02 20:15:14.666670785 +0200
977 +What: /debug/aufs/si_<id>/
979 +Contact: J. R. Okajima <hooanon05g@gmail.com>
981 + Under /debug/aufs, a directory named si_<id> is created
982 + per aufs mount, where <id> is a unique id generated
985 +What: /debug/aufs/si_<id>/plink
987 +Contact: J. R. Okajima <hooanon05g@gmail.com>
989 + It has three lines and shows the information about the
990 + pseudo-link. The first line is a single number
991 + representing a number of buckets. The second line is a
992 + number of pseudo-links per buckets (separated by a
993 + blank). The last line is a single number representing a
994 + total number of psedo-links.
995 + When the aufs mount option 'noplink' is specified, it
996 + will show "1\n0\n0\n".
998 +What: /debug/aufs/si_<id>/xib
1000 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1002 + It shows the consumed blocks by xib (External Inode Number
1003 + Bitmap), its block size and file size.
1004 + When the aufs mount option 'noxino' is specified, it
1005 + will be empty. About XINO files, see the aufs manual.
1007 +What: /debug/aufs/si_<id>/xi<branch-index>
1009 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1011 + It shows the consumed blocks by xino (External Inode Number
1012 + Translation Table), its link count, block size and file
1014 + Due to the file size limit, there may exist multiple
1015 + xino files per branch. In this case, "-N" is added to
1016 + the filename and it corresponds to the index of the
1017 + internal xino array. "-0" is omitted.
1018 + When the aufs mount option 'noxino' is specified, Those
1019 + entries won't exist. About XINO files, see the aufs
1022 +What: /debug/aufs/si_<id>/xigen
1024 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1026 + It shows the consumed blocks by xigen (External Inode
1027 + Generation Table), its block size and file size.
1028 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1030 + When the aufs mount option 'noxino' is specified, it
1031 + will be empty. About XINO files, see the aufs manual.
1032 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1033 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1034 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-05-02 20:15:14.666670785 +0200
1036 +What: /sys/fs/aufs/si_<id>/
1038 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1040 + Under /sys/fs/aufs, a directory named si_<id> is created
1041 + per aufs mount, where <id> is a unique id generated
1044 +What: /sys/fs/aufs/si_<id>/br<idx>
1046 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1048 + It shows the abolute path of a member directory (which
1049 + is called branch) in aufs, and its permission.
1051 +What: /sys/fs/aufs/si_<id>/brid<idx>
1053 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1055 + It shows the id of a member directory (which is called
1058 +What: /sys/fs/aufs/si_<id>/xi_path
1060 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1062 + It shows the abolute path of XINO (External Inode Number
1063 + Bitmap, Translation Table and Generation Table) file
1064 + even if it is the default path.
1065 + When the aufs mount option 'noxino' is specified, it
1066 + will be empty. About XINO files, see the aufs manual.
1067 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1068 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1069 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-05-02 20:15:14.666670785 +0200
1072 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1074 +# This program is free software; you can redistribute it and/or modify
1075 +# it under the terms of the GNU General Public License as published by
1076 +# the Free Software Foundation; either version 2 of the License, or
1077 +# (at your option) any later version.
1079 +# This program is distributed in the hope that it will be useful,
1080 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1081 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1082 +# GNU General Public License for more details.
1084 +# You should have received a copy of the GNU General Public License
1085 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1088 +----------------------------------------
1090 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1091 +1. abbrev. for "advanced multi-layered unification filesystem".
1092 +2. abbrev. for "another unionfs".
1093 +3. abbrev. for "auf das" in German which means "on the" in English.
1094 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1095 + But "Filesystem aufs Filesystem" is hard to understand.
1096 +4. abbrev. for "African Urban Fashion Show".
1098 +AUFS is a filesystem with features:
1099 +- multi layered stackable unification filesystem, the member directory
1100 + is called as a branch.
1101 +- branch permission and attribute, 'readonly', 'real-readonly',
1102 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1104 +- internal "file copy-on-write".
1105 +- logical deletion, whiteout.
1106 +- dynamic branch manipulation, adding, deleting and changing permission.
1107 +- allow bypassing aufs, user's direct branch access.
1108 +- external inode number translation table and bitmap which maintains the
1109 + persistent aufs inode number.
1110 +- seekable directory, including NFS readdir.
1111 +- file mapping, mmap and sharing pages.
1112 +- pseudo-link, hardlink over branches.
1113 +- loopback mounted filesystem as a branch.
1114 +- several policies to select one among multiple writable branches.
1115 +- revert a single systemcall when an error occurs in aufs.
1119 +Multi Layered Stackable Unification Filesystem
1120 +----------------------------------------------------------------------
1121 +Most people already knows what it is.
1122 +It is a filesystem which unifies several directories and provides a
1123 +merged single directory. When users access a file, the access will be
1124 +passed/re-directed/converted (sorry, I am not sure which English word is
1125 +correct) to the real file on the member filesystem. The member
1126 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1127 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1128 +readonly branch is handled by creating 'whiteout' on the upper writable
1131 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1132 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1133 +different approaches to implement the merged-view.
1134 +The former tries putting it into VFS, and the latter implements as a
1135 +separate filesystem.
1136 +(If I misunderstand about these implementations, please let me know and
1137 +I shall correct it. Because it is a long time ago when I read their
1138 +source files last time).
1140 +UnionMount's approach will be able to small, but may be hard to share
1141 +branches between several UnionMount since the whiteout in it is
1142 +implemented in the inode on branch filesystem and always
1143 +shared. According to Bharata's post, readdir does not seems to be
1145 +There are several missing features known in this implementations such as
1146 +- for users, the inode number may change silently. eg. copy-up.
1147 +- link(2) may break by copy-up.
1148 +- read(2) may get an obsoleted filedata (fstat(2) too).
1149 +- fcntl(F_SETLK) may be broken by copy-up.
1150 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1153 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1154 +merged into mainline. This is another implementation of UnionMount as a
1155 +separated filesystem. All the limitations and known problems which
1156 +UnionMount are equally inherited to "overlay" filesystem.
1158 +Unionfs has a longer history. When I started implementing a stackable
1159 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1160 +inode, dentry and file objects and they have an array pointing lower
1161 +same kind objects. After contributing many patches for Unionfs, I
1162 +re-started my project AUFS (Jun 2006).
1164 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1165 +implemented my own ideas, approaches and enhancements and it became
1166 +totally different one.
1168 +Comparing DM snapshot and fs based implementation
1169 +- the number of bytes to be copied between devices is much smaller.
1170 +- the type of filesystem must be one and only.
1171 +- the fs must be writable, no readonly fs, even for the lower original
1172 + device. so the compression fs will not be usable. but if we use
1173 + loopback mount, we may address this issue.
1175 + mount /cdrom/squashfs.img /sq
1176 + losetup /sq/ext2.img
1177 + losetup /somewhere/cow
1178 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1179 +- it will be difficult (or needs more operations) to extract the
1180 + difference between the original device and COW.
1181 +- DM snapshot-merge may help a lot when users try merging. in the
1182 + fs-layer union, users will use rsync(1).
1184 +You may want to read my old paper "Filesystems in LiveCD"
1185 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1188 +Several characters/aspects/persona of aufs
1189 +----------------------------------------------------------------------
1191 +Aufs has several characters, aspects or persona.
1192 +1. a filesystem, callee of VFS helper
1193 +2. sub-VFS, caller of VFS helper for branches
1194 +3. a virtual filesystem which maintains persistent inode number
1195 +4. reader/writer of files on branches such like an application
1197 +1. Callee of VFS Helper
1198 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1199 +unlink(2) from an application reaches sys_unlink() kernel function and
1200 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1201 +calls filesystem specific unlink operation. Actually aufs implements the
1202 +unlink operation but it behaves like a redirector.
1204 +2. Caller of VFS Helper for Branches
1205 +aufs_unlink() passes the unlink request to the branch filesystem as if
1206 +it were called from VFS. So the called unlink operation of the branch
1207 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1208 +every necessary pre/post operation for the branch filesystem.
1209 +- acquire the lock for the parent dir on a branch
1210 +- lookup in a branch
1211 +- revalidate dentry on a branch
1212 +- mnt_want_write() for a branch
1213 +- vfs_unlink() for a branch
1214 +- mnt_drop_write() for a branch
1215 +- release the lock on a branch
1217 +3. Persistent Inode Number
1218 +One of the most important issue for a filesystem is to maintain inode
1219 +numbers. This is particularly important to support exporting a
1220 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1221 +backend block device for its own. But some storage is necessary to
1222 +keep and maintain the inode numbers. It may be a large space and may not
1223 +suit to keep in memory. Aufs rents some space from its first writable
1224 +branch filesystem (by default) and creates file(s) on it. These files
1225 +are created by aufs internally and removed soon (currently) keeping
1227 +Note: Because these files are removed, they are totally gone after
1228 + unmounting aufs. It means the inode numbers are not persistent
1229 + across unmount or reboot. I have a plan to make them really
1230 + persistent which will be important for aufs on NFS server.
1232 +4. Read/Write Files Internally (copy-on-write)
1233 +Because a branch can be readonly, when you write a file on it, aufs will
1234 +"copy-up" it to the upper writable branch internally. And then write the
1235 +originally requested thing to the file. Generally kernel doesn't
1236 +open/read/write file actively. In aufs, even a single write may cause a
1237 +internal "file copy". This behaviour is very similar to cp(1) command.
1239 +Some people may think it is better to pass such work to user space
1240 +helper, instead of doing in kernel space. Actually I am still thinking
1241 +about it. But currently I have implemented it in kernel space.
1242 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1243 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1244 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-05-02 20:15:14.666670785 +0200
1247 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1249 +# This program is free software; you can redistribute it and/or modify
1250 +# it under the terms of the GNU General Public License as published by
1251 +# the Free Software Foundation; either version 2 of the License, or
1252 +# (at your option) any later version.
1254 +# This program is distributed in the hope that it will be useful,
1255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1257 +# GNU General Public License for more details.
1259 +# You should have received a copy of the GNU General Public License
1260 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1262 +Basic Aufs Internal Structure
1264 +Superblock/Inode/Dentry/File Objects
1265 +----------------------------------------------------------------------
1266 +As like an ordinary filesystem, aufs has its own
1267 +superblock/inode/dentry/file objects. All these objects have a
1268 +dynamically allocated array and store the same kind of pointers to the
1269 +lower filesystem, branch.
1270 +For example, when you build a union with one readwrite branch and one
1271 +readonly, mounted /au, /rw and /ro respectively.
1273 +- /ro/fileA exists but /rw/fileA
1275 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1276 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1277 +- [0] = NULL (because /rw/fileA doesn't exist)
1280 +This style of an array is essentially same to the aufs
1281 +superblock/inode/dentry/file objects.
1283 +Because aufs supports manipulating branches, ie. add/delete/change
1284 +branches dynamically, these objects has its own generation. When
1285 +branches are changed, the generation in aufs superblock is
1286 +incremented. And a generation in other object are compared when it is
1287 +accessed. When a generation in other objects are obsoleted, aufs
1288 +refreshes the internal array.
1292 +----------------------------------------------------------------------
1293 +Additionally aufs superblock has some data for policies to select one
1294 +among multiple writable branches, XIB files, pseudo-links and kobject.
1295 +See below in detail.
1296 +About the policies which supports copy-down a directory, see
1297 +wbr_policy.txt too.
1300 +Branch and XINO(External Inode Number Translation Table)
1301 +----------------------------------------------------------------------
1302 +Every branch has its own xino (external inode number translation table)
1303 +file. The xino file is created and unlinked by aufs internally. When two
1304 +members of a union exist on the same filesystem, they share the single
1306 +The struct of a xino file is simple, just a sequence of aufs inode
1307 +numbers which is indexed by the lower inode number.
1308 +In the above sample, assume the inode number of /ro/fileA is i111 and
1309 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1310 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1312 +When the inode numbers are not contiguous, the xino file will be sparse
1313 +which has a hole in it and doesn't consume as much disk space as it
1314 +might appear. If your branch filesystem consumes disk space for such
1315 +holes, then you should specify 'xino=' option at mounting aufs.
1317 +Aufs has a mount option to free the disk blocks for such holes in XINO
1318 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1319 +meet a problem of disk shortage due to XINO files, then you should try
1320 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1321 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1322 +the holes in XINO files.
1324 +Also a writable branch has three kinds of "whiteout bases". All these
1325 +are existed when the branch is joined to aufs, and their names are
1326 +whiteout-ed doubly, so that users will never see their names in aufs
1328 +1. a regular file which will be hardlinked to all whiteouts.
1329 +2. a directory to store a pseudo-link.
1330 +3. a directory to store an "orphan"-ed file temporary.
1333 + When you remove a file on a readonly branch, aufs handles it as a
1334 + logical deletion and creates a whiteout on the upper writable branch
1335 + as a hardlink of this file in order not to consume inode on the
1338 + See below, Pseudo-link.
1340 + When "fileC" exists on the lower readonly branch only and it is
1341 + opened and removed with its parent dir, and then user writes
1342 + something into it, then aufs copies-up fileC to this
1343 + directory. Because there is no other dir to store fileC. After
1344 + creating a file under this dir, the file is unlinked.
1346 +Because aufs supports manipulating branches, ie. add/delete/change
1347 +dynamically, a branch has its own id. When the branch order changes,
1348 +aufs finds the new index by searching the branch id.
1352 +----------------------------------------------------------------------
1353 +Assume "fileA" exists on the lower readonly branch only and it is
1354 +hardlinked to "fileB" on the branch. When you write something to fileA,
1355 +aufs copies-up it to the upper writable branch. Additionally aufs
1356 +creates a hardlink under the Pseudo-link Directory of the writable
1357 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1358 +simple list. If fileB is read after unlinking fileA, aufs returns
1359 +filedata from the pseudo-link instead of the lower readonly
1360 +branch. Because the pseudo-link is based upon the inode, to keep the
1361 +inode number by xino (see above) is essentially necessary.
1363 +All the hardlinks under the Pseudo-link Directory of the writable branch
1364 +should be restored in a proper location later. Aufs provides a utility
1365 +to do this. The userspace helpers executed at remounting and unmounting
1367 +During this utility is running, it puts aufs into the pseudo-link
1368 +maintenance mode. In this mode, only the process which began the
1369 +maintenance mode (and its child processes) is allowed to operate in
1370 +aufs. Some other processes which are not related to the pseudo-link will
1371 +be allowed to run too, but the rest have to return an error or wait
1372 +until the maintenance mode ends. If a process already acquires an inode
1373 +mutex (in VFS), it has to return an error.
1376 +XIB(external inode number bitmap)
1377 +----------------------------------------------------------------------
1378 +Addition to the xino file per a branch, aufs has an external inode number
1379 +bitmap in a superblock object. It is also an internal file such like a
1381 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1383 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1385 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1386 +reduce the number of consumed disk blocks for these files.
1389 +Virtual or Vertical Dir, and Readdir in Userspace
1390 +----------------------------------------------------------------------
1391 +In order to support multiple layers (branches), aufs readdir operation
1392 +constructs a virtual dir block on memory. For readdir, aufs calls
1393 +vfs_readdir() internally for each dir on branches, merges their entries
1394 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1395 +object. So the file object has its entry list until it is closed. The
1396 +entry list will be updated when the file position is zero and becomes
1397 +obsoleted. This decision is made in aufs automatically.
1399 +The dynamically allocated memory block for the name of entries has a
1400 +unit of 512 bytes (by default) and stores the names contiguously (no
1401 +padding). Another block for each entry is handled by kmem_cache too.
1402 +During building dir blocks, aufs creates hash list and judging whether
1403 +the entry is whiteouted by its upper branch or already listed.
1404 +The merged result is cached in the corresponding inode object and
1405 +maintained by a customizable life-time option.
1407 +Some people may call it can be a security hole or invite DoS attack
1408 +since the opened and once readdir-ed dir (file object) holds its entry
1409 +list and becomes a pressure for system memory. But I'd say it is similar
1410 +to files under /proc or /sys. The virtual files in them also holds a
1411 +memory page (generally) while they are opened. When an idea to reduce
1412 +memory for them is introduced, it will be applied to aufs too.
1413 +For those who really hate this situation, I've developed readdir(3)
1414 +library which operates this merging in userspace. You just need to set
1415 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1416 +kernel space for readdir(3).
1420 +----------------------------------------------------------------------
1421 +Aufs sometimes requires privilege access to a branch. For instance,
1422 +in copy-up/down operation. When a user process is going to make changes
1423 +to a file which exists in the lower readonly branch only, and the mode
1424 +of one of ancestor directories may not be writable by a user
1425 +process. Here aufs copy-up the file with its ancestors and they may
1426 +require privilege to set its owner/group/mode/etc.
1427 +This is a typical case of a application character of aufs (see
1430 +Aufs uses workqueue synchronously for this case. It creates its own
1431 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1432 +passes the request to call mkdir or write (for example), and wait for
1433 +its completion. This approach solves a problem of a signal handler
1435 +If aufs didn't adopt the workqueue and changed the privilege of the
1436 +process, then the process may receive the unexpected SIGXFSZ or other
1439 +Also aufs uses the system global workqueue ("events" kernel thread) too
1440 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1441 +whiteout base and etc. This is unrelated to a privilege.
1442 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1443 +superblock at the beginning, at the same time waits for the completion
1444 +of all queued asynchronous tasks.
1448 +----------------------------------------------------------------------
1449 +The whiteout in aufs is very similar to Unionfs's. That is represented
1450 +by its filename. UnionMount takes an approach of a file mode, but I am
1451 +afraid several utilities (find(1) or something) will have to support it.
1453 +Basically the whiteout represents "logical deletion" which stops aufs to
1454 +lookup further, but also it represents "dir is opaque" which also stop
1457 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1458 +In order to make several functions in a single systemcall to be
1459 +revertible, aufs adopts an approach to rename a directory to a temporary
1460 +unique whiteouted name.
1461 +For example, in rename(2) dir where the target dir already existed, aufs
1462 +renames the target dir to a temporary unique whiteouted name before the
1463 +actual rename on a branch, and then handles other actions (make it opaque,
1464 +update the attributes, etc). If an error happens in these actions, aufs
1465 +simply renames the whiteouted name back and returns an error. If all are
1466 +succeeded, aufs registers a function to remove the whiteouted unique
1467 +temporary name completely and asynchronously to the system global
1472 +----------------------------------------------------------------------
1473 +It is a well-known feature or concept.
1474 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1475 +internally and makes change to the new file on the upper writable branch.
1476 +When the trigger systemcall does not update the timestamps of the parent
1477 +dir, aufs reverts it after copy-up.
1480 +Move-down (aufs3.9 and later)
1481 +----------------------------------------------------------------------
1482 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1483 +the lower readonly branch to the upper writable branch when a user
1484 +changes something about the file.
1485 +"Move-down" is an opposite action of copy-up. Basically this action is
1486 +ran manually instead of automatically and internally.
1487 +For desgin and implementation, aufs has to consider these issues.
1488 +- whiteout for the file may exist on the lower branch.
1489 +- ancestor directories may not exist on the lower branch.
1490 +- diropq for the ancestor directories may exist on the upper branch.
1491 +- free space on the lower branch will reduce.
1492 +- another access to the file may happen during moving-down, including
1493 + UDBA (see "Revalidate Dentry and UDBA").
1494 +- the file should not be hard-linked nor pseudo-linked. they should be
1495 + handled by auplink utility later.
1497 +Sometimes users want to move-down a file from the upper writable branch
1498 +to the lower readonly or writable branch. For instance,
1499 +- the free space of the upper writable branch is going to run out.
1500 +- create a new intermediate branch between the upper and lower branch.
1503 +For this purpose, use "aumvdown" command in aufs-util.git.
1504 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1505 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1506 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-05-02 20:15:14.666670785 +0200
1509 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1511 +# This program is free software; you can redistribute it and/or modify
1512 +# it under the terms of the GNU General Public License as published by
1513 +# the Free Software Foundation; either version 2 of the License, or
1514 +# (at your option) any later version.
1516 +# This program is distributed in the hope that it will be useful,
1517 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1518 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1519 +# GNU General Public License for more details.
1521 +# You should have received a copy of the GNU General Public License
1522 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1524 +Support for a branch who has its ->atomic_open()
1525 +----------------------------------------------------------------------
1526 +The filesystems who implement its ->atomic_open() are not majority. For
1527 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1528 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1529 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1530 +sure whether all filesystems who have ->atomic_open() behave like this,
1531 +but NFSv4 surely returns the error.
1533 +In order to support ->atomic_open() for aufs, there are a few
1536 +A. Introduce aufs_atomic_open()
1537 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1539 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1540 + an aufs user Pip Cet's approach
1541 + - calls aufs_create(), VFS finish_open() and notify_change().
1542 + - pass fake-mode to finish_open(), and then correct the mode by
1544 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1545 + - no aufs_atomic_open().
1546 + - aufs_lookup() registers the TID to an aufs internal object.
1547 + - aufs_create() does nothing when the matching TID is registered, but
1548 + registers the mode.
1549 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1550 + TID is registered.
1551 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1553 + - no aufs_atomic_open().
1554 + - aufs_create() registers the TID to an internal object. this info
1555 + represents "this process created this file just now."
1556 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1557 + registered TID and re-try open() with superuser's credential.
1559 +Pros and cons for each approach.
1562 + - straightforward but highly depends upon VFS internal.
1563 + - the atomic behavaiour is kept.
1564 + - some of parameters such as nameidata are hard to reproduce for
1568 + - easy to implement.
1569 + - the atomic behavaiour is lost.
1571 + - the atomic behavaiour is kept.
1572 + - dirty and tricky.
1573 + - VFS checks whether the file is created correctly after calling
1574 + ->create(), which means this approach doesn't work.
1576 + - easy to implement.
1577 + - the atomic behavaiour is lost.
1578 + - to open a file with superuser's credential and give it to a user
1579 + process is a bad idea, since the file object keeps the credential
1580 + in it. It may affect LSM or something. This approach doesn't work
1583 +The approach A is ideal, but it hard to implement. So here is a
1584 +variation of A, which is to be implemented.
1586 +A-1. Introduce aufs_atomic_open()
1587 + - calls branch fs ->atomic_open() if exists. otherwise calls
1588 + vfs_create() and finish_open().
1589 + - the demerit is that the several checks after branch fs
1590 + ->atomic_open() are lost. in the ordinary case, the checks are
1591 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1592 + be implemented in aufs, but not all I am afraid.
1593 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1594 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1595 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-05-02 20:15:14.666670785 +0200
1598 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1600 +# This program is free software; you can redistribute it and/or modify
1601 +# it under the terms of the GNU General Public License as published by
1602 +# the Free Software Foundation; either version 2 of the License, or
1603 +# (at your option) any later version.
1605 +# This program is distributed in the hope that it will be useful,
1606 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1607 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1608 +# GNU General Public License for more details.
1610 +# You should have received a copy of the GNU General Public License
1611 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1614 +----------------------------------------------------------------------
1615 +Since aufs has a character of sub-VFS (see Introduction), it operates
1616 +lookup for branches as VFS does. It may be a heavy work. But almost all
1617 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1618 +directly connected to its parent. Digging down the directory hierarchy
1619 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1622 +When a branch is a remote filesystem, aufs basically relies upon its
1623 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1625 +For d_revalidate, aufs implements three levels of revalidate tests. See
1626 +"Revalidate Dentry and UDBA" in detail.
1629 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1630 +----------------------------------------------------------------------
1631 +Let's try case study.
1632 +- aufs has two branches, upper readwrite and lower readonly.
1634 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1635 +- user invoked "chmod a+rx /au/dirA"
1636 +- the internal copy-up is activated and "/rw/dirA" is created and its
1637 + permission bits are set to world readable.
1638 +- then "/au/dirA" becomes world readable?
1640 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1641 +or it may be a natively readonly filesystem. If aufs respects the lower
1642 +branch, it should not respond readdir request from other users. But user
1643 +allowed it by chmod. Should really aufs rejects showing the entries
1646 +To be honest, I don't have a good solution for this case. So aufs
1647 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1649 +When dirperm1 is specified, aufs checks only the highest one for the
1650 +directory permission, and shows the entries. Otherwise, as usual, checks
1651 +every dir existing on all branches and rejects the request.
1653 +As a side effect, dirperm1 option improves the performance of aufs
1654 +because the number of permission check is reduced when the number of
1658 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1659 +----------------------------------------------------------------------
1660 +Generally VFS helpers re-validate a dentry as a part of lookup.
1661 +0. digging down the directory hierarchy.
1662 +1. lock the parent dir by its i_mutex.
1663 +2. lookup the final (child) entry.
1665 +4. call the actual operation (create, unlink, etc.)
1666 +5. unlock the parent dir
1668 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1669 +called. Actually aufs implements it and checks the dentry on a branch is
1671 +But it is not enough. Because aufs has to release the lock for the
1672 +parent dir on a branch at the end of ->lookup() (step 2) and
1673 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1675 +If the file on a branch is changed directly, eg. bypassing aufs, after
1676 +aufs released the lock, then the subsequent operation may cause
1677 +something unpleasant result.
1679 +This situation is a result of VFS architecture, ->lookup() and
1680 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1681 +design from VFS's point of view. It is just not suitable for sub-VFS
1684 +Aufs supports such case by three level of revalidation which is
1685 +selectable by user.
1686 +1. Simple Revalidate
1687 + Addition to the native flow in VFS's, confirm the child-parent
1688 + relationship on the branch just after locking the parent dir on the
1689 + branch in the "actual operation" (step 4). When this validation
1690 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1691 + checks the validation of the dentry on branches.
1692 +2. Monitor Changes Internally by Inotify/Fsnotify
1693 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1694 + the dentry on the branch, and returns EBUSY if it finds different
1696 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1697 + during it is in cache. When the event is notified, aufs registers a
1698 + function to kernel 'events' thread by schedule_work(). And the
1699 + function sets some special status to the cached aufs dentry and inode
1700 + private data. If they are not cached, then aufs has nothing to
1701 + do. When the same file is accessed through aufs (step 0-3) later,
1702 + aufs will detect the status and refresh all necessary data.
1703 + In this mode, aufs has to ignore the event which is fired by aufs
1705 +3. No Extra Validation
1706 + This is the simplest test and doesn't add any additional revalidation
1707 + test, and skip the revalidation in step 4. It is useful and improves
1708 + aufs performance when system surely hide the aufs branches from user,
1709 + by over-mounting something (or another method).
1710 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1711 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1712 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-05-02 20:15:14.670004120 +0200
1715 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1717 +# This program is free software; you can redistribute it and/or modify
1718 +# it under the terms of the GNU General Public License as published by
1719 +# the Free Software Foundation; either version 2 of the License, or
1720 +# (at your option) any later version.
1722 +# This program is distributed in the hope that it will be useful,
1723 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1724 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1725 +# GNU General Public License for more details.
1727 +# You should have received a copy of the GNU General Public License
1728 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1730 +Branch Manipulation
1732 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1733 +and changing its permission/attribute, there are a lot of works to do.
1737 +----------------------------------------------------------------------
1738 +o Confirm the adding dir exists outside of aufs, including loopback
1739 + mount, and its various attributes.
1740 +o Initialize the xino file and whiteout bases if necessary.
1743 +o Check the owner/group/mode of the directory
1744 + When the owner/group/mode of the adding directory differs from the
1745 + existing branch, aufs issues a warning because it may impose a
1747 + For example, when a upper writable branch has a world writable empty
1748 + top directory, a malicious user can create any files on the writable
1749 + branch directly, like copy-up and modify manually. If something like
1750 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1751 + writable branch, and the writable branch is world-writable, then a
1752 + malicious guy may create /etc/passwd on the writable branch directly
1753 + and the infected file will be valid in aufs.
1754 + I am afraid it can be a security issue, but aufs can do nothing except
1755 + producing a warning.
1759 +----------------------------------------------------------------------
1760 +o Confirm the deleting branch is not busy
1761 + To be general, there is one merit to adopt "remount" interface to
1762 + manipulate branches. It is to discard caches. At deleting a branch,
1763 + aufs checks the still cached (and connected) dentries and inodes. If
1764 + there are any, then they are all in-use. An inode without its
1765 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1767 + For the cached one, aufs checks whether the same named entry exists on
1769 + If the cached one is a directory, because aufs provides a merged view
1770 + to users, as long as one dir is left on any branch aufs can show the
1771 + dir to users. In this case, the branch can be removed from aufs.
1772 + Otherwise aufs rejects deleting the branch.
1774 + If any file on the deleting branch is opened by aufs, then aufs
1778 +Modify the Permission of a Branch
1779 +----------------------------------------------------------------------
1780 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1783 +o rw --> ro: Confirm the modifying branch is not busy
1784 + Aufs rejects the request if any of these conditions are true.
1785 + - a file on the branch is mmap-ed.
1786 + - a regular file on the branch is opened for write and there is no
1787 + same named entry on the upper branch.
1788 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1789 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1790 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-05-02 20:15:14.670004120 +0200
1793 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1795 +# This program is free software; you can redistribute it and/or modify
1796 +# it under the terms of the GNU General Public License as published by
1797 +# the Free Software Foundation; either version 2 of the License, or
1798 +# (at your option) any later version.
1800 +# This program is distributed in the hope that it will be useful,
1801 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1802 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1803 +# GNU General Public License for more details.
1805 +# You should have received a copy of the GNU General Public License
1806 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1808 +Policies to Select One among Multiple Writable Branches
1809 +----------------------------------------------------------------------
1810 +When the number of writable branch is more than one, aufs has to decide
1811 +the target branch for file creation or copy-up. By default, the highest
1812 +writable branch which has the parent (or ancestor) dir of the target
1813 +file is chosen (top-down-parent policy).
1814 +By user's request, aufs implements some other policies to select the
1815 +writable branch, for file creation several policies, round-robin,
1816 +most-free-space, and other policies. For copy-up, top-down-parent,
1817 +bottom-up-parent, bottom-up and others.
1819 +As expected, the round-robin policy selects the branch in circular. When
1820 +you have two writable branches and creates 10 new files, 5 files will be
1821 +created for each branch. mkdir(2) systemcall is an exception. When you
1822 +create 10 new directories, all will be created on the same branch.
1823 +And the most-free-space policy selects the one which has most free
1824 +space among the writable branches. The amount of free space will be
1825 +checked by aufs internally, and users can specify its time interval.
1827 +The policies for copy-up is more simple,
1828 +top-down-parent is equivalent to the same named on in create policy,
1829 +bottom-up-parent selects the writable branch where the parent dir
1830 +exists and the nearest upper one from the copyup-source,
1831 +bottom-up selects the nearest upper writable branch from the
1832 +copyup-source, regardless the existence of the parent dir.
1834 +There are some rules or exceptions to apply these policies.
1835 +- If there is a readonly branch above the policy-selected branch and
1836 + the parent dir is marked as opaque (a variation of whiteout), or the
1837 + target (creating) file is whiteout-ed on the upper readonly branch,
1838 + then the result of the policy is ignored and the target file will be
1839 + created on the nearest upper writable branch than the readonly branch.
1840 +- If there is a writable branch above the policy-selected branch and
1841 + the parent dir is marked as opaque or the target file is whiteouted
1842 + on the branch, then the result of the policy is ignored and the target
1843 + file will be created on the highest one among the upper writable
1844 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1846 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1847 + They try selecting the branch where the source exists as possible
1848 + since copyup a large file will take long time. If it can't be,
1849 + ie. the branch where the source exists is readonly, then they will
1850 + follow the copyup policy.
1851 +- There is an exception for rename(2) when the target exists.
1852 + If the rename target exists, aufs compares the index of the branches
1853 + where the source and the target exists and selects the higher
1854 + one. If the selected branch is readonly, then aufs follows the
1856 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1857 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1858 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-05-02 20:15:14.670004120 +0200
1861 +// to view this graph, run dot(1) command in GRAPHVIZ.
1865 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1869 +aufs_rename -> whinfo [label="store/remove"];
1872 +inode_list [label="h_inum list in branch\ncache"];
1875 +whinode [label="h_inum list file"];
1878 +brmgmt [label="br_add/del/mod/umount"];
1880 +brmgmt -> inode_list [label="create/remove"];
1881 +brmgmt -> whinode [label="load/store"];
1883 +inode_list -> whinode [style=dashed,dir=both];
1885 +aufs_rename -> inode_list [label="add/del"];
1887 +aufs_lookup -> inode_list [label="search"];
1889 +aufs_lookup -> whinfo [label="load/remove"];
1891 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1892 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1893 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-05-02 20:15:14.670004120 +0200
1896 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1898 +# This program is free software; you can redistribute it and/or modify
1899 +# it under the terms of the GNU General Public License as published by
1900 +# the Free Software Foundation; either version 2 of the License, or
1901 +# (at your option) any later version.
1903 +# This program is distributed in the hope that it will be useful,
1904 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1905 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1906 +# GNU General Public License for more details.
1908 +# You should have received a copy of the GNU General Public License
1909 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1911 +Special handling for renaming a directory (DIRREN)
1912 +----------------------------------------------------------------------
1913 +First, let's assume we have a simple usecase.
1917 +- /ro/dirA and /ro/dirA/file exist too
1918 +- there is no dirB on both branches
1919 +- a user issues rename("dirA", "dirB")
1921 +Now, what should aufs behave against this rename(2)?
1922 +There are a few possible cases.
1925 + since dirA exists on a readonly branch which cannot be renamed.
1927 + it is possible to copy-up dirA (only the dir itself), but the child
1928 + entries ("file" in this case) should not be. it must be a bad
1929 + approach to copy-up recursively.
1930 +C. returns a success.
1931 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1932 + is a violation of aufs' policy.
1933 +D. construct an extra information which indicates that /ro/dirA should
1934 + be handled as the name of dirB.
1935 + overlayfs has a similar feature called REDIRECT.
1937 +Until now, aufs implements the case B only which returns EXDEV, and
1938 +expects the userspace application behaves like mv(1) which tries
1939 +issueing rename(2) recursively.
1941 +A new aufs feature called DIRREN is introduced which implements the case
1942 +D. There are several "extra information" added.
1944 +1. detailed info per renamed directory
1945 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1946 +2. the inode-number list of directories on a branch
1947 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1949 +The filename of "detailed info per directory" represents the lower
1950 +branch, and its format is
1951 +- a type of the branch id
1953 + + uuid (not implemented yet)
1956 +- the inode-number of the branch root dir
1958 +And it contains these info in a single regular file.
1960 +- branch's inode-number of the logically renamed dir
1961 +- the name of the before-renamed dir
1963 +The "detailed info per directory" file is created in aufs rename(2), and
1964 +loaded in any lookup.
1965 +The info is considered in lookup for the matching case only. Here
1966 +"matching" means that the root of branch (in the info filename) is same
1967 +to the current looking-up branch. After looking-up the before-renamed
1968 +name, the inode-number is compared. And the matched dentry is used.
1970 +The "inode-number list of directories" is a regular file which contains
1971 +simply the inode-numbers on the branch. The file is created or updated
1972 +in removing the branch, and loaded in adding the branch. Its lifetime is
1973 +equal to the branch.
1974 +The list is refered in lookup, and when the current target inode is
1975 +found in the list, the aufs tries loading the "detailed info per
1976 +directory" and get the changed and valid name of the dir.
1978 +Theoretically these "extra informaiton" may be able to be put into XATTR
1979 +in the dir inode. But aufs doesn't choose this way because
1980 +1. XATTR may not be supported by the branch (or its configuration)
1981 +2. XATTR may have its size limit.
1982 +3. XATTR may be less easy to convert than a regular file, when the
1983 + format of the info is changed in the future.
1984 +At the same time, I agree that the regular file approach is much slower
1985 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1988 +This DIRREN feature is enabled by aufs configuration, and is activated
1989 +by a new mount option.
1991 +For the more complicated case, there is a work with UDBA option, which
1992 +is to dected the direct access to the branches (by-passing aufs) and to
1993 +maintain the cashes in aufs. Since a single cached aufs dentry may
1994 +contains two names, before- and after-rename, the name comparision in
1995 +UDBA handler may not work correctly. In this case, the behaviour will be
1996 +equivalen to udba=reval case.
1997 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1998 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1999 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-05-02 20:15:14.670004120 +0200
2002 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2004 +# This program is free software; you can redistribute it and/or modify
2005 +# it under the terms of the GNU General Public License as published by
2006 +# the Free Software Foundation; either version 2 of the License, or
2007 +# (at your option) any later version.
2009 +# This program is distributed in the hope that it will be useful,
2010 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2011 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2012 +# GNU General Public License for more details.
2014 +# You should have received a copy of the GNU General Public License
2015 +# along with this program; if not, write to the Free Software
2016 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2019 +File-based Hierarchical Storage Management (FHSM)
2020 +----------------------------------------------------------------------
2021 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2022 +storage world. Aufs provides this feature as file-based with multiple
2023 +writable branches, based upon the principle of "Colder, the Lower".
2024 +Here the word "colder" means that the less used files, and "lower" means
2025 +that the position in the order of the stacked branches vertically.
2026 +These multiple writable branches are prioritized, ie. the topmost one
2027 +should be the fastest drive and be used heavily.
2029 +o Characters in aufs FHSM story
2030 +- aufs itself and a new branch attribute.
2031 +- a new ioctl interface to move-down and to establish a connection with
2032 + the daemon ("move-down" is a converse of "copy-up").
2033 +- userspace tool and daemon.
2035 +The userspace daemon establishes a connection with aufs and waits for
2036 +the notification. The notified information is very similar to struct
2037 +statfs containing the number of consumed blocks and inodes.
2038 +When the consumed blocks/inodes of a branch exceeds the user-specified
2039 +upper watermark, the daemon activates its move-down process until the
2040 +consumed blocks/inodes reaches the user-specified lower watermark.
2042 +The actual move-down is done by aufs based upon the request from
2043 +user-space since we need to maintain the inode number and the internal
2044 +pointer arrays in aufs.
2046 +Currently aufs FHSM handles the regular files only. Additionally they
2047 +must not be hard-linked nor pseudo-linked.
2050 +o Cowork of aufs and the user-space daemon
2051 + During the userspace daemon established the connection, aufs sends a
2052 + small notification to it whenever aufs writes something into the
2053 + writable branch. But it may cost high since aufs issues statfs(2)
2054 + internally. So user can specify a new option to cache the
2055 + info. Actually the notification is controlled by these factors.
2056 + + the specified cache time.
2057 + + classified as "force" by aufs internally.
2058 + Until the specified time expires, aufs doesn't send the info
2059 + except the forced cases. When aufs decide forcing, the info is always
2060 + notified to userspace.
2061 + For example, the number of free inodes is generally large enough and
2062 + the shortage of it happens rarely. So aufs doesn't force the
2063 + notification when creating a new file, directory and others. This is
2064 + the typical case which aufs doesn't force.
2065 + When aufs writes the actual filedata and the files consumes any of new
2066 + blocks, the aufs forces notifying.
2069 +o Interfaces in aufs
2070 +- New branch attribute.
2072 + Specifies that the branch is managed by FHSM feature. In other word,
2073 + participant in the FHSM.
2074 + When nofhsm is set to the branch, it will not be the source/target
2075 + branch of the move-down operation. This attribute is set
2076 + independently from coo and moo attributes, and if you want full
2077 + FHSM, you should specify them as well.
2078 +- New mount option.
2080 + Specifies a second to suppress many less important info to be
2083 + + AUFS_CTL_FHSM_FD
2084 + create a new file descriptor which userspace can read the notification
2085 + (a subset of struct statfs) from aufs.
2086 +- Module parameter 'brs'
2087 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2089 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2090 + When there are two or more branches with fhsm attributes,
2091 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2092 + terminates it. As a result of remounting and branch-manipulation, the
2093 + number of branches with fhsm attribute can be one. In this case,
2094 + /sbin/mount.aufs will terminate the user-space daemon.
2097 +Finally the operation is done as these steps in kernel-space.
2099 + + no one else is using the file.
2100 + + the file is not hard-linked.
2101 + + the file is not pseudo-linked.
2102 + + the file is a regular file.
2103 + + the parent dir is not opaqued.
2104 +- find the target writable branch.
2105 +- make sure the file is not whiteout-ed by the upper (than the target)
2107 +- make the parent dir on the target branch.
2108 +- mutex lock the inode on the branch.
2109 +- unlink the whiteout on the target branch (if exists).
2110 +- lookup and create the whiteout-ed temporary name on the target branch.
2111 +- copy the file as the whiteout-ed temporary name on the target branch.
2112 +- rename the whiteout-ed temporary name to the original name.
2113 +- unlink the file on the source branch.
2114 +- maintain the internal pointer array and the external inode number
2116 +- maintain the timestamps and other attributes of the parent dir and the
2119 +And of course, in every step, an error may happen. So the operation
2120 +should restore the original file state after an error happens.
2121 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2122 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2123 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-05-02 20:15:14.670004120 +0200
2126 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2128 +# This program is free software; you can redistribute it and/or modify
2129 +# it under the terms of the GNU General Public License as published by
2130 +# the Free Software Foundation; either version 2 of the License, or
2131 +# (at your option) any later version.
2133 +# This program is distributed in the hope that it will be useful,
2134 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2135 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2136 +# GNU General Public License for more details.
2138 +# You should have received a copy of the GNU General Public License
2139 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2141 +mmap(2) -- File Memory Mapping
2142 +----------------------------------------------------------------------
2143 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2144 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2146 +This approach is simple and good, but there is one problem.
2147 +Under /proc, several entries show the mmapped files by its path (with
2148 +device and inode number), and the printed path will be the path on the
2149 +branch fs's instead of virtual aufs's.
2150 +This is not a problem in most cases, but some utilities lsof(1) (and its
2151 +user) may expect the path on aufs.
2153 +To address this issue, aufs adds a new member called vm_prfile in struct
2154 +vm_area_struct (and struct vm_region). The original vm_file points to
2155 +the file on the branch fs in order to handle everything correctly as
2156 +usual. The new vm_prfile points to a virtual file in aufs, and the
2157 +show-functions in procfs refers to vm_prfile if it is set.
2158 +Also we need to maintain several other places where touching vm_file
2160 +- fork()/clone() copies vma and the reference count of vm_file is
2162 +- merging vma maintains the ref count too.
2164 +This is not a good approach. It just fakes the printed path. But it
2165 +leaves all behaviour around f_mapping unchanged. This is surely an
2167 +Actually aufs had adopted another complicated approach which calls
2168 +generic_file_mmap() and handles struct vm_operations_struct. In this
2169 +approach, aufs met a hard problem and I could not solve it without
2170 +switching the approach.
2172 +There may be one more another approach which is
2173 +- bind-mount the branch-root onto the aufs-root internally
2174 +- grab the new vfsmount (ie. struct mount)
2175 +- lazy-umount the branch-root internally
2176 +- in open(2) the aufs-file, open the branch-file with the hidden
2177 + vfsmount (instead of the original branch's vfsmount)
2178 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2179 + but it may be possible from userspace by the mount helper.
2181 +Adding the internal hidden vfsmount and using it in opening a file, the
2182 +file path under /proc will be printed correctly. This approach looks
2183 +smarter, but is not possible I am afraid.
2184 +- aufs-root may be bind-mount later. when it happens, another hidden
2185 + vfsmount will be required.
2186 +- it is hard to get the chance to bind-mount and lazy-umount
2187 + + in kernel-space, FS can have vfsmount in open(2) via
2188 + file->f_path, and aufs can know its vfsmount. But several locks are
2189 + already acquired, and if aufs tries to bind-mount and lazy-umount
2190 + here, then it may cause a deadlock.
2191 + + in user-space, bind-mount doesn't invoke the mount helper.
2192 +- since /proc shows dev and ino, aufs has to give vma these info. it
2193 + means a new member vm_prinode will be necessary. this is essentially
2194 + equivalent to vm_prfile described above.
2196 +I have to give up this "looks-smater" approach.
2197 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2198 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2199 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-05-02 20:15:14.670004120 +0200
2202 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2204 +# This program is free software; you can redistribute it and/or modify
2205 +# it under the terms of the GNU General Public License as published by
2206 +# the Free Software Foundation; either version 2 of the License, or
2207 +# (at your option) any later version.
2209 +# This program is distributed in the hope that it will be useful,
2210 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2211 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2212 +# GNU General Public License for more details.
2214 +# You should have received a copy of the GNU General Public License
2215 +# along with this program; if not, write to the Free Software
2216 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2219 +Listing XATTR/EA and getting the value
2220 +----------------------------------------------------------------------
2221 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2222 +shows the values from the topmost existing file. This behaviour is good
2223 +for the non-dir entries since the bahaviour exactly matches the shown
2224 +information. But for the directories, aufs considers all the same named
2225 +entries on the lower branches. Which means, if one of the lower entry
2226 +rejects readdir call, then aufs returns an error even if the topmost
2227 +entry allows it. This behaviour is necessary to respect the branch fs's
2228 +security, but can make users confused since the user-visible standard
2229 +attributes don't match the behaviour.
2230 +To address this issue, aufs has a mount option called dirperm1 which
2231 +checks the permission for the topmost entry only, and ignores the lower
2232 +entry's permission.
2234 +A similar issue can happen around XATTR.
2235 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2236 +always set. Otherwise these very unpleasant situation would happen.
2237 +- listxattr(2) may return the duplicated entries.
2238 +- users may not be able to remove or reset the XATTR forever,
2241 +XATTR/EA support in the internal (copy,move)-(up,down)
2242 +----------------------------------------------------------------------
2243 +Generally the extended attributes of inode are categorized as these.
2244 +- "security" for LSM and capability.
2245 +- "system" for posix ACL, 'acl' mount option is required for the branch
2247 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2248 +- "user" for userspace, 'user_xattr' mount option is required for the
2249 + branch fs generally.
2251 +Moreover there are some other categories. Aufs handles these rather
2252 +unpopular categories as the ordinary ones, ie. there is no special
2253 +condition nor exception.
2255 +In copy-up, the support for XATTR on the dst branch may differ from the
2256 +src branch. In this case, the copy-up operation will get an error and
2257 +the original user operation which triggered the copy-up will fail. It
2258 +can happen that even all copy-up will fail.
2259 +When both of src and dst branches support XATTR and if an error occurs
2260 +during copying XATTR, then the copy-up should fail obviously. That is a
2261 +good reason and aufs should return an error to userspace. But when only
2262 +the src branch support that XATTR, aufs should not return an error.
2263 +For example, the src branch supports ACL but the dst branch doesn't
2264 +because the dst branch may natively un-support it or temporary
2265 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2266 +may NOT return an error even if the XATTR is not supported. It is
2267 +totally up to the branch fs.
2269 +Anyway when the aufs internal copy-up gets an error from the dst branch
2270 +fs, then aufs tries removing the just copied entry and returns the error
2271 +to the userspace. The worst case of this situation will be all copy-up
2274 +For the copy-up operation, there two basic approaches.
2275 +- copy the specified XATTR only (by category above), and return the
2276 + error unconditionally if it happens.
2277 +- copy all XATTR, and ignore the error on the specified category only.
2279 +In order to support XATTR and to implement the correct behaviour, aufs
2280 +chooses the latter approach and introduces some new branch attributes,
2281 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2282 +They correspond to the XATTR namespaces (see above). Additionally, to be
2283 +convenient, "icex" is also provided which means all "icex*" attributes
2284 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2286 +The meaning of these attributes is to ignore the error from setting
2287 +XATTR on that branch.
2288 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2289 +error from the dst branch according to the specified attributes.
2291 +Some XATTR may have its default value. The default value may come from
2292 +the parent dir or the environment. If the default value is set at the
2293 +file creating-time, it will be overwritten by copy-up.
2294 +Some contradiction may happen I am afraid.
2295 +Do we need another attribute to stop copying XATTR? I am unsure. For
2296 +now, aufs implements the branch attributes to ignore the error.
2297 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2298 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2299 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-05-02 20:15:14.670004120 +0200
2302 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2304 +# This program is free software; you can redistribute it and/or modify
2305 +# it under the terms of the GNU General Public License as published by
2306 +# the Free Software Foundation; either version 2 of the License, or
2307 +# (at your option) any later version.
2309 +# This program is distributed in the hope that it will be useful,
2310 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2311 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2312 +# GNU General Public License for more details.
2314 +# You should have received a copy of the GNU General Public License
2315 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2317 +Export Aufs via NFS
2318 +----------------------------------------------------------------------
2319 +Here is an approach.
2320 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2322 +- iget_locked(): initialize aufs inode generation for a new inode, and
2323 + store it in xigen file.
2324 +- destroy_inode(): increment aufs inode generation and store it in xigen
2325 + file. it is necessary even if it is not unlinked, because any data of
2326 + inode may be changed by UDBA.
2327 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2328 + build file handle by
2329 + + branch id (4 bytes)
2330 + + superblock generation (4 bytes)
2331 + + inode number (4 or 8 bytes)
2332 + + parent dir inode number (4 or 8 bytes)
2333 + + inode generation (4 bytes))
2334 + + return value of exportfs_encode_fh() for the parent on a branch (4
2336 + + file handle for a branch (by exportfs_encode_fh())
2338 + + find the index of a branch from its id in handle, and check it is
2339 + still exist in aufs.
2340 + + 1st level: get the inode number from handle and search it in cache.
2341 + + 2nd level: if not found in cache, get the parent inode number from
2342 + the handle and search it in cache. and then open the found parent
2343 + dir, find the matching inode number by vfs_readdir() and get its
2344 + name, and call lookup_one_len() for the target dentry.
2345 + + 3rd level: if the parent dir is not cached, call
2346 + exportfs_decode_fh() for a branch and get the parent on a branch,
2347 + build a pathname of it, convert it a pathname in aufs, call
2348 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2350 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2351 + for every branch, but not itself. to get this, (currently) aufs
2352 + searches in current->nsproxy->mnt_ns list. it may not be a good
2353 + idea, but I didn't get other approach.
2354 + + test the generation of the gotten inode.
2355 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2356 + convert it into ESTALE for NFSD.
2357 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2358 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2359 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2360 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2361 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-05-02 20:15:14.670004120 +0200
2364 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2366 +# This program is free software; you can redistribute it and/or modify
2367 +# it under the terms of the GNU General Public License as published by
2368 +# the Free Software Foundation; either version 2 of the License, or
2369 +# (at your option) any later version.
2371 +# This program is distributed in the hope that it will be useful,
2372 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2373 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2374 +# GNU General Public License for more details.
2376 +# You should have received a copy of the GNU General Public License
2377 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2379 +Show Whiteout Mode (shwh)
2380 +----------------------------------------------------------------------
2381 +Generally aufs hides the name of whiteouts. But in some cases, to show
2382 +them is very useful for users. For instance, creating a new middle layer
2383 +(branch) by merging existing layers.
2385 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2386 +When you have three branches,
2387 +- Bottom: 'system', squashfs (underlying base system), read-only
2388 +- Middle: 'mods', squashfs, read-only
2389 +- Top: 'overlay', ram (tmpfs), read-write
2391 +The top layer is loaded at boot time and saved at shutdown, to preserve
2392 +the changes made to the system during the session.
2393 +When larger changes have been made, or smaller changes have accumulated,
2394 +the size of the saved top layer data grows. At this point, it would be
2395 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2396 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2397 +restoring save and load speed.
2399 +This merging is simplified by the use of another aufs mount, of just the
2400 +two overlay branches using the 'shwh' option.
2401 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2402 + aufs /livesys/merge_union
2404 +A merged view of these two branches is then available at
2405 +/livesys/merge_union, and the new feature is that the whiteouts are
2407 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2408 +writing to all branches. Also the default mode for all branches is 'ro'.
2409 +It is now possible to save the combined contents of the two overlay
2410 +branches to a new squashfs, e.g.:
2411 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2413 +This new squashfs archive can be stored on the boot device and the
2414 +initramfs will use it to replace the old one at the next boot.
2415 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2416 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2417 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-05-02 20:15:14.670004120 +0200
2420 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2422 +# This program is free software; you can redistribute it and/or modify
2423 +# it under the terms of the GNU General Public License as published by
2424 +# the Free Software Foundation; either version 2 of the License, or
2425 +# (at your option) any later version.
2427 +# This program is distributed in the hope that it will be useful,
2428 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2429 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2430 +# GNU General Public License for more details.
2432 +# You should have received a copy of the GNU General Public License
2433 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2435 +Dynamically customizable FS operations
2436 +----------------------------------------------------------------------
2437 +Generally FS operations (struct inode_operations, struct
2438 +address_space_operations, struct file_operations, etc.) are defined as
2439 +"static const", but it never means that FS have only one set of
2440 +operation. Some FS have multiple sets of them. For instance, ext2 has
2441 +three sets, one for XIP, for NOBH, and for normal.
2442 +Since aufs overrides and redirects these operations, sometimes aufs has
2443 +to change its behaviour according to the branch FS type. More importantly
2444 +VFS acts differently if a function (member in the struct) is set or
2445 +not. It means aufs should have several sets of operations and select one
2446 +among them according to the branch FS definition.
2448 +In order to solve this problem and not to affect the behaviour of VFS,
2449 +aufs defines these operations dynamically. For instance, aufs defines
2450 +dummy direct_IO function for struct address_space_operations, but it may
2451 +not be set to the address_space_operations actually. When the branch FS
2452 +doesn't have it, aufs doesn't set it to its address_space_operations
2453 +while the function definition itself is still alive. So the behaviour
2454 +itself will not change, and it will return an error when direct_IO is
2457 +The lifetime of these dynamically generated operation object is
2458 +maintained by aufs branch object. When the branch is removed from aufs,
2459 +the reference counter of the object is decremented. When it reaches
2460 +zero, the dynamically generated operation object will be freed.
2462 +This approach is designed to support AIO (io_submit), Direct I/O and
2464 +Currently this approach is applied to address_space_operations for
2465 +regular files only.
2466 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2467 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2468 +++ linux/Documentation/filesystems/aufs/README 2021-05-02 20:15:14.666670785 +0200
2471 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2477 +----------------------------------------
2478 +In the early days, aufs was entirely re-designed and re-implemented
2479 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2480 +improvements and implementations, it became totally different from
2481 +Unionfs while keeping the basic features.
2482 +Later, Unionfs Version 2.x series began taking some of the same
2483 +approaches to aufs1's.
2484 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2485 +University and his team.
2487 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2489 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2490 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2491 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2492 + or aufs1 from CVS on SourceForge.
2494 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2495 + According to Christoph Hellwig, linux rejects all union-type
2496 + filesystems but UnionMount.
2497 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2499 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2500 + UnionMount, and he pointed out an issue around a directory mutex
2501 + lock and aufs addressed it. But it is still unsure whether aufs will
2502 + be merged (or any other union solution).
2503 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2507 +----------------------------------------
2508 +- unite several directories into a single virtual filesystem. The member
2509 + directory is called as a branch.
2510 +- you can specify the permission flags to the branch, which are 'readonly',
2511 + 'readwrite' and 'whiteout-able.'
2512 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2513 + readonly branch are modifiable logically.
2514 +- dynamic branch manipulation, add, del.
2517 +Also there are many enhancements in aufs, such as:
2518 +- test only the highest one for the directory permission (dirperm1)
2519 +- copyup on open (coo=)
2520 +- 'move' policy for copy-up between two writable branches, after
2521 + checking free space.
2523 +- readdir(3) in userspace.
2524 +- keep inode number by external inode number table
2525 +- keep the timestamps of file/dir in internal copyup operation
2526 +- seekable directory, supporting NFS readdir.
2527 +- whiteout is hardlinked in order to reduce the consumption of inodes
2529 +- do not copyup, nor create a whiteout when it is unnecessary
2530 +- revert a single systemcall when an error occurs in aufs
2531 +- remount interface instead of ioctl
2532 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2533 +- loopback mounted filesystem as a branch
2534 +- kernel thread for removing the dir who has a plenty of whiteouts
2535 +- support copyup sparse file (a file which has a 'hole' in it)
2536 +- default permission flags for branches
2537 +- selectable permission flags for ro branch, whether whiteout can
2540 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2541 +- support multiple writable branches, some policies to select one
2542 + among multiple writable branches.
2543 +- a new semantics for link(2) and rename(2) to support multiple
2544 + writable branches.
2545 +- no glibc changes are required.
2546 +- pseudo hardlink (hardlink over branches)
2547 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2548 + including NFS or remote filesystem branch.
2549 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2552 +Currently these features are dropped temporary from aufs5.
2553 +See design/08plan.txt in detail.
2554 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2556 +- statistics of aufs thread (/sys/fs/aufs/stat)
2558 +Features or just an idea in the future (see also design/*.txt),
2559 +- reorder the branch index without del/re-add.
2560 +- permanent xino files for NFSD
2561 +- an option for refreshing the opened files after add/del branches
2562 +- light version, without branch manipulation. (unnecessary?)
2563 +- copyup in userspace
2564 +- inotify in userspace
2569 +----------------------------------------
2570 +There are three GIT trees for aufs5, aufs5-linux.git,
2571 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2573 +While the aufs-util is always necessary, you need either of aufs5-linux
2574 +or aufs5-standalone.
2576 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2577 +git://git.kernel.org/.../torvalds/linux.git.
2578 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2579 +build aufs5 as an external kernel module.
2580 +Several extra patches are not included in this tree. Only
2581 +aufs5-standalone tree contains them. They are described in the later
2582 +section "Configuration and Compilation."
2584 +On the other hand, the aufs5-standalone tree has only aufs source files
2585 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2586 +But you need to apply all aufs patches manually.
2588 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2589 +represents the linux kernel version, "linux-5.x". For instance,
2590 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2591 +"aufs5.x-rcN" branch.
2594 +$ git clone --reference /your/linux/git/tree \
2595 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2596 +- if you don't have linux GIT tree, then remove "--reference ..."
2597 +$ cd aufs5-linux.git
2598 +$ git checkout origin/aufs5.0
2600 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2601 +leave the patch-work to GIT.
2602 +$ cd /your/linux/git/tree
2603 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2605 +$ git checkout -b my5.0 v5.0
2606 +$ (add your local change...)
2607 +$ git pull aufs5 aufs5.0
2608 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2609 +- you may need to solve some conflicts between your_changes and
2610 + aufs5.0. in this case, git-rerere is recommended so that you can
2611 + solve the similar conflicts automatically when you upgrade to 5.1 or
2612 + later in the future.
2614 +o aufs5-standalone tree
2615 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2616 +$ cd aufs5-standalone.git
2617 +$ git checkout origin/aufs5.0
2620 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2621 +- note that the public aufs-util.git is on SourceForge instead of
2624 +$ git checkout origin/aufs5.0
2626 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2627 +The minor version number, 'x' in '5.x', of aufs may not always
2628 +follow the minor version number of the kernel.
2629 +Because changes in the kernel that cause the use of a new
2630 +minor version number do not always require changes to aufs-util.
2632 +Since aufs-util has its own minor version number, you may not be
2633 +able to find a GIT branch in aufs-util for your kernel's
2634 +exact minor version number.
2635 +In this case, you should git-checkout the branch for the
2636 +nearest lower number.
2638 +For (an unreleased) example:
2639 +If you are using "linux-5.10" and the "aufs5.10" branch
2640 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2641 +or something numerically smaller is the branch for your kernel.
2643 +Also you can view all branches by
2647 +3. Configuration and Compilation
2648 +----------------------------------------
2649 +Make sure you have git-checkout'ed the correct branch.
2651 +For aufs5-linux tree,
2652 +- enable CONFIG_AUFS_FS.
2653 +- set other aufs configurations if necessary.
2655 +For aufs5-standalone tree,
2656 +There are several ways to build.
2659 +- apply ./aufs5-kbuild.patch to your kernel source files.
2660 +- apply ./aufs5-base.patch too.
2661 +- apply ./aufs5-mmap.patch too.
2662 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2663 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2664 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2665 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2666 +- enable CONFIG_AUFS_FS, you can select either
2668 +- and build your kernel as usual.
2669 +- install the built kernel.
2670 +- install the header files too by "make headers_install" to the
2671 + directory where you specify. By default, it is $PWD/usr.
2672 + "make help" shows a brief note for headers_install.
2673 +- and reboot your system.
2676 +- module only (CONFIG_AUFS_FS=m).
2677 +- apply ./aufs5-base.patch to your kernel source files.
2678 +- apply ./aufs5-mmap.patch too.
2679 +- apply ./aufs5-standalone.patch too.
2680 +- build your kernel, don't forget "make headers_install", and reboot.
2681 +- edit ./config.mk and set other aufs configurations if necessary.
2682 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2683 + every aufs configurations.
2684 +- build the module by simple "make".
2685 +- you can specify ${KDIR} make variable which points to your kernel
2687 +- install the files
2688 + + run "make install" to install the aufs module, or copy the built
2689 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2690 + + run "make install_headers" (instead of headers_install) to install
2691 + the modified aufs header file (you can specify DESTDIR which is
2692 + available in aufs standalone version's Makefile only), or copy
2693 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2694 + you like manually. By default, the target directory is $PWD/usr.
2695 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2696 + kernel source tree.
2698 +Note: The header file aufs_type.h is necessary to build aufs-util
2699 + as well as "make headers_install" in the kernel source tree.
2700 + headers_install is subject to be forgotten, but it is essentially
2701 + necessary, not only for building aufs-util.
2702 + You may not meet problems without headers_install in some older
2706 +- read README in aufs-util, build and install it
2707 +- note that your distribution may contain an obsoleted version of
2708 + aufs_type.h in /usr/include/linux or something. When you build aufs
2709 + utilities, make sure that your compiler refers the correct aufs header
2710 + file which is built by "make headers_install."
2711 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2712 + then run "make install_ulib" too. And refer to the aufs manual in
2715 +There several other patches in aufs5-standalone.git. They are all
2716 +optional. When you meet some problems, they will help you.
2717 +- aufs5-loopback.patch
2718 + Supports a nested loopback mount in a branch-fs. This patch is
2719 + unnecessary until aufs produces a message like "you may want to try
2720 + another patch for loopback file".
2721 +- proc_mounts.patch
2722 + When there are many mountpoints and many mount(2)/umount(2) are
2723 + running, then /proc/mounts may not show the all mountpoints. This
2724 + patch makes /proc/mounts always show the full mountpoints list.
2725 + If you don't want to apply this patch and meet such problem, then you
2726 + need to increase the value of 'ProcMounts_Times' make-variable in
2727 + aufs-util.git as a second best solution.
2729 + Modifies a system global kernel internal function get_next_ino() in
2730 + order to stop assigning 0 for an inode-number. Not directly related to
2731 + aufs, but recommended generally.
2733 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2734 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2735 + duplication of inode number, which is important for backup tools and
2736 + other utilities. When you find aufs XINO files for tmpfs branch
2737 + growing too much, try this patch.
2738 +- lockdep-debug.patch
2739 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2740 + also a caller of VFS functions for branch filesystems, subclassing of
2741 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2742 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2743 + need to apply this debug patch to expand several constant values.
2744 + If you don't know what LOCKDEP is, then you don't have apply this
2749 +----------------------------------------
2750 +At first, make sure aufs-util are installed, and please read the aufs
2751 +manual, aufs.5 in aufs-util.git tree.
2755 +$ mkdir /tmp/rw /tmp/aufs
2756 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2758 +Here is another example. The result is equivalent.
2759 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2761 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2762 +# mount -o remount,append:${HOME} /tmp/aufs
2764 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2765 +you modify a file under /tmp/aufs, the one on your home directory is
2766 +not affected, instead the same named file will be newly created under
2767 +/tmp/rw. And all of your modification to a file will be applied to
2768 +the one under /tmp/rw. This is called the file based Copy on Write
2770 +Aufs mount options are described in aufs.5.
2771 +If you run chroot or something and make your aufs as a root directory,
2772 +then you need to customize the shutdown script. See the aufs manual in
2775 +Additionally, there are some sample usages of aufs which are a
2776 +diskless system with network booting, and LiveCD over NFS.
2777 +See sample dir in CVS tree on SourceForge.
2781 +----------------------------------------
2782 +When you have any problems or strange behaviour in aufs, please let me
2784 +- /proc/mounts (instead of the output of mount(8))
2785 +- /sys/module/aufs/*
2786 +- /sys/fs/aufs/* (if you have them)
2787 +- /debug/aufs/* (if you have them)
2788 +- linux kernel version
2789 + if your kernel is not plain, for example modified by distributor,
2790 + the url where i can download its source is necessary too.
2791 +- aufs version which was printed at loading the module or booting the
2792 + system, instead of the date you downloaded.
2793 +- configuration (define/undefine CONFIG_AUFS_xxx)
2794 +- kernel configuration or /proc/config.gz (if you have it)
2795 +- LSM (linux security module, if you are using)
2796 +- behaviour which you think to be incorrect
2797 +- actual operation, reproducible one is better
2798 +- mailto: aufs-users at lists.sourceforge.net
2800 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2801 +and Feature Requests) on SourceForge. Please join and write to
2805 +6. Acknowledgements
2806 +----------------------------------------
2807 +Thanks to everyone who have tried and are using aufs, whoever
2808 +have reported a bug or any feedback.
2810 +Especially donators:
2811 +Tomas Matejicek(slax.org) made a donation (much more than once).
2812 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2813 + scripts) is making "doubling" donations.
2814 + Unfortunately I cannot list all of the donators, but I really
2816 + It ends Aug 2010, but the ordinary donation URL is still available.
2817 + <http://sourceforge.net/donate/index.php?group_id=167503>
2818 +Dai Itasaka made a donation (2007/8).
2819 +Chuck Smith made a donation (2008/4, 10 and 12).
2820 +Henk Schoneveld made a donation (2008/9).
2821 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2822 +Francois Dupoux made a donation (2008/11).
2823 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2824 + aufs2 GIT tree (2009/2).
2825 +William Grant made a donation (2009/3).
2826 +Patrick Lane made a donation (2009/4).
2827 +The Mail Archive (mail-archive.com) made donations (2009/5).
2828 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2829 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2830 +Pavel Pronskiy made a donation (2011/2).
2831 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2832 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2833 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2835 +Sam Liddicott made a donation (2011/9).
2836 +Era Scarecrow made a donation (2013/4).
2837 +Bor Ratajc made a donation (2013/4).
2838 +Alessandro Gorreta made a donation (2013/4).
2839 +POIRETTE Marc made a donation (2013/4).
2840 +Alessandro Gorreta made a donation (2013/4).
2841 +lauri kasvandik made a donation (2013/5).
2842 +"pemasu from Finland" made a donation (2013/7).
2843 +The Parted Magic Project made a donation (2013/9 and 11).
2844 +Pavel Barta made a donation (2013/10).
2845 +Nikolay Pertsev made a donation (2014/5).
2846 +James B made a donation (2014/7 and 2015/7).
2847 +Stefano Di Biase made a donation (2014/8).
2848 +Daniel Epellei made a donation (2015/1).
2849 +OmegaPhil made a donation (2016/1, 2018/4).
2850 +Tomasz Szewczyk made a donation (2016/4).
2851 +James Burry made a donation (2016/12).
2852 +Carsten Rose made a donation (2018/9).
2853 +Porteus Kiosk made a donation (2018/10).
2855 +Thank you very much.
2856 +Donations are always, including future donations, very important and
2857 +helpful for me to keep on developing aufs.
2861 +----------------------------------------
2862 +If you are an experienced user, no explanation is needed. Aufs is
2863 +just a linux filesystem.
2868 +# Local variables: ;
2871 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2872 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2873 +++ linux/fs/aufs/aufs.h 2021-05-02 20:15:14.670004120 +0200
2875 +/* SPDX-License-Identifier: GPL-2.0 */
2877 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2879 + * This program, aufs is free software; you can redistribute it and/or modify
2880 + * it under the terms of the GNU General Public License as published by
2881 + * the Free Software Foundation; either version 2 of the License, or
2882 + * (at your option) any later version.
2884 + * This program is distributed in the hope that it will be useful,
2885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2887 + * GNU General Public License for more details.
2889 + * You should have received a copy of the GNU General Public License
2890 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2894 + * all header files
2902 +#define AuStub(type, name, body, ...) \
2903 + static inline type name(__VA_ARGS__) { body; }
2905 +#define AuStubVoid(name, ...) \
2906 + AuStub(void, name, , __VA_ARGS__)
2907 +#define AuStubInt0(name, ...) \
2908 + AuStub(int, name, return 0, __VA_ARGS__)
2912 +#include "branch.h"
2915 +#include "dbgaufs.h"
2916 +#include "dentry.h"
2918 +#include "dirren.h"
2921 +#include "fstype.h"
2926 +#include "module.h"
2930 +#include "sysaufs.h"
2935 +#endif /* __KERNEL__ */
2936 +#endif /* __AUFS_H__ */
2937 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2938 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2939 +++ linux/fs/aufs/branch.c 2021-05-02 20:15:14.670004120 +0200
2941 +// SPDX-License-Identifier: GPL-2.0
2943 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2945 + * This program, aufs is free software; you can redistribute it and/or modify
2946 + * it under the terms of the GNU General Public License as published by
2947 + * the Free Software Foundation; either version 2 of the License, or
2948 + * (at your option) any later version.
2950 + * This program is distributed in the hope that it will be useful,
2951 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2952 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2953 + * GNU General Public License for more details.
2955 + * You should have received a copy of the GNU General Public License
2956 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2960 + * branch management
2963 +#include <linux/compat.h>
2964 +#include <linux/statfs.h>
2968 + * free a single branch
2970 +static void au_br_do_free(struct au_branch *br)
2973 + struct au_wbr *wbr;
2974 + struct au_dykey **key;
2976 + au_hnotify_fin_br(br);
2977 + /* always, regardless the mount option */
2978 + au_dr_hino_free(&br->br_dirren);
2981 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2982 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2983 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2984 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2988 + for (i = 0; i < AuBrWh_Last; i++)
2989 + dput(wbr->wbr_wh[i]);
2990 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2991 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2994 + if (br->br_fhsm) {
2995 + au_br_fhsm_fin(br->br_fhsm);
2996 + au_kfree_try_rcu(br->br_fhsm);
2999 + key = br->br_dykey;
3000 + for (i = 0; i < AuBrDynOp; i++, key++)
3006 + /* recursive lock, s_umount of branch's */
3007 + /* synchronize_rcu(); */ /* why? */
3009 + path_put(&br->br_path);
3011 + au_kfree_rcu(wbr);
3012 + au_lcnt_wait_for_fin(&br->br_nfiles);
3013 + au_lcnt_wait_for_fin(&br->br_count);
3014 + /* I don't know why, but percpu_refcount requires this */
3015 + /* synchronize_rcu(); */
3020 + * frees all branches
3022 +void au_br_free(struct au_sbinfo *sbinfo)
3024 + aufs_bindex_t bmax;
3025 + struct au_branch **br;
3027 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3029 + bmax = sbinfo->si_bbot + 1;
3030 + br = sbinfo->si_branch;
3032 + au_br_do_free(*br++);
3036 + * find the index of a branch which is specified by @br_id.
3038 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3040 + aufs_bindex_t bindex, bbot;
3042 + bbot = au_sbbot(sb);
3043 + for (bindex = 0; bindex <= bbot; bindex++)
3044 + if (au_sbr_id(sb, bindex) == br_id)
3049 +/* ---------------------------------------------------------------------- */
3055 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3056 + struct dentry *h_root)
3058 + if (unlikely(h_adding == h_root
3059 + || au_test_loopback_overlap(sb, h_adding)))
3061 + if (h_adding->d_sb != h_root->d_sb)
3063 + return au_test_subdir(h_adding, h_root)
3064 + || au_test_subdir(h_root, h_adding);
3068 + * returns a newly allocated branch. @new_nbranch is a number of branches
3069 + * after adding a branch.
3071 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3074 + struct au_branch *add_branch;
3075 + struct dentry *root;
3076 + struct inode *inode;
3080 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3081 + if (unlikely(!add_branch))
3083 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3084 + if (unlikely(!add_branch->br_xino))
3086 + err = au_hnotify_init_br(add_branch, perm);
3087 + if (unlikely(err))
3090 + if (au_br_writable(perm)) {
3091 + /* may be freed separately at changing the branch permission */
3092 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3094 + if (unlikely(!add_branch->br_wbr))
3098 + if (au_br_fhsm(perm)) {
3099 + err = au_fhsm_br_alloc(add_branch);
3100 + if (unlikely(err))
3104 + root = sb->s_root;
3105 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3107 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3109 + inode = d_inode(root);
3110 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3114 + return add_branch; /* success */
3117 + au_kfree_rcu(add_branch->br_wbr);
3119 + au_hnotify_fin_br(add_branch);
3121 + au_xino_put(add_branch);
3123 + au_kfree_rcu(add_branch);
3125 + return ERR_PTR(err);
3129 + * test if the branch permission is legal or not.
3131 +static int test_br(struct inode *inode, int brperm, char *path)
3135 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3140 + pr_err("write permission for readonly mount or inode, %s\n", path);
3148 + * 0: success, the caller will add it
3149 + * plus: success, it is already unified, the caller should ignore it
3152 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3155 + aufs_bindex_t bbot, bindex;
3156 + struct dentry *root, *h_dentry;
3157 + struct inode *inode, *h_inode;
3159 + root = sb->s_root;
3160 + bbot = au_sbbot(sb);
3161 + if (unlikely(bbot >= 0
3162 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3166 + pr_err("%s duplicated\n", add->pathname);
3171 + err = -ENOSPC; /* -E2BIG; */
3172 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3173 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3174 + pr_err("number of branches exceeded %s\n", add->pathname);
3179 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3180 + pr_err("bad index %d\n", add->bindex);
3184 + inode = d_inode(add->path.dentry);
3186 + if (unlikely(!inode->i_nlink)) {
3187 + pr_err("no existence %s\n", add->pathname);
3192 + if (unlikely(inode->i_sb == sb)) {
3193 + pr_err("%s must be outside\n", add->pathname);
3197 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3198 + pr_err("unsupported filesystem, %s (%s)\n",
3199 + add->pathname, au_sbtype(inode->i_sb));
3203 + if (unlikely(inode->i_sb->s_stack_depth)) {
3204 + pr_err("already stacked, %s (%s)\n",
3205 + add->pathname, au_sbtype(inode->i_sb));
3209 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3210 + if (unlikely(err))
3214 + return 0; /* success */
3217 + for (bindex = 0; bindex <= bbot; bindex++)
3218 + if (unlikely(test_overlap(sb, add->path.dentry,
3219 + au_h_dptr(root, bindex)))) {
3220 + pr_err("%s is overlapped\n", add->pathname);
3225 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3226 + h_dentry = au_h_dptr(root, 0);
3227 + h_inode = d_inode(h_dentry);
3228 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3229 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3230 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3231 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3233 + i_uid_read(inode), i_gid_read(inode),
3234 + (inode->i_mode & S_IALLUGO),
3235 + i_uid_read(h_inode), i_gid_read(h_inode),
3236 + (h_inode->i_mode & S_IALLUGO));
3244 + * initialize or clean the whiteouts for an adding branch
3246 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3249 + int err, old_perm;
3250 + aufs_bindex_t bindex;
3251 + struct inode *h_inode;
3252 + struct au_wbr *wbr;
3253 + struct au_hinode *hdir;
3254 + struct dentry *h_dentry;
3256 + err = vfsub_mnt_want_write(au_br_mnt(br));
3257 + if (unlikely(err))
3261 + old_perm = br->br_perm;
3262 + br->br_perm = new_perm;
3265 + bindex = au_br_index(sb, br->br_id);
3266 + if (0 <= bindex) {
3267 + hdir = au_hi(d_inode(sb->s_root), bindex);
3268 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3270 + h_dentry = au_br_dentry(br);
3271 + h_inode = d_inode(h_dentry);
3272 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3275 + err = au_wh_init(br, sb);
3277 + wbr_wh_write_lock(wbr);
3278 + err = au_wh_init(br, sb);
3279 + wbr_wh_write_unlock(wbr);
3282 + au_hn_inode_unlock(hdir);
3284 + inode_unlock(h_inode);
3285 + vfsub_mnt_drop_write(au_br_mnt(br));
3286 + br->br_perm = old_perm;
3288 + if (!err && wbr && !au_br_writable(new_perm)) {
3289 + au_kfree_rcu(wbr);
3290 + br->br_wbr = NULL;
3297 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3301 + struct kstatfs kst;
3302 + struct au_wbr *wbr;
3305 + au_rw_init(&wbr->wbr_wh_rwsem);
3306 + atomic_set(&wbr->wbr_wh_running, 0);
3309 + * a limit for rmdir/rename a dir
3310 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3312 + err = vfs_statfs(&br->br_path, &kst);
3313 + if (unlikely(err))
3316 + if (kst.f_namelen >= NAME_MAX)
3317 + err = au_br_init_wh(sb, br, perm);
3319 + pr_err("%pd(%s), unsupported namelen %ld\n",
3321 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3327 +/* initialize a new branch */
3328 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3329 + struct au_opt_add *add)
3332 + struct au_branch *brbase;
3334 + struct inode *h_inode;
3337 + br->br_perm = add->perm;
3338 + br->br_path = add->path; /* set first, path_get() later */
3339 + spin_lock_init(&br->br_dykey_lock);
3340 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3341 + au_lcnt_init(&br->br_count, /*release*/NULL);
3342 + br->br_id = au_new_br_id(sb);
3343 + AuDebugOn(br->br_id < 0);
3345 + /* always, regardless the given option */
3346 + err = au_dr_br_init(sb, br, &add->path);
3347 + if (unlikely(err))
3350 + if (au_br_writable(add->perm)) {
3351 + err = au_wbr_init(br, sb, add->perm);
3352 + if (unlikely(err))
3356 + if (au_opt_test(au_mntflags(sb), XINO)) {
3357 + brbase = au_sbr(sb, 0);
3358 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3360 + h_inode = d_inode(add->path.dentry);
3361 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3362 + if (unlikely(err)) {
3363 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3368 + sysaufs_br_init(br);
3369 + path_get(&br->br_path);
3370 + goto out; /* success */
3373 + memset(&br->br_path, 0, sizeof(br->br_path));
3378 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3379 + struct au_branch *br, aufs_bindex_t bbot,
3380 + aufs_bindex_t amount)
3382 + struct au_branch **brp;
3384 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3386 + brp = sbinfo->si_branch + bindex;
3387 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3389 + sbinfo->si_bbot++;
3390 + if (unlikely(bbot < 0))
3391 + sbinfo->si_bbot = 0;
3394 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3395 + aufs_bindex_t bbot, aufs_bindex_t amount)
3397 + struct au_hdentry *hdp;
3399 + AuRwMustWriteLock(&dinfo->di_rwsem);
3401 + hdp = au_hdentry(dinfo, bindex);
3402 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3403 + au_h_dentry_init(hdp);
3405 + if (unlikely(bbot < 0))
3406 + dinfo->di_btop = 0;
3409 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3410 + aufs_bindex_t bbot, aufs_bindex_t amount)
3412 + struct au_hinode *hip;
3414 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3416 + hip = au_hinode(iinfo, bindex);
3417 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3418 + au_hinode_init(hip);
3420 + if (unlikely(bbot < 0))
3421 + iinfo->ii_btop = 0;
3424 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3425 + aufs_bindex_t bindex)
3427 + struct dentry *root, *h_dentry;
3428 + struct inode *root_inode, *h_inode;
3429 + aufs_bindex_t bbot, amount;
3431 + root = sb->s_root;
3432 + root_inode = d_inode(root);
3433 + bbot = au_sbbot(sb);
3434 + amount = bbot + 1 - bindex;
3435 + h_dentry = au_br_dentry(br);
3436 + au_sbilist_lock();
3437 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3438 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3439 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3440 + au_set_h_dptr(root, bindex, dget(h_dentry));
3441 + h_inode = d_inode(h_dentry);
3442 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3443 + au_sbilist_unlock();
3446 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3449 + aufs_bindex_t bbot, add_bindex;
3450 + struct dentry *root, *h_dentry;
3451 + struct inode *root_inode;
3452 + struct au_branch *add_branch;
3454 + root = sb->s_root;
3455 + root_inode = d_inode(root);
3456 + IMustLock(root_inode);
3457 + IiMustWriteLock(root_inode);
3458 + err = test_add(sb, add, remount);
3459 + if (unlikely(err < 0))
3463 + goto out; /* success */
3466 + bbot = au_sbbot(sb);
3467 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3468 + err = PTR_ERR(add_branch);
3469 + if (IS_ERR(add_branch))
3472 + err = au_br_init(add_branch, sb, add);
3473 + if (unlikely(err)) {
3474 + au_br_do_free(add_branch);
3478 + add_bindex = add->bindex;
3479 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3480 + au_br_do_add(sb, add_branch, add_bindex);
3481 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3482 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3484 + h_dentry = add->path.dentry;
3485 + if (!add_bindex) {
3486 + au_cpup_attr_all(root_inode, /*force*/1);
3487 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3489 + au_add_nlink(root_inode, d_inode(h_dentry));
3495 +/* ---------------------------------------------------------------------- */
3497 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3498 + unsigned long long max __maybe_unused,
3501 + unsigned long long n;
3502 + struct file **p, *f;
3503 + struct hlist_bl_head *files;
3504 + struct hlist_bl_node *pos;
3505 + struct au_finfo *finfo;
3509 + files = &au_sbi(sb)->si_files;
3510 + hlist_bl_lock(files);
3511 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3512 + f = finfo->fi_file;
3514 + && !special_file(file_inode(f)->i_mode)) {
3518 + AuDebugOn(n > max);
3521 + hlist_bl_unlock(files);
3526 +static struct file **au_farray_alloc(struct super_block *sb,
3527 + unsigned long long *max)
3529 + struct au_sbinfo *sbi;
3532 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3533 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3536 +static void au_farray_free(struct file **a, unsigned long long max)
3538 + unsigned long long ull;
3540 + for (ull = 0; ull < max; ull++)
3546 +/* ---------------------------------------------------------------------- */
3552 +/* to show the line number, do not make it inlined function */
3553 +#define AuVerbose(do_info, fmt, ...) do { \
3555 + pr_info(fmt, ##__VA_ARGS__); \
3558 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3559 + aufs_bindex_t bbot)
3561 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3564 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3565 + aufs_bindex_t bbot)
3567 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3571 + * test if the branch is deletable or not.
3573 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3574 + unsigned int sigen, const unsigned int verbose)
3576 + int err, i, j, ndentry;
3577 + aufs_bindex_t btop, bbot;
3578 + struct au_dcsub_pages dpages;
3579 + struct au_dpage *dpage;
3582 + err = au_dpages_init(&dpages, GFP_NOFS);
3583 + if (unlikely(err))
3585 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3586 + if (unlikely(err))
3589 + for (i = 0; !err && i < dpages.ndpage; i++) {
3590 + dpage = dpages.dpages + i;
3591 + ndentry = dpage->ndentry;
3592 + for (j = 0; !err && j < ndentry; j++) {
3593 + d = dpage->dentries[j];
3594 + AuDebugOn(au_dcount(d) <= 0);
3595 + if (!au_digen_test(d, sigen)) {
3596 + di_read_lock_child(d, AuLock_IR);
3597 + if (unlikely(au_dbrange_test(d))) {
3598 + di_read_unlock(d, AuLock_IR);
3602 + di_write_lock_child(d);
3603 + if (unlikely(au_dbrange_test(d))) {
3604 + di_write_unlock(d);
3607 + err = au_reval_dpath(d, sigen);
3609 + di_downgrade_lock(d, AuLock_IR);
3611 + di_write_unlock(d);
3616 + /* AuDbgDentry(d); */
3617 + btop = au_dbtop(d);
3618 + bbot = au_dbbot(d);
3619 + if (btop <= bindex
3621 + && au_h_dptr(d, bindex)
3622 + && au_test_dbusy(d, btop, bbot)) {
3624 + AuVerbose(verbose, "busy %pd\n", d);
3627 + di_read_unlock(d, AuLock_IR);
3632 + au_dpages_free(&dpages);
3637 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3638 + unsigned int sigen, const unsigned int verbose)
3641 + unsigned long long max, ull;
3642 + struct inode *i, **array;
3643 + aufs_bindex_t btop, bbot;
3645 + array = au_iarray_alloc(sb, &max);
3646 + err = PTR_ERR(array);
3647 + if (IS_ERR(array))
3651 + AuDbg("b%d\n", bindex);
3652 + for (ull = 0; !err && ull < max; ull++) {
3656 + if (i->i_ino == AUFS_ROOT_INO)
3659 + /* AuDbgInode(i); */
3660 + if (au_iigen(i, NULL) == sigen)
3661 + ii_read_lock_child(i);
3663 + ii_write_lock_child(i);
3664 + err = au_refresh_hinode_self(i);
3667 + ii_downgrade_lock(i);
3669 + ii_write_unlock(i);
3674 + btop = au_ibtop(i);
3675 + bbot = au_ibbot(i);
3676 + if (btop <= bindex
3678 + && au_h_iptr(i, bindex)
3679 + && au_test_ibusy(i, btop, bbot)) {
3681 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3684 + ii_read_unlock(i);
3686 + au_iarray_free(array, max);
3692 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3693 + const unsigned int verbose)
3696 + unsigned int sigen;
3698 + sigen = au_sigen(root->d_sb);
3699 + DiMustNoWaiters(root);
3700 + IiMustNoWaiters(d_inode(root));
3701 + di_write_unlock(root);
3702 + err = test_dentry_busy(root, bindex, sigen, verbose);
3704 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3705 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3710 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3711 + struct file **to_free, int *idx)
3714 + unsigned char matched, root;
3715 + aufs_bindex_t bindex, bbot;
3716 + struct au_fidir *fidir;
3717 + struct au_hfile *hfile;
3720 + root = IS_ROOT(file->f_path.dentry);
3723 + to_free[*idx] = file;
3729 + fidir = au_fi(file)->fi_hdir;
3730 + AuDebugOn(!fidir);
3731 + bbot = au_fbbot_dir(file);
3732 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3733 + hfile = fidir->fd_hfile + bindex;
3734 + if (!hfile->hf_file)
3737 + if (hfile->hf_br->br_id == br_id) {
3749 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3750 + struct file **to_free, int opened)
3753 + unsigned long long ull, max;
3754 + aufs_bindex_t btop;
3755 + struct file *file, **array;
3756 + struct dentry *root;
3757 + struct au_hfile *hfile;
3759 + array = au_farray_alloc(sb, &max);
3760 + err = PTR_ERR(array);
3761 + if (IS_ERR(array))
3766 + root = sb->s_root;
3767 + di_write_unlock(root);
3768 + for (ull = 0; ull < max; ull++) {
3769 + file = array[ull];
3770 + if (unlikely(!file))
3773 + /* AuDbg("%pD\n", file); */
3774 + fi_read_lock(file);
3775 + btop = au_fbtop(file);
3776 + if (!d_is_dir(file->f_path.dentry)) {
3777 + hfile = &au_fi(file)->fi_htop;
3778 + if (hfile->hf_br->br_id == br_id)
3781 + err = test_dir_busy(file, br_id, to_free, &idx);
3782 + fi_read_unlock(file);
3783 + if (unlikely(err))
3786 + di_write_lock_child(root);
3787 + au_farray_free(array, max);
3788 + AuDebugOn(idx > opened);
3794 +static void br_del_file(struct file **to_free, unsigned long long opened,
3795 + aufs_bindex_t br_id)
3797 + unsigned long long ull;
3798 + aufs_bindex_t bindex, btop, bbot, bfound;
3799 + struct file *file;
3800 + struct au_fidir *fidir;
3801 + struct au_hfile *hfile;
3803 + for (ull = 0; ull < opened; ull++) {
3804 + file = to_free[ull];
3805 + if (unlikely(!file))
3808 + /* AuDbg("%pD\n", file); */
3809 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3811 + fidir = au_fi(file)->fi_hdir;
3812 + AuDebugOn(!fidir);
3813 + fi_write_lock(file);
3814 + btop = au_fbtop(file);
3815 + bbot = au_fbbot_dir(file);
3816 + for (bindex = btop; bindex <= bbot; bindex++) {
3817 + hfile = fidir->fd_hfile + bindex;
3818 + if (!hfile->hf_file)
3821 + if (hfile->hf_br->br_id == br_id) {
3826 + AuDebugOn(bfound < 0);
3827 + au_set_h_fptr(file, bfound, NULL);
3828 + if (bfound == btop) {
3829 + for (btop++; btop <= bbot; btop++)
3830 + if (au_hf_dir(file, btop)) {
3831 + au_set_fbtop(file, btop);
3835 + fi_write_unlock(file);
3839 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3840 + const aufs_bindex_t bindex,
3841 + const aufs_bindex_t bbot)
3843 + struct au_branch **brp, **p;
3845 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3847 + brp = sbinfo->si_branch + bindex;
3848 + if (bindex < bbot)
3849 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3850 + sbinfo->si_branch[0 + bbot] = NULL;
3851 + sbinfo->si_bbot--;
3853 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3856 + sbinfo->si_branch = p;
3857 + /* harmless error */
3860 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3861 + const aufs_bindex_t bbot)
3863 + struct au_hdentry *hdp, *p;
3865 + AuRwMustWriteLock(&dinfo->di_rwsem);
3867 + hdp = au_hdentry(dinfo, bindex);
3868 + if (bindex < bbot)
3869 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3870 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3873 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3876 + dinfo->di_hdentry = p;
3877 + /* harmless error */
3880 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3881 + const aufs_bindex_t bbot)
3883 + struct au_hinode *hip, *p;
3885 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3887 + hip = au_hinode(iinfo, bindex);
3888 + if (bindex < bbot)
3889 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3890 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3893 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3896 + iinfo->ii_hinode = p;
3897 + /* harmless error */
3900 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3901 + struct au_branch *br)
3903 + aufs_bindex_t bbot;
3904 + struct au_sbinfo *sbinfo;
3905 + struct dentry *root, *h_root;
3906 + struct inode *inode, *h_inode;
3907 + struct au_hinode *hinode;
3909 + SiMustWriteLock(sb);
3911 + root = sb->s_root;
3912 + inode = d_inode(root);
3913 + sbinfo = au_sbi(sb);
3914 + bbot = sbinfo->si_bbot;
3916 + h_root = au_h_dptr(root, bindex);
3917 + hinode = au_hi(inode, bindex);
3918 + h_inode = au_igrab(hinode->hi_inode);
3921 + au_sbilist_lock();
3922 + au_br_do_del_brp(sbinfo, bindex, bbot);
3923 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3924 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3925 + au_sbilist_unlock();
3927 + /* ignore an error */
3928 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3932 + au_br_do_free(br);
3935 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3936 + unsigned long long max, void *arg)
3941 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3944 + unsigned long long opened;
3945 + unsigned int mnt_flags;
3946 + aufs_bindex_t bindex, bbot, br_id;
3947 + unsigned char do_wh, verbose;
3948 + struct au_branch *br;
3949 + struct au_wbr *wbr;
3950 + struct dentry *root;
3951 + struct file **to_free;
3956 + root = sb->s_root;
3957 + bindex = au_find_dbindex(root, del->h_path.dentry);
3960 + goto out; /* success */
3962 + pr_err("%s no such branch\n", del->pathname);
3965 + AuDbg("bindex b%d\n", bindex);
3968 + mnt_flags = au_mntflags(sb);
3969 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3970 + bbot = au_sbbot(sb);
3971 + if (unlikely(!bbot)) {
3972 + AuVerbose(verbose, "no more branches left\n");
3976 + br = au_sbr(sb, bindex);
3977 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3978 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3979 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3983 + br_id = br->br_id;
3984 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3985 + if (unlikely(opened)) {
3986 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3987 + err = PTR_ERR(to_free);
3988 + if (IS_ERR(to_free))
3991 + err = test_file_busy(sb, br_id, to_free, opened);
3992 + if (unlikely(err)) {
3993 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3999 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4001 + /* instead of WbrWhMustWriteLock(wbr) */
4002 + SiMustWriteLock(sb);
4003 + for (i = 0; i < AuBrWh_Last; i++) {
4004 + dput(wbr->wbr_wh[i]);
4005 + wbr->wbr_wh[i] = NULL;
4009 + err = test_children_busy(root, bindex, verbose);
4010 + if (unlikely(err)) {
4019 + * now we confirmed the branch is deletable.
4020 + * let's free the remaining opened dirs on the branch.
4022 + di_write_unlock(root);
4023 + br_del_file(to_free, opened, br_id);
4024 + di_write_lock_child(root);
4027 + sysaufs_brs_del(sb, bindex); /* remove successors */
4028 + dbgaufs_xino_del(br); /* remove one */
4029 + au_br_do_del(sb, bindex, br);
4030 + sysaufs_brs_add(sb, bindex); /* append successors */
4031 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4034 + au_cpup_attr_all(d_inode(root), /*force*/1);
4035 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4037 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4038 + if (au_opt_test(mnt_flags, PLINK))
4039 + au_plink_half_refresh(sb, br_id);
4041 + goto out; /* success */
4045 + rerr = au_br_init_wh(sb, br, br->br_perm);
4047 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4048 + del->pathname, rerr);
4051 + au_farray_free(to_free, opened);
4055 +/* ---------------------------------------------------------------------- */
4057 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4060 + aufs_bindex_t btop, bbot;
4061 + struct aufs_ibusy ibusy;
4062 + struct inode *inode, *h_inode;
4065 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4068 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4070 + /* VERIFY_WRITE */
4071 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4072 + if (unlikely(err)) {
4079 + si_read_lock(sb, AuLock_FLUSH);
4080 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4084 + ibusy.h_ino = 0; /* invalid */
4085 + inode = ilookup(sb, ibusy.ino);
4087 + || inode->i_ino == AUFS_ROOT_INO
4088 + || au_is_bad_inode(inode))
4091 + ii_read_lock_child(inode);
4092 + btop = au_ibtop(inode);
4093 + bbot = au_ibbot(inode);
4094 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4095 + h_inode = au_h_iptr(inode, ibusy.bindex);
4096 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4097 + ibusy.h_ino = h_inode->i_ino;
4099 + ii_read_unlock(inode);
4103 + si_read_unlock(sb);
4105 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4106 + if (unlikely(err)) {
4115 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4117 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4120 +#ifdef CONFIG_COMPAT
4121 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4123 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4127 +/* ---------------------------------------------------------------------- */
4130 + * change a branch permission
4133 +static void au_warn_ima(void)
4136 + /* since it doesn't support mark_files_ro() */
4137 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4141 +static int do_need_sigen_inc(int a, int b)
4143 + return au_br_whable(a) && !au_br_whable(b);
4146 +static int need_sigen_inc(int old, int new)
4148 + return do_need_sigen_inc(old, new)
4149 + || do_need_sigen_inc(new, old);
4152 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4155 + unsigned int mnt_flags;
4156 + unsigned long long ull, max;
4157 + aufs_bindex_t br_id;
4158 + unsigned char verbose, writer;
4159 + struct file *file, *hf, **array;
4160 + struct au_hfile *hfile;
4161 + struct inode *h_inode;
4163 + mnt_flags = au_mntflags(sb);
4164 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4166 + array = au_farray_alloc(sb, &max);
4167 + err = PTR_ERR(array);
4168 + if (IS_ERR(array))
4172 + br_id = au_sbr_id(sb, bindex);
4173 + for (ull = 0; ull < max; ull++) {
4174 + file = array[ull];
4175 + if (unlikely(!file))
4178 + /* AuDbg("%pD\n", file); */
4179 + fi_read_lock(file);
4180 + if (unlikely(au_test_mmapped(file))) {
4182 + AuVerbose(verbose, "mmapped %pD\n", file);
4184 + FiMustNoWaiters(file);
4185 + fi_read_unlock(file);
4189 + hfile = &au_fi(file)->fi_htop;
4190 + hf = hfile->hf_file;
4191 + if (!d_is_reg(file->f_path.dentry)
4192 + || !(file->f_mode & FMODE_WRITE)
4193 + || hfile->hf_br->br_id != br_id
4194 + || !(hf->f_mode & FMODE_WRITE))
4195 + array[ull] = NULL;
4201 + FiMustNoWaiters(file);
4202 + fi_read_unlock(file);
4210 + for (ull = 0; ull < max; ull++) {
4211 + file = array[ull];
4215 + /* todo: already flushed? */
4217 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4218 + * approach which resets f_mode and calls mnt_drop_write() and
4219 + * file_release_write() for each file, because the branch
4220 + * attribute in aufs world is totally different from the native
4223 + /* fi_read_lock(file); */
4224 + hfile = &au_fi(file)->fi_htop;
4225 + hf = hfile->hf_file;
4226 + /* fi_read_unlock(file); */
4227 + spin_lock(&hf->f_lock);
4228 + writer = !!(hf->f_mode & FMODE_WRITER);
4229 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4230 + spin_unlock(&hf->f_lock);
4232 + h_inode = file_inode(hf);
4233 + if (hf->f_mode & FMODE_READ)
4234 + i_readcount_inc(h_inode);
4235 + put_write_access(h_inode);
4236 + __mnt_drop_write(hf->f_path.mnt);
4241 + au_farray_free(array, max);
4247 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4251 + aufs_bindex_t bindex;
4252 + struct dentry *root;
4253 + struct au_branch *br;
4254 + struct au_br_fhsm *bf;
4256 + root = sb->s_root;
4257 + bindex = au_find_dbindex(root, mod->h_root);
4260 + return 0; /* success */
4262 + pr_err("%s no such branch\n", mod->path);
4265 + AuDbg("bindex b%d\n", bindex);
4267 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4268 + if (unlikely(err))
4271 + br = au_sbr(sb, bindex);
4272 + AuDebugOn(mod->h_root != au_br_dentry(br));
4273 + if (br->br_perm == mod->perm)
4274 + return 0; /* success */
4276 + /* pre-allocate for non-fhsm --> fhsm */
4278 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4279 + err = au_fhsm_br_alloc(br);
4280 + if (unlikely(err))
4283 + br->br_fhsm = NULL;
4286 + if (au_br_writable(br->br_perm)) {
4287 + /* remove whiteout base */
4288 + err = au_br_init_wh(sb, br, mod->perm);
4289 + if (unlikely(err))
4292 + if (!au_br_writable(mod->perm)) {
4293 + /* rw --> ro, file might be mmapped */
4294 + DiMustNoWaiters(root);
4295 + IiMustNoWaiters(d_inode(root));
4296 + di_write_unlock(root);
4297 + err = au_br_mod_files_ro(sb, bindex);
4298 + /* aufs_write_lock() calls ..._child() */
4299 + di_write_lock_child(root);
4301 + if (unlikely(err)) {
4303 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4306 + rerr = au_wbr_init(br, sb, br->br_perm);
4307 + if (unlikely(rerr)) {
4308 + AuIOErr("nested error %d (%d)\n",
4310 + br->br_perm = mod->perm;
4314 + } else if (au_br_writable(mod->perm)) {
4317 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4319 + err = au_wbr_init(br, sb, mod->perm);
4320 + if (unlikely(err)) {
4321 + au_kfree_rcu(br->br_wbr);
4322 + br->br_wbr = NULL;
4326 + if (unlikely(err))
4329 + if (au_br_fhsm(br->br_perm)) {
4330 + if (!au_br_fhsm(mod->perm)) {
4331 + /* fhsm --> non-fhsm */
4332 + au_br_fhsm_fin(br->br_fhsm);
4333 + au_kfree_rcu(br->br_fhsm);
4334 + br->br_fhsm = NULL;
4336 + } else if (au_br_fhsm(mod->perm))
4337 + /* non-fhsm --> fhsm */
4340 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4341 + br->br_perm = mod->perm;
4342 + goto out; /* success */
4345 + au_kfree_try_rcu(bf);
4351 +/* ---------------------------------------------------------------------- */
4353 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4356 + struct kstatfs kstfs;
4358 + err = vfs_statfs(&br->br_path, &kstfs);
4360 + stfs->f_blocks = kstfs.f_blocks;
4361 + stfs->f_bavail = kstfs.f_bavail;
4362 + stfs->f_files = kstfs.f_files;
4363 + stfs->f_ffree = kstfs.f_ffree;
4368 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4369 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4370 +++ linux/fs/aufs/branch.h 2021-05-02 20:15:14.670004120 +0200
4372 +/* SPDX-License-Identifier: GPL-2.0 */
4374 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4376 + * This program, aufs is free software; you can redistribute it and/or modify
4377 + * it under the terms of the GNU General Public License as published by
4378 + * the Free Software Foundation; either version 2 of the License, or
4379 + * (at your option) any later version.
4381 + * This program is distributed in the hope that it will be useful,
4382 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4383 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4384 + * GNU General Public License for more details.
4386 + * You should have received a copy of the GNU General Public License
4387 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4391 + * branch filesystems and xino for them
4394 +#ifndef __AUFS_BRANCH_H__
4395 +#define __AUFS_BRANCH_H__
4399 +#include <linux/mount.h>
4400 +#include "dirren.h"
4406 +/* ---------------------------------------------------------------------- */
4410 + struct file **xi_file;
4411 + unsigned int xi_nfile;
4417 + /* reserved for future use */
4418 + /* unsigned long *bitmap; */
4419 + wait_queue_head_t wqh;
4422 + struct mutex xi_mtx; /* protects xi_file array */
4423 + struct hlist_bl_head xi_writing;
4425 + atomic_t xi_truncating;
4427 + struct kref xi_kref;
4430 +/* File-based Hierarchical Storage Management */
4431 +struct au_br_fhsm {
4432 +#ifdef CONFIG_AUFS_FHSM
4433 + struct mutex bf_lock;
4434 + unsigned long bf_jiffy;
4435 + struct aufs_stfs bf_stfs;
4440 +/* members for writable branch only */
4441 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4443 + struct au_rwsem wbr_wh_rwsem;
4444 + struct dentry *wbr_wh[AuBrWh_Last];
4445 + atomic_t wbr_wh_running;
4446 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4447 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4448 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4451 + unsigned long long wbr_bytes;
4454 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4455 +#define AuBrDynOp (AuDyLast * 4)
4457 +#ifdef CONFIG_AUFS_HFSNOTIFY
4458 +/* support for asynchronous destruction */
4459 +struct au_br_hfsnotify {
4460 + struct fsnotify_group *hfsn_group;
4464 +/* sysfs entries */
4465 +struct au_brsysfs {
4467 + struct attribute attr;
4476 +/* protected by superblock rwsem */
4478 + struct au_xino *br_xino;
4480 + aufs_bindex_t br_id;
4483 + struct path br_path;
4484 + spinlock_t br_dykey_lock;
4485 + struct au_dykey *br_dykey[AuBrDynOp];
4486 + au_lcnt_t br_nfiles; /* opened files */
4487 + au_lcnt_t br_count; /* in-use for other */
4489 + struct au_wbr *br_wbr;
4490 + struct au_br_fhsm *br_fhsm;
4492 +#ifdef CONFIG_AUFS_HFSNOTIFY
4493 + struct au_br_hfsnotify *br_hfsn;
4496 +#ifdef CONFIG_SYSFS
4497 + /* entries under sysfs per mount-point */
4498 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4501 +#ifdef CONFIG_DEBUG_FS
4502 + struct dentry *br_dbgaufs; /* xino */
4505 + struct au_dr_br br_dirren;
4508 +/* ---------------------------------------------------------------------- */
4510 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4512 + return br->br_path.mnt;
4515 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4517 + return br->br_path.dentry;
4520 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4522 + return mnt_user_ns(br->br_path.mnt);
4525 +static inline struct super_block *au_br_sb(struct au_branch *br)
4527 + return au_br_mnt(br)->mnt_sb;
4530 +static inline int au_br_rdonly(struct au_branch *br)
4532 + return (sb_rdonly(au_br_sb(br))
4533 + || !au_br_writable(br->br_perm))
4537 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4539 +#ifdef CONFIG_AUFS_HNOTIFY
4540 + return !(brperm & AuBrPerm_RR);
4546 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4548 + int err, exec_flag;
4551 + exec_flag = oflag & __FMODE_EXEC;
4552 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4558 +static inline void au_xino_get(struct au_branch *br)
4560 + struct au_xino *xi;
4564 + kref_get(&xi->xi_kref);
4567 +static inline int au_xino_count(struct au_branch *br)
4570 + struct au_xino *xi;
4575 + v = kref_read(&xi->xi_kref);
4580 +/* ---------------------------------------------------------------------- */
4584 +void au_br_free(struct au_sbinfo *sinfo);
4585 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4587 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4589 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4590 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4591 +#ifdef CONFIG_COMPAT
4592 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4595 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4598 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4601 +static const loff_t au_loff_max = LLONG_MAX;
4603 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4604 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4606 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4607 + struct file *copy_src);
4609 + struct au_xino *xi; /* switch between xino and xigen */
4611 + struct path *base;
4612 + struct file *copy_src;
4614 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4616 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4618 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4620 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4621 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4623 +int au_xib_trunc(struct super_block *sb);
4624 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4626 +struct au_xino *au_xino_alloc(unsigned int nfile);
4627 +int au_xino_put(struct au_branch *br);
4628 +struct file *au_xino_file1(struct au_xino *xi);
4630 +struct au_opt_xino;
4631 +void au_xino_clr(struct super_block *sb);
4632 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4633 +struct file *au_xino_def(struct super_block *sb);
4634 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4635 + struct path *base);
4637 +ino_t au_xino_new_ino(struct super_block *sb);
4638 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4640 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4641 + ino_t h_ino, int idx);
4642 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4645 +int au_xino_path(struct seq_file *seq, struct file *file);
4647 +/* ---------------------------------------------------------------------- */
4649 +/* @idx is signed to accept -1 meaning the first file */
4650 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4652 + struct file *file;
4659 + if (idx < xi->xi_nfile)
4660 + file = xi->xi_file[idx];
4662 + file = au_xino_file1(xi);
4668 +/* ---------------------------------------------------------------------- */
4670 +/* Superblock to branch */
4672 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4674 + return au_sbr(sb, bindex)->br_id;
4678 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4680 + return au_br_mnt(au_sbr(sb, bindex));
4684 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4686 + return au_br_userns(au_sbr(sb, bindex));
4690 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4692 + return au_br_sb(au_sbr(sb, bindex));
4695 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4697 + return au_sbr(sb, bindex)->br_perm;
4700 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4702 + return au_br_whable(au_sbr_perm(sb, bindex));
4705 +/* ---------------------------------------------------------------------- */
4707 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4708 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4709 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4710 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4712 +#define wbr_wh_read_trylock_nested(wbr) \
4713 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4714 +#define wbr_wh_write_trylock_nested(wbr) \
4715 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4718 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4719 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4720 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4722 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4723 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4724 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4726 +/* ---------------------------------------------------------------------- */
4728 +#ifdef CONFIG_AUFS_FHSM
4729 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4731 + mutex_init(&brfhsm->bf_lock);
4732 + brfhsm->bf_jiffy = 0;
4733 + brfhsm->bf_readable = 0;
4736 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4738 + mutex_destroy(&brfhsm->bf_lock);
4741 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4742 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4745 +#endif /* __KERNEL__ */
4746 +#endif /* __AUFS_BRANCH_H__ */
4747 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4748 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4749 +++ linux/fs/aufs/conf.mk 2021-05-02 20:15:14.670004120 +0200
4751 +# SPDX-License-Identifier: GPL-2.0
4753 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4757 +AuConfStr += ${1}=${${1}}
4761 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4763 + HNOTIFY HFSNOTIFY \
4775 +$(foreach i, ${AuConfAll}, \
4776 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4778 +AuConfName = ${obj}/conf.str
4779 +${AuConfName}.tmp: FORCE
4780 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4781 +${AuConfName}: ${AuConfName}.tmp
4782 + @diff -q $< $@ > /dev/null 2>&1 || { \
4783 + echo ' GEN ' $@; \
4787 +clean-files += ${AuConfName} ${AuConfName}.tmp
4788 +${obj}/sysfs.o: ${AuConfName}
4790 +-include ${srctree}/${src}/conf_priv.mk
4791 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4792 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4793 +++ linux/fs/aufs/cpup.c 2021-05-02 20:15:14.673337458 +0200
4795 +// SPDX-License-Identifier: GPL-2.0
4797 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4799 + * This program, aufs is free software; you can redistribute it and/or modify
4800 + * it under the terms of the GNU General Public License as published by
4801 + * the Free Software Foundation; either version 2 of the License, or
4802 + * (at your option) any later version.
4804 + * This program is distributed in the hope that it will be useful,
4805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4807 + * GNU General Public License for more details.
4809 + * You should have received a copy of the GNU General Public License
4810 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4814 + * copy-up functions, see wbr_policy.c for copy-down
4817 +#include <linux/fs_stack.h>
4818 +#include <linux/mm.h>
4819 +#include <linux/task_work.h>
4822 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4824 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4825 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4827 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4829 + dst->i_flags |= iflags & ~mask;
4830 + if (au_test_fs_notime(dst->i_sb))
4831 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4834 +void au_cpup_attr_timesizes(struct inode *inode)
4836 + struct inode *h_inode;
4838 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4839 + fsstack_copy_attr_times(inode, h_inode);
4840 + fsstack_copy_inode_size(inode, h_inode);
4843 +void au_cpup_attr_nlink(struct inode *inode, int force)
4845 + struct inode *h_inode;
4846 + struct super_block *sb;
4847 + aufs_bindex_t bindex, bbot;
4850 + bindex = au_ibtop(inode);
4851 + h_inode = au_h_iptr(inode, bindex);
4853 + && !S_ISDIR(h_inode->i_mode)
4854 + && au_opt_test(au_mntflags(sb), PLINK)
4855 + && au_plink_test(inode))
4859 + * 0 can happen in revalidating.
4860 + * h_inode->i_mutex may not be held here, but it is harmless since once
4861 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4863 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4864 + * the incorrect link count.
4866 + set_nlink(inode, h_inode->i_nlink);
4869 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4870 + * it may includes whplink directory.
4872 + if (S_ISDIR(h_inode->i_mode)) {
4873 + bbot = au_ibbot(inode);
4874 + for (bindex++; bindex <= bbot; bindex++) {
4875 + h_inode = au_h_iptr(inode, bindex);
4877 + au_add_nlink(inode, h_inode);
4882 +void au_cpup_attr_changeable(struct inode *inode)
4884 + struct inode *h_inode;
4886 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4887 + inode->i_mode = h_inode->i_mode;
4888 + inode->i_uid = h_inode->i_uid;
4889 + inode->i_gid = h_inode->i_gid;
4890 + au_cpup_attr_timesizes(inode);
4891 + au_cpup_attr_flags(inode, h_inode->i_flags);
4894 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4896 + struct au_iinfo *iinfo = au_ii(inode);
4898 + IiMustWriteLock(inode);
4900 + iinfo->ii_higen = h_inode->i_generation;
4901 + iinfo->ii_hsb1 = h_inode->i_sb;
4904 +void au_cpup_attr_all(struct inode *inode, int force)
4906 + struct inode *h_inode;
4908 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4909 + au_cpup_attr_changeable(inode);
4910 + if (inode->i_nlink > 0)
4911 + au_cpup_attr_nlink(inode, force);
4912 + inode->i_rdev = h_inode->i_rdev;
4913 + inode->i_blkbits = h_inode->i_blkbits;
4914 + au_cpup_igen(inode, h_inode);
4917 +/* ---------------------------------------------------------------------- */
4919 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4921 +/* keep the timestamps of the parent dir when cpup */
4922 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4923 + struct path *h_path)
4925 + struct inode *h_inode;
4927 + dt->dt_dentry = dentry;
4928 + dt->dt_h_path = *h_path;
4929 + h_inode = d_inode(h_path->dentry);
4930 + dt->dt_atime = h_inode->i_atime;
4931 + dt->dt_mtime = h_inode->i_mtime;
4935 +void au_dtime_revert(struct au_dtime *dt)
4937 + struct iattr attr;
4940 + attr.ia_atime = dt->dt_atime;
4941 + attr.ia_mtime = dt->dt_mtime;
4942 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4943 + | ATTR_ATIME | ATTR_ATIME_SET;
4945 + /* no delegation since this is a directory */
4946 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4947 + if (unlikely(err))
4948 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4951 +/* ---------------------------------------------------------------------- */
4953 +/* internal use only */
4954 +struct au_cpup_reg_attr {
4957 + unsigned int iflags; /* inode->i_flags */
4960 +static noinline_for_stack
4961 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4962 + struct au_cpup_reg_attr *h_src_attr)
4964 + int err, sbits, icex;
4965 + unsigned int mnt_flags;
4966 + unsigned char verbose;
4968 + struct path h_path;
4969 + struct inode *h_isrc, *h_idst;
4970 + struct kstat *h_st;
4971 + struct au_branch *br;
4973 + br = au_sbr(dst->d_sb, bindex);
4974 + h_path.mnt = au_br_mnt(br);
4975 + h_path.dentry = au_h_dptr(dst, bindex);
4976 + h_idst = d_inode(h_path.dentry);
4977 + h_isrc = d_inode(h_src->dentry);
4978 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4979 + | ATTR_ATIME | ATTR_MTIME
4980 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4981 + if (h_src_attr && h_src_attr->valid) {
4982 + h_st = &h_src_attr->st;
4983 + ia.ia_uid = h_st->uid;
4984 + ia.ia_gid = h_st->gid;
4985 + ia.ia_atime = h_st->atime;
4986 + ia.ia_mtime = h_st->mtime;
4987 + if (h_idst->i_mode != h_st->mode
4988 + && !S_ISLNK(h_idst->i_mode)) {
4989 + ia.ia_valid |= ATTR_MODE;
4990 + ia.ia_mode = h_st->mode;
4992 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4993 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4995 + ia.ia_uid = h_isrc->i_uid;
4996 + ia.ia_gid = h_isrc->i_gid;
4997 + ia.ia_atime = h_isrc->i_atime;
4998 + ia.ia_mtime = h_isrc->i_mtime;
4999 + if (h_idst->i_mode != h_isrc->i_mode
5000 + && !S_ISLNK(h_idst->i_mode)) {
5001 + ia.ia_valid |= ATTR_MODE;
5002 + ia.ia_mode = h_isrc->i_mode;
5004 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5005 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5007 + /* no delegation since it is just created */
5008 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5010 + /* is this nfs only? */
5011 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5012 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5013 + ia.ia_mode = h_isrc->i_mode;
5014 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5017 + icex = br->br_perm & AuBrAttr_ICEX;
5019 + mnt_flags = au_mntflags(dst->d_sb);
5020 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5021 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
5027 +/* ---------------------------------------------------------------------- */
5029 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5030 + char *buf, unsigned long blksize)
5033 + size_t sz, rbytes, wbytes;
5034 + unsigned char all_zero;
5036 + struct inode *h_inode;
5037 + /* reduce stack usage */
5040 + zp = page_address(ZERO_PAGE(0));
5041 + if (unlikely(!zp))
5042 + return -ENOMEM; /* possible? */
5047 + AuDbg("len %lld\n", len);
5049 + if (len < blksize)
5053 + /* todo: signal_pending? */
5054 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5055 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5058 + if (unlikely(err < 0))
5062 + if (len >= rbytes && rbytes == blksize)
5063 + all_zero = !memcmp(buf, zp, rbytes);
5070 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5072 + /* todo: signal_pending? */
5073 + if (unlikely(err == -EAGAIN || err == -EINTR))
5075 + if (unlikely(err < 0))
5080 + if (unlikely(err < 0))
5086 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5088 + if (unlikely(res < 0))
5095 + /* the last block may be a hole */
5096 + if (!err && all_zero) {
5097 + AuLabel(last hole);
5100 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5101 + /* nfs requires this step to make last hole */
5102 + /* is this only nfs? */
5104 + /* todo: signal_pending? */
5105 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5106 + } while (err == -EAGAIN || err == -EINTR);
5113 + ia->ia_size = dst->f_pos;
5114 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5115 + ia->ia_file = dst;
5116 + h_inode = file_inode(dst);
5117 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5118 + /* no delegation since it is just created */
5119 + err = vfsub_notify_change(&dst->f_path, ia,
5120 + /*delegated*/NULL);
5121 + inode_unlock(h_inode);
5128 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5131 + unsigned long blksize;
5132 + unsigned char do_kfree;
5134 + struct super_block *h_sb;
5137 + h_sb = file_inode(dst)->i_sb;
5138 + blksize = h_sb->s_blocksize;
5139 + if (!blksize || PAGE_SIZE < blksize)
5140 + blksize = PAGE_SIZE;
5141 + AuDbg("blksize %lu\n", blksize);
5142 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5144 + buf = kmalloc(blksize, GFP_NOFS);
5146 + buf = (void *)__get_free_page(GFP_NOFS);
5147 + if (unlikely(!buf))
5150 + if (len > (1 << 22))
5151 + AuDbg("copying a large file %lld\n", (long long)len);
5155 + err = au_do_copy_file(dst, src, len, buf, blksize);
5157 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5158 + au_kfree_do_rcu(buf);
5160 + free_page((unsigned long)buf);
5166 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5169 + struct super_block *h_src_sb;
5170 + struct inode *h_src_inode;
5172 + h_src_inode = file_inode(src);
5173 + h_src_sb = h_src_inode->i_sb;
5175 + /* XFS acquires inode_lock */
5176 + if (!au_test_xfs(h_src_sb))
5177 + err = au_copy_file(dst, src, len);
5179 + inode_unlock_shared(h_src_inode);
5180 + err = au_copy_file(dst, src, len);
5181 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5187 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5191 + struct super_block *h_src_sb;
5192 + struct inode *h_src_inode;
5194 + h_src_inode = file_inode(src);
5195 + h_src_sb = h_src_inode->i_sb;
5196 + if (h_src_sb != file_inode(dst)->i_sb
5197 + || !dst->f_op->remap_file_range) {
5198 + err = au_do_copy(dst, src, len);
5202 + if (!au_test_nfs(h_src_sb)) {
5203 + inode_unlock_shared(h_src_inode);
5204 + lo = vfsub_clone_file_range(src, dst, len);
5205 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5207 + lo = vfsub_clone_file_range(src, dst, len);
5210 + goto out; /* success */
5211 + } else if (lo >= 0)
5212 + /* todo: possible? */
5213 + /* paritially succeeded */
5214 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5215 + else if (lo != -EOPNOTSUPP) {
5216 + /* older XFS has a condition in cloning */
5221 + /* the backend fs on NFS may not support cloning */
5222 + err = au_do_copy(dst, src, len);
5230 + * to support a sparse file which is opened with O_APPEND,
5231 + * we need to close the file.
5233 +static int au_cp_regular(struct au_cp_generic *cpg)
5236 + enum { SRC, DST };
5238 + aufs_bindex_t bindex;
5239 + unsigned int flags;
5240 + struct dentry *dentry;
5242 + struct file *file;
5245 + .bindex = cpg->bsrc,
5246 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5249 + .bindex = cpg->bdst,
5250 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5251 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5254 + struct au_branch *br;
5255 + struct super_block *sb, *h_src_sb;
5256 + struct inode *h_src_inode;
5257 + struct task_struct *tsk = current;
5259 + /* bsrc branch can be ro/rw. */
5260 + sb = cpg->dentry->d_sb;
5262 + for (i = 0; i < 2; i++, f++) {
5263 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5264 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5265 + /*file*/NULL, f->force_wr);
5266 + if (IS_ERR(f->file)) {
5267 + err = PTR_ERR(f->file);
5275 + /* try stopping to update while we copyup */
5276 + h_src_inode = d_inode(file[SRC].dentry);
5277 + h_src_sb = h_src_inode->i_sb;
5278 + if (!au_test_nfs(h_src_sb))
5279 + IMustLock(h_src_inode);
5280 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5282 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5283 + if (tsk->flags & PF_KTHREAD)
5284 + __fput_sync(file[DST].file);
5286 + /* it happened actually */
5287 + fput(file[DST].file);
5290 + * we have to call both since we don't know which place the file
5294 + flush_delayed_fput();
5296 + br = au_sbr(sb, file[DST].bindex);
5297 + au_lcnt_dec(&br->br_nfiles);
5300 + fput(file[SRC].file);
5301 + br = au_sbr(sb, file[SRC].bindex);
5302 + au_lcnt_dec(&br->br_nfiles);
5307 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5308 + struct au_cpup_reg_attr *h_src_attr)
5312 + struct path h_path;
5313 + struct inode *h_src_inode, *h_dst_inode;
5316 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5317 + l = i_size_read(h_src_inode);
5318 + if (cpg->len == -1 || l < cpg->len)
5321 + /* try stopping to update while we are referencing */
5322 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5323 + au_pin_hdir_unlock(cpg->pin);
5325 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5326 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5327 + h_src_attr->iflags = h_src_inode->i_flags;
5328 + if (!au_test_nfs(h_src_inode->i_sb))
5329 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5331 + inode_unlock_shared(h_src_inode);
5332 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5333 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5335 + if (unlikely(err)) {
5336 + inode_unlock_shared(h_src_inode);
5339 + h_src_attr->valid = 1;
5340 + if (!au_test_nfs(h_src_inode->i_sb)) {
5341 + err = au_cp_regular(cpg);
5342 + inode_unlock_shared(h_src_inode);
5344 + inode_unlock_shared(h_src_inode);
5345 + err = au_cp_regular(cpg);
5347 + rerr = au_pin_hdir_relock(cpg->pin);
5351 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5352 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5353 + h_dst_inode = d_inode(h_path.dentry);
5354 + spin_lock(&h_dst_inode->i_lock);
5355 + h_dst_inode->i_state |= I_LINKABLE;
5356 + spin_unlock(&h_dst_inode->i_lock);
5363 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5364 + struct inode *h_dir)
5367 + DEFINE_DELAYED_CALL(done);
5370 + sym = vfs_get_link(h_src, &done);
5371 + err = PTR_ERR(sym);
5375 + err = vfsub_symlink(h_dir, h_path, sym);
5378 + do_delayed_call(&done);
5383 + * regardless 'acl' option, reset all ACL.
5384 + * All ACL will be copied up later from the original entry on the lower branch.
5386 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5389 + struct dentry *h_dentry;
5390 + struct inode *h_inode;
5391 + struct user_namespace *h_userns;
5393 + h_userns = mnt_user_ns(h_path->mnt);
5394 + h_dentry = h_path->dentry;
5395 + h_inode = d_inode(h_dentry);
5396 + /* forget_all_cached_acls(h_inode)); */
5397 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5399 + if (err == -EOPNOTSUPP)
5402 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5408 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5409 + struct inode *h_dir, struct path *h_path)
5412 + struct inode *dir, *inode;
5413 + struct user_namespace *h_userns;
5415 + h_userns = mnt_user_ns(h_path->mnt);
5416 + err = vfsub_removexattr(h_userns, h_path->dentry,
5417 + XATTR_NAME_POSIX_ACL_DEFAULT);
5419 + if (err == -EOPNOTSUPP)
5421 + if (unlikely(err))
5425 + * strange behaviour from the users view,
5426 + * particularly setattr case
5428 + dir = d_inode(dst_parent);
5429 + if (au_ibtop(dir) == cpg->bdst)
5430 + au_cpup_attr_nlink(dir, /*force*/1);
5431 + inode = d_inode(cpg->dentry);
5432 + au_cpup_attr_nlink(inode, /*force*/1);
5438 +static noinline_for_stack
5439 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5440 + struct au_cpup_reg_attr *h_src_attr)
5444 + unsigned int mnt_flags;
5445 + unsigned char isdir, isreg, force;
5446 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5447 + struct au_dtime dt;
5448 + struct path h_path;
5449 + struct dentry *h_src, *h_dst, *h_parent;
5450 + struct inode *h_inode, *h_dir;
5451 + struct super_block *sb;
5453 + /* bsrc branch can be ro/rw. */
5454 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5455 + h_inode = d_inode(h_src);
5456 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5458 + /* try stopping to be referenced while we are creating */
5459 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5460 + if (au_ftest_cpup(cpg->flags, RENAME))
5461 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5462 + AUFS_WH_PFX_LEN));
5463 + h_parent = h_dst->d_parent; /* dir inode is locked */
5464 + h_dir = d_inode(h_parent);
5466 + AuDebugOn(h_parent != h_dst->d_parent);
5468 + sb = cpg->dentry->d_sb;
5469 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5471 + h_path.dentry = h_parent;
5472 + au_dtime_store(&dt, dst_parent, &h_path);
5474 + h_path.dentry = h_dst;
5478 + mode = h_inode->i_mode;
5479 + switch (mode & S_IFMT) {
5482 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5484 + err = au_do_cpup_regular(cpg, h_src_attr);
5488 + err = vfsub_mkdir(h_dir, &h_path, mode);
5490 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5493 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5497 + AuDebugOn(!capable(CAP_MKNOD));
5501 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5504 + AuIOErr("Unknown inode type 0%o\n", mode);
5508 + err = au_reset_acl(h_dir, &h_path, mode);
5510 + mnt_flags = au_mntflags(sb);
5511 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5513 + && au_opt_test(mnt_flags, XINO)
5514 + && (h_inode->i_nlink == 1
5515 + || (h_inode->i_state & I_LINKABLE))
5516 + /* todo: unnecessary? */
5517 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5518 + && cpg->bdst < cpg->bsrc
5519 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5520 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5521 + /* ignore this error */
5526 + force = !!cpg->len;
5527 + if (cpg->len == -1)
5528 + force = !!i_size_read(h_inode);
5530 + au_fhsm_wrote(sb, cpg->bdst, force);
5534 + au_dtime_revert(&dt);
5538 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5541 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5542 + struct inode *h_dir;
5543 + aufs_bindex_t bdst;
5545 + dentry = cpg->dentry;
5547 + h_dentry = au_h_dptr(dentry, bdst);
5548 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5550 + au_set_h_dptr(dentry, bdst, NULL);
5551 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5553 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5554 + au_set_h_dptr(dentry, bdst, h_dentry);
5557 + parent = dget_parent(dentry);
5558 + h_parent = au_h_dptr(parent, bdst);
5560 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5561 + if (IS_ERR(h_path->dentry))
5562 + err = PTR_ERR(h_path->dentry);
5564 + if (unlikely(err))
5567 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5568 + h_dir = d_inode(h_parent);
5570 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5571 + /* no delegation since it is just created */
5572 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5574 + dput(h_path->dentry);
5581 + * copyup the @dentry from @bsrc to @bdst.
5582 + * the caller must set the both of lower dentries.
5583 + * @len is for truncating when it is -1 copyup the entire file.
5584 + * in link/rename cases, @dst_parent may be different from the real one.
5585 + * basic->bsrc can be larger than basic->bdst.
5586 + * aufs doesn't touch the credential so
5587 + * security_inode_copy_up{,_xattr}() are unnecessary.
5589 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5592 + aufs_bindex_t old_ibtop;
5593 + unsigned char isdir, plink;
5594 + struct dentry *h_src, *h_dst, *h_parent;
5595 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5596 + struct super_block *sb;
5597 + struct au_branch *br;
5598 + struct path h_src_path;
5599 + /* to reduce stack size */
5601 + struct au_dtime dt;
5602 + struct path h_path;
5603 + struct au_cpup_reg_attr h_src_attr;
5607 + a = kmalloc(sizeof(*a), GFP_NOFS);
5610 + a->h_src_attr.valid = 0;
5612 + sb = cpg->dentry->d_sb;
5613 + br = au_sbr(sb, cpg->bdst);
5614 + a->h_path.mnt = au_br_mnt(br);
5615 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5616 + h_parent = h_dst->d_parent; /* dir inode is locked */
5617 + h_dir = d_inode(h_parent);
5620 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5621 + inode = d_inode(cpg->dentry);
5624 + dst_parent = dget_parent(cpg->dentry);
5628 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5629 + dst_inode = au_h_iptr(inode, cpg->bdst);
5631 + if (unlikely(!plink)) {
5633 + AuIOErr("hi%lu(i%lu) exists on b%d "
5634 + "but plink is disabled\n",
5635 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5639 + if (dst_inode->i_nlink) {
5640 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5642 + h_src = au_plink_lkup(inode, cpg->bdst);
5643 + err = PTR_ERR(h_src);
5644 + if (IS_ERR(h_src))
5646 + if (unlikely(d_is_negative(h_src))) {
5648 + AuIOErr("i%lu exists on b%d "
5649 + "but not pseudo-linked\n",
5650 + inode->i_ino, cpg->bdst);
5656 + a->h_path.dentry = h_parent;
5657 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5660 + a->h_path.dentry = h_dst;
5662 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5663 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5664 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5666 + au_dtime_revert(&a->dt);
5667 + if (unlikely(err == -EWOULDBLOCK)) {
5668 + pr_warn("cannot retry for NFSv4 delegation"
5669 + " for an internal link\n");
5675 + /* todo: cpup_wh_file? */
5677 + au_update_ibrange(inode, /*do_put_zero*/1);
5680 + isdir = S_ISDIR(inode->i_mode);
5681 + old_ibtop = au_ibtop(inode);
5682 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5683 + if (unlikely(err))
5685 + dst_inode = d_inode(h_dst);
5686 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5687 + /* todo: necessary? */
5688 + /* au_pin_hdir_unlock(cpg->pin); */
5690 + h_src_path.dentry = h_src;
5691 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5692 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5693 + if (unlikely(err)) {
5694 + /* todo: necessary? */
5695 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5696 + inode_unlock(dst_inode);
5700 + if (cpg->bdst < old_ibtop) {
5701 + if (S_ISREG(inode->i_mode)) {
5702 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5703 + if (unlikely(err)) {
5704 + /* ignore an error */
5705 + /* au_pin_hdir_relock(cpg->pin); */
5706 + inode_unlock(dst_inode);
5710 + au_set_ibtop(inode, cpg->bdst);
5712 + au_set_ibbot(inode, cpg->bdst);
5713 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5714 + au_hi_flags(inode, isdir));
5716 + /* todo: necessary? */
5717 + /* err = au_pin_hdir_relock(cpg->pin); */
5718 + inode_unlock(dst_inode);
5719 + if (unlikely(err))
5722 + src_inode = d_inode(h_src);
5724 + && (src_inode->i_nlink > 1
5725 + || src_inode->i_state & I_LINKABLE)
5727 + au_plink_append(inode, cpg->bdst, h_dst);
5729 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5730 + a->h_path.dentry = h_dst;
5731 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5734 + goto out_parent; /* success */
5738 + a->h_path.dentry = h_parent;
5739 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5740 + a->h_path.dentry = h_dst;
5742 + if (d_is_positive(h_dst)) {
5744 + /* no delegation since it is just created */
5745 + rerr = vfsub_unlink(h_dir, &a->h_path,
5746 + /*delegated*/NULL, /*force*/0);
5748 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5750 + au_dtime_revert(&a->dt);
5752 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5762 +#if 0 /* reserved */
5763 +struct au_cpup_single_args {
5765 + struct au_cp_generic *cpg;
5766 + struct dentry *dst_parent;
5769 +static void au_call_cpup_single(void *args)
5771 + struct au_cpup_single_args *a = args;
5773 + au_pin_hdir_acquire_nest(a->cpg->pin);
5774 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5775 + au_pin_hdir_release(a->cpg->pin);
5780 + * prevent SIGXFSZ in copy-up.
5781 + * testing CAP_MKNOD is for generic fs,
5782 + * but CAP_FSETID is for xfs only, currently.
5784 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5787 + struct super_block *sb;
5788 + struct inode *h_dir;
5791 + sb = au_pinned_parent(pin)->d_sb;
5792 + if (!au_wkq_test()
5793 + && (!au_sbi(sb)->si_plink_maint_pid
5794 + || au_plink_maint(sb, AuLock_NOPLM))) {
5795 + switch (mode & S_IFMT) {
5797 + /* no condition about RLIMIT_FSIZE and the file size */
5802 + do_sio = !capable(CAP_MKNOD);
5806 + do_sio = ((mode & (S_ISUID | S_ISGID))
5807 + && !capable(CAP_FSETID));
5808 + /* this workaround may be removed in the future */
5810 + h_dir = au_pinned_h_dir(pin);
5811 + do_sio = h_dir->i_mode & S_ISVTX;
5818 +#if 0 /* reserved */
5819 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5822 + struct dentry *h_dentry;
5824 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5825 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5826 + err = au_cpup_single(cpg, dst_parent);
5828 + struct au_cpup_single_args args = {
5831 + .dst_parent = dst_parent
5833 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5834 + if (unlikely(wkq_err))
5843 + * copyup the @dentry from the first active lower branch to @bdst,
5844 + * using au_cpup_single().
5846 +static int au_cpup_simple(struct au_cp_generic *cpg)
5849 + unsigned int flags_orig;
5850 + struct dentry *dentry;
5852 + AuDebugOn(cpg->bsrc < 0);
5854 + dentry = cpg->dentry;
5855 + DiMustWriteLock(dentry);
5857 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5859 + flags_orig = cpg->flags;
5860 + au_fset_cpup(cpg->flags, RENAME);
5861 + err = au_cpup_single(cpg, NULL);
5862 + cpg->flags = flags_orig;
5864 + return 0; /* success */
5867 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5868 + au_set_dbtop(dentry, cpg->bsrc);
5874 +struct au_cpup_simple_args {
5876 + struct au_cp_generic *cpg;
5879 +static void au_call_cpup_simple(void *args)
5881 + struct au_cpup_simple_args *a = args;
5883 + au_pin_hdir_acquire_nest(a->cpg->pin);
5884 + *a->errp = au_cpup_simple(a->cpg);
5885 + au_pin_hdir_release(a->cpg->pin);
5888 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5891 + struct dentry *dentry, *parent;
5892 + struct file *h_file;
5893 + struct inode *h_dir;
5894 + struct user_namespace *h_userns;
5896 + dentry = cpg->dentry;
5898 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5899 + AuDebugOn(cpg->bsrc < 0);
5900 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5901 + err = PTR_ERR(h_file);
5902 + if (IS_ERR(h_file))
5906 + parent = dget_parent(dentry);
5907 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5908 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5909 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5910 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5911 + err = au_cpup_simple(cpg);
5913 + struct au_cpup_simple_args args = {
5917 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5918 + if (unlikely(wkq_err))
5924 + au_h_open_post(dentry, cpg->bsrc, h_file);
5930 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5932 + aufs_bindex_t bsrc, bbot;
5933 + struct dentry *dentry, *h_dentry;
5935 + if (cpg->bsrc < 0) {
5936 + dentry = cpg->dentry;
5937 + bbot = au_dbbot(dentry);
5938 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5939 + h_dentry = au_h_dptr(dentry, bsrc);
5941 + AuDebugOn(d_is_negative(h_dentry));
5945 + AuDebugOn(bsrc > bbot);
5948 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5949 + return au_do_sio_cpup_simple(cpg);
5952 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5954 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5955 + return au_do_sio_cpup_simple(cpg);
5958 +/* ---------------------------------------------------------------------- */
5961 + * copyup the deleted file for writing.
5963 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5964 + struct file *file)
5967 + unsigned int flags_orig;
5968 + aufs_bindex_t bsrc_orig;
5969 + struct au_dinfo *dinfo;
5971 + struct au_hdentry *hd;
5972 + struct dentry *h_dentry;
5975 + dinfo = au_di(cpg->dentry);
5976 + AuRwMustWriteLock(&dinfo->di_rwsem);
5978 + bsrc_orig = cpg->bsrc;
5979 + cpg->bsrc = dinfo->di_btop;
5980 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5981 + hdst.h_dentry = hdst.hd->hd_dentry;
5982 + hdst.hd->hd_dentry = wh_dentry;
5983 + dinfo->di_btop = cpg->bdst;
5985 + hsrc.h_dentry = NULL;
5987 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5988 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5989 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5991 + flags_orig = cpg->flags;
5992 + cpg->flags = !AuCpup_DTIME;
5993 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5994 + cpg->flags = flags_orig;
5997 + err = au_reopen_nondir(file);
5998 + hsrc.hd->hd_dentry = hsrc.h_dentry;
6000 + hdst.hd->hd_dentry = hdst.h_dentry;
6001 + dinfo->di_btop = cpg->bsrc;
6002 + cpg->bsrc = bsrc_orig;
6007 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6010 + aufs_bindex_t bdst;
6011 + struct au_dtime dt;
6012 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6013 + struct au_branch *br;
6014 + struct path h_path;
6016 + dentry = cpg->dentry;
6018 + br = au_sbr(dentry->d_sb, bdst);
6019 + parent = dget_parent(dentry);
6020 + h_parent = au_h_dptr(parent, bdst);
6021 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6022 + err = PTR_ERR(wh_dentry);
6023 + if (IS_ERR(wh_dentry))
6026 + h_path.dentry = h_parent;
6027 + h_path.mnt = au_br_mnt(br);
6028 + au_dtime_store(&dt, parent, &h_path);
6029 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6030 + if (unlikely(err))
6034 + h_path.dentry = wh_dentry;
6035 + if (!d_is_dir(wh_dentry)) {
6036 + /* no delegation since it is just created */
6037 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6038 + /*delegated*/NULL, /*force*/0);
6040 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6041 + if (unlikely(err)) {
6042 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6046 + au_dtime_revert(&dt);
6047 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6056 +struct au_cpup_wh_args {
6058 + struct au_cp_generic *cpg;
6059 + struct file *file;
6062 +static void au_call_cpup_wh(void *args)
6064 + struct au_cpup_wh_args *a = args;
6066 + au_pin_hdir_acquire_nest(a->cpg->pin);
6067 + *a->errp = au_cpup_wh(a->cpg, a->file);
6068 + au_pin_hdir_release(a->cpg->pin);
6071 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6074 + aufs_bindex_t bdst;
6075 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6076 + struct inode *dir, *h_dir, *h_tmpdir;
6077 + struct au_wbr *wbr;
6078 + struct au_pin wh_pin, *pin_orig;
6079 + struct user_namespace *h_userns;
6081 + dentry = cpg->dentry;
6083 + parent = dget_parent(dentry);
6084 + dir = d_inode(parent);
6087 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6090 + if (!h_dir->i_nlink) {
6091 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6092 + h_orph = wbr->wbr_orph;
6094 + h_parent = dget(au_h_dptr(parent, bdst));
6095 + au_set_h_dptr(parent, bdst, dget(h_orph));
6096 + h_tmpdir = d_inode(h_orph);
6097 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6099 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6100 + /* todo: au_h_open_pre()? */
6102 + pin_orig = cpg->pin;
6103 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6104 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6105 + cpg->pin = &wh_pin;
6108 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6109 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6110 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6111 + err = au_cpup_wh(cpg, file);
6113 + struct au_cpup_wh_args args = {
6118 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6119 + if (unlikely(wkq_err))
6124 + inode_unlock(h_tmpdir);
6125 + /* todo: au_h_open_post()? */
6126 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6127 + au_set_h_dptr(parent, bdst, h_parent);
6128 + AuDebugOn(!pin_orig);
6129 + cpg->pin = pin_orig;
6137 +/* ---------------------------------------------------------------------- */
6140 + * generic routine for both of copy-up and copy-down.
6142 +/* cf. revalidate function in file.c */
6143 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6144 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6145 + struct au_pin *pin,
6146 + struct dentry *h_parent, void *arg),
6150 + struct au_pin pin;
6151 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6154 + parent = dget_parent(dentry);
6155 + if (IS_ROOT(parent))
6158 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6159 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6161 + /* do not use au_dpage */
6162 + real_parent = parent;
6165 + parent = dget_parent(dentry);
6166 + h_parent = au_h_dptr(parent, bdst);
6168 + goto out; /* success */
6170 + /* find top dir which is necessary to cpup */
6174 + parent = dget_parent(d);
6175 + di_read_lock_parent3(parent, !AuLock_IR);
6176 + h_parent = au_h_dptr(parent, bdst);
6177 + di_read_unlock(parent, !AuLock_IR);
6178 + } while (!h_parent);
6180 + if (d != real_parent)
6181 + di_write_lock_child3(d);
6183 + /* somebody else might create while we were sleeping */
6184 + h_dentry = au_h_dptr(d, bdst);
6185 + if (!h_dentry || d_is_negative(h_dentry)) {
6187 + au_update_dbtop(d);
6189 + au_pin_set_dentry(&pin, d);
6190 + err = au_do_pin(&pin);
6192 + err = cp(d, bdst, &pin, h_parent, arg);
6197 + if (d != real_parent)
6198 + di_write_unlock(d);
6199 + if (unlikely(err))
6208 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6209 + struct au_pin *pin,
6210 + struct dentry *h_parent __maybe_unused,
6211 + void *arg __maybe_unused)
6213 + struct au_cp_generic cpg = {
6219 + .flags = AuCpup_DTIME
6221 + return au_sio_cpup_simple(&cpg);
6224 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6226 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6229 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6232 + struct dentry *parent;
6233 + struct inode *dir;
6235 + parent = dget_parent(dentry);
6236 + dir = d_inode(parent);
6238 + if (au_h_iptr(dir, bdst))
6241 + di_read_unlock(parent, AuLock_IR);
6242 + di_write_lock_parent(parent);
6243 + /* someone else might change our inode while we were sleeping */
6244 + if (!au_h_iptr(dir, bdst))
6245 + err = au_cpup_dirs(dentry, bdst);
6246 + di_downgrade_lock(parent, AuLock_IR);
6252 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6253 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6254 +++ linux/fs/aufs/cpup.h 2021-05-02 20:15:14.673337458 +0200
6256 +/* SPDX-License-Identifier: GPL-2.0 */
6258 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6260 + * This program, aufs is free software; you can redistribute it and/or modify
6261 + * it under the terms of the GNU General Public License as published by
6262 + * the Free Software Foundation; either version 2 of the License, or
6263 + * (at your option) any later version.
6265 + * This program is distributed in the hope that it will be useful,
6266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6268 + * GNU General Public License for more details.
6270 + * You should have received a copy of the GNU General Public License
6271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6275 + * copy-up/down functions
6278 +#ifndef __AUFS_CPUP_H__
6279 +#define __AUFS_CPUP_H__
6283 +#include <linux/path.h>
6289 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6290 +void au_cpup_attr_timesizes(struct inode *inode);
6291 +void au_cpup_attr_nlink(struct inode *inode, int force);
6292 +void au_cpup_attr_changeable(struct inode *inode);
6293 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6294 +void au_cpup_attr_all(struct inode *inode, int force);
6296 +/* ---------------------------------------------------------------------- */
6298 +struct au_cp_generic {
6299 + struct dentry *dentry;
6300 + aufs_bindex_t bdst, bsrc;
6302 + struct au_pin *pin;
6303 + unsigned int flags;
6307 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6308 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6310 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6311 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6313 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6315 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6316 + the branch is marked as RO */
6318 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6319 +#undef AuCpup_HOPEN
6320 +#define AuCpup_HOPEN 0
6323 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6324 +#define au_fset_cpup(flags, name) \
6325 + do { (flags) |= AuCpup_##name; } while (0)
6326 +#define au_fclr_cpup(flags, name) \
6327 + do { (flags) &= ~AuCpup_##name; } while (0)
6329 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6330 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6331 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6332 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6334 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6335 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6336 + struct au_pin *pin,
6337 + struct dentry *h_parent, void *arg),
6339 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6340 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6342 +/* ---------------------------------------------------------------------- */
6344 +/* keep timestamps when copyup */
6346 + struct dentry *dt_dentry;
6347 + struct path dt_h_path;
6348 + struct timespec64 dt_atime, dt_mtime;
6350 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6351 + struct path *h_path);
6352 +void au_dtime_revert(struct au_dtime *dt);
6354 +#endif /* __KERNEL__ */
6355 +#endif /* __AUFS_CPUP_H__ */
6356 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6357 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6358 +++ linux/fs/aufs/dbgaufs.c 2021-05-02 20:15:14.673337458 +0200
6360 +// SPDX-License-Identifier: GPL-2.0
6362 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6364 + * This program, aufs is free software; you can redistribute it and/or modify
6365 + * it under the terms of the GNU General Public License as published by
6366 + * the Free Software Foundation; either version 2 of the License, or
6367 + * (at your option) any later version.
6369 + * This program is distributed in the hope that it will be useful,
6370 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6371 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6372 + * GNU General Public License for more details.
6374 + * You should have received a copy of the GNU General Public License
6375 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6379 + * debugfs interface
6382 +#include <linux/debugfs.h>
6385 +#ifndef CONFIG_SYSFS
6386 +#error DEBUG_FS depends upon SYSFS
6389 +static struct dentry *dbgaufs;
6390 +static const mode_t dbgaufs_mode = 0444;
6392 +/* 20 is max digits length of ulong 64 */
6393 +struct dbgaufs_arg {
6399 + * common function for all XINO files
6401 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6402 + struct file *file)
6406 + p = file->private_data;
6408 + /* this is struct dbgaufs_arg */
6409 + AuDebugOn(!au_kfree_sz_test(p));
6410 + au_kfree_do_rcu(p);
6415 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6420 + struct dbgaufs_arg *p;
6423 + p = kmalloc(sizeof(*p), GFP_NOFS);
6429 + file->private_data = p;
6433 + err = vfsub_getattr(&xf->f_path, &st);
6437 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6438 + cnt, st.blocks, st.blksize,
6439 + (long long)st.size);
6441 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6442 + st.blocks, st.blksize,
6443 + (long long)st.size);
6444 + AuDebugOn(p->n >= sizeof(p->a));
6446 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6454 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6455 + size_t count, loff_t *ppos)
6457 + struct dbgaufs_arg *p;
6459 + p = file->private_data;
6460 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6463 +/* ---------------------------------------------------------------------- */
6465 +struct dbgaufs_plink_arg {
6470 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6471 + struct file *file)
6473 + free_page((unsigned long)file->private_data);
6477 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6479 + int err, i, limit;
6480 + unsigned long n, sum;
6481 + struct dbgaufs_plink_arg *p;
6482 + struct au_sbinfo *sbinfo;
6483 + struct super_block *sb;
6484 + struct hlist_bl_head *hbl;
6487 + p = (void *)get_zeroed_page(GFP_NOFS);
6492 + sbinfo = inode->i_private;
6493 + sb = sbinfo->si_sb;
6494 + si_noflush_read_lock(sb);
6495 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6496 + limit = PAGE_SIZE - sizeof(p->n);
6498 + /* the number of buckets */
6499 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6504 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6506 + n = au_hbl_count(hbl);
6509 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6512 + if (unlikely(limit <= 0))
6515 + p->a[p->n - 1] = '\n';
6517 + /* the sum of plinks */
6518 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6521 + if (unlikely(limit <= 0))
6524 +#define str "1\n0\n0\n"
6525 + p->n = sizeof(str) - 1;
6526 + strcpy(p->a, str);
6529 + si_read_unlock(sb);
6532 + file->private_data = p;
6533 + goto out; /* success */
6536 + free_page((unsigned long)p);
6541 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6542 + size_t count, loff_t *ppos)
6544 + struct dbgaufs_plink_arg *p;
6546 + p = file->private_data;
6547 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6550 +static const struct file_operations dbgaufs_plink_fop = {
6551 + .owner = THIS_MODULE,
6552 + .open = dbgaufs_plink_open,
6553 + .release = dbgaufs_plink_release,
6554 + .read = dbgaufs_plink_read
6557 +/* ---------------------------------------------------------------------- */
6559 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6562 + struct au_sbinfo *sbinfo;
6563 + struct super_block *sb;
6565 + sbinfo = inode->i_private;
6566 + sb = sbinfo->si_sb;
6567 + si_noflush_read_lock(sb);
6568 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6569 + si_read_unlock(sb);
6573 +static const struct file_operations dbgaufs_xib_fop = {
6574 + .owner = THIS_MODULE,
6575 + .open = dbgaufs_xib_open,
6576 + .release = dbgaufs_xi_release,
6577 + .read = dbgaufs_xi_read
6580 +/* ---------------------------------------------------------------------- */
6582 +#define DbgaufsXi_PREFIX "xi"
6584 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6588 + aufs_bindex_t bindex;
6589 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6590 + struct au_sbinfo *sbinfo;
6591 + struct super_block *sb;
6592 + struct au_xino *xi;
6594 + struct qstr *name;
6595 + struct au_branch *br;
6598 + name = &file->f_path.dentry->d_name;
6599 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6600 + || memcmp(name->name, DbgaufsXi_PREFIX,
6601 + sizeof(DbgaufsXi_PREFIX) - 1)))
6604 + AuDebugOn(name->len >= sizeof(a));
6605 + memcpy(a, name->name, name->len);
6606 + a[name->len] = '\0';
6607 + p = strchr(a, '-');
6610 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6611 + if (unlikely(err))
6616 + err = kstrtol(p + 1, 10, &l);
6617 + if (unlikely(err))
6623 + sbinfo = inode->i_private;
6624 + sb = sbinfo->si_sb;
6625 + si_noflush_read_lock(sb);
6626 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6628 + br = au_sbr(sb, bindex);
6630 + if (unlikely(idx >= xi->xi_nfile))
6632 + xf = au_xino_file(xi, idx);
6634 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6635 + au_xino_count(br));
6638 + si_read_unlock(sb);
6644 +static const struct file_operations dbgaufs_xino_fop = {
6645 + .owner = THIS_MODULE,
6646 + .open = dbgaufs_xino_open,
6647 + .release = dbgaufs_xi_release,
6648 + .read = dbgaufs_xi_read
6651 +void dbgaufs_xino_del(struct au_branch *br)
6653 + struct dentry *dbgaufs;
6655 + dbgaufs = br->br_dbgaufs;
6659 + br->br_dbgaufs = NULL;
6660 + /* debugfs acquires the parent i_mutex */
6662 + debugfs_remove(dbgaufs);
6666 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6668 + aufs_bindex_t bbot;
6669 + struct au_branch *br;
6671 + if (!au_sbi(sb)->si_dbgaufs)
6674 + bbot = au_sbbot(sb);
6675 + for (; bindex <= bbot; bindex++) {
6676 + br = au_sbr(sb, bindex);
6677 + dbgaufs_xino_del(br);
6681 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6682 + unsigned int idx, struct dentry *parent,
6683 + struct au_sbinfo *sbinfo)
6685 + struct au_branch *br;
6687 + /* "xi" bindex(5) "-" idx(2) NULL */
6688 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6691 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6693 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6695 + br = au_sbr(sb, bindex);
6696 + if (br->br_dbgaufs) {
6697 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6699 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6700 + /* debugfs acquires the parent i_mutex */
6702 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6706 + pr_warn("failed renaming %pd/%s, ignored.\n",
6711 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6712 + sbinfo, &dbgaufs_xino_fop);
6714 + if (unlikely(!br->br_dbgaufs))
6715 + pr_warn("failed creating %pd/%s, ignored.\n",
6720 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6721 + struct dentry *parent, struct au_sbinfo *sbinfo)
6723 + struct au_branch *br;
6724 + struct au_xino *xi;
6727 + br = au_sbr(sb, bindex);
6729 + for (u = 0; u < xi->xi_nfile; u++)
6730 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6733 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6735 + struct au_sbinfo *sbinfo;
6736 + struct dentry *parent;
6737 + aufs_bindex_t bbot;
6739 + if (!au_opt_test(au_mntflags(sb), XINO))
6742 + sbinfo = au_sbi(sb);
6743 + parent = sbinfo->si_dbgaufs;
6747 + bbot = au_sbbot(sb);
6749 + for (; bindex <= bbot; bindex++)
6750 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6752 + for (; bbot >= bindex; bbot--)
6753 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6756 +/* ---------------------------------------------------------------------- */
6758 +#ifdef CONFIG_AUFS_EXPORT
6759 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6762 + struct au_sbinfo *sbinfo;
6763 + struct super_block *sb;
6765 + sbinfo = inode->i_private;
6766 + sb = sbinfo->si_sb;
6767 + si_noflush_read_lock(sb);
6768 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6769 + si_read_unlock(sb);
6773 +static const struct file_operations dbgaufs_xigen_fop = {
6774 + .owner = THIS_MODULE,
6775 + .open = dbgaufs_xigen_open,
6776 + .release = dbgaufs_xi_release,
6777 + .read = dbgaufs_xi_read
6780 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6785 + * This function is a dynamic '__init' function actually,
6786 + * so the tiny check for si_rwsem is unnecessary.
6788 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6791 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6792 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6793 + &dbgaufs_xigen_fop);
6794 + if (sbinfo->si_dbgaufs_xigen)
6800 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6804 +#endif /* CONFIG_AUFS_EXPORT */
6806 +/* ---------------------------------------------------------------------- */
6808 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6811 + * This function is a dynamic '__fin' function actually,
6812 + * so the tiny check for si_rwsem is unnecessary.
6814 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6816 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6817 + sbinfo->si_dbgaufs = NULL;
6820 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6823 + char name[SysaufsSiNameLen];
6826 + * This function is a dynamic '__init' function actually,
6827 + * so the tiny check for si_rwsem is unnecessary.
6829 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6833 + AuErr1("/debug/aufs is uninitialized\n");
6838 + sysaufs_name(sbinfo, name);
6839 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6840 + if (unlikely(!sbinfo->si_dbgaufs))
6843 + /* regardless plink/noplink option */
6844 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6845 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6846 + &dbgaufs_plink_fop);
6847 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6850 + /* regardless xino/noxino option */
6851 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6852 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6853 + &dbgaufs_xib_fop);
6854 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6857 + err = dbgaufs_xigen_init(sbinfo);
6859 + goto out; /* success */
6862 + dbgaufs_si_fin(sbinfo);
6864 + if (unlikely(err))
6865 + pr_err("debugfs/aufs failed\n");
6869 +/* ---------------------------------------------------------------------- */
6871 +void dbgaufs_fin(void)
6873 + debugfs_remove(dbgaufs);
6876 +int __init dbgaufs_init(void)
6881 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6886 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6887 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6888 +++ linux/fs/aufs/dbgaufs.h 2021-05-02 20:15:14.673337458 +0200
6890 +/* SPDX-License-Identifier: GPL-2.0 */
6892 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6894 + * This program, aufs is free software; you can redistribute it and/or modify
6895 + * it under the terms of the GNU General Public License as published by
6896 + * the Free Software Foundation; either version 2 of the License, or
6897 + * (at your option) any later version.
6899 + * This program is distributed in the hope that it will be useful,
6900 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6901 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6902 + * GNU General Public License for more details.
6904 + * You should have received a copy of the GNU General Public License
6905 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6909 + * debugfs interface
6912 +#ifndef __DBGAUFS_H__
6913 +#define __DBGAUFS_H__
6917 +struct super_block;
6921 +#ifdef CONFIG_DEBUG_FS
6923 +void dbgaufs_xino_del(struct au_branch *br);
6924 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6925 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6926 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6927 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6928 +void dbgaufs_fin(void);
6929 +int __init dbgaufs_init(void);
6931 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6932 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6933 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6935 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6936 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6937 +AuStubVoid(dbgaufs_fin, void)
6938 +AuStubInt0(__init dbgaufs_init, void)
6939 +#endif /* CONFIG_DEBUG_FS */
6941 +#endif /* __KERNEL__ */
6942 +#endif /* __DBGAUFS_H__ */
6943 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6944 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6945 +++ linux/fs/aufs/dcsub.c 2021-05-02 20:15:14.673337458 +0200
6947 +// SPDX-License-Identifier: GPL-2.0
6949 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6951 + * This program, aufs is free software; you can redistribute it and/or modify
6952 + * it under the terms of the GNU General Public License as published by
6953 + * the Free Software Foundation; either version 2 of the License, or
6954 + * (at your option) any later version.
6956 + * This program is distributed in the hope that it will be useful,
6957 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6958 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6959 + * GNU General Public License for more details.
6961 + * You should have received a copy of the GNU General Public License
6962 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6966 + * sub-routines for dentry cache
6971 +static void au_dpage_free(struct au_dpage *dpage)
6974 + struct dentry **p;
6976 + p = dpage->dentries;
6977 + for (i = 0; i < dpage->ndentry; i++)
6979 + free_page((unsigned long)dpage->dentries);
6982 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6988 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6989 + if (unlikely(!dpages->dpages))
6992 + p = (void *)__get_free_page(gfp);
6996 + dpages->dpages[0].ndentry = 0;
6997 + dpages->dpages[0].dentries = p;
6998 + dpages->ndpage = 1;
6999 + return 0; /* success */
7002 + au_kfree_try_rcu(dpages->dpages);
7007 +void au_dpages_free(struct au_dcsub_pages *dpages)
7010 + struct au_dpage *p;
7012 + p = dpages->dpages;
7013 + for (i = 0; i < dpages->ndpage; i++)
7014 + au_dpage_free(p++);
7015 + au_kfree_try_rcu(dpages->dpages);
7018 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7019 + struct dentry *dentry, gfp_t gfp)
7022 + struct au_dpage *dpage;
7025 + dpage = dpages->dpages + dpages->ndpage - 1;
7026 + sz = PAGE_SIZE / sizeof(dentry);
7027 + if (unlikely(dpage->ndentry >= sz)) {
7028 + AuLabel(new dpage);
7030 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7031 + p = au_kzrealloc(dpages->dpages, sz,
7032 + sz + sizeof(*dpages->dpages), gfp,
7037 + dpages->dpages = p;
7038 + dpage = dpages->dpages + dpages->ndpage;
7039 + p = (void *)__get_free_page(gfp);
7043 + dpage->ndentry = 0;
7044 + dpage->dentries = p;
7048 + AuDebugOn(au_dcount(dentry) <= 0);
7049 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7050 + return 0; /* success */
7056 +/* todo: BAD approach */
7057 +/* copied from linux/fs/dcache.c */
7065 +extern void d_walk(struct dentry *parent, void *data,
7066 + enum d_walk_ret (*enter)(void *, struct dentry *));
7068 +struct ac_dpages_arg {
7070 + struct au_dcsub_pages *dpages;
7071 + struct super_block *sb;
7072 + au_dpages_test test;
7076 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7078 + enum d_walk_ret ret;
7079 + struct ac_dpages_arg *arg = _arg;
7081 + ret = D_WALK_CONTINUE;
7082 + if (dentry->d_sb == arg->sb
7083 + && !IS_ROOT(dentry)
7084 + && au_dcount(dentry) > 0
7086 + && (!arg->test || arg->test(dentry, arg->arg))) {
7087 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7088 + if (unlikely(arg->err))
7089 + ret = D_WALK_QUIT;
7095 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7096 + au_dpages_test test, void *arg)
7098 + struct ac_dpages_arg args = {
7106 + d_walk(root, &args, au_call_dpages_append);
7111 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7112 + int do_include, au_dpages_test test, void *arg)
7117 + write_seqlock(&rename_lock);
7118 + spin_lock(&dentry->d_lock);
7120 + && au_dcount(dentry) > 0
7121 + && (!test || test(dentry, arg)))
7122 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7123 + spin_unlock(&dentry->d_lock);
7124 + if (unlikely(err))
7128 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7131 + while (!IS_ROOT(dentry)) {
7132 + dentry = dentry->d_parent; /* rename_lock is locked */
7133 + spin_lock(&dentry->d_lock);
7134 + if (au_dcount(dentry) > 0
7135 + && (!test || test(dentry, arg)))
7136 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7137 + spin_unlock(&dentry->d_lock);
7138 + if (unlikely(err))
7143 + write_sequnlock(&rename_lock);
7147 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7149 + return au_di(dentry) && dentry->d_sb == arg;
7152 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7153 + struct dentry *dentry, int do_include)
7155 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7156 + au_dcsub_dpages_aufs, dentry->d_sb);
7159 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7161 + struct path path[2] = {
7170 + return path_is_under(path + 0, path + 1);
7172 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7173 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7174 +++ linux/fs/aufs/dcsub.h 2021-05-02 20:15:14.673337458 +0200
7176 +/* SPDX-License-Identifier: GPL-2.0 */
7178 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7180 + * This program, aufs is free software; you can redistribute it and/or modify
7181 + * it under the terms of the GNU General Public License as published by
7182 + * the Free Software Foundation; either version 2 of the License, or
7183 + * (at your option) any later version.
7185 + * This program is distributed in the hope that it will be useful,
7186 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7187 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7188 + * GNU General Public License for more details.
7190 + * You should have received a copy of the GNU General Public License
7191 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7195 + * sub-routines for dentry cache
7198 +#ifndef __AUFS_DCSUB_H__
7199 +#define __AUFS_DCSUB_H__
7203 +#include <linux/dcache.h>
7204 +#include <linux/fs.h>
7208 + struct dentry **dentries;
7211 +struct au_dcsub_pages {
7213 + struct au_dpage *dpages;
7216 +/* ---------------------------------------------------------------------- */
7219 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7220 +void au_dpages_free(struct au_dcsub_pages *dpages);
7221 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7222 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7223 + au_dpages_test test, void *arg);
7224 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7225 + int do_include, au_dpages_test test, void *arg);
7226 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7227 + struct dentry *dentry, int do_include);
7228 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7230 +/* ---------------------------------------------------------------------- */
7233 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7234 + * include/linux/dcache.h. Try them (in the future).
7237 +static inline int au_d_hashed_positive(struct dentry *d)
7240 + struct inode *inode = d_inode(d);
7243 + if (unlikely(d_unhashed(d)
7244 + || d_is_negative(d)
7245 + || !inode->i_nlink))
7250 +static inline int au_d_linkable(struct dentry *d)
7253 + struct inode *inode = d_inode(d);
7255 + err = au_d_hashed_positive(d);
7257 + && d_is_positive(d)
7258 + && (inode->i_state & I_LINKABLE))
7263 +static inline int au_d_alive(struct dentry *d)
7266 + struct inode *inode;
7270 + err = au_d_hashed_positive(d);
7272 + inode = d_inode(d);
7273 + if (unlikely(d_unlinked(d)
7274 + || d_is_negative(d)
7275 + || !inode->i_nlink))
7281 +static inline int au_alive_dir(struct dentry *d)
7285 + err = au_d_alive(d);
7286 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7291 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7293 + return a->len == b->len
7294 + && !memcmp(a->name, b->name, a->len);
7299 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7301 + * the type of d_lockref.count became int, but the inlined function d_count()
7302 + * still returns unsigned int.
7303 + * I don't know why. Maybe it is for every d_count() users?
7304 + * Anyway au_dcount() lives on.
7306 +static inline int au_dcount(struct dentry *d)
7308 + return (int)d_count(d);
7311 +#endif /* __KERNEL__ */
7312 +#endif /* __AUFS_DCSUB_H__ */
7313 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7314 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7315 +++ linux/fs/aufs/debug.c 2021-05-02 20:15:14.673337458 +0200
7317 +// SPDX-License-Identifier: GPL-2.0
7319 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7321 + * This program, aufs is free software; you can redistribute it and/or modify
7322 + * it under the terms of the GNU General Public License as published by
7323 + * the Free Software Foundation; either version 2 of the License, or
7324 + * (at your option) any later version.
7326 + * This program is distributed in the hope that it will be useful,
7327 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7328 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7329 + * GNU General Public License for more details.
7331 + * You should have received a copy of the GNU General Public License
7332 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7336 + * debug print functions
7339 +#include <linux/iversion.h>
7342 +/* Returns 0, or -errno. arg is in kp->arg. */
7343 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7347 + err = kstrtoint(val, 0, &n);
7357 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7358 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7363 + return sprintf(buffer, "%d", atomic_read(a));
7366 +static struct kernel_param_ops param_ops_atomic_t = {
7367 + .set = param_atomic_t_set,
7368 + .get = param_atomic_t_get
7369 + /* void (*free)(void *arg) */
7372 +atomic_t aufs_debug = ATOMIC_INIT(0);
7373 +MODULE_PARM_DESC(debug, "debug print");
7374 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7376 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7377 +char *au_plevel = KERN_DEBUG;
7378 +#define dpri(fmt, ...) do { \
7380 + && strcmp(au_plevel, KERN_DEBUG)) \
7381 + || au_debug_test()) \
7382 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7385 +/* ---------------------------------------------------------------------- */
7387 +void au_dpri_whlist(struct au_nhash *whlist)
7389 + unsigned long ul, n;
7390 + struct hlist_head *head;
7391 + struct au_vdir_wh *pos;
7393 + n = whlist->nh_num;
7394 + head = whlist->nh_head;
7395 + for (ul = 0; ul < n; ul++) {
7396 + hlist_for_each_entry(pos, head, wh_hash)
7397 + dpri("b%d, %.*s, %d\n",
7399 + pos->wh_str.len, pos->wh_str.name,
7405 +void au_dpri_vdir(struct au_vdir *vdir)
7408 + union au_vdir_deblk_p p;
7411 + if (!vdir || IS_ERR(vdir)) {
7412 + dpri("err %ld\n", PTR_ERR(vdir));
7416 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7417 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7418 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7419 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7420 + p.deblk = vdir->vd_deblk[ul];
7422 + dpri("[%lu]: %p\n", ul, o);
7426 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7427 + struct dentry *wh)
7432 + if (!inode || IS_ERR(inode)) {
7433 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7437 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7438 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7439 + && sizeof(inode->i_blocks) != sizeof(u64));
7441 + n = (void *)wh->d_name.name;
7442 + l = wh->d_name.len;
7445 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7446 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7448 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7449 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7450 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7451 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7452 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7453 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7454 + inode->i_generation,
7455 + l ? ", wh " : "", l, n);
7459 +void au_dpri_inode(struct inode *inode)
7461 + struct au_iinfo *iinfo;
7462 + struct au_hinode *hi;
7463 + aufs_bindex_t bindex;
7466 + err = do_pri_inode(-1, inode, -1, NULL);
7467 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7470 + iinfo = au_ii(inode);
7471 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7472 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7473 + if (iinfo->ii_btop < 0)
7476 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7477 + hi = au_hinode(iinfo, bindex);
7479 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7483 +void au_dpri_dalias(struct inode *inode)
7487 + spin_lock(&inode->i_lock);
7488 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7489 + au_dpri_dentry(d);
7490 + spin_unlock(&inode->i_lock);
7493 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7495 + struct dentry *wh = NULL;
7497 + struct inode *inode;
7498 + struct au_iinfo *iinfo;
7499 + struct au_hinode *hi;
7501 + if (!dentry || IS_ERR(dentry)) {
7502 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7505 + /* do not call dget_parent() here */
7506 + /* note: access d_xxx without d_lock */
7507 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7508 + bindex, dentry, dentry,
7509 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7510 + au_dcount(dentry), dentry->d_flags,
7511 + d_unhashed(dentry) ? "un" : "");
7514 + if (d_is_positive(dentry))
7515 + inode = d_inode(dentry);
7517 + && au_test_aufs(dentry->d_sb)
7519 + && !au_is_bad_inode(inode)) {
7520 + iinfo = au_ii(inode);
7521 + hi = au_hinode(iinfo, bindex);
7523 + wh = hi->hi_whdentry;
7525 + do_pri_inode(bindex, inode, hn, wh);
7529 +void au_dpri_dentry(struct dentry *dentry)
7531 + struct au_dinfo *dinfo;
7532 + aufs_bindex_t bindex;
7535 + err = do_pri_dentry(-1, dentry);
7536 + if (err || !au_test_aufs(dentry->d_sb))
7539 + dinfo = au_di(dentry);
7542 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7543 + dinfo->di_btop, dinfo->di_bbot,
7544 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7545 + dinfo->di_tmpfile);
7546 + if (dinfo->di_btop < 0)
7548 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7549 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7552 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7556 + if (!file || IS_ERR(file)) {
7557 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7562 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7563 + && au_test_aufs(file->f_path.dentry->d_sb)
7565 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7566 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7567 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7568 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7569 + file->f_version, file->f_pos, a);
7570 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7571 + do_pri_dentry(bindex, file->f_path.dentry);
7575 +void au_dpri_file(struct file *file)
7577 + struct au_finfo *finfo;
7578 + struct au_fidir *fidir;
7579 + struct au_hfile *hfile;
7580 + aufs_bindex_t bindex;
7583 + err = do_pri_file(-1, file);
7585 + || IS_ERR_OR_NULL(file->f_path.dentry)
7586 + || !au_test_aufs(file->f_path.dentry->d_sb))
7589 + finfo = au_fi(file);
7592 + if (finfo->fi_btop < 0)
7594 + fidir = finfo->fi_hdir;
7596 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7598 + for (bindex = finfo->fi_btop;
7599 + bindex >= 0 && bindex <= fidir->fd_bbot;
7601 + hfile = fidir->fd_hfile + bindex;
7602 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7606 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7608 + struct vfsmount *mnt;
7609 + struct super_block *sb;
7611 + if (!br || IS_ERR(br))
7613 + mnt = au_br_mnt(br);
7614 + if (!mnt || IS_ERR(mnt))
7617 + if (!sb || IS_ERR(sb))
7620 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7621 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7623 + bindex, br->br_perm, br->br_id, br->br_wbr,
7624 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7625 + sb->s_flags, sb->s_count,
7626 + atomic_read(&sb->s_active),
7627 + !!au_xino_file(br->br_xino, /*idx*/-1));
7631 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7635 +void au_dpri_sb(struct super_block *sb)
7637 + struct au_sbinfo *sbinfo;
7638 + aufs_bindex_t bindex;
7640 + /* to reduce stack size */
7642 + struct vfsmount mnt;
7643 + struct au_branch fake;
7646 + /* this function can be called from magic sysrq */
7647 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7648 + if (unlikely(!a)) {
7649 + dpri("no memory\n");
7653 + a->mnt.mnt_sb = sb;
7654 + a->fake.br_path.mnt = &a->mnt;
7655 + err = do_pri_br(-1, &a->fake);
7657 + dpri("dev 0x%x\n", sb->s_dev);
7658 + if (err || !au_test_aufs(sb))
7661 + sbinfo = au_sbi(sb);
7664 + dpri("nw %d, gen %u, kobj %d\n",
7665 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7666 + kref_read(&sbinfo->si_kobj.kref));
7667 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7668 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7671 +/* ---------------------------------------------------------------------- */
7673 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7675 + struct inode *h_inode, *inode = d_inode(dentry);
7676 + struct dentry *h_dentry;
7677 + aufs_bindex_t bindex, bbot, bi;
7679 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7682 + bbot = au_dbbot(dentry);
7683 + bi = au_ibbot(inode);
7686 + bindex = au_dbtop(dentry);
7687 + bi = au_ibtop(inode);
7691 + for (; bindex <= bbot; bindex++) {
7692 + h_dentry = au_h_dptr(dentry, bindex);
7695 + h_inode = au_h_iptr(inode, bindex);
7696 + if (unlikely(h_inode != d_inode(h_dentry))) {
7698 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7699 + AuDbgDentry(dentry);
7700 + AuDbgInode(inode);
7707 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7710 + struct au_dcsub_pages dpages;
7711 + struct au_dpage *dpage;
7712 + struct dentry **dentries;
7714 + err = au_dpages_init(&dpages, GFP_NOFS);
7716 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7718 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7719 + dpage = dpages.dpages + i;
7720 + dentries = dpage->dentries;
7721 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7722 + AuDebugOn(au_digen_test(dentries[j], sigen));
7724 + au_dpages_free(&dpages);
7727 +void au_dbg_verify_kthread(void)
7729 + if (au_wkq_test()) {
7732 + * It may be recursive, but udba=notify between two aufs mounts,
7733 + * where a single ro branch is shared, is not a problem.
7739 +/* ---------------------------------------------------------------------- */
7741 +int __init au_debug_init(void)
7743 + aufs_bindex_t bindex;
7744 + struct au_vdir_destr destr;
7747 + AuDebugOn(bindex >= 0);
7750 + AuDebugOn(destr.len < NAME_MAX);
7752 +#ifdef CONFIG_4KSTACKS
7753 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7758 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7759 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7760 +++ linux/fs/aufs/debug.h 2021-05-02 20:15:14.673337458 +0200
7762 +/* SPDX-License-Identifier: GPL-2.0 */
7764 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7766 + * This program, aufs is free software; you can redistribute it and/or modify
7767 + * it under the terms of the GNU General Public License as published by
7768 + * the Free Software Foundation; either version 2 of the License, or
7769 + * (at your option) any later version.
7771 + * This program is distributed in the hope that it will be useful,
7772 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7773 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7774 + * GNU General Public License for more details.
7776 + * You should have received a copy of the GNU General Public License
7777 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7781 + * debug print functions
7784 +#ifndef __AUFS_DEBUG_H__
7785 +#define __AUFS_DEBUG_H__
7789 +#include <linux/atomic.h>
7790 +#include <linux/module.h>
7791 +#include <linux/kallsyms.h>
7792 +#include <linux/sysrq.h>
7794 +#ifdef CONFIG_AUFS_DEBUG
7795 +#define AuDebugOn(a) BUG_ON(a)
7797 +/* module parameter */
7798 +extern atomic_t aufs_debug;
7799 +static inline void au_debug_on(void)
7801 + atomic_inc(&aufs_debug);
7803 +static inline void au_debug_off(void)
7805 + atomic_dec_if_positive(&aufs_debug);
7808 +static inline int au_debug_test(void)
7810 + return atomic_read(&aufs_debug) > 0;
7813 +#define AuDebugOn(a) do {} while (0)
7814 +AuStubVoid(au_debug_on, void)
7815 +AuStubVoid(au_debug_off, void)
7816 +AuStubInt0(au_debug_test, void)
7817 +#endif /* CONFIG_AUFS_DEBUG */
7819 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7821 +/* ---------------------------------------------------------------------- */
7825 +#define AuDbg(fmt, ...) do { \
7826 + if (au_debug_test()) \
7827 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7829 +#define AuLabel(l) AuDbg(#l "\n")
7830 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7831 +#define AuWarn1(fmt, ...) do { \
7832 + static unsigned char _c; \
7834 + pr_warn(fmt, ##__VA_ARGS__); \
7837 +#define AuErr1(fmt, ...) do { \
7838 + static unsigned char _c; \
7840 + pr_err(fmt, ##__VA_ARGS__); \
7843 +#define AuIOErr1(fmt, ...) do { \
7844 + static unsigned char _c; \
7846 + AuIOErr(fmt, ##__VA_ARGS__); \
7849 +#define AuUnsupportMsg "This operation is not supported." \
7850 + " Please report this application to aufs-users ML."
7851 +#define AuUnsupport(fmt, ...) do { \
7852 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7856 +#define AuTraceErr(e) do { \
7857 + if (unlikely((e) < 0)) \
7858 + AuDbg("err %d\n", (int)(e)); \
7861 +#define AuTraceErrPtr(p) do { \
7863 + AuDbg("err %ld\n", PTR_ERR(p)); \
7866 +/* dirty macros for debug print, use with "%.*s" and caution */
7867 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7869 +/* ---------------------------------------------------------------------- */
7872 +#ifdef CONFIG_AUFS_DEBUG
7873 +extern struct mutex au_dbg_mtx;
7874 +extern char *au_plevel;
7876 +void au_dpri_whlist(struct au_nhash *whlist);
7878 +void au_dpri_vdir(struct au_vdir *vdir);
7880 +void au_dpri_inode(struct inode *inode);
7881 +void au_dpri_dalias(struct inode *inode);
7882 +void au_dpri_dentry(struct dentry *dentry);
7884 +void au_dpri_file(struct file *filp);
7885 +struct super_block;
7886 +void au_dpri_sb(struct super_block *sb);
7888 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7889 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7890 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7891 +void au_dbg_verify_kthread(void);
7893 +int __init au_debug_init(void);
7895 +#define AuDbgWhlist(w) do { \
7896 + mutex_lock(&au_dbg_mtx); \
7898 + au_dpri_whlist(w); \
7899 + mutex_unlock(&au_dbg_mtx); \
7902 +#define AuDbgVdir(v) do { \
7903 + mutex_lock(&au_dbg_mtx); \
7905 + au_dpri_vdir(v); \
7906 + mutex_unlock(&au_dbg_mtx); \
7909 +#define AuDbgInode(i) do { \
7910 + mutex_lock(&au_dbg_mtx); \
7912 + au_dpri_inode(i); \
7913 + mutex_unlock(&au_dbg_mtx); \
7916 +#define AuDbgDAlias(i) do { \
7917 + mutex_lock(&au_dbg_mtx); \
7919 + au_dpri_dalias(i); \
7920 + mutex_unlock(&au_dbg_mtx); \
7923 +#define AuDbgDentry(d) do { \
7924 + mutex_lock(&au_dbg_mtx); \
7926 + au_dpri_dentry(d); \
7927 + mutex_unlock(&au_dbg_mtx); \
7930 +#define AuDbgFile(f) do { \
7931 + mutex_lock(&au_dbg_mtx); \
7933 + au_dpri_file(f); \
7934 + mutex_unlock(&au_dbg_mtx); \
7937 +#define AuDbgSb(sb) do { \
7938 + mutex_lock(&au_dbg_mtx); \
7939 + AuDbg(#sb "\n"); \
7941 + mutex_unlock(&au_dbg_mtx); \
7944 +#define AuDbgSym(addr) do { \
7945 + char sym[KSYM_SYMBOL_LEN]; \
7946 + sprint_symbol(sym, (unsigned long)addr); \
7947 + AuDbg("%s\n", sym); \
7950 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7951 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7952 +AuStubVoid(au_dbg_verify_kthread, void)
7953 +AuStubInt0(__init au_debug_init, void)
7955 +#define AuDbgWhlist(w) do {} while (0)
7956 +#define AuDbgVdir(v) do {} while (0)
7957 +#define AuDbgInode(i) do {} while (0)
7958 +#define AuDbgDAlias(i) do {} while (0)
7959 +#define AuDbgDentry(d) do {} while (0)
7960 +#define AuDbgFile(f) do {} while (0)
7961 +#define AuDbgSb(sb) do {} while (0)
7962 +#define AuDbgSym(addr) do {} while (0)
7963 +#endif /* CONFIG_AUFS_DEBUG */
7965 +/* ---------------------------------------------------------------------- */
7967 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7968 +int __init au_sysrq_init(void);
7969 +void au_sysrq_fin(void);
7971 +#ifdef CONFIG_HW_CONSOLE
7972 +#define au_dbg_blocked() do { \
7974 + handle_sysrq('w'); \
7977 +AuStubVoid(au_dbg_blocked, void)
7981 +AuStubInt0(__init au_sysrq_init, void)
7982 +AuStubVoid(au_sysrq_fin, void)
7983 +AuStubVoid(au_dbg_blocked, void)
7984 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7986 +#endif /* __KERNEL__ */
7987 +#endif /* __AUFS_DEBUG_H__ */
7988 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7989 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7990 +++ linux/fs/aufs/dentry.c 2021-05-02 20:15:14.673337458 +0200
7992 +// SPDX-License-Identifier: GPL-2.0
7994 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7996 + * This program, aufs is free software; you can redistribute it and/or modify
7997 + * it under the terms of the GNU General Public License as published by
7998 + * the Free Software Foundation; either version 2 of the License, or
7999 + * (at your option) any later version.
8001 + * This program is distributed in the hope that it will be useful,
8002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8004 + * GNU General Public License for more details.
8006 + * You should have received a copy of the GNU General Public License
8007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8011 + * lookup and dentry operations
8014 +#include <linux/iversion.h>
8015 +#include <linux/namei.h>
8019 + * returns positive/negative dentry, NULL or an error.
8020 + * NULL means whiteout-ed or not-found.
8022 +static struct dentry*
8023 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8024 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8026 + struct dentry *h_dentry;
8027 + struct inode *h_inode;
8028 + struct au_branch *br;
8029 + struct user_namespace *h_userns;
8030 + int wh_found, opq;
8031 + unsigned char wh_able;
8032 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8033 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8037 + br = au_sbr(dentry->d_sb, bindex);
8038 + h_userns = au_br_userns(br);
8039 + wh_able = !!au_br_whable(br->br_perm);
8041 + wh_found = au_wh_test(h_userns, h_parent, &args->whname,
8043 + h_dentry = ERR_PTR(wh_found);
8046 + if (unlikely(wh_found < 0))
8049 + /* We found a whiteout */
8050 + /* au_set_dbbot(dentry, bindex); */
8051 + au_set_dbwh(dentry, bindex);
8053 + return NULL; /* success */
8057 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8059 + h_dentry = au_sio_lkup_one(h_userns, args->name, h_parent);
8060 + if (IS_ERR(h_dentry)) {
8061 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8067 + h_inode = d_inode(h_dentry);
8068 + if (d_is_negative(h_dentry)) {
8071 + } else if (wh_found
8072 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8074 + else if (au_ftest_lkup(args->flags, DIRREN)
8076 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8077 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8078 + (unsigned long long)h_inode->i_ino);
8082 + if (au_dbbot(dentry) <= bindex)
8083 + au_set_dbbot(dentry, bindex);
8084 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8085 + au_set_dbtop(dentry, bindex);
8086 + au_set_h_dptr(dentry, bindex, h_dentry);
8088 + if (!d_is_dir(h_dentry)
8090 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8091 + goto out; /* success */
8093 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8094 + opq = au_diropq_test(h_userns, h_dentry);
8095 + inode_unlock_shared(h_inode);
8097 + au_set_dbdiropq(dentry, bindex);
8098 + else if (unlikely(opq < 0)) {
8099 + au_set_h_dptr(dentry, bindex, NULL);
8100 + h_dentry = ERR_PTR(opq);
8111 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8113 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8114 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8120 + * returns the number of lower positive dentries,
8121 + * otherwise an error.
8122 + * can be called at unlinking with @type is zero.
8124 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8125 + unsigned int flags)
8127 + int npositive, err;
8128 + aufs_bindex_t bindex, btail, bdiropq;
8129 + unsigned char isdir, dirperm1, dirren;
8130 + struct au_do_lookup_args args = {
8132 + .name = &dentry->d_name
8134 + struct dentry *parent;
8135 + struct super_block *sb;
8137 + sb = dentry->d_sb;
8138 + err = au_test_shwh(sb, args.name);
8139 + if (unlikely(err))
8142 + err = au_wh_name_alloc(&args.whname, args.name);
8143 + if (unlikely(err))
8146 + isdir = !!d_is_dir(dentry);
8147 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8148 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8150 + au_fset_lkup(args.flags, DIRREN);
8153 + parent = dget_parent(dentry);
8154 + btail = au_dbtaildir(parent);
8155 + for (bindex = btop; bindex <= btail; bindex++) {
8156 + struct dentry *h_parent, *h_dentry;
8157 + struct inode *h_inode, *h_dir;
8158 + struct au_branch *br;
8160 + h_dentry = au_h_dptr(dentry, bindex);
8162 + if (d_is_positive(h_dentry))
8166 + h_parent = au_h_dptr(parent, bindex);
8167 + if (!h_parent || !d_is_dir(h_parent))
8171 + /* if the inum matches, then use the prepared name */
8172 + err = au_dr_lkup_name(&args, bindex);
8173 + if (unlikely(err))
8177 + h_dir = d_inode(h_parent);
8178 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8179 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8180 + inode_unlock_shared(h_dir);
8181 + err = PTR_ERR(h_dentry);
8182 + if (IS_ERR(h_dentry))
8185 + au_fclr_lkup(args.flags, ALLOW_NEG);
8187 + au_fset_lkup(args.flags, IGNORE_PERM);
8189 + if (au_dbwh(dentry) == bindex)
8193 + if (d_is_negative(h_dentry))
8195 + h_inode = d_inode(h_dentry);
8198 + args.type = h_inode->i_mode & S_IFMT;
8199 + if (args.type != S_IFDIR)
8202 + /* the type of lower may be different */
8203 + bdiropq = au_dbdiropq(dentry);
8204 + if (bdiropq >= 0 && bdiropq <= bindex)
8207 + br = au_sbr(sb, bindex);
8209 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8210 + /*add_ent*/NULL)) {
8211 + /* prepare next name to lookup */
8212 + err = au_dr_lkup(&args, dentry, bindex);
8213 + if (unlikely(err))
8219 + AuLabel(positive);
8220 + au_update_dbtop(dentry);
8223 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8224 + && au_dbtop(dentry) < 0)) {
8226 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8232 + au_kfree_try_rcu(args.whname.name);
8234 + au_dr_lkup_fin(&args);
8239 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8240 + struct dentry *parent)
8242 + struct dentry *dentry;
8245 + if (!au_test_h_perm_sio(userns, d_inode(parent), MAY_EXEC))
8246 + dentry = vfsub_lkup_one(name, parent);
8248 + struct vfsub_lkup_one_args args = {
8254 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8255 + if (unlikely(wkq_err))
8256 + dentry = ERR_PTR(wkq_err);
8263 + * lookup @dentry on @bindex which should be negative.
8265 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8268 + struct dentry *parent, *h_parent, *h_dentry;
8269 + struct au_branch *br;
8270 + struct user_namespace *h_userns;
8272 + parent = dget_parent(dentry);
8273 + h_parent = au_h_dptr(parent, bindex);
8274 + br = au_sbr(dentry->d_sb, bindex);
8275 + h_userns = au_br_userns(br);
8277 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8279 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, h_parent);
8280 + err = PTR_ERR(h_dentry);
8281 + if (IS_ERR(h_dentry))
8283 + if (unlikely(d_is_positive(h_dentry))) {
8285 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8291 + if (bindex < au_dbtop(dentry))
8292 + au_set_dbtop(dentry, bindex);
8293 + if (au_dbbot(dentry) < bindex)
8294 + au_set_dbbot(dentry, bindex);
8295 + au_set_h_dptr(dentry, bindex, h_dentry);
8302 +/* ---------------------------------------------------------------------- */
8304 +/* subset of struct inode */
8306 + unsigned long i_ino;
8307 + /* unsigned int i_nlink; */
8313 + blkcnt_t i_blocks;
8318 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8320 + ia->i_ino = h_inode->i_ino;
8321 + /* ia->i_nlink = h_inode->i_nlink; */
8322 + ia->i_uid = h_inode->i_uid;
8323 + ia->i_gid = h_inode->i_gid;
8324 + ia->i_version = inode_query_iversion(h_inode);
8326 + ia->i_size = h_inode->i_size;
8327 + ia->i_blocks = h_inode->i_blocks;
8329 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8332 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8334 + return ia->i_ino != h_inode->i_ino
8335 + /* || ia->i_nlink != h_inode->i_nlink */
8336 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8337 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8338 + || !inode_eq_iversion(h_inode, ia->i_version)
8340 + || ia->i_size != h_inode->i_size
8341 + || ia->i_blocks != h_inode->i_blocks
8343 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8346 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8347 + struct au_branch *br)
8350 + struct au_iattr ia;
8351 + struct inode *h_inode;
8352 + struct dentry *h_d;
8353 + struct super_block *h_sb;
8356 + memset(&ia, -1, sizeof(ia));
8357 + h_sb = h_dentry->d_sb;
8359 + if (d_is_positive(h_dentry)) {
8360 + h_inode = d_inode(h_dentry);
8361 + au_iattr_save(&ia, h_inode);
8362 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8363 + /* nfs d_revalidate may return 0 for negative dentry */
8364 + /* fuse d_revalidate always return 0 for negative dentry */
8367 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8368 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8369 + err = PTR_ERR(h_d);
8374 + if (unlikely(h_d != h_dentry
8375 + || d_inode(h_d) != h_inode
8376 + || (h_inode && au_iattr_test(&ia, h_inode))))
8377 + err = au_busy_or_stale();
8385 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8386 + struct dentry *h_parent, struct au_branch *br)
8391 + if (udba == AuOpt_UDBA_REVAL
8392 + && !au_test_fs_remote(h_dentry->d_sb)) {
8394 + err = (d_inode(h_dentry->d_parent) != h_dir);
8395 + } else if (udba != AuOpt_UDBA_NONE)
8396 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8401 +/* ---------------------------------------------------------------------- */
8403 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8406 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8407 + struct au_hdentry tmp, *p, *q;
8408 + struct au_dinfo *dinfo;
8409 + struct super_block *sb;
8411 + DiMustWriteLock(dentry);
8413 + sb = dentry->d_sb;
8414 + dinfo = au_di(dentry);
8415 + bbot = dinfo->di_bbot;
8416 + bwh = dinfo->di_bwh;
8417 + bdiropq = dinfo->di_bdiropq;
8418 + bindex = dinfo->di_btop;
8419 + p = au_hdentry(dinfo, bindex);
8420 + for (; bindex <= bbot; bindex++, p++) {
8421 + if (!p->hd_dentry)
8424 + new_bindex = au_br_index(sb, p->hd_id);
8425 + if (new_bindex == bindex)
8428 + if (dinfo->di_bwh == bindex)
8430 + if (dinfo->di_bdiropq == bindex)
8431 + bdiropq = new_bindex;
8432 + if (new_bindex < 0) {
8434 + p->hd_dentry = NULL;
8438 + /* swap two lower dentries, and loop again */
8439 + q = au_hdentry(dinfo, new_bindex);
8443 + if (tmp.hd_dentry) {
8449 + dinfo->di_bwh = -1;
8450 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8451 + dinfo->di_bwh = bwh;
8453 + dinfo->di_bdiropq = -1;
8455 + && bdiropq <= au_sbbot(sb)
8456 + && au_sbr_whable(sb, bdiropq))
8457 + dinfo->di_bdiropq = bdiropq;
8460 + dinfo->di_btop = -1;
8461 + dinfo->di_bbot = -1;
8462 + bbot = au_dbbot(parent);
8464 + p = au_hdentry(dinfo, bindex);
8465 + for (; bindex <= bbot; bindex++, p++)
8466 + if (p->hd_dentry) {
8467 + dinfo->di_btop = bindex;
8471 + if (dinfo->di_btop >= 0) {
8473 + p = au_hdentry(dinfo, bindex);
8474 + for (; bindex >= 0; bindex--, p--)
8475 + if (p->hd_dentry) {
8476 + dinfo->di_bbot = bindex;
8485 +static void au_do_hide(struct dentry *dentry)
8487 + struct inode *inode;
8489 + if (d_really_is_positive(dentry)) {
8490 + inode = d_inode(dentry);
8491 + if (!d_is_dir(dentry)) {
8492 + if (inode->i_nlink && !d_unhashed(dentry))
8493 + drop_nlink(inode);
8495 + clear_nlink(inode);
8496 + /* stop next lookup */
8497 + inode->i_flags |= S_DEAD;
8499 + smp_mb(); /* necessary? */
8504 +static int au_hide_children(struct dentry *parent)
8506 + int err, i, j, ndentry;
8507 + struct au_dcsub_pages dpages;
8508 + struct au_dpage *dpage;
8509 + struct dentry *dentry;
8511 + err = au_dpages_init(&dpages, GFP_NOFS);
8512 + if (unlikely(err))
8514 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8515 + if (unlikely(err))
8518 + /* in reverse order */
8519 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8520 + dpage = dpages.dpages + i;
8521 + ndentry = dpage->ndentry;
8522 + for (j = ndentry - 1; j >= 0; j--) {
8523 + dentry = dpage->dentries[j];
8524 + if (dentry != parent)
8525 + au_do_hide(dentry);
8530 + au_dpages_free(&dpages);
8535 +static void au_hide(struct dentry *dentry)
8539 + AuDbgDentry(dentry);
8540 + if (d_is_dir(dentry)) {
8541 + /* shrink_dcache_parent(dentry); */
8542 + err = au_hide_children(dentry);
8543 + if (unlikely(err))
8544 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8547 + au_do_hide(dentry);
8551 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8553 + * a dirty branch is added
8554 + * - on the top of layers
8555 + * - in the middle of layers
8556 + * - to the bottom of layers
8558 + * on the added branch there exists
8561 + * - a same named entry
8563 + * * negative --> positive
8564 + * * positive --> positive
8565 + * - type is unchanged
8566 + * - type is changed
8568 + * * negative --> negative
8569 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8572 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8573 + struct au_dinfo *tmp)
8576 + aufs_bindex_t bindex, bbot;
8578 + struct dentry *dentry;
8579 + struct inode *inode;
8581 + } orig_h, tmp_h = {
8584 + struct au_hdentry *hd;
8585 + struct inode *inode, *h_inode;
8586 + struct dentry *h_dentry;
8589 + AuDebugOn(dinfo->di_btop < 0);
8591 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8592 + orig_h.inode = NULL;
8593 + if (d_is_positive(orig_h.dentry)) {
8594 + orig_h.inode = d_inode(orig_h.dentry);
8595 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8597 + if (tmp->di_btop >= 0) {
8598 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8599 + if (d_is_positive(tmp_h.dentry)) {
8600 + tmp_h.inode = d_inode(tmp_h.dentry);
8601 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8606 + if (d_really_is_positive(dentry))
8607 + inode = d_inode(dentry);
8608 + if (!orig_h.inode) {
8609 + AuDbg("negative originally\n");
8615 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8616 + AuDebugOn(dinfo->di_bdiropq != -1);
8618 + if (!tmp_h.inode) {
8619 + AuDbg("negative --> negative\n");
8620 + /* should have only one negative lower */
8621 + if (tmp->di_btop >= 0
8622 + && tmp->di_btop < dinfo->di_btop) {
8623 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8624 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8625 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8626 + au_di_cp(dinfo, tmp);
8627 + hd = au_hdentry(tmp, tmp->di_btop);
8628 + au_set_h_dptr(dentry, tmp->di_btop,
8629 + dget(hd->hd_dentry));
8631 + au_dbg_verify_dinode(dentry);
8633 + AuDbg("negative --> positive\n");
8635 + * similar to the behaviour of creating with bypassing
8637 + * unhash it in order to force an error in the
8638 + * succeeding create operation.
8639 + * we should not set S_DEAD here.
8642 + /* au_di_swap(tmp, dinfo); */
8643 + au_dbg_verify_dinode(dentry);
8646 + AuDbg("positive originally\n");
8647 + /* inode may be NULL */
8648 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8649 + if (!tmp_h.inode) {
8650 + AuDbg("positive --> negative\n");
8651 + /* or bypassing aufs */
8653 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8654 + dinfo->di_bwh = tmp->di_bwh;
8656 + err = au_refresh_hinode_self(inode);
8657 + au_dbg_verify_dinode(dentry);
8658 + } else if (orig_h.mode == tmp_h.mode) {
8659 + AuDbg("positive --> positive, same type\n");
8660 + if (!S_ISDIR(orig_h.mode)
8661 + && dinfo->di_btop > tmp->di_btop) {
8663 + * similar to the behaviour of removing and
8668 + err = au_refresh_hinode_self(inode);
8669 + au_dbg_verify_dinode(dentry);
8671 + /* fill empty slots */
8672 + if (dinfo->di_btop > tmp->di_btop)
8673 + dinfo->di_btop = tmp->di_btop;
8674 + if (dinfo->di_bbot < tmp->di_bbot)
8675 + dinfo->di_bbot = tmp->di_bbot;
8676 + dinfo->di_bwh = tmp->di_bwh;
8677 + dinfo->di_bdiropq = tmp->di_bdiropq;
8678 + bbot = dinfo->di_bbot;
8679 + bindex = tmp->di_btop;
8680 + hd = au_hdentry(tmp, bindex);
8681 + for (; bindex <= bbot; bindex++, hd++) {
8682 + if (au_h_dptr(dentry, bindex))
8684 + h_dentry = hd->hd_dentry;
8687 + AuDebugOn(d_is_negative(h_dentry));
8688 + h_inode = d_inode(h_dentry);
8689 + AuDebugOn(orig_h.mode
8690 + != (h_inode->i_mode
8692 + au_set_h_dptr(dentry, bindex,
8696 + err = au_refresh_hinode(inode, dentry);
8697 + au_dbg_verify_dinode(dentry);
8700 + AuDbg("positive --> positive, different type\n");
8701 + /* similar to the behaviour of removing and creating */
8704 + err = au_refresh_hinode_self(inode);
8705 + au_dbg_verify_dinode(dentry);
8713 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8715 + const struct dentry_operations *dop
8716 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8717 + static const unsigned int mask
8718 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8720 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8722 + if (dentry->d_op == dop)
8725 + AuDbg("%pd\n", dentry);
8726 + spin_lock(&dentry->d_lock);
8727 + if (dop == &aufs_dop)
8728 + dentry->d_flags |= mask;
8730 + dentry->d_flags &= ~mask;
8731 + dentry->d_op = dop;
8732 + spin_unlock(&dentry->d_lock);
8735 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8737 + int err, ebrange, nbr;
8738 + unsigned int sigen;
8739 + struct au_dinfo *dinfo, *tmp;
8740 + struct super_block *sb;
8741 + struct inode *inode;
8743 + DiMustWriteLock(dentry);
8744 + AuDebugOn(IS_ROOT(dentry));
8745 + AuDebugOn(d_really_is_negative(parent));
8747 + sb = dentry->d_sb;
8748 + sigen = au_sigen(sb);
8749 + err = au_digen_test(parent, sigen);
8750 + if (unlikely(err))
8753 + nbr = au_sbbot(sb) + 1;
8754 + dinfo = au_di(dentry);
8755 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8756 + if (unlikely(err))
8758 + ebrange = au_dbrange_test(dentry);
8760 + ebrange = au_do_refresh_hdentry(dentry, parent);
8762 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8763 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8764 + if (d_really_is_positive(dentry)) {
8765 + inode = d_inode(dentry);
8766 + err = au_refresh_hinode_self(inode);
8768 + au_dbg_verify_dinode(dentry);
8770 + goto out_dgen; /* success */
8774 + /* temporary dinfo */
8775 + AuDbgDentry(dentry);
8777 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8778 + if (unlikely(!tmp))
8780 + au_di_swap(tmp, dinfo);
8781 + /* returns the number of positive dentries */
8783 + * if current working dir is removed, it returns an error.
8784 + * but the dentry is legal.
8786 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8787 + AuDbgDentry(dentry);
8788 + au_di_swap(tmp, dinfo);
8789 + if (err == -ENOENT)
8792 + /* compare/refresh by dinfo */
8793 + AuDbgDentry(dentry);
8794 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8795 + au_dbg_verify_dinode(dentry);
8798 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8799 + au_rw_write_unlock(&tmp->di_rwsem);
8801 + if (unlikely(err))
8805 + au_update_digen(dentry);
8807 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8808 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8809 + AuDbgDentry(dentry);
8815 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8816 + struct dentry *dentry, aufs_bindex_t bindex)
8821 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8824 + AuDbg("b%d\n", bindex);
8826 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8827 + * due to whiteout and branch permission.
8829 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8830 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8831 + /* it may return tri-state */
8832 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8834 + if (unlikely(valid < 0))
8844 +/* todo: remove this */
8845 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8846 + unsigned int flags, int do_udba, int dirren)
8849 + umode_t mode, h_mode;
8850 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8851 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8852 + struct inode *h_inode, *h_cached_inode;
8853 + struct dentry *h_dentry;
8854 + struct qstr *name, *h_name;
8861 + unhashed = !!d_unhashed(dentry);
8862 + is_root = !!IS_ROOT(dentry);
8863 + name = &dentry->d_name;
8864 + tmpfile = au_di(dentry)->di_tmpfile;
8867 + * Theoretically, REVAL test should be unnecessary in case of
8869 + * But {fs,i}notify doesn't fire some necessary events,
8870 + * IN_ATTRIB for atime/nlink/pageio
8871 + * Let's do REVAL test too.
8873 + if (do_udba && inode) {
8874 + mode = (inode->i_mode & S_IFMT);
8875 + plus = (inode->i_nlink > 0);
8876 + ibs = au_ibtop(inode);
8877 + ibe = au_ibbot(inode);
8880 + btop = au_dbtop(dentry);
8882 + if (inode && S_ISDIR(inode->i_mode))
8883 + btail = au_dbtaildir(dentry);
8884 + for (bindex = btop; bindex <= btail; bindex++) {
8885 + h_dentry = au_h_dptr(dentry, bindex);
8889 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8890 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8891 + spin_lock(&h_dentry->d_lock);
8892 + h_name = &h_dentry->d_name;
8893 + if (unlikely(do_udba
8896 + && (unhashed != !!d_unhashed(h_dentry)
8897 + || (!tmpfile && !dirren
8898 + && !au_qstreq(name, h_name))
8901 + && !(flags & LOOKUP_OPEN)
8902 + && (h_dentry->d_flags
8903 + & DCACHE_NFSFS_RENAMED)))
8907 + h_unhashed = d_unhashed(h_dentry);
8908 + spin_unlock(&h_dentry->d_lock);
8909 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8910 + unhashed, h_unhashed, dentry, h_dentry);
8913 + spin_unlock(&h_dentry->d_lock);
8915 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8916 + if (unlikely(err))
8917 + /* do not goto err, to keep the errno */
8920 + /* todo: plink too? */
8925 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8929 + if (d_is_positive(h_dentry))
8930 + h_inode = d_inode(h_dentry);
8933 + h_cached_inode = h_inode;
8935 + h_mode = (h_inode->i_mode & S_IFMT);
8936 + h_plus = (h_inode->i_nlink > 0);
8938 + if (inode && ibs <= bindex && bindex <= ibe)
8939 + h_cached_inode = au_h_iptr(inode, bindex);
8942 + if (unlikely(plus != h_plus && !tmpfile))
8945 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8947 + && !IS_ROOT(h_dentry)
8948 + && unhashed != d_unhashed(h_dentry)))
8951 + if (unlikely(mode != h_mode
8952 + || h_cached_inode != h_inode))
8965 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8966 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8969 + struct dentry *parent;
8971 + if (!au_digen_test(dentry, sigen))
8974 + parent = dget_parent(dentry);
8975 + di_read_lock_parent(parent, AuLock_IR);
8976 + AuDebugOn(au_digen_test(parent, sigen));
8977 + au_dbg_verify_gen(parent, sigen);
8978 + err = au_refresh_dentry(dentry, parent);
8979 + di_read_unlock(parent, AuLock_IR);
8985 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8988 + struct dentry *d, *parent;
8990 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8991 + return simple_reval_dpath(dentry, sigen);
8993 + /* slow loop, keep it simple and stupid */
8994 + /* cf: au_cpup_dirs() */
8997 + while (au_digen_test(dentry, sigen)) {
9001 + parent = dget_parent(d);
9002 + if (!au_digen_test(parent, sigen))
9008 + di_write_lock_child2(d);
9010 + /* someone might update our dentry while we were sleeping */
9011 + if (au_digen_test(d, sigen)) {
9013 + * todo: consolidate with simple_reval_dpath(),
9014 + * do_refresh() and au_reval_for_attr().
9016 + di_read_lock_parent(parent, AuLock_IR);
9017 + err = au_refresh_dentry(d, parent);
9018 + di_read_unlock(parent, AuLock_IR);
9022 + di_write_unlock(d);
9024 + if (unlikely(err))
9032 + * if valid returns 1, otherwise 0.
9034 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9037 + unsigned int sigen;
9038 + unsigned char do_udba, dirren;
9039 + struct super_block *sb;
9040 + struct inode *inode;
9042 + /* todo: support rcu-walk? */
9043 + if (flags & LOOKUP_RCU)
9047 + if (unlikely(!au_di(dentry)))
9051 + sb = dentry->d_sb;
9054 + * i_mutex of parent dir may be held,
9055 + * but we should not return 'invalid' due to busy.
9057 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9058 + if (unlikely(err)) {
9064 + if (d_really_is_positive(dentry))
9065 + inode = d_inode(dentry);
9066 + if (unlikely(inode && au_is_bad_inode(inode))) {
9071 + if (unlikely(au_dbrange_test(dentry))) {
9077 + sigen = au_sigen(sb);
9078 + if (au_digen_test(dentry, sigen)) {
9079 + AuDebugOn(IS_ROOT(dentry));
9080 + err = au_reval_dpath(dentry, sigen);
9081 + if (unlikely(err)) {
9086 + di_downgrade_lock(dentry, AuLock_IR);
9089 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9091 + && !(inode->i_state && I_LINKABLE)
9092 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9097 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9098 + if (do_udba && inode) {
9099 + aufs_bindex_t btop = au_ibtop(inode);
9100 + struct inode *h_inode;
9103 + h_inode = au_h_iptr(inode, btop);
9104 + if (h_inode && au_test_higen(inode, h_inode)) {
9111 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9112 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9113 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9115 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9121 + di_downgrade_lock(dentry, AuLock_IR);
9123 + aufs_read_unlock(dentry, AuLock_IR);
9128 + AuDbg("%pd invalid, %d\n", dentry, valid);
9134 +static void aufs_d_release(struct dentry *dentry)
9136 + if (au_di(dentry)) {
9137 + au_di_fin(dentry);
9138 + au_hn_di_reinit(dentry);
9142 +const struct dentry_operations aufs_dop = {
9143 + .d_revalidate = aufs_d_revalidate,
9144 + .d_weak_revalidate = aufs_d_revalidate,
9145 + .d_release = aufs_d_release
9148 +/* aufs_dop without d_revalidate */
9149 +const struct dentry_operations aufs_dop_noreval = {
9150 + .d_release = aufs_d_release
9152 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9153 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9154 +++ linux/fs/aufs/dentry.h 2021-05-02 20:15:14.673337458 +0200
9156 +/* SPDX-License-Identifier: GPL-2.0 */
9158 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9160 + * This program, aufs is free software; you can redistribute it and/or modify
9161 + * it under the terms of the GNU General Public License as published by
9162 + * the Free Software Foundation; either version 2 of the License, or
9163 + * (at your option) any later version.
9165 + * This program is distributed in the hope that it will be useful,
9166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9168 + * GNU General Public License for more details.
9170 + * You should have received a copy of the GNU General Public License
9171 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9175 + * lookup and dentry operations
9178 +#ifndef __AUFS_DENTRY_H__
9179 +#define __AUFS_DENTRY_H__
9183 +#include <linux/dcache.h>
9184 +#include "dirren.h"
9187 +struct au_hdentry {
9188 + struct dentry *hd_dentry;
9189 + aufs_bindex_t hd_id;
9193 + atomic_t di_generation;
9195 + struct au_rwsem di_rwsem;
9196 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9197 + unsigned char di_tmpfile; /* to allow the different name */
9198 + struct au_hdentry *di_hdentry;
9199 + struct rcu_head rcu;
9200 +} ____cacheline_aligned_in_smp;
9202 +/* ---------------------------------------------------------------------- */
9204 +/* flags for au_lkup_dentry() */
9205 +#define AuLkup_ALLOW_NEG 1
9206 +#define AuLkup_IGNORE_PERM (1 << 1)
9207 +#define AuLkup_DIRREN (1 << 2)
9208 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9209 +#define au_fset_lkup(flags, name) \
9210 + do { (flags) |= AuLkup_##name; } while (0)
9211 +#define au_fclr_lkup(flags, name) \
9212 + do { (flags) &= ~AuLkup_##name; } while (0)
9214 +#ifndef CONFIG_AUFS_DIRREN
9215 +#undef AuLkup_DIRREN
9216 +#define AuLkup_DIRREN 0
9219 +struct au_do_lookup_args {
9220 + unsigned int flags;
9222 + struct qstr whname, *name;
9223 + struct au_dr_lookup dirren;
9226 +/* ---------------------------------------------------------------------- */
9229 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9231 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9232 + struct dentry *parent);
9233 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9234 + struct dentry *h_parent, struct au_branch *br);
9236 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9237 + unsigned int flags);
9238 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9239 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9240 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9241 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9244 +void au_di_init_once(void *_di);
9245 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9246 +void au_di_free(struct au_dinfo *dinfo);
9247 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9248 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9249 +int au_di_init(struct dentry *dentry);
9250 +void au_di_fin(struct dentry *dentry);
9251 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9253 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9254 +void di_read_unlock(struct dentry *d, int flags);
9255 +void di_downgrade_lock(struct dentry *d, int flags);
9256 +void di_write_lock(struct dentry *d, unsigned int lsc);
9257 +void di_write_unlock(struct dentry *d);
9258 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9259 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9260 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9262 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9263 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9264 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9265 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9267 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9268 + struct dentry *h_dentry);
9269 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9270 +int au_dbrange_test(struct dentry *dentry);
9271 +void au_update_digen(struct dentry *dentry);
9272 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9273 +void au_update_dbtop(struct dentry *dentry);
9274 +void au_update_dbbot(struct dentry *dentry);
9275 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9277 +/* ---------------------------------------------------------------------- */
9279 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9281 + return dentry->d_fsdata;
9284 +/* ---------------------------------------------------------------------- */
9286 +/* lock subclass for dinfo */
9288 + AuLsc_DI_CHILD, /* child first */
9289 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9290 + AuLsc_DI_CHILD3, /* copyup dirs */
9294 + AuLsc_DI_TMP /* temp for replacing dinfo */
9298 + * di_read_lock_child, di_write_lock_child,
9299 + * di_read_lock_child2, di_write_lock_child2,
9300 + * di_read_lock_child3, di_write_lock_child3,
9301 + * di_read_lock_parent, di_write_lock_parent,
9302 + * di_read_lock_parent2, di_write_lock_parent2,
9303 + * di_read_lock_parent3, di_write_lock_parent3,
9305 +#define AuReadLockFunc(name, lsc) \
9306 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9307 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9309 +#define AuWriteLockFunc(name, lsc) \
9310 +static inline void di_write_lock_##name(struct dentry *d) \
9311 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9313 +#define AuRWLockFuncs(name, lsc) \
9314 + AuReadLockFunc(name, lsc) \
9315 + AuWriteLockFunc(name, lsc)
9317 +AuRWLockFuncs(child, CHILD);
9318 +AuRWLockFuncs(child2, CHILD2);
9319 +AuRWLockFuncs(child3, CHILD3);
9320 +AuRWLockFuncs(parent, PARENT);
9321 +AuRWLockFuncs(parent2, PARENT2);
9322 +AuRWLockFuncs(parent3, PARENT3);
9324 +#undef AuReadLockFunc
9325 +#undef AuWriteLockFunc
9326 +#undef AuRWLockFuncs
9328 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9329 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9330 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9332 +/* ---------------------------------------------------------------------- */
9334 +/* todo: memory barrier? */
9335 +static inline unsigned int au_digen(struct dentry *d)
9337 + return atomic_read(&au_di(d)->di_generation);
9340 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9342 + hdentry->hd_dentry = NULL;
9345 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9346 + aufs_bindex_t bindex)
9348 + return di->di_hdentry + bindex;
9351 +static inline void au_hdput(struct au_hdentry *hd)
9354 + dput(hd->hd_dentry);
9357 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9359 + DiMustAnyLock(dentry);
9360 + return au_di(dentry)->di_btop;
9363 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9365 + DiMustAnyLock(dentry);
9366 + return au_di(dentry)->di_bbot;
9369 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9371 + DiMustAnyLock(dentry);
9372 + return au_di(dentry)->di_bwh;
9375 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9377 + DiMustAnyLock(dentry);
9378 + return au_di(dentry)->di_bdiropq;
9381 +/* todo: hard/soft set? */
9382 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9384 + DiMustWriteLock(dentry);
9385 + au_di(dentry)->di_btop = bindex;
9388 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9390 + DiMustWriteLock(dentry);
9391 + au_di(dentry)->di_bbot = bindex;
9394 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9396 + DiMustWriteLock(dentry);
9397 + /* dbwh can be outside of btop - bbot range */
9398 + au_di(dentry)->di_bwh = bindex;
9401 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9403 + DiMustWriteLock(dentry);
9404 + au_di(dentry)->di_bdiropq = bindex;
9407 +/* ---------------------------------------------------------------------- */
9409 +#ifdef CONFIG_AUFS_HNOTIFY
9410 +static inline void au_digen_dec(struct dentry *d)
9412 + atomic_dec(&au_di(d)->di_generation);
9415 +static inline void au_hn_di_reinit(struct dentry *dentry)
9417 + dentry->d_fsdata = NULL;
9420 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9421 +#endif /* CONFIG_AUFS_HNOTIFY */
9423 +#endif /* __KERNEL__ */
9424 +#endif /* __AUFS_DENTRY_H__ */
9425 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9426 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9427 +++ linux/fs/aufs/dinfo.c 2021-05-02 20:15:14.673337458 +0200
9429 +// SPDX-License-Identifier: GPL-2.0
9431 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9433 + * This program, aufs is free software; you can redistribute it and/or modify
9434 + * it under the terms of the GNU General Public License as published by
9435 + * the Free Software Foundation; either version 2 of the License, or
9436 + * (at your option) any later version.
9438 + * This program is distributed in the hope that it will be useful,
9439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9441 + * GNU General Public License for more details.
9443 + * You should have received a copy of the GNU General Public License
9444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9448 + * dentry private data
9453 +void au_di_init_once(void *_dinfo)
9455 + struct au_dinfo *dinfo = _dinfo;
9457 + au_rw_init(&dinfo->di_rwsem);
9460 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9462 + struct au_dinfo *dinfo;
9465 + dinfo = au_cache_alloc_dinfo();
9466 + if (unlikely(!dinfo))
9469 + nbr = au_sbbot(sb) + 1;
9472 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9473 + if (dinfo->di_hdentry) {
9474 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9475 + dinfo->di_btop = -1;
9476 + dinfo->di_bbot = -1;
9477 + dinfo->di_bwh = -1;
9478 + dinfo->di_bdiropq = -1;
9479 + dinfo->di_tmpfile = 0;
9480 + for (i = 0; i < nbr; i++)
9481 + dinfo->di_hdentry[i].hd_id = -1;
9485 + au_cache_free_dinfo(dinfo);
9492 +void au_di_free(struct au_dinfo *dinfo)
9494 + struct au_hdentry *p;
9495 + aufs_bindex_t bbot, bindex;
9497 + /* dentry may not be revalidated */
9498 + bindex = dinfo->di_btop;
9499 + if (bindex >= 0) {
9500 + bbot = dinfo->di_bbot;
9501 + p = au_hdentry(dinfo, bindex);
9502 + while (bindex++ <= bbot)
9505 + au_kfree_try_rcu(dinfo->di_hdentry);
9506 + au_cache_free_dinfo(dinfo);
9509 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9511 + struct au_hdentry *p;
9514 + AuRwMustWriteLock(&a->di_rwsem);
9515 + AuRwMustWriteLock(&b->di_rwsem);
9517 +#define DiSwap(v, name) \
9519 + v = a->di_##name; \
9520 + a->di_##name = b->di_##name; \
9521 + b->di_##name = v; \
9524 + DiSwap(p, hdentry);
9528 + DiSwap(bi, bdiropq);
9534 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9536 + AuRwMustWriteLock(&dst->di_rwsem);
9537 + AuRwMustWriteLock(&src->di_rwsem);
9539 + dst->di_btop = src->di_btop;
9540 + dst->di_bbot = src->di_bbot;
9541 + dst->di_bwh = src->di_bwh;
9542 + dst->di_bdiropq = src->di_bdiropq;
9546 +int au_di_init(struct dentry *dentry)
9549 + struct super_block *sb;
9550 + struct au_dinfo *dinfo;
9553 + sb = dentry->d_sb;
9554 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9556 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9557 + /* smp_mb(); */ /* atomic_set */
9558 + dentry->d_fsdata = dinfo;
9565 +void au_di_fin(struct dentry *dentry)
9567 + struct au_dinfo *dinfo;
9569 + dinfo = au_di(dentry);
9570 + AuRwDestroy(&dinfo->di_rwsem);
9571 + au_di_free(dinfo);
9574 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9577 + struct au_hdentry *hdp;
9579 + AuRwMustWriteLock(&dinfo->di_rwsem);
9582 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9584 + sz = sizeof(*hdp);
9585 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9588 + dinfo->di_hdentry = hdp;
9595 +/* ---------------------------------------------------------------------- */
9597 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9600 + case AuLsc_DI_CHILD:
9601 + ii_write_lock_child(inode);
9603 + case AuLsc_DI_CHILD2:
9604 + ii_write_lock_child2(inode);
9606 + case AuLsc_DI_CHILD3:
9607 + ii_write_lock_child3(inode);
9609 + case AuLsc_DI_PARENT:
9610 + ii_write_lock_parent(inode);
9612 + case AuLsc_DI_PARENT2:
9613 + ii_write_lock_parent2(inode);
9615 + case AuLsc_DI_PARENT3:
9616 + ii_write_lock_parent3(inode);
9623 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9626 + case AuLsc_DI_CHILD:
9627 + ii_read_lock_child(inode);
9629 + case AuLsc_DI_CHILD2:
9630 + ii_read_lock_child2(inode);
9632 + case AuLsc_DI_CHILD3:
9633 + ii_read_lock_child3(inode);
9635 + case AuLsc_DI_PARENT:
9636 + ii_read_lock_parent(inode);
9638 + case AuLsc_DI_PARENT2:
9639 + ii_read_lock_parent2(inode);
9641 + case AuLsc_DI_PARENT3:
9642 + ii_read_lock_parent3(inode);
9649 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9651 + struct inode *inode;
9653 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9654 + if (d_really_is_positive(d)) {
9655 + inode = d_inode(d);
9656 + if (au_ftest_lock(flags, IW))
9657 + do_ii_write_lock(inode, lsc);
9658 + else if (au_ftest_lock(flags, IR))
9659 + do_ii_read_lock(inode, lsc);
9663 +void di_read_unlock(struct dentry *d, int flags)
9665 + struct inode *inode;
9667 + if (d_really_is_positive(d)) {
9668 + inode = d_inode(d);
9669 + if (au_ftest_lock(flags, IW)) {
9670 + au_dbg_verify_dinode(d);
9671 + ii_write_unlock(inode);
9672 + } else if (au_ftest_lock(flags, IR)) {
9673 + au_dbg_verify_dinode(d);
9674 + ii_read_unlock(inode);
9677 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9680 +void di_downgrade_lock(struct dentry *d, int flags)
9682 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9683 + ii_downgrade_lock(d_inode(d));
9684 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9687 +void di_write_lock(struct dentry *d, unsigned int lsc)
9689 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9690 + if (d_really_is_positive(d))
9691 + do_ii_write_lock(d_inode(d), lsc);
9694 +void di_write_unlock(struct dentry *d)
9696 + au_dbg_verify_dinode(d);
9697 + if (d_really_is_positive(d))
9698 + ii_write_unlock(d_inode(d));
9699 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9702 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9704 + AuDebugOn(d1 == d2
9705 + || d_inode(d1) == d_inode(d2)
9706 + || d1->d_sb != d2->d_sb);
9708 + if ((isdir && au_test_subdir(d1, d2))
9710 + di_write_lock_child(d1);
9711 + di_write_lock_child2(d2);
9713 + di_write_lock_child(d2);
9714 + di_write_lock_child2(d1);
9718 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9720 + AuDebugOn(d1 == d2
9721 + || d_inode(d1) == d_inode(d2)
9722 + || d1->d_sb != d2->d_sb);
9724 + if ((isdir && au_test_subdir(d1, d2))
9726 + di_write_lock_parent(d1);
9727 + di_write_lock_parent2(d2);
9729 + di_write_lock_parent(d2);
9730 + di_write_lock_parent2(d1);
9734 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9736 + di_write_unlock(d1);
9737 + if (d_inode(d1) == d_inode(d2))
9738 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9740 + di_write_unlock(d2);
9743 +/* ---------------------------------------------------------------------- */
9745 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9749 + DiMustAnyLock(dentry);
9751 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9753 + AuDebugOn(bindex < 0);
9754 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9755 + AuDebugOn(d && au_dcount(d) <= 0);
9760 + * extended version of au_h_dptr().
9761 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9764 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9766 + struct dentry *h_dentry;
9767 + struct inode *inode, *h_inode;
9769 + AuDebugOn(d_really_is_negative(dentry));
9772 + if (au_dbtop(dentry) <= bindex
9773 + && bindex <= au_dbbot(dentry))
9774 + h_dentry = au_h_dptr(dentry, bindex);
9775 + if (h_dentry && !au_d_linkable(h_dentry)) {
9777 + goto out; /* success */
9780 + inode = d_inode(dentry);
9781 + AuDebugOn(bindex < au_ibtop(inode));
9782 + AuDebugOn(au_ibbot(inode) < bindex);
9783 + h_inode = au_h_iptr(inode, bindex);
9784 + h_dentry = d_find_alias(h_inode);
9786 + if (!IS_ERR(h_dentry)) {
9787 + if (!au_d_linkable(h_dentry))
9788 + goto out; /* success */
9794 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9795 + h_dentry = au_plink_lkup(inode, bindex);
9796 + AuDebugOn(!h_dentry);
9797 + if (!IS_ERR(h_dentry)) {
9798 + if (!au_d_hashed_positive(h_dentry))
9799 + goto out; /* success */
9806 + AuDbgDentry(h_dentry);
9810 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9812 + aufs_bindex_t bbot, bwh;
9814 + bbot = au_dbbot(dentry);
9816 + bwh = au_dbwh(dentry);
9819 + if (0 < bwh && bwh < bbot)
9825 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9827 + aufs_bindex_t bbot, bopq;
9829 + bbot = au_dbtail(dentry);
9831 + bopq = au_dbdiropq(dentry);
9832 + if (0 <= bopq && bopq < bbot)
9838 +/* ---------------------------------------------------------------------- */
9840 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9841 + struct dentry *h_dentry)
9843 + struct au_dinfo *dinfo;
9844 + struct au_hdentry *hd;
9845 + struct au_branch *br;
9847 + DiMustWriteLock(dentry);
9849 + dinfo = au_di(dentry);
9850 + hd = au_hdentry(dinfo, bindex);
9852 + hd->hd_dentry = h_dentry;
9854 + br = au_sbr(dentry->d_sb, bindex);
9855 + hd->hd_id = br->br_id;
9859 +int au_dbrange_test(struct dentry *dentry)
9862 + aufs_bindex_t btop, bbot;
9865 + btop = au_dbtop(dentry);
9866 + bbot = au_dbbot(dentry);
9868 + AuDebugOn(bbot < 0 && btop > bbot);
9871 + AuDebugOn(bbot >= 0);
9877 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9882 + if (unlikely(au_digen(dentry) != sigen
9883 + || au_iigen_test(d_inode(dentry), sigen)))
9889 +void au_update_digen(struct dentry *dentry)
9891 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9892 + /* smp_mb(); */ /* atomic_set */
9895 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9897 + struct au_dinfo *dinfo;
9898 + struct dentry *h_d;
9899 + struct au_hdentry *hdp;
9900 + aufs_bindex_t bindex, bbot;
9902 + DiMustWriteLock(dentry);
9904 + dinfo = au_di(dentry);
9905 + if (!dinfo || dinfo->di_btop < 0)
9908 + if (do_put_zero) {
9909 + bbot = dinfo->di_bbot;
9910 + bindex = dinfo->di_btop;
9911 + hdp = au_hdentry(dinfo, bindex);
9912 + for (; bindex <= bbot; bindex++, hdp++) {
9913 + h_d = hdp->hd_dentry;
9914 + if (h_d && d_is_negative(h_d))
9915 + au_set_h_dptr(dentry, bindex, NULL);
9919 + dinfo->di_btop = 0;
9920 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9921 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9922 + if (hdp->hd_dentry)
9924 + if (dinfo->di_btop > dinfo->di_bbot) {
9925 + dinfo->di_btop = -1;
9926 + dinfo->di_bbot = -1;
9930 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9931 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9932 + if (hdp->hd_dentry)
9934 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9937 +void au_update_dbtop(struct dentry *dentry)
9939 + aufs_bindex_t bindex, bbot;
9940 + struct dentry *h_dentry;
9942 + bbot = au_dbbot(dentry);
9943 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9944 + h_dentry = au_h_dptr(dentry, bindex);
9947 + if (d_is_positive(h_dentry)) {
9948 + au_set_dbtop(dentry, bindex);
9951 + au_set_h_dptr(dentry, bindex, NULL);
9955 +void au_update_dbbot(struct dentry *dentry)
9957 + aufs_bindex_t bindex, btop;
9958 + struct dentry *h_dentry;
9960 + btop = au_dbtop(dentry);
9961 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9962 + h_dentry = au_h_dptr(dentry, bindex);
9965 + if (d_is_positive(h_dentry)) {
9966 + au_set_dbbot(dentry, bindex);
9969 + au_set_h_dptr(dentry, bindex, NULL);
9973 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9975 + aufs_bindex_t bindex, bbot;
9977 + bbot = au_dbbot(dentry);
9978 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9979 + if (au_h_dptr(dentry, bindex) == h_dentry)
9983 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9984 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9985 +++ linux/fs/aufs/dir.c 2021-05-02 20:15:14.673337458 +0200
9987 +// SPDX-License-Identifier: GPL-2.0
9989 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9991 + * This program, aufs is free software; you can redistribute it and/or modify
9992 + * it under the terms of the GNU General Public License as published by
9993 + * the Free Software Foundation; either version 2 of the License, or
9994 + * (at your option) any later version.
9996 + * This program is distributed in the hope that it will be useful,
9997 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9998 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9999 + * GNU General Public License for more details.
10001 + * You should have received a copy of the GNU General Public License
10002 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10006 + * directory operations
10009 +#include <linux/fs_stack.h>
10010 +#include <linux/iversion.h>
10013 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10015 + unsigned int nlink;
10017 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10019 + nlink = dir->i_nlink;
10020 + nlink += h_dir->i_nlink - 2;
10021 + if (h_dir->i_nlink < 2)
10023 + smp_mb(); /* for i_nlink */
10024 + /* 0 can happen in revaliding */
10025 + set_nlink(dir, nlink);
10028 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10030 + unsigned int nlink;
10032 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10034 + nlink = dir->i_nlink;
10035 + nlink -= h_dir->i_nlink - 2;
10036 + if (h_dir->i_nlink < 2)
10038 + smp_mb(); /* for i_nlink */
10039 + /* nlink == 0 means the branch-fs is broken */
10040 + set_nlink(dir, nlink);
10043 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10046 + aufs_bindex_t bindex, bbot;
10047 + struct file *h_file;
10048 + struct dentry *h_dentry;
10052 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10054 + bbot = au_fbbot_dir(file);
10055 + for (bindex = au_fbtop(file);
10056 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10058 + h_file = au_hf_dir(file, bindex);
10059 + if (h_file && file_inode(h_file))
10060 + sz += vfsub_f_size_read(h_file);
10063 + AuDebugOn(!dentry);
10064 + AuDebugOn(!d_is_dir(dentry));
10066 + bbot = au_dbtaildir(dentry);
10067 + for (bindex = au_dbtop(dentry);
10068 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10070 + h_dentry = au_h_dptr(dentry, bindex);
10071 + if (h_dentry && d_is_positive(h_dentry))
10072 + sz += i_size_read(d_inode(h_dentry));
10075 + if (sz < KMALLOC_MAX_SIZE)
10076 + sz = roundup_pow_of_two(sz);
10077 + if (sz > KMALLOC_MAX_SIZE)
10078 + sz = KMALLOC_MAX_SIZE;
10079 + else if (sz < NAME_MAX) {
10080 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10081 + sz = AUFS_RDBLK_DEF;
10086 +struct au_dir_ts_arg {
10087 + struct dentry *dentry;
10088 + aufs_bindex_t brid;
10091 +static void au_do_dir_ts(void *arg)
10093 + struct au_dir_ts_arg *a = arg;
10094 + struct au_dtime dt;
10095 + struct path h_path;
10096 + struct inode *dir, *h_dir;
10097 + struct super_block *sb;
10098 + struct au_branch *br;
10099 + struct au_hinode *hdir;
10101 + aufs_bindex_t btop, bindex;
10103 + sb = a->dentry->d_sb;
10104 + if (d_really_is_negative(a->dentry))
10106 + /* no dir->i_mutex lock */
10107 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10109 + dir = d_inode(a->dentry);
10110 + btop = au_ibtop(dir);
10111 + bindex = au_br_index(sb, a->brid);
10112 + if (bindex < btop)
10115 + br = au_sbr(sb, bindex);
10116 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10117 + if (!h_path.dentry)
10119 + h_path.mnt = au_br_mnt(br);
10120 + au_dtime_store(&dt, a->dentry, &h_path);
10122 + br = au_sbr(sb, btop);
10123 + if (!au_br_writable(br->br_perm))
10125 + h_path.dentry = au_h_dptr(a->dentry, btop);
10126 + h_path.mnt = au_br_mnt(br);
10127 + err = vfsub_mnt_want_write(h_path.mnt);
10130 + hdir = au_hi(dir, btop);
10131 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10132 + h_dir = au_h_iptr(dir, btop);
10133 + if (h_dir->i_nlink
10134 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10135 + dt.dt_h_path = h_path;
10136 + au_dtime_revert(&dt);
10138 + au_hn_inode_unlock(hdir);
10139 + vfsub_mnt_drop_write(h_path.mnt);
10140 + au_cpup_attr_timesizes(dir);
10143 + aufs_read_unlock(a->dentry, AuLock_DW);
10146 + au_nwt_done(&au_sbi(sb)->si_nowait);
10147 + au_kfree_try_rcu(arg);
10150 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10152 + int perm, wkq_err;
10153 + aufs_bindex_t btop;
10154 + struct au_dir_ts_arg *arg;
10155 + struct dentry *dentry;
10156 + struct super_block *sb;
10160 + dentry = d_find_any_alias(dir);
10161 + AuDebugOn(!dentry);
10162 + sb = dentry->d_sb;
10163 + btop = au_ibtop(dir);
10164 + if (btop == bindex) {
10165 + au_cpup_attr_timesizes(dir);
10169 + perm = au_sbr_perm(sb, btop);
10170 + if (!au_br_writable(perm))
10173 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10177 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10178 + arg->brid = au_sbr_id(sb, bindex);
10179 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10180 + if (unlikely(wkq_err)) {
10181 + pr_err("wkq %d\n", wkq_err);
10183 + au_kfree_try_rcu(arg);
10190 +/* ---------------------------------------------------------------------- */
10192 +static int reopen_dir(struct file *file)
10195 + unsigned int flags;
10196 + aufs_bindex_t bindex, btail, btop;
10197 + struct dentry *dentry, *h_dentry;
10198 + struct file *h_file;
10200 + /* open all lower dirs */
10201 + dentry = file->f_path.dentry;
10202 + btop = au_dbtop(dentry);
10203 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10204 + au_set_h_fptr(file, bindex, NULL);
10205 + au_set_fbtop(file, btop);
10207 + btail = au_dbtaildir(dentry);
10208 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10209 + au_set_h_fptr(file, bindex, NULL);
10210 + au_set_fbbot_dir(file, btail);
10212 + flags = vfsub_file_flags(file);
10213 + for (bindex = btop; bindex <= btail; bindex++) {
10214 + h_dentry = au_h_dptr(dentry, bindex);
10217 + h_file = au_hf_dir(file, bindex);
10221 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10222 + err = PTR_ERR(h_file);
10223 + if (IS_ERR(h_file))
10224 + goto out; /* close all? */
10225 + au_set_h_fptr(file, bindex, h_file);
10227 + au_update_figen(file);
10228 + /* todo: necessary? */
10229 + /* file->f_ra = h_file->f_ra; */
10236 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10239 + aufs_bindex_t bindex, btail;
10240 + struct dentry *dentry, *h_dentry;
10241 + struct vfsmount *mnt;
10243 + FiMustWriteLock(file);
10244 + AuDebugOn(h_file);
10247 + mnt = file->f_path.mnt;
10248 + dentry = file->f_path.dentry;
10249 + file->f_version = inode_query_iversion(d_inode(dentry));
10250 + bindex = au_dbtop(dentry);
10251 + au_set_fbtop(file, bindex);
10252 + btail = au_dbtaildir(dentry);
10253 + au_set_fbbot_dir(file, btail);
10254 + for (; !err && bindex <= btail; bindex++) {
10255 + h_dentry = au_h_dptr(dentry, bindex);
10259 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10260 + if (unlikely(err))
10262 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10263 + if (IS_ERR(h_file)) {
10264 + err = PTR_ERR(h_file);
10267 + au_set_h_fptr(file, bindex, h_file);
10269 + au_update_figen(file);
10270 + /* todo: necessary? */
10271 + /* file->f_ra = h_file->f_ra; */
10273 + return 0; /* success */
10276 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10277 + au_set_h_fptr(file, bindex, NULL);
10278 + au_set_fbtop(file, -1);
10279 + au_set_fbbot_dir(file, -1);
10284 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10285 + struct file *file)
10288 + struct super_block *sb;
10289 + struct au_fidir *fidir;
10292 + sb = file->f_path.dentry->d_sb;
10293 + si_read_lock(sb, AuLock_FLUSH);
10294 + fidir = au_fidir_alloc(sb);
10296 + struct au_do_open_args args = {
10297 + .open = do_open_dir,
10300 + err = au_do_open(file, &args);
10301 + if (unlikely(err))
10302 + au_kfree_rcu(fidir);
10304 + si_read_unlock(sb);
10308 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10309 + struct file *file)
10311 + struct au_vdir *vdir_cache;
10312 + struct au_finfo *finfo;
10313 + struct au_fidir *fidir;
10314 + struct au_hfile *hf;
10315 + aufs_bindex_t bindex, bbot;
10317 + finfo = au_fi(file);
10318 + fidir = finfo->fi_hdir;
10320 + au_hbl_del(&finfo->fi_hlist,
10321 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10322 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10324 + au_vdir_free(vdir_cache);
10326 + bindex = finfo->fi_btop;
10327 + if (bindex >= 0) {
10328 + hf = fidir->fd_hfile + bindex;
10330 + * calls fput() instead of filp_close(),
10331 + * since no dnotify or lock for the lower file.
10333 + bbot = fidir->fd_bbot;
10334 + for (; bindex <= bbot; bindex++, hf++)
10336 + au_hfput(hf, /*execed*/0);
10338 + au_kfree_rcu(fidir);
10339 + finfo->fi_hdir = NULL;
10341 + au_finfo_fin(file);
10345 +/* ---------------------------------------------------------------------- */
10347 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10350 + aufs_bindex_t bindex, bbot;
10351 + struct file *h_file;
10354 + bbot = au_fbbot_dir(file);
10355 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10356 + h_file = au_hf_dir(file, bindex);
10358 + err = vfsub_flush(h_file, id);
10363 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10365 + return au_do_flush(file, id, au_do_flush_dir);
10368 +/* ---------------------------------------------------------------------- */
10370 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10373 + aufs_bindex_t bbot, bindex;
10374 + struct inode *inode;
10375 + struct super_block *sb;
10378 + sb = dentry->d_sb;
10379 + inode = d_inode(dentry);
10380 + IMustLock(inode);
10381 + bbot = au_dbbot(dentry);
10382 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10383 + struct path h_path;
10385 + if (au_test_ro(sb, bindex, inode))
10387 + h_path.dentry = au_h_dptr(dentry, bindex);
10388 + if (!h_path.dentry)
10391 + h_path.mnt = au_sbr_mnt(sb, bindex);
10392 + err = vfsub_fsync(NULL, &h_path, datasync);
10398 +static int au_do_fsync_dir(struct file *file, int datasync)
10401 + aufs_bindex_t bbot, bindex;
10402 + struct file *h_file;
10403 + struct super_block *sb;
10404 + struct inode *inode;
10406 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10407 + if (unlikely(err))
10410 + inode = file_inode(file);
10411 + sb = inode->i_sb;
10412 + bbot = au_fbbot_dir(file);
10413 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10414 + h_file = au_hf_dir(file, bindex);
10415 + if (!h_file || au_test_ro(sb, bindex, inode))
10418 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10426 + * @file may be NULL
10428 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10432 + struct dentry *dentry;
10433 + struct inode *inode;
10434 + struct super_block *sb;
10437 + dentry = file->f_path.dentry;
10438 + inode = d_inode(dentry);
10439 + inode_lock(inode);
10440 + sb = dentry->d_sb;
10441 + si_noflush_read_lock(sb);
10443 + err = au_do_fsync_dir(file, datasync);
10445 + di_write_lock_child(dentry);
10446 + err = au_do_fsync_dir_no_file(dentry, datasync);
10448 + au_cpup_attr_timesizes(inode);
10449 + di_write_unlock(dentry);
10451 + fi_write_unlock(file);
10453 + si_read_unlock(sb);
10454 + inode_unlock(inode);
10458 +/* ---------------------------------------------------------------------- */
10460 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10463 + struct dentry *dentry;
10464 + struct inode *inode, *h_inode;
10465 + struct super_block *sb;
10467 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10469 + dentry = file->f_path.dentry;
10470 + inode = d_inode(dentry);
10471 + IMustLock(inode);
10473 + sb = dentry->d_sb;
10474 + si_read_lock(sb, AuLock_FLUSH);
10475 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10476 + if (unlikely(err))
10478 + err = au_alive_dir(dentry);
10480 + err = au_vdir_init(file);
10481 + di_downgrade_lock(dentry, AuLock_IR);
10482 + if (unlikely(err))
10485 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10486 + if (!au_test_nfsd()) {
10487 + err = au_vdir_fill_de(file, ctx);
10488 + fsstack_copy_attr_atime(inode, h_inode);
10491 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10492 + * encode_fh() and others.
10494 + atomic_inc(&h_inode->i_count);
10495 + di_read_unlock(dentry, AuLock_IR);
10496 + si_read_unlock(sb);
10497 + err = au_vdir_fill_de(file, ctx);
10498 + fsstack_copy_attr_atime(inode, h_inode);
10499 + fi_write_unlock(file);
10507 + di_read_unlock(dentry, AuLock_IR);
10508 + fi_write_unlock(file);
10510 + si_read_unlock(sb);
10514 +/* ---------------------------------------------------------------------- */
10516 +#define AuTestEmpty_WHONLY 1
10517 +#define AuTestEmpty_CALLED (1 << 1)
10518 +#define AuTestEmpty_SHWH (1 << 2)
10519 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10520 +#define au_fset_testempty(flags, name) \
10521 + do { (flags) |= AuTestEmpty_##name; } while (0)
10522 +#define au_fclr_testempty(flags, name) \
10523 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10525 +#ifndef CONFIG_AUFS_SHWH
10526 +#undef AuTestEmpty_SHWH
10527 +#define AuTestEmpty_SHWH 0
10530 +struct test_empty_arg {
10531 + struct dir_context ctx;
10532 + struct au_nhash *whlist;
10533 + unsigned int flags;
10535 + aufs_bindex_t bindex;
10538 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10539 + int namelen, loff_t offset __maybe_unused, u64 ino,
10540 + unsigned int d_type)
10542 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10544 + char *name = (void *)__name;
10547 + au_fset_testempty(arg->flags, CALLED);
10549 + if (name[0] == '.'
10550 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10551 + goto out; /* success */
10553 + if (namelen <= AUFS_WH_PFX_LEN
10554 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10555 + if (au_ftest_testempty(arg->flags, WHONLY)
10556 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10557 + arg->err = -ENOTEMPTY;
10561 + name += AUFS_WH_PFX_LEN;
10562 + namelen -= AUFS_WH_PFX_LEN;
10563 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10564 + arg->err = au_nhash_append_wh
10565 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10566 + au_ftest_testempty(arg->flags, SHWH));
10570 + AuTraceErr(arg->err);
10574 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10577 + struct file *h_file;
10578 + struct au_branch *br;
10580 + h_file = au_h_open(dentry, arg->bindex,
10581 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10582 + /*file*/NULL, /*force_wr*/0);
10583 + err = PTR_ERR(h_file);
10584 + if (IS_ERR(h_file))
10588 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10589 + && !file_inode(h_file)->i_nlink)
10594 + au_fclr_testempty(arg->flags, CALLED);
10596 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10599 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10603 + br = au_sbr(dentry->d_sb, arg->bindex);
10604 + au_lcnt_dec(&br->br_nfiles);
10609 +struct do_test_empty_args {
10611 + struct dentry *dentry;
10612 + struct test_empty_arg *arg;
10615 +static void call_do_test_empty(void *args)
10617 + struct do_test_empty_args *a = args;
10618 + *a->errp = do_test_empty(a->dentry, a->arg);
10621 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10623 + int err, wkq_err;
10624 + struct dentry *h_dentry;
10625 + struct inode *h_inode;
10626 + struct user_namespace *h_userns;
10628 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10629 + h_dentry = au_h_dptr(dentry, arg->bindex);
10630 + h_inode = d_inode(h_dentry);
10631 + /* todo: i_mode changes anytime? */
10632 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10633 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10634 + inode_unlock_shared(h_inode);
10636 + err = do_test_empty(dentry, arg);
10638 + struct do_test_empty_args args = {
10640 + .dentry = dentry,
10643 + unsigned int flags = arg->flags;
10645 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10646 + if (unlikely(wkq_err))
10648 + arg->flags = flags;
10654 +int au_test_empty_lower(struct dentry *dentry)
10657 + unsigned int rdhash;
10658 + aufs_bindex_t bindex, btop, btail;
10659 + struct au_nhash whlist;
10660 + struct test_empty_arg arg = {
10662 + .actor = test_empty_cb
10665 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10667 + SiMustAnyLock(dentry->d_sb);
10669 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10671 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10672 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10673 + if (unlikely(err))
10677 + arg.whlist = &whlist;
10678 + btop = au_dbtop(dentry);
10679 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10680 + au_fset_testempty(arg.flags, SHWH);
10681 + test_empty = do_test_empty;
10682 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10683 + test_empty = sio_test_empty;
10684 + arg.bindex = btop;
10685 + err = test_empty(dentry, &arg);
10686 + if (unlikely(err))
10689 + au_fset_testempty(arg.flags, WHONLY);
10690 + btail = au_dbtaildir(dentry);
10691 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10692 + struct dentry *h_dentry;
10694 + h_dentry = au_h_dptr(dentry, bindex);
10695 + if (h_dentry && d_is_positive(h_dentry)) {
10696 + arg.bindex = bindex;
10697 + err = test_empty(dentry, &arg);
10702 + au_nhash_wh_free(&whlist);
10707 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10710 + struct test_empty_arg arg = {
10712 + .actor = test_empty_cb
10715 + aufs_bindex_t bindex, btail;
10718 + arg.whlist = whlist;
10719 + arg.flags = AuTestEmpty_WHONLY;
10720 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10721 + au_fset_testempty(arg.flags, SHWH);
10722 + btail = au_dbtaildir(dentry);
10723 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10724 + struct dentry *h_dentry;
10726 + h_dentry = au_h_dptr(dentry, bindex);
10727 + if (h_dentry && d_is_positive(h_dentry)) {
10728 + arg.bindex = bindex;
10729 + err = sio_test_empty(dentry, &arg);
10736 +/* ---------------------------------------------------------------------- */
10738 +const struct file_operations aufs_dir_fop = {
10739 + .owner = THIS_MODULE,
10740 + .llseek = default_llseek,
10741 + .read = generic_read_dir,
10742 + .iterate_shared = aufs_iterate_shared,
10743 + .unlocked_ioctl = aufs_ioctl_dir,
10744 +#ifdef CONFIG_COMPAT
10745 + .compat_ioctl = aufs_compat_ioctl_dir,
10747 + .open = aufs_open_dir,
10748 + .release = aufs_release_dir,
10749 + .flush = aufs_flush_dir,
10750 + .fsync = aufs_fsync_dir
10752 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10753 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10754 +++ linux/fs/aufs/dir.h 2021-05-02 20:15:14.673337458 +0200
10756 +/* SPDX-License-Identifier: GPL-2.0 */
10758 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10760 + * This program, aufs is free software; you can redistribute it and/or modify
10761 + * it under the terms of the GNU General Public License as published by
10762 + * the Free Software Foundation; either version 2 of the License, or
10763 + * (at your option) any later version.
10765 + * This program is distributed in the hope that it will be useful,
10766 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10767 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10768 + * GNU General Public License for more details.
10770 + * You should have received a copy of the GNU General Public License
10771 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10775 + * directory operations
10778 +#ifndef __AUFS_DIR_H__
10779 +#define __AUFS_DIR_H__
10783 +#include <linux/fs.h>
10785 +/* ---------------------------------------------------------------------- */
10787 +/* need to be faster and smaller */
10790 + unsigned int nh_num;
10791 + struct hlist_head *nh_head;
10794 +struct au_vdir_destr {
10795 + unsigned char len;
10796 + unsigned char name[];
10799 +struct au_vdir_dehstr {
10800 + struct hlist_node hash;
10801 + struct au_vdir_destr *str;
10802 + struct rcu_head rcu;
10803 +} ____cacheline_aligned_in_smp;
10805 +struct au_vdir_de {
10807 + unsigned char de_type;
10808 + /* caution: packed */
10809 + struct au_vdir_destr de_str;
10812 +struct au_vdir_wh {
10813 + struct hlist_node wh_hash;
10814 +#ifdef CONFIG_AUFS_SHWH
10816 + aufs_bindex_t wh_bindex;
10817 + unsigned char wh_type;
10819 + aufs_bindex_t wh_bindex;
10821 + /* caution: packed */
10822 + struct au_vdir_destr wh_str;
10825 +union au_vdir_deblk_p {
10826 + unsigned char *deblk;
10827 + struct au_vdir_de *de;
10831 + unsigned char **vd_deblk;
10832 + unsigned long vd_nblk;
10834 + unsigned long ul;
10835 + union au_vdir_deblk_p p;
10839 + unsigned int vd_deblk_sz;
10840 + unsigned long vd_jiffy;
10841 + struct rcu_head rcu;
10842 +} ____cacheline_aligned_in_smp;
10844 +/* ---------------------------------------------------------------------- */
10847 +extern const struct file_operations aufs_dir_fop;
10848 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10849 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10850 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10851 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10852 +int au_test_empty_lower(struct dentry *dentry);
10853 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10856 +unsigned int au_rdhash_est(loff_t sz);
10857 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10858 +void au_nhash_wh_free(struct au_nhash *whlist);
10859 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10861 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10862 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10863 + unsigned int d_type, aufs_bindex_t bindex,
10864 + unsigned char shwh);
10865 +void au_vdir_free(struct au_vdir *vdir);
10866 +int au_vdir_init(struct file *file);
10867 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10870 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10872 +#ifdef CONFIG_AUFS_RDU
10874 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10875 +#ifdef CONFIG_COMPAT
10876 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10877 + unsigned long arg);
10880 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10881 + unsigned int cmd, unsigned long arg)
10882 +#ifdef CONFIG_COMPAT
10883 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10884 + unsigned int cmd, unsigned long arg)
10888 +#endif /* __KERNEL__ */
10889 +#endif /* __AUFS_DIR_H__ */
10890 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10891 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10892 +++ linux/fs/aufs/dirren.c 2021-05-02 20:15:14.673337458 +0200
10894 +// SPDX-License-Identifier: GPL-2.0
10896 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10898 + * This program, aufs is free software; you can redistribute it and/or modify
10899 + * it under the terms of the GNU General Public License as published by
10900 + * the Free Software Foundation; either version 2 of the License, or
10901 + * (at your option) any later version.
10903 + * This program is distributed in the hope that it will be useful,
10904 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10905 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10906 + * GNU General Public License for more details.
10908 + * You should have received a copy of the GNU General Public License
10909 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10913 + * special handling in renaming a directory
10914 + * in order to support looking-up the before-renamed name on the lower readonly
10918 +#include <linux/byteorder/generic.h>
10921 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10925 + idx = au_dr_ihash(ent->dr_h_ino);
10926 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10929 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10932 + struct hlist_bl_head *hbl;
10935 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10936 + hbl = dr->dr_h_ino + i;
10937 + hlist_bl_lock(hbl);
10938 + ret &= hlist_bl_empty(hbl);
10939 + hlist_bl_unlock(hbl);
10945 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10947 + struct au_dr_hino *found, *ent;
10948 + struct hlist_bl_head *hbl;
10949 + struct hlist_bl_node *pos;
10953 + idx = au_dr_ihash(ino);
10954 + hbl = dr->dr_h_ino + idx;
10955 + hlist_bl_lock(hbl);
10956 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10957 + if (ent->dr_h_ino == ino) {
10961 + hlist_bl_unlock(hbl);
10966 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10967 + struct au_dr_hino *add_ent)
10970 + struct hlist_bl_head *hbl;
10971 + struct hlist_bl_node *pos;
10972 + struct au_dr_hino *ent;
10975 + idx = au_dr_ihash(ino);
10976 + hbl = dr->dr_h_ino + idx;
10977 +#if 0 /* debug print */
10979 + struct hlist_bl_node *tmp;
10981 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10982 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10985 + hlist_bl_lock(hbl);
10986 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10987 + if (ent->dr_h_ino == ino) {
10991 + if (!found && add_ent)
10992 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10993 + hlist_bl_unlock(hbl);
10995 + if (!found && add_ent)
10996 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
11001 +void au_dr_hino_free(struct au_dr_br *dr)
11004 + struct hlist_bl_head *hbl;
11005 + struct hlist_bl_node *pos, *tmp;
11006 + struct au_dr_hino *ent;
11008 + /* SiMustWriteLock(sb); */
11010 + for (i = 0; i < AuDirren_NHASH; i++) {
11011 + hbl = dr->dr_h_ino + i;
11012 + /* no spinlock since sbinfo must be write-locked */
11013 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11014 + au_kfree_rcu(ent);
11015 + INIT_HLIST_BL_HEAD(hbl);
11019 +/* returns the number of inodes or an error */
11020 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11021 + struct file *hinofile)
11025 + loff_t pos, oldsize;
11027 + struct inode *hinoinode;
11028 + struct hlist_bl_head *hbl;
11029 + struct hlist_bl_node *n1, *n2;
11030 + struct au_dr_hino *ent;
11032 + SiMustWriteLock(sb);
11033 + AuDebugOn(!au_br_writable(br->br_perm));
11035 + hinoinode = file_inode(hinofile);
11036 + oldsize = i_size_read(hinoinode);
11040 + hbl = br->br_dirren.dr_h_ino;
11041 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11042 + /* no bit-lock since sbinfo must be write-locked */
11043 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11044 + AuDbg("hi%llu, %pD2\n",
11045 + (unsigned long long)ent->dr_h_ino, hinofile);
11046 + u64 = cpu_to_be64(ent->dr_h_ino);
11047 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11048 + if (ssz == sizeof(u64))
11051 + /* write error */
11052 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11059 + /* regardless the error */
11060 + if (pos < oldsize) {
11061 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11069 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11076 + struct au_dr_hino *ent;
11077 + struct inode *hinoinode;
11078 + struct hlist_bl_head *hbl;
11082 + hbl = dr->dr_h_ino;
11083 + hinoinode = file_inode(hinofile);
11084 + sz = i_size_read(hinoinode);
11085 + AuDebugOn(sz % sizeof(u64));
11086 + n = sz / sizeof(u64);
11088 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11089 + if (unlikely(ssz != sizeof(u64))) {
11090 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11097 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11103 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11104 + AuDbg("hi%llu, %pD2\n",
11105 + (unsigned long long)ent->dr_h_ino, hinofile);
11106 + hidx = au_dr_ihash(ent->dr_h_ino);
11107 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11109 + goto out; /* success */
11112 + au_dr_hino_free(dr);
11119 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11120 + * @path is a switch to distinguish load and store.
11122 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11123 + struct au_branch *br, const struct path *path)
11126 + unsigned char load, suspend;
11127 + struct file *hinofile;
11128 + struct au_hinode *hdir;
11129 + struct inode *dir, *delegated;
11130 + struct path hinopath;
11131 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11132 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11134 + AuDebugOn(bindex < 0 && !br);
11135 + AuDebugOn(bindex >= 0 && br);
11140 + br = au_sbr(sb, bindex);
11143 + path = &br->br_path;
11144 + AuDebugOn(!au_br_writable(br->br_perm));
11145 + if (unlikely(!au_br_writable(br->br_perm)))
11151 + dir = d_inode(sb->s_root);
11152 + hdir = au_hinode(au_ii(dir), bindex);
11153 + dir = hdir->hi_inode;
11154 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11156 + dir = d_inode(path->dentry);
11157 + inode_lock_nested(dir, AuLsc_I_CHILD);
11159 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11160 + err = PTR_ERR(hinopath.dentry);
11161 + if (IS_ERR(hinopath.dentry))
11163 + hinopath.mnt = path->mnt;
11166 + flags = O_RDONLY;
11168 + if (d_is_negative(hinopath.dentry))
11169 + goto out_dput; /* success */
11171 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11172 + if (d_is_positive(hinopath.dentry)) {
11173 + delegated = NULL;
11174 + err = vfsub_unlink(dir, &hinopath, &delegated,
11177 + if (unlikely(err))
11178 + pr_err("ignored err %d, %pd2\n",
11179 + err, hinopath.dentry);
11180 + if (unlikely(err == -EWOULDBLOCK))
11185 + } else if (!d_is_positive(hinopath.dentry)) {
11186 + err = vfsub_create(dir, &hinopath, 0600,
11187 + /*want_excl*/false);
11189 + if (unlikely(err))
11192 + flags = O_WRONLY;
11194 + hinofile = vfsub_dentry_open(&hinopath, flags);
11196 + au_hn_inode_unlock(hdir);
11198 + inode_unlock(dir);
11199 + dput(hinopath.dentry);
11200 + AuTraceErrPtr(hinofile);
11201 + if (IS_ERR(hinofile)) {
11202 + err = PTR_ERR(hinofile);
11207 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11209 + err = au_dr_hino_store(sb, br, hinofile);
11214 + dput(hinopath.dentry);
11217 + au_hn_inode_unlock(hdir);
11219 + inode_unlock(dir);
11225 +/* ---------------------------------------------------------------------- */
11227 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11230 + struct kstatfs kstfs;
11232 + struct dentry *dentry;
11233 + struct super_block *sb;
11235 + err = vfs_statfs((void *)path, &kstfs);
11237 + if (unlikely(err))
11240 + /* todo: support for UUID */
11242 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11243 + brid->type = AuBrid_FSID;
11244 + brid->fsid = kstfs.f_fsid;
11246 + dentry = path->dentry;
11247 + sb = dentry->d_sb;
11250 + brid->type = AuBrid_DEV;
11259 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11260 + const struct path *path)
11263 + struct au_dr_br *dr;
11264 + struct hlist_bl_head *hbl;
11266 + dr = &br->br_dirren;
11267 + hbl = dr->dr_h_ino;
11268 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11269 + INIT_HLIST_BL_HEAD(hbl);
11271 + err = au_dr_brid_init(&dr->dr_brid, path);
11272 + if (unlikely(err))
11275 + if (au_opt_test(au_mntflags(sb), DIRREN))
11276 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11283 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11288 + if (au_br_writable(br->br_perm))
11289 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11291 + au_dr_hino_free(&br->br_dirren);
11296 +/* ---------------------------------------------------------------------- */
11298 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11299 + char *buf, size_t sz)
11302 + unsigned int major, minor;
11306 + err = snprintf(p, sz, "%d_", brid->type);
11307 + AuDebugOn(err > sz);
11310 + switch (brid->type) {
11311 + case AuBrid_Unset:
11313 + case AuBrid_UUID:
11314 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11316 + case AuBrid_FSID:
11317 + err = snprintf(p, sz, "%08x-%08x",
11318 + brid->fsid.val[0], brid->fsid.val[1]);
11321 + major = MAJOR(brid->dev);
11322 + minor = MINOR(brid->dev);
11323 + if (major <= 0xff && minor <= 0xff)
11324 + err = snprintf(p, sz, "%02x%02x", major, minor);
11326 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11329 + AuDebugOn(err > sz);
11332 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11333 + AuDebugOn(err > sz);
11340 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11343 + struct dentry *br_dentry;
11344 + struct inode *br_inode;
11346 + br_dentry = au_br_dentry(br);
11347 + br_inode = d_inode(br_dentry);
11348 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11349 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11350 + AuDebugOn(rlen > len);
11355 +/* ---------------------------------------------------------------------- */
11358 + * from the given @h_dentry, construct drinfo at @*fdata.
11359 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11362 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11363 + struct dentry *h_dentry,
11364 + unsigned char *allocated)
11367 + struct au_drinfo_fdata *f, *p;
11368 + struct au_drinfo *drinfo;
11369 + struct inode *h_inode;
11370 + struct qstr *qname;
11374 + h_inode = d_inode(h_dentry);
11375 + qname = &h_dentry->d_name;
11376 + drinfo = &f->drinfo;
11377 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11378 + drinfo->oldnamelen = qname->len;
11379 + if (*allocated < sizeof(*f) + qname->len) {
11380 + v = roundup_pow_of_two(*allocated + qname->len);
11381 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11382 + if (unlikely(!p)) {
11390 + drinfo = &f->drinfo;
11392 + memcpy(drinfo->oldname, qname->name, qname->len);
11393 + AuDbg("i%llu, %.*s\n",
11394 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11395 + drinfo->oldname);
11402 +/* callers have to free the return value */
11403 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11405 + struct au_drinfo *ret, *drinfo;
11406 + struct au_drinfo_fdata fdata;
11411 + ret = ERR_PTR(-EIO);
11413 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11414 + if (unlikely(ssz != sizeof(fdata))) {
11415 + AuIOErr("ssz %zd, %u, %pD2\n",
11416 + ssz, (unsigned int)sizeof(fdata), file);
11420 + fdata.magic = ntohl((__force __be32)fdata.magic);
11421 + switch (fdata.magic) {
11422 + case AUFS_DRINFO_MAGIC_V1:
11425 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11426 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11430 + drinfo = &fdata.drinfo;
11431 + len = drinfo->oldnamelen;
11433 + AuIOErr("broken drinfo %pD2\n", file);
11438 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11439 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11440 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11441 + (unsigned long long)drinfo->ino,
11442 + (unsigned long long)h_ino, file);
11443 + goto out; /* success */
11446 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11447 + if (unlikely(!ret)) {
11448 + ret = ERR_PTR(-ENOMEM);
11449 + AuTraceErrPtr(ret);
11454 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11455 + if (unlikely(ssz != len)) {
11456 + au_kfree_rcu(ret);
11457 + ret = ERR_PTR(-EIO);
11458 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11462 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11468 +/* ---------------------------------------------------------------------- */
11470 +/* in order to be revertible */
11471 +struct au_drinfo_rev_elm {
11473 + struct dentry *info_dentry;
11474 + struct au_drinfo *info_last;
11477 +struct au_drinfo_rev {
11478 + unsigned char already;
11479 + aufs_bindex_t nelm;
11480 + struct au_drinfo_rev_elm elm[];
11483 +/* todo: isn't it too large? */
11484 +struct au_drinfo_store {
11485 + struct path h_ppath;
11486 + struct dentry *h_dentry;
11487 + struct au_drinfo_fdata *fdata;
11488 + char *infoname; /* inside of whname, just after PFX */
11489 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11490 + aufs_bindex_t btgt, btail;
11491 + unsigned char no_sio,
11492 + allocated, /* current size of *fdata */
11493 + infonamelen, /* room size for p */
11494 + whnamelen, /* length of the generated name */
11495 + renameback; /* renamed back */
11498 +/* on rename(2) error, the caller should revert it using @elm */
11499 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11500 + struct au_drinfo_rev_elm *elm)
11505 + struct path infopath = {
11506 + .mnt = w->h_ppath.mnt
11508 + struct inode *h_dir, *h_inode, *delegated;
11509 + struct file *infofile;
11510 + struct qstr *qname;
11513 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11515 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11517 + AuTraceErrPtr(infopath.dentry);
11518 + if (IS_ERR(infopath.dentry)) {
11519 + err = PTR_ERR(infopath.dentry);
11524 + h_dir = d_inode(w->h_ppath.dentry);
11525 + if (elm && d_is_negative(infopath.dentry)) {
11526 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11528 + if (unlikely(err))
11530 + elm->created = 1;
11531 + elm->info_dentry = dget(infopath.dentry);
11534 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11535 + AuTraceErrPtr(infofile);
11536 + if (IS_ERR(infofile)) {
11537 + err = PTR_ERR(infofile);
11541 + h_inode = d_inode(infopath.dentry);
11542 + if (elm && i_size_read(h_inode)) {
11543 + h_inode = d_inode(w->h_dentry);
11544 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11545 + AuTraceErrPtr(elm->info_last);
11546 + if (IS_ERR(elm->info_last)) {
11547 + err = PTR_ERR(elm->info_last);
11548 + elm->info_last = NULL;
11549 + AuDebugOn(elm->info_dentry);
11554 + if (elm && w->renameback) {
11555 + delegated = NULL;
11556 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11558 + if (unlikely(err == -EWOULDBLOCK))
11564 + qname = &w->h_dentry->d_name;
11565 + len = sizeof(*w->fdata) + qname->len;
11567 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11568 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11569 + if (ssz == len) {
11570 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11571 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11572 + goto out_fput; /* success */
11577 + /* the caller should revert it using @elm */
11583 + dput(infopath.dentry);
11589 +struct au_call_drinfo_do_store_args {
11591 + struct au_drinfo_store *w;
11592 + struct au_drinfo_rev_elm *elm;
11595 +static void au_call_drinfo_do_store(void *args)
11597 + struct au_call_drinfo_do_store_args *a = args;
11599 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11602 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11603 + struct au_drinfo_rev_elm *elm)
11605 + int err, wkq_err;
11608 + err = au_drinfo_do_store(w, elm);
11610 + struct au_call_drinfo_do_store_args a = {
11615 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11616 + if (unlikely(wkq_err))
11624 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11625 + aufs_bindex_t btgt)
11629 + memset(w, 0, sizeof(*w));
11630 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11631 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11632 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11633 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11635 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11638 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11639 + if (unlikely(!w->fdata)) {
11643 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11650 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11652 + au_kfree_rcu(w->fdata);
11655 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11656 + struct au_drinfo_store *w)
11658 + struct au_drinfo_rev_elm *elm;
11659 + struct inode *h_dir, *delegated;
11661 + struct path infopath = {
11662 + .mnt = w->h_ppath.mnt
11665 + h_dir = d_inode(w->h_ppath.dentry);
11666 + IMustLock(h_dir);
11670 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11671 + AuDebugOn(elm->created && elm->info_last);
11672 + if (elm->created) {
11674 + delegated = NULL;
11675 + infopath.dentry = elm->info_dentry;
11676 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11679 + if (unlikely(err == -EWOULDBLOCK))
11681 + dput(elm->info_dentry);
11682 + } else if (elm->info_last) {
11684 + w->fdata->drinfo = *elm->info_last;
11685 + memcpy(w->fdata->drinfo.oldname,
11686 + elm->info_last->oldname,
11687 + elm->info_last->oldnamelen);
11688 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11689 + au_kfree_rcu(elm->info_last);
11691 + if (unlikely(err))
11692 + AuIOErr("%d, %s\n", err, w->whname);
11693 + /* go on even if err */
11697 +/* caller has to call au_dr_rename_fin() later */
11698 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11699 + struct qstr *dst_name, void *_rev)
11701 + int err, sz, nelm;
11702 + aufs_bindex_t bindex, btail;
11703 + struct au_drinfo_store work;
11704 + struct au_drinfo_rev *rev, **p;
11705 + struct au_drinfo_rev_elm *elm;
11706 + struct super_block *sb;
11707 + struct au_branch *br;
11708 + struct au_hinode *hdir;
11710 + err = au_drinfo_store_work_init(&work, btgt);
11712 + if (unlikely(err))
11716 + btail = au_dbtaildir(dentry);
11717 + nelm = btail - btgt;
11718 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11719 + rev = kcalloc(1, sz, GFP_NOFS);
11720 + if (unlikely(!rev)) {
11724 + rev->nelm = nelm;
11730 + sb = dentry->d_sb;
11731 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11732 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11733 + hdir = au_hi(d_inode(dentry), btgt);
11734 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11735 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11736 + work.h_dentry = au_h_dptr(dentry, bindex);
11737 + if (!work.h_dentry)
11740 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11741 + &work.allocated);
11743 + if (unlikely(err))
11746 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11747 + br = au_sbr(sb, bindex);
11748 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11749 + work.whnamelen += au_drinfo_name(br, work.infoname,
11750 + work.infonamelen);
11751 + AuDbg("whname %.*s, i%llu, %.*s\n",
11752 + work.whnamelen, work.whname,
11753 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11754 + work.fdata->drinfo.oldnamelen,
11755 + work.fdata->drinfo.oldname);
11757 + err = au_drinfo_store_sio(&work, elm);
11759 + if (unlikely(err))
11762 + if (unlikely(err)) {
11763 + /* revert all drinfo */
11764 + au_drinfo_store_rev(rev, &work);
11765 + au_kfree_try_rcu(rev);
11768 + au_hn_inode_unlock(hdir);
11771 + au_drinfo_store_work_fin(&work);
11776 +/* ---------------------------------------------------------------------- */
11778 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11779 + struct qstr *dst_name, void *_rev)
11781 + int err, already;
11783 + struct super_block *sb;
11784 + struct au_branch *br;
11785 + struct au_dr_br *dr;
11786 + struct dentry *h_dentry;
11787 + struct inode *h_inode;
11788 + struct au_dr_hino *ent;
11789 + struct au_drinfo_rev *rev, **p;
11791 + AuDbg("bindex %d\n", bindex);
11794 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11795 + if (unlikely(!ent))
11799 + br = au_sbr(sb, bindex);
11800 + dr = &br->br_dirren;
11801 + h_dentry = au_h_dptr(src, bindex);
11802 + h_inode = d_inode(h_dentry);
11803 + ino = h_inode->i_ino;
11804 + ent->dr_h_ino = ino;
11805 + already = au_dr_hino_test_add(dr, ino, ent);
11806 + AuDbg("b%d, hi%llu, already %d\n",
11807 + bindex, (unsigned long long)ino, already);
11809 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11814 + rev->already = already;
11815 + goto out; /* success */
11820 + au_dr_hino_del(dr, ent);
11821 + au_kfree_rcu(ent);
11828 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11830 + struct au_drinfo_rev *rev;
11831 + struct au_drinfo_rev_elm *elm;
11836 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11837 + dput(elm->info_dentry);
11838 + au_kfree_rcu(elm->info_last);
11840 + au_kfree_try_rcu(rev);
11843 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11846 + struct au_drinfo_store work;
11847 + struct au_drinfo_rev *rev = _rev;
11848 + struct super_block *sb;
11849 + struct au_branch *br;
11850 + struct inode *h_inode;
11851 + struct au_dr_br *dr;
11852 + struct au_dr_hino *ent;
11854 + err = au_drinfo_store_work_init(&work, btgt);
11855 + if (unlikely(err))
11859 + br = au_sbr(sb, btgt);
11860 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11861 + work.h_ppath.mnt = au_br_mnt(br);
11862 + au_drinfo_store_rev(rev, &work);
11863 + au_drinfo_store_work_fin(&work);
11864 + if (rev->already)
11867 + dr = &br->br_dirren;
11868 + h_inode = d_inode(work.h_ppath.dentry);
11869 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11871 + au_dr_hino_del(dr, ent);
11872 + au_kfree_rcu(ent);
11875 + au_kfree_try_rcu(rev);
11876 + if (unlikely(err))
11877 + pr_err("failed to remove dirren info\n");
11880 +/* ---------------------------------------------------------------------- */
11882 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11883 + char *whname, int whnamelen,
11884 + struct dentry **info_dentry)
11886 + struct au_drinfo *drinfo;
11888 + struct inode *h_dir;
11889 + struct path infopath;
11892 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11894 + *info_dentry = NULL;
11897 + h_dir = d_inode(h_ppath->dentry);
11898 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11899 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11901 + if (IS_ERR(infopath.dentry)) {
11902 + drinfo = (void *)infopath.dentry;
11906 + if (d_is_negative(infopath.dentry))
11907 + goto out_dput; /* success */
11909 + infopath.mnt = h_ppath->mnt;
11910 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11911 + inode_unlock_shared(h_dir);
11914 + drinfo = (void *)f;
11918 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11919 + if (IS_ERR_OR_NULL(drinfo))
11922 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11923 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11928 + dput(infopath.dentry);
11931 + inode_unlock_shared(h_dir);
11932 + AuTraceErrPtr(drinfo);
11936 +struct au_drinfo_do_load_args {
11937 + struct au_drinfo **drinfop;
11938 + struct path *h_ppath;
11941 + struct dentry **info_dentry;
11944 +static void au_call_drinfo_do_load(void *args)
11946 + struct au_drinfo_do_load_args *a = args;
11948 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11952 +struct au_drinfo_load {
11953 + struct path h_ppath;
11954 + struct qstr *qname;
11955 + unsigned char no_sio;
11957 + aufs_bindex_t ninfo;
11958 + struct au_drinfo **drinfo;
11961 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11962 + struct au_branch *br)
11964 + int err, wkq_err, whnamelen, e;
11965 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11966 + = AUFS_WH_DR_INFO_PFX;
11967 + struct au_drinfo *drinfo;
11968 + struct qstr oldname;
11969 + struct inode *h_dir, *delegated;
11970 + struct dentry *info_dentry;
11971 + struct path infopath;
11973 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11974 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11975 + sizeof(whname) - whnamelen);
11977 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11980 + struct au_drinfo_do_load_args args = {
11981 + .drinfop = &drinfo,
11982 + .h_ppath = &w->h_ppath,
11983 + .whname = whname,
11984 + .whnamelen = whnamelen,
11985 + .info_dentry = &info_dentry
11987 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11988 + if (unlikely(wkq_err))
11989 + drinfo = ERR_PTR(wkq_err);
11991 + err = PTR_ERR(drinfo);
11992 + if (IS_ERR_OR_NULL(drinfo))
11996 + oldname.len = drinfo->oldnamelen;
11997 + oldname.name = drinfo->oldname;
11998 + if (au_qstreq(w->qname, &oldname)) {
11999 + /* the name is renamed back */
12000 + au_kfree_rcu(drinfo);
12003 + infopath.dentry = info_dentry;
12004 + infopath.mnt = w->h_ppath.mnt;
12005 + h_dir = d_inode(w->h_ppath.dentry);
12006 + delegated = NULL;
12007 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12008 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12009 + inode_unlock(h_dir);
12011 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12012 + if (unlikely(e == -EWOULDBLOCK))
12015 + au_kfree_rcu(w->drinfo[bindex]);
12016 + w->drinfo[bindex] = drinfo;
12017 + dput(info_dentry);
12024 +/* ---------------------------------------------------------------------- */
12026 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12028 + struct au_drinfo **p = drinfo;
12031 + au_kfree_rcu(*drinfo++);
12032 + au_kfree_try_rcu(p);
12035 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12036 + aufs_bindex_t btgt)
12039 + struct au_drinfo_load w;
12040 + aufs_bindex_t bindex, bbot;
12041 + struct au_branch *br;
12042 + struct inode *h_dir;
12043 + struct au_dr_hino *ent;
12044 + struct super_block *sb;
12046 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12047 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12048 + AuLNPair(&lkup->whname), btgt);
12050 + sb = dentry->d_sb;
12051 + bbot = au_sbbot(sb);
12052 + w.ninfo = bbot + 1;
12053 + if (!lkup->dirren.drinfo) {
12054 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12055 + sizeof(*lkup->dirren.drinfo),
12057 + if (unlikely(!lkup->dirren.drinfo)) {
12061 + lkup->dirren.ninfo = w.ninfo;
12063 + w.drinfo = lkup->dirren.drinfo;
12064 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12065 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12066 + AuDebugOn(!w.h_ppath.dentry);
12067 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12068 + w.qname = &dentry->d_name;
12071 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12072 + br = au_sbr(sb, bindex);
12073 + err = au_drinfo_load(&w, bindex, br);
12074 + if (unlikely(err))
12076 + if (w.drinfo[bindex])
12080 + br = au_sbr(sb, btgt);
12081 + h_dir = d_inode(w.h_ppath.dentry);
12082 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12084 + au_dr_hino_del(&br->br_dirren, ent);
12085 + au_kfree_rcu(ent);
12087 + goto out; /* success */
12090 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12091 + lkup->dirren.ninfo = 0;
12092 + lkup->dirren.drinfo = NULL;
12098 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12100 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12103 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12106 + struct au_drinfo *drinfo;
12109 + if (!lkup->dirren.drinfo)
12111 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12112 + drinfo = lkup->dirren.drinfo[btgt];
12116 + au_kfree_try_rcu(lkup->whname.name);
12117 + lkup->whname.name = NULL;
12118 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12119 + lkup->dirren.dr_name.name = drinfo->oldname;
12120 + lkup->name = &lkup->dirren.dr_name;
12121 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12123 + AuDbg("name %.*s, whname %.*s, b%d\n",
12124 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12132 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12136 + struct au_drinfo *drinfo;
12139 + if (!lkup->dirren.drinfo)
12141 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12142 + drinfo = lkup->dirren.drinfo[bindex];
12146 + match = (drinfo->ino == h_ino);
12147 + AuDbg("match %d\n", match);
12153 +/* ---------------------------------------------------------------------- */
12155 +int au_dr_opt_set(struct super_block *sb)
12158 + aufs_bindex_t bindex, bbot;
12159 + struct au_branch *br;
12162 + bbot = au_sbbot(sb);
12163 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12164 + br = au_sbr(sb, bindex);
12165 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12171 +int au_dr_opt_flush(struct super_block *sb)
12174 + aufs_bindex_t bindex, bbot;
12175 + struct au_branch *br;
12178 + bbot = au_sbbot(sb);
12179 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12180 + br = au_sbr(sb, bindex);
12181 + if (au_br_writable(br->br_perm))
12182 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12188 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12191 + aufs_bindex_t bindex, bbot;
12192 + struct au_branch *br;
12196 + err = au_dr_opt_flush(sb);
12197 + if (unlikely(err))
12201 + bbot = au_sbbot(sb);
12202 + for (bindex = 0; bindex <= bbot; bindex++) {
12203 + br = au_sbr(sb, bindex);
12204 + au_dr_hino_free(&br->br_dirren);
12210 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12211 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12212 +++ linux/fs/aufs/dirren.h 2021-05-02 20:15:14.673337458 +0200
12214 +/* SPDX-License-Identifier: GPL-2.0 */
12216 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12218 + * This program, aufs is free software; you can redistribute it and/or modify
12219 + * it under the terms of the GNU General Public License as published by
12220 + * the Free Software Foundation; either version 2 of the License, or
12221 + * (at your option) any later version.
12223 + * This program is distributed in the hope that it will be useful,
12224 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12225 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12226 + * GNU General Public License for more details.
12228 + * You should have received a copy of the GNU General Public License
12229 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12233 + * renamed dir info
12236 +#ifndef __AUFS_DIRREN_H__
12237 +#define __AUFS_DIRREN_H__
12241 +#include <linux/dcache.h>
12242 +#include <linux/statfs.h>
12243 +#include <linux/uuid.h>
12246 +#define AuDirren_NHASH 100
12248 +#ifdef CONFIG_AUFS_DIRREN
12249 +enum au_brid_type {
12256 +struct au_dr_brid {
12257 + enum au_brid_type type;
12259 + uuid_t uuid; /* unimplemented yet */
12265 +/* 20 is the max digits length of ulong 64 */
12266 +/* brid-type "_" uuid "_" inum */
12267 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12268 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12270 +struct au_dr_hino {
12271 + struct hlist_bl_node dr_hnode;
12276 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12277 + struct au_dr_brid dr_brid;
12280 +struct au_dr_lookup {
12281 + /* dr_name is pointed by struct au_do_lookup_args.name */
12282 + struct qstr dr_name; /* subset of dr_info */
12283 + aufs_bindex_t ninfo;
12284 + struct au_drinfo **drinfo;
12287 +struct au_dr_hino;
12289 +struct au_dr_br { };
12290 +struct au_dr_lookup { };
12293 +/* ---------------------------------------------------------------------- */
12296 +struct au_do_lookup_args;
12298 +#ifdef CONFIG_AUFS_DIRREN
12299 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12300 + struct au_dr_hino *add_ent);
12301 +void au_dr_hino_free(struct au_dr_br *dr);
12302 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12303 + const struct path *path);
12304 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12305 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12306 + struct qstr *dst_name, void *_rev);
12307 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12308 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12309 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12310 + aufs_bindex_t bindex);
12311 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12312 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12314 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12315 +int au_dr_opt_set(struct super_block *sb);
12316 +int au_dr_opt_flush(struct super_block *sb);
12317 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12319 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12320 + struct au_dr_hino *add_ent);
12321 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12322 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12323 + const struct path *path);
12324 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12325 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12326 + struct qstr *dst_name, void *_rev);
12327 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12328 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12330 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12331 + aufs_bindex_t bindex);
12332 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12333 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12334 + aufs_bindex_t bindex, ino_t h_ino);
12335 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12336 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12337 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12338 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12341 +/* ---------------------------------------------------------------------- */
12343 +#ifdef CONFIG_AUFS_DIRREN
12344 +static inline int au_dr_ihash(ino_t h_ino)
12346 + return h_ino % AuDirren_NHASH;
12349 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12352 +#endif /* __KERNEL__ */
12353 +#endif /* __AUFS_DIRREN_H__ */
12354 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12355 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12356 +++ linux/fs/aufs/dynop.c 2021-05-02 20:15:14.673337458 +0200
12358 +// SPDX-License-Identifier: GPL-2.0
12360 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12362 + * This program, aufs is free software; you can redistribute it and/or modify
12363 + * it under the terms of the GNU General Public License as published by
12364 + * the Free Software Foundation; either version 2 of the License, or
12365 + * (at your option) any later version.
12367 + * This program is distributed in the hope that it will be useful,
12368 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12369 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12370 + * GNU General Public License for more details.
12372 + * You should have received a copy of the GNU General Public License
12373 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12377 + * dynamically customizable operations for regular files
12382 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12385 + * How large will these lists be?
12386 + * Usually just a few elements, 20-30 at most for each, I guess.
12388 +static struct hlist_bl_head dynop[AuDyLast];
12390 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12391 + const void *h_op)
12393 + struct au_dykey *key, *tmp;
12394 + struct hlist_bl_node *pos;
12397 + hlist_bl_lock(hbl);
12398 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12399 + if (tmp->dk_op.dy_hop == h_op) {
12400 + if (kref_get_unless_zero(&tmp->dk_kref))
12404 + hlist_bl_unlock(hbl);
12409 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12411 + struct au_dykey **k, *found;
12412 + const void *h_op = key->dk_op.dy_hop;
12416 + k = br->br_dykey;
12417 + for (i = 0; i < AuBrDynOp; i++)
12419 + if (k[i]->dk_op.dy_hop == h_op) {
12426 + spin_lock(&br->br_dykey_lock);
12427 + for (; i < AuBrDynOp; i++)
12429 + if (k[i]->dk_op.dy_hop == h_op) {
12437 + spin_unlock(&br->br_dykey_lock);
12438 + BUG_ON(i == AuBrDynOp); /* expand the array */
12444 +/* kref_get() if @key is already added */
12445 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12447 + struct au_dykey *tmp, *found;
12448 + struct hlist_bl_node *pos;
12449 + const void *h_op = key->dk_op.dy_hop;
12452 + hlist_bl_lock(hbl);
12453 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12454 + if (tmp->dk_op.dy_hop == h_op) {
12455 + if (kref_get_unless_zero(&tmp->dk_kref))
12460 + hlist_bl_add_head(&key->dk_hnode, hbl);
12461 + hlist_bl_unlock(hbl);
12468 +static void dy_free_rcu(struct rcu_head *rcu)
12470 + struct au_dykey *key;
12472 + key = container_of(rcu, struct au_dykey, dk_rcu);
12477 +static void dy_free(struct kref *kref)
12479 + struct au_dykey *key;
12480 + struct hlist_bl_head *hbl;
12482 + key = container_of(kref, struct au_dykey, dk_kref);
12483 + hbl = dynop + key->dk_op.dy_type;
12484 + au_hbl_del(&key->dk_hnode, hbl);
12485 + call_rcu(&key->dk_rcu, dy_free_rcu);
12488 +void au_dy_put(struct au_dykey *key)
12490 + kref_put(&key->dk_kref, dy_free);
12493 +/* ---------------------------------------------------------------------- */
12495 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12497 +#ifdef CONFIG_AUFS_DEBUG
12498 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12499 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12501 +#define DyDbgDeclare(cnt) do {} while (0)
12502 +#define DyDbgInc(cnt) do {} while (0)
12505 +#define DySet(func, dst, src, h_op, h_sb) do { \
12507 + if (h_op->func) { \
12509 + dst.func = src.func; \
12511 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12515 +#define DySetForce(func, dst, src) do { \
12516 + AuDebugOn(!src.func); \
12518 + dst.func = src.func; \
12521 +#define DySetAop(func) \
12522 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12523 +#define DySetAopForce(func) \
12524 + DySetForce(func, dyaop->da_op, aufs_aop)
12526 +static void dy_aop(struct au_dykey *key, const void *h_op,
12527 + struct super_block *h_sb __maybe_unused)
12529 + struct au_dyaop *dyaop = (void *)key;
12530 + const struct address_space_operations *h_aop = h_op;
12531 + DyDbgDeclare(cnt);
12533 + AuDbg("%s\n", au_sbtype(h_sb));
12535 + DySetAop(writepage);
12536 + DySetAopForce(readpage); /* force */
12537 + DySetAop(writepages);
12538 + DySetAop(set_page_dirty);
12539 + DySetAop(readpages);
12540 + DySetAop(readahead);
12541 + DySetAop(write_begin);
12542 + DySetAop(write_end);
12544 + DySetAop(invalidatepage);
12545 + DySetAop(releasepage);
12546 + DySetAop(freepage);
12547 + /* this one will be changed according to an aufs mount option */
12548 + DySetAop(direct_IO);
12549 + DySetAop(migratepage);
12550 + DySetAop(isolate_page);
12551 + DySetAop(putback_page);
12552 + DySetAop(launder_page);
12553 + DySetAop(is_partially_uptodate);
12554 + DySetAop(is_dirty_writeback);
12555 + DySetAop(error_remove_page);
12556 + DySetAop(swap_activate);
12557 + DySetAop(swap_deactivate);
12559 + DyDbgSize(cnt, *h_aop);
12562 +/* ---------------------------------------------------------------------- */
12564 +static void dy_bug(struct kref *kref)
12569 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12571 + struct au_dykey *key, *old;
12572 + struct hlist_bl_head *hbl;
12575 + void (*set)(struct au_dykey *key, const void *h_op,
12576 + struct super_block *h_sb __maybe_unused);
12578 + static const struct op a[] = {
12580 + .sz = sizeof(struct au_dyaop),
12584 + const struct op *p;
12586 + hbl = dynop + op->dy_type;
12587 + key = dy_gfind_get(hbl, op->dy_hop);
12589 + goto out_add; /* success */
12591 + p = a + op->dy_type;
12592 + key = kzalloc(p->sz, GFP_NOFS);
12593 + if (unlikely(!key)) {
12594 + key = ERR_PTR(-ENOMEM);
12598 + key->dk_op.dy_hop = op->dy_hop;
12599 + kref_init(&key->dk_kref);
12600 + p->set(key, op->dy_hop, au_br_sb(br));
12601 + old = dy_gadd(hbl, key);
12603 + au_kfree_rcu(key);
12608 + old = dy_bradd(br, key);
12610 + /* its ref-count should never be zero here */
12611 + kref_put(&key->dk_kref, dy_bug);
12616 +/* ---------------------------------------------------------------------- */
12618 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12619 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12620 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12621 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12622 + * See the aufs manual in detail.
12624 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12627 + dyaop->da_op.direct_IO = NULL;
12629 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12632 +static struct au_dyaop *dy_aget(struct au_branch *br,
12633 + const struct address_space_operations *h_aop,
12636 + struct au_dyaop *dyaop;
12637 + struct au_dynop op;
12639 + op.dy_type = AuDy_AOP;
12640 + op.dy_haop = h_aop;
12641 + dyaop = (void *)dy_get(&op, br);
12642 + if (IS_ERR(dyaop))
12644 + dy_adx(dyaop, do_dx);
12650 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12651 + struct inode *h_inode)
12654 + struct super_block *sb;
12655 + struct au_branch *br;
12656 + struct au_dyaop *dyaop;
12658 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12659 + IiMustWriteLock(inode);
12661 + sb = inode->i_sb;
12662 + br = au_sbr(sb, bindex);
12663 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12664 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12665 + err = PTR_ERR(dyaop);
12666 + if (IS_ERR(dyaop))
12667 + /* unnecessary to call dy_fput() */
12671 + inode->i_mapping->a_ops = &dyaop->da_op;
12678 + * Is it safe to replace a_ops during the inode/file is in operation?
12679 + * Yes, I hope so.
12681 +int au_dy_irefresh(struct inode *inode)
12684 + aufs_bindex_t btop;
12685 + struct inode *h_inode;
12688 + if (S_ISREG(inode->i_mode)) {
12689 + btop = au_ibtop(inode);
12690 + h_inode = au_h_iptr(inode, btop);
12691 + err = au_dy_iaop(inode, btop, h_inode);
12696 +void au_dy_arefresh(int do_dx)
12698 + struct hlist_bl_head *hbl;
12699 + struct hlist_bl_node *pos;
12700 + struct au_dykey *key;
12702 + hbl = dynop + AuDy_AOP;
12703 + hlist_bl_lock(hbl);
12704 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12705 + dy_adx((void *)key, do_dx);
12706 + hlist_bl_unlock(hbl);
12709 +/* ---------------------------------------------------------------------- */
12711 +void __init au_dy_init(void)
12715 + for (i = 0; i < AuDyLast; i++)
12716 + INIT_HLIST_BL_HEAD(dynop + i);
12719 +void au_dy_fin(void)
12723 + for (i = 0; i < AuDyLast; i++)
12724 + WARN_ON(!hlist_bl_empty(dynop + i));
12726 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12727 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12728 +++ linux/fs/aufs/dynop.h 2021-05-02 20:15:14.673337458 +0200
12730 +/* SPDX-License-Identifier: GPL-2.0 */
12732 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12734 + * This program, aufs is free software; you can redistribute it and/or modify
12735 + * it under the terms of the GNU General Public License as published by
12736 + * the Free Software Foundation; either version 2 of the License, or
12737 + * (at your option) any later version.
12739 + * This program is distributed in the hope that it will be useful,
12740 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12741 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12742 + * GNU General Public License for more details.
12744 + * You should have received a copy of the GNU General Public License
12745 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12749 + * dynamically customizable operations (for regular files only)
12752 +#ifndef __AUFS_DYNOP_H__
12753 +#define __AUFS_DYNOP_H__
12757 +#include <linux/fs.h>
12758 +#include <linux/kref.h>
12760 +enum {AuDy_AOP, AuDyLast};
12765 + const void *dy_hop;
12766 + const struct address_space_operations *dy_haop;
12772 + struct hlist_bl_node dk_hnode;
12773 + struct rcu_head dk_rcu;
12775 + struct au_dynop dk_op;
12778 + * during I am in the branch local array, kref is gotten. when the
12779 + * branch is removed, kref is put.
12781 + struct kref dk_kref;
12784 +/* stop unioning since their sizes are very different from each other */
12786 + struct au_dykey da_key;
12787 + struct address_space_operations da_op; /* not const */
12789 +/* make sure that 'struct au_dykey *' can be any type */
12790 +static_assert(!offsetof(struct au_dyaop, da_key));
12792 +/* ---------------------------------------------------------------------- */
12796 +void au_dy_put(struct au_dykey *key);
12797 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12798 + struct inode *h_inode);
12799 +int au_dy_irefresh(struct inode *inode);
12800 +void au_dy_arefresh(int do_dio);
12802 +void __init au_dy_init(void);
12803 +void au_dy_fin(void);
12805 +#endif /* __KERNEL__ */
12806 +#endif /* __AUFS_DYNOP_H__ */
12807 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12808 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12809 +++ linux/fs/aufs/export.c 2021-05-02 20:15:14.673337458 +0200
12811 +// SPDX-License-Identifier: GPL-2.0
12813 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12815 + * This program, aufs is free software; you can redistribute it and/or modify
12816 + * it under the terms of the GNU General Public License as published by
12817 + * the Free Software Foundation; either version 2 of the License, or
12818 + * (at your option) any later version.
12820 + * This program is distributed in the hope that it will be useful,
12821 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12822 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12823 + * GNU General Public License for more details.
12825 + * You should have received a copy of the GNU General Public License
12826 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12833 +#include <linux/exportfs.h>
12834 +#include <linux/fs_struct.h>
12835 +#include <linux/namei.h>
12836 +#include <linux/nsproxy.h>
12837 +#include <linux/random.h>
12838 +#include <linux/writeback.h>
12842 +#ifdef CONFIG_AUFS_INO_T_64
12850 +static ino_t decode_ino(__u32 *a)
12854 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12856 +#ifdef CONFIG_AUFS_INO_T_64
12862 +static void encode_ino(__u32 *a, ino_t ino)
12868 +#ifdef CONFIG_AUFS_INO_T_64
12873 +/* NFS file handle */
12877 +#ifdef CONFIG_AUFS_INO_T_64
12878 + /* support 64bit inode number */
12891 + Fh_ino = Fh_ino1,
12892 + Fh_dir_ino = Fh_dir_ino1
12895 +static int au_test_anon(struct dentry *dentry)
12897 + /* note: read d_flags without d_lock */
12898 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12901 +int au_test_nfsd(void)
12904 + struct task_struct *tsk = current;
12905 + char comm[sizeof(tsk->comm)];
12908 + if (tsk->flags & PF_KTHREAD) {
12909 + get_task_comm(comm, tsk);
12910 + ret = !strcmp(comm, "nfsd");
12916 +/* ---------------------------------------------------------------------- */
12917 +/* inode generation external table */
12919 +void au_xigen_inc(struct inode *inode)
12924 + struct super_block *sb;
12925 + struct au_sbinfo *sbinfo;
12927 + sb = inode->i_sb;
12928 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12930 + sbinfo = au_sbi(sb);
12931 + pos = inode->i_ino;
12932 + pos *= sizeof(igen);
12933 + igen = inode->i_generation + 1;
12934 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12935 + if (sz == sizeof(igen))
12936 + return; /* success */
12938 + if (unlikely(sz >= 0))
12939 + AuIOErr("xigen error (%zd)\n", sz);
12942 +int au_xigen_new(struct inode *inode)
12947 + struct super_block *sb;
12948 + struct au_sbinfo *sbinfo;
12949 + struct file *file;
12952 + /* todo: dirty, at mount time */
12953 + if (inode->i_ino == AUFS_ROOT_INO)
12955 + sb = inode->i_sb;
12956 + SiMustAnyLock(sb);
12957 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12961 + pos = inode->i_ino;
12962 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12963 + AuIOErr1("too large i%lld\n", pos);
12966 + pos *= sizeof(inode->i_generation);
12969 + sbinfo = au_sbi(sb);
12970 + file = sbinfo->si_xigen;
12973 + if (vfsub_f_size_read(file)
12974 + < pos + sizeof(inode->i_generation)) {
12975 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12976 + sz = xino_fwrite(file, &inode->i_generation,
12977 + sizeof(inode->i_generation), &pos);
12979 + sz = xino_fread(file, &inode->i_generation,
12980 + sizeof(inode->i_generation), &pos);
12981 + if (sz == sizeof(inode->i_generation))
12982 + goto out; /* success */
12985 + if (unlikely(sz >= 0)) {
12987 + AuIOErr("xigen error (%zd)\n", sz);
12994 +int au_xigen_set(struct super_block *sb, struct path *path)
12997 + struct au_sbinfo *sbinfo;
12998 + struct file *file;
13000 + SiMustWriteLock(sb);
13002 + sbinfo = au_sbi(sb);
13003 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
13004 + err = PTR_ERR(file);
13005 + if (IS_ERR(file))
13008 + if (sbinfo->si_xigen)
13009 + fput(sbinfo->si_xigen);
13010 + sbinfo->si_xigen = file;
13017 +void au_xigen_clr(struct super_block *sb)
13019 + struct au_sbinfo *sbinfo;
13021 + SiMustWriteLock(sb);
13023 + sbinfo = au_sbi(sb);
13024 + if (sbinfo->si_xigen) {
13025 + fput(sbinfo->si_xigen);
13026 + sbinfo->si_xigen = NULL;
13030 +/* ---------------------------------------------------------------------- */
13032 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13035 + struct dentry *dentry, *d;
13036 + struct inode *inode;
13037 + unsigned int sigen;
13040 + inode = ilookup(sb, ino);
13044 + dentry = ERR_PTR(-ESTALE);
13045 + sigen = au_sigen(sb);
13046 + if (unlikely(au_is_bad_inode(inode)
13047 + || IS_DEADDIR(inode)
13048 + || sigen != au_iigen(inode, NULL)))
13052 + if (!dir_ino || S_ISDIR(inode->i_mode))
13053 + dentry = d_find_alias(inode);
13055 + spin_lock(&inode->i_lock);
13056 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13057 + spin_lock(&d->d_lock);
13058 + if (!au_test_anon(d)
13059 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13060 + dentry = dget_dlock(d);
13061 + spin_unlock(&d->d_lock);
13064 + spin_unlock(&d->d_lock);
13066 + spin_unlock(&inode->i_lock);
13068 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13069 + /* need to refresh */
13077 + AuTraceErrPtr(dentry);
13081 +/* ---------------------------------------------------------------------- */
13083 +/* todo: dirty? */
13084 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13086 +struct au_compare_mnt_args {
13088 + struct super_block *sb;
13091 + struct vfsmount *mnt;
13094 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13096 + struct au_compare_mnt_args *a = arg;
13098 + if (mnt->mnt_sb != a->sb)
13100 + a->mnt = mntget(mnt);
13104 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13107 + struct path root;
13108 + struct au_compare_mnt_args args = {
13112 + get_fs_root(current->fs, &root);
13114 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13115 + rcu_read_unlock();
13118 + AuDebugOn(!args.mnt);
13122 +struct au_nfsd_si_lock {
13123 + unsigned int sigen;
13124 + aufs_bindex_t bindex, br_id;
13125 + unsigned char force_lock;
13128 +static int si_nfsd_read_lock(struct super_block *sb,
13129 + struct au_nfsd_si_lock *nsi_lock)
13132 + aufs_bindex_t bindex;
13134 + si_read_lock(sb, AuLock_FLUSH);
13136 + /* branch id may be wrapped around */
13138 + bindex = au_br_index(sb, nsi_lock->br_id);
13139 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13140 + goto out; /* success */
13144 + if (!nsi_lock->force_lock)
13145 + si_read_unlock(sb);
13148 + nsi_lock->bindex = bindex;
13152 +struct find_name_by_ino {
13153 + struct dir_context ctx;
13154 + int called, found;
13161 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13162 + loff_t offset, u64 ino, unsigned int d_type)
13164 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13168 + if (a->ino != ino)
13171 + memcpy(a->name, name, namelen);
13172 + a->namelen = namelen;
13177 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13178 + struct au_nfsd_si_lock *nsi_lock)
13180 + struct dentry *dentry, *parent;
13181 + struct file *file;
13182 + struct inode *dir;
13183 + struct find_name_by_ino arg = {
13185 + .actor = find_name_by_ino
13190 + parent = path->dentry;
13192 + si_read_unlock(parent->d_sb);
13193 + file = vfsub_dentry_open(path, au_dir_roflags);
13194 + dentry = (void *)file;
13195 + if (IS_ERR(file))
13198 + dentry = ERR_PTR(-ENOMEM);
13199 + arg.name = (void *)__get_free_page(GFP_NOFS);
13200 + if (unlikely(!arg.name))
13207 + err = vfsub_iterate_dir(file, &arg.ctx);
13208 + } while (!err && !arg.found && arg.called);
13209 + dentry = ERR_PTR(err);
13210 + if (unlikely(err))
13212 + /* instead of ENOENT */
13213 + dentry = ERR_PTR(-ESTALE);
13217 + /* do not call vfsub_lkup_one() */
13218 + dir = d_inode(parent);
13219 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13220 + AuTraceErrPtr(dentry);
13221 + if (IS_ERR(dentry))
13223 + AuDebugOn(au_test_anon(dentry));
13224 + if (unlikely(d_really_is_negative(dentry))) {
13226 + dentry = ERR_PTR(-ENOENT);
13230 + free_page((unsigned long)arg.name);
13234 + if (unlikely(nsi_lock
13235 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13236 + if (!IS_ERR(dentry)) {
13238 + dentry = ERR_PTR(-ESTALE);
13240 + AuTraceErrPtr(dentry);
13244 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13246 + struct au_nfsd_si_lock *nsi_lock)
13248 + struct dentry *dentry;
13249 + struct path path;
13251 + if (dir_ino != AUFS_ROOT_INO) {
13252 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13253 + dentry = path.dentry;
13254 + if (!path.dentry || IS_ERR(path.dentry))
13256 + AuDebugOn(au_test_anon(path.dentry));
13258 + path.dentry = dget(sb->s_root);
13260 + path.mnt = au_mnt_get(sb);
13261 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13265 + AuTraceErrPtr(dentry);
13269 +/* ---------------------------------------------------------------------- */
13271 +static int h_acceptable(void *expv, struct dentry *dentry)
13276 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13277 + char *buf, int len, struct super_block *sb)
13281 + struct path path;
13283 + p = d_path(h_rootpath, buf, len);
13288 + path.mnt = h_rootpath->mnt;
13289 + path.dentry = h_parent;
13290 + p = d_path(&path, buf, len);
13296 + path.mnt = au_mnt_get(sb);
13297 + path.dentry = sb->s_root;
13298 + p = d_path(&path, buf, len - strlen(p));
13299 + mntput(path.mnt);
13303 + p[strlen(p)] = '/';
13306 + AuTraceErrPtr(p);
13311 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13312 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13314 + struct dentry *dentry, *h_parent, *root;
13315 + struct super_block *h_sb;
13316 + char *pathname, *p;
13317 + struct vfsmount *h_mnt;
13318 + struct au_branch *br;
13320 + struct path path;
13322 + br = au_sbr(sb, nsi_lock->bindex);
13323 + h_mnt = au_br_mnt(br);
13324 + h_sb = h_mnt->mnt_sb;
13325 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13327 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13328 + fh_len - Fh_tail, fh[Fh_h_type],
13329 + h_acceptable, /*context*/NULL);
13331 + dentry = h_parent;
13332 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13333 + AuWarn1("%s decode_fh failed, %ld\n",
13334 + au_sbtype(h_sb), PTR_ERR(h_parent));
13338 + if (unlikely(au_test_anon(h_parent))) {
13339 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13340 + au_sbtype(h_sb));
13341 + goto out_h_parent;
13344 + dentry = ERR_PTR(-ENOMEM);
13345 + pathname = (void *)__get_free_page(GFP_NOFS);
13346 + if (unlikely(!pathname))
13347 + goto out_h_parent;
13349 + root = sb->s_root;
13350 + path.mnt = h_mnt;
13351 + di_read_lock_parent(root, !AuLock_IR);
13352 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13353 + di_read_unlock(root, !AuLock_IR);
13354 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13355 + dentry = (void *)p;
13357 + goto out_pathname;
13359 + si_read_unlock(sb);
13360 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13361 + dentry = ERR_PTR(err);
13362 + if (unlikely(err))
13365 + dentry = ERR_PTR(-ENOENT);
13366 + AuDebugOn(au_test_anon(path.dentry));
13367 + if (unlikely(d_really_is_negative(path.dentry)))
13370 + if (ino != d_inode(path.dentry)->i_ino)
13371 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13373 + dentry = dget(path.dentry);
13378 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13379 + if (!IS_ERR(dentry)) {
13381 + dentry = ERR_PTR(-ESTALE);
13384 + free_page((unsigned long)pathname);
13388 + AuTraceErrPtr(dentry);
13392 +/* ---------------------------------------------------------------------- */
13394 +static struct dentry *
13395 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13398 + struct dentry *dentry;
13399 + __u32 *fh = fid->raw;
13400 + struct au_branch *br;
13401 + ino_t ino, dir_ino;
13402 + struct au_nfsd_si_lock nsi_lock = {
13406 + dentry = ERR_PTR(-ESTALE);
13407 + /* it should never happen, but the file handle is unreliable */
13408 + if (unlikely(fh_len < Fh_tail))
13410 + nsi_lock.sigen = fh[Fh_sigen];
13411 + nsi_lock.br_id = fh[Fh_br_id];
13413 + /* branch id may be wrapped around */
13415 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13417 + nsi_lock.force_lock = 1;
13419 + /* is this inode still cached? */
13420 + ino = decode_ino(fh + Fh_ino);
13421 + /* it should never happen */
13422 + if (unlikely(ino == AUFS_ROOT_INO))
13425 + dir_ino = decode_ino(fh + Fh_dir_ino);
13426 + dentry = decode_by_ino(sb, ino, dir_ino);
13427 + if (IS_ERR(dentry))
13432 + /* is the parent dir cached? */
13433 + br = au_sbr(sb, nsi_lock.bindex);
13434 + au_lcnt_inc(&br->br_nfiles);
13435 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13436 + if (IS_ERR(dentry))
13441 + /* lookup path */
13442 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13443 + if (IS_ERR(dentry))
13445 + if (unlikely(!dentry))
13446 + /* todo?: make it ESTALE */
13450 + if (!au_digen_test(dentry, au_sigen(sb))
13451 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13452 + goto out_unlock; /* success */
13455 + dentry = ERR_PTR(-ESTALE);
13458 + au_lcnt_dec(&br->br_nfiles);
13459 + si_read_unlock(sb);
13461 + AuTraceErrPtr(dentry);
13465 +#if 0 /* reserved for future use */
13466 +/* support subtreecheck option */
13467 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13468 + int fh_len, int fh_type)
13470 + struct dentry *parent;
13471 + __u32 *fh = fid->raw;
13474 + dir_ino = decode_ino(fh + Fh_dir_ino);
13475 + parent = decode_by_ino(sb, dir_ino, 0);
13476 + if (IS_ERR(parent))
13479 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13480 + dir_ino, fh, fh_len);
13483 + AuTraceErrPtr(parent);
13488 +/* ---------------------------------------------------------------------- */
13490 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13491 + struct inode *dir)
13494 + aufs_bindex_t bindex;
13495 + struct super_block *sb, *h_sb;
13496 + struct dentry *dentry, *parent, *h_parent;
13497 + struct inode *h_dir;
13498 + struct au_branch *br;
13501 + if (unlikely(*max_len <= Fh_tail)) {
13502 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13506 + err = FILEID_ROOT;
13507 + if (inode->i_ino == AUFS_ROOT_INO) {
13508 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13513 + sb = inode->i_sb;
13514 + err = si_read_lock(sb, AuLock_FLUSH);
13515 + if (unlikely(err))
13518 +#ifdef CONFIG_AUFS_DEBUG
13519 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13520 + AuWarn1("NFS-exporting requires xino\n");
13524 + ii_read_lock_child(inode);
13525 + bindex = au_ibtop(inode);
13527 + dentry = d_find_any_alias(inode);
13528 + if (unlikely(!dentry))
13530 + AuDebugOn(au_test_anon(dentry));
13531 + parent = dget_parent(dentry);
13533 + if (unlikely(!parent))
13535 + if (d_really_is_positive(parent))
13536 + dir = d_inode(parent);
13539 + ii_read_lock_parent(dir);
13540 + h_dir = au_h_iptr(dir, bindex);
13541 + ii_read_unlock(dir);
13542 + if (unlikely(!h_dir))
13544 + h_parent = d_find_any_alias(h_dir);
13545 + if (unlikely(!h_parent))
13546 + goto out_hparent;
13549 + br = au_sbr(sb, bindex);
13550 + h_sb = au_br_sb(br);
13551 + if (unlikely(!h_sb->s_export_op)) {
13552 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13553 + goto out_hparent;
13556 + fh[Fh_br_id] = br->br_id;
13557 + fh[Fh_sigen] = au_sigen(sb);
13558 + encode_ino(fh + Fh_ino, inode->i_ino);
13559 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13560 + fh[Fh_igen] = inode->i_generation;
13562 + *max_len -= Fh_tail;
13563 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13565 + /*connectable or subtreecheck*/0);
13566 + err = fh[Fh_h_type];
13567 + *max_len += Fh_tail;
13568 + /* todo: macros? */
13569 + if (err != FILEID_INVALID)
13572 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13579 + ii_read_unlock(inode);
13580 + si_read_unlock(sb);
13582 + if (unlikely(err < 0))
13583 + err = FILEID_INVALID;
13587 +/* ---------------------------------------------------------------------- */
13589 +static int aufs_commit_metadata(struct inode *inode)
13592 + aufs_bindex_t bindex;
13593 + struct super_block *sb;
13594 + struct inode *h_inode;
13595 + int (*f)(struct inode *inode);
13597 + sb = inode->i_sb;
13598 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13599 + ii_write_lock_child(inode);
13600 + bindex = au_ibtop(inode);
13601 + AuDebugOn(bindex < 0);
13602 + h_inode = au_h_iptr(inode, bindex);
13604 + f = h_inode->i_sb->s_export_op->commit_metadata;
13606 + err = f(h_inode);
13608 + struct writeback_control wbc = {
13609 + .sync_mode = WB_SYNC_ALL,
13610 + .nr_to_write = 0 /* metadata only */
13613 + err = sync_inode(h_inode, &wbc);
13616 + au_cpup_attr_timesizes(inode);
13617 + ii_write_unlock(inode);
13618 + si_read_unlock(sb);
13622 +/* ---------------------------------------------------------------------- */
13624 +static struct export_operations aufs_export_op = {
13625 + .fh_to_dentry = aufs_fh_to_dentry,
13626 + /* .fh_to_parent = aufs_fh_to_parent, */
13627 + .encode_fh = aufs_encode_fh,
13628 + .commit_metadata = aufs_commit_metadata
13631 +void au_export_init(struct super_block *sb)
13633 + struct au_sbinfo *sbinfo;
13636 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13637 + && IS_MODULE(CONFIG_EXPORTFS),
13638 + AUFS_NAME ": unsupported configuration "
13639 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13641 + sb->s_export_op = &aufs_export_op;
13642 + sbinfo = au_sbi(sb);
13643 + sbinfo->si_xigen = NULL;
13644 + get_random_bytes(&u, sizeof(u));
13645 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13646 + atomic_set(&sbinfo->si_xigen_next, u);
13648 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13649 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13650 +++ linux/fs/aufs/fhsm.c 2021-05-02 20:15:14.673337458 +0200
13652 +// SPDX-License-Identifier: GPL-2.0
13654 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13656 + * This program, aufs is free software; you can redistribute it and/or modify
13657 + * it under the terms of the GNU General Public License as published by
13658 + * the Free Software Foundation; either version 2 of the License, or
13659 + * (at your option) any later version.
13661 + * This program is distributed in the hope that it will be useful,
13662 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13663 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13664 + * GNU General Public License for more details.
13666 + * You should have received a copy of the GNU General Public License
13667 + * along with this program; if not, write to the Free Software
13668 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13672 + * File-based Hierarchy Storage Management
13675 +#include <linux/anon_inodes.h>
13676 +#include <linux/poll.h>
13677 +#include <linux/seq_file.h>
13678 +#include <linux/statfs.h>
13681 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13683 + struct au_sbinfo *sbinfo;
13684 + struct au_fhsm *fhsm;
13686 + SiMustAnyLock(sb);
13688 + sbinfo = au_sbi(sb);
13689 + fhsm = &sbinfo->si_fhsm;
13690 + AuDebugOn(!fhsm);
13691 + return fhsm->fhsm_bottom;
13694 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13696 + struct au_sbinfo *sbinfo;
13697 + struct au_fhsm *fhsm;
13699 + SiMustWriteLock(sb);
13701 + sbinfo = au_sbi(sb);
13702 + fhsm = &sbinfo->si_fhsm;
13703 + AuDebugOn(!fhsm);
13704 + fhsm->fhsm_bottom = bindex;
13707 +/* ---------------------------------------------------------------------- */
13709 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13711 + struct au_br_fhsm *bf;
13713 + bf = br->br_fhsm;
13714 + MtxMustLock(&bf->bf_lock);
13716 + return !bf->bf_readable
13717 + || time_after(jiffies,
13718 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13721 +/* ---------------------------------------------------------------------- */
13723 +static void au_fhsm_notify(struct super_block *sb, int val)
13725 + struct au_sbinfo *sbinfo;
13726 + struct au_fhsm *fhsm;
13728 + SiMustAnyLock(sb);
13730 + sbinfo = au_sbi(sb);
13731 + fhsm = &sbinfo->si_fhsm;
13732 + if (au_fhsm_pid(fhsm)
13733 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13734 + atomic_set(&fhsm->fhsm_readable, val);
13736 + wake_up(&fhsm->fhsm_wqh);
13740 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13741 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13744 + struct au_branch *br;
13745 + struct au_br_fhsm *bf;
13747 + br = au_sbr(sb, bindex);
13748 + AuDebugOn(au_br_rdonly(br));
13749 + bf = br->br_fhsm;
13753 + mutex_lock(&bf->bf_lock);
13755 + MtxMustLock(&bf->bf_lock);
13757 + /* sb->s_root for NFS is unreliable */
13758 + err = au_br_stfs(br, &bf->bf_stfs);
13759 + if (unlikely(err)) {
13760 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13764 + bf->bf_jiffy = jiffies;
13765 + bf->bf_readable = 1;
13767 + au_fhsm_notify(sb, /*val*/1);
13769 + *rstfs = bf->bf_stfs;
13773 + mutex_unlock(&bf->bf_lock);
13774 + au_fhsm_notify(sb, /*val*/1);
13779 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13782 + struct au_sbinfo *sbinfo;
13783 + struct au_fhsm *fhsm;
13784 + struct au_branch *br;
13785 + struct au_br_fhsm *bf;
13787 + AuDbg("b%d, force %d\n", bindex, force);
13788 + SiMustAnyLock(sb);
13790 + sbinfo = au_sbi(sb);
13791 + fhsm = &sbinfo->si_fhsm;
13792 + if (!au_ftest_si(sbinfo, FHSM)
13793 + || fhsm->fhsm_bottom == bindex)
13796 + br = au_sbr(sb, bindex);
13797 + bf = br->br_fhsm;
13799 + mutex_lock(&bf->bf_lock);
13801 + || au_fhsm_pid(fhsm)
13802 + || au_fhsm_test_jiffy(sbinfo, br))
13803 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13805 + mutex_unlock(&bf->bf_lock);
13808 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13810 + aufs_bindex_t bindex, bbot;
13811 + struct au_branch *br;
13813 + /* exclude the bottom */
13814 + bbot = au_fhsm_bottom(sb);
13815 + for (bindex = 0; bindex < bbot; bindex++) {
13816 + br = au_sbr(sb, bindex);
13817 + if (au_br_fhsm(br->br_perm))
13818 + au_fhsm_wrote(sb, bindex, force);
13822 +/* ---------------------------------------------------------------------- */
13824 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13827 + struct au_sbinfo *sbinfo;
13828 + struct au_fhsm *fhsm;
13831 + sbinfo = file->private_data;
13832 + fhsm = &sbinfo->si_fhsm;
13833 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13834 + if (atomic_read(&fhsm->fhsm_readable))
13835 + mask = EPOLLIN /* | EPOLLRDNORM */;
13838 + AuDbg("mask 0x%x\n", mask);
13842 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13843 + struct aufs_stfs *stfs, __s16 brid)
13847 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13849 + err = __put_user(brid, &stbr->brid);
13850 + if (unlikely(err))
13856 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13857 + struct aufs_stbr __user *stbr, size_t count)
13861 + aufs_bindex_t bindex, bbot;
13862 + struct au_branch *br;
13863 + struct au_br_fhsm *bf;
13865 + /* except the bottom branch */
13868 + bbot = au_fhsm_bottom(sb);
13869 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13870 + br = au_sbr(sb, bindex);
13871 + if (!au_br_fhsm(br->br_perm))
13874 + bf = br->br_fhsm;
13875 + mutex_lock(&bf->bf_lock);
13876 + if (bf->bf_readable) {
13878 + if (count >= sizeof(*stbr))
13879 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13882 + bf->bf_readable = 0;
13883 + count -= sizeof(*stbr);
13887 + mutex_unlock(&bf->bf_lock);
13890 + err = sizeof(*stbr) * nstbr;
13895 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13900 + aufs_bindex_t nfhsm, bindex, bbot;
13901 + struct au_sbinfo *sbinfo;
13902 + struct au_fhsm *fhsm;
13903 + struct au_branch *br;
13904 + struct super_block *sb;
13907 + sbinfo = file->private_data;
13908 + fhsm = &sbinfo->si_fhsm;
13910 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13911 + if (!atomic_read(&fhsm->fhsm_readable)) {
13912 + if (vfsub_file_flags(file) & O_NONBLOCK)
13915 + err = wait_event_interruptible_locked_irq
13917 + atomic_read(&fhsm->fhsm_readable));
13919 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13920 + if (unlikely(err))
13923 + /* sb may already be dead */
13924 + au_rw_read_lock(&sbinfo->si_rwsem);
13925 + readable = atomic_read(&fhsm->fhsm_readable);
13926 + if (readable > 0) {
13927 + sb = sbinfo->si_sb;
13929 + /* exclude the bottom branch */
13931 + bbot = au_fhsm_bottom(sb);
13932 + for (bindex = 0; bindex < bbot; bindex++) {
13933 + br = au_sbr(sb, bindex);
13934 + if (au_br_fhsm(br->br_perm))
13938 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13939 + atomic_set(&fhsm->fhsm_readable, 0);
13940 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13944 + au_rw_read_unlock(&sbinfo->si_rwsem);
13952 +static int au_fhsm_release(struct inode *inode, struct file *file)
13954 + struct au_sbinfo *sbinfo;
13955 + struct au_fhsm *fhsm;
13957 + /* sb may already be dead */
13958 + sbinfo = file->private_data;
13959 + fhsm = &sbinfo->si_fhsm;
13960 + spin_lock(&fhsm->fhsm_spin);
13961 + fhsm->fhsm_pid = 0;
13962 + spin_unlock(&fhsm->fhsm_spin);
13963 + kobject_put(&sbinfo->si_kobj);
13968 +static const struct file_operations au_fhsm_fops = {
13969 + .owner = THIS_MODULE,
13970 + .llseek = noop_llseek,
13971 + .read = au_fhsm_read,
13972 + .poll = au_fhsm_poll,
13973 + .release = au_fhsm_release
13976 +int au_fhsm_fd(struct super_block *sb, int oflags)
13979 + struct au_sbinfo *sbinfo;
13980 + struct au_fhsm *fhsm;
13983 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13987 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13991 + sbinfo = au_sbi(sb);
13992 + fhsm = &sbinfo->si_fhsm;
13993 + spin_lock(&fhsm->fhsm_spin);
13994 + if (!fhsm->fhsm_pid)
13995 + fhsm->fhsm_pid = current->pid;
13998 + spin_unlock(&fhsm->fhsm_spin);
13999 + if (unlikely(err))
14002 + oflags |= O_RDONLY;
14003 + /* oflags |= FMODE_NONOTIFY; */
14004 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14006 + if (unlikely(fd < 0))
14009 + /* succeed regardless 'fhsm' status */
14010 + kobject_get(&sbinfo->si_kobj);
14011 + si_noflush_read_lock(sb);
14012 + if (au_ftest_si(sbinfo, FHSM))
14013 + au_fhsm_wrote_all(sb, /*force*/0);
14014 + si_read_unlock(sb);
14015 + goto out; /* success */
14018 + spin_lock(&fhsm->fhsm_spin);
14019 + fhsm->fhsm_pid = 0;
14020 + spin_unlock(&fhsm->fhsm_spin);
14026 +/* ---------------------------------------------------------------------- */
14028 +int au_fhsm_br_alloc(struct au_branch *br)
14033 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14035 + au_br_fhsm_init(br->br_fhsm);
14042 +/* ---------------------------------------------------------------------- */
14044 +void au_fhsm_fin(struct super_block *sb)
14046 + au_fhsm_notify(sb, /*val*/-1);
14049 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14051 + struct au_fhsm *fhsm;
14053 + fhsm = &sbinfo->si_fhsm;
14054 + spin_lock_init(&fhsm->fhsm_spin);
14055 + init_waitqueue_head(&fhsm->fhsm_wqh);
14056 + atomic_set(&fhsm->fhsm_readable, 0);
14057 + fhsm->fhsm_expire
14058 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14059 + fhsm->fhsm_bottom = -1;
14062 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14064 + sbinfo->si_fhsm.fhsm_expire
14065 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14068 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14072 + if (!au_ftest_si(sbinfo, FHSM))
14075 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14076 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14077 + seq_printf(seq, ",fhsm_sec=%u", u);
14079 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14080 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14081 +++ linux/fs/aufs/file.c 2021-05-02 20:15:14.673337458 +0200
14083 +// SPDX-License-Identifier: GPL-2.0
14085 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14087 + * This program, aufs is free software; you can redistribute it and/or modify
14088 + * it under the terms of the GNU General Public License as published by
14089 + * the Free Software Foundation; either version 2 of the License, or
14090 + * (at your option) any later version.
14092 + * This program is distributed in the hope that it will be useful,
14093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14095 + * GNU General Public License for more details.
14097 + * You should have received a copy of the GNU General Public License
14098 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14102 + * handling file/dir, and address_space operation
14105 +#ifdef CONFIG_AUFS_DEBUG
14106 +#include <linux/migrate.h>
14108 +#include <linux/pagemap.h>
14111 +/* drop flags for writing */
14112 +unsigned int au_file_roflags(unsigned int flags)
14114 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14115 + flags |= O_RDONLY | O_NOATIME;
14119 +/* common functions to regular file and dir */
14120 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14121 + struct file *file, int force_wr)
14123 + struct file *h_file;
14124 + struct dentry *h_dentry;
14125 + struct inode *h_inode;
14126 + struct super_block *sb;
14127 + struct au_branch *br;
14128 + struct path h_path;
14131 + /* a race condition can happen between open and unlink/rmdir */
14132 + h_file = ERR_PTR(-ENOENT);
14133 + h_dentry = au_h_dptr(dentry, bindex);
14134 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14136 + h_inode = d_inode(h_dentry);
14137 + spin_lock(&h_dentry->d_lock);
14138 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14139 + /* || !d_inode(dentry)->i_nlink */
14141 + spin_unlock(&h_dentry->d_lock);
14142 + if (unlikely(err))
14145 + sb = dentry->d_sb;
14146 + br = au_sbr(sb, bindex);
14147 + err = au_br_test_oflag(flags, br);
14148 + h_file = ERR_PTR(err);
14149 + if (unlikely(err))
14152 + /* drop flags for writing */
14153 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14154 + if (force_wr && !(flags & O_WRONLY))
14156 + flags = au_file_roflags(flags);
14158 + h_file = ERR_PTR(-EROFS);
14159 + flags = au_file_roflags(flags);
14160 + if (unlikely(vfsub_native_ro(h_inode)
14161 + || IS_APPEND(h_inode)))
14163 + flags &= ~O_ACCMODE;
14164 + flags |= O_WRONLY;
14167 + flags &= ~O_CREAT;
14168 + au_lcnt_inc(&br->br_nfiles);
14169 + h_path.dentry = h_dentry;
14170 + h_path.mnt = au_br_mnt(br);
14171 + h_file = vfsub_dentry_open(&h_path, flags);
14172 + if (IS_ERR(h_file))
14175 + if (flags & __FMODE_EXEC) {
14176 + err = deny_write_access(h_file);
14177 + if (unlikely(err)) {
14179 + h_file = ERR_PTR(err);
14183 + fsnotify_open(h_file);
14184 + goto out; /* success */
14187 + au_lcnt_dec(&br->br_nfiles);
14192 +static int au_cmoo(struct dentry *dentry)
14194 + int err, cmoo, matched;
14195 + unsigned int udba;
14196 + struct path h_path;
14197 + struct au_pin pin;
14198 + struct au_cp_generic cpg = {
14199 + .dentry = dentry,
14204 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14206 + struct inode *delegated;
14207 + struct super_block *sb;
14208 + struct au_sbinfo *sbinfo;
14209 + struct au_fhsm *fhsm;
14211 + struct au_branch *br;
14212 + struct dentry *parent;
14213 + struct au_hinode *hdir;
14215 + DiMustWriteLock(dentry);
14216 + IiMustWriteLock(d_inode(dentry));
14219 + if (IS_ROOT(dentry))
14221 + cpg.bsrc = au_dbtop(dentry);
14225 + sb = dentry->d_sb;
14226 + sbinfo = au_sbi(sb);
14227 + fhsm = &sbinfo->si_fhsm;
14228 + pid = au_fhsm_pid(fhsm);
14231 + && (current->pid == pid
14232 + || rcu_dereference(current->real_parent)->pid == pid));
14233 + rcu_read_unlock();
14237 + br = au_sbr(sb, cpg.bsrc);
14238 + cmoo = au_br_cmoo(br->br_perm);
14241 + if (!d_is_reg(dentry))
14242 + cmoo &= AuBrAttr_COO_ALL;
14246 + parent = dget_parent(dentry);
14247 + di_write_lock_parent(parent);
14248 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14250 + if (unlikely(err < 0)) {
14251 + err = 0; /* there is no upper writable branch */
14254 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14256 + /* do not respect the coo attrib for the target branch */
14257 + err = au_cpup_dirs(dentry, cpg.bdst);
14258 + if (unlikely(err))
14261 + di_downgrade_lock(parent, AuLock_IR);
14262 + udba = au_opt_udba(sb);
14263 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14264 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14265 + if (unlikely(err))
14268 + err = au_sio_cpup_simple(&cpg);
14270 + if (unlikely(err))
14272 + if (!(cmoo & AuBrWAttr_MOO))
14273 + goto out_parent; /* success */
14275 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14276 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14277 + if (unlikely(err))
14280 + h_path.mnt = au_br_mnt(br);
14281 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14282 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14283 + delegated = NULL;
14284 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14286 + /* todo: keep h_dentry or not? */
14287 + if (unlikely(err == -EWOULDBLOCK)) {
14288 + pr_warn("cannot retry for NFSv4 delegation"
14289 + " for an internal unlink\n");
14292 + if (unlikely(err)) {
14293 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14297 + goto out_parent; /* success */
14300 + di_downgrade_lock(parent, AuLock_IR);
14302 + di_read_unlock(parent, AuLock_IR);
14309 +int au_do_open(struct file *file, struct au_do_open_args *args)
14311 + int err, aopen = args->aopen;
14312 + struct dentry *dentry;
14313 + struct au_finfo *finfo;
14316 + err = au_finfo_init(file, args->fidir);
14319 + err = au_finfo_init(file, args->fidir);
14322 + if (unlikely(err))
14325 + dentry = file->f_path.dentry;
14326 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14327 + di_write_lock_child(dentry);
14328 + err = au_cmoo(dentry);
14329 + di_downgrade_lock(dentry, AuLock_IR);
14332 + err = args->open(file, vfsub_file_flags(file), NULL);
14335 + err = args->open(file, vfsub_file_flags(file),
14340 + di_read_unlock(dentry, AuLock_IR);
14342 + finfo = au_fi(file);
14344 + finfo->fi_file = file;
14345 + au_hbl_add(&finfo->fi_hlist,
14346 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14349 + fi_write_unlock(file);
14352 + fi_write_unlock(file);
14355 + if (unlikely(err)) {
14356 + finfo->fi_hdir = NULL;
14357 + au_finfo_fin(file);
14365 +int au_reopen_nondir(struct file *file)
14368 + aufs_bindex_t btop;
14369 + struct dentry *dentry;
14370 + struct au_branch *br;
14371 + struct file *h_file, *h_file_tmp;
14373 + dentry = file->f_path.dentry;
14374 + btop = au_dbtop(dentry);
14375 + br = au_sbr(dentry->d_sb, btop);
14376 + h_file_tmp = NULL;
14377 + if (au_fbtop(file) == btop) {
14378 + h_file = au_hf_top(file);
14379 + if (file->f_mode == h_file->f_mode)
14380 + return 0; /* success */
14381 + h_file_tmp = h_file;
14382 + get_file(h_file_tmp);
14383 + au_lcnt_inc(&br->br_nfiles);
14384 + au_set_h_fptr(file, btop, NULL);
14386 + AuDebugOn(au_fi(file)->fi_hdir);
14389 + * file exists on both of rw and ro
14390 + * open --> dbtop and fbtop are both 0
14391 + * prepend a branch as rw, "rw" become ro
14393 + * delete the top branch, "rw" becomes rw again
14394 + * --> dbtop is 1, fbtop is still 0
14395 + * write --> fbtop is 0 but dbtop is 1
14397 + /* AuDebugOn(au_fbtop(file) < btop); */
14399 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14400 + file, /*force_wr*/0);
14401 + err = PTR_ERR(h_file);
14402 + if (IS_ERR(h_file)) {
14403 + if (h_file_tmp) {
14405 + au_set_h_fptr(file, btop, h_file_tmp);
14406 + h_file_tmp = NULL;
14408 + goto out; /* todo: close all? */
14412 + au_set_fbtop(file, btop);
14413 + au_set_h_fptr(file, btop, h_file);
14414 + au_update_figen(file);
14415 + /* todo: necessary? */
14416 + /* file->f_ra = h_file->f_ra; */
14419 + if (h_file_tmp) {
14420 + fput(h_file_tmp);
14421 + au_lcnt_dec(&br->br_nfiles);
14426 +/* ---------------------------------------------------------------------- */
14428 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14429 + struct dentry *hi_wh)
14432 + aufs_bindex_t btop;
14433 + struct au_dinfo *dinfo;
14434 + struct dentry *h_dentry;
14435 + struct au_hdentry *hdp;
14437 + dinfo = au_di(file->f_path.dentry);
14438 + AuRwMustWriteLock(&dinfo->di_rwsem);
14440 + btop = dinfo->di_btop;
14441 + dinfo->di_btop = btgt;
14442 + hdp = au_hdentry(dinfo, btgt);
14443 + h_dentry = hdp->hd_dentry;
14444 + hdp->hd_dentry = hi_wh;
14445 + err = au_reopen_nondir(file);
14446 + hdp->hd_dentry = h_dentry;
14447 + dinfo->di_btop = btop;
14452 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14453 + aufs_bindex_t bcpup, struct au_pin *pin)
14456 + struct inode *inode, *h_inode;
14457 + struct dentry *h_dentry, *hi_wh;
14458 + struct au_cp_generic cpg = {
14459 + .dentry = file->f_path.dentry,
14466 + au_update_dbtop(cpg.dentry);
14467 + inode = d_inode(cpg.dentry);
14469 + if (au_dbtop(cpg.dentry) <= bcpup
14470 + && au_dbbot(cpg.dentry) >= bcpup) {
14471 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14472 + if (h_dentry && d_is_positive(h_dentry))
14473 + h_inode = d_inode(h_dentry);
14475 + hi_wh = au_hi_wh(inode, bcpup);
14476 + if (!hi_wh && !h_inode)
14477 + err = au_sio_cpup_wh(&cpg, file);
14479 + /* already copied-up after unlink */
14480 + err = au_reopen_wh(file, bcpup, hi_wh);
14483 + && (inode->i_nlink > 1
14484 + || (inode->i_state & I_LINKABLE))
14485 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14486 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14492 + * prepare the @file for writing.
14494 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14497 + aufs_bindex_t dbtop;
14498 + struct dentry *parent;
14499 + struct inode *inode;
14500 + struct super_block *sb;
14501 + struct file *h_file;
14502 + struct au_cp_generic cpg = {
14503 + .dentry = file->f_path.dentry,
14508 + .flags = AuCpup_DTIME
14511 + sb = cpg.dentry->d_sb;
14512 + inode = d_inode(cpg.dentry);
14513 + cpg.bsrc = au_fbtop(file);
14514 + err = au_test_ro(sb, cpg.bsrc, inode);
14515 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14516 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14521 + /* need to cpup or reopen */
14522 + parent = dget_parent(cpg.dentry);
14523 + di_write_lock_parent(parent);
14524 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14526 + if (unlikely(err < 0))
14530 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14531 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14532 + if (unlikely(err))
14536 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14537 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14538 + if (unlikely(err))
14541 + dbtop = au_dbtop(cpg.dentry);
14542 + if (dbtop <= cpg.bdst)
14543 + cpg.bsrc = cpg.bdst;
14545 + if (dbtop <= cpg.bdst /* just reopen */
14546 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14548 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14549 + if (IS_ERR(h_file))
14550 + err = PTR_ERR(h_file);
14552 + di_downgrade_lock(parent, AuLock_IR);
14553 + if (dbtop > cpg.bdst)
14554 + err = au_sio_cpup_simple(&cpg);
14556 + err = au_reopen_nondir(file);
14557 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14559 + } else { /* copyup as wh and reopen */
14561 + * since writable hfsplus branch is not supported,
14562 + * h_open_pre/post() are unnecessary.
14564 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14565 + di_downgrade_lock(parent, AuLock_IR);
14569 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14570 + goto out_dput; /* success */
14576 + di_downgrade_lock(parent, AuLock_IR);
14578 + di_read_unlock(parent, AuLock_IR);
14585 +/* ---------------------------------------------------------------------- */
14587 +int au_do_flush(struct file *file, fl_owner_t id,
14588 + int (*flush)(struct file *file, fl_owner_t id))
14591 + struct super_block *sb;
14592 + struct inode *inode;
14594 + inode = file_inode(file);
14595 + sb = inode->i_sb;
14596 + si_noflush_read_lock(sb);
14597 + fi_read_lock(file);
14598 + ii_read_lock_child(inode);
14600 + err = flush(file, id);
14601 + au_cpup_attr_timesizes(inode);
14603 + ii_read_unlock(inode);
14604 + fi_read_unlock(file);
14605 + si_read_unlock(sb);
14609 +/* ---------------------------------------------------------------------- */
14611 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14614 + struct au_pin pin;
14615 + struct au_finfo *finfo;
14616 + struct dentry *parent, *hi_wh;
14617 + struct inode *inode;
14618 + struct super_block *sb;
14619 + struct au_cp_generic cpg = {
14620 + .dentry = file->f_path.dentry,
14625 + .flags = AuCpup_DTIME
14628 + FiMustWriteLock(file);
14631 + finfo = au_fi(file);
14632 + sb = cpg.dentry->d_sb;
14633 + inode = d_inode(cpg.dentry);
14634 + cpg.bdst = au_ibtop(inode);
14635 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14638 + parent = dget_parent(cpg.dentry);
14639 + if (au_test_ro(sb, cpg.bdst, inode)) {
14640 + di_read_lock_parent(parent, !AuLock_IR);
14641 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14643 + di_read_unlock(parent, !AuLock_IR);
14644 + if (unlikely(err < 0))
14649 + di_read_lock_parent(parent, AuLock_IR);
14650 + hi_wh = au_hi_wh(inode, cpg.bdst);
14651 + if (!S_ISDIR(inode->i_mode)
14652 + && au_opt_test(au_mntflags(sb), PLINK)
14653 + && au_plink_test(inode)
14654 + && !d_unhashed(cpg.dentry)
14655 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14656 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14657 + if (unlikely(err))
14660 + /* always superio. */
14661 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14662 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14664 + err = au_sio_cpup_simple(&cpg);
14667 + } else if (hi_wh) {
14668 + /* already copied-up after unlink */
14669 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14670 + *need_reopen = 0;
14674 + di_read_unlock(parent, AuLock_IR);
14681 +static void au_do_refresh_dir(struct file *file)
14683 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14684 + struct au_hfile *p, tmp, *q;
14685 + struct au_finfo *finfo;
14686 + struct super_block *sb;
14687 + struct au_fidir *fidir;
14689 + FiMustWriteLock(file);
14691 + sb = file->f_path.dentry->d_sb;
14692 + finfo = au_fi(file);
14693 + fidir = finfo->fi_hdir;
14694 + AuDebugOn(!fidir);
14695 + p = fidir->fd_hfile + finfo->fi_btop;
14696 + brid = p->hf_br->br_id;
14697 + bbot = fidir->fd_bbot;
14698 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14702 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14703 + if (new_bindex == bindex)
14705 + if (new_bindex < 0) {
14706 + au_set_h_fptr(file, bindex, NULL);
14710 + /* swap two lower inode, and loop again */
14711 + q = fidir->fd_hfile + new_bindex;
14715 + if (tmp.hf_file) {
14721 + p = fidir->fd_hfile;
14722 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14723 + bbot = au_sbbot(sb);
14724 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14725 + finfo->fi_btop++, p++)
14726 + if (p->hf_file) {
14727 + if (file_inode(p->hf_file))
14729 + au_hfput(p, /*execed*/0);
14732 + bbot = au_br_index(sb, brid);
14733 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14734 + finfo->fi_btop++, p++)
14736 + au_hfput(p, /*execed*/0);
14737 + bbot = au_sbbot(sb);
14740 + p = fidir->fd_hfile + bbot;
14741 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14742 + fidir->fd_bbot--, p--)
14743 + if (p->hf_file) {
14744 + if (file_inode(p->hf_file))
14746 + au_hfput(p, /*execed*/0);
14748 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14752 + * after branch manipulating, refresh the file.
14754 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14756 + int err, need_reopen, nbr;
14757 + aufs_bindex_t bbot, bindex;
14758 + struct dentry *dentry;
14759 + struct super_block *sb;
14760 + struct au_finfo *finfo;
14761 + struct au_hfile *hfile;
14763 + dentry = file->f_path.dentry;
14764 + sb = dentry->d_sb;
14765 + nbr = au_sbbot(sb) + 1;
14766 + finfo = au_fi(file);
14767 + if (!finfo->fi_hdir) {
14768 + hfile = &finfo->fi_htop;
14769 + AuDebugOn(!hfile->hf_file);
14770 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14771 + AuDebugOn(bindex < 0);
14772 + if (bindex != finfo->fi_btop)
14773 + au_set_fbtop(file, bindex);
14775 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14776 + if (unlikely(err))
14778 + au_do_refresh_dir(file);
14783 + if (!au_test_mmapped(file))
14784 + err = au_file_refresh_by_inode(file, &need_reopen);
14785 + if (finfo->fi_hdir)
14786 + /* harmless if err */
14787 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14788 + if (!err && need_reopen && !d_unlinked(dentry))
14789 + err = reopen(file);
14791 + au_update_figen(file);
14792 + goto out; /* success */
14795 + /* error, close all lower files */
14796 + if (finfo->fi_hdir) {
14797 + bbot = au_fbbot_dir(file);
14798 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14799 + au_set_h_fptr(file, bindex, NULL);
14806 +/* common function to regular file and dir */
14807 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14808 + int wlock, unsigned int fi_lsc)
14811 + unsigned int sigen, figen;
14812 + aufs_bindex_t btop;
14813 + unsigned char pseudo_link;
14814 + struct dentry *dentry;
14815 + struct inode *inode;
14818 + dentry = file->f_path.dentry;
14819 + inode = d_inode(dentry);
14820 + sigen = au_sigen(dentry->d_sb);
14821 + fi_write_lock_nested(file, fi_lsc);
14822 + figen = au_figen(file);
14824 + di_write_lock_child(dentry);
14826 + di_write_lock_child2(dentry);
14827 + btop = au_dbtop(dentry);
14828 + pseudo_link = (btop != au_ibtop(inode));
14829 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14831 + di_downgrade_lock(dentry, AuLock_IR);
14832 + fi_downgrade_lock(file);
14834 + goto out; /* success */
14837 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14838 + if (au_digen_test(dentry, sigen)) {
14839 + err = au_reval_dpath(dentry, sigen);
14840 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14844 + err = refresh_file(file, reopen);
14847 + di_downgrade_lock(dentry, AuLock_IR);
14848 + fi_downgrade_lock(file);
14851 + di_write_unlock(dentry);
14852 + fi_write_unlock(file);
14859 +/* ---------------------------------------------------------------------- */
14861 +/* cf. aufs_nopage() */
14862 +/* for madvise(2) */
14863 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14865 + unlock_page(page);
14869 +/* it will never be called, but necessary to support O_DIRECT */
14870 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14871 +{ BUG(); return 0; }
14873 +/* they will never be called. */
14874 +#ifdef CONFIG_AUFS_DEBUG
14875 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14876 + loff_t pos, unsigned len, unsigned flags,
14877 + struct page **pagep, void **fsdata)
14878 +{ AuUnsupport(); return 0; }
14879 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14880 + loff_t pos, unsigned len, unsigned copied,
14881 + struct page *page, void *fsdata)
14882 +{ AuUnsupport(); return 0; }
14883 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14884 +{ AuUnsupport(); return 0; }
14886 +static int aufs_set_page_dirty(struct page *page)
14887 +{ AuUnsupport(); return 0; }
14888 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14889 + unsigned int length)
14890 +{ AuUnsupport(); }
14891 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14892 +{ AuUnsupport(); return 0; }
14893 +#if 0 /* called by memory compaction regardless file */
14894 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14895 + struct page *page, enum migrate_mode mode)
14896 +{ AuUnsupport(); return 0; }
14898 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14899 +{ AuUnsupport(); return true; }
14900 +static void aufs_putback_page(struct page *page)
14901 +{ AuUnsupport(); }
14902 +static int aufs_launder_page(struct page *page)
14903 +{ AuUnsupport(); return 0; }
14904 +static int aufs_is_partially_uptodate(struct page *page,
14905 + unsigned long from,
14906 + unsigned long count)
14907 +{ AuUnsupport(); return 0; }
14908 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14910 +{ AuUnsupport(); }
14911 +static int aufs_error_remove_page(struct address_space *mapping,
14912 + struct page *page)
14913 +{ AuUnsupport(); return 0; }
14914 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14916 +{ AuUnsupport(); return 0; }
14917 +static void aufs_swap_deactivate(struct file *file)
14918 +{ AuUnsupport(); }
14919 +#endif /* CONFIG_AUFS_DEBUG */
14921 +const struct address_space_operations aufs_aop = {
14922 + .readpage = aufs_readpage,
14923 + .direct_IO = aufs_direct_IO,
14924 +#ifdef CONFIG_AUFS_DEBUG
14925 + .writepage = aufs_writepage,
14926 + /* no writepages, because of writepage */
14927 + .set_page_dirty = aufs_set_page_dirty,
14928 + /* no readpages, because of readpage */
14929 + .write_begin = aufs_write_begin,
14930 + .write_end = aufs_write_end,
14931 + /* no bmap, no block device */
14932 + .invalidatepage = aufs_invalidatepage,
14933 + .releasepage = aufs_releasepage,
14934 + /* is fallback_migrate_page ok? */
14935 + /* .migratepage = aufs_migratepage, */
14936 + .isolate_page = aufs_isolate_page,
14937 + .putback_page = aufs_putback_page,
14938 + .launder_page = aufs_launder_page,
14939 + .is_partially_uptodate = aufs_is_partially_uptodate,
14940 + .is_dirty_writeback = aufs_is_dirty_writeback,
14941 + .error_remove_page = aufs_error_remove_page,
14942 + .swap_activate = aufs_swap_activate,
14943 + .swap_deactivate = aufs_swap_deactivate
14944 +#endif /* CONFIG_AUFS_DEBUG */
14946 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14947 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14948 +++ linux/fs/aufs/file.h 2021-05-02 20:15:14.673337458 +0200
14950 +/* SPDX-License-Identifier: GPL-2.0 */
14952 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14954 + * This program, aufs is free software; you can redistribute it and/or modify
14955 + * it under the terms of the GNU General Public License as published by
14956 + * the Free Software Foundation; either version 2 of the License, or
14957 + * (at your option) any later version.
14959 + * This program is distributed in the hope that it will be useful,
14960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14962 + * GNU General Public License for more details.
14964 + * You should have received a copy of the GNU General Public License
14965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14969 + * file operations
14972 +#ifndef __AUFS_FILE_H__
14973 +#define __AUFS_FILE_H__
14977 +#include <linux/file.h>
14978 +#include <linux/fs.h>
14979 +#include <linux/mm_types.h>
14980 +#include <linux/poll.h>
14981 +#include "rwsem.h"
14985 + struct file *hf_file;
14986 + struct au_branch *hf_br;
14991 + aufs_bindex_t fd_bbot;
14992 + aufs_bindex_t fd_nent;
14993 + struct au_vdir *fd_vdir_cache;
14994 + struct au_hfile fd_hfile[];
14997 +static inline int au_fidir_sz(int nent)
14999 + AuDebugOn(nent < 0);
15000 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
15004 + atomic_t fi_generation;
15006 + struct au_rwsem fi_rwsem;
15007 + aufs_bindex_t fi_btop;
15009 + /* do not union them */
15010 + struct { /* for non-dir */
15011 + struct au_hfile fi_htop;
15012 + atomic_t fi_mmapped;
15014 + struct au_fidir *fi_hdir; /* for dir only */
15016 + struct hlist_bl_node fi_hlist;
15017 + struct file *fi_file; /* very ugly */
15018 + struct rcu_head rcu;
15019 +} ____cacheline_aligned_in_smp;
15021 +/* ---------------------------------------------------------------------- */
15024 +extern const struct address_space_operations aufs_aop;
15025 +unsigned int au_file_roflags(unsigned int flags);
15026 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15027 + struct file *file, int force_wr);
15028 +struct au_do_open_args {
15030 + int (*open)(struct file *file, int flags,
15031 + struct file *h_file);
15032 + struct au_fidir *fidir;
15033 + struct file *h_file;
15035 +int au_do_open(struct file *file, struct au_do_open_args *args);
15036 +int au_reopen_nondir(struct file *file);
15038 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15039 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15040 + int wlock, unsigned int fi_lsc);
15041 +int au_do_flush(struct file *file, fl_owner_t id,
15042 + int (*flush)(struct file *file, fl_owner_t id));
15045 +#ifdef CONFIG_AUFS_POLL
15046 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15049 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15051 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15053 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15054 + struct file *h_file);
15056 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15057 + aufs_bindex_t bindex, int force_wr)
15058 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15059 + struct file *h_file);
15063 +extern const struct file_operations aufs_file_fop;
15064 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15065 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15066 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15069 +void au_hfput(struct au_hfile *hf, int execed);
15070 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15071 + struct file *h_file);
15073 +void au_update_figen(struct file *file);
15074 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15075 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15077 +void au_fi_init_once(void *_fi);
15078 +void au_finfo_fin(struct file *file);
15079 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15082 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15083 +#ifdef CONFIG_COMPAT
15084 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15085 + unsigned long arg);
15086 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15087 + unsigned long arg);
15090 +/* ---------------------------------------------------------------------- */
15092 +static inline struct au_finfo *au_fi(struct file *file)
15094 + return file->private_data;
15097 +/* ---------------------------------------------------------------------- */
15099 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15100 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15101 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15102 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15104 +#define fi_read_trylock_nested(f) \
15105 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15106 +#define fi_write_trylock_nested(f) \
15107 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15110 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15111 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15112 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15114 +/* lock subclass for finfo */
15120 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15122 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15125 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15127 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15131 + * fi_read_lock_1, fi_write_lock_1,
15132 + * fi_read_lock_2, fi_write_lock_2
15134 +#define AuReadLockFunc(name) \
15135 +static inline void fi_read_lock_##name(struct file *f) \
15136 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15138 +#define AuWriteLockFunc(name) \
15139 +static inline void fi_write_lock_##name(struct file *f) \
15140 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15142 +#define AuRWLockFuncs(name) \
15143 + AuReadLockFunc(name) \
15144 + AuWriteLockFunc(name)
15149 +#undef AuReadLockFunc
15150 +#undef AuWriteLockFunc
15151 +#undef AuRWLockFuncs
15153 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15154 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15155 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15157 +/* ---------------------------------------------------------------------- */
15159 +/* todo: hard/soft set? */
15160 +static inline aufs_bindex_t au_fbtop(struct file *file)
15162 + FiMustAnyLock(file);
15163 + return au_fi(file)->fi_btop;
15166 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15168 + FiMustAnyLock(file);
15169 + AuDebugOn(!au_fi(file)->fi_hdir);
15170 + return au_fi(file)->fi_hdir->fd_bbot;
15173 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15175 + FiMustAnyLock(file);
15176 + AuDebugOn(!au_fi(file)->fi_hdir);
15177 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15180 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15182 + FiMustWriteLock(file);
15183 + au_fi(file)->fi_btop = bindex;
15186 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15188 + FiMustWriteLock(file);
15189 + AuDebugOn(!au_fi(file)->fi_hdir);
15190 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15193 +static inline void au_set_fvdir_cache(struct file *file,
15194 + struct au_vdir *vdir_cache)
15196 + FiMustWriteLock(file);
15197 + AuDebugOn(!au_fi(file)->fi_hdir);
15198 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15201 +static inline struct file *au_hf_top(struct file *file)
15203 + FiMustAnyLock(file);
15204 + AuDebugOn(au_fi(file)->fi_hdir);
15205 + return au_fi(file)->fi_htop.hf_file;
15208 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15210 + FiMustAnyLock(file);
15211 + AuDebugOn(!au_fi(file)->fi_hdir);
15212 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15215 +/* todo: memory barrier? */
15216 +static inline unsigned int au_figen(struct file *f)
15218 + return atomic_read(&au_fi(f)->fi_generation);
15221 +static inline void au_set_mmapped(struct file *f)
15223 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15225 + pr_warn("fi_mmapped wrapped around\n");
15226 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15230 +static inline void au_unset_mmapped(struct file *f)
15232 + atomic_dec(&au_fi(f)->fi_mmapped);
15235 +static inline int au_test_mmapped(struct file *f)
15237 + return atomic_read(&au_fi(f)->fi_mmapped);
15240 +/* customize vma->vm_file */
15242 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15243 + struct file *file)
15247 + f = vma->vm_file;
15249 + vma->vm_file = file;
15254 +#define AuDbgVmRegion(file, vma) do {} while (0)
15256 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15257 + struct file *file)
15259 + au_do_vm_file_reset(vma, file);
15262 +#define AuDbgVmRegion(file, vma) \
15263 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15265 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15266 + struct file *file)
15270 + au_do_vm_file_reset(vma, file);
15271 + f = vma->vm_region->vm_file;
15273 + vma->vm_region->vm_file = file;
15276 +#endif /* CONFIG_MMU */
15278 +/* handle vma->vm_prfile */
15279 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15280 + struct file *file)
15283 + vma->vm_prfile = file;
15284 +#ifndef CONFIG_MMU
15286 + vma->vm_region->vm_prfile = file;
15290 +#endif /* __KERNEL__ */
15291 +#endif /* __AUFS_FILE_H__ */
15292 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15293 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15294 +++ linux/fs/aufs/finfo.c 2021-05-02 20:15:14.673337458 +0200
15296 +// SPDX-License-Identifier: GPL-2.0
15298 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15300 + * This program, aufs is free software; you can redistribute it and/or modify
15301 + * it under the terms of the GNU General Public License as published by
15302 + * the Free Software Foundation; either version 2 of the License, or
15303 + * (at your option) any later version.
15305 + * This program is distributed in the hope that it will be useful,
15306 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15307 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15308 + * GNU General Public License for more details.
15310 + * You should have received a copy of the GNU General Public License
15311 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15315 + * file private data
15320 +void au_hfput(struct au_hfile *hf, int execed)
15323 + allow_write_access(hf->hf_file);
15324 + fput(hf->hf_file);
15325 + hf->hf_file = NULL;
15326 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15327 + hf->hf_br = NULL;
15330 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15332 + struct au_finfo *finfo = au_fi(file);
15333 + struct au_hfile *hf;
15334 + struct au_fidir *fidir;
15336 + fidir = finfo->fi_hdir;
15338 + AuDebugOn(finfo->fi_btop != bindex);
15339 + hf = &finfo->fi_htop;
15341 + hf = fidir->fd_hfile + bindex;
15343 + if (hf && hf->hf_file)
15344 + au_hfput(hf, vfsub_file_execed(file));
15346 + FiMustWriteLock(file);
15347 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15348 + hf->hf_file = val;
15349 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15353 +void au_update_figen(struct file *file)
15355 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15356 + /* smp_mb(); */ /* atomic_set */
15359 +/* ---------------------------------------------------------------------- */
15361 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15363 + struct au_fidir *fidir;
15366 + nbr = au_sbbot(sb) + 1;
15368 + nbr = 2; /* initial allocate for 2 branches */
15369 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15371 + fidir->fd_bbot = -1;
15372 + fidir->fd_nent = nbr;
15378 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15381 + struct au_fidir *fidir, *p;
15383 + AuRwMustWriteLock(&finfo->fi_rwsem);
15384 + fidir = finfo->fi_hdir;
15385 + AuDebugOn(!fidir);
15388 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15389 + GFP_NOFS, may_shrink);
15391 + p->fd_nent = nbr;
15392 + finfo->fi_hdir = p;
15399 +/* ---------------------------------------------------------------------- */
15401 +void au_finfo_fin(struct file *file)
15403 + struct au_finfo *finfo;
15405 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15407 + finfo = au_fi(file);
15408 + AuDebugOn(finfo->fi_hdir);
15409 + AuRwDestroy(&finfo->fi_rwsem);
15410 + au_cache_free_finfo(finfo);
15413 +void au_fi_init_once(void *_finfo)
15415 + struct au_finfo *finfo = _finfo;
15417 + au_rw_init(&finfo->fi_rwsem);
15420 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15423 + struct au_finfo *finfo;
15424 + struct dentry *dentry;
15427 + dentry = file->f_path.dentry;
15428 + finfo = au_cache_alloc_finfo();
15429 + if (unlikely(!finfo))
15433 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15434 + au_rw_write_lock(&finfo->fi_rwsem);
15435 + finfo->fi_btop = -1;
15436 + finfo->fi_hdir = fidir;
15437 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15438 + /* smp_mb(); */ /* atomic_set */
15440 + file->private_data = finfo;
15445 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15446 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15447 +++ linux/fs/aufs/f_op.c 2021-05-02 20:15:14.673337458 +0200
15449 +// SPDX-License-Identifier: GPL-2.0
15451 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15453 + * This program, aufs is free software; you can redistribute it and/or modify
15454 + * it under the terms of the GNU General Public License as published by
15455 + * the Free Software Foundation; either version 2 of the License, or
15456 + * (at your option) any later version.
15458 + * This program is distributed in the hope that it will be useful,
15459 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15460 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15461 + * GNU General Public License for more details.
15463 + * You should have received a copy of the GNU General Public License
15464 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15468 + * file and vm operations
15471 +#include <linux/aio.h>
15472 +#include <linux/fs_stack.h>
15473 +#include <linux/mman.h>
15474 +#include <linux/security.h>
15477 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15480 + aufs_bindex_t bindex;
15481 + struct dentry *dentry, *h_dentry;
15482 + struct au_finfo *finfo;
15483 + struct inode *h_inode;
15485 + FiMustWriteLock(file);
15488 + dentry = file->f_path.dentry;
15489 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15490 + finfo = au_fi(file);
15491 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15492 + atomic_set(&finfo->fi_mmapped, 0);
15493 + bindex = au_dbtop(dentry);
15495 + h_dentry = au_h_dptr(dentry, bindex);
15496 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15497 + if (unlikely(err))
15499 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15500 + if (IS_ERR(h_file)) {
15501 + err = PTR_ERR(h_file);
15505 + h_dentry = h_file->f_path.dentry;
15506 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15507 + if (unlikely(err))
15509 + /* br ref is already inc-ed */
15512 + if ((flags & __O_TMPFILE)
15513 + && !(flags & O_EXCL)) {
15514 + h_inode = file_inode(h_file);
15515 + spin_lock(&h_inode->i_lock);
15516 + h_inode->i_state |= I_LINKABLE;
15517 + spin_unlock(&h_inode->i_lock);
15519 + au_set_fbtop(file, bindex);
15520 + au_set_h_fptr(file, bindex, h_file);
15521 + au_update_figen(file);
15522 + /* todo: necessary? */
15523 + /* file->f_ra = h_file->f_ra; */
15529 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15530 + struct file *file)
15533 + struct super_block *sb;
15534 + struct au_do_open_args args = {
15535 + .open = au_do_open_nondir
15538 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15539 + file, vfsub_file_flags(file), file->f_mode);
15541 + sb = file->f_path.dentry->d_sb;
15542 + si_read_lock(sb, AuLock_FLUSH);
15543 + err = au_do_open(file, &args);
15544 + si_read_unlock(sb);
15548 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15550 + struct au_finfo *finfo;
15551 + aufs_bindex_t bindex;
15553 + finfo = au_fi(file);
15554 + au_hbl_del(&finfo->fi_hlist,
15555 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15556 + bindex = finfo->fi_btop;
15558 + au_set_h_fptr(file, bindex, NULL);
15560 + au_finfo_fin(file);
15564 +/* ---------------------------------------------------------------------- */
15566 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15569 + struct file *h_file;
15572 + h_file = au_hf_top(file);
15574 + err = vfsub_flush(h_file, id);
15578 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15580 + return au_do_flush(file, id, au_do_flush_nondir);
15583 +/* ---------------------------------------------------------------------- */
15585 + * read and write functions acquire [fdi]_rwsem once, but release before
15586 + * mmap_sem. This is because to stop a race condition between mmap(2).
15587 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15588 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15589 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15592 +/* Callers should call au_read_post() or fput() in the end */
15593 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15595 + struct file *h_file;
15598 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15600 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15601 + h_file = au_hf_top(file);
15602 + get_file(h_file);
15604 + fi_read_unlock(file);
15606 + h_file = ERR_PTR(err);
15611 +static void au_read_post(struct inode *inode, struct file *h_file)
15613 + /* update without lock, I don't think it a problem */
15614 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15618 +struct au_write_pre {
15620 + unsigned int lsc;
15624 + aufs_bindex_t btop;
15628 + * return with iinfo is write-locked
15629 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15632 +static struct file *au_write_pre(struct file *file, int do_ready,
15633 + struct au_write_pre *wpre)
15635 + struct file *h_file;
15636 + struct dentry *dentry;
15638 + unsigned int lsc;
15639 + struct au_pin pin;
15644 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15645 + h_file = ERR_PTR(err);
15646 + if (unlikely(err))
15649 + dentry = file->f_path.dentry;
15651 + err = au_ready_to_write(file, -1, &pin);
15652 + if (unlikely(err)) {
15653 + h_file = ERR_PTR(err);
15654 + di_write_unlock(dentry);
15659 + di_downgrade_lock(dentry, /*flags*/0);
15661 + wpre->btop = au_fbtop(file);
15662 + h_file = au_hf_top(file);
15663 + get_file(h_file);
15665 + wpre->blks = file_inode(h_file)->i_blocks;
15668 + di_read_unlock(dentry, /*flags*/0);
15671 + fi_write_unlock(file);
15676 +static void au_write_post(struct inode *inode, struct file *h_file,
15677 + struct au_write_pre *wpre, ssize_t written)
15679 + struct inode *h_inode;
15681 + au_cpup_attr_timesizes(inode);
15682 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15683 + h_inode = file_inode(h_file);
15684 + inode->i_mode = h_inode->i_mode;
15685 + ii_write_unlock(inode);
15686 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15688 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15689 + /*force*/h_inode->i_blocks > wpre->blks);
15694 + * todo: very ugly
15695 + * it locks both of i_mutex and si_rwsem for read in safe.
15696 + * if the plink maintenance mode continues forever (that is the problem),
15697 + * may loop forever.
15699 +static void au_mtx_and_read_lock(struct inode *inode)
15702 + struct super_block *sb = inode->i_sb;
15705 + inode_lock(inode);
15706 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15709 + inode_unlock(inode);
15710 + si_read_lock(sb, AuLock_NOPLMW);
15711 + si_read_unlock(sb);
15715 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15716 + struct iov_iter *iov_iter)
15719 + struct file *file;
15720 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15722 + err = security_file_permission(h_file, rw);
15723 + if (unlikely(err))
15726 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15728 + if (rw == MAY_READ)
15729 + iter = h_file->f_op->read_iter;
15730 + else if (rw == MAY_WRITE)
15731 + iter = h_file->f_op->write_iter;
15733 + file = kio->ki_filp;
15734 + kio->ki_filp = h_file;
15737 + err = iter(kio, iov_iter);
15740 + /* currently there is no such fs */
15742 + kio->ki_filp = file;
15748 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15751 + struct file *file, *h_file;
15752 + struct inode *inode;
15753 + struct super_block *sb;
15755 + file = kio->ki_filp;
15756 + inode = file_inode(file);
15757 + sb = inode->i_sb;
15758 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15760 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15761 + err = PTR_ERR(h_file);
15762 + if (IS_ERR(h_file))
15765 + if (au_test_loopback_kthread()) {
15766 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15767 + if (file->f_mapping != h_file->f_mapping) {
15768 + file->f_mapping = h_file->f_mapping;
15769 + smp_mb(); /* unnecessary? */
15772 + fi_read_unlock(file);
15774 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15775 + /* todo: necessary? */
15776 + /* file->f_ra = h_file->f_ra; */
15777 + au_read_post(inode, h_file);
15780 + si_read_unlock(sb);
15784 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15787 + struct au_write_pre wpre;
15788 + struct inode *inode;
15789 + struct file *file, *h_file;
15791 + file = kio->ki_filp;
15792 + inode = file_inode(file);
15793 + au_mtx_and_read_lock(inode);
15796 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15797 + err = PTR_ERR(h_file);
15798 + if (IS_ERR(h_file))
15801 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15802 + au_write_post(inode, h_file, &wpre, err);
15805 + si_read_unlock(inode->i_sb);
15806 + inode_unlock(inode);
15811 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15812 + * don't have their own .splice_{read,write} implimentations, and they use
15813 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15814 + * simple converters to f_op->iter_read() and ->iter_write().
15815 + * But we keep our own implementations because some non-mainlined FSes may have
15816 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15817 + * away an opportunity to co-work with aufs from them.
15819 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15820 + struct pipe_inode_info *pipe, size_t len,
15821 + unsigned int flags)
15824 + struct file *h_file;
15825 + struct inode *inode;
15826 + struct super_block *sb;
15828 + inode = file_inode(file);
15829 + sb = inode->i_sb;
15830 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15832 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15833 + err = PTR_ERR(h_file);
15834 + if (IS_ERR(h_file))
15837 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15838 + /* todo: necessary? */
15839 + /* file->f_ra = h_file->f_ra; */
15840 + au_read_post(inode, h_file);
15843 + si_read_unlock(sb);
15848 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15849 + size_t len, unsigned int flags)
15852 + struct au_write_pre wpre;
15853 + struct inode *inode;
15854 + struct file *h_file;
15856 + inode = file_inode(file);
15857 + au_mtx_and_read_lock(inode);
15860 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15861 + err = PTR_ERR(h_file);
15862 + if (IS_ERR(h_file))
15865 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15866 + au_write_post(inode, h_file, &wpre, err);
15869 + si_read_unlock(inode->i_sb);
15870 + inode_unlock(inode);
15874 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15878 + struct au_write_pre wpre;
15879 + struct inode *inode;
15880 + struct file *h_file;
15882 + inode = file_inode(file);
15883 + au_mtx_and_read_lock(inode);
15886 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15887 + err = PTR_ERR(h_file);
15888 + if (IS_ERR(h_file))
15892 + err = vfs_fallocate(h_file, mode, offset, len);
15894 + au_write_post(inode, h_file, &wpre, /*written*/1);
15897 + si_read_unlock(inode->i_sb);
15898 + inode_unlock(inode);
15902 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15903 + struct file *dst, loff_t dst_pos,
15904 + size_t len, unsigned int flags)
15907 + struct au_write_pre wpre;
15908 + enum { SRC, DST };
15910 + struct inode *inode;
15911 + struct file *h_file;
15912 + struct super_block *h_sb;
15914 +#define a_src a[SRC]
15915 +#define a_dst a[DST]
15918 + a_src.inode = file_inode(src);
15919 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15921 + a_dst.inode = file_inode(dst);
15922 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15925 + au_mtx_and_read_lock(a_dst.inode);
15927 + * in order to match the order in di_write_lock2_{child,parent}(),
15928 + * use f_path.dentry for this comparison.
15930 + if (src->f_path.dentry < dst->f_path.dentry) {
15931 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15932 + err = PTR_ERR(a_src.h_file);
15933 + if (IS_ERR(a_src.h_file))
15936 + wpre.lsc = AuLsc_FI_2;
15937 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15938 + err = PTR_ERR(a_dst.h_file);
15939 + if (IS_ERR(a_dst.h_file)) {
15940 + au_read_post(a_src.inode, a_src.h_file);
15944 + wpre.lsc = AuLsc_FI_1;
15945 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15946 + err = PTR_ERR(a_dst.h_file);
15947 + if (IS_ERR(a_dst.h_file))
15950 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15951 + err = PTR_ERR(a_src.h_file);
15952 + if (IS_ERR(a_src.h_file)) {
15953 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15960 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15961 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15962 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15968 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15969 + dst_pos, len, flags);
15972 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15973 + fi_read_unlock(src);
15974 + au_read_post(a_src.inode, a_src.h_file);
15976 + si_read_unlock(a_dst.inode->i_sb);
15977 + inode_unlock(a_dst.inode);
15984 +/* ---------------------------------------------------------------------- */
15987 + * The locking order around current->mmap_sem.
15988 + * - in most and regular cases
15989 + * file I/O syscall -- aufs_read() or something
15990 + * -- si_rwsem for read -- mmap_sem
15991 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15993 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15994 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15995 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15996 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15997 + * It means that when aufs acquires si_rwsem for write, the process should never
15998 + * acquire mmap_sem.
16000 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16001 + * problem either since any directory is not able to be mmap-ed.
16002 + * The similar scenario is applied to aufs_readlink() too.
16005 +#if 0 /* stop calling security_file_mmap() */
16006 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16007 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16009 +static unsigned long au_arch_prot_conv(unsigned long flags)
16011 + /* currently ppc64 only */
16012 +#ifdef CONFIG_PPC64
16013 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16014 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16015 + return AuConv_VM_PROT(flags, SAO);
16017 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16022 +static unsigned long au_prot_conv(unsigned long flags)
16024 + return AuConv_VM_PROT(flags, READ)
16025 + | AuConv_VM_PROT(flags, WRITE)
16026 + | AuConv_VM_PROT(flags, EXEC)
16027 + | au_arch_prot_conv(flags);
16030 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16031 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16033 +static unsigned long au_flag_conv(unsigned long flags)
16035 + return AuConv_VM_MAP(flags, GROWSDOWN)
16036 + | AuConv_VM_MAP(flags, DENYWRITE)
16037 + | AuConv_VM_MAP(flags, LOCKED);
16041 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16044 + const unsigned char wlock
16045 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16046 + struct super_block *sb;
16047 + struct file *h_file;
16048 + struct inode *inode;
16050 + AuDbgVmRegion(file, vma);
16052 + inode = file_inode(file);
16053 + sb = inode->i_sb;
16055 + si_read_lock(sb, AuLock_NOPLMW);
16057 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16059 + err = PTR_ERR(h_file);
16060 + if (IS_ERR(h_file))
16064 + au_set_mmapped(file);
16065 + au_vm_file_reset(vma, h_file);
16067 + * we cannot call security_mmap_file() here since it may acquire
16068 + * mmap_sem or i_mutex.
16070 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16071 + * au_flag_conv(vma->vm_flags));
16074 + err = call_mmap(h_file, vma);
16076 + au_vm_prfile_set(vma, file);
16077 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16078 + goto out_fput; /* success */
16080 + au_unset_mmapped(file);
16081 + au_vm_file_reset(vma, file);
16085 + ii_write_unlock(inode);
16090 + si_read_unlock(sb);
16096 +/* ---------------------------------------------------------------------- */
16098 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16102 + struct au_write_pre wpre;
16103 + struct inode *inode;
16104 + struct file *h_file;
16106 + err = 0; /* -EBADF; */ /* posix? */
16107 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16110 + inode = file_inode(file);
16111 + au_mtx_and_read_lock(inode);
16114 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16115 + err = PTR_ERR(h_file);
16116 + if (IS_ERR(h_file))
16119 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16120 + au_write_post(inode, h_file, &wpre, /*written*/0);
16123 + si_read_unlock(inode->i_sb);
16124 + inode_unlock(inode);
16129 +static int aufs_fasync(int fd, struct file *file, int flag)
16132 + struct file *h_file;
16133 + struct super_block *sb;
16135 + sb = file->f_path.dentry->d_sb;
16136 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16138 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16139 + err = PTR_ERR(h_file);
16140 + if (IS_ERR(h_file))
16143 + if (h_file->f_op->fasync)
16144 + err = h_file->f_op->fasync(fd, h_file, flag);
16145 + fput(h_file); /* instead of au_read_post() */
16148 + si_read_unlock(sb);
16152 +static int aufs_setfl(struct file *file, unsigned long arg)
16155 + struct file *h_file;
16156 + struct super_block *sb;
16158 + sb = file->f_path.dentry->d_sb;
16159 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16161 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16162 + err = PTR_ERR(h_file);
16163 + if (IS_ERR(h_file))
16166 + /* stop calling h_file->fasync */
16167 + arg |= vfsub_file_flags(file) & FASYNC;
16168 + err = setfl(/*unused fd*/-1, h_file, arg);
16169 + fput(h_file); /* instead of au_read_post() */
16172 + si_read_unlock(sb);
16176 +/* ---------------------------------------------------------------------- */
16178 +/* no one supports this operation, currently */
16179 +#if 0 /* reserved for future use */
16180 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16181 + size_t len, loff_t *pos, int more)
16186 +/* ---------------------------------------------------------------------- */
16188 +const struct file_operations aufs_file_fop = {
16189 + .owner = THIS_MODULE,
16191 + .llseek = default_llseek,
16193 + .read_iter = aufs_read_iter,
16194 + .write_iter = aufs_write_iter,
16196 +#ifdef CONFIG_AUFS_POLL
16197 + .poll = aufs_poll,
16199 + .unlocked_ioctl = aufs_ioctl_nondir,
16200 +#ifdef CONFIG_COMPAT
16201 + .compat_ioctl = aufs_compat_ioctl_nondir,
16203 + .mmap = aufs_mmap,
16204 + .open = aufs_open_nondir,
16205 + .flush = aufs_flush_nondir,
16206 + .release = aufs_release_nondir,
16207 + .fsync = aufs_fsync_nondir,
16208 + .fasync = aufs_fasync,
16209 + /* .sendpage = aufs_sendpage, */
16210 + .setfl = aufs_setfl,
16211 + .splice_write = aufs_splice_write,
16212 + .splice_read = aufs_splice_read,
16213 +#if 0 /* reserved for future use */
16214 + .aio_splice_write = aufs_aio_splice_write,
16215 + .aio_splice_read = aufs_aio_splice_read,
16217 + .fallocate = aufs_fallocate,
16218 + .copy_file_range = aufs_copy_file_range
16220 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16221 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16222 +++ linux/fs/aufs/fstype.h 2021-05-02 20:15:14.673337458 +0200
16224 +/* SPDX-License-Identifier: GPL-2.0 */
16226 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16228 + * This program, aufs is free software; you can redistribute it and/or modify
16229 + * it under the terms of the GNU General Public License as published by
16230 + * the Free Software Foundation; either version 2 of the License, or
16231 + * (at your option) any later version.
16233 + * This program is distributed in the hope that it will be useful,
16234 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16235 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16236 + * GNU General Public License for more details.
16238 + * You should have received a copy of the GNU General Public License
16239 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16243 + * judging filesystem type
16246 +#ifndef __AUFS_FSTYPE_H__
16247 +#define __AUFS_FSTYPE_H__
16251 +#include <linux/fs.h>
16252 +#include <linux/magic.h>
16253 +#include <linux/nfs_fs.h>
16254 +#include <linux/romfs_fs.h>
16256 +static inline int au_test_aufs(struct super_block *sb)
16258 + return sb->s_magic == AUFS_SUPER_MAGIC;
16261 +static inline const char *au_sbtype(struct super_block *sb)
16263 + return sb->s_type->name;
16266 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16268 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16269 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16275 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16277 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16278 + return sb->s_magic == ROMFS_MAGIC;
16284 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16286 +#if IS_ENABLED(CONFIG_CRAMFS)
16287 + return sb->s_magic == CRAMFS_MAGIC;
16292 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16294 +#if IS_ENABLED(CONFIG_NFS_FS)
16295 + return sb->s_magic == NFS_SUPER_MAGIC;
16301 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16303 +#if IS_ENABLED(CONFIG_FUSE_FS)
16304 + return sb->s_magic == FUSE_SUPER_MAGIC;
16310 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16312 +#if IS_ENABLED(CONFIG_XFS_FS)
16313 + return sb->s_magic == XFS_SB_MAGIC;
16319 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16321 +#ifdef CONFIG_TMPFS
16322 + return sb->s_magic == TMPFS_MAGIC;
16328 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16330 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16331 + return !strcmp(au_sbtype(sb), "ecryptfs");
16337 +static inline int au_test_ramfs(struct super_block *sb)
16339 + return sb->s_magic == RAMFS_MAGIC;
16342 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16344 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16345 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16351 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16353 +#ifdef CONFIG_PROC_FS
16354 + return sb->s_magic == PROC_SUPER_MAGIC;
16360 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16362 +#ifdef CONFIG_SYSFS
16363 + return sb->s_magic == SYSFS_MAGIC;
16369 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16371 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16372 + return sb->s_magic == CONFIGFS_MAGIC;
16378 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16380 +#if IS_ENABLED(CONFIG_MINIX_FS)
16381 + return sb->s_magic == MINIX3_SUPER_MAGIC
16382 + || sb->s_magic == MINIX2_SUPER_MAGIC
16383 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16384 + || sb->s_magic == MINIX_SUPER_MAGIC
16385 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16391 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16393 +#if IS_ENABLED(CONFIG_FAT_FS)
16394 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16400 +static inline int au_test_msdos(struct super_block *sb)
16402 + return au_test_fat(sb);
16405 +static inline int au_test_vfat(struct super_block *sb)
16407 + return au_test_fat(sb);
16410 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16412 +#ifdef CONFIG_SECURITYFS
16413 + return sb->s_magic == SECURITYFS_MAGIC;
16419 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16421 +#if IS_ENABLED(CONFIG_SQUASHFS)
16422 + return sb->s_magic == SQUASHFS_MAGIC;
16428 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16430 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16431 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16437 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16439 +#if IS_ENABLED(CONFIG_XENFS)
16440 + return sb->s_magic == XENFS_SUPER_MAGIC;
16446 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16448 +#ifdef CONFIG_DEBUG_FS
16449 + return sb->s_magic == DEBUGFS_MAGIC;
16455 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16457 +#if IS_ENABLED(CONFIG_NILFS)
16458 + return sb->s_magic == NILFS_SUPER_MAGIC;
16464 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16466 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16467 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16473 +/* ---------------------------------------------------------------------- */
16475 + * they can't be an aufs branch.
16477 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16480 +#ifndef CONFIG_AUFS_BR_RAMFS
16481 + au_test_ramfs(sb) ||
16483 + au_test_procfs(sb)
16484 + || au_test_sysfs(sb)
16485 + || au_test_configfs(sb)
16486 + || au_test_debugfs(sb)
16487 + || au_test_securityfs(sb)
16488 + || au_test_xenfs(sb)
16489 + || au_test_ecryptfs(sb)
16490 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16491 + || au_test_aufs(sb); /* will be supported in next version */
16494 +static inline int au_test_fs_remote(struct super_block *sb)
16496 + return !au_test_tmpfs(sb)
16497 +#ifdef CONFIG_AUFS_BR_RAMFS
16498 + && !au_test_ramfs(sb)
16500 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16503 +/* ---------------------------------------------------------------------- */
16506 + * Note: these functions (below) are created after reading ->getattr() in all
16507 + * filesystems under linux/fs. it means we have to do so in every update...
16511 + * some filesystems require getattr to refresh the inode attributes before
16513 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16514 + * and leave the work for d_revalidate()
16516 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16518 + return au_test_nfs(sb)
16519 + || au_test_fuse(sb)
16520 + /* || au_test_btrfs(sb) */ /* untested */
16525 + * filesystems which don't maintain i_size or i_blocks.
16527 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16529 + return au_test_xfs(sb)
16530 + || au_test_btrfs(sb)
16531 + || au_test_ubifs(sb)
16532 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16533 + /* || au_test_minix(sb) */ /* untested */
16538 + * filesystems which don't store the correct value in some of their inode
16541 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16543 + return au_test_fs_bad_iattr_size(sb)
16544 + || au_test_fat(sb)
16545 + || au_test_msdos(sb)
16546 + || au_test_vfat(sb);
16549 +/* they don't check i_nlink in link(2) */
16550 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16552 + return au_test_tmpfs(sb)
16553 +#ifdef CONFIG_AUFS_BR_RAMFS
16554 + || au_test_ramfs(sb)
16556 + || au_test_ubifs(sb)
16557 + || au_test_hfsplus(sb);
16561 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16563 +static inline int au_test_fs_notime(struct super_block *sb)
16565 + return au_test_nfs(sb)
16566 + || au_test_fuse(sb)
16567 + || au_test_ubifs(sb)
16571 +/* temporary support for i#1 in cramfs */
16572 +static inline int au_test_fs_unique_ino(struct inode *inode)
16574 + if (au_test_cramfs(inode->i_sb))
16575 + return inode->i_ino != 1;
16579 +/* ---------------------------------------------------------------------- */
16582 + * the filesystem where the xino files placed must support i/o after unlink and
16583 + * maintain i_size and i_blocks.
16585 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16587 + return au_test_fs_remote(sb)
16588 + || au_test_fs_bad_iattr_size(sb)
16589 + /* don't want unnecessary work for xino */
16590 + || au_test_aufs(sb)
16591 + || au_test_ecryptfs(sb)
16592 + || au_test_nilfs(sb);
16595 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16597 + return au_test_tmpfs(sb)
16598 + || au_test_ramfs(sb);
16602 + * test if the @sb is real-readonly.
16604 +static inline int au_test_fs_rr(struct super_block *sb)
16606 + return au_test_squashfs(sb)
16607 + || au_test_iso9660(sb)
16608 + || au_test_cramfs(sb)
16609 + || au_test_romfs(sb);
16613 + * test if the @inode is nfs with 'noacl' option
16614 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16616 +static inline int au_test_nfs_noacl(struct inode *inode)
16618 + return au_test_nfs(inode->i_sb)
16619 + /* && IS_POSIXACL(inode) */
16620 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16623 +#endif /* __KERNEL__ */
16624 +#endif /* __AUFS_FSTYPE_H__ */
16625 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16626 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16627 +++ linux/fs/aufs/hbl.h 2021-05-02 20:15:14.673337458 +0200
16629 +/* SPDX-License-Identifier: GPL-2.0 */
16631 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16633 + * This program, aufs is free software; you can redistribute it and/or modify
16634 + * it under the terms of the GNU General Public License as published by
16635 + * the Free Software Foundation; either version 2 of the License, or
16636 + * (at your option) any later version.
16638 + * This program is distributed in the hope that it will be useful,
16639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16641 + * GNU General Public License for more details.
16643 + * You should have received a copy of the GNU General Public License
16644 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16648 + * helpers for hlist_bl.h
16651 +#ifndef __AUFS_HBL_H__
16652 +#define __AUFS_HBL_H__
16656 +#include <linux/list_bl.h>
16658 +static inline void au_hbl_add(struct hlist_bl_node *node,
16659 + struct hlist_bl_head *hbl)
16661 + hlist_bl_lock(hbl);
16662 + hlist_bl_add_head(node, hbl);
16663 + hlist_bl_unlock(hbl);
16666 +static inline void au_hbl_del(struct hlist_bl_node *node,
16667 + struct hlist_bl_head *hbl)
16669 + hlist_bl_lock(hbl);
16670 + hlist_bl_del(node);
16671 + hlist_bl_unlock(hbl);
16674 +#define au_hbl_for_each(pos, head) \
16675 + for (pos = hlist_bl_first(head); \
16679 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16681 + unsigned long cnt;
16682 + struct hlist_bl_node *pos;
16685 + hlist_bl_lock(hbl);
16686 + au_hbl_for_each(pos, hbl)
16688 + hlist_bl_unlock(hbl);
16692 +#endif /* __KERNEL__ */
16693 +#endif /* __AUFS_HBL_H__ */
16694 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16695 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16696 +++ linux/fs/aufs/hfsnotify.c 2021-05-02 20:15:14.673337458 +0200
16698 +// SPDX-License-Identifier: GPL-2.0
16700 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16702 + * This program, aufs is free software; you can redistribute it and/or modify
16703 + * it under the terms of the GNU General Public License as published by
16704 + * the Free Software Foundation; either version 2 of the License, or
16705 + * (at your option) any later version.
16707 + * This program is distributed in the hope that it will be useful,
16708 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16709 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16710 + * GNU General Public License for more details.
16712 + * You should have received a copy of the GNU General Public License
16713 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16717 + * fsnotify for the lower directories
16722 +/* FS_IN_IGNORED is unnecessary */
16723 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16724 + | FS_CREATE | FS_EVENT_ON_CHILD);
16725 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16726 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16728 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16730 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16732 + /* AuDbg("here\n"); */
16733 + au_cache_free_hnotify(hn);
16734 + smp_mb__before_atomic(); /* for atomic64_dec */
16735 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16736 + wake_up(&au_hfsn_wq);
16739 +static int au_hfsn_alloc(struct au_hinode *hinode)
16742 + struct au_hnotify *hn;
16743 + struct super_block *sb;
16744 + struct au_branch *br;
16745 + struct fsnotify_mark *mark;
16746 + aufs_bindex_t bindex;
16748 + hn = hinode->hi_notify;
16749 + sb = hn->hn_aufs_inode->i_sb;
16750 + bindex = au_br_index(sb, hinode->hi_id);
16751 + br = au_sbr(sb, bindex);
16752 + AuDebugOn(!br->br_hfsn);
16754 + mark = &hn->hn_mark;
16755 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16756 + mark->mask = AuHfsnMask;
16758 + * by udba rename or rmdir, aufs assign a new inode to the known
16759 + * h_inode, so specify 1 to allow dups.
16762 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16768 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16770 + struct fsnotify_mark *mark;
16771 + unsigned long long ull;
16772 + struct fsnotify_group *group;
16774 + ull = atomic64_inc_return(&au_hfsn_ifree);
16777 + mark = &hn->hn_mark;
16778 + spin_lock(&mark->lock);
16779 + group = mark->group;
16780 + fsnotify_get_group(group);
16781 + spin_unlock(&mark->lock);
16783 + fsnotify_destroy_mark(mark, group);
16784 + fsnotify_put_mark(mark);
16785 + fsnotify_put_group(group);
16788 + /* free hn by myself */
16792 +/* ---------------------------------------------------------------------- */
16794 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16796 + struct fsnotify_mark *mark;
16798 + mark = &hinode->hi_notify->hn_mark;
16799 + spin_lock(&mark->lock);
16801 + AuDebugOn(mark->mask & AuHfsnMask);
16802 + mark->mask |= AuHfsnMask;
16804 + AuDebugOn(!(mark->mask & AuHfsnMask));
16805 + mark->mask &= ~AuHfsnMask;
16807 + spin_unlock(&mark->lock);
16808 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16811 +/* ---------------------------------------------------------------------- */
16813 +/* #define AuDbgHnotify */
16814 +#ifdef AuDbgHnotify
16815 +static char *au_hfsn_name(u32 mask)
16817 +#ifdef CONFIG_AUFS_DEBUG
16818 +#define test_ret(flag) \
16820 + if (mask & flag) \
16823 + test_ret(FS_ACCESS);
16824 + test_ret(FS_MODIFY);
16825 + test_ret(FS_ATTRIB);
16826 + test_ret(FS_CLOSE_WRITE);
16827 + test_ret(FS_CLOSE_NOWRITE);
16828 + test_ret(FS_OPEN);
16829 + test_ret(FS_MOVED_FROM);
16830 + test_ret(FS_MOVED_TO);
16831 + test_ret(FS_CREATE);
16832 + test_ret(FS_DELETE);
16833 + test_ret(FS_DELETE_SELF);
16834 + test_ret(FS_MOVE_SELF);
16835 + test_ret(FS_UNMOUNT);
16836 + test_ret(FS_Q_OVERFLOW);
16837 + test_ret(FS_IN_IGNORED);
16838 + test_ret(FS_ISDIR);
16839 + test_ret(FS_IN_ONESHOT);
16840 + test_ret(FS_EVENT_ON_CHILD);
16849 +/* ---------------------------------------------------------------------- */
16851 +static void au_hfsn_free_group(struct fsnotify_group *group)
16853 + struct au_br_hfsnotify *hfsn = group->private;
16855 + /* AuDbg("here\n"); */
16856 + au_kfree_try_rcu(hfsn);
16859 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16860 + u32 mask, const void *data, int data_type,
16861 + struct inode *dir,
16862 + const struct qstr *file_name, u32 cookie,
16863 + struct fsnotify_iter_info *iter_info)
16866 + struct au_hnotify *hnotify;
16867 + struct inode *h_dir, *h_inode;
16868 + struct fsnotify_mark *inode_mark;
16870 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16873 + /* if FS_UNMOUNT happens, there must be another bug */
16874 + AuDebugOn(mask & FS_UNMOUNT);
16875 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16880 +#ifdef AuDbgHnotify
16882 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16883 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16884 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16885 + h_dir->i_ino, mask, au_hfsn_name(mask),
16886 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16887 + /* WARN_ON(1); */
16892 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16893 + AuDebugOn(!inode_mark);
16894 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16895 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16901 +static struct fsnotify_ops au_hfsn_ops = {
16902 + .handle_event = au_hfsn_handle_event,
16903 + .free_group_priv = au_hfsn_free_group,
16904 + .free_mark = au_hfsn_free_mark
16907 +/* ---------------------------------------------------------------------- */
16909 +static void au_hfsn_fin_br(struct au_branch *br)
16911 + struct au_br_hfsnotify *hfsn;
16913 + hfsn = br->br_hfsn;
16916 + fsnotify_put_group(hfsn->hfsn_group);
16921 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16924 + struct fsnotify_group *group;
16925 + struct au_br_hfsnotify *hfsn;
16928 + br->br_hfsn = NULL;
16929 + if (!au_br_hnotifyable(perm))
16933 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16934 + if (unlikely(!hfsn))
16938 + group = fsnotify_alloc_group(&au_hfsn_ops);
16939 + if (IS_ERR(group)) {
16940 + err = PTR_ERR(group);
16941 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16945 + group->private = hfsn;
16946 + hfsn->hfsn_group = group;
16947 + br->br_hfsn = hfsn;
16948 + goto out; /* success */
16951 + au_kfree_try_rcu(hfsn);
16956 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16961 + if (!br->br_hfsn)
16962 + err = au_hfsn_init_br(br, perm);
16967 +/* ---------------------------------------------------------------------- */
16969 +static void au_hfsn_fin(void)
16971 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16972 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16975 +const struct au_hnotify_op au_hnotify_op = {
16976 + .ctl = au_hfsn_ctl,
16977 + .alloc = au_hfsn_alloc,
16978 + .free = au_hfsn_free,
16980 + .fin = au_hfsn_fin,
16982 + .reset_br = au_hfsn_reset_br,
16983 + .fin_br = au_hfsn_fin_br,
16984 + .init_br = au_hfsn_init_br
16986 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16987 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16988 +++ linux/fs/aufs/hfsplus.c 2021-05-02 20:15:14.673337458 +0200
16990 +// SPDX-License-Identifier: GPL-2.0
16992 + * Copyright (C) 2010-2020 Junjiro R. Okajima
16994 + * This program, aufs is free software; you can redistribute it and/or modify
16995 + * it under the terms of the GNU General Public License as published by
16996 + * the Free Software Foundation; either version 2 of the License, or
16997 + * (at your option) any later version.
16999 + * This program is distributed in the hope that it will be useful,
17000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17002 + * GNU General Public License for more details.
17004 + * You should have received a copy of the GNU General Public License
17005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17009 + * special support for filesystems which acquires an inode mutex
17010 + * at final closing a file, eg, hfsplus.
17012 + * This trick is very simple and stupid, just to open the file before really
17013 + * necessary open to tell hfsplus that this is not the final closing.
17014 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17015 + * and au_h_open_post() after releasing it.
17020 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17023 + struct file *h_file;
17024 + struct dentry *h_dentry;
17026 + h_dentry = au_h_dptr(dentry, bindex);
17027 + AuDebugOn(!h_dentry);
17028 + AuDebugOn(d_is_negative(h_dentry));
17031 + if (au_test_hfsplus(h_dentry->d_sb)
17032 + && d_is_reg(h_dentry))
17033 + h_file = au_h_open(dentry, bindex,
17034 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17035 + /*file*/NULL, force_wr);
17039 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17040 + struct file *h_file)
17042 + struct au_branch *br;
17046 + br = au_sbr(dentry->d_sb, bindex);
17047 + au_lcnt_dec(&br->br_nfiles);
17050 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17051 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17052 +++ linux/fs/aufs/hnotify.c 2021-05-02 20:15:14.673337458 +0200
17054 +// SPDX-License-Identifier: GPL-2.0
17056 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17058 + * This program, aufs is free software; you can redistribute it and/or modify
17059 + * it under the terms of the GNU General Public License as published by
17060 + * the Free Software Foundation; either version 2 of the License, or
17061 + * (at your option) any later version.
17063 + * This program is distributed in the hope that it will be useful,
17064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17066 + * GNU General Public License for more details.
17068 + * You should have received a copy of the GNU General Public License
17069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17073 + * abstraction to notify the direct changes on lower directories
17076 +/* #include <linux/iversion.h> */
17079 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17082 + struct au_hnotify *hn;
17085 + hn = au_cache_alloc_hnotify();
17087 + hn->hn_aufs_inode = inode;
17088 + hinode->hi_notify = hn;
17089 + err = au_hnotify_op.alloc(hinode);
17091 + if (unlikely(err)) {
17092 + hinode->hi_notify = NULL;
17093 + au_cache_free_hnotify(hn);
17095 + * The upper dir was removed by udba, but the same named
17096 + * dir left. In this case, aufs assigns a new inode
17097 + * number and set the monitor again.
17098 + * For the lower dir, the old monitor is still left.
17100 + if (err == -EEXIST)
17109 +void au_hn_free(struct au_hinode *hinode)
17111 + struct au_hnotify *hn;
17113 + hn = hinode->hi_notify;
17115 + hinode->hi_notify = NULL;
17116 + if (au_hnotify_op.free(hinode, hn))
17117 + au_cache_free_hnotify(hn);
17121 +/* ---------------------------------------------------------------------- */
17123 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17125 + if (hinode->hi_notify)
17126 + au_hnotify_op.ctl(hinode, do_set);
17129 +void au_hn_reset(struct inode *inode, unsigned int flags)
17131 + aufs_bindex_t bindex, bbot;
17132 + struct inode *hi;
17133 + struct dentry *iwhdentry;
17135 + bbot = au_ibbot(inode);
17136 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17137 + hi = au_h_iptr(inode, bindex);
17141 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17142 + iwhdentry = au_hi_wh(inode, bindex);
17146 + au_set_h_iptr(inode, bindex, NULL, 0);
17147 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17148 + flags & ~AuHi_XINO);
17151 + /* inode_unlock(hi); */
17155 +/* ---------------------------------------------------------------------- */
17157 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17160 + aufs_bindex_t bindex, bbot, bfound, btop;
17161 + struct inode *h_i;
17164 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17165 + pr_warn("branch root dir was changed\n");
17170 + bbot = au_ibbot(inode);
17171 + btop = au_ibtop(inode);
17172 +#if 0 /* reserved for future use */
17173 + if (bindex == bbot) {
17174 + /* keep this ino in rename case */
17178 + for (bindex = btop; bindex <= bbot; bindex++)
17179 + if (au_h_iptr(inode, bindex) == h_inode) {
17186 + for (bindex = btop; bindex <= bbot; bindex++) {
17187 + h_i = au_h_iptr(inode, bindex);
17191 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17192 + /* ignore this error */
17193 + /* bad action? */
17196 + /* children inode number will be broken */
17203 +static int hn_gen_tree(struct dentry *dentry)
17205 + int err, i, j, ndentry;
17206 + struct au_dcsub_pages dpages;
17207 + struct au_dpage *dpage;
17208 + struct dentry **dentries;
17210 + err = au_dpages_init(&dpages, GFP_NOFS);
17211 + if (unlikely(err))
17213 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17214 + if (unlikely(err))
17217 + for (i = 0; i < dpages.ndpage; i++) {
17218 + dpage = dpages.dpages + i;
17219 + dentries = dpage->dentries;
17220 + ndentry = dpage->ndentry;
17221 + for (j = 0; j < ndentry; j++) {
17222 + struct dentry *d;
17229 + if (d_really_is_positive(d))
17230 + /* todo: reset children xino?
17231 + cached children only? */
17232 + au_iigen_dec(d_inode(d));
17237 + au_dpages_free(&dpages);
17243 + * return 0 if processed.
17245 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17246 + const unsigned int isdir)
17249 + struct dentry *d;
17250 + struct qstr *dname;
17253 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17254 + pr_warn("branch root dir was changed\n");
17260 + AuDebugOn(!name);
17261 + au_iigen_dec(inode);
17262 + spin_lock(&inode->i_lock);
17263 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17264 + spin_lock(&d->d_lock);
17265 + dname = &d->d_name;
17266 + if (dname->len != nlen
17267 + && memcmp(dname->name, name, nlen)) {
17268 + spin_unlock(&d->d_lock);
17273 + spin_unlock(&d->d_lock);
17276 + spin_unlock(&inode->i_lock);
17278 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17279 + d = d_find_any_alias(inode);
17281 + au_iigen_dec(inode);
17285 + spin_lock(&d->d_lock);
17286 + dname = &d->d_name;
17287 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17288 + spin_unlock(&d->d_lock);
17289 + err = hn_gen_tree(d);
17290 + spin_lock(&d->d_lock);
17292 + spin_unlock(&d->d_lock);
17301 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17305 + if (IS_ROOT(dentry)) {
17306 + pr_warn("branch root dir was changed\n");
17312 + au_digen_dec(dentry);
17313 + if (d_really_is_positive(dentry))
17314 + au_iigen_dec(d_inode(dentry));
17316 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17317 + if (d_really_is_positive(dentry))
17318 + err = hn_gen_tree(dentry);
17325 +/* ---------------------------------------------------------------------- */
17327 +/* hnotify job flags */
17328 +#define AuHnJob_XINO0 1
17329 +#define AuHnJob_GEN (1 << 1)
17330 +#define AuHnJob_DIRENT (1 << 2)
17331 +#define AuHnJob_ISDIR (1 << 3)
17332 +#define AuHnJob_TRYXINO0 (1 << 4)
17333 +#define AuHnJob_MNTPNT (1 << 5)
17334 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17335 +#define au_fset_hnjob(flags, name) \
17336 + do { (flags) |= AuHnJob_##name; } while (0)
17337 +#define au_fclr_hnjob(flags, name) \
17338 + do { (flags) &= ~AuHnJob_##name; } while (0)
17346 +struct au_hnotify_args {
17347 + struct inode *h_dir, *dir, *h_child_inode;
17349 + unsigned int flags[AuHnLast];
17350 + unsigned int h_child_nlen;
17351 + char h_child_name[];
17354 +struct hn_job_args {
17355 + unsigned int flags;
17356 + struct inode *inode, *h_inode, *dir, *h_dir;
17357 + struct dentry *dentry;
17362 +static int hn_job(struct hn_job_args *a)
17364 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17368 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17369 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17371 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17374 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17375 + if (!a->h_inode->i_nlink
17376 + && !(a->h_inode->i_state & I_LINKABLE))
17377 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17378 + inode_unlock_shared(a->h_inode);
17381 + /* make the generation obsolete */
17382 + if (au_ftest_hnjob(a->flags, GEN)) {
17385 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17387 + if (e && a->dentry)
17388 + hn_gen_by_name(a->dentry, isdir);
17389 + /* ignore this error */
17392 + /* make dir entries obsolete */
17393 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17394 + struct au_vdir *vdir;
17396 + vdir = au_ivdir(a->inode);
17398 + vdir->vd_jiffy = 0;
17399 + /* IMustLock(a->inode); */
17400 + /* inode_inc_iversion(a->inode); */
17403 + /* can do nothing but warn */
17404 + if (au_ftest_hnjob(a->flags, MNTPNT)
17406 + && d_mountpoint(a->dentry))
17407 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17412 +/* ---------------------------------------------------------------------- */
17414 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17415 + struct inode *dir)
17417 + struct dentry *dentry, *d, *parent;
17418 + struct qstr *dname;
17420 + parent = d_find_any_alias(dir);
17425 + spin_lock(&parent->d_lock);
17426 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17427 + /* AuDbg("%pd\n", d); */
17428 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17429 + dname = &d->d_name;
17430 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17431 + goto cont_unlock;
17435 + goto cont_unlock;
17436 + if (au_dcount(d) > 0) {
17437 + dentry = dget_dlock(d);
17438 + spin_unlock(&d->d_lock);
17443 + spin_unlock(&d->d_lock);
17445 + spin_unlock(&parent->d_lock);
17449 + di_write_lock_child(dentry);
17454 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17455 + aufs_bindex_t bindex, ino_t h_ino)
17457 + struct inode *inode;
17462 + err = au_xino_read(sb, bindex, h_ino, &ino);
17464 + inode = ilookup(sb, ino);
17468 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17469 + pr_warn("wrong root branch\n");
17475 + ii_write_lock_child(inode);
17481 +static void au_hn_bh(void *_args)
17483 + struct au_hnotify_args *a = _args;
17484 + struct super_block *sb;
17485 + aufs_bindex_t bindex, bbot, bfound;
17486 + unsigned char xino, try_iput;
17488 + struct inode *inode;
17490 + struct hn_job_args args;
17491 + struct dentry *dentry;
17492 + struct au_sbinfo *sbinfo;
17494 + AuDebugOn(!_args);
17495 + AuDebugOn(!a->h_dir);
17496 + AuDebugOn(!a->dir);
17497 + AuDebugOn(!a->mask);
17498 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17499 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17500 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17505 + * do not lock a->dir->i_mutex here
17506 + * because of d_revalidate() may cause a deadlock.
17508 + sb = a->dir->i_sb;
17510 + sbinfo = au_sbi(sb);
17511 + AuDebugOn(!sbinfo);
17512 + si_write_lock(sb, AuLock_NOPLMW);
17514 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17515 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17516 + case FS_MOVED_FROM:
17517 + case FS_MOVED_TO:
17518 + AuWarn1("DIRREN with UDBA may not work correctly "
17519 + "for the direct rename(2)\n");
17522 + ii_read_lock_parent(a->dir);
17524 + bbot = au_ibbot(a->dir);
17525 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17526 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17530 + ii_read_unlock(a->dir);
17531 + if (unlikely(bfound < 0))
17534 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17536 + if (a->h_child_inode)
17537 + h_ino = a->h_child_inode->i_ino;
17539 + if (a->h_child_nlen
17540 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17541 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17542 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17545 + if (dentry && d_really_is_positive(dentry))
17546 + inode = d_inode(dentry);
17547 + if (xino && !inode && h_ino
17548 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17549 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17550 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17551 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17555 + args.flags = a->flags[AuHn_CHILD];
17556 + args.dentry = dentry;
17557 + args.inode = inode;
17558 + args.h_inode = a->h_child_inode;
17559 + args.dir = a->dir;
17560 + args.h_dir = a->h_dir;
17561 + args.h_name = a->h_child_name;
17562 + args.h_nlen = a->h_child_nlen;
17563 + err = hn_job(&args);
17565 + if (au_di(dentry))
17566 + di_write_unlock(dentry);
17569 + if (inode && try_iput) {
17570 + ii_write_unlock(inode);
17574 + ii_write_lock_parent(a->dir);
17575 + args.flags = a->flags[AuHn_PARENT];
17576 + args.dentry = NULL;
17577 + args.inode = a->dir;
17578 + args.h_inode = a->h_dir;
17580 + args.h_dir = NULL;
17581 + args.h_name = NULL;
17583 + err = hn_job(&args);
17584 + ii_write_unlock(a->dir);
17587 + iput(a->h_child_inode);
17590 + si_write_unlock(sb);
17591 + au_nwt_done(&sbinfo->si_nowait);
17595 +/* ---------------------------------------------------------------------- */
17597 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17598 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17601 + unsigned int flags[AuHnLast], f;
17602 + unsigned char isdir, isroot, wh;
17603 + struct inode *dir;
17604 + struct au_hnotify_args *args;
17605 + char *p, *h_child_name;
17608 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17609 + dir = igrab(hnotify->hn_aufs_inode);
17613 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17615 + h_child_name = (void *)h_child_qstr->name;
17616 + len = h_child_qstr->len;
17617 + if (h_child_name) {
17618 + if (len > AUFS_WH_PFX_LEN
17619 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17620 + h_child_name += AUFS_WH_PFX_LEN;
17621 + len -= AUFS_WH_PFX_LEN;
17627 + if (h_child_inode)
17628 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17629 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17630 + flags[AuHn_CHILD] = 0;
17632 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17633 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17634 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17635 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17636 + case FS_MOVED_FROM:
17637 + case FS_MOVED_TO:
17638 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17639 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17642 + AuDebugOn(!h_child_name);
17647 + * aufs never be able to get this child inode.
17648 + * revalidation should be in d_revalidate()
17649 + * by checking i_nlink, i_generation or d_unhashed().
17651 + AuDebugOn(!h_child_name);
17652 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17653 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17661 + h_child_inode = NULL;
17664 + /* iput() and kfree() will be called in au_hnotify() */
17665 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17666 + if (unlikely(!args)) {
17667 + AuErr1("no memory\n");
17671 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17672 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17673 + args->mask = mask;
17675 + args->h_dir = igrab(h_dir);
17676 + if (h_child_inode)
17677 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17678 + args->h_child_inode = h_child_inode;
17679 + args->h_child_nlen = len;
17681 + p = (void *)args;
17682 + p += sizeof(*args);
17683 + memcpy(p, h_child_name, len);
17687 + /* NFS fires the event for silly-renamed one from kworker */
17689 + if (!dir->i_nlink
17690 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17692 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17693 + if (unlikely(err)) {
17694 + pr_err("wkq %d\n", err);
17695 + iput(args->h_child_inode);
17696 + iput(args->h_dir);
17698 + au_kfree_rcu(args);
17705 +/* ---------------------------------------------------------------------- */
17707 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17711 + AuDebugOn(!(udba & AuOptMask_UDBA));
17714 + if (au_hnotify_op.reset_br)
17715 + err = au_hnotify_op.reset_br(udba, br, perm);
17720 +int au_hnotify_init_br(struct au_branch *br, int perm)
17725 + if (au_hnotify_op.init_br)
17726 + err = au_hnotify_op.init_br(br, perm);
17731 +void au_hnotify_fin_br(struct au_branch *br)
17733 + if (au_hnotify_op.fin_br)
17734 + au_hnotify_op.fin_br(br);
17737 +static void au_hn_destroy_cache(void)
17739 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17740 + au_cache[AuCache_HNOTIFY] = NULL;
17743 +int __init au_hnotify_init(void)
17748 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17749 + if (au_cache[AuCache_HNOTIFY]) {
17751 + if (au_hnotify_op.init)
17752 + err = au_hnotify_op.init();
17753 + if (unlikely(err))
17754 + au_hn_destroy_cache();
17760 +void au_hnotify_fin(void)
17762 + if (au_hnotify_op.fin)
17763 + au_hnotify_op.fin();
17765 + /* cf. au_cache_fin() */
17766 + if (au_cache[AuCache_HNOTIFY])
17767 + au_hn_destroy_cache();
17769 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17770 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17771 +++ linux/fs/aufs/iinfo.c 2021-05-02 20:15:14.673337458 +0200
17773 +// SPDX-License-Identifier: GPL-2.0
17775 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17777 + * This program, aufs is free software; you can redistribute it and/or modify
17778 + * it under the terms of the GNU General Public License as published by
17779 + * the Free Software Foundation; either version 2 of the License, or
17780 + * (at your option) any later version.
17782 + * This program is distributed in the hope that it will be useful,
17783 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17784 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17785 + * GNU General Public License for more details.
17787 + * You should have received a copy of the GNU General Public License
17788 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17792 + * inode private data
17797 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17799 + struct inode *h_inode;
17800 + struct au_hinode *hinode;
17802 + IiMustAnyLock(inode);
17804 + hinode = au_hinode(au_ii(inode), bindex);
17805 + h_inode = hinode->hi_inode;
17806 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17810 +/* todo: hard/soft set? */
17811 +void au_hiput(struct au_hinode *hinode)
17813 + au_hn_free(hinode);
17814 + dput(hinode->hi_whdentry);
17815 + iput(hinode->hi_inode);
17818 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17820 + unsigned int flags;
17821 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17824 + if (au_opt_test(mnt_flags, XINO))
17825 + au_fset_hi(flags, XINO);
17826 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17827 + au_fset_hi(flags, HNOTIFY);
17831 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17832 + struct inode *h_inode, unsigned int flags)
17834 + struct au_hinode *hinode;
17835 + struct inode *hi;
17836 + struct au_iinfo *iinfo = au_ii(inode);
17838 + IiMustWriteLock(inode);
17840 + hinode = au_hinode(iinfo, bindex);
17841 + hi = hinode->hi_inode;
17842 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17845 + au_hiput(hinode);
17846 + hinode->hi_inode = h_inode;
17849 + struct super_block *sb = inode->i_sb;
17850 + struct au_branch *br;
17852 + AuDebugOn(inode->i_mode
17853 + && (h_inode->i_mode & S_IFMT)
17854 + != (inode->i_mode & S_IFMT));
17855 + if (bindex == iinfo->ii_btop)
17856 + au_cpup_igen(inode, h_inode);
17857 + br = au_sbr(sb, bindex);
17858 + hinode->hi_id = br->br_id;
17859 + if (au_ftest_hi(flags, XINO)) {
17860 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17862 + if (unlikely(err))
17863 + AuIOErr1("failed au_xino_write() %d\n", err);
17866 + if (au_ftest_hi(flags, HNOTIFY)
17867 + && au_br_hnotifyable(br->br_perm)) {
17868 + err = au_hn_alloc(hinode, inode);
17869 + if (unlikely(err))
17870 + AuIOErr1("au_hn_alloc() %d\n", err);
17875 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17876 + struct dentry *h_wh)
17878 + struct au_hinode *hinode;
17880 + IiMustWriteLock(inode);
17882 + hinode = au_hinode(au_ii(inode), bindex);
17883 + AuDebugOn(hinode->hi_whdentry);
17884 + hinode->hi_whdentry = h_wh;
17887 +void au_update_iigen(struct inode *inode, int half)
17889 + struct au_iinfo *iinfo;
17890 + struct au_iigen *iigen;
17891 + unsigned int sigen;
17893 + sigen = au_sigen(inode->i_sb);
17894 + iinfo = au_ii(inode);
17895 + iigen = &iinfo->ii_generation;
17896 + spin_lock(&iigen->ig_spin);
17897 + iigen->ig_generation = sigen;
17899 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17901 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17902 + spin_unlock(&iigen->ig_spin);
17905 +/* it may be called at remount time, too */
17906 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17908 + struct au_iinfo *iinfo;
17909 + aufs_bindex_t bindex, bbot;
17911 + AuDebugOn(au_is_bad_inode(inode));
17912 + IiMustWriteLock(inode);
17914 + iinfo = au_ii(inode);
17915 + if (do_put_zero && iinfo->ii_btop >= 0) {
17916 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17918 + struct inode *h_i;
17920 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17923 + && !(h_i->i_state & I_LINKABLE))
17924 + au_set_h_iptr(inode, bindex, NULL, 0);
17928 + iinfo->ii_btop = -1;
17929 + iinfo->ii_bbot = -1;
17930 + bbot = au_sbbot(inode->i_sb);
17931 + for (bindex = 0; bindex <= bbot; bindex++)
17932 + if (au_hinode(iinfo, bindex)->hi_inode) {
17933 + iinfo->ii_btop = bindex;
17936 + if (iinfo->ii_btop >= 0)
17937 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17938 + if (au_hinode(iinfo, bindex)->hi_inode) {
17939 + iinfo->ii_bbot = bindex;
17942 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17945 +/* ---------------------------------------------------------------------- */
17947 +void au_icntnr_init_once(void *_c)
17949 + struct au_icntnr *c = _c;
17950 + struct au_iinfo *iinfo = &c->iinfo;
17952 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17953 + au_rw_init(&iinfo->ii_rwsem);
17954 + inode_init_once(&c->vfs_inode);
17957 +void au_hinode_init(struct au_hinode *hinode)
17959 + hinode->hi_inode = NULL;
17960 + hinode->hi_id = -1;
17961 + au_hn_init(hinode);
17962 + hinode->hi_whdentry = NULL;
17965 +int au_iinfo_init(struct inode *inode)
17967 + struct au_iinfo *iinfo;
17968 + struct super_block *sb;
17969 + struct au_hinode *hi;
17972 + sb = inode->i_sb;
17973 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17974 + nbr = au_sbbot(sb) + 1;
17975 + if (unlikely(nbr <= 0))
17977 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17979 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17981 + iinfo->ii_hinode = hi;
17982 + for (i = 0; i < nbr; i++, hi++)
17983 + au_hinode_init(hi);
17985 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17986 + iinfo->ii_btop = -1;
17987 + iinfo->ii_bbot = -1;
17988 + iinfo->ii_vdir = NULL;
17994 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17997 + struct au_hinode *hip;
17999 + AuRwMustWriteLock(&iinfo->ii_rwsem);
18002 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18005 + iinfo->ii_hinode = hip;
18006 + i = iinfo->ii_bbot + 1;
18008 + for (; i < nbr; i++, hip++)
18009 + au_hinode_init(hip);
18016 +void au_iinfo_fin(struct inode *inode)
18018 + struct au_iinfo *iinfo;
18019 + struct au_hinode *hi;
18020 + struct super_block *sb;
18021 + aufs_bindex_t bindex, bbot;
18022 + const unsigned char unlinked = !inode->i_nlink;
18024 + AuDebugOn(au_is_bad_inode(inode));
18026 + sb = inode->i_sb;
18027 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18028 + if (si_pid_test(sb))
18029 + au_xino_delete_inode(inode, unlinked);
18032 + * it is safe to hide the dependency between sbinfo and
18036 + si_noflush_read_lock(sb);
18037 + au_xino_delete_inode(inode, unlinked);
18038 + si_read_unlock(sb);
18042 + iinfo = au_ii(inode);
18043 + if (iinfo->ii_vdir)
18044 + au_vdir_free(iinfo->ii_vdir);
18046 + bindex = iinfo->ii_btop;
18047 + if (bindex >= 0) {
18048 + hi = au_hinode(iinfo, bindex);
18049 + bbot = iinfo->ii_bbot;
18050 + while (bindex++ <= bbot) {
18051 + if (hi->hi_inode)
18056 + au_kfree_rcu(iinfo->ii_hinode);
18057 + AuRwDestroy(&iinfo->ii_rwsem);
18059 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18060 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18061 +++ linux/fs/aufs/inode.c 2021-05-02 20:15:14.673337458 +0200
18063 +// SPDX-License-Identifier: GPL-2.0
18065 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18067 + * This program, aufs is free software; you can redistribute it and/or modify
18068 + * it under the terms of the GNU General Public License as published by
18069 + * the Free Software Foundation; either version 2 of the License, or
18070 + * (at your option) any later version.
18072 + * This program is distributed in the hope that it will be useful,
18073 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18074 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18075 + * GNU General Public License for more details.
18077 + * You should have received a copy of the GNU General Public License
18078 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18082 + * inode functions
18085 +#include <linux/iversion.h>
18088 +struct inode *au_igrab(struct inode *inode)
18091 + AuDebugOn(!atomic_read(&inode->i_count));
18097 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18099 + au_cpup_attr_all(inode, /*force*/0);
18100 + au_update_iigen(inode, /*half*/1);
18102 + inode_inc_iversion(inode);
18105 +static int au_ii_refresh(struct inode *inode, int *update)
18109 + aufs_bindex_t bindex, new_bindex;
18110 + struct super_block *sb;
18111 + struct au_iinfo *iinfo;
18112 + struct au_hinode *p, *q, tmp;
18114 + AuDebugOn(au_is_bad_inode(inode));
18115 + IiMustWriteLock(inode);
18118 + sb = inode->i_sb;
18119 + nbr = au_sbbot(sb) + 1;
18120 + type = inode->i_mode & S_IFMT;
18121 + iinfo = au_ii(inode);
18122 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18123 + if (unlikely(err))
18126 + AuDebugOn(iinfo->ii_btop < 0);
18127 + p = au_hinode(iinfo, iinfo->ii_btop);
18128 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18130 + if (!p->hi_inode)
18133 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18134 + new_bindex = au_br_index(sb, p->hi_id);
18135 + if (new_bindex == bindex)
18138 + if (new_bindex < 0) {
18141 + p->hi_inode = NULL;
18145 + if (new_bindex < iinfo->ii_btop)
18146 + iinfo->ii_btop = new_bindex;
18147 + if (iinfo->ii_bbot < new_bindex)
18148 + iinfo->ii_bbot = new_bindex;
18149 + /* swap two lower inode, and loop again */
18150 + q = au_hinode(iinfo, new_bindex);
18154 + if (tmp.hi_inode) {
18159 + au_update_ibrange(inode, /*do_put_zero*/0);
18160 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18161 + e = au_dy_irefresh(inode);
18162 + if (unlikely(e && !err))
18170 +void au_refresh_iop(struct inode *inode, int force_getattr)
18173 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18174 + const struct inode_operations *iop
18175 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18177 + if (inode->i_op == iop)
18180 + switch (inode->i_mode & S_IFMT) {
18182 + type = AuIop_DIR;
18185 + type = AuIop_SYMLINK;
18188 + type = AuIop_OTHER;
18192 + inode->i_op = iop + type;
18193 + /* unnecessary smp_wmb() */
18196 +int au_refresh_hinode_self(struct inode *inode)
18200 + err = au_ii_refresh(inode, &update);
18202 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18208 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18210 + int err, e, update;
18211 + unsigned int flags;
18213 + aufs_bindex_t bindex, bbot;
18214 + unsigned char isdir;
18215 + struct au_hinode *p;
18216 + struct au_iinfo *iinfo;
18218 + err = au_ii_refresh(inode, &update);
18219 + if (unlikely(err))
18223 + iinfo = au_ii(inode);
18224 + p = au_hinode(iinfo, iinfo->ii_btop);
18225 + mode = (inode->i_mode & S_IFMT);
18226 + isdir = S_ISDIR(mode);
18227 + flags = au_hi_flags(inode, isdir);
18228 + bbot = au_dbbot(dentry);
18229 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18230 + struct inode *h_i, *h_inode;
18231 + struct dentry *h_d;
18233 + h_d = au_h_dptr(dentry, bindex);
18234 + if (!h_d || d_is_negative(h_d))
18237 + h_inode = d_inode(h_d);
18238 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18239 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18240 + h_i = au_h_iptr(inode, bindex);
18242 + if (h_i == h_inode)
18248 + if (bindex < iinfo->ii_btop)
18249 + iinfo->ii_btop = bindex;
18250 + if (iinfo->ii_bbot < bindex)
18251 + iinfo->ii_bbot = bindex;
18252 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18255 + au_update_ibrange(inode, /*do_put_zero*/0);
18256 + e = au_dy_irefresh(inode);
18257 + if (unlikely(e && !err))
18260 + au_refresh_hinode_attr(inode, update && isdir);
18267 +static int set_inode(struct inode *inode, struct dentry *dentry)
18270 + unsigned int flags;
18272 + aufs_bindex_t bindex, btop, btail;
18273 + unsigned char isdir;
18274 + struct dentry *h_dentry;
18275 + struct inode *h_inode;
18276 + struct au_iinfo *iinfo;
18277 + const struct inode_operations *iop;
18279 + IiMustWriteLock(inode);
18283 + iop = au_sbi(inode->i_sb)->si_iop_array;
18284 + btop = au_dbtop(dentry);
18285 + h_dentry = au_h_dptr(dentry, btop);
18286 + h_inode = d_inode(h_dentry);
18287 + mode = h_inode->i_mode;
18288 + switch (mode & S_IFMT) {
18290 + btail = au_dbtail(dentry);
18291 + inode->i_op = iop + AuIop_OTHER;
18292 + inode->i_fop = &aufs_file_fop;
18293 + err = au_dy_iaop(inode, btop, h_inode);
18294 + if (unlikely(err))
18299 + btail = au_dbtaildir(dentry);
18300 + inode->i_op = iop + AuIop_DIR;
18301 + inode->i_fop = &aufs_dir_fop;
18304 + btail = au_dbtail(dentry);
18305 + inode->i_op = iop + AuIop_SYMLINK;
18311 + btail = au_dbtail(dentry);
18312 + inode->i_op = iop + AuIop_OTHER;
18313 + init_special_inode(inode, mode, h_inode->i_rdev);
18316 + AuIOErr("Unknown file type 0%o\n", mode);
18321 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18322 + flags = au_hi_flags(inode, isdir);
18323 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18324 + && au_ftest_hi(flags, HNOTIFY)
18325 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18326 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18327 + au_fclr_hi(flags, HNOTIFY);
18328 + iinfo = au_ii(inode);
18329 + iinfo->ii_btop = btop;
18330 + iinfo->ii_bbot = btail;
18331 + for (bindex = btop; bindex <= btail; bindex++) {
18332 + h_dentry = au_h_dptr(dentry, bindex);
18334 + au_set_h_iptr(inode, bindex,
18335 + au_igrab(d_inode(h_dentry)), flags);
18337 + au_cpup_attr_all(inode, /*force*/1);
18339 + * to force calling aufs_get_acl() every time,
18340 + * do not call cache_no_acl() for aufs inode.
18348 + * successful returns with iinfo write_locked
18350 + * zero: success, matched
18351 + * plus: no error, but unmatched
18353 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18356 + unsigned int gen, igflags;
18357 + aufs_bindex_t bindex, bbot;
18358 + struct inode *h_inode, *h_dinode;
18359 + struct dentry *h_dentry;
18362 + * before this function, if aufs got any iinfo lock, it must be only
18363 + * one, the parent dir.
18364 + * it can happen by UDBA and the obsoleted inode number.
18367 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18371 + ii_write_lock_new_child(inode);
18372 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18373 + h_dinode = d_inode(h_dentry);
18374 + bbot = au_ibbot(inode);
18375 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18376 + h_inode = au_h_iptr(inode, bindex);
18377 + if (!h_inode || h_inode != h_dinode)
18381 + gen = au_iigen(inode, &igflags);
18382 + if (gen == au_digen(dentry)
18383 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18386 + /* fully refresh inode using dentry */
18387 + err = au_refresh_hinode(inode, dentry);
18389 + au_update_iigen(inode, /*half*/0);
18393 + if (unlikely(err))
18394 + ii_write_unlock(inode);
18399 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18400 + unsigned int d_type, ino_t *ino)
18403 + const int isnondir = d_type != DT_DIR;
18405 + /* prevent hardlinked inode number from race condition */
18407 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18408 + if (unlikely(err))
18412 + err = au_xino_read(sb, bindex, h_ino, ino);
18413 + if (unlikely(err))
18414 + goto out_xinondir;
18418 + *ino = au_xino_new_ino(sb);
18419 + if (unlikely(!*ino))
18420 + goto out_xinondir;
18421 + err = au_xino_write(sb, bindex, h_ino, *ino);
18422 + if (unlikely(err))
18423 + goto out_xinondir;
18427 + if (isnondir && idx >= 0)
18428 + au_xinondir_leave(sb, bindex, h_ino, idx);
18433 +/* successful returns with iinfo write_locked */
18434 +/* todo: return with unlocked? */
18435 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18437 + struct inode *inode, *h_inode;
18438 + struct dentry *h_dentry;
18439 + struct super_block *sb;
18440 + ino_t h_ino, ino;
18441 + int err, idx, hlinked;
18442 + aufs_bindex_t btop;
18444 + sb = dentry->d_sb;
18445 + btop = au_dbtop(dentry);
18446 + h_dentry = au_h_dptr(dentry, btop);
18447 + h_inode = d_inode(h_dentry);
18448 + h_ino = h_inode->i_ino;
18449 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18453 + * stop 'race'-ing between hardlinks under different
18457 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18458 + inode = ERR_PTR(err);
18459 + if (unlikely(err))
18463 + err = au_xino_read(sb, btop, h_ino, &ino);
18464 + inode = ERR_PTR(err);
18465 + if (unlikely(err))
18466 + goto out_xinondir;
18469 + ino = au_xino_new_ino(sb);
18470 + if (unlikely(!ino)) {
18471 + inode = ERR_PTR(-EIO);
18472 + goto out_xinondir;
18476 + AuDbg("i%lu\n", (unsigned long)ino);
18477 + inode = au_iget_locked(sb, ino);
18478 + err = PTR_ERR(inode);
18479 + if (IS_ERR(inode))
18480 + goto out_xinondir;
18482 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18483 + if (inode->i_state & I_NEW) {
18484 + ii_write_lock_new_child(inode);
18485 + err = set_inode(inode, dentry);
18487 + unlock_new_inode(inode);
18488 + goto out_xinondir; /* success */
18492 + * iget_failed() calls iput(), but we need to call
18493 + * ii_write_unlock() after iget_failed(). so dirty hack for
18496 + atomic_inc(&inode->i_count);
18497 + iget_failed(inode);
18498 + ii_write_unlock(inode);
18499 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18500 + /* ignore this error */
18502 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18504 + * horrible race condition between lookup, readdir and copyup
18505 + * (or something).
18507 + if (hlinked && idx >= 0)
18508 + au_xinondir_leave(sb, btop, h_ino, idx);
18509 + err = reval_inode(inode, dentry);
18510 + if (unlikely(err < 0)) {
18515 + goto out; /* success */
18516 + else if (hlinked && idx >= 0) {
18517 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18518 + if (unlikely(err)) {
18520 + inode = ERR_PTR(err);
18526 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18527 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18528 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18529 + btop, au_sbtype(h_dentry->d_sb), dentry,
18530 + (unsigned long)h_ino, (unsigned long)ino);
18532 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18535 + if (hlinked && idx >= 0)
18536 + au_xinondir_leave(sb, btop, h_ino, idx);
18542 + inode = ERR_PTR(err);
18544 + if (hlinked && idx >= 0)
18545 + au_xinondir_leave(sb, btop, h_ino, idx);
18550 +/* ---------------------------------------------------------------------- */
18552 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18553 + struct inode *inode)
18556 + struct inode *hi;
18558 + err = au_br_rdonly(au_sbr(sb, bindex));
18560 + /* pseudo-link after flushed may happen out of bounds */
18563 + && au_ibtop(inode) <= bindex
18564 + && bindex <= au_ibbot(inode)) {
18566 + * permission check is unnecessary since vfsub routine
18567 + * will be called later
18569 + hi = au_h_iptr(inode, bindex);
18571 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18577 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18580 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18582 + return inode_permission(h_userns, h_inode, mask);
18585 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18588 + if (au_test_nfs(h_inode->i_sb)
18589 + && (mask & MAY_WRITE)
18590 + && S_ISDIR(h_inode->i_mode))
18591 + mask |= MAY_READ; /* force permission check */
18592 + return au_test_h_perm(h_userns, h_inode, mask);
18594 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18595 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18596 +++ linux/fs/aufs/inode.h 2021-05-02 20:15:14.673337458 +0200
18598 +/* SPDX-License-Identifier: GPL-2.0 */
18600 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18602 + * This program, aufs is free software; you can redistribute it and/or modify
18603 + * it under the terms of the GNU General Public License as published by
18604 + * the Free Software Foundation; either version 2 of the License, or
18605 + * (at your option) any later version.
18607 + * This program is distributed in the hope that it will be useful,
18608 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18609 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18610 + * GNU General Public License for more details.
18612 + * You should have received a copy of the GNU General Public License
18613 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18617 + * inode operations
18620 +#ifndef __AUFS_INODE_H__
18621 +#define __AUFS_INODE_H__
18625 +#include <linux/fsnotify.h>
18626 +#include "rwsem.h"
18630 +struct au_hnotify {
18631 +#ifdef CONFIG_AUFS_HNOTIFY
18632 +#ifdef CONFIG_AUFS_HFSNOTIFY
18633 + /* never use fsnotify_add_vfsmount_mark() */
18634 + struct fsnotify_mark hn_mark;
18636 + struct inode *hn_aufs_inode; /* no get/put */
18637 + struct rcu_head rcu;
18639 +} ____cacheline_aligned_in_smp;
18641 +struct au_hinode {
18642 + struct inode *hi_inode;
18643 + aufs_bindex_t hi_id;
18644 +#ifdef CONFIG_AUFS_HNOTIFY
18645 + struct au_hnotify *hi_notify;
18648 + /* reference to the copied-up whiteout with get/put */
18649 + struct dentry *hi_whdentry;
18653 +#define AuIG_HALF_REFRESHED 1
18654 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18655 +#define au_ig_fset(flags, name) \
18656 + do { (flags) |= AuIG_##name; } while (0)
18657 +#define au_ig_fclr(flags, name) \
18658 + do { (flags) &= ~AuIG_##name; } while (0)
18661 + spinlock_t ig_spin;
18662 + __u32 ig_generation, ig_flags;
18667 + struct au_iigen ii_generation;
18668 + struct super_block *ii_hsb1; /* no get/put */
18670 + struct au_rwsem ii_rwsem;
18671 + aufs_bindex_t ii_btop, ii_bbot;
18673 + struct au_hinode *ii_hinode;
18674 + struct au_vdir *ii_vdir;
18677 +struct au_icntnr {
18678 + struct au_iinfo iinfo;
18679 + struct inode vfs_inode;
18680 + struct hlist_bl_node plink;
18681 + struct rcu_head rcu;
18682 +} ____cacheline_aligned_in_smp;
18684 +/* au_pin flags */
18685 +#define AuPin_DI_LOCKED 1
18686 +#define AuPin_MNT_WRITE (1 << 1)
18687 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18688 +#define au_fset_pin(flags, name) \
18689 + do { (flags) |= AuPin_##name; } while (0)
18690 +#define au_fclr_pin(flags, name) \
18691 + do { (flags) &= ~AuPin_##name; } while (0)
18695 + struct dentry *dentry;
18696 + unsigned int udba;
18697 + unsigned char lsc_di, lsc_hi, flags;
18698 + aufs_bindex_t bindex;
18701 + struct dentry *parent;
18702 + struct au_hinode *hdir;
18703 + struct vfsmount *h_mnt;
18705 + /* temporary unlock/relock for copyup */
18706 + struct dentry *h_dentry, *h_parent;
18707 + struct au_branch *br;
18708 + struct task_struct *task;
18711 +void au_pin_hdir_unlock(struct au_pin *p);
18712 +int au_pin_hdir_lock(struct au_pin *p);
18713 +int au_pin_hdir_relock(struct au_pin *p);
18714 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18715 +void au_pin_hdir_release(struct au_pin *p);
18717 +/* ---------------------------------------------------------------------- */
18719 +static inline struct au_iinfo *au_ii(struct inode *inode)
18721 + BUG_ON(is_bad_inode(inode));
18722 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18725 +/* ---------------------------------------------------------------------- */
18728 +struct inode *au_igrab(struct inode *inode);
18729 +void au_refresh_iop(struct inode *inode, int force_getattr);
18730 +int au_refresh_hinode_self(struct inode *inode);
18731 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18732 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18733 + unsigned int d_type, ino_t *ino);
18734 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18735 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18736 + struct inode *inode);
18737 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18739 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18742 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18743 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18745 +#ifdef CONFIG_AUFS_SHWH
18746 + return au_ino(sb, bindex, h_ino, d_type, ino);
18759 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18760 + aufs_iop_nogetattr[AuIop_Last];
18762 +/* au_wr_dir flags */
18763 +#define AuWrDir_ADD_ENTRY 1
18764 +#define AuWrDir_ISDIR (1 << 1)
18765 +#define AuWrDir_TMPFILE (1 << 2)
18766 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18767 +#define au_fset_wrdir(flags, name) \
18768 + do { (flags) |= AuWrDir_##name; } while (0)
18769 +#define au_fclr_wrdir(flags, name) \
18770 + do { (flags) &= ~AuWrDir_##name; } while (0)
18772 +struct au_wr_dir_args {
18773 + aufs_bindex_t force_btgt;
18774 + unsigned char flags;
18776 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18777 + struct au_wr_dir_args *args);
18779 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18780 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18781 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18782 + unsigned int udba, unsigned char flags);
18783 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18784 + unsigned int udba, unsigned char flags) __must_check;
18785 +int au_do_pin(struct au_pin *pin) __must_check;
18786 +void au_unpin(struct au_pin *pin);
18787 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18789 +#define AuIcpup_DID_CPUP 1
18790 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18791 +#define au_fset_icpup(flags, name) \
18792 + do { (flags) |= AuIcpup_##name; } while (0)
18793 +#define au_fclr_icpup(flags, name) \
18794 + do { (flags) &= ~AuIcpup_##name; } while (0)
18796 +struct au_icpup_args {
18797 + unsigned char flags;
18798 + unsigned char pin_flags;
18799 + aufs_bindex_t btgt;
18800 + unsigned int udba;
18801 + struct au_pin pin;
18802 + struct path h_path;
18803 + struct inode *h_inode;
18806 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18807 + struct au_icpup_args *a);
18809 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18810 + struct path *h_path, int locked);
18813 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18814 + struct dentry *h_parent, int isdir);
18815 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
18816 + struct dentry *dentry, umode_t mode, dev_t dev);
18817 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
18818 + struct dentry *dentry, const char *symname);
18819 +int aufs_create(struct user_namespace *userns, struct inode *dir,
18820 + struct dentry *dentry, umode_t mode, bool want_excl);
18821 +struct vfsub_aopen_args;
18822 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18823 + struct vfsub_aopen_args *args);
18824 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
18825 + struct dentry *dentry, umode_t mode);
18826 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18827 + struct dentry *dentry);
18828 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
18829 + struct dentry *dentry, umode_t mode);
18832 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18833 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18834 + struct dentry *h_parent, int isdir);
18835 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18836 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18839 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18840 +int aufs_rename(struct user_namespace *userns,
18841 + struct inode *_src_dir, struct dentry *_src_dentry,
18842 + struct inode *_dst_dir, struct dentry *_dst_dentry,
18843 + unsigned int _flags);
18846 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18847 +void au_hiput(struct au_hinode *hinode);
18848 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18849 + struct dentry *h_wh);
18850 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18852 +/* hinode flags */
18853 +#define AuHi_XINO 1
18854 +#define AuHi_HNOTIFY (1 << 1)
18855 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18856 +#define au_fset_hi(flags, name) \
18857 + do { (flags) |= AuHi_##name; } while (0)
18858 +#define au_fclr_hi(flags, name) \
18859 + do { (flags) &= ~AuHi_##name; } while (0)
18861 +#ifndef CONFIG_AUFS_HNOTIFY
18862 +#undef AuHi_HNOTIFY
18863 +#define AuHi_HNOTIFY 0
18866 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18867 + struct inode *h_inode, unsigned int flags);
18869 +void au_update_iigen(struct inode *inode, int half);
18870 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18872 +void au_icntnr_init_once(void *_c);
18873 +void au_hinode_init(struct au_hinode *hinode);
18874 +int au_iinfo_init(struct inode *inode);
18875 +void au_iinfo_fin(struct inode *inode);
18876 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18878 +#ifdef CONFIG_PROC_FS
18880 +int au_plink_maint(struct super_block *sb, int flags);
18882 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18883 +int au_plink_maint_enter(struct super_block *sb);
18884 +#ifdef CONFIG_AUFS_DEBUG
18885 +void au_plink_list(struct super_block *sb);
18887 +AuStubVoid(au_plink_list, struct super_block *sb)
18889 +int au_plink_test(struct inode *inode);
18890 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18891 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18892 + struct dentry *h_dentry);
18893 +void au_plink_put(struct super_block *sb, int verbose);
18894 +void au_plink_clean(struct super_block *sb, int verbose);
18895 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18897 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18898 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18899 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18900 +AuStubVoid(au_plink_list, struct super_block *sb);
18901 +AuStubInt0(au_plink_test, struct inode *inode);
18902 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18903 + struct inode *inode, aufs_bindex_t bindex);
18904 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18905 + struct dentry *h_dentry);
18906 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18907 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18908 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18909 +#endif /* CONFIG_PROC_FS */
18911 +#ifdef CONFIG_AUFS_XATTR
18913 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
18914 + unsigned int verbose);
18915 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18916 +void au_xattr_init(struct super_block *sb);
18918 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
18919 + int ignore_flags, unsigned int verbose);
18920 +AuStubVoid(au_xattr_init, struct super_block *sb);
18923 +#ifdef CONFIG_FS_POSIX_ACL
18924 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18925 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
18926 + struct posix_acl *acl, int type);
18929 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18935 +struct au_sxattr {
18939 + const char *name;
18940 + const void *value;
18945 + struct posix_acl *acl;
18950 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18951 + struct au_sxattr *arg);
18954 +/* ---------------------------------------------------------------------- */
18956 +/* lock subclass for iinfo */
18958 + AuLsc_II_CHILD, /* child first */
18959 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18960 + AuLsc_II_CHILD3, /* copyup dirs */
18961 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18962 + AuLsc_II_PARENT2,
18963 + AuLsc_II_PARENT3, /* copyup dirs */
18964 + AuLsc_II_NEW_CHILD
18968 + * ii_read_lock_child, ii_write_lock_child,
18969 + * ii_read_lock_child2, ii_write_lock_child2,
18970 + * ii_read_lock_child3, ii_write_lock_child3,
18971 + * ii_read_lock_parent, ii_write_lock_parent,
18972 + * ii_read_lock_parent2, ii_write_lock_parent2,
18973 + * ii_read_lock_parent3, ii_write_lock_parent3,
18974 + * ii_read_lock_new_child, ii_write_lock_new_child,
18976 +#define AuReadLockFunc(name, lsc) \
18977 +static inline void ii_read_lock_##name(struct inode *i) \
18979 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18982 +#define AuWriteLockFunc(name, lsc) \
18983 +static inline void ii_write_lock_##name(struct inode *i) \
18985 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18988 +#define AuRWLockFuncs(name, lsc) \
18989 + AuReadLockFunc(name, lsc) \
18990 + AuWriteLockFunc(name, lsc)
18992 +AuRWLockFuncs(child, CHILD);
18993 +AuRWLockFuncs(child2, CHILD2);
18994 +AuRWLockFuncs(child3, CHILD3);
18995 +AuRWLockFuncs(parent, PARENT);
18996 +AuRWLockFuncs(parent2, PARENT2);
18997 +AuRWLockFuncs(parent3, PARENT3);
18998 +AuRWLockFuncs(new_child, NEW_CHILD);
19000 +#undef AuReadLockFunc
19001 +#undef AuWriteLockFunc
19002 +#undef AuRWLockFuncs
19004 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19005 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19006 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19008 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19009 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19010 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19012 +/* ---------------------------------------------------------------------- */
19014 +static inline void au_icntnr_init(struct au_icntnr *c)
19016 +#ifdef CONFIG_AUFS_DEBUG
19017 + c->vfs_inode.i_mode = 0;
19021 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19023 + unsigned int gen;
19024 + struct au_iinfo *iinfo;
19025 + struct au_iigen *iigen;
19027 + iinfo = au_ii(inode);
19028 + iigen = &iinfo->ii_generation;
19029 + spin_lock(&iigen->ig_spin);
19031 + *igflags = iigen->ig_flags;
19032 + gen = iigen->ig_generation;
19033 + spin_unlock(&iigen->ig_spin);
19038 +/* tiny test for inode number */
19039 +/* tmpfs generation is too rough */
19040 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19042 + struct au_iinfo *iinfo;
19044 + iinfo = au_ii(inode);
19045 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19046 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19047 + && iinfo->ii_higen == h_inode->i_generation);
19050 +static inline void au_iigen_dec(struct inode *inode)
19052 + struct au_iinfo *iinfo;
19053 + struct au_iigen *iigen;
19055 + iinfo = au_ii(inode);
19056 + iigen = &iinfo->ii_generation;
19057 + spin_lock(&iigen->ig_spin);
19058 + iigen->ig_generation--;
19059 + spin_unlock(&iigen->ig_spin);
19062 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19067 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19073 +/* ---------------------------------------------------------------------- */
19075 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19076 + aufs_bindex_t bindex)
19078 + return iinfo->ii_hinode + bindex;
19081 +static inline int au_is_bad_inode(struct inode *inode)
19083 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19086 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19087 + aufs_bindex_t bindex)
19089 + IiMustAnyLock(inode);
19090 + return au_hinode(au_ii(inode), bindex)->hi_id;
19093 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19095 + IiMustAnyLock(inode);
19096 + return au_ii(inode)->ii_btop;
19099 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19101 + IiMustAnyLock(inode);
19102 + return au_ii(inode)->ii_bbot;
19105 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19107 + IiMustAnyLock(inode);
19108 + return au_ii(inode)->ii_vdir;
19111 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19113 + IiMustAnyLock(inode);
19114 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19117 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19119 + IiMustWriteLock(inode);
19120 + au_ii(inode)->ii_btop = bindex;
19123 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19125 + IiMustWriteLock(inode);
19126 + au_ii(inode)->ii_bbot = bindex;
19129 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19131 + IiMustWriteLock(inode);
19132 + au_ii(inode)->ii_vdir = vdir;
19135 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19137 + IiMustAnyLock(inode);
19138 + return au_hinode(au_ii(inode), bindex);
19141 +/* ---------------------------------------------------------------------- */
19143 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19146 + return pin->parent;
19150 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19152 + if (pin && pin->hdir)
19153 + return pin->hdir->hi_inode;
19157 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19160 + return pin->hdir;
19164 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19167 + pin->dentry = dentry;
19170 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19171 + unsigned char lflag)
19175 + au_fset_pin(pin->flags, DI_LOCKED);
19177 + au_fclr_pin(pin->flags, DI_LOCKED);
19181 +#if 0 /* reserved */
19182 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19185 + dput(pin->parent);
19186 + pin->parent = dget(parent);
19191 +/* ---------------------------------------------------------------------- */
19194 +#ifdef CONFIG_AUFS_HNOTIFY
19195 +struct au_hnotify_op {
19196 + void (*ctl)(struct au_hinode *hinode, int do_set);
19197 + int (*alloc)(struct au_hinode *hinode);
19200 + * if it returns true, the caller should free hinode->hi_notify,
19201 + * otherwise ->free() frees it.
19203 + int (*free)(struct au_hinode *hinode,
19204 + struct au_hnotify *hn) __must_check;
19206 + void (*fin)(void);
19207 + int (*init)(void);
19209 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19210 + void (*fin_br)(struct au_branch *br);
19211 + int (*init_br)(struct au_branch *br, int perm);
19215 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19216 +void au_hn_free(struct au_hinode *hinode);
19217 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19218 +void au_hn_reset(struct inode *inode, unsigned int flags);
19219 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19220 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19221 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19222 +int au_hnotify_init_br(struct au_branch *br, int perm);
19223 +void au_hnotify_fin_br(struct au_branch *br);
19224 +int __init au_hnotify_init(void);
19225 +void au_hnotify_fin(void);
19228 +extern const struct au_hnotify_op au_hnotify_op;
19231 +void au_hn_init(struct au_hinode *hinode)
19233 + hinode->hi_notify = NULL;
19236 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19238 + return hinode->hi_notify;
19242 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19243 + struct au_hinode *hinode __maybe_unused,
19244 + struct inode *inode __maybe_unused)
19245 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19246 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19247 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19248 + int do_set __maybe_unused)
19249 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19250 + unsigned int flags __maybe_unused)
19251 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19252 + struct au_branch *br __maybe_unused,
19253 + int perm __maybe_unused)
19254 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19255 + int perm __maybe_unused)
19256 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19257 +AuStubInt0(__init au_hnotify_init, void)
19258 +AuStubVoid(au_hnotify_fin, void)
19259 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19260 +#endif /* CONFIG_AUFS_HNOTIFY */
19262 +static inline void au_hn_suspend(struct au_hinode *hdir)
19264 + au_hn_ctl(hdir, /*do_set*/0);
19267 +static inline void au_hn_resume(struct au_hinode *hdir)
19269 + au_hn_ctl(hdir, /*do_set*/1);
19272 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19274 + inode_lock(hdir->hi_inode);
19275 + au_hn_suspend(hdir);
19278 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19279 + unsigned int sc __maybe_unused)
19281 + inode_lock_nested(hdir->hi_inode, sc);
19282 + au_hn_suspend(hdir);
19285 +#if 0 /* unused */
19286 +#include "vfsub.h"
19287 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19290 + inode_lock_shared_nested(hdir->hi_inode, sc);
19291 + au_hn_suspend(hdir);
19295 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19297 + au_hn_resume(hdir);
19298 + inode_unlock(hdir->hi_inode);
19301 +#endif /* __KERNEL__ */
19302 +#endif /* __AUFS_INODE_H__ */
19303 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19304 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19305 +++ linux/fs/aufs/ioctl.c 2021-05-02 20:15:14.673337458 +0200
19307 +// SPDX-License-Identifier: GPL-2.0
19309 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19311 + * This program, aufs is free software; you can redistribute it and/or modify
19312 + * it under the terms of the GNU General Public License as published by
19313 + * the Free Software Foundation; either version 2 of the License, or
19314 + * (at your option) any later version.
19316 + * This program is distributed in the hope that it will be useful,
19317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19319 + * GNU General Public License for more details.
19321 + * You should have received a copy of the GNU General Public License
19322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19327 + * plink-management and readdir in userspace.
19328 + * assist the pathconf(3) wrapper library.
19330 + * File-based Hierarchical Storage Management.
19333 +#include <linux/compat.h>
19334 +#include <linux/file.h>
19337 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19340 + aufs_bindex_t wbi, bindex, bbot;
19341 + struct file *h_file;
19342 + struct super_block *sb;
19343 + struct dentry *root;
19344 + struct au_branch *br;
19345 + struct aufs_wbr_fd wbrfd = {
19346 + .oflags = au_dir_roflags,
19349 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19350 + | O_NOATIME | O_CLOEXEC;
19352 + AuDebugOn(wbrfd.oflags & ~valid);
19355 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19356 + if (unlikely(err)) {
19362 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19363 + wbrfd.oflags |= au_dir_roflags;
19364 + AuDbg("0%o\n", wbrfd.oflags);
19365 + if (unlikely(wbrfd.oflags & ~valid))
19369 + fd = get_unused_fd_flags(0);
19371 + if (unlikely(fd < 0))
19374 + h_file = ERR_PTR(-EINVAL);
19377 + sb = path->dentry->d_sb;
19378 + root = sb->s_root;
19379 + aufs_read_lock(root, AuLock_IR);
19380 + bbot = au_sbbot(sb);
19381 + if (wbrfd.brid >= 0) {
19382 + wbi = au_br_index(sb, wbrfd.brid);
19383 + if (unlikely(wbi < 0 || wbi > bbot))
19387 + h_file = ERR_PTR(-ENOENT);
19388 + br = au_sbr(sb, wbi);
19389 + if (!au_br_writable(br->br_perm)) {
19393 + bindex = wbi + 1;
19395 + for (; bindex <= bbot; bindex++) {
19396 + br = au_sbr(sb, bindex);
19397 + if (au_br_writable(br->br_perm)) {
19399 + br = au_sbr(sb, wbi);
19404 + AuDbg("wbi %d\n", wbi);
19406 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19410 + aufs_read_unlock(root, AuLock_IR);
19411 + err = PTR_ERR(h_file);
19412 + if (IS_ERR(h_file))
19415 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19416 + fd_install(fd, h_file);
19418 + goto out; /* success */
19421 + put_unused_fd(fd);
19427 +/* ---------------------------------------------------------------------- */
19429 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19432 + struct dentry *dentry;
19435 + case AUFS_CTL_RDU:
19436 + case AUFS_CTL_RDU_INO:
19437 + err = au_rdu_ioctl(file, cmd, arg);
19440 + case AUFS_CTL_WBR_FD:
19441 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19444 + case AUFS_CTL_IBUSY:
19445 + err = au_ibusy_ioctl(file, arg);
19448 + case AUFS_CTL_BRINFO:
19449 + err = au_brinfo_ioctl(file, arg);
19452 + case AUFS_CTL_FHSM_FD:
19453 + dentry = file->f_path.dentry;
19454 + if (IS_ROOT(dentry))
19455 + err = au_fhsm_fd(dentry->d_sb, arg);
19461 + /* do not call the lower */
19462 + AuDbg("0x%x\n", cmd);
19470 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19475 + case AUFS_CTL_MVDOWN:
19476 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19479 + case AUFS_CTL_WBR_FD:
19480 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19484 + /* do not call the lower */
19485 + AuDbg("0x%x\n", cmd);
19493 +#ifdef CONFIG_COMPAT
19494 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19495 + unsigned long arg)
19500 + case AUFS_CTL_RDU:
19501 + case AUFS_CTL_RDU_INO:
19502 + err = au_rdu_compat_ioctl(file, cmd, arg);
19505 + case AUFS_CTL_IBUSY:
19506 + err = au_ibusy_compat_ioctl(file, arg);
19509 + case AUFS_CTL_BRINFO:
19510 + err = au_brinfo_compat_ioctl(file, arg);
19514 + err = aufs_ioctl_dir(file, cmd, arg);
19521 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19522 + unsigned long arg)
19524 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19527 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19528 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19529 +++ linux/fs/aufs/i_op_add.c 2021-05-02 20:15:14.673337458 +0200
19531 +// SPDX-License-Identifier: GPL-2.0
19533 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19535 + * This program, aufs is free software; you can redistribute it and/or modify
19536 + * it under the terms of the GNU General Public License as published by
19537 + * the Free Software Foundation; either version 2 of the License, or
19538 + * (at your option) any later version.
19540 + * This program is distributed in the hope that it will be useful,
19541 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19542 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19543 + * GNU General Public License for more details.
19545 + * You should have received a copy of the GNU General Public License
19546 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19550 + * inode operations (add entry)
19553 +#include <linux/iversion.h>
19557 + * final procedure of adding a new entry, except link(2).
19558 + * remove whiteout, instantiate, copyup the parent dir's times and size
19559 + * and update version.
19560 + * if it failed, re-create the removed whiteout.
19562 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19563 + struct dentry *wh_dentry, struct dentry *dentry)
19566 + aufs_bindex_t bwh;
19567 + struct path h_path;
19568 + struct super_block *sb;
19569 + struct inode *inode, *h_dir;
19570 + struct dentry *wh;
19575 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19576 + IMustLock(h_dir);
19577 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19578 + bwh = au_dbwh(dentry);
19579 + h_path.dentry = wh_dentry;
19580 + h_path.mnt = au_sbr_mnt(sb, bindex);
19581 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19583 + if (unlikely(err))
19587 + inode = au_new_inode(dentry, /*must_new*/1);
19588 + if (!IS_ERR(inode)) {
19589 + d_instantiate(dentry, inode);
19590 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19592 + au_dir_ts(dir, bindex);
19593 + inode_inc_iversion(dir);
19594 + au_fhsm_wrote(sb, bindex, /*force*/0);
19595 + return 0; /* success */
19598 + err = PTR_ERR(inode);
19603 + /* dir inode is locked */
19604 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19605 + rerr = PTR_ERR(wh);
19606 + if (IS_ERR(wh)) {
19607 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19608 + dentry, err, rerr);
19617 +static int au_d_may_add(struct dentry *dentry)
19622 + if (unlikely(d_unhashed(dentry)))
19624 + if (unlikely(d_really_is_positive(dentry)))
19630 + * simple tests for the adding inode operations.
19631 + * following the checks in vfs, plus the parent-child relationship.
19633 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19634 + struct dentry *h_parent, int isdir)
19638 + struct dentry *h_dentry;
19639 + struct inode *h_inode;
19641 + err = -ENAMETOOLONG;
19642 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19645 + h_dentry = au_h_dptr(dentry, bindex);
19646 + if (d_really_is_negative(dentry)) {
19648 + if (unlikely(d_is_positive(h_dentry)))
19651 + /* rename(2) case */
19653 + if (unlikely(d_is_negative(h_dentry)))
19655 + h_inode = d_inode(h_dentry);
19656 + if (unlikely(!h_inode->i_nlink))
19659 + h_mode = h_inode->i_mode;
19662 + if (unlikely(S_ISDIR(h_mode)))
19664 + } else if (unlikely(!S_ISDIR(h_mode))) {
19671 + /* expected parent dir is locked */
19672 + if (unlikely(h_parent != h_dentry->d_parent))
19681 + * initial procedure of adding a new entry.
19682 + * prepare writable branch and the parent dir, lock it,
19683 + * and lookup whiteout for the new entry.
19685 +static struct dentry*
19686 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19687 + struct dentry *src_dentry, struct au_pin *pin,
19688 + struct au_wr_dir_args *wr_dir_args)
19690 + struct dentry *wh_dentry, *h_parent;
19691 + struct super_block *sb;
19692 + struct au_branch *br;
19694 + unsigned int udba;
19695 + aufs_bindex_t bcpup;
19697 + AuDbg("%pd\n", dentry);
19699 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19701 + wh_dentry = ERR_PTR(err);
19702 + if (unlikely(err < 0))
19705 + sb = dentry->d_sb;
19706 + udba = au_opt_udba(sb);
19707 + err = au_pin(pin, dentry, bcpup, udba,
19708 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19709 + wh_dentry = ERR_PTR(err);
19710 + if (unlikely(err))
19713 + h_parent = au_pinned_h_parent(pin);
19714 + if (udba != AuOpt_UDBA_NONE
19715 + && au_dbtop(dentry) == bcpup)
19716 + err = au_may_add(dentry, bcpup, h_parent,
19717 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19718 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19719 + err = -ENAMETOOLONG;
19720 + wh_dentry = ERR_PTR(err);
19721 + if (unlikely(err))
19724 + br = au_sbr(sb, bcpup);
19726 + struct path tmp = {
19727 + .dentry = h_parent,
19728 + .mnt = au_br_mnt(br)
19730 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19733 + wh_dentry = NULL;
19734 + if (bcpup != au_dbwh(dentry))
19735 + goto out; /* success */
19738 + * ENAMETOOLONG here means that if we allowed create such name, then it
19739 + * would not be able to removed in the future. So we don't allow such
19740 + * name here and we don't handle ENAMETOOLONG differently here.
19742 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19745 + if (IS_ERR(wh_dentry))
19748 + return wh_dentry;
19751 +/* ---------------------------------------------------------------------- */
19753 +enum { Mknod, Symlink, Creat };
19754 +struct simple_arg {
19761 + struct vfsub_aopen_args *aopen;
19764 + const char *symname;
19773 +static int add_simple(struct inode *dir, struct dentry *dentry,
19774 + struct simple_arg *arg)
19777 + aufs_bindex_t btop;
19778 + unsigned char created;
19779 + const unsigned char try_aopen
19780 + = (arg->type == Creat && arg->u.c.try_aopen);
19781 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19782 + struct dentry *wh_dentry, *parent;
19783 + struct inode *h_dir;
19784 + struct super_block *sb;
19785 + struct au_branch *br;
19786 + /* to reduce stack size */
19788 + struct au_dtime dt;
19789 + struct au_pin pin;
19790 + struct path h_path;
19791 + struct au_wr_dir_args wr_dir_args;
19794 + AuDbg("%pd\n", dentry);
19798 + a = kmalloc(sizeof(*a), GFP_NOFS);
19799 + if (unlikely(!a))
19801 + a->wr_dir_args.force_btgt = -1;
19802 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19804 + parent = dentry->d_parent; /* dir inode is locked */
19805 + if (!try_aopen) {
19806 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19807 + if (unlikely(err))
19810 + err = au_d_may_add(dentry);
19811 + if (unlikely(err))
19814 + di_write_lock_parent(parent);
19815 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19816 + &a->pin, &a->wr_dir_args);
19817 + err = PTR_ERR(wh_dentry);
19818 + if (IS_ERR(wh_dentry))
19821 + btop = au_dbtop(dentry);
19822 + sb = dentry->d_sb;
19823 + br = au_sbr(sb, btop);
19824 + a->h_path.dentry = au_h_dptr(dentry, btop);
19825 + a->h_path.mnt = au_br_mnt(br);
19826 + h_dir = au_pinned_h_dir(&a->pin);
19827 + switch (arg->type) {
19829 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19830 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19831 + arg->u.c.want_excl);
19833 + if (!err && try_aopen)
19834 + aopen->file->f_mode |= FMODE_CREATED;
19837 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19838 + AuDbg("err %d\n", err);
19839 + AuDbgFile(aopen->file);
19840 + created = err >= 0
19841 + && !!(aopen->file->f_mode & FMODE_CREATED);
19845 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19849 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19856 + if (unlikely(err < 0))
19859 + err = epilog(dir, btop, wh_dentry, dentry);
19861 + goto out_unpin; /* success */
19864 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19865 + /* no delegation since it is just created */
19866 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19869 + AuIOErr("%pd revert failure(%d, %d)\n",
19870 + dentry, err, rerr);
19873 + au_dtime_revert(&a->dt);
19875 + if (try_aopen && h_dir->i_op->atomic_open
19876 + && (aopen->file->f_mode & FMODE_OPENED))
19877 + /* aopen->file is still opened */
19878 + au_lcnt_dec(&aopen->br->br_nfiles);
19881 + au_unpin(&a->pin);
19885 + di_write_unlock(parent);
19887 + if (unlikely(err)) {
19888 + au_update_dbtop(dentry);
19892 + aufs_read_unlock(dentry, AuLock_DW);
19899 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
19900 + struct dentry *dentry, umode_t mode, dev_t dev)
19902 + struct simple_arg arg = {
19909 + return add_simple(dir, dentry, &arg);
19912 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
19913 + struct dentry *dentry, const char *symname)
19915 + struct simple_arg arg = {
19917 + .u.s.symname = symname
19919 + return add_simple(dir, dentry, &arg);
19922 +int aufs_create(struct user_namespace *userns, struct inode *dir,
19923 + struct dentry *dentry, umode_t mode, bool want_excl)
19925 + struct simple_arg arg = {
19929 + .want_excl = want_excl
19932 + return add_simple(dir, dentry, &arg);
19935 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19936 + struct vfsub_aopen_args *aopen_args)
19938 + struct simple_arg arg = {
19941 + .mode = aopen_args->create_mode,
19942 + .want_excl = aopen_args->open_flag & O_EXCL,
19943 + .try_aopen = true,
19944 + .aopen = aopen_args
19947 + return add_simple(dir, dentry, &arg);
19950 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
19951 + struct dentry *dentry, umode_t mode)
19954 + aufs_bindex_t bindex;
19955 + struct super_block *sb;
19956 + struct dentry *parent, *h_parent, *h_dentry;
19957 + struct inode *h_dir, *inode;
19958 + struct vfsmount *h_mnt;
19959 + struct user_namespace *h_userns;
19960 + struct au_wr_dir_args wr_dir_args = {
19961 + .force_btgt = -1,
19962 + .flags = AuWrDir_TMPFILE
19965 + /* copy-up may happen */
19969 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19970 + if (unlikely(err))
19973 + err = au_di_init(dentry);
19974 + if (unlikely(err))
19978 + parent = d_find_any_alias(dir);
19979 + AuDebugOn(!parent);
19980 + di_write_lock_parent(parent);
19981 + if (unlikely(d_inode(parent) != dir))
19984 + err = au_digen_test(parent, au_sigen(sb));
19985 + if (unlikely(err))
19988 + bindex = au_dbtop(parent);
19989 + au_set_dbtop(dentry, bindex);
19990 + au_set_dbbot(dentry, bindex);
19991 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19993 + if (unlikely(err < 0))
19996 + err = -EOPNOTSUPP;
19997 + h_dir = au_h_iptr(dir, bindex);
19998 + if (unlikely(!h_dir->i_op->tmpfile))
20001 + h_mnt = au_sbr_mnt(sb, bindex);
20002 + err = vfsub_mnt_want_write(h_mnt);
20003 + if (unlikely(err))
20006 + h_userns = mnt_user_ns(h_mnt);
20007 + h_parent = au_h_dptr(parent, bindex);
20008 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
20009 + if (IS_ERR(h_dentry)) {
20010 + err = PTR_ERR(h_dentry);
20014 + au_set_dbtop(dentry, bindex);
20015 + au_set_dbbot(dentry, bindex);
20016 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20017 + inode = au_new_inode(dentry, /*must_new*/1);
20018 + if (IS_ERR(inode)) {
20019 + err = PTR_ERR(inode);
20020 + au_set_h_dptr(dentry, bindex, NULL);
20021 + au_set_dbtop(dentry, -1);
20022 + au_set_dbbot(dentry, -1);
20024 + if (!inode->i_nlink)
20025 + set_nlink(inode, 1);
20026 + d_tmpfile(dentry, inode);
20027 + au_di(dentry)->di_tmpfile = 1;
20029 + /* update without i_mutex */
20030 + if (au_ibtop(dir) == au_dbtop(dentry))
20031 + au_cpup_attr_timesizes(dir);
20036 + vfsub_mnt_drop_write(h_mnt);
20038 + di_write_unlock(parent);
20040 + di_write_unlock(dentry);
20041 + if (unlikely(err)) {
20042 + au_di_fin(dentry);
20043 + dentry->d_fsdata = NULL;
20046 + si_read_unlock(sb);
20048 + inode_unlock(dir);
20052 +/* ---------------------------------------------------------------------- */
20054 +struct au_link_args {
20055 + aufs_bindex_t bdst, bsrc;
20056 + struct au_pin pin;
20057 + struct path h_path;
20058 + struct dentry *src_parent, *parent;
20061 +static int au_cpup_before_link(struct dentry *src_dentry,
20062 + struct au_link_args *a)
20065 + struct dentry *h_src_dentry;
20066 + struct au_cp_generic cpg = {
20067 + .dentry = src_dentry,
20072 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20075 + di_read_lock_parent(a->src_parent, AuLock_IR);
20076 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20077 + if (unlikely(err))
20080 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20081 + err = au_pin(&a->pin, src_dentry, a->bdst,
20082 + au_opt_udba(src_dentry->d_sb),
20083 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20084 + if (unlikely(err))
20087 + err = au_sio_cpup_simple(&cpg);
20088 + au_unpin(&a->pin);
20091 + di_read_unlock(a->src_parent, AuLock_IR);
20095 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20096 + struct au_link_args *a)
20099 + unsigned char plink;
20100 + aufs_bindex_t bbot;
20101 + struct dentry *h_src_dentry;
20102 + struct inode *h_inode, *inode, *delegated;
20103 + struct super_block *sb;
20104 + struct file *h_file;
20108 + sb = src_dentry->d_sb;
20109 + inode = d_inode(src_dentry);
20110 + if (au_ibtop(inode) <= a->bdst)
20111 + h_inode = au_h_iptr(inode, a->bdst);
20112 + if (!h_inode || !h_inode->i_nlink) {
20113 + /* copyup src_dentry as the name of dentry. */
20114 + bbot = au_dbbot(dentry);
20115 + if (bbot < a->bsrc)
20116 + au_set_dbbot(dentry, a->bsrc);
20117 + au_set_h_dptr(dentry, a->bsrc,
20118 + dget(au_h_dptr(src_dentry, a->bsrc)));
20119 + dget(a->h_path.dentry);
20120 + au_set_h_dptr(dentry, a->bdst, NULL);
20121 + AuDbg("temporary d_inode...\n");
20122 + spin_lock(&dentry->d_lock);
20123 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20124 + spin_unlock(&dentry->d_lock);
20125 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20126 + if (IS_ERR(h_file))
20127 + err = PTR_ERR(h_file);
20129 + struct au_cp_generic cpg = {
20130 + .dentry = dentry,
20135 + .flags = AuCpup_KEEPLINO
20137 + err = au_sio_cpup_simple(&cpg);
20138 + au_h_open_post(dentry, a->bsrc, h_file);
20140 + dput(a->h_path.dentry);
20141 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20143 + au_set_h_dptr(dentry, a->bdst,
20144 + a->h_path.dentry);
20146 + spin_lock(&dentry->d_lock);
20147 + dentry->d_inode = NULL; /* restore */
20148 + spin_unlock(&dentry->d_lock);
20149 + AuDbg("temporary d_inode...done\n");
20150 + au_set_h_dptr(dentry, a->bsrc, NULL);
20151 + au_set_dbbot(dentry, bbot);
20153 + /* the inode of src_dentry already exists on a.bdst branch */
20154 + h_src_dentry = d_find_alias(h_inode);
20155 + if (!h_src_dentry && au_plink_test(inode)) {
20157 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20158 + err = PTR_ERR(h_src_dentry);
20159 + if (IS_ERR(h_src_dentry))
20162 + if (unlikely(d_is_negative(h_src_dentry))) {
20163 + dput(h_src_dentry);
20164 + h_src_dentry = NULL;
20168 + if (h_src_dentry) {
20169 + delegated = NULL;
20170 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20171 + &a->h_path, &delegated);
20172 + if (unlikely(err == -EWOULDBLOCK)) {
20173 + pr_warn("cannot retry for NFSv4 delegation"
20174 + " for an internal link\n");
20177 + dput(h_src_dentry);
20179 + AuIOErr("no dentry found for hi%lu on b%d\n",
20180 + h_inode->i_ino, a->bdst);
20185 + if (!err && !plink)
20186 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20193 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20194 + struct dentry *dentry)
20197 + struct au_dtime dt;
20198 + struct au_link_args *a;
20199 + struct dentry *wh_dentry, *h_src_dentry;
20200 + struct inode *inode, *delegated;
20201 + struct super_block *sb;
20202 + struct au_wr_dir_args wr_dir_args = {
20203 + /* .force_btgt = -1, */
20204 + .flags = AuWrDir_ADD_ENTRY
20208 + inode = d_inode(src_dentry);
20209 + IMustLock(inode);
20212 + a = kzalloc(sizeof(*a), GFP_NOFS);
20213 + if (unlikely(!a))
20216 + a->parent = dentry->d_parent; /* dir inode is locked */
20217 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20218 + AuLock_NOPLM | AuLock_GEN);
20219 + if (unlikely(err))
20221 + err = au_d_linkable(src_dentry);
20222 + if (unlikely(err))
20224 + err = au_d_may_add(dentry);
20225 + if (unlikely(err))
20228 + a->src_parent = dget_parent(src_dentry);
20229 + wr_dir_args.force_btgt = au_ibtop(inode);
20231 + di_write_lock_parent(a->parent);
20232 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20233 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20235 + err = PTR_ERR(wh_dentry);
20236 + if (IS_ERR(wh_dentry))
20240 + sb = dentry->d_sb;
20241 + a->bdst = au_dbtop(dentry);
20242 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20243 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20244 + a->bsrc = au_ibtop(inode);
20245 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20246 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20247 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20248 + if (!h_src_dentry) {
20249 + a->bsrc = au_dbtop(src_dentry);
20250 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20251 + AuDebugOn(!h_src_dentry);
20252 + } else if (IS_ERR(h_src_dentry)) {
20253 + err = PTR_ERR(h_src_dentry);
20258 + * aufs doesn't touch the credential so
20259 + * security_dentry_create_files_as() is unnecessary.
20261 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20262 + if (a->bdst < a->bsrc
20263 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20264 + err = au_cpup_or_link(src_dentry, dentry, a);
20266 + delegated = NULL;
20267 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20268 + &a->h_path, &delegated);
20269 + if (unlikely(err == -EWOULDBLOCK)) {
20270 + pr_warn("cannot retry for NFSv4 delegation"
20271 + " for an internal link\n");
20275 + dput(h_src_dentry);
20278 + * copyup src_dentry to the branch we process,
20279 + * and then link(2) to it.
20281 + dput(h_src_dentry);
20282 + if (a->bdst < a->bsrc
20283 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20284 + au_unpin(&a->pin);
20285 + di_write_unlock(a->parent);
20286 + err = au_cpup_before_link(src_dentry, a);
20287 + di_write_lock_parent(a->parent);
20289 + err = au_pin(&a->pin, dentry, a->bdst,
20291 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20292 + if (unlikely(err))
20296 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20298 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20299 + delegated = NULL;
20300 + err = vfsub_link(h_src_dentry,
20301 + au_pinned_h_dir(&a->pin),
20302 + &a->h_path, &delegated);
20303 + if (unlikely(err == -EWOULDBLOCK)) {
20304 + pr_warn("cannot retry"
20305 + " for NFSv4 delegation"
20306 + " for an internal link\n");
20312 + if (unlikely(err))
20316 + a->h_path.dentry = wh_dentry;
20317 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20319 + if (unlikely(err))
20323 + au_dir_ts(dir, a->bdst);
20324 + inode_inc_iversion(dir);
20325 + inc_nlink(inode);
20326 + inode->i_ctime = dir->i_ctime;
20327 + d_instantiate(dentry, au_igrab(inode));
20328 + if (d_unhashed(a->h_path.dentry))
20329 + /* some filesystem calls d_drop() */
20331 + /* some filesystems consume an inode even hardlink */
20332 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20333 + goto out_unpin; /* success */
20336 + /* no delegation since it is just created */
20337 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20338 + /*delegated*/NULL, /*force*/0);
20339 + if (unlikely(rerr)) {
20340 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20343 + au_dtime_revert(&dt);
20345 + au_unpin(&a->pin);
20349 + di_write_unlock(a->parent);
20350 + dput(a->src_parent);
20352 + if (unlikely(err)) {
20353 + au_update_dbtop(dentry);
20356 + aufs_read_and_write_unlock2(dentry, src_dentry);
20364 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20365 + struct dentry *dentry, umode_t mode)
20368 + aufs_bindex_t bindex;
20369 + unsigned char diropq;
20370 + struct path h_path;
20371 + struct dentry *wh_dentry, *parent, *opq_dentry;
20372 + struct inode *h_inode;
20373 + struct super_block *sb;
20375 + struct au_pin pin;
20376 + struct au_dtime dt;
20377 + } *a; /* reduce the stack usage */
20378 + struct au_wr_dir_args wr_dir_args = {
20379 + .force_btgt = -1,
20380 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20386 + a = kmalloc(sizeof(*a), GFP_NOFS);
20387 + if (unlikely(!a))
20390 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20391 + if (unlikely(err))
20393 + err = au_d_may_add(dentry);
20394 + if (unlikely(err))
20397 + parent = dentry->d_parent; /* dir inode is locked */
20398 + di_write_lock_parent(parent);
20399 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20400 + &a->pin, &wr_dir_args);
20401 + err = PTR_ERR(wh_dentry);
20402 + if (IS_ERR(wh_dentry))
20405 + sb = dentry->d_sb;
20406 + bindex = au_dbtop(dentry);
20407 + h_path.dentry = au_h_dptr(dentry, bindex);
20408 + h_path.mnt = au_sbr_mnt(sb, bindex);
20409 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20410 + if (unlikely(err))
20413 + /* make the dir opaque */
20415 + h_inode = d_inode(h_path.dentry);
20417 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20418 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20419 + opq_dentry = au_diropq_create(dentry, bindex);
20420 + inode_unlock(h_inode);
20421 + err = PTR_ERR(opq_dentry);
20422 + if (IS_ERR(opq_dentry))
20424 + dput(opq_dentry);
20428 + err = epilog(dir, bindex, wh_dentry, dentry);
20431 + goto out_unpin; /* success */
20436 + AuLabel(revert opq);
20437 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20438 + rerr = au_diropq_remove(dentry, bindex);
20439 + inode_unlock(h_inode);
20441 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20442 + dentry, err, rerr);
20448 + AuLabel(revert dir);
20449 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20451 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20452 + dentry, err, rerr);
20455 + au_dtime_revert(&a->dt);
20457 + au_unpin(&a->pin);
20460 + di_write_unlock(parent);
20462 + if (unlikely(err)) {
20463 + au_update_dbtop(dentry);
20466 + aufs_read_unlock(dentry, AuLock_DW);
20472 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20473 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20474 +++ linux/fs/aufs/i_op.c 2021-05-02 20:15:14.673337458 +0200
20476 +// SPDX-License-Identifier: GPL-2.0
20478 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20480 + * This program, aufs is free software; you can redistribute it and/or modify
20481 + * it under the terms of the GNU General Public License as published by
20482 + * the Free Software Foundation; either version 2 of the License, or
20483 + * (at your option) any later version.
20485 + * This program is distributed in the hope that it will be useful,
20486 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20487 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20488 + * GNU General Public License for more details.
20490 + * You should have received a copy of the GNU General Public License
20491 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20495 + * inode operations (except add/del/rename)
20498 +#include <linux/device_cgroup.h>
20499 +#include <linux/fs_stack.h>
20500 +#include <linux/iversion.h>
20501 +#include <linux/namei.h>
20502 +#include <linux/security.h>
20505 +static int h_permission(struct inode *h_inode, int mask,
20506 + struct path *h_path, int brperm)
20509 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20510 + struct user_namespace *h_userns;
20513 + if (write_mask && IS_IMMUTABLE(h_inode))
20517 + if (((mask & MAY_EXEC)
20518 + && S_ISREG(h_inode->i_mode)
20519 + && (path_noexec(h_path)
20520 + || !(h_inode->i_mode & 0111))))
20524 + * - skip the lower fs test in the case of write to ro branch.
20525 + * - nfs dir permission write check is optimized, but a policy for
20526 + * link/rename requires a real check.
20527 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20528 + * in this case, generic_permission() returns -EOPNOTSUPP.
20530 + h_userns = mnt_user_ns(h_path->mnt);
20531 + if ((write_mask && !au_br_writable(brperm))
20532 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20533 + && write_mask && !(mask & MAY_READ))
20534 + || !h_inode->i_op->permission) {
20535 + /* AuLabel(generic_permission); */
20536 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20537 + err = generic_permission(h_userns, h_inode, mask);
20538 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20539 + err = h_inode->i_op->permission(h_userns, h_inode,
20543 + /* AuLabel(h_inode->permission); */
20544 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
20549 + err = devcgroup_inode_permission(h_inode, mask);
20551 + err = security_inode_permission(h_inode, mask);
20557 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
20561 + aufs_bindex_t bindex, bbot;
20562 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20563 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20564 + struct inode *h_inode;
20565 + struct super_block *sb;
20566 + struct au_branch *br;
20568 + /* todo: support rcu-walk? */
20569 + if (mask & MAY_NOT_BLOCK)
20572 + sb = inode->i_sb;
20573 + si_read_lock(sb, AuLock_FLUSH);
20574 + ii_read_lock_child(inode);
20575 +#if 0 /* reserved for future use */
20577 + * This test may be rather 'too much' since the test is essentially done
20578 + * in the aufs_lookup(). Theoretically it is possible that the inode
20579 + * generation doesn't match to the superblock's here. But it isn't a
20580 + * big deal I suppose.
20582 + err = au_iigen_test(inode, au_sigen(sb));
20583 + if (unlikely(err))
20589 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20590 + err = au_busy_or_stale();
20591 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20592 + if (unlikely(!h_inode
20593 + || (h_inode->i_mode & S_IFMT)
20594 + != (inode->i_mode & S_IFMT)))
20598 + bindex = au_ibtop(inode);
20599 + br = au_sbr(sb, bindex);
20600 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20603 + && !special_file(h_inode->i_mode)) {
20604 + /* test whether the upper writable branch exists */
20606 + for (; bindex >= 0; bindex--)
20607 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20615 + /* non-write to dir */
20617 + bbot = au_ibbot(inode);
20618 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20619 + h_inode = au_h_iptr(inode, bindex);
20621 + err = au_busy_or_stale();
20622 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20625 + br = au_sbr(sb, bindex);
20626 + err = h_permission(h_inode, mask, &br->br_path,
20632 + ii_read_unlock(inode);
20633 + si_read_unlock(sb);
20637 +/* ---------------------------------------------------------------------- */
20639 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20640 + unsigned int flags)
20642 + struct dentry *ret, *parent;
20643 + struct inode *inode;
20644 + struct super_block *sb;
20645 + int err, npositive;
20649 + /* todo: support rcu-walk? */
20650 + ret = ERR_PTR(-ECHILD);
20651 + if (flags & LOOKUP_RCU)
20654 + ret = ERR_PTR(-ENAMETOOLONG);
20655 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20659 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20660 + ret = ERR_PTR(err);
20661 + if (unlikely(err))
20664 + err = au_di_init(dentry);
20665 + ret = ERR_PTR(err);
20666 + if (unlikely(err))
20670 + npositive = 0; /* suppress a warning */
20671 + parent = dentry->d_parent; /* dir inode is locked */
20672 + di_read_lock_parent(parent, AuLock_IR);
20673 + err = au_alive_dir(parent);
20675 + err = au_digen_test(parent, au_sigen(sb));
20677 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20678 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20679 + AuLkup_ALLOW_NEG);
20682 + di_read_unlock(parent, AuLock_IR);
20683 + ret = ERR_PTR(err);
20684 + if (unlikely(err < 0))
20688 + inode = au_new_inode(dentry, /*must_new*/0);
20689 + if (IS_ERR(inode)) {
20690 + ret = (void *)inode;
20697 + atomic_inc(&inode->i_count);
20698 + ret = d_splice_alias(inode, dentry);
20699 +#if 0 /* reserved for future use */
20700 + if (unlikely(d_need_lookup(dentry))) {
20701 + spin_lock(&dentry->d_lock);
20702 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20703 + spin_unlock(&dentry->d_lock);
20707 + if (!IS_ERR(ret)) {
20709 + if (ret && ret != dentry)
20710 + ii_write_unlock(inode);
20712 + ii_write_unlock(inode);
20719 + di_write_unlock(dentry);
20721 + si_read_unlock(sb);
20726 +/* ---------------------------------------------------------------------- */
20729 + * very dirty and complicated aufs ->atomic_open().
20730 + * aufs_atomic_open()
20731 + * + au_aopen_or_create()
20733 + * + vfsub_atomic_open()
20734 + * + branch fs ->atomic_open()
20735 + * may call the actual 'open' for h_file
20736 + * + inc br_nfiles only if opened
20737 + * + au_aopen_no_open() or au_aopen_do_open()
20739 + * au_aopen_do_open()
20740 + * + finish_open()
20741 + * + au_do_aopen()
20742 + * + au_do_open() the body of all 'open'
20743 + * + au_do_open_nondir()
20744 + * set the passed h_file
20746 + * au_aopen_no_open()
20747 + * + finish_no_open()
20750 +struct aopen_node {
20751 + struct hlist_bl_node hblist;
20752 + struct file *file, *h_file;
20755 +static int au_do_aopen(struct inode *inode, struct file *file)
20757 + struct hlist_bl_head *aopen;
20758 + struct hlist_bl_node *pos;
20759 + struct aopen_node *node;
20760 + struct au_do_open_args args = {
20762 + .open = au_do_open_nondir
20765 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20766 + hlist_bl_lock(aopen);
20767 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20768 + if (node->file == file) {
20769 + args.h_file = node->h_file;
20772 + hlist_bl_unlock(aopen);
20773 + /* AuDebugOn(!args.h_file); */
20775 + return au_do_open(file, &args);
20778 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20779 + struct aopen_node *aopen_node)
20782 + struct hlist_bl_head *aopen;
20785 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20786 + au_hbl_add(&aopen_node->hblist, aopen);
20787 + err = finish_open(file, dentry, au_do_aopen);
20788 + au_hbl_del(&aopen_node->hblist, aopen);
20789 + /* AuDbgFile(file); */
20790 + AuDbg("%pd%s%s\n", dentry,
20791 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20792 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20798 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20804 + err = finish_no_open(file, dentry);
20810 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20811 + struct file *file, unsigned int open_flag,
20812 + umode_t create_mode)
20814 + int err, did_open;
20815 + unsigned int lkup_flags;
20816 + aufs_bindex_t bindex;
20817 + struct super_block *sb;
20818 + struct dentry *parent, *d;
20819 + struct vfsub_aopen_args args = {
20820 + .open_flag = open_flag,
20821 + .create_mode = create_mode
20823 + struct aopen_node aopen_node = {
20828 + AuDbg("open_flag 0%o\n", open_flag);
20829 + AuDbgDentry(dentry);
20832 + if (!au_di(dentry)) {
20833 + lkup_flags = LOOKUP_OPEN;
20834 + if (open_flag & O_CREAT)
20835 + lkup_flags |= LOOKUP_CREATE;
20836 + d = aufs_lookup(dir, dentry, lkup_flags);
20838 + err = PTR_ERR(d);
20843 + * obsoleted dentry found.
20844 + * another error will be returned later.
20850 + AuDbgDentry(dentry);
20853 + if (d_is_positive(dentry)
20854 + || d_unhashed(dentry)
20855 + || d_unlinked(dentry)
20856 + || !(open_flag & O_CREAT)) {
20857 + err = au_aopen_no_open(file, dentry);
20858 + goto out; /* success */
20861 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20862 + if (unlikely(err))
20865 + sb = dentry->d_sb;
20866 + parent = dentry->d_parent; /* dir is locked */
20867 + di_write_lock_parent(parent);
20868 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20869 + if (unlikely(err < 0))
20872 + AuDbgDentry(dentry);
20873 + if (d_is_positive(dentry)) {
20874 + err = au_aopen_no_open(file, dentry);
20875 + goto out_parent; /* success */
20878 + args.file = alloc_empty_file(file->f_flags, current_cred());
20879 + err = PTR_ERR(args.file);
20880 + if (IS_ERR(args.file))
20883 + bindex = au_dbtop(dentry);
20884 + err = au_aopen_or_create(dir, dentry, &args);
20886 + AuDbgFile(args.file);
20887 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20888 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20891 + args.file = NULL;
20893 + di_write_unlock(parent);
20894 + di_write_unlock(dentry);
20895 + if (unlikely(err < 0)) {
20902 + err = au_aopen_no_open(file, dentry);
20904 + aopen_node.h_file = args.file;
20905 + err = au_aopen_do_open(file, dentry, &aopen_node);
20907 + if (unlikely(err < 0)) {
20911 + au_lcnt_dec(&args.br->br_nfiles);
20913 + goto out_sb; /* success */
20916 + di_write_unlock(parent);
20917 + di_write_unlock(dentry);
20919 + si_read_unlock(sb);
20927 +/* ---------------------------------------------------------------------- */
20929 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20930 + const unsigned char add_entry, aufs_bindex_t bcpup,
20931 + aufs_bindex_t btop)
20934 + struct dentry *h_parent;
20935 + struct inode *h_dir;
20938 + IMustLock(d_inode(parent));
20940 + di_write_lock_parent(parent);
20943 + if (!au_h_dptr(parent, bcpup)) {
20944 + if (btop > bcpup)
20945 + err = au_cpup_dirs(dentry, bcpup);
20946 + else if (btop < bcpup)
20947 + err = au_cpdown_dirs(dentry, bcpup);
20951 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20952 + h_parent = au_h_dptr(parent, bcpup);
20953 + h_dir = d_inode(h_parent);
20954 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20955 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20956 + /* todo: no unlock here */
20957 + inode_unlock_shared(h_dir);
20959 + AuDbg("bcpup %d\n", bcpup);
20961 + if (d_really_is_negative(dentry))
20962 + au_set_h_dptr(dentry, btop, NULL);
20963 + au_update_dbrange(dentry, /*do_put_zero*/0);
20968 + di_write_unlock(parent);
20970 + err = bcpup; /* success */
20977 + * decide the branch and the parent dir where we will create a new entry.
20978 + * returns new bindex or an error.
20979 + * copyup the parent dir if needed.
20981 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20982 + struct au_wr_dir_args *args)
20985 + unsigned int flags;
20986 + aufs_bindex_t bcpup, btop, src_btop;
20987 + const unsigned char add_entry
20988 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20989 + | au_ftest_wrdir(args->flags, TMPFILE);
20990 + struct super_block *sb;
20991 + struct dentry *parent;
20992 + struct au_sbinfo *sbinfo;
20994 + sb = dentry->d_sb;
20995 + sbinfo = au_sbi(sb);
20996 + parent = dget_parent(dentry);
20997 + btop = au_dbtop(dentry);
20999 + if (args->force_btgt < 0) {
21000 + if (src_dentry) {
21001 + src_btop = au_dbtop(src_dentry);
21002 + if (src_btop < btop)
21003 + bcpup = src_btop;
21004 + } else if (add_entry) {
21006 + if (au_ftest_wrdir(args->flags, ISDIR))
21007 + au_fset_wbr(flags, DIR);
21008 + err = AuWbrCreate(sbinfo, dentry, flags);
21012 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21014 + err = AuWbrCopyup(sbinfo, dentry);
21016 + if (!IS_ROOT(dentry)) {
21017 + di_read_lock_parent(parent, !AuLock_IR);
21018 + err = AuWbrCopyup(sbinfo, dentry);
21019 + di_read_unlock(parent, !AuLock_IR);
21021 + err = AuWbrCopyup(sbinfo, dentry);
21024 + if (unlikely(err < 0))
21028 + bcpup = args->force_btgt;
21029 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21032 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21034 + if (bcpup == btop)
21035 + goto out; /* success */
21037 + /* copyup the new parent into the branch we process */
21038 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21040 + if (d_really_is_negative(dentry)) {
21041 + au_set_h_dptr(dentry, btop, NULL);
21042 + au_set_dbtop(dentry, bcpup);
21043 + au_set_dbbot(dentry, bcpup);
21045 + AuDebugOn(add_entry
21046 + && !au_ftest_wrdir(args->flags, TMPFILE)
21047 + && !au_h_dptr(dentry, bcpup));
21055 +/* ---------------------------------------------------------------------- */
21057 +void au_pin_hdir_unlock(struct au_pin *p)
21060 + au_hn_inode_unlock(p->hdir);
21063 +int au_pin_hdir_lock(struct au_pin *p)
21071 + /* even if an error happens later, keep this lock */
21072 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21075 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21080 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21081 + p->h_parent, p->br);
21087 +int au_pin_hdir_relock(struct au_pin *p)
21090 + struct inode *h_i;
21091 + struct dentry *h_d[] = {
21096 + err = au_pin_hdir_lock(p);
21097 + if (unlikely(err))
21100 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21103 + if (d_is_positive(h_d[i])) {
21104 + h_i = d_inode(h_d[i]);
21105 + err = !h_i->i_nlink;
21113 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21115 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21118 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21121 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21122 + p->lsc_hi, 0, NULL, _RET_IP_);
21123 + au_pin_hdir_set_owner(p, current);
21127 +void au_pin_hdir_release(struct au_pin *p)
21130 + au_pin_hdir_set_owner(p, p->task);
21131 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21135 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21137 + if (pin && pin->parent)
21138 + return au_h_dptr(pin->parent, pin->bindex);
21142 +void au_unpin(struct au_pin *p)
21145 + au_pin_hdir_unlock(p);
21146 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21147 + vfsub_mnt_drop_write(p->h_mnt);
21151 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21152 + di_read_unlock(p->parent, AuLock_IR);
21153 + iput(p->hdir->hi_inode);
21155 + p->parent = NULL;
21158 + /* do not clear p->task */
21161 +int au_do_pin(struct au_pin *p)
21164 + struct super_block *sb;
21165 + struct inode *h_dir;
21168 + sb = p->dentry->d_sb;
21169 + p->br = au_sbr(sb, p->bindex);
21170 + if (IS_ROOT(p->dentry)) {
21171 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21172 + p->h_mnt = au_br_mnt(p->br);
21173 + err = vfsub_mnt_want_write(p->h_mnt);
21174 + if (unlikely(err)) {
21175 + au_fclr_pin(p->flags, MNT_WRITE);
21182 + p->h_dentry = NULL;
21183 + if (p->bindex <= au_dbbot(p->dentry))
21184 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21186 + p->parent = dget_parent(p->dentry);
21187 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21188 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21191 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21192 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21194 + h_dir = p->hdir->hi_inode;
21198 + * if DI_LOCKED is not set, then p->parent may be different
21199 + * and h_parent can be NULL.
21201 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21203 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21204 + di_read_unlock(p->parent, AuLock_IR);
21206 + p->parent = NULL;
21210 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21211 + p->h_mnt = au_br_mnt(p->br);
21212 + err = vfsub_mnt_want_write(p->h_mnt);
21213 + if (unlikely(err)) {
21214 + au_fclr_pin(p->flags, MNT_WRITE);
21215 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21216 + di_read_unlock(p->parent, AuLock_IR);
21218 + p->parent = NULL;
21224 + err = au_pin_hdir_lock(p);
21226 + goto out; /* success */
21231 + pr_err("err %d\n", err);
21232 + err = au_busy_or_stale();
21237 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21238 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21239 + unsigned int udba, unsigned char flags)
21241 + p->dentry = dentry;
21243 + p->lsc_di = lsc_di;
21244 + p->lsc_hi = lsc_hi;
21245 + p->flags = flags;
21246 + p->bindex = bindex;
21248 + p->parent = NULL;
21252 + p->h_dentry = NULL;
21253 + p->h_parent = NULL;
21255 + p->task = current;
21258 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21259 + unsigned int udba, unsigned char flags)
21261 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21263 + return au_do_pin(pin);
21266 +/* ---------------------------------------------------------------------- */
21269 + * ->setattr() and ->getattr() are called in various cases.
21270 + * chmod, stat: dentry is revalidated.
21271 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21273 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21275 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21276 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21279 + struct dentry *parent;
21282 + if (au_digen_test(dentry, sigen)) {
21283 + parent = dget_parent(dentry);
21284 + di_read_lock_parent(parent, AuLock_IR);
21285 + err = au_refresh_dentry(dentry, parent);
21286 + di_read_unlock(parent, AuLock_IR);
21294 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21295 + struct au_icpup_args *a)
21299 + aufs_bindex_t btop, ibtop;
21300 + struct dentry *hi_wh, *parent;
21301 + struct inode *inode;
21302 + struct au_wr_dir_args wr_dir_args = {
21303 + .force_btgt = -1,
21307 + if (d_is_dir(dentry))
21308 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21309 + /* plink or hi_wh() case */
21310 + btop = au_dbtop(dentry);
21311 + inode = d_inode(dentry);
21312 + ibtop = au_ibtop(inode);
21313 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21314 + wr_dir_args.force_btgt = ibtop;
21315 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21316 + if (unlikely(err < 0))
21320 + au_fset_icpup(a->flags, DID_CPUP);
21323 + a->pin_flags = AuPin_MNT_WRITE;
21325 + if (!IS_ROOT(dentry)) {
21326 + au_fset_pin(a->pin_flags, DI_LOCKED);
21327 + parent = dget_parent(dentry);
21328 + di_write_lock_parent(parent);
21331 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21332 + if (unlikely(err))
21336 + a->h_path.dentry = au_h_dptr(dentry, btop);
21337 + a->h_inode = d_inode(a->h_path.dentry);
21338 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21339 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21340 + if (ia->ia_size < i_size_read(a->h_inode))
21341 + sz = ia->ia_size;
21342 + inode_unlock_shared(a->h_inode);
21346 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21347 + hi_wh = au_hi_wh(inode, a->btgt);
21349 + struct au_cp_generic cpg = {
21350 + .dentry = dentry,
21356 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21357 + if (unlikely(err))
21359 + hi_wh = au_hi_wh(inode, a->btgt);
21360 + /* todo: revalidate hi_wh? */
21365 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21366 + di_downgrade_lock(parent, AuLock_IR);
21370 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21371 + goto out; /* success */
21373 + if (!d_unhashed(dentry)) {
21374 + struct au_cp_generic cpg = {
21375 + .dentry = dentry,
21380 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21382 + err = au_sio_cpup_simple(&cpg);
21384 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21385 + } else if (!hi_wh)
21386 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21388 + a->h_path.dentry = hi_wh; /* do not dget here */
21391 + a->h_inode = d_inode(a->h_path.dentry);
21393 + goto out; /* success */
21394 + au_unpin(&a->pin);
21397 + di_write_unlock(parent);
21402 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21406 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
21407 + struct iattr *ia)
21410 + struct inode *inode, *delegated;
21411 + struct super_block *sb;
21412 + struct file *file;
21413 + struct au_icpup_args *a;
21414 + struct user_namespace *h_userns;
21416 + inode = d_inode(dentry);
21417 + IMustLock(inode);
21419 + err = setattr_prepare(userns, dentry, ia);
21420 + if (unlikely(err))
21424 + a = kzalloc(sizeof(*a), GFP_NOFS);
21425 + if (unlikely(!a))
21428 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21429 + ia->ia_valid &= ~ATTR_MODE;
21432 + sb = dentry->d_sb;
21433 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21434 + if (unlikely(err))
21437 + if (ia->ia_valid & ATTR_FILE) {
21438 + /* currently ftruncate(2) only */
21439 + AuDebugOn(!d_is_reg(dentry));
21440 + file = ia->ia_file;
21441 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21443 + if (unlikely(err))
21445 + ia->ia_file = au_hf_top(file);
21446 + a->udba = AuOpt_UDBA_NONE;
21448 + /* fchmod() doesn't pass ia_file */
21449 + a->udba = au_opt_udba(sb);
21450 + di_write_lock_child(dentry);
21451 + /* no d_unlinked(), to set UDBA_NONE for root */
21452 + if (d_unhashed(dentry))
21453 + a->udba = AuOpt_UDBA_NONE;
21454 + if (a->udba != AuOpt_UDBA_NONE) {
21455 + AuDebugOn(IS_ROOT(dentry));
21456 + err = au_reval_for_attr(dentry, au_sigen(sb));
21457 + if (unlikely(err))
21462 + err = au_pin_and_icpup(dentry, ia, a);
21463 + if (unlikely(err < 0))
21465 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21466 + ia->ia_file = NULL;
21467 + ia->ia_valid &= ~ATTR_FILE;
21470 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21471 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21472 + == (ATTR_MODE | ATTR_CTIME)) {
21473 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21474 + if (unlikely(err))
21476 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21477 + && (ia->ia_valid & ATTR_CTIME)) {
21478 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21479 + if (unlikely(err))
21483 + if (ia->ia_valid & ATTR_SIZE) {
21486 + if (ia->ia_size < i_size_read(inode))
21488 + truncate_setsize(inode, ia->ia_size);
21491 + if (ia->ia_valid & ATTR_FILE)
21493 + inode_unlock(a->h_inode);
21494 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21495 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21497 + delegated = NULL;
21499 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21501 + err = break_deleg_wait(&delegated);
21509 + * regardless aufs 'acl' option setting.
21510 + * why don't all acl-aware fs call this func from their ->setattr()?
21512 + if (!err && (ia->ia_valid & ATTR_MODE)) {
21513 + h_userns = mnt_user_ns(a->h_path.mnt);
21514 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
21517 + au_cpup_attr_changeable(inode);
21520 + inode_unlock(a->h_inode);
21521 + au_unpin(&a->pin);
21522 + if (unlikely(err))
21523 + au_update_dbtop(dentry);
21525 + di_write_unlock(dentry);
21527 + fi_write_unlock(file);
21528 + ia->ia_file = file;
21529 + ia->ia_valid |= ATTR_FILE;
21532 + si_read_unlock(sb);
21540 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21541 +static int au_h_path_to_set_attr(struct dentry *dentry,
21542 + struct au_icpup_args *a, struct path *h_path)
21545 + struct super_block *sb;
21547 + sb = dentry->d_sb;
21548 + a->udba = au_opt_udba(sb);
21549 + /* no d_unlinked(), to set UDBA_NONE for root */
21550 + if (d_unhashed(dentry))
21551 + a->udba = AuOpt_UDBA_NONE;
21552 + if (a->udba != AuOpt_UDBA_NONE) {
21553 + AuDebugOn(IS_ROOT(dentry));
21554 + err = au_reval_for_attr(dentry, au_sigen(sb));
21555 + if (unlikely(err))
21558 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21559 + if (unlikely(err < 0))
21562 + h_path->dentry = a->h_path.dentry;
21563 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21569 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21570 + struct au_sxattr *arg)
21573 + struct path h_path;
21574 + struct super_block *sb;
21575 + struct au_icpup_args *a;
21576 + struct inode *h_inode;
21577 + struct user_namespace *h_userns;
21579 + IMustLock(inode);
21582 + a = kzalloc(sizeof(*a), GFP_NOFS);
21583 + if (unlikely(!a))
21586 + sb = dentry->d_sb;
21587 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21588 + if (unlikely(err))
21591 + h_path.dentry = NULL; /* silence gcc */
21592 + di_write_lock_child(dentry);
21593 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21594 + if (unlikely(err))
21596 + h_userns = mnt_user_ns(h_path.mnt);
21598 + inode_unlock(a->h_inode);
21599 + switch (arg->type) {
21600 + case AU_XATTR_SET:
21601 + AuDebugOn(d_is_negative(h_path.dentry));
21602 + err = vfsub_setxattr(h_userns, h_path.dentry,
21603 + arg->u.set.name, arg->u.set.value,
21604 + arg->u.set.size, arg->u.set.flags);
21607 + err = -EOPNOTSUPP;
21608 + h_inode = d_inode(h_path.dentry);
21609 + if (h_inode->i_op->set_acl) {
21610 + /* this will call posix_acl_update_mode */
21611 + err = h_inode->i_op->set_acl(h_userns, h_inode,
21612 + arg->u.acl_set.acl,
21613 + arg->u.acl_set.type);
21618 + au_cpup_attr_timesizes(inode);
21620 + au_unpin(&a->pin);
21621 + if (unlikely(err))
21622 + au_update_dbtop(dentry);
21625 + di_write_unlock(dentry);
21626 + si_read_unlock(sb);
21635 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21636 + unsigned int nlink)
21640 + inode->i_mode = st->mode;
21641 + /* don't i_[ug]id_write() here */
21642 + inode->i_uid = st->uid;
21643 + inode->i_gid = st->gid;
21644 + inode->i_atime = st->atime;
21645 + inode->i_mtime = st->mtime;
21646 + inode->i_ctime = st->ctime;
21648 + au_cpup_attr_nlink(inode, /*force*/0);
21649 + if (S_ISDIR(inode->i_mode)) {
21650 + n = inode->i_nlink;
21653 + smp_mb(); /* for i_nlink */
21654 + /* 0 can happen */
21655 + set_nlink(inode, n);
21658 + spin_lock(&inode->i_lock);
21659 + inode->i_blocks = st->blocks;
21660 + i_size_write(inode, st->size);
21661 + spin_unlock(&inode->i_lock);
21665 + * common routine for aufs_getattr() and au_getxattr().
21666 + * returns zero or negative (an error).
21667 + * @dentry will be read-locked in success.
21669 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21670 + struct path *h_path, int locked)
21673 + unsigned int mnt_flags, sigen;
21674 + unsigned char udba_none;
21675 + aufs_bindex_t bindex;
21676 + struct super_block *sb, *h_sb;
21678 + h_path->mnt = NULL;
21679 + h_path->dentry = NULL;
21682 + sb = dentry->d_sb;
21683 + mnt_flags = au_mntflags(sb);
21684 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21686 + if (unlikely(locked))
21687 + goto body; /* skip locking dinfo */
21689 + /* support fstat(2) */
21690 + if (!d_unlinked(dentry) && !udba_none) {
21691 + sigen = au_sigen(sb);
21692 + err = au_digen_test(dentry, sigen);
21694 + di_read_lock_child(dentry, AuLock_IR);
21695 + err = au_dbrange_test(dentry);
21696 + if (unlikely(err)) {
21697 + di_read_unlock(dentry, AuLock_IR);
21701 + AuDebugOn(IS_ROOT(dentry));
21702 + di_write_lock_child(dentry);
21703 + err = au_dbrange_test(dentry);
21705 + err = au_reval_for_attr(dentry, sigen);
21707 + di_downgrade_lock(dentry, AuLock_IR);
21709 + di_write_unlock(dentry);
21714 + di_read_lock_child(dentry, AuLock_IR);
21718 + inode = d_inode(dentry);
21719 + if (unlikely(!inode))
21722 + bindex = au_ibtop(inode);
21723 + h_path->mnt = au_sbr_mnt(sb, bindex);
21724 + h_sb = h_path->mnt->mnt_sb;
21726 + && !au_test_fs_bad_iattr(h_sb)
21728 + goto out; /* success */
21730 + if (au_dbtop(dentry) == bindex)
21731 + h_path->dentry = au_h_dptr(dentry, bindex);
21732 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21733 + h_path->dentry = au_plink_lkup(inode, bindex);
21734 + if (IS_ERR(h_path->dentry))
21735 + /* pretending success */
21736 + h_path->dentry = NULL;
21738 + dput(h_path->dentry);
21745 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
21746 + struct kstat *st, u32 request, unsigned int query)
21749 + unsigned char positive;
21750 + struct path h_path;
21751 + struct dentry *dentry;
21752 + struct inode *inode;
21753 + struct super_block *sb;
21755 + dentry = path->dentry;
21756 + inode = d_inode(dentry);
21757 + sb = dentry->d_sb;
21758 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21759 + if (unlikely(err))
21761 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21763 + if (unlikely(err))
21765 + if (unlikely(!h_path.dentry))
21766 + /* illegally overlapped or something */
21767 + goto out_fill; /* pretending success */
21769 + positive = d_is_positive(h_path.dentry);
21771 + /* no vfsub version */
21772 + err = vfs_getattr(&h_path, st, request, query);
21775 + au_refresh_iattr(inode, st,
21776 + d_inode(h_path.dentry)->i_nlink);
21777 + goto out_fill; /* success */
21783 + generic_fillattr(userns, inode, st);
21785 + di_read_unlock(dentry, AuLock_IR);
21787 + si_read_unlock(sb);
21793 +/* ---------------------------------------------------------------------- */
21795 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21796 + struct delayed_call *done)
21799 + struct dentry *h_dentry;
21800 + struct inode *h_inode;
21802 + aufs_bindex_t bindex;
21804 + ret = NULL; /* suppress a warning */
21809 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21810 + if (unlikely(err))
21813 + err = au_d_hashed_positive(dentry);
21814 + if (unlikely(err))
21818 + inode = d_inode(dentry);
21819 + bindex = au_ibtop(inode);
21820 + h_inode = au_h_iptr(inode, bindex);
21821 + if (unlikely(!h_inode->i_op->get_link))
21826 + if (au_dbtop(dentry) <= bindex) {
21827 + h_dentry = au_h_dptr(dentry, bindex);
21832 + h_dentry = d_find_any_alias(h_inode);
21833 + if (IS_ERR(h_dentry)) {
21834 + err = PTR_ERR(h_dentry);
21838 + if (unlikely(!h_dentry))
21842 + AuDbg("%ps\n", h_inode->i_op->get_link);
21843 + AuDbgDentry(h_dentry);
21844 + ret = vfs_get_link(h_dentry, done);
21847 + err = PTR_ERR(ret);
21850 + aufs_read_unlock(dentry, AuLock_IR);
21852 + if (unlikely(err))
21853 + ret = ERR_PTR(err);
21854 + AuTraceErrPtr(ret);
21858 +/* ---------------------------------------------------------------------- */
21860 +static int au_is_special(struct inode *inode)
21862 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21865 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21869 + aufs_bindex_t bindex;
21870 + struct super_block *sb;
21871 + struct inode *h_inode;
21872 + struct vfsmount *h_mnt;
21874 + sb = inode->i_sb;
21875 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21876 + "unexpected s_flags 0x%lx", sb->s_flags);
21878 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21880 + si_read_lock(sb, AuLock_FLUSH);
21881 + ii_write_lock_child(inode);
21884 + bindex = au_ibtop(inode);
21885 + h_inode = au_h_iptr(inode, bindex);
21886 + if (!au_test_ro(sb, bindex, inode)) {
21887 + h_mnt = au_sbr_mnt(sb, bindex);
21888 + err = vfsub_mnt_want_write(h_mnt);
21890 + err = vfsub_update_time(h_inode, ts, flags);
21891 + vfsub_mnt_drop_write(h_mnt);
21893 + } else if (au_is_special(h_inode)) {
21895 + * Never copy-up here.
21896 + * These special files may already be opened and used for
21897 + * communicating. If we copied it up, then the communication
21898 + * would be corrupted.
21900 + AuWarn1("timestamps for i%lu are ignored "
21901 + "since it is on readonly branch (hi%lu).\n",
21902 + inode->i_ino, h_inode->i_ino);
21903 + } else if (flags & ~S_ATIME) {
21905 + AuIOErr1("unexpected flags 0x%x\n", flags);
21910 + au_cpup_attr_timesizes(inode);
21911 + ii_write_unlock(inode);
21912 + si_read_unlock(sb);
21915 + if (!err && (flags & S_VERSION))
21916 + inode_inc_iversion(inode);
21921 +/* ---------------------------------------------------------------------- */
21923 +/* no getattr version will be set by module.c:aufs_init() */
21924 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21926 + [AuIop_SYMLINK] = {
21927 + .permission = aufs_permission,
21928 +#ifdef CONFIG_FS_POSIX_ACL
21929 + .get_acl = aufs_get_acl,
21930 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21933 + .setattr = aufs_setattr,
21934 + .getattr = aufs_getattr,
21936 +#ifdef CONFIG_AUFS_XATTR
21937 + .listxattr = aufs_listxattr,
21940 + .get_link = aufs_get_link,
21942 + /* .update_time = aufs_update_time */
21945 + .create = aufs_create,
21946 + .lookup = aufs_lookup,
21947 + .link = aufs_link,
21948 + .unlink = aufs_unlink,
21949 + .symlink = aufs_symlink,
21950 + .mkdir = aufs_mkdir,
21951 + .rmdir = aufs_rmdir,
21952 + .mknod = aufs_mknod,
21953 + .rename = aufs_rename,
21955 + .permission = aufs_permission,
21956 +#ifdef CONFIG_FS_POSIX_ACL
21957 + .get_acl = aufs_get_acl,
21958 + .set_acl = aufs_set_acl,
21961 + .setattr = aufs_setattr,
21962 + .getattr = aufs_getattr,
21964 +#ifdef CONFIG_AUFS_XATTR
21965 + .listxattr = aufs_listxattr,
21968 + .update_time = aufs_update_time,
21969 + .atomic_open = aufs_atomic_open,
21970 + .tmpfile = aufs_tmpfile
21972 + [AuIop_OTHER] = {
21973 + .permission = aufs_permission,
21974 +#ifdef CONFIG_FS_POSIX_ACL
21975 + .get_acl = aufs_get_acl,
21976 + .set_acl = aufs_set_acl,
21979 + .setattr = aufs_setattr,
21980 + .getattr = aufs_getattr,
21982 +#ifdef CONFIG_AUFS_XATTR
21983 + .listxattr = aufs_listxattr,
21986 + .update_time = aufs_update_time
21989 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21990 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21991 +++ linux/fs/aufs/i_op_del.c 2021-05-02 20:15:14.673337458 +0200
21993 +// SPDX-License-Identifier: GPL-2.0
21995 + * Copyright (C) 2005-2020 Junjiro R. Okajima
21997 + * This program, aufs is free software; you can redistribute it and/or modify
21998 + * it under the terms of the GNU General Public License as published by
21999 + * the Free Software Foundation; either version 2 of the License, or
22000 + * (at your option) any later version.
22002 + * This program is distributed in the hope that it will be useful,
22003 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22004 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22005 + * GNU General Public License for more details.
22007 + * You should have received a copy of the GNU General Public License
22008 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22012 + * inode operations (del entry)
22015 +#include <linux/iversion.h>
22019 + * decide if a new whiteout for @dentry is necessary or not.
22020 + * when it is necessary, prepare the parent dir for the upper branch whose
22021 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22022 + * be done by caller.
22024 + * 0: wh is unnecessary
22025 + * plus: wh is necessary
22028 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22030 + int need_wh, err;
22031 + aufs_bindex_t btop;
22032 + struct super_block *sb;
22034 + sb = dentry->d_sb;
22035 + btop = au_dbtop(dentry);
22036 + if (*bcpup < 0) {
22038 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22039 + err = AuWbrCopyup(au_sbi(sb), dentry);
22041 + if (unlikely(err < 0))
22045 + AuDebugOn(btop < *bcpup
22046 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22047 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22049 + if (*bcpup != btop) {
22050 + err = au_cpup_dirs(dentry, *bcpup);
22051 + if (unlikely(err))
22055 + struct au_dinfo *dinfo, *tmp;
22057 + need_wh = -ENOMEM;
22058 + dinfo = au_di(dentry);
22059 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22061 + au_di_cp(tmp, dinfo);
22062 + au_di_swap(tmp, dinfo);
22063 + /* returns the number of positive dentries */
22064 + need_wh = au_lkup_dentry(dentry, btop + 1,
22065 + /* AuLkup_IGNORE_PERM */ 0);
22066 + au_di_swap(tmp, dinfo);
22067 + au_rw_write_unlock(&tmp->di_rwsem);
22071 + AuDbg("need_wh %d\n", need_wh);
22079 + * simple tests for the del-entry operations.
22080 + * following the checks in vfs, plus the parent-child relationship.
22082 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22083 + struct dentry *h_parent, int isdir)
22087 + struct dentry *h_dentry, *h_latest;
22088 + struct inode *h_inode;
22089 + struct user_namespace *h_userns;
22091 + h_dentry = au_h_dptr(dentry, bindex);
22092 + if (d_really_is_positive(dentry)) {
22094 + if (unlikely(d_is_negative(h_dentry)))
22096 + h_inode = d_inode(h_dentry);
22097 + if (unlikely(!h_inode->i_nlink))
22100 + h_mode = h_inode->i_mode;
22103 + if (unlikely(S_ISDIR(h_mode)))
22105 + } else if (unlikely(!S_ISDIR(h_mode))) {
22110 + /* rename(2) case */
22112 + if (unlikely(d_is_positive(h_dentry)))
22117 + /* expected parent dir is locked */
22118 + if (unlikely(h_parent != h_dentry->d_parent))
22123 + * rmdir a dir may break the consistency on some filesystem.
22124 + * let's try heavy test.
22127 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
22128 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22129 + && au_test_h_perm(h_userns, d_inode(h_parent),
22130 + MAY_EXEC | MAY_WRITE)))
22133 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, h_parent);
22135 + if (IS_ERR(h_latest))
22137 + if (h_latest == h_dentry)
22146 + * decide the branch where we operate for @dentry. the branch index will be set
22147 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22148 + * dir for reverting.
22149 + * when a new whiteout is necessary, create it.
22151 +static struct dentry*
22152 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22153 + struct au_dtime *dt, struct au_pin *pin)
22155 + struct dentry *wh_dentry;
22156 + struct super_block *sb;
22157 + struct path h_path;
22158 + int err, need_wh;
22159 + unsigned int udba;
22160 + aufs_bindex_t bcpup;
22162 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22163 + wh_dentry = ERR_PTR(need_wh);
22164 + if (unlikely(need_wh < 0))
22167 + sb = dentry->d_sb;
22168 + udba = au_opt_udba(sb);
22170 + err = au_pin(pin, dentry, bcpup, udba,
22171 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22172 + wh_dentry = ERR_PTR(err);
22173 + if (unlikely(err))
22176 + h_path.dentry = au_pinned_h_parent(pin);
22177 + if (udba != AuOpt_UDBA_NONE
22178 + && au_dbtop(dentry) == bcpup) {
22179 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22180 + wh_dentry = ERR_PTR(err);
22181 + if (unlikely(err))
22185 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22186 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22187 + wh_dentry = NULL;
22189 + goto out; /* success, no need to create whiteout */
22191 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22192 + if (IS_ERR(wh_dentry))
22195 + /* returns with the parent is locked and wh_dentry is dget-ed */
22196 + goto out; /* success */
22201 + return wh_dentry;
22205 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22206 + * in order to be revertible and save time for removing many child whiteouts
22208 + * returns 1 when there are too many child whiteout and caller should remove
22209 + * them asynchronously. returns 0 when the number of children is enough small to
22210 + * remove now or the branch fs is a remote fs.
22211 + * otherwise return an error.
22213 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22214 + struct au_nhash *whlist, struct inode *dir)
22216 + int rmdir_later, err, dirwh;
22217 + struct dentry *h_dentry;
22218 + struct super_block *sb;
22219 + struct inode *inode;
22221 + sb = dentry->d_sb;
22222 + SiMustAnyLock(sb);
22223 + h_dentry = au_h_dptr(dentry, bindex);
22224 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22225 + if (unlikely(err))
22228 + /* stop monitoring */
22229 + inode = d_inode(dentry);
22230 + au_hn_free(au_hi(inode, bindex));
22232 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22233 + dirwh = au_sbi(sb)->si_dirwh;
22234 + rmdir_later = (dirwh <= 1);
22235 + if (!rmdir_later)
22236 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22239 + return rmdir_later;
22242 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22243 + if (unlikely(err)) {
22244 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22245 + h_dentry, bindex, err);
22255 + * final procedure for deleting a entry.
22256 + * maintain dentry and iattr.
22258 +static void epilog(struct inode *dir, struct dentry *dentry,
22259 + aufs_bindex_t bindex)
22261 + struct inode *inode;
22263 + inode = d_inode(dentry);
22265 + inode->i_ctime = dir->i_ctime;
22267 + au_dir_ts(dir, bindex);
22268 + inode_inc_iversion(dir);
22272 + * when an error happened, remove the created whiteout and revert everything.
22274 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22275 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22276 + struct dentry *dentry, struct au_dtime *dt)
22279 + struct path h_path = {
22280 + .dentry = wh_dentry,
22281 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22284 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22286 + au_set_dbwh(dentry, bwh);
22287 + au_dtime_revert(dt);
22291 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22295 +/* ---------------------------------------------------------------------- */
22297 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22300 + aufs_bindex_t bwh, bindex, btop;
22301 + struct inode *inode, *h_dir, *delegated;
22302 + struct dentry *parent, *wh_dentry;
22303 + /* to reduce stack size */
22305 + struct au_dtime dt;
22306 + struct au_pin pin;
22307 + struct path h_path;
22313 + a = kmalloc(sizeof(*a), GFP_NOFS);
22314 + if (unlikely(!a))
22317 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22318 + if (unlikely(err))
22320 + err = au_d_hashed_positive(dentry);
22321 + if (unlikely(err))
22323 + inode = d_inode(dentry);
22324 + IMustLock(inode);
22326 + if (unlikely(d_is_dir(dentry)))
22327 + goto out_unlock; /* possible? */
22329 + btop = au_dbtop(dentry);
22330 + bwh = au_dbwh(dentry);
22332 + parent = dentry->d_parent; /* dir inode is locked */
22333 + di_write_lock_parent(parent);
22334 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22336 + err = PTR_ERR(wh_dentry);
22337 + if (IS_ERR(wh_dentry))
22340 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22341 + a->h_path.dentry = au_h_dptr(dentry, btop);
22342 + dget(a->h_path.dentry);
22343 + if (bindex == btop) {
22344 + h_dir = au_pinned_h_dir(&a->pin);
22345 + delegated = NULL;
22346 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22347 + if (unlikely(err == -EWOULDBLOCK)) {
22348 + pr_warn("cannot retry for NFSv4 delegation"
22349 + " for an internal unlink\n");
22353 + /* dir inode is locked */
22354 + h_dir = d_inode(wh_dentry->d_parent);
22355 + IMustLock(h_dir);
22360 + vfsub_drop_nlink(inode);
22361 + epilog(dir, dentry, bindex);
22363 + /* update target timestamps */
22364 + if (bindex == btop) {
22365 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22367 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22369 + /* todo: this timestamp may be reverted later */
22370 + inode->i_ctime = h_dir->i_ctime;
22371 + goto out_unpin; /* success */
22378 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22385 + au_unpin(&a->pin);
22387 + dput(a->h_path.dentry);
22389 + di_write_unlock(parent);
22391 + aufs_read_unlock(dentry, AuLock_DW);
22398 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22400 + int err, rmdir_later;
22401 + aufs_bindex_t bwh, bindex, btop;
22402 + struct inode *inode;
22403 + struct dentry *parent, *wh_dentry, *h_dentry;
22404 + struct au_whtmp_rmdir *args;
22405 + /* to reduce stack size */
22407 + struct au_dtime dt;
22408 + struct au_pin pin;
22414 + a = kmalloc(sizeof(*a), GFP_NOFS);
22415 + if (unlikely(!a))
22418 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22419 + if (unlikely(err))
22421 + err = au_alive_dir(dentry);
22422 + if (unlikely(err))
22424 + inode = d_inode(dentry);
22425 + IMustLock(inode);
22427 + if (unlikely(!d_is_dir(dentry)))
22428 + goto out_unlock; /* possible? */
22431 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22432 + if (unlikely(!args))
22435 + parent = dentry->d_parent; /* dir inode is locked */
22436 + di_write_lock_parent(parent);
22437 + err = au_test_empty(dentry, &args->whlist);
22438 + if (unlikely(err))
22441 + btop = au_dbtop(dentry);
22442 + bwh = au_dbwh(dentry);
22444 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22446 + err = PTR_ERR(wh_dentry);
22447 + if (IS_ERR(wh_dentry))
22450 + h_dentry = au_h_dptr(dentry, btop);
22453 + if (bindex == btop) {
22454 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22456 + rmdir_later = err;
22460 + /* stop monitoring */
22461 + au_hn_free(au_hi(inode, btop));
22463 + /* dir inode is locked */
22464 + IMustLock(d_inode(wh_dentry->d_parent));
22469 + vfsub_dead_dir(inode);
22470 + au_set_dbdiropq(dentry, -1);
22471 + epilog(dir, dentry, bindex);
22473 + if (rmdir_later) {
22474 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22478 + goto out_unpin; /* success */
22486 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22493 + au_unpin(&a->pin);
22497 + di_write_unlock(parent);
22499 + au_whtmp_rmdir_free(args);
22501 + aufs_read_unlock(dentry, AuLock_DW);
22508 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22509 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22510 +++ linux/fs/aufs/i_op_ren.c 2021-05-02 20:15:14.673337458 +0200
22512 +// SPDX-License-Identifier: GPL-2.0
22514 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22516 + * This program, aufs is free software; you can redistribute it and/or modify
22517 + * it under the terms of the GNU General Public License as published by
22518 + * the Free Software Foundation; either version 2 of the License, or
22519 + * (at your option) any later version.
22521 + * This program is distributed in the hope that it will be useful,
22522 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22523 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22524 + * GNU General Public License for more details.
22526 + * You should have received a copy of the GNU General Public License
22527 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22531 + * inode operation (rename entry)
22532 + * todo: this is crazy monster
22535 +#include <linux/iversion.h>
22538 +enum { AuSRC, AuDST, AuSrcDst };
22539 +enum { AuPARENT, AuCHILD, AuParentChild };
22541 +#define AuRen_ISDIR_SRC 1
22542 +#define AuRen_ISDIR_DST (1 << 1)
22543 +#define AuRen_ISSAMEDIR (1 << 2)
22544 +#define AuRen_WHSRC (1 << 3)
22545 +#define AuRen_WHDST (1 << 4)
22546 +#define AuRen_MNT_WRITE (1 << 5)
22547 +#define AuRen_DT_DSTDIR (1 << 6)
22548 +#define AuRen_DIROPQ_SRC (1 << 7)
22549 +#define AuRen_DIROPQ_DST (1 << 8)
22550 +#define AuRen_DIRREN (1 << 9)
22551 +#define AuRen_DROPPED_SRC (1 << 10)
22552 +#define AuRen_DROPPED_DST (1 << 11)
22553 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22554 +#define au_fset_ren(flags, name) \
22555 + do { (flags) |= AuRen_##name; } while (0)
22556 +#define au_fclr_ren(flags, name) \
22557 + do { (flags) &= ~AuRen_##name; } while (0)
22559 +#ifndef CONFIG_AUFS_DIRREN
22560 +#undef AuRen_DIRREN
22561 +#define AuRen_DIRREN 0
22564 +struct au_ren_args {
22566 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22568 + struct inode *dir, *inode;
22569 + struct au_hinode *hdir, *hinode;
22570 + struct au_dtime dt[AuParentChild];
22571 + aufs_bindex_t btop, bdiropq;
22574 +#define src_dentry sd[AuSRC].dentry
22575 +#define src_dir sd[AuSRC].dir
22576 +#define src_inode sd[AuSRC].inode
22577 +#define src_h_dentry sd[AuSRC].h_dentry
22578 +#define src_parent sd[AuSRC].parent
22579 +#define src_h_parent sd[AuSRC].h_parent
22580 +#define src_wh_dentry sd[AuSRC].wh_dentry
22581 +#define src_hdir sd[AuSRC].hdir
22582 +#define src_hinode sd[AuSRC].hinode
22583 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22584 +#define src_dt sd[AuSRC].dt
22585 +#define src_btop sd[AuSRC].btop
22586 +#define src_bdiropq sd[AuSRC].bdiropq
22588 +#define dst_dentry sd[AuDST].dentry
22589 +#define dst_dir sd[AuDST].dir
22590 +#define dst_inode sd[AuDST].inode
22591 +#define dst_h_dentry sd[AuDST].h_dentry
22592 +#define dst_parent sd[AuDST].parent
22593 +#define dst_h_parent sd[AuDST].h_parent
22594 +#define dst_wh_dentry sd[AuDST].wh_dentry
22595 +#define dst_hdir sd[AuDST].hdir
22596 +#define dst_hinode sd[AuDST].hinode
22597 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22598 +#define dst_dt sd[AuDST].dt
22599 +#define dst_btop sd[AuDST].btop
22600 +#define dst_bdiropq sd[AuDST].bdiropq
22602 + struct dentry *h_trap;
22603 + struct au_branch *br;
22604 + struct path h_path;
22605 + struct au_nhash whlist;
22606 + aufs_bindex_t btgt, src_bwh;
22609 + unsigned short auren_flags;
22610 + unsigned char flags; /* syscall parameter */
22611 + unsigned char exchange;
22614 + struct au_whtmp_rmdir *thargs;
22615 + struct dentry *h_dst;
22616 + struct au_hinode *h_root;
22619 +/* ---------------------------------------------------------------------- */
22622 + * functions for reverting.
22623 + * when an error happened in a single rename systemcall, we should revert
22624 + * everything as if nothing happened.
22625 + * we don't need to revert the copied-up/down the parent dir since they are
22629 +#define RevertFailure(fmt, ...) do { \
22630 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22631 + ##__VA_ARGS__, err, rerr); \
22635 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22638 + struct dentry *d;
22639 +#define src_or_dst(member) a->sd[idx].member
22641 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22642 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22643 + rerr = au_diropq_remove(d, a->btgt);
22644 + au_hn_inode_unlock(src_or_dst(hinode));
22645 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22647 + RevertFailure("remove diropq %pd", d);
22649 +#undef src_or_dst_
22652 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22654 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22655 + au_ren_do_rev_diropq(err, a, AuSRC);
22656 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22657 + au_ren_do_rev_diropq(err, a, AuDST);
22660 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22663 + struct inode *delegated;
22665 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22666 + a->src_h_parent);
22667 + rerr = PTR_ERR(a->h_path.dentry);
22668 + if (IS_ERR(a->h_path.dentry)) {
22669 + RevertFailure("lkup one %pd", a->src_dentry);
22673 + delegated = NULL;
22674 + rerr = vfsub_rename(a->dst_h_dir,
22675 + au_h_dptr(a->src_dentry, a->btgt),
22676 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22677 + if (unlikely(rerr == -EWOULDBLOCK)) {
22678 + pr_warn("cannot retry for NFSv4 delegation"
22679 + " for an internal rename\n");
22682 + d_drop(a->h_path.dentry);
22683 + dput(a->h_path.dentry);
22684 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22686 + RevertFailure("rename %pd", a->src_dentry);
22689 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22692 + struct inode *delegated;
22694 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22695 + a->dst_h_parent);
22696 + rerr = PTR_ERR(a->h_path.dentry);
22697 + if (IS_ERR(a->h_path.dentry)) {
22698 + RevertFailure("lkup one %pd", a->dst_dentry);
22701 + if (d_is_positive(a->h_path.dentry)) {
22702 + d_drop(a->h_path.dentry);
22703 + dput(a->h_path.dentry);
22707 + delegated = NULL;
22708 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22709 + &delegated, a->flags);
22710 + if (unlikely(rerr == -EWOULDBLOCK)) {
22711 + pr_warn("cannot retry for NFSv4 delegation"
22712 + " for an internal rename\n");
22715 + d_drop(a->h_path.dentry);
22716 + dput(a->h_path.dentry);
22718 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22720 + RevertFailure("rename %pd", a->h_dst);
22723 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22727 + a->h_path.dentry = a->src_wh_dentry;
22728 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22729 + au_set_dbwh(a->src_dentry, a->src_bwh);
22731 + RevertFailure("unlink %pd", a->src_wh_dentry);
22733 +#undef RevertFailure
22735 +/* ---------------------------------------------------------------------- */
22738 + * when we have to copyup the renaming entry, do it with the rename-target name
22739 + * in order to minimize the cost (the later actual rename is unnecessary).
22740 + * otherwise rename it on the target branch.
22742 +static int au_ren_or_cpup(struct au_ren_args *a)
22745 + struct dentry *d;
22746 + struct inode *delegated;
22748 + d = a->src_dentry;
22749 + if (au_dbtop(d) == a->btgt) {
22750 + a->h_path.dentry = a->dst_h_dentry;
22751 + AuDebugOn(au_dbtop(d) != a->btgt);
22752 + delegated = NULL;
22753 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22754 + a->dst_h_dir, &a->h_path, &delegated,
22756 + if (unlikely(err == -EWOULDBLOCK)) {
22757 + pr_warn("cannot retry for NFSv4 delegation"
22758 + " for an internal rename\n");
22764 + if (!err && a->h_dst)
22765 + /* it will be set to dinfo later */
22771 +/* cf. aufs_rmdir() */
22772 +static int au_ren_del_whtmp(struct au_ren_args *a)
22775 + struct inode *dir;
22777 + dir = a->dst_dir;
22778 + SiMustAnyLock(dir->i_sb);
22779 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22780 + au_sbi(dir->i_sb)->si_dirwh)
22781 + || au_test_fs_remote(a->h_dst->d_sb)) {
22782 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22783 + if (unlikely(err))
22784 + pr_warn("failed removing whtmp dir %pd (%d), "
22785 + "ignored.\n", a->h_dst, err);
22787 + au_nhash_wh_free(&a->thargs->whlist);
22788 + a->thargs->whlist = a->whlist;
22789 + a->whlist.nh_num = 0;
22790 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22792 + a->thargs = NULL;
22798 +/* make it 'opaque' dir. */
22799 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22802 + struct dentry *d, *diropq;
22803 +#define src_or_dst(member) a->sd[idx].member
22806 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22807 + src_or_dst(bdiropq) = au_dbdiropq(d);
22808 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22809 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22810 + diropq = au_diropq_create(d, a->btgt);
22811 + au_hn_inode_unlock(src_or_dst(hinode));
22812 + if (IS_ERR(diropq))
22813 + err = PTR_ERR(diropq);
22817 +#undef src_or_dst_
22821 +static int au_ren_diropq(struct au_ren_args *a)
22824 + unsigned char always;
22825 + struct dentry *d;
22828 + d = a->dst_dentry; /* already renamed on the branch */
22829 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22830 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22831 + && !au_ftest_ren(a->auren_flags, DIRREN)
22832 + && a->btgt != au_dbdiropq(a->src_dentry)
22833 + && (a->dst_wh_dentry
22834 + || a->btgt <= au_dbdiropq(d)
22835 + /* hide the lower to keep xino */
22836 + /* the lowers may not be a dir, but we hide them anyway */
22837 + || a->btgt < au_dbbot(d)
22840 + err = au_ren_do_diropq(a, AuSRC);
22841 + if (unlikely(err))
22843 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22845 + if (!a->exchange)
22846 + goto out; /* success */
22848 + d = a->src_dentry; /* already renamed on the branch */
22849 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22850 + && a->btgt != au_dbdiropq(a->dst_dentry)
22851 + && (a->btgt < au_dbdiropq(d)
22852 + || a->btgt < au_dbbot(d)
22854 + AuDbgDentry(a->src_dentry);
22855 + AuDbgDentry(a->dst_dentry);
22856 + err = au_ren_do_diropq(a, AuDST);
22857 + if (unlikely(err))
22858 + goto out_rev_src;
22859 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22861 + goto out; /* success */
22864 + AuDbg("err %d, reverting src\n", err);
22865 + au_ren_rev_diropq(err, a);
22870 +static int do_rename(struct au_ren_args *a)
22873 + struct dentry *d, *h_d;
22875 + if (!a->exchange) {
22876 + /* prepare workqueue args for asynchronous rmdir */
22877 + h_d = a->dst_h_dentry;
22878 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22879 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22880 + && d_is_positive(h_d)) {
22882 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22884 + if (unlikely(!a->thargs))
22886 + a->h_dst = dget(h_d);
22889 + /* create whiteout for src_dentry */
22890 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22891 + a->src_bwh = au_dbwh(a->src_dentry);
22892 + AuDebugOn(a->src_bwh >= 0);
22893 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22894 + a->src_h_parent);
22895 + err = PTR_ERR(a->src_wh_dentry);
22896 + if (IS_ERR(a->src_wh_dentry))
22900 + /* lookup whiteout for dentry */
22901 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22902 + h_d = au_wh_lkup(a->dst_h_parent,
22903 + &a->dst_dentry->d_name, a->br);
22904 + err = PTR_ERR(h_d);
22907 + if (d_is_negative(h_d))
22910 + a->dst_wh_dentry = h_d;
22913 + /* rename dentry to tmpwh */
22915 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22916 + if (unlikely(err))
22919 + d = a->dst_dentry;
22920 + au_set_h_dptr(d, a->btgt, NULL);
22921 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22922 + if (unlikely(err))
22924 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22928 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22929 +#if 0 /* debugging */
22930 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22931 + && d_is_positive(a->dst_h_dentry)
22932 + && a->src_btop != a->btgt);
22935 + /* rename by vfs_rename or cpup */
22936 + err = au_ren_or_cpup(a);
22937 + if (unlikely(err))
22938 + /* leave the copied-up one */
22941 + /* make dir opaque */
22942 + err = au_ren_diropq(a);
22943 + if (unlikely(err))
22946 + /* update target timestamps */
22947 + if (a->exchange) {
22948 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22949 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22950 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22951 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22953 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22954 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22955 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22956 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22958 + if (!a->exchange) {
22959 + /* remove whiteout for dentry */
22960 + if (a->dst_wh_dentry) {
22961 + a->h_path.dentry = a->dst_wh_dentry;
22962 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22964 + if (unlikely(err))
22968 + /* remove whtmp */
22970 + au_ren_del_whtmp(a); /* ignore this error */
22972 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22975 + goto out_success;
22978 + au_ren_rev_diropq(err, a);
22980 + au_ren_rev_rename(err, a);
22984 + au_ren_rev_whtmp(err, a);
22986 + dput(a->dst_wh_dentry);
22987 + a->dst_wh_dentry = NULL;
22989 + if (a->src_wh_dentry)
22990 + au_ren_rev_whsrc(err, a);
22992 + dput(a->src_wh_dentry);
22993 + dput(a->dst_wh_dentry);
22997 + au_whtmp_rmdir_free(a->thargs);
22998 + a->thargs = NULL;
23004 +/* ---------------------------------------------------------------------- */
23007 + * test if @dentry dir can be rename destination or not.
23008 + * success means, it is a logically empty dir.
23010 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23012 + return au_test_empty(dentry, whlist);
23016 + * test if @a->src_dentry dir can be rename source or not.
23017 + * if it can, return 0.
23019 + * - it is a logically empty dir.
23020 + * - or, it exists on writable branch and has no children including whiteouts
23021 + * on the lower branch unless DIRREN is on.
23023 +static int may_rename_srcdir(struct au_ren_args *a)
23026 + unsigned int rdhash;
23027 + aufs_bindex_t btop, btgt;
23028 + struct dentry *dentry;
23029 + struct super_block *sb;
23030 + struct au_sbinfo *sbinfo;
23032 + dentry = a->src_dentry;
23033 + sb = dentry->d_sb;
23034 + sbinfo = au_sbi(sb);
23035 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23036 + au_fset_ren(a->auren_flags, DIRREN);
23039 + btop = au_dbtop(dentry);
23040 + if (btop != btgt) {
23041 + struct au_nhash whlist;
23043 + SiMustAnyLock(sb);
23044 + rdhash = sbinfo->si_rdhash;
23046 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23048 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23049 + if (unlikely(err))
23051 + err = au_test_empty(dentry, &whlist);
23052 + au_nhash_wh_free(&whlist);
23056 + if (btop == au_dbtaildir(dentry))
23057 + return 0; /* success */
23059 + err = au_test_empty_lower(dentry);
23062 + if (err == -ENOTEMPTY) {
23063 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23066 + AuWarn1("renaming dir who has child(ren) on multiple "
23067 + "branches, is not supported\n");
23074 +/* side effect: sets whlist and h_dentry */
23075 +static int au_ren_may_dir(struct au_ren_args *a)
23078 + unsigned int rdhash;
23079 + struct dentry *d;
23081 + d = a->dst_dentry;
23082 + SiMustAnyLock(d->d_sb);
23085 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23086 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23088 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23089 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23090 + if (unlikely(err))
23093 + if (!a->exchange) {
23094 + au_set_dbtop(d, a->dst_btop);
23095 + err = may_rename_dstdir(d, &a->whlist);
23096 + au_set_dbtop(d, a->btgt);
23098 + err = may_rename_srcdir(a);
23100 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23101 + if (unlikely(err))
23104 + d = a->src_dentry;
23105 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23106 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23107 + err = may_rename_srcdir(a);
23108 + if (unlikely(err)) {
23109 + au_nhash_wh_free(&a->whlist);
23110 + a->whlist.nh_num = 0;
23117 +/* ---------------------------------------------------------------------- */
23120 + * simple tests for rename.
23121 + * following the checks in vfs, plus the parent-child relationship.
23123 +static int au_may_ren(struct au_ren_args *a)
23126 + struct inode *h_inode;
23128 + if (a->src_btop == a->btgt) {
23129 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23130 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23131 + if (unlikely(err))
23134 + if (unlikely(a->src_h_dentry == a->h_trap))
23139 + if (a->dst_btop != a->btgt)
23142 + err = -ENOTEMPTY;
23143 + if (unlikely(a->dst_h_dentry == a->h_trap))
23147 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23148 + if (d_really_is_negative(a->dst_dentry)) {
23149 + if (d_is_negative(a->dst_h_dentry))
23150 + err = au_may_add(a->dst_dentry, a->btgt,
23151 + a->dst_h_parent, isdir);
23153 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23155 + h_inode = d_inode(a->dst_h_dentry);
23156 + if (h_inode->i_nlink)
23157 + err = au_may_del(a->dst_dentry, a->btgt,
23158 + a->dst_h_parent, isdir);
23162 + if (unlikely(err == -ENOENT || err == -EEXIST))
23168 +/* ---------------------------------------------------------------------- */
23173 + * - src_dir and dir by lock_rename()
23174 + * - inode if exists
23177 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23179 + * + di_write_lock2_child()
23180 + * + di_write_lock_child()
23181 + * + ii_write_lock_child()
23182 + * + di_write_lock_child2()
23183 + * + ii_write_lock_child2()
23184 + * + src_parent and parent
23185 + * + di_write_lock_parent()
23186 + * + ii_write_lock_parent()
23187 + * + di_write_lock_parent2()
23188 + * + ii_write_lock_parent2()
23189 + * + lower src_dir and dir by vfsub_lock_rename()
23190 + * + verify the every relationships between child and parent. if any
23191 + * of them failed, unlock all and return -EBUSY.
23193 +static void au_ren_unlock(struct au_ren_args *a)
23195 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23196 + a->dst_h_parent, a->dst_hdir);
23197 + if (au_ftest_ren(a->auren_flags, DIRREN)
23199 + au_hn_inode_unlock(a->h_root);
23200 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23201 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23204 +static int au_ren_lock(struct au_ren_args *a)
23207 + unsigned int udba;
23210 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23211 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23212 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23213 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23215 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23216 + if (unlikely(err))
23218 + au_fset_ren(a->auren_flags, MNT_WRITE);
23219 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23220 + struct dentry *root;
23221 + struct inode *dir;
23224 + * sbinfo is already locked, so this ii_read_lock is
23225 + * unnecessary. but our debugging feature checks it.
23227 + root = a->src_inode->i_sb->s_root;
23228 + if (root != a->src_parent && root != a->dst_parent) {
23229 + dir = d_inode(root);
23230 + ii_read_lock_parent3(dir);
23231 + a->h_root = au_hi(dir, a->btgt);
23232 + ii_read_unlock(dir);
23233 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23236 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23237 + a->dst_h_parent, a->dst_hdir);
23238 + udba = au_opt_udba(a->src_dentry->d_sb);
23239 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23240 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23241 + err = au_busy_or_stale();
23242 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23243 + err = au_h_verify(a->src_h_dentry, udba,
23244 + d_inode(a->src_h_parent), a->src_h_parent,
23246 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23247 + err = au_h_verify(a->dst_h_dentry, udba,
23248 + d_inode(a->dst_h_parent), a->dst_h_parent,
23251 + goto out; /* success */
23253 + err = au_busy_or_stale();
23254 + au_ren_unlock(a);
23260 +/* ---------------------------------------------------------------------- */
23262 +static void au_ren_refresh_dir(struct au_ren_args *a)
23264 + struct inode *dir;
23266 + dir = a->dst_dir;
23267 + inode_inc_iversion(dir);
23268 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23269 + /* is this updating defined in POSIX? */
23270 + au_cpup_attr_timesizes(a->src_inode);
23271 + au_cpup_attr_nlink(dir, /*force*/1);
23273 + au_dir_ts(dir, a->btgt);
23275 + if (a->exchange) {
23276 + dir = a->src_dir;
23277 + inode_inc_iversion(dir);
23278 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23279 + /* is this updating defined in POSIX? */
23280 + au_cpup_attr_timesizes(a->dst_inode);
23281 + au_cpup_attr_nlink(dir, /*force*/1);
23283 + au_dir_ts(dir, a->btgt);
23286 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23289 + dir = a->src_dir;
23290 + inode_inc_iversion(dir);
23291 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23292 + au_cpup_attr_nlink(dir, /*force*/1);
23293 + au_dir_ts(dir, a->btgt);
23296 +static void au_ren_refresh(struct au_ren_args *a)
23298 + aufs_bindex_t bbot, bindex;
23299 + struct dentry *d, *h_d;
23300 + struct inode *i, *h_i;
23301 + struct super_block *sb;
23303 + d = a->dst_dentry;
23306 + /* already dget-ed by au_ren_or_cpup() */
23307 + au_set_h_dptr(d, a->btgt, a->h_dst);
23309 + i = a->dst_inode;
23311 + if (!a->exchange) {
23312 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23313 + vfsub_drop_nlink(i);
23315 + vfsub_dead_dir(i);
23316 + au_cpup_attr_timesizes(i);
23318 + au_update_dbrange(d, /*do_put_zero*/1);
23320 + au_cpup_attr_nlink(i, /*force*/1);
23323 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23324 + au_set_h_dptr(d, bindex, NULL);
23325 + bbot = au_dbbot(d);
23326 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23327 + au_set_h_dptr(d, bindex, NULL);
23328 + au_update_dbrange(d, /*do_put_zero*/0);
23332 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23333 + d_drop(a->src_dentry);
23334 + if (au_ftest_ren(a->auren_flags, DIRREN))
23335 + au_set_dbwh(a->src_dentry, -1);
23339 + d = a->src_dentry;
23340 + au_set_dbwh(d, -1);
23341 + bbot = au_dbbot(d);
23342 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23343 + h_d = au_h_dptr(d, bindex);
23345 + au_set_h_dptr(d, bindex, NULL);
23347 + au_set_dbbot(d, a->btgt);
23350 + i = a->src_inode;
23351 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23352 + return; /* success */
23354 + bbot = au_ibbot(i);
23355 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23356 + h_i = au_h_iptr(i, bindex);
23358 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23359 + /* ignore this error */
23360 + au_set_h_iptr(i, bindex, NULL, 0);
23363 + au_set_ibbot(i, a->btgt);
23366 +/* ---------------------------------------------------------------------- */
23368 +/* mainly for link(2) and rename(2) */
23369 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23371 + aufs_bindex_t bdiropq, bwh;
23372 + struct dentry *parent;
23373 + struct au_branch *br;
23375 + parent = dentry->d_parent;
23376 + IMustLock(d_inode(parent)); /* dir is locked */
23378 + bdiropq = au_dbdiropq(parent);
23379 + bwh = au_dbwh(dentry);
23380 + br = au_sbr(dentry->d_sb, btgt);
23381 + if (au_br_rdonly(br)
23382 + || (0 <= bdiropq && bdiropq < btgt)
23383 + || (0 <= bwh && bwh < btgt))
23386 + AuDbg("btgt %d\n", btgt);
23390 +/* sets src_btop, dst_btop and btgt */
23391 +static int au_ren_wbr(struct au_ren_args *a)
23394 + struct au_wr_dir_args wr_dir_args = {
23395 + /* .force_btgt = -1, */
23396 + .flags = AuWrDir_ADD_ENTRY
23399 + a->src_btop = au_dbtop(a->src_dentry);
23400 + a->dst_btop = au_dbtop(a->dst_dentry);
23401 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23402 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23403 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23404 + wr_dir_args.force_btgt = a->src_btop;
23405 + if (a->dst_inode && a->dst_btop < a->src_btop)
23406 + wr_dir_args.force_btgt = a->dst_btop;
23407 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23408 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23411 + au_update_dbtop(a->dst_dentry);
23416 +static void au_ren_dt(struct au_ren_args *a)
23418 + a->h_path.dentry = a->src_h_parent;
23419 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23420 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23421 + a->h_path.dentry = a->dst_h_parent;
23422 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23425 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23426 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23430 + a->h_path.dentry = a->src_h_dentry;
23431 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23432 + if (d_is_positive(a->dst_h_dentry)) {
23433 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23434 + a->h_path.dentry = a->dst_h_dentry;
23435 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23439 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23441 + struct dentry *h_d;
23442 + struct inode *h_inode;
23444 + au_dtime_revert(a->src_dt + AuPARENT);
23445 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23446 + au_dtime_revert(a->dst_dt + AuPARENT);
23448 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23449 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23450 + h_inode = d_inode(h_d);
23451 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23452 + au_dtime_revert(a->src_dt + AuCHILD);
23453 + inode_unlock(h_inode);
23455 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23456 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23457 + h_inode = d_inode(h_d);
23458 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23459 + au_dtime_revert(a->dst_dt + AuCHILD);
23460 + inode_unlock(h_inode);
23465 +/* ---------------------------------------------------------------------- */
23467 +int aufs_rename(struct user_namespace *userns,
23468 + struct inode *_src_dir, struct dentry *_src_dentry,
23469 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23470 + unsigned int _flags)
23472 + int err, lock_flags;
23474 + /* reduce stack space */
23475 + struct au_ren_args *a;
23476 + struct au_pin pin;
23478 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23479 + IMustLock(_src_dir);
23480 + IMustLock(_dst_dir);
23483 + if (unlikely(_flags & RENAME_WHITEOUT))
23487 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23488 + a = kzalloc(sizeof(*a), GFP_NOFS);
23489 + if (unlikely(!a))
23492 + a->flags = _flags;
23493 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23494 + && RENAME_EXCHANGE > U8_MAX);
23495 + a->exchange = _flags & RENAME_EXCHANGE;
23496 + a->src_dir = _src_dir;
23497 + a->src_dentry = _src_dentry;
23498 + a->src_inode = NULL;
23499 + if (d_really_is_positive(a->src_dentry))
23500 + a->src_inode = d_inode(a->src_dentry);
23501 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23502 + a->dst_dir = _dst_dir;
23503 + a->dst_dentry = _dst_dentry;
23504 + a->dst_inode = NULL;
23505 + if (d_really_is_positive(a->dst_dentry))
23506 + a->dst_inode = d_inode(a->dst_dentry);
23507 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23508 + if (a->dst_inode) {
23510 + * if EXCHANGE && src is non-dir && dst is dir,
23511 + * dst is not locked.
23513 + /* IMustLock(a->dst_inode); */
23514 + au_igrab(a->dst_inode);
23518 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23519 + if (d_is_dir(a->src_dentry)) {
23520 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23521 + if (unlikely(!a->exchange
23522 + && d_really_is_positive(a->dst_dentry)
23523 + && !d_is_dir(a->dst_dentry)))
23525 + lock_flags |= AuLock_DIRS;
23527 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23528 + au_fset_ren(a->auren_flags, ISDIR_DST);
23529 + if (unlikely(!a->exchange
23530 + && d_really_is_positive(a->src_dentry)
23531 + && !d_is_dir(a->src_dentry)))
23533 + lock_flags |= AuLock_DIRS;
23535 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23537 + if (unlikely(err))
23540 + err = au_d_hashed_positive(a->src_dentry);
23541 + if (unlikely(err))
23544 + if (a->dst_inode) {
23546 + * If it is a dir, VFS unhash it before this
23547 + * function. It means we cannot rely upon d_unhashed().
23549 + if (unlikely(!a->dst_inode->i_nlink))
23551 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23552 + err = au_d_hashed_positive(a->dst_dentry);
23553 + if (unlikely(err && !a->exchange))
23555 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23557 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23561 + * is it possible?
23562 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23563 + * there may exist a problem somewhere else.
23566 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23569 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23570 + di_write_lock_parent(a->dst_parent);
23572 + /* which branch we process */
23573 + err = au_ren_wbr(a);
23574 + if (unlikely(err < 0))
23576 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23577 + a->h_path.mnt = au_br_mnt(a->br);
23579 + /* are they available to be renamed */
23580 + err = au_ren_may_dir(a);
23581 + if (unlikely(err))
23582 + goto out_children;
23584 + /* prepare the writable parent dir on the same branch */
23585 + if (a->dst_btop == a->btgt) {
23586 + au_fset_ren(a->auren_flags, WHDST);
23588 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23589 + if (unlikely(err))
23590 + goto out_children;
23594 + if (!a->exchange) {
23595 + if (a->src_dir != a->dst_dir) {
23597 + * this temporary unlock is safe,
23598 + * because both dir->i_mutex are locked.
23600 + di_write_unlock(a->dst_parent);
23601 + di_write_lock_parent(a->src_parent);
23602 + err = au_wr_dir_need_wh(a->src_dentry,
23603 + au_ftest_ren(a->auren_flags,
23606 + di_write_unlock(a->src_parent);
23607 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23609 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23611 + err = au_wr_dir_need_wh(a->src_dentry,
23612 + au_ftest_ren(a->auren_flags,
23616 + if (unlikely(err < 0))
23617 + goto out_children;
23619 + au_fset_ren(a->auren_flags, WHSRC);
23622 + if (a->src_btop != a->btgt) {
23623 + err = au_pin(&pin, a->src_dentry, a->btgt,
23624 + au_opt_udba(a->src_dentry->d_sb),
23625 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23627 + struct au_cp_generic cpg = {
23628 + .dentry = a->src_dentry,
23630 + .bsrc = a->src_btop,
23633 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23635 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23636 + err = au_sio_cpup_simple(&cpg);
23639 + if (unlikely(err))
23640 + goto out_children;
23641 + a->src_btop = a->btgt;
23642 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23643 + if (!a->exchange)
23644 + au_fset_ren(a->auren_flags, WHSRC);
23648 + if (a->exchange && a->dst_inode
23649 + && a->dst_btop != a->btgt) {
23650 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23651 + au_opt_udba(a->dst_dentry->d_sb),
23652 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23654 + struct au_cp_generic cpg = {
23655 + .dentry = a->dst_dentry,
23657 + .bsrc = a->dst_btop,
23660 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23662 + err = au_sio_cpup_simple(&cpg);
23665 + if (unlikely(err))
23666 + goto out_children;
23667 + a->dst_btop = a->btgt;
23668 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23671 + /* lock them all */
23672 + err = au_ren_lock(a);
23673 + if (unlikely(err))
23674 + /* leave the copied-up one */
23675 + goto out_children;
23677 + if (!a->exchange) {
23678 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23679 + err = au_may_ren(a);
23680 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23681 + err = -ENAMETOOLONG;
23682 + if (unlikely(err))
23686 + /* store timestamps to be revertible */
23689 + /* store dirren info */
23690 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23691 + err = au_dr_rename(a->src_dentry, a->btgt,
23692 + &a->dst_dentry->d_name, &rev);
23694 + if (unlikely(err))
23699 + err = do_rename(a);
23700 + if (unlikely(err))
23703 + if (au_ftest_ren(a->auren_flags, DIRREN))
23704 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23706 + /* update dir attributes */
23707 + au_ren_refresh_dir(a);
23709 + /* dput/iput all lower dentries */
23710 + au_ren_refresh(a);
23712 + goto out_hdir; /* success */
23715 + if (au_ftest_ren(a->auren_flags, DIRREN))
23716 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23718 + au_ren_rev_dt(err, a);
23720 + au_ren_unlock(a);
23722 + au_nhash_wh_free(&a->whlist);
23723 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23724 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23725 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23726 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23730 + if (d_unhashed(a->src_dentry))
23731 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23732 + if (d_unhashed(a->dst_dentry))
23733 + au_fset_ren(a->auren_flags, DROPPED_DST);
23734 + if (!a->exchange)
23735 + d_move(a->src_dentry, a->dst_dentry);
23737 + d_exchange(a->src_dentry, a->dst_dentry);
23738 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23739 + d_drop(a->dst_dentry);
23741 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23742 + d_drop(a->src_dentry);
23744 + au_update_dbtop(a->dst_dentry);
23745 + if (!a->dst_inode)
23746 + d_drop(a->dst_dentry);
23748 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23749 + di_write_unlock(a->dst_parent);
23751 + di_write_unlock2(a->src_parent, a->dst_parent);
23753 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23755 + iput(a->dst_inode);
23757 + au_whtmp_rmdir_free(a->thargs);
23763 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23764 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23765 +++ linux/fs/aufs/Kconfig 2021-05-02 20:15:14.670004120 +0200
23767 +# SPDX-License-Identifier: GPL-2.0
23769 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23771 + Aufs is a stackable unification filesystem such as Unionfs,
23772 + which unifies several directories and provides a merged single
23774 + In the early days, aufs was entirely re-designed and
23775 + re-implemented Unionfs Version 1.x series. Introducing many
23776 + original ideas, approaches and improvements, it becomes totally
23777 + different from Unionfs while keeping the basic features.
23781 + prompt "Maximum number of branches"
23782 + default AUFS_BRANCH_MAX_127
23784 + Specifies the maximum number of branches (or member directories)
23785 + in a single aufs. The larger value consumes more system
23786 + resources and has a minor impact to performance.
23787 +config AUFS_BRANCH_MAX_127
23790 + Specifies the maximum number of branches (or member directories)
23791 + in a single aufs. The larger value consumes more system
23792 + resources and has a minor impact to performance.
23793 +config AUFS_BRANCH_MAX_511
23796 + Specifies the maximum number of branches (or member directories)
23797 + in a single aufs. The larger value consumes more system
23798 + resources and has a minor impact to performance.
23799 +config AUFS_BRANCH_MAX_1023
23802 + Specifies the maximum number of branches (or member directories)
23803 + in a single aufs. The larger value consumes more system
23804 + resources and has a minor impact to performance.
23805 +config AUFS_BRANCH_MAX_32767
23808 + Specifies the maximum number of branches (or member directories)
23809 + in a single aufs. The larger value consumes more system
23810 + resources and has a minor impact to performance.
23813 +config AUFS_SBILIST
23815 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23818 + Automatic configuration for internal use.
23819 + When aufs supports Magic SysRq or /proc, enabled automatically.
23821 +config AUFS_HNOTIFY
23822 + bool "Detect direct branch access (bypassing aufs)"
23824 + If you want to modify files on branches directly, eg. bypassing aufs,
23825 + and want aufs to detect the changes of them fully, then enable this
23826 + option and use 'udba=notify' mount option.
23827 + Currently there is only one available configuration, "fsnotify".
23828 + It will have a negative impact to the performance.
23829 + See detail in aufs.5.
23832 + prompt "method" if AUFS_HNOTIFY
23833 + default AUFS_HFSNOTIFY
23834 +config AUFS_HFSNOTIFY
23839 +config AUFS_EXPORT
23840 + bool "NFS-exportable aufs"
23841 + depends on EXPORTFS
23843 + If you want to export your mounted aufs via NFS, then enable this
23844 + option. There are several requirements for this configuration.
23845 + See detail in aufs.5.
23847 +config AUFS_INO_T_64
23849 + depends on AUFS_EXPORT
23850 + depends on 64BIT && !(ALPHA || S390)
23853 + Automatic configuration for internal use.
23854 + /* typedef unsigned long/int __kernel_ino_t */
23855 + /* alpha and s390x are int */
23858 + bool "support for XATTR/EA (including Security Labels)"
23860 + If your branch fs supports XATTR/EA and you want to make them
23861 + available in aufs too, then enable this opsion and specify the
23862 + branch attributes for EA.
23863 + See detail in aufs.5.
23866 + bool "File-based Hierarchical Storage Management"
23868 + Hierarchical Storage Management (or HSM) is a well-known feature
23869 + in the storage world. Aufs provides this feature as file-based.
23870 + with multiple branches.
23871 + These multiple branches are prioritized, ie. the topmost one
23872 + should be the fastest drive and be used heavily.
23875 + bool "Readdir in userspace"
23877 + Aufs has two methods to provide a merged view for a directory,
23878 + by a user-space library and by kernel-space natively. The latter
23879 + is always enabled but sometimes large and slow.
23880 + If you enable this option, install the library in aufs2-util
23881 + package, and set some environment variables for your readdir(3),
23882 + then the work will be handled in user-space which generally
23883 + shows better performance in most cases.
23884 + See detail in aufs.5.
23886 +config AUFS_DIRREN
23887 + bool "Workaround for rename(2)-ing a directory"
23889 + By default, aufs returns EXDEV error in renameing a dir who has
23890 + his child on the lower branch, since it is a bad idea to issue
23891 + rename(2) internally for every lower branch. But user may not
23892 + accept this behaviour. So here is a workaround to allow such
23893 + rename(2) and store some extra infromation on the writable
23894 + branch. Obviously this costs high (and I don't like it).
23895 + To use this feature, you need to enable this configuration AND
23896 + to specify the mount option `dirren.'
23897 + See details in aufs.5 and the design documents.
23900 + bool "Show whiteouts"
23902 + If you want to make the whiteouts in aufs visible, then enable
23903 + this option and specify 'shwh' mount option. Although it may
23904 + sounds like philosophy or something, but in technically it
23905 + simply shows the name of whiteout with keeping its behaviour.
23907 +config AUFS_BR_RAMFS
23908 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23910 + If you want to use ramfs as an aufs branch fs, then enable this
23911 + option. Generally tmpfs is recommended.
23912 + Aufs prohibited them to be a branch fs by default, because
23913 + initramfs becomes unusable after switch_root or something
23914 + generally. If you sets initramfs as an aufs branch and boot your
23915 + system by switch_root, you will meet a problem easily since the
23916 + files in initramfs may be inaccessible.
23917 + Unless you are going to use ramfs as an aufs branch fs without
23918 + switch_root or something, leave it N.
23920 +config AUFS_BR_FUSE
23921 + bool "Fuse fs as an aufs branch"
23922 + depends on FUSE_FS
23925 + If you want to use fuse-based userspace filesystem as an aufs
23926 + branch fs, then enable this option.
23927 + It implements the internal poll(2) operation which is
23928 + implemented by fuse only (curretnly).
23933 + Automatic configuration for internal use.
23935 +config AUFS_BR_HFSPLUS
23936 + bool "Hfsplus as an aufs branch"
23937 + depends on HFSPLUS_FS
23940 + If you want to use hfsplus fs as an aufs branch fs, then enable
23941 + this option. This option introduces a small overhead at
23942 + copying-up a file on hfsplus.
23944 +config AUFS_BDEV_LOOP
23946 + depends on BLK_DEV_LOOP
23949 + Automatic configuration for internal use.
23950 + Convert =[ym] into =y.
23953 + bool "Debug aufs"
23955 + Enable this to compile aufs internal debug code.
23956 + It will have a negative impact to the performance.
23958 +config AUFS_MAGIC_SYSRQ
23960 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23963 + Automatic configuration for internal use.
23964 + When aufs supports Magic SysRq, enabled automatically.
23966 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23967 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23968 +++ linux/fs/aufs/lcnt.h 2021-05-02 20:15:14.673337458 +0200
23970 +/* SPDX-License-Identifier: GPL-2.0 */
23972 + * Copyright (C) 2018-2020 Junjiro R. Okajima
23974 + * This program, aufs is free software; you can redistribute it and/or modify
23975 + * it under the terms of the GNU General Public License as published by
23976 + * the Free Software Foundation; either version 2 of the License, or
23977 + * (at your option) any later version.
23979 + * This program is distributed in the hope that it will be useful,
23980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23982 + * GNU General Public License for more details.
23984 + * You should have received a copy of the GNU General Public License
23985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23989 + * simple long counter wrapper
23992 +#ifndef __AUFS_LCNT_H__
23993 +#define __AUFS_LCNT_H__
23997 +#include "debug.h"
23999 +#define AuLCntATOMIC 1
24000 +#define AuLCntPCPUCNT 2
24002 + * why does percpu_refcount require extra synchronize_rcu()s in
24003 + * au_br_do_free()
24005 +#define AuLCntPCPUREF 3
24007 +/* #define AuLCntChosen AuLCntATOMIC */
24008 +#define AuLCntChosen AuLCntPCPUCNT
24009 +/* #define AuLCntChosen AuLCntPCPUREF */
24011 +#if AuLCntChosen == AuLCntATOMIC
24012 +#include <linux/atomic.h>
24014 +typedef atomic_long_t au_lcnt_t;
24016 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24018 + atomic_long_set(cnt, 0);
24022 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24027 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24028 + int do_sync __maybe_unused)
24033 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24035 + atomic_long_inc(cnt);
24038 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24040 + atomic_long_dec(cnt);
24043 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24045 + return atomic_long_read(cnt);
24049 +#if AuLCntChosen == AuLCntPCPUCNT
24050 +#include <linux/percpu_counter.h>
24052 +typedef struct percpu_counter au_lcnt_t;
24054 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24056 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24059 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24064 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24066 + percpu_counter_destroy(cnt);
24069 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24071 + percpu_counter_inc(cnt);
24074 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24076 + percpu_counter_dec(cnt);
24079 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24083 + n = percpu_counter_sum(cnt);
24085 + if (LONG_MAX != LLONG_MAX
24087 + AuWarn1("%s\n", "wrap-around");
24093 +#if AuLCntChosen == AuLCntPCPUREF
24094 +#include <linux/percpu-refcount.h>
24096 +typedef struct percpu_ref au_lcnt_t;
24098 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24101 + release = percpu_ref_exit;
24102 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24105 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24107 + synchronize_rcu();
24110 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24112 + percpu_ref_kill(cnt);
24114 + au_lcnt_wait_for_fin(cnt);
24117 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24119 + percpu_ref_get(cnt);
24122 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24124 + percpu_ref_put(cnt);
24128 + * avoid calling this func as possible.
24130 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24134 + percpu_ref_switch_to_atomic_sync(cnt);
24135 + l = atomic_long_read(&cnt->count);
24137 + percpu_ref_switch_to_percpu(cnt);
24139 + /* percpu_ref is initialized by 1 instead of 0 */
24144 +#ifdef CONFIG_AUFS_DEBUG
24145 +#define AuLCntZero(val) do { \
24148 + AuDbg("%s = %ld\n", #val, l); \
24151 +#define AuLCntZero(val) do {} while (0)
24154 +#endif /* __KERNEL__ */
24155 +#endif /* __AUFS_LCNT_H__ */
24156 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24157 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24158 +++ linux/fs/aufs/loop.c 2021-05-02 20:15:14.673337458 +0200
24160 +// SPDX-License-Identifier: GPL-2.0
24162 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24164 + * This program, aufs is free software; you can redistribute it and/or modify
24165 + * it under the terms of the GNU General Public License as published by
24166 + * the Free Software Foundation; either version 2 of the License, or
24167 + * (at your option) any later version.
24169 + * This program is distributed in the hope that it will be useful,
24170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24172 + * GNU General Public License for more details.
24174 + * You should have received a copy of the GNU General Public License
24175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24179 + * support for loopback block device as a branch
24184 +/* added into drivers/block/loop.c */
24185 +static struct file *(*backing_file_func)(struct super_block *sb);
24188 + * test if two lower dentries have overlapping branches.
24190 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24192 + struct super_block *h_sb;
24193 + struct file *backing_file;
24195 + if (unlikely(!backing_file_func)) {
24196 + /* don't load "loop" module here */
24197 + backing_file_func = symbol_get(loop_backing_file);
24198 + if (unlikely(!backing_file_func))
24199 + /* "loop" module is not loaded */
24203 + h_sb = h_adding->d_sb;
24204 + backing_file = backing_file_func(h_sb);
24205 + if (!backing_file)
24208 + h_adding = backing_file->f_path.dentry;
24210 + * h_adding can be local NFS.
24211 + * in this case aufs cannot detect the loop.
24213 + if (unlikely(h_adding->d_sb == sb))
24215 + return !!au_test_subdir(h_adding, sb->s_root);
24218 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24219 +int au_test_loopback_kthread(void)
24222 + struct task_struct *tsk = current;
24223 + char c, comm[sizeof(tsk->comm)];
24226 + if (tsk->flags & PF_KTHREAD) {
24227 + get_task_comm(comm, tsk);
24229 + ret = ('0' <= c && c <= '9'
24230 + && !strncmp(comm, "loop", 4));
24236 +/* ---------------------------------------------------------------------- */
24238 +#define au_warn_loopback_step 16
24239 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24240 +static unsigned long *au_warn_loopback_array;
24242 +void au_warn_loopback(struct super_block *h_sb)
24244 + int i, new_nelem;
24245 + unsigned long *a, magic;
24246 + static DEFINE_SPINLOCK(spin);
24248 + magic = h_sb->s_magic;
24249 + spin_lock(&spin);
24250 + a = au_warn_loopback_array;
24251 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24252 + if (a[i] == magic) {
24253 + spin_unlock(&spin);
24257 + /* h_sb is new to us, print it */
24258 + if (i < au_warn_loopback_nelem) {
24263 + /* expand the array */
24264 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24265 + a = au_kzrealloc(au_warn_loopback_array,
24266 + au_warn_loopback_nelem * sizeof(unsigned long),
24267 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24268 + /*may_shrink*/0);
24270 + au_warn_loopback_nelem = new_nelem;
24271 + au_warn_loopback_array = a;
24276 + spin_unlock(&spin);
24277 + AuWarn1("realloc failed, ignored\n");
24281 + spin_unlock(&spin);
24282 + pr_warn("you may want to try another patch for loopback file "
24283 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24286 +int au_loopback_init(void)
24289 + struct super_block *sb __maybe_unused;
24291 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24294 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24295 + sizeof(unsigned long), GFP_NOFS);
24296 + if (unlikely(!au_warn_loopback_array))
24302 +void au_loopback_fin(void)
24304 + if (backing_file_func)
24305 + symbol_put(loop_backing_file);
24306 + au_kfree_try_rcu(au_warn_loopback_array);
24308 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24309 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24310 +++ linux/fs/aufs/loop.h 2021-05-02 20:15:14.673337458 +0200
24312 +/* SPDX-License-Identifier: GPL-2.0 */
24314 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24316 + * This program, aufs is free software; you can redistribute it and/or modify
24317 + * it under the terms of the GNU General Public License as published by
24318 + * the Free Software Foundation; either version 2 of the License, or
24319 + * (at your option) any later version.
24321 + * This program is distributed in the hope that it will be useful,
24322 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24323 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24324 + * GNU General Public License for more details.
24326 + * You should have received a copy of the GNU General Public License
24327 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24331 + * support for loopback mount as a branch
24334 +#ifndef __AUFS_LOOP_H__
24335 +#define __AUFS_LOOP_H__
24340 +struct super_block;
24342 +#ifdef CONFIG_AUFS_BDEV_LOOP
24343 +/* drivers/block/loop.c */
24344 +struct file *loop_backing_file(struct super_block *sb);
24347 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24348 +int au_test_loopback_kthread(void);
24349 +void au_warn_loopback(struct super_block *h_sb);
24351 +int au_loopback_init(void);
24352 +void au_loopback_fin(void);
24354 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24356 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24357 + struct dentry *h_adding)
24358 +AuStubInt0(au_test_loopback_kthread, void)
24359 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24361 +AuStubInt0(au_loopback_init, void)
24362 +AuStubVoid(au_loopback_fin, void)
24363 +#endif /* BLK_DEV_LOOP */
24365 +#endif /* __KERNEL__ */
24366 +#endif /* __AUFS_LOOP_H__ */
24367 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24368 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24369 +++ linux/fs/aufs/magic.mk 2021-05-02 20:15:14.673337458 +0200
24371 +# SPDX-License-Identifier: GPL-2.0
24373 +# defined in ${srctree}/fs/fuse/inode.c
24375 +ifdef CONFIG_FUSE_FS
24376 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24379 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24381 +ifdef CONFIG_XFS_FS
24382 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24385 +# defined in ${srctree}/fs/configfs/mount.c
24387 +ifdef CONFIG_CONFIGFS_FS
24388 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24391 +# defined in ${srctree}/fs/ubifs/ubifs.h
24393 +ifdef CONFIG_UBIFS_FS
24394 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24397 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24399 +ifdef CONFIG_HFSPLUS_FS
24400 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24402 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24403 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24404 +++ linux/fs/aufs/Makefile 2021-05-02 20:15:14.670004120 +0200
24406 +# SPDX-License-Identifier: GPL-2.0
24408 +include ${src}/magic.mk
24409 +ifeq (${CONFIG_AUFS_FS},m)
24410 +include ${src}/conf.mk
24412 +-include ${src}/priv_def.mk
24414 +# cf. include/linux/kernel.h
24416 +ccflags-y += -DDEBUG
24417 +# sparse requires the full pathname
24419 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24421 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24424 +obj-$(CONFIG_AUFS_FS) += aufs.o
24425 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24426 + wkq.o vfsub.o dcsub.o \
24427 + cpup.o whout.o wbr_policy.o \
24428 + dinfo.o dentry.o \
24430 + finfo.o file.o f_op.o \
24432 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24436 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24437 +aufs-$(CONFIG_SYSFS) += sysfs.o
24438 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24439 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24440 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24441 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24442 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24443 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24444 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24445 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24446 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24447 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24448 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24449 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24450 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24451 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24452 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24453 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24454 +++ linux/fs/aufs/module.c 2021-05-02 20:15:14.673337458 +0200
24456 +// SPDX-License-Identifier: GPL-2.0
24458 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24460 + * This program, aufs is free software; you can redistribute it and/or modify
24461 + * it under the terms of the GNU General Public License as published by
24462 + * the Free Software Foundation; either version 2 of the License, or
24463 + * (at your option) any later version.
24465 + * This program is distributed in the hope that it will be useful,
24466 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24467 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24468 + * GNU General Public License for more details.
24470 + * You should have received a copy of the GNU General Public License
24471 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24475 + * module global variables and operations
24478 +#include <linux/module.h>
24479 +#include <linux/seq_file.h>
24482 +/* shrinkable realloc */
24483 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24491 +#if 0 /* unused */
24498 + AuDebugOn(!new_sz);
24501 + diff = au_kmidx_sub(sz, new_sz);
24507 + /* expand or SLOB */
24508 + p = krealloc(p, new_sz, gfp);
24509 + else if (new_sz < sz && may_shrink) {
24513 + q = kmalloc(new_sz, gfp);
24516 + memcpy(q, p, new_sz);
24517 + au_kfree_try_rcu(p);
24528 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24531 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24532 + if (p && new_sz > nused)
24533 + memset(p + nused, 0, new_sz - nused);
24537 +/* ---------------------------------------------------------------------- */
24541 +struct kmem_cache *au_cache[AuCache_Last];
24543 +static void au_cache_fin(void)
24548 + * Make sure all delayed rcu free inodes are flushed before we
24553 + /* excluding AuCache_HNOTIFY */
24554 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24555 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24556 + kmem_cache_destroy(au_cache[i]);
24557 + au_cache[i] = NULL;
24561 +static int __init au_cache_init(void)
24563 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24564 + if (au_cache[AuCache_DINFO])
24565 + /* SLAB_DESTROY_BY_RCU */
24566 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24567 + au_icntnr_init_once);
24568 + if (au_cache[AuCache_ICNTNR])
24569 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24570 + au_fi_init_once);
24571 + if (au_cache[AuCache_FINFO])
24572 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24573 + if (au_cache[AuCache_VDIR])
24574 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24575 + if (au_cache[AuCache_DEHSTR])
24582 +/* ---------------------------------------------------------------------- */
24584 +int au_dir_roflags;
24586 +#ifdef CONFIG_AUFS_SBILIST
24588 + * iterate_supers_type() doesn't protect us from
24589 + * remounting (branch management)
24591 +struct hlist_bl_head au_sbilist;
24595 + * functions for module interface.
24597 +MODULE_LICENSE("GPL");
24598 +/* MODULE_LICENSE("GPL v2"); */
24599 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24600 +MODULE_DESCRIPTION(AUFS_NAME
24601 + " -- Advanced multi layered unification filesystem");
24602 +MODULE_VERSION(AUFS_VERSION);
24603 +MODULE_ALIAS_FS(AUFS_NAME);
24605 +/* this module parameter has no meaning when SYSFS is disabled */
24606 +int sysaufs_brs = 1;
24607 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24608 +module_param_named(brs, sysaufs_brs, int, 0444);
24610 +/* this module parameter has no meaning when USER_NS is disabled */
24612 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24613 +module_param_named(allow_userns, au_userns, bool, 0444);
24615 +/* ---------------------------------------------------------------------- */
24617 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24619 +int au_seq_path(struct seq_file *seq, struct path *path)
24623 + err = seq_path(seq, path, au_esc_chars);
24632 +/* ---------------------------------------------------------------------- */
24634 +static int __init aufs_init(void)
24639 + p = au_esc_chars;
24640 + for (i = 1; i <= ' '; i++)
24646 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24648 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24649 + for (i = 0; i < AuIop_Last; i++)
24650 + aufs_iop_nogetattr[i].getattr = NULL;
24652 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24654 + au_sbilist_init();
24655 + sysaufs_brs_init();
24658 + err = sysaufs_init();
24659 + if (unlikely(err))
24661 + err = dbgaufs_init();
24662 + if (unlikely(err))
24663 + goto out_sysaufs;
24664 + err = au_procfs_init();
24665 + if (unlikely(err))
24666 + goto out_dbgaufs;
24667 + err = au_wkq_init();
24668 + if (unlikely(err))
24670 + err = au_loopback_init();
24671 + if (unlikely(err))
24673 + err = au_hnotify_init();
24674 + if (unlikely(err))
24675 + goto out_loopback;
24676 + err = au_sysrq_init();
24677 + if (unlikely(err))
24679 + err = au_cache_init();
24680 + if (unlikely(err))
24683 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24684 + err = register_filesystem(&aufs_fs_type);
24685 + if (unlikely(err))
24688 + /* since we define pr_fmt, call printk directly */
24689 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24690 + goto out; /* success */
24697 + au_hnotify_fin();
24699 + au_loopback_fin();
24713 +static void __exit aufs_exit(void)
24715 + unregister_filesystem(&aufs_fs_type);
24718 + au_hnotify_fin();
24719 + au_loopback_fin();
24727 +module_init(aufs_init);
24728 +module_exit(aufs_exit);
24729 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24730 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24731 +++ linux/fs/aufs/module.h 2021-05-02 20:15:14.673337458 +0200
24733 +/* SPDX-License-Identifier: GPL-2.0 */
24735 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24737 + * This program, aufs is free software; you can redistribute it and/or modify
24738 + * it under the terms of the GNU General Public License as published by
24739 + * the Free Software Foundation; either version 2 of the License, or
24740 + * (at your option) any later version.
24742 + * This program is distributed in the hope that it will be useful,
24743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24745 + * GNU General Public License for more details.
24747 + * You should have received a copy of the GNU General Public License
24748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24752 + * module initialization and module-global
24755 +#ifndef __AUFS_MODULE_H__
24756 +#define __AUFS_MODULE_H__
24760 +#include <linux/slab.h>
24761 +#include "debug.h"
24762 +#include "dentry.h"
24765 +#include "inode.h"
24770 +/* module parameters */
24771 +extern int sysaufs_brs;
24772 +extern bool au_userns;
24774 +/* ---------------------------------------------------------------------- */
24776 +extern int au_dir_roflags;
24778 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24779 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24783 + * Comparing the size of the object with sizeof(struct rcu_head)
24784 + * case 1: object is always larger
24785 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24786 + * case 2: object is always smaller
24787 + * --> au_kfree_small()
24788 + * case 3: object can be any size
24789 + * --> au_kfree_try_rcu()
24792 +static inline void au_kfree_do_rcu(const void *p)
24795 + struct rcu_head rcu;
24796 + } *a = (void *)p;
24798 + kfree_rcu(a, rcu);
24801 +#define au_kfree_rcu(_p) do { \
24802 + typeof(_p) p = (_p); \
24803 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24805 + au_kfree_do_rcu(p); \
24808 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24809 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24811 +static inline void au_kfree_try_rcu(const void *p)
24815 + if (au_kfree_sz_test(p))
24816 + au_kfree_do_rcu(p);
24821 +static inline void au_kfree_small(const void *p)
24825 + AuDebugOn(au_kfree_sz_test(p));
24829 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24831 +#ifndef CONFIG_SLOB
24832 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24834 + return -1; /* SLOB is untested */
24838 +int au_seq_path(struct seq_file *seq, struct path *path);
24840 +#ifdef CONFIG_PROC_FS
24842 +int __init au_procfs_init(void);
24843 +void au_procfs_fin(void);
24845 +AuStubInt0(au_procfs_init, void);
24846 +AuStubVoid(au_procfs_fin, void);
24849 +/* ---------------------------------------------------------------------- */
24858 + AuCache_HNOTIFY, /* must be last */
24862 +extern struct kmem_cache *au_cache[AuCache_Last];
24864 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24865 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24866 +#define AuCacheCtor(type, ctor) \
24867 + kmem_cache_create(#type, sizeof(struct type), \
24868 + __alignof__(struct type), AuCacheFlags, ctor)
24870 +#define AuCacheFuncs(name, index) \
24871 + static inline struct au_##name *au_cache_alloc_##name(void) \
24872 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24873 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24874 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24876 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24877 + { void *p = rcu; \
24878 + p -= offsetof(struct au_##name, rcu); \
24879 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24880 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24881 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24882 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24884 + static inline void au_cache_free_##name(struct au_##name *p) \
24885 + { /* au_cache_free_##name##_norcu(p); */ \
24886 + au_cache_free_##name##_rcu(p); }
24888 +AuCacheFuncs(dinfo, DINFO);
24889 +AuCacheFuncs(icntnr, ICNTNR);
24890 +AuCacheFuncs(finfo, FINFO);
24891 +AuCacheFuncs(vdir, VDIR);
24892 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24893 +#ifdef CONFIG_AUFS_HNOTIFY
24894 +AuCacheFuncs(hnotify, HNOTIFY);
24897 +#endif /* __KERNEL__ */
24898 +#endif /* __AUFS_MODULE_H__ */
24899 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24900 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24901 +++ linux/fs/aufs/mvdown.c 2021-05-02 20:15:14.673337458 +0200
24903 +// SPDX-License-Identifier: GPL-2.0
24905 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24907 + * This program, aufs is free software; you can redistribute it and/or modify
24908 + * it under the terms of the GNU General Public License as published by
24909 + * the Free Software Foundation; either version 2 of the License, or
24910 + * (at your option) any later version.
24912 + * This program is distributed in the hope that it will be useful,
24913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24915 + * GNU General Public License for more details.
24917 + * You should have received a copy of the GNU General Public License
24918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24922 + * move-down, opposite of copy-up
24927 +struct au_mvd_args {
24929 + struct super_block *h_sb;
24930 + struct dentry *h_parent;
24931 + struct au_hinode *hdir;
24932 + struct inode *h_dir, *h_inode;
24933 + struct au_pin pin;
24934 + } info[AUFS_MVDOWN_NARRAY];
24936 + struct aufs_mvdown mvdown;
24937 + struct dentry *dentry, *parent;
24938 + struct inode *inode, *dir;
24939 + struct super_block *sb;
24940 + aufs_bindex_t bopq, bwh, bfound;
24941 + unsigned char rename_lock;
24944 +#define mvd_errno mvdown.au_errno
24945 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24946 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24947 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24948 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24950 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24951 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24952 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24953 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24954 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24955 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24957 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24958 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24959 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24960 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24961 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24962 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24964 +#define AU_MVD_PR(flag, ...) do { \
24966 + pr_err(__VA_ARGS__); \
24969 +static int find_lower_writable(struct au_mvd_args *a)
24971 + struct super_block *sb;
24972 + aufs_bindex_t bindex, bbot;
24973 + struct au_branch *br;
24976 + bindex = a->mvd_bsrc;
24977 + bbot = au_sbbot(sb);
24978 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24979 + for (bindex++; bindex <= bbot; bindex++) {
24980 + br = au_sbr(sb, bindex);
24981 + if (au_br_fhsm(br->br_perm)
24982 + && !sb_rdonly(au_br_sb(br)))
24985 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24986 + for (bindex++; bindex <= bbot; bindex++) {
24987 + br = au_sbr(sb, bindex);
24988 + if (!au_br_rdonly(br))
24992 + for (bindex++; bindex <= bbot; bindex++) {
24993 + br = au_sbr(sb, bindex);
24994 + if (!sb_rdonly(au_br_sb(br))) {
24995 + if (au_br_rdonly(br))
24997 + |= AUFS_MVDOWN_ROLOWER_R;
25005 +/* make the parent dir on bdst */
25006 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25011 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25012 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25013 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25014 + a->mvd_h_dst_parent = NULL;
25015 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25016 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25017 + if (!a->mvd_h_dst_parent) {
25018 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25019 + if (unlikely(err)) {
25020 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25023 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25031 +/* lock them all */
25032 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25035 + struct dentry *h_trap;
25037 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25038 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25039 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25040 + au_opt_udba(a->sb),
25041 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25043 + if (unlikely(err)) {
25044 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25048 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25049 + a->rename_lock = 0;
25050 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25051 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25052 + au_opt_udba(a->sb),
25053 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25054 + err = au_do_pin(&a->mvd_pin_src);
25056 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25057 + if (unlikely(err)) {
25058 + AU_MVD_PR(dmsg, "pin_src failed\n");
25061 + goto out; /* success */
25064 + a->rename_lock = 1;
25065 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25066 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25067 + au_opt_udba(a->sb),
25068 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25070 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25071 + if (unlikely(err)) {
25072 + AU_MVD_PR(dmsg, "pin_src failed\n");
25073 + au_pin_hdir_lock(&a->mvd_pin_dst);
25076 + au_pin_hdir_unlock(&a->mvd_pin_src);
25077 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25078 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25080 + err = (h_trap != a->mvd_h_src_parent);
25082 + err = (h_trap != a->mvd_h_dst_parent);
25084 + BUG_ON(err); /* it should never happen */
25085 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25088 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25089 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25090 + au_pin_hdir_lock(&a->mvd_pin_src);
25091 + au_unpin(&a->mvd_pin_src);
25092 + au_pin_hdir_lock(&a->mvd_pin_dst);
25095 + goto out; /* success */
25098 + au_unpin(&a->mvd_pin_dst);
25104 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25106 + if (!a->rename_lock)
25107 + au_unpin(&a->mvd_pin_src);
25109 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25110 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25111 + au_pin_hdir_lock(&a->mvd_pin_src);
25112 + au_unpin(&a->mvd_pin_src);
25113 + au_pin_hdir_lock(&a->mvd_pin_dst);
25115 + au_unpin(&a->mvd_pin_dst);
25118 +/* copy-down the file */
25119 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25122 + struct au_cp_generic cpg = {
25123 + .dentry = a->dentry,
25124 + .bdst = a->mvd_bdst,
25125 + .bsrc = a->mvd_bsrc,
25127 + .pin = &a->mvd_pin_dst,
25128 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25131 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25132 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25133 + au_fset_cpup(cpg.flags, OVERWRITE);
25134 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25135 + au_fset_cpup(cpg.flags, RWDST);
25136 + err = au_sio_cpdown_simple(&cpg);
25137 + if (unlikely(err))
25138 + AU_MVD_PR(dmsg, "cpdown failed\n");
25145 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25148 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25151 + struct path h_path;
25152 + struct au_branch *br;
25153 + struct inode *delegated;
25155 + br = au_sbr(a->sb, a->mvd_bdst);
25156 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25157 + err = PTR_ERR(h_path.dentry);
25158 + if (IS_ERR(h_path.dentry)) {
25159 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25164 + if (d_is_positive(h_path.dentry)) {
25165 + h_path.mnt = au_br_mnt(br);
25166 + delegated = NULL;
25167 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25168 + &delegated, /*force*/0);
25169 + if (unlikely(err == -EWOULDBLOCK)) {
25170 + pr_warn("cannot retry for NFSv4 delegation"
25171 + " for an internal unlink\n");
25174 + if (unlikely(err))
25175 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25177 + dput(h_path.dentry);
25185 + * unlink the topmost h_dentry
25187 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25190 + struct path h_path;
25191 + struct inode *delegated;
25193 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25194 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25195 + delegated = NULL;
25196 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25197 + if (unlikely(err == -EWOULDBLOCK)) {
25198 + pr_warn("cannot retry for NFSv4 delegation"
25199 + " for an internal unlink\n");
25202 + if (unlikely(err))
25203 + AU_MVD_PR(dmsg, "unlink failed\n");
25209 +/* Since mvdown succeeded, we ignore an error of this function */
25210 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25213 + struct au_branch *br;
25215 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25216 + br = au_sbr(a->sb, a->mvd_bsrc);
25217 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25219 + br = au_sbr(a->sb, a->mvd_bdst);
25220 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25221 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25224 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25226 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25230 + * copy-down the file and unlink the bsrc file.
25231 + * - unlink the bdst whout if exist
25232 + * - copy-down the file (with whtmp name and rename)
25233 + * - unlink the bsrc file
25235 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25239 + err = au_do_mkdir(dmsg, a);
25241 + err = au_do_lock(dmsg, a);
25242 + if (unlikely(err))
25246 + * do not revert the activities we made on bdst since they should be
25247 + * harmless in aufs.
25250 + err = au_do_cpdown(dmsg, a);
25252 + err = au_do_unlink_wh(dmsg, a);
25253 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25254 + err = au_do_unlink(dmsg, a);
25255 + if (unlikely(err))
25258 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25259 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25260 + if (find_lower_writable(a) < 0)
25261 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25263 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25264 + au_do_stfs(dmsg, a);
25266 + /* maintain internal array */
25267 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25268 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25269 + au_set_dbtop(a->dentry, a->mvd_bdst);
25270 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25271 + au_set_ibtop(a->inode, a->mvd_bdst);
25273 + /* hide the lower */
25274 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25275 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25276 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25277 + au_set_ibbot(a->inode, a->mvd_bsrc);
25279 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25280 + au_set_dbbot(a->dentry, a->mvd_bdst);
25281 + if (au_ibbot(a->inode) < a->mvd_bdst)
25282 + au_set_ibbot(a->inode, a->mvd_bdst);
25285 + au_do_unlock(dmsg, a);
25291 +/* ---------------------------------------------------------------------- */
25293 +/* make sure the file is idle */
25294 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25296 + int err, plinked;
25299 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25300 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25301 + && au_dcount(a->dentry) == 1
25302 + && atomic_read(&a->inode->i_count) == 1
25303 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25304 + && (!plinked || !au_plink_test(a->inode))
25305 + && a->inode->i_nlink == 1)
25310 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25311 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25312 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25313 + a->mvd_h_src_inode->i_nlink,
25314 + plinked, plinked ? au_plink_test(a->inode) : 0);
25321 +/* make sure the parent dir is fine */
25322 +static int au_mvd_args_parent(const unsigned char dmsg,
25323 + struct au_mvd_args *a)
25326 + aufs_bindex_t bindex;
25329 + if (unlikely(au_alive_dir(a->parent))) {
25331 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25335 + a->bopq = au_dbdiropq(a->parent);
25336 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25337 + AuDbg("b%d\n", bindex);
25338 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25339 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25341 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25342 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25343 + a->bopq, a->mvd_bdst);
25351 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25352 + struct au_mvd_args *a)
25355 + struct au_dinfo *dinfo, *tmp;
25357 + /* lookup the next lower positive entry */
25359 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25360 + if (unlikely(!tmp))
25365 + dinfo = au_di(a->dentry);
25366 + au_di_cp(tmp, dinfo);
25367 + au_di_swap(tmp, dinfo);
25369 + /* returns the number of positive dentries */
25370 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25371 + /* AuLkup_IGNORE_PERM */ 0);
25373 + a->bwh = au_dbwh(a->dentry);
25374 + else if (err > 0)
25375 + a->bfound = au_dbtop(a->dentry);
25377 + au_di_swap(tmp, dinfo);
25378 + au_rw_write_unlock(&tmp->di_rwsem);
25380 + if (unlikely(err < 0))
25381 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25384 + * here, we have these cases.
25386 + * no positive dentry under bsrc. there are more sub-cases.
25388 + * there no whiteout, we can safely move-down.
25391 + * bsrc < bwh && bwh < bdst
25392 + * there is a whiteout on RO branch. cannot proceed.
25394 + * there is a whiteout on the RW target branch. it should
25397 + * there is a whiteout somewhere unrelated branch.
25398 + * -1 < bfound && bfound <= bsrc
25401 + * found, but it is on RO branch between bsrc and bdst. cannot
25404 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25407 + * found, after we create the file on bdst, it will be hidden.
25410 + AuDebugOn(a->bfound == -1
25412 + && a->bwh <= a->mvd_bsrc);
25413 + AuDebugOn(-1 < a->bfound
25414 + && a->bfound <= a->mvd_bsrc);
25417 + if (a->bfound == -1
25418 + && a->mvd_bsrc < a->bwh
25420 + && a->bwh < a->mvd_bdst) {
25421 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25422 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25423 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25425 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25426 + a->mvd_errno = EAU_MVDOWN_UPPER;
25427 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25428 + a->mvd_bdst, a->bfound);
25432 + err = 0; /* success */
25439 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25444 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25445 + && a->bfound == a->mvd_bdst)
25451 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25454 + struct au_branch *br;
25457 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25461 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25462 + a->mvd_bsrc = au_ibtop(a->inode);
25464 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25465 + if (unlikely(a->mvd_bsrc < 0
25466 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25467 + || au_dbbot(a->dentry) < a->mvd_bsrc
25468 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25469 + || (a->mvd_bsrc < au_ibtop(a->inode)
25470 + || au_ibbot(a->inode) < a->mvd_bsrc
25471 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25472 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25473 + AU_MVD_PR(dmsg, "no upper\n");
25477 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25478 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25479 + AU_MVD_PR(dmsg, "on the bottom\n");
25482 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25483 + br = au_sbr(a->sb, a->mvd_bsrc);
25484 + err = au_br_rdonly(br);
25485 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25486 + if (unlikely(err))
25488 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25489 + || IS_APPEND(a->mvd_h_src_inode))) {
25491 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25497 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25498 + a->mvd_bdst = find_lower_writable(a);
25499 + if (unlikely(a->mvd_bdst < 0)) {
25500 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25501 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25505 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25506 + if (unlikely(a->mvd_bdst < 0
25507 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25508 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25509 + AU_MVD_PR(dmsg, "no lower brid\n");
25514 + err = au_mvd_args_busy(dmsg, a);
25516 + err = au_mvd_args_parent(dmsg, a);
25518 + err = au_mvd_args_intermediate(dmsg, a);
25520 + err = au_mvd_args_exist(dmsg, a);
25522 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25529 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25532 + unsigned char dmsg;
25533 + struct au_mvd_args *args;
25534 + struct inode *inode;
25536 + inode = d_inode(dentry);
25538 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25542 + args = kmalloc(sizeof(*args), GFP_NOFS);
25543 + if (unlikely(!args))
25546 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25548 + /* VERIFY_WRITE */
25549 + err = !access_ok(uarg, sizeof(*uarg));
25550 + if (unlikely(err)) {
25555 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25556 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25557 + args->mvdown.au_errno = 0;
25558 + args->dentry = dentry;
25559 + args->inode = inode;
25560 + args->sb = dentry->d_sb;
25563 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25564 + args->parent = dget_parent(dentry);
25565 + args->dir = d_inode(args->parent);
25566 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25567 + dput(args->parent);
25568 + if (unlikely(args->parent != dentry->d_parent)) {
25569 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25573 + inode_lock_nested(inode, I_MUTEX_CHILD);
25574 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25575 + if (unlikely(err))
25578 + di_write_lock_parent(args->parent);
25579 + err = au_mvd_args(dmsg, args);
25580 + if (unlikely(err))
25583 + err = au_do_mvdown(dmsg, args);
25584 + if (unlikely(err))
25587 + au_cpup_attr_timesizes(args->dir);
25588 + au_cpup_attr_timesizes(inode);
25589 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25590 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25591 + /* au_digen_dec(dentry); */
25594 + di_write_unlock(args->parent);
25595 + aufs_read_unlock(dentry, AuLock_DW);
25597 + inode_unlock(inode);
25599 + inode_unlock(args->dir);
25601 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25604 + au_kfree_rcu(args);
25609 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25610 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25611 +++ linux/fs/aufs/opts.c 2021-05-02 20:15:14.676670793 +0200
25613 +// SPDX-License-Identifier: GPL-2.0
25615 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25617 + * This program, aufs is free software; you can redistribute it and/or modify
25618 + * it under the terms of the GNU General Public License as published by
25619 + * the Free Software Foundation; either version 2 of the License, or
25620 + * (at your option) any later version.
25622 + * This program is distributed in the hope that it will be useful,
25623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25625 + * GNU General Public License for more details.
25627 + * You should have received a copy of the GNU General Public License
25628 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25632 + * mount options/flags
25635 +#include <linux/namei.h>
25636 +#include <linux/types.h> /* a distribution requires */
25637 +#include <linux/parser.h>
25640 +/* ---------------------------------------------------------------------- */
25644 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25645 + Opt_idel, Opt_imod,
25646 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25647 + Opt_rdblk_def, Opt_rdhash_def,
25648 + Opt_xino, Opt_noxino,
25649 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25650 + Opt_trunc_xino_path, Opt_itrunc_xino,
25651 + Opt_trunc_xib, Opt_notrunc_xib,
25652 + Opt_shwh, Opt_noshwh,
25653 + Opt_plink, Opt_noplink, Opt_list_plink,
25655 + Opt_dio, Opt_nodio,
25656 + Opt_diropq_a, Opt_diropq_w,
25657 + Opt_warn_perm, Opt_nowarn_perm,
25658 + Opt_wbr_copyup, Opt_wbr_create,
25660 + Opt_verbose, Opt_noverbose,
25661 + Opt_sum, Opt_nosum, Opt_wsum,
25662 + Opt_dirperm1, Opt_nodirperm1,
25663 + Opt_dirren, Opt_nodirren,
25664 + Opt_acl, Opt_noacl,
25665 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25668 +static match_table_t options = {
25669 + {Opt_br, "br=%s"},
25670 + {Opt_br, "br:%s"},
25672 + {Opt_add, "add=%d:%s"},
25673 + {Opt_add, "add:%d:%s"},
25674 + {Opt_add, "ins=%d:%s"},
25675 + {Opt_add, "ins:%d:%s"},
25676 + {Opt_append, "append=%s"},
25677 + {Opt_append, "append:%s"},
25678 + {Opt_prepend, "prepend=%s"},
25679 + {Opt_prepend, "prepend:%s"},
25681 + {Opt_del, "del=%s"},
25682 + {Opt_del, "del:%s"},
25683 + /* {Opt_idel, "idel:%d"}, */
25684 + {Opt_mod, "mod=%s"},
25685 + {Opt_mod, "mod:%s"},
25686 + /* {Opt_imod, "imod:%d:%s"}, */
25688 + {Opt_dirwh, "dirwh=%d"},
25690 + {Opt_xino, "xino=%s"},
25691 + {Opt_noxino, "noxino"},
25692 + {Opt_trunc_xino, "trunc_xino"},
25693 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25694 + {Opt_notrunc_xino, "notrunc_xino"},
25695 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25696 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25697 + /* {Opt_zxino, "zxino=%s"}, */
25698 + {Opt_trunc_xib, "trunc_xib"},
25699 + {Opt_notrunc_xib, "notrunc_xib"},
25701 +#ifdef CONFIG_PROC_FS
25702 + {Opt_plink, "plink"},
25704 + {Opt_ignore_silent, "plink"},
25707 + {Opt_noplink, "noplink"},
25709 +#ifdef CONFIG_AUFS_DEBUG
25710 + {Opt_list_plink, "list_plink"},
25713 + {Opt_udba, "udba=%s"},
25715 + {Opt_dio, "dio"},
25716 + {Opt_nodio, "nodio"},
25718 +#ifdef CONFIG_AUFS_DIRREN
25719 + {Opt_dirren, "dirren"},
25720 + {Opt_nodirren, "nodirren"},
25722 + {Opt_ignore, "dirren"},
25723 + {Opt_ignore_silent, "nodirren"},
25726 +#ifdef CONFIG_AUFS_FHSM
25727 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25729 + {Opt_ignore, "fhsm_sec=%d"},
25732 + {Opt_diropq_a, "diropq=always"},
25733 + {Opt_diropq_a, "diropq=a"},
25734 + {Opt_diropq_w, "diropq=whiteouted"},
25735 + {Opt_diropq_w, "diropq=w"},
25737 + {Opt_warn_perm, "warn_perm"},
25738 + {Opt_nowarn_perm, "nowarn_perm"},
25740 + /* keep them temporary */
25741 + {Opt_ignore_silent, "nodlgt"},
25742 + {Opt_ignore, "clean_plink"},
25744 +#ifdef CONFIG_AUFS_SHWH
25745 + {Opt_shwh, "shwh"},
25747 + {Opt_noshwh, "noshwh"},
25749 + {Opt_dirperm1, "dirperm1"},
25750 + {Opt_nodirperm1, "nodirperm1"},
25752 + {Opt_verbose, "verbose"},
25753 + {Opt_verbose, "v"},
25754 + {Opt_noverbose, "noverbose"},
25755 + {Opt_noverbose, "quiet"},
25756 + {Opt_noverbose, "q"},
25757 + {Opt_noverbose, "silent"},
25759 + {Opt_sum, "sum"},
25760 + {Opt_nosum, "nosum"},
25761 + {Opt_wsum, "wsum"},
25763 + {Opt_rdcache, "rdcache=%d"},
25764 + {Opt_rdblk, "rdblk=%d"},
25765 + {Opt_rdblk_def, "rdblk=def"},
25766 + {Opt_rdhash, "rdhash=%d"},
25767 + {Opt_rdhash_def, "rdhash=def"},
25769 + {Opt_wbr_create, "create=%s"},
25770 + {Opt_wbr_create, "create_policy=%s"},
25771 + {Opt_wbr_copyup, "cpup=%s"},
25772 + {Opt_wbr_copyup, "copyup=%s"},
25773 + {Opt_wbr_copyup, "copyup_policy=%s"},
25775 + /* generic VFS flag */
25776 +#ifdef CONFIG_FS_POSIX_ACL
25777 + {Opt_acl, "acl"},
25778 + {Opt_noacl, "noacl"},
25780 + {Opt_ignore, "acl"},
25781 + {Opt_ignore_silent, "noacl"},
25784 + /* internal use for the scripts */
25785 + {Opt_ignore_silent, "si=%s"},
25787 + {Opt_br, "dirs=%s"},
25788 + {Opt_ignore, "debug=%d"},
25789 + {Opt_ignore, "delete=whiteout"},
25790 + {Opt_ignore, "delete=all"},
25791 + {Opt_ignore, "imap=%s"},
25793 + /* temporary workaround, due to old mount(8)? */
25794 + {Opt_ignore_silent, "relatime"},
25799 +/* ---------------------------------------------------------------------- */
25801 +static const char *au_parser_pattern(int val, match_table_t tbl)
25803 + struct match_token *p;
25806 + while (p->pattern) {
25807 + if (p->token == val)
25808 + return p->pattern;
25815 +static const char *au_optstr(int *val, match_table_t tbl)
25817 + struct match_token *p;
25824 + while (p->pattern) {
25826 + && (v & p->token) == p->token) {
25827 + *val &= ~p->token;
25828 + return p->pattern;
25837 +/* ---------------------------------------------------------------------- */
25839 +static match_table_t brperm = {
25840 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25841 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25842 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25846 +static match_table_t brattr = {
25848 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25849 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25850 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25851 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25852 +#ifdef CONFIG_AUFS_FHSM
25853 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25855 +#ifdef CONFIG_AUFS_XATTR
25856 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25857 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25858 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25859 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25860 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25861 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25864 + /* ro/rr branch */
25865 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25868 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25869 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25874 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25881 + p = strchr(str, '+');
25884 + v = match_token(str, table, args);
25886 + if (v & AuBrAttr_CMOO_Mask)
25887 + attr &= ~AuBrAttr_CMOO_Mask;
25892 + pr_warn("ignored branch attribute %s\n", str);
25902 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25910 + p = au_optstr(&perm, brattr);
25913 + memcpy(q, p, sz + 1);
25919 + p = au_optstr(&perm, brattr);
25923 + memcpy(q, p, sz + 1);
25929 + return q - str->a;
25932 +static int noinline_for_stack br_perm_val(char *perm)
25934 + int val, bad, sz;
25936 + substring_t args[MAX_OPT_ARGS];
25937 + au_br_perm_str_t attr;
25939 + p = strchr(perm, '+');
25942 + val = match_token(perm, brperm, args);
25946 + pr_warn("ignored branch permission %s\n", perm);
25947 + val = AuBrPerm_RO;
25953 + val |= br_attr_val(p + 1, brattr, args);
25956 + switch (val & AuBrPerm_Mask) {
25957 + case AuBrPerm_RO:
25958 + case AuBrPerm_RR:
25959 + bad = val & AuBrWAttr_Mask;
25960 + val &= ~AuBrWAttr_Mask;
25962 + case AuBrPerm_RW:
25963 + bad = val & AuBrRAttr_Mask;
25964 + val &= ~AuBrRAttr_Mask;
25969 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25970 + * does not treat it as an error, just warning.
25971 + * this is a tiny guard for the user operation.
25973 + if (val & AuBrAttr_UNPIN) {
25974 + bad |= AuBrAttr_UNPIN;
25975 + val &= ~AuBrAttr_UNPIN;
25978 + if (unlikely(bad)) {
25979 + sz = au_do_optstr_br_attr(&attr, bad);
25981 + pr_warn("ignored branch attribute %s\n", attr.a);
25988 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25990 + au_br_perm_str_t attr;
25996 + p = au_optstr(&perm, brperm);
25997 + AuDebugOn(!p || !*p);
25999 + memcpy(q, p, sz + 1);
26002 + sz = au_do_optstr_br_attr(&attr, perm);
26005 + memcpy(q, attr.a, sz + 1);
26008 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26011 +/* ---------------------------------------------------------------------- */
26013 +static match_table_t udbalevel = {
26014 + {AuOpt_UDBA_REVAL, "reval"},
26015 + {AuOpt_UDBA_NONE, "none"},
26016 +#ifdef CONFIG_AUFS_HNOTIFY
26017 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26018 +#ifdef CONFIG_AUFS_HFSNOTIFY
26019 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26025 +static int noinline_for_stack udba_val(char *str)
26027 + substring_t args[MAX_OPT_ARGS];
26029 + return match_token(str, udbalevel, args);
26032 +const char *au_optstr_udba(int udba)
26034 + return au_parser_pattern(udba, udbalevel);
26037 +/* ---------------------------------------------------------------------- */
26039 +static match_table_t au_wbr_create_policy = {
26040 + {AuWbrCreate_TDP, "tdp"},
26041 + {AuWbrCreate_TDP, "top-down-parent"},
26042 + {AuWbrCreate_RR, "rr"},
26043 + {AuWbrCreate_RR, "round-robin"},
26044 + {AuWbrCreate_MFS, "mfs"},
26045 + {AuWbrCreate_MFS, "most-free-space"},
26046 + {AuWbrCreate_MFSV, "mfs:%d"},
26047 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26049 + /* top-down regardless the parent, and then mfs */
26050 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26051 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26053 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26054 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26055 + {AuWbrCreate_PMFS, "pmfs"},
26056 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26057 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26058 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26063 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26064 + struct au_opt_wbr_create *create)
26067 + unsigned long long ull;
26070 + if (!match_u64(arg, &ull))
26071 + create->mfsrr_watermark = ull;
26073 + pr_err("bad integer in %s\n", str);
26080 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26081 + struct au_opt_wbr_create *create)
26086 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26087 + create->mfs_second = n;
26089 + pr_err("bad integer in %s\n", str);
26096 +static int noinline_for_stack
26097 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26100 + substring_t args[MAX_OPT_ARGS];
26102 + err = match_token(str, au_wbr_create_policy, args);
26103 + create->wbr_create = err;
26105 + case AuWbrCreate_MFSRRV:
26106 + case AuWbrCreate_TDMFSV:
26107 + case AuWbrCreate_PMFSRRV:
26108 + e = au_wbr_mfs_wmark(&args[0], str, create);
26110 + e = au_wbr_mfs_sec(&args[1], str, create);
26114 + case AuWbrCreate_MFSRR:
26115 + case AuWbrCreate_TDMFS:
26116 + case AuWbrCreate_PMFSRR:
26117 + e = au_wbr_mfs_wmark(&args[0], str, create);
26118 + if (unlikely(e)) {
26123 + case AuWbrCreate_MFS:
26124 + case AuWbrCreate_PMFS:
26125 + create->mfs_second = AUFS_MFS_DEF_SEC;
26127 + case AuWbrCreate_MFSV:
26128 + case AuWbrCreate_PMFSV:
26129 + e = au_wbr_mfs_sec(&args[0], str, create);
26138 +const char *au_optstr_wbr_create(int wbr_create)
26140 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26143 +static match_table_t au_wbr_copyup_policy = {
26144 + {AuWbrCopyup_TDP, "tdp"},
26145 + {AuWbrCopyup_TDP, "top-down-parent"},
26146 + {AuWbrCopyup_BUP, "bup"},
26147 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26148 + {AuWbrCopyup_BU, "bu"},
26149 + {AuWbrCopyup_BU, "bottom-up"},
26153 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26155 + substring_t args[MAX_OPT_ARGS];
26157 + return match_token(str, au_wbr_copyup_policy, args);
26160 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26162 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26165 +/* ---------------------------------------------------------------------- */
26167 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26169 +static void dump_opts(struct au_opts *opts)
26171 +#ifdef CONFIG_AUFS_DEBUG
26172 + /* reduce stack space */
26174 + struct au_opt_add *add;
26175 + struct au_opt_del *del;
26176 + struct au_opt_mod *mod;
26177 + struct au_opt_xino *xino;
26178 + struct au_opt_xino_itrunc *xino_itrunc;
26179 + struct au_opt_wbr_create *create;
26181 + struct au_opt *opt;
26184 + while (opt->type != Opt_tail) {
26185 + switch (opt->type) {
26187 + u.add = &opt->add;
26188 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26189 + u.add->bindex, u.add->pathname, u.add->perm,
26190 + u.add->path.dentry);
26194 + u.del = &opt->del;
26195 + AuDbg("del {%s, %p}\n",
26196 + u.del->pathname, u.del->h_path.dentry);
26200 + u.mod = &opt->mod;
26201 + AuDbg("mod {%s, 0x%x, %p}\n",
26202 + u.mod->path, u.mod->perm, u.mod->h_root);
26205 + u.add = &opt->add;
26206 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26207 + u.add->bindex, u.add->pathname, u.add->perm,
26208 + u.add->path.dentry);
26210 + case Opt_prepend:
26211 + u.add = &opt->add;
26212 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26213 + u.add->bindex, u.add->pathname, u.add->perm,
26214 + u.add->path.dentry);
26217 + AuDbg("dirwh %d\n", opt->dirwh);
26219 + case Opt_rdcache:
26220 + AuDbg("rdcache %d\n", opt->rdcache);
26223 + AuDbg("rdblk %u\n", opt->rdblk);
26225 + case Opt_rdblk_def:
26226 + AuDbg("rdblk_def\n");
26229 + AuDbg("rdhash %u\n", opt->rdhash);
26231 + case Opt_rdhash_def:
26232 + AuDbg("rdhash_def\n");
26235 + u.xino = &opt->xino;
26236 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26238 + case Opt_trunc_xino:
26239 + AuLabel(trunc_xino);
26241 + case Opt_notrunc_xino:
26242 + AuLabel(notrunc_xino);
26244 + case Opt_trunc_xino_path:
26245 + case Opt_itrunc_xino:
26246 + u.xino_itrunc = &opt->xino_itrunc;
26247 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26252 + case Opt_trunc_xib:
26253 + AuLabel(trunc_xib);
26255 + case Opt_notrunc_xib:
26256 + AuLabel(notrunc_xib);
26264 + case Opt_dirperm1:
26265 + AuLabel(dirperm1);
26267 + case Opt_nodirperm1:
26268 + AuLabel(nodirperm1);
26273 + case Opt_noplink:
26274 + AuLabel(noplink);
26276 + case Opt_list_plink:
26277 + AuLabel(list_plink);
26280 + AuDbg("udba %d, %s\n",
26281 + opt->udba, au_optstr_udba(opt->udba));
26289 + case Opt_diropq_a:
26290 + AuLabel(diropq_a);
26292 + case Opt_diropq_w:
26293 + AuLabel(diropq_w);
26295 + case Opt_warn_perm:
26296 + AuLabel(warn_perm);
26298 + case Opt_nowarn_perm:
26299 + AuLabel(nowarn_perm);
26301 + case Opt_verbose:
26302 + AuLabel(verbose);
26304 + case Opt_noverbose:
26305 + AuLabel(noverbose);
26316 + case Opt_wbr_create:
26317 + u.create = &opt->wbr_create;
26318 + AuDbg("create %d, %s\n", u.create->wbr_create,
26319 + au_optstr_wbr_create(u.create->wbr_create));
26320 + switch (u.create->wbr_create) {
26321 + case AuWbrCreate_MFSV:
26322 + case AuWbrCreate_PMFSV:
26323 + AuDbg("%d sec\n", u.create->mfs_second);
26325 + case AuWbrCreate_MFSRR:
26326 + case AuWbrCreate_TDMFS:
26327 + AuDbg("%llu watermark\n",
26328 + u.create->mfsrr_watermark);
26330 + case AuWbrCreate_MFSRRV:
26331 + case AuWbrCreate_TDMFSV:
26332 + case AuWbrCreate_PMFSRRV:
26333 + AuDbg("%llu watermark, %d sec\n",
26334 + u.create->mfsrr_watermark,
26335 + u.create->mfs_second);
26339 + case Opt_wbr_copyup:
26340 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26341 + au_optstr_wbr_copyup(opt->wbr_copyup));
26343 + case Opt_fhsm_sec:
26344 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26349 + case Opt_nodirren:
26350 + AuLabel(nodirren);
26366 +void au_opts_free(struct au_opts *opts)
26368 + struct au_opt *opt;
26371 + while (opt->type != Opt_tail) {
26372 + switch (opt->type) {
26375 + case Opt_prepend:
26376 + path_put(&opt->add.path);
26380 + path_put(&opt->del.h_path);
26384 + dput(opt->mod.h_root);
26387 + fput(opt->xino.file);
26394 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26395 + aufs_bindex_t bindex)
26398 + struct au_opt_add *add = &opt->add;
26401 + add->bindex = bindex;
26402 + add->perm = AuBrPerm_RO;
26403 + add->pathname = opt_str;
26404 + p = strchr(opt_str, '=');
26408 + add->perm = br_perm_val(p);
26411 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26414 + add->perm = AuBrPerm_RO;
26415 + if (au_test_fs_rr(add->path.dentry->d_sb))
26416 + add->perm = AuBrPerm_RR;
26417 + else if (!bindex && !(sb_flags & SB_RDONLY))
26418 + add->perm = AuBrPerm_RW;
26420 + opt->type = Opt_add;
26423 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26430 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26434 + del->pathname = args[0].from;
26435 + AuDbg("del path %s\n", del->pathname);
26437 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26438 + if (unlikely(err))
26439 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26444 +#if 0 /* reserved for future use */
26445 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26446 + struct au_opt_del *del, substring_t args[])
26449 + struct dentry *root;
26452 + root = sb->s_root;
26453 + aufs_read_lock(root, AuLock_FLUSH);
26454 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26455 + pr_err("out of bounds, %d\n", bindex);
26460 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26461 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26464 + aufs_read_unlock(root, !AuLock_IR);
26469 +static int noinline_for_stack
26470 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26473 + struct path path;
26477 + mod->path = args[0].from;
26478 + p = strchr(mod->path, '=');
26479 + if (unlikely(!p)) {
26480 + pr_err("no permission %s\n", args[0].from);
26485 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26486 + if (unlikely(err)) {
26487 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26491 + mod->perm = br_perm_val(p);
26492 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26493 + mod->h_root = dget(path.dentry);
26500 +#if 0 /* reserved for future use */
26501 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26502 + struct au_opt_mod *mod, substring_t args[])
26505 + struct dentry *root;
26508 + root = sb->s_root;
26509 + aufs_read_lock(root, AuLock_FLUSH);
26510 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26511 + pr_err("out of bounds, %d\n", bindex);
26516 + mod->perm = br_perm_val(args[1].from);
26517 + AuDbg("mod path %s, perm 0x%x, %s\n",
26518 + mod->path, mod->perm, args[1].from);
26519 + mod->h_root = dget(au_h_dptr(root, bindex));
26522 + aufs_read_unlock(root, !AuLock_IR);
26527 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26528 + substring_t args[])
26531 + struct file *file;
26533 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26534 + err = PTR_ERR(file);
26535 + if (IS_ERR(file))
26539 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26541 + pr_err("%s must be outside\n", args[0].from);
26546 + xino->file = file;
26547 + xino->path = args[0].from;
26553 +static int noinline_for_stack
26554 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26555 + struct au_opt_xino_itrunc *xino_itrunc,
26556 + substring_t args[])
26559 + aufs_bindex_t bbot, bindex;
26560 + struct path path;
26561 + struct dentry *root;
26563 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26564 + if (unlikely(err)) {
26565 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26569 + xino_itrunc->bindex = -1;
26570 + root = sb->s_root;
26571 + aufs_read_lock(root, AuLock_FLUSH);
26572 + bbot = au_sbbot(sb);
26573 + for (bindex = 0; bindex <= bbot; bindex++) {
26574 + if (au_h_dptr(root, bindex) == path.dentry) {
26575 + xino_itrunc->bindex = bindex;
26579 + aufs_read_unlock(root, !AuLock_IR);
26582 + if (unlikely(xino_itrunc->bindex < 0)) {
26583 + pr_err("no such branch %s\n", args[0].from);
26591 +/* called without aufs lock */
26592 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26594 + int err, n, token;
26595 + aufs_bindex_t bindex;
26596 + unsigned char skipped;
26597 + struct dentry *root;
26598 + struct au_opt *opt, *opt_tail;
26600 + /* reduce the stack space */
26602 + struct au_opt_xino_itrunc *xino_itrunc;
26603 + struct au_opt_wbr_create *create;
26606 + substring_t args[MAX_OPT_ARGS];
26610 + a = kmalloc(sizeof(*a), GFP_NOFS);
26611 + if (unlikely(!a))
26614 + root = sb->s_root;
26618 + opt_tail = opt + opts->max_opt - 1;
26619 + opt->type = Opt_tail;
26620 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26623 + token = match_token(opt_str, options, a->args);
26627 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26629 + err = opt_add(opt, opt_str, opts->sb_flags,
26631 + if (unlikely(!err && ++opt > opt_tail)) {
26635 + opt->type = Opt_tail;
26640 + if (unlikely(match_int(&a->args[0], &n))) {
26641 + pr_err("bad integer in %s\n", opt_str);
26645 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26648 + opt->type = token;
26651 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26652 + /*dummy bindex*/1);
26654 + opt->type = token;
26656 + case Opt_prepend:
26657 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26660 + opt->type = token;
26663 + err = au_opts_parse_del(&opt->del, a->args);
26665 + opt->type = token;
26667 +#if 0 /* reserved for future use */
26669 + del->pathname = "(indexed)";
26670 + if (unlikely(match_int(&args[0], &n))) {
26671 + pr_err("bad integer in %s\n", opt_str);
26674 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26676 + opt->type = token;
26680 + err = au_opts_parse_mod(&opt->mod, a->args);
26682 + opt->type = token;
26684 +#ifdef IMOD /* reserved for future use */
26686 + u.mod->path = "(indexed)";
26687 + if (unlikely(match_int(&a->args[0], &n))) {
26688 + pr_err("bad integer in %s\n", opt_str);
26691 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26693 + opt->type = token;
26697 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26699 + opt->type = token;
26702 + case Opt_trunc_xino_path:
26703 + err = au_opts_parse_xino_itrunc_path
26704 + (sb, &opt->xino_itrunc, a->args);
26706 + opt->type = token;
26709 + case Opt_itrunc_xino:
26710 + u.xino_itrunc = &opt->xino_itrunc;
26711 + if (unlikely(match_int(&a->args[0], &n))) {
26712 + pr_err("bad integer in %s\n", opt_str);
26715 + u.xino_itrunc->bindex = n;
26716 + aufs_read_lock(root, AuLock_FLUSH);
26717 + if (n < 0 || au_sbbot(sb) < n) {
26718 + pr_err("out of bounds, %d\n", n);
26719 + aufs_read_unlock(root, !AuLock_IR);
26722 + aufs_read_unlock(root, !AuLock_IR);
26724 + opt->type = token;
26728 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26731 + opt->type = token;
26734 + case Opt_rdcache:
26735 + if (unlikely(match_int(&a->args[0], &n))) {
26736 + pr_err("bad integer in %s\n", opt_str);
26739 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26740 + pr_err("rdcache must be smaller than %d\n",
26741 + AUFS_RDCACHE_MAX);
26744 + opt->rdcache = n;
26746 + opt->type = token;
26749 + if (unlikely(match_int(&a->args[0], &n)
26751 + || n > KMALLOC_MAX_SIZE)) {
26752 + pr_err("bad integer in %s\n", opt_str);
26755 + if (unlikely(n && n < NAME_MAX)) {
26756 + pr_err("rdblk must be larger than %d\n",
26762 + opt->type = token;
26765 + if (unlikely(match_int(&a->args[0], &n)
26767 + || n * sizeof(struct hlist_head)
26768 + > KMALLOC_MAX_SIZE)) {
26769 + pr_err("bad integer in %s\n", opt_str);
26774 + opt->type = token;
26777 + case Opt_trunc_xino:
26778 + case Opt_notrunc_xino:
26780 + case Opt_trunc_xib:
26781 + case Opt_notrunc_xib:
26784 + case Opt_dirperm1:
26785 + case Opt_nodirperm1:
26787 + case Opt_noplink:
26788 + case Opt_list_plink:
26791 + case Opt_diropq_a:
26792 + case Opt_diropq_w:
26793 + case Opt_warn_perm:
26794 + case Opt_nowarn_perm:
26795 + case Opt_verbose:
26796 + case Opt_noverbose:
26800 + case Opt_rdblk_def:
26801 + case Opt_rdhash_def:
26803 + case Opt_nodirren:
26807 + opt->type = token;
26811 + opt->udba = udba_val(a->args[0].from);
26812 + if (opt->udba >= 0) {
26814 + opt->type = token;
26816 + pr_err("wrong value, %s\n", opt_str);
26819 + case Opt_wbr_create:
26820 + u.create = &opt->wbr_create;
26821 + u.create->wbr_create
26822 + = au_wbr_create_val(a->args[0].from, u.create);
26823 + if (u.create->wbr_create >= 0) {
26825 + opt->type = token;
26827 + pr_err("wrong value, %s\n", opt_str);
26829 + case Opt_wbr_copyup:
26830 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26831 + if (opt->wbr_copyup >= 0) {
26833 + opt->type = token;
26835 + pr_err("wrong value, %s\n", opt_str);
26838 + case Opt_fhsm_sec:
26839 + if (unlikely(match_int(&a->args[0], &n)
26841 + pr_err("bad integer in %s\n", opt_str);
26844 + if (sysaufs_brs) {
26845 + opt->fhsm_second = n;
26846 + opt->type = token;
26848 + pr_warn("ignored %s\n", opt_str);
26853 + pr_warn("ignored %s\n", opt_str);
26855 + case Opt_ignore_silent:
26860 + pr_err("unknown option %s\n", opt_str);
26864 + if (!err && !skipped) {
26865 + if (unlikely(++opt > opt_tail)) {
26868 + opt->type = Opt_tail;
26871 + opt->type = Opt_tail;
26877 + if (unlikely(err))
26878 + au_opts_free(opts);
26884 +static int au_opt_wbr_create(struct super_block *sb,
26885 + struct au_opt_wbr_create *create)
26888 + struct au_sbinfo *sbinfo;
26890 + SiMustWriteLock(sb);
26892 + err = 1; /* handled */
26893 + sbinfo = au_sbi(sb);
26894 + if (sbinfo->si_wbr_create_ops->fin) {
26895 + err = sbinfo->si_wbr_create_ops->fin(sb);
26900 + sbinfo->si_wbr_create = create->wbr_create;
26901 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26902 + switch (create->wbr_create) {
26903 + case AuWbrCreate_MFSRRV:
26904 + case AuWbrCreate_MFSRR:
26905 + case AuWbrCreate_TDMFS:
26906 + case AuWbrCreate_TDMFSV:
26907 + case AuWbrCreate_PMFSRR:
26908 + case AuWbrCreate_PMFSRRV:
26909 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26911 + case AuWbrCreate_MFS:
26912 + case AuWbrCreate_MFSV:
26913 + case AuWbrCreate_PMFS:
26914 + case AuWbrCreate_PMFSV:
26915 + sbinfo->si_wbr_mfs.mfs_expire
26916 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26920 + if (sbinfo->si_wbr_create_ops->init)
26921 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26928 + * plus: processed without an error
26929 + * zero: unprocessed
26931 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26932 + struct au_opts *opts)
26935 + struct au_sbinfo *sbinfo;
26937 + SiMustWriteLock(sb);
26939 + err = 1; /* handled */
26940 + sbinfo = au_sbi(sb);
26941 + switch (opt->type) {
26943 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26944 + sbinfo->si_mntflags |= opt->udba;
26945 + opts->given_udba |= opt->udba;
26949 + au_opt_set(sbinfo->si_mntflags, PLINK);
26951 + case Opt_noplink:
26952 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26953 + au_plink_put(sb, /*verbose*/1);
26954 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26956 + case Opt_list_plink:
26957 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26958 + au_plink_list(sb);
26962 + au_opt_set(sbinfo->si_mntflags, DIO);
26963 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26966 + au_opt_clr(sbinfo->si_mntflags, DIO);
26967 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26970 + case Opt_fhsm_sec:
26971 + au_fhsm_set(sbinfo, opt->fhsm_second);
26974 + case Opt_diropq_a:
26975 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26977 + case Opt_diropq_w:
26978 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26981 + case Opt_warn_perm:
26982 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26984 + case Opt_nowarn_perm:
26985 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26988 + case Opt_verbose:
26989 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26991 + case Opt_noverbose:
26992 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26996 + au_opt_set(sbinfo->si_mntflags, SUM);
26999 + au_opt_clr(sbinfo->si_mntflags, SUM);
27000 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27003 + au_opt_clr(sbinfo->si_mntflags, SUM);
27004 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27007 + case Opt_wbr_create:
27008 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27010 + case Opt_wbr_copyup:
27011 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27012 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27016 + sbinfo->si_dirwh = opt->dirwh;
27019 + case Opt_rdcache:
27020 + sbinfo->si_rdcache
27021 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27024 + sbinfo->si_rdblk = opt->rdblk;
27026 + case Opt_rdblk_def:
27027 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27030 + sbinfo->si_rdhash = opt->rdhash;
27032 + case Opt_rdhash_def:
27033 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27037 + au_opt_set(sbinfo->si_mntflags, SHWH);
27040 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27043 + case Opt_dirperm1:
27044 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27046 + case Opt_nodirperm1:
27047 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27050 + case Opt_trunc_xino:
27051 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27053 + case Opt_notrunc_xino:
27054 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27057 + case Opt_trunc_xino_path:
27058 + case Opt_itrunc_xino:
27059 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27065 + case Opt_trunc_xib:
27066 + au_fset_opts(opts->flags, TRUNC_XIB);
27068 + case Opt_notrunc_xib:
27069 + au_fclr_opts(opts->flags, TRUNC_XIB);
27074 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27075 + err = au_dr_opt_set(sb);
27080 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27082 + case Opt_nodirren:
27084 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27085 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27091 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27095 + sb->s_flags |= SB_POSIXACL;
27098 + sb->s_flags &= ~SB_POSIXACL;
27110 + * returns tri-state.
27111 + * plus: processed without an error
27112 + * zero: unprocessed
27115 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27116 + struct au_opts *opts)
27118 + int err, do_refresh;
27121 + switch (opt->type) {
27123 + opt->add.bindex = au_sbbot(sb) + 1;
27124 + if (opt->add.bindex < 0)
27125 + opt->add.bindex = 0;
27127 + /* Always goto add, not fallthrough */
27128 + case Opt_prepend:
27129 + opt->add.bindex = 0;
27131 + add: /* indented label */
27133 + err = au_br_add(sb, &opt->add,
27134 + au_ftest_opts(opts->flags, REMOUNT));
27137 + au_fset_opts(opts->flags, REFRESH);
27143 + err = au_br_del(sb, &opt->del,
27144 + au_ftest_opts(opts->flags, REMOUNT));
27147 + au_fset_opts(opts->flags, TRUNC_XIB);
27148 + au_fset_opts(opts->flags, REFRESH);
27154 + err = au_br_mod(sb, &opt->mod,
27155 + au_ftest_opts(opts->flags, REMOUNT),
27160 + au_fset_opts(opts->flags, REFRESH);
27167 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27168 + struct au_opt_xino **opt_xino,
27169 + struct au_opts *opts)
27174 + switch (opt->type) {
27176 + err = au_xino_set(sb, &opt->xino,
27177 + !!au_ftest_opts(opts->flags, REMOUNT));
27178 + if (unlikely(err))
27181 + *opt_xino = &opt->xino;
27186 + *opt_xino = (void *)-1;
27193 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27194 + unsigned int pending)
27197 + aufs_bindex_t bindex, bbot;
27198 + unsigned char do_plink, skip, do_free, can_no_dreval;
27199 + struct au_branch *br;
27200 + struct au_wbr *wbr;
27201 + struct dentry *root, *dentry;
27202 + struct inode *dir, *h_dir;
27203 + struct au_sbinfo *sbinfo;
27204 + struct au_hinode *hdir;
27206 + SiMustAnyLock(sb);
27208 + sbinfo = au_sbi(sb);
27209 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27211 + if (!(sb_flags & SB_RDONLY)) {
27212 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27213 + pr_warn("first branch should be rw\n");
27214 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27215 + pr_warn_once("shwh should be used with ro\n");
27218 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27219 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27220 + pr_warn_once("udba=*notify requires xino\n");
27222 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27223 + pr_warn_once("dirperm1 breaks the protection"
27224 + " by the permission bits on the lower branch\n");
27228 + root = sb->s_root;
27229 + dir = d_inode(root);
27230 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27231 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27233 + bbot = au_sbbot(sb);
27234 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27236 + h_dir = au_h_iptr(dir, bindex);
27237 + br = au_sbr(sb, bindex);
27239 + if ((br->br_perm & AuBrAttr_ICEX)
27240 + && !h_dir->i_op->listxattr)
27241 + br->br_perm &= ~AuBrAttr_ICEX;
27242 +#if 0 /* untested */
27243 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27244 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27245 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27249 + wbr = br->br_wbr;
27251 + wbr_wh_read_lock(wbr);
27253 + if (!au_br_writable(br->br_perm)) {
27256 + || (!wbr->wbr_whbase
27257 + && !wbr->wbr_plink
27258 + && !wbr->wbr_orph));
27259 + } else if (!au_br_wh_linkable(br->br_perm)) {
27260 + /* skip = (!br->br_whbase && !br->br_orph); */
27261 + skip = (!wbr || !wbr->wbr_whbase);
27262 + if (skip && wbr) {
27264 + skip = !!wbr->wbr_plink;
27266 + skip = !wbr->wbr_plink;
27269 + /* skip = (br->br_whbase && br->br_ohph); */
27270 + skip = (wbr && wbr->wbr_whbase);
27273 + skip = !!wbr->wbr_plink;
27275 + skip = !wbr->wbr_plink;
27279 + wbr_wh_read_unlock(wbr);
27281 + if (can_no_dreval) {
27282 + dentry = br->br_path.dentry;
27283 + spin_lock(&dentry->d_lock);
27284 + if (dentry->d_flags &
27285 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27286 + can_no_dreval = 0;
27287 + spin_unlock(&dentry->d_lock);
27290 + if (au_br_fhsm(br->br_perm)) {
27292 + AuDebugOn(!br->br_fhsm);
27298 + hdir = au_hi(dir, bindex);
27299 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27301 + wbr_wh_write_lock(wbr);
27302 + err = au_wh_init(br, sb);
27304 + wbr_wh_write_unlock(wbr);
27305 + au_hn_inode_unlock(hdir);
27307 + if (!err && do_free) {
27308 + au_kfree_rcu(wbr);
27309 + br->br_wbr = NULL;
27313 + if (can_no_dreval)
27314 + au_fset_si(sbinfo, NO_DREVAL);
27316 + au_fclr_si(sbinfo, NO_DREVAL);
27319 + au_fset_si(sbinfo, FHSM);
27320 + for (bindex = bbot; bindex >= 0; bindex--) {
27321 + br = au_sbr(sb, bindex);
27322 + if (au_br_fhsm(br->br_perm)) {
27323 + au_fhsm_set_bottom(sb, bindex);
27328 + au_fclr_si(sbinfo, FHSM);
27329 + au_fhsm_set_bottom(sb, -1);
27335 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27338 + unsigned int tmp;
27339 + aufs_bindex_t bindex, bbot;
27340 + struct au_opt *opt;
27341 + struct au_opt_xino *opt_xino, xino;
27342 + struct au_sbinfo *sbinfo;
27343 + struct au_branch *br;
27344 + struct inode *dir;
27346 + SiMustWriteLock(sb);
27351 + while (err >= 0 && opt->type != Opt_tail)
27352 + err = au_opt_simple(sb, opt++, opts);
27355 + else if (unlikely(err < 0))
27358 + /* disable xino and udba temporary */
27359 + sbinfo = au_sbi(sb);
27360 + tmp = sbinfo->si_mntflags;
27361 + au_opt_clr(sbinfo->si_mntflags, XINO);
27362 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27365 + while (err >= 0 && opt->type != Opt_tail)
27366 + err = au_opt_br(sb, opt++, opts);
27369 + else if (unlikely(err < 0))
27372 + bbot = au_sbbot(sb);
27373 + if (unlikely(bbot < 0)) {
27375 + pr_err("no branches\n");
27379 + if (au_opt_test(tmp, XINO))
27380 + au_opt_set(sbinfo->si_mntflags, XINO);
27382 + while (!err && opt->type != Opt_tail)
27383 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27384 + if (unlikely(err))
27387 + err = au_opts_verify(sb, sb->s_flags, tmp);
27388 + if (unlikely(err))
27391 + /* restore xino */
27392 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27393 + xino.file = au_xino_def(sb);
27394 + err = PTR_ERR(xino.file);
27395 + if (IS_ERR(xino.file))
27398 + err = au_xino_set(sb, &xino, /*remount*/0);
27400 + if (unlikely(err))
27404 + /* restore udba */
27405 + tmp &= AuOptMask_UDBA;
27406 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27407 + sbinfo->si_mntflags |= tmp;
27408 + bbot = au_sbbot(sb);
27409 + for (bindex = 0; bindex <= bbot; bindex++) {
27410 + br = au_sbr(sb, bindex);
27411 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27412 + if (unlikely(err))
27413 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27415 + /* go on even if err */
27417 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27418 + dir = d_inode(sb->s_root);
27419 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27426 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27429 + unsigned char no_dreval;
27430 + struct inode *dir;
27431 + struct au_opt_xino *opt_xino;
27432 + struct au_opt *opt;
27433 + struct au_sbinfo *sbinfo;
27435 + SiMustWriteLock(sb);
27437 + err = au_dr_opt_flush(sb);
27438 + if (unlikely(err))
27440 + au_fset_opts(opts->flags, DR_FLUSHED);
27442 + dir = d_inode(sb->s_root);
27443 + sbinfo = au_sbi(sb);
27446 + while (err >= 0 && opt->type != Opt_tail) {
27447 + err = au_opt_simple(sb, opt, opts);
27449 + err = au_opt_br(sb, opt, opts);
27451 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27457 + /* go on even err */
27459 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27460 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27461 + if (unlikely(rerr && !err))
27464 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27465 + au_fset_opts(opts->flags, REFRESH_IDOP);
27467 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27468 + rerr = au_xib_trunc(sb);
27469 + if (unlikely(rerr && !err))
27473 + /* will be handled by the caller */
27474 + if (!au_ftest_opts(opts->flags, REFRESH)
27475 + && (opts->given_udba
27476 + || au_opt_test(sbinfo->si_mntflags, XINO)
27477 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27479 + au_fset_opts(opts->flags, REFRESH);
27481 + AuDbg("status 0x%x\n", opts->flags);
27487 +/* ---------------------------------------------------------------------- */
27489 +unsigned int au_opt_udba(struct super_block *sb)
27491 + return au_mntflags(sb) & AuOptMask_UDBA;
27493 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27494 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27495 +++ linux/fs/aufs/opts.h 2021-05-02 20:15:14.676670793 +0200
27497 +/* SPDX-License-Identifier: GPL-2.0 */
27499 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27501 + * This program, aufs is free software; you can redistribute it and/or modify
27502 + * it under the terms of the GNU General Public License as published by
27503 + * the Free Software Foundation; either version 2 of the License, or
27504 + * (at your option) any later version.
27506 + * This program is distributed in the hope that it will be useful,
27507 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27508 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27509 + * GNU General Public License for more details.
27511 + * You should have received a copy of the GNU General Public License
27512 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27516 + * mount options/flags
27519 +#ifndef __AUFS_OPTS_H__
27520 +#define __AUFS_OPTS_H__
27524 +#include <linux/path.h>
27528 +/* ---------------------------------------------------------------------- */
27531 +#define AuOpt_XINO 1 /* external inode number bitmap
27532 + and translation table */
27533 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27534 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27535 +#define AuOpt_UDBA_REVAL (1 << 3)
27536 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27537 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27538 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27539 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27541 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27542 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27543 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27544 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27545 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27546 +#define AuOpt_DIO (1 << 14) /* direct io */
27547 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27549 +#ifndef CONFIG_AUFS_HNOTIFY
27550 +#undef AuOpt_UDBA_HNOTIFY
27551 +#define AuOpt_UDBA_HNOTIFY 0
27553 +#ifndef CONFIG_AUFS_DIRREN
27554 +#undef AuOpt_DIRREN
27555 +#define AuOpt_DIRREN 0
27557 +#ifndef CONFIG_AUFS_SHWH
27559 +#define AuOpt_SHWH 0
27562 +#define AuOpt_Def (AuOpt_XINO \
27563 + | AuOpt_UDBA_REVAL \
27565 + /* | AuOpt_DIRPERM1 */ \
27566 + | AuOpt_WARN_PERM)
27567 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27568 + | AuOpt_UDBA_REVAL \
27569 + | AuOpt_UDBA_HNOTIFY)
27571 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27572 +#define au_opt_set(flags, name) do { \
27573 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27574 + ((flags) |= AuOpt_##name); \
27576 +#define au_opt_set_udba(flags, name) do { \
27577 + (flags) &= ~AuOptMask_UDBA; \
27578 + ((flags) |= AuOpt_##name); \
27580 +#define au_opt_clr(flags, name) do { \
27581 + ((flags) &= ~AuOpt_##name); \
27584 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27586 +#ifdef CONFIG_PROC_FS
27589 + return mntflags & ~AuOpt_PLINK;
27593 +/* ---------------------------------------------------------------------- */
27595 +/* policies to select one among multiple writable branches */
27597 + AuWbrCreate_TDP, /* top down parent */
27598 + AuWbrCreate_RR, /* round robin */
27599 + AuWbrCreate_MFS, /* most free space */
27600 + AuWbrCreate_MFSV, /* mfs with seconds */
27601 + AuWbrCreate_MFSRR, /* mfs then rr */
27602 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27603 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27604 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27605 + AuWbrCreate_PMFS, /* parent and mfs */
27606 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27607 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27608 + AuWbrCreate_PMFSRRV, /* plus seconds */
27610 + AuWbrCreate_Def = AuWbrCreate_TDP
27614 + AuWbrCopyup_TDP, /* top down parent */
27615 + AuWbrCopyup_BUP, /* bottom up parent */
27616 + AuWbrCopyup_BU, /* bottom up */
27618 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27621 +/* ---------------------------------------------------------------------- */
27623 +struct au_opt_add {
27624 + aufs_bindex_t bindex;
27627 + struct path path;
27630 +struct au_opt_del {
27632 + struct path h_path;
27635 +struct au_opt_mod {
27638 + struct dentry *h_root;
27641 +struct au_opt_xino {
27643 + struct file *file;
27646 +struct au_opt_xino_itrunc {
27647 + aufs_bindex_t bindex;
27650 +struct au_opt_wbr_create {
27653 + unsigned long long mfsrr_watermark;
27659 + struct au_opt_xino xino;
27660 + struct au_opt_xino_itrunc xino_itrunc;
27661 + struct au_opt_add add;
27662 + struct au_opt_del del;
27663 + struct au_opt_mod mod;
27666 + unsigned int rdblk;
27667 + unsigned int rdhash;
27669 + struct au_opt_wbr_create wbr_create;
27671 + unsigned int fhsm_second;
27676 +#define AuOpts_REMOUNT 1
27677 +#define AuOpts_REFRESH (1 << 1)
27678 +#define AuOpts_TRUNC_XIB (1 << 2)
27679 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27680 +#define AuOpts_REFRESH_IDOP (1 << 4)
27681 +#define AuOpts_DR_FLUSHED (1 << 5)
27682 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27683 +#define au_fset_opts(flags, name) \
27684 + do { (flags) |= AuOpts_##name; } while (0)
27685 +#define au_fclr_opts(flags, name) \
27686 + do { (flags) &= ~AuOpts_##name; } while (0)
27688 +#ifndef CONFIG_AUFS_DIRREN
27689 +#undef AuOpts_DR_FLUSHED
27690 +#define AuOpts_DR_FLUSHED 0
27694 + struct au_opt *opt;
27697 + unsigned int given_udba;
27698 + unsigned int flags;
27699 + unsigned long sb_flags;
27702 +/* ---------------------------------------------------------------------- */
27705 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27706 +const char *au_optstr_udba(int udba);
27707 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27708 +const char *au_optstr_wbr_create(int wbr_create);
27710 +void au_opts_free(struct au_opts *opts);
27711 +struct super_block;
27712 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27713 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27714 + unsigned int pending);
27715 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27716 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27718 +unsigned int au_opt_udba(struct super_block *sb);
27720 +#endif /* __KERNEL__ */
27721 +#endif /* __AUFS_OPTS_H__ */
27722 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27723 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27724 +++ linux/fs/aufs/plink.c 2021-05-02 20:15:14.676670793 +0200
27726 +// SPDX-License-Identifier: GPL-2.0
27728 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27730 + * This program, aufs is free software; you can redistribute it and/or modify
27731 + * it under the terms of the GNU General Public License as published by
27732 + * the Free Software Foundation; either version 2 of the License, or
27733 + * (at your option) any later version.
27735 + * This program is distributed in the hope that it will be useful,
27736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27738 + * GNU General Public License for more details.
27740 + * You should have received a copy of the GNU General Public License
27741 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27751 + * the pseudo-link maintenance mode.
27752 + * during a user process maintains the pseudo-links,
27753 + * prohibit adding a new plink and branch manipulation.
27757 + * For entry functions which will handle plink, and i_mutex is already held
27759 + * They cannot wait and should return an error at once.
27760 + * Callers has to check the error.
27762 + * For entry functions which will handle plink, but i_mutex is not held
27764 + * They can wait the plink maintenance mode to finish.
27766 + * They behave like F_SETLK and F_SETLKW.
27767 + * If the caller never handle plink, then both flags are unnecessary.
27770 +int au_plink_maint(struct super_block *sb, int flags)
27774 + struct task_struct *parent, *prev;
27775 + struct au_sbinfo *sbi;
27777 + SiMustAnyLock(sb);
27780 + if (!au_opt_test(au_mntflags(sb), PLINK))
27783 + sbi = au_sbi(sb);
27784 + pid = sbi->si_plink_maint_pid;
27785 + if (!pid || pid == current->pid)
27788 + /* todo: it highly depends upon /sbin/mount.aufs */
27790 + parent = current;
27794 + parent = rcu_dereference(parent->real_parent);
27795 + if (parent == prev)
27797 + ppid = task_pid_vnr(parent);
27798 + if (pid == ppid) {
27799 + rcu_read_unlock();
27804 + rcu_read_unlock();
27806 + if (au_ftest_lock(flags, NOPLMW)) {
27807 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27808 + /* AuDebugOn(!lockdep_depth(current)); */
27809 + while (sbi->si_plink_maint_pid) {
27810 + si_read_unlock(sb);
27811 + /* gave up wake_up_bit() */
27812 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27814 + if (au_ftest_lock(flags, FLUSH))
27815 + au_nwt_flush(&sbi->si_nowait);
27816 + si_noflush_read_lock(sb);
27818 + } else if (au_ftest_lock(flags, NOPLM)) {
27819 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27827 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27829 + spin_lock(&sbinfo->si_plink_maint_lock);
27830 + sbinfo->si_plink_maint_pid = 0;
27831 + spin_unlock(&sbinfo->si_plink_maint_lock);
27832 + wake_up_all(&sbinfo->si_plink_wq);
27835 +int au_plink_maint_enter(struct super_block *sb)
27838 + struct au_sbinfo *sbinfo;
27841 + sbinfo = au_sbi(sb);
27842 + /* make sure i am the only one in this fs */
27843 + si_write_lock(sb, AuLock_FLUSH);
27844 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27845 + spin_lock(&sbinfo->si_plink_maint_lock);
27846 + if (!sbinfo->si_plink_maint_pid)
27847 + sbinfo->si_plink_maint_pid = current->pid;
27850 + spin_unlock(&sbinfo->si_plink_maint_lock);
27852 + si_write_unlock(sb);
27857 +/* ---------------------------------------------------------------------- */
27859 +#ifdef CONFIG_AUFS_DEBUG
27860 +void au_plink_list(struct super_block *sb)
27863 + struct au_sbinfo *sbinfo;
27864 + struct hlist_bl_head *hbl;
27865 + struct hlist_bl_node *pos;
27866 + struct au_icntnr *icntnr;
27868 + SiMustAnyLock(sb);
27870 + sbinfo = au_sbi(sb);
27871 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27872 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27874 + for (i = 0; i < AuPlink_NHASH; i++) {
27875 + hbl = sbinfo->si_plink + i;
27876 + hlist_bl_lock(hbl);
27877 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27878 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27879 + hlist_bl_unlock(hbl);
27884 +/* is the inode pseudo-linked? */
27885 +int au_plink_test(struct inode *inode)
27888 + struct au_sbinfo *sbinfo;
27889 + struct hlist_bl_head *hbl;
27890 + struct hlist_bl_node *pos;
27891 + struct au_icntnr *icntnr;
27893 + sbinfo = au_sbi(inode->i_sb);
27894 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27895 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27896 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27899 + i = au_plink_hash(inode->i_ino);
27900 + hbl = sbinfo->si_plink + i;
27901 + hlist_bl_lock(hbl);
27902 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27903 + if (&icntnr->vfs_inode == inode) {
27907 + hlist_bl_unlock(hbl);
27911 +/* ---------------------------------------------------------------------- */
27914 + * generate a name for plink.
27915 + * the file will be stored under AUFS_WH_PLINKDIR.
27917 +/* 20 is max digits length of ulong 64 */
27918 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27920 +static int plink_name(char *name, int len, struct inode *inode,
27921 + aufs_bindex_t bindex)
27924 + struct inode *h_inode;
27926 + h_inode = au_h_iptr(inode, bindex);
27927 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27931 +struct au_do_plink_lkup_args {
27932 + struct dentry **errp;
27933 + struct qstr *tgtname;
27934 + struct dentry *h_parent;
27935 + struct au_branch *br;
27938 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27939 + struct dentry *h_parent,
27940 + struct au_branch *br)
27942 + struct dentry *h_dentry;
27943 + struct inode *h_inode;
27945 + h_inode = d_inode(h_parent);
27946 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27947 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27948 + inode_unlock_shared(h_inode);
27952 +static void au_call_do_plink_lkup(void *args)
27954 + struct au_do_plink_lkup_args *a = args;
27955 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27958 +/* lookup the plink-ed @inode under the branch at @bindex */
27959 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27961 + struct dentry *h_dentry, *h_parent;
27962 + struct au_branch *br;
27964 + char a[PLINK_NAME_LEN];
27965 + struct qstr tgtname = QSTR_INIT(a, 0);
27967 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27969 + br = au_sbr(inode->i_sb, bindex);
27970 + h_parent = br->br_wbr->wbr_plink;
27971 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27973 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27974 + struct au_do_plink_lkup_args args = {
27975 + .errp = &h_dentry,
27976 + .tgtname = &tgtname,
27977 + .h_parent = h_parent,
27981 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27982 + if (unlikely(wkq_err))
27983 + h_dentry = ERR_PTR(wkq_err);
27985 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27990 +/* create a pseudo-link */
27991 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27992 + struct dentry *h_dentry, struct au_branch *br)
27995 + struct path h_path = {
27996 + .mnt = au_br_mnt(br)
27998 + struct inode *h_dir, *delegated;
28000 + h_dir = d_inode(h_parent);
28001 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28003 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
28004 + err = PTR_ERR(h_path.dentry);
28005 + if (IS_ERR(h_path.dentry))
28009 + /* wh.plink dir is not monitored */
28010 + /* todo: is it really safe? */
28011 + if (d_is_positive(h_path.dentry)
28012 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28013 + delegated = NULL;
28014 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28015 + if (unlikely(err == -EWOULDBLOCK)) {
28016 + pr_warn("cannot retry for NFSv4 delegation"
28017 + " for an internal unlink\n");
28020 + dput(h_path.dentry);
28021 + h_path.dentry = NULL;
28025 + if (!err && d_is_negative(h_path.dentry)) {
28026 + delegated = NULL;
28027 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28028 + if (unlikely(err == -EWOULDBLOCK)) {
28029 + pr_warn("cannot retry for NFSv4 delegation"
28030 + " for an internal link\n");
28034 + dput(h_path.dentry);
28037 + inode_unlock(h_dir);
28041 +struct do_whplink_args {
28043 + struct qstr *tgt;
28044 + struct dentry *h_parent;
28045 + struct dentry *h_dentry;
28046 + struct au_branch *br;
28049 +static void call_do_whplink(void *args)
28051 + struct do_whplink_args *a = args;
28052 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28055 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28056 + aufs_bindex_t bindex, struct au_branch *br)
28058 + int err, wkq_err;
28059 + struct au_wbr *wbr;
28060 + struct dentry *h_parent;
28061 + char a[PLINK_NAME_LEN];
28062 + struct qstr tgtname = QSTR_INIT(a, 0);
28064 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28065 + h_parent = wbr->wbr_plink;
28066 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28068 + /* always superio. */
28069 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28070 + struct do_whplink_args args = {
28073 + .h_parent = h_parent,
28074 + .h_dentry = h_dentry,
28077 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28078 + if (unlikely(wkq_err))
28081 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28087 + * create a new pseudo-link for @h_dentry on @bindex.
28088 + * the linked inode is held in aufs @inode.
28090 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28091 + struct dentry *h_dentry)
28093 + struct super_block *sb;
28094 + struct au_sbinfo *sbinfo;
28095 + struct hlist_bl_head *hbl;
28096 + struct hlist_bl_node *pos;
28097 + struct au_icntnr *icntnr;
28098 + int found, err, cnt, i;
28100 + sb = inode->i_sb;
28101 + sbinfo = au_sbi(sb);
28102 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28103 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28105 + found = au_plink_test(inode);
28109 + i = au_plink_hash(inode->i_ino);
28110 + hbl = sbinfo->si_plink + i;
28113 + hlist_bl_lock(hbl);
28114 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28115 + if (&icntnr->vfs_inode == inode) {
28121 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28122 + hlist_bl_add_head(&icntnr->plink, hbl);
28124 + hlist_bl_unlock(hbl);
28126 + cnt = au_hbl_count(hbl);
28127 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28128 + if (cnt > AUFS_PLINK_WARN)
28129 + AuWarn1(msg ", %d\n", cnt);
28131 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28132 + if (unlikely(err)) {
28133 + pr_warn("err %d, damaged pseudo link.\n", err);
28134 + au_hbl_del(&icntnr->plink, hbl);
28135 + iput(&icntnr->vfs_inode);
28138 + iput(&icntnr->vfs_inode);
28141 +/* free all plinks */
28142 +void au_plink_put(struct super_block *sb, int verbose)
28145 + struct au_sbinfo *sbinfo;
28146 + struct hlist_bl_head *hbl;
28147 + struct hlist_bl_node *pos, *tmp;
28148 + struct au_icntnr *icntnr;
28150 + SiMustWriteLock(sb);
28152 + sbinfo = au_sbi(sb);
28153 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28154 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28156 + /* no spin_lock since sbinfo is write-locked */
28158 + for (i = 0; i < AuPlink_NHASH; i++) {
28159 + hbl = sbinfo->si_plink + i;
28160 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28161 + pr_warn("pseudo-link is not flushed");
28164 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28165 + iput(&icntnr->vfs_inode);
28166 + INIT_HLIST_BL_HEAD(hbl);
28170 +void au_plink_clean(struct super_block *sb, int verbose)
28172 + struct dentry *root;
28174 + root = sb->s_root;
28175 + aufs_write_lock(root);
28176 + if (au_opt_test(au_mntflags(sb), PLINK))
28177 + au_plink_put(sb, verbose);
28178 + aufs_write_unlock(root);
28181 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28184 + aufs_bindex_t btop, bbot, bindex;
28187 + btop = au_ibtop(inode);
28188 + bbot = au_ibbot(inode);
28190 + for (bindex = btop; bindex <= bbot; bindex++) {
28191 + if (!au_h_iptr(inode, bindex)
28192 + || au_ii_br_id(inode, bindex) != br_id)
28194 + au_set_h_iptr(inode, bindex, NULL, 0);
28199 + for (bindex = btop; bindex <= bbot; bindex++)
28200 + if (au_h_iptr(inode, bindex)) {
28210 +/* free the plinks on a branch specified by @br_id */
28211 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28213 + struct au_sbinfo *sbinfo;
28214 + struct hlist_bl_head *hbl;
28215 + struct hlist_bl_node *pos, *tmp;
28216 + struct au_icntnr *icntnr;
28217 + struct inode *inode;
28220 + SiMustWriteLock(sb);
28222 + sbinfo = au_sbi(sb);
28223 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28224 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28226 + /* no bit_lock since sbinfo is write-locked */
28227 + for (i = 0; i < AuPlink_NHASH; i++) {
28228 + hbl = sbinfo->si_plink + i;
28229 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28230 + inode = au_igrab(&icntnr->vfs_inode);
28231 + ii_write_lock_child(inode);
28232 + do_put = au_plink_do_half_refresh(inode, br_id);
28234 + hlist_bl_del(&icntnr->plink);
28237 + ii_write_unlock(inode);
28242 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28243 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28244 +++ linux/fs/aufs/poll.c 2021-05-02 20:15:14.676670793 +0200
28246 +// SPDX-License-Identifier: GPL-2.0
28248 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28250 + * This program, aufs is free software; you can redistribute it and/or modify
28251 + * it under the terms of the GNU General Public License as published by
28252 + * the Free Software Foundation; either version 2 of the License, or
28253 + * (at your option) any later version.
28255 + * This program is distributed in the hope that it will be useful,
28256 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28257 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28258 + * GNU General Public License for more details.
28260 + * You should have received a copy of the GNU General Public License
28261 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28266 + * There is only one filesystem which implements ->poll operation, currently.
28271 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28274 + struct file *h_file;
28275 + struct super_block *sb;
28277 + /* We should pretend an error happened. */
28278 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28279 + sb = file->f_path.dentry->d_sb;
28280 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28282 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28283 + if (IS_ERR(h_file)) {
28284 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28288 + mask = vfs_poll(h_file, pt);
28289 + fput(h_file); /* instead of au_read_post() */
28292 + si_read_unlock(sb);
28293 + if (mask & EPOLLERR)
28294 + AuDbg("mask 0x%x\n", mask);
28297 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28298 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28299 +++ linux/fs/aufs/posix_acl.c 2021-05-02 20:15:14.676670793 +0200
28301 +// SPDX-License-Identifier: GPL-2.0
28303 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28305 + * This program, aufs is free software; you can redistribute it and/or modify
28306 + * it under the terms of the GNU General Public License as published by
28307 + * the Free Software Foundation; either version 2 of the License, or
28308 + * (at your option) any later version.
28310 + * This program is distributed in the hope that it will be useful,
28311 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28312 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28313 + * GNU General Public License for more details.
28315 + * You should have received a copy of the GNU General Public License
28316 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28320 + * posix acl operations
28323 +#include <linux/fs.h>
28326 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28328 + struct posix_acl *acl;
28330 + aufs_bindex_t bindex;
28331 + struct inode *h_inode;
28332 + struct super_block *sb;
28335 + sb = inode->i_sb;
28336 + si_read_lock(sb, AuLock_FLUSH);
28337 + ii_read_lock_child(inode);
28338 + if (!(sb->s_flags & SB_POSIXACL))
28341 + bindex = au_ibtop(inode);
28342 + h_inode = au_h_iptr(inode, bindex);
28343 + if (unlikely(!h_inode
28344 + || ((h_inode->i_mode & S_IFMT)
28345 + != (inode->i_mode & S_IFMT)))) {
28346 + err = au_busy_or_stale();
28347 + acl = ERR_PTR(err);
28351 + /* always topmost only */
28352 + acl = get_acl(h_inode, type);
28354 + forget_cached_acl(inode, type);
28356 + set_cached_acl(inode, type, acl);
28359 + ii_read_unlock(inode);
28360 + si_read_unlock(sb);
28362 + AuTraceErrPtr(acl);
28366 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28367 + struct posix_acl *acl, int type)
28371 + struct dentry *dentry;
28372 + struct au_sxattr arg = {
28373 + .type = AU_ACL_SET,
28380 + IMustLock(inode);
28382 + if (inode->i_ino == AUFS_ROOT_INO)
28383 + dentry = dget(inode->i_sb->s_root);
28385 + dentry = d_find_alias(inode);
28387 + dentry = d_find_any_alias(inode);
28389 + pr_warn("cannot handle this inode, "
28390 + "please report to aufs-users ML\n");
28396 + ssz = au_sxattr(dentry, inode, &arg);
28397 + /* forget even it if succeeds since the branch might set differently */
28398 + forget_cached_acl(inode, type);
28407 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28408 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28409 +++ linux/fs/aufs/procfs.c 2021-05-02 20:15:14.676670793 +0200
28411 +// SPDX-License-Identifier: GPL-2.0
28413 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28415 + * This program, aufs is free software; you can redistribute it and/or modify
28416 + * it under the terms of the GNU General Public License as published by
28417 + * the Free Software Foundation; either version 2 of the License, or
28418 + * (at your option) any later version.
28420 + * This program is distributed in the hope that it will be useful,
28421 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28422 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28423 + * GNU General Public License for more details.
28425 + * You should have received a copy of the GNU General Public License
28426 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28430 + * procfs interfaces
28433 +#include <linux/proc_fs.h>
28436 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28438 + struct au_sbinfo *sbinfo;
28440 + sbinfo = file->private_data;
28442 + au_plink_maint_leave(sbinfo);
28443 + kobject_put(&sbinfo->si_kobj);
28449 +static void au_procfs_plm_write_clean(struct file *file)
28451 + struct au_sbinfo *sbinfo;
28453 + sbinfo = file->private_data;
28455 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28458 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28461 + struct super_block *sb;
28462 + struct au_sbinfo *sbinfo;
28463 + struct hlist_bl_node *pos;
28466 + if (unlikely(file->private_data))
28470 + /* don't use au_sbilist_lock() here */
28471 + hlist_bl_lock(&au_sbilist);
28472 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28473 + if (id == sysaufs_si_id(sbinfo)) {
28474 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28475 + sb = sbinfo->si_sb;
28478 + hlist_bl_unlock(&au_sbilist);
28481 + if (unlikely(!sb))
28484 + err = au_plink_maint_enter(sb);
28486 + /* keep kobject_get() */
28487 + file->private_data = sbinfo;
28489 + kobject_put(&sbinfo->si_kobj);
28495 + * Accept a valid "si=xxxx" only.
28496 + * Once it is accepted successfully, accept "clean" too.
28498 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28499 + size_t count, loff_t *ppos)
28502 + unsigned long id;
28503 + /* last newline is allowed */
28504 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28507 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28511 + if (unlikely(count > sizeof(buf)))
28514 + err = copy_from_user(buf, ubuf, count);
28515 + if (unlikely(err)) {
28522 + if (!strcmp("clean", buf)) {
28523 + au_procfs_plm_write_clean(file);
28524 + goto out_success;
28525 + } else if (unlikely(strncmp("si=", buf, 3)))
28528 + err = kstrtoul(buf + 3, 16, &id);
28529 + if (unlikely(err))
28532 + err = au_procfs_plm_write_si(file, id);
28533 + if (unlikely(err))
28537 + err = count; /* success */
28542 +static const struct proc_ops au_procfs_plm_op = {
28543 + .proc_write = au_procfs_plm_write,
28544 + .proc_release = au_procfs_plm_release
28547 +/* ---------------------------------------------------------------------- */
28549 +static struct proc_dir_entry *au_procfs_dir;
28551 +void au_procfs_fin(void)
28553 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28554 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28557 +int __init au_procfs_init(void)
28560 + struct proc_dir_entry *entry;
28563 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28564 + if (unlikely(!au_procfs_dir))
28567 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28568 + au_procfs_dir, &au_procfs_plm_op);
28569 + if (unlikely(!entry))
28573 + goto out; /* success */
28577 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28581 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28582 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28583 +++ linux/fs/aufs/rdu.c 2021-05-02 20:15:14.676670793 +0200
28585 +// SPDX-License-Identifier: GPL-2.0
28587 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28589 + * This program, aufs is free software; you can redistribute it and/or modify
28590 + * it under the terms of the GNU General Public License as published by
28591 + * the Free Software Foundation; either version 2 of the License, or
28592 + * (at your option) any later version.
28594 + * This program is distributed in the hope that it will be useful,
28595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28597 + * GNU General Public License for more details.
28599 + * You should have received a copy of the GNU General Public License
28600 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28604 + * readdir in userspace.
28607 +#include <linux/compat.h>
28608 +#include <linux/fs_stack.h>
28609 +#include <linux/security.h>
28612 +/* bits for struct aufs_rdu.flags */
28613 +#define AuRdu_CALLED 1
28614 +#define AuRdu_CONT (1 << 1)
28615 +#define AuRdu_FULL (1 << 2)
28616 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28617 +#define au_fset_rdu(flags, name) \
28618 + do { (flags) |= AuRdu_##name; } while (0)
28619 +#define au_fclr_rdu(flags, name) \
28620 + do { (flags) &= ~AuRdu_##name; } while (0)
28622 +struct au_rdu_arg {
28623 + struct dir_context ctx;
28624 + struct aufs_rdu *rdu;
28625 + union au_rdu_ent_ul ent;
28626 + unsigned long end;
28628 + struct super_block *sb;
28632 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28633 + loff_t offset, u64 h_ino, unsigned int d_type)
28636 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28637 + struct aufs_rdu *rdu = arg->rdu;
28638 + struct au_rdu_ent ent;
28642 + au_fset_rdu(rdu->cookie.flags, CALLED);
28643 + len = au_rdu_len(nlen);
28644 + if (arg->ent.ul + len < arg->end) {
28646 + ent.bindex = rdu->cookie.bindex;
28647 + ent.type = d_type;
28649 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28650 + ent.type = DT_UNKNOWN;
28652 + /* unnecessary to support mmap_sem since this is a dir */
28654 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28656 + if (copy_to_user(arg->ent.e->name, name, nlen))
28658 + /* the terminating NULL */
28659 + if (__put_user(0, arg->ent.e->name + nlen))
28662 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28663 + arg->ent.ul += len;
28667 + au_fset_rdu(rdu->cookie.flags, FULL);
28669 + rdu->tail = arg->ent;
28673 + /* AuTraceErr(err); */
28677 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28681 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28683 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28684 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28686 + if (unlikely(offset != cookie->h_pos))
28692 + au_fclr_rdu(cookie->flags, CALLED);
28694 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28698 + && au_ftest_rdu(cookie->flags, CALLED)
28699 + && !au_ftest_rdu(cookie->flags, FULL));
28700 + cookie->h_pos = h_file->f_pos;
28707 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28710 + aufs_bindex_t bbot;
28711 + struct au_rdu_arg arg = {
28713 + .actor = au_rdu_fill
28716 + struct dentry *dentry;
28717 + struct inode *inode;
28718 + struct file *h_file;
28719 + struct au_rdu_cookie *cookie = &rdu->cookie;
28721 + /* VERIFY_WRITE */
28722 + err = !access_ok(rdu->ent.e, rdu->sz);
28723 + if (unlikely(err)) {
28729 + rdu->tail = rdu->ent;
28732 + arg.ent = rdu->ent;
28733 + arg.end = arg.ent.ul;
28734 + arg.end += rdu->sz;
28737 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28740 + err = security_file_permission(file, MAY_READ);
28742 + if (unlikely(err))
28745 + dentry = file->f_path.dentry;
28746 + inode = d_inode(dentry);
28747 + inode_lock_shared(inode);
28749 + arg.sb = inode->i_sb;
28750 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28751 + if (unlikely(err))
28753 + err = au_alive_dir(dentry);
28754 + if (unlikely(err))
28756 + /* todo: reval? */
28757 + fi_read_lock(file);
28760 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28761 + && cookie->generation != au_figen(file)))
28766 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28768 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28770 + bbot = au_fbtop(file);
28771 + if (cookie->bindex < bbot)
28772 + cookie->bindex = bbot;
28773 + bbot = au_fbbot_dir(file);
28774 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28775 + for (; !err && cookie->bindex <= bbot;
28776 + cookie->bindex++, cookie->h_pos = 0) {
28777 + h_file = au_hf_dir(file, cookie->bindex);
28781 + au_fclr_rdu(cookie->flags, FULL);
28782 + err = au_rdu_do(h_file, &arg);
28784 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28787 + AuDbg("rent %llu\n", rdu->rent);
28789 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28790 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28791 + au_fset_rdu(cookie->flags, CONT);
28792 + cookie->generation = au_figen(file);
28795 + ii_read_lock_child(inode);
28796 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28797 + ii_read_unlock(inode);
28800 + fi_read_unlock(file);
28802 + si_read_unlock(arg.sb);
28804 + inode_unlock_shared(inode);
28810 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28814 + unsigned long long nent;
28815 + union au_rdu_ent_ul *u;
28816 + struct au_rdu_ent ent;
28817 + struct super_block *sb;
28820 + nent = rdu->nent;
28822 + sb = file->f_path.dentry->d_sb;
28823 + si_read_lock(sb, AuLock_FLUSH);
28824 + while (nent-- > 0) {
28825 + /* unnecessary to support mmap_sem since this is a dir */
28826 + err = copy_from_user(&ent, u->e, sizeof(ent));
28828 + /* VERIFY_WRITE */
28829 + err = !access_ok(&u->e->ino, sizeof(ino));
28830 + if (unlikely(err)) {
28836 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28838 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28840 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28842 + if (unlikely(err)) {
28847 + err = __put_user(ino, &u->e->ino);
28848 + if (unlikely(err)) {
28853 + u->ul += au_rdu_len(ent.nlen);
28855 + si_read_unlock(sb);
28860 +/* ---------------------------------------------------------------------- */
28862 +static int au_rdu_verify(struct aufs_rdu *rdu)
28864 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28865 + "%llu, b%d, 0x%x, g%u}\n",
28866 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28868 + rdu->rent, rdu->shwh, rdu->full,
28869 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28870 + rdu->cookie.generation);
28872 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28876 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28880 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28883 + struct aufs_rdu rdu;
28884 + void __user *p = (void __user *)arg;
28886 + err = copy_from_user(&rdu, p, sizeof(rdu));
28887 + if (unlikely(err)) {
28892 + err = au_rdu_verify(&rdu);
28893 + if (unlikely(err))
28897 + case AUFS_CTL_RDU:
28898 + err = au_rdu(file, &rdu);
28899 + if (unlikely(err))
28902 + e = copy_to_user(p, &rdu, sizeof(rdu));
28903 + if (unlikely(e)) {
28908 + case AUFS_CTL_RDU_INO:
28909 + err = au_rdu_ino(file, &rdu);
28913 + /* err = -ENOTTY; */
28922 +#ifdef CONFIG_COMPAT
28923 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28926 + struct aufs_rdu rdu;
28927 + void __user *p = compat_ptr(arg);
28929 + /* todo: get_user()? */
28930 + err = copy_from_user(&rdu, p, sizeof(rdu));
28931 + if (unlikely(err)) {
28936 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28937 + err = au_rdu_verify(&rdu);
28938 + if (unlikely(err))
28942 + case AUFS_CTL_RDU:
28943 + err = au_rdu(file, &rdu);
28944 + if (unlikely(err))
28947 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28948 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28949 + e = copy_to_user(p, &rdu, sizeof(rdu));
28950 + if (unlikely(e)) {
28955 + case AUFS_CTL_RDU_INO:
28956 + err = au_rdu_ino(file, &rdu);
28960 + /* err = -ENOTTY; */
28969 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28970 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28971 +++ linux/fs/aufs/rwsem.h 2021-05-02 20:15:14.676670793 +0200
28973 +/* SPDX-License-Identifier: GPL-2.0 */
28975 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28977 + * This program, aufs is free software; you can redistribute it and/or modify
28978 + * it under the terms of the GNU General Public License as published by
28979 + * the Free Software Foundation; either version 2 of the License, or
28980 + * (at your option) any later version.
28982 + * This program is distributed in the hope that it will be useful,
28983 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28984 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28985 + * GNU General Public License for more details.
28987 + * You should have received a copy of the GNU General Public License
28988 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28992 + * simple read-write semaphore wrappers
28995 +#ifndef __AUFS_RWSEM_H__
28996 +#define __AUFS_RWSEM_H__
29000 +#include "debug.h"
29002 +/* in the future, the name 'au_rwsem' will be totally gone */
29003 +#define au_rwsem rw_semaphore
29005 +/* to debug easier, do not make them inlined functions */
29006 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29008 +#ifdef CONFIG_LOCKDEP
29009 +/* rwsem_is_locked() is unusable */
29010 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29011 + && !lockdep_recursing(current) \
29013 + && !lockdep_is_held_type(rw, 1))
29014 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29015 + && !lockdep_recursing(current) \
29017 + && !lockdep_is_held_type(rw, 0))
29018 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29019 + && !lockdep_recursing(current) \
29021 + && !lockdep_is_held(rw))
29022 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29023 + && !lockdep_recursing(current) \
29025 + && lockdep_is_held(rw))
29027 +#define AuRwMustReadLock(rw) do {} while (0)
29028 +#define AuRwMustWriteLock(rw) do {} while (0)
29029 +#define AuRwMustAnyLock(rw) do {} while (0)
29030 +#define AuRwDestroy(rw) do {} while (0)
29033 +#define au_rw_init(rw) init_rwsem(rw)
29035 +#define au_rw_init_wlock(rw) do { \
29036 + au_rw_init(rw); \
29037 + down_write(rw); \
29040 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29041 + au_rw_init(rw); \
29042 + down_write_nested(rw, lsc); \
29045 +#define au_rw_read_lock(rw) down_read(rw)
29046 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29047 +#define au_rw_read_unlock(rw) up_read(rw)
29048 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29049 +#define au_rw_write_lock(rw) down_write(rw)
29050 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29051 +#define au_rw_write_unlock(rw) up_write(rw)
29052 +/* why is not _nested version defined? */
29053 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29054 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29056 +#endif /* __KERNEL__ */
29057 +#endif /* __AUFS_RWSEM_H__ */
29058 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29059 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29060 +++ linux/fs/aufs/sbinfo.c 2021-05-02 20:15:14.676670793 +0200
29062 +// SPDX-License-Identifier: GPL-2.0
29064 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29066 + * This program, aufs is free software; you can redistribute it and/or modify
29067 + * it under the terms of the GNU General Public License as published by
29068 + * the Free Software Foundation; either version 2 of the License, or
29069 + * (at your option) any later version.
29071 + * This program is distributed in the hope that it will be useful,
29072 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29073 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29074 + * GNU General Public License for more details.
29076 + * You should have received a copy of the GNU General Public License
29077 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29081 + * superblock private data
29084 +#include <linux/iversion.h>
29088 + * they are necessary regardless sysfs is disabled.
29090 +void au_si_free(struct kobject *kobj)
29093 + struct au_sbinfo *sbinfo;
29094 + char *locked __maybe_unused; /* debug only */
29096 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29097 + for (i = 0; i < AuPlink_NHASH; i++)
29098 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29099 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29101 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29102 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29103 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29104 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29106 + dbgaufs_si_fin(sbinfo);
29107 + au_rw_write_lock(&sbinfo->si_rwsem);
29108 + au_br_free(sbinfo);
29109 + au_rw_write_unlock(&sbinfo->si_rwsem);
29111 + au_kfree_try_rcu(sbinfo->si_branch);
29112 + mutex_destroy(&sbinfo->si_xib_mtx);
29113 + AuRwDestroy(&sbinfo->si_rwsem);
29115 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29116 + /* si_nfiles is waited too */
29117 + au_kfree_rcu(sbinfo);
29120 +int au_si_alloc(struct super_block *sb)
29123 + struct au_sbinfo *sbinfo;
29126 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29127 + if (unlikely(!sbinfo))
29130 + /* will be reallocated separately */
29131 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29132 + if (unlikely(!sbinfo->si_branch))
29135 + err = sysaufs_si_init(sbinfo);
29137 + dbgaufs_si_null(sbinfo);
29138 + err = dbgaufs_si_init(sbinfo);
29139 + if (unlikely(err))
29140 + kobject_put(&sbinfo->si_kobj);
29142 + if (unlikely(err))
29145 + au_nwt_init(&sbinfo->si_nowait);
29146 + au_rw_init_wlock(&sbinfo->si_rwsem);
29148 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29149 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29151 + sbinfo->si_bbot = -1;
29152 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29154 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29155 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29156 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29157 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29159 + au_fhsm_init(sbinfo);
29161 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29163 + sbinfo->si_xino_jiffy = jiffies;
29164 + sbinfo->si_xino_expire
29165 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29166 + mutex_init(&sbinfo->si_xib_mtx);
29167 + /* leave si_xib_last_pindex and si_xib_next_bit */
29169 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29171 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29172 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29173 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29174 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29176 + for (i = 0; i < AuPlink_NHASH; i++)
29177 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29178 + init_waitqueue_head(&sbinfo->si_plink_wq);
29179 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29181 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29183 + /* with getattr by default */
29184 + sbinfo->si_iop_array = aufs_iop;
29186 + /* leave other members for sysaufs and si_mnt. */
29187 + sbinfo->si_sb = sb;
29188 + sb->s_fs_info = sbinfo;
29190 + return 0; /* success */
29193 + au_kfree_try_rcu(sbinfo->si_branch);
29195 + au_kfree_rcu(sbinfo);
29200 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29203 + struct au_branch **brp;
29205 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29208 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29209 + if (unlikely(!sz))
29210 + sz = sizeof(*brp);
29211 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29214 + sbinfo->si_branch = brp;
29221 +/* ---------------------------------------------------------------------- */
29223 +unsigned int au_sigen_inc(struct super_block *sb)
29225 + unsigned int gen;
29226 + struct inode *inode;
29228 + SiMustWriteLock(sb);
29230 + gen = ++au_sbi(sb)->si_generation;
29231 + au_update_digen(sb->s_root);
29232 + inode = d_inode(sb->s_root);
29233 + au_update_iigen(inode, /*half*/0);
29234 + inode_inc_iversion(inode);
29238 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29240 + aufs_bindex_t br_id;
29242 + struct au_sbinfo *sbinfo;
29244 + SiMustWriteLock(sb);
29246 + sbinfo = au_sbi(sb);
29247 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29248 + br_id = ++sbinfo->si_last_br_id;
29249 + AuDebugOn(br_id < 0);
29250 + if (br_id && au_br_index(sb, br_id) < 0)
29257 +/* ---------------------------------------------------------------------- */
29259 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29260 +int si_read_lock(struct super_block *sb, int flags)
29265 + if (au_ftest_lock(flags, FLUSH))
29266 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29268 + si_noflush_read_lock(sb);
29269 + err = au_plink_maint(sb, flags);
29270 + if (unlikely(err))
29271 + si_read_unlock(sb);
29276 +int si_write_lock(struct super_block *sb, int flags)
29280 + if (au_ftest_lock(flags, FLUSH))
29281 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29283 + si_noflush_write_lock(sb);
29284 + err = au_plink_maint(sb, flags);
29285 + if (unlikely(err))
29286 + si_write_unlock(sb);
29291 +/* dentry and super_block lock. call at entry point */
29292 +int aufs_read_lock(struct dentry *dentry, int flags)
29295 + struct super_block *sb;
29297 + sb = dentry->d_sb;
29298 + err = si_read_lock(sb, flags);
29299 + if (unlikely(err))
29302 + if (au_ftest_lock(flags, DW))
29303 + di_write_lock_child(dentry);
29305 + di_read_lock_child(dentry, flags);
29307 + if (au_ftest_lock(flags, GEN)) {
29308 + err = au_digen_test(dentry, au_sigen(sb));
29309 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29310 + AuDebugOn(!err && au_dbrange_test(dentry));
29312 + err = au_dbrange_test(dentry);
29313 + if (unlikely(err))
29314 + aufs_read_unlock(dentry, flags);
29321 +void aufs_read_unlock(struct dentry *dentry, int flags)
29323 + if (au_ftest_lock(flags, DW))
29324 + di_write_unlock(dentry);
29326 + di_read_unlock(dentry, flags);
29327 + si_read_unlock(dentry->d_sb);
29330 +void aufs_write_lock(struct dentry *dentry)
29332 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29333 + di_write_lock_child(dentry);
29336 +void aufs_write_unlock(struct dentry *dentry)
29338 + di_write_unlock(dentry);
29339 + si_write_unlock(dentry->d_sb);
29342 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29345 + unsigned int sigen;
29346 + struct super_block *sb;
29349 + err = si_read_lock(sb, flags);
29350 + if (unlikely(err))
29353 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29355 + if (au_ftest_lock(flags, GEN)) {
29356 + sigen = au_sigen(sb);
29357 + err = au_digen_test(d1, sigen);
29358 + AuDebugOn(!err && au_dbrange_test(d1));
29360 + err = au_digen_test(d2, sigen);
29361 + AuDebugOn(!err && au_dbrange_test(d2));
29363 + if (unlikely(err))
29364 + aufs_read_and_write_unlock2(d1, d2);
29371 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29373 + di_write_unlock2(d1, d2);
29374 + si_read_unlock(d1->d_sb);
29376 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29377 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29378 +++ linux/fs/aufs/super.c 2021-05-02 20:15:14.676670793 +0200
29380 +// SPDX-License-Identifier: GPL-2.0
29382 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29384 + * This program, aufs is free software; you can redistribute it and/or modify
29385 + * it under the terms of the GNU General Public License as published by
29386 + * the Free Software Foundation; either version 2 of the License, or
29387 + * (at your option) any later version.
29389 + * This program is distributed in the hope that it will be useful,
29390 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29391 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29392 + * GNU General Public License for more details.
29394 + * You should have received a copy of the GNU General Public License
29395 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29399 + * mount and super_block operations
29402 +#include <linux/iversion.h>
29403 +#include <linux/mm.h>
29404 +#include <linux/seq_file.h>
29405 +#include <linux/statfs.h>
29406 +#include <linux/vmalloc.h>
29410 + * super_operations
29412 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29414 + struct au_icntnr *c;
29416 + c = au_cache_alloc_icntnr();
29418 + au_icntnr_init(c);
29419 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29420 + c->iinfo.ii_hinode = NULL;
29421 + return &c->vfs_inode;
29426 +static void aufs_destroy_inode(struct inode *inode)
29428 + if (!au_is_bad_inode(inode))
29429 + au_iinfo_fin(inode);
29432 +static void aufs_free_inode(struct inode *inode)
29434 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29437 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29439 + struct inode *inode;
29442 + inode = iget_locked(sb, ino);
29443 + if (unlikely(!inode)) {
29444 + inode = ERR_PTR(-ENOMEM);
29447 + if (!(inode->i_state & I_NEW))
29450 + err = au_xigen_new(inode);
29452 + err = au_iinfo_init(inode);
29454 + inode_inc_iversion(inode);
29456 + iget_failed(inode);
29457 + inode = ERR_PTR(err);
29461 + /* never return NULL */
29462 + AuDebugOn(!inode);
29463 + AuTraceErrPtr(inode);
29467 +/* lock free root dinfo */
29468 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29471 + aufs_bindex_t bindex, bbot;
29472 + struct path path;
29473 + struct au_hdentry *hdp;
29474 + struct au_branch *br;
29475 + au_br_perm_str_t perm;
29478 + bbot = au_sbbot(sb);
29480 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29481 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29482 + br = au_sbr(sb, bindex);
29483 + path.mnt = au_br_mnt(br);
29484 + path.dentry = hdp->hd_dentry;
29485 + err = au_seq_path(seq, &path);
29487 + au_optstr_br_perm(&perm, br->br_perm);
29488 + seq_printf(seq, "=%s", perm.a);
29489 + if (bindex != bbot)
29490 + seq_putc(seq, ':');
29493 + if (unlikely(err || seq_has_overflowed(seq)))
29499 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29500 + const char *append)
29505 + while (*pat != ':')
29508 + strcpy(p, append);
29509 + AuDebugOn(strlen(fmt) >= len);
29512 +static void au_show_wbr_create(struct seq_file *m, int v,
29513 + struct au_sbinfo *sbinfo)
29517 + struct au_wbr_mfs *mfs;
29519 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29521 + seq_puts(m, ",create=");
29522 + pat = au_optstr_wbr_create(v);
29523 + mfs = &sbinfo->si_wbr_mfs;
29525 + case AuWbrCreate_TDP:
29526 + case AuWbrCreate_RR:
29527 + case AuWbrCreate_MFS:
29528 + case AuWbrCreate_PMFS:
29529 + seq_puts(m, pat);
29531 + case AuWbrCreate_MFSRR:
29532 + case AuWbrCreate_TDMFS:
29533 + case AuWbrCreate_PMFSRR:
29534 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29535 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29537 + case AuWbrCreate_MFSV:
29538 + case AuWbrCreate_PMFSV:
29539 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29540 + seq_printf(m, fmt,
29541 + jiffies_to_msecs(mfs->mfs_expire)
29544 + case AuWbrCreate_MFSRRV:
29545 + case AuWbrCreate_TDMFSV:
29546 + case AuWbrCreate_PMFSRRV:
29547 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29548 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29549 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29556 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29558 +#ifdef CONFIG_SYSFS
29562 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29563 + aufs_bindex_t bindex, brid;
29564 + struct qstr *name;
29566 + struct dentry *d, *h_root;
29567 + struct au_branch *br;
29569 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29572 + f = au_sbi(sb)->si_xib;
29576 + /* stop printing the default xino path on the first writable branch */
29578 + bindex = au_xi_root(sb, f->f_path.dentry);
29579 + if (bindex >= 0) {
29580 + br = au_sbr_sb(sb, bindex);
29581 + h_root = au_br_dentry(br);
29584 + d = f->f_path.dentry;
29585 + name = &d->d_name;
29586 + /* safe ->d_parent because the file is unlinked */
29587 + if (d->d_parent == h_root
29588 + && name->len == len
29589 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29592 + seq_puts(seq, ",xino=");
29593 + err = au_xino_path(seq, f);
29600 +/* seq_file will re-call me in case of too long string */
29601 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29604 + unsigned int mnt_flags, v;
29605 + struct super_block *sb;
29606 + struct au_sbinfo *sbinfo;
29608 +#define AuBool(name, str) do { \
29609 + v = au_opt_test(mnt_flags, name); \
29610 + if (v != au_opt_test(AuOpt_Def, name)) \
29611 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29614 +#define AuStr(name, str) do { \
29615 + v = mnt_flags & AuOptMask_##name; \
29616 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29617 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29620 +#define AuUInt(name, str, val) do { \
29621 + if (val != AUFS_##name##_DEF) \
29622 + seq_printf(m, "," #str "=%u", val); \
29625 + sb = dentry->d_sb;
29626 + if (sb->s_flags & SB_POSIXACL)
29627 + seq_puts(m, ",acl");
29628 +#if 0 /* reserved for future use */
29629 + if (sb->s_flags & SB_I_VERSION)
29630 + seq_puts(m, ",i_version");
29633 + /* lock free root dinfo */
29634 + si_noflush_read_lock(sb);
29635 + sbinfo = au_sbi(sb);
29636 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29638 + mnt_flags = au_mntflags(sb);
29639 + if (au_opt_test(mnt_flags, XINO)) {
29640 + err = au_show_xino(m, sb);
29641 + if (unlikely(err))
29644 + seq_puts(m, ",noxino");
29646 + AuBool(TRUNC_XINO, trunc_xino);
29647 + AuStr(UDBA, udba);
29648 + AuBool(SHWH, shwh);
29649 + AuBool(PLINK, plink);
29650 + AuBool(DIO, dio);
29651 + AuBool(DIRPERM1, dirperm1);
29653 + v = sbinfo->si_wbr_create;
29654 + if (v != AuWbrCreate_Def)
29655 + au_show_wbr_create(m, v, sbinfo);
29657 + v = sbinfo->si_wbr_copyup;
29658 + if (v != AuWbrCopyup_Def)
29659 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29661 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29662 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29663 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29665 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29667 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29668 + AuUInt(RDCACHE, rdcache, v);
29670 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29671 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29673 + au_fhsm_show(m, sbinfo);
29675 + AuBool(DIRREN, dirren);
29676 + AuBool(SUM, sum);
29677 + /* AuBool(SUM_W, wsum); */
29678 + AuBool(WARN_PERM, warn_perm);
29679 + AuBool(VERBOSE, verbose);
29682 + /* be sure to print "br:" last */
29683 + if (!sysaufs_brs) {
29684 + seq_puts(m, ",br:");
29685 + au_show_brs(m, sb);
29687 + si_read_unlock(sb);
29695 +/* ---------------------------------------------------------------------- */
29697 +/* sum mode which returns the summation for statfs(2) */
29699 +static u64 au_add_till_max(u64 a, u64 b)
29707 + return ULLONG_MAX;
29710 +static u64 au_mul_till_max(u64 a, long mul)
29718 + return ULLONG_MAX;
29721 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29724 + long bsize, factor;
29725 + u64 blocks, bfree, bavail, files, ffree;
29726 + aufs_bindex_t bbot, bindex, i;
29727 + unsigned char shared;
29728 + struct path h_path;
29729 + struct super_block *h_sb;
29732 + bsize = LONG_MAX;
29738 + bbot = au_sbbot(sb);
29739 + for (bindex = 0; bindex <= bbot; bindex++) {
29740 + h_path.mnt = au_sbr_mnt(sb, bindex);
29741 + h_sb = h_path.mnt->mnt_sb;
29743 + for (i = 0; !shared && i < bindex; i++)
29744 + shared = (au_sbr_sb(sb, i) == h_sb);
29748 + /* sb->s_root for NFS is unreliable */
29749 + h_path.dentry = h_path.mnt->mnt_root;
29750 + err = vfs_statfs(&h_path, buf);
29751 + if (unlikely(err))
29754 + if (bsize > buf->f_bsize) {
29756 + * we will reduce bsize, so we have to expand blocks
29757 + * etc. to match them again
29759 + factor = (bsize / buf->f_bsize);
29760 + blocks = au_mul_till_max(blocks, factor);
29761 + bfree = au_mul_till_max(bfree, factor);
29762 + bavail = au_mul_till_max(bavail, factor);
29763 + bsize = buf->f_bsize;
29766 + factor = (buf->f_bsize / bsize);
29767 + blocks = au_add_till_max(blocks,
29768 + au_mul_till_max(buf->f_blocks, factor));
29769 + bfree = au_add_till_max(bfree,
29770 + au_mul_till_max(buf->f_bfree, factor));
29771 + bavail = au_add_till_max(bavail,
29772 + au_mul_till_max(buf->f_bavail, factor));
29773 + files = au_add_till_max(files, buf->f_files);
29774 + ffree = au_add_till_max(ffree, buf->f_ffree);
29777 + buf->f_bsize = bsize;
29778 + buf->f_blocks = blocks;
29779 + buf->f_bfree = bfree;
29780 + buf->f_bavail = bavail;
29781 + buf->f_files = files;
29782 + buf->f_ffree = ffree;
29783 + buf->f_frsize = 0;
29789 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29792 + struct path h_path;
29793 + struct super_block *sb;
29795 + /* lock free root dinfo */
29796 + sb = dentry->d_sb;
29797 + si_noflush_read_lock(sb);
29798 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29799 + /* sb->s_root for NFS is unreliable */
29800 + h_path.mnt = au_sbr_mnt(sb, 0);
29801 + h_path.dentry = h_path.mnt->mnt_root;
29802 + err = vfs_statfs(&h_path, buf);
29804 + err = au_statfs_sum(sb, buf);
29805 + si_read_unlock(sb);
29808 + buf->f_type = AUFS_SUPER_MAGIC;
29809 + buf->f_namelen = AUFS_MAX_NAMELEN;
29810 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29812 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29817 +/* ---------------------------------------------------------------------- */
29819 +static int aufs_sync_fs(struct super_block *sb, int wait)
29822 + aufs_bindex_t bbot, bindex;
29823 + struct au_branch *br;
29824 + struct super_block *h_sb;
29827 + si_noflush_read_lock(sb);
29828 + bbot = au_sbbot(sb);
29829 + for (bindex = 0; bindex <= bbot; bindex++) {
29830 + br = au_sbr(sb, bindex);
29831 + if (!au_br_writable(br->br_perm))
29834 + h_sb = au_sbr_sb(sb, bindex);
29835 + e = vfsub_sync_filesystem(h_sb, wait);
29836 + if (unlikely(e && !err))
29838 + /* go on even if an error happens */
29840 + si_read_unlock(sb);
29845 +/* ---------------------------------------------------------------------- */
29847 +/* final actions when unmounting a file system */
29848 +static void aufs_put_super(struct super_block *sb)
29850 + struct au_sbinfo *sbinfo;
29852 + sbinfo = au_sbi(sb);
29854 + kobject_put(&sbinfo->si_kobj);
29857 +/* ---------------------------------------------------------------------- */
29859 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29860 + struct super_block *sb, void *arg)
29863 + unsigned long long n, sz;
29870 + if (*hint > ULLONG_MAX / sizeof(array)) {
29871 + array = ERR_PTR(-EMFILE);
29872 + pr_err("hint %llu\n", *hint);
29876 + sz = sizeof(array) * *hint;
29877 + array = kzalloc(sz, GFP_NOFS);
29878 + if (unlikely(!array))
29879 + array = vzalloc(sz);
29880 + if (unlikely(!array)) {
29881 + array = ERR_PTR(-ENOMEM);
29885 + n = cb(sb, array, *hint, arg);
29886 + AuDebugOn(n > *hint);
29893 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29894 + unsigned long long max __maybe_unused,
29897 + unsigned long long n;
29898 + struct inode **p, *inode;
29899 + struct list_head *head;
29904 + spin_lock(&sb->s_inode_list_lock);
29905 + list_for_each_entry(inode, head, i_sb_list) {
29906 + if (!au_is_bad_inode(inode)
29907 + && au_ii(inode)->ii_btop >= 0) {
29908 + spin_lock(&inode->i_lock);
29909 + if (atomic_read(&inode->i_count)) {
29913 + AuDebugOn(n > max);
29915 + spin_unlock(&inode->i_lock);
29918 + spin_unlock(&sb->s_inode_list_lock);
29923 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29925 + struct au_sbinfo *sbi;
29927 + sbi = au_sbi(sb);
29928 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29929 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29932 +void au_iarray_free(struct inode **a, unsigned long long max)
29934 + unsigned long long ull;
29936 + for (ull = 0; ull < max; ull++)
29941 +/* ---------------------------------------------------------------------- */
29944 + * refresh dentry and inode at remount time.
29946 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29947 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29948 + struct dentry *parent)
29952 + di_write_lock_child(dentry);
29953 + di_read_lock_parent(parent, AuLock_IR);
29954 + err = au_refresh_dentry(dentry, parent);
29955 + if (!err && dir_flags)
29956 + au_hn_reset(d_inode(dentry), dir_flags);
29957 + di_read_unlock(parent, AuLock_IR);
29958 + di_write_unlock(dentry);
29963 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29964 + struct au_sbinfo *sbinfo,
29965 + const unsigned int dir_flags, unsigned int do_idop)
29968 + struct dentry *parent;
29971 + parent = dget_parent(dentry);
29972 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29973 + if (d_really_is_positive(dentry)) {
29974 + if (!d_is_dir(dentry))
29975 + err = au_do_refresh(dentry, /*dir_flags*/0,
29978 + err = au_do_refresh(dentry, dir_flags, parent);
29979 + if (unlikely(err))
29980 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29983 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29984 + AuDbgDentry(dentry);
29990 + au_refresh_dop(dentry, /*force_reval*/0);
29992 + au_refresh_dop(dentry, /*force_reval*/1);
29998 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30000 + int err, i, j, ndentry, e;
30001 + unsigned int sigen;
30002 + struct au_dcsub_pages dpages;
30003 + struct au_dpage *dpage;
30004 + struct dentry **dentries, *d;
30005 + struct au_sbinfo *sbinfo;
30006 + struct dentry *root = sb->s_root;
30007 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30010 + au_refresh_dop(root, /*force_reval*/0);
30012 + err = au_dpages_init(&dpages, GFP_NOFS);
30013 + if (unlikely(err))
30015 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30016 + if (unlikely(err))
30019 + sigen = au_sigen(sb);
30020 + sbinfo = au_sbi(sb);
30021 + for (i = 0; i < dpages.ndpage; i++) {
30022 + dpage = dpages.dpages + i;
30023 + dentries = dpage->dentries;
30024 + ndentry = dpage->ndentry;
30025 + for (j = 0; j < ndentry; j++) {
30027 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30029 + if (unlikely(e && !err))
30031 + /* go on even err */
30036 + au_dpages_free(&dpages);
30041 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30044 + unsigned int sigen;
30045 + unsigned long long max, ull;
30046 + struct inode *inode, **array;
30048 + array = au_iarray_alloc(sb, &max);
30049 + err = PTR_ERR(array);
30050 + if (IS_ERR(array))
30054 + sigen = au_sigen(sb);
30055 + for (ull = 0; ull < max; ull++) {
30056 + inode = array[ull];
30057 + if (unlikely(!inode))
30061 + ii_write_lock_child(inode);
30062 + if (au_iigen(inode, NULL) != sigen) {
30063 + e = au_refresh_hinode_self(inode);
30064 + if (unlikely(e)) {
30065 + au_refresh_iop(inode, /*force_getattr*/1);
30066 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30069 + /* go on even if err */
30072 + if (!e && do_idop)
30073 + au_refresh_iop(inode, /*force_getattr*/0);
30074 + ii_write_unlock(inode);
30077 + au_iarray_free(array, max);
30083 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30086 + unsigned int udba;
30087 + aufs_bindex_t bindex, bbot;
30088 + struct dentry *root;
30089 + struct inode *inode;
30090 + struct au_branch *br;
30091 + struct au_sbinfo *sbi;
30093 + au_sigen_inc(sb);
30094 + sbi = au_sbi(sb);
30095 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30097 + root = sb->s_root;
30098 + DiMustNoWaiters(root);
30099 + inode = d_inode(root);
30100 + IiMustNoWaiters(inode);
30102 + udba = au_opt_udba(sb);
30103 + bbot = au_sbbot(sb);
30104 + for (bindex = 0; bindex <= bbot; bindex++) {
30105 + br = au_sbr(sb, bindex);
30106 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30107 + if (unlikely(err))
30108 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30110 + /* go on even if err */
30112 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30115 + if (au_ftest_si(sbi, NO_DREVAL)) {
30116 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30117 + sb->s_d_op = &aufs_dop_noreval;
30118 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30119 + sbi->si_iop_array = aufs_iop_nogetattr;
30121 + AuDebugOn(sb->s_d_op == &aufs_dop);
30122 + sb->s_d_op = &aufs_dop;
30123 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30124 + sbi->si_iop_array = aufs_iop;
30126 + pr_info("reset to %ps and %ps\n",
30127 + sb->s_d_op, sbi->si_iop_array);
30130 + di_write_unlock(root);
30131 + err = au_refresh_d(sb, do_idop);
30132 + e = au_refresh_i(sb, do_idop);
30133 + if (unlikely(e && !err))
30135 + /* aufs_write_lock() calls ..._child() */
30136 + di_write_lock_child(root);
30138 + au_cpup_attr_all(inode, /*force*/1);
30140 + if (unlikely(err))
30141 + AuIOErr("refresh failed, ignored, %d\n", err);
30144 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30145 +static int cvt_err(int err)
30159 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30162 + unsigned int mntflags;
30163 + struct au_opts opts = {
30166 + struct dentry *root;
30167 + struct inode *inode;
30168 + struct au_sbinfo *sbinfo;
30171 + root = sb->s_root;
30172 + if (!data || !*data) {
30173 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30175 + di_write_lock_child(root);
30176 + err = au_opts_verify(sb, *flags, /*pending*/0);
30177 + aufs_write_unlock(root);
30183 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30184 + if (unlikely(!opts.opt))
30186 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30187 + opts.flags = AuOpts_REMOUNT;
30188 + opts.sb_flags = *flags;
30190 + /* parse it before aufs lock */
30191 + err = au_opts_parse(sb, data, &opts);
30192 + if (unlikely(err))
30195 + sbinfo = au_sbi(sb);
30196 + inode = d_inode(root);
30197 + inode_lock(inode);
30198 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30199 + if (unlikely(err))
30201 + di_write_lock_child(root);
30203 + /* au_opts_remount() may return an error */
30204 + err = au_opts_remount(sb, &opts);
30205 + au_opts_free(&opts);
30207 + if (au_ftest_opts(opts.flags, REFRESH))
30208 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30210 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30211 + mntflags = au_mntflags(sb);
30212 + do_dx = !!au_opt_test(mntflags, DIO);
30213 + au_dy_arefresh(do_dx);
30216 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30217 + aufs_write_unlock(root);
30220 + inode_unlock(inode);
30222 + free_page((unsigned long)opts.opt);
30224 + err = cvt_err(err);
30229 +static const struct super_operations aufs_sop = {
30230 + .alloc_inode = aufs_alloc_inode,
30231 + .destroy_inode = aufs_destroy_inode,
30232 + .free_inode = aufs_free_inode,
30233 + /* always deleting, no clearing */
30234 + .drop_inode = generic_delete_inode,
30235 + .show_options = aufs_show_options,
30236 + .statfs = aufs_statfs,
30237 + .put_super = aufs_put_super,
30238 + .sync_fs = aufs_sync_fs,
30239 + .remount_fs = aufs_remount_fs
30242 +/* ---------------------------------------------------------------------- */
30244 +static int alloc_root(struct super_block *sb)
30247 + struct inode *inode;
30248 + struct dentry *root;
30251 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30252 + err = PTR_ERR(inode);
30253 + if (IS_ERR(inode))
30256 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30257 + inode->i_fop = &aufs_dir_fop;
30258 + inode->i_mode = S_IFDIR;
30259 + set_nlink(inode, 2);
30260 + unlock_new_inode(inode);
30262 + root = d_make_root(inode);
30263 + if (unlikely(!root))
30265 + err = PTR_ERR(root);
30266 + if (IS_ERR(root))
30269 + err = au_di_init(root);
30271 + sb->s_root = root;
30272 + return 0; /* success */
30280 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30281 + int silent __maybe_unused)
30284 + struct au_opts opts = {
30287 + struct au_sbinfo *sbinfo;
30288 + struct dentry *root;
30289 + struct inode *inode;
30290 + char *arg = raw_data;
30292 + if (unlikely(!arg || !*arg)) {
30294 + pr_err("no arg\n");
30299 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30300 + if (unlikely(!opts.opt))
30302 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30303 + opts.sb_flags = sb->s_flags;
30305 + err = au_si_alloc(sb);
30306 + if (unlikely(err))
30308 + sbinfo = au_sbi(sb);
30310 + /* all timestamps always follow the ones on the branch */
30311 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30312 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30313 + sb->s_op = &aufs_sop;
30314 + sb->s_d_op = &aufs_dop;
30315 + sb->s_magic = AUFS_SUPER_MAGIC;
30316 + sb->s_maxbytes = 0;
30317 + sb->s_stack_depth = 1;
30318 + au_export_init(sb);
30319 + au_xattr_init(sb);
30321 + err = alloc_root(sb);
30322 + if (unlikely(err)) {
30323 + si_write_unlock(sb);
30326 + root = sb->s_root;
30327 + inode = d_inode(root);
30330 + * actually we can parse options regardless aufs lock here.
30331 + * but at remount time, parsing must be done before aufs lock.
30332 + * so we follow the same rule.
30334 + ii_write_lock_parent(inode);
30335 + aufs_write_unlock(root);
30336 + err = au_opts_parse(sb, arg, &opts);
30337 + if (unlikely(err))
30340 + /* lock vfs_inode first, then aufs. */
30341 + inode_lock(inode);
30342 + aufs_write_lock(root);
30343 + err = au_opts_mount(sb, &opts);
30344 + au_opts_free(&opts);
30345 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30346 + sb->s_d_op = &aufs_dop_noreval;
30347 + pr_info("%ps\n", sb->s_d_op);
30348 + au_refresh_dop(root, /*force_reval*/0);
30349 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30350 + au_refresh_iop(inode, /*force_getattr*/0);
30352 + aufs_write_unlock(root);
30353 + inode_unlock(inode);
30355 + goto out_opts; /* success */
30359 + sb->s_root = NULL;
30361 + kobject_put(&sbinfo->si_kobj);
30362 + sb->s_fs_info = NULL;
30364 + free_page((unsigned long)opts.opt);
30367 + err = cvt_err(err);
30372 +/* ---------------------------------------------------------------------- */
30374 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30375 + const char *dev_name __maybe_unused,
30378 + struct dentry *root;
30380 + /* all timestamps always follow the ones on the branch */
30381 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30382 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30383 + if (IS_ERR(root))
30386 + au_sbilist_add(root->d_sb);
30392 +static void aufs_kill_sb(struct super_block *sb)
30394 + struct au_sbinfo *sbinfo;
30396 + sbinfo = au_sbi(sb);
30398 + au_sbilist_del(sb);
30399 + aufs_write_lock(sb->s_root);
30401 + if (sbinfo->si_wbr_create_ops->fin)
30402 + sbinfo->si_wbr_create_ops->fin(sb);
30403 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30404 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30405 + au_remount_refresh(sb, /*do_idop*/0);
30407 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30408 + au_plink_put(sb, /*verbose*/1);
30410 + au_dr_opt_flush(sb);
30411 + sbinfo->si_sb = NULL;
30412 + aufs_write_unlock(sb->s_root);
30413 + au_nwt_flush(&sbinfo->si_nowait);
30415 + kill_anon_super(sb);
30418 +struct file_system_type aufs_fs_type = {
30419 + .name = AUFS_FSTYPE,
30420 + /* a race between rename and others */
30421 + .fs_flags = FS_RENAME_DOES_D_MOVE
30423 + /*| FS_ALLOW_IDMAP*/
30425 + .mount = aufs_mount,
30426 + .kill_sb = aufs_kill_sb,
30427 + /* no need to __module_get() and module_put(). */
30428 + .owner = THIS_MODULE,
30430 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30431 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30432 +++ linux/fs/aufs/super.h 2021-05-02 20:15:14.676670793 +0200
30434 +/* SPDX-License-Identifier: GPL-2.0 */
30436 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30438 + * This program, aufs is free software; you can redistribute it and/or modify
30439 + * it under the terms of the GNU General Public License as published by
30440 + * the Free Software Foundation; either version 2 of the License, or
30441 + * (at your option) any later version.
30443 + * This program is distributed in the hope that it will be useful,
30444 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30445 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30446 + * GNU General Public License for more details.
30448 + * You should have received a copy of the GNU General Public License
30449 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30453 + * super_block operations
30456 +#ifndef __AUFS_SUPER_H__
30457 +#define __AUFS_SUPER_H__
30461 +#include <linux/fs.h>
30462 +#include <linux/kobject.h>
30465 +#include "rwsem.h"
30468 +/* policies to select one among multiple writable branches */
30469 +struct au_wbr_copyup_operations {
30470 + int (*copyup)(struct dentry *dentry);
30473 +#define AuWbr_DIR 1 /* target is a dir */
30474 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30476 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30477 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30478 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30480 +struct au_wbr_create_operations {
30481 + int (*create)(struct dentry *dentry, unsigned int flags);
30482 + int (*init)(struct super_block *sb);
30483 + int (*fin)(struct super_block *sb);
30486 +struct au_wbr_mfs {
30487 + struct mutex mfs_lock; /* protect this structure */
30488 + unsigned long mfs_jiffy;
30489 + unsigned long mfs_expire;
30490 + aufs_bindex_t mfs_bindex;
30492 + unsigned long long mfsrr_bytes;
30493 + unsigned long long mfsrr_watermark;
30496 +#define AuPlink_NHASH 100
30497 +static inline int au_plink_hash(ino_t ino)
30499 + return ino % AuPlink_NHASH;
30502 +/* File-based Hierarchical Storage Management */
30504 +#ifdef CONFIG_AUFS_FHSM
30505 + /* allow only one process who can receive the notification */
30506 + spinlock_t fhsm_spin;
30508 + wait_queue_head_t fhsm_wqh;
30509 + atomic_t fhsm_readable;
30511 + /* these are protected by si_rwsem */
30512 + unsigned long fhsm_expire;
30513 + aufs_bindex_t fhsm_bottom;
30518 +struct au_sbinfo {
30519 + /* nowait tasks in the system-wide workqueue */
30520 + struct au_nowait_tasks si_nowait;
30523 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30524 + * rwsem for au_sbinfo is necessary.
30526 + struct au_rwsem si_rwsem;
30529 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30532 + au_lcnt_t si_ninodes, si_nfiles;
30534 + /* branch management */
30535 + unsigned int si_generation;
30537 + /* see AuSi_ flags */
30538 + unsigned char au_si_status;
30540 + aufs_bindex_t si_bbot;
30542 + /* dirty trick to keep br_id plus */
30543 + unsigned int si_last_br_id :
30544 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30545 + struct au_branch **si_branch;
30547 + /* policy to select a writable branch */
30548 + unsigned char si_wbr_copyup;
30549 + unsigned char si_wbr_create;
30550 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30551 + struct au_wbr_create_operations *si_wbr_create_ops;
30553 + /* round robin */
30554 + atomic_t si_wbr_rr_next;
30556 + /* most free space */
30557 + struct au_wbr_mfs si_wbr_mfs;
30559 + /* File-based Hierarchical Storage Management */
30560 + struct au_fhsm si_fhsm;
30562 + /* mount flags */
30563 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30564 + unsigned int si_mntflags;
30566 + /* external inode number (bitmap and translation table) */
30567 + loff_t si_ximaxent; /* max entries in a xino */
30569 + struct file *si_xib;
30570 + struct mutex si_xib_mtx; /* protect xib members */
30571 + unsigned long *si_xib_buf;
30572 + unsigned long si_xib_last_pindex;
30573 + int si_xib_next_bit;
30575 + unsigned long si_xino_jiffy;
30576 + unsigned long si_xino_expire;
30577 + /* reserved for future use */
30578 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30580 +#ifdef CONFIG_AUFS_EXPORT
30581 + /* i_generation */
30582 + /* todo: make xigen file an array to support many inode numbers */
30583 + struct file *si_xigen;
30584 + atomic_t si_xigen_next;
30587 + /* dirty trick to support atomic_open */
30588 + struct hlist_bl_head si_aopen;
30590 + /* vdir parameters */
30591 + unsigned long si_rdcache; /* max cache time in jiffies */
30592 + unsigned int si_rdblk; /* deblk size */
30593 + unsigned int si_rdhash; /* hash size */
30596 + * If the number of whiteouts are larger than si_dirwh, leave all of
30597 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30598 + * future fsck.aufs or kernel thread will remove them later.
30599 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30601 + unsigned int si_dirwh;
30603 + /* pseudo_link list */
30604 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30605 + wait_queue_head_t si_plink_wq;
30606 + spinlock_t si_plink_maint_lock;
30607 + pid_t si_plink_maint_pid;
30610 + struct hlist_bl_head si_files;
30612 + /* with/without getattr, brother of sb->s_d_op */
30613 + const struct inode_operations *si_iop_array;
30616 + * sysfs and lifetime management.
30617 + * this is not a small structure and it may be a waste of memory in case
30618 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30619 + * but using sysfs is majority.
30621 + struct kobject si_kobj;
30622 +#ifdef CONFIG_DEBUG_FS
30623 + struct dentry *si_dbgaufs;
30624 + struct dentry *si_dbgaufs_plink;
30625 + struct dentry *si_dbgaufs_xib;
30626 +#ifdef CONFIG_AUFS_EXPORT
30627 + struct dentry *si_dbgaufs_xigen;
30631 +#ifdef CONFIG_AUFS_SBILIST
30632 + struct hlist_bl_node si_list;
30635 + /* dirty, necessary for unmounting, sysfs and sysrq */
30636 + struct super_block *si_sb;
30639 +/* sbinfo status flags */
30641 + * set true when refresh_dirs() failed at remount time.
30642 + * then try refreshing dirs at access time again.
30643 + * if it is false, refreshing dirs at access time is unnecessary
30645 +#define AuSi_FAILED_REFRESH_DIR 1
30646 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30647 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30649 +#ifndef CONFIG_AUFS_FHSM
30651 +#define AuSi_FHSM 0
30654 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30655 + unsigned int flag)
30657 + AuRwMustAnyLock(&sbi->si_rwsem);
30658 + return sbi->au_si_status & flag;
30660 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30661 +#define au_fset_si(sbinfo, name) do { \
30662 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30663 + (sbinfo)->au_si_status |= AuSi_##name; \
30665 +#define au_fclr_si(sbinfo, name) do { \
30666 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30667 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30670 +/* ---------------------------------------------------------------------- */
30672 +/* policy to select one among writable branches */
30673 +#define AuWbrCopyup(sbinfo, ...) \
30674 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30675 +#define AuWbrCreate(sbinfo, ...) \
30676 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30678 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30679 +#define AuLock_DW 1 /* write-lock dentry */
30680 +#define AuLock_IR (1 << 1) /* read-lock inode */
30681 +#define AuLock_IW (1 << 2) /* write-lock inode */
30682 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30683 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30684 + /* except RENAME_EXCHANGE */
30685 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30686 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30687 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30688 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30689 +#define au_fset_lock(flags, name) \
30690 + do { (flags) |= AuLock_##name; } while (0)
30691 +#define au_fclr_lock(flags, name) \
30692 + do { (flags) &= ~AuLock_##name; } while (0)
30694 +/* ---------------------------------------------------------------------- */
30697 +extern struct file_system_type aufs_fs_type;
30698 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30699 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30700 + unsigned long long max, void *arg);
30701 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30702 + struct super_block *sb, void *arg);
30703 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30704 +void au_iarray_free(struct inode **a, unsigned long long max);
30707 +void au_si_free(struct kobject *kobj);
30708 +int au_si_alloc(struct super_block *sb);
30709 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30711 +unsigned int au_sigen_inc(struct super_block *sb);
30712 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30714 +int si_read_lock(struct super_block *sb, int flags);
30715 +int si_write_lock(struct super_block *sb, int flags);
30716 +int aufs_read_lock(struct dentry *dentry, int flags);
30717 +void aufs_read_unlock(struct dentry *dentry, int flags);
30718 +void aufs_write_lock(struct dentry *dentry);
30719 +void aufs_write_unlock(struct dentry *dentry);
30720 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30721 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30723 +/* wbr_policy.c */
30724 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30725 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30726 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30727 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30728 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30731 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30733 +#ifdef CONFIG_AUFS_FHSM
30736 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30740 + spin_lock(&fhsm->fhsm_spin);
30741 + pid = fhsm->fhsm_pid;
30742 + spin_unlock(&fhsm->fhsm_spin);
30747 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30748 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30749 +int au_fhsm_fd(struct super_block *sb, int oflags);
30750 +int au_fhsm_br_alloc(struct au_branch *br);
30751 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30752 +void au_fhsm_fin(struct super_block *sb);
30753 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30754 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30755 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30757 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30759 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30760 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30761 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30762 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30763 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30764 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30765 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30766 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30767 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30770 +/* ---------------------------------------------------------------------- */
30772 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30774 + return sb->s_fs_info;
30777 +/* ---------------------------------------------------------------------- */
30779 +#ifdef CONFIG_AUFS_EXPORT
30780 +int au_test_nfsd(void);
30781 +void au_export_init(struct super_block *sb);
30782 +void au_xigen_inc(struct inode *inode);
30783 +int au_xigen_new(struct inode *inode);
30784 +int au_xigen_set(struct super_block *sb, struct path *path);
30785 +void au_xigen_clr(struct super_block *sb);
30787 +static inline int au_busy_or_stale(void)
30789 + if (!au_test_nfsd())
30794 +AuStubInt0(au_test_nfsd, void)
30795 +AuStubVoid(au_export_init, struct super_block *sb)
30796 +AuStubVoid(au_xigen_inc, struct inode *inode)
30797 +AuStubInt0(au_xigen_new, struct inode *inode)
30798 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30799 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30800 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30801 +#endif /* CONFIG_AUFS_EXPORT */
30803 +/* ---------------------------------------------------------------------- */
30805 +#ifdef CONFIG_AUFS_SBILIST
30807 +extern struct hlist_bl_head au_sbilist;
30809 +static inline void au_sbilist_init(void)
30811 + INIT_HLIST_BL_HEAD(&au_sbilist);
30814 +static inline void au_sbilist_add(struct super_block *sb)
30816 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30819 +static inline void au_sbilist_del(struct super_block *sb)
30821 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30824 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30825 +static inline void au_sbilist_lock(void)
30827 + hlist_bl_lock(&au_sbilist);
30830 +static inline void au_sbilist_unlock(void)
30832 + hlist_bl_unlock(&au_sbilist);
30834 +#define AuGFP_SBILIST GFP_ATOMIC
30836 +AuStubVoid(au_sbilist_lock, void)
30837 +AuStubVoid(au_sbilist_unlock, void)
30838 +#define AuGFP_SBILIST GFP_NOFS
30839 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30841 +AuStubVoid(au_sbilist_init, void)
30842 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30843 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30844 +AuStubVoid(au_sbilist_lock, void)
30845 +AuStubVoid(au_sbilist_unlock, void)
30846 +#define AuGFP_SBILIST GFP_NOFS
30849 +/* ---------------------------------------------------------------------- */
30851 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30854 + * This function is a dynamic '__init' function actually,
30855 + * so the tiny check for si_rwsem is unnecessary.
30857 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30858 +#ifdef CONFIG_DEBUG_FS
30859 + sbinfo->si_dbgaufs = NULL;
30860 + sbinfo->si_dbgaufs_plink = NULL;
30861 + sbinfo->si_dbgaufs_xib = NULL;
30862 +#ifdef CONFIG_AUFS_EXPORT
30863 + sbinfo->si_dbgaufs_xigen = NULL;
30868 +/* ---------------------------------------------------------------------- */
30870 +/* current->atomic_flags */
30871 +/* this value should never corrupt the ones defined in linux/sched.h */
30872 +#define PFA_AUFS 0x10
30874 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30875 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30876 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30878 +static inline int si_pid_test(struct super_block *sb)
30880 + return !!task_test_aufs(current);
30883 +static inline void si_pid_clr(struct super_block *sb)
30885 + AuDebugOn(!task_test_aufs(current));
30886 + task_clear_aufs(current);
30889 +static inline void si_pid_set(struct super_block *sb)
30891 + AuDebugOn(task_test_aufs(current));
30892 + task_set_aufs(current);
30895 +/* ---------------------------------------------------------------------- */
30897 +/* lock superblock. mainly for entry point functions */
30898 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30899 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30900 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30901 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30903 +#define __si_read_trylock_nested(sb) \
30904 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30905 +#define __si_write_trylock_nested(sb) \
30906 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30909 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30910 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30911 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30913 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30914 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30915 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30917 +static inline void si_noflush_read_lock(struct super_block *sb)
30919 + __si_read_lock(sb);
30923 +static inline int si_noflush_read_trylock(struct super_block *sb)
30927 + locked = __si_read_trylock(sb);
30933 +static inline void si_noflush_write_lock(struct super_block *sb)
30935 + __si_write_lock(sb);
30939 +static inline int si_noflush_write_trylock(struct super_block *sb)
30943 + locked = __si_write_trylock(sb);
30949 +#if 0 /* reserved */
30950 +static inline int si_read_trylock(struct super_block *sb, int flags)
30952 + if (au_ftest_lock(flags, FLUSH))
30953 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30954 + return si_noflush_read_trylock(sb);
30958 +static inline void si_read_unlock(struct super_block *sb)
30961 + __si_read_unlock(sb);
30964 +#if 0 /* reserved */
30965 +static inline int si_write_trylock(struct super_block *sb, int flags)
30967 + if (au_ftest_lock(flags, FLUSH))
30968 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30969 + return si_noflush_write_trylock(sb);
30973 +static inline void si_write_unlock(struct super_block *sb)
30976 + __si_write_unlock(sb);
30979 +#if 0 /* reserved */
30980 +static inline void si_downgrade_lock(struct super_block *sb)
30982 + __si_downgrade_lock(sb);
30986 +/* ---------------------------------------------------------------------- */
30988 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30990 + SiMustAnyLock(sb);
30991 + return au_sbi(sb)->si_bbot;
30994 +static inline unsigned int au_mntflags(struct super_block *sb)
30996 + SiMustAnyLock(sb);
30997 + return au_sbi(sb)->si_mntflags;
31000 +static inline unsigned int au_sigen(struct super_block *sb)
31002 + SiMustAnyLock(sb);
31003 + return au_sbi(sb)->si_generation;
31006 +static inline struct au_branch *au_sbr(struct super_block *sb,
31007 + aufs_bindex_t bindex)
31009 + SiMustAnyLock(sb);
31010 + return au_sbi(sb)->si_branch[0 + bindex];
31013 +static inline loff_t au_xi_maxent(struct super_block *sb)
31015 + SiMustAnyLock(sb);
31016 + return au_sbi(sb)->si_ximaxent;
31019 +#endif /* __KERNEL__ */
31020 +#endif /* __AUFS_SUPER_H__ */
31021 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31022 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31023 +++ linux/fs/aufs/sysaufs.c 2021-05-02 20:15:14.676670793 +0200
31025 +// SPDX-License-Identifier: GPL-2.0
31027 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31029 + * This program, aufs is free software; you can redistribute it and/or modify
31030 + * it under the terms of the GNU General Public License as published by
31031 + * the Free Software Foundation; either version 2 of the License, or
31032 + * (at your option) any later version.
31034 + * This program is distributed in the hope that it will be useful,
31035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31037 + * GNU General Public License for more details.
31039 + * You should have received a copy of the GNU General Public License
31040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31044 + * sysfs interface and lifetime management
31045 + * they are necessary regardless sysfs is disabled.
31048 +#include <linux/random.h>
31051 +unsigned long sysaufs_si_mask;
31052 +struct kset *sysaufs_kset;
31054 +#define AuSiAttr(_name) { \
31055 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31056 + .show = sysaufs_si_##_name, \
31059 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31060 +struct attribute *sysaufs_si_attrs[] = {
31061 + &sysaufs_si_attr_xi_path.attr,
31065 +static const struct sysfs_ops au_sbi_ops = {
31066 + .show = sysaufs_si_show
31069 +static struct kobj_type au_sbi_ktype = {
31070 + .release = au_si_free,
31071 + .sysfs_ops = &au_sbi_ops,
31072 + .default_attrs = sysaufs_si_attrs
31075 +/* ---------------------------------------------------------------------- */
31077 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31081 + sbinfo->si_kobj.kset = sysaufs_kset;
31082 + /* cf. sysaufs_name() */
31083 + err = kobject_init_and_add
31084 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31085 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31090 +void sysaufs_fin(void)
31092 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31093 + kset_unregister(sysaufs_kset);
31096 +int __init sysaufs_init(void)
31101 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31102 + } while (!sysaufs_si_mask);
31105 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31106 + if (unlikely(!sysaufs_kset))
31108 + err = PTR_ERR(sysaufs_kset);
31109 + if (IS_ERR(sysaufs_kset))
31111 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31112 + if (unlikely(err))
31113 + kset_unregister(sysaufs_kset);
31118 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31119 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31120 +++ linux/fs/aufs/sysaufs.h 2021-05-02 20:15:14.676670793 +0200
31122 +/* SPDX-License-Identifier: GPL-2.0 */
31124 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31126 + * This program, aufs is free software; you can redistribute it and/or modify
31127 + * it under the terms of the GNU General Public License as published by
31128 + * the Free Software Foundation; either version 2 of the License, or
31129 + * (at your option) any later version.
31131 + * This program is distributed in the hope that it will be useful,
31132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31134 + * GNU General Public License for more details.
31136 + * You should have received a copy of the GNU General Public License
31137 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31141 + * sysfs interface and mount lifetime management
31144 +#ifndef __SYSAUFS_H__
31145 +#define __SYSAUFS_H__
31149 +#include <linux/sysfs.h>
31150 +#include "module.h"
31152 +struct super_block;
31155 +struct sysaufs_si_attr {
31156 + struct attribute attr;
31157 + int (*show)(struct seq_file *seq, struct super_block *sb);
31160 +/* ---------------------------------------------------------------------- */
31163 +extern unsigned long sysaufs_si_mask;
31164 +extern struct kset *sysaufs_kset;
31165 +extern struct attribute *sysaufs_si_attrs[];
31166 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31167 +int __init sysaufs_init(void);
31168 +void sysaufs_fin(void);
31170 +/* ---------------------------------------------------------------------- */
31172 +/* some people doesn't like to show a pointer in kernel */
31173 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31175 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31178 +#define SysaufsSiNamePrefix "si_"
31179 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31180 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31182 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31183 + sysaufs_si_id(sbinfo));
31187 +#ifdef CONFIG_SYSFS
31189 +extern struct attribute_group *sysaufs_attr_group;
31191 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31192 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31194 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31195 +#ifdef CONFIG_COMPAT
31196 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31199 +void sysaufs_br_init(struct au_branch *br);
31200 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31201 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31203 +#define sysaufs_brs_init() do {} while (0)
31206 +#define sysaufs_attr_group NULL
31208 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31209 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31210 + struct attribute *attr, char *buf)
31211 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31212 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31213 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31215 +static inline void sysaufs_brs_init(void)
31220 +#endif /* CONFIG_SYSFS */
31222 +#endif /* __KERNEL__ */
31223 +#endif /* __SYSAUFS_H__ */
31224 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31225 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31226 +++ linux/fs/aufs/sysfs.c 2021-05-02 20:15:14.676670793 +0200
31228 +// SPDX-License-Identifier: GPL-2.0
31230 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31232 + * This program, aufs is free software; you can redistribute it and/or modify
31233 + * it under the terms of the GNU General Public License as published by
31234 + * the Free Software Foundation; either version 2 of the License, or
31235 + * (at your option) any later version.
31237 + * This program is distributed in the hope that it will be useful,
31238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31240 + * GNU General Public License for more details.
31242 + * You should have received a copy of the GNU General Public License
31243 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31247 + * sysfs interface
31250 +#include <linux/compat.h>
31251 +#include <linux/seq_file.h>
31254 +#ifdef CONFIG_AUFS_FS_MODULE
31255 +/* this entry violates the "one line per file" policy of sysfs */
31256 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31260 + static char *conf =
31261 +/* this file is generated at compiling */
31262 +#include "conf.str"
31265 + err = snprintf(buf, PAGE_SIZE, conf);
31266 + if (unlikely(err >= PAGE_SIZE))
31271 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31274 +static struct attribute *au_attr[] = {
31275 +#ifdef CONFIG_AUFS_FS_MODULE
31276 + &au_config_attr.attr,
31278 + NULL, /* need to NULL terminate the list of attributes */
31281 +static struct attribute_group sysaufs_attr_group_body = {
31285 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31287 +/* ---------------------------------------------------------------------- */
31289 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31293 + SiMustAnyLock(sb);
31296 + if (au_opt_test(au_mntflags(sb), XINO)) {
31297 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31298 + seq_putc(seq, '\n');
31304 + * the lifetime of branch is independent from the entry under sysfs.
31305 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31308 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31309 + aufs_bindex_t bindex, int idx)
31312 + struct path path;
31313 + struct dentry *root;
31314 + struct au_branch *br;
31315 + au_br_perm_str_t perm;
31317 + AuDbg("b%d\n", bindex);
31320 + root = sb->s_root;
31321 + di_read_lock_parent(root, !AuLock_IR);
31322 + br = au_sbr(sb, bindex);
31325 + case AuBrSysfs_BR:
31326 + path.mnt = au_br_mnt(br);
31327 + path.dentry = au_h_dptr(root, bindex);
31328 + err = au_seq_path(seq, &path);
31330 + au_optstr_br_perm(&perm, br->br_perm);
31331 + seq_printf(seq, "=%s\n", perm.a);
31334 + case AuBrSysfs_BRID:
31335 + seq_printf(seq, "%d\n", br->br_id);
31338 + di_read_unlock(root, !AuLock_IR);
31339 + if (unlikely(err || seq_has_overflowed(seq)))
31345 +/* ---------------------------------------------------------------------- */
31347 +static struct seq_file *au_seq(char *p, ssize_t len)
31349 + struct seq_file *seq;
31351 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31353 + /* mutex_init(&seq.lock); */
31356 + return seq; /* success */
31359 + seq = ERR_PTR(-ENOMEM);
31363 +#define SysaufsBr_PREFIX "br"
31364 +#define SysaufsBrid_PREFIX "brid"
31366 +/* todo: file size may exceed PAGE_SIZE */
31367 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31373 + aufs_bindex_t bbot;
31374 + struct au_sbinfo *sbinfo;
31375 + struct super_block *sb;
31376 + struct seq_file *seq;
31378 + struct attribute **cattr;
31380 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31381 + sb = sbinfo->si_sb;
31384 + * prevent a race condition between sysfs and aufs.
31385 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31386 + * prohibits maintaining the sysfs entries.
31387 + * hew we acquire read lock after sysfs_get_active_two().
31388 + * on the other hand, the remount process may maintain the sysfs/aufs
31389 + * entries after acquiring write lock.
31390 + * it can cause a deadlock.
31391 + * simply we gave up processing read here.
31394 + if (unlikely(!si_noflush_read_trylock(sb)))
31397 + seq = au_seq(buf, PAGE_SIZE);
31398 + err = PTR_ERR(seq);
31402 + name = (void *)attr->name;
31403 + cattr = sysaufs_si_attrs;
31405 + if (!strcmp(name, (*cattr)->name)) {
31406 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31413 + if (!strncmp(name, SysaufsBrid_PREFIX,
31414 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31415 + idx = AuBrSysfs_BRID;
31416 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31417 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31418 + sizeof(SysaufsBr_PREFIX) - 1)) {
31419 + idx = AuBrSysfs_BR;
31420 + name += sizeof(SysaufsBr_PREFIX) - 1;
31424 + err = kstrtol(name, 10, &l);
31426 + bbot = au_sbbot(sb);
31428 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31435 + err = seq->count;
31436 + /* sysfs limit */
31437 + if (unlikely(err == PAGE_SIZE))
31440 + au_kfree_rcu(seq);
31442 + si_read_unlock(sb);
31447 +/* ---------------------------------------------------------------------- */
31449 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31453 + aufs_bindex_t bindex, bbot;
31456 + struct seq_file *seq;
31457 + struct au_branch *br;
31459 + si_read_lock(sb, AuLock_FLUSH);
31460 + bbot = au_sbbot(sb);
31466 + buf = (void *)__get_free_page(GFP_NOFS);
31467 + if (unlikely(!buf))
31470 + seq = au_seq(buf, PAGE_SIZE);
31471 + err = PTR_ERR(seq);
31475 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31476 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31477 + /* VERIFY_WRITE */
31478 + err = !access_ok(arg, sizeof(*arg));
31479 + if (unlikely(err))
31482 + br = au_sbr(sb, bindex);
31483 + brid = br->br_id;
31484 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31485 + err = __put_user(brid, &arg->id);
31486 + if (unlikely(err))
31489 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31490 + err = __put_user(br->br_perm, &arg->perm);
31491 + if (unlikely(err))
31494 + err = au_seq_path(seq, &br->br_path);
31495 + if (unlikely(err))
31497 + seq_putc(seq, '\0');
31498 + if (!seq_has_overflowed(seq)) {
31499 + err = copy_to_user(arg->path, seq->buf, seq->count);
31501 + if (unlikely(err))
31508 + if (unlikely(err))
31512 + au_kfree_rcu(seq);
31514 + free_page((unsigned long)buf);
31516 + si_read_unlock(sb);
31520 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31522 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31525 +#ifdef CONFIG_COMPAT
31526 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31528 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31532 +/* ---------------------------------------------------------------------- */
31534 +void sysaufs_br_init(struct au_branch *br)
31537 + struct au_brsysfs *br_sysfs;
31538 + struct attribute *attr;
31540 + br_sysfs = br->br_sysfs;
31541 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31542 + attr = &br_sysfs->attr;
31543 + sysfs_attr_init(attr);
31544 + attr->name = br_sysfs->name;
31545 + attr->mode = 0444;
31550 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31552 + struct au_branch *br;
31553 + struct kobject *kobj;
31554 + struct au_brsysfs *br_sysfs;
31556 + aufs_bindex_t bbot;
31558 + if (!sysaufs_brs)
31561 + kobj = &au_sbi(sb)->si_kobj;
31562 + bbot = au_sbbot(sb);
31563 + for (; bindex <= bbot; bindex++) {
31564 + br = au_sbr(sb, bindex);
31565 + br_sysfs = br->br_sysfs;
31566 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31567 + sysfs_remove_file(kobj, &br_sysfs->attr);
31573 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31576 + aufs_bindex_t bbot;
31577 + struct kobject *kobj;
31578 + struct au_branch *br;
31579 + struct au_brsysfs *br_sysfs;
31581 + if (!sysaufs_brs)
31584 + kobj = &au_sbi(sb)->si_kobj;
31585 + bbot = au_sbbot(sb);
31586 + for (; bindex <= bbot; bindex++) {
31587 + br = au_sbr(sb, bindex);
31588 + br_sysfs = br->br_sysfs;
31589 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31590 + SysaufsBr_PREFIX "%d", bindex);
31591 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31592 + SysaufsBrid_PREFIX "%d", bindex);
31593 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31594 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31595 + if (unlikely(err))
31596 + pr_warn("failed %s under sysfs(%d)\n",
31597 + br_sysfs->name, err);
31602 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31603 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31604 +++ linux/fs/aufs/sysrq.c 2021-05-02 20:15:14.676670793 +0200
31606 +// SPDX-License-Identifier: GPL-2.0
31608 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31610 + * This program, aufs is free software; you can redistribute it and/or modify
31611 + * it under the terms of the GNU General Public License as published by
31612 + * the Free Software Foundation; either version 2 of the License, or
31613 + * (at your option) any later version.
31615 + * This program is distributed in the hope that it will be useful,
31616 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31617 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31618 + * GNU General Public License for more details.
31620 + * You should have received a copy of the GNU General Public License
31621 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31625 + * magic sysrq handler
31628 +/* #include <linux/sysrq.h> */
31629 +#include <linux/writeback.h>
31632 +/* ---------------------------------------------------------------------- */
31634 +static void sysrq_sb(struct super_block *sb)
31637 + struct au_sbinfo *sbinfo;
31638 + struct file *file;
31639 + struct hlist_bl_head *files;
31640 + struct hlist_bl_node *pos;
31641 + struct au_finfo *finfo;
31644 + plevel = au_plevel;
31645 + au_plevel = KERN_WARNING;
31647 + /* since we define pr_fmt, call printk directly */
31648 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31650 + sbinfo = au_sbi(sb);
31651 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31652 + pr("superblock\n");
31655 +#if 0 /* reserved */
31657 + int err, i, j, ndentry;
31658 + struct au_dcsub_pages dpages;
31659 + struct au_dpage *dpage;
31661 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31662 + if (unlikely(err))
31664 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31666 + for (i = 0; i < dpages.ndpage; i++) {
31667 + dpage = dpages.dpages + i;
31668 + ndentry = dpage->ndentry;
31669 + for (j = 0; j < ndentry; j++)
31670 + au_dpri_dentry(dpage->dentries[j]);
31672 + au_dpages_free(&dpages);
31676 + pr("isolated inode\n");
31677 + spin_lock(&sb->s_inode_list_lock);
31678 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31679 + spin_lock(&i->i_lock);
31680 + if (hlist_empty(&i->i_dentry))
31681 + au_dpri_inode(i);
31682 + spin_unlock(&i->i_lock);
31684 + spin_unlock(&sb->s_inode_list_lock);
31687 + files = &au_sbi(sb)->si_files;
31688 + hlist_bl_lock(files);
31689 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31692 + file = finfo->fi_file;
31693 + mode = file_inode(file)->i_mode;
31694 + if (!special_file(mode))
31695 + au_dpri_file(file);
31697 + hlist_bl_unlock(files);
31701 + au_plevel = plevel;
31704 +/* ---------------------------------------------------------------------- */
31706 +/* module parameter */
31707 +static char *aufs_sysrq_key = "a";
31708 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31709 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31711 +static void au_sysrq(int key __maybe_unused)
31713 + struct au_sbinfo *sbinfo;
31714 + struct hlist_bl_node *pos;
31717 + au_sbilist_lock();
31718 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31719 + sysrq_sb(sbinfo->si_sb);
31720 + au_sbilist_unlock();
31724 +static struct sysrq_key_op au_sysrq_op = {
31725 + .handler = au_sysrq,
31726 + .help_msg = "Aufs",
31727 + .action_msg = "Aufs",
31728 + .enable_mask = SYSRQ_ENABLE_DUMP
31731 +/* ---------------------------------------------------------------------- */
31733 +int __init au_sysrq_init(void)
31739 + key = *aufs_sysrq_key;
31740 + if ('a' <= key && key <= 'z')
31741 + err = register_sysrq_key(key, &au_sysrq_op);
31742 + if (unlikely(err))
31743 + pr_err("err %d, sysrq=%c\n", err, key);
31747 +void au_sysrq_fin(void)
31751 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31752 + if (unlikely(err))
31753 + pr_err("err %d (ignored)\n", err);
31755 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31756 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31757 +++ linux/fs/aufs/vdir.c 2021-05-02 20:15:14.676670793 +0200
31759 +// SPDX-License-Identifier: GPL-2.0
31761 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31763 + * This program, aufs is free software; you can redistribute it and/or modify
31764 + * it under the terms of the GNU General Public License as published by
31765 + * the Free Software Foundation; either version 2 of the License, or
31766 + * (at your option) any later version.
31768 + * This program is distributed in the hope that it will be useful,
31769 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31770 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31771 + * GNU General Public License for more details.
31773 + * You should have received a copy of the GNU General Public License
31774 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31778 + * virtual or vertical directory
31781 +#include <linux/iversion.h>
31784 +static unsigned int calc_size(int nlen)
31786 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31789 +static int set_deblk_end(union au_vdir_deblk_p *p,
31790 + union au_vdir_deblk_p *deblk_end)
31792 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31793 + p->de->de_str.len = 0;
31797 + return -1; /* error */
31800 +/* returns true or false */
31801 +static int is_deblk_end(union au_vdir_deblk_p *p,
31802 + union au_vdir_deblk_p *deblk_end)
31804 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31805 + return !p->de->de_str.len;
31809 +static unsigned char *last_deblk(struct au_vdir *vdir)
31811 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31814 +/* ---------------------------------------------------------------------- */
31816 +/* estimate the appropriate size for name hash table */
31817 +unsigned int au_rdhash_est(loff_t sz)
31825 + if (sz < AUFS_RDHASH_DEF)
31826 + n = AUFS_RDHASH_DEF;
31827 + /* pr_info("n %u\n", n); */
31832 + * the allocated memory has to be freed by
31833 + * au_nhash_wh_free() or au_nhash_de_free().
31835 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31837 + struct hlist_head *head;
31841 + sz = sizeof(*nhash->nh_head) * num_hash;
31842 + head = kmalloc(sz, gfp);
31844 + nhash->nh_num = num_hash;
31845 + nhash->nh_head = head;
31846 + for (u = 0; u < num_hash; u++)
31847 + INIT_HLIST_HEAD(head++);
31848 + return 0; /* success */
31854 +static void nhash_count(struct hlist_head *head)
31856 +#if 0 /* debugging */
31858 + struct hlist_node *pos;
31861 + hlist_for_each(pos, head)
31863 + pr_info("%lu\n", n);
31867 +static void au_nhash_wh_do_free(struct hlist_head *head)
31869 + struct au_vdir_wh *pos;
31870 + struct hlist_node *node;
31872 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31873 + au_kfree_rcu(pos);
31876 +static void au_nhash_de_do_free(struct hlist_head *head)
31878 + struct au_vdir_dehstr *pos;
31879 + struct hlist_node *node;
31881 + hlist_for_each_entry_safe(pos, node, head, hash)
31882 + au_cache_free_vdir_dehstr(pos);
31885 +static void au_nhash_do_free(struct au_nhash *nhash,
31886 + void (*free)(struct hlist_head *head))
31889 + struct hlist_head *head;
31891 + n = nhash->nh_num;
31895 + head = nhash->nh_head;
31896 + while (n-- > 0) {
31897 + nhash_count(head);
31900 + au_kfree_try_rcu(nhash->nh_head);
31903 +void au_nhash_wh_free(struct au_nhash *whlist)
31905 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31908 +static void au_nhash_de_free(struct au_nhash *delist)
31910 + au_nhash_do_free(delist, au_nhash_de_do_free);
31913 +/* ---------------------------------------------------------------------- */
31915 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31919 + unsigned int u, n;
31920 + struct hlist_head *head;
31921 + struct au_vdir_wh *pos;
31924 + n = whlist->nh_num;
31925 + head = whlist->nh_head;
31926 + for (u = 0; u < n; u++, head++)
31927 + hlist_for_each_entry(pos, head, wh_hash)
31928 + if (pos->wh_bindex == btgt && ++num > limit)
31933 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31934 + unsigned char *name,
31935 + unsigned int len)
31938 + /* const unsigned int magic_bit = 12; */
31940 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31947 + /* v = hash_long(v, magic_bit); */
31948 + v %= nhash->nh_num;
31949 + return nhash->nh_head + v;
31952 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31955 + return str->len == nlen && !memcmp(str->name, name, nlen);
31958 +/* returns found or not */
31959 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31961 + struct hlist_head *head;
31962 + struct au_vdir_wh *pos;
31963 + struct au_vdir_destr *str;
31965 + head = au_name_hash(whlist, name, nlen);
31966 + hlist_for_each_entry(pos, head, wh_hash) {
31967 + str = &pos->wh_str;
31968 + AuDbg("%.*s\n", str->len, str->name);
31969 + if (au_nhash_test_name(str, name, nlen))
31975 +/* returns found(true) or not */
31976 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31978 + struct hlist_head *head;
31979 + struct au_vdir_dehstr *pos;
31980 + struct au_vdir_destr *str;
31982 + head = au_name_hash(delist, name, nlen);
31983 + hlist_for_each_entry(pos, head, hash) {
31985 + AuDbg("%.*s\n", str->len, str->name);
31986 + if (au_nhash_test_name(str, name, nlen))
31992 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31993 + unsigned char d_type)
31995 +#ifdef CONFIG_AUFS_SHWH
31996 + wh->wh_ino = ino;
31997 + wh->wh_type = d_type;
32001 +/* ---------------------------------------------------------------------- */
32003 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32004 + unsigned int d_type, aufs_bindex_t bindex,
32005 + unsigned char shwh)
32008 + struct au_vdir_destr *str;
32009 + struct au_vdir_wh *wh;
32011 + AuDbg("%.*s\n", nlen, name);
32012 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32015 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32016 + if (unlikely(!wh))
32020 + wh->wh_bindex = bindex;
32022 + au_shwh_init_wh(wh, ino, d_type);
32023 + str = &wh->wh_str;
32025 + memcpy(str->name, name, nlen);
32026 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32033 +static int append_deblk(struct au_vdir *vdir)
32036 + unsigned long ul;
32037 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32038 + union au_vdir_deblk_p p, deblk_end;
32039 + unsigned char **o;
32042 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32043 + GFP_NOFS, /*may_shrink*/0);
32044 + if (unlikely(!o))
32047 + vdir->vd_deblk = o;
32048 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32050 + ul = vdir->vd_nblk++;
32051 + vdir->vd_deblk[ul] = p.deblk;
32052 + vdir->vd_last.ul = ul;
32053 + vdir->vd_last.p.deblk = p.deblk;
32054 + deblk_end.deblk = p.deblk + deblk_sz;
32055 + err = set_deblk_end(&p, &deblk_end);
32062 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32063 + unsigned int d_type, struct au_nhash *delist)
32067 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32068 + union au_vdir_deblk_p p, *room, deblk_end;
32069 + struct au_vdir_dehstr *dehstr;
32071 + p.deblk = last_deblk(vdir);
32072 + deblk_end.deblk = p.deblk + deblk_sz;
32073 + room = &vdir->vd_last.p;
32074 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32075 + || !is_deblk_end(room, &deblk_end));
32077 + sz = calc_size(nlen);
32078 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32079 + err = append_deblk(vdir);
32080 + if (unlikely(err))
32083 + p.deblk = last_deblk(vdir);
32084 + deblk_end.deblk = p.deblk + deblk_sz;
32086 + AuDebugOn(room->deblk != p.deblk);
32090 + dehstr = au_cache_alloc_vdir_dehstr();
32091 + if (unlikely(!dehstr))
32094 + dehstr->str = &room->de->de_str;
32095 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32096 + room->de->de_ino = ino;
32097 + room->de->de_type = d_type;
32098 + room->de->de_str.len = nlen;
32099 + memcpy(room->de->de_str.name, name, nlen);
32102 + room->deblk += sz;
32103 + if (unlikely(set_deblk_end(room, &deblk_end)))
32104 + err = append_deblk(vdir);
32111 +/* ---------------------------------------------------------------------- */
32113 +void au_vdir_free(struct au_vdir *vdir)
32115 + unsigned char **deblk;
32117 + deblk = vdir->vd_deblk;
32118 + while (vdir->vd_nblk--)
32119 + au_kfree_try_rcu(*deblk++);
32120 + au_kfree_try_rcu(vdir->vd_deblk);
32121 + au_cache_free_vdir(vdir);
32124 +static struct au_vdir *alloc_vdir(struct file *file)
32126 + struct au_vdir *vdir;
32127 + struct super_block *sb;
32130 + sb = file->f_path.dentry->d_sb;
32131 + SiMustAnyLock(sb);
32134 + vdir = au_cache_alloc_vdir();
32135 + if (unlikely(!vdir))
32138 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32139 + if (unlikely(!vdir->vd_deblk))
32142 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32143 + if (!vdir->vd_deblk_sz) {
32144 + /* estimate the appropriate size for deblk */
32145 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32146 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32148 + vdir->vd_nblk = 0;
32149 + vdir->vd_version = 0;
32150 + vdir->vd_jiffy = 0;
32151 + err = append_deblk(vdir);
32153 + return vdir; /* success */
32155 + au_kfree_try_rcu(vdir->vd_deblk);
32158 + au_cache_free_vdir(vdir);
32160 + vdir = ERR_PTR(err);
32164 +static int reinit_vdir(struct au_vdir *vdir)
32167 + union au_vdir_deblk_p p, deblk_end;
32169 + while (vdir->vd_nblk > 1) {
32170 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32171 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32174 + p.deblk = vdir->vd_deblk[0];
32175 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32176 + err = set_deblk_end(&p, &deblk_end);
32177 + /* keep vd_dblk_sz */
32178 + vdir->vd_last.ul = 0;
32179 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32180 + vdir->vd_version = 0;
32181 + vdir->vd_jiffy = 0;
32186 +/* ---------------------------------------------------------------------- */
32188 +#define AuFillVdir_CALLED 1
32189 +#define AuFillVdir_WHABLE (1 << 1)
32190 +#define AuFillVdir_SHWH (1 << 2)
32191 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32192 +#define au_fset_fillvdir(flags, name) \
32193 + do { (flags) |= AuFillVdir_##name; } while (0)
32194 +#define au_fclr_fillvdir(flags, name) \
32195 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32197 +#ifndef CONFIG_AUFS_SHWH
32198 +#undef AuFillVdir_SHWH
32199 +#define AuFillVdir_SHWH 0
32202 +struct fillvdir_arg {
32203 + struct dir_context ctx;
32204 + struct file *file;
32205 + struct au_vdir *vdir;
32206 + struct au_nhash delist;
32207 + struct au_nhash whlist;
32208 + aufs_bindex_t bindex;
32209 + unsigned int flags;
32213 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32214 + loff_t offset __maybe_unused, u64 h_ino,
32215 + unsigned int d_type)
32217 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32218 + char *name = (void *)__name;
32219 + struct super_block *sb;
32221 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32224 + sb = arg->file->f_path.dentry->d_sb;
32225 + au_fset_fillvdir(arg->flags, CALLED);
32227 + if (nlen <= AUFS_WH_PFX_LEN
32228 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32229 + if (test_known(&arg->delist, name, nlen)
32230 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32231 + goto out; /* already exists or whiteouted */
32233 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32235 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32236 + d_type = DT_UNKNOWN;
32237 + arg->err = append_de(arg->vdir, name, nlen, ino,
32238 + d_type, &arg->delist);
32240 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32241 + name += AUFS_WH_PFX_LEN;
32242 + nlen -= AUFS_WH_PFX_LEN;
32243 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32244 + goto out; /* already whiteouted */
32246 + ino = 0; /* just to suppress a warning */
32248 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32251 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32252 + d_type = DT_UNKNOWN;
32253 + arg->err = au_nhash_append_wh
32254 + (&arg->whlist, name, nlen, ino, d_type,
32255 + arg->bindex, shwh);
32261 + arg->vdir->vd_jiffy = jiffies;
32263 + AuTraceErr(arg->err);
32267 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32268 + struct au_nhash *whlist, struct au_nhash *delist)
32270 +#ifdef CONFIG_AUFS_SHWH
32272 + unsigned int nh, u;
32273 + struct hlist_head *head;
32274 + struct au_vdir_wh *pos;
32275 + struct hlist_node *n;
32277 + struct au_vdir_destr *destr;
32279 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32282 + o = p = (void *)__get_free_page(GFP_NOFS);
32283 + if (unlikely(!p))
32287 + nh = whlist->nh_num;
32288 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32289 + p += AUFS_WH_PFX_LEN;
32290 + for (u = 0; u < nh; u++) {
32291 + head = whlist->nh_head + u;
32292 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32293 + destr = &pos->wh_str;
32294 + memcpy(p, destr->name, destr->len);
32295 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32296 + pos->wh_ino, pos->wh_type, delist);
32297 + if (unlikely(err))
32302 + free_page((unsigned long)o);
32312 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32315 + unsigned int rdhash;
32317 + aufs_bindex_t bbot, bindex, btop;
32318 + unsigned char shwh;
32319 + struct file *hf, *file;
32320 + struct super_block *sb;
32322 + file = arg->file;
32323 + sb = file->f_path.dentry->d_sb;
32324 + SiMustAnyLock(sb);
32326 + rdhash = au_sbi(sb)->si_rdhash;
32328 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32329 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32330 + if (unlikely(err))
32332 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32333 + if (unlikely(err))
32339 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32341 + au_fset_fillvdir(arg->flags, SHWH);
32343 + btop = au_fbtop(file);
32344 + bbot = au_fbbot_dir(file);
32345 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32346 + hf = au_hf_dir(file, bindex);
32350 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32352 + if (unlikely(offset))
32355 + arg->bindex = bindex;
32356 + au_fclr_fillvdir(arg->flags, WHABLE);
32358 + || (bindex != bbot
32359 + && au_br_whable(au_sbr_perm(sb, bindex))))
32360 + au_fset_fillvdir(arg->flags, WHABLE);
32363 + au_fclr_fillvdir(arg->flags, CALLED);
32365 + err = vfsub_iterate_dir(hf, &arg->ctx);
32368 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32371 + * dir_relax() may be good for concurrency, but aufs should not
32372 + * use it since it will cause a lockdep problem.
32376 + if (!err && shwh)
32377 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32379 + au_nhash_wh_free(&arg->whlist);
32382 + au_nhash_de_free(&arg->delist);
32387 +static int read_vdir(struct file *file, int may_read)
32390 + unsigned long expire;
32391 + unsigned char do_read;
32392 + struct fillvdir_arg arg = {
32394 + .actor = fillvdir
32397 + struct inode *inode;
32398 + struct au_vdir *vdir, *allocated;
32401 + inode = file_inode(file);
32402 + IMustLock(inode);
32403 + IiMustWriteLock(inode);
32404 + SiMustAnyLock(inode->i_sb);
32406 + allocated = NULL;
32408 + expire = au_sbi(inode->i_sb)->si_rdcache;
32409 + vdir = au_ivdir(inode);
32412 + vdir = alloc_vdir(file);
32413 + err = PTR_ERR(vdir);
32414 + if (IS_ERR(vdir))
32417 + allocated = vdir;
32418 + } else if (may_read
32419 + && (!inode_eq_iversion(inode, vdir->vd_version)
32420 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32422 + err = reinit_vdir(vdir);
32423 + if (unlikely(err))
32428 + return 0; /* success */
32432 + err = au_do_read_vdir(&arg);
32434 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32435 + vdir->vd_version = inode_query_iversion(inode);
32436 + vdir->vd_last.ul = 0;
32437 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32439 + au_set_ivdir(inode, allocated);
32440 + } else if (allocated)
32441 + au_vdir_free(allocated);
32447 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32450 + unsigned long ul, n;
32451 + const unsigned int deblk_sz = src->vd_deblk_sz;
32453 + AuDebugOn(tgt->vd_nblk != 1);
32456 + if (tgt->vd_nblk < src->vd_nblk) {
32457 + unsigned char **p;
32459 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32460 + GFP_NOFS, /*may_shrink*/0);
32461 + if (unlikely(!p))
32463 + tgt->vd_deblk = p;
32466 + if (tgt->vd_deblk_sz != deblk_sz) {
32467 + unsigned char *p;
32469 + tgt->vd_deblk_sz = deblk_sz;
32470 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32471 + /*may_shrink*/1);
32472 + if (unlikely(!p))
32474 + tgt->vd_deblk[0] = p;
32476 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32477 + tgt->vd_version = src->vd_version;
32478 + tgt->vd_jiffy = src->vd_jiffy;
32480 + n = src->vd_nblk;
32481 + for (ul = 1; ul < n; ul++) {
32482 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32484 + if (unlikely(!tgt->vd_deblk[ul]))
32488 + tgt->vd_nblk = n;
32489 + tgt->vd_last.ul = tgt->vd_last.ul;
32490 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32491 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32492 + - src->vd_deblk[src->vd_last.ul];
32494 + return 0; /* success */
32497 + rerr = reinit_vdir(tgt);
32502 +int au_vdir_init(struct file *file)
32505 + struct inode *inode;
32506 + struct au_vdir *vdir_cache, *allocated;
32508 + /* test file->f_pos here instead of ctx->pos */
32509 + err = read_vdir(file, !file->f_pos);
32510 + if (unlikely(err))
32513 + allocated = NULL;
32514 + vdir_cache = au_fvdir_cache(file);
32515 + if (!vdir_cache) {
32516 + vdir_cache = alloc_vdir(file);
32517 + err = PTR_ERR(vdir_cache);
32518 + if (IS_ERR(vdir_cache))
32520 + allocated = vdir_cache;
32521 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32522 + /* test file->f_pos here instead of ctx->pos */
32523 + err = reinit_vdir(vdir_cache);
32524 + if (unlikely(err))
32527 + return 0; /* success */
32529 + inode = file_inode(file);
32530 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32532 + file->f_version = inode_query_iversion(inode);
32534 + au_set_fvdir_cache(file, allocated);
32535 + } else if (allocated)
32536 + au_vdir_free(allocated);
32542 +static loff_t calc_offset(struct au_vdir *vdir)
32545 + union au_vdir_deblk_p p;
32547 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32548 + offset = vdir->vd_last.p.deblk - p.deblk;
32549 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32553 +/* returns true or false */
32554 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32557 + unsigned int deblk_sz;
32558 + unsigned long ul, n;
32560 + union au_vdir_deblk_p p, deblk_end;
32561 + struct au_vdir *vdir_cache;
32564 + vdir_cache = au_fvdir_cache(file);
32565 + offset = calc_offset(vdir_cache);
32566 + AuDbg("offset %lld\n", offset);
32567 + if (ctx->pos == offset)
32570 + vdir_cache->vd_last.ul = 0;
32571 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32576 + deblk_sz = vdir_cache->vd_deblk_sz;
32577 + ul = div64_u64(ctx->pos, deblk_sz);
32578 + AuDbg("ul %lu\n", ul);
32579 + if (ul >= vdir_cache->vd_nblk)
32582 + n = vdir_cache->vd_nblk;
32583 + for (; ul < n; ul++) {
32584 + p.deblk = vdir_cache->vd_deblk[ul];
32585 + deblk_end.deblk = p.deblk + deblk_sz;
32587 + offset *= deblk_sz;
32588 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32591 + l = calc_size(p.de->de_str.len);
32595 + if (!is_deblk_end(&p, &deblk_end)) {
32597 + vdir_cache->vd_last.ul = ul;
32598 + vdir_cache->vd_last.p = p;
32606 + AuDbg("valid %d\n", !valid);
32610 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32612 + unsigned int l, deblk_sz;
32613 + union au_vdir_deblk_p deblk_end;
32614 + struct au_vdir *vdir_cache;
32615 + struct au_vdir_de *de;
32617 + if (!seek_vdir(file, ctx))
32620 + vdir_cache = au_fvdir_cache(file);
32621 + deblk_sz = vdir_cache->vd_deblk_sz;
32623 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32624 + deblk_end.deblk += deblk_sz;
32625 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32626 + de = vdir_cache->vd_last.p.de;
32627 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32628 + de->de_str.len, de->de_str.name, ctx->pos,
32629 + (unsigned long)de->de_ino, de->de_type);
32630 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32631 + de->de_str.len, de->de_ino,
32633 + /* todo: ignore the error caused by udba? */
32634 + /* return err; */
32638 + l = calc_size(de->de_str.len);
32639 + vdir_cache->vd_last.p.deblk += l;
32642 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32643 + vdir_cache->vd_last.ul++;
32644 + vdir_cache->vd_last.p.deblk
32645 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32646 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32655 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32656 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32657 +++ linux/fs/aufs/vfsub.c 2021-05-02 20:15:14.676670793 +0200
32659 +// SPDX-License-Identifier: GPL-2.0
32661 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32663 + * This program, aufs is free software; you can redistribute it and/or modify
32664 + * it under the terms of the GNU General Public License as published by
32665 + * the Free Software Foundation; either version 2 of the License, or
32666 + * (at your option) any later version.
32668 + * This program is distributed in the hope that it will be useful,
32669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32671 + * GNU General Public License for more details.
32673 + * You should have received a copy of the GNU General Public License
32674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32678 + * sub-routines for VFS
32681 +#include <linux/mnt_namespace.h>
32682 +#include <linux/namei.h>
32683 +#include <linux/nsproxy.h>
32684 +#include <linux/security.h>
32685 +#include <linux/splice.h>
32688 +#ifdef CONFIG_AUFS_BR_FUSE
32689 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32691 + if (!au_test_fuse(h_sb) || !au_userns)
32694 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32698 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32703 + down_read(&h_sb->s_umount);
32704 + err = __sync_filesystem(h_sb, wait);
32705 + up_read(&h_sb->s_umount);
32711 +/* ---------------------------------------------------------------------- */
32713 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32717 + struct super_block *h_sb;
32719 + /* for remote fs, leave work for its getattr or d_revalidate */
32720 + /* for bad i_attr fs, handle them in aufs_getattr() */
32721 + /* still some fs may acquire i_mutex. we need to skip them */
32725 + h_sb = h_path->dentry->d_sb;
32726 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32728 + err = vfsub_getattr(h_path, &st);
32733 +/* ---------------------------------------------------------------------- */
32735 +struct file *vfsub_dentry_open(struct path *path, int flags)
32737 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32741 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32743 + struct file *file;
32746 + file = filp_open(path,
32747 + oflags /* | __FMODE_NONOTIFY */,
32750 + if (IS_ERR(file))
32752 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32759 + * Ideally this function should call VFS:do_last() in order to keep all its
32760 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32761 + * structure such as nameidata. This is a second (or third) best approach.
32762 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32764 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32765 + struct vfsub_aopen_args *args)
32768 + struct au_branch *br = args->br;
32769 + struct file *file = args->file;
32770 + /* copied from linux/fs/namei.c:atomic_open() */
32771 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32774 + AuDebugOn(!dir->i_op->atomic_open);
32776 + err = au_br_test_oflag(args->open_flag, br);
32777 + if (unlikely(err))
32780 + au_lcnt_inc(&br->br_nfiles);
32781 + file->f_path.dentry = DENTRY_NOT_SET;
32782 + file->f_path.mnt = au_br_mnt(br);
32783 + AuDbg("%ps\n", dir->i_op->atomic_open);
32784 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32785 + args->create_mode);
32786 + if (unlikely(err < 0)) {
32787 + au_lcnt_dec(&br->br_nfiles);
32791 + /* temporary workaround for nfsv4 branch */
32792 + if (au_test_nfs(dir->i_sb))
32793 + nfs_mark_for_revalidate(dir);
32795 + if (file->f_mode & FMODE_CREATED)
32796 + fsnotify_create(dir, dentry);
32797 + if (!(file->f_mode & FMODE_OPENED)) {
32798 + au_lcnt_dec(&br->br_nfiles);
32802 + /* todo: call VFS:may_open() here */
32803 + /* todo: ima_file_check() too? */
32804 + if (!err && (args->open_flag & __FMODE_EXEC))
32805 + err = deny_write_access(file);
32807 + fsnotify_open(file);
32809 + au_lcnt_dec(&br->br_nfiles);
32810 + /* note that the file is created and still opened */
32816 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32820 + err = kern_path(name, flags, path);
32821 + if (!err && d_is_positive(path->dentry))
32822 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32826 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32827 + struct dentry *parent, int len)
32829 + struct path path = {
32833 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32834 + if (IS_ERR(path.dentry))
32836 + if (d_is_positive(path.dentry))
32837 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32840 + AuTraceErrPtr(path.dentry);
32841 + return path.dentry;
32844 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32847 + struct path path = {
32851 + /* VFS checks it too, but by WARN_ON_ONCE() */
32852 + IMustLock(d_inode(parent));
32854 + path.dentry = lookup_one_len(name, parent, len);
32855 + if (IS_ERR(path.dentry))
32857 + if (d_is_positive(path.dentry))
32858 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32861 + AuTraceErrPtr(path.dentry);
32862 + return path.dentry;
32865 +void vfsub_call_lkup_one(void *args)
32867 + struct vfsub_lkup_one_args *a = args;
32868 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32871 +/* ---------------------------------------------------------------------- */
32873 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32874 + struct dentry *d2, struct au_hinode *hdir2)
32876 + struct dentry *d;
32879 + d = lock_rename(d1, d2);
32881 + au_hn_suspend(hdir1);
32882 + if (hdir1 != hdir2)
32883 + au_hn_suspend(hdir2);
32888 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32889 + struct dentry *d2, struct au_hinode *hdir2)
32891 + au_hn_resume(hdir1);
32892 + if (hdir1 != hdir2)
32893 + au_hn_resume(hdir2);
32895 + unlock_rename(d1, d2);
32899 +/* ---------------------------------------------------------------------- */
32901 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32904 + struct dentry *d;
32905 + struct user_namespace *userns;
32909 + d = path->dentry;
32910 + path->dentry = d->d_parent;
32911 + err = security_path_mknod(path, d, mode, 0);
32912 + path->dentry = d;
32913 + if (unlikely(err))
32915 + userns = mnt_user_ns(path->mnt);
32918 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
32921 + struct path tmp = *path;
32924 + vfsub_update_h_iattr(&tmp, &did);
32926 + tmp.dentry = path->dentry->d_parent;
32927 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32936 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32939 + struct dentry *d;
32940 + struct user_namespace *userns;
32944 + d = path->dentry;
32945 + path->dentry = d->d_parent;
32946 + err = security_path_symlink(path, d, symname);
32947 + path->dentry = d;
32948 + if (unlikely(err))
32950 + userns = mnt_user_ns(path->mnt);
32953 + err = vfs_symlink(userns, dir, path->dentry, symname);
32956 + struct path tmp = *path;
32959 + vfsub_update_h_iattr(&tmp, &did);
32961 + tmp.dentry = path->dentry->d_parent;
32962 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32971 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32974 + struct dentry *d;
32975 + struct user_namespace *userns;
32979 + d = path->dentry;
32980 + path->dentry = d->d_parent;
32981 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32982 + path->dentry = d;
32983 + if (unlikely(err))
32985 + userns = mnt_user_ns(path->mnt);
32988 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
32991 + struct path tmp = *path;
32994 + vfsub_update_h_iattr(&tmp, &did);
32996 + tmp.dentry = path->dentry->d_parent;
32997 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33006 +static int au_test_nlink(struct inode *inode)
33008 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33010 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33011 + || inode->i_nlink < link_max)
33016 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33017 + struct inode **delegated_inode)
33020 + struct dentry *d;
33021 + struct user_namespace *userns;
33025 + err = au_test_nlink(d_inode(src_dentry));
33026 + if (unlikely(err))
33029 + /* we don't call may_linkat() */
33030 + d = path->dentry;
33031 + path->dentry = d->d_parent;
33032 + err = security_path_link(src_dentry, path, d);
33033 + path->dentry = d;
33034 + if (unlikely(err))
33036 + userns = mnt_user_ns(path->mnt);
33039 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33042 + struct path tmp = *path;
33045 + /* fuse has different memory inode for the same inumber */
33046 + vfsub_update_h_iattr(&tmp, &did);
33048 + tmp.dentry = path->dentry->d_parent;
33049 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33050 + tmp.dentry = src_dentry;
33051 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33060 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33061 + struct inode *dir, struct path *path,
33062 + struct inode **delegated_inode, unsigned int flags)
33065 + struct renamedata rd;
33066 + struct path tmp = {
33069 + struct dentry *d;
33072 + IMustLock(src_dir);
33074 + d = path->dentry;
33075 + path->dentry = d->d_parent;
33076 + tmp.dentry = src_dentry->d_parent;
33077 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33078 + path->dentry = d;
33079 + if (unlikely(err))
33082 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33083 + rd.old_dir = src_dir;
33084 + rd.old_dentry = src_dentry;
33085 + rd.new_mnt_userns = rd.old_mnt_userns;
33086 + rd.new_dir = dir;
33087 + rd.new_dentry = path->dentry;
33088 + rd.delegated_inode = delegated_inode;
33089 + rd.flags = flags;
33091 + err = vfs_rename(&rd);
33096 + tmp.dentry = d->d_parent;
33097 + vfsub_update_h_iattr(&tmp, &did);
33099 + tmp.dentry = src_dentry;
33100 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33101 + tmp.dentry = src_dentry->d_parent;
33102 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33111 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33114 + struct dentry *d;
33115 + struct user_namespace *userns;
33119 + d = path->dentry;
33120 + path->dentry = d->d_parent;
33121 + err = security_path_mkdir(path, d, mode);
33122 + path->dentry = d;
33123 + if (unlikely(err))
33125 + userns = mnt_user_ns(path->mnt);
33128 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33131 + struct path tmp = *path;
33134 + vfsub_update_h_iattr(&tmp, &did);
33136 + tmp.dentry = path->dentry->d_parent;
33137 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33146 +int vfsub_rmdir(struct inode *dir, struct path *path)
33149 + struct dentry *d;
33150 + struct user_namespace *userns;
33154 + d = path->dentry;
33155 + path->dentry = d->d_parent;
33156 + err = security_path_rmdir(path, d);
33157 + path->dentry = d;
33158 + if (unlikely(err))
33160 + userns = mnt_user_ns(path->mnt);
33163 + err = vfs_rmdir(userns, dir, path->dentry);
33166 + struct path tmp = {
33167 + .dentry = path->dentry->d_parent,
33171 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33178 +/* ---------------------------------------------------------------------- */
33180 +/* todo: support mmap_sem? */
33181 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33187 + err = vfs_read(file, ubuf, count, ppos);
33190 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33194 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33200 + err = kernel_read(file, kbuf, count, ppos);
33204 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33208 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33214 + err = vfs_write(file, ubuf, count, ppos);
33217 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33221 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33226 + err = kernel_write(file, kbuf, count, ppos);
33229 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33233 +int vfsub_flush(struct file *file, fl_owner_t id)
33238 + if (file->f_op->flush) {
33239 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33240 + err = file->f_op->flush(file, id);
33243 + err = file->f_op->flush(file, id);
33247 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33253 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33257 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33260 + err = iterate_dir(file, ctx);
33263 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33268 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33269 + struct pipe_inode_info *pipe, size_t len,
33270 + unsigned int flags)
33275 + err = do_splice_to(in, ppos, pipe, len, flags);
33277 + file_accessed(in);
33279 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33283 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33284 + loff_t *ppos, size_t len, unsigned int flags)
33289 + err = do_splice_from(pipe, out, ppos, len, flags);
33292 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33296 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33300 + /* file can be NULL */
33302 + err = vfs_fsync(file, datasync);
33306 + AuDebugOn(!file);
33307 + path = &file->f_path;
33309 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33314 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33315 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33316 + struct file *h_file)
33319 + struct inode *h_inode;
33320 + struct super_block *h_sb;
33321 + struct user_namespace *h_userns;
33324 + err = vfsub_truncate(h_path, length);
33328 + h_inode = d_inode(h_path->dentry);
33329 + h_sb = h_inode->i_sb;
33331 + sb_start_write(h_sb);
33333 + err = locks_verify_truncate(h_inode, h_file, length);
33335 + err = security_path_truncate(h_path);
33337 + h_userns = mnt_user_ns(h_path->mnt);
33339 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33344 + sb_end_write(h_sb);
33351 +/* ---------------------------------------------------------------------- */
33353 +struct au_vfsub_mkdir_args {
33355 + struct inode *dir;
33356 + struct path *path;
33360 +static void au_call_vfsub_mkdir(void *args)
33362 + struct au_vfsub_mkdir_args *a = args;
33363 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33366 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33368 + int err, do_sio, wkq_err;
33369 + struct user_namespace *userns;
33371 + userns = mnt_user_ns(path->mnt);
33372 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33375 + err = vfsub_mkdir(dir, path, mode);
33378 + struct au_vfsub_mkdir_args args = {
33384 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33385 + if (unlikely(wkq_err))
33392 +struct au_vfsub_rmdir_args {
33394 + struct inode *dir;
33395 + struct path *path;
33398 +static void au_call_vfsub_rmdir(void *args)
33400 + struct au_vfsub_rmdir_args *a = args;
33401 + *a->errp = vfsub_rmdir(a->dir, a->path);
33404 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33406 + int err, do_sio, wkq_err;
33407 + struct user_namespace *userns;
33409 + userns = mnt_user_ns(path->mnt);
33410 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33413 + err = vfsub_rmdir(dir, path);
33416 + struct au_vfsub_rmdir_args args = {
33421 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33422 + if (unlikely(wkq_err))
33429 +/* ---------------------------------------------------------------------- */
33431 +struct notify_change_args {
33433 + struct path *path;
33434 + struct iattr *ia;
33435 + struct inode **delegated_inode;
33438 +static void call_notify_change(void *args)
33440 + struct notify_change_args *a = args;
33441 + struct inode *h_inode;
33442 + struct user_namespace *userns;
33444 + h_inode = d_inode(a->path->dentry);
33445 + IMustLock(h_inode);
33447 + *a->errp = -EPERM;
33448 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33449 + userns = mnt_user_ns(a->path->mnt);
33451 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33452 + a->delegated_inode);
33455 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33457 + AuTraceErr(*a->errp);
33460 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33461 + struct inode **delegated_inode)
33464 + struct notify_change_args args = {
33468 + .delegated_inode = delegated_inode
33471 + call_notify_change(&args);
33476 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33477 + struct inode **delegated_inode)
33479 + int err, wkq_err;
33480 + struct notify_change_args args = {
33484 + .delegated_inode = delegated_inode
33487 + wkq_err = au_wkq_wait(call_notify_change, &args);
33488 + if (unlikely(wkq_err))
33494 +/* ---------------------------------------------------------------------- */
33496 +struct unlink_args {
33498 + struct inode *dir;
33499 + struct path *path;
33500 + struct inode **delegated_inode;
33503 +static void call_unlink(void *args)
33505 + struct unlink_args *a = args;
33506 + struct dentry *d = a->path->dentry;
33507 + struct inode *h_inode;
33508 + struct user_namespace *userns;
33509 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33510 + && au_dcount(d) == 1);
33512 + IMustLock(a->dir);
33514 + a->path->dentry = d->d_parent;
33515 + *a->errp = security_path_unlink(a->path, d);
33516 + a->path->dentry = d;
33517 + if (unlikely(*a->errp))
33520 + if (!stop_sillyrename)
33523 + if (d_is_positive(d)) {
33524 + h_inode = d_inode(d);
33528 + userns = mnt_user_ns(a->path->mnt);
33530 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33533 + struct path tmp = {
33534 + .dentry = d->d_parent,
33535 + .mnt = a->path->mnt
33537 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33540 + if (!stop_sillyrename)
33545 + AuTraceErr(*a->errp);
33549 + * @dir: must be locked.
33550 + * @dentry: target dentry.
33552 +int vfsub_unlink(struct inode *dir, struct path *path,
33553 + struct inode **delegated_inode, int force)
33556 + struct unlink_args args = {
33560 + .delegated_inode = delegated_inode
33564 + call_unlink(&args);
33568 + wkq_err = au_wkq_wait(call_unlink, &args);
33569 + if (unlikely(wkq_err))
33575 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33576 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33577 +++ linux/fs/aufs/vfsub.h 2021-05-02 20:15:14.676670793 +0200
33579 +/* SPDX-License-Identifier: GPL-2.0 */
33581 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33583 + * This program, aufs is free software; you can redistribute it and/or modify
33584 + * it under the terms of the GNU General Public License as published by
33585 + * the Free Software Foundation; either version 2 of the License, or
33586 + * (at your option) any later version.
33588 + * This program is distributed in the hope that it will be useful,
33589 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33590 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33591 + * GNU General Public License for more details.
33593 + * You should have received a copy of the GNU General Public License
33594 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33598 + * sub-routines for VFS
33601 +#ifndef __AUFS_VFSUB_H__
33602 +#define __AUFS_VFSUB_H__
33606 +#include <linux/fs.h>
33607 +#include <linux/mount.h>
33608 +#include <linux/posix_acl.h>
33609 +#include <linux/xattr.h>
33610 +#include "debug.h"
33612 +/* copied from linux/fs/internal.h */
33613 +/* todo: BAD approach!! */
33614 +extern void __mnt_drop_write(struct vfsmount *);
33615 +extern struct file *alloc_empty_file(int, const struct cred *);
33617 +/* ---------------------------------------------------------------------- */
33619 +/* lock subclass for lower inode */
33620 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33621 +/* reduce? gave up. */
33623 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33624 + AuLsc_I_PARENT, /* lower inode, parent first */
33625 + AuLsc_I_PARENT2, /* copyup dirs */
33626 + AuLsc_I_PARENT3, /* copyup wh */
33632 +/* to debug easier, do not make them inlined functions */
33633 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33634 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33636 +/* ---------------------------------------------------------------------- */
33638 +static inline void vfsub_drop_nlink(struct inode *inode)
33640 + AuDebugOn(!inode->i_nlink);
33641 + drop_nlink(inode);
33644 +static inline void vfsub_dead_dir(struct inode *inode)
33646 + AuDebugOn(!S_ISDIR(inode->i_mode));
33647 + inode->i_flags |= S_DEAD;
33648 + clear_nlink(inode);
33651 +static inline int vfsub_native_ro(struct inode *inode)
33653 + return sb_rdonly(inode->i_sb)
33654 + || IS_RDONLY(inode)
33655 + /* || IS_APPEND(inode) */
33656 + || IS_IMMUTABLE(inode);
33659 +#ifdef CONFIG_AUFS_BR_FUSE
33660 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33662 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33665 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33667 +/* ---------------------------------------------------------------------- */
33669 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33670 +struct file *vfsub_dentry_open(struct path *path, int flags);
33671 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33673 +struct vfsub_aopen_args {
33674 + struct file *file;
33675 + unsigned int open_flag;
33676 + umode_t create_mode;
33677 + struct au_branch *br;
33679 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33680 + struct vfsub_aopen_args *args);
33681 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33683 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33684 + struct dentry *parent, int len);
33685 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33688 +struct vfsub_lkup_one_args {
33689 + struct dentry **errp;
33690 + struct qstr *name;
33691 + struct dentry *parent;
33694 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33695 + struct dentry *parent)
33697 + return vfsub_lookup_one_len(name->name, parent, name->len);
33700 +void vfsub_call_lkup_one(void *args);
33702 +/* ---------------------------------------------------------------------- */
33704 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33709 + err = mnt_want_write(mnt);
33714 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33717 + mnt_drop_write(mnt);
33721 +#if 0 /* reserved */
33722 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33725 + mnt_drop_write_file(file);
33730 +/* ---------------------------------------------------------------------- */
33733 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33734 + struct dentry *d2, struct au_hinode *hdir2);
33735 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33736 + struct dentry *d2, struct au_hinode *hdir2);
33738 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33740 +int vfsub_symlink(struct inode *dir, struct path *path,
33741 + const char *symname);
33742 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33743 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33744 + struct path *path, struct inode **delegated_inode);
33745 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33746 + struct inode *hdir, struct path *path,
33747 + struct inode **delegated_inode, unsigned int flags);
33748 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33749 +int vfsub_rmdir(struct inode *dir, struct path *path);
33751 +/* ---------------------------------------------------------------------- */
33753 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33755 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33757 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33759 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33761 +int vfsub_flush(struct file *file, fl_owner_t id);
33762 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33764 +static inline loff_t vfsub_f_size_read(struct file *file)
33766 + return i_size_read(file_inode(file));
33769 +static inline unsigned int vfsub_file_flags(struct file *file)
33771 + unsigned int flags;
33773 + spin_lock(&file->f_lock);
33774 + flags = file->f_flags;
33775 + spin_unlock(&file->f_lock);
33780 +static inline int vfsub_file_execed(struct file *file)
33782 + /* todo: direct access f_flags */
33783 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33786 +#if 0 /* reserved */
33787 +static inline void vfsub_file_accessed(struct file *h_file)
33789 + file_accessed(h_file);
33790 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33794 +#if 0 /* reserved */
33795 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33796 + struct dentry *h_dentry)
33798 + struct path h_path = {
33799 + .dentry = h_dentry,
33802 + touch_atime(&h_path);
33803 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33807 +static inline int vfsub_update_time(struct inode *h_inode,
33808 + struct timespec64 *ts, int flags)
33810 + return update_time(h_inode, ts, flags);
33811 + /* no vfsub_update_h_iattr() since we don't have struct path */
33814 +#ifdef CONFIG_FS_POSIX_ACL
33815 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
33816 + struct inode *h_inode, umode_t h_mode)
33820 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
33821 + if (err == -EOPNOTSUPP)
33826 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
33827 + struct inode *h_inode, umode_t h_mode);
33830 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33831 + struct pipe_inode_info *pipe, size_t len,
33832 + unsigned int flags);
33833 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33834 + loff_t *ppos, size_t len, unsigned int flags);
33836 +static inline long vfsub_truncate(struct path *path, loff_t length)
33841 + err = vfs_truncate(path, length);
33846 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33847 + struct file *h_file);
33848 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33851 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33854 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33860 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33866 +/* copy_file_range(2) is a systemcall */
33867 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33868 + struct file *dst, loff_t dst_pos,
33869 + size_t len, unsigned int flags)
33874 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33880 +/* ---------------------------------------------------------------------- */
33882 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33887 + err = vfs_llseek(file, offset, origin);
33892 +/* ---------------------------------------------------------------------- */
33894 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33895 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33896 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33897 + struct inode **delegated_inode);
33898 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33899 + struct inode **delegated_inode);
33900 +int vfsub_unlink(struct inode *dir, struct path *path,
33901 + struct inode **delegated_inode, int force);
33903 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33905 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33908 +/* ---------------------------------------------------------------------- */
33910 +static inline int vfsub_setxattr(struct user_namespace *userns,
33911 + struct dentry *dentry, const char *name,
33912 + const void *value, size_t size, int flags)
33917 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
33923 +static inline int vfsub_removexattr(struct user_namespace *userns,
33924 + struct dentry *dentry, const char *name)
33929 + err = vfs_removexattr(userns, dentry, name);
33935 +#endif /* __KERNEL__ */
33936 +#endif /* __AUFS_VFSUB_H__ */
33937 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33938 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33939 +++ linux/fs/aufs/wbr_policy.c 2021-05-02 20:15:14.676670793 +0200
33941 +// SPDX-License-Identifier: GPL-2.0
33943 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33945 + * This program, aufs is free software; you can redistribute it and/or modify
33946 + * it under the terms of the GNU General Public License as published by
33947 + * the Free Software Foundation; either version 2 of the License, or
33948 + * (at your option) any later version.
33950 + * This program is distributed in the hope that it will be useful,
33951 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33952 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33953 + * GNU General Public License for more details.
33955 + * You should have received a copy of the GNU General Public License
33956 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33960 + * policies for selecting one among multiple writable branches
33963 +#include <linux/statfs.h>
33966 +/* subset of cpup_attr() */
33967 +static noinline_for_stack
33968 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33972 + struct inode *h_isrc;
33974 + h_isrc = d_inode(h_src);
33975 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33976 + ia.ia_mode = h_isrc->i_mode;
33977 + ia.ia_uid = h_isrc->i_uid;
33978 + ia.ia_gid = h_isrc->i_gid;
33979 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33980 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33981 + /* no delegation since it is just created */
33982 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33984 + /* is this nfs only? */
33985 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33986 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33987 + ia.ia_mode = h_isrc->i_mode;
33988 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33994 +#define AuCpdown_PARENT_OPQ 1
33995 +#define AuCpdown_WHED (1 << 1)
33996 +#define AuCpdown_MADE_DIR (1 << 2)
33997 +#define AuCpdown_DIROPQ (1 << 3)
33998 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33999 +#define au_fset_cpdown(flags, name) \
34000 + do { (flags) |= AuCpdown_##name; } while (0)
34001 +#define au_fclr_cpdown(flags, name) \
34002 + do { (flags) &= ~AuCpdown_##name; } while (0)
34004 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34005 + unsigned int *flags)
34008 + struct dentry *opq_dentry;
34010 + opq_dentry = au_diropq_create(dentry, bdst);
34011 + err = PTR_ERR(opq_dentry);
34012 + if (IS_ERR(opq_dentry))
34014 + dput(opq_dentry);
34015 + au_fset_cpdown(*flags, DIROPQ);
34021 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34022 + struct inode *dir, aufs_bindex_t bdst)
34025 + struct path h_path;
34026 + struct au_branch *br;
34028 + br = au_sbr(dentry->d_sb, bdst);
34029 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34030 + err = PTR_ERR(h_path.dentry);
34031 + if (IS_ERR(h_path.dentry))
34035 + if (d_is_positive(h_path.dentry)) {
34036 + h_path.mnt = au_br_mnt(br);
34037 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34040 + dput(h_path.dentry);
34046 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34047 + struct au_pin *pin,
34048 + struct dentry *h_parent, void *arg)
34051 + aufs_bindex_t bopq, btop;
34052 + struct path h_path;
34053 + struct dentry *parent;
34054 + struct inode *h_dir, *h_inode, *inode, *dir;
34055 + unsigned int *flags = arg;
34057 + btop = au_dbtop(dentry);
34058 + /* dentry is di-locked */
34059 + parent = dget_parent(dentry);
34060 + dir = d_inode(parent);
34061 + h_dir = d_inode(h_parent);
34062 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34063 + IMustLock(h_dir);
34065 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34066 + if (unlikely(err < 0))
34068 + h_path.dentry = au_h_dptr(dentry, bdst);
34069 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34070 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34071 + if (unlikely(err))
34073 + au_fset_cpdown(*flags, MADE_DIR);
34075 + bopq = au_dbdiropq(dentry);
34076 + au_fclr_cpdown(*flags, WHED);
34077 + au_fclr_cpdown(*flags, DIROPQ);
34078 + if (au_dbwh(dentry) == bdst)
34079 + au_fset_cpdown(*flags, WHED);
34080 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34081 + au_fset_cpdown(*flags, PARENT_OPQ);
34082 + h_inode = d_inode(h_path.dentry);
34083 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34084 + if (au_ftest_cpdown(*flags, WHED)) {
34085 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34086 + if (unlikely(err)) {
34087 + inode_unlock(h_inode);
34092 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34093 + inode_unlock(h_inode);
34094 + if (unlikely(err))
34097 + if (au_ftest_cpdown(*flags, WHED)) {
34098 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34099 + if (unlikely(err))
34103 + inode = d_inode(dentry);
34104 + if (au_ibbot(inode) < bdst)
34105 + au_set_ibbot(inode, bdst);
34106 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34107 + au_hi_flags(inode, /*isdir*/1));
34108 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34109 + goto out; /* success */
34113 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34114 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34115 + rerr = au_diropq_remove(dentry, bdst);
34116 + inode_unlock(h_inode);
34117 + if (unlikely(rerr)) {
34118 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34119 + dentry, bdst, rerr);
34125 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34126 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34127 + if (unlikely(rerr)) {
34128 + AuIOErr("failed removing %pd b%d (%d)\n",
34129 + dentry, bdst, rerr);
34134 + au_set_h_dptr(dentry, bdst, NULL);
34135 + if (au_dbbot(dentry) == bdst)
34136 + au_update_dbbot(dentry);
34142 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34145 + unsigned int flags;
34148 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34153 +/* ---------------------------------------------------------------------- */
34155 +/* policies for create */
34157 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34159 + int err, i, j, ndentry;
34160 + aufs_bindex_t bopq;
34161 + struct au_dcsub_pages dpages;
34162 + struct au_dpage *dpage;
34163 + struct dentry **dentries, *parent, *d;
34165 + err = au_dpages_init(&dpages, GFP_NOFS);
34166 + if (unlikely(err))
34168 + parent = dget_parent(dentry);
34169 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34170 + if (unlikely(err))
34174 + for (i = 0; i < dpages.ndpage; i++) {
34175 + dpage = dpages.dpages + i;
34176 + dentries = dpage->dentries;
34177 + ndentry = dpage->ndentry;
34178 + for (j = 0; j < ndentry; j++) {
34180 + di_read_lock_parent2(d, !AuLock_IR);
34181 + bopq = au_dbdiropq(d);
34182 + di_read_unlock(d, !AuLock_IR);
34183 + if (bopq >= 0 && bopq < err)
34190 + au_dpages_free(&dpages);
34195 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34197 + for (; bindex >= 0; bindex--)
34198 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34203 +/* top down parent */
34204 +static int au_wbr_create_tdp(struct dentry *dentry,
34205 + unsigned int flags __maybe_unused)
34208 + aufs_bindex_t btop, bindex;
34209 + struct super_block *sb;
34210 + struct dentry *parent, *h_parent;
34212 + sb = dentry->d_sb;
34213 + btop = au_dbtop(dentry);
34215 + if (!au_br_rdonly(au_sbr(sb, btop)))
34219 + parent = dget_parent(dentry);
34220 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34221 + h_parent = au_h_dptr(parent, bindex);
34222 + if (!h_parent || d_is_negative(h_parent))
34225 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34232 + /* bottom up here */
34233 + if (unlikely(err < 0)) {
34234 + err = au_wbr_bu(sb, btop - 1);
34236 + err = au_wbr_nonopq(dentry, err);
34240 + AuDbg("b%d\n", err);
34244 +/* ---------------------------------------------------------------------- */
34246 +/* an exception for the policy other than tdp */
34247 +static int au_wbr_create_exp(struct dentry *dentry)
34250 + aufs_bindex_t bwh, bdiropq;
34251 + struct dentry *parent;
34254 + bwh = au_dbwh(dentry);
34255 + parent = dget_parent(dentry);
34256 + bdiropq = au_dbdiropq(parent);
34258 + if (bdiropq >= 0)
34259 + err = min(bdiropq, bwh);
34262 + AuDbg("%d\n", err);
34263 + } else if (bdiropq >= 0) {
34265 + AuDbg("%d\n", err);
34270 + err = au_wbr_nonopq(dentry, err);
34272 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34275 + AuDbg("%d\n", err);
34279 +/* ---------------------------------------------------------------------- */
34282 +static int au_wbr_create_init_rr(struct super_block *sb)
34286 + err = au_wbr_bu(sb, au_sbbot(sb));
34287 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34290 + AuDbg("b%d\n", err);
34294 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34298 + aufs_bindex_t bindex, bbot;
34299 + struct super_block *sb;
34302 + err = au_wbr_create_exp(dentry);
34306 + sb = dentry->d_sb;
34307 + next = &au_sbi(sb)->si_wbr_rr_next;
34308 + bbot = au_sbbot(sb);
34310 + for (bindex = 0; bindex <= bbot; bindex++) {
34311 + if (!au_ftest_wbr(flags, DIR)) {
34312 + err = atomic_dec_return(next) + 1;
34313 + /* modulo for 0 is meaningless */
34314 + if (unlikely(!err))
34315 + err = atomic_dec_return(next) + 1;
34317 + err = atomic_read(next);
34318 + AuDbg("%d\n", err);
34321 + AuDbg("%d\n", err);
34322 + if (!au_br_rdonly(au_sbr(sb, err)))
34328 + err = au_wbr_nonopq(dentry, err);
34331 + AuDbg("%d\n", err);
34335 +/* ---------------------------------------------------------------------- */
34337 +/* most free space */
34338 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34340 + struct super_block *sb;
34341 + struct au_branch *br;
34342 + struct au_wbr_mfs *mfs;
34343 + struct dentry *h_parent;
34344 + aufs_bindex_t bindex, bbot;
34346 + unsigned long long b, bavail;
34347 + struct path h_path;
34348 + /* reduce the stack usage */
34349 + struct kstatfs *st;
34351 + st = kmalloc(sizeof(*st), GFP_NOFS);
34352 + if (unlikely(!st)) {
34353 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34358 + sb = dentry->d_sb;
34359 + mfs = &au_sbi(sb)->si_wbr_mfs;
34360 + MtxMustLock(&mfs->mfs_lock);
34361 + mfs->mfs_bindex = -EROFS;
34362 + mfs->mfsrr_bytes = 0;
34365 + bbot = au_sbbot(sb);
34367 + bindex = au_dbtop(parent);
34368 + bbot = au_dbtaildir(parent);
34371 + for (; bindex <= bbot; bindex++) {
34373 + h_parent = au_h_dptr(parent, bindex);
34374 + if (!h_parent || d_is_negative(h_parent))
34377 + br = au_sbr(sb, bindex);
34378 + if (au_br_rdonly(br))
34381 + /* sb->s_root for NFS is unreliable */
34382 + h_path.mnt = au_br_mnt(br);
34383 + h_path.dentry = h_path.mnt->mnt_root;
34384 + err = vfs_statfs(&h_path, st);
34385 + if (unlikely(err)) {
34386 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34390 + /* when the available size is equal, select the lower one */
34391 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34392 + || sizeof(b) < sizeof(st->f_bsize));
34393 + b = st->f_bavail * st->f_bsize;
34394 + br->br_wbr->wbr_bytes = b;
34395 + if (b >= bavail) {
34397 + mfs->mfs_bindex = bindex;
34398 + mfs->mfs_jiffy = jiffies;
34402 + mfs->mfsrr_bytes = bavail;
34403 + AuDbg("b%d\n", mfs->mfs_bindex);
34404 + au_kfree_rcu(st);
34407 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34410 + struct dentry *parent;
34411 + struct super_block *sb;
34412 + struct au_wbr_mfs *mfs;
34414 + err = au_wbr_create_exp(dentry);
34418 + sb = dentry->d_sb;
34420 + if (au_ftest_wbr(flags, PARENT))
34421 + parent = dget_parent(dentry);
34422 + mfs = &au_sbi(sb)->si_wbr_mfs;
34423 + mutex_lock(&mfs->mfs_lock);
34424 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34425 + || mfs->mfs_bindex < 0
34426 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34427 + au_mfs(dentry, parent);
34428 + mutex_unlock(&mfs->mfs_lock);
34429 + err = mfs->mfs_bindex;
34433 + err = au_wbr_nonopq(dentry, err);
34436 + AuDbg("b%d\n", err);
34440 +static int au_wbr_create_init_mfs(struct super_block *sb)
34442 + struct au_wbr_mfs *mfs;
34444 + mfs = &au_sbi(sb)->si_wbr_mfs;
34445 + mutex_init(&mfs->mfs_lock);
34446 + mfs->mfs_jiffy = 0;
34447 + mfs->mfs_bindex = -EROFS;
34452 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34454 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34458 +/* ---------------------------------------------------------------------- */
34460 +/* top down regardless parent, and then mfs */
34461 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34462 + unsigned int flags __maybe_unused)
34465 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34466 + unsigned long long watermark;
34467 + struct super_block *sb;
34468 + struct au_wbr_mfs *mfs;
34469 + struct au_branch *br;
34470 + struct dentry *parent;
34472 + sb = dentry->d_sb;
34473 + mfs = &au_sbi(sb)->si_wbr_mfs;
34474 + mutex_lock(&mfs->mfs_lock);
34475 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34476 + || mfs->mfs_bindex < 0)
34477 + au_mfs(dentry, /*parent*/NULL);
34478 + watermark = mfs->mfsrr_watermark;
34479 + bmfs = mfs->mfs_bindex;
34480 + mutex_unlock(&mfs->mfs_lock);
34482 + /* another style of au_wbr_create_exp() */
34483 + bwh = au_dbwh(dentry);
34484 + parent = dget_parent(dentry);
34485 + btail = au_dbtaildir(parent);
34486 + if (bwh >= 0 && bwh < btail)
34489 + err = au_wbr_nonopq(dentry, btail);
34490 + if (unlikely(err < 0))
34494 + for (bindex = 0; bindex <= btail; bindex++) {
34495 + br = au_sbr(sb, bindex);
34496 + if (au_br_rdonly(br))
34498 + if (br->br_wbr->wbr_bytes > watermark) {
34509 + AuDbg("b%d\n", err);
34513 +/* ---------------------------------------------------------------------- */
34515 +/* most free space and then round robin */
34516 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34519 + struct au_wbr_mfs *mfs;
34521 + err = au_wbr_create_mfs(dentry, flags);
34523 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34524 + mutex_lock(&mfs->mfs_lock);
34525 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34526 + err = au_wbr_create_rr(dentry, flags);
34527 + mutex_unlock(&mfs->mfs_lock);
34530 + AuDbg("b%d\n", err);
34534 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34538 + au_wbr_create_init_mfs(sb); /* ignore */
34539 + err = au_wbr_create_init_rr(sb);
34544 +/* ---------------------------------------------------------------------- */
34546 +/* top down parent and most free space */
34547 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34550 + unsigned long long b;
34551 + aufs_bindex_t bindex, btop, bbot;
34552 + struct super_block *sb;
34553 + struct dentry *parent, *h_parent;
34554 + struct au_branch *br;
34556 + err = au_wbr_create_tdp(dentry, flags);
34557 + if (unlikely(err < 0))
34559 + parent = dget_parent(dentry);
34560 + btop = au_dbtop(parent);
34561 + bbot = au_dbtaildir(parent);
34562 + if (btop == bbot)
34563 + goto out_parent; /* success */
34565 + e2 = au_wbr_create_mfs(dentry, flags);
34567 + goto out_parent; /* success */
34569 + /* when the available size is equal, select upper one */
34570 + sb = dentry->d_sb;
34571 + br = au_sbr(sb, err);
34572 + b = br->br_wbr->wbr_bytes;
34573 + AuDbg("b%d, %llu\n", err, b);
34575 + for (bindex = btop; bindex <= bbot; bindex++) {
34576 + h_parent = au_h_dptr(parent, bindex);
34577 + if (!h_parent || d_is_negative(h_parent))
34580 + br = au_sbr(sb, bindex);
34581 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34582 + b = br->br_wbr->wbr_bytes;
34584 + AuDbg("b%d, %llu\n", err, b);
34589 + err = au_wbr_nonopq(dentry, err);
34594 + AuDbg("b%d\n", err);
34598 +/* ---------------------------------------------------------------------- */
34601 + * - top down parent
34602 + * - most free space with parent
34603 + * - most free space round-robin regardless parent
34605 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34608 + unsigned long long watermark;
34609 + struct super_block *sb;
34610 + struct au_branch *br;
34611 + struct au_wbr_mfs *mfs;
34613 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34614 + if (unlikely(err < 0))
34617 + sb = dentry->d_sb;
34618 + br = au_sbr(sb, err);
34619 + mfs = &au_sbi(sb)->si_wbr_mfs;
34620 + mutex_lock(&mfs->mfs_lock);
34621 + watermark = mfs->mfsrr_watermark;
34622 + mutex_unlock(&mfs->mfs_lock);
34623 + if (br->br_wbr->wbr_bytes < watermark)
34624 + /* regardless the parent dir */
34625 + err = au_wbr_create_mfsrr(dentry, flags);
34628 + AuDbg("b%d\n", err);
34632 +/* ---------------------------------------------------------------------- */
34634 +/* policies for copyup */
34636 +/* top down parent */
34637 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34639 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34642 +/* bottom up parent */
34643 +static int au_wbr_copyup_bup(struct dentry *dentry)
34646 + aufs_bindex_t bindex, btop;
34647 + struct dentry *parent, *h_parent;
34648 + struct super_block *sb;
34651 + sb = dentry->d_sb;
34652 + parent = dget_parent(dentry);
34653 + btop = au_dbtop(parent);
34654 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34655 + h_parent = au_h_dptr(parent, bindex);
34656 + if (!h_parent || d_is_negative(h_parent))
34659 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34666 + /* bottom up here */
34667 + if (unlikely(err < 0))
34668 + err = au_wbr_bu(sb, btop - 1);
34670 + AuDbg("b%d\n", err);
34675 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34679 + err = au_wbr_bu(dentry->d_sb, btop);
34680 + AuDbg("b%d\n", err);
34682 + err = au_wbr_nonopq(dentry, err);
34684 + AuDbg("b%d\n", err);
34688 +static int au_wbr_copyup_bu(struct dentry *dentry)
34691 + aufs_bindex_t btop;
34693 + btop = au_dbtop(dentry);
34694 + err = au_wbr_do_copyup_bu(dentry, btop);
34698 +/* ---------------------------------------------------------------------- */
34700 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34701 + [AuWbrCopyup_TDP] = {
34702 + .copyup = au_wbr_copyup_tdp
34704 + [AuWbrCopyup_BUP] = {
34705 + .copyup = au_wbr_copyup_bup
34707 + [AuWbrCopyup_BU] = {
34708 + .copyup = au_wbr_copyup_bu
34712 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34713 + [AuWbrCreate_TDP] = {
34714 + .create = au_wbr_create_tdp
34716 + [AuWbrCreate_RR] = {
34717 + .create = au_wbr_create_rr,
34718 + .init = au_wbr_create_init_rr
34720 + [AuWbrCreate_MFS] = {
34721 + .create = au_wbr_create_mfs,
34722 + .init = au_wbr_create_init_mfs,
34723 + .fin = au_wbr_create_fin_mfs
34725 + [AuWbrCreate_MFSV] = {
34726 + .create = au_wbr_create_mfs,
34727 + .init = au_wbr_create_init_mfs,
34728 + .fin = au_wbr_create_fin_mfs
34730 + [AuWbrCreate_MFSRR] = {
34731 + .create = au_wbr_create_mfsrr,
34732 + .init = au_wbr_create_init_mfsrr,
34733 + .fin = au_wbr_create_fin_mfs
34735 + [AuWbrCreate_MFSRRV] = {
34736 + .create = au_wbr_create_mfsrr,
34737 + .init = au_wbr_create_init_mfsrr,
34738 + .fin = au_wbr_create_fin_mfs
34740 + [AuWbrCreate_TDMFS] = {
34741 + .create = au_wbr_create_tdmfs,
34742 + .init = au_wbr_create_init_mfs,
34743 + .fin = au_wbr_create_fin_mfs
34745 + [AuWbrCreate_TDMFSV] = {
34746 + .create = au_wbr_create_tdmfs,
34747 + .init = au_wbr_create_init_mfs,
34748 + .fin = au_wbr_create_fin_mfs
34750 + [AuWbrCreate_PMFS] = {
34751 + .create = au_wbr_create_pmfs,
34752 + .init = au_wbr_create_init_mfs,
34753 + .fin = au_wbr_create_fin_mfs
34755 + [AuWbrCreate_PMFSV] = {
34756 + .create = au_wbr_create_pmfs,
34757 + .init = au_wbr_create_init_mfs,
34758 + .fin = au_wbr_create_fin_mfs
34760 + [AuWbrCreate_PMFSRR] = {
34761 + .create = au_wbr_create_pmfsrr,
34762 + .init = au_wbr_create_init_mfsrr,
34763 + .fin = au_wbr_create_fin_mfs
34765 + [AuWbrCreate_PMFSRRV] = {
34766 + .create = au_wbr_create_pmfsrr,
34767 + .init = au_wbr_create_init_mfsrr,
34768 + .fin = au_wbr_create_fin_mfs
34771 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34772 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34773 +++ linux/fs/aufs/whout.c 2021-05-02 20:15:14.676670793 +0200
34775 +// SPDX-License-Identifier: GPL-2.0
34777 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34779 + * This program, aufs is free software; you can redistribute it and/or modify
34780 + * it under the terms of the GNU General Public License as published by
34781 + * the Free Software Foundation; either version 2 of the License, or
34782 + * (at your option) any later version.
34784 + * This program is distributed in the hope that it will be useful,
34785 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34786 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34787 + * GNU General Public License for more details.
34789 + * You should have received a copy of the GNU General Public License
34790 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34794 + * whiteout for logical deletion and opaque directory
34799 +#define WH_MASK 0444
34802 + * If a directory contains this file, then it is opaque. We start with the
34803 + * .wh. flag so that it is blocked by lookup.
34805 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34806 + sizeof(AUFS_WH_DIROPQ) - 1);
34809 + * generate whiteout name, which is NOT terminated by NULL.
34810 + * @name: original d_name.name
34811 + * @len: original d_name.len
34812 + * @wh: whiteout qstr
34813 + * returns zero when succeeds, otherwise error.
34814 + * succeeded value as wh->name should be freed by kfree().
34816 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34820 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34821 + return -ENAMETOOLONG;
34823 + wh->len = name->len + AUFS_WH_PFX_LEN;
34824 + p = kmalloc(wh->len, GFP_NOFS);
34827 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34828 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34835 +/* ---------------------------------------------------------------------- */
34838 + * test if the @wh_name exists under @h_parent.
34839 + * @try_sio specifies the necessary of super-io.
34841 +int au_wh_test(struct user_namespace *h_userns, struct dentry *h_parent,
34842 + struct qstr *wh_name, int try_sio)
34845 + struct dentry *wh_dentry;
34848 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34850 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_parent);
34851 + err = PTR_ERR(wh_dentry);
34852 + if (IS_ERR(wh_dentry)) {
34853 + if (err == -ENAMETOOLONG)
34859 + if (d_is_negative(wh_dentry))
34860 + goto out_wh; /* success */
34863 + if (d_is_reg(wh_dentry))
34864 + goto out_wh; /* success */
34867 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34868 + wh_dentry, d_inode(wh_dentry)->i_mode);
34877 + * test if the @h_dentry sets opaque or not.
34879 +int au_diropq_test(struct user_namespace *h_userns, struct dentry *h_dentry)
34882 + struct inode *h_dir;
34884 + h_dir = d_inode(h_dentry);
34885 + err = au_wh_test(h_userns, h_dentry, &diropq_name,
34886 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
34891 + * returns a negative dentry whose name is unique and temporary.
34893 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34894 + struct qstr *prefix)
34896 + struct dentry *dentry;
34898 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34900 + /* strict atomic_t is unnecessary here */
34901 + static unsigned short cnt;
34903 + struct user_namespace *h_userns;
34905 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34908 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34909 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34910 + dentry = ERR_PTR(-ENAMETOOLONG);
34911 + if (unlikely(qs.len > NAME_MAX))
34913 + dentry = ERR_PTR(-ENOMEM);
34914 + name = kmalloc(qs.len + 1, GFP_NOFS);
34915 + if (unlikely(!name))
34919 + /* doubly whiteout-ed */
34920 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34921 + p = name + AUFS_WH_PFX_LEN * 2;
34922 + memcpy(p, prefix->name, prefix->len);
34923 + p += prefix->len;
34925 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34927 + h_userns = au_br_userns(br);
34929 + for (i = 0; i < 3; i++) {
34930 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34931 + dentry = au_sio_lkup_one(h_userns, &qs, h_parent);
34932 + if (IS_ERR(dentry) || d_is_negative(dentry))
34936 + /* pr_warn("could not get random name\n"); */
34937 + dentry = ERR_PTR(-EEXIST);
34938 + AuDbg("%.*s\n", AuLNPair(&qs));
34942 + if (name != defname)
34943 + au_kfree_try_rcu(name);
34945 + AuTraceErrPtr(dentry);
34950 + * rename the @h_dentry on @br to the whiteouted temporary name.
34952 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34955 + struct path h_path = {
34956 + .mnt = au_br_mnt(br)
34958 + struct inode *h_dir, *delegated;
34959 + struct dentry *h_parent;
34961 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34962 + h_dir = d_inode(h_parent);
34963 + IMustLock(h_dir);
34965 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34966 + err = PTR_ERR(h_path.dentry);
34967 + if (IS_ERR(h_path.dentry))
34970 + /* under the same dir, no need to lock_rename() */
34971 + delegated = NULL;
34972 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34975 + if (unlikely(err == -EWOULDBLOCK)) {
34976 + pr_warn("cannot retry for NFSv4 delegation"
34977 + " for an internal rename\n");
34980 + dput(h_path.dentry);
34987 +/* ---------------------------------------------------------------------- */
34989 + * functions for removing a whiteout
34992 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34995 + struct inode *delegated;
34998 + * forces superio when the dir has a sticky bit.
34999 + * this may be a violation of unix fs semantics.
35001 + force = (h_dir->i_mode & S_ISVTX)
35002 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35003 + delegated = NULL;
35004 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35005 + if (unlikely(err == -EWOULDBLOCK)) {
35006 + pr_warn("cannot retry for NFSv4 delegation"
35007 + " for an internal unlink\n");
35013 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35014 + struct dentry *dentry)
35018 + err = do_unlink_wh(h_dir, h_path);
35019 + if (!err && dentry)
35020 + au_set_dbwh(dentry, -1);
35025 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35026 + struct au_branch *br)
35029 + struct path h_path = {
35030 + .mnt = au_br_mnt(br)
35034 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35035 + if (IS_ERR(h_path.dentry))
35036 + err = PTR_ERR(h_path.dentry);
35038 + if (d_is_reg(h_path.dentry))
35039 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35040 + dput(h_path.dentry);
35046 +/* ---------------------------------------------------------------------- */
35048 + * initialize/clean whiteout for a branch
35051 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35055 + struct inode *delegated;
35057 + if (d_is_negative(whpath->dentry))
35061 + err = vfsub_rmdir(h_dir, whpath);
35063 + delegated = NULL;
35064 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35065 + if (unlikely(err == -EWOULDBLOCK)) {
35066 + pr_warn("cannot retry for NFSv4 delegation"
35067 + " for an internal unlink\n");
35071 + if (unlikely(err))
35072 + pr_warn("failed removing %pd (%d), ignored.\n",
35073 + whpath->dentry, err);
35076 +static int test_linkable(struct dentry *h_root)
35078 + struct inode *h_dir = d_inode(h_root);
35080 + if (h_dir->i_op->link)
35083 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35084 + h_root, au_sbtype(h_root->d_sb));
35085 + return -ENOSYS; /* the branch doesn't have its ->link() */
35088 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35089 +static int au_whdir(struct inode *h_dir, struct path *path)
35094 + if (d_is_negative(path->dentry)) {
35097 + if (au_test_nfs(path->dentry->d_sb))
35099 + err = vfsub_mkdir(h_dir, path, mode);
35100 + } else if (d_is_dir(path->dentry))
35103 + pr_err("unknown %pd exists\n", path->dentry);
35108 +struct au_wh_base {
35109 + const struct qstr *name;
35110 + struct dentry *dentry;
35113 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35114 + struct path *h_path)
35116 + h_path->dentry = base[AuBrWh_BASE].dentry;
35117 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35118 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35119 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35120 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35121 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35125 + * returns tri-state,
35126 + * minus: error, caller should print the message
35128 + * plus: error, caller should NOT print the message
35130 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35131 + int do_plink, struct au_wh_base base[],
35132 + struct path *h_path)
35135 + struct inode *h_dir;
35137 + h_dir = d_inode(h_root);
35138 + h_path->dentry = base[AuBrWh_BASE].dentry;
35139 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35140 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35142 + err = test_linkable(h_root);
35143 + if (unlikely(err)) {
35148 + err = au_whdir(h_dir, h_path);
35149 + if (unlikely(err))
35151 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35153 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35154 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35155 + err = au_whdir(h_dir, h_path);
35156 + if (unlikely(err))
35158 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35165 + * for the moment, aufs supports the branch filesystem which does not support
35166 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35167 + * copyup failed. finally, such filesystem will not be used as the writable
35170 + * returns tri-state, see above.
35172 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35173 + int do_plink, struct au_wh_base base[],
35174 + struct path *h_path)
35177 + struct inode *h_dir;
35179 + WbrWhMustWriteLock(wbr);
35181 + err = test_linkable(h_root);
35182 + if (unlikely(err)) {
35188 + * todo: should this create be done in /sbin/mount.aufs helper?
35191 + h_dir = d_inode(h_root);
35192 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35193 + h_path->dentry = base[AuBrWh_BASE].dentry;
35194 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35195 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35198 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35199 + if (unlikely(err))
35202 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35204 + err = au_whdir(h_dir, h_path);
35205 + if (unlikely(err))
35207 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35209 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35210 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35212 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35213 + err = au_whdir(h_dir, h_path);
35214 + if (unlikely(err))
35216 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35223 + * initialize the whiteout base file/dir for @br.
35225 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35228 + const unsigned char do_plink
35229 + = !!au_opt_test(au_mntflags(sb), PLINK);
35230 + struct inode *h_dir;
35231 + struct path path = br->br_path;
35232 + struct dentry *h_root = path.dentry;
35233 + struct au_wbr *wbr = br->br_wbr;
35234 + static const struct qstr base_name[] = {
35235 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35236 + sizeof(AUFS_BASE_NAME) - 1),
35237 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35238 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35239 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35240 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35242 + struct au_wh_base base[] = {
35243 + [AuBrWh_BASE] = {
35244 + .name = base_name + AuBrWh_BASE,
35247 + [AuBrWh_PLINK] = {
35248 + .name = base_name + AuBrWh_PLINK,
35251 + [AuBrWh_ORPH] = {
35252 + .name = base_name + AuBrWh_ORPH,
35258 + WbrWhMustWriteLock(wbr);
35260 + for (i = 0; i < AuBrWh_Last; i++) {
35261 + /* doubly whiteouted */
35262 + struct dentry *d;
35264 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35265 + err = PTR_ERR(d);
35269 + base[i].dentry = d;
35271 + && wbr->wbr_wh[i]
35272 + && wbr->wbr_wh[i] != base[i].dentry);
35276 + for (i = 0; i < AuBrWh_Last; i++) {
35277 + dput(wbr->wbr_wh[i]);
35278 + wbr->wbr_wh[i] = NULL;
35282 + if (!au_br_writable(br->br_perm)) {
35283 + h_dir = d_inode(h_root);
35284 + au_wh_init_ro(h_dir, base, &path);
35285 + } else if (!au_br_wh_linkable(br->br_perm)) {
35286 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35292 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35298 + goto out; /* success */
35301 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35302 + err, h_root, au_sbtype(h_root->d_sb));
35304 + for (i = 0; i < AuBrWh_Last; i++)
35305 + dput(base[i].dentry);
35309 +/* ---------------------------------------------------------------------- */
35311 + * whiteouts are all hard-linked usually.
35312 + * when its link count reaches a ceiling, we create a new whiteout base
35313 + * asynchronously.
35316 +struct reinit_br_wh {
35317 + struct super_block *sb;
35318 + struct au_branch *br;
35321 +static void reinit_br_wh(void *arg)
35324 + aufs_bindex_t bindex;
35325 + struct path h_path;
35326 + struct reinit_br_wh *a = arg;
35327 + struct au_wbr *wbr;
35328 + struct inode *dir, *delegated;
35329 + struct dentry *h_root;
35330 + struct au_hinode *hdir;
35333 + wbr = a->br->br_wbr;
35334 + /* big aufs lock */
35335 + si_noflush_write_lock(a->sb);
35336 + if (!au_br_writable(a->br->br_perm))
35338 + bindex = au_br_index(a->sb, a->br->br_id);
35339 + if (unlikely(bindex < 0))
35342 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35343 + dir = d_inode(a->sb->s_root);
35344 + hdir = au_hi(dir, bindex);
35345 + h_root = au_h_dptr(a->sb->s_root, bindex);
35346 + AuDebugOn(h_root != au_br_dentry(a->br));
35348 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35349 + wbr_wh_write_lock(wbr);
35350 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35353 + h_path.dentry = wbr->wbr_whbase;
35354 + h_path.mnt = au_br_mnt(a->br);
35355 + delegated = NULL;
35356 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35358 + if (unlikely(err == -EWOULDBLOCK)) {
35359 + pr_warn("cannot retry for NFSv4 delegation"
35360 + " for an internal unlink\n");
35364 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35367 + dput(wbr->wbr_whbase);
35368 + wbr->wbr_whbase = NULL;
35370 + err = au_wh_init(a->br, a->sb);
35371 + wbr_wh_write_unlock(wbr);
35372 + au_hn_inode_unlock(hdir);
35373 + di_read_unlock(a->sb->s_root, AuLock_IR);
35375 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35379 + atomic_dec(&wbr->wbr_wh_running);
35380 + au_lcnt_dec(&a->br->br_count);
35381 + si_write_unlock(a->sb);
35382 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35384 + if (unlikely(err))
35385 + AuIOErr("err %d\n", err);
35388 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35390 + int do_dec, wkq_err;
35391 + struct reinit_br_wh *arg;
35394 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35397 + /* ignore ENOMEM */
35398 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35401 + * dec(wh_running), kfree(arg) and dec(br_count)
35402 + * in reinit function
35406 + au_lcnt_inc(&br->br_count);
35407 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35408 + if (unlikely(wkq_err)) {
35409 + atomic_dec(&br->br_wbr->wbr_wh_running);
35410 + au_lcnt_dec(&br->br_count);
35411 + au_kfree_rcu(arg);
35418 + atomic_dec(&br->br_wbr->wbr_wh_running);
35421 +/* ---------------------------------------------------------------------- */
35424 + * create the whiteout @wh.
35426 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35427 + struct dentry *wh)
35430 + struct path h_path = {
35433 + struct au_branch *br;
35434 + struct au_wbr *wbr;
35435 + struct dentry *h_parent;
35436 + struct inode *h_dir, *delegated;
35438 + h_parent = wh->d_parent; /* dir inode is locked */
35439 + h_dir = d_inode(h_parent);
35440 + IMustLock(h_dir);
35442 + br = au_sbr(sb, bindex);
35443 + h_path.mnt = au_br_mnt(br);
35444 + wbr = br->br_wbr;
35445 + wbr_wh_read_lock(wbr);
35446 + if (wbr->wbr_whbase) {
35447 + delegated = NULL;
35448 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35449 + if (unlikely(err == -EWOULDBLOCK)) {
35450 + pr_warn("cannot retry for NFSv4 delegation"
35451 + " for an internal link\n");
35454 + if (!err || err != -EMLINK)
35457 + /* link count full. re-initialize br_whbase. */
35458 + kick_reinit_br_wh(sb, br);
35461 + /* return this error in this context */
35462 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35464 + au_fhsm_wrote(sb, bindex, /*force*/0);
35467 + wbr_wh_read_unlock(wbr);
35471 +/* ---------------------------------------------------------------------- */
35474 + * create or remove the diropq.
35476 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35477 + unsigned int flags)
35479 + struct dentry *opq_dentry, *h_dentry;
35480 + struct super_block *sb;
35481 + struct au_branch *br;
35484 + sb = dentry->d_sb;
35485 + br = au_sbr(sb, bindex);
35486 + h_dentry = au_h_dptr(dentry, bindex);
35487 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35488 + if (IS_ERR(opq_dentry))
35491 + if (au_ftest_diropq(flags, CREATE)) {
35492 + err = link_or_create_wh(sb, bindex, opq_dentry);
35494 + au_set_dbdiropq(dentry, bindex);
35495 + goto out; /* success */
35498 + struct path tmp = {
35499 + .dentry = opq_dentry,
35500 + .mnt = au_br_mnt(br)
35502 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35504 + au_set_dbdiropq(dentry, -1);
35506 + dput(opq_dentry);
35507 + opq_dentry = ERR_PTR(err);
35510 + return opq_dentry;
35513 +struct do_diropq_args {
35514 + struct dentry **errp;
35515 + struct dentry *dentry;
35516 + aufs_bindex_t bindex;
35517 + unsigned int flags;
35520 +static void call_do_diropq(void *args)
35522 + struct do_diropq_args *a = args;
35523 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35526 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35527 + unsigned int flags)
35529 + struct dentry *diropq, *h_dentry;
35530 + struct user_namespace *h_userns;
35532 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35533 + h_dentry = au_h_dptr(dentry, bindex);
35534 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35535 + MAY_EXEC | MAY_WRITE))
35536 + diropq = do_diropq(dentry, bindex, flags);
35539 + struct do_diropq_args args = {
35541 + .dentry = dentry,
35542 + .bindex = bindex,
35546 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35547 + if (unlikely(wkq_err))
35548 + diropq = ERR_PTR(wkq_err);
35554 +/* ---------------------------------------------------------------------- */
35557 + * lookup whiteout dentry.
35558 + * @h_parent: lower parent dentry which must exist and be locked
35559 + * @base_name: name of dentry which will be whiteouted
35560 + * returns dentry for whiteout.
35562 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35563 + struct au_branch *br)
35566 + struct qstr wh_name;
35567 + struct dentry *wh_dentry;
35569 + err = au_wh_name_alloc(&wh_name, base_name);
35570 + wh_dentry = ERR_PTR(err);
35572 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35573 + au_kfree_try_rcu(wh_name.name);
35575 + return wh_dentry;
35579 + * link/create a whiteout for @dentry on @bindex.
35581 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35582 + struct dentry *h_parent)
35584 + struct dentry *wh_dentry;
35585 + struct super_block *sb;
35588 + sb = dentry->d_sb;
35589 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35590 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35591 + err = link_or_create_wh(sb, bindex, wh_dentry);
35593 + au_set_dbwh(dentry, bindex);
35594 + au_fhsm_wrote(sb, bindex, /*force*/0);
35597 + wh_dentry = ERR_PTR(err);
35601 + return wh_dentry;
35604 +/* ---------------------------------------------------------------------- */
35606 +/* Delete all whiteouts in this directory on branch bindex. */
35607 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35608 + aufs_bindex_t bindex, struct au_branch *br)
35611 + unsigned long ul, n;
35612 + struct qstr wh_name;
35614 + struct hlist_head *head;
35615 + struct au_vdir_wh *pos;
35616 + struct au_vdir_destr *str;
35619 + p = (void *)__get_free_page(GFP_NOFS);
35620 + wh_name.name = p;
35621 + if (unlikely(!wh_name.name))
35625 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35626 + p += AUFS_WH_PFX_LEN;
35627 + n = whlist->nh_num;
35628 + head = whlist->nh_head;
35629 + for (ul = 0; !err && ul < n; ul++, head++) {
35630 + hlist_for_each_entry(pos, head, wh_hash) {
35631 + if (pos->wh_bindex != bindex)
35634 + str = &pos->wh_str;
35635 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35636 + memcpy(p, str->name, str->len);
35637 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35638 + err = unlink_wh_name(h_dentry, &wh_name, br);
35643 + AuIOErr("whiteout name too long %.*s\n",
35644 + str->len, str->name);
35649 + free_page((unsigned long)wh_name.name);
35655 +struct del_wh_children_args {
35657 + struct dentry *h_dentry;
35658 + struct au_nhash *whlist;
35659 + aufs_bindex_t bindex;
35660 + struct au_branch *br;
35663 +static void call_del_wh_children(void *args)
35665 + struct del_wh_children_args *a = args;
35666 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35669 +/* ---------------------------------------------------------------------- */
35671 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35673 + struct au_whtmp_rmdir *whtmp;
35675 + unsigned int rdhash;
35677 + SiMustAnyLock(sb);
35679 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35680 + if (unlikely(!whtmp)) {
35681 + whtmp = ERR_PTR(-ENOMEM);
35685 + /* no estimation for dir size */
35686 + rdhash = au_sbi(sb)->si_rdhash;
35688 + rdhash = AUFS_RDHASH_DEF;
35689 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35690 + if (unlikely(err)) {
35691 + au_kfree_rcu(whtmp);
35692 + whtmp = ERR_PTR(err);
35699 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35702 + au_lcnt_dec(&whtmp->br->br_count);
35703 + dput(whtmp->wh_dentry);
35704 + iput(whtmp->dir);
35705 + au_nhash_wh_free(&whtmp->whlist);
35706 + au_kfree_rcu(whtmp);
35710 + * rmdir the whiteouted temporary named dir @h_dentry.
35711 + * @whlist: whiteouted children.
35713 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35714 + struct dentry *wh_dentry, struct au_nhash *whlist)
35717 + unsigned int h_nlink;
35718 + struct path h_tmp;
35719 + struct inode *wh_inode, *h_dir;
35720 + struct au_branch *br;
35721 + struct user_namespace *h_userns;
35723 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35724 + IMustLock(h_dir);
35726 + br = au_sbr(dir->i_sb, bindex);
35727 + h_userns = au_br_userns(br);
35728 + wh_inode = d_inode(wh_dentry);
35729 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35732 + * someone else might change some whiteouts while we were sleeping.
35733 + * it means this whlist may have an obsoleted entry.
35735 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35736 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35739 + struct del_wh_children_args args = {
35741 + .h_dentry = wh_dentry,
35742 + .whlist = whlist,
35743 + .bindex = bindex,
35747 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35748 + if (unlikely(wkq_err))
35751 + inode_unlock(wh_inode);
35754 + h_tmp.dentry = wh_dentry;
35755 + h_tmp.mnt = au_br_mnt(br);
35756 + h_nlink = h_dir->i_nlink;
35757 + err = vfsub_rmdir(h_dir, &h_tmp);
35758 + /* some fs doesn't change the parent nlink in some cases */
35759 + h_nlink -= h_dir->i_nlink;
35763 + if (au_ibtop(dir) == bindex) {
35764 + /* todo: dir->i_mutex is necessary */
35765 + au_cpup_attr_timesizes(dir);
35767 + vfsub_drop_nlink(dir);
35769 + return 0; /* success */
35772 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35776 +static void call_rmdir_whtmp(void *args)
35779 + aufs_bindex_t bindex;
35780 + struct au_whtmp_rmdir *a = args;
35781 + struct super_block *sb;
35782 + struct dentry *h_parent;
35783 + struct inode *h_dir;
35784 + struct au_hinode *hdir;
35786 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35787 + /* inode_lock(a->dir); */
35789 + sb = a->dir->i_sb;
35790 + si_read_lock(sb, !AuLock_FLUSH);
35791 + if (!au_br_writable(a->br->br_perm))
35793 + bindex = au_br_index(sb, a->br->br_id);
35794 + if (unlikely(bindex < 0))
35798 + ii_write_lock_parent(a->dir);
35799 + h_parent = dget_parent(a->wh_dentry);
35800 + h_dir = d_inode(h_parent);
35801 + hdir = au_hi(a->dir, bindex);
35802 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35803 + if (unlikely(err))
35805 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35806 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35809 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35810 + au_hn_inode_unlock(hdir);
35811 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35815 + ii_write_unlock(a->dir);
35817 + /* inode_unlock(a->dir); */
35818 + au_whtmp_rmdir_free(a);
35819 + si_read_unlock(sb);
35820 + au_nwt_done(&au_sbi(sb)->si_nowait);
35821 + if (unlikely(err))
35822 + AuIOErr("err %d\n", err);
35825 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35826 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35829 + struct super_block *sb;
35833 + /* all post-process will be done in do_rmdir_whtmp(). */
35835 + args->dir = au_igrab(dir);
35836 + args->br = au_sbr(sb, bindex);
35837 + au_lcnt_inc(&args->br->br_count);
35838 + args->wh_dentry = dget(wh_dentry);
35839 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35840 + if (unlikely(wkq_err)) {
35841 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35842 + au_whtmp_rmdir_free(args);
35845 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35846 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35847 +++ linux/fs/aufs/whout.h 2021-05-02 20:15:14.676670793 +0200
35849 +/* SPDX-License-Identifier: GPL-2.0 */
35851 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35853 + * This program, aufs is free software; you can redistribute it and/or modify
35854 + * it under the terms of the GNU General Public License as published by
35855 + * the Free Software Foundation; either version 2 of the License, or
35856 + * (at your option) any later version.
35858 + * This program is distributed in the hope that it will be useful,
35859 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35860 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35861 + * GNU General Public License for more details.
35863 + * You should have received a copy of the GNU General Public License
35864 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35868 + * whiteout for logical deletion and opaque directory
35871 +#ifndef __AUFS_WHOUT_H__
35872 +#define __AUFS_WHOUT_H__
35879 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35880 +int au_wh_test(struct user_namespace *h_userns, struct dentry *h_parent,
35881 + struct qstr *wh_name, int try_sio);
35882 +int au_diropq_test(struct user_namespace *h_userns, struct dentry *h_dentry);
35884 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35885 + struct qstr *prefix);
35886 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35887 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35888 + struct dentry *dentry);
35889 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35891 +/* diropq flags */
35892 +#define AuDiropq_CREATE 1
35893 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35894 +#define au_fset_diropq(flags, name) \
35895 + do { (flags) |= AuDiropq_##name; } while (0)
35896 +#define au_fclr_diropq(flags, name) \
35897 + do { (flags) &= ~AuDiropq_##name; } while (0)
35899 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35900 + unsigned int flags);
35901 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35902 + struct au_branch *br);
35903 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35904 + struct dentry *h_parent);
35906 +/* real rmdir for the whiteout-ed dir */
35907 +struct au_whtmp_rmdir {
35908 + struct inode *dir;
35909 + struct au_branch *br;
35910 + struct dentry *wh_dentry;
35911 + struct au_nhash whlist;
35914 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35915 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35916 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35917 + struct dentry *wh_dentry, struct au_nhash *whlist);
35918 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35919 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35921 +/* ---------------------------------------------------------------------- */
35923 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35924 + aufs_bindex_t bindex)
35926 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35929 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35931 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35934 +#endif /* __KERNEL__ */
35935 +#endif /* __AUFS_WHOUT_H__ */
35936 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35937 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35938 +++ linux/fs/aufs/wkq.c 2021-05-02 20:15:14.676670793 +0200
35940 +// SPDX-License-Identifier: GPL-2.0
35942 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35944 + * This program, aufs is free software; you can redistribute it and/or modify
35945 + * it under the terms of the GNU General Public License as published by
35946 + * the Free Software Foundation; either version 2 of the License, or
35947 + * (at your option) any later version.
35949 + * This program is distributed in the hope that it will be useful,
35950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35952 + * GNU General Public License for more details.
35954 + * You should have received a copy of the GNU General Public License
35955 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35959 + * workqueue for asynchronous/super-io operations
35960 + * todo: try new credential scheme
35963 +#include <linux/module.h>
35966 +/* internal workqueue named AUFS_WKQ_NAME */
35968 +static struct workqueue_struct *au_wkq;
35970 +struct au_wkinfo {
35971 + struct work_struct wk;
35972 + struct kobject *kobj;
35974 + unsigned int flags; /* see wkq.h */
35976 + au_wkq_func_t func;
35979 +#ifdef CONFIG_LOCKDEP
35981 + struct held_lock **hlock;
35984 + struct completion *comp;
35987 +/* ---------------------------------------------------------------------- */
35989 + * Aufs passes some operations to the workqueue such as the internal copyup.
35990 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35991 + * job run by workqueue depends upon the locks acquired in the other task.
35992 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35993 + * information too. And the job in the workqueue restores the info in order to
35994 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35995 + * correctly and expectedly.
35998 +#ifndef CONFIG_LOCKDEP
35999 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36000 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36001 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36002 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36003 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36005 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36007 + wkinfo->hlock = NULL;
36008 + wkinfo->dont_check = 0;
36015 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36017 + static DEFINE_SPINLOCK(spin);
36020 + struct lock_class_key *key;
36022 + { .name = "&sbinfo->si_rwsem" },
36023 + { .name = "&finfo->fi_rwsem" },
36024 + { .name = "&dinfo->di_rwsem" },
36025 + { .name = "&iinfo->ii_rwsem" }
36030 + /* lockless read from 'set.' see below */
36031 + if (set == ARRAY_SIZE(a)) {
36032 + for (i = 0; i < ARRAY_SIZE(a); i++)
36033 + if (a[i].key == key)
36038 + spin_lock(&spin);
36040 + for (i = 0; i < ARRAY_SIZE(a); i++)
36041 + if (a[i].key == key) {
36042 + spin_unlock(&spin);
36045 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36047 + if (unlikely(a[i].key == key)) { /* rare but possible */
36048 + spin_unlock(&spin);
36053 + if (strstr(a[i].name, name)) {
36055 + * the order of these three lines is important for the
36056 + * lockless read above.
36059 + spin_unlock(&spin);
36061 + /* AuDbg("%d, %s\n", set, name); */
36065 + spin_unlock(&spin);
36074 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36077 + struct task_struct *curr;
36078 + struct held_lock **hl, *held_locks, *p;
36082 + wkinfo->dont_check = lockdep_recursing(curr);
36083 + if (wkinfo->dont_check)
36085 + n = curr->lockdep_depth;
36090 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36091 + if (unlikely(!wkinfo->hlock))
36095 +#if 0 /* left for debugging */
36096 + if (0 && au_debug_test())
36097 + lockdep_print_held_locks(curr);
36099 + held_locks = curr->held_locks;
36100 + hl = wkinfo->hlock;
36102 + p = held_locks++;
36103 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36112 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36114 + au_kfree_try_rcu(wkinfo->hlock);
36117 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36119 + struct held_lock *p, **hl = wkinfo->hlock;
36122 + if (wkinfo->dont_check)
36126 + while ((p = *hl++)) { /* assignment */
36127 + subclass = lockdep_hlock_class(p)->subclass;
36128 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36130 + rwsem_acquire_read(p->instance, subclass, 0,
36131 + /*p->acquire_ip*/_RET_IP_);
36133 + rwsem_acquire(p->instance, subclass, 0,
36134 + /*p->acquire_ip*/_RET_IP_);
36138 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36140 + struct held_lock *p, **hl = wkinfo->hlock;
36142 + if (wkinfo->dont_check)
36146 + while ((p = *hl++)) /* assignment */
36147 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36151 +static void wkq_func(struct work_struct *wk)
36153 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36155 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36156 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36158 + au_wkq_lockdep_pre(wkinfo);
36159 + wkinfo->func(wkinfo->args);
36160 + au_wkq_lockdep_post(wkinfo);
36161 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36162 + complete(wkinfo->comp);
36164 + kobject_put(wkinfo->kobj);
36165 + module_put(THIS_MODULE); /* todo: ?? */
36166 + au_kfree_rcu(wkinfo);
36171 + * Since struct completion is large, try allocating it dynamically.
36173 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36175 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36177 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36179 + init_completion(*comp);
36180 + wkinfo->comp = *comp;
36186 +static void au_wkq_comp_free(struct completion *comp)
36188 + au_kfree_rcu(comp);
36191 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36193 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36194 + if (au_wkq_test()) {
36195 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36196 + " due to a dead dir by UDBA,"
36197 + " or async xino write?\n");
36198 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36201 + au_dbg_verify_kthread();
36203 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36204 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36205 + queue_work(au_wkq, &wkinfo->wk);
36207 + INIT_WORK(&wkinfo->wk, wkq_func);
36208 + schedule_work(&wkinfo->wk);
36213 + * Be careful. It is easy to make deadlock happen.
36214 + * processA: lock, wkq and wait
36215 + * processB: wkq and wait, lock in wkq
36218 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36221 + AuWkqCompDeclare(comp);
36222 + struct au_wkinfo wkinfo = {
36228 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36229 + if (unlikely(err))
36231 + err = au_wkq_lockdep_alloc(&wkinfo);
36232 + if (unlikely(err))
36235 + au_wkq_run(&wkinfo);
36236 + /* no timeout, no interrupt */
36237 + wait_for_completion(wkinfo.comp);
36239 + au_wkq_lockdep_free(&wkinfo);
36242 + au_wkq_comp_free(comp);
36244 + destroy_work_on_stack(&wkinfo.wk);
36249 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36250 + * problem in a concurrent umounting.
36252 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36253 + unsigned int flags)
36256 + struct au_wkinfo *wkinfo;
36258 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36261 + * wkq_func() must free this wkinfo.
36262 + * it highly depends upon the implementation of workqueue.
36265 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36267 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36268 + wkinfo->flags = flags & ~AuWkq_WAIT;
36269 + wkinfo->func = func;
36270 + wkinfo->args = args;
36271 + wkinfo->comp = NULL;
36272 + au_wkq_lockdep_init(wkinfo);
36273 + kobject_get(wkinfo->kobj);
36274 + __module_get(THIS_MODULE); /* todo: ?? */
36276 + au_wkq_run(wkinfo);
36279 + au_nwt_done(&au_sbi(sb)->si_nowait);
36285 +/* ---------------------------------------------------------------------- */
36287 +void au_nwt_init(struct au_nowait_tasks *nwt)
36289 + atomic_set(&nwt->nw_len, 0);
36290 + /* smp_mb(); */ /* atomic_set */
36291 + init_waitqueue_head(&nwt->nw_wq);
36294 +void au_wkq_fin(void)
36296 + destroy_workqueue(au_wkq);
36299 +int __init au_wkq_init(void)
36304 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36305 + if (IS_ERR(au_wkq))
36306 + err = PTR_ERR(au_wkq);
36307 + else if (!au_wkq)
36312 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36313 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36314 +++ linux/fs/aufs/wkq.h 2021-05-02 20:15:14.676670793 +0200
36316 +/* SPDX-License-Identifier: GPL-2.0 */
36318 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36320 + * This program, aufs is free software; you can redistribute it and/or modify
36321 + * it under the terms of the GNU General Public License as published by
36322 + * the Free Software Foundation; either version 2 of the License, or
36323 + * (at your option) any later version.
36325 + * This program is distributed in the hope that it will be useful,
36326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36328 + * GNU General Public License for more details.
36330 + * You should have received a copy of the GNU General Public License
36331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36335 + * workqueue for asynchronous/super-io operations
36336 + * todo: try new credentials management scheme
36339 +#ifndef __AUFS_WKQ_H__
36340 +#define __AUFS_WKQ_H__
36344 +#include <linux/wait.h>
36346 +struct super_block;
36348 +/* ---------------------------------------------------------------------- */
36351 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36353 +struct au_nowait_tasks {
36355 + wait_queue_head_t nw_wq;
36358 +/* ---------------------------------------------------------------------- */
36360 +typedef void (*au_wkq_func_t)(void *args);
36363 +#define AuWkq_WAIT 1
36364 +#define AuWkq_NEST (1 << 1)
36365 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36366 +#define au_fset_wkq(flags, name) \
36367 + do { (flags) |= AuWkq_##name; } while (0)
36368 +#define au_fclr_wkq(flags, name) \
36369 + do { (flags) &= ~AuWkq_##name; } while (0)
36372 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36373 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36374 + unsigned int flags);
36375 +void au_nwt_init(struct au_nowait_tasks *nwt);
36376 +int __init au_wkq_init(void);
36377 +void au_wkq_fin(void);
36379 +/* ---------------------------------------------------------------------- */
36381 +static inline int au_wkq_test(void)
36383 + return current->flags & PF_WQ_WORKER;
36386 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36388 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36391 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36393 + if (atomic_dec_and_test(&nwt->nw_len))
36394 + wake_up_all(&nwt->nw_wq);
36397 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36399 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36403 +#endif /* __KERNEL__ */
36404 +#endif /* __AUFS_WKQ_H__ */
36405 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36406 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36407 +++ linux/fs/aufs/xattr.c 2021-05-02 20:15:14.676670793 +0200
36409 +// SPDX-License-Identifier: GPL-2.0
36411 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36413 + * This program, aufs is free software; you can redistribute it and/or modify
36414 + * it under the terms of the GNU General Public License as published by
36415 + * the Free Software Foundation; either version 2 of the License, or
36416 + * (at your option) any later version.
36418 + * This program is distributed in the hope that it will be useful,
36419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36421 + * GNU General Public License for more details.
36423 + * You should have received a copy of the GNU General Public License
36424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36428 + * handling xattr functions
36431 +#include <linux/fs.h>
36432 +#include <linux/posix_acl_xattr.h>
36433 +#include <linux/xattr.h>
36436 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36438 + if (!ignore_flags)
36446 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36451 +#define cmp(brattr, prefix) do { \
36452 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36453 + XATTR_##prefix##_PREFIX_LEN)) { \
36454 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36460 + cmp(SEC, SECURITY);
36461 + cmp(SYS, SYSTEM);
36462 + cmp(TR, TRUSTED);
36466 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36473 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36475 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36476 + char *name, char **buf, unsigned int ignore_flags,
36477 + unsigned int verbose)
36481 + struct inode *h_idst;
36482 + struct dentry *h_dst_dentry, *h_src_dentry;
36483 + struct user_namespace *h_dst_userns, *h_src_userns;
36485 + h_src_userns = mnt_user_ns(h_src->mnt);
36486 + h_src_dentry = h_src->dentry;
36487 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36490 + if (unlikely(err <= 0)) {
36491 + if (err == -ENODATA
36492 + || (err == -EOPNOTSUPP
36493 + && ((ignore_flags & au_xattr_out_of_list)
36494 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36495 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36497 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36500 + if (err && (verbose || au_debug_test()))
36501 + pr_err("%s, err %d\n", name, err);
36505 + /* unlock it temporary */
36506 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36507 + h_dst_dentry = h_dst->dentry;
36508 + h_idst = d_inode(h_dst_dentry);
36509 + inode_unlock(h_idst);
36510 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36512 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36513 + if (unlikely(err)) {
36514 + if (verbose || au_debug_test())
36515 + pr_err("%s, err %d\n", name, err);
36516 + err = au_xattr_ignore(err, name, ignore_flags);
36523 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36524 + unsigned int verbose)
36526 + int err, unlocked, acl_access, acl_default;
36528 + struct dentry *h_dst_dentry, *h_src_dentry;
36529 + struct inode *h_isrc, *h_idst;
36530 + char *value, *p, *o, *e;
36532 + /* try stopping to update the source inode while we are referencing */
36533 + /* there should not be the parent-child relationship between them */
36534 + h_dst_dentry = h_dst->dentry;
36535 + h_idst = d_inode(h_dst_dentry);
36536 + h_src_dentry = h_src->dentry;
36537 + h_isrc = d_inode(h_src_dentry);
36538 + inode_unlock(h_idst);
36539 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36540 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36543 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36544 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36546 + if (unlikely(err < 0)) {
36548 + if (err == -ENODATA
36549 + || err == -EOPNOTSUPP)
36550 + err = 0; /* ignore */
36559 + p = kmalloc(ssz, GFP_NOFS);
36561 + if (unlikely(!p))
36563 + err = vfs_listxattr(h_src_dentry, p, ssz);
36565 + inode_unlock_shared(h_isrc);
36567 + AuDbg("err %d, ssz %zd\n", err, ssz);
36568 + if (unlikely(err < 0))
36576 + while (!err && p < e) {
36577 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36578 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36579 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36580 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36582 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36584 + p += strlen(p) + 1;
36587 + ignore_flags |= au_xattr_out_of_list;
36588 + if (!err && !acl_access) {
36589 + err = au_do_cpup_xattr(h_dst, h_src,
36590 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36591 + ignore_flags, verbose);
36594 + if (!err && !acl_default) {
36595 + err = au_do_cpup_xattr(h_dst, h_src,
36596 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36597 + ignore_flags, verbose);
36601 + au_kfree_try_rcu(value);
36604 + au_kfree_try_rcu(o);
36607 + inode_unlock_shared(h_isrc);
36612 +/* ---------------------------------------------------------------------- */
36614 +static int au_smack_reentering(struct super_block *sb)
36616 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36618 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36619 + * i_op->getxattr(). ouch.
36621 + return si_pid_test(sb);
36632 +struct au_lgxattr {
36640 + const char *name;
36647 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36648 + struct au_lgxattr *arg)
36652 + struct path h_path;
36653 + struct super_block *sb;
36655 + sb = dentry->d_sb;
36656 + reenter = au_smack_reentering(sb);
36658 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36659 + if (unlikely(err))
36662 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36663 + if (unlikely(err))
36665 + if (unlikely(!h_path.dentry))
36666 + /* illegally overlapped or something */
36667 + goto out_di; /* pretending success */
36669 + /* always topmost entry only */
36670 + switch (arg->type) {
36671 + case AU_XATTR_LIST:
36672 + err = vfs_listxattr(h_path.dentry,
36673 + arg->u.list.list, arg->u.list.size);
36675 + case AU_XATTR_GET:
36676 + AuDebugOn(d_is_negative(h_path.dentry));
36677 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36678 + arg->u.get.name, arg->u.get.value,
36679 + arg->u.get.size);
36685 + di_read_unlock(dentry, AuLock_IR);
36688 + si_read_unlock(sb);
36694 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36696 + struct au_lgxattr arg = {
36697 + .type = AU_XATTR_LIST,
36704 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36707 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36708 + const char *name, void *value, size_t size)
36710 + struct au_lgxattr arg = {
36711 + .type = AU_XATTR_GET,
36719 + return au_lgxattr(dentry, inode, &arg);
36722 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36723 + const char *name, const void *value, size_t size,
36726 + struct au_sxattr arg = {
36727 + .type = AU_XATTR_SET,
36736 + return au_sxattr(dentry, inode, &arg);
36739 +/* ---------------------------------------------------------------------- */
36741 +static int au_xattr_get(const struct xattr_handler *handler,
36742 + struct dentry *dentry, struct inode *inode,
36743 + const char *name, void *buffer, size_t size)
36745 + return au_getxattr(dentry, inode, name, buffer, size);
36748 +static int au_xattr_set(const struct xattr_handler *handler,
36749 + struct user_namespace *userns,
36750 + struct dentry *dentry, struct inode *inode,
36751 + const char *name, const void *value, size_t size,
36754 + return au_setxattr(dentry, inode, name, value, size, flags);
36757 +static const struct xattr_handler au_xattr_handler = {
36760 + .get = au_xattr_get,
36761 + .set = au_xattr_set
36764 +static const struct xattr_handler *au_xattr_handlers[] = {
36765 +#ifdef CONFIG_FS_POSIX_ACL
36766 + &posix_acl_access_xattr_handler,
36767 + &posix_acl_default_xattr_handler,
36769 + &au_xattr_handler, /* must be last */
36773 +void au_xattr_init(struct super_block *sb)
36775 + sb->s_xattr = au_xattr_handlers;
36777 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36778 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36779 +++ linux/fs/aufs/xino.c 2021-05-02 20:15:14.676670793 +0200
36781 +// SPDX-License-Identifier: GPL-2.0
36783 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36785 + * This program, aufs is free software; you can redistribute it and/or modify
36786 + * it under the terms of the GNU General Public License as published by
36787 + * the Free Software Foundation; either version 2 of the License, or
36788 + * (at your option) any later version.
36790 + * This program is distributed in the hope that it will be useful,
36791 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36792 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36793 + * GNU General Public License for more details.
36795 + * You should have received a copy of the GNU General Public License
36796 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36800 + * external inode number translation table and bitmap
36802 + * things to consider
36804 + * + au_xino object
36805 + * + XINO files (xino, xib, xigen)
36806 + * + dynamic debugfs entries (xiN)
36807 + * + static debugfs entries (xib, xigen)
36808 + * + static sysfs entry (xi_path)
36809 + * - several entry points to handle them.
36810 + * + mount(2) without xino option (default)
36811 + * + mount(2) with xino option
36812 + * + mount(2) with noxino option
36814 + * + remount with add/del branches
36815 + * + remount with xino/noxino options
36818 +#include <linux/seq_file.h>
36819 +#include <linux/statfs.h>
36822 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36823 + aufs_bindex_t bbot,
36824 + struct super_block *h_sb)
36826 + /* todo: try binary-search if the branches are many */
36827 + for (; btop <= bbot; btop++)
36828 + if (h_sb == au_sbr_sb(sb, btop))
36834 + * find another branch who is on the same filesystem of the specified
36835 + * branch{@btgt}. search until @bbot.
36837 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36838 + aufs_bindex_t bbot)
36840 + aufs_bindex_t bindex;
36841 + struct super_block *tgt_sb;
36843 + tgt_sb = au_sbr_sb(sb, btgt);
36844 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36846 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36851 +/* ---------------------------------------------------------------------- */
36854 + * stop unnecessary notify events at creating xino files
36857 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36859 + aufs_bindex_t bfound, bindex, bbot;
36860 + struct dentry *parent;
36861 + struct au_branch *br;
36864 + parent = dentry->d_parent; /* safe d_parent access */
36865 + bbot = au_sbbot(sb);
36866 + for (bindex = 0; bindex <= bbot; bindex++) {
36867 + br = au_sbr(sb, bindex);
36868 + if (au_br_dentry(br) == parent) {
36874 + AuDbg("bfound b%d\n", bfound);
36878 +struct au_xino_lock_dir {
36879 + struct au_hinode *hdir;
36880 + struct dentry *parent;
36881 + struct inode *dir;
36884 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36885 + unsigned int lsc)
36887 + struct dentry *parent;
36888 + struct inode *dir;
36890 + parent = dget_parent(dentry);
36891 + dir = d_inode(parent);
36892 + inode_lock_nested(dir, lsc);
36893 +#if 0 /* it should not happen */
36894 + spin_lock(&dentry->d_lock);
36895 + if (unlikely(dentry->d_parent != parent)) {
36896 + spin_unlock(&dentry->d_lock);
36897 + inode_unlock(dir);
36902 + spin_unlock(&dentry->d_lock);
36909 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36910 + struct au_xino_lock_dir *ldir)
36912 + aufs_bindex_t bindex;
36914 + ldir->hdir = NULL;
36915 + bindex = au_xi_root(sb, xipath->dentry);
36916 + if (bindex >= 0) {
36917 + /* rw branch root */
36918 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36919 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36922 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36924 + ldir->dir = d_inode(ldir->parent);
36928 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36931 + au_hn_inode_unlock(ldir->hdir);
36933 + inode_unlock(ldir->dir);
36934 + dput(ldir->parent);
36938 +/* ---------------------------------------------------------------------- */
36941 + * create and set a new xino file
36943 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36946 + struct file *file;
36947 + struct dentry *h_parent, *d;
36948 + struct inode *h_dir, *inode;
36950 + static DEFINE_MUTEX(mtx);
36953 + * at mount-time, and the xino file is the default path,
36954 + * hnotify is disabled so we have no notify events to ignore.
36955 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36958 + mutex_lock(&mtx);
36959 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36960 + /* | __FMODE_NONOTIFY */,
36962 + if (IS_ERR(file)) {
36964 + mutex_unlock(&mtx);
36966 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36970 + /* keep file count */
36972 + d = file->f_path.dentry;
36973 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36975 + mutex_unlock(&mtx);
36976 + /* mnt_want_write() is unnecessary here */
36977 + h_dir = d_inode(h_parent);
36978 + inode = file_inode(file);
36979 + /* no delegation since it is just created */
36980 + if (inode->i_nlink)
36981 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36983 + inode_unlock(h_dir);
36985 + if (unlikely(err)) {
36987 + pr_err("unlink %s(%d)\n", fpath, err);
36992 + if (unlikely(sb == d->d_sb)) {
36994 + pr_err("%s must be outside\n", fpath);
36997 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36999 + pr_err("xino doesn't support %s(%s)\n",
37000 + fpath, au_sbtype(d->d_sb));
37003 + return file; /* success */
37007 + file = ERR_PTR(err);
37012 + * create a new xinofile at the same place/path as @base.
37014 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37015 + struct file *copy_src)
37017 + struct file *file;
37018 + struct dentry *dentry, *parent;
37019 + struct inode *dir, *delegated;
37020 + struct qstr *name;
37021 + struct path path;
37022 + int err, do_unlock;
37023 + struct au_xino_lock_dir ldir;
37026 + au_xino_lock_dir(sb, base, &ldir);
37027 + dentry = base->dentry;
37028 + parent = dentry->d_parent; /* dir inode is locked */
37029 + dir = d_inode(parent);
37032 + name = &dentry->d_name;
37033 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37034 + if (IS_ERR(path.dentry)) {
37035 + file = (void *)path.dentry;
37036 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37040 + /* no need to mnt_want_write() since we call dentry_open() later */
37041 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37042 + if (unlikely(err)) {
37043 + file = ERR_PTR(err);
37044 + pr_err("%pd create err %d\n", dentry, err);
37048 + path.mnt = base->mnt;
37049 + file = vfsub_dentry_open(&path,
37050 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37051 + /* | __FMODE_NONOTIFY */);
37052 + if (IS_ERR(file)) {
37053 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37057 + delegated = NULL;
37058 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37059 + au_xino_unlock_dir(&ldir);
37061 + if (unlikely(err == -EWOULDBLOCK)) {
37062 + pr_warn("cannot retry for NFSv4 delegation"
37063 + " for an internal unlink\n");
37066 + if (unlikely(err)) {
37067 + pr_err("%pd unlink err %d\n", dentry, err);
37072 + /* no one can touch copy_src xino */
37073 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37074 + if (unlikely(err)) {
37075 + pr_err("%pd copy err %d\n", dentry, err);
37079 + goto out_dput; /* success */
37083 + file = ERR_PTR(err);
37085 + dput(path.dentry);
37088 + au_xino_unlock_dir(&ldir);
37092 +struct file *au_xino_file1(struct au_xino *xi)
37094 + struct file *file;
37095 + unsigned int u, nfile;
37098 + nfile = xi->xi_nfile;
37099 + for (u = 0; u < nfile; u++) {
37100 + file = xi->xi_file[u];
37108 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37119 + if (idx < xi->xi_nfile) {
37120 + f = xi->xi_file[idx];
37124 + p = au_kzrealloc(xi->xi_file,
37125 + sizeof(*xi->xi_file) * xi->xi_nfile,
37126 + sizeof(*xi->xi_file) * (idx + 1),
37127 + GFP_NOFS, /*may_shrink*/0);
37129 + MtxMustLock(&xi->xi_mtx);
37131 + xi->xi_nfile = idx + 1;
37139 + xi->xi_file[idx] = file;
37146 + * if @xinew->xi is not set, then create new xigen file.
37148 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37150 + struct file *file;
37153 + SiMustAnyLock(sb);
37155 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37156 + if (IS_ERR(file)) {
37157 + err = PTR_ERR(file);
37158 + pr_err("%s[%d], err %d\n",
37159 + xinew->xi ? "xino" : "xigen",
37160 + xinew->idx, err);
37165 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37168 + /* todo: make xigen file an array */
37169 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37172 + if (unlikely(err))
37173 + file = ERR_PTR(err);
37179 +/* ---------------------------------------------------------------------- */
37182 + * truncate xino files
37184 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37185 + int idx, struct kstatfs *st)
37189 + struct file *file, *new_xino;
37190 + struct au_xi_new xinew = {
37195 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37196 + file = au_xino_file(xinew.xi, idx);
37200 + xinew.base = &file->f_path;
37201 + err = vfs_statfs(xinew.base, st);
37202 + if (unlikely(err)) {
37203 + AuErr1("statfs err %d, ignored\n", err);
37208 + blocks = file_inode(file)->i_blocks;
37209 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37210 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37212 + xinew.copy_src = file;
37213 + new_xino = au_xi_new(sb, &xinew);
37214 + if (IS_ERR(new_xino)) {
37215 + err = PTR_ERR(new_xino);
37216 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37220 + err = vfs_statfs(&new_xino->f_path, st);
37222 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37223 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37224 + st->f_bfree, st->f_blocks);
37226 + AuErr1("statfs err %d, ignored\n", err);
37234 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37237 + unsigned long jiffy;
37238 + aufs_bindex_t bbot;
37239 + struct kstatfs *st;
37240 + struct au_branch *br;
37241 + struct au_xino *xi;
37244 + st = kmalloc(sizeof(*st), GFP_NOFS);
37245 + if (unlikely(!st))
37249 + bbot = au_sbbot(sb);
37250 + if (unlikely(bindex < 0 || bbot < bindex))
37255 + br = au_sbr(sb, bindex);
37256 + xi = br->br_xino;
37257 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37258 + err = au_xino_do_trunc(sb, bindex, i, st);
37260 + au_sbi(sb)->si_xino_jiffy = jiffy;
37263 + au_kfree_rcu(st);
37268 +struct xino_do_trunc_args {
37269 + struct super_block *sb;
37270 + struct au_branch *br;
37274 +static void xino_do_trunc(void *_args)
37276 + struct xino_do_trunc_args *args = _args;
37277 + struct super_block *sb;
37278 + struct au_branch *br;
37279 + struct inode *dir;
37281 + aufs_bindex_t bindex;
37285 + dir = d_inode(sb->s_root);
37289 + si_noflush_write_lock(sb);
37290 + ii_read_lock_parent(dir);
37291 + bindex = au_br_index(sb, br->br_id);
37292 + err = au_xino_trunc(sb, bindex, idx);
37293 + ii_read_unlock(dir);
37294 + if (unlikely(err))
37295 + pr_warn("err b%d, (%d)\n", bindex, err);
37296 + atomic_dec(&br->br_xino->xi_truncating);
37297 + au_lcnt_dec(&br->br_count);
37298 + si_write_unlock(sb);
37299 + au_nwt_done(&au_sbi(sb)->si_nowait);
37300 + au_kfree_rcu(args);
37304 + * returns the index in the xi_file array whose corresponding file is necessary
37305 + * to truncate, or -1 which means no need to truncate.
37307 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37311 + struct kstatfs st;
37312 + struct au_sbinfo *sbinfo;
37313 + struct au_xino *xi;
37314 + struct file *file;
37316 + /* todo: si_xino_expire and the ratio should be customizable */
37317 + sbinfo = au_sbi(sb);
37318 + if (time_before(jiffies,
37319 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37322 + /* truncation border */
37323 + xi = br->br_xino;
37324 + for (u = 0; u < xi->xi_nfile; u++) {
37325 + file = au_xino_file(xi, u);
37329 + err = vfs_statfs(&file->f_path, &st);
37330 + if (unlikely(err)) {
37331 + AuErr1("statfs err %d, ignored\n", err);
37334 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37335 + >= AUFS_XINO_DEF_TRUNC)
37342 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37345 + struct xino_do_trunc_args *args;
37348 + idx = xino_trunc_test(sb, br);
37352 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37355 + /* lock and kfree() will be called in trunc_xino() */
37356 + args = kmalloc(sizeof(*args), GFP_NOFS);
37357 + if (unlikely(!args)) {
37358 + AuErr1("no memory\n");
37362 + au_lcnt_inc(&br->br_count);
37366 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37368 + return; /* success */
37370 + pr_err("wkq %d\n", wkq_err);
37371 + au_lcnt_dec(&br->br_count);
37372 + au_kfree_rcu(args);
37375 + atomic_dec(&br->br_xino->xi_truncating);
37378 +/* ---------------------------------------------------------------------- */
37380 +struct au_xi_calc {
37385 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37386 + struct au_xi_calc *calc)
37390 + maxent = au_xi_maxent(sb);
37391 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37392 + calc->pos *= sizeof(ino_t);
37395 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37396 + struct au_xi_calc *calc)
37399 + struct file *file;
37400 + struct au_xino *xi = br->br_xino;
37401 + struct au_xi_new xinew = {
37405 + SiMustAnyLock(sb);
37411 + mutex_lock(&xi->xi_mtx);
37412 + file = au_xino_file(xi, calc->idx);
37416 + file = au_xino_file(xi, /*idx*/-1);
37417 + AuDebugOn(!file);
37418 + xinew.idx = calc->idx;
37419 + xinew.base = &file->f_path;
37420 + /* xinew.copy_src = NULL; */
37421 + file = au_xi_new(sb, &xinew);
37422 + if (IS_ERR(file))
37423 + err = PTR_ERR(file);
37426 + mutex_unlock(&xi->xi_mtx);
37431 +struct au_xino_do_new_async_args {
37432 + struct super_block *sb;
37433 + struct au_branch *br;
37434 + struct au_xi_calc calc;
37438 +struct au_xi_writing {
37439 + struct hlist_bl_node node;
37440 + ino_t h_ino, ino;
37443 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37446 +static void au_xino_call_do_new_async(void *args)
37448 + struct au_xino_do_new_async_args *a = args;
37449 + struct au_branch *br;
37450 + struct super_block *sb;
37451 + struct au_sbinfo *sbi;
37452 + struct inode *root;
37453 + struct file *file;
37454 + struct au_xi_writing *del, *p;
37455 + struct hlist_bl_head *hbl;
37456 + struct hlist_bl_node *pos;
37461 + sbi = au_sbi(sb);
37462 + si_noflush_read_lock(sb);
37463 + root = d_inode(sb->s_root);
37464 + ii_read_lock_child(root);
37465 + err = au_xino_do_new_async(sb, br, &a->calc);
37466 + if (unlikely(err)) {
37467 + AuIOErr("err %d\n", err);
37471 + file = au_xino_file(br->br_xino, a->calc.idx);
37472 + AuDebugOn(!file);
37473 + err = au_xino_do_write(file, &a->calc, a->ino);
37474 + if (unlikely(err)) {
37475 + AuIOErr("err %d\n", err);
37480 + hbl = &br->br_xino->xi_writing;
37481 + hlist_bl_lock(hbl);
37482 + au_hbl_for_each(pos, hbl) {
37483 + p = container_of(pos, struct au_xi_writing, node);
37484 + if (p->ino == a->ino) {
37486 + hlist_bl_del(&p->node);
37490 + hlist_bl_unlock(hbl);
37491 + au_kfree_rcu(del);
37494 + au_lcnt_dec(&br->br_count);
37495 + ii_read_unlock(root);
37496 + si_read_unlock(sb);
37497 + au_nwt_done(&sbi->si_nowait);
37502 + * create a new xino file asynchronously
37504 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37505 + struct au_xi_calc *calc, ino_t ino)
37508 + struct au_xino_do_new_async_args *arg;
37511 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37512 + if (unlikely(!arg))
37517 + arg->calc = *calc;
37519 + au_lcnt_inc(&br->br_count);
37520 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37521 + if (unlikely(err)) {
37522 + pr_err("wkq %d\n", err);
37523 + au_lcnt_dec(&br->br_count);
37524 + au_kfree_rcu(arg);
37532 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37533 + * at the position of @h_ino.
37535 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37540 + struct au_xi_calc calc;
37541 + struct au_sbinfo *sbinfo;
37542 + struct file *file;
37543 + struct au_xino *xi;
37544 + struct hlist_bl_head *hbl;
37545 + struct hlist_bl_node *pos;
37546 + struct au_xi_writing *p;
37549 + if (!au_opt_test(au_mntflags(sb), XINO))
37550 + return 0; /* no xino */
37553 + au_xi_calc(sb, h_ino, &calc);
37554 + xi = au_sbr(sb, bindex)->br_xino;
37555 + file = au_xino_file(xi, calc.idx);
37557 + hbl = &xi->xi_writing;
37558 + hlist_bl_lock(hbl);
37559 + au_hbl_for_each(pos, hbl) {
37560 + p = container_of(pos, struct au_xi_writing, node);
37561 + if (p->h_ino == h_ino) {
37562 + AuDbg("hi%llu, i%llu, found\n",
37563 + (u64)p->h_ino, (u64)p->ino);
37568 + hlist_bl_unlock(hbl);
37570 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37571 + return 0; /* no xino */
37573 + sbinfo = au_sbi(sb);
37574 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37575 + if (sz == sizeof(*ino))
37576 + return 0; /* success */
37579 + if (unlikely(sz >= 0)) {
37581 + AuIOErr("xino read error (%zd)\n", sz);
37586 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37591 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37592 + if (sz == sizeof(ino))
37593 + return 0; /* success */
37595 + AuIOErr("write failed (%zd)\n", sz);
37600 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37601 + * at the position of @h_ino.
37602 + * even if @ino is zero, it is written to the xinofile and means no entry.
37603 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37604 + * try truncating it.
37606 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37610 + unsigned int mnt_flags;
37611 + struct au_xi_calc calc;
37612 + struct file *file;
37613 + struct au_branch *br;
37614 + struct au_xino *xi;
37615 + struct au_xi_writing *p;
37617 + SiMustAnyLock(sb);
37619 + mnt_flags = au_mntflags(sb);
37620 + if (!au_opt_test(mnt_flags, XINO))
37623 + au_xi_calc(sb, h_ino, &calc);
37624 + br = au_sbr(sb, bindex);
37625 + xi = br->br_xino;
37626 + file = au_xino_file(xi, calc.idx);
37628 + /* store the inum pair into the list */
37629 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37630 + p->h_ino = h_ino;
37632 + au_hbl_add(&p->node, &xi->xi_writing);
37634 + /* create and write a new xino file asynchronously */
37635 + err = au_xino_new_async(sb, br, &calc, ino);
37637 + return 0; /* success */
37641 + err = au_xino_do_write(file, &calc, ino);
37643 + br = au_sbr(sb, bindex);
37644 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37645 + && au_test_fs_trunc_xino(au_br_sb(br)))
37646 + xino_try_trunc(sb, br);
37647 + return 0; /* success */
37651 + AuIOErr("write failed (%d)\n", err);
37655 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37658 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37659 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37663 + const int prevent_endless = 10;
37667 + err = vfsub_read_k(file, kbuf, size, pos);
37668 + if (err == -EINTR
37669 + && !au_wkq_test()
37670 + && fatal_signal_pending(current)) {
37671 + err = xino_fread_wkq(file, kbuf, size, pos);
37672 + BUG_ON(err == -EINTR);
37674 + } while (i++ < prevent_endless
37675 + && (err == -EAGAIN || err == -EINTR));
37677 +#if 0 /* reserved for future use */
37679 + fsnotify_access(file->f_path.dentry);
37685 +struct xino_fread_args {
37687 + struct file *file;
37693 +static void call_xino_fread(void *args)
37695 + struct xino_fread_args *a = args;
37696 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37699 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37704 + struct xino_fread_args args = {
37712 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37713 + if (unlikely(wkq_err))
37719 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37722 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37727 + const int prevent_endless = 10;
37731 + err = vfsub_write_k(file, kbuf, size, pos);
37732 + if (err == -EINTR
37733 + && !au_wkq_test()
37734 + && fatal_signal_pending(current)) {
37735 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37736 + BUG_ON(err == -EINTR);
37738 + } while (i++ < prevent_endless
37739 + && (err == -EAGAIN || err == -EINTR));
37741 +#if 0 /* reserved for future use */
37743 + fsnotify_modify(file->f_path.dentry);
37749 +struct do_xino_fwrite_args {
37751 + struct file *file;
37757 +static void call_do_xino_fwrite(void *args)
37759 + struct do_xino_fwrite_args *a = args;
37760 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37763 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37768 + struct do_xino_fwrite_args args = {
37777 + * it breaks RLIMIT_FSIZE and normal user's limit,
37778 + * users should care about quota and real 'filesystem full.'
37780 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37781 + if (unlikely(wkq_err))
37787 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37791 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37793 + err = do_xino_fwrite(file, buf, size, pos);
37797 + err = xino_fwrite_wkq(file, buf, size, pos);
37804 +/* ---------------------------------------------------------------------- */
37807 + * inode number bitmap
37809 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37810 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37814 + AuDebugOn(bit < 0 || page_bits <= bit);
37815 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37819 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37821 + AuDebugOn(ino < AUFS_FIRST_INO);
37822 + ino -= AUFS_FIRST_INO;
37823 + *pindex = ino / page_bits;
37824 + *bit = ino % page_bits;
37827 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37832 + struct au_sbinfo *sbinfo;
37833 + struct file *xib;
37834 + unsigned long *p;
37836 + sbinfo = au_sbi(sb);
37837 + MtxMustLock(&sbinfo->si_xib_mtx);
37838 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37839 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37841 + if (pindex == sbinfo->si_xib_last_pindex)
37844 + xib = sbinfo->si_xib;
37845 + p = sbinfo->si_xib_buf;
37846 + pos = sbinfo->si_xib_last_pindex;
37847 + pos *= PAGE_SIZE;
37848 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37849 + if (unlikely(sz != PAGE_SIZE))
37853 + pos *= PAGE_SIZE;
37854 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37855 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37857 + memset(p, 0, PAGE_SIZE);
37858 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37860 + if (sz == PAGE_SIZE) {
37861 + sbinfo->si_xib_last_pindex = pindex;
37862 + return 0; /* success */
37866 + AuIOErr1("write failed (%zd)\n", sz);
37873 +static void au_xib_clear_bit(struct inode *inode)
37876 + unsigned long pindex;
37877 + struct super_block *sb;
37878 + struct au_sbinfo *sbinfo;
37880 + AuDebugOn(inode->i_nlink);
37882 + sb = inode->i_sb;
37883 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37884 + AuDebugOn(page_bits <= bit);
37885 + sbinfo = au_sbi(sb);
37886 + mutex_lock(&sbinfo->si_xib_mtx);
37887 + err = xib_pindex(sb, pindex);
37889 + clear_bit(bit, sbinfo->si_xib_buf);
37890 + sbinfo->si_xib_next_bit = bit;
37892 + mutex_unlock(&sbinfo->si_xib_mtx);
37895 +/* ---------------------------------------------------------------------- */
37898 + * truncate a xino bitmap file
37902 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37906 + unsigned long pindex;
37907 + loff_t pos, pend;
37908 + struct au_sbinfo *sbinfo;
37910 + unsigned long *p;
37913 + sbinfo = au_sbi(sb);
37914 + MtxMustLock(&sbinfo->si_xib_mtx);
37915 + p = sbinfo->si_xib_buf;
37916 + pend = vfsub_f_size_read(file);
37918 + while (pos < pend) {
37919 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37921 + if (unlikely(sz <= 0))
37925 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37926 + if (unlikely(*ino < AUFS_FIRST_INO))
37929 + xib_calc_bit(*ino, &pindex, &bit);
37930 + AuDebugOn(page_bits <= bit);
37931 + err = xib_pindex(sb, pindex);
37943 +static int xib_restore(struct super_block *sb)
37946 + unsigned int nfile;
37947 + aufs_bindex_t bindex, bbot;
37949 + struct au_branch *br;
37950 + struct au_xino *xi;
37951 + struct file *file;
37954 + page = (void *)__get_free_page(GFP_NOFS);
37955 + if (unlikely(!page))
37959 + bbot = au_sbbot(sb);
37960 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37961 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37962 + br = au_sbr(sb, bindex);
37963 + xi = br->br_xino;
37964 + nfile = xi->xi_nfile;
37965 + for (i = 0; i < nfile; i++) {
37966 + file = au_xino_file(xi, i);
37968 + err = do_xib_restore(sb, file, page);
37971 + AuDbg("skip shared b%d\n", bindex);
37972 + free_page((unsigned long)page);
37978 +int au_xib_trunc(struct super_block *sb)
37983 + struct au_sbinfo *sbinfo;
37984 + unsigned long *p;
37985 + struct file *file;
37987 + SiMustWriteLock(sb);
37990 + sbinfo = au_sbi(sb);
37991 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37994 + file = sbinfo->si_xib;
37995 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37998 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37999 + err = PTR_ERR(file);
38000 + if (IS_ERR(file))
38002 + fput(sbinfo->si_xib);
38003 + sbinfo->si_xib = file;
38005 + p = sbinfo->si_xib_buf;
38006 + memset(p, 0, PAGE_SIZE);
38008 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38009 + if (unlikely(sz != PAGE_SIZE)) {
38011 + AuIOErr("err %d\n", err);
38017 + mutex_lock(&sbinfo->si_xib_mtx);
38018 + /* mnt_want_write() is unnecessary here */
38019 + err = xib_restore(sb);
38020 + mutex_unlock(&sbinfo->si_xib_mtx);
38026 +/* ---------------------------------------------------------------------- */
38028 +struct au_xino *au_xino_alloc(unsigned int nfile)
38030 + struct au_xino *xi;
38032 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38033 + if (unlikely(!xi))
38035 + xi->xi_nfile = nfile;
38036 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38037 + if (unlikely(!xi->xi_file))
38040 + xi->xi_nondir.total = 8; /* initial size */
38041 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38043 + if (unlikely(!xi->xi_nondir.array))
38046 + spin_lock_init(&xi->xi_nondir.spin);
38047 + init_waitqueue_head(&xi->xi_nondir.wqh);
38048 + mutex_init(&xi->xi_mtx);
38049 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38050 + atomic_set(&xi->xi_truncating, 0);
38051 + kref_init(&xi->xi_kref);
38052 + goto out; /* success */
38055 + au_kfree_try_rcu(xi->xi_file);
38057 + au_kfree_rcu(xi);
38063 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38066 + struct au_xino *xi;
38069 + xi = au_xino_alloc(idx + 1);
38070 + if (unlikely(!xi)) {
38077 + xi->xi_file[idx] = file;
38078 + AuDebugOn(br->br_xino);
38079 + br->br_xino = xi;
38085 +static void au_xino_release(struct kref *kref)
38087 + struct au_xino *xi;
38089 + unsigned long ul;
38090 + struct hlist_bl_head *hbl;
38091 + struct hlist_bl_node *pos, *n;
38092 + struct au_xi_writing *p;
38094 + xi = container_of(kref, struct au_xino, xi_kref);
38095 + for (i = 0; i < xi->xi_nfile; i++)
38096 + if (xi->xi_file[i])
38097 + fput(xi->xi_file[i]);
38098 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38099 + AuDebugOn(xi->xi_nondir.array[i]);
38100 + mutex_destroy(&xi->xi_mtx);
38101 + hbl = &xi->xi_writing;
38102 + ul = au_hbl_count(hbl);
38103 + if (unlikely(ul)) {
38104 + pr_warn("xi_writing %lu\n", ul);
38105 + hlist_bl_lock(hbl);
38106 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38107 + hlist_bl_del(&p->node);
38108 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38111 + hlist_bl_unlock(hbl);
38113 + au_kfree_try_rcu(xi->xi_file);
38114 + au_kfree_try_rcu(xi->xi_nondir.array);
38115 + au_kfree_rcu(xi);
38118 +int au_xino_put(struct au_branch *br)
38121 + struct au_xino *xi;
38124 + xi = br->br_xino;
38126 + br->br_xino = NULL;
38127 + ret = kref_put(&xi->xi_kref, au_xino_release);
38133 +/* ---------------------------------------------------------------------- */
38136 + * xino mount option handlers
38140 +static void xino_clear_xib(struct super_block *sb)
38142 + struct au_sbinfo *sbinfo;
38144 + SiMustWriteLock(sb);
38146 + sbinfo = au_sbi(sb);
38147 + if (sbinfo->si_xib)
38148 + fput(sbinfo->si_xib);
38149 + sbinfo->si_xib = NULL;
38150 + if (sbinfo->si_xib_buf)
38151 + free_page((unsigned long)sbinfo->si_xib_buf);
38152 + sbinfo->si_xib_buf = NULL;
38155 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38159 + struct au_sbinfo *sbinfo;
38160 + struct file *file;
38161 + struct super_block *xi_sb;
38163 + SiMustWriteLock(sb);
38165 + sbinfo = au_sbi(sb);
38166 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38167 + err = PTR_ERR(file);
38168 + if (IS_ERR(file))
38170 + if (sbinfo->si_xib)
38171 + fput(sbinfo->si_xib);
38172 + sbinfo->si_xib = file;
38173 + xi_sb = file_inode(file)->i_sb;
38174 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38175 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38177 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38178 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38181 + sbinfo->si_ximaxent /= sizeof(ino_t);
38184 + if (!sbinfo->si_xib_buf)
38185 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38186 + if (unlikely(!sbinfo->si_xib_buf))
38189 + sbinfo->si_xib_last_pindex = 0;
38190 + sbinfo->si_xib_next_bit = 0;
38191 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38193 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38194 + if (unlikely(err != PAGE_SIZE))
38198 + goto out; /* success */
38201 + if (sbinfo->si_xib_buf)
38202 + free_page((unsigned long)sbinfo->si_xib_buf);
38203 + sbinfo->si_xib_buf = NULL;
38207 + fput(sbinfo->si_xib);
38208 + sbinfo->si_xib = NULL;
38214 +/* xino for each branch */
38215 +static void xino_clear_br(struct super_block *sb)
38217 + aufs_bindex_t bindex, bbot;
38218 + struct au_branch *br;
38220 + bbot = au_sbbot(sb);
38221 + for (bindex = 0; bindex <= bbot; bindex++) {
38222 + br = au_sbr(sb, bindex);
38228 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38229 + aufs_bindex_t bshared)
38231 + struct au_branch *brshared;
38233 + brshared = au_sbr(sb, bshared);
38234 + AuDebugOn(!brshared->br_xino);
38235 + AuDebugOn(!brshared->br_xino->xi_file);
38236 + if (br->br_xino != brshared->br_xino) {
38237 + au_xino_get(brshared);
38239 + br->br_xino = brshared->br_xino;
38243 +struct au_xino_do_set_br {
38244 + struct au_branch *br;
38246 + aufs_bindex_t bshared;
38249 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38250 + struct au_xino_do_set_br *args)
38253 + struct au_xi_calc calc;
38254 + struct file *file;
38255 + struct au_branch *br;
38256 + struct au_xi_new xinew = {
38261 + xinew.xi = br->br_xino;
38262 + au_xi_calc(sb, args->h_ino, &calc);
38263 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38264 + if (args->bshared >= 0)
38265 + /* shared xino */
38266 + au_xino_set_br_shared(sb, br, args->bshared);
38267 + else if (!xinew.xi) {
38269 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38270 + if (unlikely(err))
38274 + /* force re-creating */
38275 + xinew.xi = br->br_xino;
38276 + xinew.idx = calc.idx;
38277 + mutex_lock(&xinew.xi->xi_mtx);
38278 + file = au_xi_new(sb, &xinew);
38279 + mutex_unlock(&xinew.xi->xi_mtx);
38280 + err = PTR_ERR(file);
38281 + if (IS_ERR(file))
38283 + AuDebugOn(!file);
38285 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38286 + if (unlikely(err))
38294 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38297 + aufs_bindex_t bindex, bbot;
38298 + struct au_xino_do_set_br args;
38299 + struct inode *inode;
38301 + SiMustWriteLock(sb);
38303 + bbot = au_sbbot(sb);
38304 + inode = d_inode(sb->s_root);
38305 + for (bindex = 0; bindex <= bbot; bindex++) {
38306 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38307 + args.br = au_sbr(sb, bindex);
38308 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38309 + err = au_xino_do_set_br(sb, path, &args);
38310 + if (unlikely(err))
38318 +void au_xino_clr(struct super_block *sb)
38320 + struct au_sbinfo *sbinfo;
38322 + au_xigen_clr(sb);
38323 + xino_clear_xib(sb);
38324 + xino_clear_br(sb);
38325 + dbgaufs_brs_del(sb, 0);
38326 + sbinfo = au_sbi(sb);
38327 + /* lvalue, do not call au_mntflags() */
38328 + au_opt_clr(sbinfo->si_mntflags, XINO);
38331 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38334 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38335 + struct qstr *dname, *cur_name;
38336 + struct file *cur_xino;
38337 + struct au_sbinfo *sbinfo;
38338 + struct path *path, *cur_path;
38340 + SiMustWriteLock(sb);
38343 + sbinfo = au_sbi(sb);
38344 + path = &xiopt->file->f_path;
38345 + dentry = path->dentry;
38346 + parent = dget_parent(dentry);
38349 + cur_xino = sbinfo->si_xib;
38351 + cur_path = &cur_xino->f_path;
38352 + cur_dentry = cur_path->dentry;
38353 + cur_parent = dget_parent(cur_dentry);
38354 + cur_name = &cur_dentry->d_name;
38355 + dname = &dentry->d_name;
38356 + skip = (cur_parent == parent
38357 + && au_qstreq(dname, cur_name));
38358 + dput(cur_parent);
38364 + au_opt_set(sbinfo->si_mntflags, XINO);
38365 + err = au_xino_set_xib(sb, path);
38366 + /* si_x{read,write} are set */
38368 + err = au_xigen_set(sb, path);
38370 + err = au_xino_set_br(sb, path);
38372 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38373 + goto out; /* success */
38377 + AuIOErr("failed setting xino(%d).\n", err);
38386 + * create a xinofile at the default place/path.
38388 +struct file *au_xino_def(struct super_block *sb)
38390 + struct file *file;
38392 + struct au_branch *br;
38393 + struct super_block *h_sb;
38394 + struct path path;
38395 + aufs_bindex_t bbot, bindex, bwr;
38398 + bbot = au_sbbot(sb);
38400 + for (bindex = 0; bindex <= bbot; bindex++) {
38401 + br = au_sbr(sb, bindex);
38402 + if (au_br_writable(br->br_perm)
38403 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38410 + file = ERR_PTR(-ENOMEM);
38411 + page = (void *)__get_free_page(GFP_NOFS);
38412 + if (unlikely(!page))
38414 + path.mnt = au_br_mnt(br);
38415 + path.dentry = au_h_dptr(sb->s_root, bwr);
38416 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38417 + file = (void *)p;
38418 + if (!IS_ERR(p)) {
38419 + strcat(p, "/" AUFS_XINO_FNAME);
38420 + AuDbg("%s\n", p);
38421 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38423 + free_page((unsigned long)page);
38425 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38427 + if (IS_ERR(file))
38429 + h_sb = file->f_path.dentry->d_sb;
38430 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38431 + pr_err("xino doesn't support %s(%s)\n",
38432 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38434 + file = ERR_PTR(-EINVAL);
38442 +/* ---------------------------------------------------------------------- */
38445 + * initialize the xinofile for the specified branch @br
38446 + * at the place/path where @base_file indicates.
38447 + * test whether another branch is on the same filesystem or not,
38448 + * if found then share the xinofile with another branch.
38450 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38451 + struct path *base)
38454 + struct au_xino_do_set_br args = {
38459 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38461 + err = au_xino_do_set_br(sb, base, &args);
38462 + if (unlikely(err))
38468 +/* ---------------------------------------------------------------------- */
38471 + * get an unused inode number from bitmap
38473 +ino_t au_xino_new_ino(struct super_block *sb)
38476 + unsigned long *p, pindex, ul, pend;
38477 + struct au_sbinfo *sbinfo;
38478 + struct file *file;
38479 + int free_bit, err;
38481 + if (!au_opt_test(au_mntflags(sb), XINO))
38482 + return iunique(sb, AUFS_FIRST_INO);
38484 + sbinfo = au_sbi(sb);
38485 + mutex_lock(&sbinfo->si_xib_mtx);
38486 + p = sbinfo->si_xib_buf;
38487 + free_bit = sbinfo->si_xib_next_bit;
38488 + if (free_bit < page_bits && !test_bit(free_bit, p))
38489 + goto out; /* success */
38490 + free_bit = find_first_zero_bit(p, page_bits);
38491 + if (free_bit < page_bits)
38492 + goto out; /* success */
38494 + pindex = sbinfo->si_xib_last_pindex;
38495 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38496 + err = xib_pindex(sb, ul);
38497 + if (unlikely(err))
38499 + free_bit = find_first_zero_bit(p, page_bits);
38500 + if (free_bit < page_bits)
38501 + goto out; /* success */
38504 + file = sbinfo->si_xib;
38505 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38506 + for (ul = pindex + 1; ul <= pend; ul++) {
38507 + err = xib_pindex(sb, ul);
38508 + if (unlikely(err))
38510 + free_bit = find_first_zero_bit(p, page_bits);
38511 + if (free_bit < page_bits)
38512 + goto out; /* success */
38517 + set_bit(free_bit, p);
38518 + sbinfo->si_xib_next_bit = free_bit + 1;
38519 + pindex = sbinfo->si_xib_last_pindex;
38520 + mutex_unlock(&sbinfo->si_xib_mtx);
38521 + ino = xib_calc_ino(pindex, free_bit);
38522 + AuDbg("i%lu\n", (unsigned long)ino);
38525 + mutex_unlock(&sbinfo->si_xib_mtx);
38530 +/* for s_op->delete_inode() */
38531 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38534 + unsigned int mnt_flags;
38535 + aufs_bindex_t bindex, bbot, bi;
38536 + unsigned char try_trunc;
38537 + struct au_iinfo *iinfo;
38538 + struct super_block *sb;
38539 + struct au_hinode *hi;
38540 + struct inode *h_inode;
38541 + struct au_branch *br;
38542 + struct au_xi_calc calc;
38543 + struct file *file;
38545 + AuDebugOn(au_is_bad_inode(inode));
38547 + sb = inode->i_sb;
38548 + mnt_flags = au_mntflags(sb);
38549 + if (!au_opt_test(mnt_flags, XINO)
38550 + || inode->i_ino == AUFS_ROOT_INO)
38554 + au_xigen_inc(inode);
38555 + au_xib_clear_bit(inode);
38558 + iinfo = au_ii(inode);
38559 + bindex = iinfo->ii_btop;
38563 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38564 + hi = au_hinode(iinfo, bindex);
38565 + bbot = iinfo->ii_bbot;
38566 + for (; bindex <= bbot; bindex++, hi++) {
38567 + h_inode = hi->hi_inode;
38569 + || (!unlinked && h_inode->i_nlink))
38572 + /* inode may not be revalidated */
38573 + bi = au_br_index(sb, hi->hi_id);
38577 + br = au_sbr(sb, bi);
38578 + au_xi_calc(sb, h_inode->i_ino, &calc);
38579 + file = au_xino_file(br->br_xino, calc.idx);
38580 + if (IS_ERR_OR_NULL(file))
38583 + err = au_xino_do_write(file, &calc, /*ino*/0);
38584 + if (!err && try_trunc
38585 + && au_test_fs_trunc_xino(au_br_sb(br)))
38586 + xino_try_trunc(sb, br);
38590 +/* ---------------------------------------------------------------------- */
38592 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38594 + int found, total, i;
38597 + total = xi->xi_nondir.total;
38598 + for (i = 0; i < total; i++) {
38599 + if (xi->xi_nondir.array[i] != h_ino)
38608 +static int au_xinondir_expand(struct au_xino *xi)
38613 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38616 + sz = xi->xi_nondir.total * sizeof(ino_t);
38617 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38619 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38620 + /*may_shrink*/0);
38622 + xi->xi_nondir.array = p;
38623 + xi->xi_nondir.total <<= 1;
38624 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38632 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38633 + ino_t h_ino, int idx)
38635 + struct au_xino *xi;
38637 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38638 + xi = au_sbr(sb, bindex)->br_xino;
38639 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38641 + spin_lock(&xi->xi_nondir.spin);
38642 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38643 + xi->xi_nondir.array[idx] = 0;
38644 + spin_unlock(&xi->xi_nondir.spin);
38645 + wake_up_all(&xi->xi_nondir.wqh);
38648 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38651 + int err, found, empty;
38652 + struct au_xino *xi;
38656 + if (!au_opt_test(au_mntflags(sb), XINO))
38657 + goto out; /* no xino */
38659 + xi = au_sbr(sb, bindex)->br_xino;
38662 + spin_lock(&xi->xi_nondir.spin);
38663 + found = au_xinondir_find(xi, h_ino);
38664 + if (found == -1) {
38665 + empty = au_xinondir_find(xi, /*h_ino*/0);
38666 + if (empty == -1) {
38667 + empty = xi->xi_nondir.total;
38668 + err = au_xinondir_expand(xi);
38669 + if (unlikely(err))
38672 + xi->xi_nondir.array[empty] = h_ino;
38675 + spin_unlock(&xi->xi_nondir.spin);
38676 + wait_event(xi->xi_nondir.wqh,
38677 + xi->xi_nondir.array[found] != h_ino);
38682 + spin_unlock(&xi->xi_nondir.spin);
38687 +/* ---------------------------------------------------------------------- */
38689 +int au_xino_path(struct seq_file *seq, struct file *file)
38693 + err = au_seq_path(seq, &file->f_path);
38694 + if (unlikely(err))
38697 +#define Deleted "\\040(deleted)"
38698 + seq->count -= sizeof(Deleted) - 1;
38699 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38700 + sizeof(Deleted) - 1));
38706 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38707 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38708 +++ linux/include/uapi/linux/aufs_type.h 2021-05-02 20:15:14.676670793 +0200
38710 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38712 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38714 + * This program, aufs is free software; you can redistribute it and/or modify
38715 + * it under the terms of the GNU General Public License as published by
38716 + * the Free Software Foundation; either version 2 of the License, or
38717 + * (at your option) any later version.
38719 + * This program is distributed in the hope that it will be useful,
38720 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38721 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38722 + * GNU General Public License for more details.
38724 + * You should have received a copy of the GNU General Public License
38725 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38728 +#ifndef __AUFS_TYPE_H__
38729 +#define __AUFS_TYPE_H__
38731 +#define AUFS_NAME "aufs"
38735 + * define it before including all other headers.
38736 + * sched.h may use pr_* macros before defining "current", so define the
38737 + * no-current version first, and re-define later.
38739 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38740 +#include <linux/sched.h>
38742 +#define pr_fmt(fmt) \
38743 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38744 + (int)sizeof(current->comm), current->comm, current->pid
38745 +#include <linux/limits.h>
38747 +#include <stdint.h>
38748 +#include <sys/types.h>
38749 +#include <limits.h>
38750 +#endif /* __KERNEL__ */
38752 +#define AUFS_VERSION "5.12-20210503"
38754 +/* todo? move this to linux-2.6.19/include/magic.h */
38755 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38757 +/* ---------------------------------------------------------------------- */
38760 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38761 +typedef int8_t aufs_bindex_t;
38762 +#define AUFS_BRANCH_MAX 127
38764 +typedef int16_t aufs_bindex_t;
38765 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38766 +#define AUFS_BRANCH_MAX 511
38767 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38768 +#define AUFS_BRANCH_MAX 1023
38769 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38770 +#define AUFS_BRANCH_MAX 32767
38774 +#ifndef AUFS_BRANCH_MAX
38775 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38777 +#endif /* __KERNEL__ */
38779 +/* ---------------------------------------------------------------------- */
38781 +#define AUFS_FSTYPE AUFS_NAME
38783 +#define AUFS_ROOT_INO 2
38784 +#define AUFS_FIRST_INO 11
38786 +#define AUFS_WH_PFX ".wh."
38787 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38788 +#define AUFS_WH_TMP_LEN 4
38789 +/* a limit for rmdir/rename a dir and copyup */
38790 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38791 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38793 + - AUFS_WH_TMP_LEN) /* hex */
38794 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38795 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38796 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38797 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38798 +#define AUFS_DIRWH_DEF 3
38799 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38800 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38801 +#define AUFS_RDBLK_DEF 512 /* bytes */
38802 +#define AUFS_RDHASH_DEF 32
38803 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38804 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38805 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38806 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38807 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38809 +/* pseudo-link maintenace under /proc */
38810 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38811 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38812 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38814 +/* dirren, renamed dir */
38815 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38816 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38817 +/* whiteouted doubly */
38818 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38819 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38821 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38822 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38824 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38825 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38826 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38828 +/* doubly whiteouted */
38829 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38830 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38831 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38833 +/* branch permissions and attributes */
38834 +#define AUFS_BRPERM_RW "rw"
38835 +#define AUFS_BRPERM_RO "ro"
38836 +#define AUFS_BRPERM_RR "rr"
38837 +#define AUFS_BRATTR_COO_REG "coo_reg"
38838 +#define AUFS_BRATTR_COO_ALL "coo_all"
38839 +#define AUFS_BRATTR_FHSM "fhsm"
38840 +#define AUFS_BRATTR_UNPIN "unpin"
38841 +#define AUFS_BRATTR_ICEX "icex"
38842 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38843 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38844 +#define AUFS_BRATTR_ICEX_TR "icextr"
38845 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38846 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38847 +#define AUFS_BRRATTR_WH "wh"
38848 +#define AUFS_BRWATTR_NLWH "nolwh"
38849 +#define AUFS_BRWATTR_MOO "moo"
38851 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38852 +#define AuBrPerm_RO (1 << 1) /* readonly */
38853 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38854 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38856 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38857 +#define AuBrAttr_COO_ALL (1 << 4)
38858 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38860 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38861 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38862 + branch. meaningless since
38863 + linux-3.18-rc1 */
38865 +/* ignore error in copying XATTR */
38866 +#define AuBrAttr_ICEX_SEC (1 << 7)
38867 +#define AuBrAttr_ICEX_SYS (1 << 8)
38868 +#define AuBrAttr_ICEX_TR (1 << 9)
38869 +#define AuBrAttr_ICEX_USR (1 << 10)
38870 +#define AuBrAttr_ICEX_OTH (1 << 11)
38871 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38872 + | AuBrAttr_ICEX_SYS \
38873 + | AuBrAttr_ICEX_TR \
38874 + | AuBrAttr_ICEX_USR \
38875 + | AuBrAttr_ICEX_OTH)
38877 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38878 +#define AuBrRAttr_Mask AuBrRAttr_WH
38880 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38881 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38882 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38884 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38886 +/* #warning test userspace */
38888 +#ifndef CONFIG_AUFS_FHSM
38889 +#undef AuBrAttr_FHSM
38890 +#define AuBrAttr_FHSM 0
38892 +#ifndef CONFIG_AUFS_XATTR
38893 +#undef AuBrAttr_ICEX
38894 +#define AuBrAttr_ICEX 0
38895 +#undef AuBrAttr_ICEX_SEC
38896 +#define AuBrAttr_ICEX_SEC 0
38897 +#undef AuBrAttr_ICEX_SYS
38898 +#define AuBrAttr_ICEX_SYS 0
38899 +#undef AuBrAttr_ICEX_TR
38900 +#define AuBrAttr_ICEX_TR 0
38901 +#undef AuBrAttr_ICEX_USR
38902 +#define AuBrAttr_ICEX_USR 0
38903 +#undef AuBrAttr_ICEX_OTH
38904 +#define AuBrAttr_ICEX_OTH 0
38908 +/* the longest combination */
38909 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38910 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38911 + "+" AUFS_BRATTR_COO_REG \
38912 + "+" AUFS_BRATTR_FHSM \
38913 + "+" AUFS_BRATTR_UNPIN \
38914 + "+" AUFS_BRATTR_ICEX_SEC \
38915 + "+" AUFS_BRATTR_ICEX_SYS \
38916 + "+" AUFS_BRATTR_ICEX_USR \
38917 + "+" AUFS_BRATTR_ICEX_OTH \
38918 + "+" AUFS_BRWATTR_NLWH)
38921 + char a[AuBrPermStrSz];
38922 +} au_br_perm_str_t;
38924 +static inline int au_br_writable(int brperm)
38926 + return brperm & AuBrPerm_RW;
38929 +static inline int au_br_whable(int brperm)
38931 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38934 +static inline int au_br_wh_linkable(int brperm)
38936 + return !(brperm & AuBrWAttr_NoLinkWH);
38939 +static inline int au_br_cmoo(int brperm)
38941 + return brperm & AuBrAttr_CMOO_Mask;
38944 +static inline int au_br_fhsm(int brperm)
38946 + return brperm & AuBrAttr_FHSM;
38949 +/* ---------------------------------------------------------------------- */
38953 + /* readdir in userspace */
38957 + AuCtl_WBR_FD, /* pathconf wrapper */
38958 + AuCtl_IBUSY, /* busy inode */
38959 + AuCtl_MVDOWN, /* move-down */
38960 + AuCtl_BR, /* info about branches */
38961 + AuCtl_FHSM_FD /* connection for fhsm */
38964 +/* borrowed from linux/include/linux/kernel.h */
38966 +#ifdef _GNU_SOURCE
38967 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38969 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38971 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38974 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38976 +#define __aligned(x) __attribute__((aligned(x)))
38981 +#define __packed __attribute__((packed))
38985 +struct au_rdu_cookie {
38990 + uint32_t generation;
38993 +struct au_rdu_ent {
39002 +static inline int au_rdu_len(int nlen)
39004 + /* include the terminating NULL */
39005 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39006 + sizeof(uint64_t));
39009 +union au_rdu_ent_ul {
39010 + struct au_rdu_ent __user *e;
39022 + uint64_t sz; /* AuCtl_RDU */
39023 + uint64_t nent; /* AuCtl_RDU_INO */
39025 + union au_rdu_ent_ul ent;
39026 + uint16_t verify[AufsCtlRduV_End];
39028 + /* input/output */
39032 + union au_rdu_ent_ul tail;
39033 + /* number of entries which were added in a single call */
39038 + struct au_rdu_cookie cookie;
39041 +/* ---------------------------------------------------------------------- */
39043 +/* dirren. the branch is identified by the filename who contains this */
39044 +struct au_drinfo {
39047 + uint8_t oldnamelen;
39048 + uint64_t _padding;
39050 + uint8_t oldname[];
39053 +struct au_drinfo_fdata {
39055 + struct au_drinfo drinfo;
39058 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39060 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39062 +/* ---------------------------------------------------------------------- */
39064 +struct aufs_wbr_fd {
39069 +/* ---------------------------------------------------------------------- */
39071 +struct aufs_ibusy {
39072 + uint64_t ino, h_ino;
39076 +/* ---------------------------------------------------------------------- */
39078 +/* error code for move-down */
39079 +/* the actual message strings are implemented in aufs-util.git */
39081 + EAU_MVDOWN_OPAQUE = 1,
39082 + EAU_MVDOWN_WHITEOUT,
39083 + EAU_MVDOWN_UPPER,
39084 + EAU_MVDOWN_BOTTOM,
39085 + EAU_MVDOWN_NOUPPER,
39086 + EAU_MVDOWN_NOLOWERBR,
39090 +/* flags for move-down */
39091 +#define AUFS_MVDOWN_DMSG 1
39092 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39093 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39094 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39095 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39096 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39097 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39098 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39099 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39100 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39101 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39102 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39103 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39105 +/* index for move-down */
39107 + AUFS_MVDOWN_UPPER,
39108 + AUFS_MVDOWN_LOWER,
39109 + AUFS_MVDOWN_NARRAY
39113 + * additional info of move-down
39114 + * number of free blocks and inodes.
39115 + * subset of struct kstatfs, but smaller and always 64bit.
39117 +struct aufs_stfs {
39118 + uint64_t f_blocks;
39119 + uint64_t f_bavail;
39120 + uint64_t f_files;
39121 + uint64_t f_ffree;
39124 +struct aufs_stbr {
39125 + int16_t brid; /* optional input */
39126 + int16_t bindex; /* output */
39127 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39130 +struct aufs_mvdown {
39131 + uint32_t flags; /* input/output */
39132 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39133 + int8_t au_errno; /* output */
39136 +/* ---------------------------------------------------------------------- */
39138 +union aufs_brinfo {
39139 + /* PATH_MAX may differ between kernel-space and user-space */
39140 + char _spacer[4096];
39148 +/* ---------------------------------------------------------------------- */
39150 +#define AuCtlType 'A'
39151 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39152 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39153 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39154 + struct aufs_wbr_fd)
39155 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39156 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39157 + struct aufs_mvdown)
39158 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39159 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39161 +#endif /* __AUFS_TYPE_H__ */
39162 SPDX-License-Identifier: GPL-2.0
39163 aufs5.12 loopback patch
39165 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39166 index 01ca256575fb2..f5a76bacf6c85 100644
39167 --- a/drivers/block/loop.c
39168 +++ b/drivers/block/loop.c
39169 @@ -646,6 +646,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39173 +static struct file *loop_real_file(struct file *file)
39175 + struct file *f = NULL;
39177 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39178 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39182 static void loop_reread_partitions(struct loop_device *lo,
39183 struct block_device *bdev)
39185 @@ -701,6 +710,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39188 struct file *file = NULL, *old_file;
39189 + struct file *f, *virt_file = NULL, *old_virt_file;
39193 @@ -720,12 +730,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39197 + f = loop_real_file(file);
39199 + virt_file = file;
39204 error = loop_validate_file(file, bdev);
39208 old_file = lo->lo_backing_file;
39209 + old_virt_file = lo->lo_backing_virt_file;
39213 @@ -737,6 +754,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39214 blk_mq_freeze_queue(lo->lo_queue);
39215 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39216 lo->lo_backing_file = file;
39217 + lo->lo_backing_virt_file = virt_file;
39218 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39219 mapping_set_gfp_mask(file->f_mapping,
39220 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39221 @@ -750,6 +768,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39225 + if (old_virt_file)
39226 + fput(old_virt_file);
39228 loop_reread_partitions(lo, bdev);
39230 @@ -758,6 +778,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39231 mutex_unlock(&lo->lo_mutex);
39239 @@ -1084,7 +1106,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39240 struct block_device *bdev,
39241 const struct loop_config *config)
39243 - struct file *file;
39244 + struct file *file, *f, *virt_file = NULL;
39245 struct inode *inode;
39246 struct address_space *mapping;
39248 @@ -1099,6 +1121,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39249 file = fget(config->fd);
39252 + f = loop_real_file(file);
39254 + virt_file = file;
39260 * If we don't hold exclusive handle for the device, upgrade to it
39261 @@ -1153,6 +1181,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39262 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39263 lo->lo_device = bdev;
39264 lo->lo_backing_file = file;
39265 + lo->lo_backing_virt_file = virt_file;
39266 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39267 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39269 @@ -1203,6 +1232,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39270 bd_abort_claiming(bdev, loop_configure);
39276 /* This is safe: open() is still holding a reference. */
39277 module_put(THIS_MODULE);
39278 @@ -1212,6 +1243,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39279 static int __loop_clr_fd(struct loop_device *lo, bool release)
39281 struct file *filp = NULL;
39282 + struct file *virt_filp = lo->lo_backing_virt_file;
39283 gfp_t gfp = lo->old_gfp_mask;
39284 struct block_device *bdev = lo->lo_device;
39286 @@ -1238,6 +1270,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39288 spin_lock_irq(&lo->lo_lock);
39289 lo->lo_backing_file = NULL;
39290 + lo->lo_backing_virt_file = NULL;
39291 spin_unlock_irq(&lo->lo_lock);
39293 loop_release_xfer(lo);
39294 @@ -1319,6 +1352,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39303 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39304 index a3c04f310672e..161c3c5d1c22b 100644
39305 --- a/drivers/block/loop.h
39306 +++ b/drivers/block/loop.h
39307 @@ -46,7 +46,7 @@ struct loop_device {
39308 int (*ioctl)(struct loop_device *, int cmd,
39309 unsigned long arg);
39311 - struct file * lo_backing_file;
39312 + struct file *lo_backing_file, *lo_backing_virt_file;
39313 struct block_device *lo_device;
39316 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39317 index 9f58ba0cb769f..1c2267a5a2ae1 100644
39318 --- a/fs/aufs/f_op.c
39319 +++ b/fs/aufs/f_op.c
39320 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39321 if (IS_ERR(h_file))
39324 - if (au_test_loopback_kthread()) {
39325 + if (0 && au_test_loopback_kthread()) {
39326 au_warn_loopback(h_file->f_path.dentry->d_sb);
39327 if (file->f_mapping != h_file->f_mapping) {
39328 file->f_mapping = h_file->f_mapping;
39329 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39330 index a8b63acc62045..9d97c3af5686a 100644
39331 --- a/fs/aufs/loop.c
39332 +++ b/fs/aufs/loop.c
39333 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39334 symbol_put(loop_backing_file);
39335 au_kfree_try_rcu(au_warn_loopback_array);
39338 +/* ---------------------------------------------------------------------- */
39340 +/* support the loopback block device insude aufs */
39342 +struct file *aufs_real_loop(struct file *file)
39346 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39347 + fi_read_lock(file);
39348 + f = au_hf_top(file);
39349 + fi_read_unlock(file);
39353 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39354 index 94f4f80ae33bf..ca1194354aff4 100644
39355 --- a/fs/aufs/loop.h
39356 +++ b/fs/aufs/loop.h
39357 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39359 int au_loopback_init(void);
39360 void au_loopback_fin(void);
39362 +struct file *aufs_real_loop(struct file *file);
39364 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39366 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39368 AuStubInt0(au_loopback_init, void)
39369 AuStubVoid(au_loopback_fin, void)
39371 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39372 #endif /* BLK_DEV_LOOP */
39374 #endif /* __KERNEL__ */
39375 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39376 index d252963a87b53..ecfc5fc96ad8c 100644
39377 --- a/fs/aufs/super.c
39378 +++ b/fs/aufs/super.c
39379 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39380 .statfs = aufs_statfs,
39381 .put_super = aufs_put_super,
39382 .sync_fs = aufs_sync_fs,
39383 - .remount_fs = aufs_remount_fs
39384 + .remount_fs = aufs_remount_fs,
39385 +#ifdef CONFIG_AUFS_BDEV_LOOP
39386 + .real_loop = aufs_real_loop
39390 /* ---------------------------------------------------------------------- */
39391 diff --git a/include/linux/fs.h b/include/linux/fs.h
39392 index 4fa4b24535fde..2aec4bc9f5aa1 100644
39393 --- a/include/linux/fs.h
39394 +++ b/include/linux/fs.h
39395 @@ -2041,6 +2041,10 @@ struct super_operations {
39396 struct shrink_control *);
39397 long (*free_cached_objects)(struct super_block *,
39398 struct shrink_control *);
39399 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39401 + struct file *(*real_loop)(struct file *);