1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a7749c126b8e2..12fd57d4aa57e 100644
8 @@ -307,6 +307,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 f98f3e691c376..5e9aaa284700e 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 d7b4f32875a94..6c23696108031 100644
32 @@ -3089,6 +3089,19 @@ F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda <ojeda@kernel.org>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index f0cdff0c5fbf4..e65f941a4181a 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -810,6 +810,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 cf871a81f4fdc..bc5095b734f58 100644
85 @@ -1320,7 +1320,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index f946bec8f1f1b..a44da05bcb9a6 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 c93500d84264d..f24d21236ad01 100644
120 @@ -1778,7 +1778,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 97adcb5ab5d55..4f543907c8200 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 640574294216c..ffeed3ccd2d62 100644
189 --- a/include/linux/fs.h
190 +++ b/include/linux/fs.h
191 @@ -1335,6 +1335,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 @@ -2043,6 +2044,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 @@ -2564,6 +2566,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 @@ -2810,6 +2813,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 5cf3878137549..59b65e1a9e85c 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 bf1c00c881e48..e0aaf34974df5 100644
273 --- a/kernel/locking/lockdep.c
274 +++ b/kernel/locking/lockdep.c
275 @@ -189,7 +189,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 @@ -210,6 +210,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 e5b5f7709d48f..4394d8c1bdad8 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 eb97468dfe4ca..570f1003a7dc6 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 @@ -1866,7 +1869,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 7ca22e6e694a8..c7c40fd7f65a6 100644
367 --- a/include/linux/mm.h
368 +++ b/include/linux/mm.h
369 @@ -1805,6 +1805,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 52bbd2b7cb465..aeb888d448055 100644
400 --- a/include/linux/mm_types.h
401 +++ b/include/linux/mm_types.h
402 @@ -286,6 +286,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 @@ -365,6 +366,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 44f4c2d83763f..dc1b528f962ce 100644
422 @@ -559,7 +559,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 e3436741d5391..0d1dc7789d640 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 d1458ecf2f51e..6ab6b7d72466e 100644
448 @@ -3240,7 +3240,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 ca54d36d203ae..43a69a77914f5 100644
461 @@ -185,7 +185,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 @@ -955,7 +955,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 @@ -1898,7 +1898,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 @@ -2758,7 +2758,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 @@ -2777,7 +2777,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 @@ -2972,7 +2972,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 @@ -3031,10 +3031,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
516 if (vma->vm_flags & VM_LOCKED)
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 @@ -3315,7 +3332,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 3a93d40548104..501a874fedcb0 100644
557 @@ -523,7 +523,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 @@ -655,7 +655,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 @@ -1178,7 +1178,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 @@ -1255,10 +1255,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..511543ab1b418
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-2021 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.14 standalone patch
692 diff --git a/fs/dcache.c b/fs/dcache.c
693 index bc5095b734f58..9508bd57a3bc0 100644
696 @@ -1425,6 +1425,7 @@ void d_walk(struct dentry *parent, void *data,
700 +EXPORT_SYMBOL_GPL(d_walk);
703 struct vfsmount *mnt;
704 @@ -2970,6 +2971,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 38f63451b9282..7710637ed0bc9 100644
716 @@ -111,6 +111,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 a44da05bcb9a6..a9cf3ad532923 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 f24d21236ad01..78de5b5dc0840 100644
760 @@ -1784,6 +1784,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 4f543907c8200..74d756a79cb72 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 @@ -2018,6 +2020,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 fb89c351295d6..460ad19c2570a 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 94bef26ff1b61..33412587d76dd 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 5c8c5175b385c..ff7e9ff774b73 100644
876 @@ -384,6 +384,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 e0aaf34974df5..d7b737731d4ef 100644
886 --- a/kernel/locking/lockdep.c
887 +++ b/kernel/locking/lockdep.c
888 @@ -210,6 +210,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 1698fbe6f0e13..081b05acadf82 100644
898 --- a/kernel/task_work.c
899 +++ b/kernel/task_work.c
900 @@ -167,3 +167,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 9ffa9e9c5c554..83b533a3fb8e8 100644
907 --- a/security/security.c
908 +++ b/security/security.c
909 @@ -1147,6 +1147,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 @@ -1163,6 +1164,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 @@ -1171,6 +1173,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 @@ -1198,6 +1201,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 @@ -1205,6 +1209,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 @@ -1212,6 +1217,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 @@ -1312,6 +1318,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 @@ -1509,6 +1516,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-09-06 21:02:45.273492232 +0200
1072 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
1247 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
1509 +# Copyright (C) 2015-2021 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-09-06 21:02:45.273492232 +0200
1598 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
1715 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
1793 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
1896 +# Copyright (C) 2017-2021 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-09-06 21:02:45.273492232 +0200
2002 +# Copyright (C) 2011-2021 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-09-06 21:02:45.273492232 +0200
2126 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
2202 +# Copyright (C) 2014-2021 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-09-06 21:02:45.273492232 +0200
2302 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
2364 +# Copyright (C) 2005-2021 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-09-06 21:02:45.273492232 +0200
2420 +# Copyright (C) 2010-2021 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-08-24 09:59:43.048691434 +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.
2654 +- for aufs5.13 and later
2655 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2656 + also a caller of VFS functions for branch filesystems, subclassing of
2657 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2658 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2659 + need to customize some LOCKDEP numbers. Here are what I use on my
2661 + CONFIG_LOCKDEP_BITS=21
2662 + CONFIG_LOCKDEP_CHAINS_BITS=21
2663 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2665 +For aufs5-standalone tree,
2666 +There are several ways to build.
2669 +- apply ./aufs5-kbuild.patch to your kernel source files.
2670 +- apply ./aufs5-base.patch too.
2671 +- apply ./aufs5-mmap.patch too.
2672 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2673 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2674 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2675 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2676 +- enable CONFIG_AUFS_FS, you can select either
2678 +- and build your kernel as usual.
2679 +- install the built kernel.
2680 +- install the header files too by "make headers_install" to the
2681 + directory where you specify. By default, it is $PWD/usr.
2682 + "make help" shows a brief note for headers_install.
2683 +- and reboot your system.
2686 +- module only (CONFIG_AUFS_FS=m).
2687 +- apply ./aufs5-base.patch to your kernel source files.
2688 +- apply ./aufs5-mmap.patch too.
2689 +- apply ./aufs5-standalone.patch too.
2690 +- build your kernel, don't forget "make headers_install", and reboot.
2691 +- edit ./config.mk and set other aufs configurations if necessary.
2692 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2693 + every aufs configurations.
2694 +- build the module by simple "make".
2695 +- you can specify ${KDIR} make variable which points to your kernel
2697 +- install the files
2698 + + run "make install" to install the aufs module, or copy the built
2699 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2700 + + run "make install_headers" (instead of headers_install) to install
2701 + the modified aufs header file (you can specify DESTDIR which is
2702 + available in aufs standalone version's Makefile only), or copy
2703 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2704 + you like manually. By default, the target directory is $PWD/usr.
2705 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2706 + kernel source tree.
2708 +Note: The header file aufs_type.h is necessary to build aufs-util
2709 + as well as "make headers_install" in the kernel source tree.
2710 + headers_install is subject to be forgotten, but it is essentially
2711 + necessary, not only for building aufs-util.
2712 + You may not meet problems without headers_install in some older
2716 +- read README in aufs-util, build and install it
2717 +- note that your distribution may contain an obsoleted version of
2718 + aufs_type.h in /usr/include/linux or something. When you build aufs
2719 + utilities, make sure that your compiler refers the correct aufs header
2720 + file which is built by "make headers_install."
2721 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2722 + then run "make install_ulib" too. And refer to the aufs manual in
2725 +There several other patches in aufs5-standalone.git. They are all
2726 +optional. When you meet some problems, they will help you.
2727 +- aufs5-loopback.patch
2728 + Supports a nested loopback mount in a branch-fs. This patch is
2729 + unnecessary until aufs produces a message like "you may want to try
2730 + another patch for loopback file".
2732 + Modifies a system global kernel internal function get_next_ino() in
2733 + order to stop assigning 0 for an inode-number. Not directly related to
2734 + aufs, but recommended generally.
2736 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2737 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2738 + duplication of inode number, which is important for backup tools and
2739 + other utilities. When you find aufs XINO files for tmpfs branch
2740 + growing too much, try this patch.
2744 +----------------------------------------
2745 +At first, make sure aufs-util are installed, and please read the aufs
2746 +manual, aufs.5 in aufs-util.git tree.
2750 +$ mkdir /tmp/rw /tmp/aufs
2751 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2753 +Here is another example. The result is equivalent.
2754 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2756 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2757 +# mount -o remount,append:${HOME} /tmp/aufs
2759 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2760 +you modify a file under /tmp/aufs, the one on your home directory is
2761 +not affected, instead the same named file will be newly created under
2762 +/tmp/rw. And all of your modification to a file will be applied to
2763 +the one under /tmp/rw. This is called the file based Copy on Write
2765 +Aufs mount options are described in aufs.5.
2766 +If you run chroot or something and make your aufs as a root directory,
2767 +then you need to customize the shutdown script. See the aufs manual in
2770 +Additionally, there are some sample usages of aufs which are a
2771 +diskless system with network booting, and LiveCD over NFS.
2772 +See sample dir in CVS tree on SourceForge.
2776 +----------------------------------------
2777 +When you have any problems or strange behaviour in aufs, please let me
2779 +- /proc/mounts (instead of the output of mount(8))
2780 +- /sys/module/aufs/*
2781 +- /sys/fs/aufs/* (if you have them)
2782 +- /debug/aufs/* (if you have them)
2783 +- linux kernel version
2784 + if your kernel is not plain, for example modified by distributor,
2785 + the url where i can download its source is necessary too.
2786 +- aufs version which was printed at loading the module or booting the
2787 + system, instead of the date you downloaded.
2788 +- configuration (define/undefine CONFIG_AUFS_xxx)
2789 +- kernel configuration or /proc/config.gz (if you have it)
2790 +- LSM (linux security module, if you are using)
2791 +- behaviour which you think to be incorrect
2792 +- actual operation, reproducible one is better
2793 +- mailto: aufs-users at lists.sourceforge.net
2795 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2796 +and Feature Requests) on SourceForge. Please join and write to
2800 +6. Acknowledgements
2801 +----------------------------------------
2802 +Thanks to everyone who have tried and are using aufs, whoever
2803 +have reported a bug or any feedback.
2805 +Especially donators:
2806 +Tomas Matejicek(slax.org) made a donation (much more than once).
2807 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2808 + scripts) is making "doubling" donations.
2809 + Unfortunately I cannot list all of the donators, but I really
2811 + It ends Aug 2010, but the ordinary donation URL is still available.
2812 + <http://sourceforge.net/donate/index.php?group_id=167503>
2813 +Dai Itasaka made a donation (2007/8).
2814 +Chuck Smith made a donation (2008/4, 10 and 12).
2815 +Henk Schoneveld made a donation (2008/9).
2816 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2817 +Francois Dupoux made a donation (2008/11).
2818 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2819 + aufs2 GIT tree (2009/2).
2820 +William Grant made a donation (2009/3).
2821 +Patrick Lane made a donation (2009/4).
2822 +The Mail Archive (mail-archive.com) made donations (2009/5).
2823 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2824 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2825 +Pavel Pronskiy made a donation (2011/2).
2826 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2827 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2828 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2830 +Sam Liddicott made a donation (2011/9).
2831 +Era Scarecrow made a donation (2013/4).
2832 +Bor Ratajc made a donation (2013/4).
2833 +Alessandro Gorreta made a donation (2013/4).
2834 +POIRETTE Marc made a donation (2013/4).
2835 +Alessandro Gorreta made a donation (2013/4).
2836 +lauri kasvandik made a donation (2013/5).
2837 +"pemasu from Finland" made a donation (2013/7).
2838 +The Parted Magic Project made a donation (2013/9 and 11).
2839 +Pavel Barta made a donation (2013/10).
2840 +Nikolay Pertsev made a donation (2014/5).
2841 +James B made a donation (2014/7 and 2015/7).
2842 +Stefano Di Biase made a donation (2014/8).
2843 +Daniel Epellei made a donation (2015/1).
2844 +OmegaPhil made a donation (2016/1, 2018/4).
2845 +Tomasz Szewczyk made a donation (2016/4).
2846 +James Burry made a donation (2016/12).
2847 +Carsten Rose made a donation (2018/9).
2848 +Porteus Kiosk made a donation (2018/10).
2850 +Thank you very much.
2851 +Donations are always, including future donations, very important and
2852 +helpful for me to keep on developing aufs.
2856 +----------------------------------------
2857 +If you are an experienced user, no explanation is needed. Aufs is
2858 +just a linux filesystem.
2863 +# Local variables: ;
2866 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2867 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2868 +++ linux/fs/aufs/aufs.h 2021-09-06 21:02:45.273492232 +0200
2870 +/* SPDX-License-Identifier: GPL-2.0 */
2872 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2874 + * This program, aufs is free software; you can redistribute it and/or modify
2875 + * it under the terms of the GNU General Public License as published by
2876 + * the Free Software Foundation; either version 2 of the License, or
2877 + * (at your option) any later version.
2879 + * This program is distributed in the hope that it will be useful,
2880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2882 + * GNU General Public License for more details.
2884 + * You should have received a copy of the GNU General Public License
2885 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2889 + * all header files
2897 +#define AuStub(type, name, body, ...) \
2898 + static inline type name(__VA_ARGS__) { body; }
2900 +#define AuStubVoid(name, ...) \
2901 + AuStub(void, name, , __VA_ARGS__)
2902 +#define AuStubInt0(name, ...) \
2903 + AuStub(int, name, return 0, __VA_ARGS__)
2907 +#include "branch.h"
2910 +#include "dbgaufs.h"
2911 +#include "dentry.h"
2913 +#include "dirren.h"
2916 +#include "fstype.h"
2921 +#include "module.h"
2925 +#include "sysaufs.h"
2930 +#endif /* __KERNEL__ */
2931 +#endif /* __AUFS_H__ */
2932 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2933 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2934 +++ linux/fs/aufs/branch.c 2021-09-06 21:02:45.273492232 +0200
2936 +// SPDX-License-Identifier: GPL-2.0
2938 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2940 + * This program, aufs is free software; you can redistribute it and/or modify
2941 + * it under the terms of the GNU General Public License as published by
2942 + * the Free Software Foundation; either version 2 of the License, or
2943 + * (at your option) any later version.
2945 + * This program is distributed in the hope that it will be useful,
2946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2948 + * GNU General Public License for more details.
2950 + * You should have received a copy of the GNU General Public License
2951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2955 + * branch management
2958 +#include <linux/compat.h>
2959 +#include <linux/statfs.h>
2963 + * free a single branch
2965 +static void au_br_do_free(struct au_branch *br)
2968 + struct au_wbr *wbr;
2969 + struct au_dykey **key;
2971 + au_hnotify_fin_br(br);
2972 + /* always, regardless the mount option */
2973 + au_dr_hino_free(&br->br_dirren);
2976 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2977 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2978 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2979 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2983 + for (i = 0; i < AuBrWh_Last; i++)
2984 + dput(wbr->wbr_wh[i]);
2985 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2986 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2989 + if (br->br_fhsm) {
2990 + au_br_fhsm_fin(br->br_fhsm);
2991 + au_kfree_try_rcu(br->br_fhsm);
2994 + key = br->br_dykey;
2995 + for (i = 0; i < AuBrDynOp; i++, key++)
3001 + /* recursive lock, s_umount of branch's */
3002 + /* synchronize_rcu(); */ /* why? */
3004 + path_put(&br->br_path);
3006 + au_kfree_rcu(wbr);
3007 + au_lcnt_wait_for_fin(&br->br_nfiles);
3008 + au_lcnt_wait_for_fin(&br->br_count);
3009 + /* I don't know why, but percpu_refcount requires this */
3010 + /* synchronize_rcu(); */
3015 + * frees all branches
3017 +void au_br_free(struct au_sbinfo *sbinfo)
3019 + aufs_bindex_t bmax;
3020 + struct au_branch **br;
3022 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3024 + bmax = sbinfo->si_bbot + 1;
3025 + br = sbinfo->si_branch;
3027 + au_br_do_free(*br++);
3031 + * find the index of a branch which is specified by @br_id.
3033 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3035 + aufs_bindex_t bindex, bbot;
3037 + bbot = au_sbbot(sb);
3038 + for (bindex = 0; bindex <= bbot; bindex++)
3039 + if (au_sbr_id(sb, bindex) == br_id)
3044 +/* ---------------------------------------------------------------------- */
3050 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3051 + struct dentry *h_root)
3053 + if (unlikely(h_adding == h_root
3054 + || au_test_loopback_overlap(sb, h_adding)))
3056 + if (h_adding->d_sb != h_root->d_sb)
3058 + return au_test_subdir(h_adding, h_root)
3059 + || au_test_subdir(h_root, h_adding);
3063 + * returns a newly allocated branch. @new_nbranch is a number of branches
3064 + * after adding a branch.
3066 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3069 + struct au_branch *add_branch;
3070 + struct dentry *root;
3071 + struct inode *inode;
3075 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3076 + if (unlikely(!add_branch))
3078 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3079 + if (unlikely(!add_branch->br_xino))
3081 + err = au_hnotify_init_br(add_branch, perm);
3082 + if (unlikely(err))
3085 + if (au_br_writable(perm)) {
3086 + /* may be freed separately at changing the branch permission */
3087 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3089 + if (unlikely(!add_branch->br_wbr))
3093 + if (au_br_fhsm(perm)) {
3094 + err = au_fhsm_br_alloc(add_branch);
3095 + if (unlikely(err))
3099 + root = sb->s_root;
3100 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3102 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3104 + inode = d_inode(root);
3105 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3109 + return add_branch; /* success */
3112 + au_kfree_rcu(add_branch->br_wbr);
3114 + au_hnotify_fin_br(add_branch);
3116 + au_xino_put(add_branch);
3118 + au_kfree_rcu(add_branch);
3120 + return ERR_PTR(err);
3124 + * test if the branch permission is legal or not.
3126 +static int test_br(struct inode *inode, int brperm, char *path)
3130 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3135 + pr_err("write permission for readonly mount or inode, %s\n", path);
3143 + * 0: success, the caller will add it
3144 + * plus: success, it is already unified, the caller should ignore it
3147 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3150 + aufs_bindex_t bbot, bindex;
3151 + struct dentry *root, *h_dentry;
3152 + struct inode *inode, *h_inode;
3154 + root = sb->s_root;
3155 + bbot = au_sbbot(sb);
3156 + if (unlikely(bbot >= 0
3157 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3161 + pr_err("%s duplicated\n", add->pathname);
3166 + err = -ENOSPC; /* -E2BIG; */
3167 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3168 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3169 + pr_err("number of branches exceeded %s\n", add->pathname);
3174 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3175 + pr_err("bad index %d\n", add->bindex);
3179 + inode = d_inode(add->path.dentry);
3181 + if (unlikely(!inode->i_nlink)) {
3182 + pr_err("no existence %s\n", add->pathname);
3187 + if (unlikely(inode->i_sb == sb)) {
3188 + pr_err("%s must be outside\n", add->pathname);
3192 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3193 + pr_err("unsupported filesystem, %s (%s)\n",
3194 + add->pathname, au_sbtype(inode->i_sb));
3198 + if (unlikely(inode->i_sb->s_stack_depth)) {
3199 + pr_err("already stacked, %s (%s)\n",
3200 + add->pathname, au_sbtype(inode->i_sb));
3204 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3205 + if (unlikely(err))
3209 + return 0; /* success */
3212 + for (bindex = 0; bindex <= bbot; bindex++)
3213 + if (unlikely(test_overlap(sb, add->path.dentry,
3214 + au_h_dptr(root, bindex)))) {
3215 + pr_err("%s is overlapped\n", add->pathname);
3220 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3221 + h_dentry = au_h_dptr(root, 0);
3222 + h_inode = d_inode(h_dentry);
3223 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3224 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3225 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3226 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3228 + i_uid_read(inode), i_gid_read(inode),
3229 + (inode->i_mode & S_IALLUGO),
3230 + i_uid_read(h_inode), i_gid_read(h_inode),
3231 + (h_inode->i_mode & S_IALLUGO));
3239 + * initialize or clean the whiteouts for an adding branch
3241 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3244 + int err, old_perm;
3245 + aufs_bindex_t bindex;
3246 + struct inode *h_inode;
3247 + struct au_wbr *wbr;
3248 + struct au_hinode *hdir;
3249 + struct dentry *h_dentry;
3251 + err = vfsub_mnt_want_write(au_br_mnt(br));
3252 + if (unlikely(err))
3256 + old_perm = br->br_perm;
3257 + br->br_perm = new_perm;
3260 + bindex = au_br_index(sb, br->br_id);
3261 + if (0 <= bindex) {
3262 + hdir = au_hi(d_inode(sb->s_root), bindex);
3263 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3265 + h_dentry = au_br_dentry(br);
3266 + h_inode = d_inode(h_dentry);
3267 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3270 + err = au_wh_init(br, sb);
3272 + wbr_wh_write_lock(wbr);
3273 + err = au_wh_init(br, sb);
3274 + wbr_wh_write_unlock(wbr);
3277 + au_hn_inode_unlock(hdir);
3279 + inode_unlock(h_inode);
3280 + vfsub_mnt_drop_write(au_br_mnt(br));
3281 + br->br_perm = old_perm;
3283 + if (!err && wbr && !au_br_writable(new_perm)) {
3284 + au_kfree_rcu(wbr);
3285 + br->br_wbr = NULL;
3292 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3296 + struct kstatfs kst;
3297 + struct au_wbr *wbr;
3300 + au_rw_init(&wbr->wbr_wh_rwsem);
3301 + atomic_set(&wbr->wbr_wh_running, 0);
3304 + * a limit for rmdir/rename a dir
3305 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3307 + err = vfs_statfs(&br->br_path, &kst);
3308 + if (unlikely(err))
3311 + if (kst.f_namelen >= NAME_MAX)
3312 + err = au_br_init_wh(sb, br, perm);
3314 + pr_err("%pd(%s), unsupported namelen %ld\n",
3316 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3322 +/* initialize a new branch */
3323 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3324 + struct au_opt_add *add)
3327 + struct au_branch *brbase;
3329 + struct inode *h_inode;
3332 + br->br_perm = add->perm;
3333 + br->br_path = add->path; /* set first, path_get() later */
3334 + spin_lock_init(&br->br_dykey_lock);
3335 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3336 + au_lcnt_init(&br->br_count, /*release*/NULL);
3337 + br->br_id = au_new_br_id(sb);
3338 + AuDebugOn(br->br_id < 0);
3340 + /* always, regardless the given option */
3341 + err = au_dr_br_init(sb, br, &add->path);
3342 + if (unlikely(err))
3345 + if (au_br_writable(add->perm)) {
3346 + err = au_wbr_init(br, sb, add->perm);
3347 + if (unlikely(err))
3351 + if (au_opt_test(au_mntflags(sb), XINO)) {
3352 + brbase = au_sbr(sb, 0);
3353 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3355 + h_inode = d_inode(add->path.dentry);
3356 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3357 + if (unlikely(err)) {
3358 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3363 + sysaufs_br_init(br);
3364 + path_get(&br->br_path);
3365 + goto out; /* success */
3368 + memset(&br->br_path, 0, sizeof(br->br_path));
3373 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3374 + struct au_branch *br, aufs_bindex_t bbot,
3375 + aufs_bindex_t amount)
3377 + struct au_branch **brp;
3379 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3381 + brp = sbinfo->si_branch + bindex;
3382 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3384 + sbinfo->si_bbot++;
3385 + if (unlikely(bbot < 0))
3386 + sbinfo->si_bbot = 0;
3389 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3390 + aufs_bindex_t bbot, aufs_bindex_t amount)
3392 + struct au_hdentry *hdp;
3394 + AuRwMustWriteLock(&dinfo->di_rwsem);
3396 + hdp = au_hdentry(dinfo, bindex);
3397 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3398 + au_h_dentry_init(hdp);
3400 + if (unlikely(bbot < 0))
3401 + dinfo->di_btop = 0;
3404 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3405 + aufs_bindex_t bbot, aufs_bindex_t amount)
3407 + struct au_hinode *hip;
3409 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3411 + hip = au_hinode(iinfo, bindex);
3412 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3413 + au_hinode_init(hip);
3415 + if (unlikely(bbot < 0))
3416 + iinfo->ii_btop = 0;
3419 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3420 + aufs_bindex_t bindex)
3422 + struct dentry *root, *h_dentry;
3423 + struct inode *root_inode, *h_inode;
3424 + aufs_bindex_t bbot, amount;
3426 + root = sb->s_root;
3427 + root_inode = d_inode(root);
3428 + bbot = au_sbbot(sb);
3429 + amount = bbot + 1 - bindex;
3430 + h_dentry = au_br_dentry(br);
3431 + au_sbilist_lock();
3432 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3433 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3434 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3435 + au_set_h_dptr(root, bindex, dget(h_dentry));
3436 + h_inode = d_inode(h_dentry);
3437 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3438 + au_sbilist_unlock();
3441 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3444 + aufs_bindex_t bbot, add_bindex;
3445 + struct dentry *root, *h_dentry;
3446 + struct inode *root_inode;
3447 + struct au_branch *add_branch;
3449 + root = sb->s_root;
3450 + root_inode = d_inode(root);
3451 + IMustLock(root_inode);
3452 + IiMustWriteLock(root_inode);
3453 + err = test_add(sb, add, remount);
3454 + if (unlikely(err < 0))
3458 + goto out; /* success */
3461 + bbot = au_sbbot(sb);
3462 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3463 + err = PTR_ERR(add_branch);
3464 + if (IS_ERR(add_branch))
3467 + err = au_br_init(add_branch, sb, add);
3468 + if (unlikely(err)) {
3469 + au_br_do_free(add_branch);
3473 + add_bindex = add->bindex;
3474 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3475 + au_br_do_add(sb, add_branch, add_bindex);
3476 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3477 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3479 + h_dentry = add->path.dentry;
3480 + if (!add_bindex) {
3481 + au_cpup_attr_all(root_inode, /*force*/1);
3482 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3484 + au_add_nlink(root_inode, d_inode(h_dentry));
3490 +/* ---------------------------------------------------------------------- */
3492 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3493 + unsigned long long max __maybe_unused,
3496 + unsigned long long n;
3497 + struct file **p, *f;
3498 + struct hlist_bl_head *files;
3499 + struct hlist_bl_node *pos;
3500 + struct au_finfo *finfo;
3504 + files = &au_sbi(sb)->si_files;
3505 + hlist_bl_lock(files);
3506 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3507 + f = finfo->fi_file;
3509 + && !special_file(file_inode(f)->i_mode)) {
3513 + AuDebugOn(n > max);
3516 + hlist_bl_unlock(files);
3521 +static struct file **au_farray_alloc(struct super_block *sb,
3522 + unsigned long long *max)
3524 + struct au_sbinfo *sbi;
3527 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3528 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3531 +static void au_farray_free(struct file **a, unsigned long long max)
3533 + unsigned long long ull;
3535 + for (ull = 0; ull < max; ull++)
3541 +/* ---------------------------------------------------------------------- */
3547 +/* to show the line number, do not make it inlined function */
3548 +#define AuVerbose(do_info, fmt, ...) do { \
3550 + pr_info(fmt, ##__VA_ARGS__); \
3553 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3554 + aufs_bindex_t bbot)
3556 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3559 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3560 + aufs_bindex_t bbot)
3562 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3566 + * test if the branch is deletable or not.
3568 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3569 + unsigned int sigen, const unsigned int verbose)
3571 + int err, i, j, ndentry;
3572 + aufs_bindex_t btop, bbot;
3573 + struct au_dcsub_pages dpages;
3574 + struct au_dpage *dpage;
3577 + err = au_dpages_init(&dpages, GFP_NOFS);
3578 + if (unlikely(err))
3580 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3581 + if (unlikely(err))
3584 + for (i = 0; !err && i < dpages.ndpage; i++) {
3585 + dpage = dpages.dpages + i;
3586 + ndentry = dpage->ndentry;
3587 + for (j = 0; !err && j < ndentry; j++) {
3588 + d = dpage->dentries[j];
3589 + AuDebugOn(au_dcount(d) <= 0);
3590 + if (!au_digen_test(d, sigen)) {
3591 + di_read_lock_child(d, AuLock_IR);
3592 + if (unlikely(au_dbrange_test(d))) {
3593 + di_read_unlock(d, AuLock_IR);
3597 + di_write_lock_child(d);
3598 + if (unlikely(au_dbrange_test(d))) {
3599 + di_write_unlock(d);
3602 + err = au_reval_dpath(d, sigen);
3604 + di_downgrade_lock(d, AuLock_IR);
3606 + di_write_unlock(d);
3611 + /* AuDbgDentry(d); */
3612 + btop = au_dbtop(d);
3613 + bbot = au_dbbot(d);
3614 + if (btop <= bindex
3616 + && au_h_dptr(d, bindex)
3617 + && au_test_dbusy(d, btop, bbot)) {
3619 + AuVerbose(verbose, "busy %pd\n", d);
3622 + di_read_unlock(d, AuLock_IR);
3627 + au_dpages_free(&dpages);
3632 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3633 + unsigned int sigen, const unsigned int verbose)
3636 + unsigned long long max, ull;
3637 + struct inode *i, **array;
3638 + aufs_bindex_t btop, bbot;
3640 + array = au_iarray_alloc(sb, &max);
3641 + err = PTR_ERR(array);
3642 + if (IS_ERR(array))
3646 + AuDbg("b%d\n", bindex);
3647 + for (ull = 0; !err && ull < max; ull++) {
3651 + if (i->i_ino == AUFS_ROOT_INO)
3654 + /* AuDbgInode(i); */
3655 + if (au_iigen(i, NULL) == sigen)
3656 + ii_read_lock_child(i);
3658 + ii_write_lock_child(i);
3659 + err = au_refresh_hinode_self(i);
3662 + ii_downgrade_lock(i);
3664 + ii_write_unlock(i);
3669 + btop = au_ibtop(i);
3670 + bbot = au_ibbot(i);
3671 + if (btop <= bindex
3673 + && au_h_iptr(i, bindex)
3674 + && au_test_ibusy(i, btop, bbot)) {
3676 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3679 + ii_read_unlock(i);
3681 + au_iarray_free(array, max);
3687 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3688 + const unsigned int verbose)
3691 + unsigned int sigen;
3693 + sigen = au_sigen(root->d_sb);
3694 + DiMustNoWaiters(root);
3695 + IiMustNoWaiters(d_inode(root));
3696 + di_write_unlock(root);
3697 + err = test_dentry_busy(root, bindex, sigen, verbose);
3699 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3700 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3705 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3706 + struct file **to_free, int *idx)
3709 + unsigned char matched, root;
3710 + aufs_bindex_t bindex, bbot;
3711 + struct au_fidir *fidir;
3712 + struct au_hfile *hfile;
3715 + root = IS_ROOT(file->f_path.dentry);
3718 + to_free[*idx] = file;
3724 + fidir = au_fi(file)->fi_hdir;
3725 + AuDebugOn(!fidir);
3726 + bbot = au_fbbot_dir(file);
3727 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3728 + hfile = fidir->fd_hfile + bindex;
3729 + if (!hfile->hf_file)
3732 + if (hfile->hf_br->br_id == br_id) {
3744 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3745 + struct file **to_free, int opened)
3748 + unsigned long long ull, max;
3749 + aufs_bindex_t btop;
3750 + struct file *file, **array;
3751 + struct dentry *root;
3752 + struct au_hfile *hfile;
3754 + array = au_farray_alloc(sb, &max);
3755 + err = PTR_ERR(array);
3756 + if (IS_ERR(array))
3761 + root = sb->s_root;
3762 + di_write_unlock(root);
3763 + for (ull = 0; ull < max; ull++) {
3764 + file = array[ull];
3765 + if (unlikely(!file))
3768 + /* AuDbg("%pD\n", file); */
3769 + fi_read_lock(file);
3770 + btop = au_fbtop(file);
3771 + if (!d_is_dir(file->f_path.dentry)) {
3772 + hfile = &au_fi(file)->fi_htop;
3773 + if (hfile->hf_br->br_id == br_id)
3776 + err = test_dir_busy(file, br_id, to_free, &idx);
3777 + fi_read_unlock(file);
3778 + if (unlikely(err))
3781 + di_write_lock_child(root);
3782 + au_farray_free(array, max);
3783 + AuDebugOn(idx > opened);
3789 +static void br_del_file(struct file **to_free, unsigned long long opened,
3790 + aufs_bindex_t br_id)
3792 + unsigned long long ull;
3793 + aufs_bindex_t bindex, btop, bbot, bfound;
3794 + struct file *file;
3795 + struct au_fidir *fidir;
3796 + struct au_hfile *hfile;
3798 + for (ull = 0; ull < opened; ull++) {
3799 + file = to_free[ull];
3800 + if (unlikely(!file))
3803 + /* AuDbg("%pD\n", file); */
3804 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3806 + fidir = au_fi(file)->fi_hdir;
3807 + AuDebugOn(!fidir);
3808 + fi_write_lock(file);
3809 + btop = au_fbtop(file);
3810 + bbot = au_fbbot_dir(file);
3811 + for (bindex = btop; bindex <= bbot; bindex++) {
3812 + hfile = fidir->fd_hfile + bindex;
3813 + if (!hfile->hf_file)
3816 + if (hfile->hf_br->br_id == br_id) {
3821 + AuDebugOn(bfound < 0);
3822 + au_set_h_fptr(file, bfound, NULL);
3823 + if (bfound == btop) {
3824 + for (btop++; btop <= bbot; btop++)
3825 + if (au_hf_dir(file, btop)) {
3826 + au_set_fbtop(file, btop);
3830 + fi_write_unlock(file);
3834 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3835 + const aufs_bindex_t bindex,
3836 + const aufs_bindex_t bbot)
3838 + struct au_branch **brp, **p;
3840 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3842 + brp = sbinfo->si_branch + bindex;
3843 + if (bindex < bbot)
3844 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3845 + sbinfo->si_branch[0 + bbot] = NULL;
3846 + sbinfo->si_bbot--;
3848 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3851 + sbinfo->si_branch = p;
3852 + /* harmless error */
3855 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3856 + const aufs_bindex_t bbot)
3858 + struct au_hdentry *hdp, *p;
3860 + AuRwMustWriteLock(&dinfo->di_rwsem);
3862 + hdp = au_hdentry(dinfo, bindex);
3863 + if (bindex < bbot)
3864 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3865 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3868 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3871 + dinfo->di_hdentry = p;
3872 + /* harmless error */
3875 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3876 + const aufs_bindex_t bbot)
3878 + struct au_hinode *hip, *p;
3880 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3882 + hip = au_hinode(iinfo, bindex);
3883 + if (bindex < bbot)
3884 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3885 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3888 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3891 + iinfo->ii_hinode = p;
3892 + /* harmless error */
3895 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3896 + struct au_branch *br)
3898 + aufs_bindex_t bbot;
3899 + struct au_sbinfo *sbinfo;
3900 + struct dentry *root, *h_root;
3901 + struct inode *inode, *h_inode;
3902 + struct au_hinode *hinode;
3904 + SiMustWriteLock(sb);
3906 + root = sb->s_root;
3907 + inode = d_inode(root);
3908 + sbinfo = au_sbi(sb);
3909 + bbot = sbinfo->si_bbot;
3911 + h_root = au_h_dptr(root, bindex);
3912 + hinode = au_hi(inode, bindex);
3913 + h_inode = au_igrab(hinode->hi_inode);
3916 + au_sbilist_lock();
3917 + au_br_do_del_brp(sbinfo, bindex, bbot);
3918 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3919 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3920 + au_sbilist_unlock();
3922 + /* ignore an error */
3923 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3927 + au_br_do_free(br);
3930 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3931 + unsigned long long max, void *arg)
3936 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3939 + unsigned long long opened;
3940 + unsigned int mnt_flags;
3941 + aufs_bindex_t bindex, bbot, br_id;
3942 + unsigned char do_wh, verbose;
3943 + struct au_branch *br;
3944 + struct au_wbr *wbr;
3945 + struct dentry *root;
3946 + struct file **to_free;
3951 + root = sb->s_root;
3952 + bindex = au_find_dbindex(root, del->h_path.dentry);
3955 + goto out; /* success */
3957 + pr_err("%s no such branch\n", del->pathname);
3960 + AuDbg("bindex b%d\n", bindex);
3963 + mnt_flags = au_mntflags(sb);
3964 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3965 + bbot = au_sbbot(sb);
3966 + if (unlikely(!bbot)) {
3967 + AuVerbose(verbose, "no more branches left\n");
3971 + br = au_sbr(sb, bindex);
3972 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3973 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3974 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3978 + br_id = br->br_id;
3979 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3980 + if (unlikely(opened)) {
3981 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3982 + err = PTR_ERR(to_free);
3983 + if (IS_ERR(to_free))
3986 + err = test_file_busy(sb, br_id, to_free, opened);
3987 + if (unlikely(err)) {
3988 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3994 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3996 + /* instead of WbrWhMustWriteLock(wbr) */
3997 + SiMustWriteLock(sb);
3998 + for (i = 0; i < AuBrWh_Last; i++) {
3999 + dput(wbr->wbr_wh[i]);
4000 + wbr->wbr_wh[i] = NULL;
4004 + err = test_children_busy(root, bindex, verbose);
4005 + if (unlikely(err)) {
4014 + * now we confirmed the branch is deletable.
4015 + * let's free the remaining opened dirs on the branch.
4017 + di_write_unlock(root);
4018 + br_del_file(to_free, opened, br_id);
4019 + di_write_lock_child(root);
4022 + sysaufs_brs_del(sb, bindex); /* remove successors */
4023 + dbgaufs_xino_del(br); /* remove one */
4024 + au_br_do_del(sb, bindex, br);
4025 + sysaufs_brs_add(sb, bindex); /* append successors */
4026 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4029 + au_cpup_attr_all(d_inode(root), /*force*/1);
4030 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4032 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4033 + if (au_opt_test(mnt_flags, PLINK))
4034 + au_plink_half_refresh(sb, br_id);
4036 + goto out; /* success */
4040 + rerr = au_br_init_wh(sb, br, br->br_perm);
4042 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4043 + del->pathname, rerr);
4046 + au_farray_free(to_free, opened);
4050 +/* ---------------------------------------------------------------------- */
4052 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4055 + aufs_bindex_t btop, bbot;
4056 + struct aufs_ibusy ibusy;
4057 + struct inode *inode, *h_inode;
4060 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4063 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4065 + /* VERIFY_WRITE */
4066 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4067 + if (unlikely(err)) {
4074 + si_read_lock(sb, AuLock_FLUSH);
4075 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4079 + ibusy.h_ino = 0; /* invalid */
4080 + inode = ilookup(sb, ibusy.ino);
4082 + || inode->i_ino == AUFS_ROOT_INO
4083 + || au_is_bad_inode(inode))
4086 + ii_read_lock_child(inode);
4087 + btop = au_ibtop(inode);
4088 + bbot = au_ibbot(inode);
4089 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4090 + h_inode = au_h_iptr(inode, ibusy.bindex);
4091 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4092 + ibusy.h_ino = h_inode->i_ino;
4094 + ii_read_unlock(inode);
4098 + si_read_unlock(sb);
4100 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4101 + if (unlikely(err)) {
4110 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4112 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4115 +#ifdef CONFIG_COMPAT
4116 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4118 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4122 +/* ---------------------------------------------------------------------- */
4125 + * change a branch permission
4128 +static void au_warn_ima(void)
4131 + /* since it doesn't support mark_files_ro() */
4132 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4136 +static int do_need_sigen_inc(int a, int b)
4138 + return au_br_whable(a) && !au_br_whable(b);
4141 +static int need_sigen_inc(int old, int new)
4143 + return do_need_sigen_inc(old, new)
4144 + || do_need_sigen_inc(new, old);
4147 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4150 + unsigned int mnt_flags;
4151 + unsigned long long ull, max;
4152 + aufs_bindex_t br_id;
4153 + unsigned char verbose, writer;
4154 + struct file *file, *hf, **array;
4155 + struct au_hfile *hfile;
4156 + struct inode *h_inode;
4158 + mnt_flags = au_mntflags(sb);
4159 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4161 + array = au_farray_alloc(sb, &max);
4162 + err = PTR_ERR(array);
4163 + if (IS_ERR(array))
4167 + br_id = au_sbr_id(sb, bindex);
4168 + for (ull = 0; ull < max; ull++) {
4169 + file = array[ull];
4170 + if (unlikely(!file))
4173 + /* AuDbg("%pD\n", file); */
4174 + fi_read_lock(file);
4175 + if (unlikely(au_test_mmapped(file))) {
4177 + AuVerbose(verbose, "mmapped %pD\n", file);
4179 + FiMustNoWaiters(file);
4180 + fi_read_unlock(file);
4184 + hfile = &au_fi(file)->fi_htop;
4185 + hf = hfile->hf_file;
4186 + if (!d_is_reg(file->f_path.dentry)
4187 + || !(file->f_mode & FMODE_WRITE)
4188 + || hfile->hf_br->br_id != br_id
4189 + || !(hf->f_mode & FMODE_WRITE))
4190 + array[ull] = NULL;
4196 + FiMustNoWaiters(file);
4197 + fi_read_unlock(file);
4205 + for (ull = 0; ull < max; ull++) {
4206 + file = array[ull];
4210 + /* todo: already flushed? */
4212 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4213 + * approach which resets f_mode and calls mnt_drop_write() and
4214 + * file_release_write() for each file, because the branch
4215 + * attribute in aufs world is totally different from the native
4218 + /* fi_read_lock(file); */
4219 + hfile = &au_fi(file)->fi_htop;
4220 + hf = hfile->hf_file;
4221 + /* fi_read_unlock(file); */
4222 + spin_lock(&hf->f_lock);
4223 + writer = !!(hf->f_mode & FMODE_WRITER);
4224 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4225 + spin_unlock(&hf->f_lock);
4227 + h_inode = file_inode(hf);
4228 + if (hf->f_mode & FMODE_READ)
4229 + i_readcount_inc(h_inode);
4230 + put_write_access(h_inode);
4231 + __mnt_drop_write(hf->f_path.mnt);
4236 + au_farray_free(array, max);
4242 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4246 + aufs_bindex_t bindex;
4247 + struct dentry *root;
4248 + struct au_branch *br;
4249 + struct au_br_fhsm *bf;
4251 + root = sb->s_root;
4252 + bindex = au_find_dbindex(root, mod->h_root);
4255 + return 0; /* success */
4257 + pr_err("%s no such branch\n", mod->path);
4260 + AuDbg("bindex b%d\n", bindex);
4262 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4263 + if (unlikely(err))
4266 + br = au_sbr(sb, bindex);
4267 + AuDebugOn(mod->h_root != au_br_dentry(br));
4268 + if (br->br_perm == mod->perm)
4269 + return 0; /* success */
4271 + /* pre-allocate for non-fhsm --> fhsm */
4273 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4274 + err = au_fhsm_br_alloc(br);
4275 + if (unlikely(err))
4278 + br->br_fhsm = NULL;
4281 + if (au_br_writable(br->br_perm)) {
4282 + /* remove whiteout base */
4283 + err = au_br_init_wh(sb, br, mod->perm);
4284 + if (unlikely(err))
4287 + if (!au_br_writable(mod->perm)) {
4288 + /* rw --> ro, file might be mmapped */
4289 + DiMustNoWaiters(root);
4290 + IiMustNoWaiters(d_inode(root));
4291 + di_write_unlock(root);
4292 + err = au_br_mod_files_ro(sb, bindex);
4293 + /* aufs_write_lock() calls ..._child() */
4294 + di_write_lock_child(root);
4296 + if (unlikely(err)) {
4298 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4301 + rerr = au_wbr_init(br, sb, br->br_perm);
4302 + if (unlikely(rerr)) {
4303 + AuIOErr("nested error %d (%d)\n",
4305 + br->br_perm = mod->perm;
4309 + } else if (au_br_writable(mod->perm)) {
4312 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4314 + err = au_wbr_init(br, sb, mod->perm);
4315 + if (unlikely(err)) {
4316 + au_kfree_rcu(br->br_wbr);
4317 + br->br_wbr = NULL;
4321 + if (unlikely(err))
4324 + if (au_br_fhsm(br->br_perm)) {
4325 + if (!au_br_fhsm(mod->perm)) {
4326 + /* fhsm --> non-fhsm */
4327 + au_br_fhsm_fin(br->br_fhsm);
4328 + au_kfree_rcu(br->br_fhsm);
4329 + br->br_fhsm = NULL;
4331 + } else if (au_br_fhsm(mod->perm))
4332 + /* non-fhsm --> fhsm */
4335 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4336 + br->br_perm = mod->perm;
4337 + goto out; /* success */
4340 + au_kfree_try_rcu(bf);
4346 +/* ---------------------------------------------------------------------- */
4348 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4351 + struct kstatfs kstfs;
4353 + err = vfs_statfs(&br->br_path, &kstfs);
4355 + stfs->f_blocks = kstfs.f_blocks;
4356 + stfs->f_bavail = kstfs.f_bavail;
4357 + stfs->f_files = kstfs.f_files;
4358 + stfs->f_ffree = kstfs.f_ffree;
4363 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4364 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4365 +++ linux/fs/aufs/branch.h 2021-09-06 21:02:45.273492232 +0200
4367 +/* SPDX-License-Identifier: GPL-2.0 */
4369 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4371 + * This program, aufs is free software; you can redistribute it and/or modify
4372 + * it under the terms of the GNU General Public License as published by
4373 + * the Free Software Foundation; either version 2 of the License, or
4374 + * (at your option) any later version.
4376 + * This program is distributed in the hope that it will be useful,
4377 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4378 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4379 + * GNU General Public License for more details.
4381 + * You should have received a copy of the GNU General Public License
4382 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4386 + * branch filesystems and xino for them
4389 +#ifndef __AUFS_BRANCH_H__
4390 +#define __AUFS_BRANCH_H__
4394 +#include <linux/mount.h>
4395 +#include "dirren.h"
4401 +/* ---------------------------------------------------------------------- */
4405 + struct file **xi_file;
4406 + unsigned int xi_nfile;
4412 + /* reserved for future use */
4413 + /* unsigned long *bitmap; */
4414 + wait_queue_head_t wqh;
4417 + struct mutex xi_mtx; /* protects xi_file array */
4418 + struct hlist_bl_head xi_writing;
4420 + atomic_t xi_truncating;
4422 + struct kref xi_kref;
4425 +/* File-based Hierarchical Storage Management */
4426 +struct au_br_fhsm {
4427 +#ifdef CONFIG_AUFS_FHSM
4428 + struct mutex bf_lock;
4429 + unsigned long bf_jiffy;
4430 + struct aufs_stfs bf_stfs;
4435 +/* members for writable branch only */
4436 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4438 + struct au_rwsem wbr_wh_rwsem;
4439 + struct dentry *wbr_wh[AuBrWh_Last];
4440 + atomic_t wbr_wh_running;
4441 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4442 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4443 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4446 + unsigned long long wbr_bytes;
4449 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4450 +#define AuBrDynOp (AuDyLast * 4)
4452 +#ifdef CONFIG_AUFS_HFSNOTIFY
4453 +/* support for asynchronous destruction */
4454 +struct au_br_hfsnotify {
4455 + struct fsnotify_group *hfsn_group;
4459 +/* sysfs entries */
4460 +struct au_brsysfs {
4462 + struct attribute attr;
4471 +/* protected by superblock rwsem */
4473 + struct au_xino *br_xino;
4475 + aufs_bindex_t br_id;
4478 + struct path br_path;
4479 + spinlock_t br_dykey_lock;
4480 + struct au_dykey *br_dykey[AuBrDynOp];
4481 + au_lcnt_t br_nfiles; /* opened files */
4482 + au_lcnt_t br_count; /* in-use for other */
4484 + struct au_wbr *br_wbr;
4485 + struct au_br_fhsm *br_fhsm;
4487 +#ifdef CONFIG_AUFS_HFSNOTIFY
4488 + struct au_br_hfsnotify *br_hfsn;
4491 +#ifdef CONFIG_SYSFS
4492 + /* entries under sysfs per mount-point */
4493 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4496 +#ifdef CONFIG_DEBUG_FS
4497 + struct dentry *br_dbgaufs; /* xino */
4500 + struct au_dr_br br_dirren;
4503 +/* ---------------------------------------------------------------------- */
4505 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4507 + return br->br_path.mnt;
4510 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4512 + return br->br_path.dentry;
4515 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4517 + return mnt_user_ns(br->br_path.mnt);
4520 +static inline struct super_block *au_br_sb(struct au_branch *br)
4522 + return au_br_mnt(br)->mnt_sb;
4525 +static inline int au_br_rdonly(struct au_branch *br)
4527 + return (sb_rdonly(au_br_sb(br))
4528 + || !au_br_writable(br->br_perm))
4532 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4534 +#ifdef CONFIG_AUFS_HNOTIFY
4535 + return !(brperm & AuBrPerm_RR);
4541 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4543 + int err, exec_flag;
4546 + exec_flag = oflag & __FMODE_EXEC;
4547 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4553 +static inline void au_xino_get(struct au_branch *br)
4555 + struct au_xino *xi;
4559 + kref_get(&xi->xi_kref);
4562 +static inline int au_xino_count(struct au_branch *br)
4565 + struct au_xino *xi;
4570 + v = kref_read(&xi->xi_kref);
4575 +/* ---------------------------------------------------------------------- */
4579 +void au_br_free(struct au_sbinfo *sinfo);
4580 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4582 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4584 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4585 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4586 +#ifdef CONFIG_COMPAT
4587 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4590 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4593 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4596 +static const loff_t au_loff_max = LLONG_MAX;
4598 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4599 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4601 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4602 + struct file *copy_src);
4604 + struct au_xino *xi; /* switch between xino and xigen */
4606 + struct path *base;
4607 + struct file *copy_src;
4609 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4611 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4613 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4615 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4616 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4618 +int au_xib_trunc(struct super_block *sb);
4619 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4621 +struct au_xino *au_xino_alloc(unsigned int nfile);
4622 +int au_xino_put(struct au_branch *br);
4623 +struct file *au_xino_file1(struct au_xino *xi);
4625 +struct au_opt_xino;
4626 +void au_xino_clr(struct super_block *sb);
4627 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4628 +struct file *au_xino_def(struct super_block *sb);
4629 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4630 + struct path *base);
4632 +ino_t au_xino_new_ino(struct super_block *sb);
4633 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4635 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4636 + ino_t h_ino, int idx);
4637 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4640 +int au_xino_path(struct seq_file *seq, struct file *file);
4642 +/* ---------------------------------------------------------------------- */
4644 +/* @idx is signed to accept -1 meaning the first file */
4645 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4647 + struct file *file;
4654 + if (idx < xi->xi_nfile)
4655 + file = xi->xi_file[idx];
4657 + file = au_xino_file1(xi);
4663 +/* ---------------------------------------------------------------------- */
4665 +/* Superblock to branch */
4667 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4669 + return au_sbr(sb, bindex)->br_id;
4673 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4675 + return au_br_mnt(au_sbr(sb, bindex));
4679 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4681 + return au_br_userns(au_sbr(sb, bindex));
4685 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4687 + return au_br_sb(au_sbr(sb, bindex));
4690 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4692 + return au_sbr(sb, bindex)->br_perm;
4695 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4697 + return au_br_whable(au_sbr_perm(sb, bindex));
4700 +/* ---------------------------------------------------------------------- */
4702 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4703 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4704 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4705 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4707 +#define wbr_wh_read_trylock_nested(wbr) \
4708 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4709 +#define wbr_wh_write_trylock_nested(wbr) \
4710 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4713 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4714 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4715 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4717 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4718 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4719 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4721 +/* ---------------------------------------------------------------------- */
4723 +#ifdef CONFIG_AUFS_FHSM
4724 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4726 + mutex_init(&brfhsm->bf_lock);
4727 + brfhsm->bf_jiffy = 0;
4728 + brfhsm->bf_readable = 0;
4731 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4733 + mutex_destroy(&brfhsm->bf_lock);
4736 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4737 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4740 +#endif /* __KERNEL__ */
4741 +#endif /* __AUFS_BRANCH_H__ */
4742 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4743 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4744 +++ linux/fs/aufs/conf.mk 2021-05-02 20:15:14.670004120 +0200
4746 +# SPDX-License-Identifier: GPL-2.0
4748 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4752 +AuConfStr += ${1}=${${1}}
4756 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4758 + HNOTIFY HFSNOTIFY \
4770 +$(foreach i, ${AuConfAll}, \
4771 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4773 +AuConfName = ${obj}/conf.str
4774 +${AuConfName}.tmp: FORCE
4775 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4776 +${AuConfName}: ${AuConfName}.tmp
4777 + @diff -q $< $@ > /dev/null 2>&1 || { \
4778 + echo ' GEN ' $@; \
4782 +clean-files += ${AuConfName} ${AuConfName}.tmp
4783 +${obj}/sysfs.o: ${AuConfName}
4785 +-include ${srctree}/${src}/conf_priv.mk
4786 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4787 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4788 +++ linux/fs/aufs/cpup.c 2021-09-06 21:02:45.273492232 +0200
4790 +// SPDX-License-Identifier: GPL-2.0
4792 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4794 + * This program, aufs is free software; you can redistribute it and/or modify
4795 + * it under the terms of the GNU General Public License as published by
4796 + * the Free Software Foundation; either version 2 of the License, or
4797 + * (at your option) any later version.
4799 + * This program is distributed in the hope that it will be useful,
4800 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4801 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4802 + * GNU General Public License for more details.
4804 + * You should have received a copy of the GNU General Public License
4805 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4809 + * copy-up functions, see wbr_policy.c for copy-down
4812 +#include <linux/fs_stack.h>
4813 +#include <linux/mm.h>
4814 +#include <linux/task_work.h>
4817 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4819 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4820 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4822 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4824 + dst->i_flags |= iflags & ~mask;
4825 + if (au_test_fs_notime(dst->i_sb))
4826 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4829 +void au_cpup_attr_timesizes(struct inode *inode)
4831 + struct inode *h_inode;
4833 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4834 + fsstack_copy_attr_times(inode, h_inode);
4835 + fsstack_copy_inode_size(inode, h_inode);
4838 +void au_cpup_attr_nlink(struct inode *inode, int force)
4840 + struct inode *h_inode;
4841 + struct super_block *sb;
4842 + aufs_bindex_t bindex, bbot;
4845 + bindex = au_ibtop(inode);
4846 + h_inode = au_h_iptr(inode, bindex);
4848 + && !S_ISDIR(h_inode->i_mode)
4849 + && au_opt_test(au_mntflags(sb), PLINK)
4850 + && au_plink_test(inode))
4854 + * 0 can happen in revalidating.
4855 + * h_inode->i_mutex may not be held here, but it is harmless since once
4856 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4858 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4859 + * the incorrect link count.
4861 + set_nlink(inode, h_inode->i_nlink);
4864 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4865 + * it may includes whplink directory.
4867 + if (S_ISDIR(h_inode->i_mode)) {
4868 + bbot = au_ibbot(inode);
4869 + for (bindex++; bindex <= bbot; bindex++) {
4870 + h_inode = au_h_iptr(inode, bindex);
4872 + au_add_nlink(inode, h_inode);
4877 +void au_cpup_attr_changeable(struct inode *inode)
4879 + struct inode *h_inode;
4881 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4882 + inode->i_mode = h_inode->i_mode;
4883 + inode->i_uid = h_inode->i_uid;
4884 + inode->i_gid = h_inode->i_gid;
4885 + au_cpup_attr_timesizes(inode);
4886 + au_cpup_attr_flags(inode, h_inode->i_flags);
4889 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4891 + struct au_iinfo *iinfo = au_ii(inode);
4893 + IiMustWriteLock(inode);
4895 + iinfo->ii_higen = h_inode->i_generation;
4896 + iinfo->ii_hsb1 = h_inode->i_sb;
4899 +void au_cpup_attr_all(struct inode *inode, int force)
4901 + struct inode *h_inode;
4903 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4904 + au_cpup_attr_changeable(inode);
4905 + if (inode->i_nlink > 0)
4906 + au_cpup_attr_nlink(inode, force);
4907 + inode->i_rdev = h_inode->i_rdev;
4908 + inode->i_blkbits = h_inode->i_blkbits;
4909 + au_cpup_igen(inode, h_inode);
4912 +/* ---------------------------------------------------------------------- */
4914 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4916 +/* keep the timestamps of the parent dir when cpup */
4917 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4918 + struct path *h_path)
4920 + struct inode *h_inode;
4922 + dt->dt_dentry = dentry;
4923 + dt->dt_h_path = *h_path;
4924 + h_inode = d_inode(h_path->dentry);
4925 + dt->dt_atime = h_inode->i_atime;
4926 + dt->dt_mtime = h_inode->i_mtime;
4930 +void au_dtime_revert(struct au_dtime *dt)
4932 + struct iattr attr;
4935 + attr.ia_atime = dt->dt_atime;
4936 + attr.ia_mtime = dt->dt_mtime;
4937 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4938 + | ATTR_ATIME | ATTR_ATIME_SET;
4940 + /* no delegation since this is a directory */
4941 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4942 + if (unlikely(err))
4943 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4946 +/* ---------------------------------------------------------------------- */
4948 +/* internal use only */
4949 +struct au_cpup_reg_attr {
4952 + unsigned int iflags; /* inode->i_flags */
4955 +static noinline_for_stack
4956 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4957 + struct au_cpup_reg_attr *h_src_attr)
4959 + int err, sbits, icex;
4960 + unsigned int mnt_flags;
4961 + unsigned char verbose;
4963 + struct path h_path;
4964 + struct inode *h_isrc, *h_idst;
4965 + struct kstat *h_st;
4966 + struct au_branch *br;
4968 + br = au_sbr(dst->d_sb, bindex);
4969 + h_path.mnt = au_br_mnt(br);
4970 + h_path.dentry = au_h_dptr(dst, bindex);
4971 + h_idst = d_inode(h_path.dentry);
4972 + h_isrc = d_inode(h_src->dentry);
4973 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4974 + | ATTR_ATIME | ATTR_MTIME
4975 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4976 + if (h_src_attr && h_src_attr->valid) {
4977 + h_st = &h_src_attr->st;
4978 + ia.ia_uid = h_st->uid;
4979 + ia.ia_gid = h_st->gid;
4980 + ia.ia_atime = h_st->atime;
4981 + ia.ia_mtime = h_st->mtime;
4982 + if (h_idst->i_mode != h_st->mode
4983 + && !S_ISLNK(h_idst->i_mode)) {
4984 + ia.ia_valid |= ATTR_MODE;
4985 + ia.ia_mode = h_st->mode;
4987 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4988 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4990 + ia.ia_uid = h_isrc->i_uid;
4991 + ia.ia_gid = h_isrc->i_gid;
4992 + ia.ia_atime = h_isrc->i_atime;
4993 + ia.ia_mtime = h_isrc->i_mtime;
4994 + if (h_idst->i_mode != h_isrc->i_mode
4995 + && !S_ISLNK(h_idst->i_mode)) {
4996 + ia.ia_valid |= ATTR_MODE;
4997 + ia.ia_mode = h_isrc->i_mode;
4999 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5000 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5002 + /* no delegation since it is just created */
5003 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5005 + /* is this nfs only? */
5006 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5007 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5008 + ia.ia_mode = h_isrc->i_mode;
5009 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5012 + icex = br->br_perm & AuBrAttr_ICEX;
5014 + mnt_flags = au_mntflags(dst->d_sb);
5015 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5016 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
5022 +/* ---------------------------------------------------------------------- */
5024 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5025 + char *buf, unsigned long blksize)
5028 + size_t sz, rbytes, wbytes;
5029 + unsigned char all_zero;
5031 + struct inode *h_inode;
5032 + /* reduce stack usage */
5035 + zp = page_address(ZERO_PAGE(0));
5036 + if (unlikely(!zp))
5037 + return -ENOMEM; /* possible? */
5042 + AuDbg("len %lld\n", len);
5044 + if (len < blksize)
5048 + /* todo: signal_pending? */
5049 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5050 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5053 + if (unlikely(err < 0))
5057 + if (len >= rbytes && rbytes == blksize)
5058 + all_zero = !memcmp(buf, zp, rbytes);
5065 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5067 + /* todo: signal_pending? */
5068 + if (unlikely(err == -EAGAIN || err == -EINTR))
5070 + if (unlikely(err < 0))
5075 + if (unlikely(err < 0))
5081 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5083 + if (unlikely(res < 0))
5090 + /* the last block may be a hole */
5091 + if (!err && all_zero) {
5092 + AuLabel(last hole);
5095 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5096 + /* nfs requires this step to make last hole */
5097 + /* is this only nfs? */
5099 + /* todo: signal_pending? */
5100 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5101 + } while (err == -EAGAIN || err == -EINTR);
5108 + ia->ia_size = dst->f_pos;
5109 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5110 + ia->ia_file = dst;
5111 + h_inode = file_inode(dst);
5112 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5113 + /* no delegation since it is just created */
5114 + err = vfsub_notify_change(&dst->f_path, ia,
5115 + /*delegated*/NULL);
5116 + inode_unlock(h_inode);
5123 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5126 + unsigned long blksize;
5127 + unsigned char do_kfree;
5129 + struct super_block *h_sb;
5132 + h_sb = file_inode(dst)->i_sb;
5133 + blksize = h_sb->s_blocksize;
5134 + if (!blksize || PAGE_SIZE < blksize)
5135 + blksize = PAGE_SIZE;
5136 + AuDbg("blksize %lu\n", blksize);
5137 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5139 + buf = kmalloc(blksize, GFP_NOFS);
5141 + buf = (void *)__get_free_page(GFP_NOFS);
5142 + if (unlikely(!buf))
5145 + if (len > (1 << 22))
5146 + AuDbg("copying a large file %lld\n", (long long)len);
5150 + err = au_do_copy_file(dst, src, len, buf, blksize);
5152 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5153 + au_kfree_do_rcu(buf);
5155 + free_page((unsigned long)buf);
5161 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5164 + struct super_block *h_src_sb;
5165 + struct inode *h_src_inode;
5167 + h_src_inode = file_inode(src);
5168 + h_src_sb = h_src_inode->i_sb;
5170 + /* XFS acquires inode_lock */
5171 + if (!au_test_xfs(h_src_sb))
5172 + err = au_copy_file(dst, src, len);
5174 + inode_unlock_shared(h_src_inode);
5175 + err = au_copy_file(dst, src, len);
5176 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5182 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5186 + struct super_block *h_src_sb;
5187 + struct inode *h_src_inode;
5189 + h_src_inode = file_inode(src);
5190 + h_src_sb = h_src_inode->i_sb;
5191 + if (h_src_sb != file_inode(dst)->i_sb
5192 + || !dst->f_op->remap_file_range) {
5193 + err = au_do_copy(dst, src, len);
5197 + if (!au_test_nfs(h_src_sb)) {
5198 + inode_unlock_shared(h_src_inode);
5199 + lo = vfsub_clone_file_range(src, dst, len);
5200 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5202 + lo = vfsub_clone_file_range(src, dst, len);
5205 + goto out; /* success */
5206 + } else if (lo >= 0)
5207 + /* todo: possible? */
5208 + /* paritially succeeded */
5209 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5210 + else if (lo != -EOPNOTSUPP) {
5211 + /* older XFS has a condition in cloning */
5216 + /* the backend fs on NFS may not support cloning */
5217 + err = au_do_copy(dst, src, len);
5225 + * to support a sparse file which is opened with O_APPEND,
5226 + * we need to close the file.
5228 +static int au_cp_regular(struct au_cp_generic *cpg)
5231 + enum { SRC, DST };
5233 + aufs_bindex_t bindex;
5234 + unsigned int flags;
5235 + struct dentry *dentry;
5237 + struct file *file;
5240 + .bindex = cpg->bsrc,
5241 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5244 + .bindex = cpg->bdst,
5245 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5246 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5249 + struct au_branch *br;
5250 + struct super_block *sb, *h_src_sb;
5251 + struct inode *h_src_inode;
5252 + struct task_struct *tsk = current;
5254 + /* bsrc branch can be ro/rw. */
5255 + sb = cpg->dentry->d_sb;
5257 + for (i = 0; i < 2; i++, f++) {
5258 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5259 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5260 + /*file*/NULL, f->force_wr);
5261 + if (IS_ERR(f->file)) {
5262 + err = PTR_ERR(f->file);
5270 + /* try stopping to update while we copyup */
5271 + h_src_inode = d_inode(file[SRC].dentry);
5272 + h_src_sb = h_src_inode->i_sb;
5273 + if (!au_test_nfs(h_src_sb))
5274 + IMustLock(h_src_inode);
5275 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5277 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5278 + if (tsk->flags & PF_KTHREAD)
5279 + __fput_sync(file[DST].file);
5281 + /* it happened actually */
5282 + fput(file[DST].file);
5285 + * we have to call both since we don't know which place the file
5289 + flush_delayed_fput();
5291 + br = au_sbr(sb, file[DST].bindex);
5292 + au_lcnt_dec(&br->br_nfiles);
5295 + fput(file[SRC].file);
5296 + br = au_sbr(sb, file[SRC].bindex);
5297 + au_lcnt_dec(&br->br_nfiles);
5302 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5303 + struct au_cpup_reg_attr *h_src_attr)
5307 + struct path h_path;
5308 + struct inode *h_src_inode, *h_dst_inode;
5311 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5312 + l = i_size_read(h_src_inode);
5313 + if (cpg->len == -1 || l < cpg->len)
5316 + /* try stopping to update while we are referencing */
5317 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5318 + au_pin_hdir_unlock(cpg->pin);
5320 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5321 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5322 + h_src_attr->iflags = h_src_inode->i_flags;
5323 + if (!au_test_nfs(h_src_inode->i_sb))
5324 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5326 + inode_unlock_shared(h_src_inode);
5327 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5328 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5330 + if (unlikely(err)) {
5331 + inode_unlock_shared(h_src_inode);
5334 + h_src_attr->valid = 1;
5335 + if (!au_test_nfs(h_src_inode->i_sb)) {
5336 + err = au_cp_regular(cpg);
5337 + inode_unlock_shared(h_src_inode);
5339 + inode_unlock_shared(h_src_inode);
5340 + err = au_cp_regular(cpg);
5342 + rerr = au_pin_hdir_relock(cpg->pin);
5346 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5347 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5348 + h_dst_inode = d_inode(h_path.dentry);
5349 + spin_lock(&h_dst_inode->i_lock);
5350 + h_dst_inode->i_state |= I_LINKABLE;
5351 + spin_unlock(&h_dst_inode->i_lock);
5358 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5359 + struct inode *h_dir)
5362 + DEFINE_DELAYED_CALL(done);
5365 + sym = vfs_get_link(h_src, &done);
5366 + err = PTR_ERR(sym);
5370 + err = vfsub_symlink(h_dir, h_path, sym);
5373 + do_delayed_call(&done);
5378 + * regardless 'acl' option, reset all ACL.
5379 + * All ACL will be copied up later from the original entry on the lower branch.
5381 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5384 + struct dentry *h_dentry;
5385 + struct inode *h_inode;
5386 + struct user_namespace *h_userns;
5388 + h_userns = mnt_user_ns(h_path->mnt);
5389 + h_dentry = h_path->dentry;
5390 + h_inode = d_inode(h_dentry);
5391 + /* forget_all_cached_acls(h_inode)); */
5392 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5394 + if (err == -EOPNOTSUPP)
5397 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5403 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5404 + struct inode *h_dir, struct path *h_path)
5407 + struct inode *dir, *inode;
5408 + struct user_namespace *h_userns;
5410 + h_userns = mnt_user_ns(h_path->mnt);
5411 + err = vfsub_removexattr(h_userns, h_path->dentry,
5412 + XATTR_NAME_POSIX_ACL_DEFAULT);
5414 + if (err == -EOPNOTSUPP)
5416 + if (unlikely(err))
5420 + * strange behaviour from the users view,
5421 + * particularly setattr case
5423 + dir = d_inode(dst_parent);
5424 + if (au_ibtop(dir) == cpg->bdst)
5425 + au_cpup_attr_nlink(dir, /*force*/1);
5426 + inode = d_inode(cpg->dentry);
5427 + au_cpup_attr_nlink(inode, /*force*/1);
5433 +static noinline_for_stack
5434 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5435 + struct au_cpup_reg_attr *h_src_attr)
5439 + unsigned int mnt_flags;
5440 + unsigned char isdir, isreg, force;
5441 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5442 + struct au_dtime dt;
5443 + struct path h_path;
5444 + struct dentry *h_src, *h_dst, *h_parent;
5445 + struct inode *h_inode, *h_dir;
5446 + struct super_block *sb;
5448 + /* bsrc branch can be ro/rw. */
5449 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5450 + h_inode = d_inode(h_src);
5451 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5453 + /* try stopping to be referenced while we are creating */
5454 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5455 + if (au_ftest_cpup(cpg->flags, RENAME))
5456 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5457 + AUFS_WH_PFX_LEN));
5458 + h_parent = h_dst->d_parent; /* dir inode is locked */
5459 + h_dir = d_inode(h_parent);
5461 + AuDebugOn(h_parent != h_dst->d_parent);
5463 + sb = cpg->dentry->d_sb;
5464 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5466 + h_path.dentry = h_parent;
5467 + au_dtime_store(&dt, dst_parent, &h_path);
5469 + h_path.dentry = h_dst;
5473 + mode = h_inode->i_mode;
5474 + switch (mode & S_IFMT) {
5477 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5479 + err = au_do_cpup_regular(cpg, h_src_attr);
5483 + err = vfsub_mkdir(h_dir, &h_path, mode);
5485 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5488 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5492 + AuDebugOn(!capable(CAP_MKNOD));
5496 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5499 + AuIOErr("Unknown inode type 0%o\n", mode);
5503 + err = au_reset_acl(h_dir, &h_path, mode);
5505 + mnt_flags = au_mntflags(sb);
5506 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5508 + && au_opt_test(mnt_flags, XINO)
5509 + && (h_inode->i_nlink == 1
5510 + || (h_inode->i_state & I_LINKABLE))
5511 + /* todo: unnecessary? */
5512 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5513 + && cpg->bdst < cpg->bsrc
5514 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5515 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5516 + /* ignore this error */
5521 + force = !!cpg->len;
5522 + if (cpg->len == -1)
5523 + force = !!i_size_read(h_inode);
5525 + au_fhsm_wrote(sb, cpg->bdst, force);
5529 + au_dtime_revert(&dt);
5533 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5536 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5537 + struct inode *h_dir;
5538 + aufs_bindex_t bdst;
5540 + dentry = cpg->dentry;
5542 + h_dentry = au_h_dptr(dentry, bdst);
5543 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5545 + au_set_h_dptr(dentry, bdst, NULL);
5546 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5548 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5549 + au_set_h_dptr(dentry, bdst, h_dentry);
5552 + parent = dget_parent(dentry);
5553 + h_parent = au_h_dptr(parent, bdst);
5555 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5556 + if (IS_ERR(h_path->dentry))
5557 + err = PTR_ERR(h_path->dentry);
5559 + if (unlikely(err))
5562 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5563 + h_dir = d_inode(h_parent);
5565 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5566 + /* no delegation since it is just created */
5567 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5569 + dput(h_path->dentry);
5576 + * copyup the @dentry from @bsrc to @bdst.
5577 + * the caller must set the both of lower dentries.
5578 + * @len is for truncating when it is -1 copyup the entire file.
5579 + * in link/rename cases, @dst_parent may be different from the real one.
5580 + * basic->bsrc can be larger than basic->bdst.
5581 + * aufs doesn't touch the credential so
5582 + * security_inode_copy_up{,_xattr}() are unnecessary.
5584 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5587 + aufs_bindex_t old_ibtop;
5588 + unsigned char isdir, plink;
5589 + struct dentry *h_src, *h_dst, *h_parent;
5590 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5591 + struct super_block *sb;
5592 + struct au_branch *br;
5593 + struct path h_src_path;
5594 + /* to reduce stack size */
5596 + struct au_dtime dt;
5597 + struct path h_path;
5598 + struct au_cpup_reg_attr h_src_attr;
5602 + a = kmalloc(sizeof(*a), GFP_NOFS);
5605 + a->h_src_attr.valid = 0;
5607 + sb = cpg->dentry->d_sb;
5608 + br = au_sbr(sb, cpg->bdst);
5609 + a->h_path.mnt = au_br_mnt(br);
5610 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5611 + h_parent = h_dst->d_parent; /* dir inode is locked */
5612 + h_dir = d_inode(h_parent);
5615 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5616 + inode = d_inode(cpg->dentry);
5619 + dst_parent = dget_parent(cpg->dentry);
5623 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5624 + dst_inode = au_h_iptr(inode, cpg->bdst);
5626 + if (unlikely(!plink)) {
5628 + AuIOErr("hi%lu(i%lu) exists on b%d "
5629 + "but plink is disabled\n",
5630 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5634 + if (dst_inode->i_nlink) {
5635 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5637 + h_src = au_plink_lkup(inode, cpg->bdst);
5638 + err = PTR_ERR(h_src);
5639 + if (IS_ERR(h_src))
5641 + if (unlikely(d_is_negative(h_src))) {
5643 + AuIOErr("i%lu exists on b%d "
5644 + "but not pseudo-linked\n",
5645 + inode->i_ino, cpg->bdst);
5651 + a->h_path.dentry = h_parent;
5652 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5655 + a->h_path.dentry = h_dst;
5657 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5658 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5659 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5661 + au_dtime_revert(&a->dt);
5662 + if (unlikely(err == -EWOULDBLOCK)) {
5663 + pr_warn("cannot retry for NFSv4 delegation"
5664 + " for an internal link\n");
5670 + /* todo: cpup_wh_file? */
5672 + au_update_ibrange(inode, /*do_put_zero*/1);
5675 + isdir = S_ISDIR(inode->i_mode);
5676 + old_ibtop = au_ibtop(inode);
5677 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5678 + if (unlikely(err))
5680 + dst_inode = d_inode(h_dst);
5681 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5682 + /* todo: necessary? */
5683 + /* au_pin_hdir_unlock(cpg->pin); */
5685 + h_src_path.dentry = h_src;
5686 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5687 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5688 + if (unlikely(err)) {
5689 + /* todo: necessary? */
5690 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5691 + inode_unlock(dst_inode);
5695 + if (cpg->bdst < old_ibtop) {
5696 + if (S_ISREG(inode->i_mode)) {
5697 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5698 + if (unlikely(err)) {
5699 + /* ignore an error */
5700 + /* au_pin_hdir_relock(cpg->pin); */
5701 + inode_unlock(dst_inode);
5705 + au_set_ibtop(inode, cpg->bdst);
5707 + au_set_ibbot(inode, cpg->bdst);
5708 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5709 + au_hi_flags(inode, isdir));
5711 + /* todo: necessary? */
5712 + /* err = au_pin_hdir_relock(cpg->pin); */
5713 + inode_unlock(dst_inode);
5714 + if (unlikely(err))
5717 + src_inode = d_inode(h_src);
5719 + && (src_inode->i_nlink > 1
5720 + || src_inode->i_state & I_LINKABLE)
5722 + au_plink_append(inode, cpg->bdst, h_dst);
5724 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5725 + a->h_path.dentry = h_dst;
5726 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5729 + goto out_parent; /* success */
5733 + a->h_path.dentry = h_parent;
5734 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5735 + a->h_path.dentry = h_dst;
5737 + if (d_is_positive(h_dst)) {
5739 + /* no delegation since it is just created */
5740 + rerr = vfsub_unlink(h_dir, &a->h_path,
5741 + /*delegated*/NULL, /*force*/0);
5743 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5745 + au_dtime_revert(&a->dt);
5747 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5757 +#if 0 /* reserved */
5758 +struct au_cpup_single_args {
5760 + struct au_cp_generic *cpg;
5761 + struct dentry *dst_parent;
5764 +static void au_call_cpup_single(void *args)
5766 + struct au_cpup_single_args *a = args;
5768 + au_pin_hdir_acquire_nest(a->cpg->pin);
5769 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5770 + au_pin_hdir_release(a->cpg->pin);
5775 + * prevent SIGXFSZ in copy-up.
5776 + * testing CAP_MKNOD is for generic fs,
5777 + * but CAP_FSETID is for xfs only, currently.
5779 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5782 + struct super_block *sb;
5783 + struct inode *h_dir;
5786 + sb = au_pinned_parent(pin)->d_sb;
5787 + if (!au_wkq_test()
5788 + && (!au_sbi(sb)->si_plink_maint_pid
5789 + || au_plink_maint(sb, AuLock_NOPLM))) {
5790 + switch (mode & S_IFMT) {
5792 + /* no condition about RLIMIT_FSIZE and the file size */
5797 + do_sio = !capable(CAP_MKNOD);
5801 + do_sio = ((mode & (S_ISUID | S_ISGID))
5802 + && !capable(CAP_FSETID));
5803 + /* this workaround may be removed in the future */
5805 + h_dir = au_pinned_h_dir(pin);
5806 + do_sio = h_dir->i_mode & S_ISVTX;
5813 +#if 0 /* reserved */
5814 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5817 + struct dentry *h_dentry;
5819 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5820 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5821 + err = au_cpup_single(cpg, dst_parent);
5823 + struct au_cpup_single_args args = {
5826 + .dst_parent = dst_parent
5828 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5829 + if (unlikely(wkq_err))
5838 + * copyup the @dentry from the first active lower branch to @bdst,
5839 + * using au_cpup_single().
5841 +static int au_cpup_simple(struct au_cp_generic *cpg)
5844 + unsigned int flags_orig;
5845 + struct dentry *dentry;
5847 + AuDebugOn(cpg->bsrc < 0);
5849 + dentry = cpg->dentry;
5850 + DiMustWriteLock(dentry);
5852 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5854 + flags_orig = cpg->flags;
5855 + au_fset_cpup(cpg->flags, RENAME);
5856 + err = au_cpup_single(cpg, NULL);
5857 + cpg->flags = flags_orig;
5859 + return 0; /* success */
5862 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5863 + au_set_dbtop(dentry, cpg->bsrc);
5869 +struct au_cpup_simple_args {
5871 + struct au_cp_generic *cpg;
5874 +static void au_call_cpup_simple(void *args)
5876 + struct au_cpup_simple_args *a = args;
5878 + au_pin_hdir_acquire_nest(a->cpg->pin);
5879 + *a->errp = au_cpup_simple(a->cpg);
5880 + au_pin_hdir_release(a->cpg->pin);
5883 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5886 + struct dentry *dentry, *parent;
5887 + struct file *h_file;
5888 + struct inode *h_dir;
5889 + struct user_namespace *h_userns;
5891 + dentry = cpg->dentry;
5893 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5894 + AuDebugOn(cpg->bsrc < 0);
5895 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5896 + err = PTR_ERR(h_file);
5897 + if (IS_ERR(h_file))
5901 + parent = dget_parent(dentry);
5902 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5903 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5904 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5905 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5906 + err = au_cpup_simple(cpg);
5908 + struct au_cpup_simple_args args = {
5912 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5913 + if (unlikely(wkq_err))
5919 + au_h_open_post(dentry, cpg->bsrc, h_file);
5925 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5927 + aufs_bindex_t bsrc, bbot;
5928 + struct dentry *dentry, *h_dentry;
5930 + if (cpg->bsrc < 0) {
5931 + dentry = cpg->dentry;
5932 + bbot = au_dbbot(dentry);
5933 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5934 + h_dentry = au_h_dptr(dentry, bsrc);
5936 + AuDebugOn(d_is_negative(h_dentry));
5940 + AuDebugOn(bsrc > bbot);
5943 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5944 + return au_do_sio_cpup_simple(cpg);
5947 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5949 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5950 + return au_do_sio_cpup_simple(cpg);
5953 +/* ---------------------------------------------------------------------- */
5956 + * copyup the deleted file for writing.
5958 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5959 + struct file *file)
5962 + unsigned int flags_orig;
5963 + aufs_bindex_t bsrc_orig;
5964 + struct au_dinfo *dinfo;
5966 + struct au_hdentry *hd;
5967 + struct dentry *h_dentry;
5970 + dinfo = au_di(cpg->dentry);
5971 + AuRwMustWriteLock(&dinfo->di_rwsem);
5973 + bsrc_orig = cpg->bsrc;
5974 + cpg->bsrc = dinfo->di_btop;
5975 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5976 + hdst.h_dentry = hdst.hd->hd_dentry;
5977 + hdst.hd->hd_dentry = wh_dentry;
5978 + dinfo->di_btop = cpg->bdst;
5980 + hsrc.h_dentry = NULL;
5982 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5983 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5984 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5986 + flags_orig = cpg->flags;
5987 + cpg->flags = !AuCpup_DTIME;
5988 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5989 + cpg->flags = flags_orig;
5992 + err = au_reopen_nondir(file);
5993 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5995 + hdst.hd->hd_dentry = hdst.h_dentry;
5996 + dinfo->di_btop = cpg->bsrc;
5997 + cpg->bsrc = bsrc_orig;
6002 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6005 + aufs_bindex_t bdst;
6006 + struct au_dtime dt;
6007 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6008 + struct au_branch *br;
6009 + struct path h_path;
6011 + dentry = cpg->dentry;
6013 + br = au_sbr(dentry->d_sb, bdst);
6014 + parent = dget_parent(dentry);
6015 + h_parent = au_h_dptr(parent, bdst);
6016 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6017 + err = PTR_ERR(wh_dentry);
6018 + if (IS_ERR(wh_dentry))
6021 + h_path.dentry = h_parent;
6022 + h_path.mnt = au_br_mnt(br);
6023 + au_dtime_store(&dt, parent, &h_path);
6024 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6025 + if (unlikely(err))
6029 + h_path.dentry = wh_dentry;
6030 + if (!d_is_dir(wh_dentry)) {
6031 + /* no delegation since it is just created */
6032 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6033 + /*delegated*/NULL, /*force*/0);
6035 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6036 + if (unlikely(err)) {
6037 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6041 + au_dtime_revert(&dt);
6042 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6051 +struct au_cpup_wh_args {
6053 + struct au_cp_generic *cpg;
6054 + struct file *file;
6057 +static void au_call_cpup_wh(void *args)
6059 + struct au_cpup_wh_args *a = args;
6061 + au_pin_hdir_acquire_nest(a->cpg->pin);
6062 + *a->errp = au_cpup_wh(a->cpg, a->file);
6063 + au_pin_hdir_release(a->cpg->pin);
6066 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6069 + aufs_bindex_t bdst;
6070 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6071 + struct inode *dir, *h_dir, *h_tmpdir;
6072 + struct au_wbr *wbr;
6073 + struct au_pin wh_pin, *pin_orig;
6074 + struct user_namespace *h_userns;
6076 + dentry = cpg->dentry;
6078 + parent = dget_parent(dentry);
6079 + dir = d_inode(parent);
6082 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6085 + if (!h_dir->i_nlink) {
6086 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6087 + h_orph = wbr->wbr_orph;
6089 + h_parent = dget(au_h_dptr(parent, bdst));
6090 + au_set_h_dptr(parent, bdst, dget(h_orph));
6091 + h_tmpdir = d_inode(h_orph);
6092 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6094 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6095 + /* todo: au_h_open_pre()? */
6097 + pin_orig = cpg->pin;
6098 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6099 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6100 + cpg->pin = &wh_pin;
6103 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6104 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6105 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6106 + err = au_cpup_wh(cpg, file);
6108 + struct au_cpup_wh_args args = {
6113 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6114 + if (unlikely(wkq_err))
6119 + inode_unlock(h_tmpdir);
6120 + /* todo: au_h_open_post()? */
6121 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6122 + au_set_h_dptr(parent, bdst, h_parent);
6123 + AuDebugOn(!pin_orig);
6124 + cpg->pin = pin_orig;
6132 +/* ---------------------------------------------------------------------- */
6135 + * generic routine for both of copy-up and copy-down.
6137 +/* cf. revalidate function in file.c */
6138 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6139 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6140 + struct au_pin *pin,
6141 + struct dentry *h_parent, void *arg),
6145 + struct au_pin pin;
6146 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6149 + parent = dget_parent(dentry);
6150 + if (IS_ROOT(parent))
6153 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6154 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6156 + /* do not use au_dpage */
6157 + real_parent = parent;
6160 + parent = dget_parent(dentry);
6161 + h_parent = au_h_dptr(parent, bdst);
6163 + goto out; /* success */
6165 + /* find top dir which is necessary to cpup */
6169 + parent = dget_parent(d);
6170 + di_read_lock_parent3(parent, !AuLock_IR);
6171 + h_parent = au_h_dptr(parent, bdst);
6172 + di_read_unlock(parent, !AuLock_IR);
6173 + } while (!h_parent);
6175 + if (d != real_parent)
6176 + di_write_lock_child3(d);
6178 + /* somebody else might create while we were sleeping */
6179 + h_dentry = au_h_dptr(d, bdst);
6180 + if (!h_dentry || d_is_negative(h_dentry)) {
6182 + au_update_dbtop(d);
6184 + au_pin_set_dentry(&pin, d);
6185 + err = au_do_pin(&pin);
6187 + err = cp(d, bdst, &pin, h_parent, arg);
6192 + if (d != real_parent)
6193 + di_write_unlock(d);
6194 + if (unlikely(err))
6203 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6204 + struct au_pin *pin,
6205 + struct dentry *h_parent __maybe_unused,
6206 + void *arg __maybe_unused)
6208 + struct au_cp_generic cpg = {
6214 + .flags = AuCpup_DTIME
6216 + return au_sio_cpup_simple(&cpg);
6219 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6221 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6224 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6227 + struct dentry *parent;
6228 + struct inode *dir;
6230 + parent = dget_parent(dentry);
6231 + dir = d_inode(parent);
6233 + if (au_h_iptr(dir, bdst))
6236 + di_read_unlock(parent, AuLock_IR);
6237 + di_write_lock_parent(parent);
6238 + /* someone else might change our inode while we were sleeping */
6239 + if (!au_h_iptr(dir, bdst))
6240 + err = au_cpup_dirs(dentry, bdst);
6241 + di_downgrade_lock(parent, AuLock_IR);
6247 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6248 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6249 +++ linux/fs/aufs/cpup.h 2021-09-06 21:02:45.273492232 +0200
6251 +/* SPDX-License-Identifier: GPL-2.0 */
6253 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6255 + * This program, aufs is free software; you can redistribute it and/or modify
6256 + * it under the terms of the GNU General Public License as published by
6257 + * the Free Software Foundation; either version 2 of the License, or
6258 + * (at your option) any later version.
6260 + * This program is distributed in the hope that it will be useful,
6261 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6262 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6263 + * GNU General Public License for more details.
6265 + * You should have received a copy of the GNU General Public License
6266 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6270 + * copy-up/down functions
6273 +#ifndef __AUFS_CPUP_H__
6274 +#define __AUFS_CPUP_H__
6278 +#include <linux/path.h>
6284 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6285 +void au_cpup_attr_timesizes(struct inode *inode);
6286 +void au_cpup_attr_nlink(struct inode *inode, int force);
6287 +void au_cpup_attr_changeable(struct inode *inode);
6288 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6289 +void au_cpup_attr_all(struct inode *inode, int force);
6291 +/* ---------------------------------------------------------------------- */
6293 +struct au_cp_generic {
6294 + struct dentry *dentry;
6295 + aufs_bindex_t bdst, bsrc;
6297 + struct au_pin *pin;
6298 + unsigned int flags;
6302 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6303 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6305 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6306 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6308 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6310 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6311 + the branch is marked as RO */
6313 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6314 +#undef AuCpup_HOPEN
6315 +#define AuCpup_HOPEN 0
6318 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6319 +#define au_fset_cpup(flags, name) \
6320 + do { (flags) |= AuCpup_##name; } while (0)
6321 +#define au_fclr_cpup(flags, name) \
6322 + do { (flags) &= ~AuCpup_##name; } while (0)
6324 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6325 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6326 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6327 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6329 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6330 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6331 + struct au_pin *pin,
6332 + struct dentry *h_parent, void *arg),
6334 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6335 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6337 +/* ---------------------------------------------------------------------- */
6339 +/* keep timestamps when copyup */
6341 + struct dentry *dt_dentry;
6342 + struct path dt_h_path;
6343 + struct timespec64 dt_atime, dt_mtime;
6345 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6346 + struct path *h_path);
6347 +void au_dtime_revert(struct au_dtime *dt);
6349 +#endif /* __KERNEL__ */
6350 +#endif /* __AUFS_CPUP_H__ */
6351 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6352 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6353 +++ linux/fs/aufs/dbgaufs.c 2021-09-06 21:02:45.273492232 +0200
6355 +// SPDX-License-Identifier: GPL-2.0
6357 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6359 + * This program, aufs is free software; you can redistribute it and/or modify
6360 + * it under the terms of the GNU General Public License as published by
6361 + * the Free Software Foundation; either version 2 of the License, or
6362 + * (at your option) any later version.
6364 + * This program is distributed in the hope that it will be useful,
6365 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6367 + * GNU General Public License for more details.
6369 + * You should have received a copy of the GNU General Public License
6370 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6374 + * debugfs interface
6377 +#include <linux/debugfs.h>
6380 +#ifndef CONFIG_SYSFS
6381 +#error DEBUG_FS depends upon SYSFS
6384 +static struct dentry *dbgaufs;
6385 +static const mode_t dbgaufs_mode = 0444;
6387 +/* 20 is max digits length of ulong 64 */
6388 +struct dbgaufs_arg {
6394 + * common function for all XINO files
6396 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6397 + struct file *file)
6401 + p = file->private_data;
6403 + /* this is struct dbgaufs_arg */
6404 + AuDebugOn(!au_kfree_sz_test(p));
6405 + au_kfree_do_rcu(p);
6410 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6415 + struct dbgaufs_arg *p;
6418 + p = kmalloc(sizeof(*p), GFP_NOFS);
6424 + file->private_data = p;
6428 + err = vfsub_getattr(&xf->f_path, &st);
6432 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6433 + cnt, st.blocks, st.blksize,
6434 + (long long)st.size);
6436 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6437 + st.blocks, st.blksize,
6438 + (long long)st.size);
6439 + AuDebugOn(p->n >= sizeof(p->a));
6441 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6449 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6450 + size_t count, loff_t *ppos)
6452 + struct dbgaufs_arg *p;
6454 + p = file->private_data;
6455 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6458 +/* ---------------------------------------------------------------------- */
6460 +struct dbgaufs_plink_arg {
6465 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6466 + struct file *file)
6468 + free_page((unsigned long)file->private_data);
6472 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6474 + int err, i, limit;
6475 + unsigned long n, sum;
6476 + struct dbgaufs_plink_arg *p;
6477 + struct au_sbinfo *sbinfo;
6478 + struct super_block *sb;
6479 + struct hlist_bl_head *hbl;
6482 + p = (void *)get_zeroed_page(GFP_NOFS);
6487 + sbinfo = inode->i_private;
6488 + sb = sbinfo->si_sb;
6489 + si_noflush_read_lock(sb);
6490 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6491 + limit = PAGE_SIZE - sizeof(p->n);
6493 + /* the number of buckets */
6494 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6499 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6501 + n = au_hbl_count(hbl);
6504 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6507 + if (unlikely(limit <= 0))
6510 + p->a[p->n - 1] = '\n';
6512 + /* the sum of plinks */
6513 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6516 + if (unlikely(limit <= 0))
6519 +#define str "1\n0\n0\n"
6520 + p->n = sizeof(str) - 1;
6521 + strcpy(p->a, str);
6524 + si_read_unlock(sb);
6527 + file->private_data = p;
6528 + goto out; /* success */
6531 + free_page((unsigned long)p);
6536 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6537 + size_t count, loff_t *ppos)
6539 + struct dbgaufs_plink_arg *p;
6541 + p = file->private_data;
6542 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6545 +static const struct file_operations dbgaufs_plink_fop = {
6546 + .owner = THIS_MODULE,
6547 + .open = dbgaufs_plink_open,
6548 + .release = dbgaufs_plink_release,
6549 + .read = dbgaufs_plink_read
6552 +/* ---------------------------------------------------------------------- */
6554 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6557 + struct au_sbinfo *sbinfo;
6558 + struct super_block *sb;
6560 + sbinfo = inode->i_private;
6561 + sb = sbinfo->si_sb;
6562 + si_noflush_read_lock(sb);
6563 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6564 + si_read_unlock(sb);
6568 +static const struct file_operations dbgaufs_xib_fop = {
6569 + .owner = THIS_MODULE,
6570 + .open = dbgaufs_xib_open,
6571 + .release = dbgaufs_xi_release,
6572 + .read = dbgaufs_xi_read
6575 +/* ---------------------------------------------------------------------- */
6577 +#define DbgaufsXi_PREFIX "xi"
6579 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6583 + aufs_bindex_t bindex;
6584 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6585 + struct au_sbinfo *sbinfo;
6586 + struct super_block *sb;
6587 + struct au_xino *xi;
6589 + struct qstr *name;
6590 + struct au_branch *br;
6593 + name = &file->f_path.dentry->d_name;
6594 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6595 + || memcmp(name->name, DbgaufsXi_PREFIX,
6596 + sizeof(DbgaufsXi_PREFIX) - 1)))
6599 + AuDebugOn(name->len >= sizeof(a));
6600 + memcpy(a, name->name, name->len);
6601 + a[name->len] = '\0';
6602 + p = strchr(a, '-');
6605 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6606 + if (unlikely(err))
6611 + err = kstrtol(p + 1, 10, &l);
6612 + if (unlikely(err))
6618 + sbinfo = inode->i_private;
6619 + sb = sbinfo->si_sb;
6620 + si_noflush_read_lock(sb);
6621 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6623 + br = au_sbr(sb, bindex);
6625 + if (unlikely(idx >= xi->xi_nfile))
6627 + xf = au_xino_file(xi, idx);
6629 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6630 + au_xino_count(br));
6633 + si_read_unlock(sb);
6639 +static const struct file_operations dbgaufs_xino_fop = {
6640 + .owner = THIS_MODULE,
6641 + .open = dbgaufs_xino_open,
6642 + .release = dbgaufs_xi_release,
6643 + .read = dbgaufs_xi_read
6646 +void dbgaufs_xino_del(struct au_branch *br)
6648 + struct dentry *dbgaufs;
6650 + dbgaufs = br->br_dbgaufs;
6654 + br->br_dbgaufs = NULL;
6655 + /* debugfs acquires the parent i_mutex */
6657 + debugfs_remove(dbgaufs);
6661 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6663 + aufs_bindex_t bbot;
6664 + struct au_branch *br;
6666 + if (!au_sbi(sb)->si_dbgaufs)
6669 + bbot = au_sbbot(sb);
6670 + for (; bindex <= bbot; bindex++) {
6671 + br = au_sbr(sb, bindex);
6672 + dbgaufs_xino_del(br);
6676 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6677 + unsigned int idx, struct dentry *parent,
6678 + struct au_sbinfo *sbinfo)
6680 + struct au_branch *br;
6682 + /* "xi" bindex(5) "-" idx(2) NULL */
6683 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6686 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6688 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6690 + br = au_sbr(sb, bindex);
6691 + if (br->br_dbgaufs) {
6692 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6694 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6695 + /* debugfs acquires the parent i_mutex */
6697 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6701 + pr_warn("failed renaming %pd/%s, ignored.\n",
6706 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6707 + sbinfo, &dbgaufs_xino_fop);
6709 + if (unlikely(!br->br_dbgaufs))
6710 + pr_warn("failed creating %pd/%s, ignored.\n",
6715 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6716 + struct dentry *parent, struct au_sbinfo *sbinfo)
6718 + struct au_branch *br;
6719 + struct au_xino *xi;
6722 + br = au_sbr(sb, bindex);
6724 + for (u = 0; u < xi->xi_nfile; u++)
6725 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6728 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6730 + struct au_sbinfo *sbinfo;
6731 + struct dentry *parent;
6732 + aufs_bindex_t bbot;
6734 + if (!au_opt_test(au_mntflags(sb), XINO))
6737 + sbinfo = au_sbi(sb);
6738 + parent = sbinfo->si_dbgaufs;
6742 + bbot = au_sbbot(sb);
6744 + for (; bindex <= bbot; bindex++)
6745 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6747 + for (; bbot >= bindex; bbot--)
6748 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6751 +/* ---------------------------------------------------------------------- */
6753 +#ifdef CONFIG_AUFS_EXPORT
6754 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6757 + struct au_sbinfo *sbinfo;
6758 + struct super_block *sb;
6760 + sbinfo = inode->i_private;
6761 + sb = sbinfo->si_sb;
6762 + si_noflush_read_lock(sb);
6763 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6764 + si_read_unlock(sb);
6768 +static const struct file_operations dbgaufs_xigen_fop = {
6769 + .owner = THIS_MODULE,
6770 + .open = dbgaufs_xigen_open,
6771 + .release = dbgaufs_xi_release,
6772 + .read = dbgaufs_xi_read
6775 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6780 + * This function is a dynamic '__init' function actually,
6781 + * so the tiny check for si_rwsem is unnecessary.
6783 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6786 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6787 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6788 + &dbgaufs_xigen_fop);
6789 + if (sbinfo->si_dbgaufs_xigen)
6795 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6799 +#endif /* CONFIG_AUFS_EXPORT */
6801 +/* ---------------------------------------------------------------------- */
6803 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6806 + * This function is a dynamic '__fin' function actually,
6807 + * so the tiny check for si_rwsem is unnecessary.
6809 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6811 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6812 + sbinfo->si_dbgaufs = NULL;
6815 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6818 + char name[SysaufsSiNameLen];
6821 + * This function is a dynamic '__init' function actually,
6822 + * so the tiny check for si_rwsem is unnecessary.
6824 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6828 + AuErr1("/debug/aufs is uninitialized\n");
6833 + sysaufs_name(sbinfo, name);
6834 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6835 + if (unlikely(!sbinfo->si_dbgaufs))
6838 + /* regardless plink/noplink option */
6839 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6840 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6841 + &dbgaufs_plink_fop);
6842 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6845 + /* regardless xino/noxino option */
6846 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6847 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6848 + &dbgaufs_xib_fop);
6849 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6852 + err = dbgaufs_xigen_init(sbinfo);
6854 + goto out; /* success */
6857 + dbgaufs_si_fin(sbinfo);
6859 + if (unlikely(err))
6860 + pr_err("debugfs/aufs failed\n");
6864 +/* ---------------------------------------------------------------------- */
6866 +void dbgaufs_fin(void)
6868 + debugfs_remove(dbgaufs);
6871 +int __init dbgaufs_init(void)
6876 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6881 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6882 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6883 +++ linux/fs/aufs/dbgaufs.h 2021-09-06 21:02:45.273492232 +0200
6885 +/* SPDX-License-Identifier: GPL-2.0 */
6887 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6889 + * This program, aufs is free software; you can redistribute it and/or modify
6890 + * it under the terms of the GNU General Public License as published by
6891 + * the Free Software Foundation; either version 2 of the License, or
6892 + * (at your option) any later version.
6894 + * This program is distributed in the hope that it will be useful,
6895 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6896 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6897 + * GNU General Public License for more details.
6899 + * You should have received a copy of the GNU General Public License
6900 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6904 + * debugfs interface
6907 +#ifndef __DBGAUFS_H__
6908 +#define __DBGAUFS_H__
6912 +struct super_block;
6916 +#ifdef CONFIG_DEBUG_FS
6918 +void dbgaufs_xino_del(struct au_branch *br);
6919 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6920 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6921 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6922 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6923 +void dbgaufs_fin(void);
6924 +int __init dbgaufs_init(void);
6926 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6927 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6928 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6930 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6931 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6932 +AuStubVoid(dbgaufs_fin, void)
6933 +AuStubInt0(__init dbgaufs_init, void)
6934 +#endif /* CONFIG_DEBUG_FS */
6936 +#endif /* __KERNEL__ */
6937 +#endif /* __DBGAUFS_H__ */
6938 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6939 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6940 +++ linux/fs/aufs/dcsub.c 2021-09-06 21:02:45.273492232 +0200
6942 +// SPDX-License-Identifier: GPL-2.0
6944 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6946 + * This program, aufs is free software; you can redistribute it and/or modify
6947 + * it under the terms of the GNU General Public License as published by
6948 + * the Free Software Foundation; either version 2 of the License, or
6949 + * (at your option) any later version.
6951 + * This program is distributed in the hope that it will be useful,
6952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6954 + * GNU General Public License for more details.
6956 + * You should have received a copy of the GNU General Public License
6957 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6961 + * sub-routines for dentry cache
6966 +static void au_dpage_free(struct au_dpage *dpage)
6969 + struct dentry **p;
6971 + p = dpage->dentries;
6972 + for (i = 0; i < dpage->ndentry; i++)
6974 + free_page((unsigned long)dpage->dentries);
6977 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6983 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6984 + if (unlikely(!dpages->dpages))
6987 + p = (void *)__get_free_page(gfp);
6991 + dpages->dpages[0].ndentry = 0;
6992 + dpages->dpages[0].dentries = p;
6993 + dpages->ndpage = 1;
6994 + return 0; /* success */
6997 + au_kfree_try_rcu(dpages->dpages);
7002 +void au_dpages_free(struct au_dcsub_pages *dpages)
7005 + struct au_dpage *p;
7007 + p = dpages->dpages;
7008 + for (i = 0; i < dpages->ndpage; i++)
7009 + au_dpage_free(p++);
7010 + au_kfree_try_rcu(dpages->dpages);
7013 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7014 + struct dentry *dentry, gfp_t gfp)
7017 + struct au_dpage *dpage;
7020 + dpage = dpages->dpages + dpages->ndpage - 1;
7021 + sz = PAGE_SIZE / sizeof(dentry);
7022 + if (unlikely(dpage->ndentry >= sz)) {
7023 + AuLabel(new dpage);
7025 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7026 + p = au_kzrealloc(dpages->dpages, sz,
7027 + sz + sizeof(*dpages->dpages), gfp,
7032 + dpages->dpages = p;
7033 + dpage = dpages->dpages + dpages->ndpage;
7034 + p = (void *)__get_free_page(gfp);
7038 + dpage->ndentry = 0;
7039 + dpage->dentries = p;
7043 + AuDebugOn(au_dcount(dentry) <= 0);
7044 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7045 + return 0; /* success */
7051 +/* todo: BAD approach */
7052 +/* copied from linux/fs/dcache.c */
7060 +extern void d_walk(struct dentry *parent, void *data,
7061 + enum d_walk_ret (*enter)(void *, struct dentry *));
7063 +struct ac_dpages_arg {
7065 + struct au_dcsub_pages *dpages;
7066 + struct super_block *sb;
7067 + au_dpages_test test;
7071 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7073 + enum d_walk_ret ret;
7074 + struct ac_dpages_arg *arg = _arg;
7076 + ret = D_WALK_CONTINUE;
7077 + if (dentry->d_sb == arg->sb
7078 + && !IS_ROOT(dentry)
7079 + && au_dcount(dentry) > 0
7081 + && (!arg->test || arg->test(dentry, arg->arg))) {
7082 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7083 + if (unlikely(arg->err))
7084 + ret = D_WALK_QUIT;
7090 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7091 + au_dpages_test test, void *arg)
7093 + struct ac_dpages_arg args = {
7101 + d_walk(root, &args, au_call_dpages_append);
7106 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7107 + int do_include, au_dpages_test test, void *arg)
7112 + write_seqlock(&rename_lock);
7113 + spin_lock(&dentry->d_lock);
7115 + && au_dcount(dentry) > 0
7116 + && (!test || test(dentry, arg)))
7117 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7118 + spin_unlock(&dentry->d_lock);
7119 + if (unlikely(err))
7123 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7126 + while (!IS_ROOT(dentry)) {
7127 + dentry = dentry->d_parent; /* rename_lock is locked */
7128 + spin_lock(&dentry->d_lock);
7129 + if (au_dcount(dentry) > 0
7130 + && (!test || test(dentry, arg)))
7131 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7132 + spin_unlock(&dentry->d_lock);
7133 + if (unlikely(err))
7138 + write_sequnlock(&rename_lock);
7142 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7144 + return au_di(dentry) && dentry->d_sb == arg;
7147 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7148 + struct dentry *dentry, int do_include)
7150 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7151 + au_dcsub_dpages_aufs, dentry->d_sb);
7154 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7156 + struct path path[2] = {
7165 + return path_is_under(path + 0, path + 1);
7167 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7168 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7169 +++ linux/fs/aufs/dcsub.h 2021-09-06 21:02:45.273492232 +0200
7171 +/* SPDX-License-Identifier: GPL-2.0 */
7173 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7175 + * This program, aufs is free software; you can redistribute it and/or modify
7176 + * it under the terms of the GNU General Public License as published by
7177 + * the Free Software Foundation; either version 2 of the License, or
7178 + * (at your option) any later version.
7180 + * This program is distributed in the hope that it will be useful,
7181 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7182 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7183 + * GNU General Public License for more details.
7185 + * You should have received a copy of the GNU General Public License
7186 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7190 + * sub-routines for dentry cache
7193 +#ifndef __AUFS_DCSUB_H__
7194 +#define __AUFS_DCSUB_H__
7198 +#include <linux/dcache.h>
7199 +#include <linux/fs.h>
7203 + struct dentry **dentries;
7206 +struct au_dcsub_pages {
7208 + struct au_dpage *dpages;
7211 +/* ---------------------------------------------------------------------- */
7214 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7215 +void au_dpages_free(struct au_dcsub_pages *dpages);
7216 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7217 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7218 + au_dpages_test test, void *arg);
7219 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7220 + int do_include, au_dpages_test test, void *arg);
7221 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7222 + struct dentry *dentry, int do_include);
7223 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7225 +/* ---------------------------------------------------------------------- */
7228 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7229 + * include/linux/dcache.h. Try them (in the future).
7232 +static inline int au_d_hashed_positive(struct dentry *d)
7235 + struct inode *inode = d_inode(d);
7238 + if (unlikely(d_unhashed(d)
7239 + || d_is_negative(d)
7240 + || !inode->i_nlink))
7245 +static inline int au_d_linkable(struct dentry *d)
7248 + struct inode *inode = d_inode(d);
7250 + err = au_d_hashed_positive(d);
7252 + && d_is_positive(d)
7253 + && (inode->i_state & I_LINKABLE))
7258 +static inline int au_d_alive(struct dentry *d)
7261 + struct inode *inode;
7265 + err = au_d_hashed_positive(d);
7267 + inode = d_inode(d);
7268 + if (unlikely(d_unlinked(d)
7269 + || d_is_negative(d)
7270 + || !inode->i_nlink))
7276 +static inline int au_alive_dir(struct dentry *d)
7280 + err = au_d_alive(d);
7281 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7286 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7288 + return a->len == b->len
7289 + && !memcmp(a->name, b->name, a->len);
7294 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7296 + * the type of d_lockref.count became int, but the inlined function d_count()
7297 + * still returns unsigned int.
7298 + * I don't know why. Maybe it is for every d_count() users?
7299 + * Anyway au_dcount() lives on.
7301 +static inline int au_dcount(struct dentry *d)
7303 + return (int)d_count(d);
7306 +#endif /* __KERNEL__ */
7307 +#endif /* __AUFS_DCSUB_H__ */
7308 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7309 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7310 +++ linux/fs/aufs/debug.c 2021-09-06 21:02:45.273492232 +0200
7312 +// SPDX-License-Identifier: GPL-2.0
7314 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7316 + * This program, aufs is free software; you can redistribute it and/or modify
7317 + * it under the terms of the GNU General Public License as published by
7318 + * the Free Software Foundation; either version 2 of the License, or
7319 + * (at your option) any later version.
7321 + * This program is distributed in the hope that it will be useful,
7322 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7323 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7324 + * GNU General Public License for more details.
7326 + * You should have received a copy of the GNU General Public License
7327 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7331 + * debug print functions
7334 +#include <linux/iversion.h>
7337 +/* Returns 0, or -errno. arg is in kp->arg. */
7338 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7342 + err = kstrtoint(val, 0, &n);
7352 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7353 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7358 + return sprintf(buffer, "%d", atomic_read(a));
7361 +static struct kernel_param_ops param_ops_atomic_t = {
7362 + .set = param_atomic_t_set,
7363 + .get = param_atomic_t_get
7364 + /* void (*free)(void *arg) */
7367 +atomic_t aufs_debug = ATOMIC_INIT(0);
7368 +MODULE_PARM_DESC(debug, "debug print");
7369 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7371 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7372 +char *au_plevel = KERN_DEBUG;
7373 +#define dpri(fmt, ...) do { \
7375 + && strcmp(au_plevel, KERN_DEBUG)) \
7376 + || au_debug_test()) \
7377 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7380 +/* ---------------------------------------------------------------------- */
7382 +void au_dpri_whlist(struct au_nhash *whlist)
7384 + unsigned long ul, n;
7385 + struct hlist_head *head;
7386 + struct au_vdir_wh *pos;
7388 + n = whlist->nh_num;
7389 + head = whlist->nh_head;
7390 + for (ul = 0; ul < n; ul++) {
7391 + hlist_for_each_entry(pos, head, wh_hash)
7392 + dpri("b%d, %.*s, %d\n",
7394 + pos->wh_str.len, pos->wh_str.name,
7400 +void au_dpri_vdir(struct au_vdir *vdir)
7403 + union au_vdir_deblk_p p;
7406 + if (!vdir || IS_ERR(vdir)) {
7407 + dpri("err %ld\n", PTR_ERR(vdir));
7411 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7412 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7413 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7414 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7415 + p.deblk = vdir->vd_deblk[ul];
7417 + dpri("[%lu]: %p\n", ul, o);
7421 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7422 + struct dentry *wh)
7427 + if (!inode || IS_ERR(inode)) {
7428 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7432 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7433 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7434 + && sizeof(inode->i_blocks) != sizeof(u64));
7436 + n = (void *)wh->d_name.name;
7437 + l = wh->d_name.len;
7440 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7441 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7443 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7444 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7445 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7446 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7447 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7448 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7449 + inode->i_generation,
7450 + l ? ", wh " : "", l, n);
7454 +void au_dpri_inode(struct inode *inode)
7456 + struct au_iinfo *iinfo;
7457 + struct au_hinode *hi;
7458 + aufs_bindex_t bindex;
7461 + err = do_pri_inode(-1, inode, -1, NULL);
7462 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7465 + iinfo = au_ii(inode);
7466 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7467 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7468 + if (iinfo->ii_btop < 0)
7471 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7472 + hi = au_hinode(iinfo, bindex);
7474 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7478 +void au_dpri_dalias(struct inode *inode)
7482 + spin_lock(&inode->i_lock);
7483 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7484 + au_dpri_dentry(d);
7485 + spin_unlock(&inode->i_lock);
7488 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7490 + struct dentry *wh = NULL;
7492 + struct inode *inode;
7493 + struct au_iinfo *iinfo;
7494 + struct au_hinode *hi;
7496 + if (!dentry || IS_ERR(dentry)) {
7497 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7500 + /* do not call dget_parent() here */
7501 + /* note: access d_xxx without d_lock */
7502 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7503 + bindex, dentry, dentry,
7504 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7505 + au_dcount(dentry), dentry->d_flags,
7506 + d_unhashed(dentry) ? "un" : "");
7509 + if (d_is_positive(dentry))
7510 + inode = d_inode(dentry);
7512 + && au_test_aufs(dentry->d_sb)
7514 + && !au_is_bad_inode(inode)) {
7515 + iinfo = au_ii(inode);
7516 + hi = au_hinode(iinfo, bindex);
7518 + wh = hi->hi_whdentry;
7520 + do_pri_inode(bindex, inode, hn, wh);
7524 +void au_dpri_dentry(struct dentry *dentry)
7526 + struct au_dinfo *dinfo;
7527 + aufs_bindex_t bindex;
7530 + err = do_pri_dentry(-1, dentry);
7531 + if (err || !au_test_aufs(dentry->d_sb))
7534 + dinfo = au_di(dentry);
7537 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7538 + dinfo->di_btop, dinfo->di_bbot,
7539 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7540 + dinfo->di_tmpfile);
7541 + if (dinfo->di_btop < 0)
7543 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7544 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7547 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7551 + if (!file || IS_ERR(file)) {
7552 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7557 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7558 + && au_test_aufs(file->f_path.dentry->d_sb)
7560 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7561 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7562 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7563 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7564 + file->f_version, file->f_pos, a);
7565 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7566 + do_pri_dentry(bindex, file->f_path.dentry);
7570 +void au_dpri_file(struct file *file)
7572 + struct au_finfo *finfo;
7573 + struct au_fidir *fidir;
7574 + struct au_hfile *hfile;
7575 + aufs_bindex_t bindex;
7578 + err = do_pri_file(-1, file);
7580 + || IS_ERR_OR_NULL(file->f_path.dentry)
7581 + || !au_test_aufs(file->f_path.dentry->d_sb))
7584 + finfo = au_fi(file);
7587 + if (finfo->fi_btop < 0)
7589 + fidir = finfo->fi_hdir;
7591 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7593 + for (bindex = finfo->fi_btop;
7594 + bindex >= 0 && bindex <= fidir->fd_bbot;
7596 + hfile = fidir->fd_hfile + bindex;
7597 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7601 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7603 + struct vfsmount *mnt;
7604 + struct super_block *sb;
7606 + if (!br || IS_ERR(br))
7608 + mnt = au_br_mnt(br);
7609 + if (!mnt || IS_ERR(mnt))
7612 + if (!sb || IS_ERR(sb))
7615 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7616 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7618 + bindex, br->br_perm, br->br_id, br->br_wbr,
7619 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7620 + sb->s_flags, sb->s_count,
7621 + atomic_read(&sb->s_active),
7622 + !!au_xino_file(br->br_xino, /*idx*/-1));
7626 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7630 +void au_dpri_sb(struct super_block *sb)
7632 + struct au_sbinfo *sbinfo;
7633 + aufs_bindex_t bindex;
7635 + /* to reduce stack size */
7637 + struct vfsmount mnt;
7638 + struct au_branch fake;
7641 + /* this function can be called from magic sysrq */
7642 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7643 + if (unlikely(!a)) {
7644 + dpri("no memory\n");
7648 + a->mnt.mnt_sb = sb;
7649 + a->fake.br_path.mnt = &a->mnt;
7650 + err = do_pri_br(-1, &a->fake);
7652 + dpri("dev 0x%x\n", sb->s_dev);
7653 + if (err || !au_test_aufs(sb))
7656 + sbinfo = au_sbi(sb);
7659 + dpri("nw %d, gen %u, kobj %d\n",
7660 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7661 + kref_read(&sbinfo->si_kobj.kref));
7662 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7663 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7666 +/* ---------------------------------------------------------------------- */
7668 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7670 + struct inode *h_inode, *inode = d_inode(dentry);
7671 + struct dentry *h_dentry;
7672 + aufs_bindex_t bindex, bbot, bi;
7674 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7677 + bbot = au_dbbot(dentry);
7678 + bi = au_ibbot(inode);
7681 + bindex = au_dbtop(dentry);
7682 + bi = au_ibtop(inode);
7686 + for (; bindex <= bbot; bindex++) {
7687 + h_dentry = au_h_dptr(dentry, bindex);
7690 + h_inode = au_h_iptr(inode, bindex);
7691 + if (unlikely(h_inode != d_inode(h_dentry))) {
7693 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7694 + AuDbgDentry(dentry);
7695 + AuDbgInode(inode);
7702 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7705 + struct au_dcsub_pages dpages;
7706 + struct au_dpage *dpage;
7707 + struct dentry **dentries;
7709 + err = au_dpages_init(&dpages, GFP_NOFS);
7711 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7713 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7714 + dpage = dpages.dpages + i;
7715 + dentries = dpage->dentries;
7716 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7717 + AuDebugOn(au_digen_test(dentries[j], sigen));
7719 + au_dpages_free(&dpages);
7722 +void au_dbg_verify_kthread(void)
7724 + if (au_wkq_test()) {
7727 + * It may be recursive, but udba=notify between two aufs mounts,
7728 + * where a single ro branch is shared, is not a problem.
7734 +/* ---------------------------------------------------------------------- */
7736 +int __init au_debug_init(void)
7738 + aufs_bindex_t bindex;
7739 + struct au_vdir_destr destr;
7742 + AuDebugOn(bindex >= 0);
7745 + AuDebugOn(destr.len < NAME_MAX);
7747 +#ifdef CONFIG_4KSTACKS
7748 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7753 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7754 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7755 +++ linux/fs/aufs/debug.h 2021-09-06 21:02:45.273492232 +0200
7757 +/* SPDX-License-Identifier: GPL-2.0 */
7759 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7761 + * This program, aufs is free software; you can redistribute it and/or modify
7762 + * it under the terms of the GNU General Public License as published by
7763 + * the Free Software Foundation; either version 2 of the License, or
7764 + * (at your option) any later version.
7766 + * This program is distributed in the hope that it will be useful,
7767 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7768 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7769 + * GNU General Public License for more details.
7771 + * You should have received a copy of the GNU General Public License
7772 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7776 + * debug print functions
7779 +#ifndef __AUFS_DEBUG_H__
7780 +#define __AUFS_DEBUG_H__
7784 +#include <linux/atomic.h>
7785 +#include <linux/module.h>
7786 +#include <linux/kallsyms.h>
7787 +#include <linux/sysrq.h>
7789 +#ifdef CONFIG_AUFS_DEBUG
7790 +#define AuDebugOn(a) BUG_ON(a)
7792 +/* module parameter */
7793 +extern atomic_t aufs_debug;
7794 +static inline void au_debug_on(void)
7796 + atomic_inc(&aufs_debug);
7798 +static inline void au_debug_off(void)
7800 + atomic_dec_if_positive(&aufs_debug);
7803 +static inline int au_debug_test(void)
7805 + return atomic_read(&aufs_debug) > 0;
7808 +#define AuDebugOn(a) do {} while (0)
7809 +AuStubVoid(au_debug_on, void)
7810 +AuStubVoid(au_debug_off, void)
7811 +AuStubInt0(au_debug_test, void)
7812 +#endif /* CONFIG_AUFS_DEBUG */
7814 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7816 +/* ---------------------------------------------------------------------- */
7820 +#define AuDbg(fmt, ...) do { \
7821 + if (au_debug_test()) \
7822 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7824 +#define AuLabel(l) AuDbg(#l "\n")
7825 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7826 +#define AuWarn1(fmt, ...) do { \
7827 + static unsigned char _c; \
7829 + pr_warn(fmt, ##__VA_ARGS__); \
7832 +#define AuErr1(fmt, ...) do { \
7833 + static unsigned char _c; \
7835 + pr_err(fmt, ##__VA_ARGS__); \
7838 +#define AuIOErr1(fmt, ...) do { \
7839 + static unsigned char _c; \
7841 + AuIOErr(fmt, ##__VA_ARGS__); \
7844 +#define AuUnsupportMsg "This operation is not supported." \
7845 + " Please report this application to aufs-users ML."
7846 +#define AuUnsupport(fmt, ...) do { \
7847 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7851 +#define AuTraceErr(e) do { \
7852 + if (unlikely((e) < 0)) \
7853 + AuDbg("err %d\n", (int)(e)); \
7856 +#define AuTraceErrPtr(p) do { \
7858 + AuDbg("err %ld\n", PTR_ERR(p)); \
7861 +/* dirty macros for debug print, use with "%.*s" and caution */
7862 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7864 +/* ---------------------------------------------------------------------- */
7867 +#ifdef CONFIG_AUFS_DEBUG
7868 +extern struct mutex au_dbg_mtx;
7869 +extern char *au_plevel;
7871 +void au_dpri_whlist(struct au_nhash *whlist);
7873 +void au_dpri_vdir(struct au_vdir *vdir);
7875 +void au_dpri_inode(struct inode *inode);
7876 +void au_dpri_dalias(struct inode *inode);
7877 +void au_dpri_dentry(struct dentry *dentry);
7879 +void au_dpri_file(struct file *filp);
7880 +struct super_block;
7881 +void au_dpri_sb(struct super_block *sb);
7883 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7884 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7885 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7886 +void au_dbg_verify_kthread(void);
7888 +int __init au_debug_init(void);
7890 +#define AuDbgWhlist(w) do { \
7891 + mutex_lock(&au_dbg_mtx); \
7893 + au_dpri_whlist(w); \
7894 + mutex_unlock(&au_dbg_mtx); \
7897 +#define AuDbgVdir(v) do { \
7898 + mutex_lock(&au_dbg_mtx); \
7900 + au_dpri_vdir(v); \
7901 + mutex_unlock(&au_dbg_mtx); \
7904 +#define AuDbgInode(i) do { \
7905 + mutex_lock(&au_dbg_mtx); \
7907 + au_dpri_inode(i); \
7908 + mutex_unlock(&au_dbg_mtx); \
7911 +#define AuDbgDAlias(i) do { \
7912 + mutex_lock(&au_dbg_mtx); \
7914 + au_dpri_dalias(i); \
7915 + mutex_unlock(&au_dbg_mtx); \
7918 +#define AuDbgDentry(d) do { \
7919 + mutex_lock(&au_dbg_mtx); \
7921 + au_dpri_dentry(d); \
7922 + mutex_unlock(&au_dbg_mtx); \
7925 +#define AuDbgFile(f) do { \
7926 + mutex_lock(&au_dbg_mtx); \
7928 + au_dpri_file(f); \
7929 + mutex_unlock(&au_dbg_mtx); \
7932 +#define AuDbgSb(sb) do { \
7933 + mutex_lock(&au_dbg_mtx); \
7934 + AuDbg(#sb "\n"); \
7936 + mutex_unlock(&au_dbg_mtx); \
7939 +#define AuDbgSym(addr) do { \
7940 + char sym[KSYM_SYMBOL_LEN]; \
7941 + sprint_symbol(sym, (unsigned long)addr); \
7942 + AuDbg("%s\n", sym); \
7945 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7946 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7947 +AuStubVoid(au_dbg_verify_kthread, void)
7948 +AuStubInt0(__init au_debug_init, void)
7950 +#define AuDbgWhlist(w) do {} while (0)
7951 +#define AuDbgVdir(v) do {} while (0)
7952 +#define AuDbgInode(i) do {} while (0)
7953 +#define AuDbgDAlias(i) do {} while (0)
7954 +#define AuDbgDentry(d) do {} while (0)
7955 +#define AuDbgFile(f) do {} while (0)
7956 +#define AuDbgSb(sb) do {} while (0)
7957 +#define AuDbgSym(addr) do {} while (0)
7958 +#endif /* CONFIG_AUFS_DEBUG */
7960 +/* ---------------------------------------------------------------------- */
7962 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7963 +int __init au_sysrq_init(void);
7964 +void au_sysrq_fin(void);
7966 +#ifdef CONFIG_HW_CONSOLE
7967 +#define au_dbg_blocked() do { \
7969 + handle_sysrq('w'); \
7972 +AuStubVoid(au_dbg_blocked, void)
7976 +AuStubInt0(__init au_sysrq_init, void)
7977 +AuStubVoid(au_sysrq_fin, void)
7978 +AuStubVoid(au_dbg_blocked, void)
7979 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7981 +#endif /* __KERNEL__ */
7982 +#endif /* __AUFS_DEBUG_H__ */
7983 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7984 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7985 +++ linux/fs/aufs/dentry.c 2021-09-06 21:02:45.273492232 +0200
7987 +// SPDX-License-Identifier: GPL-2.0
7989 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7991 + * This program, aufs is free software; you can redistribute it and/or modify
7992 + * it under the terms of the GNU General Public License as published by
7993 + * the Free Software Foundation; either version 2 of the License, or
7994 + * (at your option) any later version.
7996 + * This program is distributed in the hope that it will be useful,
7997 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7998 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7999 + * GNU General Public License for more details.
8001 + * You should have received a copy of the GNU General Public License
8002 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8006 + * lookup and dentry operations
8009 +#include <linux/iversion.h>
8010 +#include <linux/namei.h>
8014 + * returns positive/negative dentry, NULL or an error.
8015 + * NULL means whiteout-ed or not-found.
8017 +static struct dentry*
8018 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8019 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8021 + struct dentry *h_dentry;
8022 + struct inode *h_inode;
8023 + struct au_branch *br;
8024 + struct user_namespace *h_userns;
8025 + int wh_found, opq;
8026 + unsigned char wh_able;
8027 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8028 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8032 + br = au_sbr(dentry->d_sb, bindex);
8033 + h_userns = au_br_userns(br);
8034 + wh_able = !!au_br_whable(br->br_perm);
8036 + wh_found = au_wh_test(h_userns, h_parent, &args->whname,
8038 + h_dentry = ERR_PTR(wh_found);
8041 + if (unlikely(wh_found < 0))
8044 + /* We found a whiteout */
8045 + /* au_set_dbbot(dentry, bindex); */
8046 + au_set_dbwh(dentry, bindex);
8048 + return NULL; /* success */
8052 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8054 + h_dentry = au_sio_lkup_one(h_userns, args->name, h_parent);
8055 + if (IS_ERR(h_dentry)) {
8056 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8062 + h_inode = d_inode(h_dentry);
8063 + if (d_is_negative(h_dentry)) {
8066 + } else if (wh_found
8067 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8069 + else if (au_ftest_lkup(args->flags, DIRREN)
8071 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8072 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8073 + (unsigned long long)h_inode->i_ino);
8077 + if (au_dbbot(dentry) <= bindex)
8078 + au_set_dbbot(dentry, bindex);
8079 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8080 + au_set_dbtop(dentry, bindex);
8081 + au_set_h_dptr(dentry, bindex, h_dentry);
8083 + if (!d_is_dir(h_dentry)
8085 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8086 + goto out; /* success */
8088 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8089 + opq = au_diropq_test(h_userns, h_dentry);
8090 + inode_unlock_shared(h_inode);
8092 + au_set_dbdiropq(dentry, bindex);
8093 + else if (unlikely(opq < 0)) {
8094 + au_set_h_dptr(dentry, bindex, NULL);
8095 + h_dentry = ERR_PTR(opq);
8106 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8108 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8109 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8115 + * returns the number of lower positive dentries,
8116 + * otherwise an error.
8117 + * can be called at unlinking with @type is zero.
8119 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8120 + unsigned int flags)
8122 + int npositive, err;
8123 + aufs_bindex_t bindex, btail, bdiropq;
8124 + unsigned char isdir, dirperm1, dirren;
8125 + struct au_do_lookup_args args = {
8127 + .name = &dentry->d_name
8129 + struct dentry *parent;
8130 + struct super_block *sb;
8132 + sb = dentry->d_sb;
8133 + err = au_test_shwh(sb, args.name);
8134 + if (unlikely(err))
8137 + err = au_wh_name_alloc(&args.whname, args.name);
8138 + if (unlikely(err))
8141 + isdir = !!d_is_dir(dentry);
8142 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8143 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8145 + au_fset_lkup(args.flags, DIRREN);
8148 + parent = dget_parent(dentry);
8149 + btail = au_dbtaildir(parent);
8150 + for (bindex = btop; bindex <= btail; bindex++) {
8151 + struct dentry *h_parent, *h_dentry;
8152 + struct inode *h_inode, *h_dir;
8153 + struct au_branch *br;
8155 + h_dentry = au_h_dptr(dentry, bindex);
8157 + if (d_is_positive(h_dentry))
8161 + h_parent = au_h_dptr(parent, bindex);
8162 + if (!h_parent || !d_is_dir(h_parent))
8166 + /* if the inum matches, then use the prepared name */
8167 + err = au_dr_lkup_name(&args, bindex);
8168 + if (unlikely(err))
8172 + h_dir = d_inode(h_parent);
8173 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8174 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8175 + inode_unlock_shared(h_dir);
8176 + err = PTR_ERR(h_dentry);
8177 + if (IS_ERR(h_dentry))
8180 + au_fclr_lkup(args.flags, ALLOW_NEG);
8182 + au_fset_lkup(args.flags, IGNORE_PERM);
8184 + if (au_dbwh(dentry) == bindex)
8188 + if (d_is_negative(h_dentry))
8190 + h_inode = d_inode(h_dentry);
8193 + args.type = h_inode->i_mode & S_IFMT;
8194 + if (args.type != S_IFDIR)
8197 + /* the type of lower may be different */
8198 + bdiropq = au_dbdiropq(dentry);
8199 + if (bdiropq >= 0 && bdiropq <= bindex)
8202 + br = au_sbr(sb, bindex);
8204 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8205 + /*add_ent*/NULL)) {
8206 + /* prepare next name to lookup */
8207 + err = au_dr_lkup(&args, dentry, bindex);
8208 + if (unlikely(err))
8214 + AuLabel(positive);
8215 + au_update_dbtop(dentry);
8218 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8219 + && au_dbtop(dentry) < 0)) {
8221 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8227 + au_kfree_try_rcu(args.whname.name);
8229 + au_dr_lkup_fin(&args);
8234 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8235 + struct dentry *parent)
8237 + struct dentry *dentry;
8240 + if (!au_test_h_perm_sio(userns, d_inode(parent), MAY_EXEC))
8241 + dentry = vfsub_lkup_one(name, parent);
8243 + struct vfsub_lkup_one_args args = {
8249 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8250 + if (unlikely(wkq_err))
8251 + dentry = ERR_PTR(wkq_err);
8258 + * lookup @dentry on @bindex which should be negative.
8260 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8263 + struct dentry *parent, *h_parent, *h_dentry;
8264 + struct au_branch *br;
8265 + struct user_namespace *h_userns;
8267 + parent = dget_parent(dentry);
8268 + h_parent = au_h_dptr(parent, bindex);
8269 + br = au_sbr(dentry->d_sb, bindex);
8270 + h_userns = au_br_userns(br);
8272 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8274 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, h_parent);
8275 + err = PTR_ERR(h_dentry);
8276 + if (IS_ERR(h_dentry))
8278 + if (unlikely(d_is_positive(h_dentry))) {
8280 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8286 + if (bindex < au_dbtop(dentry))
8287 + au_set_dbtop(dentry, bindex);
8288 + if (au_dbbot(dentry) < bindex)
8289 + au_set_dbbot(dentry, bindex);
8290 + au_set_h_dptr(dentry, bindex, h_dentry);
8297 +/* ---------------------------------------------------------------------- */
8299 +/* subset of struct inode */
8301 + unsigned long i_ino;
8302 + /* unsigned int i_nlink; */
8308 + blkcnt_t i_blocks;
8313 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8315 + ia->i_ino = h_inode->i_ino;
8316 + /* ia->i_nlink = h_inode->i_nlink; */
8317 + ia->i_uid = h_inode->i_uid;
8318 + ia->i_gid = h_inode->i_gid;
8319 + ia->i_version = inode_query_iversion(h_inode);
8321 + ia->i_size = h_inode->i_size;
8322 + ia->i_blocks = h_inode->i_blocks;
8324 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8327 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8329 + return ia->i_ino != h_inode->i_ino
8330 + /* || ia->i_nlink != h_inode->i_nlink */
8331 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8332 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8333 + || !inode_eq_iversion(h_inode, ia->i_version)
8335 + || ia->i_size != h_inode->i_size
8336 + || ia->i_blocks != h_inode->i_blocks
8338 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8341 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8342 + struct au_branch *br)
8345 + struct au_iattr ia;
8346 + struct inode *h_inode;
8347 + struct dentry *h_d;
8348 + struct super_block *h_sb;
8351 + memset(&ia, -1, sizeof(ia));
8352 + h_sb = h_dentry->d_sb;
8354 + if (d_is_positive(h_dentry)) {
8355 + h_inode = d_inode(h_dentry);
8356 + au_iattr_save(&ia, h_inode);
8357 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8358 + /* nfs d_revalidate may return 0 for negative dentry */
8359 + /* fuse d_revalidate always return 0 for negative dentry */
8362 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8363 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8364 + err = PTR_ERR(h_d);
8369 + if (unlikely(h_d != h_dentry
8370 + || d_inode(h_d) != h_inode
8371 + || (h_inode && au_iattr_test(&ia, h_inode))))
8372 + err = au_busy_or_stale();
8380 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8381 + struct dentry *h_parent, struct au_branch *br)
8386 + if (udba == AuOpt_UDBA_REVAL
8387 + && !au_test_fs_remote(h_dentry->d_sb)) {
8389 + err = (d_inode(h_dentry->d_parent) != h_dir);
8390 + } else if (udba != AuOpt_UDBA_NONE)
8391 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8396 +/* ---------------------------------------------------------------------- */
8398 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8401 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8402 + struct au_hdentry tmp, *p, *q;
8403 + struct au_dinfo *dinfo;
8404 + struct super_block *sb;
8406 + DiMustWriteLock(dentry);
8408 + sb = dentry->d_sb;
8409 + dinfo = au_di(dentry);
8410 + bbot = dinfo->di_bbot;
8411 + bwh = dinfo->di_bwh;
8412 + bdiropq = dinfo->di_bdiropq;
8413 + bindex = dinfo->di_btop;
8414 + p = au_hdentry(dinfo, bindex);
8415 + for (; bindex <= bbot; bindex++, p++) {
8416 + if (!p->hd_dentry)
8419 + new_bindex = au_br_index(sb, p->hd_id);
8420 + if (new_bindex == bindex)
8423 + if (dinfo->di_bwh == bindex)
8425 + if (dinfo->di_bdiropq == bindex)
8426 + bdiropq = new_bindex;
8427 + if (new_bindex < 0) {
8429 + p->hd_dentry = NULL;
8433 + /* swap two lower dentries, and loop again */
8434 + q = au_hdentry(dinfo, new_bindex);
8438 + if (tmp.hd_dentry) {
8444 + dinfo->di_bwh = -1;
8445 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8446 + dinfo->di_bwh = bwh;
8448 + dinfo->di_bdiropq = -1;
8450 + && bdiropq <= au_sbbot(sb)
8451 + && au_sbr_whable(sb, bdiropq))
8452 + dinfo->di_bdiropq = bdiropq;
8455 + dinfo->di_btop = -1;
8456 + dinfo->di_bbot = -1;
8457 + bbot = au_dbbot(parent);
8459 + p = au_hdentry(dinfo, bindex);
8460 + for (; bindex <= bbot; bindex++, p++)
8461 + if (p->hd_dentry) {
8462 + dinfo->di_btop = bindex;
8466 + if (dinfo->di_btop >= 0) {
8468 + p = au_hdentry(dinfo, bindex);
8469 + for (; bindex >= 0; bindex--, p--)
8470 + if (p->hd_dentry) {
8471 + dinfo->di_bbot = bindex;
8480 +static void au_do_hide(struct dentry *dentry)
8482 + struct inode *inode;
8484 + if (d_really_is_positive(dentry)) {
8485 + inode = d_inode(dentry);
8486 + if (!d_is_dir(dentry)) {
8487 + if (inode->i_nlink && !d_unhashed(dentry))
8488 + drop_nlink(inode);
8490 + clear_nlink(inode);
8491 + /* stop next lookup */
8492 + inode->i_flags |= S_DEAD;
8494 + smp_mb(); /* necessary? */
8499 +static int au_hide_children(struct dentry *parent)
8501 + int err, i, j, ndentry;
8502 + struct au_dcsub_pages dpages;
8503 + struct au_dpage *dpage;
8504 + struct dentry *dentry;
8506 + err = au_dpages_init(&dpages, GFP_NOFS);
8507 + if (unlikely(err))
8509 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8510 + if (unlikely(err))
8513 + /* in reverse order */
8514 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8515 + dpage = dpages.dpages + i;
8516 + ndentry = dpage->ndentry;
8517 + for (j = ndentry - 1; j >= 0; j--) {
8518 + dentry = dpage->dentries[j];
8519 + if (dentry != parent)
8520 + au_do_hide(dentry);
8525 + au_dpages_free(&dpages);
8530 +static void au_hide(struct dentry *dentry)
8534 + AuDbgDentry(dentry);
8535 + if (d_is_dir(dentry)) {
8536 + /* shrink_dcache_parent(dentry); */
8537 + err = au_hide_children(dentry);
8538 + if (unlikely(err))
8539 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8542 + au_do_hide(dentry);
8546 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8548 + * a dirty branch is added
8549 + * - on the top of layers
8550 + * - in the middle of layers
8551 + * - to the bottom of layers
8553 + * on the added branch there exists
8556 + * - a same named entry
8558 + * * negative --> positive
8559 + * * positive --> positive
8560 + * - type is unchanged
8561 + * - type is changed
8563 + * * negative --> negative
8564 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8567 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8568 + struct au_dinfo *tmp)
8571 + aufs_bindex_t bindex, bbot;
8573 + struct dentry *dentry;
8574 + struct inode *inode;
8576 + } orig_h, tmp_h = {
8579 + struct au_hdentry *hd;
8580 + struct inode *inode, *h_inode;
8581 + struct dentry *h_dentry;
8584 + AuDebugOn(dinfo->di_btop < 0);
8586 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8587 + orig_h.inode = NULL;
8588 + if (d_is_positive(orig_h.dentry)) {
8589 + orig_h.inode = d_inode(orig_h.dentry);
8590 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8592 + if (tmp->di_btop >= 0) {
8593 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8594 + if (d_is_positive(tmp_h.dentry)) {
8595 + tmp_h.inode = d_inode(tmp_h.dentry);
8596 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8601 + if (d_really_is_positive(dentry))
8602 + inode = d_inode(dentry);
8603 + if (!orig_h.inode) {
8604 + AuDbg("negative originally\n");
8610 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8611 + AuDebugOn(dinfo->di_bdiropq != -1);
8613 + if (!tmp_h.inode) {
8614 + AuDbg("negative --> negative\n");
8615 + /* should have only one negative lower */
8616 + if (tmp->di_btop >= 0
8617 + && tmp->di_btop < dinfo->di_btop) {
8618 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8619 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8620 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8621 + au_di_cp(dinfo, tmp);
8622 + hd = au_hdentry(tmp, tmp->di_btop);
8623 + au_set_h_dptr(dentry, tmp->di_btop,
8624 + dget(hd->hd_dentry));
8626 + au_dbg_verify_dinode(dentry);
8628 + AuDbg("negative --> positive\n");
8630 + * similar to the behaviour of creating with bypassing
8632 + * unhash it in order to force an error in the
8633 + * succeeding create operation.
8634 + * we should not set S_DEAD here.
8637 + /* au_di_swap(tmp, dinfo); */
8638 + au_dbg_verify_dinode(dentry);
8641 + AuDbg("positive originally\n");
8642 + /* inode may be NULL */
8643 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8644 + if (!tmp_h.inode) {
8645 + AuDbg("positive --> negative\n");
8646 + /* or bypassing aufs */
8648 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8649 + dinfo->di_bwh = tmp->di_bwh;
8651 + err = au_refresh_hinode_self(inode);
8652 + au_dbg_verify_dinode(dentry);
8653 + } else if (orig_h.mode == tmp_h.mode) {
8654 + AuDbg("positive --> positive, same type\n");
8655 + if (!S_ISDIR(orig_h.mode)
8656 + && dinfo->di_btop > tmp->di_btop) {
8658 + * similar to the behaviour of removing and
8663 + err = au_refresh_hinode_self(inode);
8664 + au_dbg_verify_dinode(dentry);
8666 + /* fill empty slots */
8667 + if (dinfo->di_btop > tmp->di_btop)
8668 + dinfo->di_btop = tmp->di_btop;
8669 + if (dinfo->di_bbot < tmp->di_bbot)
8670 + dinfo->di_bbot = tmp->di_bbot;
8671 + dinfo->di_bwh = tmp->di_bwh;
8672 + dinfo->di_bdiropq = tmp->di_bdiropq;
8673 + bbot = dinfo->di_bbot;
8674 + bindex = tmp->di_btop;
8675 + hd = au_hdentry(tmp, bindex);
8676 + for (; bindex <= bbot; bindex++, hd++) {
8677 + if (au_h_dptr(dentry, bindex))
8679 + h_dentry = hd->hd_dentry;
8682 + AuDebugOn(d_is_negative(h_dentry));
8683 + h_inode = d_inode(h_dentry);
8684 + AuDebugOn(orig_h.mode
8685 + != (h_inode->i_mode
8687 + au_set_h_dptr(dentry, bindex,
8691 + err = au_refresh_hinode(inode, dentry);
8692 + au_dbg_verify_dinode(dentry);
8695 + AuDbg("positive --> positive, different type\n");
8696 + /* similar to the behaviour of removing and creating */
8699 + err = au_refresh_hinode_self(inode);
8700 + au_dbg_verify_dinode(dentry);
8708 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8710 + const struct dentry_operations *dop
8711 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8712 + static const unsigned int mask
8713 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8715 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8717 + if (dentry->d_op == dop)
8720 + AuDbg("%pd\n", dentry);
8721 + spin_lock(&dentry->d_lock);
8722 + if (dop == &aufs_dop)
8723 + dentry->d_flags |= mask;
8725 + dentry->d_flags &= ~mask;
8726 + dentry->d_op = dop;
8727 + spin_unlock(&dentry->d_lock);
8730 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8732 + int err, ebrange, nbr;
8733 + unsigned int sigen;
8734 + struct au_dinfo *dinfo, *tmp;
8735 + struct super_block *sb;
8736 + struct inode *inode;
8738 + DiMustWriteLock(dentry);
8739 + AuDebugOn(IS_ROOT(dentry));
8740 + AuDebugOn(d_really_is_negative(parent));
8742 + sb = dentry->d_sb;
8743 + sigen = au_sigen(sb);
8744 + err = au_digen_test(parent, sigen);
8745 + if (unlikely(err))
8748 + nbr = au_sbbot(sb) + 1;
8749 + dinfo = au_di(dentry);
8750 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8751 + if (unlikely(err))
8753 + ebrange = au_dbrange_test(dentry);
8755 + ebrange = au_do_refresh_hdentry(dentry, parent);
8757 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8758 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8759 + if (d_really_is_positive(dentry)) {
8760 + inode = d_inode(dentry);
8761 + err = au_refresh_hinode_self(inode);
8763 + au_dbg_verify_dinode(dentry);
8765 + goto out_dgen; /* success */
8769 + /* temporary dinfo */
8770 + AuDbgDentry(dentry);
8772 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8773 + if (unlikely(!tmp))
8775 + au_di_swap(tmp, dinfo);
8776 + /* returns the number of positive dentries */
8778 + * if current working dir is removed, it returns an error.
8779 + * but the dentry is legal.
8781 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8782 + AuDbgDentry(dentry);
8783 + au_di_swap(tmp, dinfo);
8784 + if (err == -ENOENT)
8787 + /* compare/refresh by dinfo */
8788 + AuDbgDentry(dentry);
8789 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8790 + au_dbg_verify_dinode(dentry);
8793 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8794 + au_rw_write_unlock(&tmp->di_rwsem);
8796 + if (unlikely(err))
8800 + au_update_digen(dentry);
8802 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8803 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8804 + AuDbgDentry(dentry);
8810 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8811 + struct dentry *dentry, aufs_bindex_t bindex)
8816 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8819 + AuDbg("b%d\n", bindex);
8821 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8822 + * due to whiteout and branch permission.
8824 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8825 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8826 + /* it may return tri-state */
8827 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8829 + if (unlikely(valid < 0))
8839 +/* todo: remove this */
8840 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8841 + unsigned int flags, int do_udba, int dirren)
8844 + umode_t mode, h_mode;
8845 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8846 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8847 + struct inode *h_inode, *h_cached_inode;
8848 + struct dentry *h_dentry;
8849 + struct qstr *name, *h_name;
8856 + unhashed = !!d_unhashed(dentry);
8857 + is_root = !!IS_ROOT(dentry);
8858 + name = &dentry->d_name;
8859 + tmpfile = au_di(dentry)->di_tmpfile;
8862 + * Theoretically, REVAL test should be unnecessary in case of
8864 + * But {fs,i}notify doesn't fire some necessary events,
8865 + * IN_ATTRIB for atime/nlink/pageio
8866 + * Let's do REVAL test too.
8868 + if (do_udba && inode) {
8869 + mode = (inode->i_mode & S_IFMT);
8870 + plus = (inode->i_nlink > 0);
8871 + ibs = au_ibtop(inode);
8872 + ibe = au_ibbot(inode);
8875 + btop = au_dbtop(dentry);
8877 + if (inode && S_ISDIR(inode->i_mode))
8878 + btail = au_dbtaildir(dentry);
8879 + for (bindex = btop; bindex <= btail; bindex++) {
8880 + h_dentry = au_h_dptr(dentry, bindex);
8884 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8885 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8886 + spin_lock(&h_dentry->d_lock);
8887 + h_name = &h_dentry->d_name;
8888 + if (unlikely(do_udba
8891 + && (unhashed != !!d_unhashed(h_dentry)
8892 + || (!tmpfile && !dirren
8893 + && !au_qstreq(name, h_name))
8896 + && !(flags & LOOKUP_OPEN)
8897 + && (h_dentry->d_flags
8898 + & DCACHE_NFSFS_RENAMED)))
8902 + h_unhashed = d_unhashed(h_dentry);
8903 + spin_unlock(&h_dentry->d_lock);
8904 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8905 + unhashed, h_unhashed, dentry, h_dentry);
8908 + spin_unlock(&h_dentry->d_lock);
8910 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8911 + if (unlikely(err))
8912 + /* do not goto err, to keep the errno */
8915 + /* todo: plink too? */
8920 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8924 + if (d_is_positive(h_dentry))
8925 + h_inode = d_inode(h_dentry);
8928 + h_cached_inode = h_inode;
8930 + h_mode = (h_inode->i_mode & S_IFMT);
8931 + h_plus = (h_inode->i_nlink > 0);
8933 + if (inode && ibs <= bindex && bindex <= ibe)
8934 + h_cached_inode = au_h_iptr(inode, bindex);
8937 + if (unlikely(plus != h_plus && !tmpfile))
8940 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8942 + && !IS_ROOT(h_dentry)
8943 + && unhashed != d_unhashed(h_dentry)))
8946 + if (unlikely(mode != h_mode
8947 + || h_cached_inode != h_inode))
8960 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8961 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8964 + struct dentry *parent;
8966 + if (!au_digen_test(dentry, sigen))
8969 + parent = dget_parent(dentry);
8970 + di_read_lock_parent(parent, AuLock_IR);
8971 + AuDebugOn(au_digen_test(parent, sigen));
8972 + au_dbg_verify_gen(parent, sigen);
8973 + err = au_refresh_dentry(dentry, parent);
8974 + di_read_unlock(parent, AuLock_IR);
8980 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8983 + struct dentry *d, *parent;
8985 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8986 + return simple_reval_dpath(dentry, sigen);
8988 + /* slow loop, keep it simple and stupid */
8989 + /* cf: au_cpup_dirs() */
8992 + while (au_digen_test(dentry, sigen)) {
8996 + parent = dget_parent(d);
8997 + if (!au_digen_test(parent, sigen))
9003 + di_write_lock_child2(d);
9005 + /* someone might update our dentry while we were sleeping */
9006 + if (au_digen_test(d, sigen)) {
9008 + * todo: consolidate with simple_reval_dpath(),
9009 + * do_refresh() and au_reval_for_attr().
9011 + di_read_lock_parent(parent, AuLock_IR);
9012 + err = au_refresh_dentry(d, parent);
9013 + di_read_unlock(parent, AuLock_IR);
9017 + di_write_unlock(d);
9019 + if (unlikely(err))
9027 + * if valid returns 1, otherwise 0.
9029 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9032 + unsigned int sigen;
9033 + unsigned char do_udba, dirren;
9034 + struct super_block *sb;
9035 + struct inode *inode;
9037 + /* todo: support rcu-walk? */
9038 + if (flags & LOOKUP_RCU)
9042 + if (unlikely(!au_di(dentry)))
9046 + sb = dentry->d_sb;
9049 + * i_mutex of parent dir may be held,
9050 + * but we should not return 'invalid' due to busy.
9052 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9053 + if (unlikely(err)) {
9059 + if (d_really_is_positive(dentry))
9060 + inode = d_inode(dentry);
9061 + if (unlikely(inode && au_is_bad_inode(inode))) {
9066 + if (unlikely(au_dbrange_test(dentry))) {
9072 + sigen = au_sigen(sb);
9073 + if (au_digen_test(dentry, sigen)) {
9074 + AuDebugOn(IS_ROOT(dentry));
9075 + err = au_reval_dpath(dentry, sigen);
9076 + if (unlikely(err)) {
9081 + di_downgrade_lock(dentry, AuLock_IR);
9084 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9086 + && !(inode->i_state && I_LINKABLE)
9087 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9092 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9093 + if (do_udba && inode) {
9094 + aufs_bindex_t btop = au_ibtop(inode);
9095 + struct inode *h_inode;
9098 + h_inode = au_h_iptr(inode, btop);
9099 + if (h_inode && au_test_higen(inode, h_inode)) {
9106 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9107 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9108 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9110 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9116 + di_downgrade_lock(dentry, AuLock_IR);
9118 + aufs_read_unlock(dentry, AuLock_IR);
9123 + AuDbg("%pd invalid, %d\n", dentry, valid);
9129 +static void aufs_d_release(struct dentry *dentry)
9131 + if (au_di(dentry)) {
9132 + au_di_fin(dentry);
9133 + au_hn_di_reinit(dentry);
9137 +const struct dentry_operations aufs_dop = {
9138 + .d_revalidate = aufs_d_revalidate,
9139 + .d_weak_revalidate = aufs_d_revalidate,
9140 + .d_release = aufs_d_release
9143 +/* aufs_dop without d_revalidate */
9144 +const struct dentry_operations aufs_dop_noreval = {
9145 + .d_release = aufs_d_release
9147 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9148 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9149 +++ linux/fs/aufs/dentry.h 2021-09-06 21:02:45.276825587 +0200
9151 +/* SPDX-License-Identifier: GPL-2.0 */
9153 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9155 + * This program, aufs is free software; you can redistribute it and/or modify
9156 + * it under the terms of the GNU General Public License as published by
9157 + * the Free Software Foundation; either version 2 of the License, or
9158 + * (at your option) any later version.
9160 + * This program is distributed in the hope that it will be useful,
9161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9163 + * GNU General Public License for more details.
9165 + * You should have received a copy of the GNU General Public License
9166 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9170 + * lookup and dentry operations
9173 +#ifndef __AUFS_DENTRY_H__
9174 +#define __AUFS_DENTRY_H__
9178 +#include <linux/dcache.h>
9179 +#include "dirren.h"
9182 +struct au_hdentry {
9183 + struct dentry *hd_dentry;
9184 + aufs_bindex_t hd_id;
9188 + atomic_t di_generation;
9190 + struct au_rwsem di_rwsem;
9191 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9192 + unsigned char di_tmpfile; /* to allow the different name */
9193 + struct au_hdentry *di_hdentry;
9194 + struct rcu_head rcu;
9195 +} ____cacheline_aligned_in_smp;
9197 +/* ---------------------------------------------------------------------- */
9199 +/* flags for au_lkup_dentry() */
9200 +#define AuLkup_ALLOW_NEG 1
9201 +#define AuLkup_IGNORE_PERM (1 << 1)
9202 +#define AuLkup_DIRREN (1 << 2)
9203 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9204 +#define au_fset_lkup(flags, name) \
9205 + do { (flags) |= AuLkup_##name; } while (0)
9206 +#define au_fclr_lkup(flags, name) \
9207 + do { (flags) &= ~AuLkup_##name; } while (0)
9209 +#ifndef CONFIG_AUFS_DIRREN
9210 +#undef AuLkup_DIRREN
9211 +#define AuLkup_DIRREN 0
9214 +struct au_do_lookup_args {
9215 + unsigned int flags;
9217 + struct qstr whname, *name;
9218 + struct au_dr_lookup dirren;
9221 +/* ---------------------------------------------------------------------- */
9224 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9226 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9227 + struct dentry *parent);
9228 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9229 + struct dentry *h_parent, struct au_branch *br);
9231 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9232 + unsigned int flags);
9233 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9234 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9235 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9236 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9239 +void au_di_init_once(void *_di);
9240 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9241 +void au_di_free(struct au_dinfo *dinfo);
9242 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9243 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9244 +int au_di_init(struct dentry *dentry);
9245 +void au_di_fin(struct dentry *dentry);
9246 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9248 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9249 +void di_read_unlock(struct dentry *d, int flags);
9250 +void di_downgrade_lock(struct dentry *d, int flags);
9251 +void di_write_lock(struct dentry *d, unsigned int lsc);
9252 +void di_write_unlock(struct dentry *d);
9253 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9254 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9255 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9257 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9258 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9259 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9260 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9262 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9263 + struct dentry *h_dentry);
9264 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9265 +int au_dbrange_test(struct dentry *dentry);
9266 +void au_update_digen(struct dentry *dentry);
9267 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9268 +void au_update_dbtop(struct dentry *dentry);
9269 +void au_update_dbbot(struct dentry *dentry);
9270 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9272 +/* ---------------------------------------------------------------------- */
9274 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9276 + return dentry->d_fsdata;
9279 +/* ---------------------------------------------------------------------- */
9281 +/* lock subclass for dinfo */
9283 + AuLsc_DI_CHILD, /* child first */
9284 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9285 + AuLsc_DI_CHILD3, /* copyup dirs */
9289 + AuLsc_DI_TMP /* temp for replacing dinfo */
9293 + * di_read_lock_child, di_write_lock_child,
9294 + * di_read_lock_child2, di_write_lock_child2,
9295 + * di_read_lock_child3, di_write_lock_child3,
9296 + * di_read_lock_parent, di_write_lock_parent,
9297 + * di_read_lock_parent2, di_write_lock_parent2,
9298 + * di_read_lock_parent3, di_write_lock_parent3,
9300 +#define AuReadLockFunc(name, lsc) \
9301 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9302 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9304 +#define AuWriteLockFunc(name, lsc) \
9305 +static inline void di_write_lock_##name(struct dentry *d) \
9306 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9308 +#define AuRWLockFuncs(name, lsc) \
9309 + AuReadLockFunc(name, lsc) \
9310 + AuWriteLockFunc(name, lsc)
9312 +AuRWLockFuncs(child, CHILD);
9313 +AuRWLockFuncs(child2, CHILD2);
9314 +AuRWLockFuncs(child3, CHILD3);
9315 +AuRWLockFuncs(parent, PARENT);
9316 +AuRWLockFuncs(parent2, PARENT2);
9317 +AuRWLockFuncs(parent3, PARENT3);
9319 +#undef AuReadLockFunc
9320 +#undef AuWriteLockFunc
9321 +#undef AuRWLockFuncs
9323 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9324 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9325 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9327 +/* ---------------------------------------------------------------------- */
9329 +/* todo: memory barrier? */
9330 +static inline unsigned int au_digen(struct dentry *d)
9332 + return atomic_read(&au_di(d)->di_generation);
9335 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9337 + hdentry->hd_dentry = NULL;
9340 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9341 + aufs_bindex_t bindex)
9343 + return di->di_hdentry + bindex;
9346 +static inline void au_hdput(struct au_hdentry *hd)
9349 + dput(hd->hd_dentry);
9352 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9354 + DiMustAnyLock(dentry);
9355 + return au_di(dentry)->di_btop;
9358 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9360 + DiMustAnyLock(dentry);
9361 + return au_di(dentry)->di_bbot;
9364 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9366 + DiMustAnyLock(dentry);
9367 + return au_di(dentry)->di_bwh;
9370 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9372 + DiMustAnyLock(dentry);
9373 + return au_di(dentry)->di_bdiropq;
9376 +/* todo: hard/soft set? */
9377 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9379 + DiMustWriteLock(dentry);
9380 + au_di(dentry)->di_btop = bindex;
9383 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9385 + DiMustWriteLock(dentry);
9386 + au_di(dentry)->di_bbot = bindex;
9389 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9391 + DiMustWriteLock(dentry);
9392 + /* dbwh can be outside of btop - bbot range */
9393 + au_di(dentry)->di_bwh = bindex;
9396 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9398 + DiMustWriteLock(dentry);
9399 + au_di(dentry)->di_bdiropq = bindex;
9402 +/* ---------------------------------------------------------------------- */
9404 +#ifdef CONFIG_AUFS_HNOTIFY
9405 +static inline void au_digen_dec(struct dentry *d)
9407 + atomic_dec(&au_di(d)->di_generation);
9410 +static inline void au_hn_di_reinit(struct dentry *dentry)
9412 + dentry->d_fsdata = NULL;
9415 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9416 +#endif /* CONFIG_AUFS_HNOTIFY */
9418 +#endif /* __KERNEL__ */
9419 +#endif /* __AUFS_DENTRY_H__ */
9420 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9421 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9422 +++ linux/fs/aufs/dinfo.c 2021-09-06 21:02:45.276825587 +0200
9424 +// SPDX-License-Identifier: GPL-2.0
9426 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9428 + * This program, aufs is free software; you can redistribute it and/or modify
9429 + * it under the terms of the GNU General Public License as published by
9430 + * the Free Software Foundation; either version 2 of the License, or
9431 + * (at your option) any later version.
9433 + * This program is distributed in the hope that it will be useful,
9434 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9435 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9436 + * GNU General Public License for more details.
9438 + * You should have received a copy of the GNU General Public License
9439 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9443 + * dentry private data
9448 +void au_di_init_once(void *_dinfo)
9450 + struct au_dinfo *dinfo = _dinfo;
9452 + au_rw_init(&dinfo->di_rwsem);
9455 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9457 + struct au_dinfo *dinfo;
9460 + dinfo = au_cache_alloc_dinfo();
9461 + if (unlikely(!dinfo))
9464 + nbr = au_sbbot(sb) + 1;
9467 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9468 + if (dinfo->di_hdentry) {
9469 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9470 + dinfo->di_btop = -1;
9471 + dinfo->di_bbot = -1;
9472 + dinfo->di_bwh = -1;
9473 + dinfo->di_bdiropq = -1;
9474 + dinfo->di_tmpfile = 0;
9475 + for (i = 0; i < nbr; i++)
9476 + dinfo->di_hdentry[i].hd_id = -1;
9480 + au_cache_free_dinfo(dinfo);
9487 +void au_di_free(struct au_dinfo *dinfo)
9489 + struct au_hdentry *p;
9490 + aufs_bindex_t bbot, bindex;
9492 + /* dentry may not be revalidated */
9493 + bindex = dinfo->di_btop;
9494 + if (bindex >= 0) {
9495 + bbot = dinfo->di_bbot;
9496 + p = au_hdentry(dinfo, bindex);
9497 + while (bindex++ <= bbot)
9500 + au_kfree_try_rcu(dinfo->di_hdentry);
9501 + au_cache_free_dinfo(dinfo);
9504 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9506 + struct au_hdentry *p;
9509 + AuRwMustWriteLock(&a->di_rwsem);
9510 + AuRwMustWriteLock(&b->di_rwsem);
9512 +#define DiSwap(v, name) \
9514 + v = a->di_##name; \
9515 + a->di_##name = b->di_##name; \
9516 + b->di_##name = v; \
9519 + DiSwap(p, hdentry);
9523 + DiSwap(bi, bdiropq);
9529 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9531 + AuRwMustWriteLock(&dst->di_rwsem);
9532 + AuRwMustWriteLock(&src->di_rwsem);
9534 + dst->di_btop = src->di_btop;
9535 + dst->di_bbot = src->di_bbot;
9536 + dst->di_bwh = src->di_bwh;
9537 + dst->di_bdiropq = src->di_bdiropq;
9541 +int au_di_init(struct dentry *dentry)
9544 + struct super_block *sb;
9545 + struct au_dinfo *dinfo;
9548 + sb = dentry->d_sb;
9549 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9551 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9552 + /* smp_mb(); */ /* atomic_set */
9553 + dentry->d_fsdata = dinfo;
9560 +void au_di_fin(struct dentry *dentry)
9562 + struct au_dinfo *dinfo;
9564 + dinfo = au_di(dentry);
9565 + AuRwDestroy(&dinfo->di_rwsem);
9566 + au_di_free(dinfo);
9569 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9572 + struct au_hdentry *hdp;
9574 + AuRwMustWriteLock(&dinfo->di_rwsem);
9577 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9579 + sz = sizeof(*hdp);
9580 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9583 + dinfo->di_hdentry = hdp;
9590 +/* ---------------------------------------------------------------------- */
9592 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9595 + case AuLsc_DI_CHILD:
9596 + ii_write_lock_child(inode);
9598 + case AuLsc_DI_CHILD2:
9599 + ii_write_lock_child2(inode);
9601 + case AuLsc_DI_CHILD3:
9602 + ii_write_lock_child3(inode);
9604 + case AuLsc_DI_PARENT:
9605 + ii_write_lock_parent(inode);
9607 + case AuLsc_DI_PARENT2:
9608 + ii_write_lock_parent2(inode);
9610 + case AuLsc_DI_PARENT3:
9611 + ii_write_lock_parent3(inode);
9618 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9621 + case AuLsc_DI_CHILD:
9622 + ii_read_lock_child(inode);
9624 + case AuLsc_DI_CHILD2:
9625 + ii_read_lock_child2(inode);
9627 + case AuLsc_DI_CHILD3:
9628 + ii_read_lock_child3(inode);
9630 + case AuLsc_DI_PARENT:
9631 + ii_read_lock_parent(inode);
9633 + case AuLsc_DI_PARENT2:
9634 + ii_read_lock_parent2(inode);
9636 + case AuLsc_DI_PARENT3:
9637 + ii_read_lock_parent3(inode);
9644 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9646 + struct inode *inode;
9648 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9649 + if (d_really_is_positive(d)) {
9650 + inode = d_inode(d);
9651 + if (au_ftest_lock(flags, IW))
9652 + do_ii_write_lock(inode, lsc);
9653 + else if (au_ftest_lock(flags, IR))
9654 + do_ii_read_lock(inode, lsc);
9658 +void di_read_unlock(struct dentry *d, int flags)
9660 + struct inode *inode;
9662 + if (d_really_is_positive(d)) {
9663 + inode = d_inode(d);
9664 + if (au_ftest_lock(flags, IW)) {
9665 + au_dbg_verify_dinode(d);
9666 + ii_write_unlock(inode);
9667 + } else if (au_ftest_lock(flags, IR)) {
9668 + au_dbg_verify_dinode(d);
9669 + ii_read_unlock(inode);
9672 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9675 +void di_downgrade_lock(struct dentry *d, int flags)
9677 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9678 + ii_downgrade_lock(d_inode(d));
9679 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9682 +void di_write_lock(struct dentry *d, unsigned int lsc)
9684 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9685 + if (d_really_is_positive(d))
9686 + do_ii_write_lock(d_inode(d), lsc);
9689 +void di_write_unlock(struct dentry *d)
9691 + au_dbg_verify_dinode(d);
9692 + if (d_really_is_positive(d))
9693 + ii_write_unlock(d_inode(d));
9694 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9697 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9699 + AuDebugOn(d1 == d2
9700 + || d_inode(d1) == d_inode(d2)
9701 + || d1->d_sb != d2->d_sb);
9703 + if ((isdir && au_test_subdir(d1, d2))
9705 + di_write_lock_child(d1);
9706 + di_write_lock_child2(d2);
9708 + di_write_lock_child(d2);
9709 + di_write_lock_child2(d1);
9713 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9715 + AuDebugOn(d1 == d2
9716 + || d_inode(d1) == d_inode(d2)
9717 + || d1->d_sb != d2->d_sb);
9719 + if ((isdir && au_test_subdir(d1, d2))
9721 + di_write_lock_parent(d1);
9722 + di_write_lock_parent2(d2);
9724 + di_write_lock_parent(d2);
9725 + di_write_lock_parent2(d1);
9729 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9731 + di_write_unlock(d1);
9732 + if (d_inode(d1) == d_inode(d2))
9733 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9735 + di_write_unlock(d2);
9738 +/* ---------------------------------------------------------------------- */
9740 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9744 + DiMustAnyLock(dentry);
9746 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9748 + AuDebugOn(bindex < 0);
9749 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9750 + AuDebugOn(d && au_dcount(d) <= 0);
9755 + * extended version of au_h_dptr().
9756 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9759 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9761 + struct dentry *h_dentry;
9762 + struct inode *inode, *h_inode;
9764 + AuDebugOn(d_really_is_negative(dentry));
9767 + if (au_dbtop(dentry) <= bindex
9768 + && bindex <= au_dbbot(dentry))
9769 + h_dentry = au_h_dptr(dentry, bindex);
9770 + if (h_dentry && !au_d_linkable(h_dentry)) {
9772 + goto out; /* success */
9775 + inode = d_inode(dentry);
9776 + AuDebugOn(bindex < au_ibtop(inode));
9777 + AuDebugOn(au_ibbot(inode) < bindex);
9778 + h_inode = au_h_iptr(inode, bindex);
9779 + h_dentry = d_find_alias(h_inode);
9781 + if (!IS_ERR(h_dentry)) {
9782 + if (!au_d_linkable(h_dentry))
9783 + goto out; /* success */
9789 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9790 + h_dentry = au_plink_lkup(inode, bindex);
9791 + AuDebugOn(!h_dentry);
9792 + if (!IS_ERR(h_dentry)) {
9793 + if (!au_d_hashed_positive(h_dentry))
9794 + goto out; /* success */
9801 + AuDbgDentry(h_dentry);
9805 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9807 + aufs_bindex_t bbot, bwh;
9809 + bbot = au_dbbot(dentry);
9811 + bwh = au_dbwh(dentry);
9814 + if (0 < bwh && bwh < bbot)
9820 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9822 + aufs_bindex_t bbot, bopq;
9824 + bbot = au_dbtail(dentry);
9826 + bopq = au_dbdiropq(dentry);
9827 + if (0 <= bopq && bopq < bbot)
9833 +/* ---------------------------------------------------------------------- */
9835 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9836 + struct dentry *h_dentry)
9838 + struct au_dinfo *dinfo;
9839 + struct au_hdentry *hd;
9840 + struct au_branch *br;
9842 + DiMustWriteLock(dentry);
9844 + dinfo = au_di(dentry);
9845 + hd = au_hdentry(dinfo, bindex);
9847 + hd->hd_dentry = h_dentry;
9849 + br = au_sbr(dentry->d_sb, bindex);
9850 + hd->hd_id = br->br_id;
9854 +int au_dbrange_test(struct dentry *dentry)
9857 + aufs_bindex_t btop, bbot;
9860 + btop = au_dbtop(dentry);
9861 + bbot = au_dbbot(dentry);
9863 + AuDebugOn(bbot < 0 && btop > bbot);
9866 + AuDebugOn(bbot >= 0);
9872 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9877 + if (unlikely(au_digen(dentry) != sigen
9878 + || au_iigen_test(d_inode(dentry), sigen)))
9884 +void au_update_digen(struct dentry *dentry)
9886 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9887 + /* smp_mb(); */ /* atomic_set */
9890 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9892 + struct au_dinfo *dinfo;
9893 + struct dentry *h_d;
9894 + struct au_hdentry *hdp;
9895 + aufs_bindex_t bindex, bbot;
9897 + DiMustWriteLock(dentry);
9899 + dinfo = au_di(dentry);
9900 + if (!dinfo || dinfo->di_btop < 0)
9903 + if (do_put_zero) {
9904 + bbot = dinfo->di_bbot;
9905 + bindex = dinfo->di_btop;
9906 + hdp = au_hdentry(dinfo, bindex);
9907 + for (; bindex <= bbot; bindex++, hdp++) {
9908 + h_d = hdp->hd_dentry;
9909 + if (h_d && d_is_negative(h_d))
9910 + au_set_h_dptr(dentry, bindex, NULL);
9914 + dinfo->di_btop = 0;
9915 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9916 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9917 + if (hdp->hd_dentry)
9919 + if (dinfo->di_btop > dinfo->di_bbot) {
9920 + dinfo->di_btop = -1;
9921 + dinfo->di_bbot = -1;
9925 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9926 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9927 + if (hdp->hd_dentry)
9929 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9932 +void au_update_dbtop(struct dentry *dentry)
9934 + aufs_bindex_t bindex, bbot;
9935 + struct dentry *h_dentry;
9937 + bbot = au_dbbot(dentry);
9938 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9939 + h_dentry = au_h_dptr(dentry, bindex);
9942 + if (d_is_positive(h_dentry)) {
9943 + au_set_dbtop(dentry, bindex);
9946 + au_set_h_dptr(dentry, bindex, NULL);
9950 +void au_update_dbbot(struct dentry *dentry)
9952 + aufs_bindex_t bindex, btop;
9953 + struct dentry *h_dentry;
9955 + btop = au_dbtop(dentry);
9956 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9957 + h_dentry = au_h_dptr(dentry, bindex);
9960 + if (d_is_positive(h_dentry)) {
9961 + au_set_dbbot(dentry, bindex);
9964 + au_set_h_dptr(dentry, bindex, NULL);
9968 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9970 + aufs_bindex_t bindex, bbot;
9972 + bbot = au_dbbot(dentry);
9973 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9974 + if (au_h_dptr(dentry, bindex) == h_dentry)
9978 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9979 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9980 +++ linux/fs/aufs/dir.c 2021-09-06 21:02:45.276825587 +0200
9982 +// SPDX-License-Identifier: GPL-2.0
9984 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9986 + * This program, aufs is free software; you can redistribute it and/or modify
9987 + * it under the terms of the GNU General Public License as published by
9988 + * the Free Software Foundation; either version 2 of the License, or
9989 + * (at your option) any later version.
9991 + * This program is distributed in the hope that it will be useful,
9992 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9993 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9994 + * GNU General Public License for more details.
9996 + * You should have received a copy of the GNU General Public License
9997 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10001 + * directory operations
10004 +#include <linux/fs_stack.h>
10005 +#include <linux/iversion.h>
10008 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10010 + unsigned int nlink;
10012 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10014 + nlink = dir->i_nlink;
10015 + nlink += h_dir->i_nlink - 2;
10016 + if (h_dir->i_nlink < 2)
10018 + smp_mb(); /* for i_nlink */
10019 + /* 0 can happen in revaliding */
10020 + set_nlink(dir, nlink);
10023 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10025 + unsigned int nlink;
10027 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10029 + nlink = dir->i_nlink;
10030 + nlink -= h_dir->i_nlink - 2;
10031 + if (h_dir->i_nlink < 2)
10033 + smp_mb(); /* for i_nlink */
10034 + /* nlink == 0 means the branch-fs is broken */
10035 + set_nlink(dir, nlink);
10038 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10041 + aufs_bindex_t bindex, bbot;
10042 + struct file *h_file;
10043 + struct dentry *h_dentry;
10047 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10049 + bbot = au_fbbot_dir(file);
10050 + for (bindex = au_fbtop(file);
10051 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10053 + h_file = au_hf_dir(file, bindex);
10054 + if (h_file && file_inode(h_file))
10055 + sz += vfsub_f_size_read(h_file);
10058 + AuDebugOn(!dentry);
10059 + AuDebugOn(!d_is_dir(dentry));
10061 + bbot = au_dbtaildir(dentry);
10062 + for (bindex = au_dbtop(dentry);
10063 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10065 + h_dentry = au_h_dptr(dentry, bindex);
10066 + if (h_dentry && d_is_positive(h_dentry))
10067 + sz += i_size_read(d_inode(h_dentry));
10070 + if (sz < KMALLOC_MAX_SIZE)
10071 + sz = roundup_pow_of_two(sz);
10072 + if (sz > KMALLOC_MAX_SIZE)
10073 + sz = KMALLOC_MAX_SIZE;
10074 + else if (sz < NAME_MAX) {
10075 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10076 + sz = AUFS_RDBLK_DEF;
10081 +struct au_dir_ts_arg {
10082 + struct dentry *dentry;
10083 + aufs_bindex_t brid;
10086 +static void au_do_dir_ts(void *arg)
10088 + struct au_dir_ts_arg *a = arg;
10089 + struct au_dtime dt;
10090 + struct path h_path;
10091 + struct inode *dir, *h_dir;
10092 + struct super_block *sb;
10093 + struct au_branch *br;
10094 + struct au_hinode *hdir;
10096 + aufs_bindex_t btop, bindex;
10098 + sb = a->dentry->d_sb;
10099 + if (d_really_is_negative(a->dentry))
10101 + /* no dir->i_mutex lock */
10102 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10104 + dir = d_inode(a->dentry);
10105 + btop = au_ibtop(dir);
10106 + bindex = au_br_index(sb, a->brid);
10107 + if (bindex < btop)
10110 + br = au_sbr(sb, bindex);
10111 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10112 + if (!h_path.dentry)
10114 + h_path.mnt = au_br_mnt(br);
10115 + au_dtime_store(&dt, a->dentry, &h_path);
10117 + br = au_sbr(sb, btop);
10118 + if (!au_br_writable(br->br_perm))
10120 + h_path.dentry = au_h_dptr(a->dentry, btop);
10121 + h_path.mnt = au_br_mnt(br);
10122 + err = vfsub_mnt_want_write(h_path.mnt);
10125 + hdir = au_hi(dir, btop);
10126 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10127 + h_dir = au_h_iptr(dir, btop);
10128 + if (h_dir->i_nlink
10129 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10130 + dt.dt_h_path = h_path;
10131 + au_dtime_revert(&dt);
10133 + au_hn_inode_unlock(hdir);
10134 + vfsub_mnt_drop_write(h_path.mnt);
10135 + au_cpup_attr_timesizes(dir);
10138 + aufs_read_unlock(a->dentry, AuLock_DW);
10141 + au_nwt_done(&au_sbi(sb)->si_nowait);
10142 + au_kfree_try_rcu(arg);
10145 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10147 + int perm, wkq_err;
10148 + aufs_bindex_t btop;
10149 + struct au_dir_ts_arg *arg;
10150 + struct dentry *dentry;
10151 + struct super_block *sb;
10155 + dentry = d_find_any_alias(dir);
10156 + AuDebugOn(!dentry);
10157 + sb = dentry->d_sb;
10158 + btop = au_ibtop(dir);
10159 + if (btop == bindex) {
10160 + au_cpup_attr_timesizes(dir);
10164 + perm = au_sbr_perm(sb, btop);
10165 + if (!au_br_writable(perm))
10168 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10172 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10173 + arg->brid = au_sbr_id(sb, bindex);
10174 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10175 + if (unlikely(wkq_err)) {
10176 + pr_err("wkq %d\n", wkq_err);
10178 + au_kfree_try_rcu(arg);
10185 +/* ---------------------------------------------------------------------- */
10187 +static int reopen_dir(struct file *file)
10190 + unsigned int flags;
10191 + aufs_bindex_t bindex, btail, btop;
10192 + struct dentry *dentry, *h_dentry;
10193 + struct file *h_file;
10195 + /* open all lower dirs */
10196 + dentry = file->f_path.dentry;
10197 + btop = au_dbtop(dentry);
10198 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10199 + au_set_h_fptr(file, bindex, NULL);
10200 + au_set_fbtop(file, btop);
10202 + btail = au_dbtaildir(dentry);
10203 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10204 + au_set_h_fptr(file, bindex, NULL);
10205 + au_set_fbbot_dir(file, btail);
10207 + flags = vfsub_file_flags(file);
10208 + for (bindex = btop; bindex <= btail; bindex++) {
10209 + h_dentry = au_h_dptr(dentry, bindex);
10212 + h_file = au_hf_dir(file, bindex);
10216 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10217 + err = PTR_ERR(h_file);
10218 + if (IS_ERR(h_file))
10219 + goto out; /* close all? */
10220 + au_set_h_fptr(file, bindex, h_file);
10222 + au_update_figen(file);
10223 + /* todo: necessary? */
10224 + /* file->f_ra = h_file->f_ra; */
10231 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10234 + aufs_bindex_t bindex, btail;
10235 + struct dentry *dentry, *h_dentry;
10236 + struct vfsmount *mnt;
10238 + FiMustWriteLock(file);
10239 + AuDebugOn(h_file);
10242 + mnt = file->f_path.mnt;
10243 + dentry = file->f_path.dentry;
10244 + file->f_version = inode_query_iversion(d_inode(dentry));
10245 + bindex = au_dbtop(dentry);
10246 + au_set_fbtop(file, bindex);
10247 + btail = au_dbtaildir(dentry);
10248 + au_set_fbbot_dir(file, btail);
10249 + for (; !err && bindex <= btail; bindex++) {
10250 + h_dentry = au_h_dptr(dentry, bindex);
10254 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10255 + if (unlikely(err))
10257 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10258 + if (IS_ERR(h_file)) {
10259 + err = PTR_ERR(h_file);
10262 + au_set_h_fptr(file, bindex, h_file);
10264 + au_update_figen(file);
10265 + /* todo: necessary? */
10266 + /* file->f_ra = h_file->f_ra; */
10268 + return 0; /* success */
10271 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10272 + au_set_h_fptr(file, bindex, NULL);
10273 + au_set_fbtop(file, -1);
10274 + au_set_fbbot_dir(file, -1);
10279 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10280 + struct file *file)
10283 + struct super_block *sb;
10284 + struct au_fidir *fidir;
10287 + sb = file->f_path.dentry->d_sb;
10288 + si_read_lock(sb, AuLock_FLUSH);
10289 + fidir = au_fidir_alloc(sb);
10291 + struct au_do_open_args args = {
10292 + .open = do_open_dir,
10295 + err = au_do_open(file, &args);
10296 + if (unlikely(err))
10297 + au_kfree_rcu(fidir);
10299 + si_read_unlock(sb);
10303 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10304 + struct file *file)
10306 + struct au_vdir *vdir_cache;
10307 + struct au_finfo *finfo;
10308 + struct au_fidir *fidir;
10309 + struct au_hfile *hf;
10310 + aufs_bindex_t bindex, bbot;
10312 + finfo = au_fi(file);
10313 + fidir = finfo->fi_hdir;
10315 + au_hbl_del(&finfo->fi_hlist,
10316 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10317 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10319 + au_vdir_free(vdir_cache);
10321 + bindex = finfo->fi_btop;
10322 + if (bindex >= 0) {
10323 + hf = fidir->fd_hfile + bindex;
10325 + * calls fput() instead of filp_close(),
10326 + * since no dnotify or lock for the lower file.
10328 + bbot = fidir->fd_bbot;
10329 + for (; bindex <= bbot; bindex++, hf++)
10331 + au_hfput(hf, /*execed*/0);
10333 + au_kfree_rcu(fidir);
10334 + finfo->fi_hdir = NULL;
10336 + au_finfo_fin(file);
10340 +/* ---------------------------------------------------------------------- */
10342 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10345 + aufs_bindex_t bindex, bbot;
10346 + struct file *h_file;
10349 + bbot = au_fbbot_dir(file);
10350 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10351 + h_file = au_hf_dir(file, bindex);
10353 + err = vfsub_flush(h_file, id);
10358 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10360 + return au_do_flush(file, id, au_do_flush_dir);
10363 +/* ---------------------------------------------------------------------- */
10365 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10368 + aufs_bindex_t bbot, bindex;
10369 + struct inode *inode;
10370 + struct super_block *sb;
10373 + sb = dentry->d_sb;
10374 + inode = d_inode(dentry);
10375 + IMustLock(inode);
10376 + bbot = au_dbbot(dentry);
10377 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10378 + struct path h_path;
10380 + if (au_test_ro(sb, bindex, inode))
10382 + h_path.dentry = au_h_dptr(dentry, bindex);
10383 + if (!h_path.dentry)
10386 + h_path.mnt = au_sbr_mnt(sb, bindex);
10387 + err = vfsub_fsync(NULL, &h_path, datasync);
10393 +static int au_do_fsync_dir(struct file *file, int datasync)
10396 + aufs_bindex_t bbot, bindex;
10397 + struct file *h_file;
10398 + struct super_block *sb;
10399 + struct inode *inode;
10401 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10402 + if (unlikely(err))
10405 + inode = file_inode(file);
10406 + sb = inode->i_sb;
10407 + bbot = au_fbbot_dir(file);
10408 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10409 + h_file = au_hf_dir(file, bindex);
10410 + if (!h_file || au_test_ro(sb, bindex, inode))
10413 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10421 + * @file may be NULL
10423 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10427 + struct dentry *dentry;
10428 + struct inode *inode;
10429 + struct super_block *sb;
10432 + dentry = file->f_path.dentry;
10433 + inode = d_inode(dentry);
10434 + inode_lock(inode);
10435 + sb = dentry->d_sb;
10436 + si_noflush_read_lock(sb);
10438 + err = au_do_fsync_dir(file, datasync);
10440 + di_write_lock_child(dentry);
10441 + err = au_do_fsync_dir_no_file(dentry, datasync);
10443 + au_cpup_attr_timesizes(inode);
10444 + di_write_unlock(dentry);
10446 + fi_write_unlock(file);
10448 + si_read_unlock(sb);
10449 + inode_unlock(inode);
10453 +/* ---------------------------------------------------------------------- */
10455 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10458 + struct dentry *dentry;
10459 + struct inode *inode, *h_inode;
10460 + struct super_block *sb;
10462 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10464 + dentry = file->f_path.dentry;
10465 + inode = d_inode(dentry);
10466 + IMustLock(inode);
10468 + sb = dentry->d_sb;
10469 + si_read_lock(sb, AuLock_FLUSH);
10470 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10471 + if (unlikely(err))
10473 + err = au_alive_dir(dentry);
10475 + err = au_vdir_init(file);
10476 + di_downgrade_lock(dentry, AuLock_IR);
10477 + if (unlikely(err))
10480 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10481 + if (!au_test_nfsd()) {
10482 + err = au_vdir_fill_de(file, ctx);
10483 + fsstack_copy_attr_atime(inode, h_inode);
10486 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10487 + * encode_fh() and others.
10489 + atomic_inc(&h_inode->i_count);
10490 + di_read_unlock(dentry, AuLock_IR);
10491 + si_read_unlock(sb);
10492 + err = au_vdir_fill_de(file, ctx);
10493 + fsstack_copy_attr_atime(inode, h_inode);
10494 + fi_write_unlock(file);
10502 + di_read_unlock(dentry, AuLock_IR);
10503 + fi_write_unlock(file);
10505 + si_read_unlock(sb);
10509 +/* ---------------------------------------------------------------------- */
10511 +#define AuTestEmpty_WHONLY 1
10512 +#define AuTestEmpty_CALLED (1 << 1)
10513 +#define AuTestEmpty_SHWH (1 << 2)
10514 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10515 +#define au_fset_testempty(flags, name) \
10516 + do { (flags) |= AuTestEmpty_##name; } while (0)
10517 +#define au_fclr_testempty(flags, name) \
10518 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10520 +#ifndef CONFIG_AUFS_SHWH
10521 +#undef AuTestEmpty_SHWH
10522 +#define AuTestEmpty_SHWH 0
10525 +struct test_empty_arg {
10526 + struct dir_context ctx;
10527 + struct au_nhash *whlist;
10528 + unsigned int flags;
10530 + aufs_bindex_t bindex;
10533 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10534 + int namelen, loff_t offset __maybe_unused, u64 ino,
10535 + unsigned int d_type)
10537 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10539 + char *name = (void *)__name;
10542 + au_fset_testempty(arg->flags, CALLED);
10544 + if (name[0] == '.'
10545 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10546 + goto out; /* success */
10548 + if (namelen <= AUFS_WH_PFX_LEN
10549 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10550 + if (au_ftest_testempty(arg->flags, WHONLY)
10551 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10552 + arg->err = -ENOTEMPTY;
10556 + name += AUFS_WH_PFX_LEN;
10557 + namelen -= AUFS_WH_PFX_LEN;
10558 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10559 + arg->err = au_nhash_append_wh
10560 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10561 + au_ftest_testempty(arg->flags, SHWH));
10565 + AuTraceErr(arg->err);
10569 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10572 + struct file *h_file;
10573 + struct au_branch *br;
10575 + h_file = au_h_open(dentry, arg->bindex,
10576 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10577 + /*file*/NULL, /*force_wr*/0);
10578 + err = PTR_ERR(h_file);
10579 + if (IS_ERR(h_file))
10583 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10584 + && !file_inode(h_file)->i_nlink)
10589 + au_fclr_testempty(arg->flags, CALLED);
10591 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10594 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10598 + br = au_sbr(dentry->d_sb, arg->bindex);
10599 + au_lcnt_dec(&br->br_nfiles);
10604 +struct do_test_empty_args {
10606 + struct dentry *dentry;
10607 + struct test_empty_arg *arg;
10610 +static void call_do_test_empty(void *args)
10612 + struct do_test_empty_args *a = args;
10613 + *a->errp = do_test_empty(a->dentry, a->arg);
10616 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10618 + int err, wkq_err;
10619 + struct dentry *h_dentry;
10620 + struct inode *h_inode;
10621 + struct user_namespace *h_userns;
10623 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10624 + h_dentry = au_h_dptr(dentry, arg->bindex);
10625 + h_inode = d_inode(h_dentry);
10626 + /* todo: i_mode changes anytime? */
10627 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10628 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10629 + inode_unlock_shared(h_inode);
10631 + err = do_test_empty(dentry, arg);
10633 + struct do_test_empty_args args = {
10635 + .dentry = dentry,
10638 + unsigned int flags = arg->flags;
10640 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10641 + if (unlikely(wkq_err))
10643 + arg->flags = flags;
10649 +int au_test_empty_lower(struct dentry *dentry)
10652 + unsigned int rdhash;
10653 + aufs_bindex_t bindex, btop, btail;
10654 + struct au_nhash whlist;
10655 + struct test_empty_arg arg = {
10657 + .actor = test_empty_cb
10660 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10662 + SiMustAnyLock(dentry->d_sb);
10664 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10666 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10667 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10668 + if (unlikely(err))
10672 + arg.whlist = &whlist;
10673 + btop = au_dbtop(dentry);
10674 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10675 + au_fset_testempty(arg.flags, SHWH);
10676 + test_empty = do_test_empty;
10677 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10678 + test_empty = sio_test_empty;
10679 + arg.bindex = btop;
10680 + err = test_empty(dentry, &arg);
10681 + if (unlikely(err))
10684 + au_fset_testempty(arg.flags, WHONLY);
10685 + btail = au_dbtaildir(dentry);
10686 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10687 + struct dentry *h_dentry;
10689 + h_dentry = au_h_dptr(dentry, bindex);
10690 + if (h_dentry && d_is_positive(h_dentry)) {
10691 + arg.bindex = bindex;
10692 + err = test_empty(dentry, &arg);
10697 + au_nhash_wh_free(&whlist);
10702 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10705 + struct test_empty_arg arg = {
10707 + .actor = test_empty_cb
10710 + aufs_bindex_t bindex, btail;
10713 + arg.whlist = whlist;
10714 + arg.flags = AuTestEmpty_WHONLY;
10715 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10716 + au_fset_testempty(arg.flags, SHWH);
10717 + btail = au_dbtaildir(dentry);
10718 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10719 + struct dentry *h_dentry;
10721 + h_dentry = au_h_dptr(dentry, bindex);
10722 + if (h_dentry && d_is_positive(h_dentry)) {
10723 + arg.bindex = bindex;
10724 + err = sio_test_empty(dentry, &arg);
10731 +/* ---------------------------------------------------------------------- */
10733 +const struct file_operations aufs_dir_fop = {
10734 + .owner = THIS_MODULE,
10735 + .llseek = default_llseek,
10736 + .read = generic_read_dir,
10737 + .iterate_shared = aufs_iterate_shared,
10738 + .unlocked_ioctl = aufs_ioctl_dir,
10739 +#ifdef CONFIG_COMPAT
10740 + .compat_ioctl = aufs_compat_ioctl_dir,
10742 + .open = aufs_open_dir,
10743 + .release = aufs_release_dir,
10744 + .flush = aufs_flush_dir,
10745 + .fsync = aufs_fsync_dir
10747 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10748 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10749 +++ linux/fs/aufs/dir.h 2021-09-06 21:02:45.276825587 +0200
10751 +/* SPDX-License-Identifier: GPL-2.0 */
10753 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10755 + * This program, aufs is free software; you can redistribute it and/or modify
10756 + * it under the terms of the GNU General Public License as published by
10757 + * the Free Software Foundation; either version 2 of the License, or
10758 + * (at your option) any later version.
10760 + * This program is distributed in the hope that it will be useful,
10761 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10762 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10763 + * GNU General Public License for more details.
10765 + * You should have received a copy of the GNU General Public License
10766 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10770 + * directory operations
10773 +#ifndef __AUFS_DIR_H__
10774 +#define __AUFS_DIR_H__
10778 +#include <linux/fs.h>
10780 +/* ---------------------------------------------------------------------- */
10782 +/* need to be faster and smaller */
10785 + unsigned int nh_num;
10786 + struct hlist_head *nh_head;
10789 +struct au_vdir_destr {
10790 + unsigned char len;
10791 + unsigned char name[];
10794 +struct au_vdir_dehstr {
10795 + struct hlist_node hash;
10796 + struct au_vdir_destr *str;
10797 + struct rcu_head rcu;
10798 +} ____cacheline_aligned_in_smp;
10800 +struct au_vdir_de {
10802 + unsigned char de_type;
10803 + /* caution: packed */
10804 + struct au_vdir_destr de_str;
10807 +struct au_vdir_wh {
10808 + struct hlist_node wh_hash;
10809 +#ifdef CONFIG_AUFS_SHWH
10811 + aufs_bindex_t wh_bindex;
10812 + unsigned char wh_type;
10814 + aufs_bindex_t wh_bindex;
10816 + /* caution: packed */
10817 + struct au_vdir_destr wh_str;
10820 +union au_vdir_deblk_p {
10821 + unsigned char *deblk;
10822 + struct au_vdir_de *de;
10826 + unsigned char **vd_deblk;
10827 + unsigned long vd_nblk;
10829 + unsigned long ul;
10830 + union au_vdir_deblk_p p;
10834 + unsigned int vd_deblk_sz;
10835 + unsigned long vd_jiffy;
10836 + struct rcu_head rcu;
10837 +} ____cacheline_aligned_in_smp;
10839 +/* ---------------------------------------------------------------------- */
10842 +extern const struct file_operations aufs_dir_fop;
10843 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10844 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10845 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10846 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10847 +int au_test_empty_lower(struct dentry *dentry);
10848 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10851 +unsigned int au_rdhash_est(loff_t sz);
10852 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10853 +void au_nhash_wh_free(struct au_nhash *whlist);
10854 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10856 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10857 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10858 + unsigned int d_type, aufs_bindex_t bindex,
10859 + unsigned char shwh);
10860 +void au_vdir_free(struct au_vdir *vdir);
10861 +int au_vdir_init(struct file *file);
10862 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10865 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10867 +#ifdef CONFIG_AUFS_RDU
10869 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10870 +#ifdef CONFIG_COMPAT
10871 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10872 + unsigned long arg);
10875 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10876 + unsigned int cmd, unsigned long arg)
10877 +#ifdef CONFIG_COMPAT
10878 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10879 + unsigned int cmd, unsigned long arg)
10883 +#endif /* __KERNEL__ */
10884 +#endif /* __AUFS_DIR_H__ */
10885 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10886 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10887 +++ linux/fs/aufs/dirren.c 2021-09-06 21:02:45.276825587 +0200
10889 +// SPDX-License-Identifier: GPL-2.0
10891 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10893 + * This program, aufs is free software; you can redistribute it and/or modify
10894 + * it under the terms of the GNU General Public License as published by
10895 + * the Free Software Foundation; either version 2 of the License, or
10896 + * (at your option) any later version.
10898 + * This program is distributed in the hope that it will be useful,
10899 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10900 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10901 + * GNU General Public License for more details.
10903 + * You should have received a copy of the GNU General Public License
10904 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10908 + * special handling in renaming a directory
10909 + * in order to support looking-up the before-renamed name on the lower readonly
10913 +#include <linux/byteorder/generic.h>
10916 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10920 + idx = au_dr_ihash(ent->dr_h_ino);
10921 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10924 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10927 + struct hlist_bl_head *hbl;
10930 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10931 + hbl = dr->dr_h_ino + i;
10932 + hlist_bl_lock(hbl);
10933 + ret &= hlist_bl_empty(hbl);
10934 + hlist_bl_unlock(hbl);
10940 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10942 + struct au_dr_hino *found, *ent;
10943 + struct hlist_bl_head *hbl;
10944 + struct hlist_bl_node *pos;
10948 + idx = au_dr_ihash(ino);
10949 + hbl = dr->dr_h_ino + idx;
10950 + hlist_bl_lock(hbl);
10951 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10952 + if (ent->dr_h_ino == ino) {
10956 + hlist_bl_unlock(hbl);
10961 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10962 + struct au_dr_hino *add_ent)
10965 + struct hlist_bl_head *hbl;
10966 + struct hlist_bl_node *pos;
10967 + struct au_dr_hino *ent;
10970 + idx = au_dr_ihash(ino);
10971 + hbl = dr->dr_h_ino + idx;
10972 +#if 0 /* debug print */
10974 + struct hlist_bl_node *tmp;
10976 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10977 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10980 + hlist_bl_lock(hbl);
10981 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10982 + if (ent->dr_h_ino == ino) {
10986 + if (!found && add_ent)
10987 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10988 + hlist_bl_unlock(hbl);
10990 + if (!found && add_ent)
10991 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10996 +void au_dr_hino_free(struct au_dr_br *dr)
10999 + struct hlist_bl_head *hbl;
11000 + struct hlist_bl_node *pos, *tmp;
11001 + struct au_dr_hino *ent;
11003 + /* SiMustWriteLock(sb); */
11005 + for (i = 0; i < AuDirren_NHASH; i++) {
11006 + hbl = dr->dr_h_ino + i;
11007 + /* no spinlock since sbinfo must be write-locked */
11008 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11009 + au_kfree_rcu(ent);
11010 + INIT_HLIST_BL_HEAD(hbl);
11014 +/* returns the number of inodes or an error */
11015 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11016 + struct file *hinofile)
11020 + loff_t pos, oldsize;
11022 + struct inode *hinoinode;
11023 + struct hlist_bl_head *hbl;
11024 + struct hlist_bl_node *n1, *n2;
11025 + struct au_dr_hino *ent;
11027 + SiMustWriteLock(sb);
11028 + AuDebugOn(!au_br_writable(br->br_perm));
11030 + hinoinode = file_inode(hinofile);
11031 + oldsize = i_size_read(hinoinode);
11035 + hbl = br->br_dirren.dr_h_ino;
11036 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11037 + /* no bit-lock since sbinfo must be write-locked */
11038 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11039 + AuDbg("hi%llu, %pD2\n",
11040 + (unsigned long long)ent->dr_h_ino, hinofile);
11041 + u64 = cpu_to_be64(ent->dr_h_ino);
11042 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11043 + if (ssz == sizeof(u64))
11046 + /* write error */
11047 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11054 + /* regardless the error */
11055 + if (pos < oldsize) {
11056 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11064 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11071 + struct au_dr_hino *ent;
11072 + struct inode *hinoinode;
11073 + struct hlist_bl_head *hbl;
11077 + hbl = dr->dr_h_ino;
11078 + hinoinode = file_inode(hinofile);
11079 + sz = i_size_read(hinoinode);
11080 + AuDebugOn(sz % sizeof(u64));
11081 + n = sz / sizeof(u64);
11083 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11084 + if (unlikely(ssz != sizeof(u64))) {
11085 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11092 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11098 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11099 + AuDbg("hi%llu, %pD2\n",
11100 + (unsigned long long)ent->dr_h_ino, hinofile);
11101 + hidx = au_dr_ihash(ent->dr_h_ino);
11102 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11104 + goto out; /* success */
11107 + au_dr_hino_free(dr);
11114 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11115 + * @path is a switch to distinguish load and store.
11117 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11118 + struct au_branch *br, const struct path *path)
11121 + unsigned char load, suspend;
11122 + struct file *hinofile;
11123 + struct au_hinode *hdir;
11124 + struct inode *dir, *delegated;
11125 + struct path hinopath;
11126 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11127 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11129 + AuDebugOn(bindex < 0 && !br);
11130 + AuDebugOn(bindex >= 0 && br);
11135 + br = au_sbr(sb, bindex);
11138 + path = &br->br_path;
11139 + AuDebugOn(!au_br_writable(br->br_perm));
11140 + if (unlikely(!au_br_writable(br->br_perm)))
11146 + dir = d_inode(sb->s_root);
11147 + hdir = au_hinode(au_ii(dir), bindex);
11148 + dir = hdir->hi_inode;
11149 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11151 + dir = d_inode(path->dentry);
11152 + inode_lock_nested(dir, AuLsc_I_CHILD);
11154 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11155 + err = PTR_ERR(hinopath.dentry);
11156 + if (IS_ERR(hinopath.dentry))
11158 + hinopath.mnt = path->mnt;
11161 + flags = O_RDONLY;
11163 + if (d_is_negative(hinopath.dentry))
11164 + goto out_dput; /* success */
11166 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11167 + if (d_is_positive(hinopath.dentry)) {
11168 + delegated = NULL;
11169 + err = vfsub_unlink(dir, &hinopath, &delegated,
11172 + if (unlikely(err))
11173 + pr_err("ignored err %d, %pd2\n",
11174 + err, hinopath.dentry);
11175 + if (unlikely(err == -EWOULDBLOCK))
11180 + } else if (!d_is_positive(hinopath.dentry)) {
11181 + err = vfsub_create(dir, &hinopath, 0600,
11182 + /*want_excl*/false);
11184 + if (unlikely(err))
11187 + flags = O_WRONLY;
11189 + hinofile = vfsub_dentry_open(&hinopath, flags);
11191 + au_hn_inode_unlock(hdir);
11193 + inode_unlock(dir);
11194 + dput(hinopath.dentry);
11195 + AuTraceErrPtr(hinofile);
11196 + if (IS_ERR(hinofile)) {
11197 + err = PTR_ERR(hinofile);
11202 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11204 + err = au_dr_hino_store(sb, br, hinofile);
11209 + dput(hinopath.dentry);
11212 + au_hn_inode_unlock(hdir);
11214 + inode_unlock(dir);
11220 +/* ---------------------------------------------------------------------- */
11222 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11225 + struct kstatfs kstfs;
11227 + struct dentry *dentry;
11228 + struct super_block *sb;
11230 + err = vfs_statfs((void *)path, &kstfs);
11232 + if (unlikely(err))
11235 + /* todo: support for UUID */
11237 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11238 + brid->type = AuBrid_FSID;
11239 + brid->fsid = kstfs.f_fsid;
11241 + dentry = path->dentry;
11242 + sb = dentry->d_sb;
11245 + brid->type = AuBrid_DEV;
11254 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11255 + const struct path *path)
11258 + struct au_dr_br *dr;
11259 + struct hlist_bl_head *hbl;
11261 + dr = &br->br_dirren;
11262 + hbl = dr->dr_h_ino;
11263 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11264 + INIT_HLIST_BL_HEAD(hbl);
11266 + err = au_dr_brid_init(&dr->dr_brid, path);
11267 + if (unlikely(err))
11270 + if (au_opt_test(au_mntflags(sb), DIRREN))
11271 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11278 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11283 + if (au_br_writable(br->br_perm))
11284 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11286 + au_dr_hino_free(&br->br_dirren);
11291 +/* ---------------------------------------------------------------------- */
11293 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11294 + char *buf, size_t sz)
11297 + unsigned int major, minor;
11301 + err = snprintf(p, sz, "%d_", brid->type);
11302 + AuDebugOn(err > sz);
11305 + switch (brid->type) {
11306 + case AuBrid_Unset:
11308 + case AuBrid_UUID:
11309 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11311 + case AuBrid_FSID:
11312 + err = snprintf(p, sz, "%08x-%08x",
11313 + brid->fsid.val[0], brid->fsid.val[1]);
11316 + major = MAJOR(brid->dev);
11317 + minor = MINOR(brid->dev);
11318 + if (major <= 0xff && minor <= 0xff)
11319 + err = snprintf(p, sz, "%02x%02x", major, minor);
11321 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11324 + AuDebugOn(err > sz);
11327 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11328 + AuDebugOn(err > sz);
11335 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11338 + struct dentry *br_dentry;
11339 + struct inode *br_inode;
11341 + br_dentry = au_br_dentry(br);
11342 + br_inode = d_inode(br_dentry);
11343 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11344 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11345 + AuDebugOn(rlen > len);
11350 +/* ---------------------------------------------------------------------- */
11353 + * from the given @h_dentry, construct drinfo at @*fdata.
11354 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11357 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11358 + struct dentry *h_dentry,
11359 + unsigned char *allocated)
11362 + struct au_drinfo_fdata *f, *p;
11363 + struct au_drinfo *drinfo;
11364 + struct inode *h_inode;
11365 + struct qstr *qname;
11369 + h_inode = d_inode(h_dentry);
11370 + qname = &h_dentry->d_name;
11371 + drinfo = &f->drinfo;
11372 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11373 + drinfo->oldnamelen = qname->len;
11374 + if (*allocated < sizeof(*f) + qname->len) {
11375 + v = roundup_pow_of_two(*allocated + qname->len);
11376 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11377 + if (unlikely(!p)) {
11385 + drinfo = &f->drinfo;
11387 + memcpy(drinfo->oldname, qname->name, qname->len);
11388 + AuDbg("i%llu, %.*s\n",
11389 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11390 + drinfo->oldname);
11397 +/* callers have to free the return value */
11398 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11400 + struct au_drinfo *ret, *drinfo;
11401 + struct au_drinfo_fdata fdata;
11406 + ret = ERR_PTR(-EIO);
11408 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11409 + if (unlikely(ssz != sizeof(fdata))) {
11410 + AuIOErr("ssz %zd, %u, %pD2\n",
11411 + ssz, (unsigned int)sizeof(fdata), file);
11415 + fdata.magic = ntohl((__force __be32)fdata.magic);
11416 + switch (fdata.magic) {
11417 + case AUFS_DRINFO_MAGIC_V1:
11420 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11421 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11425 + drinfo = &fdata.drinfo;
11426 + len = drinfo->oldnamelen;
11428 + AuIOErr("broken drinfo %pD2\n", file);
11433 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11434 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11435 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11436 + (unsigned long long)drinfo->ino,
11437 + (unsigned long long)h_ino, file);
11438 + goto out; /* success */
11441 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11442 + if (unlikely(!ret)) {
11443 + ret = ERR_PTR(-ENOMEM);
11444 + AuTraceErrPtr(ret);
11449 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11450 + if (unlikely(ssz != len)) {
11451 + au_kfree_rcu(ret);
11452 + ret = ERR_PTR(-EIO);
11453 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11457 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11463 +/* ---------------------------------------------------------------------- */
11465 +/* in order to be revertible */
11466 +struct au_drinfo_rev_elm {
11468 + struct dentry *info_dentry;
11469 + struct au_drinfo *info_last;
11472 +struct au_drinfo_rev {
11473 + unsigned char already;
11474 + aufs_bindex_t nelm;
11475 + struct au_drinfo_rev_elm elm[];
11478 +/* todo: isn't it too large? */
11479 +struct au_drinfo_store {
11480 + struct path h_ppath;
11481 + struct dentry *h_dentry;
11482 + struct au_drinfo_fdata *fdata;
11483 + char *infoname; /* inside of whname, just after PFX */
11484 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11485 + aufs_bindex_t btgt, btail;
11486 + unsigned char no_sio,
11487 + allocated, /* current size of *fdata */
11488 + infonamelen, /* room size for p */
11489 + whnamelen, /* length of the generated name */
11490 + renameback; /* renamed back */
11493 +/* on rename(2) error, the caller should revert it using @elm */
11494 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11495 + struct au_drinfo_rev_elm *elm)
11500 + struct path infopath = {
11501 + .mnt = w->h_ppath.mnt
11503 + struct inode *h_dir, *h_inode, *delegated;
11504 + struct file *infofile;
11505 + struct qstr *qname;
11508 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11510 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11512 + AuTraceErrPtr(infopath.dentry);
11513 + if (IS_ERR(infopath.dentry)) {
11514 + err = PTR_ERR(infopath.dentry);
11519 + h_dir = d_inode(w->h_ppath.dentry);
11520 + if (elm && d_is_negative(infopath.dentry)) {
11521 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11523 + if (unlikely(err))
11525 + elm->created = 1;
11526 + elm->info_dentry = dget(infopath.dentry);
11529 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11530 + AuTraceErrPtr(infofile);
11531 + if (IS_ERR(infofile)) {
11532 + err = PTR_ERR(infofile);
11536 + h_inode = d_inode(infopath.dentry);
11537 + if (elm && i_size_read(h_inode)) {
11538 + h_inode = d_inode(w->h_dentry);
11539 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11540 + AuTraceErrPtr(elm->info_last);
11541 + if (IS_ERR(elm->info_last)) {
11542 + err = PTR_ERR(elm->info_last);
11543 + elm->info_last = NULL;
11544 + AuDebugOn(elm->info_dentry);
11549 + if (elm && w->renameback) {
11550 + delegated = NULL;
11551 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11553 + if (unlikely(err == -EWOULDBLOCK))
11559 + qname = &w->h_dentry->d_name;
11560 + len = sizeof(*w->fdata) + qname->len;
11562 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11563 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11564 + if (ssz == len) {
11565 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11566 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11567 + goto out_fput; /* success */
11572 + /* the caller should revert it using @elm */
11578 + dput(infopath.dentry);
11584 +struct au_call_drinfo_do_store_args {
11586 + struct au_drinfo_store *w;
11587 + struct au_drinfo_rev_elm *elm;
11590 +static void au_call_drinfo_do_store(void *args)
11592 + struct au_call_drinfo_do_store_args *a = args;
11594 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11597 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11598 + struct au_drinfo_rev_elm *elm)
11600 + int err, wkq_err;
11603 + err = au_drinfo_do_store(w, elm);
11605 + struct au_call_drinfo_do_store_args a = {
11610 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11611 + if (unlikely(wkq_err))
11619 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11620 + aufs_bindex_t btgt)
11624 + memset(w, 0, sizeof(*w));
11625 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11626 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11627 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11628 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11630 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11633 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11634 + if (unlikely(!w->fdata)) {
11638 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11645 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11647 + au_kfree_rcu(w->fdata);
11650 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11651 + struct au_drinfo_store *w)
11653 + struct au_drinfo_rev_elm *elm;
11654 + struct inode *h_dir, *delegated;
11656 + struct path infopath = {
11657 + .mnt = w->h_ppath.mnt
11660 + h_dir = d_inode(w->h_ppath.dentry);
11661 + IMustLock(h_dir);
11665 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11666 + AuDebugOn(elm->created && elm->info_last);
11667 + if (elm->created) {
11669 + delegated = NULL;
11670 + infopath.dentry = elm->info_dentry;
11671 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11674 + if (unlikely(err == -EWOULDBLOCK))
11676 + dput(elm->info_dentry);
11677 + } else if (elm->info_last) {
11679 + w->fdata->drinfo = *elm->info_last;
11680 + memcpy(w->fdata->drinfo.oldname,
11681 + elm->info_last->oldname,
11682 + elm->info_last->oldnamelen);
11683 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11684 + au_kfree_rcu(elm->info_last);
11686 + if (unlikely(err))
11687 + AuIOErr("%d, %s\n", err, w->whname);
11688 + /* go on even if err */
11692 +/* caller has to call au_dr_rename_fin() later */
11693 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11694 + struct qstr *dst_name, void *_rev)
11696 + int err, sz, nelm;
11697 + aufs_bindex_t bindex, btail;
11698 + struct au_drinfo_store work;
11699 + struct au_drinfo_rev *rev, **p;
11700 + struct au_drinfo_rev_elm *elm;
11701 + struct super_block *sb;
11702 + struct au_branch *br;
11703 + struct au_hinode *hdir;
11705 + err = au_drinfo_store_work_init(&work, btgt);
11707 + if (unlikely(err))
11711 + btail = au_dbtaildir(dentry);
11712 + nelm = btail - btgt;
11713 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11714 + rev = kcalloc(1, sz, GFP_NOFS);
11715 + if (unlikely(!rev)) {
11719 + rev->nelm = nelm;
11725 + sb = dentry->d_sb;
11726 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11727 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11728 + hdir = au_hi(d_inode(dentry), btgt);
11729 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11730 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11731 + work.h_dentry = au_h_dptr(dentry, bindex);
11732 + if (!work.h_dentry)
11735 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11736 + &work.allocated);
11738 + if (unlikely(err))
11741 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11742 + br = au_sbr(sb, bindex);
11743 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11744 + work.whnamelen += au_drinfo_name(br, work.infoname,
11745 + work.infonamelen);
11746 + AuDbg("whname %.*s, i%llu, %.*s\n",
11747 + work.whnamelen, work.whname,
11748 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11749 + work.fdata->drinfo.oldnamelen,
11750 + work.fdata->drinfo.oldname);
11752 + err = au_drinfo_store_sio(&work, elm);
11754 + if (unlikely(err))
11757 + if (unlikely(err)) {
11758 + /* revert all drinfo */
11759 + au_drinfo_store_rev(rev, &work);
11760 + au_kfree_try_rcu(rev);
11763 + au_hn_inode_unlock(hdir);
11766 + au_drinfo_store_work_fin(&work);
11771 +/* ---------------------------------------------------------------------- */
11773 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11774 + struct qstr *dst_name, void *_rev)
11776 + int err, already;
11778 + struct super_block *sb;
11779 + struct au_branch *br;
11780 + struct au_dr_br *dr;
11781 + struct dentry *h_dentry;
11782 + struct inode *h_inode;
11783 + struct au_dr_hino *ent;
11784 + struct au_drinfo_rev *rev, **p;
11786 + AuDbg("bindex %d\n", bindex);
11789 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11790 + if (unlikely(!ent))
11794 + br = au_sbr(sb, bindex);
11795 + dr = &br->br_dirren;
11796 + h_dentry = au_h_dptr(src, bindex);
11797 + h_inode = d_inode(h_dentry);
11798 + ino = h_inode->i_ino;
11799 + ent->dr_h_ino = ino;
11800 + already = au_dr_hino_test_add(dr, ino, ent);
11801 + AuDbg("b%d, hi%llu, already %d\n",
11802 + bindex, (unsigned long long)ino, already);
11804 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11809 + rev->already = already;
11810 + goto out; /* success */
11815 + au_dr_hino_del(dr, ent);
11816 + au_kfree_rcu(ent);
11823 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11825 + struct au_drinfo_rev *rev;
11826 + struct au_drinfo_rev_elm *elm;
11831 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11832 + dput(elm->info_dentry);
11833 + au_kfree_rcu(elm->info_last);
11835 + au_kfree_try_rcu(rev);
11838 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11841 + struct au_drinfo_store work;
11842 + struct au_drinfo_rev *rev = _rev;
11843 + struct super_block *sb;
11844 + struct au_branch *br;
11845 + struct inode *h_inode;
11846 + struct au_dr_br *dr;
11847 + struct au_dr_hino *ent;
11849 + err = au_drinfo_store_work_init(&work, btgt);
11850 + if (unlikely(err))
11854 + br = au_sbr(sb, btgt);
11855 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11856 + work.h_ppath.mnt = au_br_mnt(br);
11857 + au_drinfo_store_rev(rev, &work);
11858 + au_drinfo_store_work_fin(&work);
11859 + if (rev->already)
11862 + dr = &br->br_dirren;
11863 + h_inode = d_inode(work.h_ppath.dentry);
11864 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11866 + au_dr_hino_del(dr, ent);
11867 + au_kfree_rcu(ent);
11870 + au_kfree_try_rcu(rev);
11871 + if (unlikely(err))
11872 + pr_err("failed to remove dirren info\n");
11875 +/* ---------------------------------------------------------------------- */
11877 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11878 + char *whname, int whnamelen,
11879 + struct dentry **info_dentry)
11881 + struct au_drinfo *drinfo;
11883 + struct inode *h_dir;
11884 + struct path infopath;
11887 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11889 + *info_dentry = NULL;
11892 + h_dir = d_inode(h_ppath->dentry);
11893 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11894 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11896 + if (IS_ERR(infopath.dentry)) {
11897 + drinfo = (void *)infopath.dentry;
11901 + if (d_is_negative(infopath.dentry))
11902 + goto out_dput; /* success */
11904 + infopath.mnt = h_ppath->mnt;
11905 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11906 + inode_unlock_shared(h_dir);
11909 + drinfo = (void *)f;
11913 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11914 + if (IS_ERR_OR_NULL(drinfo))
11917 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11918 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11923 + dput(infopath.dentry);
11926 + inode_unlock_shared(h_dir);
11927 + AuTraceErrPtr(drinfo);
11931 +struct au_drinfo_do_load_args {
11932 + struct au_drinfo **drinfop;
11933 + struct path *h_ppath;
11936 + struct dentry **info_dentry;
11939 +static void au_call_drinfo_do_load(void *args)
11941 + struct au_drinfo_do_load_args *a = args;
11943 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11947 +struct au_drinfo_load {
11948 + struct path h_ppath;
11949 + struct qstr *qname;
11950 + unsigned char no_sio;
11952 + aufs_bindex_t ninfo;
11953 + struct au_drinfo **drinfo;
11956 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11957 + struct au_branch *br)
11959 + int err, wkq_err, whnamelen, e;
11960 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11961 + = AUFS_WH_DR_INFO_PFX;
11962 + struct au_drinfo *drinfo;
11963 + struct qstr oldname;
11964 + struct inode *h_dir, *delegated;
11965 + struct dentry *info_dentry;
11966 + struct path infopath;
11968 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11969 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11970 + sizeof(whname) - whnamelen);
11972 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11975 + struct au_drinfo_do_load_args args = {
11976 + .drinfop = &drinfo,
11977 + .h_ppath = &w->h_ppath,
11978 + .whname = whname,
11979 + .whnamelen = whnamelen,
11980 + .info_dentry = &info_dentry
11982 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11983 + if (unlikely(wkq_err))
11984 + drinfo = ERR_PTR(wkq_err);
11986 + err = PTR_ERR(drinfo);
11987 + if (IS_ERR_OR_NULL(drinfo))
11991 + oldname.len = drinfo->oldnamelen;
11992 + oldname.name = drinfo->oldname;
11993 + if (au_qstreq(w->qname, &oldname)) {
11994 + /* the name is renamed back */
11995 + au_kfree_rcu(drinfo);
11998 + infopath.dentry = info_dentry;
11999 + infopath.mnt = w->h_ppath.mnt;
12000 + h_dir = d_inode(w->h_ppath.dentry);
12001 + delegated = NULL;
12002 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
12003 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
12004 + inode_unlock(h_dir);
12006 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12007 + if (unlikely(e == -EWOULDBLOCK))
12010 + au_kfree_rcu(w->drinfo[bindex]);
12011 + w->drinfo[bindex] = drinfo;
12012 + dput(info_dentry);
12019 +/* ---------------------------------------------------------------------- */
12021 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12023 + struct au_drinfo **p = drinfo;
12026 + au_kfree_rcu(*drinfo++);
12027 + au_kfree_try_rcu(p);
12030 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12031 + aufs_bindex_t btgt)
12034 + struct au_drinfo_load w;
12035 + aufs_bindex_t bindex, bbot;
12036 + struct au_branch *br;
12037 + struct inode *h_dir;
12038 + struct au_dr_hino *ent;
12039 + struct super_block *sb;
12041 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12042 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12043 + AuLNPair(&lkup->whname), btgt);
12045 + sb = dentry->d_sb;
12046 + bbot = au_sbbot(sb);
12047 + w.ninfo = bbot + 1;
12048 + if (!lkup->dirren.drinfo) {
12049 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12050 + sizeof(*lkup->dirren.drinfo),
12052 + if (unlikely(!lkup->dirren.drinfo)) {
12056 + lkup->dirren.ninfo = w.ninfo;
12058 + w.drinfo = lkup->dirren.drinfo;
12059 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12060 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12061 + AuDebugOn(!w.h_ppath.dentry);
12062 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12063 + w.qname = &dentry->d_name;
12066 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12067 + br = au_sbr(sb, bindex);
12068 + err = au_drinfo_load(&w, bindex, br);
12069 + if (unlikely(err))
12071 + if (w.drinfo[bindex])
12075 + br = au_sbr(sb, btgt);
12076 + h_dir = d_inode(w.h_ppath.dentry);
12077 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12079 + au_dr_hino_del(&br->br_dirren, ent);
12080 + au_kfree_rcu(ent);
12082 + goto out; /* success */
12085 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12086 + lkup->dirren.ninfo = 0;
12087 + lkup->dirren.drinfo = NULL;
12093 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12095 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12098 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12101 + struct au_drinfo *drinfo;
12104 + if (!lkup->dirren.drinfo)
12106 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12107 + drinfo = lkup->dirren.drinfo[btgt];
12111 + au_kfree_try_rcu(lkup->whname.name);
12112 + lkup->whname.name = NULL;
12113 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12114 + lkup->dirren.dr_name.name = drinfo->oldname;
12115 + lkup->name = &lkup->dirren.dr_name;
12116 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12118 + AuDbg("name %.*s, whname %.*s, b%d\n",
12119 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12127 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12131 + struct au_drinfo *drinfo;
12134 + if (!lkup->dirren.drinfo)
12136 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12137 + drinfo = lkup->dirren.drinfo[bindex];
12141 + match = (drinfo->ino == h_ino);
12142 + AuDbg("match %d\n", match);
12148 +/* ---------------------------------------------------------------------- */
12150 +int au_dr_opt_set(struct super_block *sb)
12153 + aufs_bindex_t bindex, bbot;
12154 + struct au_branch *br;
12157 + bbot = au_sbbot(sb);
12158 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12159 + br = au_sbr(sb, bindex);
12160 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12166 +int au_dr_opt_flush(struct super_block *sb)
12169 + aufs_bindex_t bindex, bbot;
12170 + struct au_branch *br;
12173 + bbot = au_sbbot(sb);
12174 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12175 + br = au_sbr(sb, bindex);
12176 + if (au_br_writable(br->br_perm))
12177 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12183 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12186 + aufs_bindex_t bindex, bbot;
12187 + struct au_branch *br;
12191 + err = au_dr_opt_flush(sb);
12192 + if (unlikely(err))
12196 + bbot = au_sbbot(sb);
12197 + for (bindex = 0; bindex <= bbot; bindex++) {
12198 + br = au_sbr(sb, bindex);
12199 + au_dr_hino_free(&br->br_dirren);
12205 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12206 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12207 +++ linux/fs/aufs/dirren.h 2021-09-06 21:02:45.276825587 +0200
12209 +/* SPDX-License-Identifier: GPL-2.0 */
12211 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12213 + * This program, aufs is free software; you can redistribute it and/or modify
12214 + * it under the terms of the GNU General Public License as published by
12215 + * the Free Software Foundation; either version 2 of the License, or
12216 + * (at your option) any later version.
12218 + * This program is distributed in the hope that it will be useful,
12219 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12220 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12221 + * GNU General Public License for more details.
12223 + * You should have received a copy of the GNU General Public License
12224 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12228 + * renamed dir info
12231 +#ifndef __AUFS_DIRREN_H__
12232 +#define __AUFS_DIRREN_H__
12236 +#include <linux/dcache.h>
12237 +#include <linux/statfs.h>
12238 +#include <linux/uuid.h>
12241 +#define AuDirren_NHASH 100
12243 +#ifdef CONFIG_AUFS_DIRREN
12244 +enum au_brid_type {
12251 +struct au_dr_brid {
12252 + enum au_brid_type type;
12254 + uuid_t uuid; /* unimplemented yet */
12260 +/* 20 is the max digits length of ulong 64 */
12261 +/* brid-type "_" uuid "_" inum */
12262 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12263 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12265 +struct au_dr_hino {
12266 + struct hlist_bl_node dr_hnode;
12271 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12272 + struct au_dr_brid dr_brid;
12275 +struct au_dr_lookup {
12276 + /* dr_name is pointed by struct au_do_lookup_args.name */
12277 + struct qstr dr_name; /* subset of dr_info */
12278 + aufs_bindex_t ninfo;
12279 + struct au_drinfo **drinfo;
12282 +struct au_dr_hino;
12284 +struct au_dr_br { };
12285 +struct au_dr_lookup { };
12288 +/* ---------------------------------------------------------------------- */
12291 +struct au_do_lookup_args;
12293 +#ifdef CONFIG_AUFS_DIRREN
12294 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12295 + struct au_dr_hino *add_ent);
12296 +void au_dr_hino_free(struct au_dr_br *dr);
12297 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12298 + const struct path *path);
12299 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12300 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12301 + struct qstr *dst_name, void *_rev);
12302 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12303 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12304 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12305 + aufs_bindex_t bindex);
12306 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12307 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12309 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12310 +int au_dr_opt_set(struct super_block *sb);
12311 +int au_dr_opt_flush(struct super_block *sb);
12312 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12314 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12315 + struct au_dr_hino *add_ent);
12316 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12317 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12318 + const struct path *path);
12319 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12320 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12321 + struct qstr *dst_name, void *_rev);
12322 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12323 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12325 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12326 + aufs_bindex_t bindex);
12327 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12328 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12329 + aufs_bindex_t bindex, ino_t h_ino);
12330 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12331 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12332 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12333 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12336 +/* ---------------------------------------------------------------------- */
12338 +#ifdef CONFIG_AUFS_DIRREN
12339 +static inline int au_dr_ihash(ino_t h_ino)
12341 + return h_ino % AuDirren_NHASH;
12344 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12347 +#endif /* __KERNEL__ */
12348 +#endif /* __AUFS_DIRREN_H__ */
12349 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12350 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12351 +++ linux/fs/aufs/dynop.c 2021-09-06 21:02:45.276825587 +0200
12353 +// SPDX-License-Identifier: GPL-2.0
12355 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12357 + * This program, aufs is free software; you can redistribute it and/or modify
12358 + * it under the terms of the GNU General Public License as published by
12359 + * the Free Software Foundation; either version 2 of the License, or
12360 + * (at your option) any later version.
12362 + * This program is distributed in the hope that it will be useful,
12363 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12364 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12365 + * GNU General Public License for more details.
12367 + * You should have received a copy of the GNU General Public License
12368 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12372 + * dynamically customizable operations for regular files
12377 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12380 + * How large will these lists be?
12381 + * Usually just a few elements, 20-30 at most for each, I guess.
12383 +static struct hlist_bl_head dynop[AuDyLast];
12385 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12386 + const void *h_op)
12388 + struct au_dykey *key, *tmp;
12389 + struct hlist_bl_node *pos;
12392 + hlist_bl_lock(hbl);
12393 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12394 + if (tmp->dk_op.dy_hop == h_op) {
12395 + if (kref_get_unless_zero(&tmp->dk_kref))
12399 + hlist_bl_unlock(hbl);
12404 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12406 + struct au_dykey **k, *found;
12407 + const void *h_op = key->dk_op.dy_hop;
12411 + k = br->br_dykey;
12412 + for (i = 0; i < AuBrDynOp; i++)
12414 + if (k[i]->dk_op.dy_hop == h_op) {
12421 + spin_lock(&br->br_dykey_lock);
12422 + for (; i < AuBrDynOp; i++)
12424 + if (k[i]->dk_op.dy_hop == h_op) {
12432 + spin_unlock(&br->br_dykey_lock);
12433 + BUG_ON(i == AuBrDynOp); /* expand the array */
12439 +/* kref_get() if @key is already added */
12440 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12442 + struct au_dykey *tmp, *found;
12443 + struct hlist_bl_node *pos;
12444 + const void *h_op = key->dk_op.dy_hop;
12447 + hlist_bl_lock(hbl);
12448 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12449 + if (tmp->dk_op.dy_hop == h_op) {
12450 + if (kref_get_unless_zero(&tmp->dk_kref))
12455 + hlist_bl_add_head(&key->dk_hnode, hbl);
12456 + hlist_bl_unlock(hbl);
12463 +static void dy_free_rcu(struct rcu_head *rcu)
12465 + struct au_dykey *key;
12467 + key = container_of(rcu, struct au_dykey, dk_rcu);
12472 +static void dy_free(struct kref *kref)
12474 + struct au_dykey *key;
12475 + struct hlist_bl_head *hbl;
12477 + key = container_of(kref, struct au_dykey, dk_kref);
12478 + hbl = dynop + key->dk_op.dy_type;
12479 + au_hbl_del(&key->dk_hnode, hbl);
12480 + call_rcu(&key->dk_rcu, dy_free_rcu);
12483 +void au_dy_put(struct au_dykey *key)
12485 + kref_put(&key->dk_kref, dy_free);
12488 +/* ---------------------------------------------------------------------- */
12490 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12492 +#ifdef CONFIG_AUFS_DEBUG
12493 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12494 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12496 +#define DyDbgDeclare(cnt) do {} while (0)
12497 +#define DyDbgInc(cnt) do {} while (0)
12500 +#define DySet(func, dst, src, h_op, h_sb) do { \
12502 + if (h_op->func) { \
12504 + dst.func = src.func; \
12506 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12510 +#define DySetForce(func, dst, src) do { \
12511 + AuDebugOn(!src.func); \
12513 + dst.func = src.func; \
12516 +#define DySetAop(func) \
12517 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12518 +#define DySetAopForce(func) \
12519 + DySetForce(func, dyaop->da_op, aufs_aop)
12521 +static void dy_aop(struct au_dykey *key, const void *h_op,
12522 + struct super_block *h_sb __maybe_unused)
12524 + struct au_dyaop *dyaop = (void *)key;
12525 + const struct address_space_operations *h_aop = h_op;
12526 + DyDbgDeclare(cnt);
12528 + AuDbg("%s\n", au_sbtype(h_sb));
12530 + DySetAop(writepage);
12531 + DySetAopForce(readpage); /* force */
12532 + DySetAop(writepages);
12533 + DySetAop(set_page_dirty);
12534 + DySetAop(readpages);
12535 + DySetAop(readahead);
12536 + DySetAop(write_begin);
12537 + DySetAop(write_end);
12539 + DySetAop(invalidatepage);
12540 + DySetAop(releasepage);
12541 + DySetAop(freepage);
12542 + /* this one will be changed according to an aufs mount option */
12543 + DySetAop(direct_IO);
12544 + DySetAop(migratepage);
12545 + DySetAop(isolate_page);
12546 + DySetAop(putback_page);
12547 + DySetAop(launder_page);
12548 + DySetAop(is_partially_uptodate);
12549 + DySetAop(is_dirty_writeback);
12550 + DySetAop(error_remove_page);
12551 + DySetAop(swap_activate);
12552 + DySetAop(swap_deactivate);
12554 + DyDbgSize(cnt, *h_aop);
12557 +/* ---------------------------------------------------------------------- */
12559 +static void dy_bug(struct kref *kref)
12564 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12566 + struct au_dykey *key, *old;
12567 + struct hlist_bl_head *hbl;
12570 + void (*set)(struct au_dykey *key, const void *h_op,
12571 + struct super_block *h_sb __maybe_unused);
12573 + static const struct op a[] = {
12575 + .sz = sizeof(struct au_dyaop),
12579 + const struct op *p;
12581 + hbl = dynop + op->dy_type;
12582 + key = dy_gfind_get(hbl, op->dy_hop);
12584 + goto out_add; /* success */
12586 + p = a + op->dy_type;
12587 + key = kzalloc(p->sz, GFP_NOFS);
12588 + if (unlikely(!key)) {
12589 + key = ERR_PTR(-ENOMEM);
12593 + key->dk_op.dy_hop = op->dy_hop;
12594 + kref_init(&key->dk_kref);
12595 + p->set(key, op->dy_hop, au_br_sb(br));
12596 + old = dy_gadd(hbl, key);
12598 + au_kfree_rcu(key);
12603 + old = dy_bradd(br, key);
12605 + /* its ref-count should never be zero here */
12606 + kref_put(&key->dk_kref, dy_bug);
12611 +/* ---------------------------------------------------------------------- */
12613 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12614 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12615 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12616 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12617 + * See the aufs manual in detail.
12619 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12622 + dyaop->da_op.direct_IO = NULL;
12624 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12627 +static struct au_dyaop *dy_aget(struct au_branch *br,
12628 + const struct address_space_operations *h_aop,
12631 + struct au_dyaop *dyaop;
12632 + struct au_dynop op;
12634 + op.dy_type = AuDy_AOP;
12635 + op.dy_haop = h_aop;
12636 + dyaop = (void *)dy_get(&op, br);
12637 + if (IS_ERR(dyaop))
12639 + dy_adx(dyaop, do_dx);
12645 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12646 + struct inode *h_inode)
12649 + struct super_block *sb;
12650 + struct au_branch *br;
12651 + struct au_dyaop *dyaop;
12653 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12654 + IiMustWriteLock(inode);
12656 + sb = inode->i_sb;
12657 + br = au_sbr(sb, bindex);
12658 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12659 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12660 + err = PTR_ERR(dyaop);
12661 + if (IS_ERR(dyaop))
12662 + /* unnecessary to call dy_fput() */
12666 + inode->i_mapping->a_ops = &dyaop->da_op;
12673 + * Is it safe to replace a_ops during the inode/file is in operation?
12674 + * Yes, I hope so.
12676 +int au_dy_irefresh(struct inode *inode)
12679 + aufs_bindex_t btop;
12680 + struct inode *h_inode;
12683 + if (S_ISREG(inode->i_mode)) {
12684 + btop = au_ibtop(inode);
12685 + h_inode = au_h_iptr(inode, btop);
12686 + err = au_dy_iaop(inode, btop, h_inode);
12691 +void au_dy_arefresh(int do_dx)
12693 + struct hlist_bl_head *hbl;
12694 + struct hlist_bl_node *pos;
12695 + struct au_dykey *key;
12697 + hbl = dynop + AuDy_AOP;
12698 + hlist_bl_lock(hbl);
12699 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12700 + dy_adx((void *)key, do_dx);
12701 + hlist_bl_unlock(hbl);
12704 +/* ---------------------------------------------------------------------- */
12706 +void __init au_dy_init(void)
12710 + for (i = 0; i < AuDyLast; i++)
12711 + INIT_HLIST_BL_HEAD(dynop + i);
12714 +void au_dy_fin(void)
12718 + for (i = 0; i < AuDyLast; i++)
12719 + WARN_ON(!hlist_bl_empty(dynop + i));
12721 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12722 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12723 +++ linux/fs/aufs/dynop.h 2021-09-06 21:02:45.276825587 +0200
12725 +/* SPDX-License-Identifier: GPL-2.0 */
12727 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12729 + * This program, aufs is free software; you can redistribute it and/or modify
12730 + * it under the terms of the GNU General Public License as published by
12731 + * the Free Software Foundation; either version 2 of the License, or
12732 + * (at your option) any later version.
12734 + * This program is distributed in the hope that it will be useful,
12735 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12736 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12737 + * GNU General Public License for more details.
12739 + * You should have received a copy of the GNU General Public License
12740 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12744 + * dynamically customizable operations (for regular files only)
12747 +#ifndef __AUFS_DYNOP_H__
12748 +#define __AUFS_DYNOP_H__
12752 +#include <linux/fs.h>
12753 +#include <linux/kref.h>
12755 +enum {AuDy_AOP, AuDyLast};
12760 + const void *dy_hop;
12761 + const struct address_space_operations *dy_haop;
12767 + struct hlist_bl_node dk_hnode;
12768 + struct rcu_head dk_rcu;
12770 + struct au_dynop dk_op;
12773 + * during I am in the branch local array, kref is gotten. when the
12774 + * branch is removed, kref is put.
12776 + struct kref dk_kref;
12779 +/* stop unioning since their sizes are very different from each other */
12781 + struct au_dykey da_key;
12782 + struct address_space_operations da_op; /* not const */
12784 +/* make sure that 'struct au_dykey *' can be any type */
12785 +static_assert(!offsetof(struct au_dyaop, da_key));
12787 +/* ---------------------------------------------------------------------- */
12791 +void au_dy_put(struct au_dykey *key);
12792 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12793 + struct inode *h_inode);
12794 +int au_dy_irefresh(struct inode *inode);
12795 +void au_dy_arefresh(int do_dio);
12797 +void __init au_dy_init(void);
12798 +void au_dy_fin(void);
12800 +#endif /* __KERNEL__ */
12801 +#endif /* __AUFS_DYNOP_H__ */
12802 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12803 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12804 +++ linux/fs/aufs/export.c 2021-09-06 21:02:45.276825587 +0200
12806 +// SPDX-License-Identifier: GPL-2.0
12808 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12810 + * This program, aufs is free software; you can redistribute it and/or modify
12811 + * it under the terms of the GNU General Public License as published by
12812 + * the Free Software Foundation; either version 2 of the License, or
12813 + * (at your option) any later version.
12815 + * This program is distributed in the hope that it will be useful,
12816 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12817 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12818 + * GNU General Public License for more details.
12820 + * You should have received a copy of the GNU General Public License
12821 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12828 +#include <linux/exportfs.h>
12829 +#include <linux/fs_struct.h>
12830 +#include <linux/namei.h>
12831 +#include <linux/nsproxy.h>
12832 +#include <linux/random.h>
12833 +#include <linux/writeback.h>
12837 +#ifdef CONFIG_AUFS_INO_T_64
12845 +static ino_t decode_ino(__u32 *a)
12849 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12851 +#ifdef CONFIG_AUFS_INO_T_64
12857 +static void encode_ino(__u32 *a, ino_t ino)
12863 +#ifdef CONFIG_AUFS_INO_T_64
12868 +/* NFS file handle */
12872 +#ifdef CONFIG_AUFS_INO_T_64
12873 + /* support 64bit inode number */
12886 + Fh_ino = Fh_ino1,
12887 + Fh_dir_ino = Fh_dir_ino1
12890 +static int au_test_anon(struct dentry *dentry)
12892 + /* note: read d_flags without d_lock */
12893 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12896 +int au_test_nfsd(void)
12899 + struct task_struct *tsk = current;
12900 + char comm[sizeof(tsk->comm)];
12903 + if (tsk->flags & PF_KTHREAD) {
12904 + get_task_comm(comm, tsk);
12905 + ret = !strcmp(comm, "nfsd");
12911 +/* ---------------------------------------------------------------------- */
12912 +/* inode generation external table */
12914 +void au_xigen_inc(struct inode *inode)
12919 + struct super_block *sb;
12920 + struct au_sbinfo *sbinfo;
12922 + sb = inode->i_sb;
12923 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12925 + sbinfo = au_sbi(sb);
12926 + pos = inode->i_ino;
12927 + pos *= sizeof(igen);
12928 + igen = inode->i_generation + 1;
12929 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12930 + if (sz == sizeof(igen))
12931 + return; /* success */
12933 + if (unlikely(sz >= 0))
12934 + AuIOErr("xigen error (%zd)\n", sz);
12937 +int au_xigen_new(struct inode *inode)
12942 + struct super_block *sb;
12943 + struct au_sbinfo *sbinfo;
12944 + struct file *file;
12947 + /* todo: dirty, at mount time */
12948 + if (inode->i_ino == AUFS_ROOT_INO)
12950 + sb = inode->i_sb;
12951 + SiMustAnyLock(sb);
12952 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12956 + pos = inode->i_ino;
12957 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12958 + AuIOErr1("too large i%lld\n", pos);
12961 + pos *= sizeof(inode->i_generation);
12964 + sbinfo = au_sbi(sb);
12965 + file = sbinfo->si_xigen;
12968 + if (vfsub_f_size_read(file)
12969 + < pos + sizeof(inode->i_generation)) {
12970 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12971 + sz = xino_fwrite(file, &inode->i_generation,
12972 + sizeof(inode->i_generation), &pos);
12974 + sz = xino_fread(file, &inode->i_generation,
12975 + sizeof(inode->i_generation), &pos);
12976 + if (sz == sizeof(inode->i_generation))
12977 + goto out; /* success */
12980 + if (unlikely(sz >= 0)) {
12982 + AuIOErr("xigen error (%zd)\n", sz);
12989 +int au_xigen_set(struct super_block *sb, struct path *path)
12992 + struct au_sbinfo *sbinfo;
12993 + struct file *file;
12995 + SiMustWriteLock(sb);
12997 + sbinfo = au_sbi(sb);
12998 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12999 + err = PTR_ERR(file);
13000 + if (IS_ERR(file))
13003 + if (sbinfo->si_xigen)
13004 + fput(sbinfo->si_xigen);
13005 + sbinfo->si_xigen = file;
13012 +void au_xigen_clr(struct super_block *sb)
13014 + struct au_sbinfo *sbinfo;
13016 + SiMustWriteLock(sb);
13018 + sbinfo = au_sbi(sb);
13019 + if (sbinfo->si_xigen) {
13020 + fput(sbinfo->si_xigen);
13021 + sbinfo->si_xigen = NULL;
13025 +/* ---------------------------------------------------------------------- */
13027 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13030 + struct dentry *dentry, *d;
13031 + struct inode *inode;
13032 + unsigned int sigen;
13035 + inode = ilookup(sb, ino);
13039 + dentry = ERR_PTR(-ESTALE);
13040 + sigen = au_sigen(sb);
13041 + if (unlikely(au_is_bad_inode(inode)
13042 + || IS_DEADDIR(inode)
13043 + || sigen != au_iigen(inode, NULL)))
13047 + if (!dir_ino || S_ISDIR(inode->i_mode))
13048 + dentry = d_find_alias(inode);
13050 + spin_lock(&inode->i_lock);
13051 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13052 + spin_lock(&d->d_lock);
13053 + if (!au_test_anon(d)
13054 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13055 + dentry = dget_dlock(d);
13056 + spin_unlock(&d->d_lock);
13059 + spin_unlock(&d->d_lock);
13061 + spin_unlock(&inode->i_lock);
13063 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13064 + /* need to refresh */
13072 + AuTraceErrPtr(dentry);
13076 +/* ---------------------------------------------------------------------- */
13078 +/* todo: dirty? */
13079 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13081 +struct au_compare_mnt_args {
13083 + struct super_block *sb;
13086 + struct vfsmount *mnt;
13089 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13091 + struct au_compare_mnt_args *a = arg;
13093 + if (mnt->mnt_sb != a->sb)
13095 + a->mnt = mntget(mnt);
13099 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13102 + struct path root;
13103 + struct au_compare_mnt_args args = {
13107 + get_fs_root(current->fs, &root);
13109 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13110 + rcu_read_unlock();
13113 + AuDebugOn(!args.mnt);
13117 +struct au_nfsd_si_lock {
13118 + unsigned int sigen;
13119 + aufs_bindex_t bindex, br_id;
13120 + unsigned char force_lock;
13123 +static int si_nfsd_read_lock(struct super_block *sb,
13124 + struct au_nfsd_si_lock *nsi_lock)
13127 + aufs_bindex_t bindex;
13129 + si_read_lock(sb, AuLock_FLUSH);
13131 + /* branch id may be wrapped around */
13133 + bindex = au_br_index(sb, nsi_lock->br_id);
13134 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13135 + goto out; /* success */
13139 + if (!nsi_lock->force_lock)
13140 + si_read_unlock(sb);
13143 + nsi_lock->bindex = bindex;
13147 +struct find_name_by_ino {
13148 + struct dir_context ctx;
13149 + int called, found;
13156 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13157 + loff_t offset, u64 ino, unsigned int d_type)
13159 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13163 + if (a->ino != ino)
13166 + memcpy(a->name, name, namelen);
13167 + a->namelen = namelen;
13172 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13173 + struct au_nfsd_si_lock *nsi_lock)
13175 + struct dentry *dentry, *parent;
13176 + struct file *file;
13177 + struct inode *dir;
13178 + struct find_name_by_ino arg = {
13180 + .actor = find_name_by_ino
13185 + parent = path->dentry;
13187 + si_read_unlock(parent->d_sb);
13188 + file = vfsub_dentry_open(path, au_dir_roflags);
13189 + dentry = (void *)file;
13190 + if (IS_ERR(file))
13193 + dentry = ERR_PTR(-ENOMEM);
13194 + arg.name = (void *)__get_free_page(GFP_NOFS);
13195 + if (unlikely(!arg.name))
13202 + err = vfsub_iterate_dir(file, &arg.ctx);
13203 + } while (!err && !arg.found && arg.called);
13204 + dentry = ERR_PTR(err);
13205 + if (unlikely(err))
13207 + /* instead of ENOENT */
13208 + dentry = ERR_PTR(-ESTALE);
13212 + /* do not call vfsub_lkup_one() */
13213 + dir = d_inode(parent);
13214 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13215 + AuTraceErrPtr(dentry);
13216 + if (IS_ERR(dentry))
13218 + AuDebugOn(au_test_anon(dentry));
13219 + if (unlikely(d_really_is_negative(dentry))) {
13221 + dentry = ERR_PTR(-ENOENT);
13225 + free_page((unsigned long)arg.name);
13229 + if (unlikely(nsi_lock
13230 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13231 + if (!IS_ERR(dentry)) {
13233 + dentry = ERR_PTR(-ESTALE);
13235 + AuTraceErrPtr(dentry);
13239 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13241 + struct au_nfsd_si_lock *nsi_lock)
13243 + struct dentry *dentry;
13244 + struct path path;
13246 + if (dir_ino != AUFS_ROOT_INO) {
13247 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13248 + dentry = path.dentry;
13249 + if (!path.dentry || IS_ERR(path.dentry))
13251 + AuDebugOn(au_test_anon(path.dentry));
13253 + path.dentry = dget(sb->s_root);
13255 + path.mnt = au_mnt_get(sb);
13256 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13260 + AuTraceErrPtr(dentry);
13264 +/* ---------------------------------------------------------------------- */
13266 +static int h_acceptable(void *expv, struct dentry *dentry)
13271 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13272 + char *buf, int len, struct super_block *sb)
13276 + struct path path;
13278 + p = d_path(h_rootpath, buf, len);
13283 + path.mnt = h_rootpath->mnt;
13284 + path.dentry = h_parent;
13285 + p = d_path(&path, buf, len);
13291 + path.mnt = au_mnt_get(sb);
13292 + path.dentry = sb->s_root;
13293 + p = d_path(&path, buf, len - strlen(p));
13294 + mntput(path.mnt);
13298 + p[strlen(p)] = '/';
13301 + AuTraceErrPtr(p);
13306 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13307 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13309 + struct dentry *dentry, *h_parent, *root;
13310 + struct super_block *h_sb;
13311 + char *pathname, *p;
13312 + struct vfsmount *h_mnt;
13313 + struct au_branch *br;
13315 + struct path path;
13317 + br = au_sbr(sb, nsi_lock->bindex);
13318 + h_mnt = au_br_mnt(br);
13319 + h_sb = h_mnt->mnt_sb;
13320 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13322 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13323 + fh_len - Fh_tail, fh[Fh_h_type],
13324 + h_acceptable, /*context*/NULL);
13326 + dentry = h_parent;
13327 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13328 + AuWarn1("%s decode_fh failed, %ld\n",
13329 + au_sbtype(h_sb), PTR_ERR(h_parent));
13333 + if (unlikely(au_test_anon(h_parent))) {
13334 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13335 + au_sbtype(h_sb));
13336 + goto out_h_parent;
13339 + dentry = ERR_PTR(-ENOMEM);
13340 + pathname = (void *)__get_free_page(GFP_NOFS);
13341 + if (unlikely(!pathname))
13342 + goto out_h_parent;
13344 + root = sb->s_root;
13345 + path.mnt = h_mnt;
13346 + di_read_lock_parent(root, !AuLock_IR);
13347 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13348 + di_read_unlock(root, !AuLock_IR);
13349 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13350 + dentry = (void *)p;
13352 + goto out_pathname;
13354 + si_read_unlock(sb);
13355 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13356 + dentry = ERR_PTR(err);
13357 + if (unlikely(err))
13360 + dentry = ERR_PTR(-ENOENT);
13361 + AuDebugOn(au_test_anon(path.dentry));
13362 + if (unlikely(d_really_is_negative(path.dentry)))
13365 + if (ino != d_inode(path.dentry)->i_ino)
13366 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13368 + dentry = dget(path.dentry);
13373 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13374 + if (!IS_ERR(dentry)) {
13376 + dentry = ERR_PTR(-ESTALE);
13379 + free_page((unsigned long)pathname);
13383 + AuTraceErrPtr(dentry);
13387 +/* ---------------------------------------------------------------------- */
13389 +static struct dentry *
13390 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13393 + struct dentry *dentry;
13394 + __u32 *fh = fid->raw;
13395 + struct au_branch *br;
13396 + ino_t ino, dir_ino;
13397 + struct au_nfsd_si_lock nsi_lock = {
13401 + dentry = ERR_PTR(-ESTALE);
13402 + /* it should never happen, but the file handle is unreliable */
13403 + if (unlikely(fh_len < Fh_tail))
13405 + nsi_lock.sigen = fh[Fh_sigen];
13406 + nsi_lock.br_id = fh[Fh_br_id];
13408 + /* branch id may be wrapped around */
13410 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13412 + nsi_lock.force_lock = 1;
13414 + /* is this inode still cached? */
13415 + ino = decode_ino(fh + Fh_ino);
13416 + /* it should never happen */
13417 + if (unlikely(ino == AUFS_ROOT_INO))
13420 + dir_ino = decode_ino(fh + Fh_dir_ino);
13421 + dentry = decode_by_ino(sb, ino, dir_ino);
13422 + if (IS_ERR(dentry))
13427 + /* is the parent dir cached? */
13428 + br = au_sbr(sb, nsi_lock.bindex);
13429 + au_lcnt_inc(&br->br_nfiles);
13430 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13431 + if (IS_ERR(dentry))
13436 + /* lookup path */
13437 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13438 + if (IS_ERR(dentry))
13440 + if (unlikely(!dentry))
13441 + /* todo?: make it ESTALE */
13445 + if (!au_digen_test(dentry, au_sigen(sb))
13446 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13447 + goto out_unlock; /* success */
13450 + dentry = ERR_PTR(-ESTALE);
13453 + au_lcnt_dec(&br->br_nfiles);
13454 + si_read_unlock(sb);
13456 + AuTraceErrPtr(dentry);
13460 +#if 0 /* reserved for future use */
13461 +/* support subtreecheck option */
13462 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13463 + int fh_len, int fh_type)
13465 + struct dentry *parent;
13466 + __u32 *fh = fid->raw;
13469 + dir_ino = decode_ino(fh + Fh_dir_ino);
13470 + parent = decode_by_ino(sb, dir_ino, 0);
13471 + if (IS_ERR(parent))
13474 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13475 + dir_ino, fh, fh_len);
13478 + AuTraceErrPtr(parent);
13483 +/* ---------------------------------------------------------------------- */
13485 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13486 + struct inode *dir)
13489 + aufs_bindex_t bindex;
13490 + struct super_block *sb, *h_sb;
13491 + struct dentry *dentry, *parent, *h_parent;
13492 + struct inode *h_dir;
13493 + struct au_branch *br;
13496 + if (unlikely(*max_len <= Fh_tail)) {
13497 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13501 + err = FILEID_ROOT;
13502 + if (inode->i_ino == AUFS_ROOT_INO) {
13503 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13508 + sb = inode->i_sb;
13509 + err = si_read_lock(sb, AuLock_FLUSH);
13510 + if (unlikely(err))
13513 +#ifdef CONFIG_AUFS_DEBUG
13514 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13515 + AuWarn1("NFS-exporting requires xino\n");
13519 + ii_read_lock_child(inode);
13520 + bindex = au_ibtop(inode);
13522 + dentry = d_find_any_alias(inode);
13523 + if (unlikely(!dentry))
13525 + AuDebugOn(au_test_anon(dentry));
13526 + parent = dget_parent(dentry);
13528 + if (unlikely(!parent))
13530 + if (d_really_is_positive(parent))
13531 + dir = d_inode(parent);
13534 + ii_read_lock_parent(dir);
13535 + h_dir = au_h_iptr(dir, bindex);
13536 + ii_read_unlock(dir);
13537 + if (unlikely(!h_dir))
13539 + h_parent = d_find_any_alias(h_dir);
13540 + if (unlikely(!h_parent))
13541 + goto out_hparent;
13544 + br = au_sbr(sb, bindex);
13545 + h_sb = au_br_sb(br);
13546 + if (unlikely(!h_sb->s_export_op)) {
13547 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13548 + goto out_hparent;
13551 + fh[Fh_br_id] = br->br_id;
13552 + fh[Fh_sigen] = au_sigen(sb);
13553 + encode_ino(fh + Fh_ino, inode->i_ino);
13554 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13555 + fh[Fh_igen] = inode->i_generation;
13557 + *max_len -= Fh_tail;
13558 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13560 + /*connectable or subtreecheck*/0);
13561 + err = fh[Fh_h_type];
13562 + *max_len += Fh_tail;
13563 + /* todo: macros? */
13564 + if (err != FILEID_INVALID)
13567 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13574 + ii_read_unlock(inode);
13575 + si_read_unlock(sb);
13577 + if (unlikely(err < 0))
13578 + err = FILEID_INVALID;
13582 +/* ---------------------------------------------------------------------- */
13584 +static int aufs_commit_metadata(struct inode *inode)
13587 + aufs_bindex_t bindex;
13588 + struct super_block *sb;
13589 + struct inode *h_inode;
13590 + int (*f)(struct inode *inode);
13592 + sb = inode->i_sb;
13593 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13594 + ii_write_lock_child(inode);
13595 + bindex = au_ibtop(inode);
13596 + AuDebugOn(bindex < 0);
13597 + h_inode = au_h_iptr(inode, bindex);
13599 + f = h_inode->i_sb->s_export_op->commit_metadata;
13601 + err = f(h_inode);
13603 + struct writeback_control wbc = {
13604 + .sync_mode = WB_SYNC_ALL,
13605 + .nr_to_write = 0 /* metadata only */
13608 + err = sync_inode(h_inode, &wbc);
13611 + au_cpup_attr_timesizes(inode);
13612 + ii_write_unlock(inode);
13613 + si_read_unlock(sb);
13617 +/* ---------------------------------------------------------------------- */
13619 +static struct export_operations aufs_export_op = {
13620 + .fh_to_dentry = aufs_fh_to_dentry,
13621 + /* .fh_to_parent = aufs_fh_to_parent, */
13622 + .encode_fh = aufs_encode_fh,
13623 + .commit_metadata = aufs_commit_metadata
13626 +void au_export_init(struct super_block *sb)
13628 + struct au_sbinfo *sbinfo;
13631 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13632 + && IS_MODULE(CONFIG_EXPORTFS),
13633 + AUFS_NAME ": unsupported configuration "
13634 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13636 + sb->s_export_op = &aufs_export_op;
13637 + sbinfo = au_sbi(sb);
13638 + sbinfo->si_xigen = NULL;
13639 + get_random_bytes(&u, sizeof(u));
13640 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13641 + atomic_set(&sbinfo->si_xigen_next, u);
13643 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13644 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13645 +++ linux/fs/aufs/fhsm.c 2021-09-06 21:02:45.276825587 +0200
13647 +// SPDX-License-Identifier: GPL-2.0
13649 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13651 + * This program, aufs is free software; you can redistribute it and/or modify
13652 + * it under the terms of the GNU General Public License as published by
13653 + * the Free Software Foundation; either version 2 of the License, or
13654 + * (at your option) any later version.
13656 + * This program is distributed in the hope that it will be useful,
13657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13659 + * GNU General Public License for more details.
13661 + * You should have received a copy of the GNU General Public License
13662 + * along with this program; if not, write to the Free Software
13663 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13667 + * File-based Hierarchy Storage Management
13670 +#include <linux/anon_inodes.h>
13671 +#include <linux/poll.h>
13672 +#include <linux/seq_file.h>
13673 +#include <linux/statfs.h>
13676 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13678 + struct au_sbinfo *sbinfo;
13679 + struct au_fhsm *fhsm;
13681 + SiMustAnyLock(sb);
13683 + sbinfo = au_sbi(sb);
13684 + fhsm = &sbinfo->si_fhsm;
13685 + AuDebugOn(!fhsm);
13686 + return fhsm->fhsm_bottom;
13689 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13691 + struct au_sbinfo *sbinfo;
13692 + struct au_fhsm *fhsm;
13694 + SiMustWriteLock(sb);
13696 + sbinfo = au_sbi(sb);
13697 + fhsm = &sbinfo->si_fhsm;
13698 + AuDebugOn(!fhsm);
13699 + fhsm->fhsm_bottom = bindex;
13702 +/* ---------------------------------------------------------------------- */
13704 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13706 + struct au_br_fhsm *bf;
13708 + bf = br->br_fhsm;
13709 + MtxMustLock(&bf->bf_lock);
13711 + return !bf->bf_readable
13712 + || time_after(jiffies,
13713 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13716 +/* ---------------------------------------------------------------------- */
13718 +static void au_fhsm_notify(struct super_block *sb, int val)
13720 + struct au_sbinfo *sbinfo;
13721 + struct au_fhsm *fhsm;
13723 + SiMustAnyLock(sb);
13725 + sbinfo = au_sbi(sb);
13726 + fhsm = &sbinfo->si_fhsm;
13727 + if (au_fhsm_pid(fhsm)
13728 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13729 + atomic_set(&fhsm->fhsm_readable, val);
13731 + wake_up(&fhsm->fhsm_wqh);
13735 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13736 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13739 + struct au_branch *br;
13740 + struct au_br_fhsm *bf;
13742 + br = au_sbr(sb, bindex);
13743 + AuDebugOn(au_br_rdonly(br));
13744 + bf = br->br_fhsm;
13748 + mutex_lock(&bf->bf_lock);
13750 + MtxMustLock(&bf->bf_lock);
13752 + /* sb->s_root for NFS is unreliable */
13753 + err = au_br_stfs(br, &bf->bf_stfs);
13754 + if (unlikely(err)) {
13755 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13759 + bf->bf_jiffy = jiffies;
13760 + bf->bf_readable = 1;
13762 + au_fhsm_notify(sb, /*val*/1);
13764 + *rstfs = bf->bf_stfs;
13768 + mutex_unlock(&bf->bf_lock);
13769 + au_fhsm_notify(sb, /*val*/1);
13774 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13777 + struct au_sbinfo *sbinfo;
13778 + struct au_fhsm *fhsm;
13779 + struct au_branch *br;
13780 + struct au_br_fhsm *bf;
13782 + AuDbg("b%d, force %d\n", bindex, force);
13783 + SiMustAnyLock(sb);
13785 + sbinfo = au_sbi(sb);
13786 + fhsm = &sbinfo->si_fhsm;
13787 + if (!au_ftest_si(sbinfo, FHSM)
13788 + || fhsm->fhsm_bottom == bindex)
13791 + br = au_sbr(sb, bindex);
13792 + bf = br->br_fhsm;
13794 + mutex_lock(&bf->bf_lock);
13796 + || au_fhsm_pid(fhsm)
13797 + || au_fhsm_test_jiffy(sbinfo, br))
13798 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13800 + mutex_unlock(&bf->bf_lock);
13803 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13805 + aufs_bindex_t bindex, bbot;
13806 + struct au_branch *br;
13808 + /* exclude the bottom */
13809 + bbot = au_fhsm_bottom(sb);
13810 + for (bindex = 0; bindex < bbot; bindex++) {
13811 + br = au_sbr(sb, bindex);
13812 + if (au_br_fhsm(br->br_perm))
13813 + au_fhsm_wrote(sb, bindex, force);
13817 +/* ---------------------------------------------------------------------- */
13819 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13822 + struct au_sbinfo *sbinfo;
13823 + struct au_fhsm *fhsm;
13826 + sbinfo = file->private_data;
13827 + fhsm = &sbinfo->si_fhsm;
13828 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13829 + if (atomic_read(&fhsm->fhsm_readable))
13830 + mask = EPOLLIN /* | EPOLLRDNORM */;
13833 + AuDbg("mask 0x%x\n", mask);
13837 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13838 + struct aufs_stfs *stfs, __s16 brid)
13842 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13844 + err = __put_user(brid, &stbr->brid);
13845 + if (unlikely(err))
13851 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13852 + struct aufs_stbr __user *stbr, size_t count)
13856 + aufs_bindex_t bindex, bbot;
13857 + struct au_branch *br;
13858 + struct au_br_fhsm *bf;
13860 + /* except the bottom branch */
13863 + bbot = au_fhsm_bottom(sb);
13864 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13865 + br = au_sbr(sb, bindex);
13866 + if (!au_br_fhsm(br->br_perm))
13869 + bf = br->br_fhsm;
13870 + mutex_lock(&bf->bf_lock);
13871 + if (bf->bf_readable) {
13873 + if (count >= sizeof(*stbr))
13874 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13877 + bf->bf_readable = 0;
13878 + count -= sizeof(*stbr);
13882 + mutex_unlock(&bf->bf_lock);
13885 + err = sizeof(*stbr) * nstbr;
13890 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13895 + aufs_bindex_t nfhsm, bindex, bbot;
13896 + struct au_sbinfo *sbinfo;
13897 + struct au_fhsm *fhsm;
13898 + struct au_branch *br;
13899 + struct super_block *sb;
13902 + sbinfo = file->private_data;
13903 + fhsm = &sbinfo->si_fhsm;
13905 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13906 + if (!atomic_read(&fhsm->fhsm_readable)) {
13907 + if (vfsub_file_flags(file) & O_NONBLOCK)
13910 + err = wait_event_interruptible_locked_irq
13912 + atomic_read(&fhsm->fhsm_readable));
13914 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13915 + if (unlikely(err))
13918 + /* sb may already be dead */
13919 + au_rw_read_lock(&sbinfo->si_rwsem);
13920 + readable = atomic_read(&fhsm->fhsm_readable);
13921 + if (readable > 0) {
13922 + sb = sbinfo->si_sb;
13924 + /* exclude the bottom branch */
13926 + bbot = au_fhsm_bottom(sb);
13927 + for (bindex = 0; bindex < bbot; bindex++) {
13928 + br = au_sbr(sb, bindex);
13929 + if (au_br_fhsm(br->br_perm))
13933 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13934 + atomic_set(&fhsm->fhsm_readable, 0);
13935 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13939 + au_rw_read_unlock(&sbinfo->si_rwsem);
13947 +static int au_fhsm_release(struct inode *inode, struct file *file)
13949 + struct au_sbinfo *sbinfo;
13950 + struct au_fhsm *fhsm;
13952 + /* sb may already be dead */
13953 + sbinfo = file->private_data;
13954 + fhsm = &sbinfo->si_fhsm;
13955 + spin_lock(&fhsm->fhsm_spin);
13956 + fhsm->fhsm_pid = 0;
13957 + spin_unlock(&fhsm->fhsm_spin);
13958 + kobject_put(&sbinfo->si_kobj);
13963 +static const struct file_operations au_fhsm_fops = {
13964 + .owner = THIS_MODULE,
13965 + .llseek = noop_llseek,
13966 + .read = au_fhsm_read,
13967 + .poll = au_fhsm_poll,
13968 + .release = au_fhsm_release
13971 +int au_fhsm_fd(struct super_block *sb, int oflags)
13974 + struct au_sbinfo *sbinfo;
13975 + struct au_fhsm *fhsm;
13978 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13982 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13986 + sbinfo = au_sbi(sb);
13987 + fhsm = &sbinfo->si_fhsm;
13988 + spin_lock(&fhsm->fhsm_spin);
13989 + if (!fhsm->fhsm_pid)
13990 + fhsm->fhsm_pid = current->pid;
13993 + spin_unlock(&fhsm->fhsm_spin);
13994 + if (unlikely(err))
13997 + oflags |= O_RDONLY;
13998 + /* oflags |= FMODE_NONOTIFY; */
13999 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
14001 + if (unlikely(fd < 0))
14004 + /* succeed regardless 'fhsm' status */
14005 + kobject_get(&sbinfo->si_kobj);
14006 + si_noflush_read_lock(sb);
14007 + if (au_ftest_si(sbinfo, FHSM))
14008 + au_fhsm_wrote_all(sb, /*force*/0);
14009 + si_read_unlock(sb);
14010 + goto out; /* success */
14013 + spin_lock(&fhsm->fhsm_spin);
14014 + fhsm->fhsm_pid = 0;
14015 + spin_unlock(&fhsm->fhsm_spin);
14021 +/* ---------------------------------------------------------------------- */
14023 +int au_fhsm_br_alloc(struct au_branch *br)
14028 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14030 + au_br_fhsm_init(br->br_fhsm);
14037 +/* ---------------------------------------------------------------------- */
14039 +void au_fhsm_fin(struct super_block *sb)
14041 + au_fhsm_notify(sb, /*val*/-1);
14044 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14046 + struct au_fhsm *fhsm;
14048 + fhsm = &sbinfo->si_fhsm;
14049 + spin_lock_init(&fhsm->fhsm_spin);
14050 + init_waitqueue_head(&fhsm->fhsm_wqh);
14051 + atomic_set(&fhsm->fhsm_readable, 0);
14052 + fhsm->fhsm_expire
14053 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14054 + fhsm->fhsm_bottom = -1;
14057 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14059 + sbinfo->si_fhsm.fhsm_expire
14060 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14063 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14067 + if (!au_ftest_si(sbinfo, FHSM))
14070 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14071 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14072 + seq_printf(seq, ",fhsm_sec=%u", u);
14074 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14075 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14076 +++ linux/fs/aufs/file.c 2021-09-06 21:02:45.276825587 +0200
14078 +// SPDX-License-Identifier: GPL-2.0
14080 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14082 + * This program, aufs is free software; you can redistribute it and/or modify
14083 + * it under the terms of the GNU General Public License as published by
14084 + * the Free Software Foundation; either version 2 of the License, or
14085 + * (at your option) any later version.
14087 + * This program is distributed in the hope that it will be useful,
14088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14090 + * GNU General Public License for more details.
14092 + * You should have received a copy of the GNU General Public License
14093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14097 + * handling file/dir, and address_space operation
14100 +#ifdef CONFIG_AUFS_DEBUG
14101 +#include <linux/migrate.h>
14103 +#include <linux/pagemap.h>
14106 +/* drop flags for writing */
14107 +unsigned int au_file_roflags(unsigned int flags)
14109 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14110 + flags |= O_RDONLY | O_NOATIME;
14114 +/* common functions to regular file and dir */
14115 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14116 + struct file *file, int force_wr)
14118 + struct file *h_file;
14119 + struct dentry *h_dentry;
14120 + struct inode *h_inode;
14121 + struct super_block *sb;
14122 + struct au_branch *br;
14123 + struct path h_path;
14126 + /* a race condition can happen between open and unlink/rmdir */
14127 + h_file = ERR_PTR(-ENOENT);
14128 + h_dentry = au_h_dptr(dentry, bindex);
14129 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14131 + h_inode = d_inode(h_dentry);
14132 + spin_lock(&h_dentry->d_lock);
14133 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14134 + /* || !d_inode(dentry)->i_nlink */
14136 + spin_unlock(&h_dentry->d_lock);
14137 + if (unlikely(err))
14140 + sb = dentry->d_sb;
14141 + br = au_sbr(sb, bindex);
14142 + err = au_br_test_oflag(flags, br);
14143 + h_file = ERR_PTR(err);
14144 + if (unlikely(err))
14147 + /* drop flags for writing */
14148 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14149 + if (force_wr && !(flags & O_WRONLY))
14151 + flags = au_file_roflags(flags);
14153 + h_file = ERR_PTR(-EROFS);
14154 + flags = au_file_roflags(flags);
14155 + if (unlikely(vfsub_native_ro(h_inode)
14156 + || IS_APPEND(h_inode)))
14158 + flags &= ~O_ACCMODE;
14159 + flags |= O_WRONLY;
14162 + flags &= ~O_CREAT;
14163 + au_lcnt_inc(&br->br_nfiles);
14164 + h_path.dentry = h_dentry;
14165 + h_path.mnt = au_br_mnt(br);
14166 + h_file = vfsub_dentry_open(&h_path, flags);
14167 + if (IS_ERR(h_file))
14170 + if (flags & __FMODE_EXEC) {
14171 + err = deny_write_access(h_file);
14172 + if (unlikely(err)) {
14174 + h_file = ERR_PTR(err);
14178 + fsnotify_open(h_file);
14179 + goto out; /* success */
14182 + au_lcnt_dec(&br->br_nfiles);
14187 +static int au_cmoo(struct dentry *dentry)
14189 + int err, cmoo, matched;
14190 + unsigned int udba;
14191 + struct path h_path;
14192 + struct au_pin pin;
14193 + struct au_cp_generic cpg = {
14194 + .dentry = dentry,
14199 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14201 + struct inode *delegated;
14202 + struct super_block *sb;
14203 + struct au_sbinfo *sbinfo;
14204 + struct au_fhsm *fhsm;
14206 + struct au_branch *br;
14207 + struct dentry *parent;
14208 + struct au_hinode *hdir;
14210 + DiMustWriteLock(dentry);
14211 + IiMustWriteLock(d_inode(dentry));
14214 + if (IS_ROOT(dentry))
14216 + cpg.bsrc = au_dbtop(dentry);
14220 + sb = dentry->d_sb;
14221 + sbinfo = au_sbi(sb);
14222 + fhsm = &sbinfo->si_fhsm;
14223 + pid = au_fhsm_pid(fhsm);
14226 + && (current->pid == pid
14227 + || rcu_dereference(current->real_parent)->pid == pid));
14228 + rcu_read_unlock();
14232 + br = au_sbr(sb, cpg.bsrc);
14233 + cmoo = au_br_cmoo(br->br_perm);
14236 + if (!d_is_reg(dentry))
14237 + cmoo &= AuBrAttr_COO_ALL;
14241 + parent = dget_parent(dentry);
14242 + di_write_lock_parent(parent);
14243 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14245 + if (unlikely(err < 0)) {
14246 + err = 0; /* there is no upper writable branch */
14249 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14251 + /* do not respect the coo attrib for the target branch */
14252 + err = au_cpup_dirs(dentry, cpg.bdst);
14253 + if (unlikely(err))
14256 + di_downgrade_lock(parent, AuLock_IR);
14257 + udba = au_opt_udba(sb);
14258 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14259 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14260 + if (unlikely(err))
14263 + err = au_sio_cpup_simple(&cpg);
14265 + if (unlikely(err))
14267 + if (!(cmoo & AuBrWAttr_MOO))
14268 + goto out_parent; /* success */
14270 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14271 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14272 + if (unlikely(err))
14275 + h_path.mnt = au_br_mnt(br);
14276 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14277 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14278 + delegated = NULL;
14279 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14281 + /* todo: keep h_dentry or not? */
14282 + if (unlikely(err == -EWOULDBLOCK)) {
14283 + pr_warn("cannot retry for NFSv4 delegation"
14284 + " for an internal unlink\n");
14287 + if (unlikely(err)) {
14288 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14292 + goto out_parent; /* success */
14295 + di_downgrade_lock(parent, AuLock_IR);
14297 + di_read_unlock(parent, AuLock_IR);
14304 +int au_do_open(struct file *file, struct au_do_open_args *args)
14306 + int err, aopen = args->aopen;
14307 + struct dentry *dentry;
14308 + struct au_finfo *finfo;
14311 + err = au_finfo_init(file, args->fidir);
14314 + err = au_finfo_init(file, args->fidir);
14317 + if (unlikely(err))
14320 + dentry = file->f_path.dentry;
14321 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14322 + di_write_lock_child(dentry);
14323 + err = au_cmoo(dentry);
14324 + di_downgrade_lock(dentry, AuLock_IR);
14327 + err = args->open(file, vfsub_file_flags(file), NULL);
14330 + err = args->open(file, vfsub_file_flags(file),
14335 + di_read_unlock(dentry, AuLock_IR);
14337 + finfo = au_fi(file);
14339 + finfo->fi_file = file;
14340 + au_hbl_add(&finfo->fi_hlist,
14341 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14344 + fi_write_unlock(file);
14347 + fi_write_unlock(file);
14350 + if (unlikely(err)) {
14351 + finfo->fi_hdir = NULL;
14352 + au_finfo_fin(file);
14360 +int au_reopen_nondir(struct file *file)
14363 + aufs_bindex_t btop;
14364 + struct dentry *dentry;
14365 + struct au_branch *br;
14366 + struct file *h_file, *h_file_tmp;
14368 + dentry = file->f_path.dentry;
14369 + btop = au_dbtop(dentry);
14370 + br = au_sbr(dentry->d_sb, btop);
14371 + h_file_tmp = NULL;
14372 + if (au_fbtop(file) == btop) {
14373 + h_file = au_hf_top(file);
14374 + if (file->f_mode == h_file->f_mode)
14375 + return 0; /* success */
14376 + h_file_tmp = h_file;
14377 + get_file(h_file_tmp);
14378 + au_lcnt_inc(&br->br_nfiles);
14379 + au_set_h_fptr(file, btop, NULL);
14381 + AuDebugOn(au_fi(file)->fi_hdir);
14384 + * file exists on both of rw and ro
14385 + * open --> dbtop and fbtop are both 0
14386 + * prepend a branch as rw, "rw" become ro
14388 + * delete the top branch, "rw" becomes rw again
14389 + * --> dbtop is 1, fbtop is still 0
14390 + * write --> fbtop is 0 but dbtop is 1
14392 + /* AuDebugOn(au_fbtop(file) < btop); */
14394 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14395 + file, /*force_wr*/0);
14396 + err = PTR_ERR(h_file);
14397 + if (IS_ERR(h_file)) {
14398 + if (h_file_tmp) {
14400 + au_set_h_fptr(file, btop, h_file_tmp);
14401 + h_file_tmp = NULL;
14403 + goto out; /* todo: close all? */
14407 + au_set_fbtop(file, btop);
14408 + au_set_h_fptr(file, btop, h_file);
14409 + au_update_figen(file);
14410 + /* todo: necessary? */
14411 + /* file->f_ra = h_file->f_ra; */
14414 + if (h_file_tmp) {
14415 + fput(h_file_tmp);
14416 + au_lcnt_dec(&br->br_nfiles);
14421 +/* ---------------------------------------------------------------------- */
14423 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14424 + struct dentry *hi_wh)
14427 + aufs_bindex_t btop;
14428 + struct au_dinfo *dinfo;
14429 + struct dentry *h_dentry;
14430 + struct au_hdentry *hdp;
14432 + dinfo = au_di(file->f_path.dentry);
14433 + AuRwMustWriteLock(&dinfo->di_rwsem);
14435 + btop = dinfo->di_btop;
14436 + dinfo->di_btop = btgt;
14437 + hdp = au_hdentry(dinfo, btgt);
14438 + h_dentry = hdp->hd_dentry;
14439 + hdp->hd_dentry = hi_wh;
14440 + err = au_reopen_nondir(file);
14441 + hdp->hd_dentry = h_dentry;
14442 + dinfo->di_btop = btop;
14447 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14448 + aufs_bindex_t bcpup, struct au_pin *pin)
14451 + struct inode *inode, *h_inode;
14452 + struct dentry *h_dentry, *hi_wh;
14453 + struct au_cp_generic cpg = {
14454 + .dentry = file->f_path.dentry,
14461 + au_update_dbtop(cpg.dentry);
14462 + inode = d_inode(cpg.dentry);
14464 + if (au_dbtop(cpg.dentry) <= bcpup
14465 + && au_dbbot(cpg.dentry) >= bcpup) {
14466 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14467 + if (h_dentry && d_is_positive(h_dentry))
14468 + h_inode = d_inode(h_dentry);
14470 + hi_wh = au_hi_wh(inode, bcpup);
14471 + if (!hi_wh && !h_inode)
14472 + err = au_sio_cpup_wh(&cpg, file);
14474 + /* already copied-up after unlink */
14475 + err = au_reopen_wh(file, bcpup, hi_wh);
14478 + && (inode->i_nlink > 1
14479 + || (inode->i_state & I_LINKABLE))
14480 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14481 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14487 + * prepare the @file for writing.
14489 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14492 + aufs_bindex_t dbtop;
14493 + struct dentry *parent;
14494 + struct inode *inode;
14495 + struct super_block *sb;
14496 + struct file *h_file;
14497 + struct au_cp_generic cpg = {
14498 + .dentry = file->f_path.dentry,
14503 + .flags = AuCpup_DTIME
14506 + sb = cpg.dentry->d_sb;
14507 + inode = d_inode(cpg.dentry);
14508 + cpg.bsrc = au_fbtop(file);
14509 + err = au_test_ro(sb, cpg.bsrc, inode);
14510 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14511 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14516 + /* need to cpup or reopen */
14517 + parent = dget_parent(cpg.dentry);
14518 + di_write_lock_parent(parent);
14519 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14521 + if (unlikely(err < 0))
14525 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14526 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14527 + if (unlikely(err))
14531 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14532 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14533 + if (unlikely(err))
14536 + dbtop = au_dbtop(cpg.dentry);
14537 + if (dbtop <= cpg.bdst)
14538 + cpg.bsrc = cpg.bdst;
14540 + if (dbtop <= cpg.bdst /* just reopen */
14541 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14543 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14544 + if (IS_ERR(h_file))
14545 + err = PTR_ERR(h_file);
14547 + di_downgrade_lock(parent, AuLock_IR);
14548 + if (dbtop > cpg.bdst)
14549 + err = au_sio_cpup_simple(&cpg);
14551 + err = au_reopen_nondir(file);
14552 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14554 + } else { /* copyup as wh and reopen */
14556 + * since writable hfsplus branch is not supported,
14557 + * h_open_pre/post() are unnecessary.
14559 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14560 + di_downgrade_lock(parent, AuLock_IR);
14564 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14565 + goto out_dput; /* success */
14571 + di_downgrade_lock(parent, AuLock_IR);
14573 + di_read_unlock(parent, AuLock_IR);
14580 +/* ---------------------------------------------------------------------- */
14582 +int au_do_flush(struct file *file, fl_owner_t id,
14583 + int (*flush)(struct file *file, fl_owner_t id))
14586 + struct super_block *sb;
14587 + struct inode *inode;
14589 + inode = file_inode(file);
14590 + sb = inode->i_sb;
14591 + si_noflush_read_lock(sb);
14592 + fi_read_lock(file);
14593 + ii_read_lock_child(inode);
14595 + err = flush(file, id);
14596 + au_cpup_attr_timesizes(inode);
14598 + ii_read_unlock(inode);
14599 + fi_read_unlock(file);
14600 + si_read_unlock(sb);
14604 +/* ---------------------------------------------------------------------- */
14606 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14609 + struct au_pin pin;
14610 + struct au_finfo *finfo;
14611 + struct dentry *parent, *hi_wh;
14612 + struct inode *inode;
14613 + struct super_block *sb;
14614 + struct au_cp_generic cpg = {
14615 + .dentry = file->f_path.dentry,
14620 + .flags = AuCpup_DTIME
14623 + FiMustWriteLock(file);
14626 + finfo = au_fi(file);
14627 + sb = cpg.dentry->d_sb;
14628 + inode = d_inode(cpg.dentry);
14629 + cpg.bdst = au_ibtop(inode);
14630 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14633 + parent = dget_parent(cpg.dentry);
14634 + if (au_test_ro(sb, cpg.bdst, inode)) {
14635 + di_read_lock_parent(parent, !AuLock_IR);
14636 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14638 + di_read_unlock(parent, !AuLock_IR);
14639 + if (unlikely(err < 0))
14644 + di_read_lock_parent(parent, AuLock_IR);
14645 + hi_wh = au_hi_wh(inode, cpg.bdst);
14646 + if (!S_ISDIR(inode->i_mode)
14647 + && au_opt_test(au_mntflags(sb), PLINK)
14648 + && au_plink_test(inode)
14649 + && !d_unhashed(cpg.dentry)
14650 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14651 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14652 + if (unlikely(err))
14655 + /* always superio. */
14656 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14657 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14659 + err = au_sio_cpup_simple(&cpg);
14662 + } else if (hi_wh) {
14663 + /* already copied-up after unlink */
14664 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14665 + *need_reopen = 0;
14669 + di_read_unlock(parent, AuLock_IR);
14676 +static void au_do_refresh_dir(struct file *file)
14678 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14679 + struct au_hfile *p, tmp, *q;
14680 + struct au_finfo *finfo;
14681 + struct super_block *sb;
14682 + struct au_fidir *fidir;
14684 + FiMustWriteLock(file);
14686 + sb = file->f_path.dentry->d_sb;
14687 + finfo = au_fi(file);
14688 + fidir = finfo->fi_hdir;
14689 + AuDebugOn(!fidir);
14690 + p = fidir->fd_hfile + finfo->fi_btop;
14691 + brid = p->hf_br->br_id;
14692 + bbot = fidir->fd_bbot;
14693 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14697 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14698 + if (new_bindex == bindex)
14700 + if (new_bindex < 0) {
14701 + au_set_h_fptr(file, bindex, NULL);
14705 + /* swap two lower inode, and loop again */
14706 + q = fidir->fd_hfile + new_bindex;
14710 + if (tmp.hf_file) {
14716 + p = fidir->fd_hfile;
14717 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14718 + bbot = au_sbbot(sb);
14719 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14720 + finfo->fi_btop++, p++)
14721 + if (p->hf_file) {
14722 + if (file_inode(p->hf_file))
14724 + au_hfput(p, /*execed*/0);
14727 + bbot = au_br_index(sb, brid);
14728 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14729 + finfo->fi_btop++, p++)
14731 + au_hfput(p, /*execed*/0);
14732 + bbot = au_sbbot(sb);
14735 + p = fidir->fd_hfile + bbot;
14736 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14737 + fidir->fd_bbot--, p--)
14738 + if (p->hf_file) {
14739 + if (file_inode(p->hf_file))
14741 + au_hfput(p, /*execed*/0);
14743 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14747 + * after branch manipulating, refresh the file.
14749 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14751 + int err, need_reopen, nbr;
14752 + aufs_bindex_t bbot, bindex;
14753 + struct dentry *dentry;
14754 + struct super_block *sb;
14755 + struct au_finfo *finfo;
14756 + struct au_hfile *hfile;
14758 + dentry = file->f_path.dentry;
14759 + sb = dentry->d_sb;
14760 + nbr = au_sbbot(sb) + 1;
14761 + finfo = au_fi(file);
14762 + if (!finfo->fi_hdir) {
14763 + hfile = &finfo->fi_htop;
14764 + AuDebugOn(!hfile->hf_file);
14765 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14766 + AuDebugOn(bindex < 0);
14767 + if (bindex != finfo->fi_btop)
14768 + au_set_fbtop(file, bindex);
14770 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14771 + if (unlikely(err))
14773 + au_do_refresh_dir(file);
14778 + if (!au_test_mmapped(file))
14779 + err = au_file_refresh_by_inode(file, &need_reopen);
14780 + if (finfo->fi_hdir)
14781 + /* harmless if err */
14782 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14783 + if (!err && need_reopen && !d_unlinked(dentry))
14784 + err = reopen(file);
14786 + au_update_figen(file);
14787 + goto out; /* success */
14790 + /* error, close all lower files */
14791 + if (finfo->fi_hdir) {
14792 + bbot = au_fbbot_dir(file);
14793 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14794 + au_set_h_fptr(file, bindex, NULL);
14801 +/* common function to regular file and dir */
14802 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14803 + int wlock, unsigned int fi_lsc)
14806 + unsigned int sigen, figen;
14807 + aufs_bindex_t btop;
14808 + unsigned char pseudo_link;
14809 + struct dentry *dentry;
14810 + struct inode *inode;
14813 + dentry = file->f_path.dentry;
14814 + inode = d_inode(dentry);
14815 + sigen = au_sigen(dentry->d_sb);
14816 + fi_write_lock_nested(file, fi_lsc);
14817 + figen = au_figen(file);
14819 + di_write_lock_child(dentry);
14821 + di_write_lock_child2(dentry);
14822 + btop = au_dbtop(dentry);
14823 + pseudo_link = (btop != au_ibtop(inode));
14824 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14826 + di_downgrade_lock(dentry, AuLock_IR);
14827 + fi_downgrade_lock(file);
14829 + goto out; /* success */
14832 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14833 + if (au_digen_test(dentry, sigen)) {
14834 + err = au_reval_dpath(dentry, sigen);
14835 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14839 + err = refresh_file(file, reopen);
14842 + di_downgrade_lock(dentry, AuLock_IR);
14843 + fi_downgrade_lock(file);
14846 + di_write_unlock(dentry);
14847 + fi_write_unlock(file);
14854 +/* ---------------------------------------------------------------------- */
14856 +/* cf. aufs_nopage() */
14857 +/* for madvise(2) */
14858 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14860 + unlock_page(page);
14864 +/* it will never be called, but necessary to support O_DIRECT */
14865 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14866 +{ BUG(); return 0; }
14868 +/* they will never be called. */
14869 +#ifdef CONFIG_AUFS_DEBUG
14870 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14871 + loff_t pos, unsigned len, unsigned flags,
14872 + struct page **pagep, void **fsdata)
14873 +{ AuUnsupport(); return 0; }
14874 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14875 + loff_t pos, unsigned len, unsigned copied,
14876 + struct page *page, void *fsdata)
14877 +{ AuUnsupport(); return 0; }
14878 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14879 +{ AuUnsupport(); return 0; }
14881 +static int aufs_set_page_dirty(struct page *page)
14882 +{ AuUnsupport(); return 0; }
14883 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14884 + unsigned int length)
14885 +{ AuUnsupport(); }
14886 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14887 +{ AuUnsupport(); return 0; }
14888 +#if 0 /* called by memory compaction regardless file */
14889 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14890 + struct page *page, enum migrate_mode mode)
14891 +{ AuUnsupport(); return 0; }
14893 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14894 +{ AuUnsupport(); return true; }
14895 +static void aufs_putback_page(struct page *page)
14896 +{ AuUnsupport(); }
14897 +static int aufs_launder_page(struct page *page)
14898 +{ AuUnsupport(); return 0; }
14899 +static int aufs_is_partially_uptodate(struct page *page,
14900 + unsigned long from,
14901 + unsigned long count)
14902 +{ AuUnsupport(); return 0; }
14903 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14905 +{ AuUnsupport(); }
14906 +static int aufs_error_remove_page(struct address_space *mapping,
14907 + struct page *page)
14908 +{ AuUnsupport(); return 0; }
14909 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14911 +{ AuUnsupport(); return 0; }
14912 +static void aufs_swap_deactivate(struct file *file)
14913 +{ AuUnsupport(); }
14914 +#endif /* CONFIG_AUFS_DEBUG */
14916 +const struct address_space_operations aufs_aop = {
14917 + .readpage = aufs_readpage,
14918 + .direct_IO = aufs_direct_IO,
14919 +#ifdef CONFIG_AUFS_DEBUG
14920 + .writepage = aufs_writepage,
14921 + /* no writepages, because of writepage */
14922 + .set_page_dirty = aufs_set_page_dirty,
14923 + /* no readpages, because of readpage */
14924 + .write_begin = aufs_write_begin,
14925 + .write_end = aufs_write_end,
14926 + /* no bmap, no block device */
14927 + .invalidatepage = aufs_invalidatepage,
14928 + .releasepage = aufs_releasepage,
14929 + /* is fallback_migrate_page ok? */
14930 + /* .migratepage = aufs_migratepage, */
14931 + .isolate_page = aufs_isolate_page,
14932 + .putback_page = aufs_putback_page,
14933 + .launder_page = aufs_launder_page,
14934 + .is_partially_uptodate = aufs_is_partially_uptodate,
14935 + .is_dirty_writeback = aufs_is_dirty_writeback,
14936 + .error_remove_page = aufs_error_remove_page,
14937 + .swap_activate = aufs_swap_activate,
14938 + .swap_deactivate = aufs_swap_deactivate
14939 +#endif /* CONFIG_AUFS_DEBUG */
14941 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14942 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14943 +++ linux/fs/aufs/file.h 2021-09-06 21:02:45.276825587 +0200
14945 +/* SPDX-License-Identifier: GPL-2.0 */
14947 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14949 + * This program, aufs is free software; you can redistribute it and/or modify
14950 + * it under the terms of the GNU General Public License as published by
14951 + * the Free Software Foundation; either version 2 of the License, or
14952 + * (at your option) any later version.
14954 + * This program is distributed in the hope that it will be useful,
14955 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14956 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14957 + * GNU General Public License for more details.
14959 + * You should have received a copy of the GNU General Public License
14960 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14964 + * file operations
14967 +#ifndef __AUFS_FILE_H__
14968 +#define __AUFS_FILE_H__
14972 +#include <linux/file.h>
14973 +#include <linux/fs.h>
14974 +#include <linux/mm_types.h>
14975 +#include <linux/poll.h>
14976 +#include "rwsem.h"
14980 + struct file *hf_file;
14981 + struct au_branch *hf_br;
14986 + aufs_bindex_t fd_bbot;
14987 + aufs_bindex_t fd_nent;
14988 + struct au_vdir *fd_vdir_cache;
14989 + struct au_hfile fd_hfile[];
14992 +static inline int au_fidir_sz(int nent)
14994 + AuDebugOn(nent < 0);
14995 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14999 + atomic_t fi_generation;
15001 + struct au_rwsem fi_rwsem;
15002 + aufs_bindex_t fi_btop;
15004 + /* do not union them */
15005 + struct { /* for non-dir */
15006 + struct au_hfile fi_htop;
15007 + atomic_t fi_mmapped;
15009 + struct au_fidir *fi_hdir; /* for dir only */
15011 + struct hlist_bl_node fi_hlist;
15012 + struct file *fi_file; /* very ugly */
15013 + struct rcu_head rcu;
15014 +} ____cacheline_aligned_in_smp;
15016 +/* ---------------------------------------------------------------------- */
15019 +extern const struct address_space_operations aufs_aop;
15020 +unsigned int au_file_roflags(unsigned int flags);
15021 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15022 + struct file *file, int force_wr);
15023 +struct au_do_open_args {
15025 + int (*open)(struct file *file, int flags,
15026 + struct file *h_file);
15027 + struct au_fidir *fidir;
15028 + struct file *h_file;
15030 +int au_do_open(struct file *file, struct au_do_open_args *args);
15031 +int au_reopen_nondir(struct file *file);
15033 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15034 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15035 + int wlock, unsigned int fi_lsc);
15036 +int au_do_flush(struct file *file, fl_owner_t id,
15037 + int (*flush)(struct file *file, fl_owner_t id));
15040 +#ifdef CONFIG_AUFS_POLL
15041 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15044 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15046 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15048 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15049 + struct file *h_file);
15051 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15052 + aufs_bindex_t bindex, int force_wr)
15053 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15054 + struct file *h_file);
15058 +extern const struct file_operations aufs_file_fop;
15059 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15060 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15061 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15064 +void au_hfput(struct au_hfile *hf, int execed);
15065 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15066 + struct file *h_file);
15068 +void au_update_figen(struct file *file);
15069 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15070 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15072 +void au_fi_init_once(void *_fi);
15073 +void au_finfo_fin(struct file *file);
15074 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15077 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15078 +#ifdef CONFIG_COMPAT
15079 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15080 + unsigned long arg);
15081 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15082 + unsigned long arg);
15085 +/* ---------------------------------------------------------------------- */
15087 +static inline struct au_finfo *au_fi(struct file *file)
15089 + return file->private_data;
15092 +/* ---------------------------------------------------------------------- */
15094 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15095 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15096 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15097 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15099 +#define fi_read_trylock_nested(f) \
15100 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15101 +#define fi_write_trylock_nested(f) \
15102 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15105 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15106 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15107 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15109 +/* lock subclass for finfo */
15115 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15117 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15120 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15122 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15126 + * fi_read_lock_1, fi_write_lock_1,
15127 + * fi_read_lock_2, fi_write_lock_2
15129 +#define AuReadLockFunc(name) \
15130 +static inline void fi_read_lock_##name(struct file *f) \
15131 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15133 +#define AuWriteLockFunc(name) \
15134 +static inline void fi_write_lock_##name(struct file *f) \
15135 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15137 +#define AuRWLockFuncs(name) \
15138 + AuReadLockFunc(name) \
15139 + AuWriteLockFunc(name)
15144 +#undef AuReadLockFunc
15145 +#undef AuWriteLockFunc
15146 +#undef AuRWLockFuncs
15148 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15149 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15150 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15152 +/* ---------------------------------------------------------------------- */
15154 +/* todo: hard/soft set? */
15155 +static inline aufs_bindex_t au_fbtop(struct file *file)
15157 + FiMustAnyLock(file);
15158 + return au_fi(file)->fi_btop;
15161 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15163 + FiMustAnyLock(file);
15164 + AuDebugOn(!au_fi(file)->fi_hdir);
15165 + return au_fi(file)->fi_hdir->fd_bbot;
15168 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15170 + FiMustAnyLock(file);
15171 + AuDebugOn(!au_fi(file)->fi_hdir);
15172 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15175 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15177 + FiMustWriteLock(file);
15178 + au_fi(file)->fi_btop = bindex;
15181 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15183 + FiMustWriteLock(file);
15184 + AuDebugOn(!au_fi(file)->fi_hdir);
15185 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15188 +static inline void au_set_fvdir_cache(struct file *file,
15189 + struct au_vdir *vdir_cache)
15191 + FiMustWriteLock(file);
15192 + AuDebugOn(!au_fi(file)->fi_hdir);
15193 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15196 +static inline struct file *au_hf_top(struct file *file)
15198 + FiMustAnyLock(file);
15199 + AuDebugOn(au_fi(file)->fi_hdir);
15200 + return au_fi(file)->fi_htop.hf_file;
15203 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15205 + FiMustAnyLock(file);
15206 + AuDebugOn(!au_fi(file)->fi_hdir);
15207 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15210 +/* todo: memory barrier? */
15211 +static inline unsigned int au_figen(struct file *f)
15213 + return atomic_read(&au_fi(f)->fi_generation);
15216 +static inline void au_set_mmapped(struct file *f)
15218 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15220 + pr_warn("fi_mmapped wrapped around\n");
15221 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15225 +static inline void au_unset_mmapped(struct file *f)
15227 + atomic_dec(&au_fi(f)->fi_mmapped);
15230 +static inline int au_test_mmapped(struct file *f)
15232 + return atomic_read(&au_fi(f)->fi_mmapped);
15235 +/* customize vma->vm_file */
15237 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15238 + struct file *file)
15242 + f = vma->vm_file;
15244 + vma->vm_file = file;
15249 +#define AuDbgVmRegion(file, vma) do {} while (0)
15251 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15252 + struct file *file)
15254 + au_do_vm_file_reset(vma, file);
15257 +#define AuDbgVmRegion(file, vma) \
15258 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15260 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15261 + struct file *file)
15265 + au_do_vm_file_reset(vma, file);
15266 + f = vma->vm_region->vm_file;
15268 + vma->vm_region->vm_file = file;
15271 +#endif /* CONFIG_MMU */
15273 +/* handle vma->vm_prfile */
15274 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15275 + struct file *file)
15278 + vma->vm_prfile = file;
15279 +#ifndef CONFIG_MMU
15281 + vma->vm_region->vm_prfile = file;
15285 +#endif /* __KERNEL__ */
15286 +#endif /* __AUFS_FILE_H__ */
15287 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15288 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15289 +++ linux/fs/aufs/finfo.c 2021-09-06 21:02:45.276825587 +0200
15291 +// SPDX-License-Identifier: GPL-2.0
15293 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15295 + * This program, aufs is free software; you can redistribute it and/or modify
15296 + * it under the terms of the GNU General Public License as published by
15297 + * the Free Software Foundation; either version 2 of the License, or
15298 + * (at your option) any later version.
15300 + * This program is distributed in the hope that it will be useful,
15301 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15302 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15303 + * GNU General Public License for more details.
15305 + * You should have received a copy of the GNU General Public License
15306 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15310 + * file private data
15315 +void au_hfput(struct au_hfile *hf, int execed)
15318 + allow_write_access(hf->hf_file);
15319 + fput(hf->hf_file);
15320 + hf->hf_file = NULL;
15321 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15322 + hf->hf_br = NULL;
15325 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15327 + struct au_finfo *finfo = au_fi(file);
15328 + struct au_hfile *hf;
15329 + struct au_fidir *fidir;
15331 + fidir = finfo->fi_hdir;
15333 + AuDebugOn(finfo->fi_btop != bindex);
15334 + hf = &finfo->fi_htop;
15336 + hf = fidir->fd_hfile + bindex;
15338 + if (hf && hf->hf_file)
15339 + au_hfput(hf, vfsub_file_execed(file));
15341 + FiMustWriteLock(file);
15342 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15343 + hf->hf_file = val;
15344 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15348 +void au_update_figen(struct file *file)
15350 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15351 + /* smp_mb(); */ /* atomic_set */
15354 +/* ---------------------------------------------------------------------- */
15356 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15358 + struct au_fidir *fidir;
15361 + nbr = au_sbbot(sb) + 1;
15363 + nbr = 2; /* initial allocate for 2 branches */
15364 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15366 + fidir->fd_bbot = -1;
15367 + fidir->fd_nent = nbr;
15373 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15376 + struct au_fidir *fidir, *p;
15378 + AuRwMustWriteLock(&finfo->fi_rwsem);
15379 + fidir = finfo->fi_hdir;
15380 + AuDebugOn(!fidir);
15383 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15384 + GFP_NOFS, may_shrink);
15386 + p->fd_nent = nbr;
15387 + finfo->fi_hdir = p;
15394 +/* ---------------------------------------------------------------------- */
15396 +void au_finfo_fin(struct file *file)
15398 + struct au_finfo *finfo;
15400 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15402 + finfo = au_fi(file);
15403 + AuDebugOn(finfo->fi_hdir);
15404 + AuRwDestroy(&finfo->fi_rwsem);
15405 + au_cache_free_finfo(finfo);
15408 +void au_fi_init_once(void *_finfo)
15410 + struct au_finfo *finfo = _finfo;
15412 + au_rw_init(&finfo->fi_rwsem);
15415 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15418 + struct au_finfo *finfo;
15419 + struct dentry *dentry;
15422 + dentry = file->f_path.dentry;
15423 + finfo = au_cache_alloc_finfo();
15424 + if (unlikely(!finfo))
15428 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15429 + au_rw_write_lock(&finfo->fi_rwsem);
15430 + finfo->fi_btop = -1;
15431 + finfo->fi_hdir = fidir;
15432 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15433 + /* smp_mb(); */ /* atomic_set */
15435 + file->private_data = finfo;
15440 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15441 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15442 +++ linux/fs/aufs/f_op.c 2021-09-06 21:02:45.276825587 +0200
15444 +// SPDX-License-Identifier: GPL-2.0
15446 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15448 + * This program, aufs is free software; you can redistribute it and/or modify
15449 + * it under the terms of the GNU General Public License as published by
15450 + * the Free Software Foundation; either version 2 of the License, or
15451 + * (at your option) any later version.
15453 + * This program is distributed in the hope that it will be useful,
15454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15456 + * GNU General Public License for more details.
15458 + * You should have received a copy of the GNU General Public License
15459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15463 + * file and vm operations
15466 +#include <linux/aio.h>
15467 +#include <linux/fs_stack.h>
15468 +#include <linux/mman.h>
15469 +#include <linux/security.h>
15472 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15475 + aufs_bindex_t bindex;
15476 + struct dentry *dentry, *h_dentry;
15477 + struct au_finfo *finfo;
15478 + struct inode *h_inode;
15480 + FiMustWriteLock(file);
15483 + dentry = file->f_path.dentry;
15484 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15485 + finfo = au_fi(file);
15486 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15487 + atomic_set(&finfo->fi_mmapped, 0);
15488 + bindex = au_dbtop(dentry);
15490 + h_dentry = au_h_dptr(dentry, bindex);
15491 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15492 + if (unlikely(err))
15494 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15495 + if (IS_ERR(h_file)) {
15496 + err = PTR_ERR(h_file);
15500 + h_dentry = h_file->f_path.dentry;
15501 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15502 + if (unlikely(err))
15504 + /* br ref is already inc-ed */
15507 + if ((flags & __O_TMPFILE)
15508 + && !(flags & O_EXCL)) {
15509 + h_inode = file_inode(h_file);
15510 + spin_lock(&h_inode->i_lock);
15511 + h_inode->i_state |= I_LINKABLE;
15512 + spin_unlock(&h_inode->i_lock);
15514 + au_set_fbtop(file, bindex);
15515 + au_set_h_fptr(file, bindex, h_file);
15516 + au_update_figen(file);
15517 + /* todo: necessary? */
15518 + /* file->f_ra = h_file->f_ra; */
15524 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15525 + struct file *file)
15528 + struct super_block *sb;
15529 + struct au_do_open_args args = {
15530 + .open = au_do_open_nondir
15533 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15534 + file, vfsub_file_flags(file), file->f_mode);
15536 + sb = file->f_path.dentry->d_sb;
15537 + si_read_lock(sb, AuLock_FLUSH);
15538 + err = au_do_open(file, &args);
15539 + si_read_unlock(sb);
15543 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15545 + struct au_finfo *finfo;
15546 + aufs_bindex_t bindex;
15548 + finfo = au_fi(file);
15549 + au_hbl_del(&finfo->fi_hlist,
15550 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15551 + bindex = finfo->fi_btop;
15553 + au_set_h_fptr(file, bindex, NULL);
15555 + au_finfo_fin(file);
15559 +/* ---------------------------------------------------------------------- */
15561 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15564 + struct file *h_file;
15567 + h_file = au_hf_top(file);
15569 + err = vfsub_flush(h_file, id);
15573 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15575 + return au_do_flush(file, id, au_do_flush_nondir);
15578 +/* ---------------------------------------------------------------------- */
15580 + * read and write functions acquire [fdi]_rwsem once, but release before
15581 + * mmap_sem. This is because to stop a race condition between mmap(2).
15582 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15583 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15584 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15587 +/* Callers should call au_read_post() or fput() in the end */
15588 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15590 + struct file *h_file;
15593 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15595 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15596 + h_file = au_hf_top(file);
15597 + get_file(h_file);
15599 + fi_read_unlock(file);
15601 + h_file = ERR_PTR(err);
15606 +static void au_read_post(struct inode *inode, struct file *h_file)
15608 + /* update without lock, I don't think it a problem */
15609 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15613 +struct au_write_pre {
15615 + unsigned int lsc;
15619 + aufs_bindex_t btop;
15623 + * return with iinfo is write-locked
15624 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15627 +static struct file *au_write_pre(struct file *file, int do_ready,
15628 + struct au_write_pre *wpre)
15630 + struct file *h_file;
15631 + struct dentry *dentry;
15633 + unsigned int lsc;
15634 + struct au_pin pin;
15639 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15640 + h_file = ERR_PTR(err);
15641 + if (unlikely(err))
15644 + dentry = file->f_path.dentry;
15646 + err = au_ready_to_write(file, -1, &pin);
15647 + if (unlikely(err)) {
15648 + h_file = ERR_PTR(err);
15649 + di_write_unlock(dentry);
15654 + di_downgrade_lock(dentry, /*flags*/0);
15656 + wpre->btop = au_fbtop(file);
15657 + h_file = au_hf_top(file);
15658 + get_file(h_file);
15660 + wpre->blks = file_inode(h_file)->i_blocks;
15663 + di_read_unlock(dentry, /*flags*/0);
15666 + fi_write_unlock(file);
15671 +static void au_write_post(struct inode *inode, struct file *h_file,
15672 + struct au_write_pre *wpre, ssize_t written)
15674 + struct inode *h_inode;
15676 + au_cpup_attr_timesizes(inode);
15677 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15678 + h_inode = file_inode(h_file);
15679 + inode->i_mode = h_inode->i_mode;
15680 + ii_write_unlock(inode);
15681 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15683 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15684 + /*force*/h_inode->i_blocks > wpre->blks);
15689 + * todo: very ugly
15690 + * it locks both of i_mutex and si_rwsem for read in safe.
15691 + * if the plink maintenance mode continues forever (that is the problem),
15692 + * may loop forever.
15694 +static void au_mtx_and_read_lock(struct inode *inode)
15697 + struct super_block *sb = inode->i_sb;
15700 + inode_lock(inode);
15701 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15704 + inode_unlock(inode);
15705 + si_read_lock(sb, AuLock_NOPLMW);
15706 + si_read_unlock(sb);
15710 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15711 + struct iov_iter *iov_iter)
15714 + struct file *file;
15715 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15717 + err = security_file_permission(h_file, rw);
15718 + if (unlikely(err))
15721 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15723 + if (rw == MAY_READ)
15724 + iter = h_file->f_op->read_iter;
15725 + else if (rw == MAY_WRITE)
15726 + iter = h_file->f_op->write_iter;
15728 + file = kio->ki_filp;
15729 + kio->ki_filp = h_file;
15732 + err = iter(kio, iov_iter);
15735 + /* currently there is no such fs */
15737 + kio->ki_filp = file;
15743 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15746 + struct file *file, *h_file;
15747 + struct inode *inode;
15748 + struct super_block *sb;
15750 + file = kio->ki_filp;
15751 + inode = file_inode(file);
15752 + sb = inode->i_sb;
15753 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15755 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15756 + err = PTR_ERR(h_file);
15757 + if (IS_ERR(h_file))
15760 + if (au_test_loopback_kthread()) {
15761 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15762 + if (file->f_mapping != h_file->f_mapping) {
15763 + file->f_mapping = h_file->f_mapping;
15764 + smp_mb(); /* unnecessary? */
15767 + fi_read_unlock(file);
15769 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15770 + /* todo: necessary? */
15771 + /* file->f_ra = h_file->f_ra; */
15772 + au_read_post(inode, h_file);
15775 + si_read_unlock(sb);
15779 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15782 + struct au_write_pre wpre;
15783 + struct inode *inode;
15784 + struct file *file, *h_file;
15786 + file = kio->ki_filp;
15787 + inode = file_inode(file);
15788 + au_mtx_and_read_lock(inode);
15791 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15792 + err = PTR_ERR(h_file);
15793 + if (IS_ERR(h_file))
15796 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15797 + au_write_post(inode, h_file, &wpre, err);
15800 + si_read_unlock(inode->i_sb);
15801 + inode_unlock(inode);
15806 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15807 + * don't have their own .splice_{read,write} implimentations, and they use
15808 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15809 + * simple converters to f_op->iter_read() and ->iter_write().
15810 + * But we keep our own implementations because some non-mainlined FSes may have
15811 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15812 + * away an opportunity to co-work with aufs from them.
15814 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15815 + struct pipe_inode_info *pipe, size_t len,
15816 + unsigned int flags)
15819 + struct file *h_file;
15820 + struct inode *inode;
15821 + struct super_block *sb;
15823 + inode = file_inode(file);
15824 + sb = inode->i_sb;
15825 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15827 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15828 + err = PTR_ERR(h_file);
15829 + if (IS_ERR(h_file))
15832 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15833 + /* todo: necessary? */
15834 + /* file->f_ra = h_file->f_ra; */
15835 + au_read_post(inode, h_file);
15838 + si_read_unlock(sb);
15843 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15844 + size_t len, unsigned int flags)
15847 + struct au_write_pre wpre;
15848 + struct inode *inode;
15849 + struct file *h_file;
15851 + inode = file_inode(file);
15852 + au_mtx_and_read_lock(inode);
15855 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15856 + err = PTR_ERR(h_file);
15857 + if (IS_ERR(h_file))
15860 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15861 + au_write_post(inode, h_file, &wpre, err);
15864 + si_read_unlock(inode->i_sb);
15865 + inode_unlock(inode);
15869 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15873 + struct au_write_pre wpre;
15874 + struct inode *inode;
15875 + struct file *h_file;
15877 + inode = file_inode(file);
15878 + au_mtx_and_read_lock(inode);
15881 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15882 + err = PTR_ERR(h_file);
15883 + if (IS_ERR(h_file))
15887 + err = vfs_fallocate(h_file, mode, offset, len);
15889 + au_write_post(inode, h_file, &wpre, /*written*/1);
15892 + si_read_unlock(inode->i_sb);
15893 + inode_unlock(inode);
15897 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15898 + struct file *dst, loff_t dst_pos,
15899 + size_t len, unsigned int flags)
15902 + struct au_write_pre wpre;
15903 + enum { SRC, DST };
15905 + struct inode *inode;
15906 + struct file *h_file;
15907 + struct super_block *h_sb;
15909 +#define a_src a[SRC]
15910 +#define a_dst a[DST]
15913 + a_src.inode = file_inode(src);
15914 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15916 + a_dst.inode = file_inode(dst);
15917 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15920 + au_mtx_and_read_lock(a_dst.inode);
15922 + * in order to match the order in di_write_lock2_{child,parent}(),
15923 + * use f_path.dentry for this comparison.
15925 + if (src->f_path.dentry < dst->f_path.dentry) {
15926 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15927 + err = PTR_ERR(a_src.h_file);
15928 + if (IS_ERR(a_src.h_file))
15931 + wpre.lsc = AuLsc_FI_2;
15932 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15933 + err = PTR_ERR(a_dst.h_file);
15934 + if (IS_ERR(a_dst.h_file)) {
15935 + au_read_post(a_src.inode, a_src.h_file);
15939 + wpre.lsc = AuLsc_FI_1;
15940 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15941 + err = PTR_ERR(a_dst.h_file);
15942 + if (IS_ERR(a_dst.h_file))
15945 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15946 + err = PTR_ERR(a_src.h_file);
15947 + if (IS_ERR(a_src.h_file)) {
15948 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15955 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15956 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15957 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15963 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15964 + dst_pos, len, flags);
15967 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15968 + fi_read_unlock(src);
15969 + au_read_post(a_src.inode, a_src.h_file);
15971 + si_read_unlock(a_dst.inode->i_sb);
15972 + inode_unlock(a_dst.inode);
15979 +/* ---------------------------------------------------------------------- */
15982 + * The locking order around current->mmap_sem.
15983 + * - in most and regular cases
15984 + * file I/O syscall -- aufs_read() or something
15985 + * -- si_rwsem for read -- mmap_sem
15986 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15988 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15989 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15990 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15991 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15992 + * It means that when aufs acquires si_rwsem for write, the process should never
15993 + * acquire mmap_sem.
15995 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15996 + * problem either since any directory is not able to be mmap-ed.
15997 + * The similar scenario is applied to aufs_readlink() too.
16000 +#if 0 /* stop calling security_file_mmap() */
16001 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16002 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16004 +static unsigned long au_arch_prot_conv(unsigned long flags)
16006 + /* currently ppc64 only */
16007 +#ifdef CONFIG_PPC64
16008 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16009 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16010 + return AuConv_VM_PROT(flags, SAO);
16012 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16017 +static unsigned long au_prot_conv(unsigned long flags)
16019 + return AuConv_VM_PROT(flags, READ)
16020 + | AuConv_VM_PROT(flags, WRITE)
16021 + | AuConv_VM_PROT(flags, EXEC)
16022 + | au_arch_prot_conv(flags);
16025 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16026 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16028 +static unsigned long au_flag_conv(unsigned long flags)
16030 + return AuConv_VM_MAP(flags, GROWSDOWN)
16031 + | AuConv_VM_MAP(flags, DENYWRITE)
16032 + | AuConv_VM_MAP(flags, LOCKED);
16036 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16039 + const unsigned char wlock
16040 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16041 + struct super_block *sb;
16042 + struct file *h_file;
16043 + struct inode *inode;
16045 + AuDbgVmRegion(file, vma);
16047 + inode = file_inode(file);
16048 + sb = inode->i_sb;
16050 + si_read_lock(sb, AuLock_NOPLMW);
16052 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16054 + err = PTR_ERR(h_file);
16055 + if (IS_ERR(h_file))
16059 + au_set_mmapped(file);
16060 + au_vm_file_reset(vma, h_file);
16062 + * we cannot call security_mmap_file() here since it may acquire
16063 + * mmap_sem or i_mutex.
16065 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16066 + * au_flag_conv(vma->vm_flags));
16069 + err = call_mmap(h_file, vma);
16071 + au_vm_prfile_set(vma, file);
16072 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16073 + goto out_fput; /* success */
16075 + au_unset_mmapped(file);
16076 + au_vm_file_reset(vma, file);
16080 + ii_write_unlock(inode);
16085 + si_read_unlock(sb);
16091 +/* ---------------------------------------------------------------------- */
16093 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16097 + struct au_write_pre wpre;
16098 + struct inode *inode;
16099 + struct file *h_file;
16101 + err = 0; /* -EBADF; */ /* posix? */
16102 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16105 + inode = file_inode(file);
16106 + au_mtx_and_read_lock(inode);
16109 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16110 + err = PTR_ERR(h_file);
16111 + if (IS_ERR(h_file))
16114 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16115 + au_write_post(inode, h_file, &wpre, /*written*/0);
16118 + si_read_unlock(inode->i_sb);
16119 + inode_unlock(inode);
16124 +static int aufs_fasync(int fd, struct file *file, int flag)
16127 + struct file *h_file;
16128 + struct super_block *sb;
16130 + sb = file->f_path.dentry->d_sb;
16131 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16133 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16134 + err = PTR_ERR(h_file);
16135 + if (IS_ERR(h_file))
16138 + if (h_file->f_op->fasync)
16139 + err = h_file->f_op->fasync(fd, h_file, flag);
16140 + fput(h_file); /* instead of au_read_post() */
16143 + si_read_unlock(sb);
16147 +static int aufs_setfl(struct file *file, unsigned long arg)
16150 + struct file *h_file;
16151 + struct super_block *sb;
16153 + sb = file->f_path.dentry->d_sb;
16154 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16156 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16157 + err = PTR_ERR(h_file);
16158 + if (IS_ERR(h_file))
16161 + /* stop calling h_file->fasync */
16162 + arg |= vfsub_file_flags(file) & FASYNC;
16163 + err = setfl(/*unused fd*/-1, h_file, arg);
16164 + fput(h_file); /* instead of au_read_post() */
16167 + si_read_unlock(sb);
16171 +/* ---------------------------------------------------------------------- */
16173 +/* no one supports this operation, currently */
16174 +#if 0 /* reserved for future use */
16175 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16176 + size_t len, loff_t *pos, int more)
16181 +/* ---------------------------------------------------------------------- */
16183 +const struct file_operations aufs_file_fop = {
16184 + .owner = THIS_MODULE,
16186 + .llseek = default_llseek,
16188 + .read_iter = aufs_read_iter,
16189 + .write_iter = aufs_write_iter,
16191 +#ifdef CONFIG_AUFS_POLL
16192 + .poll = aufs_poll,
16194 + .unlocked_ioctl = aufs_ioctl_nondir,
16195 +#ifdef CONFIG_COMPAT
16196 + .compat_ioctl = aufs_compat_ioctl_nondir,
16198 + .mmap = aufs_mmap,
16199 + .open = aufs_open_nondir,
16200 + .flush = aufs_flush_nondir,
16201 + .release = aufs_release_nondir,
16202 + .fsync = aufs_fsync_nondir,
16203 + .fasync = aufs_fasync,
16204 + /* .sendpage = aufs_sendpage, */
16205 + .setfl = aufs_setfl,
16206 + .splice_write = aufs_splice_write,
16207 + .splice_read = aufs_splice_read,
16208 +#if 0 /* reserved for future use */
16209 + .aio_splice_write = aufs_aio_splice_write,
16210 + .aio_splice_read = aufs_aio_splice_read,
16212 + .fallocate = aufs_fallocate,
16213 + .copy_file_range = aufs_copy_file_range
16215 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16216 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16217 +++ linux/fs/aufs/fstype.h 2021-09-06 21:02:45.276825587 +0200
16219 +/* SPDX-License-Identifier: GPL-2.0 */
16221 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16223 + * This program, aufs is free software; you can redistribute it and/or modify
16224 + * it under the terms of the GNU General Public License as published by
16225 + * the Free Software Foundation; either version 2 of the License, or
16226 + * (at your option) any later version.
16228 + * This program is distributed in the hope that it will be useful,
16229 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16230 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16231 + * GNU General Public License for more details.
16233 + * You should have received a copy of the GNU General Public License
16234 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16238 + * judging filesystem type
16241 +#ifndef __AUFS_FSTYPE_H__
16242 +#define __AUFS_FSTYPE_H__
16246 +#include <linux/fs.h>
16247 +#include <linux/magic.h>
16248 +#include <linux/nfs_fs.h>
16249 +#include <linux/romfs_fs.h>
16251 +static inline int au_test_aufs(struct super_block *sb)
16253 + return sb->s_magic == AUFS_SUPER_MAGIC;
16256 +static inline const char *au_sbtype(struct super_block *sb)
16258 + return sb->s_type->name;
16261 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16263 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16264 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16270 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16272 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16273 + return sb->s_magic == ROMFS_MAGIC;
16279 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16281 +#if IS_ENABLED(CONFIG_CRAMFS)
16282 + return sb->s_magic == CRAMFS_MAGIC;
16287 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16289 +#if IS_ENABLED(CONFIG_NFS_FS)
16290 + return sb->s_magic == NFS_SUPER_MAGIC;
16296 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16298 +#if IS_ENABLED(CONFIG_FUSE_FS)
16299 + return sb->s_magic == FUSE_SUPER_MAGIC;
16305 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16307 +#if IS_ENABLED(CONFIG_XFS_FS)
16308 + return sb->s_magic == XFS_SB_MAGIC;
16314 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16316 +#ifdef CONFIG_TMPFS
16317 + return sb->s_magic == TMPFS_MAGIC;
16323 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16325 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16326 + return !strcmp(au_sbtype(sb), "ecryptfs");
16332 +static inline int au_test_ramfs(struct super_block *sb)
16334 + return sb->s_magic == RAMFS_MAGIC;
16337 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16339 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16340 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16346 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16348 +#ifdef CONFIG_PROC_FS
16349 + return sb->s_magic == PROC_SUPER_MAGIC;
16355 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16357 +#ifdef CONFIG_SYSFS
16358 + return sb->s_magic == SYSFS_MAGIC;
16364 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16366 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16367 + return sb->s_magic == CONFIGFS_MAGIC;
16373 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16375 +#if IS_ENABLED(CONFIG_MINIX_FS)
16376 + return sb->s_magic == MINIX3_SUPER_MAGIC
16377 + || sb->s_magic == MINIX2_SUPER_MAGIC
16378 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16379 + || sb->s_magic == MINIX_SUPER_MAGIC
16380 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16386 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16388 +#if IS_ENABLED(CONFIG_FAT_FS)
16389 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16395 +static inline int au_test_msdos(struct super_block *sb)
16397 + return au_test_fat(sb);
16400 +static inline int au_test_vfat(struct super_block *sb)
16402 + return au_test_fat(sb);
16405 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16407 +#ifdef CONFIG_SECURITYFS
16408 + return sb->s_magic == SECURITYFS_MAGIC;
16414 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16416 +#if IS_ENABLED(CONFIG_SQUASHFS)
16417 + return sb->s_magic == SQUASHFS_MAGIC;
16423 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16425 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16426 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16432 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16434 +#if IS_ENABLED(CONFIG_XENFS)
16435 + return sb->s_magic == XENFS_SUPER_MAGIC;
16441 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16443 +#ifdef CONFIG_DEBUG_FS
16444 + return sb->s_magic == DEBUGFS_MAGIC;
16450 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16452 +#if IS_ENABLED(CONFIG_NILFS)
16453 + return sb->s_magic == NILFS_SUPER_MAGIC;
16459 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16461 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16462 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16468 +/* ---------------------------------------------------------------------- */
16470 + * they can't be an aufs branch.
16472 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16475 +#ifndef CONFIG_AUFS_BR_RAMFS
16476 + au_test_ramfs(sb) ||
16478 + au_test_procfs(sb)
16479 + || au_test_sysfs(sb)
16480 + || au_test_configfs(sb)
16481 + || au_test_debugfs(sb)
16482 + || au_test_securityfs(sb)
16483 + || au_test_xenfs(sb)
16484 + || au_test_ecryptfs(sb)
16485 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16486 + || au_test_aufs(sb); /* will be supported in next version */
16489 +static inline int au_test_fs_remote(struct super_block *sb)
16491 + return !au_test_tmpfs(sb)
16492 +#ifdef CONFIG_AUFS_BR_RAMFS
16493 + && !au_test_ramfs(sb)
16495 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16498 +/* ---------------------------------------------------------------------- */
16501 + * Note: these functions (below) are created after reading ->getattr() in all
16502 + * filesystems under linux/fs. it means we have to do so in every update...
16506 + * some filesystems require getattr to refresh the inode attributes before
16508 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16509 + * and leave the work for d_revalidate()
16511 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16513 + return au_test_nfs(sb)
16514 + || au_test_fuse(sb)
16515 + /* || au_test_btrfs(sb) */ /* untested */
16520 + * filesystems which don't maintain i_size or i_blocks.
16522 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16524 + return au_test_xfs(sb)
16525 + || au_test_btrfs(sb)
16526 + || au_test_ubifs(sb)
16527 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16528 + /* || au_test_minix(sb) */ /* untested */
16533 + * filesystems which don't store the correct value in some of their inode
16536 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16538 + return au_test_fs_bad_iattr_size(sb)
16539 + || au_test_fat(sb)
16540 + || au_test_msdos(sb)
16541 + || au_test_vfat(sb);
16544 +/* they don't check i_nlink in link(2) */
16545 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16547 + return au_test_tmpfs(sb)
16548 +#ifdef CONFIG_AUFS_BR_RAMFS
16549 + || au_test_ramfs(sb)
16551 + || au_test_ubifs(sb)
16552 + || au_test_hfsplus(sb);
16556 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16558 +static inline int au_test_fs_notime(struct super_block *sb)
16560 + return au_test_nfs(sb)
16561 + || au_test_fuse(sb)
16562 + || au_test_ubifs(sb)
16566 +/* temporary support for i#1 in cramfs */
16567 +static inline int au_test_fs_unique_ino(struct inode *inode)
16569 + if (au_test_cramfs(inode->i_sb))
16570 + return inode->i_ino != 1;
16574 +/* ---------------------------------------------------------------------- */
16577 + * the filesystem where the xino files placed must support i/o after unlink and
16578 + * maintain i_size and i_blocks.
16580 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16582 + return au_test_fs_remote(sb)
16583 + || au_test_fs_bad_iattr_size(sb)
16584 + /* don't want unnecessary work for xino */
16585 + || au_test_aufs(sb)
16586 + || au_test_ecryptfs(sb)
16587 + || au_test_nilfs(sb);
16590 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16592 + return au_test_tmpfs(sb)
16593 + || au_test_ramfs(sb);
16597 + * test if the @sb is real-readonly.
16599 +static inline int au_test_fs_rr(struct super_block *sb)
16601 + return au_test_squashfs(sb)
16602 + || au_test_iso9660(sb)
16603 + || au_test_cramfs(sb)
16604 + || au_test_romfs(sb);
16608 + * test if the @inode is nfs with 'noacl' option
16609 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16611 +static inline int au_test_nfs_noacl(struct inode *inode)
16613 + return au_test_nfs(inode->i_sb)
16614 + /* && IS_POSIXACL(inode) */
16615 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16618 +#endif /* __KERNEL__ */
16619 +#endif /* __AUFS_FSTYPE_H__ */
16620 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16621 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16622 +++ linux/fs/aufs/hbl.h 2021-09-06 21:02:45.276825587 +0200
16624 +/* SPDX-License-Identifier: GPL-2.0 */
16626 + * Copyright (C) 2017-2021 Junjiro R. Okajima
16628 + * This program, aufs is free software; you can redistribute it and/or modify
16629 + * it under the terms of the GNU General Public License as published by
16630 + * the Free Software Foundation; either version 2 of the License, or
16631 + * (at your option) any later version.
16633 + * This program is distributed in the hope that it will be useful,
16634 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16635 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16636 + * GNU General Public License for more details.
16638 + * You should have received a copy of the GNU General Public License
16639 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16643 + * helpers for hlist_bl.h
16646 +#ifndef __AUFS_HBL_H__
16647 +#define __AUFS_HBL_H__
16651 +#include <linux/list_bl.h>
16653 +static inline void au_hbl_add(struct hlist_bl_node *node,
16654 + struct hlist_bl_head *hbl)
16656 + hlist_bl_lock(hbl);
16657 + hlist_bl_add_head(node, hbl);
16658 + hlist_bl_unlock(hbl);
16661 +static inline void au_hbl_del(struct hlist_bl_node *node,
16662 + struct hlist_bl_head *hbl)
16664 + hlist_bl_lock(hbl);
16665 + hlist_bl_del(node);
16666 + hlist_bl_unlock(hbl);
16669 +#define au_hbl_for_each(pos, head) \
16670 + for (pos = hlist_bl_first(head); \
16674 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16676 + unsigned long cnt;
16677 + struct hlist_bl_node *pos;
16680 + hlist_bl_lock(hbl);
16681 + au_hbl_for_each(pos, hbl)
16683 + hlist_bl_unlock(hbl);
16687 +#endif /* __KERNEL__ */
16688 +#endif /* __AUFS_HBL_H__ */
16689 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16690 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16691 +++ linux/fs/aufs/hfsnotify.c 2021-09-06 21:02:45.276825587 +0200
16693 +// SPDX-License-Identifier: GPL-2.0
16695 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16697 + * This program, aufs is free software; you can redistribute it and/or modify
16698 + * it under the terms of the GNU General Public License as published by
16699 + * the Free Software Foundation; either version 2 of the License, or
16700 + * (at your option) any later version.
16702 + * This program is distributed in the hope that it will be useful,
16703 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16704 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16705 + * GNU General Public License for more details.
16707 + * You should have received a copy of the GNU General Public License
16708 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16712 + * fsnotify for the lower directories
16717 +/* FS_IN_IGNORED is unnecessary */
16718 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16719 + | FS_CREATE | FS_EVENT_ON_CHILD);
16720 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16721 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16723 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16725 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16727 + /* AuDbg("here\n"); */
16728 + au_cache_free_hnotify(hn);
16729 + smp_mb__before_atomic(); /* for atomic64_dec */
16730 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16731 + wake_up(&au_hfsn_wq);
16734 +static int au_hfsn_alloc(struct au_hinode *hinode)
16737 + struct au_hnotify *hn;
16738 + struct super_block *sb;
16739 + struct au_branch *br;
16740 + struct fsnotify_mark *mark;
16741 + aufs_bindex_t bindex;
16743 + hn = hinode->hi_notify;
16744 + sb = hn->hn_aufs_inode->i_sb;
16745 + bindex = au_br_index(sb, hinode->hi_id);
16746 + br = au_sbr(sb, bindex);
16747 + AuDebugOn(!br->br_hfsn);
16749 + mark = &hn->hn_mark;
16750 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16751 + mark->mask = AuHfsnMask;
16753 + * by udba rename or rmdir, aufs assign a new inode to the known
16754 + * h_inode, so specify 1 to allow dups.
16757 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16763 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16765 + struct fsnotify_mark *mark;
16766 + unsigned long long ull;
16767 + struct fsnotify_group *group;
16769 + ull = atomic64_inc_return(&au_hfsn_ifree);
16772 + mark = &hn->hn_mark;
16773 + spin_lock(&mark->lock);
16774 + group = mark->group;
16775 + fsnotify_get_group(group);
16776 + spin_unlock(&mark->lock);
16778 + fsnotify_destroy_mark(mark, group);
16779 + fsnotify_put_mark(mark);
16780 + fsnotify_put_group(group);
16783 + /* free hn by myself */
16787 +/* ---------------------------------------------------------------------- */
16789 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16791 + struct fsnotify_mark *mark;
16793 + mark = &hinode->hi_notify->hn_mark;
16794 + spin_lock(&mark->lock);
16796 + AuDebugOn(mark->mask & AuHfsnMask);
16797 + mark->mask |= AuHfsnMask;
16799 + AuDebugOn(!(mark->mask & AuHfsnMask));
16800 + mark->mask &= ~AuHfsnMask;
16802 + spin_unlock(&mark->lock);
16803 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16806 +/* ---------------------------------------------------------------------- */
16808 +/* #define AuDbgHnotify */
16809 +#ifdef AuDbgHnotify
16810 +static char *au_hfsn_name(u32 mask)
16812 +#ifdef CONFIG_AUFS_DEBUG
16813 +#define test_ret(flag) \
16815 + if (mask & flag) \
16818 + test_ret(FS_ACCESS);
16819 + test_ret(FS_MODIFY);
16820 + test_ret(FS_ATTRIB);
16821 + test_ret(FS_CLOSE_WRITE);
16822 + test_ret(FS_CLOSE_NOWRITE);
16823 + test_ret(FS_OPEN);
16824 + test_ret(FS_MOVED_FROM);
16825 + test_ret(FS_MOVED_TO);
16826 + test_ret(FS_CREATE);
16827 + test_ret(FS_DELETE);
16828 + test_ret(FS_DELETE_SELF);
16829 + test_ret(FS_MOVE_SELF);
16830 + test_ret(FS_UNMOUNT);
16831 + test_ret(FS_Q_OVERFLOW);
16832 + test_ret(FS_IN_IGNORED);
16833 + test_ret(FS_ISDIR);
16834 + test_ret(FS_IN_ONESHOT);
16835 + test_ret(FS_EVENT_ON_CHILD);
16844 +/* ---------------------------------------------------------------------- */
16846 +static void au_hfsn_free_group(struct fsnotify_group *group)
16848 + struct au_br_hfsnotify *hfsn = group->private;
16850 + /* AuDbg("here\n"); */
16851 + au_kfree_try_rcu(hfsn);
16854 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16855 + u32 mask, const void *data, int data_type,
16856 + struct inode *dir,
16857 + const struct qstr *file_name, u32 cookie,
16858 + struct fsnotify_iter_info *iter_info)
16861 + struct au_hnotify *hnotify;
16862 + struct inode *h_dir, *h_inode;
16863 + struct fsnotify_mark *inode_mark;
16865 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16868 + /* if FS_UNMOUNT happens, there must be another bug */
16869 + AuDebugOn(mask & FS_UNMOUNT);
16870 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16875 +#ifdef AuDbgHnotify
16877 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16878 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16879 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16880 + h_dir->i_ino, mask, au_hfsn_name(mask),
16881 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16882 + /* WARN_ON(1); */
16887 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16888 + AuDebugOn(!inode_mark);
16889 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16890 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16896 +static struct fsnotify_ops au_hfsn_ops = {
16897 + .handle_event = au_hfsn_handle_event,
16898 + .free_group_priv = au_hfsn_free_group,
16899 + .free_mark = au_hfsn_free_mark
16902 +/* ---------------------------------------------------------------------- */
16904 +static void au_hfsn_fin_br(struct au_branch *br)
16906 + struct au_br_hfsnotify *hfsn;
16908 + hfsn = br->br_hfsn;
16911 + fsnotify_put_group(hfsn->hfsn_group);
16916 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16919 + struct fsnotify_group *group;
16920 + struct au_br_hfsnotify *hfsn;
16923 + br->br_hfsn = NULL;
16924 + if (!au_br_hnotifyable(perm))
16928 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16929 + if (unlikely(!hfsn))
16933 + group = fsnotify_alloc_group(&au_hfsn_ops);
16934 + if (IS_ERR(group)) {
16935 + err = PTR_ERR(group);
16936 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16940 + group->private = hfsn;
16941 + hfsn->hfsn_group = group;
16942 + br->br_hfsn = hfsn;
16943 + goto out; /* success */
16946 + au_kfree_try_rcu(hfsn);
16951 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16956 + if (!br->br_hfsn)
16957 + err = au_hfsn_init_br(br, perm);
16962 +/* ---------------------------------------------------------------------- */
16964 +static void au_hfsn_fin(void)
16966 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16967 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16970 +const struct au_hnotify_op au_hnotify_op = {
16971 + .ctl = au_hfsn_ctl,
16972 + .alloc = au_hfsn_alloc,
16973 + .free = au_hfsn_free,
16975 + .fin = au_hfsn_fin,
16977 + .reset_br = au_hfsn_reset_br,
16978 + .fin_br = au_hfsn_fin_br,
16979 + .init_br = au_hfsn_init_br
16981 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16982 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16983 +++ linux/fs/aufs/hfsplus.c 2021-09-06 21:02:45.276825587 +0200
16985 +// SPDX-License-Identifier: GPL-2.0
16987 + * Copyright (C) 2010-2021 Junjiro R. Okajima
16989 + * This program, aufs is free software; you can redistribute it and/or modify
16990 + * it under the terms of the GNU General Public License as published by
16991 + * the Free Software Foundation; either version 2 of the License, or
16992 + * (at your option) any later version.
16994 + * This program is distributed in the hope that it will be useful,
16995 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16996 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16997 + * GNU General Public License for more details.
16999 + * You should have received a copy of the GNU General Public License
17000 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17004 + * special support for filesystems which acquires an inode mutex
17005 + * at final closing a file, eg, hfsplus.
17007 + * This trick is very simple and stupid, just to open the file before really
17008 + * necessary open to tell hfsplus that this is not the final closing.
17009 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
17010 + * and au_h_open_post() after releasing it.
17015 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
17018 + struct file *h_file;
17019 + struct dentry *h_dentry;
17021 + h_dentry = au_h_dptr(dentry, bindex);
17022 + AuDebugOn(!h_dentry);
17023 + AuDebugOn(d_is_negative(h_dentry));
17026 + if (au_test_hfsplus(h_dentry->d_sb)
17027 + && d_is_reg(h_dentry))
17028 + h_file = au_h_open(dentry, bindex,
17029 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17030 + /*file*/NULL, force_wr);
17034 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17035 + struct file *h_file)
17037 + struct au_branch *br;
17041 + br = au_sbr(dentry->d_sb, bindex);
17042 + au_lcnt_dec(&br->br_nfiles);
17045 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17046 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17047 +++ linux/fs/aufs/hnotify.c 2021-09-06 21:02:45.276825587 +0200
17049 +// SPDX-License-Identifier: GPL-2.0
17051 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17053 + * This program, aufs is free software; you can redistribute it and/or modify
17054 + * it under the terms of the GNU General Public License as published by
17055 + * the Free Software Foundation; either version 2 of the License, or
17056 + * (at your option) any later version.
17058 + * This program is distributed in the hope that it will be useful,
17059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17061 + * GNU General Public License for more details.
17063 + * You should have received a copy of the GNU General Public License
17064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17068 + * abstraction to notify the direct changes on lower directories
17071 +/* #include <linux/iversion.h> */
17074 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17077 + struct au_hnotify *hn;
17080 + hn = au_cache_alloc_hnotify();
17082 + hn->hn_aufs_inode = inode;
17083 + hinode->hi_notify = hn;
17084 + err = au_hnotify_op.alloc(hinode);
17086 + if (unlikely(err)) {
17087 + hinode->hi_notify = NULL;
17088 + au_cache_free_hnotify(hn);
17090 + * The upper dir was removed by udba, but the same named
17091 + * dir left. In this case, aufs assigns a new inode
17092 + * number and set the monitor again.
17093 + * For the lower dir, the old monitor is still left.
17095 + if (err == -EEXIST)
17104 +void au_hn_free(struct au_hinode *hinode)
17106 + struct au_hnotify *hn;
17108 + hn = hinode->hi_notify;
17110 + hinode->hi_notify = NULL;
17111 + if (au_hnotify_op.free(hinode, hn))
17112 + au_cache_free_hnotify(hn);
17116 +/* ---------------------------------------------------------------------- */
17118 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17120 + if (hinode->hi_notify)
17121 + au_hnotify_op.ctl(hinode, do_set);
17124 +void au_hn_reset(struct inode *inode, unsigned int flags)
17126 + aufs_bindex_t bindex, bbot;
17127 + struct inode *hi;
17128 + struct dentry *iwhdentry;
17130 + bbot = au_ibbot(inode);
17131 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17132 + hi = au_h_iptr(inode, bindex);
17136 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17137 + iwhdentry = au_hi_wh(inode, bindex);
17141 + au_set_h_iptr(inode, bindex, NULL, 0);
17142 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17143 + flags & ~AuHi_XINO);
17146 + /* inode_unlock(hi); */
17150 +/* ---------------------------------------------------------------------- */
17152 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17155 + aufs_bindex_t bindex, bbot, bfound, btop;
17156 + struct inode *h_i;
17159 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17160 + pr_warn("branch root dir was changed\n");
17165 + bbot = au_ibbot(inode);
17166 + btop = au_ibtop(inode);
17167 +#if 0 /* reserved for future use */
17168 + if (bindex == bbot) {
17169 + /* keep this ino in rename case */
17173 + for (bindex = btop; bindex <= bbot; bindex++)
17174 + if (au_h_iptr(inode, bindex) == h_inode) {
17181 + for (bindex = btop; bindex <= bbot; bindex++) {
17182 + h_i = au_h_iptr(inode, bindex);
17186 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17187 + /* ignore this error */
17188 + /* bad action? */
17191 + /* children inode number will be broken */
17198 +static int hn_gen_tree(struct dentry *dentry)
17200 + int err, i, j, ndentry;
17201 + struct au_dcsub_pages dpages;
17202 + struct au_dpage *dpage;
17203 + struct dentry **dentries;
17205 + err = au_dpages_init(&dpages, GFP_NOFS);
17206 + if (unlikely(err))
17208 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17209 + if (unlikely(err))
17212 + for (i = 0; i < dpages.ndpage; i++) {
17213 + dpage = dpages.dpages + i;
17214 + dentries = dpage->dentries;
17215 + ndentry = dpage->ndentry;
17216 + for (j = 0; j < ndentry; j++) {
17217 + struct dentry *d;
17224 + if (d_really_is_positive(d))
17225 + /* todo: reset children xino?
17226 + cached children only? */
17227 + au_iigen_dec(d_inode(d));
17232 + au_dpages_free(&dpages);
17238 + * return 0 if processed.
17240 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17241 + const unsigned int isdir)
17244 + struct dentry *d;
17245 + struct qstr *dname;
17248 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17249 + pr_warn("branch root dir was changed\n");
17255 + AuDebugOn(!name);
17256 + au_iigen_dec(inode);
17257 + spin_lock(&inode->i_lock);
17258 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17259 + spin_lock(&d->d_lock);
17260 + dname = &d->d_name;
17261 + if (dname->len != nlen
17262 + && memcmp(dname->name, name, nlen)) {
17263 + spin_unlock(&d->d_lock);
17268 + spin_unlock(&d->d_lock);
17271 + spin_unlock(&inode->i_lock);
17273 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17274 + d = d_find_any_alias(inode);
17276 + au_iigen_dec(inode);
17280 + spin_lock(&d->d_lock);
17281 + dname = &d->d_name;
17282 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17283 + spin_unlock(&d->d_lock);
17284 + err = hn_gen_tree(d);
17285 + spin_lock(&d->d_lock);
17287 + spin_unlock(&d->d_lock);
17296 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17300 + if (IS_ROOT(dentry)) {
17301 + pr_warn("branch root dir was changed\n");
17307 + au_digen_dec(dentry);
17308 + if (d_really_is_positive(dentry))
17309 + au_iigen_dec(d_inode(dentry));
17311 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17312 + if (d_really_is_positive(dentry))
17313 + err = hn_gen_tree(dentry);
17320 +/* ---------------------------------------------------------------------- */
17322 +/* hnotify job flags */
17323 +#define AuHnJob_XINO0 1
17324 +#define AuHnJob_GEN (1 << 1)
17325 +#define AuHnJob_DIRENT (1 << 2)
17326 +#define AuHnJob_ISDIR (1 << 3)
17327 +#define AuHnJob_TRYXINO0 (1 << 4)
17328 +#define AuHnJob_MNTPNT (1 << 5)
17329 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17330 +#define au_fset_hnjob(flags, name) \
17331 + do { (flags) |= AuHnJob_##name; } while (0)
17332 +#define au_fclr_hnjob(flags, name) \
17333 + do { (flags) &= ~AuHnJob_##name; } while (0)
17341 +struct au_hnotify_args {
17342 + struct inode *h_dir, *dir, *h_child_inode;
17344 + unsigned int flags[AuHnLast];
17345 + unsigned int h_child_nlen;
17346 + char h_child_name[];
17349 +struct hn_job_args {
17350 + unsigned int flags;
17351 + struct inode *inode, *h_inode, *dir, *h_dir;
17352 + struct dentry *dentry;
17357 +static int hn_job(struct hn_job_args *a)
17359 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17363 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17364 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17366 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17369 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17370 + if (!a->h_inode->i_nlink
17371 + && !(a->h_inode->i_state & I_LINKABLE))
17372 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17373 + inode_unlock_shared(a->h_inode);
17376 + /* make the generation obsolete */
17377 + if (au_ftest_hnjob(a->flags, GEN)) {
17380 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17382 + if (e && a->dentry)
17383 + hn_gen_by_name(a->dentry, isdir);
17384 + /* ignore this error */
17387 + /* make dir entries obsolete */
17388 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17389 + struct au_vdir *vdir;
17391 + vdir = au_ivdir(a->inode);
17393 + vdir->vd_jiffy = 0;
17394 + /* IMustLock(a->inode); */
17395 + /* inode_inc_iversion(a->inode); */
17398 + /* can do nothing but warn */
17399 + if (au_ftest_hnjob(a->flags, MNTPNT)
17401 + && d_mountpoint(a->dentry))
17402 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17407 +/* ---------------------------------------------------------------------- */
17409 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17410 + struct inode *dir)
17412 + struct dentry *dentry, *d, *parent;
17413 + struct qstr *dname;
17415 + parent = d_find_any_alias(dir);
17420 + spin_lock(&parent->d_lock);
17421 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17422 + /* AuDbg("%pd\n", d); */
17423 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17424 + dname = &d->d_name;
17425 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17426 + goto cont_unlock;
17430 + goto cont_unlock;
17431 + if (au_dcount(d) > 0) {
17432 + dentry = dget_dlock(d);
17433 + spin_unlock(&d->d_lock);
17438 + spin_unlock(&d->d_lock);
17440 + spin_unlock(&parent->d_lock);
17444 + di_write_lock_child(dentry);
17449 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17450 + aufs_bindex_t bindex, ino_t h_ino)
17452 + struct inode *inode;
17457 + err = au_xino_read(sb, bindex, h_ino, &ino);
17459 + inode = ilookup(sb, ino);
17463 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17464 + pr_warn("wrong root branch\n");
17470 + ii_write_lock_child(inode);
17476 +static void au_hn_bh(void *_args)
17478 + struct au_hnotify_args *a = _args;
17479 + struct super_block *sb;
17480 + aufs_bindex_t bindex, bbot, bfound;
17481 + unsigned char xino, try_iput;
17483 + struct inode *inode;
17485 + struct hn_job_args args;
17486 + struct dentry *dentry;
17487 + struct au_sbinfo *sbinfo;
17489 + AuDebugOn(!_args);
17490 + AuDebugOn(!a->h_dir);
17491 + AuDebugOn(!a->dir);
17492 + AuDebugOn(!a->mask);
17493 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17494 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17495 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17500 + * do not lock a->dir->i_mutex here
17501 + * because of d_revalidate() may cause a deadlock.
17503 + sb = a->dir->i_sb;
17505 + sbinfo = au_sbi(sb);
17506 + AuDebugOn(!sbinfo);
17507 + si_write_lock(sb, AuLock_NOPLMW);
17509 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17510 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17511 + case FS_MOVED_FROM:
17512 + case FS_MOVED_TO:
17513 + AuWarn1("DIRREN with UDBA may not work correctly "
17514 + "for the direct rename(2)\n");
17517 + ii_read_lock_parent(a->dir);
17519 + bbot = au_ibbot(a->dir);
17520 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17521 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17525 + ii_read_unlock(a->dir);
17526 + if (unlikely(bfound < 0))
17529 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17531 + if (a->h_child_inode)
17532 + h_ino = a->h_child_inode->i_ino;
17534 + if (a->h_child_nlen
17535 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17536 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17537 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17540 + if (dentry && d_really_is_positive(dentry))
17541 + inode = d_inode(dentry);
17542 + if (xino && !inode && h_ino
17543 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17544 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17545 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17546 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17550 + args.flags = a->flags[AuHn_CHILD];
17551 + args.dentry = dentry;
17552 + args.inode = inode;
17553 + args.h_inode = a->h_child_inode;
17554 + args.dir = a->dir;
17555 + args.h_dir = a->h_dir;
17556 + args.h_name = a->h_child_name;
17557 + args.h_nlen = a->h_child_nlen;
17558 + err = hn_job(&args);
17560 + if (au_di(dentry))
17561 + di_write_unlock(dentry);
17564 + if (inode && try_iput) {
17565 + ii_write_unlock(inode);
17569 + ii_write_lock_parent(a->dir);
17570 + args.flags = a->flags[AuHn_PARENT];
17571 + args.dentry = NULL;
17572 + args.inode = a->dir;
17573 + args.h_inode = a->h_dir;
17575 + args.h_dir = NULL;
17576 + args.h_name = NULL;
17578 + err = hn_job(&args);
17579 + ii_write_unlock(a->dir);
17582 + iput(a->h_child_inode);
17585 + si_write_unlock(sb);
17586 + au_nwt_done(&sbinfo->si_nowait);
17590 +/* ---------------------------------------------------------------------- */
17592 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17593 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17596 + unsigned int flags[AuHnLast], f;
17597 + unsigned char isdir, isroot, wh;
17598 + struct inode *dir;
17599 + struct au_hnotify_args *args;
17600 + char *p, *h_child_name;
17603 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17604 + dir = igrab(hnotify->hn_aufs_inode);
17608 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17610 + h_child_name = (void *)h_child_qstr->name;
17611 + len = h_child_qstr->len;
17612 + if (h_child_name) {
17613 + if (len > AUFS_WH_PFX_LEN
17614 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17615 + h_child_name += AUFS_WH_PFX_LEN;
17616 + len -= AUFS_WH_PFX_LEN;
17622 + if (h_child_inode)
17623 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17624 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17625 + flags[AuHn_CHILD] = 0;
17627 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17628 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17629 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17630 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17631 + case FS_MOVED_FROM:
17632 + case FS_MOVED_TO:
17633 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17634 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17637 + AuDebugOn(!h_child_name);
17642 + * aufs never be able to get this child inode.
17643 + * revalidation should be in d_revalidate()
17644 + * by checking i_nlink, i_generation or d_unhashed().
17646 + AuDebugOn(!h_child_name);
17647 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17648 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17656 + h_child_inode = NULL;
17659 + /* iput() and kfree() will be called in au_hnotify() */
17660 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17661 + if (unlikely(!args)) {
17662 + AuErr1("no memory\n");
17666 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17667 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17668 + args->mask = mask;
17670 + args->h_dir = igrab(h_dir);
17671 + if (h_child_inode)
17672 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17673 + args->h_child_inode = h_child_inode;
17674 + args->h_child_nlen = len;
17676 + p = (void *)args;
17677 + p += sizeof(*args);
17678 + memcpy(p, h_child_name, len);
17682 + /* NFS fires the event for silly-renamed one from kworker */
17684 + if (!dir->i_nlink
17685 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17687 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17688 + if (unlikely(err)) {
17689 + pr_err("wkq %d\n", err);
17690 + iput(args->h_child_inode);
17691 + iput(args->h_dir);
17693 + au_kfree_rcu(args);
17700 +/* ---------------------------------------------------------------------- */
17702 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17706 + AuDebugOn(!(udba & AuOptMask_UDBA));
17709 + if (au_hnotify_op.reset_br)
17710 + err = au_hnotify_op.reset_br(udba, br, perm);
17715 +int au_hnotify_init_br(struct au_branch *br, int perm)
17720 + if (au_hnotify_op.init_br)
17721 + err = au_hnotify_op.init_br(br, perm);
17726 +void au_hnotify_fin_br(struct au_branch *br)
17728 + if (au_hnotify_op.fin_br)
17729 + au_hnotify_op.fin_br(br);
17732 +static void au_hn_destroy_cache(void)
17734 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17735 + au_cache[AuCache_HNOTIFY] = NULL;
17738 +int __init au_hnotify_init(void)
17743 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17744 + if (au_cache[AuCache_HNOTIFY]) {
17746 + if (au_hnotify_op.init)
17747 + err = au_hnotify_op.init();
17748 + if (unlikely(err))
17749 + au_hn_destroy_cache();
17755 +void au_hnotify_fin(void)
17757 + if (au_hnotify_op.fin)
17758 + au_hnotify_op.fin();
17760 + /* cf. au_cache_fin() */
17761 + if (au_cache[AuCache_HNOTIFY])
17762 + au_hn_destroy_cache();
17764 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17765 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17766 +++ linux/fs/aufs/iinfo.c 2021-09-06 21:02:45.276825587 +0200
17768 +// SPDX-License-Identifier: GPL-2.0
17770 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17772 + * This program, aufs is free software; you can redistribute it and/or modify
17773 + * it under the terms of the GNU General Public License as published by
17774 + * the Free Software Foundation; either version 2 of the License, or
17775 + * (at your option) any later version.
17777 + * This program is distributed in the hope that it will be useful,
17778 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17779 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17780 + * GNU General Public License for more details.
17782 + * You should have received a copy of the GNU General Public License
17783 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17787 + * inode private data
17792 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17794 + struct inode *h_inode;
17795 + struct au_hinode *hinode;
17797 + IiMustAnyLock(inode);
17799 + hinode = au_hinode(au_ii(inode), bindex);
17800 + h_inode = hinode->hi_inode;
17801 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17805 +/* todo: hard/soft set? */
17806 +void au_hiput(struct au_hinode *hinode)
17808 + au_hn_free(hinode);
17809 + dput(hinode->hi_whdentry);
17810 + iput(hinode->hi_inode);
17813 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17815 + unsigned int flags;
17816 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17819 + if (au_opt_test(mnt_flags, XINO))
17820 + au_fset_hi(flags, XINO);
17821 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17822 + au_fset_hi(flags, HNOTIFY);
17826 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17827 + struct inode *h_inode, unsigned int flags)
17829 + struct au_hinode *hinode;
17830 + struct inode *hi;
17831 + struct au_iinfo *iinfo = au_ii(inode);
17833 + IiMustWriteLock(inode);
17835 + hinode = au_hinode(iinfo, bindex);
17836 + hi = hinode->hi_inode;
17837 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17840 + au_hiput(hinode);
17841 + hinode->hi_inode = h_inode;
17844 + struct super_block *sb = inode->i_sb;
17845 + struct au_branch *br;
17847 + AuDebugOn(inode->i_mode
17848 + && (h_inode->i_mode & S_IFMT)
17849 + != (inode->i_mode & S_IFMT));
17850 + if (bindex == iinfo->ii_btop)
17851 + au_cpup_igen(inode, h_inode);
17852 + br = au_sbr(sb, bindex);
17853 + hinode->hi_id = br->br_id;
17854 + if (au_ftest_hi(flags, XINO)) {
17855 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17857 + if (unlikely(err))
17858 + AuIOErr1("failed au_xino_write() %d\n", err);
17861 + if (au_ftest_hi(flags, HNOTIFY)
17862 + && au_br_hnotifyable(br->br_perm)) {
17863 + err = au_hn_alloc(hinode, inode);
17864 + if (unlikely(err))
17865 + AuIOErr1("au_hn_alloc() %d\n", err);
17870 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17871 + struct dentry *h_wh)
17873 + struct au_hinode *hinode;
17875 + IiMustWriteLock(inode);
17877 + hinode = au_hinode(au_ii(inode), bindex);
17878 + AuDebugOn(hinode->hi_whdentry);
17879 + hinode->hi_whdentry = h_wh;
17882 +void au_update_iigen(struct inode *inode, int half)
17884 + struct au_iinfo *iinfo;
17885 + struct au_iigen *iigen;
17886 + unsigned int sigen;
17888 + sigen = au_sigen(inode->i_sb);
17889 + iinfo = au_ii(inode);
17890 + iigen = &iinfo->ii_generation;
17891 + spin_lock(&iigen->ig_spin);
17892 + iigen->ig_generation = sigen;
17894 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17896 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17897 + spin_unlock(&iigen->ig_spin);
17900 +/* it may be called at remount time, too */
17901 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17903 + struct au_iinfo *iinfo;
17904 + aufs_bindex_t bindex, bbot;
17906 + AuDebugOn(au_is_bad_inode(inode));
17907 + IiMustWriteLock(inode);
17909 + iinfo = au_ii(inode);
17910 + if (do_put_zero && iinfo->ii_btop >= 0) {
17911 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17913 + struct inode *h_i;
17915 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17918 + && !(h_i->i_state & I_LINKABLE))
17919 + au_set_h_iptr(inode, bindex, NULL, 0);
17923 + iinfo->ii_btop = -1;
17924 + iinfo->ii_bbot = -1;
17925 + bbot = au_sbbot(inode->i_sb);
17926 + for (bindex = 0; bindex <= bbot; bindex++)
17927 + if (au_hinode(iinfo, bindex)->hi_inode) {
17928 + iinfo->ii_btop = bindex;
17931 + if (iinfo->ii_btop >= 0)
17932 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17933 + if (au_hinode(iinfo, bindex)->hi_inode) {
17934 + iinfo->ii_bbot = bindex;
17937 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17940 +/* ---------------------------------------------------------------------- */
17942 +void au_icntnr_init_once(void *_c)
17944 + struct au_icntnr *c = _c;
17945 + struct au_iinfo *iinfo = &c->iinfo;
17947 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17948 + au_rw_init(&iinfo->ii_rwsem);
17949 + inode_init_once(&c->vfs_inode);
17952 +void au_hinode_init(struct au_hinode *hinode)
17954 + hinode->hi_inode = NULL;
17955 + hinode->hi_id = -1;
17956 + au_hn_init(hinode);
17957 + hinode->hi_whdentry = NULL;
17960 +int au_iinfo_init(struct inode *inode)
17962 + struct au_iinfo *iinfo;
17963 + struct super_block *sb;
17964 + struct au_hinode *hi;
17967 + sb = inode->i_sb;
17968 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17969 + nbr = au_sbbot(sb) + 1;
17970 + if (unlikely(nbr <= 0))
17972 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17974 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17976 + iinfo->ii_hinode = hi;
17977 + for (i = 0; i < nbr; i++, hi++)
17978 + au_hinode_init(hi);
17980 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17981 + iinfo->ii_btop = -1;
17982 + iinfo->ii_bbot = -1;
17983 + iinfo->ii_vdir = NULL;
17989 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17992 + struct au_hinode *hip;
17994 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17997 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
18000 + iinfo->ii_hinode = hip;
18001 + i = iinfo->ii_bbot + 1;
18003 + for (; i < nbr; i++, hip++)
18004 + au_hinode_init(hip);
18011 +void au_iinfo_fin(struct inode *inode)
18013 + struct au_iinfo *iinfo;
18014 + struct au_hinode *hi;
18015 + struct super_block *sb;
18016 + aufs_bindex_t bindex, bbot;
18017 + const unsigned char unlinked = !inode->i_nlink;
18019 + AuDebugOn(au_is_bad_inode(inode));
18021 + sb = inode->i_sb;
18022 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
18023 + if (si_pid_test(sb))
18024 + au_xino_delete_inode(inode, unlinked);
18027 + * it is safe to hide the dependency between sbinfo and
18031 + si_noflush_read_lock(sb);
18032 + au_xino_delete_inode(inode, unlinked);
18033 + si_read_unlock(sb);
18037 + iinfo = au_ii(inode);
18038 + if (iinfo->ii_vdir)
18039 + au_vdir_free(iinfo->ii_vdir);
18041 + bindex = iinfo->ii_btop;
18042 + if (bindex >= 0) {
18043 + hi = au_hinode(iinfo, bindex);
18044 + bbot = iinfo->ii_bbot;
18045 + while (bindex++ <= bbot) {
18046 + if (hi->hi_inode)
18051 + au_kfree_rcu(iinfo->ii_hinode);
18052 + AuRwDestroy(&iinfo->ii_rwsem);
18054 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18055 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18056 +++ linux/fs/aufs/inode.c 2021-09-06 21:02:45.276825587 +0200
18058 +// SPDX-License-Identifier: GPL-2.0
18060 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18062 + * This program, aufs is free software; you can redistribute it and/or modify
18063 + * it under the terms of the GNU General Public License as published by
18064 + * the Free Software Foundation; either version 2 of the License, or
18065 + * (at your option) any later version.
18067 + * This program is distributed in the hope that it will be useful,
18068 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18070 + * GNU General Public License for more details.
18072 + * You should have received a copy of the GNU General Public License
18073 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18077 + * inode functions
18080 +#include <linux/iversion.h>
18083 +struct inode *au_igrab(struct inode *inode)
18086 + AuDebugOn(!atomic_read(&inode->i_count));
18092 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18094 + au_cpup_attr_all(inode, /*force*/0);
18095 + au_update_iigen(inode, /*half*/1);
18097 + inode_inc_iversion(inode);
18100 +static int au_ii_refresh(struct inode *inode, int *update)
18104 + aufs_bindex_t bindex, new_bindex;
18105 + struct super_block *sb;
18106 + struct au_iinfo *iinfo;
18107 + struct au_hinode *p, *q, tmp;
18109 + AuDebugOn(au_is_bad_inode(inode));
18110 + IiMustWriteLock(inode);
18113 + sb = inode->i_sb;
18114 + nbr = au_sbbot(sb) + 1;
18115 + type = inode->i_mode & S_IFMT;
18116 + iinfo = au_ii(inode);
18117 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18118 + if (unlikely(err))
18121 + AuDebugOn(iinfo->ii_btop < 0);
18122 + p = au_hinode(iinfo, iinfo->ii_btop);
18123 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18125 + if (!p->hi_inode)
18128 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18129 + new_bindex = au_br_index(sb, p->hi_id);
18130 + if (new_bindex == bindex)
18133 + if (new_bindex < 0) {
18136 + p->hi_inode = NULL;
18140 + if (new_bindex < iinfo->ii_btop)
18141 + iinfo->ii_btop = new_bindex;
18142 + if (iinfo->ii_bbot < new_bindex)
18143 + iinfo->ii_bbot = new_bindex;
18144 + /* swap two lower inode, and loop again */
18145 + q = au_hinode(iinfo, new_bindex);
18149 + if (tmp.hi_inode) {
18154 + au_update_ibrange(inode, /*do_put_zero*/0);
18155 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18156 + e = au_dy_irefresh(inode);
18157 + if (unlikely(e && !err))
18165 +void au_refresh_iop(struct inode *inode, int force_getattr)
18168 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18169 + const struct inode_operations *iop
18170 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18172 + if (inode->i_op == iop)
18175 + switch (inode->i_mode & S_IFMT) {
18177 + type = AuIop_DIR;
18180 + type = AuIop_SYMLINK;
18183 + type = AuIop_OTHER;
18187 + inode->i_op = iop + type;
18188 + /* unnecessary smp_wmb() */
18191 +int au_refresh_hinode_self(struct inode *inode)
18195 + err = au_ii_refresh(inode, &update);
18197 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18203 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18205 + int err, e, update;
18206 + unsigned int flags;
18208 + aufs_bindex_t bindex, bbot;
18209 + unsigned char isdir;
18210 + struct au_hinode *p;
18211 + struct au_iinfo *iinfo;
18213 + err = au_ii_refresh(inode, &update);
18214 + if (unlikely(err))
18218 + iinfo = au_ii(inode);
18219 + p = au_hinode(iinfo, iinfo->ii_btop);
18220 + mode = (inode->i_mode & S_IFMT);
18221 + isdir = S_ISDIR(mode);
18222 + flags = au_hi_flags(inode, isdir);
18223 + bbot = au_dbbot(dentry);
18224 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18225 + struct inode *h_i, *h_inode;
18226 + struct dentry *h_d;
18228 + h_d = au_h_dptr(dentry, bindex);
18229 + if (!h_d || d_is_negative(h_d))
18232 + h_inode = d_inode(h_d);
18233 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18234 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18235 + h_i = au_h_iptr(inode, bindex);
18237 + if (h_i == h_inode)
18243 + if (bindex < iinfo->ii_btop)
18244 + iinfo->ii_btop = bindex;
18245 + if (iinfo->ii_bbot < bindex)
18246 + iinfo->ii_bbot = bindex;
18247 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18250 + au_update_ibrange(inode, /*do_put_zero*/0);
18251 + e = au_dy_irefresh(inode);
18252 + if (unlikely(e && !err))
18255 + au_refresh_hinode_attr(inode, update && isdir);
18262 +static int set_inode(struct inode *inode, struct dentry *dentry)
18265 + unsigned int flags;
18267 + aufs_bindex_t bindex, btop, btail;
18268 + unsigned char isdir;
18269 + struct dentry *h_dentry;
18270 + struct inode *h_inode;
18271 + struct au_iinfo *iinfo;
18272 + const struct inode_operations *iop;
18274 + IiMustWriteLock(inode);
18278 + iop = au_sbi(inode->i_sb)->si_iop_array;
18279 + btop = au_dbtop(dentry);
18280 + h_dentry = au_h_dptr(dentry, btop);
18281 + h_inode = d_inode(h_dentry);
18282 + mode = h_inode->i_mode;
18283 + switch (mode & S_IFMT) {
18285 + btail = au_dbtail(dentry);
18286 + inode->i_op = iop + AuIop_OTHER;
18287 + inode->i_fop = &aufs_file_fop;
18288 + err = au_dy_iaop(inode, btop, h_inode);
18289 + if (unlikely(err))
18294 + btail = au_dbtaildir(dentry);
18295 + inode->i_op = iop + AuIop_DIR;
18296 + inode->i_fop = &aufs_dir_fop;
18299 + btail = au_dbtail(dentry);
18300 + inode->i_op = iop + AuIop_SYMLINK;
18306 + btail = au_dbtail(dentry);
18307 + inode->i_op = iop + AuIop_OTHER;
18308 + init_special_inode(inode, mode, h_inode->i_rdev);
18311 + AuIOErr("Unknown file type 0%o\n", mode);
18316 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18317 + flags = au_hi_flags(inode, isdir);
18318 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18319 + && au_ftest_hi(flags, HNOTIFY)
18320 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18321 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18322 + au_fclr_hi(flags, HNOTIFY);
18323 + iinfo = au_ii(inode);
18324 + iinfo->ii_btop = btop;
18325 + iinfo->ii_bbot = btail;
18326 + for (bindex = btop; bindex <= btail; bindex++) {
18327 + h_dentry = au_h_dptr(dentry, bindex);
18329 + au_set_h_iptr(inode, bindex,
18330 + au_igrab(d_inode(h_dentry)), flags);
18332 + au_cpup_attr_all(inode, /*force*/1);
18334 + * to force calling aufs_get_acl() every time,
18335 + * do not call cache_no_acl() for aufs inode.
18343 + * successful returns with iinfo write_locked
18345 + * zero: success, matched
18346 + * plus: no error, but unmatched
18348 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18351 + unsigned int gen, igflags;
18352 + aufs_bindex_t bindex, bbot;
18353 + struct inode *h_inode, *h_dinode;
18354 + struct dentry *h_dentry;
18357 + * before this function, if aufs got any iinfo lock, it must be only
18358 + * one, the parent dir.
18359 + * it can happen by UDBA and the obsoleted inode number.
18362 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18366 + ii_write_lock_new_child(inode);
18367 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18368 + h_dinode = d_inode(h_dentry);
18369 + bbot = au_ibbot(inode);
18370 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18371 + h_inode = au_h_iptr(inode, bindex);
18372 + if (!h_inode || h_inode != h_dinode)
18376 + gen = au_iigen(inode, &igflags);
18377 + if (gen == au_digen(dentry)
18378 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18381 + /* fully refresh inode using dentry */
18382 + err = au_refresh_hinode(inode, dentry);
18384 + au_update_iigen(inode, /*half*/0);
18388 + if (unlikely(err))
18389 + ii_write_unlock(inode);
18394 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18395 + unsigned int d_type, ino_t *ino)
18398 + const int isnondir = d_type != DT_DIR;
18400 + /* prevent hardlinked inode number from race condition */
18402 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18403 + if (unlikely(err))
18407 + err = au_xino_read(sb, bindex, h_ino, ino);
18408 + if (unlikely(err))
18409 + goto out_xinondir;
18413 + *ino = au_xino_new_ino(sb);
18414 + if (unlikely(!*ino))
18415 + goto out_xinondir;
18416 + err = au_xino_write(sb, bindex, h_ino, *ino);
18417 + if (unlikely(err))
18418 + goto out_xinondir;
18422 + if (isnondir && idx >= 0)
18423 + au_xinondir_leave(sb, bindex, h_ino, idx);
18428 +/* successful returns with iinfo write_locked */
18429 +/* todo: return with unlocked? */
18430 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18432 + struct inode *inode, *h_inode;
18433 + struct dentry *h_dentry;
18434 + struct super_block *sb;
18435 + ino_t h_ino, ino;
18436 + int err, idx, hlinked;
18437 + aufs_bindex_t btop;
18439 + sb = dentry->d_sb;
18440 + btop = au_dbtop(dentry);
18441 + h_dentry = au_h_dptr(dentry, btop);
18442 + h_inode = d_inode(h_dentry);
18443 + h_ino = h_inode->i_ino;
18444 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18448 + * stop 'race'-ing between hardlinks under different
18452 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18453 + inode = ERR_PTR(err);
18454 + if (unlikely(err))
18458 + err = au_xino_read(sb, btop, h_ino, &ino);
18459 + inode = ERR_PTR(err);
18460 + if (unlikely(err))
18461 + goto out_xinondir;
18464 + ino = au_xino_new_ino(sb);
18465 + if (unlikely(!ino)) {
18466 + inode = ERR_PTR(-EIO);
18467 + goto out_xinondir;
18471 + AuDbg("i%lu\n", (unsigned long)ino);
18472 + inode = au_iget_locked(sb, ino);
18473 + err = PTR_ERR(inode);
18474 + if (IS_ERR(inode))
18475 + goto out_xinondir;
18477 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18478 + if (inode->i_state & I_NEW) {
18479 + ii_write_lock_new_child(inode);
18480 + err = set_inode(inode, dentry);
18482 + unlock_new_inode(inode);
18483 + goto out_xinondir; /* success */
18487 + * iget_failed() calls iput(), but we need to call
18488 + * ii_write_unlock() after iget_failed(). so dirty hack for
18491 + atomic_inc(&inode->i_count);
18492 + iget_failed(inode);
18493 + ii_write_unlock(inode);
18494 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18495 + /* ignore this error */
18497 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18499 + * horrible race condition between lookup, readdir and copyup
18500 + * (or something).
18502 + if (hlinked && idx >= 0)
18503 + au_xinondir_leave(sb, btop, h_ino, idx);
18504 + err = reval_inode(inode, dentry);
18505 + if (unlikely(err < 0)) {
18510 + goto out; /* success */
18511 + else if (hlinked && idx >= 0) {
18512 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18513 + if (unlikely(err)) {
18515 + inode = ERR_PTR(err);
18521 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18522 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18523 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18524 + btop, au_sbtype(h_dentry->d_sb), dentry,
18525 + (unsigned long)h_ino, (unsigned long)ino);
18527 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18530 + if (hlinked && idx >= 0)
18531 + au_xinondir_leave(sb, btop, h_ino, idx);
18537 + inode = ERR_PTR(err);
18539 + if (hlinked && idx >= 0)
18540 + au_xinondir_leave(sb, btop, h_ino, idx);
18545 +/* ---------------------------------------------------------------------- */
18547 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18548 + struct inode *inode)
18551 + struct inode *hi;
18553 + err = au_br_rdonly(au_sbr(sb, bindex));
18555 + /* pseudo-link after flushed may happen out of bounds */
18558 + && au_ibtop(inode) <= bindex
18559 + && bindex <= au_ibbot(inode)) {
18561 + * permission check is unnecessary since vfsub routine
18562 + * will be called later
18564 + hi = au_h_iptr(inode, bindex);
18566 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18572 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18575 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18577 + return inode_permission(h_userns, h_inode, mask);
18580 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18583 + if (au_test_nfs(h_inode->i_sb)
18584 + && (mask & MAY_WRITE)
18585 + && S_ISDIR(h_inode->i_mode))
18586 + mask |= MAY_READ; /* force permission check */
18587 + return au_test_h_perm(h_userns, h_inode, mask);
18589 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18590 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18591 +++ linux/fs/aufs/inode.h 2021-09-06 21:02:45.276825587 +0200
18593 +/* SPDX-License-Identifier: GPL-2.0 */
18595 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18597 + * This program, aufs is free software; you can redistribute it and/or modify
18598 + * it under the terms of the GNU General Public License as published by
18599 + * the Free Software Foundation; either version 2 of the License, or
18600 + * (at your option) any later version.
18602 + * This program is distributed in the hope that it will be useful,
18603 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18604 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18605 + * GNU General Public License for more details.
18607 + * You should have received a copy of the GNU General Public License
18608 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18612 + * inode operations
18615 +#ifndef __AUFS_INODE_H__
18616 +#define __AUFS_INODE_H__
18620 +#include <linux/fsnotify.h>
18621 +#include "rwsem.h"
18625 +struct au_hnotify {
18626 +#ifdef CONFIG_AUFS_HNOTIFY
18627 +#ifdef CONFIG_AUFS_HFSNOTIFY
18628 + /* never use fsnotify_add_vfsmount_mark() */
18629 + struct fsnotify_mark hn_mark;
18631 + struct inode *hn_aufs_inode; /* no get/put */
18632 + struct rcu_head rcu;
18634 +} ____cacheline_aligned_in_smp;
18636 +struct au_hinode {
18637 + struct inode *hi_inode;
18638 + aufs_bindex_t hi_id;
18639 +#ifdef CONFIG_AUFS_HNOTIFY
18640 + struct au_hnotify *hi_notify;
18643 + /* reference to the copied-up whiteout with get/put */
18644 + struct dentry *hi_whdentry;
18648 +#define AuIG_HALF_REFRESHED 1
18649 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18650 +#define au_ig_fset(flags, name) \
18651 + do { (flags) |= AuIG_##name; } while (0)
18652 +#define au_ig_fclr(flags, name) \
18653 + do { (flags) &= ~AuIG_##name; } while (0)
18656 + spinlock_t ig_spin;
18657 + __u32 ig_generation, ig_flags;
18662 + struct au_iigen ii_generation;
18663 + struct super_block *ii_hsb1; /* no get/put */
18665 + struct au_rwsem ii_rwsem;
18666 + aufs_bindex_t ii_btop, ii_bbot;
18668 + struct au_hinode *ii_hinode;
18669 + struct au_vdir *ii_vdir;
18672 +struct au_icntnr {
18673 + struct au_iinfo iinfo;
18674 + struct inode vfs_inode;
18675 + struct hlist_bl_node plink;
18676 + struct rcu_head rcu;
18677 +} ____cacheline_aligned_in_smp;
18679 +/* au_pin flags */
18680 +#define AuPin_DI_LOCKED 1
18681 +#define AuPin_MNT_WRITE (1 << 1)
18682 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18683 +#define au_fset_pin(flags, name) \
18684 + do { (flags) |= AuPin_##name; } while (0)
18685 +#define au_fclr_pin(flags, name) \
18686 + do { (flags) &= ~AuPin_##name; } while (0)
18690 + struct dentry *dentry;
18691 + unsigned int udba;
18692 + unsigned char lsc_di, lsc_hi, flags;
18693 + aufs_bindex_t bindex;
18696 + struct dentry *parent;
18697 + struct au_hinode *hdir;
18698 + struct vfsmount *h_mnt;
18700 + /* temporary unlock/relock for copyup */
18701 + struct dentry *h_dentry, *h_parent;
18702 + struct au_branch *br;
18703 + struct task_struct *task;
18706 +void au_pin_hdir_unlock(struct au_pin *p);
18707 +int au_pin_hdir_lock(struct au_pin *p);
18708 +int au_pin_hdir_relock(struct au_pin *p);
18709 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18710 +void au_pin_hdir_release(struct au_pin *p);
18712 +/* ---------------------------------------------------------------------- */
18714 +static inline struct au_iinfo *au_ii(struct inode *inode)
18716 + BUG_ON(is_bad_inode(inode));
18717 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18720 +/* ---------------------------------------------------------------------- */
18723 +struct inode *au_igrab(struct inode *inode);
18724 +void au_refresh_iop(struct inode *inode, int force_getattr);
18725 +int au_refresh_hinode_self(struct inode *inode);
18726 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18727 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18728 + unsigned int d_type, ino_t *ino);
18729 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18730 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18731 + struct inode *inode);
18732 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18734 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18737 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18738 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18740 +#ifdef CONFIG_AUFS_SHWH
18741 + return au_ino(sb, bindex, h_ino, d_type, ino);
18754 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18755 + aufs_iop_nogetattr[AuIop_Last];
18757 +/* au_wr_dir flags */
18758 +#define AuWrDir_ADD_ENTRY 1
18759 +#define AuWrDir_ISDIR (1 << 1)
18760 +#define AuWrDir_TMPFILE (1 << 2)
18761 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18762 +#define au_fset_wrdir(flags, name) \
18763 + do { (flags) |= AuWrDir_##name; } while (0)
18764 +#define au_fclr_wrdir(flags, name) \
18765 + do { (flags) &= ~AuWrDir_##name; } while (0)
18767 +struct au_wr_dir_args {
18768 + aufs_bindex_t force_btgt;
18769 + unsigned char flags;
18771 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18772 + struct au_wr_dir_args *args);
18774 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18775 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18776 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18777 + unsigned int udba, unsigned char flags);
18778 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18779 + unsigned int udba, unsigned char flags) __must_check;
18780 +int au_do_pin(struct au_pin *pin) __must_check;
18781 +void au_unpin(struct au_pin *pin);
18782 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18784 +#define AuIcpup_DID_CPUP 1
18785 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18786 +#define au_fset_icpup(flags, name) \
18787 + do { (flags) |= AuIcpup_##name; } while (0)
18788 +#define au_fclr_icpup(flags, name) \
18789 + do { (flags) &= ~AuIcpup_##name; } while (0)
18791 +struct au_icpup_args {
18792 + unsigned char flags;
18793 + unsigned char pin_flags;
18794 + aufs_bindex_t btgt;
18795 + unsigned int udba;
18796 + struct au_pin pin;
18797 + struct path h_path;
18798 + struct inode *h_inode;
18801 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18802 + struct au_icpup_args *a);
18804 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18805 + struct path *h_path, int locked);
18808 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18809 + struct dentry *h_parent, int isdir);
18810 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
18811 + struct dentry *dentry, umode_t mode, dev_t dev);
18812 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
18813 + struct dentry *dentry, const char *symname);
18814 +int aufs_create(struct user_namespace *userns, struct inode *dir,
18815 + struct dentry *dentry, umode_t mode, bool want_excl);
18816 +struct vfsub_aopen_args;
18817 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18818 + struct vfsub_aopen_args *args);
18819 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
18820 + struct dentry *dentry, umode_t mode);
18821 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18822 + struct dentry *dentry);
18823 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
18824 + struct dentry *dentry, umode_t mode);
18827 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18828 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18829 + struct dentry *h_parent, int isdir);
18830 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18831 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18834 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18835 +int aufs_rename(struct user_namespace *userns,
18836 + struct inode *_src_dir, struct dentry *_src_dentry,
18837 + struct inode *_dst_dir, struct dentry *_dst_dentry,
18838 + unsigned int _flags);
18841 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18842 +void au_hiput(struct au_hinode *hinode);
18843 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18844 + struct dentry *h_wh);
18845 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18847 +/* hinode flags */
18848 +#define AuHi_XINO 1
18849 +#define AuHi_HNOTIFY (1 << 1)
18850 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18851 +#define au_fset_hi(flags, name) \
18852 + do { (flags) |= AuHi_##name; } while (0)
18853 +#define au_fclr_hi(flags, name) \
18854 + do { (flags) &= ~AuHi_##name; } while (0)
18856 +#ifndef CONFIG_AUFS_HNOTIFY
18857 +#undef AuHi_HNOTIFY
18858 +#define AuHi_HNOTIFY 0
18861 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18862 + struct inode *h_inode, unsigned int flags);
18864 +void au_update_iigen(struct inode *inode, int half);
18865 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18867 +void au_icntnr_init_once(void *_c);
18868 +void au_hinode_init(struct au_hinode *hinode);
18869 +int au_iinfo_init(struct inode *inode);
18870 +void au_iinfo_fin(struct inode *inode);
18871 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18873 +#ifdef CONFIG_PROC_FS
18875 +int au_plink_maint(struct super_block *sb, int flags);
18877 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18878 +int au_plink_maint_enter(struct super_block *sb);
18879 +#ifdef CONFIG_AUFS_DEBUG
18880 +void au_plink_list(struct super_block *sb);
18882 +AuStubVoid(au_plink_list, struct super_block *sb)
18884 +int au_plink_test(struct inode *inode);
18885 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18886 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18887 + struct dentry *h_dentry);
18888 +void au_plink_put(struct super_block *sb, int verbose);
18889 +void au_plink_clean(struct super_block *sb, int verbose);
18890 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18892 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18893 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18894 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18895 +AuStubVoid(au_plink_list, struct super_block *sb);
18896 +AuStubInt0(au_plink_test, struct inode *inode);
18897 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18898 + struct inode *inode, aufs_bindex_t bindex);
18899 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18900 + struct dentry *h_dentry);
18901 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18902 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18903 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18904 +#endif /* CONFIG_PROC_FS */
18906 +#ifdef CONFIG_AUFS_XATTR
18908 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
18909 + unsigned int verbose);
18910 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18911 +void au_xattr_init(struct super_block *sb);
18913 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
18914 + int ignore_flags, unsigned int verbose);
18915 +AuStubVoid(au_xattr_init, struct super_block *sb);
18918 +#ifdef CONFIG_FS_POSIX_ACL
18919 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18920 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
18921 + struct posix_acl *acl, int type);
18924 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18930 +struct au_sxattr {
18934 + const char *name;
18935 + const void *value;
18940 + struct posix_acl *acl;
18945 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18946 + struct au_sxattr *arg);
18949 +/* ---------------------------------------------------------------------- */
18951 +/* lock subclass for iinfo */
18953 + AuLsc_II_CHILD, /* child first */
18954 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18955 + AuLsc_II_CHILD3, /* copyup dirs */
18956 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18957 + AuLsc_II_PARENT2,
18958 + AuLsc_II_PARENT3, /* copyup dirs */
18959 + AuLsc_II_NEW_CHILD
18963 + * ii_read_lock_child, ii_write_lock_child,
18964 + * ii_read_lock_child2, ii_write_lock_child2,
18965 + * ii_read_lock_child3, ii_write_lock_child3,
18966 + * ii_read_lock_parent, ii_write_lock_parent,
18967 + * ii_read_lock_parent2, ii_write_lock_parent2,
18968 + * ii_read_lock_parent3, ii_write_lock_parent3,
18969 + * ii_read_lock_new_child, ii_write_lock_new_child,
18971 +#define AuReadLockFunc(name, lsc) \
18972 +static inline void ii_read_lock_##name(struct inode *i) \
18974 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18977 +#define AuWriteLockFunc(name, lsc) \
18978 +static inline void ii_write_lock_##name(struct inode *i) \
18980 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18983 +#define AuRWLockFuncs(name, lsc) \
18984 + AuReadLockFunc(name, lsc) \
18985 + AuWriteLockFunc(name, lsc)
18987 +AuRWLockFuncs(child, CHILD);
18988 +AuRWLockFuncs(child2, CHILD2);
18989 +AuRWLockFuncs(child3, CHILD3);
18990 +AuRWLockFuncs(parent, PARENT);
18991 +AuRWLockFuncs(parent2, PARENT2);
18992 +AuRWLockFuncs(parent3, PARENT3);
18993 +AuRWLockFuncs(new_child, NEW_CHILD);
18995 +#undef AuReadLockFunc
18996 +#undef AuWriteLockFunc
18997 +#undef AuRWLockFuncs
18999 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
19000 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
19001 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
19003 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
19004 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
19005 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
19007 +/* ---------------------------------------------------------------------- */
19009 +static inline void au_icntnr_init(struct au_icntnr *c)
19011 +#ifdef CONFIG_AUFS_DEBUG
19012 + c->vfs_inode.i_mode = 0;
19016 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
19018 + unsigned int gen;
19019 + struct au_iinfo *iinfo;
19020 + struct au_iigen *iigen;
19022 + iinfo = au_ii(inode);
19023 + iigen = &iinfo->ii_generation;
19024 + spin_lock(&iigen->ig_spin);
19026 + *igflags = iigen->ig_flags;
19027 + gen = iigen->ig_generation;
19028 + spin_unlock(&iigen->ig_spin);
19033 +/* tiny test for inode number */
19034 +/* tmpfs generation is too rough */
19035 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19037 + struct au_iinfo *iinfo;
19039 + iinfo = au_ii(inode);
19040 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19041 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19042 + && iinfo->ii_higen == h_inode->i_generation);
19045 +static inline void au_iigen_dec(struct inode *inode)
19047 + struct au_iinfo *iinfo;
19048 + struct au_iigen *iigen;
19050 + iinfo = au_ii(inode);
19051 + iigen = &iinfo->ii_generation;
19052 + spin_lock(&iigen->ig_spin);
19053 + iigen->ig_generation--;
19054 + spin_unlock(&iigen->ig_spin);
19057 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19062 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19068 +/* ---------------------------------------------------------------------- */
19070 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19071 + aufs_bindex_t bindex)
19073 + return iinfo->ii_hinode + bindex;
19076 +static inline int au_is_bad_inode(struct inode *inode)
19078 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19081 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19082 + aufs_bindex_t bindex)
19084 + IiMustAnyLock(inode);
19085 + return au_hinode(au_ii(inode), bindex)->hi_id;
19088 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19090 + IiMustAnyLock(inode);
19091 + return au_ii(inode)->ii_btop;
19094 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19096 + IiMustAnyLock(inode);
19097 + return au_ii(inode)->ii_bbot;
19100 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19102 + IiMustAnyLock(inode);
19103 + return au_ii(inode)->ii_vdir;
19106 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19108 + IiMustAnyLock(inode);
19109 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19112 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19114 + IiMustWriteLock(inode);
19115 + au_ii(inode)->ii_btop = bindex;
19118 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19120 + IiMustWriteLock(inode);
19121 + au_ii(inode)->ii_bbot = bindex;
19124 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19126 + IiMustWriteLock(inode);
19127 + au_ii(inode)->ii_vdir = vdir;
19130 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19132 + IiMustAnyLock(inode);
19133 + return au_hinode(au_ii(inode), bindex);
19136 +/* ---------------------------------------------------------------------- */
19138 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19141 + return pin->parent;
19145 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19147 + if (pin && pin->hdir)
19148 + return pin->hdir->hi_inode;
19152 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19155 + return pin->hdir;
19159 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19162 + pin->dentry = dentry;
19165 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19166 + unsigned char lflag)
19170 + au_fset_pin(pin->flags, DI_LOCKED);
19172 + au_fclr_pin(pin->flags, DI_LOCKED);
19176 +#if 0 /* reserved */
19177 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19180 + dput(pin->parent);
19181 + pin->parent = dget(parent);
19186 +/* ---------------------------------------------------------------------- */
19189 +#ifdef CONFIG_AUFS_HNOTIFY
19190 +struct au_hnotify_op {
19191 + void (*ctl)(struct au_hinode *hinode, int do_set);
19192 + int (*alloc)(struct au_hinode *hinode);
19195 + * if it returns true, the caller should free hinode->hi_notify,
19196 + * otherwise ->free() frees it.
19198 + int (*free)(struct au_hinode *hinode,
19199 + struct au_hnotify *hn) __must_check;
19201 + void (*fin)(void);
19202 + int (*init)(void);
19204 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19205 + void (*fin_br)(struct au_branch *br);
19206 + int (*init_br)(struct au_branch *br, int perm);
19210 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19211 +void au_hn_free(struct au_hinode *hinode);
19212 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19213 +void au_hn_reset(struct inode *inode, unsigned int flags);
19214 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19215 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19216 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19217 +int au_hnotify_init_br(struct au_branch *br, int perm);
19218 +void au_hnotify_fin_br(struct au_branch *br);
19219 +int __init au_hnotify_init(void);
19220 +void au_hnotify_fin(void);
19223 +extern const struct au_hnotify_op au_hnotify_op;
19226 +void au_hn_init(struct au_hinode *hinode)
19228 + hinode->hi_notify = NULL;
19231 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19233 + return hinode->hi_notify;
19237 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19238 + struct au_hinode *hinode __maybe_unused,
19239 + struct inode *inode __maybe_unused)
19240 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19241 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19242 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19243 + int do_set __maybe_unused)
19244 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19245 + unsigned int flags __maybe_unused)
19246 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19247 + struct au_branch *br __maybe_unused,
19248 + int perm __maybe_unused)
19249 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19250 + int perm __maybe_unused)
19251 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19252 +AuStubInt0(__init au_hnotify_init, void)
19253 +AuStubVoid(au_hnotify_fin, void)
19254 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19255 +#endif /* CONFIG_AUFS_HNOTIFY */
19257 +static inline void au_hn_suspend(struct au_hinode *hdir)
19259 + au_hn_ctl(hdir, /*do_set*/0);
19262 +static inline void au_hn_resume(struct au_hinode *hdir)
19264 + au_hn_ctl(hdir, /*do_set*/1);
19267 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19269 + inode_lock(hdir->hi_inode);
19270 + au_hn_suspend(hdir);
19273 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19274 + unsigned int sc __maybe_unused)
19276 + inode_lock_nested(hdir->hi_inode, sc);
19277 + au_hn_suspend(hdir);
19280 +#if 0 /* unused */
19281 +#include "vfsub.h"
19282 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19285 + inode_lock_shared_nested(hdir->hi_inode, sc);
19286 + au_hn_suspend(hdir);
19290 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19292 + au_hn_resume(hdir);
19293 + inode_unlock(hdir->hi_inode);
19296 +#endif /* __KERNEL__ */
19297 +#endif /* __AUFS_INODE_H__ */
19298 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19299 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19300 +++ linux/fs/aufs/ioctl.c 2021-09-06 21:02:45.276825587 +0200
19302 +// SPDX-License-Identifier: GPL-2.0
19304 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19306 + * This program, aufs is free software; you can redistribute it and/or modify
19307 + * it under the terms of the GNU General Public License as published by
19308 + * the Free Software Foundation; either version 2 of the License, or
19309 + * (at your option) any later version.
19311 + * This program is distributed in the hope that it will be useful,
19312 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19313 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19314 + * GNU General Public License for more details.
19316 + * You should have received a copy of the GNU General Public License
19317 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19322 + * plink-management and readdir in userspace.
19323 + * assist the pathconf(3) wrapper library.
19325 + * File-based Hierarchical Storage Management.
19328 +#include <linux/compat.h>
19329 +#include <linux/file.h>
19332 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19335 + aufs_bindex_t wbi, bindex, bbot;
19336 + struct file *h_file;
19337 + struct super_block *sb;
19338 + struct dentry *root;
19339 + struct au_branch *br;
19340 + struct aufs_wbr_fd wbrfd = {
19341 + .oflags = au_dir_roflags,
19344 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19345 + | O_NOATIME | O_CLOEXEC;
19347 + AuDebugOn(wbrfd.oflags & ~valid);
19350 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19351 + if (unlikely(err)) {
19357 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19358 + wbrfd.oflags |= au_dir_roflags;
19359 + AuDbg("0%o\n", wbrfd.oflags);
19360 + if (unlikely(wbrfd.oflags & ~valid))
19364 + fd = get_unused_fd_flags(0);
19366 + if (unlikely(fd < 0))
19369 + h_file = ERR_PTR(-EINVAL);
19372 + sb = path->dentry->d_sb;
19373 + root = sb->s_root;
19374 + aufs_read_lock(root, AuLock_IR);
19375 + bbot = au_sbbot(sb);
19376 + if (wbrfd.brid >= 0) {
19377 + wbi = au_br_index(sb, wbrfd.brid);
19378 + if (unlikely(wbi < 0 || wbi > bbot))
19382 + h_file = ERR_PTR(-ENOENT);
19383 + br = au_sbr(sb, wbi);
19384 + if (!au_br_writable(br->br_perm)) {
19388 + bindex = wbi + 1;
19390 + for (; bindex <= bbot; bindex++) {
19391 + br = au_sbr(sb, bindex);
19392 + if (au_br_writable(br->br_perm)) {
19394 + br = au_sbr(sb, wbi);
19399 + AuDbg("wbi %d\n", wbi);
19401 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19405 + aufs_read_unlock(root, AuLock_IR);
19406 + err = PTR_ERR(h_file);
19407 + if (IS_ERR(h_file))
19410 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19411 + fd_install(fd, h_file);
19413 + goto out; /* success */
19416 + put_unused_fd(fd);
19422 +/* ---------------------------------------------------------------------- */
19424 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19427 + struct dentry *dentry;
19430 + case AUFS_CTL_RDU:
19431 + case AUFS_CTL_RDU_INO:
19432 + err = au_rdu_ioctl(file, cmd, arg);
19435 + case AUFS_CTL_WBR_FD:
19436 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19439 + case AUFS_CTL_IBUSY:
19440 + err = au_ibusy_ioctl(file, arg);
19443 + case AUFS_CTL_BRINFO:
19444 + err = au_brinfo_ioctl(file, arg);
19447 + case AUFS_CTL_FHSM_FD:
19448 + dentry = file->f_path.dentry;
19449 + if (IS_ROOT(dentry))
19450 + err = au_fhsm_fd(dentry->d_sb, arg);
19456 + /* do not call the lower */
19457 + AuDbg("0x%x\n", cmd);
19465 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19470 + case AUFS_CTL_MVDOWN:
19471 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19474 + case AUFS_CTL_WBR_FD:
19475 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19479 + /* do not call the lower */
19480 + AuDbg("0x%x\n", cmd);
19488 +#ifdef CONFIG_COMPAT
19489 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19490 + unsigned long arg)
19495 + case AUFS_CTL_RDU:
19496 + case AUFS_CTL_RDU_INO:
19497 + err = au_rdu_compat_ioctl(file, cmd, arg);
19500 + case AUFS_CTL_IBUSY:
19501 + err = au_ibusy_compat_ioctl(file, arg);
19504 + case AUFS_CTL_BRINFO:
19505 + err = au_brinfo_compat_ioctl(file, arg);
19509 + err = aufs_ioctl_dir(file, cmd, arg);
19516 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19517 + unsigned long arg)
19519 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19522 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19523 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19524 +++ linux/fs/aufs/i_op_add.c 2021-09-06 21:02:45.276825587 +0200
19526 +// SPDX-License-Identifier: GPL-2.0
19528 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19530 + * This program, aufs is free software; you can redistribute it and/or modify
19531 + * it under the terms of the GNU General Public License as published by
19532 + * the Free Software Foundation; either version 2 of the License, or
19533 + * (at your option) any later version.
19535 + * This program is distributed in the hope that it will be useful,
19536 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19537 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19538 + * GNU General Public License for more details.
19540 + * You should have received a copy of the GNU General Public License
19541 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19545 + * inode operations (add entry)
19548 +#include <linux/iversion.h>
19552 + * final procedure of adding a new entry, except link(2).
19553 + * remove whiteout, instantiate, copyup the parent dir's times and size
19554 + * and update version.
19555 + * if it failed, re-create the removed whiteout.
19557 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19558 + struct dentry *wh_dentry, struct dentry *dentry)
19561 + aufs_bindex_t bwh;
19562 + struct path h_path;
19563 + struct super_block *sb;
19564 + struct inode *inode, *h_dir;
19565 + struct dentry *wh;
19570 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19571 + IMustLock(h_dir);
19572 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19573 + bwh = au_dbwh(dentry);
19574 + h_path.dentry = wh_dentry;
19575 + h_path.mnt = au_sbr_mnt(sb, bindex);
19576 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19578 + if (unlikely(err))
19582 + inode = au_new_inode(dentry, /*must_new*/1);
19583 + if (!IS_ERR(inode)) {
19584 + d_instantiate(dentry, inode);
19585 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19587 + au_dir_ts(dir, bindex);
19588 + inode_inc_iversion(dir);
19589 + au_fhsm_wrote(sb, bindex, /*force*/0);
19590 + return 0; /* success */
19593 + err = PTR_ERR(inode);
19598 + /* dir inode is locked */
19599 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19600 + rerr = PTR_ERR(wh);
19601 + if (IS_ERR(wh)) {
19602 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19603 + dentry, err, rerr);
19612 +static int au_d_may_add(struct dentry *dentry)
19617 + if (unlikely(d_unhashed(dentry)))
19619 + if (unlikely(d_really_is_positive(dentry)))
19625 + * simple tests for the adding inode operations.
19626 + * following the checks in vfs, plus the parent-child relationship.
19628 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19629 + struct dentry *h_parent, int isdir)
19633 + struct dentry *h_dentry;
19634 + struct inode *h_inode;
19636 + err = -ENAMETOOLONG;
19637 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19640 + h_dentry = au_h_dptr(dentry, bindex);
19641 + if (d_really_is_negative(dentry)) {
19643 + if (unlikely(d_is_positive(h_dentry)))
19646 + /* rename(2) case */
19648 + if (unlikely(d_is_negative(h_dentry)))
19650 + h_inode = d_inode(h_dentry);
19651 + if (unlikely(!h_inode->i_nlink))
19654 + h_mode = h_inode->i_mode;
19657 + if (unlikely(S_ISDIR(h_mode)))
19659 + } else if (unlikely(!S_ISDIR(h_mode))) {
19666 + /* expected parent dir is locked */
19667 + if (unlikely(h_parent != h_dentry->d_parent))
19676 + * initial procedure of adding a new entry.
19677 + * prepare writable branch and the parent dir, lock it,
19678 + * and lookup whiteout for the new entry.
19680 +static struct dentry*
19681 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19682 + struct dentry *src_dentry, struct au_pin *pin,
19683 + struct au_wr_dir_args *wr_dir_args)
19685 + struct dentry *wh_dentry, *h_parent;
19686 + struct super_block *sb;
19687 + struct au_branch *br;
19689 + unsigned int udba;
19690 + aufs_bindex_t bcpup;
19692 + AuDbg("%pd\n", dentry);
19694 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19696 + wh_dentry = ERR_PTR(err);
19697 + if (unlikely(err < 0))
19700 + sb = dentry->d_sb;
19701 + udba = au_opt_udba(sb);
19702 + err = au_pin(pin, dentry, bcpup, udba,
19703 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19704 + wh_dentry = ERR_PTR(err);
19705 + if (unlikely(err))
19708 + h_parent = au_pinned_h_parent(pin);
19709 + if (udba != AuOpt_UDBA_NONE
19710 + && au_dbtop(dentry) == bcpup)
19711 + err = au_may_add(dentry, bcpup, h_parent,
19712 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19713 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19714 + err = -ENAMETOOLONG;
19715 + wh_dentry = ERR_PTR(err);
19716 + if (unlikely(err))
19719 + br = au_sbr(sb, bcpup);
19721 + struct path tmp = {
19722 + .dentry = h_parent,
19723 + .mnt = au_br_mnt(br)
19725 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19728 + wh_dentry = NULL;
19729 + if (bcpup != au_dbwh(dentry))
19730 + goto out; /* success */
19733 + * ENAMETOOLONG here means that if we allowed create such name, then it
19734 + * would not be able to removed in the future. So we don't allow such
19735 + * name here and we don't handle ENAMETOOLONG differently here.
19737 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19740 + if (IS_ERR(wh_dentry))
19743 + return wh_dentry;
19746 +/* ---------------------------------------------------------------------- */
19748 +enum { Mknod, Symlink, Creat };
19749 +struct simple_arg {
19756 + struct vfsub_aopen_args *aopen;
19759 + const char *symname;
19768 +static int add_simple(struct inode *dir, struct dentry *dentry,
19769 + struct simple_arg *arg)
19772 + aufs_bindex_t btop;
19773 + unsigned char created;
19774 + const unsigned char try_aopen
19775 + = (arg->type == Creat && arg->u.c.try_aopen);
19776 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19777 + struct dentry *wh_dentry, *parent;
19778 + struct inode *h_dir;
19779 + struct super_block *sb;
19780 + struct au_branch *br;
19781 + /* to reduce stack size */
19783 + struct au_dtime dt;
19784 + struct au_pin pin;
19785 + struct path h_path;
19786 + struct au_wr_dir_args wr_dir_args;
19789 + AuDbg("%pd\n", dentry);
19793 + a = kmalloc(sizeof(*a), GFP_NOFS);
19794 + if (unlikely(!a))
19796 + a->wr_dir_args.force_btgt = -1;
19797 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19799 + parent = dentry->d_parent; /* dir inode is locked */
19800 + if (!try_aopen) {
19801 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19802 + if (unlikely(err))
19805 + err = au_d_may_add(dentry);
19806 + if (unlikely(err))
19809 + di_write_lock_parent(parent);
19810 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19811 + &a->pin, &a->wr_dir_args);
19812 + err = PTR_ERR(wh_dentry);
19813 + if (IS_ERR(wh_dentry))
19816 + btop = au_dbtop(dentry);
19817 + sb = dentry->d_sb;
19818 + br = au_sbr(sb, btop);
19819 + a->h_path.dentry = au_h_dptr(dentry, btop);
19820 + a->h_path.mnt = au_br_mnt(br);
19821 + h_dir = au_pinned_h_dir(&a->pin);
19822 + switch (arg->type) {
19824 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19825 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19826 + arg->u.c.want_excl);
19828 + if (!err && try_aopen)
19829 + aopen->file->f_mode |= FMODE_CREATED;
19832 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19833 + AuDbg("err %d\n", err);
19834 + AuDbgFile(aopen->file);
19835 + created = err >= 0
19836 + && !!(aopen->file->f_mode & FMODE_CREATED);
19840 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19844 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19851 + if (unlikely(err < 0))
19854 + err = epilog(dir, btop, wh_dentry, dentry);
19856 + goto out_unpin; /* success */
19859 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19860 + /* no delegation since it is just created */
19861 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19864 + AuIOErr("%pd revert failure(%d, %d)\n",
19865 + dentry, err, rerr);
19868 + au_dtime_revert(&a->dt);
19870 + if (try_aopen && h_dir->i_op->atomic_open
19871 + && (aopen->file->f_mode & FMODE_OPENED))
19872 + /* aopen->file is still opened */
19873 + au_lcnt_dec(&aopen->br->br_nfiles);
19876 + au_unpin(&a->pin);
19880 + di_write_unlock(parent);
19882 + if (unlikely(err)) {
19883 + au_update_dbtop(dentry);
19887 + aufs_read_unlock(dentry, AuLock_DW);
19894 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
19895 + struct dentry *dentry, umode_t mode, dev_t dev)
19897 + struct simple_arg arg = {
19904 + return add_simple(dir, dentry, &arg);
19907 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
19908 + struct dentry *dentry, const char *symname)
19910 + struct simple_arg arg = {
19912 + .u.s.symname = symname
19914 + return add_simple(dir, dentry, &arg);
19917 +int aufs_create(struct user_namespace *userns, struct inode *dir,
19918 + struct dentry *dentry, umode_t mode, bool want_excl)
19920 + struct simple_arg arg = {
19924 + .want_excl = want_excl
19927 + return add_simple(dir, dentry, &arg);
19930 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19931 + struct vfsub_aopen_args *aopen_args)
19933 + struct simple_arg arg = {
19936 + .mode = aopen_args->create_mode,
19937 + .want_excl = aopen_args->open_flag & O_EXCL,
19938 + .try_aopen = true,
19939 + .aopen = aopen_args
19942 + return add_simple(dir, dentry, &arg);
19945 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
19946 + struct dentry *dentry, umode_t mode)
19949 + aufs_bindex_t bindex;
19950 + struct super_block *sb;
19951 + struct dentry *parent, *h_parent, *h_dentry;
19952 + struct inode *h_dir, *inode;
19953 + struct vfsmount *h_mnt;
19954 + struct user_namespace *h_userns;
19955 + struct au_wr_dir_args wr_dir_args = {
19956 + .force_btgt = -1,
19957 + .flags = AuWrDir_TMPFILE
19960 + /* copy-up may happen */
19964 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19965 + if (unlikely(err))
19968 + err = au_di_init(dentry);
19969 + if (unlikely(err))
19973 + parent = d_find_any_alias(dir);
19974 + AuDebugOn(!parent);
19975 + di_write_lock_parent(parent);
19976 + if (unlikely(d_inode(parent) != dir))
19979 + err = au_digen_test(parent, au_sigen(sb));
19980 + if (unlikely(err))
19983 + bindex = au_dbtop(parent);
19984 + au_set_dbtop(dentry, bindex);
19985 + au_set_dbbot(dentry, bindex);
19986 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19988 + if (unlikely(err < 0))
19991 + err = -EOPNOTSUPP;
19992 + h_dir = au_h_iptr(dir, bindex);
19993 + if (unlikely(!h_dir->i_op->tmpfile))
19996 + h_mnt = au_sbr_mnt(sb, bindex);
19997 + err = vfsub_mnt_want_write(h_mnt);
19998 + if (unlikely(err))
20001 + h_userns = mnt_user_ns(h_mnt);
20002 + h_parent = au_h_dptr(parent, bindex);
20003 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
20004 + if (IS_ERR(h_dentry)) {
20005 + err = PTR_ERR(h_dentry);
20009 + au_set_dbtop(dentry, bindex);
20010 + au_set_dbbot(dentry, bindex);
20011 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
20012 + inode = au_new_inode(dentry, /*must_new*/1);
20013 + if (IS_ERR(inode)) {
20014 + err = PTR_ERR(inode);
20015 + au_set_h_dptr(dentry, bindex, NULL);
20016 + au_set_dbtop(dentry, -1);
20017 + au_set_dbbot(dentry, -1);
20019 + if (!inode->i_nlink)
20020 + set_nlink(inode, 1);
20021 + d_tmpfile(dentry, inode);
20022 + au_di(dentry)->di_tmpfile = 1;
20024 + /* update without i_mutex */
20025 + if (au_ibtop(dir) == au_dbtop(dentry))
20026 + au_cpup_attr_timesizes(dir);
20031 + vfsub_mnt_drop_write(h_mnt);
20033 + di_write_unlock(parent);
20035 + di_write_unlock(dentry);
20036 + if (unlikely(err)) {
20037 + au_di_fin(dentry);
20038 + dentry->d_fsdata = NULL;
20041 + si_read_unlock(sb);
20043 + inode_unlock(dir);
20047 +/* ---------------------------------------------------------------------- */
20049 +struct au_link_args {
20050 + aufs_bindex_t bdst, bsrc;
20051 + struct au_pin pin;
20052 + struct path h_path;
20053 + struct dentry *src_parent, *parent;
20056 +static int au_cpup_before_link(struct dentry *src_dentry,
20057 + struct au_link_args *a)
20060 + struct dentry *h_src_dentry;
20061 + struct au_cp_generic cpg = {
20062 + .dentry = src_dentry,
20067 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20070 + di_read_lock_parent(a->src_parent, AuLock_IR);
20071 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20072 + if (unlikely(err))
20075 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20076 + err = au_pin(&a->pin, src_dentry, a->bdst,
20077 + au_opt_udba(src_dentry->d_sb),
20078 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20079 + if (unlikely(err))
20082 + err = au_sio_cpup_simple(&cpg);
20083 + au_unpin(&a->pin);
20086 + di_read_unlock(a->src_parent, AuLock_IR);
20090 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20091 + struct au_link_args *a)
20094 + unsigned char plink;
20095 + aufs_bindex_t bbot;
20096 + struct dentry *h_src_dentry;
20097 + struct inode *h_inode, *inode, *delegated;
20098 + struct super_block *sb;
20099 + struct file *h_file;
20103 + sb = src_dentry->d_sb;
20104 + inode = d_inode(src_dentry);
20105 + if (au_ibtop(inode) <= a->bdst)
20106 + h_inode = au_h_iptr(inode, a->bdst);
20107 + if (!h_inode || !h_inode->i_nlink) {
20108 + /* copyup src_dentry as the name of dentry. */
20109 + bbot = au_dbbot(dentry);
20110 + if (bbot < a->bsrc)
20111 + au_set_dbbot(dentry, a->bsrc);
20112 + au_set_h_dptr(dentry, a->bsrc,
20113 + dget(au_h_dptr(src_dentry, a->bsrc)));
20114 + dget(a->h_path.dentry);
20115 + au_set_h_dptr(dentry, a->bdst, NULL);
20116 + AuDbg("temporary d_inode...\n");
20117 + spin_lock(&dentry->d_lock);
20118 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20119 + spin_unlock(&dentry->d_lock);
20120 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20121 + if (IS_ERR(h_file))
20122 + err = PTR_ERR(h_file);
20124 + struct au_cp_generic cpg = {
20125 + .dentry = dentry,
20130 + .flags = AuCpup_KEEPLINO
20132 + err = au_sio_cpup_simple(&cpg);
20133 + au_h_open_post(dentry, a->bsrc, h_file);
20135 + dput(a->h_path.dentry);
20136 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20138 + au_set_h_dptr(dentry, a->bdst,
20139 + a->h_path.dentry);
20141 + spin_lock(&dentry->d_lock);
20142 + dentry->d_inode = NULL; /* restore */
20143 + spin_unlock(&dentry->d_lock);
20144 + AuDbg("temporary d_inode...done\n");
20145 + au_set_h_dptr(dentry, a->bsrc, NULL);
20146 + au_set_dbbot(dentry, bbot);
20148 + /* the inode of src_dentry already exists on a.bdst branch */
20149 + h_src_dentry = d_find_alias(h_inode);
20150 + if (!h_src_dentry && au_plink_test(inode)) {
20152 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20153 + err = PTR_ERR(h_src_dentry);
20154 + if (IS_ERR(h_src_dentry))
20157 + if (unlikely(d_is_negative(h_src_dentry))) {
20158 + dput(h_src_dentry);
20159 + h_src_dentry = NULL;
20163 + if (h_src_dentry) {
20164 + delegated = NULL;
20165 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20166 + &a->h_path, &delegated);
20167 + if (unlikely(err == -EWOULDBLOCK)) {
20168 + pr_warn("cannot retry for NFSv4 delegation"
20169 + " for an internal link\n");
20172 + dput(h_src_dentry);
20174 + AuIOErr("no dentry found for hi%lu on b%d\n",
20175 + h_inode->i_ino, a->bdst);
20180 + if (!err && !plink)
20181 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20188 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20189 + struct dentry *dentry)
20192 + struct au_dtime dt;
20193 + struct au_link_args *a;
20194 + struct dentry *wh_dentry, *h_src_dentry;
20195 + struct inode *inode, *delegated;
20196 + struct super_block *sb;
20197 + struct au_wr_dir_args wr_dir_args = {
20198 + /* .force_btgt = -1, */
20199 + .flags = AuWrDir_ADD_ENTRY
20203 + inode = d_inode(src_dentry);
20204 + IMustLock(inode);
20207 + a = kzalloc(sizeof(*a), GFP_NOFS);
20208 + if (unlikely(!a))
20211 + a->parent = dentry->d_parent; /* dir inode is locked */
20212 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20213 + AuLock_NOPLM | AuLock_GEN);
20214 + if (unlikely(err))
20216 + err = au_d_linkable(src_dentry);
20217 + if (unlikely(err))
20219 + err = au_d_may_add(dentry);
20220 + if (unlikely(err))
20223 + a->src_parent = dget_parent(src_dentry);
20224 + wr_dir_args.force_btgt = au_ibtop(inode);
20226 + di_write_lock_parent(a->parent);
20227 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20228 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20230 + err = PTR_ERR(wh_dentry);
20231 + if (IS_ERR(wh_dentry))
20235 + sb = dentry->d_sb;
20236 + a->bdst = au_dbtop(dentry);
20237 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20238 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20239 + a->bsrc = au_ibtop(inode);
20240 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20241 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20242 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20243 + if (!h_src_dentry) {
20244 + a->bsrc = au_dbtop(src_dentry);
20245 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20246 + AuDebugOn(!h_src_dentry);
20247 + } else if (IS_ERR(h_src_dentry)) {
20248 + err = PTR_ERR(h_src_dentry);
20253 + * aufs doesn't touch the credential so
20254 + * security_dentry_create_files_as() is unnecessary.
20256 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20257 + if (a->bdst < a->bsrc
20258 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20259 + err = au_cpup_or_link(src_dentry, dentry, a);
20261 + delegated = NULL;
20262 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20263 + &a->h_path, &delegated);
20264 + if (unlikely(err == -EWOULDBLOCK)) {
20265 + pr_warn("cannot retry for NFSv4 delegation"
20266 + " for an internal link\n");
20270 + dput(h_src_dentry);
20273 + * copyup src_dentry to the branch we process,
20274 + * and then link(2) to it.
20276 + dput(h_src_dentry);
20277 + if (a->bdst < a->bsrc
20278 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20279 + au_unpin(&a->pin);
20280 + di_write_unlock(a->parent);
20281 + err = au_cpup_before_link(src_dentry, a);
20282 + di_write_lock_parent(a->parent);
20284 + err = au_pin(&a->pin, dentry, a->bdst,
20286 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20287 + if (unlikely(err))
20291 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20293 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20294 + delegated = NULL;
20295 + err = vfsub_link(h_src_dentry,
20296 + au_pinned_h_dir(&a->pin),
20297 + &a->h_path, &delegated);
20298 + if (unlikely(err == -EWOULDBLOCK)) {
20299 + pr_warn("cannot retry"
20300 + " for NFSv4 delegation"
20301 + " for an internal link\n");
20307 + if (unlikely(err))
20311 + a->h_path.dentry = wh_dentry;
20312 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20314 + if (unlikely(err))
20318 + au_dir_ts(dir, a->bdst);
20319 + inode_inc_iversion(dir);
20320 + inc_nlink(inode);
20321 + inode->i_ctime = dir->i_ctime;
20322 + d_instantiate(dentry, au_igrab(inode));
20323 + if (d_unhashed(a->h_path.dentry))
20324 + /* some filesystem calls d_drop() */
20326 + /* some filesystems consume an inode even hardlink */
20327 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20328 + goto out_unpin; /* success */
20331 + /* no delegation since it is just created */
20332 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20333 + /*delegated*/NULL, /*force*/0);
20334 + if (unlikely(rerr)) {
20335 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20338 + au_dtime_revert(&dt);
20340 + au_unpin(&a->pin);
20344 + di_write_unlock(a->parent);
20345 + dput(a->src_parent);
20347 + if (unlikely(err)) {
20348 + au_update_dbtop(dentry);
20351 + aufs_read_and_write_unlock2(dentry, src_dentry);
20359 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20360 + struct dentry *dentry, umode_t mode)
20363 + aufs_bindex_t bindex;
20364 + unsigned char diropq;
20365 + struct path h_path;
20366 + struct dentry *wh_dentry, *parent, *opq_dentry;
20367 + struct inode *h_inode;
20368 + struct super_block *sb;
20370 + struct au_pin pin;
20371 + struct au_dtime dt;
20372 + } *a; /* reduce the stack usage */
20373 + struct au_wr_dir_args wr_dir_args = {
20374 + .force_btgt = -1,
20375 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20381 + a = kmalloc(sizeof(*a), GFP_NOFS);
20382 + if (unlikely(!a))
20385 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20386 + if (unlikely(err))
20388 + err = au_d_may_add(dentry);
20389 + if (unlikely(err))
20392 + parent = dentry->d_parent; /* dir inode is locked */
20393 + di_write_lock_parent(parent);
20394 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20395 + &a->pin, &wr_dir_args);
20396 + err = PTR_ERR(wh_dentry);
20397 + if (IS_ERR(wh_dentry))
20400 + sb = dentry->d_sb;
20401 + bindex = au_dbtop(dentry);
20402 + h_path.dentry = au_h_dptr(dentry, bindex);
20403 + h_path.mnt = au_sbr_mnt(sb, bindex);
20404 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20405 + if (unlikely(err))
20408 + /* make the dir opaque */
20410 + h_inode = d_inode(h_path.dentry);
20412 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20413 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20414 + opq_dentry = au_diropq_create(dentry, bindex);
20415 + inode_unlock(h_inode);
20416 + err = PTR_ERR(opq_dentry);
20417 + if (IS_ERR(opq_dentry))
20419 + dput(opq_dentry);
20423 + err = epilog(dir, bindex, wh_dentry, dentry);
20426 + goto out_unpin; /* success */
20431 + AuLabel(revert opq);
20432 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20433 + rerr = au_diropq_remove(dentry, bindex);
20434 + inode_unlock(h_inode);
20436 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20437 + dentry, err, rerr);
20443 + AuLabel(revert dir);
20444 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20446 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20447 + dentry, err, rerr);
20450 + au_dtime_revert(&a->dt);
20452 + au_unpin(&a->pin);
20455 + di_write_unlock(parent);
20457 + if (unlikely(err)) {
20458 + au_update_dbtop(dentry);
20461 + aufs_read_unlock(dentry, AuLock_DW);
20467 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20468 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20469 +++ linux/fs/aufs/i_op.c 2021-09-06 21:02:45.276825587 +0200
20471 +// SPDX-License-Identifier: GPL-2.0
20473 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20475 + * This program, aufs is free software; you can redistribute it and/or modify
20476 + * it under the terms of the GNU General Public License as published by
20477 + * the Free Software Foundation; either version 2 of the License, or
20478 + * (at your option) any later version.
20480 + * This program is distributed in the hope that it will be useful,
20481 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20482 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20483 + * GNU General Public License for more details.
20485 + * You should have received a copy of the GNU General Public License
20486 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20490 + * inode operations (except add/del/rename)
20493 +#include <linux/device_cgroup.h>
20494 +#include <linux/fs_stack.h>
20495 +#include <linux/iversion.h>
20496 +#include <linux/namei.h>
20497 +#include <linux/security.h>
20500 +static int h_permission(struct inode *h_inode, int mask,
20501 + struct path *h_path, int brperm)
20504 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20505 + struct user_namespace *h_userns;
20508 + if (write_mask && IS_IMMUTABLE(h_inode))
20512 + if (((mask & MAY_EXEC)
20513 + && S_ISREG(h_inode->i_mode)
20514 + && (path_noexec(h_path)
20515 + || !(h_inode->i_mode & 0111))))
20519 + * - skip the lower fs test in the case of write to ro branch.
20520 + * - nfs dir permission write check is optimized, but a policy for
20521 + * link/rename requires a real check.
20522 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20523 + * in this case, generic_permission() returns -EOPNOTSUPP.
20525 + h_userns = mnt_user_ns(h_path->mnt);
20526 + if ((write_mask && !au_br_writable(brperm))
20527 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20528 + && write_mask && !(mask & MAY_READ))
20529 + || !h_inode->i_op->permission) {
20530 + /* AuLabel(generic_permission); */
20531 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20532 + err = generic_permission(h_userns, h_inode, mask);
20533 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20534 + err = h_inode->i_op->permission(h_userns, h_inode,
20538 + /* AuLabel(h_inode->permission); */
20539 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
20544 + err = devcgroup_inode_permission(h_inode, mask);
20546 + err = security_inode_permission(h_inode, mask);
20552 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
20556 + aufs_bindex_t bindex, bbot;
20557 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20558 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20559 + struct inode *h_inode;
20560 + struct super_block *sb;
20561 + struct au_branch *br;
20563 + /* todo: support rcu-walk? */
20564 + if (mask & MAY_NOT_BLOCK)
20567 + sb = inode->i_sb;
20568 + si_read_lock(sb, AuLock_FLUSH);
20569 + ii_read_lock_child(inode);
20570 +#if 0 /* reserved for future use */
20572 + * This test may be rather 'too much' since the test is essentially done
20573 + * in the aufs_lookup(). Theoretically it is possible that the inode
20574 + * generation doesn't match to the superblock's here. But it isn't a
20575 + * big deal I suppose.
20577 + err = au_iigen_test(inode, au_sigen(sb));
20578 + if (unlikely(err))
20584 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20585 + err = au_busy_or_stale();
20586 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20587 + if (unlikely(!h_inode
20588 + || (h_inode->i_mode & S_IFMT)
20589 + != (inode->i_mode & S_IFMT)))
20593 + bindex = au_ibtop(inode);
20594 + br = au_sbr(sb, bindex);
20595 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20598 + && !special_file(h_inode->i_mode)) {
20599 + /* test whether the upper writable branch exists */
20601 + for (; bindex >= 0; bindex--)
20602 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20610 + /* non-write to dir */
20612 + bbot = au_ibbot(inode);
20613 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20614 + h_inode = au_h_iptr(inode, bindex);
20616 + err = au_busy_or_stale();
20617 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20620 + br = au_sbr(sb, bindex);
20621 + err = h_permission(h_inode, mask, &br->br_path,
20627 + ii_read_unlock(inode);
20628 + si_read_unlock(sb);
20632 +/* ---------------------------------------------------------------------- */
20634 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20635 + unsigned int flags)
20637 + struct dentry *ret, *parent;
20638 + struct inode *inode;
20639 + struct super_block *sb;
20640 + int err, npositive;
20644 + /* todo: support rcu-walk? */
20645 + ret = ERR_PTR(-ECHILD);
20646 + if (flags & LOOKUP_RCU)
20649 + ret = ERR_PTR(-ENAMETOOLONG);
20650 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20654 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20655 + ret = ERR_PTR(err);
20656 + if (unlikely(err))
20659 + err = au_di_init(dentry);
20660 + ret = ERR_PTR(err);
20661 + if (unlikely(err))
20665 + npositive = 0; /* suppress a warning */
20666 + parent = dentry->d_parent; /* dir inode is locked */
20667 + di_read_lock_parent(parent, AuLock_IR);
20668 + err = au_alive_dir(parent);
20670 + err = au_digen_test(parent, au_sigen(sb));
20672 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20673 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20674 + AuLkup_ALLOW_NEG);
20677 + di_read_unlock(parent, AuLock_IR);
20678 + ret = ERR_PTR(err);
20679 + if (unlikely(err < 0))
20683 + inode = au_new_inode(dentry, /*must_new*/0);
20684 + if (IS_ERR(inode)) {
20685 + ret = (void *)inode;
20692 + atomic_inc(&inode->i_count);
20693 + ret = d_splice_alias(inode, dentry);
20694 +#if 0 /* reserved for future use */
20695 + if (unlikely(d_need_lookup(dentry))) {
20696 + spin_lock(&dentry->d_lock);
20697 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20698 + spin_unlock(&dentry->d_lock);
20702 + if (!IS_ERR(ret)) {
20704 + if (ret && ret != dentry)
20705 + ii_write_unlock(inode);
20707 + ii_write_unlock(inode);
20714 + di_write_unlock(dentry);
20716 + si_read_unlock(sb);
20721 +/* ---------------------------------------------------------------------- */
20724 + * very dirty and complicated aufs ->atomic_open().
20725 + * aufs_atomic_open()
20726 + * + au_aopen_or_create()
20728 + * + vfsub_atomic_open()
20729 + * + branch fs ->atomic_open()
20730 + * may call the actual 'open' for h_file
20731 + * + inc br_nfiles only if opened
20732 + * + au_aopen_no_open() or au_aopen_do_open()
20734 + * au_aopen_do_open()
20735 + * + finish_open()
20736 + * + au_do_aopen()
20737 + * + au_do_open() the body of all 'open'
20738 + * + au_do_open_nondir()
20739 + * set the passed h_file
20741 + * au_aopen_no_open()
20742 + * + finish_no_open()
20745 +struct aopen_node {
20746 + struct hlist_bl_node hblist;
20747 + struct file *file, *h_file;
20750 +static int au_do_aopen(struct inode *inode, struct file *file)
20752 + struct hlist_bl_head *aopen;
20753 + struct hlist_bl_node *pos;
20754 + struct aopen_node *node;
20755 + struct au_do_open_args args = {
20757 + .open = au_do_open_nondir
20760 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20761 + hlist_bl_lock(aopen);
20762 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20763 + if (node->file == file) {
20764 + args.h_file = node->h_file;
20767 + hlist_bl_unlock(aopen);
20768 + /* AuDebugOn(!args.h_file); */
20770 + return au_do_open(file, &args);
20773 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20774 + struct aopen_node *aopen_node)
20777 + struct hlist_bl_head *aopen;
20780 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20781 + au_hbl_add(&aopen_node->hblist, aopen);
20782 + err = finish_open(file, dentry, au_do_aopen);
20783 + au_hbl_del(&aopen_node->hblist, aopen);
20784 + /* AuDbgFile(file); */
20785 + AuDbg("%pd%s%s\n", dentry,
20786 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20787 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20793 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20799 + err = finish_no_open(file, dentry);
20805 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20806 + struct file *file, unsigned int open_flag,
20807 + umode_t create_mode)
20809 + int err, did_open;
20810 + unsigned int lkup_flags;
20811 + aufs_bindex_t bindex;
20812 + struct super_block *sb;
20813 + struct dentry *parent, *d;
20814 + struct vfsub_aopen_args args = {
20815 + .open_flag = open_flag,
20816 + .create_mode = create_mode
20818 + struct aopen_node aopen_node = {
20823 + AuDbg("open_flag 0%o\n", open_flag);
20824 + AuDbgDentry(dentry);
20827 + if (!au_di(dentry)) {
20828 + lkup_flags = LOOKUP_OPEN;
20829 + if (open_flag & O_CREAT)
20830 + lkup_flags |= LOOKUP_CREATE;
20831 + d = aufs_lookup(dir, dentry, lkup_flags);
20833 + err = PTR_ERR(d);
20838 + * obsoleted dentry found.
20839 + * another error will be returned later.
20845 + AuDbgDentry(dentry);
20848 + if (d_is_positive(dentry)
20849 + || d_unhashed(dentry)
20850 + || d_unlinked(dentry)
20851 + || !(open_flag & O_CREAT)) {
20852 + err = au_aopen_no_open(file, dentry);
20853 + goto out; /* success */
20856 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20857 + if (unlikely(err))
20860 + sb = dentry->d_sb;
20861 + parent = dentry->d_parent; /* dir is locked */
20862 + di_write_lock_parent(parent);
20863 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20864 + if (unlikely(err < 0))
20867 + AuDbgDentry(dentry);
20868 + if (d_is_positive(dentry)) {
20869 + err = au_aopen_no_open(file, dentry);
20870 + goto out_parent; /* success */
20873 + args.file = alloc_empty_file(file->f_flags, current_cred());
20874 + err = PTR_ERR(args.file);
20875 + if (IS_ERR(args.file))
20878 + bindex = au_dbtop(dentry);
20879 + err = au_aopen_or_create(dir, dentry, &args);
20881 + AuDbgFile(args.file);
20882 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20883 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20886 + args.file = NULL;
20888 + di_write_unlock(parent);
20889 + di_write_unlock(dentry);
20890 + if (unlikely(err < 0)) {
20897 + err = au_aopen_no_open(file, dentry);
20899 + aopen_node.h_file = args.file;
20900 + err = au_aopen_do_open(file, dentry, &aopen_node);
20902 + if (unlikely(err < 0)) {
20906 + au_lcnt_dec(&args.br->br_nfiles);
20908 + goto out_sb; /* success */
20911 + di_write_unlock(parent);
20912 + di_write_unlock(dentry);
20914 + si_read_unlock(sb);
20922 +/* ---------------------------------------------------------------------- */
20924 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20925 + const unsigned char add_entry, aufs_bindex_t bcpup,
20926 + aufs_bindex_t btop)
20929 + struct dentry *h_parent;
20930 + struct inode *h_dir;
20933 + IMustLock(d_inode(parent));
20935 + di_write_lock_parent(parent);
20938 + if (!au_h_dptr(parent, bcpup)) {
20939 + if (btop > bcpup)
20940 + err = au_cpup_dirs(dentry, bcpup);
20941 + else if (btop < bcpup)
20942 + err = au_cpdown_dirs(dentry, bcpup);
20946 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20947 + h_parent = au_h_dptr(parent, bcpup);
20948 + h_dir = d_inode(h_parent);
20949 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20950 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20951 + /* todo: no unlock here */
20952 + inode_unlock_shared(h_dir);
20954 + AuDbg("bcpup %d\n", bcpup);
20956 + if (d_really_is_negative(dentry))
20957 + au_set_h_dptr(dentry, btop, NULL);
20958 + au_update_dbrange(dentry, /*do_put_zero*/0);
20963 + di_write_unlock(parent);
20965 + err = bcpup; /* success */
20972 + * decide the branch and the parent dir where we will create a new entry.
20973 + * returns new bindex or an error.
20974 + * copyup the parent dir if needed.
20976 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20977 + struct au_wr_dir_args *args)
20980 + unsigned int flags;
20981 + aufs_bindex_t bcpup, btop, src_btop;
20982 + const unsigned char add_entry
20983 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20984 + | au_ftest_wrdir(args->flags, TMPFILE);
20985 + struct super_block *sb;
20986 + struct dentry *parent;
20987 + struct au_sbinfo *sbinfo;
20989 + sb = dentry->d_sb;
20990 + sbinfo = au_sbi(sb);
20991 + parent = dget_parent(dentry);
20992 + btop = au_dbtop(dentry);
20994 + if (args->force_btgt < 0) {
20995 + if (src_dentry) {
20996 + src_btop = au_dbtop(src_dentry);
20997 + if (src_btop < btop)
20998 + bcpup = src_btop;
20999 + } else if (add_entry) {
21001 + if (au_ftest_wrdir(args->flags, ISDIR))
21002 + au_fset_wbr(flags, DIR);
21003 + err = AuWbrCreate(sbinfo, dentry, flags);
21007 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
21009 + err = AuWbrCopyup(sbinfo, dentry);
21011 + if (!IS_ROOT(dentry)) {
21012 + di_read_lock_parent(parent, !AuLock_IR);
21013 + err = AuWbrCopyup(sbinfo, dentry);
21014 + di_read_unlock(parent, !AuLock_IR);
21016 + err = AuWbrCopyup(sbinfo, dentry);
21019 + if (unlikely(err < 0))
21023 + bcpup = args->force_btgt;
21024 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21027 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21029 + if (bcpup == btop)
21030 + goto out; /* success */
21032 + /* copyup the new parent into the branch we process */
21033 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21035 + if (d_really_is_negative(dentry)) {
21036 + au_set_h_dptr(dentry, btop, NULL);
21037 + au_set_dbtop(dentry, bcpup);
21038 + au_set_dbbot(dentry, bcpup);
21040 + AuDebugOn(add_entry
21041 + && !au_ftest_wrdir(args->flags, TMPFILE)
21042 + && !au_h_dptr(dentry, bcpup));
21050 +/* ---------------------------------------------------------------------- */
21052 +void au_pin_hdir_unlock(struct au_pin *p)
21055 + au_hn_inode_unlock(p->hdir);
21058 +int au_pin_hdir_lock(struct au_pin *p)
21066 + /* even if an error happens later, keep this lock */
21067 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21070 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21075 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21076 + p->h_parent, p->br);
21082 +int au_pin_hdir_relock(struct au_pin *p)
21085 + struct inode *h_i;
21086 + struct dentry *h_d[] = {
21091 + err = au_pin_hdir_lock(p);
21092 + if (unlikely(err))
21095 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21098 + if (d_is_positive(h_d[i])) {
21099 + h_i = d_inode(h_d[i]);
21100 + err = !h_i->i_nlink;
21108 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21110 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21113 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21116 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21117 + p->lsc_hi, 0, NULL, _RET_IP_);
21118 + au_pin_hdir_set_owner(p, current);
21122 +void au_pin_hdir_release(struct au_pin *p)
21125 + au_pin_hdir_set_owner(p, p->task);
21126 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21130 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21132 + if (pin && pin->parent)
21133 + return au_h_dptr(pin->parent, pin->bindex);
21137 +void au_unpin(struct au_pin *p)
21140 + au_pin_hdir_unlock(p);
21141 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21142 + vfsub_mnt_drop_write(p->h_mnt);
21146 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21147 + di_read_unlock(p->parent, AuLock_IR);
21148 + iput(p->hdir->hi_inode);
21150 + p->parent = NULL;
21153 + /* do not clear p->task */
21156 +int au_do_pin(struct au_pin *p)
21159 + struct super_block *sb;
21160 + struct inode *h_dir;
21163 + sb = p->dentry->d_sb;
21164 + p->br = au_sbr(sb, p->bindex);
21165 + if (IS_ROOT(p->dentry)) {
21166 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21167 + p->h_mnt = au_br_mnt(p->br);
21168 + err = vfsub_mnt_want_write(p->h_mnt);
21169 + if (unlikely(err)) {
21170 + au_fclr_pin(p->flags, MNT_WRITE);
21177 + p->h_dentry = NULL;
21178 + if (p->bindex <= au_dbbot(p->dentry))
21179 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21181 + p->parent = dget_parent(p->dentry);
21182 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21183 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21186 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21187 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21189 + h_dir = p->hdir->hi_inode;
21193 + * if DI_LOCKED is not set, then p->parent may be different
21194 + * and h_parent can be NULL.
21196 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21198 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21199 + di_read_unlock(p->parent, AuLock_IR);
21201 + p->parent = NULL;
21205 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21206 + p->h_mnt = au_br_mnt(p->br);
21207 + err = vfsub_mnt_want_write(p->h_mnt);
21208 + if (unlikely(err)) {
21209 + au_fclr_pin(p->flags, MNT_WRITE);
21210 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21211 + di_read_unlock(p->parent, AuLock_IR);
21213 + p->parent = NULL;
21219 + err = au_pin_hdir_lock(p);
21221 + goto out; /* success */
21226 + pr_err("err %d\n", err);
21227 + err = au_busy_or_stale();
21232 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21233 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21234 + unsigned int udba, unsigned char flags)
21236 + p->dentry = dentry;
21238 + p->lsc_di = lsc_di;
21239 + p->lsc_hi = lsc_hi;
21240 + p->flags = flags;
21241 + p->bindex = bindex;
21243 + p->parent = NULL;
21247 + p->h_dentry = NULL;
21248 + p->h_parent = NULL;
21250 + p->task = current;
21253 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21254 + unsigned int udba, unsigned char flags)
21256 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21258 + return au_do_pin(pin);
21261 +/* ---------------------------------------------------------------------- */
21264 + * ->setattr() and ->getattr() are called in various cases.
21265 + * chmod, stat: dentry is revalidated.
21266 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21268 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21270 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21271 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21274 + struct dentry *parent;
21277 + if (au_digen_test(dentry, sigen)) {
21278 + parent = dget_parent(dentry);
21279 + di_read_lock_parent(parent, AuLock_IR);
21280 + err = au_refresh_dentry(dentry, parent);
21281 + di_read_unlock(parent, AuLock_IR);
21289 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21290 + struct au_icpup_args *a)
21294 + aufs_bindex_t btop, ibtop;
21295 + struct dentry *hi_wh, *parent;
21296 + struct inode *inode;
21297 + struct au_wr_dir_args wr_dir_args = {
21298 + .force_btgt = -1,
21302 + if (d_is_dir(dentry))
21303 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21304 + /* plink or hi_wh() case */
21305 + btop = au_dbtop(dentry);
21306 + inode = d_inode(dentry);
21307 + ibtop = au_ibtop(inode);
21308 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21309 + wr_dir_args.force_btgt = ibtop;
21310 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21311 + if (unlikely(err < 0))
21315 + au_fset_icpup(a->flags, DID_CPUP);
21318 + a->pin_flags = AuPin_MNT_WRITE;
21320 + if (!IS_ROOT(dentry)) {
21321 + au_fset_pin(a->pin_flags, DI_LOCKED);
21322 + parent = dget_parent(dentry);
21323 + di_write_lock_parent(parent);
21326 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21327 + if (unlikely(err))
21331 + a->h_path.dentry = au_h_dptr(dentry, btop);
21332 + a->h_inode = d_inode(a->h_path.dentry);
21333 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21334 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21335 + if (ia->ia_size < i_size_read(a->h_inode))
21336 + sz = ia->ia_size;
21337 + inode_unlock_shared(a->h_inode);
21341 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21342 + hi_wh = au_hi_wh(inode, a->btgt);
21344 + struct au_cp_generic cpg = {
21345 + .dentry = dentry,
21351 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21352 + if (unlikely(err))
21354 + hi_wh = au_hi_wh(inode, a->btgt);
21355 + /* todo: revalidate hi_wh? */
21360 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21361 + di_downgrade_lock(parent, AuLock_IR);
21365 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21366 + goto out; /* success */
21368 + if (!d_unhashed(dentry)) {
21369 + struct au_cp_generic cpg = {
21370 + .dentry = dentry,
21375 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21377 + err = au_sio_cpup_simple(&cpg);
21379 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21380 + } else if (!hi_wh)
21381 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21383 + a->h_path.dentry = hi_wh; /* do not dget here */
21386 + a->h_inode = d_inode(a->h_path.dentry);
21388 + goto out; /* success */
21389 + au_unpin(&a->pin);
21392 + di_write_unlock(parent);
21397 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21401 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
21402 + struct iattr *ia)
21405 + struct inode *inode, *delegated;
21406 + struct super_block *sb;
21407 + struct file *file;
21408 + struct au_icpup_args *a;
21409 + struct user_namespace *h_userns;
21411 + inode = d_inode(dentry);
21412 + IMustLock(inode);
21414 + err = setattr_prepare(userns, dentry, ia);
21415 + if (unlikely(err))
21419 + a = kzalloc(sizeof(*a), GFP_NOFS);
21420 + if (unlikely(!a))
21423 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21424 + ia->ia_valid &= ~ATTR_MODE;
21427 + sb = dentry->d_sb;
21428 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21429 + if (unlikely(err))
21432 + if (ia->ia_valid & ATTR_FILE) {
21433 + /* currently ftruncate(2) only */
21434 + AuDebugOn(!d_is_reg(dentry));
21435 + file = ia->ia_file;
21436 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21438 + if (unlikely(err))
21440 + ia->ia_file = au_hf_top(file);
21441 + a->udba = AuOpt_UDBA_NONE;
21443 + /* fchmod() doesn't pass ia_file */
21444 + a->udba = au_opt_udba(sb);
21445 + di_write_lock_child(dentry);
21446 + /* no d_unlinked(), to set UDBA_NONE for root */
21447 + if (d_unhashed(dentry))
21448 + a->udba = AuOpt_UDBA_NONE;
21449 + if (a->udba != AuOpt_UDBA_NONE) {
21450 + AuDebugOn(IS_ROOT(dentry));
21451 + err = au_reval_for_attr(dentry, au_sigen(sb));
21452 + if (unlikely(err))
21457 + err = au_pin_and_icpup(dentry, ia, a);
21458 + if (unlikely(err < 0))
21460 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21461 + ia->ia_file = NULL;
21462 + ia->ia_valid &= ~ATTR_FILE;
21465 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21466 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21467 + == (ATTR_MODE | ATTR_CTIME)) {
21468 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21469 + if (unlikely(err))
21471 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21472 + && (ia->ia_valid & ATTR_CTIME)) {
21473 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21474 + if (unlikely(err))
21478 + if (ia->ia_valid & ATTR_SIZE) {
21481 + if (ia->ia_size < i_size_read(inode))
21483 + truncate_setsize(inode, ia->ia_size);
21486 + if (ia->ia_valid & ATTR_FILE)
21488 + inode_unlock(a->h_inode);
21489 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21490 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21492 + delegated = NULL;
21494 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21496 + err = break_deleg_wait(&delegated);
21504 + * regardless aufs 'acl' option setting.
21505 + * why don't all acl-aware fs call this func from their ->setattr()?
21507 + if (!err && (ia->ia_valid & ATTR_MODE)) {
21508 + h_userns = mnt_user_ns(a->h_path.mnt);
21509 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
21512 + au_cpup_attr_changeable(inode);
21515 + inode_unlock(a->h_inode);
21516 + au_unpin(&a->pin);
21517 + if (unlikely(err))
21518 + au_update_dbtop(dentry);
21520 + di_write_unlock(dentry);
21522 + fi_write_unlock(file);
21523 + ia->ia_file = file;
21524 + ia->ia_valid |= ATTR_FILE;
21527 + si_read_unlock(sb);
21535 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21536 +static int au_h_path_to_set_attr(struct dentry *dentry,
21537 + struct au_icpup_args *a, struct path *h_path)
21540 + struct super_block *sb;
21542 + sb = dentry->d_sb;
21543 + a->udba = au_opt_udba(sb);
21544 + /* no d_unlinked(), to set UDBA_NONE for root */
21545 + if (d_unhashed(dentry))
21546 + a->udba = AuOpt_UDBA_NONE;
21547 + if (a->udba != AuOpt_UDBA_NONE) {
21548 + AuDebugOn(IS_ROOT(dentry));
21549 + err = au_reval_for_attr(dentry, au_sigen(sb));
21550 + if (unlikely(err))
21553 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21554 + if (unlikely(err < 0))
21557 + h_path->dentry = a->h_path.dentry;
21558 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21564 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21565 + struct au_sxattr *arg)
21568 + struct path h_path;
21569 + struct super_block *sb;
21570 + struct au_icpup_args *a;
21571 + struct inode *h_inode;
21572 + struct user_namespace *h_userns;
21574 + IMustLock(inode);
21577 + a = kzalloc(sizeof(*a), GFP_NOFS);
21578 + if (unlikely(!a))
21581 + sb = dentry->d_sb;
21582 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21583 + if (unlikely(err))
21586 + h_path.dentry = NULL; /* silence gcc */
21587 + di_write_lock_child(dentry);
21588 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21589 + if (unlikely(err))
21591 + h_userns = mnt_user_ns(h_path.mnt);
21593 + inode_unlock(a->h_inode);
21594 + switch (arg->type) {
21595 + case AU_XATTR_SET:
21596 + AuDebugOn(d_is_negative(h_path.dentry));
21597 + err = vfsub_setxattr(h_userns, h_path.dentry,
21598 + arg->u.set.name, arg->u.set.value,
21599 + arg->u.set.size, arg->u.set.flags);
21602 + err = -EOPNOTSUPP;
21603 + h_inode = d_inode(h_path.dentry);
21604 + if (h_inode->i_op->set_acl) {
21605 + /* this will call posix_acl_update_mode */
21606 + err = h_inode->i_op->set_acl(h_userns, h_inode,
21607 + arg->u.acl_set.acl,
21608 + arg->u.acl_set.type);
21613 + au_cpup_attr_timesizes(inode);
21615 + au_unpin(&a->pin);
21616 + if (unlikely(err))
21617 + au_update_dbtop(dentry);
21620 + di_write_unlock(dentry);
21621 + si_read_unlock(sb);
21630 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21631 + unsigned int nlink)
21635 + inode->i_mode = st->mode;
21636 + /* don't i_[ug]id_write() here */
21637 + inode->i_uid = st->uid;
21638 + inode->i_gid = st->gid;
21639 + inode->i_atime = st->atime;
21640 + inode->i_mtime = st->mtime;
21641 + inode->i_ctime = st->ctime;
21643 + au_cpup_attr_nlink(inode, /*force*/0);
21644 + if (S_ISDIR(inode->i_mode)) {
21645 + n = inode->i_nlink;
21648 + smp_mb(); /* for i_nlink */
21649 + /* 0 can happen */
21650 + set_nlink(inode, n);
21653 + spin_lock(&inode->i_lock);
21654 + inode->i_blocks = st->blocks;
21655 + i_size_write(inode, st->size);
21656 + spin_unlock(&inode->i_lock);
21660 + * common routine for aufs_getattr() and au_getxattr().
21661 + * returns zero or negative (an error).
21662 + * @dentry will be read-locked in success.
21664 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21665 + struct path *h_path, int locked)
21668 + unsigned int mnt_flags, sigen;
21669 + unsigned char udba_none;
21670 + aufs_bindex_t bindex;
21671 + struct super_block *sb, *h_sb;
21673 + h_path->mnt = NULL;
21674 + h_path->dentry = NULL;
21677 + sb = dentry->d_sb;
21678 + mnt_flags = au_mntflags(sb);
21679 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21681 + if (unlikely(locked))
21682 + goto body; /* skip locking dinfo */
21684 + /* support fstat(2) */
21685 + if (!d_unlinked(dentry) && !udba_none) {
21686 + sigen = au_sigen(sb);
21687 + err = au_digen_test(dentry, sigen);
21689 + di_read_lock_child(dentry, AuLock_IR);
21690 + err = au_dbrange_test(dentry);
21691 + if (unlikely(err)) {
21692 + di_read_unlock(dentry, AuLock_IR);
21696 + AuDebugOn(IS_ROOT(dentry));
21697 + di_write_lock_child(dentry);
21698 + err = au_dbrange_test(dentry);
21700 + err = au_reval_for_attr(dentry, sigen);
21702 + di_downgrade_lock(dentry, AuLock_IR);
21704 + di_write_unlock(dentry);
21709 + di_read_lock_child(dentry, AuLock_IR);
21713 + inode = d_inode(dentry);
21714 + if (unlikely(!inode))
21717 + bindex = au_ibtop(inode);
21718 + h_path->mnt = au_sbr_mnt(sb, bindex);
21719 + h_sb = h_path->mnt->mnt_sb;
21721 + && !au_test_fs_bad_iattr(h_sb)
21723 + goto out; /* success */
21725 + if (au_dbtop(dentry) == bindex)
21726 + h_path->dentry = au_h_dptr(dentry, bindex);
21727 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21728 + h_path->dentry = au_plink_lkup(inode, bindex);
21729 + if (IS_ERR(h_path->dentry))
21730 + /* pretending success */
21731 + h_path->dentry = NULL;
21733 + dput(h_path->dentry);
21740 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
21741 + struct kstat *st, u32 request, unsigned int query)
21744 + unsigned char positive;
21745 + struct path h_path;
21746 + struct dentry *dentry;
21747 + struct inode *inode;
21748 + struct super_block *sb;
21750 + dentry = path->dentry;
21751 + inode = d_inode(dentry);
21752 + sb = dentry->d_sb;
21753 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21754 + if (unlikely(err))
21756 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21758 + if (unlikely(err))
21760 + if (unlikely(!h_path.dentry))
21761 + /* illegally overlapped or something */
21762 + goto out_fill; /* pretending success */
21764 + positive = d_is_positive(h_path.dentry);
21766 + /* no vfsub version */
21767 + err = vfs_getattr(&h_path, st, request, query);
21770 + au_refresh_iattr(inode, st,
21771 + d_inode(h_path.dentry)->i_nlink);
21772 + goto out_fill; /* success */
21778 + generic_fillattr(userns, inode, st);
21780 + di_read_unlock(dentry, AuLock_IR);
21782 + si_read_unlock(sb);
21788 +/* ---------------------------------------------------------------------- */
21790 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21791 + struct delayed_call *done)
21794 + struct dentry *h_dentry;
21795 + struct inode *h_inode;
21797 + aufs_bindex_t bindex;
21799 + ret = NULL; /* suppress a warning */
21804 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21805 + if (unlikely(err))
21808 + err = au_d_hashed_positive(dentry);
21809 + if (unlikely(err))
21813 + inode = d_inode(dentry);
21814 + bindex = au_ibtop(inode);
21815 + h_inode = au_h_iptr(inode, bindex);
21816 + if (unlikely(!h_inode->i_op->get_link))
21821 + if (au_dbtop(dentry) <= bindex) {
21822 + h_dentry = au_h_dptr(dentry, bindex);
21827 + h_dentry = d_find_any_alias(h_inode);
21828 + if (IS_ERR(h_dentry)) {
21829 + err = PTR_ERR(h_dentry);
21833 + if (unlikely(!h_dentry))
21837 + AuDbg("%ps\n", h_inode->i_op->get_link);
21838 + AuDbgDentry(h_dentry);
21839 + ret = vfs_get_link(h_dentry, done);
21842 + err = PTR_ERR(ret);
21845 + aufs_read_unlock(dentry, AuLock_IR);
21847 + if (unlikely(err))
21848 + ret = ERR_PTR(err);
21849 + AuTraceErrPtr(ret);
21853 +/* ---------------------------------------------------------------------- */
21855 +static int au_is_special(struct inode *inode)
21857 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21860 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21864 + aufs_bindex_t bindex;
21865 + struct super_block *sb;
21866 + struct inode *h_inode;
21867 + struct vfsmount *h_mnt;
21869 + sb = inode->i_sb;
21870 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21871 + "unexpected s_flags 0x%lx", sb->s_flags);
21873 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21875 + si_read_lock(sb, AuLock_FLUSH);
21876 + ii_write_lock_child(inode);
21879 + bindex = au_ibtop(inode);
21880 + h_inode = au_h_iptr(inode, bindex);
21881 + if (!au_test_ro(sb, bindex, inode)) {
21882 + h_mnt = au_sbr_mnt(sb, bindex);
21883 + err = vfsub_mnt_want_write(h_mnt);
21885 + err = vfsub_update_time(h_inode, ts, flags);
21886 + vfsub_mnt_drop_write(h_mnt);
21888 + } else if (au_is_special(h_inode)) {
21890 + * Never copy-up here.
21891 + * These special files may already be opened and used for
21892 + * communicating. If we copied it up, then the communication
21893 + * would be corrupted.
21895 + AuWarn1("timestamps for i%lu are ignored "
21896 + "since it is on readonly branch (hi%lu).\n",
21897 + inode->i_ino, h_inode->i_ino);
21898 + } else if (flags & ~S_ATIME) {
21900 + AuIOErr1("unexpected flags 0x%x\n", flags);
21905 + au_cpup_attr_timesizes(inode);
21906 + ii_write_unlock(inode);
21907 + si_read_unlock(sb);
21910 + if (!err && (flags & S_VERSION))
21911 + inode_inc_iversion(inode);
21916 +/* ---------------------------------------------------------------------- */
21918 +/* no getattr version will be set by module.c:aufs_init() */
21919 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21921 + [AuIop_SYMLINK] = {
21922 + .permission = aufs_permission,
21923 +#ifdef CONFIG_FS_POSIX_ACL
21924 + .get_acl = aufs_get_acl,
21925 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21928 + .setattr = aufs_setattr,
21929 + .getattr = aufs_getattr,
21931 +#ifdef CONFIG_AUFS_XATTR
21932 + .listxattr = aufs_listxattr,
21935 + .get_link = aufs_get_link,
21937 + /* .update_time = aufs_update_time */
21940 + .create = aufs_create,
21941 + .lookup = aufs_lookup,
21942 + .link = aufs_link,
21943 + .unlink = aufs_unlink,
21944 + .symlink = aufs_symlink,
21945 + .mkdir = aufs_mkdir,
21946 + .rmdir = aufs_rmdir,
21947 + .mknod = aufs_mknod,
21948 + .rename = aufs_rename,
21950 + .permission = aufs_permission,
21951 +#ifdef CONFIG_FS_POSIX_ACL
21952 + .get_acl = aufs_get_acl,
21953 + .set_acl = aufs_set_acl,
21956 + .setattr = aufs_setattr,
21957 + .getattr = aufs_getattr,
21959 +#ifdef CONFIG_AUFS_XATTR
21960 + .listxattr = aufs_listxattr,
21963 + .update_time = aufs_update_time,
21964 + .atomic_open = aufs_atomic_open,
21965 + .tmpfile = aufs_tmpfile
21967 + [AuIop_OTHER] = {
21968 + .permission = aufs_permission,
21969 +#ifdef CONFIG_FS_POSIX_ACL
21970 + .get_acl = aufs_get_acl,
21971 + .set_acl = aufs_set_acl,
21974 + .setattr = aufs_setattr,
21975 + .getattr = aufs_getattr,
21977 +#ifdef CONFIG_AUFS_XATTR
21978 + .listxattr = aufs_listxattr,
21981 + .update_time = aufs_update_time
21984 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21985 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21986 +++ linux/fs/aufs/i_op_del.c 2021-09-06 21:02:45.276825587 +0200
21988 +// SPDX-License-Identifier: GPL-2.0
21990 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21992 + * This program, aufs is free software; you can redistribute it and/or modify
21993 + * it under the terms of the GNU General Public License as published by
21994 + * the Free Software Foundation; either version 2 of the License, or
21995 + * (at your option) any later version.
21997 + * This program is distributed in the hope that it will be useful,
21998 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21999 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22000 + * GNU General Public License for more details.
22002 + * You should have received a copy of the GNU General Public License
22003 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22007 + * inode operations (del entry)
22010 +#include <linux/iversion.h>
22014 + * decide if a new whiteout for @dentry is necessary or not.
22015 + * when it is necessary, prepare the parent dir for the upper branch whose
22016 + * branch index is @bcpup for creation. the actual creation of the whiteout will
22017 + * be done by caller.
22019 + * 0: wh is unnecessary
22020 + * plus: wh is necessary
22023 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
22025 + int need_wh, err;
22026 + aufs_bindex_t btop;
22027 + struct super_block *sb;
22029 + sb = dentry->d_sb;
22030 + btop = au_dbtop(dentry);
22031 + if (*bcpup < 0) {
22033 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22034 + err = AuWbrCopyup(au_sbi(sb), dentry);
22036 + if (unlikely(err < 0))
22040 + AuDebugOn(btop < *bcpup
22041 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22042 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22044 + if (*bcpup != btop) {
22045 + err = au_cpup_dirs(dentry, *bcpup);
22046 + if (unlikely(err))
22050 + struct au_dinfo *dinfo, *tmp;
22052 + need_wh = -ENOMEM;
22053 + dinfo = au_di(dentry);
22054 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22056 + au_di_cp(tmp, dinfo);
22057 + au_di_swap(tmp, dinfo);
22058 + /* returns the number of positive dentries */
22059 + need_wh = au_lkup_dentry(dentry, btop + 1,
22060 + /* AuLkup_IGNORE_PERM */ 0);
22061 + au_di_swap(tmp, dinfo);
22062 + au_rw_write_unlock(&tmp->di_rwsem);
22066 + AuDbg("need_wh %d\n", need_wh);
22074 + * simple tests for the del-entry operations.
22075 + * following the checks in vfs, plus the parent-child relationship.
22077 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22078 + struct dentry *h_parent, int isdir)
22082 + struct dentry *h_dentry, *h_latest;
22083 + struct inode *h_inode;
22084 + struct user_namespace *h_userns;
22086 + h_dentry = au_h_dptr(dentry, bindex);
22087 + if (d_really_is_positive(dentry)) {
22089 + if (unlikely(d_is_negative(h_dentry)))
22091 + h_inode = d_inode(h_dentry);
22092 + if (unlikely(!h_inode->i_nlink))
22095 + h_mode = h_inode->i_mode;
22098 + if (unlikely(S_ISDIR(h_mode)))
22100 + } else if (unlikely(!S_ISDIR(h_mode))) {
22105 + /* rename(2) case */
22107 + if (unlikely(d_is_positive(h_dentry)))
22112 + /* expected parent dir is locked */
22113 + if (unlikely(h_parent != h_dentry->d_parent))
22118 + * rmdir a dir may break the consistency on some filesystem.
22119 + * let's try heavy test.
22122 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
22123 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22124 + && au_test_h_perm(h_userns, d_inode(h_parent),
22125 + MAY_EXEC | MAY_WRITE)))
22128 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, h_parent);
22130 + if (IS_ERR(h_latest))
22132 + if (h_latest == h_dentry)
22141 + * decide the branch where we operate for @dentry. the branch index will be set
22142 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22143 + * dir for reverting.
22144 + * when a new whiteout is necessary, create it.
22146 +static struct dentry*
22147 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22148 + struct au_dtime *dt, struct au_pin *pin)
22150 + struct dentry *wh_dentry;
22151 + struct super_block *sb;
22152 + struct path h_path;
22153 + int err, need_wh;
22154 + unsigned int udba;
22155 + aufs_bindex_t bcpup;
22157 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22158 + wh_dentry = ERR_PTR(need_wh);
22159 + if (unlikely(need_wh < 0))
22162 + sb = dentry->d_sb;
22163 + udba = au_opt_udba(sb);
22165 + err = au_pin(pin, dentry, bcpup, udba,
22166 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22167 + wh_dentry = ERR_PTR(err);
22168 + if (unlikely(err))
22171 + h_path.dentry = au_pinned_h_parent(pin);
22172 + if (udba != AuOpt_UDBA_NONE
22173 + && au_dbtop(dentry) == bcpup) {
22174 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22175 + wh_dentry = ERR_PTR(err);
22176 + if (unlikely(err))
22180 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22181 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22182 + wh_dentry = NULL;
22184 + goto out; /* success, no need to create whiteout */
22186 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22187 + if (IS_ERR(wh_dentry))
22190 + /* returns with the parent is locked and wh_dentry is dget-ed */
22191 + goto out; /* success */
22196 + return wh_dentry;
22200 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22201 + * in order to be revertible and save time for removing many child whiteouts
22203 + * returns 1 when there are too many child whiteout and caller should remove
22204 + * them asynchronously. returns 0 when the number of children is enough small to
22205 + * remove now or the branch fs is a remote fs.
22206 + * otherwise return an error.
22208 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22209 + struct au_nhash *whlist, struct inode *dir)
22211 + int rmdir_later, err, dirwh;
22212 + struct dentry *h_dentry;
22213 + struct super_block *sb;
22214 + struct inode *inode;
22216 + sb = dentry->d_sb;
22217 + SiMustAnyLock(sb);
22218 + h_dentry = au_h_dptr(dentry, bindex);
22219 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22220 + if (unlikely(err))
22223 + /* stop monitoring */
22224 + inode = d_inode(dentry);
22225 + au_hn_free(au_hi(inode, bindex));
22227 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22228 + dirwh = au_sbi(sb)->si_dirwh;
22229 + rmdir_later = (dirwh <= 1);
22230 + if (!rmdir_later)
22231 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22234 + return rmdir_later;
22237 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22238 + if (unlikely(err)) {
22239 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22240 + h_dentry, bindex, err);
22250 + * final procedure for deleting a entry.
22251 + * maintain dentry and iattr.
22253 +static void epilog(struct inode *dir, struct dentry *dentry,
22254 + aufs_bindex_t bindex)
22256 + struct inode *inode;
22258 + inode = d_inode(dentry);
22260 + inode->i_ctime = dir->i_ctime;
22262 + au_dir_ts(dir, bindex);
22263 + inode_inc_iversion(dir);
22267 + * when an error happened, remove the created whiteout and revert everything.
22269 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22270 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22271 + struct dentry *dentry, struct au_dtime *dt)
22274 + struct path h_path = {
22275 + .dentry = wh_dentry,
22276 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22279 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22281 + au_set_dbwh(dentry, bwh);
22282 + au_dtime_revert(dt);
22286 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22290 +/* ---------------------------------------------------------------------- */
22292 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22295 + aufs_bindex_t bwh, bindex, btop;
22296 + struct inode *inode, *h_dir, *delegated;
22297 + struct dentry *parent, *wh_dentry;
22298 + /* to reduce stack size */
22300 + struct au_dtime dt;
22301 + struct au_pin pin;
22302 + struct path h_path;
22308 + a = kmalloc(sizeof(*a), GFP_NOFS);
22309 + if (unlikely(!a))
22312 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22313 + if (unlikely(err))
22315 + err = au_d_hashed_positive(dentry);
22316 + if (unlikely(err))
22318 + inode = d_inode(dentry);
22319 + IMustLock(inode);
22321 + if (unlikely(d_is_dir(dentry)))
22322 + goto out_unlock; /* possible? */
22324 + btop = au_dbtop(dentry);
22325 + bwh = au_dbwh(dentry);
22327 + parent = dentry->d_parent; /* dir inode is locked */
22328 + di_write_lock_parent(parent);
22329 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22331 + err = PTR_ERR(wh_dentry);
22332 + if (IS_ERR(wh_dentry))
22335 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22336 + a->h_path.dentry = au_h_dptr(dentry, btop);
22337 + dget(a->h_path.dentry);
22338 + if (bindex == btop) {
22339 + h_dir = au_pinned_h_dir(&a->pin);
22340 + delegated = NULL;
22341 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22342 + if (unlikely(err == -EWOULDBLOCK)) {
22343 + pr_warn("cannot retry for NFSv4 delegation"
22344 + " for an internal unlink\n");
22348 + /* dir inode is locked */
22349 + h_dir = d_inode(wh_dentry->d_parent);
22350 + IMustLock(h_dir);
22355 + vfsub_drop_nlink(inode);
22356 + epilog(dir, dentry, bindex);
22358 + /* update target timestamps */
22359 + if (bindex == btop) {
22360 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22362 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22364 + /* todo: this timestamp may be reverted later */
22365 + inode->i_ctime = h_dir->i_ctime;
22366 + goto out_unpin; /* success */
22373 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22380 + au_unpin(&a->pin);
22382 + dput(a->h_path.dentry);
22384 + di_write_unlock(parent);
22386 + aufs_read_unlock(dentry, AuLock_DW);
22393 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22395 + int err, rmdir_later;
22396 + aufs_bindex_t bwh, bindex, btop;
22397 + struct inode *inode;
22398 + struct dentry *parent, *wh_dentry, *h_dentry;
22399 + struct au_whtmp_rmdir *args;
22400 + /* to reduce stack size */
22402 + struct au_dtime dt;
22403 + struct au_pin pin;
22409 + a = kmalloc(sizeof(*a), GFP_NOFS);
22410 + if (unlikely(!a))
22413 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22414 + if (unlikely(err))
22416 + err = au_alive_dir(dentry);
22417 + if (unlikely(err))
22419 + inode = d_inode(dentry);
22420 + IMustLock(inode);
22422 + if (unlikely(!d_is_dir(dentry)))
22423 + goto out_unlock; /* possible? */
22426 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22427 + if (unlikely(!args))
22430 + parent = dentry->d_parent; /* dir inode is locked */
22431 + di_write_lock_parent(parent);
22432 + err = au_test_empty(dentry, &args->whlist);
22433 + if (unlikely(err))
22436 + btop = au_dbtop(dentry);
22437 + bwh = au_dbwh(dentry);
22439 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22441 + err = PTR_ERR(wh_dentry);
22442 + if (IS_ERR(wh_dentry))
22445 + h_dentry = au_h_dptr(dentry, btop);
22448 + if (bindex == btop) {
22449 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22451 + rmdir_later = err;
22455 + /* stop monitoring */
22456 + au_hn_free(au_hi(inode, btop));
22458 + /* dir inode is locked */
22459 + IMustLock(d_inode(wh_dentry->d_parent));
22464 + vfsub_dead_dir(inode);
22465 + au_set_dbdiropq(dentry, -1);
22466 + epilog(dir, dentry, bindex);
22468 + if (rmdir_later) {
22469 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22473 + goto out_unpin; /* success */
22481 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22488 + au_unpin(&a->pin);
22492 + di_write_unlock(parent);
22494 + au_whtmp_rmdir_free(args);
22496 + aufs_read_unlock(dentry, AuLock_DW);
22503 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22504 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22505 +++ linux/fs/aufs/i_op_ren.c 2021-09-06 21:02:45.276825587 +0200
22507 +// SPDX-License-Identifier: GPL-2.0
22509 + * Copyright (C) 2005-2021 Junjiro R. Okajima
22511 + * This program, aufs is free software; you can redistribute it and/or modify
22512 + * it under the terms of the GNU General Public License as published by
22513 + * the Free Software Foundation; either version 2 of the License, or
22514 + * (at your option) any later version.
22516 + * This program is distributed in the hope that it will be useful,
22517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22519 + * GNU General Public License for more details.
22521 + * You should have received a copy of the GNU General Public License
22522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22526 + * inode operation (rename entry)
22527 + * todo: this is crazy monster
22530 +#include <linux/iversion.h>
22533 +enum { AuSRC, AuDST, AuSrcDst };
22534 +enum { AuPARENT, AuCHILD, AuParentChild };
22536 +#define AuRen_ISDIR_SRC 1
22537 +#define AuRen_ISDIR_DST (1 << 1)
22538 +#define AuRen_ISSAMEDIR (1 << 2)
22539 +#define AuRen_WHSRC (1 << 3)
22540 +#define AuRen_WHDST (1 << 4)
22541 +#define AuRen_MNT_WRITE (1 << 5)
22542 +#define AuRen_DT_DSTDIR (1 << 6)
22543 +#define AuRen_DIROPQ_SRC (1 << 7)
22544 +#define AuRen_DIROPQ_DST (1 << 8)
22545 +#define AuRen_DIRREN (1 << 9)
22546 +#define AuRen_DROPPED_SRC (1 << 10)
22547 +#define AuRen_DROPPED_DST (1 << 11)
22548 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22549 +#define au_fset_ren(flags, name) \
22550 + do { (flags) |= AuRen_##name; } while (0)
22551 +#define au_fclr_ren(flags, name) \
22552 + do { (flags) &= ~AuRen_##name; } while (0)
22554 +#ifndef CONFIG_AUFS_DIRREN
22555 +#undef AuRen_DIRREN
22556 +#define AuRen_DIRREN 0
22559 +struct au_ren_args {
22561 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22563 + struct inode *dir, *inode;
22564 + struct au_hinode *hdir, *hinode;
22565 + struct au_dtime dt[AuParentChild];
22566 + aufs_bindex_t btop, bdiropq;
22569 +#define src_dentry sd[AuSRC].dentry
22570 +#define src_dir sd[AuSRC].dir
22571 +#define src_inode sd[AuSRC].inode
22572 +#define src_h_dentry sd[AuSRC].h_dentry
22573 +#define src_parent sd[AuSRC].parent
22574 +#define src_h_parent sd[AuSRC].h_parent
22575 +#define src_wh_dentry sd[AuSRC].wh_dentry
22576 +#define src_hdir sd[AuSRC].hdir
22577 +#define src_hinode sd[AuSRC].hinode
22578 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22579 +#define src_dt sd[AuSRC].dt
22580 +#define src_btop sd[AuSRC].btop
22581 +#define src_bdiropq sd[AuSRC].bdiropq
22583 +#define dst_dentry sd[AuDST].dentry
22584 +#define dst_dir sd[AuDST].dir
22585 +#define dst_inode sd[AuDST].inode
22586 +#define dst_h_dentry sd[AuDST].h_dentry
22587 +#define dst_parent sd[AuDST].parent
22588 +#define dst_h_parent sd[AuDST].h_parent
22589 +#define dst_wh_dentry sd[AuDST].wh_dentry
22590 +#define dst_hdir sd[AuDST].hdir
22591 +#define dst_hinode sd[AuDST].hinode
22592 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22593 +#define dst_dt sd[AuDST].dt
22594 +#define dst_btop sd[AuDST].btop
22595 +#define dst_bdiropq sd[AuDST].bdiropq
22597 + struct dentry *h_trap;
22598 + struct au_branch *br;
22599 + struct path h_path;
22600 + struct au_nhash whlist;
22601 + aufs_bindex_t btgt, src_bwh;
22604 + unsigned short auren_flags;
22605 + unsigned char flags; /* syscall parameter */
22606 + unsigned char exchange;
22609 + struct au_whtmp_rmdir *thargs;
22610 + struct dentry *h_dst;
22611 + struct au_hinode *h_root;
22614 +/* ---------------------------------------------------------------------- */
22617 + * functions for reverting.
22618 + * when an error happened in a single rename systemcall, we should revert
22619 + * everything as if nothing happened.
22620 + * we don't need to revert the copied-up/down the parent dir since they are
22624 +#define RevertFailure(fmt, ...) do { \
22625 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22626 + ##__VA_ARGS__, err, rerr); \
22630 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22633 + struct dentry *d;
22634 +#define src_or_dst(member) a->sd[idx].member
22636 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22637 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22638 + rerr = au_diropq_remove(d, a->btgt);
22639 + au_hn_inode_unlock(src_or_dst(hinode));
22640 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22642 + RevertFailure("remove diropq %pd", d);
22644 +#undef src_or_dst_
22647 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22649 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22650 + au_ren_do_rev_diropq(err, a, AuSRC);
22651 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22652 + au_ren_do_rev_diropq(err, a, AuDST);
22655 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22658 + struct inode *delegated;
22660 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22661 + a->src_h_parent);
22662 + rerr = PTR_ERR(a->h_path.dentry);
22663 + if (IS_ERR(a->h_path.dentry)) {
22664 + RevertFailure("lkup one %pd", a->src_dentry);
22668 + delegated = NULL;
22669 + rerr = vfsub_rename(a->dst_h_dir,
22670 + au_h_dptr(a->src_dentry, a->btgt),
22671 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22672 + if (unlikely(rerr == -EWOULDBLOCK)) {
22673 + pr_warn("cannot retry for NFSv4 delegation"
22674 + " for an internal rename\n");
22677 + d_drop(a->h_path.dentry);
22678 + dput(a->h_path.dentry);
22679 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22681 + RevertFailure("rename %pd", a->src_dentry);
22684 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22687 + struct inode *delegated;
22689 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22690 + a->dst_h_parent);
22691 + rerr = PTR_ERR(a->h_path.dentry);
22692 + if (IS_ERR(a->h_path.dentry)) {
22693 + RevertFailure("lkup one %pd", a->dst_dentry);
22696 + if (d_is_positive(a->h_path.dentry)) {
22697 + d_drop(a->h_path.dentry);
22698 + dput(a->h_path.dentry);
22702 + delegated = NULL;
22703 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22704 + &delegated, a->flags);
22705 + if (unlikely(rerr == -EWOULDBLOCK)) {
22706 + pr_warn("cannot retry for NFSv4 delegation"
22707 + " for an internal rename\n");
22710 + d_drop(a->h_path.dentry);
22711 + dput(a->h_path.dentry);
22713 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22715 + RevertFailure("rename %pd", a->h_dst);
22718 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22722 + a->h_path.dentry = a->src_wh_dentry;
22723 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22724 + au_set_dbwh(a->src_dentry, a->src_bwh);
22726 + RevertFailure("unlink %pd", a->src_wh_dentry);
22728 +#undef RevertFailure
22730 +/* ---------------------------------------------------------------------- */
22733 + * when we have to copyup the renaming entry, do it with the rename-target name
22734 + * in order to minimize the cost (the later actual rename is unnecessary).
22735 + * otherwise rename it on the target branch.
22737 +static int au_ren_or_cpup(struct au_ren_args *a)
22740 + struct dentry *d;
22741 + struct inode *delegated;
22743 + d = a->src_dentry;
22744 + if (au_dbtop(d) == a->btgt) {
22745 + a->h_path.dentry = a->dst_h_dentry;
22746 + AuDebugOn(au_dbtop(d) != a->btgt);
22747 + delegated = NULL;
22748 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22749 + a->dst_h_dir, &a->h_path, &delegated,
22751 + if (unlikely(err == -EWOULDBLOCK)) {
22752 + pr_warn("cannot retry for NFSv4 delegation"
22753 + " for an internal rename\n");
22759 + if (!err && a->h_dst)
22760 + /* it will be set to dinfo later */
22766 +/* cf. aufs_rmdir() */
22767 +static int au_ren_del_whtmp(struct au_ren_args *a)
22770 + struct inode *dir;
22772 + dir = a->dst_dir;
22773 + SiMustAnyLock(dir->i_sb);
22774 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22775 + au_sbi(dir->i_sb)->si_dirwh)
22776 + || au_test_fs_remote(a->h_dst->d_sb)) {
22777 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22778 + if (unlikely(err))
22779 + pr_warn("failed removing whtmp dir %pd (%d), "
22780 + "ignored.\n", a->h_dst, err);
22782 + au_nhash_wh_free(&a->thargs->whlist);
22783 + a->thargs->whlist = a->whlist;
22784 + a->whlist.nh_num = 0;
22785 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22787 + a->thargs = NULL;
22793 +/* make it 'opaque' dir. */
22794 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22797 + struct dentry *d, *diropq;
22798 +#define src_or_dst(member) a->sd[idx].member
22801 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22802 + src_or_dst(bdiropq) = au_dbdiropq(d);
22803 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22804 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22805 + diropq = au_diropq_create(d, a->btgt);
22806 + au_hn_inode_unlock(src_or_dst(hinode));
22807 + if (IS_ERR(diropq))
22808 + err = PTR_ERR(diropq);
22812 +#undef src_or_dst_
22816 +static int au_ren_diropq(struct au_ren_args *a)
22819 + unsigned char always;
22820 + struct dentry *d;
22823 + d = a->dst_dentry; /* already renamed on the branch */
22824 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22825 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22826 + && !au_ftest_ren(a->auren_flags, DIRREN)
22827 + && a->btgt != au_dbdiropq(a->src_dentry)
22828 + && (a->dst_wh_dentry
22829 + || a->btgt <= au_dbdiropq(d)
22830 + /* hide the lower to keep xino */
22831 + /* the lowers may not be a dir, but we hide them anyway */
22832 + || a->btgt < au_dbbot(d)
22835 + err = au_ren_do_diropq(a, AuSRC);
22836 + if (unlikely(err))
22838 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22840 + if (!a->exchange)
22841 + goto out; /* success */
22843 + d = a->src_dentry; /* already renamed on the branch */
22844 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22845 + && a->btgt != au_dbdiropq(a->dst_dentry)
22846 + && (a->btgt < au_dbdiropq(d)
22847 + || a->btgt < au_dbbot(d)
22849 + AuDbgDentry(a->src_dentry);
22850 + AuDbgDentry(a->dst_dentry);
22851 + err = au_ren_do_diropq(a, AuDST);
22852 + if (unlikely(err))
22853 + goto out_rev_src;
22854 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22856 + goto out; /* success */
22859 + AuDbg("err %d, reverting src\n", err);
22860 + au_ren_rev_diropq(err, a);
22865 +static int do_rename(struct au_ren_args *a)
22868 + struct dentry *d, *h_d;
22870 + if (!a->exchange) {
22871 + /* prepare workqueue args for asynchronous rmdir */
22872 + h_d = a->dst_h_dentry;
22873 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22874 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22875 + && d_is_positive(h_d)) {
22877 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22879 + if (unlikely(!a->thargs))
22881 + a->h_dst = dget(h_d);
22884 + /* create whiteout for src_dentry */
22885 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22886 + a->src_bwh = au_dbwh(a->src_dentry);
22887 + AuDebugOn(a->src_bwh >= 0);
22888 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22889 + a->src_h_parent);
22890 + err = PTR_ERR(a->src_wh_dentry);
22891 + if (IS_ERR(a->src_wh_dentry))
22895 + /* lookup whiteout for dentry */
22896 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22897 + h_d = au_wh_lkup(a->dst_h_parent,
22898 + &a->dst_dentry->d_name, a->br);
22899 + err = PTR_ERR(h_d);
22902 + if (d_is_negative(h_d))
22905 + a->dst_wh_dentry = h_d;
22908 + /* rename dentry to tmpwh */
22910 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22911 + if (unlikely(err))
22914 + d = a->dst_dentry;
22915 + au_set_h_dptr(d, a->btgt, NULL);
22916 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22917 + if (unlikely(err))
22919 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22923 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22924 +#if 0 /* debugging */
22925 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22926 + && d_is_positive(a->dst_h_dentry)
22927 + && a->src_btop != a->btgt);
22930 + /* rename by vfs_rename or cpup */
22931 + err = au_ren_or_cpup(a);
22932 + if (unlikely(err))
22933 + /* leave the copied-up one */
22936 + /* make dir opaque */
22937 + err = au_ren_diropq(a);
22938 + if (unlikely(err))
22941 + /* update target timestamps */
22942 + if (a->exchange) {
22943 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22944 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22945 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22946 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22948 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22949 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22950 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22951 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22953 + if (!a->exchange) {
22954 + /* remove whiteout for dentry */
22955 + if (a->dst_wh_dentry) {
22956 + a->h_path.dentry = a->dst_wh_dentry;
22957 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22959 + if (unlikely(err))
22963 + /* remove whtmp */
22965 + au_ren_del_whtmp(a); /* ignore this error */
22967 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22970 + goto out_success;
22973 + au_ren_rev_diropq(err, a);
22975 + au_ren_rev_rename(err, a);
22979 + au_ren_rev_whtmp(err, a);
22981 + dput(a->dst_wh_dentry);
22982 + a->dst_wh_dentry = NULL;
22984 + if (a->src_wh_dentry)
22985 + au_ren_rev_whsrc(err, a);
22987 + dput(a->src_wh_dentry);
22988 + dput(a->dst_wh_dentry);
22992 + au_whtmp_rmdir_free(a->thargs);
22993 + a->thargs = NULL;
22999 +/* ---------------------------------------------------------------------- */
23002 + * test if @dentry dir can be rename destination or not.
23003 + * success means, it is a logically empty dir.
23005 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
23007 + return au_test_empty(dentry, whlist);
23011 + * test if @a->src_dentry dir can be rename source or not.
23012 + * if it can, return 0.
23014 + * - it is a logically empty dir.
23015 + * - or, it exists on writable branch and has no children including whiteouts
23016 + * on the lower branch unless DIRREN is on.
23018 +static int may_rename_srcdir(struct au_ren_args *a)
23021 + unsigned int rdhash;
23022 + aufs_bindex_t btop, btgt;
23023 + struct dentry *dentry;
23024 + struct super_block *sb;
23025 + struct au_sbinfo *sbinfo;
23027 + dentry = a->src_dentry;
23028 + sb = dentry->d_sb;
23029 + sbinfo = au_sbi(sb);
23030 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23031 + au_fset_ren(a->auren_flags, DIRREN);
23034 + btop = au_dbtop(dentry);
23035 + if (btop != btgt) {
23036 + struct au_nhash whlist;
23038 + SiMustAnyLock(sb);
23039 + rdhash = sbinfo->si_rdhash;
23041 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23043 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23044 + if (unlikely(err))
23046 + err = au_test_empty(dentry, &whlist);
23047 + au_nhash_wh_free(&whlist);
23051 + if (btop == au_dbtaildir(dentry))
23052 + return 0; /* success */
23054 + err = au_test_empty_lower(dentry);
23057 + if (err == -ENOTEMPTY) {
23058 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23061 + AuWarn1("renaming dir who has child(ren) on multiple "
23062 + "branches, is not supported\n");
23069 +/* side effect: sets whlist and h_dentry */
23070 +static int au_ren_may_dir(struct au_ren_args *a)
23073 + unsigned int rdhash;
23074 + struct dentry *d;
23076 + d = a->dst_dentry;
23077 + SiMustAnyLock(d->d_sb);
23080 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23081 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23083 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23084 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23085 + if (unlikely(err))
23088 + if (!a->exchange) {
23089 + au_set_dbtop(d, a->dst_btop);
23090 + err = may_rename_dstdir(d, &a->whlist);
23091 + au_set_dbtop(d, a->btgt);
23093 + err = may_rename_srcdir(a);
23095 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23096 + if (unlikely(err))
23099 + d = a->src_dentry;
23100 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23101 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23102 + err = may_rename_srcdir(a);
23103 + if (unlikely(err)) {
23104 + au_nhash_wh_free(&a->whlist);
23105 + a->whlist.nh_num = 0;
23112 +/* ---------------------------------------------------------------------- */
23115 + * simple tests for rename.
23116 + * following the checks in vfs, plus the parent-child relationship.
23118 +static int au_may_ren(struct au_ren_args *a)
23121 + struct inode *h_inode;
23123 + if (a->src_btop == a->btgt) {
23124 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23125 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23126 + if (unlikely(err))
23129 + if (unlikely(a->src_h_dentry == a->h_trap))
23134 + if (a->dst_btop != a->btgt)
23137 + err = -ENOTEMPTY;
23138 + if (unlikely(a->dst_h_dentry == a->h_trap))
23142 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23143 + if (d_really_is_negative(a->dst_dentry)) {
23144 + if (d_is_negative(a->dst_h_dentry))
23145 + err = au_may_add(a->dst_dentry, a->btgt,
23146 + a->dst_h_parent, isdir);
23148 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23150 + h_inode = d_inode(a->dst_h_dentry);
23151 + if (h_inode->i_nlink)
23152 + err = au_may_del(a->dst_dentry, a->btgt,
23153 + a->dst_h_parent, isdir);
23157 + if (unlikely(err == -ENOENT || err == -EEXIST))
23163 +/* ---------------------------------------------------------------------- */
23168 + * - src_dir and dir by lock_rename()
23169 + * - inode if exists
23172 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23174 + * + di_write_lock2_child()
23175 + * + di_write_lock_child()
23176 + * + ii_write_lock_child()
23177 + * + di_write_lock_child2()
23178 + * + ii_write_lock_child2()
23179 + * + src_parent and parent
23180 + * + di_write_lock_parent()
23181 + * + ii_write_lock_parent()
23182 + * + di_write_lock_parent2()
23183 + * + ii_write_lock_parent2()
23184 + * + lower src_dir and dir by vfsub_lock_rename()
23185 + * + verify the every relationships between child and parent. if any
23186 + * of them failed, unlock all and return -EBUSY.
23188 +static void au_ren_unlock(struct au_ren_args *a)
23190 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23191 + a->dst_h_parent, a->dst_hdir);
23192 + if (au_ftest_ren(a->auren_flags, DIRREN)
23194 + au_hn_inode_unlock(a->h_root);
23195 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23196 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23199 +static int au_ren_lock(struct au_ren_args *a)
23202 + unsigned int udba;
23205 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23206 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23207 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23208 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23210 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23211 + if (unlikely(err))
23213 + au_fset_ren(a->auren_flags, MNT_WRITE);
23214 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23215 + struct dentry *root;
23216 + struct inode *dir;
23219 + * sbinfo is already locked, so this ii_read_lock is
23220 + * unnecessary. but our debugging feature checks it.
23222 + root = a->src_inode->i_sb->s_root;
23223 + if (root != a->src_parent && root != a->dst_parent) {
23224 + dir = d_inode(root);
23225 + ii_read_lock_parent3(dir);
23226 + a->h_root = au_hi(dir, a->btgt);
23227 + ii_read_unlock(dir);
23228 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23231 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23232 + a->dst_h_parent, a->dst_hdir);
23233 + udba = au_opt_udba(a->src_dentry->d_sb);
23234 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23235 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23236 + err = au_busy_or_stale();
23237 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23238 + err = au_h_verify(a->src_h_dentry, udba,
23239 + d_inode(a->src_h_parent), a->src_h_parent,
23241 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23242 + err = au_h_verify(a->dst_h_dentry, udba,
23243 + d_inode(a->dst_h_parent), a->dst_h_parent,
23246 + goto out; /* success */
23248 + err = au_busy_or_stale();
23249 + au_ren_unlock(a);
23255 +/* ---------------------------------------------------------------------- */
23257 +static void au_ren_refresh_dir(struct au_ren_args *a)
23259 + struct inode *dir;
23261 + dir = a->dst_dir;
23262 + inode_inc_iversion(dir);
23263 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23264 + /* is this updating defined in POSIX? */
23265 + au_cpup_attr_timesizes(a->src_inode);
23266 + au_cpup_attr_nlink(dir, /*force*/1);
23268 + au_dir_ts(dir, a->btgt);
23270 + if (a->exchange) {
23271 + dir = a->src_dir;
23272 + inode_inc_iversion(dir);
23273 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23274 + /* is this updating defined in POSIX? */
23275 + au_cpup_attr_timesizes(a->dst_inode);
23276 + au_cpup_attr_nlink(dir, /*force*/1);
23278 + au_dir_ts(dir, a->btgt);
23281 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23284 + dir = a->src_dir;
23285 + inode_inc_iversion(dir);
23286 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23287 + au_cpup_attr_nlink(dir, /*force*/1);
23288 + au_dir_ts(dir, a->btgt);
23291 +static void au_ren_refresh(struct au_ren_args *a)
23293 + aufs_bindex_t bbot, bindex;
23294 + struct dentry *d, *h_d;
23295 + struct inode *i, *h_i;
23296 + struct super_block *sb;
23298 + d = a->dst_dentry;
23301 + /* already dget-ed by au_ren_or_cpup() */
23302 + au_set_h_dptr(d, a->btgt, a->h_dst);
23304 + i = a->dst_inode;
23306 + if (!a->exchange) {
23307 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23308 + vfsub_drop_nlink(i);
23310 + vfsub_dead_dir(i);
23311 + au_cpup_attr_timesizes(i);
23313 + au_update_dbrange(d, /*do_put_zero*/1);
23315 + au_cpup_attr_nlink(i, /*force*/1);
23318 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23319 + au_set_h_dptr(d, bindex, NULL);
23320 + bbot = au_dbbot(d);
23321 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23322 + au_set_h_dptr(d, bindex, NULL);
23323 + au_update_dbrange(d, /*do_put_zero*/0);
23327 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23328 + d_drop(a->src_dentry);
23329 + if (au_ftest_ren(a->auren_flags, DIRREN))
23330 + au_set_dbwh(a->src_dentry, -1);
23334 + d = a->src_dentry;
23335 + au_set_dbwh(d, -1);
23336 + bbot = au_dbbot(d);
23337 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23338 + h_d = au_h_dptr(d, bindex);
23340 + au_set_h_dptr(d, bindex, NULL);
23342 + au_set_dbbot(d, a->btgt);
23345 + i = a->src_inode;
23346 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23347 + return; /* success */
23349 + bbot = au_ibbot(i);
23350 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23351 + h_i = au_h_iptr(i, bindex);
23353 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23354 + /* ignore this error */
23355 + au_set_h_iptr(i, bindex, NULL, 0);
23358 + au_set_ibbot(i, a->btgt);
23361 +/* ---------------------------------------------------------------------- */
23363 +/* mainly for link(2) and rename(2) */
23364 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23366 + aufs_bindex_t bdiropq, bwh;
23367 + struct dentry *parent;
23368 + struct au_branch *br;
23370 + parent = dentry->d_parent;
23371 + IMustLock(d_inode(parent)); /* dir is locked */
23373 + bdiropq = au_dbdiropq(parent);
23374 + bwh = au_dbwh(dentry);
23375 + br = au_sbr(dentry->d_sb, btgt);
23376 + if (au_br_rdonly(br)
23377 + || (0 <= bdiropq && bdiropq < btgt)
23378 + || (0 <= bwh && bwh < btgt))
23381 + AuDbg("btgt %d\n", btgt);
23385 +/* sets src_btop, dst_btop and btgt */
23386 +static int au_ren_wbr(struct au_ren_args *a)
23389 + struct au_wr_dir_args wr_dir_args = {
23390 + /* .force_btgt = -1, */
23391 + .flags = AuWrDir_ADD_ENTRY
23394 + a->src_btop = au_dbtop(a->src_dentry);
23395 + a->dst_btop = au_dbtop(a->dst_dentry);
23396 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23397 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23398 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23399 + wr_dir_args.force_btgt = a->src_btop;
23400 + if (a->dst_inode && a->dst_btop < a->src_btop)
23401 + wr_dir_args.force_btgt = a->dst_btop;
23402 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23403 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23406 + au_update_dbtop(a->dst_dentry);
23411 +static void au_ren_dt(struct au_ren_args *a)
23413 + a->h_path.dentry = a->src_h_parent;
23414 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23415 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23416 + a->h_path.dentry = a->dst_h_parent;
23417 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23420 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23421 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23425 + a->h_path.dentry = a->src_h_dentry;
23426 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23427 + if (d_is_positive(a->dst_h_dentry)) {
23428 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23429 + a->h_path.dentry = a->dst_h_dentry;
23430 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23434 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23436 + struct dentry *h_d;
23437 + struct inode *h_inode;
23439 + au_dtime_revert(a->src_dt + AuPARENT);
23440 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23441 + au_dtime_revert(a->dst_dt + AuPARENT);
23443 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23444 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23445 + h_inode = d_inode(h_d);
23446 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23447 + au_dtime_revert(a->src_dt + AuCHILD);
23448 + inode_unlock(h_inode);
23450 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23451 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23452 + h_inode = d_inode(h_d);
23453 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23454 + au_dtime_revert(a->dst_dt + AuCHILD);
23455 + inode_unlock(h_inode);
23460 +/* ---------------------------------------------------------------------- */
23462 +int aufs_rename(struct user_namespace *userns,
23463 + struct inode *_src_dir, struct dentry *_src_dentry,
23464 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23465 + unsigned int _flags)
23467 + int err, lock_flags;
23469 + /* reduce stack space */
23470 + struct au_ren_args *a;
23471 + struct au_pin pin;
23473 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23474 + IMustLock(_src_dir);
23475 + IMustLock(_dst_dir);
23478 + if (unlikely(_flags & RENAME_WHITEOUT))
23482 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23483 + a = kzalloc(sizeof(*a), GFP_NOFS);
23484 + if (unlikely(!a))
23487 + a->flags = _flags;
23488 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23489 + && RENAME_EXCHANGE > U8_MAX);
23490 + a->exchange = _flags & RENAME_EXCHANGE;
23491 + a->src_dir = _src_dir;
23492 + a->src_dentry = _src_dentry;
23493 + a->src_inode = NULL;
23494 + if (d_really_is_positive(a->src_dentry))
23495 + a->src_inode = d_inode(a->src_dentry);
23496 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23497 + a->dst_dir = _dst_dir;
23498 + a->dst_dentry = _dst_dentry;
23499 + a->dst_inode = NULL;
23500 + if (d_really_is_positive(a->dst_dentry))
23501 + a->dst_inode = d_inode(a->dst_dentry);
23502 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23503 + if (a->dst_inode) {
23505 + * if EXCHANGE && src is non-dir && dst is dir,
23506 + * dst is not locked.
23508 + /* IMustLock(a->dst_inode); */
23509 + au_igrab(a->dst_inode);
23513 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23514 + if (d_is_dir(a->src_dentry)) {
23515 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23516 + if (unlikely(!a->exchange
23517 + && d_really_is_positive(a->dst_dentry)
23518 + && !d_is_dir(a->dst_dentry)))
23520 + lock_flags |= AuLock_DIRS;
23522 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23523 + au_fset_ren(a->auren_flags, ISDIR_DST);
23524 + if (unlikely(!a->exchange
23525 + && d_really_is_positive(a->src_dentry)
23526 + && !d_is_dir(a->src_dentry)))
23528 + lock_flags |= AuLock_DIRS;
23530 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23532 + if (unlikely(err))
23535 + err = au_d_hashed_positive(a->src_dentry);
23536 + if (unlikely(err))
23539 + if (a->dst_inode) {
23541 + * If it is a dir, VFS unhash it before this
23542 + * function. It means we cannot rely upon d_unhashed().
23544 + if (unlikely(!a->dst_inode->i_nlink))
23546 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23547 + err = au_d_hashed_positive(a->dst_dentry);
23548 + if (unlikely(err && !a->exchange))
23550 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23552 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23556 + * is it possible?
23557 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23558 + * there may exist a problem somewhere else.
23561 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23564 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23565 + di_write_lock_parent(a->dst_parent);
23567 + /* which branch we process */
23568 + err = au_ren_wbr(a);
23569 + if (unlikely(err < 0))
23571 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23572 + a->h_path.mnt = au_br_mnt(a->br);
23574 + /* are they available to be renamed */
23575 + err = au_ren_may_dir(a);
23576 + if (unlikely(err))
23577 + goto out_children;
23579 + /* prepare the writable parent dir on the same branch */
23580 + if (a->dst_btop == a->btgt) {
23581 + au_fset_ren(a->auren_flags, WHDST);
23583 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23584 + if (unlikely(err))
23585 + goto out_children;
23589 + if (!a->exchange) {
23590 + if (a->src_dir != a->dst_dir) {
23592 + * this temporary unlock is safe,
23593 + * because both dir->i_mutex are locked.
23595 + di_write_unlock(a->dst_parent);
23596 + di_write_lock_parent(a->src_parent);
23597 + err = au_wr_dir_need_wh(a->src_dentry,
23598 + au_ftest_ren(a->auren_flags,
23601 + di_write_unlock(a->src_parent);
23602 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23604 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23606 + err = au_wr_dir_need_wh(a->src_dentry,
23607 + au_ftest_ren(a->auren_flags,
23611 + if (unlikely(err < 0))
23612 + goto out_children;
23614 + au_fset_ren(a->auren_flags, WHSRC);
23617 + if (a->src_btop != a->btgt) {
23618 + err = au_pin(&pin, a->src_dentry, a->btgt,
23619 + au_opt_udba(a->src_dentry->d_sb),
23620 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23622 + struct au_cp_generic cpg = {
23623 + .dentry = a->src_dentry,
23625 + .bsrc = a->src_btop,
23628 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23630 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23631 + err = au_sio_cpup_simple(&cpg);
23634 + if (unlikely(err))
23635 + goto out_children;
23636 + a->src_btop = a->btgt;
23637 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23638 + if (!a->exchange)
23639 + au_fset_ren(a->auren_flags, WHSRC);
23643 + if (a->exchange && a->dst_inode
23644 + && a->dst_btop != a->btgt) {
23645 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23646 + au_opt_udba(a->dst_dentry->d_sb),
23647 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23649 + struct au_cp_generic cpg = {
23650 + .dentry = a->dst_dentry,
23652 + .bsrc = a->dst_btop,
23655 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23657 + err = au_sio_cpup_simple(&cpg);
23660 + if (unlikely(err))
23661 + goto out_children;
23662 + a->dst_btop = a->btgt;
23663 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23666 + /* lock them all */
23667 + err = au_ren_lock(a);
23668 + if (unlikely(err))
23669 + /* leave the copied-up one */
23670 + goto out_children;
23672 + if (!a->exchange) {
23673 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23674 + err = au_may_ren(a);
23675 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23676 + err = -ENAMETOOLONG;
23677 + if (unlikely(err))
23681 + /* store timestamps to be revertible */
23684 + /* store dirren info */
23685 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23686 + err = au_dr_rename(a->src_dentry, a->btgt,
23687 + &a->dst_dentry->d_name, &rev);
23689 + if (unlikely(err))
23694 + err = do_rename(a);
23695 + if (unlikely(err))
23698 + if (au_ftest_ren(a->auren_flags, DIRREN))
23699 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23701 + /* update dir attributes */
23702 + au_ren_refresh_dir(a);
23704 + /* dput/iput all lower dentries */
23705 + au_ren_refresh(a);
23707 + goto out_hdir; /* success */
23710 + if (au_ftest_ren(a->auren_flags, DIRREN))
23711 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23713 + au_ren_rev_dt(err, a);
23715 + au_ren_unlock(a);
23717 + au_nhash_wh_free(&a->whlist);
23718 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23719 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23720 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23721 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23725 + if (d_unhashed(a->src_dentry))
23726 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23727 + if (d_unhashed(a->dst_dentry))
23728 + au_fset_ren(a->auren_flags, DROPPED_DST);
23729 + if (!a->exchange)
23730 + d_move(a->src_dentry, a->dst_dentry);
23732 + d_exchange(a->src_dentry, a->dst_dentry);
23733 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23734 + d_drop(a->dst_dentry);
23736 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23737 + d_drop(a->src_dentry);
23739 + au_update_dbtop(a->dst_dentry);
23740 + if (!a->dst_inode)
23741 + d_drop(a->dst_dentry);
23743 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23744 + di_write_unlock(a->dst_parent);
23746 + di_write_unlock2(a->src_parent, a->dst_parent);
23748 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23750 + iput(a->dst_inode);
23752 + au_whtmp_rmdir_free(a->thargs);
23758 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23759 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23760 +++ linux/fs/aufs/Kconfig 2021-05-02 20:15:14.670004120 +0200
23762 +# SPDX-License-Identifier: GPL-2.0
23764 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23766 + Aufs is a stackable unification filesystem such as Unionfs,
23767 + which unifies several directories and provides a merged single
23769 + In the early days, aufs was entirely re-designed and
23770 + re-implemented Unionfs Version 1.x series. Introducing many
23771 + original ideas, approaches and improvements, it becomes totally
23772 + different from Unionfs while keeping the basic features.
23776 + prompt "Maximum number of branches"
23777 + default AUFS_BRANCH_MAX_127
23779 + Specifies the maximum number of branches (or member directories)
23780 + in a single aufs. The larger value consumes more system
23781 + resources and has a minor impact to performance.
23782 +config AUFS_BRANCH_MAX_127
23785 + Specifies the maximum number of branches (or member directories)
23786 + in a single aufs. The larger value consumes more system
23787 + resources and has a minor impact to performance.
23788 +config AUFS_BRANCH_MAX_511
23791 + Specifies the maximum number of branches (or member directories)
23792 + in a single aufs. The larger value consumes more system
23793 + resources and has a minor impact to performance.
23794 +config AUFS_BRANCH_MAX_1023
23797 + Specifies the maximum number of branches (or member directories)
23798 + in a single aufs. The larger value consumes more system
23799 + resources and has a minor impact to performance.
23800 +config AUFS_BRANCH_MAX_32767
23803 + Specifies the maximum number of branches (or member directories)
23804 + in a single aufs. The larger value consumes more system
23805 + resources and has a minor impact to performance.
23808 +config AUFS_SBILIST
23810 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23813 + Automatic configuration for internal use.
23814 + When aufs supports Magic SysRq or /proc, enabled automatically.
23816 +config AUFS_HNOTIFY
23817 + bool "Detect direct branch access (bypassing aufs)"
23819 + If you want to modify files on branches directly, eg. bypassing aufs,
23820 + and want aufs to detect the changes of them fully, then enable this
23821 + option and use 'udba=notify' mount option.
23822 + Currently there is only one available configuration, "fsnotify".
23823 + It will have a negative impact to the performance.
23824 + See detail in aufs.5.
23827 + prompt "method" if AUFS_HNOTIFY
23828 + default AUFS_HFSNOTIFY
23829 +config AUFS_HFSNOTIFY
23834 +config AUFS_EXPORT
23835 + bool "NFS-exportable aufs"
23836 + depends on EXPORTFS
23838 + If you want to export your mounted aufs via NFS, then enable this
23839 + option. There are several requirements for this configuration.
23840 + See detail in aufs.5.
23842 +config AUFS_INO_T_64
23844 + depends on AUFS_EXPORT
23845 + depends on 64BIT && !(ALPHA || S390)
23848 + Automatic configuration for internal use.
23849 + /* typedef unsigned long/int __kernel_ino_t */
23850 + /* alpha and s390x are int */
23853 + bool "support for XATTR/EA (including Security Labels)"
23855 + If your branch fs supports XATTR/EA and you want to make them
23856 + available in aufs too, then enable this opsion and specify the
23857 + branch attributes for EA.
23858 + See detail in aufs.5.
23861 + bool "File-based Hierarchical Storage Management"
23863 + Hierarchical Storage Management (or HSM) is a well-known feature
23864 + in the storage world. Aufs provides this feature as file-based.
23865 + with multiple branches.
23866 + These multiple branches are prioritized, ie. the topmost one
23867 + should be the fastest drive and be used heavily.
23870 + bool "Readdir in userspace"
23872 + Aufs has two methods to provide a merged view for a directory,
23873 + by a user-space library and by kernel-space natively. The latter
23874 + is always enabled but sometimes large and slow.
23875 + If you enable this option, install the library in aufs2-util
23876 + package, and set some environment variables for your readdir(3),
23877 + then the work will be handled in user-space which generally
23878 + shows better performance in most cases.
23879 + See detail in aufs.5.
23881 +config AUFS_DIRREN
23882 + bool "Workaround for rename(2)-ing a directory"
23884 + By default, aufs returns EXDEV error in renameing a dir who has
23885 + his child on the lower branch, since it is a bad idea to issue
23886 + rename(2) internally for every lower branch. But user may not
23887 + accept this behaviour. So here is a workaround to allow such
23888 + rename(2) and store some extra infromation on the writable
23889 + branch. Obviously this costs high (and I don't like it).
23890 + To use this feature, you need to enable this configuration AND
23891 + to specify the mount option `dirren.'
23892 + See details in aufs.5 and the design documents.
23895 + bool "Show whiteouts"
23897 + If you want to make the whiteouts in aufs visible, then enable
23898 + this option and specify 'shwh' mount option. Although it may
23899 + sounds like philosophy or something, but in technically it
23900 + simply shows the name of whiteout with keeping its behaviour.
23902 +config AUFS_BR_RAMFS
23903 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23905 + If you want to use ramfs as an aufs branch fs, then enable this
23906 + option. Generally tmpfs is recommended.
23907 + Aufs prohibited them to be a branch fs by default, because
23908 + initramfs becomes unusable after switch_root or something
23909 + generally. If you sets initramfs as an aufs branch and boot your
23910 + system by switch_root, you will meet a problem easily since the
23911 + files in initramfs may be inaccessible.
23912 + Unless you are going to use ramfs as an aufs branch fs without
23913 + switch_root or something, leave it N.
23915 +config AUFS_BR_FUSE
23916 + bool "Fuse fs as an aufs branch"
23917 + depends on FUSE_FS
23920 + If you want to use fuse-based userspace filesystem as an aufs
23921 + branch fs, then enable this option.
23922 + It implements the internal poll(2) operation which is
23923 + implemented by fuse only (curretnly).
23928 + Automatic configuration for internal use.
23930 +config AUFS_BR_HFSPLUS
23931 + bool "Hfsplus as an aufs branch"
23932 + depends on HFSPLUS_FS
23935 + If you want to use hfsplus fs as an aufs branch fs, then enable
23936 + this option. This option introduces a small overhead at
23937 + copying-up a file on hfsplus.
23939 +config AUFS_BDEV_LOOP
23941 + depends on BLK_DEV_LOOP
23944 + Automatic configuration for internal use.
23945 + Convert =[ym] into =y.
23948 + bool "Debug aufs"
23950 + Enable this to compile aufs internal debug code.
23951 + It will have a negative impact to the performance.
23953 +config AUFS_MAGIC_SYSRQ
23955 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23958 + Automatic configuration for internal use.
23959 + When aufs supports Magic SysRq, enabled automatically.
23961 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23962 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23963 +++ linux/fs/aufs/lcnt.h 2021-09-06 21:02:45.276825587 +0200
23965 +/* SPDX-License-Identifier: GPL-2.0 */
23967 + * Copyright (C) 2018-2021 Junjiro R. Okajima
23969 + * This program, aufs is free software; you can redistribute it and/or modify
23970 + * it under the terms of the GNU General Public License as published by
23971 + * the Free Software Foundation; either version 2 of the License, or
23972 + * (at your option) any later version.
23974 + * This program is distributed in the hope that it will be useful,
23975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23977 + * GNU General Public License for more details.
23979 + * You should have received a copy of the GNU General Public License
23980 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23984 + * simple long counter wrapper
23987 +#ifndef __AUFS_LCNT_H__
23988 +#define __AUFS_LCNT_H__
23992 +#include "debug.h"
23994 +#define AuLCntATOMIC 1
23995 +#define AuLCntPCPUCNT 2
23997 + * why does percpu_refcount require extra synchronize_rcu()s in
23998 + * au_br_do_free()
24000 +#define AuLCntPCPUREF 3
24002 +/* #define AuLCntChosen AuLCntATOMIC */
24003 +#define AuLCntChosen AuLCntPCPUCNT
24004 +/* #define AuLCntChosen AuLCntPCPUREF */
24006 +#if AuLCntChosen == AuLCntATOMIC
24007 +#include <linux/atomic.h>
24009 +typedef atomic_long_t au_lcnt_t;
24011 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24013 + atomic_long_set(cnt, 0);
24017 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24022 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24023 + int do_sync __maybe_unused)
24028 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24030 + atomic_long_inc(cnt);
24033 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24035 + atomic_long_dec(cnt);
24038 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24040 + return atomic_long_read(cnt);
24044 +#if AuLCntChosen == AuLCntPCPUCNT
24045 +#include <linux/percpu_counter.h>
24047 +typedef struct percpu_counter au_lcnt_t;
24049 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24051 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24054 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24059 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24061 + percpu_counter_destroy(cnt);
24064 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24066 + percpu_counter_inc(cnt);
24069 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24071 + percpu_counter_dec(cnt);
24074 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24078 + n = percpu_counter_sum(cnt);
24080 + if (LONG_MAX != LLONG_MAX
24082 + AuWarn1("%s\n", "wrap-around");
24088 +#if AuLCntChosen == AuLCntPCPUREF
24089 +#include <linux/percpu-refcount.h>
24091 +typedef struct percpu_ref au_lcnt_t;
24093 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24096 + release = percpu_ref_exit;
24097 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24100 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24102 + synchronize_rcu();
24105 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24107 + percpu_ref_kill(cnt);
24109 + au_lcnt_wait_for_fin(cnt);
24112 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24114 + percpu_ref_get(cnt);
24117 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24119 + percpu_ref_put(cnt);
24123 + * avoid calling this func as possible.
24125 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24129 + percpu_ref_switch_to_atomic_sync(cnt);
24130 + l = atomic_long_read(&cnt->count);
24132 + percpu_ref_switch_to_percpu(cnt);
24134 + /* percpu_ref is initialized by 1 instead of 0 */
24139 +#ifdef CONFIG_AUFS_DEBUG
24140 +#define AuLCntZero(val) do { \
24143 + AuDbg("%s = %ld\n", #val, l); \
24146 +#define AuLCntZero(val) do {} while (0)
24149 +#endif /* __KERNEL__ */
24150 +#endif /* __AUFS_LCNT_H__ */
24151 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24152 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24153 +++ linux/fs/aufs/loop.c 2021-09-06 21:02:45.276825587 +0200
24155 +// SPDX-License-Identifier: GPL-2.0
24157 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24159 + * This program, aufs is free software; you can redistribute it and/or modify
24160 + * it under the terms of the GNU General Public License as published by
24161 + * the Free Software Foundation; either version 2 of the License, or
24162 + * (at your option) any later version.
24164 + * This program is distributed in the hope that it will be useful,
24165 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24166 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24167 + * GNU General Public License for more details.
24169 + * You should have received a copy of the GNU General Public License
24170 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24174 + * support for loopback block device as a branch
24179 +/* added into drivers/block/loop.c */
24180 +static struct file *(*backing_file_func)(struct super_block *sb);
24183 + * test if two lower dentries have overlapping branches.
24185 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24187 + struct super_block *h_sb;
24188 + struct file *backing_file;
24190 + if (unlikely(!backing_file_func)) {
24191 + /* don't load "loop" module here */
24192 + backing_file_func = symbol_get(loop_backing_file);
24193 + if (unlikely(!backing_file_func))
24194 + /* "loop" module is not loaded */
24198 + h_sb = h_adding->d_sb;
24199 + backing_file = backing_file_func(h_sb);
24200 + if (!backing_file)
24203 + h_adding = backing_file->f_path.dentry;
24205 + * h_adding can be local NFS.
24206 + * in this case aufs cannot detect the loop.
24208 + if (unlikely(h_adding->d_sb == sb))
24210 + return !!au_test_subdir(h_adding, sb->s_root);
24213 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24214 +int au_test_loopback_kthread(void)
24217 + struct task_struct *tsk = current;
24218 + char c, comm[sizeof(tsk->comm)];
24221 + if (tsk->flags & PF_KTHREAD) {
24222 + get_task_comm(comm, tsk);
24224 + ret = ('0' <= c && c <= '9'
24225 + && !strncmp(comm, "loop", 4));
24231 +/* ---------------------------------------------------------------------- */
24233 +#define au_warn_loopback_step 16
24234 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24235 +static unsigned long *au_warn_loopback_array;
24237 +void au_warn_loopback(struct super_block *h_sb)
24239 + int i, new_nelem;
24240 + unsigned long *a, magic;
24241 + static DEFINE_SPINLOCK(spin);
24243 + magic = h_sb->s_magic;
24244 + spin_lock(&spin);
24245 + a = au_warn_loopback_array;
24246 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24247 + if (a[i] == magic) {
24248 + spin_unlock(&spin);
24252 + /* h_sb is new to us, print it */
24253 + if (i < au_warn_loopback_nelem) {
24258 + /* expand the array */
24259 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24260 + a = au_kzrealloc(au_warn_loopback_array,
24261 + au_warn_loopback_nelem * sizeof(unsigned long),
24262 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24263 + /*may_shrink*/0);
24265 + au_warn_loopback_nelem = new_nelem;
24266 + au_warn_loopback_array = a;
24271 + spin_unlock(&spin);
24272 + AuWarn1("realloc failed, ignored\n");
24276 + spin_unlock(&spin);
24277 + pr_warn("you may want to try another patch for loopback file "
24278 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24281 +int au_loopback_init(void)
24284 + struct super_block *sb __maybe_unused;
24286 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24289 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24290 + sizeof(unsigned long), GFP_NOFS);
24291 + if (unlikely(!au_warn_loopback_array))
24297 +void au_loopback_fin(void)
24299 + if (backing_file_func)
24300 + symbol_put(loop_backing_file);
24301 + au_kfree_try_rcu(au_warn_loopback_array);
24303 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24304 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24305 +++ linux/fs/aufs/loop.h 2021-09-06 21:02:45.276825587 +0200
24307 +/* SPDX-License-Identifier: GPL-2.0 */
24309 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24311 + * This program, aufs is free software; you can redistribute it and/or modify
24312 + * it under the terms of the GNU General Public License as published by
24313 + * the Free Software Foundation; either version 2 of the License, or
24314 + * (at your option) any later version.
24316 + * This program is distributed in the hope that it will be useful,
24317 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24318 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24319 + * GNU General Public License for more details.
24321 + * You should have received a copy of the GNU General Public License
24322 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24326 + * support for loopback mount as a branch
24329 +#ifndef __AUFS_LOOP_H__
24330 +#define __AUFS_LOOP_H__
24335 +struct super_block;
24337 +#ifdef CONFIG_AUFS_BDEV_LOOP
24338 +/* drivers/block/loop.c */
24339 +struct file *loop_backing_file(struct super_block *sb);
24342 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24343 +int au_test_loopback_kthread(void);
24344 +void au_warn_loopback(struct super_block *h_sb);
24346 +int au_loopback_init(void);
24347 +void au_loopback_fin(void);
24349 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24351 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24352 + struct dentry *h_adding)
24353 +AuStubInt0(au_test_loopback_kthread, void)
24354 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24356 +AuStubInt0(au_loopback_init, void)
24357 +AuStubVoid(au_loopback_fin, void)
24358 +#endif /* BLK_DEV_LOOP */
24360 +#endif /* __KERNEL__ */
24361 +#endif /* __AUFS_LOOP_H__ */
24362 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24363 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24364 +++ linux/fs/aufs/magic.mk 2021-05-02 20:15:14.673337458 +0200
24366 +# SPDX-License-Identifier: GPL-2.0
24368 +# defined in ${srctree}/fs/fuse/inode.c
24370 +ifdef CONFIG_FUSE_FS
24371 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24374 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24376 +ifdef CONFIG_XFS_FS
24377 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24380 +# defined in ${srctree}/fs/configfs/mount.c
24382 +ifdef CONFIG_CONFIGFS_FS
24383 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24386 +# defined in ${srctree}/fs/ubifs/ubifs.h
24388 +ifdef CONFIG_UBIFS_FS
24389 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24392 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24394 +ifdef CONFIG_HFSPLUS_FS
24395 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24397 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24398 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24399 +++ linux/fs/aufs/Makefile 2021-05-02 20:15:14.670004120 +0200
24401 +# SPDX-License-Identifier: GPL-2.0
24403 +include ${src}/magic.mk
24404 +ifeq (${CONFIG_AUFS_FS},m)
24405 +include ${src}/conf.mk
24407 +-include ${src}/priv_def.mk
24409 +# cf. include/linux/kernel.h
24411 +ccflags-y += -DDEBUG
24412 +# sparse requires the full pathname
24414 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24416 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24419 +obj-$(CONFIG_AUFS_FS) += aufs.o
24420 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24421 + wkq.o vfsub.o dcsub.o \
24422 + cpup.o whout.o wbr_policy.o \
24423 + dinfo.o dentry.o \
24425 + finfo.o file.o f_op.o \
24427 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24431 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24432 +aufs-$(CONFIG_SYSFS) += sysfs.o
24433 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24434 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24435 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24436 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24437 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24438 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24439 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24440 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24441 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24442 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24443 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24444 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24445 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24446 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24447 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24448 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24449 +++ linux/fs/aufs/module.c 2021-09-06 21:02:45.280158943 +0200
24451 +// SPDX-License-Identifier: GPL-2.0
24453 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24455 + * This program, aufs is free software; you can redistribute it and/or modify
24456 + * it under the terms of the GNU General Public License as published by
24457 + * the Free Software Foundation; either version 2 of the License, or
24458 + * (at your option) any later version.
24460 + * This program is distributed in the hope that it will be useful,
24461 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24462 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24463 + * GNU General Public License for more details.
24465 + * You should have received a copy of the GNU General Public License
24466 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24470 + * module global variables and operations
24473 +#include <linux/module.h>
24474 +#include <linux/seq_file.h>
24477 +/* shrinkable realloc */
24478 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24486 +#if 0 /* unused */
24493 + AuDebugOn(!new_sz);
24496 + diff = au_kmidx_sub(sz, new_sz);
24502 + /* expand or SLOB */
24503 + p = krealloc(p, new_sz, gfp);
24504 + else if (new_sz < sz && may_shrink) {
24508 + q = kmalloc(new_sz, gfp);
24511 + memcpy(q, p, new_sz);
24512 + au_kfree_try_rcu(p);
24523 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24526 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24527 + if (p && new_sz > nused)
24528 + memset(p + nused, 0, new_sz - nused);
24532 +/* ---------------------------------------------------------------------- */
24536 +struct kmem_cache *au_cache[AuCache_Last];
24538 +static void au_cache_fin(void)
24543 + * Make sure all delayed rcu free inodes are flushed before we
24548 + /* excluding AuCache_HNOTIFY */
24549 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24550 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24551 + kmem_cache_destroy(au_cache[i]);
24552 + au_cache[i] = NULL;
24556 +static int __init au_cache_init(void)
24558 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24559 + if (au_cache[AuCache_DINFO])
24560 + /* SLAB_DESTROY_BY_RCU */
24561 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24562 + au_icntnr_init_once);
24563 + if (au_cache[AuCache_ICNTNR])
24564 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24565 + au_fi_init_once);
24566 + if (au_cache[AuCache_FINFO])
24567 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24568 + if (au_cache[AuCache_VDIR])
24569 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24570 + if (au_cache[AuCache_DEHSTR])
24577 +/* ---------------------------------------------------------------------- */
24579 +int au_dir_roflags;
24581 +#ifdef CONFIG_AUFS_SBILIST
24583 + * iterate_supers_type() doesn't protect us from
24584 + * remounting (branch management)
24586 +struct hlist_bl_head au_sbilist;
24590 + * functions for module interface.
24592 +MODULE_LICENSE("GPL");
24593 +/* MODULE_LICENSE("GPL v2"); */
24594 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24595 +MODULE_DESCRIPTION(AUFS_NAME
24596 + " -- Advanced multi layered unification filesystem");
24597 +MODULE_VERSION(AUFS_VERSION);
24598 +MODULE_ALIAS_FS(AUFS_NAME);
24600 +/* this module parameter has no meaning when SYSFS is disabled */
24601 +int sysaufs_brs = 1;
24602 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24603 +module_param_named(brs, sysaufs_brs, int, 0444);
24605 +/* this module parameter has no meaning when USER_NS is disabled */
24607 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24608 +module_param_named(allow_userns, au_userns, bool, 0444);
24610 +/* ---------------------------------------------------------------------- */
24612 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24614 +int au_seq_path(struct seq_file *seq, struct path *path)
24618 + err = seq_path(seq, path, au_esc_chars);
24627 +/* ---------------------------------------------------------------------- */
24629 +static int __init aufs_init(void)
24634 + p = au_esc_chars;
24635 + for (i = 1; i <= ' '; i++)
24641 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24643 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24644 + for (i = 0; i < AuIop_Last; i++)
24645 + aufs_iop_nogetattr[i].getattr = NULL;
24647 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24649 + au_sbilist_init();
24650 + sysaufs_brs_init();
24653 + err = sysaufs_init();
24654 + if (unlikely(err))
24656 + err = dbgaufs_init();
24657 + if (unlikely(err))
24658 + goto out_sysaufs;
24659 + err = au_procfs_init();
24660 + if (unlikely(err))
24661 + goto out_dbgaufs;
24662 + err = au_wkq_init();
24663 + if (unlikely(err))
24665 + err = au_loopback_init();
24666 + if (unlikely(err))
24668 + err = au_hnotify_init();
24669 + if (unlikely(err))
24670 + goto out_loopback;
24671 + err = au_sysrq_init();
24672 + if (unlikely(err))
24674 + err = au_cache_init();
24675 + if (unlikely(err))
24678 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24679 + err = register_filesystem(&aufs_fs_type);
24680 + if (unlikely(err))
24683 + /* since we define pr_fmt, call printk directly */
24684 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24685 + goto out; /* success */
24692 + au_hnotify_fin();
24694 + au_loopback_fin();
24708 +static void __exit aufs_exit(void)
24710 + unregister_filesystem(&aufs_fs_type);
24713 + au_hnotify_fin();
24714 + au_loopback_fin();
24722 +module_init(aufs_init);
24723 +module_exit(aufs_exit);
24724 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24725 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24726 +++ linux/fs/aufs/module.h 2021-09-06 21:06:28.017703615 +0200
24728 +/* SPDX-License-Identifier: GPL-2.0 */
24730 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24732 + * This program, aufs is free software; you can redistribute it and/or modify
24733 + * it under the terms of the GNU General Public License as published by
24734 + * the Free Software Foundation; either version 2 of the License, or
24735 + * (at your option) any later version.
24737 + * This program is distributed in the hope that it will be useful,
24738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24740 + * GNU General Public License for more details.
24742 + * You should have received a copy of the GNU General Public License
24743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24747 + * module initialization and module-global
24750 +#ifndef __AUFS_MODULE_H__
24751 +#define __AUFS_MODULE_H__
24755 +#include <linux/slab.h>
24756 +#include "debug.h"
24757 +#include "dentry.h"
24760 +#include "inode.h"
24765 +/* module parameters */
24766 +extern int sysaufs_brs;
24767 +extern bool au_userns;
24769 +/* ---------------------------------------------------------------------- */
24771 +extern int au_dir_roflags;
24773 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24774 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24778 + * Comparing the size of the object with sizeof(struct rcu_head)
24779 + * case 1: object is always larger
24780 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24781 + * case 2: object is always smaller
24782 + * --> au_kfree_small()
24783 + * case 3: object can be any size
24784 + * --> au_kfree_try_rcu()
24787 +static inline void au_kfree_do_rcu(const void *p)
24790 + struct rcu_head rcu;
24791 + } *a = (void *)p;
24793 + kfree_rcu(a, rcu);
24796 +#define au_kfree_rcu(_p) do { \
24797 + typeof(_p) p = (_p); \
24798 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24800 + au_kfree_do_rcu(p); \
24803 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24804 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24806 +static inline void au_kfree_try_rcu(const void *p)
24810 + if (au_kfree_sz_test(p))
24811 + au_kfree_do_rcu(p);
24816 +static inline void au_kfree_small(const void *p)
24820 + AuDebugOn(au_kfree_sz_test(p));
24824 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24826 +#ifndef CONFIG_SLOB
24827 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
24829 + return -1; /* SLOB is untested */
24833 +int au_seq_path(struct seq_file *seq, struct path *path);
24835 +#ifdef CONFIG_PROC_FS
24837 +int __init au_procfs_init(void);
24838 +void au_procfs_fin(void);
24840 +AuStubInt0(au_procfs_init, void);
24841 +AuStubVoid(au_procfs_fin, void);
24844 +/* ---------------------------------------------------------------------- */
24853 + AuCache_HNOTIFY, /* must be last */
24857 +extern struct kmem_cache *au_cache[AuCache_Last];
24859 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24860 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24861 +#define AuCacheCtor(type, ctor) \
24862 + kmem_cache_create(#type, sizeof(struct type), \
24863 + __alignof__(struct type), AuCacheFlags, ctor)
24865 +#define AuCacheFuncs(name, index) \
24866 + static inline struct au_##name *au_cache_alloc_##name(void) \
24867 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24868 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24869 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24871 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24872 + { void *p = rcu; \
24873 + p -= offsetof(struct au_##name, rcu); \
24874 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24875 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24876 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24877 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24879 + static inline void au_cache_free_##name(struct au_##name *p) \
24880 + { /* au_cache_free_##name##_norcu(p); */ \
24881 + au_cache_free_##name##_rcu(p); }
24883 +AuCacheFuncs(dinfo, DINFO);
24884 +AuCacheFuncs(icntnr, ICNTNR);
24885 +AuCacheFuncs(finfo, FINFO);
24886 +AuCacheFuncs(vdir, VDIR);
24887 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24888 +#ifdef CONFIG_AUFS_HNOTIFY
24889 +AuCacheFuncs(hnotify, HNOTIFY);
24892 +#endif /* __KERNEL__ */
24893 +#endif /* __AUFS_MODULE_H__ */
24894 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24895 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24896 +++ linux/fs/aufs/mvdown.c 2021-09-06 21:02:45.280158943 +0200
24898 +// SPDX-License-Identifier: GPL-2.0
24900 + * Copyright (C) 2011-2021 Junjiro R. Okajima
24902 + * This program, aufs is free software; you can redistribute it and/or modify
24903 + * it under the terms of the GNU General Public License as published by
24904 + * the Free Software Foundation; either version 2 of the License, or
24905 + * (at your option) any later version.
24907 + * This program is distributed in the hope that it will be useful,
24908 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24909 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24910 + * GNU General Public License for more details.
24912 + * You should have received a copy of the GNU General Public License
24913 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24917 + * move-down, opposite of copy-up
24922 +struct au_mvd_args {
24924 + struct super_block *h_sb;
24925 + struct dentry *h_parent;
24926 + struct au_hinode *hdir;
24927 + struct inode *h_dir, *h_inode;
24928 + struct au_pin pin;
24929 + } info[AUFS_MVDOWN_NARRAY];
24931 + struct aufs_mvdown mvdown;
24932 + struct dentry *dentry, *parent;
24933 + struct inode *inode, *dir;
24934 + struct super_block *sb;
24935 + aufs_bindex_t bopq, bwh, bfound;
24936 + unsigned char rename_lock;
24939 +#define mvd_errno mvdown.au_errno
24940 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24941 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24942 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24943 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24945 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24946 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24947 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24948 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24949 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24950 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24952 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24953 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24954 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24955 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24956 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24957 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24959 +#define AU_MVD_PR(flag, ...) do { \
24961 + pr_err(__VA_ARGS__); \
24964 +static int find_lower_writable(struct au_mvd_args *a)
24966 + struct super_block *sb;
24967 + aufs_bindex_t bindex, bbot;
24968 + struct au_branch *br;
24971 + bindex = a->mvd_bsrc;
24972 + bbot = au_sbbot(sb);
24973 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24974 + for (bindex++; bindex <= bbot; bindex++) {
24975 + br = au_sbr(sb, bindex);
24976 + if (au_br_fhsm(br->br_perm)
24977 + && !sb_rdonly(au_br_sb(br)))
24980 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24981 + for (bindex++; bindex <= bbot; bindex++) {
24982 + br = au_sbr(sb, bindex);
24983 + if (!au_br_rdonly(br))
24987 + for (bindex++; bindex <= bbot; bindex++) {
24988 + br = au_sbr(sb, bindex);
24989 + if (!sb_rdonly(au_br_sb(br))) {
24990 + if (au_br_rdonly(br))
24992 + |= AUFS_MVDOWN_ROLOWER_R;
25000 +/* make the parent dir on bdst */
25001 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
25006 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
25007 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
25008 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
25009 + a->mvd_h_dst_parent = NULL;
25010 + if (au_dbbot(a->parent) >= a->mvd_bdst)
25011 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25012 + if (!a->mvd_h_dst_parent) {
25013 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25014 + if (unlikely(err)) {
25015 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25018 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25026 +/* lock them all */
25027 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25030 + struct dentry *h_trap;
25032 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25033 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25034 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25035 + au_opt_udba(a->sb),
25036 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25038 + if (unlikely(err)) {
25039 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25043 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25044 + a->rename_lock = 0;
25045 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25046 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25047 + au_opt_udba(a->sb),
25048 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25049 + err = au_do_pin(&a->mvd_pin_src);
25051 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25052 + if (unlikely(err)) {
25053 + AU_MVD_PR(dmsg, "pin_src failed\n");
25056 + goto out; /* success */
25059 + a->rename_lock = 1;
25060 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25061 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25062 + au_opt_udba(a->sb),
25063 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25065 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25066 + if (unlikely(err)) {
25067 + AU_MVD_PR(dmsg, "pin_src failed\n");
25068 + au_pin_hdir_lock(&a->mvd_pin_dst);
25071 + au_pin_hdir_unlock(&a->mvd_pin_src);
25072 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25073 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25075 + err = (h_trap != a->mvd_h_src_parent);
25077 + err = (h_trap != a->mvd_h_dst_parent);
25079 + BUG_ON(err); /* it should never happen */
25080 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25083 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25084 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25085 + au_pin_hdir_lock(&a->mvd_pin_src);
25086 + au_unpin(&a->mvd_pin_src);
25087 + au_pin_hdir_lock(&a->mvd_pin_dst);
25090 + goto out; /* success */
25093 + au_unpin(&a->mvd_pin_dst);
25099 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25101 + if (!a->rename_lock)
25102 + au_unpin(&a->mvd_pin_src);
25104 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25105 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25106 + au_pin_hdir_lock(&a->mvd_pin_src);
25107 + au_unpin(&a->mvd_pin_src);
25108 + au_pin_hdir_lock(&a->mvd_pin_dst);
25110 + au_unpin(&a->mvd_pin_dst);
25113 +/* copy-down the file */
25114 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25117 + struct au_cp_generic cpg = {
25118 + .dentry = a->dentry,
25119 + .bdst = a->mvd_bdst,
25120 + .bsrc = a->mvd_bsrc,
25122 + .pin = &a->mvd_pin_dst,
25123 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25126 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25127 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25128 + au_fset_cpup(cpg.flags, OVERWRITE);
25129 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25130 + au_fset_cpup(cpg.flags, RWDST);
25131 + err = au_sio_cpdown_simple(&cpg);
25132 + if (unlikely(err))
25133 + AU_MVD_PR(dmsg, "cpdown failed\n");
25140 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25143 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25146 + struct path h_path;
25147 + struct au_branch *br;
25148 + struct inode *delegated;
25150 + br = au_sbr(a->sb, a->mvd_bdst);
25151 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25152 + err = PTR_ERR(h_path.dentry);
25153 + if (IS_ERR(h_path.dentry)) {
25154 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25159 + if (d_is_positive(h_path.dentry)) {
25160 + h_path.mnt = au_br_mnt(br);
25161 + delegated = NULL;
25162 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25163 + &delegated, /*force*/0);
25164 + if (unlikely(err == -EWOULDBLOCK)) {
25165 + pr_warn("cannot retry for NFSv4 delegation"
25166 + " for an internal unlink\n");
25169 + if (unlikely(err))
25170 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25172 + dput(h_path.dentry);
25180 + * unlink the topmost h_dentry
25182 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25185 + struct path h_path;
25186 + struct inode *delegated;
25188 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25189 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25190 + delegated = NULL;
25191 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25192 + if (unlikely(err == -EWOULDBLOCK)) {
25193 + pr_warn("cannot retry for NFSv4 delegation"
25194 + " for an internal unlink\n");
25197 + if (unlikely(err))
25198 + AU_MVD_PR(dmsg, "unlink failed\n");
25204 +/* Since mvdown succeeded, we ignore an error of this function */
25205 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25208 + struct au_branch *br;
25210 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25211 + br = au_sbr(a->sb, a->mvd_bsrc);
25212 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25214 + br = au_sbr(a->sb, a->mvd_bdst);
25215 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25216 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25219 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25221 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25225 + * copy-down the file and unlink the bsrc file.
25226 + * - unlink the bdst whout if exist
25227 + * - copy-down the file (with whtmp name and rename)
25228 + * - unlink the bsrc file
25230 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25234 + err = au_do_mkdir(dmsg, a);
25236 + err = au_do_lock(dmsg, a);
25237 + if (unlikely(err))
25241 + * do not revert the activities we made on bdst since they should be
25242 + * harmless in aufs.
25245 + err = au_do_cpdown(dmsg, a);
25247 + err = au_do_unlink_wh(dmsg, a);
25248 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25249 + err = au_do_unlink(dmsg, a);
25250 + if (unlikely(err))
25253 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25254 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25255 + if (find_lower_writable(a) < 0)
25256 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25258 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25259 + au_do_stfs(dmsg, a);
25261 + /* maintain internal array */
25262 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25263 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25264 + au_set_dbtop(a->dentry, a->mvd_bdst);
25265 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25266 + au_set_ibtop(a->inode, a->mvd_bdst);
25268 + /* hide the lower */
25269 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25270 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25271 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25272 + au_set_ibbot(a->inode, a->mvd_bsrc);
25274 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25275 + au_set_dbbot(a->dentry, a->mvd_bdst);
25276 + if (au_ibbot(a->inode) < a->mvd_bdst)
25277 + au_set_ibbot(a->inode, a->mvd_bdst);
25280 + au_do_unlock(dmsg, a);
25286 +/* ---------------------------------------------------------------------- */
25288 +/* make sure the file is idle */
25289 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25291 + int err, plinked;
25294 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25295 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25296 + && au_dcount(a->dentry) == 1
25297 + && atomic_read(&a->inode->i_count) == 1
25298 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25299 + && (!plinked || !au_plink_test(a->inode))
25300 + && a->inode->i_nlink == 1)
25305 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25306 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25307 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25308 + a->mvd_h_src_inode->i_nlink,
25309 + plinked, plinked ? au_plink_test(a->inode) : 0);
25316 +/* make sure the parent dir is fine */
25317 +static int au_mvd_args_parent(const unsigned char dmsg,
25318 + struct au_mvd_args *a)
25321 + aufs_bindex_t bindex;
25324 + if (unlikely(au_alive_dir(a->parent))) {
25326 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25330 + a->bopq = au_dbdiropq(a->parent);
25331 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25332 + AuDbg("b%d\n", bindex);
25333 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25334 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25336 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25337 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25338 + a->bopq, a->mvd_bdst);
25346 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25347 + struct au_mvd_args *a)
25350 + struct au_dinfo *dinfo, *tmp;
25352 + /* lookup the next lower positive entry */
25354 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25355 + if (unlikely(!tmp))
25360 + dinfo = au_di(a->dentry);
25361 + au_di_cp(tmp, dinfo);
25362 + au_di_swap(tmp, dinfo);
25364 + /* returns the number of positive dentries */
25365 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25366 + /* AuLkup_IGNORE_PERM */ 0);
25368 + a->bwh = au_dbwh(a->dentry);
25369 + else if (err > 0)
25370 + a->bfound = au_dbtop(a->dentry);
25372 + au_di_swap(tmp, dinfo);
25373 + au_rw_write_unlock(&tmp->di_rwsem);
25375 + if (unlikely(err < 0))
25376 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25379 + * here, we have these cases.
25381 + * no positive dentry under bsrc. there are more sub-cases.
25383 + * there no whiteout, we can safely move-down.
25386 + * bsrc < bwh && bwh < bdst
25387 + * there is a whiteout on RO branch. cannot proceed.
25389 + * there is a whiteout on the RW target branch. it should
25392 + * there is a whiteout somewhere unrelated branch.
25393 + * -1 < bfound && bfound <= bsrc
25396 + * found, but it is on RO branch between bsrc and bdst. cannot
25399 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25402 + * found, after we create the file on bdst, it will be hidden.
25405 + AuDebugOn(a->bfound == -1
25407 + && a->bwh <= a->mvd_bsrc);
25408 + AuDebugOn(-1 < a->bfound
25409 + && a->bfound <= a->mvd_bsrc);
25412 + if (a->bfound == -1
25413 + && a->mvd_bsrc < a->bwh
25415 + && a->bwh < a->mvd_bdst) {
25416 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25417 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25418 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25420 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25421 + a->mvd_errno = EAU_MVDOWN_UPPER;
25422 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25423 + a->mvd_bdst, a->bfound);
25427 + err = 0; /* success */
25434 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25439 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25440 + && a->bfound == a->mvd_bdst)
25446 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25449 + struct au_branch *br;
25452 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25456 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25457 + a->mvd_bsrc = au_ibtop(a->inode);
25459 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25460 + if (unlikely(a->mvd_bsrc < 0
25461 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25462 + || au_dbbot(a->dentry) < a->mvd_bsrc
25463 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25464 + || (a->mvd_bsrc < au_ibtop(a->inode)
25465 + || au_ibbot(a->inode) < a->mvd_bsrc
25466 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25467 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25468 + AU_MVD_PR(dmsg, "no upper\n");
25472 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25473 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25474 + AU_MVD_PR(dmsg, "on the bottom\n");
25477 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25478 + br = au_sbr(a->sb, a->mvd_bsrc);
25479 + err = au_br_rdonly(br);
25480 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25481 + if (unlikely(err))
25483 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25484 + || IS_APPEND(a->mvd_h_src_inode))) {
25486 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25492 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25493 + a->mvd_bdst = find_lower_writable(a);
25494 + if (unlikely(a->mvd_bdst < 0)) {
25495 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25496 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25500 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25501 + if (unlikely(a->mvd_bdst < 0
25502 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25503 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25504 + AU_MVD_PR(dmsg, "no lower brid\n");
25509 + err = au_mvd_args_busy(dmsg, a);
25511 + err = au_mvd_args_parent(dmsg, a);
25513 + err = au_mvd_args_intermediate(dmsg, a);
25515 + err = au_mvd_args_exist(dmsg, a);
25517 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25524 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25527 + unsigned char dmsg;
25528 + struct au_mvd_args *args;
25529 + struct inode *inode;
25531 + inode = d_inode(dentry);
25533 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25537 + args = kmalloc(sizeof(*args), GFP_NOFS);
25538 + if (unlikely(!args))
25541 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25543 + /* VERIFY_WRITE */
25544 + err = !access_ok(uarg, sizeof(*uarg));
25545 + if (unlikely(err)) {
25550 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25551 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25552 + args->mvdown.au_errno = 0;
25553 + args->dentry = dentry;
25554 + args->inode = inode;
25555 + args->sb = dentry->d_sb;
25558 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25559 + args->parent = dget_parent(dentry);
25560 + args->dir = d_inode(args->parent);
25561 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25562 + dput(args->parent);
25563 + if (unlikely(args->parent != dentry->d_parent)) {
25564 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25568 + inode_lock_nested(inode, I_MUTEX_CHILD);
25569 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25570 + if (unlikely(err))
25573 + di_write_lock_parent(args->parent);
25574 + err = au_mvd_args(dmsg, args);
25575 + if (unlikely(err))
25578 + err = au_do_mvdown(dmsg, args);
25579 + if (unlikely(err))
25582 + au_cpup_attr_timesizes(args->dir);
25583 + au_cpup_attr_timesizes(inode);
25584 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25585 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25586 + /* au_digen_dec(dentry); */
25589 + di_write_unlock(args->parent);
25590 + aufs_read_unlock(dentry, AuLock_DW);
25592 + inode_unlock(inode);
25594 + inode_unlock(args->dir);
25596 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25599 + au_kfree_rcu(args);
25604 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25605 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25606 +++ linux/fs/aufs/opts.c 2021-09-06 21:02:45.280158943 +0200
25608 +// SPDX-License-Identifier: GPL-2.0
25610 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25612 + * This program, aufs is free software; you can redistribute it and/or modify
25613 + * it under the terms of the GNU General Public License as published by
25614 + * the Free Software Foundation; either version 2 of the License, or
25615 + * (at your option) any later version.
25617 + * This program is distributed in the hope that it will be useful,
25618 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25619 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25620 + * GNU General Public License for more details.
25622 + * You should have received a copy of the GNU General Public License
25623 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25627 + * mount options/flags
25630 +#include <linux/namei.h>
25631 +#include <linux/types.h> /* a distribution requires */
25632 +#include <linux/parser.h>
25635 +/* ---------------------------------------------------------------------- */
25639 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25640 + Opt_idel, Opt_imod,
25641 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25642 + Opt_rdblk_def, Opt_rdhash_def,
25643 + Opt_xino, Opt_noxino,
25644 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25645 + Opt_trunc_xino_path, Opt_itrunc_xino,
25646 + Opt_trunc_xib, Opt_notrunc_xib,
25647 + Opt_shwh, Opt_noshwh,
25648 + Opt_plink, Opt_noplink, Opt_list_plink,
25650 + Opt_dio, Opt_nodio,
25651 + Opt_diropq_a, Opt_diropq_w,
25652 + Opt_warn_perm, Opt_nowarn_perm,
25653 + Opt_wbr_copyup, Opt_wbr_create,
25655 + Opt_verbose, Opt_noverbose,
25656 + Opt_sum, Opt_nosum, Opt_wsum,
25657 + Opt_dirperm1, Opt_nodirperm1,
25658 + Opt_dirren, Opt_nodirren,
25659 + Opt_acl, Opt_noacl,
25660 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25663 +static match_table_t options = {
25664 + {Opt_br, "br=%s"},
25665 + {Opt_br, "br:%s"},
25667 + {Opt_add, "add=%d:%s"},
25668 + {Opt_add, "add:%d:%s"},
25669 + {Opt_add, "ins=%d:%s"},
25670 + {Opt_add, "ins:%d:%s"},
25671 + {Opt_append, "append=%s"},
25672 + {Opt_append, "append:%s"},
25673 + {Opt_prepend, "prepend=%s"},
25674 + {Opt_prepend, "prepend:%s"},
25676 + {Opt_del, "del=%s"},
25677 + {Opt_del, "del:%s"},
25678 + /* {Opt_idel, "idel:%d"}, */
25679 + {Opt_mod, "mod=%s"},
25680 + {Opt_mod, "mod:%s"},
25681 + /* {Opt_imod, "imod:%d:%s"}, */
25683 + {Opt_dirwh, "dirwh=%d"},
25685 + {Opt_xino, "xino=%s"},
25686 + {Opt_noxino, "noxino"},
25687 + {Opt_trunc_xino, "trunc_xino"},
25688 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25689 + {Opt_notrunc_xino, "notrunc_xino"},
25690 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25691 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25692 + /* {Opt_zxino, "zxino=%s"}, */
25693 + {Opt_trunc_xib, "trunc_xib"},
25694 + {Opt_notrunc_xib, "notrunc_xib"},
25696 +#ifdef CONFIG_PROC_FS
25697 + {Opt_plink, "plink"},
25699 + {Opt_ignore_silent, "plink"},
25702 + {Opt_noplink, "noplink"},
25704 +#ifdef CONFIG_AUFS_DEBUG
25705 + {Opt_list_plink, "list_plink"},
25708 + {Opt_udba, "udba=%s"},
25710 + {Opt_dio, "dio"},
25711 + {Opt_nodio, "nodio"},
25713 +#ifdef CONFIG_AUFS_DIRREN
25714 + {Opt_dirren, "dirren"},
25715 + {Opt_nodirren, "nodirren"},
25717 + {Opt_ignore, "dirren"},
25718 + {Opt_ignore_silent, "nodirren"},
25721 +#ifdef CONFIG_AUFS_FHSM
25722 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25724 + {Opt_ignore, "fhsm_sec=%d"},
25727 + {Opt_diropq_a, "diropq=always"},
25728 + {Opt_diropq_a, "diropq=a"},
25729 + {Opt_diropq_w, "diropq=whiteouted"},
25730 + {Opt_diropq_w, "diropq=w"},
25732 + {Opt_warn_perm, "warn_perm"},
25733 + {Opt_nowarn_perm, "nowarn_perm"},
25735 + /* keep them temporary */
25736 + {Opt_ignore_silent, "nodlgt"},
25737 + {Opt_ignore, "clean_plink"},
25739 +#ifdef CONFIG_AUFS_SHWH
25740 + {Opt_shwh, "shwh"},
25742 + {Opt_noshwh, "noshwh"},
25744 + {Opt_dirperm1, "dirperm1"},
25745 + {Opt_nodirperm1, "nodirperm1"},
25747 + {Opt_verbose, "verbose"},
25748 + {Opt_verbose, "v"},
25749 + {Opt_noverbose, "noverbose"},
25750 + {Opt_noverbose, "quiet"},
25751 + {Opt_noverbose, "q"},
25752 + {Opt_noverbose, "silent"},
25754 + {Opt_sum, "sum"},
25755 + {Opt_nosum, "nosum"},
25756 + {Opt_wsum, "wsum"},
25758 + {Opt_rdcache, "rdcache=%d"},
25759 + {Opt_rdblk, "rdblk=%d"},
25760 + {Opt_rdblk_def, "rdblk=def"},
25761 + {Opt_rdhash, "rdhash=%d"},
25762 + {Opt_rdhash_def, "rdhash=def"},
25764 + {Opt_wbr_create, "create=%s"},
25765 + {Opt_wbr_create, "create_policy=%s"},
25766 + {Opt_wbr_copyup, "cpup=%s"},
25767 + {Opt_wbr_copyup, "copyup=%s"},
25768 + {Opt_wbr_copyup, "copyup_policy=%s"},
25770 + /* generic VFS flag */
25771 +#ifdef CONFIG_FS_POSIX_ACL
25772 + {Opt_acl, "acl"},
25773 + {Opt_noacl, "noacl"},
25775 + {Opt_ignore, "acl"},
25776 + {Opt_ignore_silent, "noacl"},
25779 + /* internal use for the scripts */
25780 + {Opt_ignore_silent, "si=%s"},
25782 + {Opt_br, "dirs=%s"},
25783 + {Opt_ignore, "debug=%d"},
25784 + {Opt_ignore, "delete=whiteout"},
25785 + {Opt_ignore, "delete=all"},
25786 + {Opt_ignore, "imap=%s"},
25788 + /* temporary workaround, due to old mount(8)? */
25789 + {Opt_ignore_silent, "relatime"},
25794 +/* ---------------------------------------------------------------------- */
25796 +static const char *au_parser_pattern(int val, match_table_t tbl)
25798 + struct match_token *p;
25801 + while (p->pattern) {
25802 + if (p->token == val)
25803 + return p->pattern;
25810 +static const char *au_optstr(int *val, match_table_t tbl)
25812 + struct match_token *p;
25819 + while (p->pattern) {
25821 + && (v & p->token) == p->token) {
25822 + *val &= ~p->token;
25823 + return p->pattern;
25832 +/* ---------------------------------------------------------------------- */
25834 +static match_table_t brperm = {
25835 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25836 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25837 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25841 +static match_table_t brattr = {
25843 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25844 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25845 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25846 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25847 +#ifdef CONFIG_AUFS_FHSM
25848 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25850 +#ifdef CONFIG_AUFS_XATTR
25851 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25852 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25853 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25854 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25855 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25856 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25859 + /* ro/rr branch */
25860 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25863 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25864 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25869 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25876 + p = strchr(str, '+');
25879 + v = match_token(str, table, args);
25881 + if (v & AuBrAttr_CMOO_Mask)
25882 + attr &= ~AuBrAttr_CMOO_Mask;
25887 + pr_warn("ignored branch attribute %s\n", str);
25897 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25905 + p = au_optstr(&perm, brattr);
25908 + memcpy(q, p, sz + 1);
25914 + p = au_optstr(&perm, brattr);
25918 + memcpy(q, p, sz + 1);
25924 + return q - str->a;
25927 +static int noinline_for_stack br_perm_val(char *perm)
25929 + int val, bad, sz;
25931 + substring_t args[MAX_OPT_ARGS];
25932 + au_br_perm_str_t attr;
25934 + p = strchr(perm, '+');
25937 + val = match_token(perm, brperm, args);
25941 + pr_warn("ignored branch permission %s\n", perm);
25942 + val = AuBrPerm_RO;
25948 + val |= br_attr_val(p + 1, brattr, args);
25951 + switch (val & AuBrPerm_Mask) {
25952 + case AuBrPerm_RO:
25953 + case AuBrPerm_RR:
25954 + bad = val & AuBrWAttr_Mask;
25955 + val &= ~AuBrWAttr_Mask;
25957 + case AuBrPerm_RW:
25958 + bad = val & AuBrRAttr_Mask;
25959 + val &= ~AuBrRAttr_Mask;
25964 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25965 + * does not treat it as an error, just warning.
25966 + * this is a tiny guard for the user operation.
25968 + if (val & AuBrAttr_UNPIN) {
25969 + bad |= AuBrAttr_UNPIN;
25970 + val &= ~AuBrAttr_UNPIN;
25973 + if (unlikely(bad)) {
25974 + sz = au_do_optstr_br_attr(&attr, bad);
25976 + pr_warn("ignored branch attribute %s\n", attr.a);
25983 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25985 + au_br_perm_str_t attr;
25991 + p = au_optstr(&perm, brperm);
25992 + AuDebugOn(!p || !*p);
25994 + memcpy(q, p, sz + 1);
25997 + sz = au_do_optstr_br_attr(&attr, perm);
26000 + memcpy(q, attr.a, sz + 1);
26003 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
26006 +/* ---------------------------------------------------------------------- */
26008 +static match_table_t udbalevel = {
26009 + {AuOpt_UDBA_REVAL, "reval"},
26010 + {AuOpt_UDBA_NONE, "none"},
26011 +#ifdef CONFIG_AUFS_HNOTIFY
26012 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26013 +#ifdef CONFIG_AUFS_HFSNOTIFY
26014 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26020 +static int noinline_for_stack udba_val(char *str)
26022 + substring_t args[MAX_OPT_ARGS];
26024 + return match_token(str, udbalevel, args);
26027 +const char *au_optstr_udba(int udba)
26029 + return au_parser_pattern(udba, udbalevel);
26032 +/* ---------------------------------------------------------------------- */
26034 +static match_table_t au_wbr_create_policy = {
26035 + {AuWbrCreate_TDP, "tdp"},
26036 + {AuWbrCreate_TDP, "top-down-parent"},
26037 + {AuWbrCreate_RR, "rr"},
26038 + {AuWbrCreate_RR, "round-robin"},
26039 + {AuWbrCreate_MFS, "mfs"},
26040 + {AuWbrCreate_MFS, "most-free-space"},
26041 + {AuWbrCreate_MFSV, "mfs:%d"},
26042 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26044 + /* top-down regardless the parent, and then mfs */
26045 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26046 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26048 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26049 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26050 + {AuWbrCreate_PMFS, "pmfs"},
26051 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26052 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26053 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26058 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26059 + struct au_opt_wbr_create *create)
26062 + unsigned long long ull;
26065 + if (!match_u64(arg, &ull))
26066 + create->mfsrr_watermark = ull;
26068 + pr_err("bad integer in %s\n", str);
26075 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26076 + struct au_opt_wbr_create *create)
26081 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26082 + create->mfs_second = n;
26084 + pr_err("bad integer in %s\n", str);
26091 +static int noinline_for_stack
26092 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26095 + substring_t args[MAX_OPT_ARGS];
26097 + err = match_token(str, au_wbr_create_policy, args);
26098 + create->wbr_create = err;
26100 + case AuWbrCreate_MFSRRV:
26101 + case AuWbrCreate_TDMFSV:
26102 + case AuWbrCreate_PMFSRRV:
26103 + e = au_wbr_mfs_wmark(&args[0], str, create);
26105 + e = au_wbr_mfs_sec(&args[1], str, create);
26109 + case AuWbrCreate_MFSRR:
26110 + case AuWbrCreate_TDMFS:
26111 + case AuWbrCreate_PMFSRR:
26112 + e = au_wbr_mfs_wmark(&args[0], str, create);
26113 + if (unlikely(e)) {
26118 + case AuWbrCreate_MFS:
26119 + case AuWbrCreate_PMFS:
26120 + create->mfs_second = AUFS_MFS_DEF_SEC;
26122 + case AuWbrCreate_MFSV:
26123 + case AuWbrCreate_PMFSV:
26124 + e = au_wbr_mfs_sec(&args[0], str, create);
26133 +const char *au_optstr_wbr_create(int wbr_create)
26135 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26138 +static match_table_t au_wbr_copyup_policy = {
26139 + {AuWbrCopyup_TDP, "tdp"},
26140 + {AuWbrCopyup_TDP, "top-down-parent"},
26141 + {AuWbrCopyup_BUP, "bup"},
26142 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26143 + {AuWbrCopyup_BU, "bu"},
26144 + {AuWbrCopyup_BU, "bottom-up"},
26148 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26150 + substring_t args[MAX_OPT_ARGS];
26152 + return match_token(str, au_wbr_copyup_policy, args);
26155 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26157 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26160 +/* ---------------------------------------------------------------------- */
26162 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26164 +static void dump_opts(struct au_opts *opts)
26166 +#ifdef CONFIG_AUFS_DEBUG
26167 + /* reduce stack space */
26169 + struct au_opt_add *add;
26170 + struct au_opt_del *del;
26171 + struct au_opt_mod *mod;
26172 + struct au_opt_xino *xino;
26173 + struct au_opt_xino_itrunc *xino_itrunc;
26174 + struct au_opt_wbr_create *create;
26176 + struct au_opt *opt;
26179 + while (opt->type != Opt_tail) {
26180 + switch (opt->type) {
26182 + u.add = &opt->add;
26183 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26184 + u.add->bindex, u.add->pathname, u.add->perm,
26185 + u.add->path.dentry);
26189 + u.del = &opt->del;
26190 + AuDbg("del {%s, %p}\n",
26191 + u.del->pathname, u.del->h_path.dentry);
26195 + u.mod = &opt->mod;
26196 + AuDbg("mod {%s, 0x%x, %p}\n",
26197 + u.mod->path, u.mod->perm, u.mod->h_root);
26200 + u.add = &opt->add;
26201 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26202 + u.add->bindex, u.add->pathname, u.add->perm,
26203 + u.add->path.dentry);
26205 + case Opt_prepend:
26206 + u.add = &opt->add;
26207 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26208 + u.add->bindex, u.add->pathname, u.add->perm,
26209 + u.add->path.dentry);
26212 + AuDbg("dirwh %d\n", opt->dirwh);
26214 + case Opt_rdcache:
26215 + AuDbg("rdcache %d\n", opt->rdcache);
26218 + AuDbg("rdblk %u\n", opt->rdblk);
26220 + case Opt_rdblk_def:
26221 + AuDbg("rdblk_def\n");
26224 + AuDbg("rdhash %u\n", opt->rdhash);
26226 + case Opt_rdhash_def:
26227 + AuDbg("rdhash_def\n");
26230 + u.xino = &opt->xino;
26231 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26233 + case Opt_trunc_xino:
26234 + AuLabel(trunc_xino);
26236 + case Opt_notrunc_xino:
26237 + AuLabel(notrunc_xino);
26239 + case Opt_trunc_xino_path:
26240 + case Opt_itrunc_xino:
26241 + u.xino_itrunc = &opt->xino_itrunc;
26242 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26247 + case Opt_trunc_xib:
26248 + AuLabel(trunc_xib);
26250 + case Opt_notrunc_xib:
26251 + AuLabel(notrunc_xib);
26259 + case Opt_dirperm1:
26260 + AuLabel(dirperm1);
26262 + case Opt_nodirperm1:
26263 + AuLabel(nodirperm1);
26268 + case Opt_noplink:
26269 + AuLabel(noplink);
26271 + case Opt_list_plink:
26272 + AuLabel(list_plink);
26275 + AuDbg("udba %d, %s\n",
26276 + opt->udba, au_optstr_udba(opt->udba));
26284 + case Opt_diropq_a:
26285 + AuLabel(diropq_a);
26287 + case Opt_diropq_w:
26288 + AuLabel(diropq_w);
26290 + case Opt_warn_perm:
26291 + AuLabel(warn_perm);
26293 + case Opt_nowarn_perm:
26294 + AuLabel(nowarn_perm);
26296 + case Opt_verbose:
26297 + AuLabel(verbose);
26299 + case Opt_noverbose:
26300 + AuLabel(noverbose);
26311 + case Opt_wbr_create:
26312 + u.create = &opt->wbr_create;
26313 + AuDbg("create %d, %s\n", u.create->wbr_create,
26314 + au_optstr_wbr_create(u.create->wbr_create));
26315 + switch (u.create->wbr_create) {
26316 + case AuWbrCreate_MFSV:
26317 + case AuWbrCreate_PMFSV:
26318 + AuDbg("%d sec\n", u.create->mfs_second);
26320 + case AuWbrCreate_MFSRR:
26321 + case AuWbrCreate_TDMFS:
26322 + AuDbg("%llu watermark\n",
26323 + u.create->mfsrr_watermark);
26325 + case AuWbrCreate_MFSRRV:
26326 + case AuWbrCreate_TDMFSV:
26327 + case AuWbrCreate_PMFSRRV:
26328 + AuDbg("%llu watermark, %d sec\n",
26329 + u.create->mfsrr_watermark,
26330 + u.create->mfs_second);
26334 + case Opt_wbr_copyup:
26335 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26336 + au_optstr_wbr_copyup(opt->wbr_copyup));
26338 + case Opt_fhsm_sec:
26339 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26344 + case Opt_nodirren:
26345 + AuLabel(nodirren);
26361 +void au_opts_free(struct au_opts *opts)
26363 + struct au_opt *opt;
26366 + while (opt->type != Opt_tail) {
26367 + switch (opt->type) {
26370 + case Opt_prepend:
26371 + path_put(&opt->add.path);
26375 + path_put(&opt->del.h_path);
26379 + dput(opt->mod.h_root);
26382 + fput(opt->xino.file);
26389 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26390 + aufs_bindex_t bindex)
26393 + struct au_opt_add *add = &opt->add;
26396 + add->bindex = bindex;
26397 + add->perm = AuBrPerm_RO;
26398 + add->pathname = opt_str;
26399 + p = strchr(opt_str, '=');
26403 + add->perm = br_perm_val(p);
26406 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26409 + add->perm = AuBrPerm_RO;
26410 + if (au_test_fs_rr(add->path.dentry->d_sb))
26411 + add->perm = AuBrPerm_RR;
26412 + else if (!bindex && !(sb_flags & SB_RDONLY))
26413 + add->perm = AuBrPerm_RW;
26415 + opt->type = Opt_add;
26418 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26425 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26429 + del->pathname = args[0].from;
26430 + AuDbg("del path %s\n", del->pathname);
26432 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26433 + if (unlikely(err))
26434 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26439 +#if 0 /* reserved for future use */
26440 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26441 + struct au_opt_del *del, substring_t args[])
26444 + struct dentry *root;
26447 + root = sb->s_root;
26448 + aufs_read_lock(root, AuLock_FLUSH);
26449 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26450 + pr_err("out of bounds, %d\n", bindex);
26455 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26456 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26459 + aufs_read_unlock(root, !AuLock_IR);
26464 +static int noinline_for_stack
26465 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26468 + struct path path;
26472 + mod->path = args[0].from;
26473 + p = strchr(mod->path, '=');
26474 + if (unlikely(!p)) {
26475 + pr_err("no permission %s\n", args[0].from);
26480 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26481 + if (unlikely(err)) {
26482 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26486 + mod->perm = br_perm_val(p);
26487 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26488 + mod->h_root = dget(path.dentry);
26495 +#if 0 /* reserved for future use */
26496 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26497 + struct au_opt_mod *mod, substring_t args[])
26500 + struct dentry *root;
26503 + root = sb->s_root;
26504 + aufs_read_lock(root, AuLock_FLUSH);
26505 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26506 + pr_err("out of bounds, %d\n", bindex);
26511 + mod->perm = br_perm_val(args[1].from);
26512 + AuDbg("mod path %s, perm 0x%x, %s\n",
26513 + mod->path, mod->perm, args[1].from);
26514 + mod->h_root = dget(au_h_dptr(root, bindex));
26517 + aufs_read_unlock(root, !AuLock_IR);
26522 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26523 + substring_t args[])
26526 + struct file *file;
26528 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26529 + err = PTR_ERR(file);
26530 + if (IS_ERR(file))
26534 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26536 + pr_err("%s must be outside\n", args[0].from);
26541 + xino->file = file;
26542 + xino->path = args[0].from;
26548 +static int noinline_for_stack
26549 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26550 + struct au_opt_xino_itrunc *xino_itrunc,
26551 + substring_t args[])
26554 + aufs_bindex_t bbot, bindex;
26555 + struct path path;
26556 + struct dentry *root;
26558 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26559 + if (unlikely(err)) {
26560 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26564 + xino_itrunc->bindex = -1;
26565 + root = sb->s_root;
26566 + aufs_read_lock(root, AuLock_FLUSH);
26567 + bbot = au_sbbot(sb);
26568 + for (bindex = 0; bindex <= bbot; bindex++) {
26569 + if (au_h_dptr(root, bindex) == path.dentry) {
26570 + xino_itrunc->bindex = bindex;
26574 + aufs_read_unlock(root, !AuLock_IR);
26577 + if (unlikely(xino_itrunc->bindex < 0)) {
26578 + pr_err("no such branch %s\n", args[0].from);
26586 +/* called without aufs lock */
26587 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26589 + int err, n, token;
26590 + aufs_bindex_t bindex;
26591 + unsigned char skipped;
26592 + struct dentry *root;
26593 + struct au_opt *opt, *opt_tail;
26595 + /* reduce the stack space */
26597 + struct au_opt_xino_itrunc *xino_itrunc;
26598 + struct au_opt_wbr_create *create;
26601 + substring_t args[MAX_OPT_ARGS];
26605 + a = kmalloc(sizeof(*a), GFP_NOFS);
26606 + if (unlikely(!a))
26609 + root = sb->s_root;
26613 + opt_tail = opt + opts->max_opt - 1;
26614 + opt->type = Opt_tail;
26615 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26618 + token = match_token(opt_str, options, a->args);
26622 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26624 + err = opt_add(opt, opt_str, opts->sb_flags,
26626 + if (unlikely(!err && ++opt > opt_tail)) {
26630 + opt->type = Opt_tail;
26635 + if (unlikely(match_int(&a->args[0], &n))) {
26636 + pr_err("bad integer in %s\n", opt_str);
26640 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26643 + opt->type = token;
26646 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26647 + /*dummy bindex*/1);
26649 + opt->type = token;
26651 + case Opt_prepend:
26652 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26655 + opt->type = token;
26658 + err = au_opts_parse_del(&opt->del, a->args);
26660 + opt->type = token;
26662 +#if 0 /* reserved for future use */
26664 + del->pathname = "(indexed)";
26665 + if (unlikely(match_int(&args[0], &n))) {
26666 + pr_err("bad integer in %s\n", opt_str);
26669 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26671 + opt->type = token;
26675 + err = au_opts_parse_mod(&opt->mod, a->args);
26677 + opt->type = token;
26679 +#ifdef IMOD /* reserved for future use */
26681 + u.mod->path = "(indexed)";
26682 + if (unlikely(match_int(&a->args[0], &n))) {
26683 + pr_err("bad integer in %s\n", opt_str);
26686 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26688 + opt->type = token;
26692 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26694 + opt->type = token;
26697 + case Opt_trunc_xino_path:
26698 + err = au_opts_parse_xino_itrunc_path
26699 + (sb, &opt->xino_itrunc, a->args);
26701 + opt->type = token;
26704 + case Opt_itrunc_xino:
26705 + u.xino_itrunc = &opt->xino_itrunc;
26706 + if (unlikely(match_int(&a->args[0], &n))) {
26707 + pr_err("bad integer in %s\n", opt_str);
26710 + u.xino_itrunc->bindex = n;
26711 + aufs_read_lock(root, AuLock_FLUSH);
26712 + if (n < 0 || au_sbbot(sb) < n) {
26713 + pr_err("out of bounds, %d\n", n);
26714 + aufs_read_unlock(root, !AuLock_IR);
26717 + aufs_read_unlock(root, !AuLock_IR);
26719 + opt->type = token;
26723 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26726 + opt->type = token;
26729 + case Opt_rdcache:
26730 + if (unlikely(match_int(&a->args[0], &n))) {
26731 + pr_err("bad integer in %s\n", opt_str);
26734 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26735 + pr_err("rdcache must be smaller than %d\n",
26736 + AUFS_RDCACHE_MAX);
26739 + opt->rdcache = n;
26741 + opt->type = token;
26744 + if (unlikely(match_int(&a->args[0], &n)
26746 + || n > KMALLOC_MAX_SIZE)) {
26747 + pr_err("bad integer in %s\n", opt_str);
26750 + if (unlikely(n && n < NAME_MAX)) {
26751 + pr_err("rdblk must be larger than %d\n",
26757 + opt->type = token;
26760 + if (unlikely(match_int(&a->args[0], &n)
26762 + || n * sizeof(struct hlist_head)
26763 + > KMALLOC_MAX_SIZE)) {
26764 + pr_err("bad integer in %s\n", opt_str);
26769 + opt->type = token;
26772 + case Opt_trunc_xino:
26773 + case Opt_notrunc_xino:
26775 + case Opt_trunc_xib:
26776 + case Opt_notrunc_xib:
26779 + case Opt_dirperm1:
26780 + case Opt_nodirperm1:
26782 + case Opt_noplink:
26783 + case Opt_list_plink:
26786 + case Opt_diropq_a:
26787 + case Opt_diropq_w:
26788 + case Opt_warn_perm:
26789 + case Opt_nowarn_perm:
26790 + case Opt_verbose:
26791 + case Opt_noverbose:
26795 + case Opt_rdblk_def:
26796 + case Opt_rdhash_def:
26798 + case Opt_nodirren:
26802 + opt->type = token;
26806 + opt->udba = udba_val(a->args[0].from);
26807 + if (opt->udba >= 0) {
26809 + opt->type = token;
26811 + pr_err("wrong value, %s\n", opt_str);
26814 + case Opt_wbr_create:
26815 + u.create = &opt->wbr_create;
26816 + u.create->wbr_create
26817 + = au_wbr_create_val(a->args[0].from, u.create);
26818 + if (u.create->wbr_create >= 0) {
26820 + opt->type = token;
26822 + pr_err("wrong value, %s\n", opt_str);
26824 + case Opt_wbr_copyup:
26825 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26826 + if (opt->wbr_copyup >= 0) {
26828 + opt->type = token;
26830 + pr_err("wrong value, %s\n", opt_str);
26833 + case Opt_fhsm_sec:
26834 + if (unlikely(match_int(&a->args[0], &n)
26836 + pr_err("bad integer in %s\n", opt_str);
26839 + if (sysaufs_brs) {
26840 + opt->fhsm_second = n;
26841 + opt->type = token;
26843 + pr_warn("ignored %s\n", opt_str);
26848 + pr_warn("ignored %s\n", opt_str);
26850 + case Opt_ignore_silent:
26855 + pr_err("unknown option %s\n", opt_str);
26859 + if (!err && !skipped) {
26860 + if (unlikely(++opt > opt_tail)) {
26863 + opt->type = Opt_tail;
26866 + opt->type = Opt_tail;
26872 + if (unlikely(err))
26873 + au_opts_free(opts);
26879 +static int au_opt_wbr_create(struct super_block *sb,
26880 + struct au_opt_wbr_create *create)
26883 + struct au_sbinfo *sbinfo;
26885 + SiMustWriteLock(sb);
26887 + err = 1; /* handled */
26888 + sbinfo = au_sbi(sb);
26889 + if (sbinfo->si_wbr_create_ops->fin) {
26890 + err = sbinfo->si_wbr_create_ops->fin(sb);
26895 + sbinfo->si_wbr_create = create->wbr_create;
26896 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26897 + switch (create->wbr_create) {
26898 + case AuWbrCreate_MFSRRV:
26899 + case AuWbrCreate_MFSRR:
26900 + case AuWbrCreate_TDMFS:
26901 + case AuWbrCreate_TDMFSV:
26902 + case AuWbrCreate_PMFSRR:
26903 + case AuWbrCreate_PMFSRRV:
26904 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26906 + case AuWbrCreate_MFS:
26907 + case AuWbrCreate_MFSV:
26908 + case AuWbrCreate_PMFS:
26909 + case AuWbrCreate_PMFSV:
26910 + sbinfo->si_wbr_mfs.mfs_expire
26911 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26915 + if (sbinfo->si_wbr_create_ops->init)
26916 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26923 + * plus: processed without an error
26924 + * zero: unprocessed
26926 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26927 + struct au_opts *opts)
26930 + struct au_sbinfo *sbinfo;
26932 + SiMustWriteLock(sb);
26934 + err = 1; /* handled */
26935 + sbinfo = au_sbi(sb);
26936 + switch (opt->type) {
26938 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26939 + sbinfo->si_mntflags |= opt->udba;
26940 + opts->given_udba |= opt->udba;
26944 + au_opt_set(sbinfo->si_mntflags, PLINK);
26946 + case Opt_noplink:
26947 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26948 + au_plink_put(sb, /*verbose*/1);
26949 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26951 + case Opt_list_plink:
26952 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26953 + au_plink_list(sb);
26957 + au_opt_set(sbinfo->si_mntflags, DIO);
26958 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26961 + au_opt_clr(sbinfo->si_mntflags, DIO);
26962 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26965 + case Opt_fhsm_sec:
26966 + au_fhsm_set(sbinfo, opt->fhsm_second);
26969 + case Opt_diropq_a:
26970 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26972 + case Opt_diropq_w:
26973 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26976 + case Opt_warn_perm:
26977 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26979 + case Opt_nowarn_perm:
26980 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26983 + case Opt_verbose:
26984 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26986 + case Opt_noverbose:
26987 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26991 + au_opt_set(sbinfo->si_mntflags, SUM);
26994 + au_opt_clr(sbinfo->si_mntflags, SUM);
26995 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26998 + au_opt_clr(sbinfo->si_mntflags, SUM);
26999 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27002 + case Opt_wbr_create:
27003 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27005 + case Opt_wbr_copyup:
27006 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27007 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27011 + sbinfo->si_dirwh = opt->dirwh;
27014 + case Opt_rdcache:
27015 + sbinfo->si_rdcache
27016 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27019 + sbinfo->si_rdblk = opt->rdblk;
27021 + case Opt_rdblk_def:
27022 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27025 + sbinfo->si_rdhash = opt->rdhash;
27027 + case Opt_rdhash_def:
27028 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27032 + au_opt_set(sbinfo->si_mntflags, SHWH);
27035 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27038 + case Opt_dirperm1:
27039 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27041 + case Opt_nodirperm1:
27042 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27045 + case Opt_trunc_xino:
27046 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27048 + case Opt_notrunc_xino:
27049 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27052 + case Opt_trunc_xino_path:
27053 + case Opt_itrunc_xino:
27054 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27060 + case Opt_trunc_xib:
27061 + au_fset_opts(opts->flags, TRUNC_XIB);
27063 + case Opt_notrunc_xib:
27064 + au_fclr_opts(opts->flags, TRUNC_XIB);
27069 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27070 + err = au_dr_opt_set(sb);
27075 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27077 + case Opt_nodirren:
27079 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27080 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27086 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27090 + sb->s_flags |= SB_POSIXACL;
27093 + sb->s_flags &= ~SB_POSIXACL;
27105 + * returns tri-state.
27106 + * plus: processed without an error
27107 + * zero: unprocessed
27110 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27111 + struct au_opts *opts)
27113 + int err, do_refresh;
27116 + switch (opt->type) {
27118 + opt->add.bindex = au_sbbot(sb) + 1;
27119 + if (opt->add.bindex < 0)
27120 + opt->add.bindex = 0;
27122 + /* Always goto add, not fallthrough */
27123 + case Opt_prepend:
27124 + opt->add.bindex = 0;
27126 + add: /* indented label */
27128 + err = au_br_add(sb, &opt->add,
27129 + au_ftest_opts(opts->flags, REMOUNT));
27132 + au_fset_opts(opts->flags, REFRESH);
27138 + err = au_br_del(sb, &opt->del,
27139 + au_ftest_opts(opts->flags, REMOUNT));
27142 + au_fset_opts(opts->flags, TRUNC_XIB);
27143 + au_fset_opts(opts->flags, REFRESH);
27149 + err = au_br_mod(sb, &opt->mod,
27150 + au_ftest_opts(opts->flags, REMOUNT),
27155 + au_fset_opts(opts->flags, REFRESH);
27162 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27163 + struct au_opt_xino **opt_xino,
27164 + struct au_opts *opts)
27169 + switch (opt->type) {
27171 + err = au_xino_set(sb, &opt->xino,
27172 + !!au_ftest_opts(opts->flags, REMOUNT));
27173 + if (unlikely(err))
27176 + *opt_xino = &opt->xino;
27181 + *opt_xino = (void *)-1;
27188 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27189 + unsigned int pending)
27192 + aufs_bindex_t bindex, bbot;
27193 + unsigned char do_plink, skip, do_free, can_no_dreval;
27194 + struct au_branch *br;
27195 + struct au_wbr *wbr;
27196 + struct dentry *root, *dentry;
27197 + struct inode *dir, *h_dir;
27198 + struct au_sbinfo *sbinfo;
27199 + struct au_hinode *hdir;
27201 + SiMustAnyLock(sb);
27203 + sbinfo = au_sbi(sb);
27204 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27206 + if (!(sb_flags & SB_RDONLY)) {
27207 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27208 + pr_warn("first branch should be rw\n");
27209 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27210 + pr_warn_once("shwh should be used with ro\n");
27213 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27214 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27215 + pr_warn_once("udba=*notify requires xino\n");
27217 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27218 + pr_warn_once("dirperm1 breaks the protection"
27219 + " by the permission bits on the lower branch\n");
27223 + root = sb->s_root;
27224 + dir = d_inode(root);
27225 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27226 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27228 + bbot = au_sbbot(sb);
27229 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27231 + h_dir = au_h_iptr(dir, bindex);
27232 + br = au_sbr(sb, bindex);
27234 + if ((br->br_perm & AuBrAttr_ICEX)
27235 + && !h_dir->i_op->listxattr)
27236 + br->br_perm &= ~AuBrAttr_ICEX;
27237 +#if 0 /* untested */
27238 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27239 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27240 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27244 + wbr = br->br_wbr;
27246 + wbr_wh_read_lock(wbr);
27248 + if (!au_br_writable(br->br_perm)) {
27251 + || (!wbr->wbr_whbase
27252 + && !wbr->wbr_plink
27253 + && !wbr->wbr_orph));
27254 + } else if (!au_br_wh_linkable(br->br_perm)) {
27255 + /* skip = (!br->br_whbase && !br->br_orph); */
27256 + skip = (!wbr || !wbr->wbr_whbase);
27257 + if (skip && wbr) {
27259 + skip = !!wbr->wbr_plink;
27261 + skip = !wbr->wbr_plink;
27264 + /* skip = (br->br_whbase && br->br_ohph); */
27265 + skip = (wbr && wbr->wbr_whbase);
27268 + skip = !!wbr->wbr_plink;
27270 + skip = !wbr->wbr_plink;
27274 + wbr_wh_read_unlock(wbr);
27276 + if (can_no_dreval) {
27277 + dentry = br->br_path.dentry;
27278 + spin_lock(&dentry->d_lock);
27279 + if (dentry->d_flags &
27280 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27281 + can_no_dreval = 0;
27282 + spin_unlock(&dentry->d_lock);
27285 + if (au_br_fhsm(br->br_perm)) {
27287 + AuDebugOn(!br->br_fhsm);
27293 + hdir = au_hi(dir, bindex);
27294 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27296 + wbr_wh_write_lock(wbr);
27297 + err = au_wh_init(br, sb);
27299 + wbr_wh_write_unlock(wbr);
27300 + au_hn_inode_unlock(hdir);
27302 + if (!err && do_free) {
27303 + au_kfree_rcu(wbr);
27304 + br->br_wbr = NULL;
27308 + if (can_no_dreval)
27309 + au_fset_si(sbinfo, NO_DREVAL);
27311 + au_fclr_si(sbinfo, NO_DREVAL);
27314 + au_fset_si(sbinfo, FHSM);
27315 + for (bindex = bbot; bindex >= 0; bindex--) {
27316 + br = au_sbr(sb, bindex);
27317 + if (au_br_fhsm(br->br_perm)) {
27318 + au_fhsm_set_bottom(sb, bindex);
27323 + au_fclr_si(sbinfo, FHSM);
27324 + au_fhsm_set_bottom(sb, -1);
27330 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27333 + unsigned int tmp;
27334 + aufs_bindex_t bindex, bbot;
27335 + struct au_opt *opt;
27336 + struct au_opt_xino *opt_xino, xino;
27337 + struct au_sbinfo *sbinfo;
27338 + struct au_branch *br;
27339 + struct inode *dir;
27341 + SiMustWriteLock(sb);
27346 + while (err >= 0 && opt->type != Opt_tail)
27347 + err = au_opt_simple(sb, opt++, opts);
27350 + else if (unlikely(err < 0))
27353 + /* disable xino and udba temporary */
27354 + sbinfo = au_sbi(sb);
27355 + tmp = sbinfo->si_mntflags;
27356 + au_opt_clr(sbinfo->si_mntflags, XINO);
27357 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27360 + while (err >= 0 && opt->type != Opt_tail)
27361 + err = au_opt_br(sb, opt++, opts);
27364 + else if (unlikely(err < 0))
27367 + bbot = au_sbbot(sb);
27368 + if (unlikely(bbot < 0)) {
27370 + pr_err("no branches\n");
27374 + if (au_opt_test(tmp, XINO))
27375 + au_opt_set(sbinfo->si_mntflags, XINO);
27377 + while (!err && opt->type != Opt_tail)
27378 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27379 + if (unlikely(err))
27382 + err = au_opts_verify(sb, sb->s_flags, tmp);
27383 + if (unlikely(err))
27386 + /* restore xino */
27387 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27388 + xino.file = au_xino_def(sb);
27389 + err = PTR_ERR(xino.file);
27390 + if (IS_ERR(xino.file))
27393 + err = au_xino_set(sb, &xino, /*remount*/0);
27395 + if (unlikely(err))
27399 + /* restore udba */
27400 + tmp &= AuOptMask_UDBA;
27401 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27402 + sbinfo->si_mntflags |= tmp;
27403 + bbot = au_sbbot(sb);
27404 + for (bindex = 0; bindex <= bbot; bindex++) {
27405 + br = au_sbr(sb, bindex);
27406 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27407 + if (unlikely(err))
27408 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27410 + /* go on even if err */
27412 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27413 + dir = d_inode(sb->s_root);
27414 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27421 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27424 + unsigned char no_dreval;
27425 + struct inode *dir;
27426 + struct au_opt_xino *opt_xino;
27427 + struct au_opt *opt;
27428 + struct au_sbinfo *sbinfo;
27430 + SiMustWriteLock(sb);
27432 + err = au_dr_opt_flush(sb);
27433 + if (unlikely(err))
27435 + au_fset_opts(opts->flags, DR_FLUSHED);
27437 + dir = d_inode(sb->s_root);
27438 + sbinfo = au_sbi(sb);
27441 + while (err >= 0 && opt->type != Opt_tail) {
27442 + err = au_opt_simple(sb, opt, opts);
27444 + err = au_opt_br(sb, opt, opts);
27446 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27452 + /* go on even err */
27454 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27455 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27456 + if (unlikely(rerr && !err))
27459 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27460 + au_fset_opts(opts->flags, REFRESH_IDOP);
27462 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27463 + rerr = au_xib_trunc(sb);
27464 + if (unlikely(rerr && !err))
27468 + /* will be handled by the caller */
27469 + if (!au_ftest_opts(opts->flags, REFRESH)
27470 + && (opts->given_udba
27471 + || au_opt_test(sbinfo->si_mntflags, XINO)
27472 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27474 + au_fset_opts(opts->flags, REFRESH);
27476 + AuDbg("status 0x%x\n", opts->flags);
27482 +/* ---------------------------------------------------------------------- */
27484 +unsigned int au_opt_udba(struct super_block *sb)
27486 + return au_mntflags(sb) & AuOptMask_UDBA;
27488 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27489 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27490 +++ linux/fs/aufs/opts.h 2021-09-06 21:02:45.280158943 +0200
27492 +/* SPDX-License-Identifier: GPL-2.0 */
27494 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27496 + * This program, aufs is free software; you can redistribute it and/or modify
27497 + * it under the terms of the GNU General Public License as published by
27498 + * the Free Software Foundation; either version 2 of the License, or
27499 + * (at your option) any later version.
27501 + * This program is distributed in the hope that it will be useful,
27502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27504 + * GNU General Public License for more details.
27506 + * You should have received a copy of the GNU General Public License
27507 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27511 + * mount options/flags
27514 +#ifndef __AUFS_OPTS_H__
27515 +#define __AUFS_OPTS_H__
27519 +#include <linux/path.h>
27523 +/* ---------------------------------------------------------------------- */
27526 +#define AuOpt_XINO 1 /* external inode number bitmap
27527 + and translation table */
27528 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27529 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27530 +#define AuOpt_UDBA_REVAL (1 << 3)
27531 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27532 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27533 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27534 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27536 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27537 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27538 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27539 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27540 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27541 +#define AuOpt_DIO (1 << 14) /* direct io */
27542 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27544 +#ifndef CONFIG_AUFS_HNOTIFY
27545 +#undef AuOpt_UDBA_HNOTIFY
27546 +#define AuOpt_UDBA_HNOTIFY 0
27548 +#ifndef CONFIG_AUFS_DIRREN
27549 +#undef AuOpt_DIRREN
27550 +#define AuOpt_DIRREN 0
27552 +#ifndef CONFIG_AUFS_SHWH
27554 +#define AuOpt_SHWH 0
27557 +#define AuOpt_Def (AuOpt_XINO \
27558 + | AuOpt_UDBA_REVAL \
27560 + /* | AuOpt_DIRPERM1 */ \
27561 + | AuOpt_WARN_PERM)
27562 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27563 + | AuOpt_UDBA_REVAL \
27564 + | AuOpt_UDBA_HNOTIFY)
27566 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27567 +#define au_opt_set(flags, name) do { \
27568 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27569 + ((flags) |= AuOpt_##name); \
27571 +#define au_opt_set_udba(flags, name) do { \
27572 + (flags) &= ~AuOptMask_UDBA; \
27573 + ((flags) |= AuOpt_##name); \
27575 +#define au_opt_clr(flags, name) do { \
27576 + ((flags) &= ~AuOpt_##name); \
27579 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27581 +#ifdef CONFIG_PROC_FS
27584 + return mntflags & ~AuOpt_PLINK;
27588 +/* ---------------------------------------------------------------------- */
27590 +/* policies to select one among multiple writable branches */
27592 + AuWbrCreate_TDP, /* top down parent */
27593 + AuWbrCreate_RR, /* round robin */
27594 + AuWbrCreate_MFS, /* most free space */
27595 + AuWbrCreate_MFSV, /* mfs with seconds */
27596 + AuWbrCreate_MFSRR, /* mfs then rr */
27597 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27598 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27599 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27600 + AuWbrCreate_PMFS, /* parent and mfs */
27601 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27602 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27603 + AuWbrCreate_PMFSRRV, /* plus seconds */
27605 + AuWbrCreate_Def = AuWbrCreate_TDP
27609 + AuWbrCopyup_TDP, /* top down parent */
27610 + AuWbrCopyup_BUP, /* bottom up parent */
27611 + AuWbrCopyup_BU, /* bottom up */
27613 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27616 +/* ---------------------------------------------------------------------- */
27618 +struct au_opt_add {
27619 + aufs_bindex_t bindex;
27622 + struct path path;
27625 +struct au_opt_del {
27627 + struct path h_path;
27630 +struct au_opt_mod {
27633 + struct dentry *h_root;
27636 +struct au_opt_xino {
27638 + struct file *file;
27641 +struct au_opt_xino_itrunc {
27642 + aufs_bindex_t bindex;
27645 +struct au_opt_wbr_create {
27648 + unsigned long long mfsrr_watermark;
27654 + struct au_opt_xino xino;
27655 + struct au_opt_xino_itrunc xino_itrunc;
27656 + struct au_opt_add add;
27657 + struct au_opt_del del;
27658 + struct au_opt_mod mod;
27661 + unsigned int rdblk;
27662 + unsigned int rdhash;
27664 + struct au_opt_wbr_create wbr_create;
27666 + unsigned int fhsm_second;
27671 +#define AuOpts_REMOUNT 1
27672 +#define AuOpts_REFRESH (1 << 1)
27673 +#define AuOpts_TRUNC_XIB (1 << 2)
27674 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27675 +#define AuOpts_REFRESH_IDOP (1 << 4)
27676 +#define AuOpts_DR_FLUSHED (1 << 5)
27677 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27678 +#define au_fset_opts(flags, name) \
27679 + do { (flags) |= AuOpts_##name; } while (0)
27680 +#define au_fclr_opts(flags, name) \
27681 + do { (flags) &= ~AuOpts_##name; } while (0)
27683 +#ifndef CONFIG_AUFS_DIRREN
27684 +#undef AuOpts_DR_FLUSHED
27685 +#define AuOpts_DR_FLUSHED 0
27689 + struct au_opt *opt;
27692 + unsigned int given_udba;
27693 + unsigned int flags;
27694 + unsigned long sb_flags;
27697 +/* ---------------------------------------------------------------------- */
27700 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27701 +const char *au_optstr_udba(int udba);
27702 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27703 +const char *au_optstr_wbr_create(int wbr_create);
27705 +void au_opts_free(struct au_opts *opts);
27706 +struct super_block;
27707 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27708 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27709 + unsigned int pending);
27710 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27711 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27713 +unsigned int au_opt_udba(struct super_block *sb);
27715 +#endif /* __KERNEL__ */
27716 +#endif /* __AUFS_OPTS_H__ */
27717 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27718 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27719 +++ linux/fs/aufs/plink.c 2021-09-06 21:02:45.280158943 +0200
27721 +// SPDX-License-Identifier: GPL-2.0
27723 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27725 + * This program, aufs is free software; you can redistribute it and/or modify
27726 + * it under the terms of the GNU General Public License as published by
27727 + * the Free Software Foundation; either version 2 of the License, or
27728 + * (at your option) any later version.
27730 + * This program is distributed in the hope that it will be useful,
27731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27733 + * GNU General Public License for more details.
27735 + * You should have received a copy of the GNU General Public License
27736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27746 + * the pseudo-link maintenance mode.
27747 + * during a user process maintains the pseudo-links,
27748 + * prohibit adding a new plink and branch manipulation.
27752 + * For entry functions which will handle plink, and i_mutex is already held
27754 + * They cannot wait and should return an error at once.
27755 + * Callers has to check the error.
27757 + * For entry functions which will handle plink, but i_mutex is not held
27759 + * They can wait the plink maintenance mode to finish.
27761 + * They behave like F_SETLK and F_SETLKW.
27762 + * If the caller never handle plink, then both flags are unnecessary.
27765 +int au_plink_maint(struct super_block *sb, int flags)
27769 + struct task_struct *parent, *prev;
27770 + struct au_sbinfo *sbi;
27772 + SiMustAnyLock(sb);
27775 + if (!au_opt_test(au_mntflags(sb), PLINK))
27778 + sbi = au_sbi(sb);
27779 + pid = sbi->si_plink_maint_pid;
27780 + if (!pid || pid == current->pid)
27783 + /* todo: it highly depends upon /sbin/mount.aufs */
27785 + parent = current;
27789 + parent = rcu_dereference(parent->real_parent);
27790 + if (parent == prev)
27792 + ppid = task_pid_vnr(parent);
27793 + if (pid == ppid) {
27794 + rcu_read_unlock();
27799 + rcu_read_unlock();
27801 + if (au_ftest_lock(flags, NOPLMW)) {
27802 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27803 + /* AuDebugOn(!lockdep_depth(current)); */
27804 + while (sbi->si_plink_maint_pid) {
27805 + si_read_unlock(sb);
27806 + /* gave up wake_up_bit() */
27807 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27809 + if (au_ftest_lock(flags, FLUSH))
27810 + au_nwt_flush(&sbi->si_nowait);
27811 + si_noflush_read_lock(sb);
27813 + } else if (au_ftest_lock(flags, NOPLM)) {
27814 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27822 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27824 + spin_lock(&sbinfo->si_plink_maint_lock);
27825 + sbinfo->si_plink_maint_pid = 0;
27826 + spin_unlock(&sbinfo->si_plink_maint_lock);
27827 + wake_up_all(&sbinfo->si_plink_wq);
27830 +int au_plink_maint_enter(struct super_block *sb)
27833 + struct au_sbinfo *sbinfo;
27836 + sbinfo = au_sbi(sb);
27837 + /* make sure i am the only one in this fs */
27838 + si_write_lock(sb, AuLock_FLUSH);
27839 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27840 + spin_lock(&sbinfo->si_plink_maint_lock);
27841 + if (!sbinfo->si_plink_maint_pid)
27842 + sbinfo->si_plink_maint_pid = current->pid;
27845 + spin_unlock(&sbinfo->si_plink_maint_lock);
27847 + si_write_unlock(sb);
27852 +/* ---------------------------------------------------------------------- */
27854 +#ifdef CONFIG_AUFS_DEBUG
27855 +void au_plink_list(struct super_block *sb)
27858 + struct au_sbinfo *sbinfo;
27859 + struct hlist_bl_head *hbl;
27860 + struct hlist_bl_node *pos;
27861 + struct au_icntnr *icntnr;
27863 + SiMustAnyLock(sb);
27865 + sbinfo = au_sbi(sb);
27866 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27867 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27869 + for (i = 0; i < AuPlink_NHASH; i++) {
27870 + hbl = sbinfo->si_plink + i;
27871 + hlist_bl_lock(hbl);
27872 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27873 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27874 + hlist_bl_unlock(hbl);
27879 +/* is the inode pseudo-linked? */
27880 +int au_plink_test(struct inode *inode)
27883 + struct au_sbinfo *sbinfo;
27884 + struct hlist_bl_head *hbl;
27885 + struct hlist_bl_node *pos;
27886 + struct au_icntnr *icntnr;
27888 + sbinfo = au_sbi(inode->i_sb);
27889 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27890 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27891 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27894 + i = au_plink_hash(inode->i_ino);
27895 + hbl = sbinfo->si_plink + i;
27896 + hlist_bl_lock(hbl);
27897 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27898 + if (&icntnr->vfs_inode == inode) {
27902 + hlist_bl_unlock(hbl);
27906 +/* ---------------------------------------------------------------------- */
27909 + * generate a name for plink.
27910 + * the file will be stored under AUFS_WH_PLINKDIR.
27912 +/* 20 is max digits length of ulong 64 */
27913 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27915 +static int plink_name(char *name, int len, struct inode *inode,
27916 + aufs_bindex_t bindex)
27919 + struct inode *h_inode;
27921 + h_inode = au_h_iptr(inode, bindex);
27922 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27926 +struct au_do_plink_lkup_args {
27927 + struct dentry **errp;
27928 + struct qstr *tgtname;
27929 + struct dentry *h_parent;
27930 + struct au_branch *br;
27933 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27934 + struct dentry *h_parent,
27935 + struct au_branch *br)
27937 + struct dentry *h_dentry;
27938 + struct inode *h_inode;
27940 + h_inode = d_inode(h_parent);
27941 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27942 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27943 + inode_unlock_shared(h_inode);
27947 +static void au_call_do_plink_lkup(void *args)
27949 + struct au_do_plink_lkup_args *a = args;
27950 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27953 +/* lookup the plink-ed @inode under the branch at @bindex */
27954 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27956 + struct dentry *h_dentry, *h_parent;
27957 + struct au_branch *br;
27959 + char a[PLINK_NAME_LEN];
27960 + struct qstr tgtname = QSTR_INIT(a, 0);
27962 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27964 + br = au_sbr(inode->i_sb, bindex);
27965 + h_parent = br->br_wbr->wbr_plink;
27966 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27968 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27969 + struct au_do_plink_lkup_args args = {
27970 + .errp = &h_dentry,
27971 + .tgtname = &tgtname,
27972 + .h_parent = h_parent,
27976 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27977 + if (unlikely(wkq_err))
27978 + h_dentry = ERR_PTR(wkq_err);
27980 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27985 +/* create a pseudo-link */
27986 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27987 + struct dentry *h_dentry, struct au_branch *br)
27990 + struct path h_path = {
27991 + .mnt = au_br_mnt(br)
27993 + struct inode *h_dir, *delegated;
27995 + h_dir = d_inode(h_parent);
27996 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27998 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27999 + err = PTR_ERR(h_path.dentry);
28000 + if (IS_ERR(h_path.dentry))
28004 + /* wh.plink dir is not monitored */
28005 + /* todo: is it really safe? */
28006 + if (d_is_positive(h_path.dentry)
28007 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28008 + delegated = NULL;
28009 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28010 + if (unlikely(err == -EWOULDBLOCK)) {
28011 + pr_warn("cannot retry for NFSv4 delegation"
28012 + " for an internal unlink\n");
28015 + dput(h_path.dentry);
28016 + h_path.dentry = NULL;
28020 + if (!err && d_is_negative(h_path.dentry)) {
28021 + delegated = NULL;
28022 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28023 + if (unlikely(err == -EWOULDBLOCK)) {
28024 + pr_warn("cannot retry for NFSv4 delegation"
28025 + " for an internal link\n");
28029 + dput(h_path.dentry);
28032 + inode_unlock(h_dir);
28036 +struct do_whplink_args {
28038 + struct qstr *tgt;
28039 + struct dentry *h_parent;
28040 + struct dentry *h_dentry;
28041 + struct au_branch *br;
28044 +static void call_do_whplink(void *args)
28046 + struct do_whplink_args *a = args;
28047 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
28050 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28051 + aufs_bindex_t bindex, struct au_branch *br)
28053 + int err, wkq_err;
28054 + struct au_wbr *wbr;
28055 + struct dentry *h_parent;
28056 + char a[PLINK_NAME_LEN];
28057 + struct qstr tgtname = QSTR_INIT(a, 0);
28059 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28060 + h_parent = wbr->wbr_plink;
28061 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28063 + /* always superio. */
28064 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28065 + struct do_whplink_args args = {
28068 + .h_parent = h_parent,
28069 + .h_dentry = h_dentry,
28072 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28073 + if (unlikely(wkq_err))
28076 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28082 + * create a new pseudo-link for @h_dentry on @bindex.
28083 + * the linked inode is held in aufs @inode.
28085 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28086 + struct dentry *h_dentry)
28088 + struct super_block *sb;
28089 + struct au_sbinfo *sbinfo;
28090 + struct hlist_bl_head *hbl;
28091 + struct hlist_bl_node *pos;
28092 + struct au_icntnr *icntnr;
28093 + int found, err, cnt, i;
28095 + sb = inode->i_sb;
28096 + sbinfo = au_sbi(sb);
28097 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28098 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28100 + found = au_plink_test(inode);
28104 + i = au_plink_hash(inode->i_ino);
28105 + hbl = sbinfo->si_plink + i;
28108 + hlist_bl_lock(hbl);
28109 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28110 + if (&icntnr->vfs_inode == inode) {
28116 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28117 + hlist_bl_add_head(&icntnr->plink, hbl);
28119 + hlist_bl_unlock(hbl);
28121 + cnt = au_hbl_count(hbl);
28122 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28123 + if (cnt > AUFS_PLINK_WARN)
28124 + AuWarn1(msg ", %d\n", cnt);
28126 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28127 + if (unlikely(err)) {
28128 + pr_warn("err %d, damaged pseudo link.\n", err);
28129 + au_hbl_del(&icntnr->plink, hbl);
28130 + iput(&icntnr->vfs_inode);
28133 + iput(&icntnr->vfs_inode);
28136 +/* free all plinks */
28137 +void au_plink_put(struct super_block *sb, int verbose)
28140 + struct au_sbinfo *sbinfo;
28141 + struct hlist_bl_head *hbl;
28142 + struct hlist_bl_node *pos, *tmp;
28143 + struct au_icntnr *icntnr;
28145 + SiMustWriteLock(sb);
28147 + sbinfo = au_sbi(sb);
28148 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28149 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28151 + /* no spin_lock since sbinfo is write-locked */
28153 + for (i = 0; i < AuPlink_NHASH; i++) {
28154 + hbl = sbinfo->si_plink + i;
28155 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28156 + pr_warn("pseudo-link is not flushed");
28159 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28160 + iput(&icntnr->vfs_inode);
28161 + INIT_HLIST_BL_HEAD(hbl);
28165 +void au_plink_clean(struct super_block *sb, int verbose)
28167 + struct dentry *root;
28169 + root = sb->s_root;
28170 + aufs_write_lock(root);
28171 + if (au_opt_test(au_mntflags(sb), PLINK))
28172 + au_plink_put(sb, verbose);
28173 + aufs_write_unlock(root);
28176 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28179 + aufs_bindex_t btop, bbot, bindex;
28182 + btop = au_ibtop(inode);
28183 + bbot = au_ibbot(inode);
28185 + for (bindex = btop; bindex <= bbot; bindex++) {
28186 + if (!au_h_iptr(inode, bindex)
28187 + || au_ii_br_id(inode, bindex) != br_id)
28189 + au_set_h_iptr(inode, bindex, NULL, 0);
28194 + for (bindex = btop; bindex <= bbot; bindex++)
28195 + if (au_h_iptr(inode, bindex)) {
28205 +/* free the plinks on a branch specified by @br_id */
28206 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28208 + struct au_sbinfo *sbinfo;
28209 + struct hlist_bl_head *hbl;
28210 + struct hlist_bl_node *pos, *tmp;
28211 + struct au_icntnr *icntnr;
28212 + struct inode *inode;
28215 + SiMustWriteLock(sb);
28217 + sbinfo = au_sbi(sb);
28218 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28219 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28221 + /* no bit_lock since sbinfo is write-locked */
28222 + for (i = 0; i < AuPlink_NHASH; i++) {
28223 + hbl = sbinfo->si_plink + i;
28224 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28225 + inode = au_igrab(&icntnr->vfs_inode);
28226 + ii_write_lock_child(inode);
28227 + do_put = au_plink_do_half_refresh(inode, br_id);
28229 + hlist_bl_del(&icntnr->plink);
28232 + ii_write_unlock(inode);
28237 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28238 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28239 +++ linux/fs/aufs/poll.c 2021-09-06 21:02:45.280158943 +0200
28241 +// SPDX-License-Identifier: GPL-2.0
28243 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28245 + * This program, aufs is free software; you can redistribute it and/or modify
28246 + * it under the terms of the GNU General Public License as published by
28247 + * the Free Software Foundation; either version 2 of the License, or
28248 + * (at your option) any later version.
28250 + * This program is distributed in the hope that it will be useful,
28251 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28252 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28253 + * GNU General Public License for more details.
28255 + * You should have received a copy of the GNU General Public License
28256 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28261 + * There is only one filesystem which implements ->poll operation, currently.
28266 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28269 + struct file *h_file;
28270 + struct super_block *sb;
28272 + /* We should pretend an error happened. */
28273 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28274 + sb = file->f_path.dentry->d_sb;
28275 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28277 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28278 + if (IS_ERR(h_file)) {
28279 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28283 + mask = vfs_poll(h_file, pt);
28284 + fput(h_file); /* instead of au_read_post() */
28287 + si_read_unlock(sb);
28288 + if (mask & EPOLLERR)
28289 + AuDbg("mask 0x%x\n", mask);
28292 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28293 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28294 +++ linux/fs/aufs/posix_acl.c 2021-09-06 21:02:45.280158943 +0200
28296 +// SPDX-License-Identifier: GPL-2.0
28298 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28300 + * This program, aufs is free software; you can redistribute it and/or modify
28301 + * it under the terms of the GNU General Public License as published by
28302 + * the Free Software Foundation; either version 2 of the License, or
28303 + * (at your option) any later version.
28305 + * This program is distributed in the hope that it will be useful,
28306 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28307 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28308 + * GNU General Public License for more details.
28310 + * You should have received a copy of the GNU General Public License
28311 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28315 + * posix acl operations
28318 +#include <linux/fs.h>
28321 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28323 + struct posix_acl *acl;
28325 + aufs_bindex_t bindex;
28326 + struct inode *h_inode;
28327 + struct super_block *sb;
28330 + sb = inode->i_sb;
28331 + si_read_lock(sb, AuLock_FLUSH);
28332 + ii_read_lock_child(inode);
28333 + if (!(sb->s_flags & SB_POSIXACL))
28336 + bindex = au_ibtop(inode);
28337 + h_inode = au_h_iptr(inode, bindex);
28338 + if (unlikely(!h_inode
28339 + || ((h_inode->i_mode & S_IFMT)
28340 + != (inode->i_mode & S_IFMT)))) {
28341 + err = au_busy_or_stale();
28342 + acl = ERR_PTR(err);
28346 + /* always topmost only */
28347 + acl = get_acl(h_inode, type);
28349 + forget_cached_acl(inode, type);
28351 + set_cached_acl(inode, type, acl);
28354 + ii_read_unlock(inode);
28355 + si_read_unlock(sb);
28357 + AuTraceErrPtr(acl);
28361 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28362 + struct posix_acl *acl, int type)
28366 + struct dentry *dentry;
28367 + struct au_sxattr arg = {
28368 + .type = AU_ACL_SET,
28375 + IMustLock(inode);
28377 + if (inode->i_ino == AUFS_ROOT_INO)
28378 + dentry = dget(inode->i_sb->s_root);
28380 + dentry = d_find_alias(inode);
28382 + dentry = d_find_any_alias(inode);
28384 + pr_warn("cannot handle this inode, "
28385 + "please report to aufs-users ML\n");
28391 + ssz = au_sxattr(dentry, inode, &arg);
28392 + /* forget even it if succeeds since the branch might set differently */
28393 + forget_cached_acl(inode, type);
28402 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28403 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28404 +++ linux/fs/aufs/procfs.c 2021-09-06 21:02:45.280158943 +0200
28406 +// SPDX-License-Identifier: GPL-2.0
28408 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28410 + * This program, aufs is free software; you can redistribute it and/or modify
28411 + * it under the terms of the GNU General Public License as published by
28412 + * the Free Software Foundation; either version 2 of the License, or
28413 + * (at your option) any later version.
28415 + * This program is distributed in the hope that it will be useful,
28416 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28417 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28418 + * GNU General Public License for more details.
28420 + * You should have received a copy of the GNU General Public License
28421 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28425 + * procfs interfaces
28428 +#include <linux/proc_fs.h>
28431 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28433 + struct au_sbinfo *sbinfo;
28435 + sbinfo = file->private_data;
28437 + au_plink_maint_leave(sbinfo);
28438 + kobject_put(&sbinfo->si_kobj);
28444 +static void au_procfs_plm_write_clean(struct file *file)
28446 + struct au_sbinfo *sbinfo;
28448 + sbinfo = file->private_data;
28450 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28453 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28456 + struct super_block *sb;
28457 + struct au_sbinfo *sbinfo;
28458 + struct hlist_bl_node *pos;
28461 + if (unlikely(file->private_data))
28465 + /* don't use au_sbilist_lock() here */
28466 + hlist_bl_lock(&au_sbilist);
28467 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28468 + if (id == sysaufs_si_id(sbinfo)) {
28469 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28470 + sb = sbinfo->si_sb;
28473 + hlist_bl_unlock(&au_sbilist);
28476 + if (unlikely(!sb))
28479 + err = au_plink_maint_enter(sb);
28481 + /* keep kobject_get() */
28482 + file->private_data = sbinfo;
28484 + kobject_put(&sbinfo->si_kobj);
28490 + * Accept a valid "si=xxxx" only.
28491 + * Once it is accepted successfully, accept "clean" too.
28493 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28494 + size_t count, loff_t *ppos)
28497 + unsigned long id;
28498 + /* last newline is allowed */
28499 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28502 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28506 + if (unlikely(count > sizeof(buf)))
28509 + err = copy_from_user(buf, ubuf, count);
28510 + if (unlikely(err)) {
28517 + if (!strcmp("clean", buf)) {
28518 + au_procfs_plm_write_clean(file);
28519 + goto out_success;
28520 + } else if (unlikely(strncmp("si=", buf, 3)))
28523 + err = kstrtoul(buf + 3, 16, &id);
28524 + if (unlikely(err))
28527 + err = au_procfs_plm_write_si(file, id);
28528 + if (unlikely(err))
28532 + err = count; /* success */
28537 +static const struct proc_ops au_procfs_plm_op = {
28538 + .proc_write = au_procfs_plm_write,
28539 + .proc_release = au_procfs_plm_release
28542 +/* ---------------------------------------------------------------------- */
28544 +static struct proc_dir_entry *au_procfs_dir;
28546 +void au_procfs_fin(void)
28548 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28549 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28552 +int __init au_procfs_init(void)
28555 + struct proc_dir_entry *entry;
28558 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28559 + if (unlikely(!au_procfs_dir))
28562 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28563 + au_procfs_dir, &au_procfs_plm_op);
28564 + if (unlikely(!entry))
28568 + goto out; /* success */
28572 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28576 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28577 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28578 +++ linux/fs/aufs/rdu.c 2021-09-06 21:02:45.280158943 +0200
28580 +// SPDX-License-Identifier: GPL-2.0
28582 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28584 + * This program, aufs is free software; you can redistribute it and/or modify
28585 + * it under the terms of the GNU General Public License as published by
28586 + * the Free Software Foundation; either version 2 of the License, or
28587 + * (at your option) any later version.
28589 + * This program is distributed in the hope that it will be useful,
28590 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28591 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28592 + * GNU General Public License for more details.
28594 + * You should have received a copy of the GNU General Public License
28595 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28599 + * readdir in userspace.
28602 +#include <linux/compat.h>
28603 +#include <linux/fs_stack.h>
28604 +#include <linux/security.h>
28607 +/* bits for struct aufs_rdu.flags */
28608 +#define AuRdu_CALLED 1
28609 +#define AuRdu_CONT (1 << 1)
28610 +#define AuRdu_FULL (1 << 2)
28611 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28612 +#define au_fset_rdu(flags, name) \
28613 + do { (flags) |= AuRdu_##name; } while (0)
28614 +#define au_fclr_rdu(flags, name) \
28615 + do { (flags) &= ~AuRdu_##name; } while (0)
28617 +struct au_rdu_arg {
28618 + struct dir_context ctx;
28619 + struct aufs_rdu *rdu;
28620 + union au_rdu_ent_ul ent;
28621 + unsigned long end;
28623 + struct super_block *sb;
28627 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28628 + loff_t offset, u64 h_ino, unsigned int d_type)
28631 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28632 + struct aufs_rdu *rdu = arg->rdu;
28633 + struct au_rdu_ent ent;
28637 + au_fset_rdu(rdu->cookie.flags, CALLED);
28638 + len = au_rdu_len(nlen);
28639 + if (arg->ent.ul + len < arg->end) {
28641 + ent.bindex = rdu->cookie.bindex;
28642 + ent.type = d_type;
28644 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28645 + ent.type = DT_UNKNOWN;
28647 + /* unnecessary to support mmap_sem since this is a dir */
28649 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28651 + if (copy_to_user(arg->ent.e->name, name, nlen))
28653 + /* the terminating NULL */
28654 + if (__put_user(0, arg->ent.e->name + nlen))
28657 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28658 + arg->ent.ul += len;
28662 + au_fset_rdu(rdu->cookie.flags, FULL);
28664 + rdu->tail = arg->ent;
28668 + /* AuTraceErr(err); */
28672 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28676 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28678 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28679 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28681 + if (unlikely(offset != cookie->h_pos))
28687 + au_fclr_rdu(cookie->flags, CALLED);
28689 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28693 + && au_ftest_rdu(cookie->flags, CALLED)
28694 + && !au_ftest_rdu(cookie->flags, FULL));
28695 + cookie->h_pos = h_file->f_pos;
28702 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28705 + aufs_bindex_t bbot;
28706 + struct au_rdu_arg arg = {
28708 + .actor = au_rdu_fill
28711 + struct dentry *dentry;
28712 + struct inode *inode;
28713 + struct file *h_file;
28714 + struct au_rdu_cookie *cookie = &rdu->cookie;
28716 + /* VERIFY_WRITE */
28717 + err = !access_ok(rdu->ent.e, rdu->sz);
28718 + if (unlikely(err)) {
28724 + rdu->tail = rdu->ent;
28727 + arg.ent = rdu->ent;
28728 + arg.end = arg.ent.ul;
28729 + arg.end += rdu->sz;
28732 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28735 + err = security_file_permission(file, MAY_READ);
28737 + if (unlikely(err))
28740 + dentry = file->f_path.dentry;
28741 + inode = d_inode(dentry);
28742 + inode_lock_shared(inode);
28744 + arg.sb = inode->i_sb;
28745 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28746 + if (unlikely(err))
28748 + err = au_alive_dir(dentry);
28749 + if (unlikely(err))
28751 + /* todo: reval? */
28752 + fi_read_lock(file);
28755 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28756 + && cookie->generation != au_figen(file)))
28761 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28763 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28765 + bbot = au_fbtop(file);
28766 + if (cookie->bindex < bbot)
28767 + cookie->bindex = bbot;
28768 + bbot = au_fbbot_dir(file);
28769 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28770 + for (; !err && cookie->bindex <= bbot;
28771 + cookie->bindex++, cookie->h_pos = 0) {
28772 + h_file = au_hf_dir(file, cookie->bindex);
28776 + au_fclr_rdu(cookie->flags, FULL);
28777 + err = au_rdu_do(h_file, &arg);
28779 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28782 + AuDbg("rent %llu\n", rdu->rent);
28784 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28785 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28786 + au_fset_rdu(cookie->flags, CONT);
28787 + cookie->generation = au_figen(file);
28790 + ii_read_lock_child(inode);
28791 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28792 + ii_read_unlock(inode);
28795 + fi_read_unlock(file);
28797 + si_read_unlock(arg.sb);
28799 + inode_unlock_shared(inode);
28805 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28809 + unsigned long long nent;
28810 + union au_rdu_ent_ul *u;
28811 + struct au_rdu_ent ent;
28812 + struct super_block *sb;
28815 + nent = rdu->nent;
28817 + sb = file->f_path.dentry->d_sb;
28818 + si_read_lock(sb, AuLock_FLUSH);
28819 + while (nent-- > 0) {
28820 + /* unnecessary to support mmap_sem since this is a dir */
28821 + err = copy_from_user(&ent, u->e, sizeof(ent));
28823 + /* VERIFY_WRITE */
28824 + err = !access_ok(&u->e->ino, sizeof(ino));
28825 + if (unlikely(err)) {
28831 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28833 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28835 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28837 + if (unlikely(err)) {
28842 + err = __put_user(ino, &u->e->ino);
28843 + if (unlikely(err)) {
28848 + u->ul += au_rdu_len(ent.nlen);
28850 + si_read_unlock(sb);
28855 +/* ---------------------------------------------------------------------- */
28857 +static int au_rdu_verify(struct aufs_rdu *rdu)
28859 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28860 + "%llu, b%d, 0x%x, g%u}\n",
28861 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28863 + rdu->rent, rdu->shwh, rdu->full,
28864 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28865 + rdu->cookie.generation);
28867 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28871 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28875 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28878 + struct aufs_rdu rdu;
28879 + void __user *p = (void __user *)arg;
28881 + err = copy_from_user(&rdu, p, sizeof(rdu));
28882 + if (unlikely(err)) {
28887 + err = au_rdu_verify(&rdu);
28888 + if (unlikely(err))
28892 + case AUFS_CTL_RDU:
28893 + err = au_rdu(file, &rdu);
28894 + if (unlikely(err))
28897 + e = copy_to_user(p, &rdu, sizeof(rdu));
28898 + if (unlikely(e)) {
28903 + case AUFS_CTL_RDU_INO:
28904 + err = au_rdu_ino(file, &rdu);
28908 + /* err = -ENOTTY; */
28917 +#ifdef CONFIG_COMPAT
28918 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28921 + struct aufs_rdu rdu;
28922 + void __user *p = compat_ptr(arg);
28924 + /* todo: get_user()? */
28925 + err = copy_from_user(&rdu, p, sizeof(rdu));
28926 + if (unlikely(err)) {
28931 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28932 + err = au_rdu_verify(&rdu);
28933 + if (unlikely(err))
28937 + case AUFS_CTL_RDU:
28938 + err = au_rdu(file, &rdu);
28939 + if (unlikely(err))
28942 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28943 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28944 + e = copy_to_user(p, &rdu, sizeof(rdu));
28945 + if (unlikely(e)) {
28950 + case AUFS_CTL_RDU_INO:
28951 + err = au_rdu_ino(file, &rdu);
28955 + /* err = -ENOTTY; */
28964 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28965 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28966 +++ linux/fs/aufs/rwsem.h 2021-09-06 21:02:45.280158943 +0200
28968 +/* SPDX-License-Identifier: GPL-2.0 */
28970 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28972 + * This program, aufs is free software; you can redistribute it and/or modify
28973 + * it under the terms of the GNU General Public License as published by
28974 + * the Free Software Foundation; either version 2 of the License, or
28975 + * (at your option) any later version.
28977 + * This program is distributed in the hope that it will be useful,
28978 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28979 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28980 + * GNU General Public License for more details.
28982 + * You should have received a copy of the GNU General Public License
28983 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28987 + * simple read-write semaphore wrappers
28990 +#ifndef __AUFS_RWSEM_H__
28991 +#define __AUFS_RWSEM_H__
28995 +#include "debug.h"
28997 +/* in the future, the name 'au_rwsem' will be totally gone */
28998 +#define au_rwsem rw_semaphore
29000 +/* to debug easier, do not make them inlined functions */
29001 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29003 +#ifdef CONFIG_LOCKDEP
29004 +/* rwsem_is_locked() is unusable */
29005 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29006 + && !lockdep_recursing(current) \
29008 + && !lockdep_is_held_type(rw, 1))
29009 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29010 + && !lockdep_recursing(current) \
29012 + && !lockdep_is_held_type(rw, 0))
29013 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29014 + && !lockdep_recursing(current) \
29016 + && !lockdep_is_held(rw))
29017 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29018 + && !lockdep_recursing(current) \
29020 + && lockdep_is_held(rw))
29022 +#define AuRwMustReadLock(rw) do {} while (0)
29023 +#define AuRwMustWriteLock(rw) do {} while (0)
29024 +#define AuRwMustAnyLock(rw) do {} while (0)
29025 +#define AuRwDestroy(rw) do {} while (0)
29028 +#define au_rw_init(rw) init_rwsem(rw)
29030 +#define au_rw_init_wlock(rw) do { \
29031 + au_rw_init(rw); \
29032 + down_write(rw); \
29035 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29036 + au_rw_init(rw); \
29037 + down_write_nested(rw, lsc); \
29040 +#define au_rw_read_lock(rw) down_read(rw)
29041 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29042 +#define au_rw_read_unlock(rw) up_read(rw)
29043 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29044 +#define au_rw_write_lock(rw) down_write(rw)
29045 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29046 +#define au_rw_write_unlock(rw) up_write(rw)
29047 +/* why is not _nested version defined? */
29048 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29049 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29051 +#endif /* __KERNEL__ */
29052 +#endif /* __AUFS_RWSEM_H__ */
29053 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29054 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29055 +++ linux/fs/aufs/sbinfo.c 2021-09-06 21:02:45.280158943 +0200
29057 +// SPDX-License-Identifier: GPL-2.0
29059 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29061 + * This program, aufs is free software; you can redistribute it and/or modify
29062 + * it under the terms of the GNU General Public License as published by
29063 + * the Free Software Foundation; either version 2 of the License, or
29064 + * (at your option) any later version.
29066 + * This program is distributed in the hope that it will be useful,
29067 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29068 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29069 + * GNU General Public License for more details.
29071 + * You should have received a copy of the GNU General Public License
29072 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29076 + * superblock private data
29079 +#include <linux/iversion.h>
29083 + * they are necessary regardless sysfs is disabled.
29085 +void au_si_free(struct kobject *kobj)
29088 + struct au_sbinfo *sbinfo;
29089 + char *locked __maybe_unused; /* debug only */
29091 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29092 + for (i = 0; i < AuPlink_NHASH; i++)
29093 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29094 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29096 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29097 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29098 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29099 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29101 + dbgaufs_si_fin(sbinfo);
29102 + au_rw_write_lock(&sbinfo->si_rwsem);
29103 + au_br_free(sbinfo);
29104 + au_rw_write_unlock(&sbinfo->si_rwsem);
29106 + au_kfree_try_rcu(sbinfo->si_branch);
29107 + mutex_destroy(&sbinfo->si_xib_mtx);
29108 + AuRwDestroy(&sbinfo->si_rwsem);
29110 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29111 + /* si_nfiles is waited too */
29112 + au_kfree_rcu(sbinfo);
29115 +int au_si_alloc(struct super_block *sb)
29118 + struct au_sbinfo *sbinfo;
29121 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29122 + if (unlikely(!sbinfo))
29125 + /* will be reallocated separately */
29126 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29127 + if (unlikely(!sbinfo->si_branch))
29130 + err = sysaufs_si_init(sbinfo);
29132 + dbgaufs_si_null(sbinfo);
29133 + err = dbgaufs_si_init(sbinfo);
29134 + if (unlikely(err))
29135 + kobject_put(&sbinfo->si_kobj);
29137 + if (unlikely(err))
29140 + au_nwt_init(&sbinfo->si_nowait);
29141 + au_rw_init_wlock(&sbinfo->si_rwsem);
29143 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29144 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29146 + sbinfo->si_bbot = -1;
29147 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29149 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29150 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29151 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29152 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29154 + au_fhsm_init(sbinfo);
29156 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29158 + sbinfo->si_xino_jiffy = jiffies;
29159 + sbinfo->si_xino_expire
29160 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29161 + mutex_init(&sbinfo->si_xib_mtx);
29162 + /* leave si_xib_last_pindex and si_xib_next_bit */
29164 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29166 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29167 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29168 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29169 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29171 + for (i = 0; i < AuPlink_NHASH; i++)
29172 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29173 + init_waitqueue_head(&sbinfo->si_plink_wq);
29174 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29176 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29178 + /* with getattr by default */
29179 + sbinfo->si_iop_array = aufs_iop;
29181 + /* leave other members for sysaufs and si_mnt. */
29182 + sbinfo->si_sb = sb;
29183 + sb->s_fs_info = sbinfo;
29185 + return 0; /* success */
29188 + au_kfree_try_rcu(sbinfo->si_branch);
29190 + au_kfree_rcu(sbinfo);
29195 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29198 + struct au_branch **brp;
29200 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29203 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29204 + if (unlikely(!sz))
29205 + sz = sizeof(*brp);
29206 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29209 + sbinfo->si_branch = brp;
29216 +/* ---------------------------------------------------------------------- */
29218 +unsigned int au_sigen_inc(struct super_block *sb)
29220 + unsigned int gen;
29221 + struct inode *inode;
29223 + SiMustWriteLock(sb);
29225 + gen = ++au_sbi(sb)->si_generation;
29226 + au_update_digen(sb->s_root);
29227 + inode = d_inode(sb->s_root);
29228 + au_update_iigen(inode, /*half*/0);
29229 + inode_inc_iversion(inode);
29233 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29235 + aufs_bindex_t br_id;
29237 + struct au_sbinfo *sbinfo;
29239 + SiMustWriteLock(sb);
29241 + sbinfo = au_sbi(sb);
29242 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29243 + br_id = ++sbinfo->si_last_br_id;
29244 + AuDebugOn(br_id < 0);
29245 + if (br_id && au_br_index(sb, br_id) < 0)
29252 +/* ---------------------------------------------------------------------- */
29254 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29255 +int si_read_lock(struct super_block *sb, int flags)
29260 + if (au_ftest_lock(flags, FLUSH))
29261 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29263 + si_noflush_read_lock(sb);
29264 + err = au_plink_maint(sb, flags);
29265 + if (unlikely(err))
29266 + si_read_unlock(sb);
29271 +int si_write_lock(struct super_block *sb, int flags)
29275 + if (au_ftest_lock(flags, FLUSH))
29276 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29278 + si_noflush_write_lock(sb);
29279 + err = au_plink_maint(sb, flags);
29280 + if (unlikely(err))
29281 + si_write_unlock(sb);
29286 +/* dentry and super_block lock. call at entry point */
29287 +int aufs_read_lock(struct dentry *dentry, int flags)
29290 + struct super_block *sb;
29292 + sb = dentry->d_sb;
29293 + err = si_read_lock(sb, flags);
29294 + if (unlikely(err))
29297 + if (au_ftest_lock(flags, DW))
29298 + di_write_lock_child(dentry);
29300 + di_read_lock_child(dentry, flags);
29302 + if (au_ftest_lock(flags, GEN)) {
29303 + err = au_digen_test(dentry, au_sigen(sb));
29304 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29305 + AuDebugOn(!err && au_dbrange_test(dentry));
29307 + err = au_dbrange_test(dentry);
29308 + if (unlikely(err))
29309 + aufs_read_unlock(dentry, flags);
29316 +void aufs_read_unlock(struct dentry *dentry, int flags)
29318 + if (au_ftest_lock(flags, DW))
29319 + di_write_unlock(dentry);
29321 + di_read_unlock(dentry, flags);
29322 + si_read_unlock(dentry->d_sb);
29325 +void aufs_write_lock(struct dentry *dentry)
29327 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29328 + di_write_lock_child(dentry);
29331 +void aufs_write_unlock(struct dentry *dentry)
29333 + di_write_unlock(dentry);
29334 + si_write_unlock(dentry->d_sb);
29337 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29340 + unsigned int sigen;
29341 + struct super_block *sb;
29344 + err = si_read_lock(sb, flags);
29345 + if (unlikely(err))
29348 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29350 + if (au_ftest_lock(flags, GEN)) {
29351 + sigen = au_sigen(sb);
29352 + err = au_digen_test(d1, sigen);
29353 + AuDebugOn(!err && au_dbrange_test(d1));
29355 + err = au_digen_test(d2, sigen);
29356 + AuDebugOn(!err && au_dbrange_test(d2));
29358 + if (unlikely(err))
29359 + aufs_read_and_write_unlock2(d1, d2);
29366 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29368 + di_write_unlock2(d1, d2);
29369 + si_read_unlock(d1->d_sb);
29371 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29372 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29373 +++ linux/fs/aufs/super.c 2021-09-06 21:02:45.280158943 +0200
29375 +// SPDX-License-Identifier: GPL-2.0
29377 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29379 + * This program, aufs is free software; you can redistribute it and/or modify
29380 + * it under the terms of the GNU General Public License as published by
29381 + * the Free Software Foundation; either version 2 of the License, or
29382 + * (at your option) any later version.
29384 + * This program is distributed in the hope that it will be useful,
29385 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29387 + * GNU General Public License for more details.
29389 + * You should have received a copy of the GNU General Public License
29390 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29394 + * mount and super_block operations
29397 +#include <linux/iversion.h>
29398 +#include <linux/mm.h>
29399 +#include <linux/seq_file.h>
29400 +#include <linux/statfs.h>
29401 +#include <linux/vmalloc.h>
29405 + * super_operations
29407 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29409 + struct au_icntnr *c;
29411 + c = au_cache_alloc_icntnr();
29413 + au_icntnr_init(c);
29414 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29415 + c->iinfo.ii_hinode = NULL;
29416 + return &c->vfs_inode;
29421 +static void aufs_destroy_inode(struct inode *inode)
29423 + if (!au_is_bad_inode(inode))
29424 + au_iinfo_fin(inode);
29427 +static void aufs_free_inode(struct inode *inode)
29429 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29432 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29434 + struct inode *inode;
29437 + inode = iget_locked(sb, ino);
29438 + if (unlikely(!inode)) {
29439 + inode = ERR_PTR(-ENOMEM);
29442 + if (!(inode->i_state & I_NEW))
29445 + err = au_xigen_new(inode);
29447 + err = au_iinfo_init(inode);
29449 + inode_inc_iversion(inode);
29451 + iget_failed(inode);
29452 + inode = ERR_PTR(err);
29456 + /* never return NULL */
29457 + AuDebugOn(!inode);
29458 + AuTraceErrPtr(inode);
29462 +/* lock free root dinfo */
29463 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29466 + aufs_bindex_t bindex, bbot;
29467 + struct path path;
29468 + struct au_hdentry *hdp;
29469 + struct au_branch *br;
29470 + au_br_perm_str_t perm;
29473 + bbot = au_sbbot(sb);
29475 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29476 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29477 + br = au_sbr(sb, bindex);
29478 + path.mnt = au_br_mnt(br);
29479 + path.dentry = hdp->hd_dentry;
29480 + err = au_seq_path(seq, &path);
29482 + au_optstr_br_perm(&perm, br->br_perm);
29483 + seq_printf(seq, "=%s", perm.a);
29484 + if (bindex != bbot)
29485 + seq_putc(seq, ':');
29488 + if (unlikely(err || seq_has_overflowed(seq)))
29494 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29495 + const char *append)
29500 + while (*pat != ':')
29503 + strcpy(p, append);
29504 + AuDebugOn(strlen(fmt) >= len);
29507 +static void au_show_wbr_create(struct seq_file *m, int v,
29508 + struct au_sbinfo *sbinfo)
29512 + struct au_wbr_mfs *mfs;
29514 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29516 + seq_puts(m, ",create=");
29517 + pat = au_optstr_wbr_create(v);
29518 + mfs = &sbinfo->si_wbr_mfs;
29520 + case AuWbrCreate_TDP:
29521 + case AuWbrCreate_RR:
29522 + case AuWbrCreate_MFS:
29523 + case AuWbrCreate_PMFS:
29524 + seq_puts(m, pat);
29526 + case AuWbrCreate_MFSRR:
29527 + case AuWbrCreate_TDMFS:
29528 + case AuWbrCreate_PMFSRR:
29529 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29530 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29532 + case AuWbrCreate_MFSV:
29533 + case AuWbrCreate_PMFSV:
29534 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29535 + seq_printf(m, fmt,
29536 + jiffies_to_msecs(mfs->mfs_expire)
29539 + case AuWbrCreate_MFSRRV:
29540 + case AuWbrCreate_TDMFSV:
29541 + case AuWbrCreate_PMFSRRV:
29542 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29543 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29544 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29551 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29553 +#ifdef CONFIG_SYSFS
29557 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29558 + aufs_bindex_t bindex, brid;
29559 + struct qstr *name;
29561 + struct dentry *d, *h_root;
29562 + struct au_branch *br;
29564 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29567 + f = au_sbi(sb)->si_xib;
29571 + /* stop printing the default xino path on the first writable branch */
29573 + bindex = au_xi_root(sb, f->f_path.dentry);
29574 + if (bindex >= 0) {
29575 + br = au_sbr_sb(sb, bindex);
29576 + h_root = au_br_dentry(br);
29579 + d = f->f_path.dentry;
29580 + name = &d->d_name;
29581 + /* safe ->d_parent because the file is unlinked */
29582 + if (d->d_parent == h_root
29583 + && name->len == len
29584 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29587 + seq_puts(seq, ",xino=");
29588 + err = au_xino_path(seq, f);
29595 +/* seq_file will re-call me in case of too long string */
29596 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29599 + unsigned int mnt_flags, v;
29600 + struct super_block *sb;
29601 + struct au_sbinfo *sbinfo;
29603 +#define AuBool(name, str) do { \
29604 + v = au_opt_test(mnt_flags, name); \
29605 + if (v != au_opt_test(AuOpt_Def, name)) \
29606 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29609 +#define AuStr(name, str) do { \
29610 + v = mnt_flags & AuOptMask_##name; \
29611 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29612 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29615 +#define AuUInt(name, str, val) do { \
29616 + if (val != AUFS_##name##_DEF) \
29617 + seq_printf(m, "," #str "=%u", val); \
29620 + sb = dentry->d_sb;
29621 + if (sb->s_flags & SB_POSIXACL)
29622 + seq_puts(m, ",acl");
29623 +#if 0 /* reserved for future use */
29624 + if (sb->s_flags & SB_I_VERSION)
29625 + seq_puts(m, ",i_version");
29628 + /* lock free root dinfo */
29629 + si_noflush_read_lock(sb);
29630 + sbinfo = au_sbi(sb);
29631 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29633 + mnt_flags = au_mntflags(sb);
29634 + if (au_opt_test(mnt_flags, XINO)) {
29635 + err = au_show_xino(m, sb);
29636 + if (unlikely(err))
29639 + seq_puts(m, ",noxino");
29641 + AuBool(TRUNC_XINO, trunc_xino);
29642 + AuStr(UDBA, udba);
29643 + AuBool(SHWH, shwh);
29644 + AuBool(PLINK, plink);
29645 + AuBool(DIO, dio);
29646 + AuBool(DIRPERM1, dirperm1);
29648 + v = sbinfo->si_wbr_create;
29649 + if (v != AuWbrCreate_Def)
29650 + au_show_wbr_create(m, v, sbinfo);
29652 + v = sbinfo->si_wbr_copyup;
29653 + if (v != AuWbrCopyup_Def)
29654 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29656 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29657 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29658 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29660 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29662 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29663 + AuUInt(RDCACHE, rdcache, v);
29665 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29666 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29668 + au_fhsm_show(m, sbinfo);
29670 + AuBool(DIRREN, dirren);
29671 + AuBool(SUM, sum);
29672 + /* AuBool(SUM_W, wsum); */
29673 + AuBool(WARN_PERM, warn_perm);
29674 + AuBool(VERBOSE, verbose);
29677 + /* be sure to print "br:" last */
29678 + if (!sysaufs_brs) {
29679 + seq_puts(m, ",br:");
29680 + au_show_brs(m, sb);
29682 + si_read_unlock(sb);
29690 +/* ---------------------------------------------------------------------- */
29692 +/* sum mode which returns the summation for statfs(2) */
29694 +static u64 au_add_till_max(u64 a, u64 b)
29702 + return ULLONG_MAX;
29705 +static u64 au_mul_till_max(u64 a, long mul)
29713 + return ULLONG_MAX;
29716 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29719 + long bsize, factor;
29720 + u64 blocks, bfree, bavail, files, ffree;
29721 + aufs_bindex_t bbot, bindex, i;
29722 + unsigned char shared;
29723 + struct path h_path;
29724 + struct super_block *h_sb;
29727 + bsize = LONG_MAX;
29733 + bbot = au_sbbot(sb);
29734 + for (bindex = 0; bindex <= bbot; bindex++) {
29735 + h_path.mnt = au_sbr_mnt(sb, bindex);
29736 + h_sb = h_path.mnt->mnt_sb;
29738 + for (i = 0; !shared && i < bindex; i++)
29739 + shared = (au_sbr_sb(sb, i) == h_sb);
29743 + /* sb->s_root for NFS is unreliable */
29744 + h_path.dentry = h_path.mnt->mnt_root;
29745 + err = vfs_statfs(&h_path, buf);
29746 + if (unlikely(err))
29749 + if (bsize > buf->f_bsize) {
29751 + * we will reduce bsize, so we have to expand blocks
29752 + * etc. to match them again
29754 + factor = (bsize / buf->f_bsize);
29755 + blocks = au_mul_till_max(blocks, factor);
29756 + bfree = au_mul_till_max(bfree, factor);
29757 + bavail = au_mul_till_max(bavail, factor);
29758 + bsize = buf->f_bsize;
29761 + factor = (buf->f_bsize / bsize);
29762 + blocks = au_add_till_max(blocks,
29763 + au_mul_till_max(buf->f_blocks, factor));
29764 + bfree = au_add_till_max(bfree,
29765 + au_mul_till_max(buf->f_bfree, factor));
29766 + bavail = au_add_till_max(bavail,
29767 + au_mul_till_max(buf->f_bavail, factor));
29768 + files = au_add_till_max(files, buf->f_files);
29769 + ffree = au_add_till_max(ffree, buf->f_ffree);
29772 + buf->f_bsize = bsize;
29773 + buf->f_blocks = blocks;
29774 + buf->f_bfree = bfree;
29775 + buf->f_bavail = bavail;
29776 + buf->f_files = files;
29777 + buf->f_ffree = ffree;
29778 + buf->f_frsize = 0;
29784 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29787 + struct path h_path;
29788 + struct super_block *sb;
29790 + /* lock free root dinfo */
29791 + sb = dentry->d_sb;
29792 + si_noflush_read_lock(sb);
29793 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29794 + /* sb->s_root for NFS is unreliable */
29795 + h_path.mnt = au_sbr_mnt(sb, 0);
29796 + h_path.dentry = h_path.mnt->mnt_root;
29797 + err = vfs_statfs(&h_path, buf);
29799 + err = au_statfs_sum(sb, buf);
29800 + si_read_unlock(sb);
29803 + buf->f_type = AUFS_SUPER_MAGIC;
29804 + buf->f_namelen = AUFS_MAX_NAMELEN;
29805 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29807 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29812 +/* ---------------------------------------------------------------------- */
29814 +static int aufs_sync_fs(struct super_block *sb, int wait)
29817 + aufs_bindex_t bbot, bindex;
29818 + struct au_branch *br;
29819 + struct super_block *h_sb;
29822 + si_noflush_read_lock(sb);
29823 + bbot = au_sbbot(sb);
29824 + for (bindex = 0; bindex <= bbot; bindex++) {
29825 + br = au_sbr(sb, bindex);
29826 + if (!au_br_writable(br->br_perm))
29829 + h_sb = au_sbr_sb(sb, bindex);
29830 + e = vfsub_sync_filesystem(h_sb, wait);
29831 + if (unlikely(e && !err))
29833 + /* go on even if an error happens */
29835 + si_read_unlock(sb);
29840 +/* ---------------------------------------------------------------------- */
29842 +/* final actions when unmounting a file system */
29843 +static void aufs_put_super(struct super_block *sb)
29845 + struct au_sbinfo *sbinfo;
29847 + sbinfo = au_sbi(sb);
29849 + kobject_put(&sbinfo->si_kobj);
29852 +/* ---------------------------------------------------------------------- */
29854 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29855 + struct super_block *sb, void *arg)
29858 + unsigned long long n, sz;
29865 + if (*hint > ULLONG_MAX / sizeof(array)) {
29866 + array = ERR_PTR(-EMFILE);
29867 + pr_err("hint %llu\n", *hint);
29871 + sz = sizeof(array) * *hint;
29872 + array = kzalloc(sz, GFP_NOFS);
29873 + if (unlikely(!array))
29874 + array = vzalloc(sz);
29875 + if (unlikely(!array)) {
29876 + array = ERR_PTR(-ENOMEM);
29880 + n = cb(sb, array, *hint, arg);
29881 + AuDebugOn(n > *hint);
29888 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29889 + unsigned long long max __maybe_unused,
29892 + unsigned long long n;
29893 + struct inode **p, *inode;
29894 + struct list_head *head;
29899 + spin_lock(&sb->s_inode_list_lock);
29900 + list_for_each_entry(inode, head, i_sb_list) {
29901 + if (!au_is_bad_inode(inode)
29902 + && au_ii(inode)->ii_btop >= 0) {
29903 + spin_lock(&inode->i_lock);
29904 + if (atomic_read(&inode->i_count)) {
29908 + AuDebugOn(n > max);
29910 + spin_unlock(&inode->i_lock);
29913 + spin_unlock(&sb->s_inode_list_lock);
29918 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29920 + struct au_sbinfo *sbi;
29922 + sbi = au_sbi(sb);
29923 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29924 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29927 +void au_iarray_free(struct inode **a, unsigned long long max)
29929 + unsigned long long ull;
29931 + for (ull = 0; ull < max; ull++)
29936 +/* ---------------------------------------------------------------------- */
29939 + * refresh dentry and inode at remount time.
29941 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29942 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29943 + struct dentry *parent)
29947 + di_write_lock_child(dentry);
29948 + di_read_lock_parent(parent, AuLock_IR);
29949 + err = au_refresh_dentry(dentry, parent);
29950 + if (!err && dir_flags)
29951 + au_hn_reset(d_inode(dentry), dir_flags);
29952 + di_read_unlock(parent, AuLock_IR);
29953 + di_write_unlock(dentry);
29958 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29959 + struct au_sbinfo *sbinfo,
29960 + const unsigned int dir_flags, unsigned int do_idop)
29963 + struct dentry *parent;
29966 + parent = dget_parent(dentry);
29967 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29968 + if (d_really_is_positive(dentry)) {
29969 + if (!d_is_dir(dentry))
29970 + err = au_do_refresh(dentry, /*dir_flags*/0,
29973 + err = au_do_refresh(dentry, dir_flags, parent);
29974 + if (unlikely(err))
29975 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29978 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29979 + AuDbgDentry(dentry);
29985 + au_refresh_dop(dentry, /*force_reval*/0);
29987 + au_refresh_dop(dentry, /*force_reval*/1);
29993 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29995 + int err, i, j, ndentry, e;
29996 + unsigned int sigen;
29997 + struct au_dcsub_pages dpages;
29998 + struct au_dpage *dpage;
29999 + struct dentry **dentries, *d;
30000 + struct au_sbinfo *sbinfo;
30001 + struct dentry *root = sb->s_root;
30002 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30005 + au_refresh_dop(root, /*force_reval*/0);
30007 + err = au_dpages_init(&dpages, GFP_NOFS);
30008 + if (unlikely(err))
30010 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30011 + if (unlikely(err))
30014 + sigen = au_sigen(sb);
30015 + sbinfo = au_sbi(sb);
30016 + for (i = 0; i < dpages.ndpage; i++) {
30017 + dpage = dpages.dpages + i;
30018 + dentries = dpage->dentries;
30019 + ndentry = dpage->ndentry;
30020 + for (j = 0; j < ndentry; j++) {
30022 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30024 + if (unlikely(e && !err))
30026 + /* go on even err */
30031 + au_dpages_free(&dpages);
30036 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30039 + unsigned int sigen;
30040 + unsigned long long max, ull;
30041 + struct inode *inode, **array;
30043 + array = au_iarray_alloc(sb, &max);
30044 + err = PTR_ERR(array);
30045 + if (IS_ERR(array))
30049 + sigen = au_sigen(sb);
30050 + for (ull = 0; ull < max; ull++) {
30051 + inode = array[ull];
30052 + if (unlikely(!inode))
30056 + ii_write_lock_child(inode);
30057 + if (au_iigen(inode, NULL) != sigen) {
30058 + e = au_refresh_hinode_self(inode);
30059 + if (unlikely(e)) {
30060 + au_refresh_iop(inode, /*force_getattr*/1);
30061 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30064 + /* go on even if err */
30067 + if (!e && do_idop)
30068 + au_refresh_iop(inode, /*force_getattr*/0);
30069 + ii_write_unlock(inode);
30072 + au_iarray_free(array, max);
30078 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30081 + unsigned int udba;
30082 + aufs_bindex_t bindex, bbot;
30083 + struct dentry *root;
30084 + struct inode *inode;
30085 + struct au_branch *br;
30086 + struct au_sbinfo *sbi;
30088 + au_sigen_inc(sb);
30089 + sbi = au_sbi(sb);
30090 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30092 + root = sb->s_root;
30093 + DiMustNoWaiters(root);
30094 + inode = d_inode(root);
30095 + IiMustNoWaiters(inode);
30097 + udba = au_opt_udba(sb);
30098 + bbot = au_sbbot(sb);
30099 + for (bindex = 0; bindex <= bbot; bindex++) {
30100 + br = au_sbr(sb, bindex);
30101 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30102 + if (unlikely(err))
30103 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30105 + /* go on even if err */
30107 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30110 + if (au_ftest_si(sbi, NO_DREVAL)) {
30111 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30112 + sb->s_d_op = &aufs_dop_noreval;
30113 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30114 + sbi->si_iop_array = aufs_iop_nogetattr;
30116 + AuDebugOn(sb->s_d_op == &aufs_dop);
30117 + sb->s_d_op = &aufs_dop;
30118 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30119 + sbi->si_iop_array = aufs_iop;
30121 + pr_info("reset to %ps and %ps\n",
30122 + sb->s_d_op, sbi->si_iop_array);
30125 + di_write_unlock(root);
30126 + err = au_refresh_d(sb, do_idop);
30127 + e = au_refresh_i(sb, do_idop);
30128 + if (unlikely(e && !err))
30130 + /* aufs_write_lock() calls ..._child() */
30131 + di_write_lock_child(root);
30133 + au_cpup_attr_all(inode, /*force*/1);
30135 + if (unlikely(err))
30136 + AuIOErr("refresh failed, ignored, %d\n", err);
30139 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30140 +static int cvt_err(int err)
30154 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30157 + unsigned int mntflags;
30158 + struct au_opts opts = {
30161 + struct dentry *root;
30162 + struct inode *inode;
30163 + struct au_sbinfo *sbinfo;
30166 + root = sb->s_root;
30167 + if (!data || !*data) {
30168 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30170 + di_write_lock_child(root);
30171 + err = au_opts_verify(sb, *flags, /*pending*/0);
30172 + aufs_write_unlock(root);
30178 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30179 + if (unlikely(!opts.opt))
30181 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30182 + opts.flags = AuOpts_REMOUNT;
30183 + opts.sb_flags = *flags;
30185 + /* parse it before aufs lock */
30186 + err = au_opts_parse(sb, data, &opts);
30187 + if (unlikely(err))
30190 + sbinfo = au_sbi(sb);
30191 + inode = d_inode(root);
30192 + inode_lock(inode);
30193 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30194 + if (unlikely(err))
30196 + di_write_lock_child(root);
30198 + /* au_opts_remount() may return an error */
30199 + err = au_opts_remount(sb, &opts);
30200 + au_opts_free(&opts);
30202 + if (au_ftest_opts(opts.flags, REFRESH))
30203 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30205 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30206 + mntflags = au_mntflags(sb);
30207 + do_dx = !!au_opt_test(mntflags, DIO);
30208 + au_dy_arefresh(do_dx);
30211 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30212 + aufs_write_unlock(root);
30215 + inode_unlock(inode);
30217 + free_page((unsigned long)opts.opt);
30219 + err = cvt_err(err);
30224 +static const struct super_operations aufs_sop = {
30225 + .alloc_inode = aufs_alloc_inode,
30226 + .destroy_inode = aufs_destroy_inode,
30227 + .free_inode = aufs_free_inode,
30228 + /* always deleting, no clearing */
30229 + .drop_inode = generic_delete_inode,
30230 + .show_options = aufs_show_options,
30231 + .statfs = aufs_statfs,
30232 + .put_super = aufs_put_super,
30233 + .sync_fs = aufs_sync_fs,
30234 + .remount_fs = aufs_remount_fs
30237 +/* ---------------------------------------------------------------------- */
30239 +static int alloc_root(struct super_block *sb)
30242 + struct inode *inode;
30243 + struct dentry *root;
30246 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30247 + err = PTR_ERR(inode);
30248 + if (IS_ERR(inode))
30251 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30252 + inode->i_fop = &aufs_dir_fop;
30253 + inode->i_mode = S_IFDIR;
30254 + set_nlink(inode, 2);
30255 + unlock_new_inode(inode);
30257 + root = d_make_root(inode);
30258 + if (unlikely(!root))
30260 + err = PTR_ERR(root);
30261 + if (IS_ERR(root))
30264 + err = au_di_init(root);
30266 + sb->s_root = root;
30267 + return 0; /* success */
30275 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30276 + int silent __maybe_unused)
30279 + struct au_opts opts = {
30282 + struct au_sbinfo *sbinfo;
30283 + struct dentry *root;
30284 + struct inode *inode;
30285 + char *arg = raw_data;
30287 + if (unlikely(!arg || !*arg)) {
30289 + pr_err("no arg\n");
30294 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30295 + if (unlikely(!opts.opt))
30297 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30298 + opts.sb_flags = sb->s_flags;
30300 + err = au_si_alloc(sb);
30301 + if (unlikely(err))
30303 + sbinfo = au_sbi(sb);
30305 + /* all timestamps always follow the ones on the branch */
30306 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30307 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30308 + sb->s_op = &aufs_sop;
30309 + sb->s_d_op = &aufs_dop;
30310 + sb->s_magic = AUFS_SUPER_MAGIC;
30311 + sb->s_maxbytes = 0;
30312 + sb->s_stack_depth = 1;
30313 + au_export_init(sb);
30314 + au_xattr_init(sb);
30316 + err = alloc_root(sb);
30317 + if (unlikely(err)) {
30318 + si_write_unlock(sb);
30321 + root = sb->s_root;
30322 + inode = d_inode(root);
30325 + * actually we can parse options regardless aufs lock here.
30326 + * but at remount time, parsing must be done before aufs lock.
30327 + * so we follow the same rule.
30329 + ii_write_lock_parent(inode);
30330 + aufs_write_unlock(root);
30331 + err = au_opts_parse(sb, arg, &opts);
30332 + if (unlikely(err))
30335 + /* lock vfs_inode first, then aufs. */
30336 + inode_lock(inode);
30337 + aufs_write_lock(root);
30338 + err = au_opts_mount(sb, &opts);
30339 + au_opts_free(&opts);
30340 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30341 + sb->s_d_op = &aufs_dop_noreval;
30342 + pr_info("%ps\n", sb->s_d_op);
30343 + au_refresh_dop(root, /*force_reval*/0);
30344 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30345 + au_refresh_iop(inode, /*force_getattr*/0);
30347 + aufs_write_unlock(root);
30348 + inode_unlock(inode);
30350 + goto out_opts; /* success */
30354 + sb->s_root = NULL;
30356 + kobject_put(&sbinfo->si_kobj);
30357 + sb->s_fs_info = NULL;
30359 + free_page((unsigned long)opts.opt);
30362 + err = cvt_err(err);
30367 +/* ---------------------------------------------------------------------- */
30369 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30370 + const char *dev_name __maybe_unused,
30373 + struct dentry *root;
30375 + /* all timestamps always follow the ones on the branch */
30376 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30377 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30378 + if (IS_ERR(root))
30381 + au_sbilist_add(root->d_sb);
30387 +static void aufs_kill_sb(struct super_block *sb)
30389 + struct au_sbinfo *sbinfo;
30391 + sbinfo = au_sbi(sb);
30393 + au_sbilist_del(sb);
30394 + aufs_write_lock(sb->s_root);
30396 + if (sbinfo->si_wbr_create_ops->fin)
30397 + sbinfo->si_wbr_create_ops->fin(sb);
30398 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30399 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30400 + au_remount_refresh(sb, /*do_idop*/0);
30402 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30403 + au_plink_put(sb, /*verbose*/1);
30405 + au_dr_opt_flush(sb);
30406 + sbinfo->si_sb = NULL;
30407 + aufs_write_unlock(sb->s_root);
30408 + au_nwt_flush(&sbinfo->si_nowait);
30410 + kill_anon_super(sb);
30413 +struct file_system_type aufs_fs_type = {
30414 + .name = AUFS_FSTYPE,
30415 + /* a race between rename and others */
30416 + .fs_flags = FS_RENAME_DOES_D_MOVE
30418 + /*| FS_ALLOW_IDMAP*/
30420 + .mount = aufs_mount,
30421 + .kill_sb = aufs_kill_sb,
30422 + /* no need to __module_get() and module_put(). */
30423 + .owner = THIS_MODULE,
30425 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30426 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30427 +++ linux/fs/aufs/super.h 2021-09-06 21:02:45.280158943 +0200
30429 +/* SPDX-License-Identifier: GPL-2.0 */
30431 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30433 + * This program, aufs is free software; you can redistribute it and/or modify
30434 + * it under the terms of the GNU General Public License as published by
30435 + * the Free Software Foundation; either version 2 of the License, or
30436 + * (at your option) any later version.
30438 + * This program is distributed in the hope that it will be useful,
30439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30441 + * GNU General Public License for more details.
30443 + * You should have received a copy of the GNU General Public License
30444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30448 + * super_block operations
30451 +#ifndef __AUFS_SUPER_H__
30452 +#define __AUFS_SUPER_H__
30456 +#include <linux/fs.h>
30457 +#include <linux/kobject.h>
30460 +#include "rwsem.h"
30463 +/* policies to select one among multiple writable branches */
30464 +struct au_wbr_copyup_operations {
30465 + int (*copyup)(struct dentry *dentry);
30468 +#define AuWbr_DIR 1 /* target is a dir */
30469 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30471 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30472 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30473 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30475 +struct au_wbr_create_operations {
30476 + int (*create)(struct dentry *dentry, unsigned int flags);
30477 + int (*init)(struct super_block *sb);
30478 + int (*fin)(struct super_block *sb);
30481 +struct au_wbr_mfs {
30482 + struct mutex mfs_lock; /* protect this structure */
30483 + unsigned long mfs_jiffy;
30484 + unsigned long mfs_expire;
30485 + aufs_bindex_t mfs_bindex;
30487 + unsigned long long mfsrr_bytes;
30488 + unsigned long long mfsrr_watermark;
30491 +#define AuPlink_NHASH 100
30492 +static inline int au_plink_hash(ino_t ino)
30494 + return ino % AuPlink_NHASH;
30497 +/* File-based Hierarchical Storage Management */
30499 +#ifdef CONFIG_AUFS_FHSM
30500 + /* allow only one process who can receive the notification */
30501 + spinlock_t fhsm_spin;
30503 + wait_queue_head_t fhsm_wqh;
30504 + atomic_t fhsm_readable;
30506 + /* these are protected by si_rwsem */
30507 + unsigned long fhsm_expire;
30508 + aufs_bindex_t fhsm_bottom;
30513 +struct au_sbinfo {
30514 + /* nowait tasks in the system-wide workqueue */
30515 + struct au_nowait_tasks si_nowait;
30518 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30519 + * rwsem for au_sbinfo is necessary.
30521 + struct au_rwsem si_rwsem;
30524 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30527 + au_lcnt_t si_ninodes, si_nfiles;
30529 + /* branch management */
30530 + unsigned int si_generation;
30532 + /* see AuSi_ flags */
30533 + unsigned char au_si_status;
30535 + aufs_bindex_t si_bbot;
30537 + /* dirty trick to keep br_id plus */
30538 + unsigned int si_last_br_id :
30539 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30540 + struct au_branch **si_branch;
30542 + /* policy to select a writable branch */
30543 + unsigned char si_wbr_copyup;
30544 + unsigned char si_wbr_create;
30545 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30546 + struct au_wbr_create_operations *si_wbr_create_ops;
30548 + /* round robin */
30549 + atomic_t si_wbr_rr_next;
30551 + /* most free space */
30552 + struct au_wbr_mfs si_wbr_mfs;
30554 + /* File-based Hierarchical Storage Management */
30555 + struct au_fhsm si_fhsm;
30557 + /* mount flags */
30558 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30559 + unsigned int si_mntflags;
30561 + /* external inode number (bitmap and translation table) */
30562 + loff_t si_ximaxent; /* max entries in a xino */
30564 + struct file *si_xib;
30565 + struct mutex si_xib_mtx; /* protect xib members */
30566 + unsigned long *si_xib_buf;
30567 + unsigned long si_xib_last_pindex;
30568 + int si_xib_next_bit;
30570 + unsigned long si_xino_jiffy;
30571 + unsigned long si_xino_expire;
30572 + /* reserved for future use */
30573 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30575 +#ifdef CONFIG_AUFS_EXPORT
30576 + /* i_generation */
30577 + /* todo: make xigen file an array to support many inode numbers */
30578 + struct file *si_xigen;
30579 + atomic_t si_xigen_next;
30582 + /* dirty trick to support atomic_open */
30583 + struct hlist_bl_head si_aopen;
30585 + /* vdir parameters */
30586 + unsigned long si_rdcache; /* max cache time in jiffies */
30587 + unsigned int si_rdblk; /* deblk size */
30588 + unsigned int si_rdhash; /* hash size */
30591 + * If the number of whiteouts are larger than si_dirwh, leave all of
30592 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30593 + * future fsck.aufs or kernel thread will remove them later.
30594 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30596 + unsigned int si_dirwh;
30598 + /* pseudo_link list */
30599 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30600 + wait_queue_head_t si_plink_wq;
30601 + spinlock_t si_plink_maint_lock;
30602 + pid_t si_plink_maint_pid;
30605 + struct hlist_bl_head si_files;
30607 + /* with/without getattr, brother of sb->s_d_op */
30608 + const struct inode_operations *si_iop_array;
30611 + * sysfs and lifetime management.
30612 + * this is not a small structure and it may be a waste of memory in case
30613 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30614 + * but using sysfs is majority.
30616 + struct kobject si_kobj;
30617 +#ifdef CONFIG_DEBUG_FS
30618 + struct dentry *si_dbgaufs;
30619 + struct dentry *si_dbgaufs_plink;
30620 + struct dentry *si_dbgaufs_xib;
30621 +#ifdef CONFIG_AUFS_EXPORT
30622 + struct dentry *si_dbgaufs_xigen;
30626 +#ifdef CONFIG_AUFS_SBILIST
30627 + struct hlist_bl_node si_list;
30630 + /* dirty, necessary for unmounting, sysfs and sysrq */
30631 + struct super_block *si_sb;
30634 +/* sbinfo status flags */
30636 + * set true when refresh_dirs() failed at remount time.
30637 + * then try refreshing dirs at access time again.
30638 + * if it is false, refreshing dirs at access time is unnecessary
30640 +#define AuSi_FAILED_REFRESH_DIR 1
30641 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30642 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30644 +#ifndef CONFIG_AUFS_FHSM
30646 +#define AuSi_FHSM 0
30649 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30650 + unsigned int flag)
30652 + AuRwMustAnyLock(&sbi->si_rwsem);
30653 + return sbi->au_si_status & flag;
30655 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30656 +#define au_fset_si(sbinfo, name) do { \
30657 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30658 + (sbinfo)->au_si_status |= AuSi_##name; \
30660 +#define au_fclr_si(sbinfo, name) do { \
30661 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30662 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30665 +/* ---------------------------------------------------------------------- */
30667 +/* policy to select one among writable branches */
30668 +#define AuWbrCopyup(sbinfo, ...) \
30669 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30670 +#define AuWbrCreate(sbinfo, ...) \
30671 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30673 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30674 +#define AuLock_DW 1 /* write-lock dentry */
30675 +#define AuLock_IR (1 << 1) /* read-lock inode */
30676 +#define AuLock_IW (1 << 2) /* write-lock inode */
30677 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30678 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30679 + /* except RENAME_EXCHANGE */
30680 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30681 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30682 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30683 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30684 +#define au_fset_lock(flags, name) \
30685 + do { (flags) |= AuLock_##name; } while (0)
30686 +#define au_fclr_lock(flags, name) \
30687 + do { (flags) &= ~AuLock_##name; } while (0)
30689 +/* ---------------------------------------------------------------------- */
30692 +extern struct file_system_type aufs_fs_type;
30693 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30694 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30695 + unsigned long long max, void *arg);
30696 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30697 + struct super_block *sb, void *arg);
30698 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30699 +void au_iarray_free(struct inode **a, unsigned long long max);
30702 +void au_si_free(struct kobject *kobj);
30703 +int au_si_alloc(struct super_block *sb);
30704 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30706 +unsigned int au_sigen_inc(struct super_block *sb);
30707 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30709 +int si_read_lock(struct super_block *sb, int flags);
30710 +int si_write_lock(struct super_block *sb, int flags);
30711 +int aufs_read_lock(struct dentry *dentry, int flags);
30712 +void aufs_read_unlock(struct dentry *dentry, int flags);
30713 +void aufs_write_lock(struct dentry *dentry);
30714 +void aufs_write_unlock(struct dentry *dentry);
30715 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30716 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30718 +/* wbr_policy.c */
30719 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30720 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30721 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30722 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30723 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30726 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30728 +#ifdef CONFIG_AUFS_FHSM
30731 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30735 + spin_lock(&fhsm->fhsm_spin);
30736 + pid = fhsm->fhsm_pid;
30737 + spin_unlock(&fhsm->fhsm_spin);
30742 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30743 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30744 +int au_fhsm_fd(struct super_block *sb, int oflags);
30745 +int au_fhsm_br_alloc(struct au_branch *br);
30746 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30747 +void au_fhsm_fin(struct super_block *sb);
30748 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30749 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30750 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30752 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30754 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30755 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30756 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30757 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30758 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30759 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30760 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30761 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30762 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30765 +/* ---------------------------------------------------------------------- */
30767 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30769 + return sb->s_fs_info;
30772 +/* ---------------------------------------------------------------------- */
30774 +#ifdef CONFIG_AUFS_EXPORT
30775 +int au_test_nfsd(void);
30776 +void au_export_init(struct super_block *sb);
30777 +void au_xigen_inc(struct inode *inode);
30778 +int au_xigen_new(struct inode *inode);
30779 +int au_xigen_set(struct super_block *sb, struct path *path);
30780 +void au_xigen_clr(struct super_block *sb);
30782 +static inline int au_busy_or_stale(void)
30784 + if (!au_test_nfsd())
30789 +AuStubInt0(au_test_nfsd, void)
30790 +AuStubVoid(au_export_init, struct super_block *sb)
30791 +AuStubVoid(au_xigen_inc, struct inode *inode)
30792 +AuStubInt0(au_xigen_new, struct inode *inode)
30793 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30794 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30795 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30796 +#endif /* CONFIG_AUFS_EXPORT */
30798 +/* ---------------------------------------------------------------------- */
30800 +#ifdef CONFIG_AUFS_SBILIST
30802 +extern struct hlist_bl_head au_sbilist;
30804 +static inline void au_sbilist_init(void)
30806 + INIT_HLIST_BL_HEAD(&au_sbilist);
30809 +static inline void au_sbilist_add(struct super_block *sb)
30811 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30814 +static inline void au_sbilist_del(struct super_block *sb)
30816 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30819 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30820 +static inline void au_sbilist_lock(void)
30822 + hlist_bl_lock(&au_sbilist);
30825 +static inline void au_sbilist_unlock(void)
30827 + hlist_bl_unlock(&au_sbilist);
30829 +#define AuGFP_SBILIST GFP_ATOMIC
30831 +AuStubVoid(au_sbilist_lock, void)
30832 +AuStubVoid(au_sbilist_unlock, void)
30833 +#define AuGFP_SBILIST GFP_NOFS
30834 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30836 +AuStubVoid(au_sbilist_init, void)
30837 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30838 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30839 +AuStubVoid(au_sbilist_lock, void)
30840 +AuStubVoid(au_sbilist_unlock, void)
30841 +#define AuGFP_SBILIST GFP_NOFS
30844 +/* ---------------------------------------------------------------------- */
30846 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30849 + * This function is a dynamic '__init' function actually,
30850 + * so the tiny check for si_rwsem is unnecessary.
30852 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30853 +#ifdef CONFIG_DEBUG_FS
30854 + sbinfo->si_dbgaufs = NULL;
30855 + sbinfo->si_dbgaufs_plink = NULL;
30856 + sbinfo->si_dbgaufs_xib = NULL;
30857 +#ifdef CONFIG_AUFS_EXPORT
30858 + sbinfo->si_dbgaufs_xigen = NULL;
30863 +/* ---------------------------------------------------------------------- */
30865 +/* current->atomic_flags */
30866 +/* this value should never corrupt the ones defined in linux/sched.h */
30867 +#define PFA_AUFS 0x10
30869 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30870 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30871 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30873 +static inline int si_pid_test(struct super_block *sb)
30875 + return !!task_test_aufs(current);
30878 +static inline void si_pid_clr(struct super_block *sb)
30880 + AuDebugOn(!task_test_aufs(current));
30881 + task_clear_aufs(current);
30884 +static inline void si_pid_set(struct super_block *sb)
30886 + AuDebugOn(task_test_aufs(current));
30887 + task_set_aufs(current);
30890 +/* ---------------------------------------------------------------------- */
30892 +/* lock superblock. mainly for entry point functions */
30893 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30894 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30895 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30896 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30898 +#define __si_read_trylock_nested(sb) \
30899 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30900 +#define __si_write_trylock_nested(sb) \
30901 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30904 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30905 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30906 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30908 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30909 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30910 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30912 +static inline void si_noflush_read_lock(struct super_block *sb)
30914 + __si_read_lock(sb);
30918 +static inline int si_noflush_read_trylock(struct super_block *sb)
30922 + locked = __si_read_trylock(sb);
30928 +static inline void si_noflush_write_lock(struct super_block *sb)
30930 + __si_write_lock(sb);
30934 +static inline int si_noflush_write_trylock(struct super_block *sb)
30938 + locked = __si_write_trylock(sb);
30944 +#if 0 /* reserved */
30945 +static inline int si_read_trylock(struct super_block *sb, int flags)
30947 + if (au_ftest_lock(flags, FLUSH))
30948 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30949 + return si_noflush_read_trylock(sb);
30953 +static inline void si_read_unlock(struct super_block *sb)
30956 + __si_read_unlock(sb);
30959 +#if 0 /* reserved */
30960 +static inline int si_write_trylock(struct super_block *sb, int flags)
30962 + if (au_ftest_lock(flags, FLUSH))
30963 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30964 + return si_noflush_write_trylock(sb);
30968 +static inline void si_write_unlock(struct super_block *sb)
30971 + __si_write_unlock(sb);
30974 +#if 0 /* reserved */
30975 +static inline void si_downgrade_lock(struct super_block *sb)
30977 + __si_downgrade_lock(sb);
30981 +/* ---------------------------------------------------------------------- */
30983 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30985 + SiMustAnyLock(sb);
30986 + return au_sbi(sb)->si_bbot;
30989 +static inline unsigned int au_mntflags(struct super_block *sb)
30991 + SiMustAnyLock(sb);
30992 + return au_sbi(sb)->si_mntflags;
30995 +static inline unsigned int au_sigen(struct super_block *sb)
30997 + SiMustAnyLock(sb);
30998 + return au_sbi(sb)->si_generation;
31001 +static inline struct au_branch *au_sbr(struct super_block *sb,
31002 + aufs_bindex_t bindex)
31004 + SiMustAnyLock(sb);
31005 + return au_sbi(sb)->si_branch[0 + bindex];
31008 +static inline loff_t au_xi_maxent(struct super_block *sb)
31010 + SiMustAnyLock(sb);
31011 + return au_sbi(sb)->si_ximaxent;
31014 +#endif /* __KERNEL__ */
31015 +#endif /* __AUFS_SUPER_H__ */
31016 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31017 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31018 +++ linux/fs/aufs/sysaufs.c 2021-09-06 21:02:45.280158943 +0200
31020 +// SPDX-License-Identifier: GPL-2.0
31022 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31024 + * This program, aufs is free software; you can redistribute it and/or modify
31025 + * it under the terms of the GNU General Public License as published by
31026 + * the Free Software Foundation; either version 2 of the License, or
31027 + * (at your option) any later version.
31029 + * This program is distributed in the hope that it will be useful,
31030 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31032 + * GNU General Public License for more details.
31034 + * You should have received a copy of the GNU General Public License
31035 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31039 + * sysfs interface and lifetime management
31040 + * they are necessary regardless sysfs is disabled.
31043 +#include <linux/random.h>
31046 +unsigned long sysaufs_si_mask;
31047 +struct kset *sysaufs_kset;
31049 +#define AuSiAttr(_name) { \
31050 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31051 + .show = sysaufs_si_##_name, \
31054 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31055 +struct attribute *sysaufs_si_attrs[] = {
31056 + &sysaufs_si_attr_xi_path.attr,
31060 +static const struct sysfs_ops au_sbi_ops = {
31061 + .show = sysaufs_si_show
31064 +static struct kobj_type au_sbi_ktype = {
31065 + .release = au_si_free,
31066 + .sysfs_ops = &au_sbi_ops,
31067 + .default_attrs = sysaufs_si_attrs
31070 +/* ---------------------------------------------------------------------- */
31072 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31076 + sbinfo->si_kobj.kset = sysaufs_kset;
31077 + /* cf. sysaufs_name() */
31078 + err = kobject_init_and_add
31079 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31080 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31085 +void sysaufs_fin(void)
31087 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31088 + kset_unregister(sysaufs_kset);
31091 +int __init sysaufs_init(void)
31096 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31097 + } while (!sysaufs_si_mask);
31100 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31101 + if (unlikely(!sysaufs_kset))
31103 + err = PTR_ERR(sysaufs_kset);
31104 + if (IS_ERR(sysaufs_kset))
31106 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31107 + if (unlikely(err))
31108 + kset_unregister(sysaufs_kset);
31113 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31114 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31115 +++ linux/fs/aufs/sysaufs.h 2021-09-06 21:02:45.280158943 +0200
31117 +/* SPDX-License-Identifier: GPL-2.0 */
31119 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31121 + * This program, aufs is free software; you can redistribute it and/or modify
31122 + * it under the terms of the GNU General Public License as published by
31123 + * the Free Software Foundation; either version 2 of the License, or
31124 + * (at your option) any later version.
31126 + * This program is distributed in the hope that it will be useful,
31127 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31128 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31129 + * GNU General Public License for more details.
31131 + * You should have received a copy of the GNU General Public License
31132 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31136 + * sysfs interface and mount lifetime management
31139 +#ifndef __SYSAUFS_H__
31140 +#define __SYSAUFS_H__
31144 +#include <linux/sysfs.h>
31145 +#include "module.h"
31147 +struct super_block;
31150 +struct sysaufs_si_attr {
31151 + struct attribute attr;
31152 + int (*show)(struct seq_file *seq, struct super_block *sb);
31155 +/* ---------------------------------------------------------------------- */
31158 +extern unsigned long sysaufs_si_mask;
31159 +extern struct kset *sysaufs_kset;
31160 +extern struct attribute *sysaufs_si_attrs[];
31161 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31162 +int __init sysaufs_init(void);
31163 +void sysaufs_fin(void);
31165 +/* ---------------------------------------------------------------------- */
31167 +/* some people doesn't like to show a pointer in kernel */
31168 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31170 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31173 +#define SysaufsSiNamePrefix "si_"
31174 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31175 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31177 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31178 + sysaufs_si_id(sbinfo));
31182 +#ifdef CONFIG_SYSFS
31184 +extern struct attribute_group *sysaufs_attr_group;
31186 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31187 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31189 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31190 +#ifdef CONFIG_COMPAT
31191 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31194 +void sysaufs_br_init(struct au_branch *br);
31195 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31196 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31198 +#define sysaufs_brs_init() do {} while (0)
31201 +#define sysaufs_attr_group NULL
31203 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31204 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31205 + struct attribute *attr, char *buf)
31206 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31207 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31208 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31210 +static inline void sysaufs_brs_init(void)
31215 +#endif /* CONFIG_SYSFS */
31217 +#endif /* __KERNEL__ */
31218 +#endif /* __SYSAUFS_H__ */
31219 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31220 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31221 +++ linux/fs/aufs/sysfs.c 2021-09-06 21:02:45.280158943 +0200
31223 +// SPDX-License-Identifier: GPL-2.0
31225 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31227 + * This program, aufs is free software; you can redistribute it and/or modify
31228 + * it under the terms of the GNU General Public License as published by
31229 + * the Free Software Foundation; either version 2 of the License, or
31230 + * (at your option) any later version.
31232 + * This program is distributed in the hope that it will be useful,
31233 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31235 + * GNU General Public License for more details.
31237 + * You should have received a copy of the GNU General Public License
31238 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31242 + * sysfs interface
31245 +#include <linux/compat.h>
31246 +#include <linux/seq_file.h>
31249 +#ifdef CONFIG_AUFS_FS_MODULE
31250 +/* this entry violates the "one line per file" policy of sysfs */
31251 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31255 + static char *conf =
31256 +/* this file is generated at compiling */
31257 +#include "conf.str"
31260 + err = snprintf(buf, PAGE_SIZE, conf);
31261 + if (unlikely(err >= PAGE_SIZE))
31266 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31269 +static struct attribute *au_attr[] = {
31270 +#ifdef CONFIG_AUFS_FS_MODULE
31271 + &au_config_attr.attr,
31273 + NULL, /* need to NULL terminate the list of attributes */
31276 +static struct attribute_group sysaufs_attr_group_body = {
31280 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31282 +/* ---------------------------------------------------------------------- */
31284 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31288 + SiMustAnyLock(sb);
31291 + if (au_opt_test(au_mntflags(sb), XINO)) {
31292 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31293 + seq_putc(seq, '\n');
31299 + * the lifetime of branch is independent from the entry under sysfs.
31300 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31303 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31304 + aufs_bindex_t bindex, int idx)
31307 + struct path path;
31308 + struct dentry *root;
31309 + struct au_branch *br;
31310 + au_br_perm_str_t perm;
31312 + AuDbg("b%d\n", bindex);
31315 + root = sb->s_root;
31316 + di_read_lock_parent(root, !AuLock_IR);
31317 + br = au_sbr(sb, bindex);
31320 + case AuBrSysfs_BR:
31321 + path.mnt = au_br_mnt(br);
31322 + path.dentry = au_h_dptr(root, bindex);
31323 + err = au_seq_path(seq, &path);
31325 + au_optstr_br_perm(&perm, br->br_perm);
31326 + seq_printf(seq, "=%s\n", perm.a);
31329 + case AuBrSysfs_BRID:
31330 + seq_printf(seq, "%d\n", br->br_id);
31333 + di_read_unlock(root, !AuLock_IR);
31334 + if (unlikely(err || seq_has_overflowed(seq)))
31340 +/* ---------------------------------------------------------------------- */
31342 +static struct seq_file *au_seq(char *p, ssize_t len)
31344 + struct seq_file *seq;
31346 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31348 + /* mutex_init(&seq.lock); */
31351 + return seq; /* success */
31354 + seq = ERR_PTR(-ENOMEM);
31358 +#define SysaufsBr_PREFIX "br"
31359 +#define SysaufsBrid_PREFIX "brid"
31361 +/* todo: file size may exceed PAGE_SIZE */
31362 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31368 + aufs_bindex_t bbot;
31369 + struct au_sbinfo *sbinfo;
31370 + struct super_block *sb;
31371 + struct seq_file *seq;
31373 + struct attribute **cattr;
31375 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31376 + sb = sbinfo->si_sb;
31379 + * prevent a race condition between sysfs and aufs.
31380 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31381 + * prohibits maintaining the sysfs entries.
31382 + * hew we acquire read lock after sysfs_get_active_two().
31383 + * on the other hand, the remount process may maintain the sysfs/aufs
31384 + * entries after acquiring write lock.
31385 + * it can cause a deadlock.
31386 + * simply we gave up processing read here.
31389 + if (unlikely(!si_noflush_read_trylock(sb)))
31392 + seq = au_seq(buf, PAGE_SIZE);
31393 + err = PTR_ERR(seq);
31397 + name = (void *)attr->name;
31398 + cattr = sysaufs_si_attrs;
31400 + if (!strcmp(name, (*cattr)->name)) {
31401 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31408 + if (!strncmp(name, SysaufsBrid_PREFIX,
31409 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31410 + idx = AuBrSysfs_BRID;
31411 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31412 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31413 + sizeof(SysaufsBr_PREFIX) - 1)) {
31414 + idx = AuBrSysfs_BR;
31415 + name += sizeof(SysaufsBr_PREFIX) - 1;
31419 + err = kstrtol(name, 10, &l);
31421 + bbot = au_sbbot(sb);
31423 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31430 + err = seq->count;
31431 + /* sysfs limit */
31432 + if (unlikely(err == PAGE_SIZE))
31435 + au_kfree_rcu(seq);
31437 + si_read_unlock(sb);
31442 +/* ---------------------------------------------------------------------- */
31444 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31448 + aufs_bindex_t bindex, bbot;
31451 + struct seq_file *seq;
31452 + struct au_branch *br;
31454 + si_read_lock(sb, AuLock_FLUSH);
31455 + bbot = au_sbbot(sb);
31461 + buf = (void *)__get_free_page(GFP_NOFS);
31462 + if (unlikely(!buf))
31465 + seq = au_seq(buf, PAGE_SIZE);
31466 + err = PTR_ERR(seq);
31470 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31471 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31472 + /* VERIFY_WRITE */
31473 + err = !access_ok(arg, sizeof(*arg));
31474 + if (unlikely(err))
31477 + br = au_sbr(sb, bindex);
31478 + brid = br->br_id;
31479 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31480 + err = __put_user(brid, &arg->id);
31481 + if (unlikely(err))
31484 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31485 + err = __put_user(br->br_perm, &arg->perm);
31486 + if (unlikely(err))
31489 + err = au_seq_path(seq, &br->br_path);
31490 + if (unlikely(err))
31492 + seq_putc(seq, '\0');
31493 + if (!seq_has_overflowed(seq)) {
31494 + err = copy_to_user(arg->path, seq->buf, seq->count);
31496 + if (unlikely(err))
31503 + if (unlikely(err))
31507 + au_kfree_rcu(seq);
31509 + free_page((unsigned long)buf);
31511 + si_read_unlock(sb);
31515 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31517 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31520 +#ifdef CONFIG_COMPAT
31521 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31523 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31527 +/* ---------------------------------------------------------------------- */
31529 +void sysaufs_br_init(struct au_branch *br)
31532 + struct au_brsysfs *br_sysfs;
31533 + struct attribute *attr;
31535 + br_sysfs = br->br_sysfs;
31536 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31537 + attr = &br_sysfs->attr;
31538 + sysfs_attr_init(attr);
31539 + attr->name = br_sysfs->name;
31540 + attr->mode = 0444;
31545 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31547 + struct au_branch *br;
31548 + struct kobject *kobj;
31549 + struct au_brsysfs *br_sysfs;
31551 + aufs_bindex_t bbot;
31553 + if (!sysaufs_brs)
31556 + kobj = &au_sbi(sb)->si_kobj;
31557 + bbot = au_sbbot(sb);
31558 + for (; bindex <= bbot; bindex++) {
31559 + br = au_sbr(sb, bindex);
31560 + br_sysfs = br->br_sysfs;
31561 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31562 + sysfs_remove_file(kobj, &br_sysfs->attr);
31568 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31571 + aufs_bindex_t bbot;
31572 + struct kobject *kobj;
31573 + struct au_branch *br;
31574 + struct au_brsysfs *br_sysfs;
31576 + if (!sysaufs_brs)
31579 + kobj = &au_sbi(sb)->si_kobj;
31580 + bbot = au_sbbot(sb);
31581 + for (; bindex <= bbot; bindex++) {
31582 + br = au_sbr(sb, bindex);
31583 + br_sysfs = br->br_sysfs;
31584 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31585 + SysaufsBr_PREFIX "%d", bindex);
31586 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31587 + SysaufsBrid_PREFIX "%d", bindex);
31588 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31589 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31590 + if (unlikely(err))
31591 + pr_warn("failed %s under sysfs(%d)\n",
31592 + br_sysfs->name, err);
31597 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31598 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31599 +++ linux/fs/aufs/sysrq.c 2021-09-06 21:02:45.280158943 +0200
31601 +// SPDX-License-Identifier: GPL-2.0
31603 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31605 + * This program, aufs is free software; you can redistribute it and/or modify
31606 + * it under the terms of the GNU General Public License as published by
31607 + * the Free Software Foundation; either version 2 of the License, or
31608 + * (at your option) any later version.
31610 + * This program is distributed in the hope that it will be useful,
31611 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31612 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31613 + * GNU General Public License for more details.
31615 + * You should have received a copy of the GNU General Public License
31616 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31620 + * magic sysrq handler
31623 +/* #include <linux/sysrq.h> */
31624 +#include <linux/writeback.h>
31627 +/* ---------------------------------------------------------------------- */
31629 +static void sysrq_sb(struct super_block *sb)
31632 + struct au_sbinfo *sbinfo;
31633 + struct file *file;
31634 + struct hlist_bl_head *files;
31635 + struct hlist_bl_node *pos;
31636 + struct au_finfo *finfo;
31639 + plevel = au_plevel;
31640 + au_plevel = KERN_WARNING;
31642 + /* since we define pr_fmt, call printk directly */
31643 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31645 + sbinfo = au_sbi(sb);
31646 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31647 + pr("superblock\n");
31650 +#if 0 /* reserved */
31652 + int err, i, j, ndentry;
31653 + struct au_dcsub_pages dpages;
31654 + struct au_dpage *dpage;
31656 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31657 + if (unlikely(err))
31659 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31661 + for (i = 0; i < dpages.ndpage; i++) {
31662 + dpage = dpages.dpages + i;
31663 + ndentry = dpage->ndentry;
31664 + for (j = 0; j < ndentry; j++)
31665 + au_dpri_dentry(dpage->dentries[j]);
31667 + au_dpages_free(&dpages);
31671 + pr("isolated inode\n");
31672 + spin_lock(&sb->s_inode_list_lock);
31673 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31674 + spin_lock(&i->i_lock);
31675 + if (hlist_empty(&i->i_dentry))
31676 + au_dpri_inode(i);
31677 + spin_unlock(&i->i_lock);
31679 + spin_unlock(&sb->s_inode_list_lock);
31682 + files = &au_sbi(sb)->si_files;
31683 + hlist_bl_lock(files);
31684 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31687 + file = finfo->fi_file;
31688 + mode = file_inode(file)->i_mode;
31689 + if (!special_file(mode))
31690 + au_dpri_file(file);
31692 + hlist_bl_unlock(files);
31696 + au_plevel = plevel;
31699 +/* ---------------------------------------------------------------------- */
31701 +/* module parameter */
31702 +static char *aufs_sysrq_key = "a";
31703 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31704 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31706 +static void au_sysrq(int key __maybe_unused)
31708 + struct au_sbinfo *sbinfo;
31709 + struct hlist_bl_node *pos;
31712 + au_sbilist_lock();
31713 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31714 + sysrq_sb(sbinfo->si_sb);
31715 + au_sbilist_unlock();
31719 +static struct sysrq_key_op au_sysrq_op = {
31720 + .handler = au_sysrq,
31721 + .help_msg = "Aufs",
31722 + .action_msg = "Aufs",
31723 + .enable_mask = SYSRQ_ENABLE_DUMP
31726 +/* ---------------------------------------------------------------------- */
31728 +int __init au_sysrq_init(void)
31734 + key = *aufs_sysrq_key;
31735 + if ('a' <= key && key <= 'z')
31736 + err = register_sysrq_key(key, &au_sysrq_op);
31737 + if (unlikely(err))
31738 + pr_err("err %d, sysrq=%c\n", err, key);
31742 +void au_sysrq_fin(void)
31746 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31747 + if (unlikely(err))
31748 + pr_err("err %d (ignored)\n", err);
31750 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31751 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31752 +++ linux/fs/aufs/vdir.c 2021-09-06 21:02:45.280158943 +0200
31754 +// SPDX-License-Identifier: GPL-2.0
31756 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31758 + * This program, aufs is free software; you can redistribute it and/or modify
31759 + * it under the terms of the GNU General Public License as published by
31760 + * the Free Software Foundation; either version 2 of the License, or
31761 + * (at your option) any later version.
31763 + * This program is distributed in the hope that it will be useful,
31764 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31765 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31766 + * GNU General Public License for more details.
31768 + * You should have received a copy of the GNU General Public License
31769 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31773 + * virtual or vertical directory
31776 +#include <linux/iversion.h>
31779 +static unsigned int calc_size(int nlen)
31781 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31784 +static int set_deblk_end(union au_vdir_deblk_p *p,
31785 + union au_vdir_deblk_p *deblk_end)
31787 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31788 + p->de->de_str.len = 0;
31792 + return -1; /* error */
31795 +/* returns true or false */
31796 +static int is_deblk_end(union au_vdir_deblk_p *p,
31797 + union au_vdir_deblk_p *deblk_end)
31799 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31800 + return !p->de->de_str.len;
31804 +static unsigned char *last_deblk(struct au_vdir *vdir)
31806 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31809 +/* ---------------------------------------------------------------------- */
31811 +/* estimate the appropriate size for name hash table */
31812 +unsigned int au_rdhash_est(loff_t sz)
31820 + if (sz < AUFS_RDHASH_DEF)
31821 + n = AUFS_RDHASH_DEF;
31822 + /* pr_info("n %u\n", n); */
31827 + * the allocated memory has to be freed by
31828 + * au_nhash_wh_free() or au_nhash_de_free().
31830 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31832 + struct hlist_head *head;
31836 + sz = sizeof(*nhash->nh_head) * num_hash;
31837 + head = kmalloc(sz, gfp);
31839 + nhash->nh_num = num_hash;
31840 + nhash->nh_head = head;
31841 + for (u = 0; u < num_hash; u++)
31842 + INIT_HLIST_HEAD(head++);
31843 + return 0; /* success */
31849 +static void nhash_count(struct hlist_head *head)
31851 +#if 0 /* debugging */
31853 + struct hlist_node *pos;
31856 + hlist_for_each(pos, head)
31858 + pr_info("%lu\n", n);
31862 +static void au_nhash_wh_do_free(struct hlist_head *head)
31864 + struct au_vdir_wh *pos;
31865 + struct hlist_node *node;
31867 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31868 + au_kfree_rcu(pos);
31871 +static void au_nhash_de_do_free(struct hlist_head *head)
31873 + struct au_vdir_dehstr *pos;
31874 + struct hlist_node *node;
31876 + hlist_for_each_entry_safe(pos, node, head, hash)
31877 + au_cache_free_vdir_dehstr(pos);
31880 +static void au_nhash_do_free(struct au_nhash *nhash,
31881 + void (*free)(struct hlist_head *head))
31884 + struct hlist_head *head;
31886 + n = nhash->nh_num;
31890 + head = nhash->nh_head;
31891 + while (n-- > 0) {
31892 + nhash_count(head);
31895 + au_kfree_try_rcu(nhash->nh_head);
31898 +void au_nhash_wh_free(struct au_nhash *whlist)
31900 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31903 +static void au_nhash_de_free(struct au_nhash *delist)
31905 + au_nhash_do_free(delist, au_nhash_de_do_free);
31908 +/* ---------------------------------------------------------------------- */
31910 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31914 + unsigned int u, n;
31915 + struct hlist_head *head;
31916 + struct au_vdir_wh *pos;
31919 + n = whlist->nh_num;
31920 + head = whlist->nh_head;
31921 + for (u = 0; u < n; u++, head++)
31922 + hlist_for_each_entry(pos, head, wh_hash)
31923 + if (pos->wh_bindex == btgt && ++num > limit)
31928 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31929 + unsigned char *name,
31930 + unsigned int len)
31933 + /* const unsigned int magic_bit = 12; */
31935 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31942 + /* v = hash_long(v, magic_bit); */
31943 + v %= nhash->nh_num;
31944 + return nhash->nh_head + v;
31947 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31950 + return str->len == nlen && !memcmp(str->name, name, nlen);
31953 +/* returns found or not */
31954 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31956 + struct hlist_head *head;
31957 + struct au_vdir_wh *pos;
31958 + struct au_vdir_destr *str;
31960 + head = au_name_hash(whlist, name, nlen);
31961 + hlist_for_each_entry(pos, head, wh_hash) {
31962 + str = &pos->wh_str;
31963 + AuDbg("%.*s\n", str->len, str->name);
31964 + if (au_nhash_test_name(str, name, nlen))
31970 +/* returns found(true) or not */
31971 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31973 + struct hlist_head *head;
31974 + struct au_vdir_dehstr *pos;
31975 + struct au_vdir_destr *str;
31977 + head = au_name_hash(delist, name, nlen);
31978 + hlist_for_each_entry(pos, head, hash) {
31980 + AuDbg("%.*s\n", str->len, str->name);
31981 + if (au_nhash_test_name(str, name, nlen))
31987 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31988 + unsigned char d_type)
31990 +#ifdef CONFIG_AUFS_SHWH
31991 + wh->wh_ino = ino;
31992 + wh->wh_type = d_type;
31996 +/* ---------------------------------------------------------------------- */
31998 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31999 + unsigned int d_type, aufs_bindex_t bindex,
32000 + unsigned char shwh)
32003 + struct au_vdir_destr *str;
32004 + struct au_vdir_wh *wh;
32006 + AuDbg("%.*s\n", nlen, name);
32007 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32010 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32011 + if (unlikely(!wh))
32015 + wh->wh_bindex = bindex;
32017 + au_shwh_init_wh(wh, ino, d_type);
32018 + str = &wh->wh_str;
32020 + memcpy(str->name, name, nlen);
32021 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32028 +static int append_deblk(struct au_vdir *vdir)
32031 + unsigned long ul;
32032 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32033 + union au_vdir_deblk_p p, deblk_end;
32034 + unsigned char **o;
32037 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32038 + GFP_NOFS, /*may_shrink*/0);
32039 + if (unlikely(!o))
32042 + vdir->vd_deblk = o;
32043 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32045 + ul = vdir->vd_nblk++;
32046 + vdir->vd_deblk[ul] = p.deblk;
32047 + vdir->vd_last.ul = ul;
32048 + vdir->vd_last.p.deblk = p.deblk;
32049 + deblk_end.deblk = p.deblk + deblk_sz;
32050 + err = set_deblk_end(&p, &deblk_end);
32057 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32058 + unsigned int d_type, struct au_nhash *delist)
32062 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32063 + union au_vdir_deblk_p p, *room, deblk_end;
32064 + struct au_vdir_dehstr *dehstr;
32066 + p.deblk = last_deblk(vdir);
32067 + deblk_end.deblk = p.deblk + deblk_sz;
32068 + room = &vdir->vd_last.p;
32069 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32070 + || !is_deblk_end(room, &deblk_end));
32072 + sz = calc_size(nlen);
32073 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32074 + err = append_deblk(vdir);
32075 + if (unlikely(err))
32078 + p.deblk = last_deblk(vdir);
32079 + deblk_end.deblk = p.deblk + deblk_sz;
32081 + AuDebugOn(room->deblk != p.deblk);
32085 + dehstr = au_cache_alloc_vdir_dehstr();
32086 + if (unlikely(!dehstr))
32089 + dehstr->str = &room->de->de_str;
32090 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32091 + room->de->de_ino = ino;
32092 + room->de->de_type = d_type;
32093 + room->de->de_str.len = nlen;
32094 + memcpy(room->de->de_str.name, name, nlen);
32097 + room->deblk += sz;
32098 + if (unlikely(set_deblk_end(room, &deblk_end)))
32099 + err = append_deblk(vdir);
32106 +/* ---------------------------------------------------------------------- */
32108 +void au_vdir_free(struct au_vdir *vdir)
32110 + unsigned char **deblk;
32112 + deblk = vdir->vd_deblk;
32113 + while (vdir->vd_nblk--)
32114 + au_kfree_try_rcu(*deblk++);
32115 + au_kfree_try_rcu(vdir->vd_deblk);
32116 + au_cache_free_vdir(vdir);
32119 +static struct au_vdir *alloc_vdir(struct file *file)
32121 + struct au_vdir *vdir;
32122 + struct super_block *sb;
32125 + sb = file->f_path.dentry->d_sb;
32126 + SiMustAnyLock(sb);
32129 + vdir = au_cache_alloc_vdir();
32130 + if (unlikely(!vdir))
32133 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32134 + if (unlikely(!vdir->vd_deblk))
32137 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32138 + if (!vdir->vd_deblk_sz) {
32139 + /* estimate the appropriate size for deblk */
32140 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32141 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32143 + vdir->vd_nblk = 0;
32144 + vdir->vd_version = 0;
32145 + vdir->vd_jiffy = 0;
32146 + err = append_deblk(vdir);
32148 + return vdir; /* success */
32150 + au_kfree_try_rcu(vdir->vd_deblk);
32153 + au_cache_free_vdir(vdir);
32155 + vdir = ERR_PTR(err);
32159 +static int reinit_vdir(struct au_vdir *vdir)
32162 + union au_vdir_deblk_p p, deblk_end;
32164 + while (vdir->vd_nblk > 1) {
32165 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32166 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32169 + p.deblk = vdir->vd_deblk[0];
32170 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32171 + err = set_deblk_end(&p, &deblk_end);
32172 + /* keep vd_dblk_sz */
32173 + vdir->vd_last.ul = 0;
32174 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32175 + vdir->vd_version = 0;
32176 + vdir->vd_jiffy = 0;
32181 +/* ---------------------------------------------------------------------- */
32183 +#define AuFillVdir_CALLED 1
32184 +#define AuFillVdir_WHABLE (1 << 1)
32185 +#define AuFillVdir_SHWH (1 << 2)
32186 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32187 +#define au_fset_fillvdir(flags, name) \
32188 + do { (flags) |= AuFillVdir_##name; } while (0)
32189 +#define au_fclr_fillvdir(flags, name) \
32190 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32192 +#ifndef CONFIG_AUFS_SHWH
32193 +#undef AuFillVdir_SHWH
32194 +#define AuFillVdir_SHWH 0
32197 +struct fillvdir_arg {
32198 + struct dir_context ctx;
32199 + struct file *file;
32200 + struct au_vdir *vdir;
32201 + struct au_nhash delist;
32202 + struct au_nhash whlist;
32203 + aufs_bindex_t bindex;
32204 + unsigned int flags;
32208 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32209 + loff_t offset __maybe_unused, u64 h_ino,
32210 + unsigned int d_type)
32212 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32213 + char *name = (void *)__name;
32214 + struct super_block *sb;
32216 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32219 + sb = arg->file->f_path.dentry->d_sb;
32220 + au_fset_fillvdir(arg->flags, CALLED);
32222 + if (nlen <= AUFS_WH_PFX_LEN
32223 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32224 + if (test_known(&arg->delist, name, nlen)
32225 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32226 + goto out; /* already exists or whiteouted */
32228 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32230 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32231 + d_type = DT_UNKNOWN;
32232 + arg->err = append_de(arg->vdir, name, nlen, ino,
32233 + d_type, &arg->delist);
32235 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32236 + name += AUFS_WH_PFX_LEN;
32237 + nlen -= AUFS_WH_PFX_LEN;
32238 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32239 + goto out; /* already whiteouted */
32241 + ino = 0; /* just to suppress a warning */
32243 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32246 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32247 + d_type = DT_UNKNOWN;
32248 + arg->err = au_nhash_append_wh
32249 + (&arg->whlist, name, nlen, ino, d_type,
32250 + arg->bindex, shwh);
32256 + arg->vdir->vd_jiffy = jiffies;
32258 + AuTraceErr(arg->err);
32262 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32263 + struct au_nhash *whlist, struct au_nhash *delist)
32265 +#ifdef CONFIG_AUFS_SHWH
32267 + unsigned int nh, u;
32268 + struct hlist_head *head;
32269 + struct au_vdir_wh *pos;
32270 + struct hlist_node *n;
32272 + struct au_vdir_destr *destr;
32274 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32277 + o = p = (void *)__get_free_page(GFP_NOFS);
32278 + if (unlikely(!p))
32282 + nh = whlist->nh_num;
32283 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32284 + p += AUFS_WH_PFX_LEN;
32285 + for (u = 0; u < nh; u++) {
32286 + head = whlist->nh_head + u;
32287 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32288 + destr = &pos->wh_str;
32289 + memcpy(p, destr->name, destr->len);
32290 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32291 + pos->wh_ino, pos->wh_type, delist);
32292 + if (unlikely(err))
32297 + free_page((unsigned long)o);
32307 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32310 + unsigned int rdhash;
32312 + aufs_bindex_t bbot, bindex, btop;
32313 + unsigned char shwh;
32314 + struct file *hf, *file;
32315 + struct super_block *sb;
32317 + file = arg->file;
32318 + sb = file->f_path.dentry->d_sb;
32319 + SiMustAnyLock(sb);
32321 + rdhash = au_sbi(sb)->si_rdhash;
32323 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32324 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32325 + if (unlikely(err))
32327 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32328 + if (unlikely(err))
32334 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32336 + au_fset_fillvdir(arg->flags, SHWH);
32338 + btop = au_fbtop(file);
32339 + bbot = au_fbbot_dir(file);
32340 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32341 + hf = au_hf_dir(file, bindex);
32345 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32347 + if (unlikely(offset))
32350 + arg->bindex = bindex;
32351 + au_fclr_fillvdir(arg->flags, WHABLE);
32353 + || (bindex != bbot
32354 + && au_br_whable(au_sbr_perm(sb, bindex))))
32355 + au_fset_fillvdir(arg->flags, WHABLE);
32358 + au_fclr_fillvdir(arg->flags, CALLED);
32360 + err = vfsub_iterate_dir(hf, &arg->ctx);
32363 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32366 + * dir_relax() may be good for concurrency, but aufs should not
32367 + * use it since it will cause a lockdep problem.
32371 + if (!err && shwh)
32372 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32374 + au_nhash_wh_free(&arg->whlist);
32377 + au_nhash_de_free(&arg->delist);
32382 +static int read_vdir(struct file *file, int may_read)
32385 + unsigned long expire;
32386 + unsigned char do_read;
32387 + struct fillvdir_arg arg = {
32389 + .actor = fillvdir
32392 + struct inode *inode;
32393 + struct au_vdir *vdir, *allocated;
32396 + inode = file_inode(file);
32397 + IMustLock(inode);
32398 + IiMustWriteLock(inode);
32399 + SiMustAnyLock(inode->i_sb);
32401 + allocated = NULL;
32403 + expire = au_sbi(inode->i_sb)->si_rdcache;
32404 + vdir = au_ivdir(inode);
32407 + vdir = alloc_vdir(file);
32408 + err = PTR_ERR(vdir);
32409 + if (IS_ERR(vdir))
32412 + allocated = vdir;
32413 + } else if (may_read
32414 + && (!inode_eq_iversion(inode, vdir->vd_version)
32415 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32417 + err = reinit_vdir(vdir);
32418 + if (unlikely(err))
32423 + return 0; /* success */
32427 + err = au_do_read_vdir(&arg);
32429 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32430 + vdir->vd_version = inode_query_iversion(inode);
32431 + vdir->vd_last.ul = 0;
32432 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32434 + au_set_ivdir(inode, allocated);
32435 + } else if (allocated)
32436 + au_vdir_free(allocated);
32442 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32445 + unsigned long ul, n;
32446 + const unsigned int deblk_sz = src->vd_deblk_sz;
32448 + AuDebugOn(tgt->vd_nblk != 1);
32451 + if (tgt->vd_nblk < src->vd_nblk) {
32452 + unsigned char **p;
32454 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32455 + GFP_NOFS, /*may_shrink*/0);
32456 + if (unlikely(!p))
32458 + tgt->vd_deblk = p;
32461 + if (tgt->vd_deblk_sz != deblk_sz) {
32462 + unsigned char *p;
32464 + tgt->vd_deblk_sz = deblk_sz;
32465 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32466 + /*may_shrink*/1);
32467 + if (unlikely(!p))
32469 + tgt->vd_deblk[0] = p;
32471 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32472 + tgt->vd_version = src->vd_version;
32473 + tgt->vd_jiffy = src->vd_jiffy;
32475 + n = src->vd_nblk;
32476 + for (ul = 1; ul < n; ul++) {
32477 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32479 + if (unlikely(!tgt->vd_deblk[ul]))
32483 + tgt->vd_nblk = n;
32484 + tgt->vd_last.ul = tgt->vd_last.ul;
32485 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32486 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32487 + - src->vd_deblk[src->vd_last.ul];
32489 + return 0; /* success */
32492 + rerr = reinit_vdir(tgt);
32497 +int au_vdir_init(struct file *file)
32500 + struct inode *inode;
32501 + struct au_vdir *vdir_cache, *allocated;
32503 + /* test file->f_pos here instead of ctx->pos */
32504 + err = read_vdir(file, !file->f_pos);
32505 + if (unlikely(err))
32508 + allocated = NULL;
32509 + vdir_cache = au_fvdir_cache(file);
32510 + if (!vdir_cache) {
32511 + vdir_cache = alloc_vdir(file);
32512 + err = PTR_ERR(vdir_cache);
32513 + if (IS_ERR(vdir_cache))
32515 + allocated = vdir_cache;
32516 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32517 + /* test file->f_pos here instead of ctx->pos */
32518 + err = reinit_vdir(vdir_cache);
32519 + if (unlikely(err))
32522 + return 0; /* success */
32524 + inode = file_inode(file);
32525 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32527 + file->f_version = inode_query_iversion(inode);
32529 + au_set_fvdir_cache(file, allocated);
32530 + } else if (allocated)
32531 + au_vdir_free(allocated);
32537 +static loff_t calc_offset(struct au_vdir *vdir)
32540 + union au_vdir_deblk_p p;
32542 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32543 + offset = vdir->vd_last.p.deblk - p.deblk;
32544 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32548 +/* returns true or false */
32549 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32552 + unsigned int deblk_sz;
32553 + unsigned long ul, n;
32555 + union au_vdir_deblk_p p, deblk_end;
32556 + struct au_vdir *vdir_cache;
32559 + vdir_cache = au_fvdir_cache(file);
32560 + offset = calc_offset(vdir_cache);
32561 + AuDbg("offset %lld\n", offset);
32562 + if (ctx->pos == offset)
32565 + vdir_cache->vd_last.ul = 0;
32566 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32571 + deblk_sz = vdir_cache->vd_deblk_sz;
32572 + ul = div64_u64(ctx->pos, deblk_sz);
32573 + AuDbg("ul %lu\n", ul);
32574 + if (ul >= vdir_cache->vd_nblk)
32577 + n = vdir_cache->vd_nblk;
32578 + for (; ul < n; ul++) {
32579 + p.deblk = vdir_cache->vd_deblk[ul];
32580 + deblk_end.deblk = p.deblk + deblk_sz;
32582 + offset *= deblk_sz;
32583 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32586 + l = calc_size(p.de->de_str.len);
32590 + if (!is_deblk_end(&p, &deblk_end)) {
32592 + vdir_cache->vd_last.ul = ul;
32593 + vdir_cache->vd_last.p = p;
32601 + AuDbg("valid %d\n", !valid);
32605 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32607 + unsigned int l, deblk_sz;
32608 + union au_vdir_deblk_p deblk_end;
32609 + struct au_vdir *vdir_cache;
32610 + struct au_vdir_de *de;
32612 + if (!seek_vdir(file, ctx))
32615 + vdir_cache = au_fvdir_cache(file);
32616 + deblk_sz = vdir_cache->vd_deblk_sz;
32618 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32619 + deblk_end.deblk += deblk_sz;
32620 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32621 + de = vdir_cache->vd_last.p.de;
32622 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32623 + de->de_str.len, de->de_str.name, ctx->pos,
32624 + (unsigned long)de->de_ino, de->de_type);
32625 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32626 + de->de_str.len, de->de_ino,
32628 + /* todo: ignore the error caused by udba? */
32629 + /* return err; */
32633 + l = calc_size(de->de_str.len);
32634 + vdir_cache->vd_last.p.deblk += l;
32637 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32638 + vdir_cache->vd_last.ul++;
32639 + vdir_cache->vd_last.p.deblk
32640 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32641 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32650 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32651 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32652 +++ linux/fs/aufs/vfsub.c 2021-09-06 21:02:45.280158943 +0200
32654 +// SPDX-License-Identifier: GPL-2.0
32656 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32658 + * This program, aufs is free software; you can redistribute it and/or modify
32659 + * it under the terms of the GNU General Public License as published by
32660 + * the Free Software Foundation; either version 2 of the License, or
32661 + * (at your option) any later version.
32663 + * This program is distributed in the hope that it will be useful,
32664 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32665 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32666 + * GNU General Public License for more details.
32668 + * You should have received a copy of the GNU General Public License
32669 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32673 + * sub-routines for VFS
32676 +#include <linux/mnt_namespace.h>
32677 +#include <linux/namei.h>
32678 +#include <linux/nsproxy.h>
32679 +#include <linux/security.h>
32680 +#include <linux/splice.h>
32683 +#ifdef CONFIG_AUFS_BR_FUSE
32684 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32686 + if (!au_test_fuse(h_sb) || !au_userns)
32689 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32693 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32698 + down_read(&h_sb->s_umount);
32699 + err = __sync_filesystem(h_sb, wait);
32700 + up_read(&h_sb->s_umount);
32706 +/* ---------------------------------------------------------------------- */
32708 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32712 + struct super_block *h_sb;
32714 + /* for remote fs, leave work for its getattr or d_revalidate */
32715 + /* for bad i_attr fs, handle them in aufs_getattr() */
32716 + /* still some fs may acquire i_mutex. we need to skip them */
32720 + h_sb = h_path->dentry->d_sb;
32721 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32723 + err = vfsub_getattr(h_path, &st);
32728 +/* ---------------------------------------------------------------------- */
32730 +struct file *vfsub_dentry_open(struct path *path, int flags)
32732 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32736 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32738 + struct file *file;
32741 + file = filp_open(path,
32742 + oflags /* | __FMODE_NONOTIFY */,
32745 + if (IS_ERR(file))
32747 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32754 + * Ideally this function should call VFS:do_last() in order to keep all its
32755 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32756 + * structure such as nameidata. This is a second (or third) best approach.
32757 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32759 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32760 + struct vfsub_aopen_args *args)
32763 + struct au_branch *br = args->br;
32764 + struct file *file = args->file;
32765 + /* copied from linux/fs/namei.c:atomic_open() */
32766 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32769 + AuDebugOn(!dir->i_op->atomic_open);
32771 + err = au_br_test_oflag(args->open_flag, br);
32772 + if (unlikely(err))
32775 + au_lcnt_inc(&br->br_nfiles);
32776 + file->f_path.dentry = DENTRY_NOT_SET;
32777 + file->f_path.mnt = au_br_mnt(br);
32778 + AuDbg("%ps\n", dir->i_op->atomic_open);
32779 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32780 + args->create_mode);
32781 + if (unlikely(err < 0)) {
32782 + au_lcnt_dec(&br->br_nfiles);
32786 + /* temporary workaround for nfsv4 branch */
32787 + if (au_test_nfs(dir->i_sb))
32788 + nfs_mark_for_revalidate(dir);
32790 + if (file->f_mode & FMODE_CREATED)
32791 + fsnotify_create(dir, dentry);
32792 + if (!(file->f_mode & FMODE_OPENED)) {
32793 + au_lcnt_dec(&br->br_nfiles);
32797 + /* todo: call VFS:may_open() here */
32798 + /* todo: ima_file_check() too? */
32799 + if (!err && (args->open_flag & __FMODE_EXEC))
32800 + err = deny_write_access(file);
32802 + fsnotify_open(file);
32804 + au_lcnt_dec(&br->br_nfiles);
32805 + /* note that the file is created and still opened */
32811 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32815 + err = kern_path(name, flags, path);
32816 + if (!err && d_is_positive(path->dentry))
32817 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32821 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32822 + struct dentry *parent, int len)
32824 + struct path path = {
32828 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32829 + if (IS_ERR(path.dentry))
32831 + if (d_is_positive(path.dentry))
32832 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32835 + AuTraceErrPtr(path.dentry);
32836 + return path.dentry;
32839 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32842 + struct path path = {
32846 + /* VFS checks it too, but by WARN_ON_ONCE() */
32847 + IMustLock(d_inode(parent));
32849 + path.dentry = lookup_one_len(name, parent, len);
32850 + if (IS_ERR(path.dentry))
32852 + if (d_is_positive(path.dentry))
32853 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32856 + AuTraceErrPtr(path.dentry);
32857 + return path.dentry;
32860 +void vfsub_call_lkup_one(void *args)
32862 + struct vfsub_lkup_one_args *a = args;
32863 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32866 +/* ---------------------------------------------------------------------- */
32868 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32869 + struct dentry *d2, struct au_hinode *hdir2)
32871 + struct dentry *d;
32874 + d = lock_rename(d1, d2);
32876 + au_hn_suspend(hdir1);
32877 + if (hdir1 != hdir2)
32878 + au_hn_suspend(hdir2);
32883 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32884 + struct dentry *d2, struct au_hinode *hdir2)
32886 + au_hn_resume(hdir1);
32887 + if (hdir1 != hdir2)
32888 + au_hn_resume(hdir2);
32890 + unlock_rename(d1, d2);
32894 +/* ---------------------------------------------------------------------- */
32896 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32899 + struct dentry *d;
32900 + struct user_namespace *userns;
32904 + d = path->dentry;
32905 + path->dentry = d->d_parent;
32906 + err = security_path_mknod(path, d, mode, 0);
32907 + path->dentry = d;
32908 + if (unlikely(err))
32910 + userns = mnt_user_ns(path->mnt);
32913 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
32916 + struct path tmp = *path;
32919 + vfsub_update_h_iattr(&tmp, &did);
32921 + tmp.dentry = path->dentry->d_parent;
32922 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32931 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32934 + struct dentry *d;
32935 + struct user_namespace *userns;
32939 + d = path->dentry;
32940 + path->dentry = d->d_parent;
32941 + err = security_path_symlink(path, d, symname);
32942 + path->dentry = d;
32943 + if (unlikely(err))
32945 + userns = mnt_user_ns(path->mnt);
32948 + err = vfs_symlink(userns, dir, path->dentry, symname);
32951 + struct path tmp = *path;
32954 + vfsub_update_h_iattr(&tmp, &did);
32956 + tmp.dentry = path->dentry->d_parent;
32957 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32966 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32969 + struct dentry *d;
32970 + struct user_namespace *userns;
32974 + d = path->dentry;
32975 + path->dentry = d->d_parent;
32976 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32977 + path->dentry = d;
32978 + if (unlikely(err))
32980 + userns = mnt_user_ns(path->mnt);
32983 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
32986 + struct path tmp = *path;
32989 + vfsub_update_h_iattr(&tmp, &did);
32991 + tmp.dentry = path->dentry->d_parent;
32992 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33001 +static int au_test_nlink(struct inode *inode)
33003 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33005 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33006 + || inode->i_nlink < link_max)
33011 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33012 + struct inode **delegated_inode)
33015 + struct dentry *d;
33016 + struct user_namespace *userns;
33020 + err = au_test_nlink(d_inode(src_dentry));
33021 + if (unlikely(err))
33024 + /* we don't call may_linkat() */
33025 + d = path->dentry;
33026 + path->dentry = d->d_parent;
33027 + err = security_path_link(src_dentry, path, d);
33028 + path->dentry = d;
33029 + if (unlikely(err))
33031 + userns = mnt_user_ns(path->mnt);
33034 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33037 + struct path tmp = *path;
33040 + /* fuse has different memory inode for the same inumber */
33041 + vfsub_update_h_iattr(&tmp, &did);
33043 + tmp.dentry = path->dentry->d_parent;
33044 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33045 + tmp.dentry = src_dentry;
33046 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33055 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33056 + struct inode *dir, struct path *path,
33057 + struct inode **delegated_inode, unsigned int flags)
33060 + struct renamedata rd;
33061 + struct path tmp = {
33064 + struct dentry *d;
33067 + IMustLock(src_dir);
33069 + d = path->dentry;
33070 + path->dentry = d->d_parent;
33071 + tmp.dentry = src_dentry->d_parent;
33072 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33073 + path->dentry = d;
33074 + if (unlikely(err))
33077 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33078 + rd.old_dir = src_dir;
33079 + rd.old_dentry = src_dentry;
33080 + rd.new_mnt_userns = rd.old_mnt_userns;
33081 + rd.new_dir = dir;
33082 + rd.new_dentry = path->dentry;
33083 + rd.delegated_inode = delegated_inode;
33084 + rd.flags = flags;
33086 + err = vfs_rename(&rd);
33091 + tmp.dentry = d->d_parent;
33092 + vfsub_update_h_iattr(&tmp, &did);
33094 + tmp.dentry = src_dentry;
33095 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33096 + tmp.dentry = src_dentry->d_parent;
33097 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33106 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33109 + struct dentry *d;
33110 + struct user_namespace *userns;
33114 + d = path->dentry;
33115 + path->dentry = d->d_parent;
33116 + err = security_path_mkdir(path, d, mode);
33117 + path->dentry = d;
33118 + if (unlikely(err))
33120 + userns = mnt_user_ns(path->mnt);
33123 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33126 + struct path tmp = *path;
33129 + vfsub_update_h_iattr(&tmp, &did);
33131 + tmp.dentry = path->dentry->d_parent;
33132 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33141 +int vfsub_rmdir(struct inode *dir, struct path *path)
33144 + struct dentry *d;
33145 + struct user_namespace *userns;
33149 + d = path->dentry;
33150 + path->dentry = d->d_parent;
33151 + err = security_path_rmdir(path, d);
33152 + path->dentry = d;
33153 + if (unlikely(err))
33155 + userns = mnt_user_ns(path->mnt);
33158 + err = vfs_rmdir(userns, dir, path->dentry);
33161 + struct path tmp = {
33162 + .dentry = path->dentry->d_parent,
33166 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33173 +/* ---------------------------------------------------------------------- */
33175 +/* todo: support mmap_sem? */
33176 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33182 + err = vfs_read(file, ubuf, count, ppos);
33185 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33189 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33195 + err = kernel_read(file, kbuf, count, ppos);
33199 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33203 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33209 + err = vfs_write(file, ubuf, count, ppos);
33212 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33216 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33221 + err = kernel_write(file, kbuf, count, ppos);
33224 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33228 +int vfsub_flush(struct file *file, fl_owner_t id)
33233 + if (file->f_op->flush) {
33234 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33235 + err = file->f_op->flush(file, id);
33238 + err = file->f_op->flush(file, id);
33242 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33248 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33252 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33255 + err = iterate_dir(file, ctx);
33258 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33263 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33264 + struct pipe_inode_info *pipe, size_t len,
33265 + unsigned int flags)
33270 + err = do_splice_to(in, ppos, pipe, len, flags);
33272 + file_accessed(in);
33274 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33278 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33279 + loff_t *ppos, size_t len, unsigned int flags)
33284 + err = do_splice_from(pipe, out, ppos, len, flags);
33287 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33291 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33295 + /* file can be NULL */
33297 + err = vfs_fsync(file, datasync);
33301 + AuDebugOn(!file);
33302 + path = &file->f_path;
33304 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33309 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33310 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33311 + struct file *h_file)
33314 + struct inode *h_inode;
33315 + struct super_block *h_sb;
33316 + struct user_namespace *h_userns;
33319 + err = vfsub_truncate(h_path, length);
33323 + h_inode = d_inode(h_path->dentry);
33324 + h_sb = h_inode->i_sb;
33326 + sb_start_write(h_sb);
33328 + err = locks_verify_truncate(h_inode, h_file, length);
33330 + err = security_path_truncate(h_path);
33332 + h_userns = mnt_user_ns(h_path->mnt);
33334 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33339 + sb_end_write(h_sb);
33346 +/* ---------------------------------------------------------------------- */
33348 +struct au_vfsub_mkdir_args {
33350 + struct inode *dir;
33351 + struct path *path;
33355 +static void au_call_vfsub_mkdir(void *args)
33357 + struct au_vfsub_mkdir_args *a = args;
33358 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33361 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33363 + int err, do_sio, wkq_err;
33364 + struct user_namespace *userns;
33366 + userns = mnt_user_ns(path->mnt);
33367 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33370 + err = vfsub_mkdir(dir, path, mode);
33373 + struct au_vfsub_mkdir_args args = {
33379 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33380 + if (unlikely(wkq_err))
33387 +struct au_vfsub_rmdir_args {
33389 + struct inode *dir;
33390 + struct path *path;
33393 +static void au_call_vfsub_rmdir(void *args)
33395 + struct au_vfsub_rmdir_args *a = args;
33396 + *a->errp = vfsub_rmdir(a->dir, a->path);
33399 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33401 + int err, do_sio, wkq_err;
33402 + struct user_namespace *userns;
33404 + userns = mnt_user_ns(path->mnt);
33405 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33408 + err = vfsub_rmdir(dir, path);
33411 + struct au_vfsub_rmdir_args args = {
33416 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33417 + if (unlikely(wkq_err))
33424 +/* ---------------------------------------------------------------------- */
33426 +struct notify_change_args {
33428 + struct path *path;
33429 + struct iattr *ia;
33430 + struct inode **delegated_inode;
33433 +static void call_notify_change(void *args)
33435 + struct notify_change_args *a = args;
33436 + struct inode *h_inode;
33437 + struct user_namespace *userns;
33439 + h_inode = d_inode(a->path->dentry);
33440 + IMustLock(h_inode);
33442 + *a->errp = -EPERM;
33443 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33444 + userns = mnt_user_ns(a->path->mnt);
33446 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33447 + a->delegated_inode);
33450 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33452 + AuTraceErr(*a->errp);
33455 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33456 + struct inode **delegated_inode)
33459 + struct notify_change_args args = {
33463 + .delegated_inode = delegated_inode
33466 + call_notify_change(&args);
33471 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33472 + struct inode **delegated_inode)
33474 + int err, wkq_err;
33475 + struct notify_change_args args = {
33479 + .delegated_inode = delegated_inode
33482 + wkq_err = au_wkq_wait(call_notify_change, &args);
33483 + if (unlikely(wkq_err))
33489 +/* ---------------------------------------------------------------------- */
33491 +struct unlink_args {
33493 + struct inode *dir;
33494 + struct path *path;
33495 + struct inode **delegated_inode;
33498 +static void call_unlink(void *args)
33500 + struct unlink_args *a = args;
33501 + struct dentry *d = a->path->dentry;
33502 + struct inode *h_inode;
33503 + struct user_namespace *userns;
33504 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33505 + && au_dcount(d) == 1);
33507 + IMustLock(a->dir);
33509 + a->path->dentry = d->d_parent;
33510 + *a->errp = security_path_unlink(a->path, d);
33511 + a->path->dentry = d;
33512 + if (unlikely(*a->errp))
33515 + if (!stop_sillyrename)
33518 + if (d_is_positive(d)) {
33519 + h_inode = d_inode(d);
33523 + userns = mnt_user_ns(a->path->mnt);
33525 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33528 + struct path tmp = {
33529 + .dentry = d->d_parent,
33530 + .mnt = a->path->mnt
33532 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33535 + if (!stop_sillyrename)
33540 + AuTraceErr(*a->errp);
33544 + * @dir: must be locked.
33545 + * @dentry: target dentry.
33547 +int vfsub_unlink(struct inode *dir, struct path *path,
33548 + struct inode **delegated_inode, int force)
33551 + struct unlink_args args = {
33555 + .delegated_inode = delegated_inode
33559 + call_unlink(&args);
33563 + wkq_err = au_wkq_wait(call_unlink, &args);
33564 + if (unlikely(wkq_err))
33570 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33571 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33572 +++ linux/fs/aufs/vfsub.h 2021-09-06 21:02:45.280158943 +0200
33574 +/* SPDX-License-Identifier: GPL-2.0 */
33576 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33578 + * This program, aufs is free software; you can redistribute it and/or modify
33579 + * it under the terms of the GNU General Public License as published by
33580 + * the Free Software Foundation; either version 2 of the License, or
33581 + * (at your option) any later version.
33583 + * This program is distributed in the hope that it will be useful,
33584 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33585 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33586 + * GNU General Public License for more details.
33588 + * You should have received a copy of the GNU General Public License
33589 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33593 + * sub-routines for VFS
33596 +#ifndef __AUFS_VFSUB_H__
33597 +#define __AUFS_VFSUB_H__
33601 +#include <linux/fs.h>
33602 +#include <linux/mount.h>
33603 +#include <linux/posix_acl.h>
33604 +#include <linux/xattr.h>
33605 +#include "debug.h"
33607 +/* copied from linux/fs/internal.h */
33608 +/* todo: BAD approach!! */
33609 +extern void __mnt_drop_write(struct vfsmount *);
33610 +extern struct file *alloc_empty_file(int, const struct cred *);
33612 +/* ---------------------------------------------------------------------- */
33614 +/* lock subclass for lower inode */
33615 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33616 +/* reduce? gave up. */
33618 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33619 + AuLsc_I_PARENT, /* lower inode, parent first */
33620 + AuLsc_I_PARENT2, /* copyup dirs */
33621 + AuLsc_I_PARENT3, /* copyup wh */
33627 +/* to debug easier, do not make them inlined functions */
33628 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33629 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33631 +/* ---------------------------------------------------------------------- */
33633 +static inline void vfsub_drop_nlink(struct inode *inode)
33635 + AuDebugOn(!inode->i_nlink);
33636 + drop_nlink(inode);
33639 +static inline void vfsub_dead_dir(struct inode *inode)
33641 + AuDebugOn(!S_ISDIR(inode->i_mode));
33642 + inode->i_flags |= S_DEAD;
33643 + clear_nlink(inode);
33646 +static inline int vfsub_native_ro(struct inode *inode)
33648 + return sb_rdonly(inode->i_sb)
33649 + || IS_RDONLY(inode)
33650 + /* || IS_APPEND(inode) */
33651 + || IS_IMMUTABLE(inode);
33654 +#ifdef CONFIG_AUFS_BR_FUSE
33655 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33657 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33660 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33662 +/* ---------------------------------------------------------------------- */
33664 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33665 +struct file *vfsub_dentry_open(struct path *path, int flags);
33666 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33668 +struct vfsub_aopen_args {
33669 + struct file *file;
33670 + unsigned int open_flag;
33671 + umode_t create_mode;
33672 + struct au_branch *br;
33674 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33675 + struct vfsub_aopen_args *args);
33676 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33678 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33679 + struct dentry *parent, int len);
33680 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33683 +struct vfsub_lkup_one_args {
33684 + struct dentry **errp;
33685 + struct qstr *name;
33686 + struct dentry *parent;
33689 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33690 + struct dentry *parent)
33692 + return vfsub_lookup_one_len(name->name, parent, name->len);
33695 +void vfsub_call_lkup_one(void *args);
33697 +/* ---------------------------------------------------------------------- */
33699 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33704 + err = mnt_want_write(mnt);
33709 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33712 + mnt_drop_write(mnt);
33716 +#if 0 /* reserved */
33717 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33720 + mnt_drop_write_file(file);
33725 +/* ---------------------------------------------------------------------- */
33728 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33729 + struct dentry *d2, struct au_hinode *hdir2);
33730 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33731 + struct dentry *d2, struct au_hinode *hdir2);
33733 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33735 +int vfsub_symlink(struct inode *dir, struct path *path,
33736 + const char *symname);
33737 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33738 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33739 + struct path *path, struct inode **delegated_inode);
33740 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33741 + struct inode *hdir, struct path *path,
33742 + struct inode **delegated_inode, unsigned int flags);
33743 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33744 +int vfsub_rmdir(struct inode *dir, struct path *path);
33746 +/* ---------------------------------------------------------------------- */
33748 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33750 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33752 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33754 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33756 +int vfsub_flush(struct file *file, fl_owner_t id);
33757 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33759 +static inline loff_t vfsub_f_size_read(struct file *file)
33761 + return i_size_read(file_inode(file));
33764 +static inline unsigned int vfsub_file_flags(struct file *file)
33766 + unsigned int flags;
33768 + spin_lock(&file->f_lock);
33769 + flags = file->f_flags;
33770 + spin_unlock(&file->f_lock);
33775 +static inline int vfsub_file_execed(struct file *file)
33777 + /* todo: direct access f_flags */
33778 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33781 +#if 0 /* reserved */
33782 +static inline void vfsub_file_accessed(struct file *h_file)
33784 + file_accessed(h_file);
33785 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33789 +#if 0 /* reserved */
33790 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33791 + struct dentry *h_dentry)
33793 + struct path h_path = {
33794 + .dentry = h_dentry,
33797 + touch_atime(&h_path);
33798 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33802 +static inline int vfsub_update_time(struct inode *h_inode,
33803 + struct timespec64 *ts, int flags)
33805 + return update_time(h_inode, ts, flags);
33806 + /* no vfsub_update_h_iattr() since we don't have struct path */
33809 +#ifdef CONFIG_FS_POSIX_ACL
33810 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
33811 + struct inode *h_inode, umode_t h_mode)
33815 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
33816 + if (err == -EOPNOTSUPP)
33821 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
33822 + struct inode *h_inode, umode_t h_mode);
33825 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33826 + struct pipe_inode_info *pipe, size_t len,
33827 + unsigned int flags);
33828 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33829 + loff_t *ppos, size_t len, unsigned int flags);
33831 +static inline long vfsub_truncate(struct path *path, loff_t length)
33836 + err = vfs_truncate(path, length);
33841 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33842 + struct file *h_file);
33843 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33846 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33849 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33855 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33861 +/* copy_file_range(2) is a systemcall */
33862 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33863 + struct file *dst, loff_t dst_pos,
33864 + size_t len, unsigned int flags)
33869 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33875 +/* ---------------------------------------------------------------------- */
33877 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33882 + err = vfs_llseek(file, offset, origin);
33887 +/* ---------------------------------------------------------------------- */
33889 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33890 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33891 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33892 + struct inode **delegated_inode);
33893 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33894 + struct inode **delegated_inode);
33895 +int vfsub_unlink(struct inode *dir, struct path *path,
33896 + struct inode **delegated_inode, int force);
33898 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33900 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33903 +/* ---------------------------------------------------------------------- */
33905 +static inline int vfsub_setxattr(struct user_namespace *userns,
33906 + struct dentry *dentry, const char *name,
33907 + const void *value, size_t size, int flags)
33912 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
33918 +static inline int vfsub_removexattr(struct user_namespace *userns,
33919 + struct dentry *dentry, const char *name)
33924 + err = vfs_removexattr(userns, dentry, name);
33930 +#endif /* __KERNEL__ */
33931 +#endif /* __AUFS_VFSUB_H__ */
33932 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33933 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33934 +++ linux/fs/aufs/wbr_policy.c 2021-09-06 21:02:45.280158943 +0200
33936 +// SPDX-License-Identifier: GPL-2.0
33938 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33940 + * This program, aufs is free software; you can redistribute it and/or modify
33941 + * it under the terms of the GNU General Public License as published by
33942 + * the Free Software Foundation; either version 2 of the License, or
33943 + * (at your option) any later version.
33945 + * This program is distributed in the hope that it will be useful,
33946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33948 + * GNU General Public License for more details.
33950 + * You should have received a copy of the GNU General Public License
33951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33955 + * policies for selecting one among multiple writable branches
33958 +#include <linux/statfs.h>
33961 +/* subset of cpup_attr() */
33962 +static noinline_for_stack
33963 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33967 + struct inode *h_isrc;
33969 + h_isrc = d_inode(h_src);
33970 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33971 + ia.ia_mode = h_isrc->i_mode;
33972 + ia.ia_uid = h_isrc->i_uid;
33973 + ia.ia_gid = h_isrc->i_gid;
33974 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33975 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33976 + /* no delegation since it is just created */
33977 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33979 + /* is this nfs only? */
33980 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33981 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33982 + ia.ia_mode = h_isrc->i_mode;
33983 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33989 +#define AuCpdown_PARENT_OPQ 1
33990 +#define AuCpdown_WHED (1 << 1)
33991 +#define AuCpdown_MADE_DIR (1 << 2)
33992 +#define AuCpdown_DIROPQ (1 << 3)
33993 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33994 +#define au_fset_cpdown(flags, name) \
33995 + do { (flags) |= AuCpdown_##name; } while (0)
33996 +#define au_fclr_cpdown(flags, name) \
33997 + do { (flags) &= ~AuCpdown_##name; } while (0)
33999 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34000 + unsigned int *flags)
34003 + struct dentry *opq_dentry;
34005 + opq_dentry = au_diropq_create(dentry, bdst);
34006 + err = PTR_ERR(opq_dentry);
34007 + if (IS_ERR(opq_dentry))
34009 + dput(opq_dentry);
34010 + au_fset_cpdown(*flags, DIROPQ);
34016 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34017 + struct inode *dir, aufs_bindex_t bdst)
34020 + struct path h_path;
34021 + struct au_branch *br;
34023 + br = au_sbr(dentry->d_sb, bdst);
34024 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34025 + err = PTR_ERR(h_path.dentry);
34026 + if (IS_ERR(h_path.dentry))
34030 + if (d_is_positive(h_path.dentry)) {
34031 + h_path.mnt = au_br_mnt(br);
34032 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34035 + dput(h_path.dentry);
34041 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34042 + struct au_pin *pin,
34043 + struct dentry *h_parent, void *arg)
34046 + aufs_bindex_t bopq, btop;
34047 + struct path h_path;
34048 + struct dentry *parent;
34049 + struct inode *h_dir, *h_inode, *inode, *dir;
34050 + unsigned int *flags = arg;
34052 + btop = au_dbtop(dentry);
34053 + /* dentry is di-locked */
34054 + parent = dget_parent(dentry);
34055 + dir = d_inode(parent);
34056 + h_dir = d_inode(h_parent);
34057 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34058 + IMustLock(h_dir);
34060 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34061 + if (unlikely(err < 0))
34063 + h_path.dentry = au_h_dptr(dentry, bdst);
34064 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34065 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34066 + if (unlikely(err))
34068 + au_fset_cpdown(*flags, MADE_DIR);
34070 + bopq = au_dbdiropq(dentry);
34071 + au_fclr_cpdown(*flags, WHED);
34072 + au_fclr_cpdown(*flags, DIROPQ);
34073 + if (au_dbwh(dentry) == bdst)
34074 + au_fset_cpdown(*flags, WHED);
34075 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34076 + au_fset_cpdown(*flags, PARENT_OPQ);
34077 + h_inode = d_inode(h_path.dentry);
34078 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34079 + if (au_ftest_cpdown(*flags, WHED)) {
34080 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34081 + if (unlikely(err)) {
34082 + inode_unlock(h_inode);
34087 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34088 + inode_unlock(h_inode);
34089 + if (unlikely(err))
34092 + if (au_ftest_cpdown(*flags, WHED)) {
34093 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34094 + if (unlikely(err))
34098 + inode = d_inode(dentry);
34099 + if (au_ibbot(inode) < bdst)
34100 + au_set_ibbot(inode, bdst);
34101 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34102 + au_hi_flags(inode, /*isdir*/1));
34103 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34104 + goto out; /* success */
34108 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34109 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34110 + rerr = au_diropq_remove(dentry, bdst);
34111 + inode_unlock(h_inode);
34112 + if (unlikely(rerr)) {
34113 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34114 + dentry, bdst, rerr);
34120 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34121 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34122 + if (unlikely(rerr)) {
34123 + AuIOErr("failed removing %pd b%d (%d)\n",
34124 + dentry, bdst, rerr);
34129 + au_set_h_dptr(dentry, bdst, NULL);
34130 + if (au_dbbot(dentry) == bdst)
34131 + au_update_dbbot(dentry);
34137 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34140 + unsigned int flags;
34143 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34148 +/* ---------------------------------------------------------------------- */
34150 +/* policies for create */
34152 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34154 + int err, i, j, ndentry;
34155 + aufs_bindex_t bopq;
34156 + struct au_dcsub_pages dpages;
34157 + struct au_dpage *dpage;
34158 + struct dentry **dentries, *parent, *d;
34160 + err = au_dpages_init(&dpages, GFP_NOFS);
34161 + if (unlikely(err))
34163 + parent = dget_parent(dentry);
34164 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34165 + if (unlikely(err))
34169 + for (i = 0; i < dpages.ndpage; i++) {
34170 + dpage = dpages.dpages + i;
34171 + dentries = dpage->dentries;
34172 + ndentry = dpage->ndentry;
34173 + for (j = 0; j < ndentry; j++) {
34175 + di_read_lock_parent2(d, !AuLock_IR);
34176 + bopq = au_dbdiropq(d);
34177 + di_read_unlock(d, !AuLock_IR);
34178 + if (bopq >= 0 && bopq < err)
34185 + au_dpages_free(&dpages);
34190 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34192 + for (; bindex >= 0; bindex--)
34193 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34198 +/* top down parent */
34199 +static int au_wbr_create_tdp(struct dentry *dentry,
34200 + unsigned int flags __maybe_unused)
34203 + aufs_bindex_t btop, bindex;
34204 + struct super_block *sb;
34205 + struct dentry *parent, *h_parent;
34207 + sb = dentry->d_sb;
34208 + btop = au_dbtop(dentry);
34210 + if (!au_br_rdonly(au_sbr(sb, btop)))
34214 + parent = dget_parent(dentry);
34215 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34216 + h_parent = au_h_dptr(parent, bindex);
34217 + if (!h_parent || d_is_negative(h_parent))
34220 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34227 + /* bottom up here */
34228 + if (unlikely(err < 0)) {
34229 + err = au_wbr_bu(sb, btop - 1);
34231 + err = au_wbr_nonopq(dentry, err);
34235 + AuDbg("b%d\n", err);
34239 +/* ---------------------------------------------------------------------- */
34241 +/* an exception for the policy other than tdp */
34242 +static int au_wbr_create_exp(struct dentry *dentry)
34245 + aufs_bindex_t bwh, bdiropq;
34246 + struct dentry *parent;
34249 + bwh = au_dbwh(dentry);
34250 + parent = dget_parent(dentry);
34251 + bdiropq = au_dbdiropq(parent);
34253 + if (bdiropq >= 0)
34254 + err = min(bdiropq, bwh);
34257 + AuDbg("%d\n", err);
34258 + } else if (bdiropq >= 0) {
34260 + AuDbg("%d\n", err);
34265 + err = au_wbr_nonopq(dentry, err);
34267 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34270 + AuDbg("%d\n", err);
34274 +/* ---------------------------------------------------------------------- */
34277 +static int au_wbr_create_init_rr(struct super_block *sb)
34281 + err = au_wbr_bu(sb, au_sbbot(sb));
34282 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34285 + AuDbg("b%d\n", err);
34289 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34293 + aufs_bindex_t bindex, bbot;
34294 + struct super_block *sb;
34297 + err = au_wbr_create_exp(dentry);
34301 + sb = dentry->d_sb;
34302 + next = &au_sbi(sb)->si_wbr_rr_next;
34303 + bbot = au_sbbot(sb);
34305 + for (bindex = 0; bindex <= bbot; bindex++) {
34306 + if (!au_ftest_wbr(flags, DIR)) {
34307 + err = atomic_dec_return(next) + 1;
34308 + /* modulo for 0 is meaningless */
34309 + if (unlikely(!err))
34310 + err = atomic_dec_return(next) + 1;
34312 + err = atomic_read(next);
34313 + AuDbg("%d\n", err);
34316 + AuDbg("%d\n", err);
34317 + if (!au_br_rdonly(au_sbr(sb, err)))
34323 + err = au_wbr_nonopq(dentry, err);
34326 + AuDbg("%d\n", err);
34330 +/* ---------------------------------------------------------------------- */
34332 +/* most free space */
34333 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34335 + struct super_block *sb;
34336 + struct au_branch *br;
34337 + struct au_wbr_mfs *mfs;
34338 + struct dentry *h_parent;
34339 + aufs_bindex_t bindex, bbot;
34341 + unsigned long long b, bavail;
34342 + struct path h_path;
34343 + /* reduce the stack usage */
34344 + struct kstatfs *st;
34346 + st = kmalloc(sizeof(*st), GFP_NOFS);
34347 + if (unlikely(!st)) {
34348 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34353 + sb = dentry->d_sb;
34354 + mfs = &au_sbi(sb)->si_wbr_mfs;
34355 + MtxMustLock(&mfs->mfs_lock);
34356 + mfs->mfs_bindex = -EROFS;
34357 + mfs->mfsrr_bytes = 0;
34360 + bbot = au_sbbot(sb);
34362 + bindex = au_dbtop(parent);
34363 + bbot = au_dbtaildir(parent);
34366 + for (; bindex <= bbot; bindex++) {
34368 + h_parent = au_h_dptr(parent, bindex);
34369 + if (!h_parent || d_is_negative(h_parent))
34372 + br = au_sbr(sb, bindex);
34373 + if (au_br_rdonly(br))
34376 + /* sb->s_root for NFS is unreliable */
34377 + h_path.mnt = au_br_mnt(br);
34378 + h_path.dentry = h_path.mnt->mnt_root;
34379 + err = vfs_statfs(&h_path, st);
34380 + if (unlikely(err)) {
34381 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34385 + /* when the available size is equal, select the lower one */
34386 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34387 + || sizeof(b) < sizeof(st->f_bsize));
34388 + b = st->f_bavail * st->f_bsize;
34389 + br->br_wbr->wbr_bytes = b;
34390 + if (b >= bavail) {
34392 + mfs->mfs_bindex = bindex;
34393 + mfs->mfs_jiffy = jiffies;
34397 + mfs->mfsrr_bytes = bavail;
34398 + AuDbg("b%d\n", mfs->mfs_bindex);
34399 + au_kfree_rcu(st);
34402 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34405 + struct dentry *parent;
34406 + struct super_block *sb;
34407 + struct au_wbr_mfs *mfs;
34409 + err = au_wbr_create_exp(dentry);
34413 + sb = dentry->d_sb;
34415 + if (au_ftest_wbr(flags, PARENT))
34416 + parent = dget_parent(dentry);
34417 + mfs = &au_sbi(sb)->si_wbr_mfs;
34418 + mutex_lock(&mfs->mfs_lock);
34419 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34420 + || mfs->mfs_bindex < 0
34421 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34422 + au_mfs(dentry, parent);
34423 + mutex_unlock(&mfs->mfs_lock);
34424 + err = mfs->mfs_bindex;
34428 + err = au_wbr_nonopq(dentry, err);
34431 + AuDbg("b%d\n", err);
34435 +static int au_wbr_create_init_mfs(struct super_block *sb)
34437 + struct au_wbr_mfs *mfs;
34439 + mfs = &au_sbi(sb)->si_wbr_mfs;
34440 + mutex_init(&mfs->mfs_lock);
34441 + mfs->mfs_jiffy = 0;
34442 + mfs->mfs_bindex = -EROFS;
34447 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34449 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34453 +/* ---------------------------------------------------------------------- */
34455 +/* top down regardless parent, and then mfs */
34456 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34457 + unsigned int flags __maybe_unused)
34460 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34461 + unsigned long long watermark;
34462 + struct super_block *sb;
34463 + struct au_wbr_mfs *mfs;
34464 + struct au_branch *br;
34465 + struct dentry *parent;
34467 + sb = dentry->d_sb;
34468 + mfs = &au_sbi(sb)->si_wbr_mfs;
34469 + mutex_lock(&mfs->mfs_lock);
34470 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34471 + || mfs->mfs_bindex < 0)
34472 + au_mfs(dentry, /*parent*/NULL);
34473 + watermark = mfs->mfsrr_watermark;
34474 + bmfs = mfs->mfs_bindex;
34475 + mutex_unlock(&mfs->mfs_lock);
34477 + /* another style of au_wbr_create_exp() */
34478 + bwh = au_dbwh(dentry);
34479 + parent = dget_parent(dentry);
34480 + btail = au_dbtaildir(parent);
34481 + if (bwh >= 0 && bwh < btail)
34484 + err = au_wbr_nonopq(dentry, btail);
34485 + if (unlikely(err < 0))
34489 + for (bindex = 0; bindex <= btail; bindex++) {
34490 + br = au_sbr(sb, bindex);
34491 + if (au_br_rdonly(br))
34493 + if (br->br_wbr->wbr_bytes > watermark) {
34504 + AuDbg("b%d\n", err);
34508 +/* ---------------------------------------------------------------------- */
34510 +/* most free space and then round robin */
34511 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34514 + struct au_wbr_mfs *mfs;
34516 + err = au_wbr_create_mfs(dentry, flags);
34518 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34519 + mutex_lock(&mfs->mfs_lock);
34520 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34521 + err = au_wbr_create_rr(dentry, flags);
34522 + mutex_unlock(&mfs->mfs_lock);
34525 + AuDbg("b%d\n", err);
34529 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34533 + au_wbr_create_init_mfs(sb); /* ignore */
34534 + err = au_wbr_create_init_rr(sb);
34539 +/* ---------------------------------------------------------------------- */
34541 +/* top down parent and most free space */
34542 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34545 + unsigned long long b;
34546 + aufs_bindex_t bindex, btop, bbot;
34547 + struct super_block *sb;
34548 + struct dentry *parent, *h_parent;
34549 + struct au_branch *br;
34551 + err = au_wbr_create_tdp(dentry, flags);
34552 + if (unlikely(err < 0))
34554 + parent = dget_parent(dentry);
34555 + btop = au_dbtop(parent);
34556 + bbot = au_dbtaildir(parent);
34557 + if (btop == bbot)
34558 + goto out_parent; /* success */
34560 + e2 = au_wbr_create_mfs(dentry, flags);
34562 + goto out_parent; /* success */
34564 + /* when the available size is equal, select upper one */
34565 + sb = dentry->d_sb;
34566 + br = au_sbr(sb, err);
34567 + b = br->br_wbr->wbr_bytes;
34568 + AuDbg("b%d, %llu\n", err, b);
34570 + for (bindex = btop; bindex <= bbot; bindex++) {
34571 + h_parent = au_h_dptr(parent, bindex);
34572 + if (!h_parent || d_is_negative(h_parent))
34575 + br = au_sbr(sb, bindex);
34576 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34577 + b = br->br_wbr->wbr_bytes;
34579 + AuDbg("b%d, %llu\n", err, b);
34584 + err = au_wbr_nonopq(dentry, err);
34589 + AuDbg("b%d\n", err);
34593 +/* ---------------------------------------------------------------------- */
34596 + * - top down parent
34597 + * - most free space with parent
34598 + * - most free space round-robin regardless parent
34600 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34603 + unsigned long long watermark;
34604 + struct super_block *sb;
34605 + struct au_branch *br;
34606 + struct au_wbr_mfs *mfs;
34608 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34609 + if (unlikely(err < 0))
34612 + sb = dentry->d_sb;
34613 + br = au_sbr(sb, err);
34614 + mfs = &au_sbi(sb)->si_wbr_mfs;
34615 + mutex_lock(&mfs->mfs_lock);
34616 + watermark = mfs->mfsrr_watermark;
34617 + mutex_unlock(&mfs->mfs_lock);
34618 + if (br->br_wbr->wbr_bytes < watermark)
34619 + /* regardless the parent dir */
34620 + err = au_wbr_create_mfsrr(dentry, flags);
34623 + AuDbg("b%d\n", err);
34627 +/* ---------------------------------------------------------------------- */
34629 +/* policies for copyup */
34631 +/* top down parent */
34632 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34634 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34637 +/* bottom up parent */
34638 +static int au_wbr_copyup_bup(struct dentry *dentry)
34641 + aufs_bindex_t bindex, btop;
34642 + struct dentry *parent, *h_parent;
34643 + struct super_block *sb;
34646 + sb = dentry->d_sb;
34647 + parent = dget_parent(dentry);
34648 + btop = au_dbtop(parent);
34649 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34650 + h_parent = au_h_dptr(parent, bindex);
34651 + if (!h_parent || d_is_negative(h_parent))
34654 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34661 + /* bottom up here */
34662 + if (unlikely(err < 0))
34663 + err = au_wbr_bu(sb, btop - 1);
34665 + AuDbg("b%d\n", err);
34670 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34674 + err = au_wbr_bu(dentry->d_sb, btop);
34675 + AuDbg("b%d\n", err);
34677 + err = au_wbr_nonopq(dentry, err);
34679 + AuDbg("b%d\n", err);
34683 +static int au_wbr_copyup_bu(struct dentry *dentry)
34686 + aufs_bindex_t btop;
34688 + btop = au_dbtop(dentry);
34689 + err = au_wbr_do_copyup_bu(dentry, btop);
34693 +/* ---------------------------------------------------------------------- */
34695 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34696 + [AuWbrCopyup_TDP] = {
34697 + .copyup = au_wbr_copyup_tdp
34699 + [AuWbrCopyup_BUP] = {
34700 + .copyup = au_wbr_copyup_bup
34702 + [AuWbrCopyup_BU] = {
34703 + .copyup = au_wbr_copyup_bu
34707 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34708 + [AuWbrCreate_TDP] = {
34709 + .create = au_wbr_create_tdp
34711 + [AuWbrCreate_RR] = {
34712 + .create = au_wbr_create_rr,
34713 + .init = au_wbr_create_init_rr
34715 + [AuWbrCreate_MFS] = {
34716 + .create = au_wbr_create_mfs,
34717 + .init = au_wbr_create_init_mfs,
34718 + .fin = au_wbr_create_fin_mfs
34720 + [AuWbrCreate_MFSV] = {
34721 + .create = au_wbr_create_mfs,
34722 + .init = au_wbr_create_init_mfs,
34723 + .fin = au_wbr_create_fin_mfs
34725 + [AuWbrCreate_MFSRR] = {
34726 + .create = au_wbr_create_mfsrr,
34727 + .init = au_wbr_create_init_mfsrr,
34728 + .fin = au_wbr_create_fin_mfs
34730 + [AuWbrCreate_MFSRRV] = {
34731 + .create = au_wbr_create_mfsrr,
34732 + .init = au_wbr_create_init_mfsrr,
34733 + .fin = au_wbr_create_fin_mfs
34735 + [AuWbrCreate_TDMFS] = {
34736 + .create = au_wbr_create_tdmfs,
34737 + .init = au_wbr_create_init_mfs,
34738 + .fin = au_wbr_create_fin_mfs
34740 + [AuWbrCreate_TDMFSV] = {
34741 + .create = au_wbr_create_tdmfs,
34742 + .init = au_wbr_create_init_mfs,
34743 + .fin = au_wbr_create_fin_mfs
34745 + [AuWbrCreate_PMFS] = {
34746 + .create = au_wbr_create_pmfs,
34747 + .init = au_wbr_create_init_mfs,
34748 + .fin = au_wbr_create_fin_mfs
34750 + [AuWbrCreate_PMFSV] = {
34751 + .create = au_wbr_create_pmfs,
34752 + .init = au_wbr_create_init_mfs,
34753 + .fin = au_wbr_create_fin_mfs
34755 + [AuWbrCreate_PMFSRR] = {
34756 + .create = au_wbr_create_pmfsrr,
34757 + .init = au_wbr_create_init_mfsrr,
34758 + .fin = au_wbr_create_fin_mfs
34760 + [AuWbrCreate_PMFSRRV] = {
34761 + .create = au_wbr_create_pmfsrr,
34762 + .init = au_wbr_create_init_mfsrr,
34763 + .fin = au_wbr_create_fin_mfs
34766 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34767 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34768 +++ linux/fs/aufs/whout.c 2021-09-06 21:02:45.280158943 +0200
34770 +// SPDX-License-Identifier: GPL-2.0
34772 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34774 + * This program, aufs is free software; you can redistribute it and/or modify
34775 + * it under the terms of the GNU General Public License as published by
34776 + * the Free Software Foundation; either version 2 of the License, or
34777 + * (at your option) any later version.
34779 + * This program is distributed in the hope that it will be useful,
34780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34782 + * GNU General Public License for more details.
34784 + * You should have received a copy of the GNU General Public License
34785 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34789 + * whiteout for logical deletion and opaque directory
34794 +#define WH_MASK 0444
34797 + * If a directory contains this file, then it is opaque. We start with the
34798 + * .wh. flag so that it is blocked by lookup.
34800 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34801 + sizeof(AUFS_WH_DIROPQ) - 1);
34804 + * generate whiteout name, which is NOT terminated by NULL.
34805 + * @name: original d_name.name
34806 + * @len: original d_name.len
34807 + * @wh: whiteout qstr
34808 + * returns zero when succeeds, otherwise error.
34809 + * succeeded value as wh->name should be freed by kfree().
34811 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34815 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34816 + return -ENAMETOOLONG;
34818 + wh->len = name->len + AUFS_WH_PFX_LEN;
34819 + p = kmalloc(wh->len, GFP_NOFS);
34822 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34823 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34830 +/* ---------------------------------------------------------------------- */
34833 + * test if the @wh_name exists under @h_parent.
34834 + * @try_sio specifies the necessary of super-io.
34836 +int au_wh_test(struct user_namespace *h_userns, struct dentry *h_parent,
34837 + struct qstr *wh_name, int try_sio)
34840 + struct dentry *wh_dentry;
34843 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34845 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_parent);
34846 + err = PTR_ERR(wh_dentry);
34847 + if (IS_ERR(wh_dentry)) {
34848 + if (err == -ENAMETOOLONG)
34854 + if (d_is_negative(wh_dentry))
34855 + goto out_wh; /* success */
34858 + if (d_is_reg(wh_dentry))
34859 + goto out_wh; /* success */
34862 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34863 + wh_dentry, d_inode(wh_dentry)->i_mode);
34872 + * test if the @h_dentry sets opaque or not.
34874 +int au_diropq_test(struct user_namespace *h_userns, struct dentry *h_dentry)
34877 + struct inode *h_dir;
34879 + h_dir = d_inode(h_dentry);
34880 + err = au_wh_test(h_userns, h_dentry, &diropq_name,
34881 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
34886 + * returns a negative dentry whose name is unique and temporary.
34888 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34889 + struct qstr *prefix)
34891 + struct dentry *dentry;
34893 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34895 + /* strict atomic_t is unnecessary here */
34896 + static unsigned short cnt;
34898 + struct user_namespace *h_userns;
34900 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34903 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34904 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34905 + dentry = ERR_PTR(-ENAMETOOLONG);
34906 + if (unlikely(qs.len > NAME_MAX))
34908 + dentry = ERR_PTR(-ENOMEM);
34909 + name = kmalloc(qs.len + 1, GFP_NOFS);
34910 + if (unlikely(!name))
34914 + /* doubly whiteout-ed */
34915 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34916 + p = name + AUFS_WH_PFX_LEN * 2;
34917 + memcpy(p, prefix->name, prefix->len);
34918 + p += prefix->len;
34920 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34922 + h_userns = au_br_userns(br);
34924 + for (i = 0; i < 3; i++) {
34925 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34926 + dentry = au_sio_lkup_one(h_userns, &qs, h_parent);
34927 + if (IS_ERR(dentry) || d_is_negative(dentry))
34931 + /* pr_warn("could not get random name\n"); */
34932 + dentry = ERR_PTR(-EEXIST);
34933 + AuDbg("%.*s\n", AuLNPair(&qs));
34937 + if (name != defname)
34938 + au_kfree_try_rcu(name);
34940 + AuTraceErrPtr(dentry);
34945 + * rename the @h_dentry on @br to the whiteouted temporary name.
34947 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34950 + struct path h_path = {
34951 + .mnt = au_br_mnt(br)
34953 + struct inode *h_dir, *delegated;
34954 + struct dentry *h_parent;
34956 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34957 + h_dir = d_inode(h_parent);
34958 + IMustLock(h_dir);
34960 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34961 + err = PTR_ERR(h_path.dentry);
34962 + if (IS_ERR(h_path.dentry))
34965 + /* under the same dir, no need to lock_rename() */
34966 + delegated = NULL;
34967 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34970 + if (unlikely(err == -EWOULDBLOCK)) {
34971 + pr_warn("cannot retry for NFSv4 delegation"
34972 + " for an internal rename\n");
34975 + dput(h_path.dentry);
34982 +/* ---------------------------------------------------------------------- */
34984 + * functions for removing a whiteout
34987 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34990 + struct inode *delegated;
34993 + * forces superio when the dir has a sticky bit.
34994 + * this may be a violation of unix fs semantics.
34996 + force = (h_dir->i_mode & S_ISVTX)
34997 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34998 + delegated = NULL;
34999 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35000 + if (unlikely(err == -EWOULDBLOCK)) {
35001 + pr_warn("cannot retry for NFSv4 delegation"
35002 + " for an internal unlink\n");
35008 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35009 + struct dentry *dentry)
35013 + err = do_unlink_wh(h_dir, h_path);
35014 + if (!err && dentry)
35015 + au_set_dbwh(dentry, -1);
35020 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
35021 + struct au_branch *br)
35024 + struct path h_path = {
35025 + .mnt = au_br_mnt(br)
35029 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
35030 + if (IS_ERR(h_path.dentry))
35031 + err = PTR_ERR(h_path.dentry);
35033 + if (d_is_reg(h_path.dentry))
35034 + err = do_unlink_wh(d_inode(h_parent), &h_path);
35035 + dput(h_path.dentry);
35041 +/* ---------------------------------------------------------------------- */
35043 + * initialize/clean whiteout for a branch
35046 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35050 + struct inode *delegated;
35052 + if (d_is_negative(whpath->dentry))
35056 + err = vfsub_rmdir(h_dir, whpath);
35058 + delegated = NULL;
35059 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35060 + if (unlikely(err == -EWOULDBLOCK)) {
35061 + pr_warn("cannot retry for NFSv4 delegation"
35062 + " for an internal unlink\n");
35066 + if (unlikely(err))
35067 + pr_warn("failed removing %pd (%d), ignored.\n",
35068 + whpath->dentry, err);
35071 +static int test_linkable(struct dentry *h_root)
35073 + struct inode *h_dir = d_inode(h_root);
35075 + if (h_dir->i_op->link)
35078 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35079 + h_root, au_sbtype(h_root->d_sb));
35080 + return -ENOSYS; /* the branch doesn't have its ->link() */
35083 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35084 +static int au_whdir(struct inode *h_dir, struct path *path)
35089 + if (d_is_negative(path->dentry)) {
35092 + if (au_test_nfs(path->dentry->d_sb))
35094 + err = vfsub_mkdir(h_dir, path, mode);
35095 + } else if (d_is_dir(path->dentry))
35098 + pr_err("unknown %pd exists\n", path->dentry);
35103 +struct au_wh_base {
35104 + const struct qstr *name;
35105 + struct dentry *dentry;
35108 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35109 + struct path *h_path)
35111 + h_path->dentry = base[AuBrWh_BASE].dentry;
35112 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35113 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35114 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35115 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35116 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35120 + * returns tri-state,
35121 + * minus: error, caller should print the message
35123 + * plus: error, caller should NOT print the message
35125 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35126 + int do_plink, struct au_wh_base base[],
35127 + struct path *h_path)
35130 + struct inode *h_dir;
35132 + h_dir = d_inode(h_root);
35133 + h_path->dentry = base[AuBrWh_BASE].dentry;
35134 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35135 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35137 + err = test_linkable(h_root);
35138 + if (unlikely(err)) {
35143 + err = au_whdir(h_dir, h_path);
35144 + if (unlikely(err))
35146 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35148 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35149 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35150 + err = au_whdir(h_dir, h_path);
35151 + if (unlikely(err))
35153 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35160 + * for the moment, aufs supports the branch filesystem which does not support
35161 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35162 + * copyup failed. finally, such filesystem will not be used as the writable
35165 + * returns tri-state, see above.
35167 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35168 + int do_plink, struct au_wh_base base[],
35169 + struct path *h_path)
35172 + struct inode *h_dir;
35174 + WbrWhMustWriteLock(wbr);
35176 + err = test_linkable(h_root);
35177 + if (unlikely(err)) {
35183 + * todo: should this create be done in /sbin/mount.aufs helper?
35186 + h_dir = d_inode(h_root);
35187 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35188 + h_path->dentry = base[AuBrWh_BASE].dentry;
35189 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35190 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35193 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35194 + if (unlikely(err))
35197 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35199 + err = au_whdir(h_dir, h_path);
35200 + if (unlikely(err))
35202 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35204 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35205 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35207 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35208 + err = au_whdir(h_dir, h_path);
35209 + if (unlikely(err))
35211 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35218 + * initialize the whiteout base file/dir for @br.
35220 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35223 + const unsigned char do_plink
35224 + = !!au_opt_test(au_mntflags(sb), PLINK);
35225 + struct inode *h_dir;
35226 + struct path path = br->br_path;
35227 + struct dentry *h_root = path.dentry;
35228 + struct au_wbr *wbr = br->br_wbr;
35229 + static const struct qstr base_name[] = {
35230 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35231 + sizeof(AUFS_BASE_NAME) - 1),
35232 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35233 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35234 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35235 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35237 + struct au_wh_base base[] = {
35238 + [AuBrWh_BASE] = {
35239 + .name = base_name + AuBrWh_BASE,
35242 + [AuBrWh_PLINK] = {
35243 + .name = base_name + AuBrWh_PLINK,
35246 + [AuBrWh_ORPH] = {
35247 + .name = base_name + AuBrWh_ORPH,
35253 + WbrWhMustWriteLock(wbr);
35255 + for (i = 0; i < AuBrWh_Last; i++) {
35256 + /* doubly whiteouted */
35257 + struct dentry *d;
35259 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35260 + err = PTR_ERR(d);
35264 + base[i].dentry = d;
35266 + && wbr->wbr_wh[i]
35267 + && wbr->wbr_wh[i] != base[i].dentry);
35271 + for (i = 0; i < AuBrWh_Last; i++) {
35272 + dput(wbr->wbr_wh[i]);
35273 + wbr->wbr_wh[i] = NULL;
35277 + if (!au_br_writable(br->br_perm)) {
35278 + h_dir = d_inode(h_root);
35279 + au_wh_init_ro(h_dir, base, &path);
35280 + } else if (!au_br_wh_linkable(br->br_perm)) {
35281 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35287 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35293 + goto out; /* success */
35296 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35297 + err, h_root, au_sbtype(h_root->d_sb));
35299 + for (i = 0; i < AuBrWh_Last; i++)
35300 + dput(base[i].dentry);
35304 +/* ---------------------------------------------------------------------- */
35306 + * whiteouts are all hard-linked usually.
35307 + * when its link count reaches a ceiling, we create a new whiteout base
35308 + * asynchronously.
35311 +struct reinit_br_wh {
35312 + struct super_block *sb;
35313 + struct au_branch *br;
35316 +static void reinit_br_wh(void *arg)
35319 + aufs_bindex_t bindex;
35320 + struct path h_path;
35321 + struct reinit_br_wh *a = arg;
35322 + struct au_wbr *wbr;
35323 + struct inode *dir, *delegated;
35324 + struct dentry *h_root;
35325 + struct au_hinode *hdir;
35328 + wbr = a->br->br_wbr;
35329 + /* big aufs lock */
35330 + si_noflush_write_lock(a->sb);
35331 + if (!au_br_writable(a->br->br_perm))
35333 + bindex = au_br_index(a->sb, a->br->br_id);
35334 + if (unlikely(bindex < 0))
35337 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35338 + dir = d_inode(a->sb->s_root);
35339 + hdir = au_hi(dir, bindex);
35340 + h_root = au_h_dptr(a->sb->s_root, bindex);
35341 + AuDebugOn(h_root != au_br_dentry(a->br));
35343 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35344 + wbr_wh_write_lock(wbr);
35345 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35348 + h_path.dentry = wbr->wbr_whbase;
35349 + h_path.mnt = au_br_mnt(a->br);
35350 + delegated = NULL;
35351 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35353 + if (unlikely(err == -EWOULDBLOCK)) {
35354 + pr_warn("cannot retry for NFSv4 delegation"
35355 + " for an internal unlink\n");
35359 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35362 + dput(wbr->wbr_whbase);
35363 + wbr->wbr_whbase = NULL;
35365 + err = au_wh_init(a->br, a->sb);
35366 + wbr_wh_write_unlock(wbr);
35367 + au_hn_inode_unlock(hdir);
35368 + di_read_unlock(a->sb->s_root, AuLock_IR);
35370 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35374 + atomic_dec(&wbr->wbr_wh_running);
35375 + au_lcnt_dec(&a->br->br_count);
35376 + si_write_unlock(a->sb);
35377 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35379 + if (unlikely(err))
35380 + AuIOErr("err %d\n", err);
35383 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35385 + int do_dec, wkq_err;
35386 + struct reinit_br_wh *arg;
35389 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35392 + /* ignore ENOMEM */
35393 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35396 + * dec(wh_running), kfree(arg) and dec(br_count)
35397 + * in reinit function
35401 + au_lcnt_inc(&br->br_count);
35402 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35403 + if (unlikely(wkq_err)) {
35404 + atomic_dec(&br->br_wbr->wbr_wh_running);
35405 + au_lcnt_dec(&br->br_count);
35406 + au_kfree_rcu(arg);
35413 + atomic_dec(&br->br_wbr->wbr_wh_running);
35416 +/* ---------------------------------------------------------------------- */
35419 + * create the whiteout @wh.
35421 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35422 + struct dentry *wh)
35425 + struct path h_path = {
35428 + struct au_branch *br;
35429 + struct au_wbr *wbr;
35430 + struct dentry *h_parent;
35431 + struct inode *h_dir, *delegated;
35433 + h_parent = wh->d_parent; /* dir inode is locked */
35434 + h_dir = d_inode(h_parent);
35435 + IMustLock(h_dir);
35437 + br = au_sbr(sb, bindex);
35438 + h_path.mnt = au_br_mnt(br);
35439 + wbr = br->br_wbr;
35440 + wbr_wh_read_lock(wbr);
35441 + if (wbr->wbr_whbase) {
35442 + delegated = NULL;
35443 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35444 + if (unlikely(err == -EWOULDBLOCK)) {
35445 + pr_warn("cannot retry for NFSv4 delegation"
35446 + " for an internal link\n");
35449 + if (!err || err != -EMLINK)
35452 + /* link count full. re-initialize br_whbase. */
35453 + kick_reinit_br_wh(sb, br);
35456 + /* return this error in this context */
35457 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35459 + au_fhsm_wrote(sb, bindex, /*force*/0);
35462 + wbr_wh_read_unlock(wbr);
35466 +/* ---------------------------------------------------------------------- */
35469 + * create or remove the diropq.
35471 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35472 + unsigned int flags)
35474 + struct dentry *opq_dentry, *h_dentry;
35475 + struct super_block *sb;
35476 + struct au_branch *br;
35479 + sb = dentry->d_sb;
35480 + br = au_sbr(sb, bindex);
35481 + h_dentry = au_h_dptr(dentry, bindex);
35482 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35483 + if (IS_ERR(opq_dentry))
35486 + if (au_ftest_diropq(flags, CREATE)) {
35487 + err = link_or_create_wh(sb, bindex, opq_dentry);
35489 + au_set_dbdiropq(dentry, bindex);
35490 + goto out; /* success */
35493 + struct path tmp = {
35494 + .dentry = opq_dentry,
35495 + .mnt = au_br_mnt(br)
35497 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35499 + au_set_dbdiropq(dentry, -1);
35501 + dput(opq_dentry);
35502 + opq_dentry = ERR_PTR(err);
35505 + return opq_dentry;
35508 +struct do_diropq_args {
35509 + struct dentry **errp;
35510 + struct dentry *dentry;
35511 + aufs_bindex_t bindex;
35512 + unsigned int flags;
35515 +static void call_do_diropq(void *args)
35517 + struct do_diropq_args *a = args;
35518 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35521 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35522 + unsigned int flags)
35524 + struct dentry *diropq, *h_dentry;
35525 + struct user_namespace *h_userns;
35527 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35528 + h_dentry = au_h_dptr(dentry, bindex);
35529 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35530 + MAY_EXEC | MAY_WRITE))
35531 + diropq = do_diropq(dentry, bindex, flags);
35534 + struct do_diropq_args args = {
35536 + .dentry = dentry,
35537 + .bindex = bindex,
35541 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35542 + if (unlikely(wkq_err))
35543 + diropq = ERR_PTR(wkq_err);
35549 +/* ---------------------------------------------------------------------- */
35552 + * lookup whiteout dentry.
35553 + * @h_parent: lower parent dentry which must exist and be locked
35554 + * @base_name: name of dentry which will be whiteouted
35555 + * returns dentry for whiteout.
35557 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35558 + struct au_branch *br)
35561 + struct qstr wh_name;
35562 + struct dentry *wh_dentry;
35564 + err = au_wh_name_alloc(&wh_name, base_name);
35565 + wh_dentry = ERR_PTR(err);
35567 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35568 + au_kfree_try_rcu(wh_name.name);
35570 + return wh_dentry;
35574 + * link/create a whiteout for @dentry on @bindex.
35576 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35577 + struct dentry *h_parent)
35579 + struct dentry *wh_dentry;
35580 + struct super_block *sb;
35583 + sb = dentry->d_sb;
35584 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35585 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35586 + err = link_or_create_wh(sb, bindex, wh_dentry);
35588 + au_set_dbwh(dentry, bindex);
35589 + au_fhsm_wrote(sb, bindex, /*force*/0);
35592 + wh_dentry = ERR_PTR(err);
35596 + return wh_dentry;
35599 +/* ---------------------------------------------------------------------- */
35601 +/* Delete all whiteouts in this directory on branch bindex. */
35602 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35603 + aufs_bindex_t bindex, struct au_branch *br)
35606 + unsigned long ul, n;
35607 + struct qstr wh_name;
35609 + struct hlist_head *head;
35610 + struct au_vdir_wh *pos;
35611 + struct au_vdir_destr *str;
35614 + p = (void *)__get_free_page(GFP_NOFS);
35615 + wh_name.name = p;
35616 + if (unlikely(!wh_name.name))
35620 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35621 + p += AUFS_WH_PFX_LEN;
35622 + n = whlist->nh_num;
35623 + head = whlist->nh_head;
35624 + for (ul = 0; !err && ul < n; ul++, head++) {
35625 + hlist_for_each_entry(pos, head, wh_hash) {
35626 + if (pos->wh_bindex != bindex)
35629 + str = &pos->wh_str;
35630 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35631 + memcpy(p, str->name, str->len);
35632 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35633 + err = unlink_wh_name(h_dentry, &wh_name, br);
35638 + AuIOErr("whiteout name too long %.*s\n",
35639 + str->len, str->name);
35644 + free_page((unsigned long)wh_name.name);
35650 +struct del_wh_children_args {
35652 + struct dentry *h_dentry;
35653 + struct au_nhash *whlist;
35654 + aufs_bindex_t bindex;
35655 + struct au_branch *br;
35658 +static void call_del_wh_children(void *args)
35660 + struct del_wh_children_args *a = args;
35661 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35664 +/* ---------------------------------------------------------------------- */
35666 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35668 + struct au_whtmp_rmdir *whtmp;
35670 + unsigned int rdhash;
35672 + SiMustAnyLock(sb);
35674 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35675 + if (unlikely(!whtmp)) {
35676 + whtmp = ERR_PTR(-ENOMEM);
35680 + /* no estimation for dir size */
35681 + rdhash = au_sbi(sb)->si_rdhash;
35683 + rdhash = AUFS_RDHASH_DEF;
35684 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35685 + if (unlikely(err)) {
35686 + au_kfree_rcu(whtmp);
35687 + whtmp = ERR_PTR(err);
35694 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35697 + au_lcnt_dec(&whtmp->br->br_count);
35698 + dput(whtmp->wh_dentry);
35699 + iput(whtmp->dir);
35700 + au_nhash_wh_free(&whtmp->whlist);
35701 + au_kfree_rcu(whtmp);
35705 + * rmdir the whiteouted temporary named dir @h_dentry.
35706 + * @whlist: whiteouted children.
35708 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35709 + struct dentry *wh_dentry, struct au_nhash *whlist)
35712 + unsigned int h_nlink;
35713 + struct path h_tmp;
35714 + struct inode *wh_inode, *h_dir;
35715 + struct au_branch *br;
35716 + struct user_namespace *h_userns;
35718 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35719 + IMustLock(h_dir);
35721 + br = au_sbr(dir->i_sb, bindex);
35722 + h_userns = au_br_userns(br);
35723 + wh_inode = d_inode(wh_dentry);
35724 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35727 + * someone else might change some whiteouts while we were sleeping.
35728 + * it means this whlist may have an obsoleted entry.
35730 + if (!au_test_h_perm_sio(h_userns, wh_inode, MAY_EXEC | MAY_WRITE))
35731 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35734 + struct del_wh_children_args args = {
35736 + .h_dentry = wh_dentry,
35737 + .whlist = whlist,
35738 + .bindex = bindex,
35742 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35743 + if (unlikely(wkq_err))
35746 + inode_unlock(wh_inode);
35749 + h_tmp.dentry = wh_dentry;
35750 + h_tmp.mnt = au_br_mnt(br);
35751 + h_nlink = h_dir->i_nlink;
35752 + err = vfsub_rmdir(h_dir, &h_tmp);
35753 + /* some fs doesn't change the parent nlink in some cases */
35754 + h_nlink -= h_dir->i_nlink;
35758 + if (au_ibtop(dir) == bindex) {
35759 + /* todo: dir->i_mutex is necessary */
35760 + au_cpup_attr_timesizes(dir);
35762 + vfsub_drop_nlink(dir);
35764 + return 0; /* success */
35767 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35771 +static void call_rmdir_whtmp(void *args)
35774 + aufs_bindex_t bindex;
35775 + struct au_whtmp_rmdir *a = args;
35776 + struct super_block *sb;
35777 + struct dentry *h_parent;
35778 + struct inode *h_dir;
35779 + struct au_hinode *hdir;
35781 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35782 + /* inode_lock(a->dir); */
35784 + sb = a->dir->i_sb;
35785 + si_read_lock(sb, !AuLock_FLUSH);
35786 + if (!au_br_writable(a->br->br_perm))
35788 + bindex = au_br_index(sb, a->br->br_id);
35789 + if (unlikely(bindex < 0))
35793 + ii_write_lock_parent(a->dir);
35794 + h_parent = dget_parent(a->wh_dentry);
35795 + h_dir = d_inode(h_parent);
35796 + hdir = au_hi(a->dir, bindex);
35797 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35798 + if (unlikely(err))
35800 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35801 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35804 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35805 + au_hn_inode_unlock(hdir);
35806 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35810 + ii_write_unlock(a->dir);
35812 + /* inode_unlock(a->dir); */
35813 + au_whtmp_rmdir_free(a);
35814 + si_read_unlock(sb);
35815 + au_nwt_done(&au_sbi(sb)->si_nowait);
35816 + if (unlikely(err))
35817 + AuIOErr("err %d\n", err);
35820 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35821 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35824 + struct super_block *sb;
35828 + /* all post-process will be done in do_rmdir_whtmp(). */
35830 + args->dir = au_igrab(dir);
35831 + args->br = au_sbr(sb, bindex);
35832 + au_lcnt_inc(&args->br->br_count);
35833 + args->wh_dentry = dget(wh_dentry);
35834 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35835 + if (unlikely(wkq_err)) {
35836 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35837 + au_whtmp_rmdir_free(args);
35840 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35841 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35842 +++ linux/fs/aufs/whout.h 2021-09-06 21:02:45.280158943 +0200
35844 +/* SPDX-License-Identifier: GPL-2.0 */
35846 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35848 + * This program, aufs is free software; you can redistribute it and/or modify
35849 + * it under the terms of the GNU General Public License as published by
35850 + * the Free Software Foundation; either version 2 of the License, or
35851 + * (at your option) any later version.
35853 + * This program is distributed in the hope that it will be useful,
35854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35856 + * GNU General Public License for more details.
35858 + * You should have received a copy of the GNU General Public License
35859 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35863 + * whiteout for logical deletion and opaque directory
35866 +#ifndef __AUFS_WHOUT_H__
35867 +#define __AUFS_WHOUT_H__
35874 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35875 +int au_wh_test(struct user_namespace *h_userns, struct dentry *h_parent,
35876 + struct qstr *wh_name, int try_sio);
35877 +int au_diropq_test(struct user_namespace *h_userns, struct dentry *h_dentry);
35879 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35880 + struct qstr *prefix);
35881 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35882 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35883 + struct dentry *dentry);
35884 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35886 +/* diropq flags */
35887 +#define AuDiropq_CREATE 1
35888 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35889 +#define au_fset_diropq(flags, name) \
35890 + do { (flags) |= AuDiropq_##name; } while (0)
35891 +#define au_fclr_diropq(flags, name) \
35892 + do { (flags) &= ~AuDiropq_##name; } while (0)
35894 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35895 + unsigned int flags);
35896 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35897 + struct au_branch *br);
35898 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35899 + struct dentry *h_parent);
35901 +/* real rmdir for the whiteout-ed dir */
35902 +struct au_whtmp_rmdir {
35903 + struct inode *dir;
35904 + struct au_branch *br;
35905 + struct dentry *wh_dentry;
35906 + struct au_nhash whlist;
35909 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35910 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35911 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35912 + struct dentry *wh_dentry, struct au_nhash *whlist);
35913 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35914 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35916 +/* ---------------------------------------------------------------------- */
35918 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35919 + aufs_bindex_t bindex)
35921 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35924 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35926 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35929 +#endif /* __KERNEL__ */
35930 +#endif /* __AUFS_WHOUT_H__ */
35931 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35932 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35933 +++ linux/fs/aufs/wkq.c 2021-09-06 21:02:45.280158943 +0200
35935 +// SPDX-License-Identifier: GPL-2.0
35937 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35939 + * This program, aufs is free software; you can redistribute it and/or modify
35940 + * it under the terms of the GNU General Public License as published by
35941 + * the Free Software Foundation; either version 2 of the License, or
35942 + * (at your option) any later version.
35944 + * This program is distributed in the hope that it will be useful,
35945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35947 + * GNU General Public License for more details.
35949 + * You should have received a copy of the GNU General Public License
35950 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35954 + * workqueue for asynchronous/super-io operations
35955 + * todo: try new credential scheme
35958 +#include <linux/module.h>
35961 +/* internal workqueue named AUFS_WKQ_NAME */
35963 +static struct workqueue_struct *au_wkq;
35965 +struct au_wkinfo {
35966 + struct work_struct wk;
35967 + struct kobject *kobj;
35969 + unsigned int flags; /* see wkq.h */
35971 + au_wkq_func_t func;
35974 +#ifdef CONFIG_LOCKDEP
35976 + struct held_lock **hlock;
35979 + struct completion *comp;
35982 +/* ---------------------------------------------------------------------- */
35984 + * Aufs passes some operations to the workqueue such as the internal copyup.
35985 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35986 + * job run by workqueue depends upon the locks acquired in the other task.
35987 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35988 + * information too. And the job in the workqueue restores the info in order to
35989 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35990 + * correctly and expectedly.
35993 +#ifndef CONFIG_LOCKDEP
35994 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35995 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35996 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35997 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35998 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36000 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36002 + wkinfo->hlock = NULL;
36003 + wkinfo->dont_check = 0;
36010 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36012 + static DEFINE_SPINLOCK(spin);
36015 + struct lock_class_key *key;
36017 + { .name = "&sbinfo->si_rwsem" },
36018 + { .name = "&finfo->fi_rwsem" },
36019 + { .name = "&dinfo->di_rwsem" },
36020 + { .name = "&iinfo->ii_rwsem" }
36025 + /* lockless read from 'set.' see below */
36026 + if (set == ARRAY_SIZE(a)) {
36027 + for (i = 0; i < ARRAY_SIZE(a); i++)
36028 + if (a[i].key == key)
36033 + spin_lock(&spin);
36035 + for (i = 0; i < ARRAY_SIZE(a); i++)
36036 + if (a[i].key == key) {
36037 + spin_unlock(&spin);
36040 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36042 + if (unlikely(a[i].key == key)) { /* rare but possible */
36043 + spin_unlock(&spin);
36048 + if (strstr(a[i].name, name)) {
36050 + * the order of these three lines is important for the
36051 + * lockless read above.
36054 + spin_unlock(&spin);
36056 + /* AuDbg("%d, %s\n", set, name); */
36060 + spin_unlock(&spin);
36069 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36072 + struct task_struct *curr;
36073 + struct held_lock **hl, *held_locks, *p;
36077 + wkinfo->dont_check = lockdep_recursing(curr);
36078 + if (wkinfo->dont_check)
36080 + n = curr->lockdep_depth;
36085 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36086 + if (unlikely(!wkinfo->hlock))
36090 +#if 0 /* left for debugging */
36091 + if (0 && au_debug_test())
36092 + lockdep_print_held_locks(curr);
36094 + held_locks = curr->held_locks;
36095 + hl = wkinfo->hlock;
36097 + p = held_locks++;
36098 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36107 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36109 + au_kfree_try_rcu(wkinfo->hlock);
36112 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36114 + struct held_lock *p, **hl = wkinfo->hlock;
36117 + if (wkinfo->dont_check)
36121 + while ((p = *hl++)) { /* assignment */
36122 + subclass = lockdep_hlock_class(p)->subclass;
36123 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36125 + rwsem_acquire_read(p->instance, subclass, 0,
36126 + /*p->acquire_ip*/_RET_IP_);
36128 + rwsem_acquire(p->instance, subclass, 0,
36129 + /*p->acquire_ip*/_RET_IP_);
36133 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36135 + struct held_lock *p, **hl = wkinfo->hlock;
36137 + if (wkinfo->dont_check)
36141 + while ((p = *hl++)) /* assignment */
36142 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36146 +static void wkq_func(struct work_struct *wk)
36148 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36150 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36151 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36153 + au_wkq_lockdep_pre(wkinfo);
36154 + wkinfo->func(wkinfo->args);
36155 + au_wkq_lockdep_post(wkinfo);
36156 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36157 + complete(wkinfo->comp);
36159 + kobject_put(wkinfo->kobj);
36160 + module_put(THIS_MODULE); /* todo: ?? */
36161 + au_kfree_rcu(wkinfo);
36166 + * Since struct completion is large, try allocating it dynamically.
36168 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36170 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36172 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36174 + init_completion(*comp);
36175 + wkinfo->comp = *comp;
36181 +static void au_wkq_comp_free(struct completion *comp)
36183 + au_kfree_rcu(comp);
36186 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36188 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36189 + if (au_wkq_test()) {
36190 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36191 + " due to a dead dir by UDBA,"
36192 + " or async xino write?\n");
36193 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36196 + au_dbg_verify_kthread();
36198 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36199 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36200 + queue_work(au_wkq, &wkinfo->wk);
36202 + INIT_WORK(&wkinfo->wk, wkq_func);
36203 + schedule_work(&wkinfo->wk);
36208 + * Be careful. It is easy to make deadlock happen.
36209 + * processA: lock, wkq and wait
36210 + * processB: wkq and wait, lock in wkq
36213 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36216 + AuWkqCompDeclare(comp);
36217 + struct au_wkinfo wkinfo = {
36223 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36224 + if (unlikely(err))
36226 + err = au_wkq_lockdep_alloc(&wkinfo);
36227 + if (unlikely(err))
36230 + au_wkq_run(&wkinfo);
36231 + /* no timeout, no interrupt */
36232 + wait_for_completion(wkinfo.comp);
36234 + au_wkq_lockdep_free(&wkinfo);
36237 + au_wkq_comp_free(comp);
36239 + destroy_work_on_stack(&wkinfo.wk);
36244 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36245 + * problem in a concurrent umounting.
36247 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36248 + unsigned int flags)
36251 + struct au_wkinfo *wkinfo;
36253 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36256 + * wkq_func() must free this wkinfo.
36257 + * it highly depends upon the implementation of workqueue.
36260 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36262 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36263 + wkinfo->flags = flags & ~AuWkq_WAIT;
36264 + wkinfo->func = func;
36265 + wkinfo->args = args;
36266 + wkinfo->comp = NULL;
36267 + au_wkq_lockdep_init(wkinfo);
36268 + kobject_get(wkinfo->kobj);
36269 + __module_get(THIS_MODULE); /* todo: ?? */
36271 + au_wkq_run(wkinfo);
36274 + au_nwt_done(&au_sbi(sb)->si_nowait);
36280 +/* ---------------------------------------------------------------------- */
36282 +void au_nwt_init(struct au_nowait_tasks *nwt)
36284 + atomic_set(&nwt->nw_len, 0);
36285 + /* smp_mb(); */ /* atomic_set */
36286 + init_waitqueue_head(&nwt->nw_wq);
36289 +void au_wkq_fin(void)
36291 + destroy_workqueue(au_wkq);
36294 +int __init au_wkq_init(void)
36299 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36300 + if (IS_ERR(au_wkq))
36301 + err = PTR_ERR(au_wkq);
36302 + else if (!au_wkq)
36307 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36308 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36309 +++ linux/fs/aufs/wkq.h 2021-09-06 21:02:45.280158943 +0200
36311 +/* SPDX-License-Identifier: GPL-2.0 */
36313 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36315 + * This program, aufs is free software; you can redistribute it and/or modify
36316 + * it under the terms of the GNU General Public License as published by
36317 + * the Free Software Foundation; either version 2 of the License, or
36318 + * (at your option) any later version.
36320 + * This program is distributed in the hope that it will be useful,
36321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36323 + * GNU General Public License for more details.
36325 + * You should have received a copy of the GNU General Public License
36326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36330 + * workqueue for asynchronous/super-io operations
36331 + * todo: try new credentials management scheme
36334 +#ifndef __AUFS_WKQ_H__
36335 +#define __AUFS_WKQ_H__
36339 +#include <linux/wait.h>
36341 +struct super_block;
36343 +/* ---------------------------------------------------------------------- */
36346 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36348 +struct au_nowait_tasks {
36350 + wait_queue_head_t nw_wq;
36353 +/* ---------------------------------------------------------------------- */
36355 +typedef void (*au_wkq_func_t)(void *args);
36358 +#define AuWkq_WAIT 1
36359 +#define AuWkq_NEST (1 << 1)
36360 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36361 +#define au_fset_wkq(flags, name) \
36362 + do { (flags) |= AuWkq_##name; } while (0)
36363 +#define au_fclr_wkq(flags, name) \
36364 + do { (flags) &= ~AuWkq_##name; } while (0)
36367 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36368 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36369 + unsigned int flags);
36370 +void au_nwt_init(struct au_nowait_tasks *nwt);
36371 +int __init au_wkq_init(void);
36372 +void au_wkq_fin(void);
36374 +/* ---------------------------------------------------------------------- */
36376 +static inline int au_wkq_test(void)
36378 + return current->flags & PF_WQ_WORKER;
36381 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36383 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36386 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36388 + if (atomic_dec_and_test(&nwt->nw_len))
36389 + wake_up_all(&nwt->nw_wq);
36392 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36394 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36398 +#endif /* __KERNEL__ */
36399 +#endif /* __AUFS_WKQ_H__ */
36400 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36401 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36402 +++ linux/fs/aufs/xattr.c 2021-09-06 21:02:45.280158943 +0200
36404 +// SPDX-License-Identifier: GPL-2.0
36406 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36408 + * This program, aufs is free software; you can redistribute it and/or modify
36409 + * it under the terms of the GNU General Public License as published by
36410 + * the Free Software Foundation; either version 2 of the License, or
36411 + * (at your option) any later version.
36413 + * This program is distributed in the hope that it will be useful,
36414 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36415 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36416 + * GNU General Public License for more details.
36418 + * You should have received a copy of the GNU General Public License
36419 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36423 + * handling xattr functions
36426 +#include <linux/fs.h>
36427 +#include <linux/posix_acl_xattr.h>
36428 +#include <linux/xattr.h>
36431 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36433 + if (!ignore_flags)
36441 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36446 +#define cmp(brattr, prefix) do { \
36447 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36448 + XATTR_##prefix##_PREFIX_LEN)) { \
36449 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36455 + cmp(SEC, SECURITY);
36456 + cmp(SYS, SYSTEM);
36457 + cmp(TR, TRUSTED);
36461 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36468 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36470 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36471 + char *name, char **buf, unsigned int ignore_flags,
36472 + unsigned int verbose)
36476 + struct inode *h_idst;
36477 + struct dentry *h_dst_dentry, *h_src_dentry;
36478 + struct user_namespace *h_dst_userns, *h_src_userns;
36480 + h_src_userns = mnt_user_ns(h_src->mnt);
36481 + h_src_dentry = h_src->dentry;
36482 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36485 + if (unlikely(err <= 0)) {
36486 + if (err == -ENODATA
36487 + || (err == -EOPNOTSUPP
36488 + && ((ignore_flags & au_xattr_out_of_list)
36489 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36490 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36492 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36495 + if (err && (verbose || au_debug_test()))
36496 + pr_err("%s, err %d\n", name, err);
36500 + /* unlock it temporary */
36501 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36502 + h_dst_dentry = h_dst->dentry;
36503 + h_idst = d_inode(h_dst_dentry);
36504 + inode_unlock(h_idst);
36505 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36507 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36508 + if (unlikely(err)) {
36509 + if (verbose || au_debug_test())
36510 + pr_err("%s, err %d\n", name, err);
36511 + err = au_xattr_ignore(err, name, ignore_flags);
36518 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36519 + unsigned int verbose)
36521 + int err, unlocked, acl_access, acl_default;
36523 + struct dentry *h_dst_dentry, *h_src_dentry;
36524 + struct inode *h_isrc, *h_idst;
36525 + char *value, *p, *o, *e;
36527 + /* try stopping to update the source inode while we are referencing */
36528 + /* there should not be the parent-child relationship between them */
36529 + h_dst_dentry = h_dst->dentry;
36530 + h_idst = d_inode(h_dst_dentry);
36531 + h_src_dentry = h_src->dentry;
36532 + h_isrc = d_inode(h_src_dentry);
36533 + inode_unlock(h_idst);
36534 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36535 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36538 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36539 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36541 + if (unlikely(err < 0)) {
36543 + if (err == -ENODATA
36544 + || err == -EOPNOTSUPP)
36545 + err = 0; /* ignore */
36554 + p = kmalloc(ssz, GFP_NOFS);
36556 + if (unlikely(!p))
36558 + err = vfs_listxattr(h_src_dentry, p, ssz);
36560 + inode_unlock_shared(h_isrc);
36562 + AuDbg("err %d, ssz %zd\n", err, ssz);
36563 + if (unlikely(err < 0))
36571 + while (!err && p < e) {
36572 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36573 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36574 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36575 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36577 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36579 + p += strlen(p) + 1;
36582 + ignore_flags |= au_xattr_out_of_list;
36583 + if (!err && !acl_access) {
36584 + err = au_do_cpup_xattr(h_dst, h_src,
36585 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36586 + ignore_flags, verbose);
36589 + if (!err && !acl_default) {
36590 + err = au_do_cpup_xattr(h_dst, h_src,
36591 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36592 + ignore_flags, verbose);
36596 + au_kfree_try_rcu(value);
36599 + au_kfree_try_rcu(o);
36602 + inode_unlock_shared(h_isrc);
36607 +/* ---------------------------------------------------------------------- */
36609 +static int au_smack_reentering(struct super_block *sb)
36611 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36613 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36614 + * i_op->getxattr(). ouch.
36616 + return si_pid_test(sb);
36627 +struct au_lgxattr {
36635 + const char *name;
36642 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36643 + struct au_lgxattr *arg)
36647 + struct path h_path;
36648 + struct super_block *sb;
36650 + sb = dentry->d_sb;
36651 + reenter = au_smack_reentering(sb);
36653 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36654 + if (unlikely(err))
36657 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36658 + if (unlikely(err))
36660 + if (unlikely(!h_path.dentry))
36661 + /* illegally overlapped or something */
36662 + goto out_di; /* pretending success */
36664 + /* always topmost entry only */
36665 + switch (arg->type) {
36666 + case AU_XATTR_LIST:
36667 + err = vfs_listxattr(h_path.dentry,
36668 + arg->u.list.list, arg->u.list.size);
36670 + case AU_XATTR_GET:
36671 + AuDebugOn(d_is_negative(h_path.dentry));
36672 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36673 + arg->u.get.name, arg->u.get.value,
36674 + arg->u.get.size);
36680 + di_read_unlock(dentry, AuLock_IR);
36683 + si_read_unlock(sb);
36689 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36691 + struct au_lgxattr arg = {
36692 + .type = AU_XATTR_LIST,
36699 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36702 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36703 + const char *name, void *value, size_t size)
36705 + struct au_lgxattr arg = {
36706 + .type = AU_XATTR_GET,
36714 + return au_lgxattr(dentry, inode, &arg);
36717 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36718 + const char *name, const void *value, size_t size,
36721 + struct au_sxattr arg = {
36722 + .type = AU_XATTR_SET,
36731 + return au_sxattr(dentry, inode, &arg);
36734 +/* ---------------------------------------------------------------------- */
36736 +static int au_xattr_get(const struct xattr_handler *handler,
36737 + struct dentry *dentry, struct inode *inode,
36738 + const char *name, void *buffer, size_t size)
36740 + return au_getxattr(dentry, inode, name, buffer, size);
36743 +static int au_xattr_set(const struct xattr_handler *handler,
36744 + struct user_namespace *userns,
36745 + struct dentry *dentry, struct inode *inode,
36746 + const char *name, const void *value, size_t size,
36749 + return au_setxattr(dentry, inode, name, value, size, flags);
36752 +static const struct xattr_handler au_xattr_handler = {
36755 + .get = au_xattr_get,
36756 + .set = au_xattr_set
36759 +static const struct xattr_handler *au_xattr_handlers[] = {
36760 +#ifdef CONFIG_FS_POSIX_ACL
36761 + &posix_acl_access_xattr_handler,
36762 + &posix_acl_default_xattr_handler,
36764 + &au_xattr_handler, /* must be last */
36768 +void au_xattr_init(struct super_block *sb)
36770 + sb->s_xattr = au_xattr_handlers;
36772 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36773 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36774 +++ linux/fs/aufs/xino.c 2021-09-06 21:02:45.280158943 +0200
36776 +// SPDX-License-Identifier: GPL-2.0
36778 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36780 + * This program, aufs is free software; you can redistribute it and/or modify
36781 + * it under the terms of the GNU General Public License as published by
36782 + * the Free Software Foundation; either version 2 of the License, or
36783 + * (at your option) any later version.
36785 + * This program is distributed in the hope that it will be useful,
36786 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36787 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36788 + * GNU General Public License for more details.
36790 + * You should have received a copy of the GNU General Public License
36791 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36795 + * external inode number translation table and bitmap
36797 + * things to consider
36799 + * + au_xino object
36800 + * + XINO files (xino, xib, xigen)
36801 + * + dynamic debugfs entries (xiN)
36802 + * + static debugfs entries (xib, xigen)
36803 + * + static sysfs entry (xi_path)
36804 + * - several entry points to handle them.
36805 + * + mount(2) without xino option (default)
36806 + * + mount(2) with xino option
36807 + * + mount(2) with noxino option
36809 + * + remount with add/del branches
36810 + * + remount with xino/noxino options
36813 +#include <linux/seq_file.h>
36814 +#include <linux/statfs.h>
36817 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36818 + aufs_bindex_t bbot,
36819 + struct super_block *h_sb)
36821 + /* todo: try binary-search if the branches are many */
36822 + for (; btop <= bbot; btop++)
36823 + if (h_sb == au_sbr_sb(sb, btop))
36829 + * find another branch who is on the same filesystem of the specified
36830 + * branch{@btgt}. search until @bbot.
36832 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36833 + aufs_bindex_t bbot)
36835 + aufs_bindex_t bindex;
36836 + struct super_block *tgt_sb;
36838 + tgt_sb = au_sbr_sb(sb, btgt);
36839 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36841 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36846 +/* ---------------------------------------------------------------------- */
36849 + * stop unnecessary notify events at creating xino files
36852 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36854 + aufs_bindex_t bfound, bindex, bbot;
36855 + struct dentry *parent;
36856 + struct au_branch *br;
36859 + parent = dentry->d_parent; /* safe d_parent access */
36860 + bbot = au_sbbot(sb);
36861 + for (bindex = 0; bindex <= bbot; bindex++) {
36862 + br = au_sbr(sb, bindex);
36863 + if (au_br_dentry(br) == parent) {
36869 + AuDbg("bfound b%d\n", bfound);
36873 +struct au_xino_lock_dir {
36874 + struct au_hinode *hdir;
36875 + struct dentry *parent;
36876 + struct inode *dir;
36879 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36880 + unsigned int lsc)
36882 + struct dentry *parent;
36883 + struct inode *dir;
36885 + parent = dget_parent(dentry);
36886 + dir = d_inode(parent);
36887 + inode_lock_nested(dir, lsc);
36888 +#if 0 /* it should not happen */
36889 + spin_lock(&dentry->d_lock);
36890 + if (unlikely(dentry->d_parent != parent)) {
36891 + spin_unlock(&dentry->d_lock);
36892 + inode_unlock(dir);
36897 + spin_unlock(&dentry->d_lock);
36904 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36905 + struct au_xino_lock_dir *ldir)
36907 + aufs_bindex_t bindex;
36909 + ldir->hdir = NULL;
36910 + bindex = au_xi_root(sb, xipath->dentry);
36911 + if (bindex >= 0) {
36912 + /* rw branch root */
36913 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36914 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36917 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36919 + ldir->dir = d_inode(ldir->parent);
36923 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36926 + au_hn_inode_unlock(ldir->hdir);
36928 + inode_unlock(ldir->dir);
36929 + dput(ldir->parent);
36933 +/* ---------------------------------------------------------------------- */
36936 + * create and set a new xino file
36938 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36941 + struct file *file;
36942 + struct dentry *h_parent, *d;
36943 + struct inode *h_dir, *inode;
36945 + static DEFINE_MUTEX(mtx);
36948 + * at mount-time, and the xino file is the default path,
36949 + * hnotify is disabled so we have no notify events to ignore.
36950 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36953 + mutex_lock(&mtx);
36954 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36955 + /* | __FMODE_NONOTIFY */,
36957 + if (IS_ERR(file)) {
36959 + mutex_unlock(&mtx);
36961 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36965 + /* keep file count */
36967 + d = file->f_path.dentry;
36968 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36970 + mutex_unlock(&mtx);
36971 + /* mnt_want_write() is unnecessary here */
36972 + h_dir = d_inode(h_parent);
36973 + inode = file_inode(file);
36974 + /* no delegation since it is just created */
36975 + if (inode->i_nlink)
36976 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36978 + inode_unlock(h_dir);
36980 + if (unlikely(err)) {
36982 + pr_err("unlink %s(%d)\n", fpath, err);
36987 + if (unlikely(sb == d->d_sb)) {
36989 + pr_err("%s must be outside\n", fpath);
36992 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36994 + pr_err("xino doesn't support %s(%s)\n",
36995 + fpath, au_sbtype(d->d_sb));
36998 + return file; /* success */
37002 + file = ERR_PTR(err);
37007 + * create a new xinofile at the same place/path as @base.
37009 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37010 + struct file *copy_src)
37012 + struct file *file;
37013 + struct dentry *dentry, *parent;
37014 + struct inode *dir, *delegated;
37015 + struct qstr *name;
37016 + struct path path;
37017 + int err, do_unlock;
37018 + struct au_xino_lock_dir ldir;
37021 + au_xino_lock_dir(sb, base, &ldir);
37022 + dentry = base->dentry;
37023 + parent = dentry->d_parent; /* dir inode is locked */
37024 + dir = d_inode(parent);
37027 + name = &dentry->d_name;
37028 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
37029 + if (IS_ERR(path.dentry)) {
37030 + file = (void *)path.dentry;
37031 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37035 + /* no need to mnt_want_write() since we call dentry_open() later */
37036 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37037 + if (unlikely(err)) {
37038 + file = ERR_PTR(err);
37039 + pr_err("%pd create err %d\n", dentry, err);
37043 + path.mnt = base->mnt;
37044 + file = vfsub_dentry_open(&path,
37045 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37046 + /* | __FMODE_NONOTIFY */);
37047 + if (IS_ERR(file)) {
37048 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37052 + delegated = NULL;
37053 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37054 + au_xino_unlock_dir(&ldir);
37056 + if (unlikely(err == -EWOULDBLOCK)) {
37057 + pr_warn("cannot retry for NFSv4 delegation"
37058 + " for an internal unlink\n");
37061 + if (unlikely(err)) {
37062 + pr_err("%pd unlink err %d\n", dentry, err);
37067 + /* no one can touch copy_src xino */
37068 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37069 + if (unlikely(err)) {
37070 + pr_err("%pd copy err %d\n", dentry, err);
37074 + goto out_dput; /* success */
37078 + file = ERR_PTR(err);
37080 + dput(path.dentry);
37083 + au_xino_unlock_dir(&ldir);
37087 +struct file *au_xino_file1(struct au_xino *xi)
37089 + struct file *file;
37090 + unsigned int u, nfile;
37093 + nfile = xi->xi_nfile;
37094 + for (u = 0; u < nfile; u++) {
37095 + file = xi->xi_file[u];
37103 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37114 + if (idx < xi->xi_nfile) {
37115 + f = xi->xi_file[idx];
37119 + p = au_kzrealloc(xi->xi_file,
37120 + sizeof(*xi->xi_file) * xi->xi_nfile,
37121 + sizeof(*xi->xi_file) * (idx + 1),
37122 + GFP_NOFS, /*may_shrink*/0);
37124 + MtxMustLock(&xi->xi_mtx);
37126 + xi->xi_nfile = idx + 1;
37134 + xi->xi_file[idx] = file;
37141 + * if @xinew->xi is not set, then create new xigen file.
37143 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37145 + struct file *file;
37148 + SiMustAnyLock(sb);
37150 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37151 + if (IS_ERR(file)) {
37152 + err = PTR_ERR(file);
37153 + pr_err("%s[%d], err %d\n",
37154 + xinew->xi ? "xino" : "xigen",
37155 + xinew->idx, err);
37160 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37163 + /* todo: make xigen file an array */
37164 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37167 + if (unlikely(err))
37168 + file = ERR_PTR(err);
37174 +/* ---------------------------------------------------------------------- */
37177 + * truncate xino files
37179 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37180 + int idx, struct kstatfs *st)
37184 + struct file *file, *new_xino;
37185 + struct au_xi_new xinew = {
37190 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37191 + file = au_xino_file(xinew.xi, idx);
37195 + xinew.base = &file->f_path;
37196 + err = vfs_statfs(xinew.base, st);
37197 + if (unlikely(err)) {
37198 + AuErr1("statfs err %d, ignored\n", err);
37203 + blocks = file_inode(file)->i_blocks;
37204 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37205 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37207 + xinew.copy_src = file;
37208 + new_xino = au_xi_new(sb, &xinew);
37209 + if (IS_ERR(new_xino)) {
37210 + err = PTR_ERR(new_xino);
37211 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37215 + err = vfs_statfs(&new_xino->f_path, st);
37217 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37218 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37219 + st->f_bfree, st->f_blocks);
37221 + AuErr1("statfs err %d, ignored\n", err);
37229 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37232 + unsigned long jiffy;
37233 + aufs_bindex_t bbot;
37234 + struct kstatfs *st;
37235 + struct au_branch *br;
37236 + struct au_xino *xi;
37239 + st = kmalloc(sizeof(*st), GFP_NOFS);
37240 + if (unlikely(!st))
37244 + bbot = au_sbbot(sb);
37245 + if (unlikely(bindex < 0 || bbot < bindex))
37250 + br = au_sbr(sb, bindex);
37251 + xi = br->br_xino;
37252 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37253 + err = au_xino_do_trunc(sb, bindex, i, st);
37255 + au_sbi(sb)->si_xino_jiffy = jiffy;
37258 + au_kfree_rcu(st);
37263 +struct xino_do_trunc_args {
37264 + struct super_block *sb;
37265 + struct au_branch *br;
37269 +static void xino_do_trunc(void *_args)
37271 + struct xino_do_trunc_args *args = _args;
37272 + struct super_block *sb;
37273 + struct au_branch *br;
37274 + struct inode *dir;
37276 + aufs_bindex_t bindex;
37280 + dir = d_inode(sb->s_root);
37284 + si_noflush_write_lock(sb);
37285 + ii_read_lock_parent(dir);
37286 + bindex = au_br_index(sb, br->br_id);
37287 + err = au_xino_trunc(sb, bindex, idx);
37288 + ii_read_unlock(dir);
37289 + if (unlikely(err))
37290 + pr_warn("err b%d, (%d)\n", bindex, err);
37291 + atomic_dec(&br->br_xino->xi_truncating);
37292 + au_lcnt_dec(&br->br_count);
37293 + si_write_unlock(sb);
37294 + au_nwt_done(&au_sbi(sb)->si_nowait);
37295 + au_kfree_rcu(args);
37299 + * returns the index in the xi_file array whose corresponding file is necessary
37300 + * to truncate, or -1 which means no need to truncate.
37302 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37306 + struct kstatfs st;
37307 + struct au_sbinfo *sbinfo;
37308 + struct au_xino *xi;
37309 + struct file *file;
37311 + /* todo: si_xino_expire and the ratio should be customizable */
37312 + sbinfo = au_sbi(sb);
37313 + if (time_before(jiffies,
37314 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37317 + /* truncation border */
37318 + xi = br->br_xino;
37319 + for (u = 0; u < xi->xi_nfile; u++) {
37320 + file = au_xino_file(xi, u);
37324 + err = vfs_statfs(&file->f_path, &st);
37325 + if (unlikely(err)) {
37326 + AuErr1("statfs err %d, ignored\n", err);
37329 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37330 + >= AUFS_XINO_DEF_TRUNC)
37337 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37340 + struct xino_do_trunc_args *args;
37343 + idx = xino_trunc_test(sb, br);
37347 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37350 + /* lock and kfree() will be called in trunc_xino() */
37351 + args = kmalloc(sizeof(*args), GFP_NOFS);
37352 + if (unlikely(!args)) {
37353 + AuErr1("no memory\n");
37357 + au_lcnt_inc(&br->br_count);
37361 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37363 + return; /* success */
37365 + pr_err("wkq %d\n", wkq_err);
37366 + au_lcnt_dec(&br->br_count);
37367 + au_kfree_rcu(args);
37370 + atomic_dec(&br->br_xino->xi_truncating);
37373 +/* ---------------------------------------------------------------------- */
37375 +struct au_xi_calc {
37380 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37381 + struct au_xi_calc *calc)
37385 + maxent = au_xi_maxent(sb);
37386 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37387 + calc->pos *= sizeof(ino_t);
37390 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37391 + struct au_xi_calc *calc)
37394 + struct file *file;
37395 + struct au_xino *xi = br->br_xino;
37396 + struct au_xi_new xinew = {
37400 + SiMustAnyLock(sb);
37406 + mutex_lock(&xi->xi_mtx);
37407 + file = au_xino_file(xi, calc->idx);
37411 + file = au_xino_file(xi, /*idx*/-1);
37412 + AuDebugOn(!file);
37413 + xinew.idx = calc->idx;
37414 + xinew.base = &file->f_path;
37415 + /* xinew.copy_src = NULL; */
37416 + file = au_xi_new(sb, &xinew);
37417 + if (IS_ERR(file))
37418 + err = PTR_ERR(file);
37421 + mutex_unlock(&xi->xi_mtx);
37426 +struct au_xino_do_new_async_args {
37427 + struct super_block *sb;
37428 + struct au_branch *br;
37429 + struct au_xi_calc calc;
37433 +struct au_xi_writing {
37434 + struct hlist_bl_node node;
37435 + ino_t h_ino, ino;
37438 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37441 +static void au_xino_call_do_new_async(void *args)
37443 + struct au_xino_do_new_async_args *a = args;
37444 + struct au_branch *br;
37445 + struct super_block *sb;
37446 + struct au_sbinfo *sbi;
37447 + struct inode *root;
37448 + struct file *file;
37449 + struct au_xi_writing *del, *p;
37450 + struct hlist_bl_head *hbl;
37451 + struct hlist_bl_node *pos;
37456 + sbi = au_sbi(sb);
37457 + si_noflush_read_lock(sb);
37458 + root = d_inode(sb->s_root);
37459 + ii_read_lock_child(root);
37460 + err = au_xino_do_new_async(sb, br, &a->calc);
37461 + if (unlikely(err)) {
37462 + AuIOErr("err %d\n", err);
37466 + file = au_xino_file(br->br_xino, a->calc.idx);
37467 + AuDebugOn(!file);
37468 + err = au_xino_do_write(file, &a->calc, a->ino);
37469 + if (unlikely(err)) {
37470 + AuIOErr("err %d\n", err);
37475 + hbl = &br->br_xino->xi_writing;
37476 + hlist_bl_lock(hbl);
37477 + au_hbl_for_each(pos, hbl) {
37478 + p = container_of(pos, struct au_xi_writing, node);
37479 + if (p->ino == a->ino) {
37481 + hlist_bl_del(&p->node);
37485 + hlist_bl_unlock(hbl);
37486 + au_kfree_rcu(del);
37489 + au_lcnt_dec(&br->br_count);
37490 + ii_read_unlock(root);
37491 + si_read_unlock(sb);
37492 + au_nwt_done(&sbi->si_nowait);
37497 + * create a new xino file asynchronously
37499 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37500 + struct au_xi_calc *calc, ino_t ino)
37503 + struct au_xino_do_new_async_args *arg;
37506 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37507 + if (unlikely(!arg))
37512 + arg->calc = *calc;
37514 + au_lcnt_inc(&br->br_count);
37515 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37516 + if (unlikely(err)) {
37517 + pr_err("wkq %d\n", err);
37518 + au_lcnt_dec(&br->br_count);
37519 + au_kfree_rcu(arg);
37527 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37528 + * at the position of @h_ino.
37530 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37535 + struct au_xi_calc calc;
37536 + struct au_sbinfo *sbinfo;
37537 + struct file *file;
37538 + struct au_xino *xi;
37539 + struct hlist_bl_head *hbl;
37540 + struct hlist_bl_node *pos;
37541 + struct au_xi_writing *p;
37544 + if (!au_opt_test(au_mntflags(sb), XINO))
37545 + return 0; /* no xino */
37548 + au_xi_calc(sb, h_ino, &calc);
37549 + xi = au_sbr(sb, bindex)->br_xino;
37550 + file = au_xino_file(xi, calc.idx);
37552 + hbl = &xi->xi_writing;
37553 + hlist_bl_lock(hbl);
37554 + au_hbl_for_each(pos, hbl) {
37555 + p = container_of(pos, struct au_xi_writing, node);
37556 + if (p->h_ino == h_ino) {
37557 + AuDbg("hi%llu, i%llu, found\n",
37558 + (u64)p->h_ino, (u64)p->ino);
37563 + hlist_bl_unlock(hbl);
37565 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37566 + return 0; /* no xino */
37568 + sbinfo = au_sbi(sb);
37569 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37570 + if (sz == sizeof(*ino))
37571 + return 0; /* success */
37574 + if (unlikely(sz >= 0)) {
37576 + AuIOErr("xino read error (%zd)\n", sz);
37581 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37586 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37587 + if (sz == sizeof(ino))
37588 + return 0; /* success */
37590 + AuIOErr("write failed (%zd)\n", sz);
37595 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37596 + * at the position of @h_ino.
37597 + * even if @ino is zero, it is written to the xinofile and means no entry.
37598 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37599 + * try truncating it.
37601 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37605 + unsigned int mnt_flags;
37606 + struct au_xi_calc calc;
37607 + struct file *file;
37608 + struct au_branch *br;
37609 + struct au_xino *xi;
37610 + struct au_xi_writing *p;
37612 + SiMustAnyLock(sb);
37614 + mnt_flags = au_mntflags(sb);
37615 + if (!au_opt_test(mnt_flags, XINO))
37618 + au_xi_calc(sb, h_ino, &calc);
37619 + br = au_sbr(sb, bindex);
37620 + xi = br->br_xino;
37621 + file = au_xino_file(xi, calc.idx);
37623 + /* store the inum pair into the list */
37624 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37625 + p->h_ino = h_ino;
37627 + au_hbl_add(&p->node, &xi->xi_writing);
37629 + /* create and write a new xino file asynchronously */
37630 + err = au_xino_new_async(sb, br, &calc, ino);
37632 + return 0; /* success */
37636 + err = au_xino_do_write(file, &calc, ino);
37638 + br = au_sbr(sb, bindex);
37639 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37640 + && au_test_fs_trunc_xino(au_br_sb(br)))
37641 + xino_try_trunc(sb, br);
37642 + return 0; /* success */
37646 + AuIOErr("write failed (%d)\n", err);
37650 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37653 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37654 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37658 + const int prevent_endless = 10;
37662 + err = vfsub_read_k(file, kbuf, size, pos);
37663 + if (err == -EINTR
37664 + && !au_wkq_test()
37665 + && fatal_signal_pending(current)) {
37666 + err = xino_fread_wkq(file, kbuf, size, pos);
37667 + BUG_ON(err == -EINTR);
37669 + } while (i++ < prevent_endless
37670 + && (err == -EAGAIN || err == -EINTR));
37672 +#if 0 /* reserved for future use */
37674 + fsnotify_access(file->f_path.dentry);
37680 +struct xino_fread_args {
37682 + struct file *file;
37688 +static void call_xino_fread(void *args)
37690 + struct xino_fread_args *a = args;
37691 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37694 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37699 + struct xino_fread_args args = {
37707 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37708 + if (unlikely(wkq_err))
37714 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37717 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37722 + const int prevent_endless = 10;
37726 + err = vfsub_write_k(file, kbuf, size, pos);
37727 + if (err == -EINTR
37728 + && !au_wkq_test()
37729 + && fatal_signal_pending(current)) {
37730 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37731 + BUG_ON(err == -EINTR);
37733 + } while (i++ < prevent_endless
37734 + && (err == -EAGAIN || err == -EINTR));
37736 +#if 0 /* reserved for future use */
37738 + fsnotify_modify(file->f_path.dentry);
37744 +struct do_xino_fwrite_args {
37746 + struct file *file;
37752 +static void call_do_xino_fwrite(void *args)
37754 + struct do_xino_fwrite_args *a = args;
37755 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37758 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37763 + struct do_xino_fwrite_args args = {
37772 + * it breaks RLIMIT_FSIZE and normal user's limit,
37773 + * users should care about quota and real 'filesystem full.'
37775 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37776 + if (unlikely(wkq_err))
37782 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37786 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37788 + err = do_xino_fwrite(file, buf, size, pos);
37792 + err = xino_fwrite_wkq(file, buf, size, pos);
37799 +/* ---------------------------------------------------------------------- */
37802 + * inode number bitmap
37804 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37805 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37809 + AuDebugOn(bit < 0 || page_bits <= bit);
37810 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37814 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37816 + AuDebugOn(ino < AUFS_FIRST_INO);
37817 + ino -= AUFS_FIRST_INO;
37818 + *pindex = ino / page_bits;
37819 + *bit = ino % page_bits;
37822 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37827 + struct au_sbinfo *sbinfo;
37828 + struct file *xib;
37829 + unsigned long *p;
37831 + sbinfo = au_sbi(sb);
37832 + MtxMustLock(&sbinfo->si_xib_mtx);
37833 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37834 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37836 + if (pindex == sbinfo->si_xib_last_pindex)
37839 + xib = sbinfo->si_xib;
37840 + p = sbinfo->si_xib_buf;
37841 + pos = sbinfo->si_xib_last_pindex;
37842 + pos *= PAGE_SIZE;
37843 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37844 + if (unlikely(sz != PAGE_SIZE))
37848 + pos *= PAGE_SIZE;
37849 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37850 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37852 + memset(p, 0, PAGE_SIZE);
37853 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37855 + if (sz == PAGE_SIZE) {
37856 + sbinfo->si_xib_last_pindex = pindex;
37857 + return 0; /* success */
37861 + AuIOErr1("write failed (%zd)\n", sz);
37868 +static void au_xib_clear_bit(struct inode *inode)
37871 + unsigned long pindex;
37872 + struct super_block *sb;
37873 + struct au_sbinfo *sbinfo;
37875 + AuDebugOn(inode->i_nlink);
37877 + sb = inode->i_sb;
37878 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37879 + AuDebugOn(page_bits <= bit);
37880 + sbinfo = au_sbi(sb);
37881 + mutex_lock(&sbinfo->si_xib_mtx);
37882 + err = xib_pindex(sb, pindex);
37884 + clear_bit(bit, sbinfo->si_xib_buf);
37885 + sbinfo->si_xib_next_bit = bit;
37887 + mutex_unlock(&sbinfo->si_xib_mtx);
37890 +/* ---------------------------------------------------------------------- */
37893 + * truncate a xino bitmap file
37897 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37901 + unsigned long pindex;
37902 + loff_t pos, pend;
37903 + struct au_sbinfo *sbinfo;
37905 + unsigned long *p;
37908 + sbinfo = au_sbi(sb);
37909 + MtxMustLock(&sbinfo->si_xib_mtx);
37910 + p = sbinfo->si_xib_buf;
37911 + pend = vfsub_f_size_read(file);
37913 + while (pos < pend) {
37914 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37916 + if (unlikely(sz <= 0))
37920 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37921 + if (unlikely(*ino < AUFS_FIRST_INO))
37924 + xib_calc_bit(*ino, &pindex, &bit);
37925 + AuDebugOn(page_bits <= bit);
37926 + err = xib_pindex(sb, pindex);
37938 +static int xib_restore(struct super_block *sb)
37941 + unsigned int nfile;
37942 + aufs_bindex_t bindex, bbot;
37944 + struct au_branch *br;
37945 + struct au_xino *xi;
37946 + struct file *file;
37949 + page = (void *)__get_free_page(GFP_NOFS);
37950 + if (unlikely(!page))
37954 + bbot = au_sbbot(sb);
37955 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37956 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37957 + br = au_sbr(sb, bindex);
37958 + xi = br->br_xino;
37959 + nfile = xi->xi_nfile;
37960 + for (i = 0; i < nfile; i++) {
37961 + file = au_xino_file(xi, i);
37963 + err = do_xib_restore(sb, file, page);
37966 + AuDbg("skip shared b%d\n", bindex);
37967 + free_page((unsigned long)page);
37973 +int au_xib_trunc(struct super_block *sb)
37978 + struct au_sbinfo *sbinfo;
37979 + unsigned long *p;
37980 + struct file *file;
37982 + SiMustWriteLock(sb);
37985 + sbinfo = au_sbi(sb);
37986 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37989 + file = sbinfo->si_xib;
37990 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37993 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37994 + err = PTR_ERR(file);
37995 + if (IS_ERR(file))
37997 + fput(sbinfo->si_xib);
37998 + sbinfo->si_xib = file;
38000 + p = sbinfo->si_xib_buf;
38001 + memset(p, 0, PAGE_SIZE);
38003 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38004 + if (unlikely(sz != PAGE_SIZE)) {
38006 + AuIOErr("err %d\n", err);
38012 + mutex_lock(&sbinfo->si_xib_mtx);
38013 + /* mnt_want_write() is unnecessary here */
38014 + err = xib_restore(sb);
38015 + mutex_unlock(&sbinfo->si_xib_mtx);
38021 +/* ---------------------------------------------------------------------- */
38023 +struct au_xino *au_xino_alloc(unsigned int nfile)
38025 + struct au_xino *xi;
38027 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38028 + if (unlikely(!xi))
38030 + xi->xi_nfile = nfile;
38031 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38032 + if (unlikely(!xi->xi_file))
38035 + xi->xi_nondir.total = 8; /* initial size */
38036 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38038 + if (unlikely(!xi->xi_nondir.array))
38041 + spin_lock_init(&xi->xi_nondir.spin);
38042 + init_waitqueue_head(&xi->xi_nondir.wqh);
38043 + mutex_init(&xi->xi_mtx);
38044 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38045 + atomic_set(&xi->xi_truncating, 0);
38046 + kref_init(&xi->xi_kref);
38047 + goto out; /* success */
38050 + au_kfree_try_rcu(xi->xi_file);
38052 + au_kfree_rcu(xi);
38058 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38061 + struct au_xino *xi;
38064 + xi = au_xino_alloc(idx + 1);
38065 + if (unlikely(!xi)) {
38072 + xi->xi_file[idx] = file;
38073 + AuDebugOn(br->br_xino);
38074 + br->br_xino = xi;
38080 +static void au_xino_release(struct kref *kref)
38082 + struct au_xino *xi;
38084 + unsigned long ul;
38085 + struct hlist_bl_head *hbl;
38086 + struct hlist_bl_node *pos, *n;
38087 + struct au_xi_writing *p;
38089 + xi = container_of(kref, struct au_xino, xi_kref);
38090 + for (i = 0; i < xi->xi_nfile; i++)
38091 + if (xi->xi_file[i])
38092 + fput(xi->xi_file[i]);
38093 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38094 + AuDebugOn(xi->xi_nondir.array[i]);
38095 + mutex_destroy(&xi->xi_mtx);
38096 + hbl = &xi->xi_writing;
38097 + ul = au_hbl_count(hbl);
38098 + if (unlikely(ul)) {
38099 + pr_warn("xi_writing %lu\n", ul);
38100 + hlist_bl_lock(hbl);
38101 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38102 + hlist_bl_del(&p->node);
38103 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38106 + hlist_bl_unlock(hbl);
38108 + au_kfree_try_rcu(xi->xi_file);
38109 + au_kfree_try_rcu(xi->xi_nondir.array);
38110 + au_kfree_rcu(xi);
38113 +int au_xino_put(struct au_branch *br)
38116 + struct au_xino *xi;
38119 + xi = br->br_xino;
38121 + br->br_xino = NULL;
38122 + ret = kref_put(&xi->xi_kref, au_xino_release);
38128 +/* ---------------------------------------------------------------------- */
38131 + * xino mount option handlers
38135 +static void xino_clear_xib(struct super_block *sb)
38137 + struct au_sbinfo *sbinfo;
38139 + SiMustWriteLock(sb);
38141 + sbinfo = au_sbi(sb);
38142 + if (sbinfo->si_xib)
38143 + fput(sbinfo->si_xib);
38144 + sbinfo->si_xib = NULL;
38145 + if (sbinfo->si_xib_buf)
38146 + free_page((unsigned long)sbinfo->si_xib_buf);
38147 + sbinfo->si_xib_buf = NULL;
38150 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38154 + struct au_sbinfo *sbinfo;
38155 + struct file *file;
38156 + struct super_block *xi_sb;
38158 + SiMustWriteLock(sb);
38160 + sbinfo = au_sbi(sb);
38161 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38162 + err = PTR_ERR(file);
38163 + if (IS_ERR(file))
38165 + if (sbinfo->si_xib)
38166 + fput(sbinfo->si_xib);
38167 + sbinfo->si_xib = file;
38168 + xi_sb = file_inode(file)->i_sb;
38169 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38170 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38172 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38173 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38176 + sbinfo->si_ximaxent /= sizeof(ino_t);
38179 + if (!sbinfo->si_xib_buf)
38180 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38181 + if (unlikely(!sbinfo->si_xib_buf))
38184 + sbinfo->si_xib_last_pindex = 0;
38185 + sbinfo->si_xib_next_bit = 0;
38186 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38188 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38189 + if (unlikely(err != PAGE_SIZE))
38193 + goto out; /* success */
38196 + if (sbinfo->si_xib_buf)
38197 + free_page((unsigned long)sbinfo->si_xib_buf);
38198 + sbinfo->si_xib_buf = NULL;
38202 + fput(sbinfo->si_xib);
38203 + sbinfo->si_xib = NULL;
38209 +/* xino for each branch */
38210 +static void xino_clear_br(struct super_block *sb)
38212 + aufs_bindex_t bindex, bbot;
38213 + struct au_branch *br;
38215 + bbot = au_sbbot(sb);
38216 + for (bindex = 0; bindex <= bbot; bindex++) {
38217 + br = au_sbr(sb, bindex);
38223 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38224 + aufs_bindex_t bshared)
38226 + struct au_branch *brshared;
38228 + brshared = au_sbr(sb, bshared);
38229 + AuDebugOn(!brshared->br_xino);
38230 + AuDebugOn(!brshared->br_xino->xi_file);
38231 + if (br->br_xino != brshared->br_xino) {
38232 + au_xino_get(brshared);
38234 + br->br_xino = brshared->br_xino;
38238 +struct au_xino_do_set_br {
38239 + struct au_branch *br;
38241 + aufs_bindex_t bshared;
38244 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38245 + struct au_xino_do_set_br *args)
38248 + struct au_xi_calc calc;
38249 + struct file *file;
38250 + struct au_branch *br;
38251 + struct au_xi_new xinew = {
38256 + xinew.xi = br->br_xino;
38257 + au_xi_calc(sb, args->h_ino, &calc);
38258 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38259 + if (args->bshared >= 0)
38260 + /* shared xino */
38261 + au_xino_set_br_shared(sb, br, args->bshared);
38262 + else if (!xinew.xi) {
38264 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38265 + if (unlikely(err))
38269 + /* force re-creating */
38270 + xinew.xi = br->br_xino;
38271 + xinew.idx = calc.idx;
38272 + mutex_lock(&xinew.xi->xi_mtx);
38273 + file = au_xi_new(sb, &xinew);
38274 + mutex_unlock(&xinew.xi->xi_mtx);
38275 + err = PTR_ERR(file);
38276 + if (IS_ERR(file))
38278 + AuDebugOn(!file);
38280 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38281 + if (unlikely(err))
38289 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38292 + aufs_bindex_t bindex, bbot;
38293 + struct au_xino_do_set_br args;
38294 + struct inode *inode;
38296 + SiMustWriteLock(sb);
38298 + bbot = au_sbbot(sb);
38299 + inode = d_inode(sb->s_root);
38300 + for (bindex = 0; bindex <= bbot; bindex++) {
38301 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38302 + args.br = au_sbr(sb, bindex);
38303 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38304 + err = au_xino_do_set_br(sb, path, &args);
38305 + if (unlikely(err))
38313 +void au_xino_clr(struct super_block *sb)
38315 + struct au_sbinfo *sbinfo;
38317 + au_xigen_clr(sb);
38318 + xino_clear_xib(sb);
38319 + xino_clear_br(sb);
38320 + dbgaufs_brs_del(sb, 0);
38321 + sbinfo = au_sbi(sb);
38322 + /* lvalue, do not call au_mntflags() */
38323 + au_opt_clr(sbinfo->si_mntflags, XINO);
38326 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38329 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38330 + struct qstr *dname, *cur_name;
38331 + struct file *cur_xino;
38332 + struct au_sbinfo *sbinfo;
38333 + struct path *path, *cur_path;
38335 + SiMustWriteLock(sb);
38338 + sbinfo = au_sbi(sb);
38339 + path = &xiopt->file->f_path;
38340 + dentry = path->dentry;
38341 + parent = dget_parent(dentry);
38344 + cur_xino = sbinfo->si_xib;
38346 + cur_path = &cur_xino->f_path;
38347 + cur_dentry = cur_path->dentry;
38348 + cur_parent = dget_parent(cur_dentry);
38349 + cur_name = &cur_dentry->d_name;
38350 + dname = &dentry->d_name;
38351 + skip = (cur_parent == parent
38352 + && au_qstreq(dname, cur_name));
38353 + dput(cur_parent);
38359 + au_opt_set(sbinfo->si_mntflags, XINO);
38360 + err = au_xino_set_xib(sb, path);
38361 + /* si_x{read,write} are set */
38363 + err = au_xigen_set(sb, path);
38365 + err = au_xino_set_br(sb, path);
38367 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38368 + goto out; /* success */
38372 + AuIOErr("failed setting xino(%d).\n", err);
38381 + * create a xinofile at the default place/path.
38383 +struct file *au_xino_def(struct super_block *sb)
38385 + struct file *file;
38387 + struct au_branch *br;
38388 + struct super_block *h_sb;
38389 + struct path path;
38390 + aufs_bindex_t bbot, bindex, bwr;
38393 + bbot = au_sbbot(sb);
38395 + for (bindex = 0; bindex <= bbot; bindex++) {
38396 + br = au_sbr(sb, bindex);
38397 + if (au_br_writable(br->br_perm)
38398 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38405 + file = ERR_PTR(-ENOMEM);
38406 + page = (void *)__get_free_page(GFP_NOFS);
38407 + if (unlikely(!page))
38409 + path.mnt = au_br_mnt(br);
38410 + path.dentry = au_h_dptr(sb->s_root, bwr);
38411 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38412 + file = (void *)p;
38413 + if (!IS_ERR(p)) {
38414 + strcat(p, "/" AUFS_XINO_FNAME);
38415 + AuDbg("%s\n", p);
38416 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38418 + free_page((unsigned long)page);
38420 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38422 + if (IS_ERR(file))
38424 + h_sb = file->f_path.dentry->d_sb;
38425 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38426 + pr_err("xino doesn't support %s(%s)\n",
38427 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38429 + file = ERR_PTR(-EINVAL);
38437 +/* ---------------------------------------------------------------------- */
38440 + * initialize the xinofile for the specified branch @br
38441 + * at the place/path where @base_file indicates.
38442 + * test whether another branch is on the same filesystem or not,
38443 + * if found then share the xinofile with another branch.
38445 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38446 + struct path *base)
38449 + struct au_xino_do_set_br args = {
38454 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38456 + err = au_xino_do_set_br(sb, base, &args);
38457 + if (unlikely(err))
38463 +/* ---------------------------------------------------------------------- */
38466 + * get an unused inode number from bitmap
38468 +ino_t au_xino_new_ino(struct super_block *sb)
38471 + unsigned long *p, pindex, ul, pend;
38472 + struct au_sbinfo *sbinfo;
38473 + struct file *file;
38474 + int free_bit, err;
38476 + if (!au_opt_test(au_mntflags(sb), XINO))
38477 + return iunique(sb, AUFS_FIRST_INO);
38479 + sbinfo = au_sbi(sb);
38480 + mutex_lock(&sbinfo->si_xib_mtx);
38481 + p = sbinfo->si_xib_buf;
38482 + free_bit = sbinfo->si_xib_next_bit;
38483 + if (free_bit < page_bits && !test_bit(free_bit, p))
38484 + goto out; /* success */
38485 + free_bit = find_first_zero_bit(p, page_bits);
38486 + if (free_bit < page_bits)
38487 + goto out; /* success */
38489 + pindex = sbinfo->si_xib_last_pindex;
38490 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38491 + err = xib_pindex(sb, ul);
38492 + if (unlikely(err))
38494 + free_bit = find_first_zero_bit(p, page_bits);
38495 + if (free_bit < page_bits)
38496 + goto out; /* success */
38499 + file = sbinfo->si_xib;
38500 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38501 + for (ul = pindex + 1; ul <= pend; ul++) {
38502 + err = xib_pindex(sb, ul);
38503 + if (unlikely(err))
38505 + free_bit = find_first_zero_bit(p, page_bits);
38506 + if (free_bit < page_bits)
38507 + goto out; /* success */
38512 + set_bit(free_bit, p);
38513 + sbinfo->si_xib_next_bit = free_bit + 1;
38514 + pindex = sbinfo->si_xib_last_pindex;
38515 + mutex_unlock(&sbinfo->si_xib_mtx);
38516 + ino = xib_calc_ino(pindex, free_bit);
38517 + AuDbg("i%lu\n", (unsigned long)ino);
38520 + mutex_unlock(&sbinfo->si_xib_mtx);
38525 +/* for s_op->delete_inode() */
38526 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38529 + unsigned int mnt_flags;
38530 + aufs_bindex_t bindex, bbot, bi;
38531 + unsigned char try_trunc;
38532 + struct au_iinfo *iinfo;
38533 + struct super_block *sb;
38534 + struct au_hinode *hi;
38535 + struct inode *h_inode;
38536 + struct au_branch *br;
38537 + struct au_xi_calc calc;
38538 + struct file *file;
38540 + AuDebugOn(au_is_bad_inode(inode));
38542 + sb = inode->i_sb;
38543 + mnt_flags = au_mntflags(sb);
38544 + if (!au_opt_test(mnt_flags, XINO)
38545 + || inode->i_ino == AUFS_ROOT_INO)
38549 + au_xigen_inc(inode);
38550 + au_xib_clear_bit(inode);
38553 + iinfo = au_ii(inode);
38554 + bindex = iinfo->ii_btop;
38558 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38559 + hi = au_hinode(iinfo, bindex);
38560 + bbot = iinfo->ii_bbot;
38561 + for (; bindex <= bbot; bindex++, hi++) {
38562 + h_inode = hi->hi_inode;
38564 + || (!unlinked && h_inode->i_nlink))
38567 + /* inode may not be revalidated */
38568 + bi = au_br_index(sb, hi->hi_id);
38572 + br = au_sbr(sb, bi);
38573 + au_xi_calc(sb, h_inode->i_ino, &calc);
38574 + file = au_xino_file(br->br_xino, calc.idx);
38575 + if (IS_ERR_OR_NULL(file))
38578 + err = au_xino_do_write(file, &calc, /*ino*/0);
38579 + if (!err && try_trunc
38580 + && au_test_fs_trunc_xino(au_br_sb(br)))
38581 + xino_try_trunc(sb, br);
38585 +/* ---------------------------------------------------------------------- */
38587 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38589 + int found, total, i;
38592 + total = xi->xi_nondir.total;
38593 + for (i = 0; i < total; i++) {
38594 + if (xi->xi_nondir.array[i] != h_ino)
38603 +static int au_xinondir_expand(struct au_xino *xi)
38608 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38611 + sz = xi->xi_nondir.total * sizeof(ino_t);
38612 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38614 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38615 + /*may_shrink*/0);
38617 + xi->xi_nondir.array = p;
38618 + xi->xi_nondir.total <<= 1;
38619 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38627 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38628 + ino_t h_ino, int idx)
38630 + struct au_xino *xi;
38632 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38633 + xi = au_sbr(sb, bindex)->br_xino;
38634 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38636 + spin_lock(&xi->xi_nondir.spin);
38637 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38638 + xi->xi_nondir.array[idx] = 0;
38639 + spin_unlock(&xi->xi_nondir.spin);
38640 + wake_up_all(&xi->xi_nondir.wqh);
38643 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38646 + int err, found, empty;
38647 + struct au_xino *xi;
38651 + if (!au_opt_test(au_mntflags(sb), XINO))
38652 + goto out; /* no xino */
38654 + xi = au_sbr(sb, bindex)->br_xino;
38657 + spin_lock(&xi->xi_nondir.spin);
38658 + found = au_xinondir_find(xi, h_ino);
38659 + if (found == -1) {
38660 + empty = au_xinondir_find(xi, /*h_ino*/0);
38661 + if (empty == -1) {
38662 + empty = xi->xi_nondir.total;
38663 + err = au_xinondir_expand(xi);
38664 + if (unlikely(err))
38667 + xi->xi_nondir.array[empty] = h_ino;
38670 + spin_unlock(&xi->xi_nondir.spin);
38671 + wait_event(xi->xi_nondir.wqh,
38672 + xi->xi_nondir.array[found] != h_ino);
38677 + spin_unlock(&xi->xi_nondir.spin);
38682 +/* ---------------------------------------------------------------------- */
38684 +int au_xino_path(struct seq_file *seq, struct file *file)
38688 + err = au_seq_path(seq, &file->f_path);
38689 + if (unlikely(err))
38692 +#define Deleted "\\040(deleted)"
38693 + seq->count -= sizeof(Deleted) - 1;
38694 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38695 + sizeof(Deleted) - 1));
38701 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38702 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38703 +++ linux/include/uapi/linux/aufs_type.h 2021-09-06 21:06:28.017703615 +0200
38705 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38707 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38709 + * This program, aufs is free software; you can redistribute it and/or modify
38710 + * it under the terms of the GNU General Public License as published by
38711 + * the Free Software Foundation; either version 2 of the License, or
38712 + * (at your option) any later version.
38714 + * This program is distributed in the hope that it will be useful,
38715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38717 + * GNU General Public License for more details.
38719 + * You should have received a copy of the GNU General Public License
38720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38723 +#ifndef __AUFS_TYPE_H__
38724 +#define __AUFS_TYPE_H__
38726 +#define AUFS_NAME "aufs"
38730 + * define it before including all other headers.
38731 + * sched.h may use pr_* macros before defining "current", so define the
38732 + * no-current version first, and re-define later.
38734 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38735 +#include <linux/sched.h>
38737 +#define pr_fmt(fmt) \
38738 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38739 + (int)sizeof(current->comm), current->comm, current->pid
38740 +#include <linux/limits.h>
38742 +#include <stdint.h>
38743 +#include <sys/types.h>
38744 +#include <limits.h>
38745 +#endif /* __KERNEL__ */
38747 +#define AUFS_VERSION "5.14-20210906"
38749 +/* todo? move this to linux-2.6.19/include/magic.h */
38750 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38752 +/* ---------------------------------------------------------------------- */
38755 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38756 +typedef int8_t aufs_bindex_t;
38757 +#define AUFS_BRANCH_MAX 127
38759 +typedef int16_t aufs_bindex_t;
38760 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38761 +#define AUFS_BRANCH_MAX 511
38762 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38763 +#define AUFS_BRANCH_MAX 1023
38764 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38765 +#define AUFS_BRANCH_MAX 32767
38769 +#ifndef AUFS_BRANCH_MAX
38770 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38772 +#endif /* __KERNEL__ */
38774 +/* ---------------------------------------------------------------------- */
38776 +#define AUFS_FSTYPE AUFS_NAME
38778 +#define AUFS_ROOT_INO 2
38779 +#define AUFS_FIRST_INO 11
38781 +#define AUFS_WH_PFX ".wh."
38782 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38783 +#define AUFS_WH_TMP_LEN 4
38784 +/* a limit for rmdir/rename a dir and copyup */
38785 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38786 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38788 + - AUFS_WH_TMP_LEN) /* hex */
38789 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38790 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38791 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38792 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38793 +#define AUFS_DIRWH_DEF 3
38794 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38795 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38796 +#define AUFS_RDBLK_DEF 512 /* bytes */
38797 +#define AUFS_RDHASH_DEF 32
38798 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38799 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38800 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38801 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38802 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38804 +/* pseudo-link maintenace under /proc */
38805 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38806 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38807 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38809 +/* dirren, renamed dir */
38810 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38811 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38812 +/* whiteouted doubly */
38813 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38814 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38816 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38817 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38819 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38820 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38821 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38823 +/* doubly whiteouted */
38824 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38825 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38826 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38828 +/* branch permissions and attributes */
38829 +#define AUFS_BRPERM_RW "rw"
38830 +#define AUFS_BRPERM_RO "ro"
38831 +#define AUFS_BRPERM_RR "rr"
38832 +#define AUFS_BRATTR_COO_REG "coo_reg"
38833 +#define AUFS_BRATTR_COO_ALL "coo_all"
38834 +#define AUFS_BRATTR_FHSM "fhsm"
38835 +#define AUFS_BRATTR_UNPIN "unpin"
38836 +#define AUFS_BRATTR_ICEX "icex"
38837 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38838 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38839 +#define AUFS_BRATTR_ICEX_TR "icextr"
38840 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38841 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38842 +#define AUFS_BRRATTR_WH "wh"
38843 +#define AUFS_BRWATTR_NLWH "nolwh"
38844 +#define AUFS_BRWATTR_MOO "moo"
38846 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38847 +#define AuBrPerm_RO (1 << 1) /* readonly */
38848 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38849 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38851 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38852 +#define AuBrAttr_COO_ALL (1 << 4)
38853 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38855 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38856 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38857 + branch. meaningless since
38858 + linux-3.18-rc1 */
38860 +/* ignore error in copying XATTR */
38861 +#define AuBrAttr_ICEX_SEC (1 << 7)
38862 +#define AuBrAttr_ICEX_SYS (1 << 8)
38863 +#define AuBrAttr_ICEX_TR (1 << 9)
38864 +#define AuBrAttr_ICEX_USR (1 << 10)
38865 +#define AuBrAttr_ICEX_OTH (1 << 11)
38866 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38867 + | AuBrAttr_ICEX_SYS \
38868 + | AuBrAttr_ICEX_TR \
38869 + | AuBrAttr_ICEX_USR \
38870 + | AuBrAttr_ICEX_OTH)
38872 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38873 +#define AuBrRAttr_Mask AuBrRAttr_WH
38875 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38876 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38877 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38879 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38881 +/* #warning test userspace */
38883 +#ifndef CONFIG_AUFS_FHSM
38884 +#undef AuBrAttr_FHSM
38885 +#define AuBrAttr_FHSM 0
38887 +#ifndef CONFIG_AUFS_XATTR
38888 +#undef AuBrAttr_ICEX
38889 +#define AuBrAttr_ICEX 0
38890 +#undef AuBrAttr_ICEX_SEC
38891 +#define AuBrAttr_ICEX_SEC 0
38892 +#undef AuBrAttr_ICEX_SYS
38893 +#define AuBrAttr_ICEX_SYS 0
38894 +#undef AuBrAttr_ICEX_TR
38895 +#define AuBrAttr_ICEX_TR 0
38896 +#undef AuBrAttr_ICEX_USR
38897 +#define AuBrAttr_ICEX_USR 0
38898 +#undef AuBrAttr_ICEX_OTH
38899 +#define AuBrAttr_ICEX_OTH 0
38903 +/* the longest combination */
38904 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38905 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38906 + "+" AUFS_BRATTR_COO_REG \
38907 + "+" AUFS_BRATTR_FHSM \
38908 + "+" AUFS_BRATTR_UNPIN \
38909 + "+" AUFS_BRATTR_ICEX_SEC \
38910 + "+" AUFS_BRATTR_ICEX_SYS \
38911 + "+" AUFS_BRATTR_ICEX_USR \
38912 + "+" AUFS_BRATTR_ICEX_OTH \
38913 + "+" AUFS_BRWATTR_NLWH)
38916 + char a[AuBrPermStrSz];
38917 +} au_br_perm_str_t;
38919 +static inline int au_br_writable(int brperm)
38921 + return brperm & AuBrPerm_RW;
38924 +static inline int au_br_whable(int brperm)
38926 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38929 +static inline int au_br_wh_linkable(int brperm)
38931 + return !(brperm & AuBrWAttr_NoLinkWH);
38934 +static inline int au_br_cmoo(int brperm)
38936 + return brperm & AuBrAttr_CMOO_Mask;
38939 +static inline int au_br_fhsm(int brperm)
38941 + return brperm & AuBrAttr_FHSM;
38944 +/* ---------------------------------------------------------------------- */
38948 + /* readdir in userspace */
38952 + AuCtl_WBR_FD, /* pathconf wrapper */
38953 + AuCtl_IBUSY, /* busy inode */
38954 + AuCtl_MVDOWN, /* move-down */
38955 + AuCtl_BR, /* info about branches */
38956 + AuCtl_FHSM_FD /* connection for fhsm */
38959 +/* borrowed from linux/include/linux/kernel.h */
38961 +#ifdef _GNU_SOURCE
38962 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38964 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38966 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38969 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38971 +#define __aligned(x) __attribute__((aligned(x)))
38976 +#define __packed __attribute__((packed))
38980 +struct au_rdu_cookie {
38985 + uint32_t generation;
38988 +struct au_rdu_ent {
38997 +static inline int au_rdu_len(int nlen)
38999 + /* include the terminating NULL */
39000 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39001 + sizeof(uint64_t));
39004 +union au_rdu_ent_ul {
39005 + struct au_rdu_ent __user *e;
39017 + uint64_t sz; /* AuCtl_RDU */
39018 + uint64_t nent; /* AuCtl_RDU_INO */
39020 + union au_rdu_ent_ul ent;
39021 + uint16_t verify[AufsCtlRduV_End];
39023 + /* input/output */
39027 + union au_rdu_ent_ul tail;
39028 + /* number of entries which were added in a single call */
39033 + struct au_rdu_cookie cookie;
39036 +/* ---------------------------------------------------------------------- */
39038 +/* dirren. the branch is identified by the filename who contains this */
39039 +struct au_drinfo {
39042 + uint8_t oldnamelen;
39043 + uint64_t _padding;
39045 + uint8_t oldname[];
39048 +struct au_drinfo_fdata {
39050 + struct au_drinfo drinfo;
39053 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39055 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39057 +/* ---------------------------------------------------------------------- */
39059 +struct aufs_wbr_fd {
39064 +/* ---------------------------------------------------------------------- */
39066 +struct aufs_ibusy {
39067 + uint64_t ino, h_ino;
39071 +/* ---------------------------------------------------------------------- */
39073 +/* error code for move-down */
39074 +/* the actual message strings are implemented in aufs-util.git */
39076 + EAU_MVDOWN_OPAQUE = 1,
39077 + EAU_MVDOWN_WHITEOUT,
39078 + EAU_MVDOWN_UPPER,
39079 + EAU_MVDOWN_BOTTOM,
39080 + EAU_MVDOWN_NOUPPER,
39081 + EAU_MVDOWN_NOLOWERBR,
39085 +/* flags for move-down */
39086 +#define AUFS_MVDOWN_DMSG 1
39087 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39088 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39089 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39090 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39091 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39092 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39093 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39094 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39095 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39096 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39097 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39098 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39100 +/* index for move-down */
39102 + AUFS_MVDOWN_UPPER,
39103 + AUFS_MVDOWN_LOWER,
39104 + AUFS_MVDOWN_NARRAY
39108 + * additional info of move-down
39109 + * number of free blocks and inodes.
39110 + * subset of struct kstatfs, but smaller and always 64bit.
39112 +struct aufs_stfs {
39113 + uint64_t f_blocks;
39114 + uint64_t f_bavail;
39115 + uint64_t f_files;
39116 + uint64_t f_ffree;
39119 +struct aufs_stbr {
39120 + int16_t brid; /* optional input */
39121 + int16_t bindex; /* output */
39122 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39125 +struct aufs_mvdown {
39126 + uint32_t flags; /* input/output */
39127 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39128 + int8_t au_errno; /* output */
39131 +/* ---------------------------------------------------------------------- */
39133 +union aufs_brinfo {
39134 + /* PATH_MAX may differ between kernel-space and user-space */
39135 + char _spacer[4096];
39143 +/* ---------------------------------------------------------------------- */
39145 +#define AuCtlType 'A'
39146 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39147 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39148 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39149 + struct aufs_wbr_fd)
39150 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39151 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39152 + struct aufs_mvdown)
39153 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39154 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39156 +#endif /* __AUFS_TYPE_H__ */
39157 SPDX-License-Identifier: GPL-2.0
39158 aufs5.14 loopback patch
39160 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39161 index e65f941a4181a..ce11efab143b7 100644
39162 --- a/drivers/block/loop.c
39163 +++ b/drivers/block/loop.c
39164 @@ -685,6 +685,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39168 +static struct file *loop_real_file(struct file *file)
39170 + struct file *f = NULL;
39172 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39173 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39177 static void loop_reread_partitions(struct loop_device *lo)
39180 @@ -742,6 +751,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39182 struct file *file = fget(arg);
39183 struct file *old_file;
39184 + struct file *f, *virt_file = NULL, *old_virt_file;
39188 @@ -761,11 +771,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39189 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39192 + f = loop_real_file(file);
39194 + virt_file = file;
39199 error = loop_validate_file(file, bdev);
39203 old_file = lo->lo_backing_file;
39204 + old_virt_file = lo->lo_backing_virt_file;
39208 @@ -777,6 +795,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39209 blk_mq_freeze_queue(lo->lo_queue);
39210 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39211 lo->lo_backing_file = file;
39212 + lo->lo_backing_virt_file = virt_file;
39213 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39214 mapping_set_gfp_mask(file->f_mapping,
39215 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39216 @@ -799,6 +818,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39220 + if (old_virt_file)
39221 + fput(old_virt_file);
39223 loop_reread_partitions(lo);
39225 @@ -807,6 +828,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39226 loop_global_unlock(lo, is_loop);
39234 @@ -1207,6 +1230,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39235 const struct loop_config *config)
39237 struct file *file = fget(config->fd);
39238 + struct file *f, *virt_file = NULL;
39239 struct inode *inode;
39240 struct address_space *mapping;
39242 @@ -1222,6 +1246,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39243 /* This is safe, since we have a reference from open(). */
39244 __module_get(THIS_MODULE);
39246 + f = loop_real_file(file);
39248 + virt_file = file;
39254 * If we don't hold exclusive handle for the device, upgrade to it
39255 * here to avoid changing device under exclusive owner.
39256 @@ -1286,6 +1317,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39257 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39258 lo->lo_device = bdev;
39259 lo->lo_backing_file = file;
39260 + lo->lo_backing_virt_file = virt_file;
39261 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39262 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39264 @@ -1340,6 +1372,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39265 bd_abort_claiming(bdev, loop_configure);
39270 /* This is safe: open() is still holding a reference. */
39271 module_put(THIS_MODULE);
39273 @@ -1348,6 +1382,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39274 static int __loop_clr_fd(struct loop_device *lo, bool release)
39276 struct file *filp = NULL;
39277 + struct file *virt_filp = lo->lo_backing_virt_file;
39278 gfp_t gfp = lo->old_gfp_mask;
39279 struct block_device *bdev = lo->lo_device;
39281 @@ -1399,6 +1434,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39283 spin_lock_irq(&lo->lo_lock);
39284 lo->lo_backing_file = NULL;
39285 + lo->lo_backing_virt_file = NULL;
39286 spin_unlock_irq(&lo->lo_lock);
39288 loop_release_xfer(lo);
39289 @@ -1479,6 +1515,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39298 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39299 index 1988899db63ac..ff866d85aceac 100644
39300 --- a/drivers/block/loop.h
39301 +++ b/drivers/block/loop.h
39302 @@ -46,7 +46,7 @@ struct loop_device {
39303 int (*ioctl)(struct loop_device *, int cmd,
39304 unsigned long arg);
39306 - struct file * lo_backing_file;
39307 + struct file *lo_backing_file, *lo_backing_virt_file;
39308 struct block_device *lo_device;
39311 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39312 index 99ceca1440449..e49dfe8550329 100644
39313 --- a/fs/aufs/f_op.c
39314 +++ b/fs/aufs/f_op.c
39315 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39316 if (IS_ERR(h_file))
39319 - if (au_test_loopback_kthread()) {
39320 + if (0 && au_test_loopback_kthread()) {
39321 au_warn_loopback(h_file->f_path.dentry->d_sb);
39322 if (file->f_mapping != h_file->f_mapping) {
39323 file->f_mapping = h_file->f_mapping;
39324 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39325 index 74347bd75b380..5ef888a1d53f4 100644
39326 --- a/fs/aufs/loop.c
39327 +++ b/fs/aufs/loop.c
39328 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39329 symbol_put(loop_backing_file);
39330 au_kfree_try_rcu(au_warn_loopback_array);
39333 +/* ---------------------------------------------------------------------- */
39335 +/* support the loopback block device insude aufs */
39337 +struct file *aufs_real_loop(struct file *file)
39341 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39342 + fi_read_lock(file);
39343 + f = au_hf_top(file);
39344 + fi_read_unlock(file);
39348 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39349 index 7293bee427f96..3345c098d0d47 100644
39350 --- a/fs/aufs/loop.h
39351 +++ b/fs/aufs/loop.h
39352 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39354 int au_loopback_init(void);
39355 void au_loopback_fin(void);
39357 +struct file *aufs_real_loop(struct file *file);
39359 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39361 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39363 AuStubInt0(au_loopback_init, void)
39364 AuStubVoid(au_loopback_fin, void)
39366 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39367 #endif /* BLK_DEV_LOOP */
39369 #endif /* __KERNEL__ */
39370 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39371 index ae38857541533..af32f0960e595 100644
39372 --- a/fs/aufs/super.c
39373 +++ b/fs/aufs/super.c
39374 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39375 .statfs = aufs_statfs,
39376 .put_super = aufs_put_super,
39377 .sync_fs = aufs_sync_fs,
39378 - .remount_fs = aufs_remount_fs
39379 + .remount_fs = aufs_remount_fs,
39380 +#ifdef CONFIG_AUFS_BDEV_LOOP
39381 + .real_loop = aufs_real_loop
39385 /* ---------------------------------------------------------------------- */
39386 diff --git a/include/linux/fs.h b/include/linux/fs.h
39387 index ffeed3ccd2d62..6a8e599051b77 100644
39388 --- a/include/linux/fs.h
39389 +++ b/include/linux/fs.h
39390 @@ -2177,6 +2177,10 @@ struct super_operations {
39391 struct shrink_control *);
39392 long (*free_cached_objects)(struct super_block *,
39393 struct shrink_control *);
39394 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39396 + struct file *(*real_loop)(struct file *);