1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a6313a969bc5f..aca4b89d41a14 100644
8 @@ -312,6 +312,7 @@ source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/erofs/Kconfig"
11 source "fs/vboxsf/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 84c5e4cdfee5a..b4fcdad8412ed 100644
20 @@ -138,3 +138,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 3b79fd441dde8..3fb0a57f61b05 100644
32 @@ -3122,6 +3122,19 @@ F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda <ojeda@kernel.org>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index 7bf4686af774e..a62b132cbd551 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -811,6 +811,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 9c6c6a3e2de51..02382fa9bd341 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -64,6 +64,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/namespace.c b/fs/namespace.c
117 index 659a8f39c61af..1283670737826 100644
120 @@ -808,6 +808,12 @@ static inline int check_mnt(struct mount *mnt)
121 return mnt->mnt_ns == current->nsproxy->mnt_ns;
124 +/* for aufs, CONFIG_AUFS_BR_FUSE */
125 +int is_current_mnt_ns(struct vfsmount *mnt)
127 + return check_mnt(real_mount(mnt));
131 * vfsmount lock must be held for write
133 diff --git a/fs/splice.c b/fs/splice.c
134 index 5dbce4dcc1a7d..3e6ba363b7775 100644
137 @@ -759,8 +759,8 @@ static int warn_unsupported(struct file *file, const char *op)
139 * Attempt to initiate a splice from pipe to file.
141 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
142 - loff_t *ppos, size_t len, unsigned int flags)
143 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
144 + loff_t *ppos, size_t len, unsigned int flags)
146 if (unlikely(!out->f_op->splice_write))
147 return warn_unsupported(out, "write");
148 @@ -770,9 +770,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
150 * Attempt to initiate a splice from a file to a pipe.
152 -static long do_splice_to(struct file *in, loff_t *ppos,
153 - struct pipe_inode_info *pipe, size_t len,
154 - unsigned int flags)
155 +long do_splice_to(struct file *in, loff_t *ppos,
156 + struct pipe_inode_info *pipe, size_t len,
157 + unsigned int flags)
159 unsigned int p_space;
161 diff --git a/fs/sync.c b/fs/sync.c
162 index 1373a610dc784..b7b5a0a0df6ff 100644
166 * wait == 1 case since in that case write_inode() functions do
167 * sync_dirty_buffer() and thus effectively write one block at a time.
169 -static int __sync_filesystem(struct super_block *sb, int wait)
170 +int __sync_filesystem(struct super_block *sb, int wait)
174 diff --git a/include/linux/fs.h b/include/linux/fs.h
175 index e7a633353fd20..376ddf1965aa2 100644
176 --- a/include/linux/fs.h
177 +++ b/include/linux/fs.h
178 @@ -1381,6 +1381,7 @@ extern void fasync_free(struct fasync_struct *);
179 /* can be called from interrupts */
180 extern void kill_fasync(struct fasync_struct **, int, int);
182 +extern int setfl(int fd, struct file *filp, unsigned long arg);
183 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
184 extern int f_setown(struct file *filp, unsigned long arg, int force);
185 extern void f_delown(struct file *filp);
186 @@ -2092,6 +2093,7 @@ struct file_operations {
187 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
188 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
189 int (*check_flags)(int);
190 + int (*setfl)(struct file *, unsigned long);
191 int (*flock) (struct file *, int, struct file_lock *);
192 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
193 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
194 @@ -2776,6 +2779,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
197 void emergency_thaw_all(void);
198 +extern int __sync_filesystem(struct super_block *, int);
199 extern int sync_filesystem(struct super_block *);
200 extern const struct file_operations def_blk_fops;
201 extern const struct file_operations def_chr_fops;
202 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
203 index 9fe165beb0f9e..e47f7e15eeaf7 100644
204 --- a/include/linux/lockdep.h
205 +++ b/include/linux/lockdep.h
206 @@ -248,6 +248,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
207 return lock->key == key;
210 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
215 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
216 index 8f882f5881e87..6b9808f098435 100644
217 --- a/include/linux/mnt_namespace.h
218 +++ b/include/linux/mnt_namespace.h
219 @@ -7,12 +7,15 @@ struct mnt_namespace;
221 struct user_namespace;
225 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
226 struct user_namespace *, struct fs_struct *);
227 extern void put_mnt_ns(struct mnt_namespace *ns);
228 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
230 +extern int is_current_mnt_ns(struct vfsmount *mnt);
232 extern const struct file_operations proc_mounts_operations;
233 extern const struct file_operations proc_mountinfo_operations;
234 extern const struct file_operations proc_mountstats_operations;
235 diff --git a/include/linux/splice.h b/include/linux/splice.h
236 index a55179fd60fc3..8e21c53cf8831 100644
237 --- a/include/linux/splice.h
238 +++ b/include/linux/splice.h
239 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
241 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
242 extern const struct pipe_buf_operations default_pipe_buf_ops;
244 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
245 + loff_t *ppos, size_t len, unsigned int flags);
246 +extern long do_splice_to(struct file *in, loff_t *ppos,
247 + struct pipe_inode_info *pipe, size_t len,
248 + unsigned int flags);
250 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
251 index bf1c00c881e48..e0aaf34974df5 100644
252 --- a/kernel/locking/lockdep.c
253 +++ b/kernel/locking/lockdep.c
254 @@ -189,7 +189,7 @@ static
255 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
256 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
258 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
259 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
261 unsigned int class_idx = hlock->class_idx;
263 @@ -210,6 +210,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
265 return lock_classes + class_idx;
267 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
269 #ifdef CONFIG_LOCK_STAT
270 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
271 SPDX-License-Identifier: GPL-2.0
274 diff --git a/fs/proc/base.c b/fs/proc/base.c
275 index 533d5836eb9a4..f5de60c5327f5 100644
278 @@ -2186,7 +2186,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
280 vma = find_exact_vma(mm, vm_start, vm_end);
281 if (vma && vma->vm_file) {
282 - *path = vma->vm_file->f_path;
283 + *path = vma_pr_or_file(vma)->f_path;
287 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
288 index 13452b32e2bd5..38acccfef9d49 100644
289 --- a/fs/proc/nommu.c
290 +++ b/fs/proc/nommu.c
291 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
292 file = region->vm_file;
295 - struct inode *inode = file_inode(region->vm_file);
296 + struct inode *inode;
298 + file = vmr_pr_or_file(region);
299 + inode = file_inode(file);
300 dev = inode->i_sb->s_dev;
303 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
304 index cf25be3e03212..70af1c25ffa22 100644
305 --- a/fs/proc/task_mmu.c
306 +++ b/fs/proc/task_mmu.c
307 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
308 const char *name = NULL;
311 - struct inode *inode = file_inode(vma->vm_file);
312 + struct inode *inode;
314 + file = vma_pr_or_file(vma);
315 + inode = file_inode(file);
316 dev = inode->i_sb->s_dev;
318 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
319 @@ -1865,7 +1868,7 @@ static int show_numa_map(struct seq_file *m, void *v)
320 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
321 struct vm_area_struct *vma = v;
322 struct numa_maps *md = &numa_priv->md;
323 - struct file *file = vma->vm_file;
324 + struct file *file = vma_pr_or_file(vma);
325 struct mm_struct *mm = vma->vm_mm;
326 struct mempolicy *pol;
328 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
329 index a6d21fc0033c6..02c2de31196e0 100644
330 --- a/fs/proc/task_nommu.c
331 +++ b/fs/proc/task_nommu.c
332 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
336 - struct inode *inode = file_inode(vma->vm_file);
337 + struct inode *inode;
339 + file = vma_pr_or_file(vma);
340 + inode = file_inode(file);
341 dev = inode->i_sb->s_dev;
343 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
344 diff --git a/include/linux/mm.h b/include/linux/mm.h
345 index 73a52aba448f9..5dd42acf0707b 100644
346 --- a/include/linux/mm.h
347 +++ b/include/linux/mm.h
348 @@ -1806,6 +1806,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
349 unmap_mapping_range(mapping, holebegin, holelen, 0);
352 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
353 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
355 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
356 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
358 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
360 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
362 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
363 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
366 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
367 +extern void vmr_do_fput(struct vm_region *, const char[], int);
369 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
371 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
372 +#endif /* !CONFIG_MMU */
374 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
375 void *buf, int len, unsigned int gup_flags);
376 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
377 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
378 index 7f8ee09c711f4..3a9a798a4ae1f 100644
379 --- a/include/linux/mm_types.h
380 +++ b/include/linux/mm_types.h
381 @@ -294,6 +294,7 @@ struct vm_region {
382 unsigned long vm_top; /* region allocated to here */
383 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
384 struct file *vm_file; /* the backing file or NULL */
385 + struct file *vm_prfile; /* the virtual backing file or NULL */
387 int vm_usage; /* region usage count (access under nommu_region_sem) */
388 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
389 @@ -373,6 +374,7 @@ struct vm_area_struct {
390 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
392 struct file * vm_file; /* File we map to (can be NULL). */
393 + struct file *vm_prfile; /* shadow of vm_file */
394 void * vm_private_data; /* was vm_pte (shared mem) */
397 diff --git a/kernel/fork.c b/kernel/fork.c
398 index 38681ad44c76b..95de8e9843192 100644
401 @@ -573,7 +573,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
403 struct address_space *mapping = file->f_mapping;
407 i_mmap_lock_write(mapping);
408 if (tmp->vm_flags & VM_SHARED)
409 mapping_allow_writable(mapping);
410 diff --git a/mm/Makefile b/mm/Makefile
411 index fc60a40ce954b..c715b0138237b 100644
414 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
415 mm_init.o percpu.o slab_common.o \
416 compaction.o vmacache.o \
417 interval_tree.o list_lru.o workingset.o \
418 - debug.o gup.o mmap_lock.o $(mmu-y)
419 + prfile.o debug.o gup.o mmap_lock.o $(mmu-y)
421 # Give 'page_alloc' its own module-parameter namespace
422 page-alloc-y := page_alloc.o
423 diff --git a/mm/filemap.c b/mm/filemap.c
424 index dae481293b5d9..52bf3bf87b757 100644
427 @@ -3350,7 +3350,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
428 vm_fault_t ret = VM_FAULT_LOCKED;
430 sb_start_pagefault(mapping->host->i_sb);
431 - file_update_time(vmf->vma->vm_file);
432 + vma_file_update_time(vmf->vma);
434 if (page->mapping != mapping) {
436 diff --git a/mm/mmap.c b/mm/mmap.c
437 index 88dcc5c252255..6c276614ca962 100644
440 @@ -183,7 +183,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
441 if (vma->vm_ops && vma->vm_ops->close)
442 vma->vm_ops->close(vma);
444 - fput(vma->vm_file);
446 mpol_put(vma_policy(vma));
449 @@ -952,7 +952,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
452 uprobe_munmap(next, next->vm_start, next->vm_end);
457 anon_vma_merge(vma, next);
458 @@ -1873,7 +1873,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
462 - fput(vma->vm_file);
466 /* Undo any partial mapping done by a device driver. */
467 @@ -2731,7 +2731,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
471 - get_file(new->vm_file);
474 if (new->vm_ops && new->vm_ops->open)
475 new->vm_ops->open(new);
476 @@ -2750,7 +2750,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
477 if (new->vm_ops && new->vm_ops->close)
478 new->vm_ops->close(new);
480 - fput(new->vm_file);
482 unlink_anon_vmas(new);
484 mpol_put(vma_policy(new));
485 @@ -2945,7 +2945,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
486 struct vm_area_struct *vma;
487 unsigned long populate = 0;
488 unsigned long ret = -EINVAL;
490 + struct file *file, *prfile;
492 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
493 current->comm, current->pid);
494 @@ -3001,10 +3001,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
495 if (vma->vm_flags & VM_LOCKED)
498 - file = get_file(vma->vm_file);
500 + file = vma->vm_file;
501 + prfile = vma->vm_prfile;
502 ret = do_mmap(vma->vm_file, start, size,
503 prot, flags, pgoff, &populate, NULL);
504 + if (!IS_ERR_VALUE(ret) && file && prfile) {
505 + struct vm_area_struct *new_vma;
507 + new_vma = find_vma(mm, ret);
508 + if (!new_vma->vm_prfile)
509 + new_vma->vm_prfile = prfile;
510 + if (new_vma != vma)
514 + * two fput()s instead of vma_fput(vma),
515 + * coz vma may not be available anymore.
521 mmap_write_unlock(mm);
523 @@ -3285,7 +3302,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
524 if (anon_vma_clone(new_vma, vma))
525 goto out_free_mempol;
526 if (new_vma->vm_file)
527 - get_file(new_vma->vm_file);
528 + vma_get_file(new_vma);
529 if (new_vma->vm_ops && new_vma->vm_ops->open)
530 new_vma->vm_ops->open(new_vma);
531 vma_link(mm, new_vma, prev, rb_link, rb_parent);
532 diff --git a/mm/nommu.c b/mm/nommu.c
533 index 02d2427b8f9e8..a7419302ab4ed 100644
536 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
537 up_write(&nommu_region_sem);
540 - fput(region->vm_file);
543 /* IO memory and memory shared directly out of the pagecache
544 * from ramfs/tmpfs mustn't be released here */
545 @@ -655,7 +655,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
546 if (vma->vm_ops && vma->vm_ops->close)
547 vma->vm_ops->close(vma);
549 - fput(vma->vm_file);
551 put_nommu_region(vma->vm_region);
554 @@ -1175,7 +1175,7 @@ unsigned long do_mmap(struct file *file,
555 goto error_just_free;
558 - fput(region->vm_file);
560 kmem_cache_free(vm_region_jar, region);
563 @@ -1252,10 +1252,10 @@ unsigned long do_mmap(struct file *file,
564 up_write(&nommu_region_sem);
567 - fput(region->vm_file);
569 kmem_cache_free(vm_region_jar, region);
571 - fput(vma->vm_file);
576 diff --git a/mm/prfile.c b/mm/prfile.c
578 index 0000000000000..511543ab1b418
582 +// SPDX-License-Identifier: GPL-2.0
584 + * Mainly for aufs which mmap(2) different file and wants to print different
585 + * path in /proc/PID/maps.
586 + * Call these functions via macros defined in linux/mm.h.
588 + * See Documentation/filesystems/aufs/design/06mmap.txt
590 + * Copyright (c) 2014-2021 Junjro R. Okajima
591 + * Copyright (c) 2014 Ian Campbell
594 +#include <linux/mm.h>
595 +#include <linux/file.h>
596 +#include <linux/fs.h>
598 +/* #define PRFILE_TRACE */
599 +static inline void prfile_trace(struct file *f, struct file *pr,
600 + const char func[], int line, const char func2[])
604 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
608 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
611 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
613 + prfile_trace(f, pr, func, line, __func__);
614 + file_update_time(f);
616 + file_update_time(pr);
619 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
622 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
624 + prfile_trace(f, pr, func, line, __func__);
625 + return (f && pr) ? pr : f;
628 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
630 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
632 + prfile_trace(f, pr, func, line, __func__);
638 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
640 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
642 + prfile_trace(f, pr, func, line, __func__);
649 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
652 + struct file *f = region->vm_file, *pr = region->vm_prfile;
654 + prfile_trace(f, pr, func, line, __func__);
655 + return (f && pr) ? pr : f;
658 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
660 + struct file *f = region->vm_file, *pr = region->vm_prfile;
662 + prfile_trace(f, pr, func, line, __func__);
667 +#endif /* !CONFIG_MMU */
668 SPDX-License-Identifier: GPL-2.0
669 aufs5.15 standalone patch
671 diff --git a/fs/dcache.c b/fs/dcache.c
672 index bc5095b734f58..9508bd57a3bc0 100644
675 @@ -1425,6 +1425,7 @@ void d_walk(struct dentry *parent, void *data,
679 +EXPORT_SYMBOL_GPL(d_walk);
682 struct vfsmount *mnt;
683 @@ -2970,6 +2971,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
685 write_sequnlock(&rename_lock);
687 +EXPORT_SYMBOL_GPL(d_exchange);
690 * d_ancestor - search for an ancestor
691 diff --git a/fs/exec.c b/fs/exec.c
692 index a098c133d8d74..7b6a249fd4778 100644
695 @@ -111,6 +111,7 @@ bool path_noexec(const struct path *path)
696 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
697 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
699 +EXPORT_SYMBOL_GPL(path_noexec);
703 diff --git a/fs/fcntl.c b/fs/fcntl.c
704 index 02382fa9bd341..3418c60b90146 100644
707 @@ -86,6 +86,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
711 +EXPORT_SYMBOL_GPL(setfl);
713 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
715 diff --git a/fs/file_table.c b/fs/file_table.c
716 index 45437f8e1003e..786af52904fcf 100644
717 --- a/fs/file_table.c
718 +++ b/fs/file_table.c
719 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
721 return ERR_PTR(-ENFILE);
723 +EXPORT_SYMBOL_GPL(alloc_empty_file);
726 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
727 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
731 +EXPORT_SYMBOL_GPL(__fput_sync);
733 void __init files_init(void)
735 diff --git a/fs/namespace.c b/fs/namespace.c
736 index 1283670737826..db99365620118 100644
739 @@ -439,6 +439,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
740 mnt_dec_writers(real_mount(mnt));
743 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
746 * mnt_drop_write - give up write access to a mount
747 @@ -813,6 +814,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
749 return check_mnt(real_mount(mnt));
751 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
754 * vfsmount lock must be held for write
755 @@ -2011,6 +2013,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
759 +EXPORT_SYMBOL_GPL(iterate_mounts);
761 static void lock_mnt_tree(struct mount *mnt)
763 diff --git a/fs/notify/group.c b/fs/notify/group.c
764 index fb89c351295d6..460ad19c2570a 100644
765 --- a/fs/notify/group.c
766 +++ b/fs/notify/group.c
767 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
769 refcount_inc(&group->refcnt);
771 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
774 * Drop a reference to a group. Free it if it's through.
775 diff --git a/fs/open.c b/fs/open.c
776 index daa324606a41f..0d8bb2f1922a3 100644
779 @@ -65,6 +65,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
780 inode_unlock(dentry->d_inode);
783 +EXPORT_SYMBOL_GPL(do_truncate);
785 long vfs_truncate(const struct path *path, loff_t length)
787 diff --git a/fs/read_write.c b/fs/read_write.c
788 index af057c57bdc64..76017f8331fbf 100644
789 --- a/fs/read_write.c
790 +++ b/fs/read_write.c
791 @@ -492,6 +492,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
795 +EXPORT_SYMBOL_GPL(vfs_read);
797 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
799 @@ -602,6 +603,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
800 file_end_write(file);
803 +EXPORT_SYMBOL_GPL(vfs_write);
805 /* file_ppos returns &file->f_pos or NULL if file is stream */
806 static inline loff_t *file_ppos(struct file *file)
807 diff --git a/fs/splice.c b/fs/splice.c
808 index 3e6ba363b7775..7c1be373eb7cd 100644
811 @@ -766,6 +766,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
812 return warn_unsupported(out, "write");
813 return out->f_op->splice_write(pipe, out, ppos, len, flags);
815 +EXPORT_SYMBOL_GPL(do_splice_from);
818 * Attempt to initiate a splice from a file to a pipe.
819 @@ -795,6 +796,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
820 return warn_unsupported(in, "read");
821 return in->f_op->splice_read(in, ppos, pipe, len, flags);
823 +EXPORT_SYMBOL_GPL(do_splice_to);
826 * splice_direct_to_actor - splices data directly between two non-pipes
827 diff --git a/fs/sync.c b/fs/sync.c
828 index b7b5a0a0df6ff..fa5c7fba7f1ba 100644
831 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
832 sb->s_op->sync_fs(sb, wait);
833 return __sync_blockdev(sb->s_bdev, wait);
835 +EXPORT_SYMBOL_GPL(__sync_filesystem);
838 * Write out and wait upon all dirty data associated with this
839 diff --git a/fs/xattr.c b/fs/xattr.c
840 index 5c8c5175b385c..ff7e9ff774b73 100644
843 @@ -384,6 +384,7 @@ vfs_getxattr_alloc(struct user_namespace *mnt_userns, struct dentry *dentry,
844 *xattr_value = value;
847 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
850 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
851 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
852 index e0aaf34974df5..d7b737731d4ef 100644
853 --- a/kernel/locking/lockdep.c
854 +++ b/kernel/locking/lockdep.c
855 @@ -210,6 +210,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
857 return lock_classes + class_idx;
859 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
860 #define hlock_class(hlock) lockdep_hlock_class(hlock)
862 #ifdef CONFIG_LOCK_STAT
863 diff --git a/kernel/task_work.c b/kernel/task_work.c
864 index 1698fbe6f0e13..081b05acadf82 100644
865 --- a/kernel/task_work.c
866 +++ b/kernel/task_work.c
867 @@ -167,3 +167,4 @@ void task_work_run(void)
871 +EXPORT_SYMBOL_GPL(task_work_run);
872 diff --git a/security/security.c b/security/security.c
873 index 9ffa9e9c5c554..83b533a3fb8e8 100644
874 --- a/security/security.c
875 +++ b/security/security.c
876 @@ -1147,6 +1147,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
878 return call_int_hook(path_rmdir, 0, dir, dentry);
880 +EXPORT_SYMBOL_GPL(security_path_rmdir);
882 int security_path_unlink(const struct path *dir, struct dentry *dentry)
884 @@ -1163,6 +1164,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
886 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
888 +EXPORT_SYMBOL_GPL(security_path_symlink);
890 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
891 struct dentry *new_dentry)
892 @@ -1171,6 +1173,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
894 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
896 +EXPORT_SYMBOL_GPL(security_path_link);
898 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
899 const struct path *new_dir, struct dentry *new_dentry,
900 @@ -1198,6 +1201,7 @@ int security_path_truncate(const struct path *path)
902 return call_int_hook(path_truncate, 0, path);
904 +EXPORT_SYMBOL_GPL(security_path_truncate);
906 int security_path_chmod(const struct path *path, umode_t mode)
908 @@ -1205,6 +1209,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
910 return call_int_hook(path_chmod, 0, path, mode);
912 +EXPORT_SYMBOL_GPL(security_path_chmod);
914 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
916 @@ -1212,6 +1217,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
918 return call_int_hook(path_chown, 0, path, uid, gid);
920 +EXPORT_SYMBOL_GPL(security_path_chown);
922 int security_path_chroot(const struct path *path)
924 @@ -1312,6 +1318,7 @@ int security_inode_permission(struct inode *inode, int mask)
926 return call_int_hook(inode_permission, 0, inode, mask);
928 +EXPORT_SYMBOL_GPL(security_inode_permission);
930 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
932 @@ -1509,6 +1516,7 @@ int security_file_permission(struct file *file, int mask)
934 return fsnotify_perm(file, mask);
936 +EXPORT_SYMBOL_GPL(security_file_permission);
938 int security_file_alloc(struct file *file)
940 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
941 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
942 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-11-01 23:48:34.199692595 +0100
944 +What: /debug/aufs/si_<id>/
946 +Contact: J. R. Okajima <hooanon05g@gmail.com>
948 + Under /debug/aufs, a directory named si_<id> is created
949 + per aufs mount, where <id> is a unique id generated
952 +What: /debug/aufs/si_<id>/plink
954 +Contact: J. R. Okajima <hooanon05g@gmail.com>
956 + It has three lines and shows the information about the
957 + pseudo-link. The first line is a single number
958 + representing a number of buckets. The second line is a
959 + number of pseudo-links per buckets (separated by a
960 + blank). The last line is a single number representing a
961 + total number of psedo-links.
962 + When the aufs mount option 'noplink' is specified, it
963 + will show "1\n0\n0\n".
965 +What: /debug/aufs/si_<id>/xib
967 +Contact: J. R. Okajima <hooanon05g@gmail.com>
969 + It shows the consumed blocks by xib (External Inode Number
970 + Bitmap), its block size and file size.
971 + When the aufs mount option 'noxino' is specified, it
972 + will be empty. About XINO files, see the aufs manual.
974 +What: /debug/aufs/si_<id>/xi<branch-index>
976 +Contact: J. R. Okajima <hooanon05g@gmail.com>
978 + It shows the consumed blocks by xino (External Inode Number
979 + Translation Table), its link count, block size and file
981 + Due to the file size limit, there may exist multiple
982 + xino files per branch. In this case, "-N" is added to
983 + the filename and it corresponds to the index of the
984 + internal xino array. "-0" is omitted.
985 + When the aufs mount option 'noxino' is specified, Those
986 + entries won't exist. About XINO files, see the aufs
989 +What: /debug/aufs/si_<id>/xigen
991 +Contact: J. R. Okajima <hooanon05g@gmail.com>
993 + It shows the consumed blocks by xigen (External Inode
994 + Generation Table), its block size and file size.
995 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
997 + When the aufs mount option 'noxino' is specified, it
998 + will be empty. About XINO files, see the aufs manual.
999 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1000 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1001 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-11-01 23:48:34.199692595 +0100
1003 +What: /sys/fs/aufs/si_<id>/
1005 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1007 + Under /sys/fs/aufs, a directory named si_<id> is created
1008 + per aufs mount, where <id> is a unique id generated
1011 +What: /sys/fs/aufs/si_<id>/br<idx>
1013 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1015 + It shows the abolute path of a member directory (which
1016 + is called branch) in aufs, and its permission.
1018 +What: /sys/fs/aufs/si_<id>/brid<idx>
1020 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1022 + It shows the id of a member directory (which is called
1025 +What: /sys/fs/aufs/si_<id>/xi_path
1027 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1029 + It shows the abolute path of XINO (External Inode Number
1030 + Bitmap, Translation Table and Generation Table) file
1031 + even if it is the default path.
1032 + When the aufs mount option 'noxino' is specified, it
1033 + will be empty. About XINO files, see the aufs manual.
1034 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1035 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1036 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-11-01 23:48:34.199692595 +0100
1039 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1041 +# This program is free software; you can redistribute it and/or modify
1042 +# it under the terms of the GNU General Public License as published by
1043 +# the Free Software Foundation; either version 2 of the License, or
1044 +# (at your option) any later version.
1046 +# This program is distributed in the hope that it will be useful,
1047 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1048 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1049 +# GNU General Public License for more details.
1051 +# You should have received a copy of the GNU General Public License
1052 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1055 +----------------------------------------
1057 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1058 +1. abbrev. for "advanced multi-layered unification filesystem".
1059 +2. abbrev. for "another unionfs".
1060 +3. abbrev. for "auf das" in German which means "on the" in English.
1061 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1062 + But "Filesystem aufs Filesystem" is hard to understand.
1063 +4. abbrev. for "African Urban Fashion Show".
1065 +AUFS is a filesystem with features:
1066 +- multi layered stackable unification filesystem, the member directory
1067 + is called as a branch.
1068 +- branch permission and attribute, 'readonly', 'real-readonly',
1069 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1071 +- internal "file copy-on-write".
1072 +- logical deletion, whiteout.
1073 +- dynamic branch manipulation, adding, deleting and changing permission.
1074 +- allow bypassing aufs, user's direct branch access.
1075 +- external inode number translation table and bitmap which maintains the
1076 + persistent aufs inode number.
1077 +- seekable directory, including NFS readdir.
1078 +- file mapping, mmap and sharing pages.
1079 +- pseudo-link, hardlink over branches.
1080 +- loopback mounted filesystem as a branch.
1081 +- several policies to select one among multiple writable branches.
1082 +- revert a single systemcall when an error occurs in aufs.
1086 +Multi Layered Stackable Unification Filesystem
1087 +----------------------------------------------------------------------
1088 +Most people already knows what it is.
1089 +It is a filesystem which unifies several directories and provides a
1090 +merged single directory. When users access a file, the access will be
1091 +passed/re-directed/converted (sorry, I am not sure which English word is
1092 +correct) to the real file on the member filesystem. The member
1093 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1094 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1095 +readonly branch is handled by creating 'whiteout' on the upper writable
1098 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1099 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1100 +different approaches to implement the merged-view.
1101 +The former tries putting it into VFS, and the latter implements as a
1102 +separate filesystem.
1103 +(If I misunderstand about these implementations, please let me know and
1104 +I shall correct it. Because it is a long time ago when I read their
1105 +source files last time).
1107 +UnionMount's approach will be able to small, but may be hard to share
1108 +branches between several UnionMount since the whiteout in it is
1109 +implemented in the inode on branch filesystem and always
1110 +shared. According to Bharata's post, readdir does not seems to be
1112 +There are several missing features known in this implementations such as
1113 +- for users, the inode number may change silently. eg. copy-up.
1114 +- link(2) may break by copy-up.
1115 +- read(2) may get an obsoleted filedata (fstat(2) too).
1116 +- fcntl(F_SETLK) may be broken by copy-up.
1117 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1120 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1121 +merged into mainline. This is another implementation of UnionMount as a
1122 +separated filesystem. All the limitations and known problems which
1123 +UnionMount are equally inherited to "overlay" filesystem.
1125 +Unionfs has a longer history. When I started implementing a stackable
1126 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1127 +inode, dentry and file objects and they have an array pointing lower
1128 +same kind objects. After contributing many patches for Unionfs, I
1129 +re-started my project AUFS (Jun 2006).
1131 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1132 +implemented my own ideas, approaches and enhancements and it became
1133 +totally different one.
1135 +Comparing DM snapshot and fs based implementation
1136 +- the number of bytes to be copied between devices is much smaller.
1137 +- the type of filesystem must be one and only.
1138 +- the fs must be writable, no readonly fs, even for the lower original
1139 + device. so the compression fs will not be usable. but if we use
1140 + loopback mount, we may address this issue.
1142 + mount /cdrom/squashfs.img /sq
1143 + losetup /sq/ext2.img
1144 + losetup /somewhere/cow
1145 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1146 +- it will be difficult (or needs more operations) to extract the
1147 + difference between the original device and COW.
1148 +- DM snapshot-merge may help a lot when users try merging. in the
1149 + fs-layer union, users will use rsync(1).
1151 +You may want to read my old paper "Filesystems in LiveCD"
1152 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1155 +Several characters/aspects/persona of aufs
1156 +----------------------------------------------------------------------
1158 +Aufs has several characters, aspects or persona.
1159 +1. a filesystem, callee of VFS helper
1160 +2. sub-VFS, caller of VFS helper for branches
1161 +3. a virtual filesystem which maintains persistent inode number
1162 +4. reader/writer of files on branches such like an application
1164 +1. Callee of VFS Helper
1165 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1166 +unlink(2) from an application reaches sys_unlink() kernel function and
1167 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1168 +calls filesystem specific unlink operation. Actually aufs implements the
1169 +unlink operation but it behaves like a redirector.
1171 +2. Caller of VFS Helper for Branches
1172 +aufs_unlink() passes the unlink request to the branch filesystem as if
1173 +it were called from VFS. So the called unlink operation of the branch
1174 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1175 +every necessary pre/post operation for the branch filesystem.
1176 +- acquire the lock for the parent dir on a branch
1177 +- lookup in a branch
1178 +- revalidate dentry on a branch
1179 +- mnt_want_write() for a branch
1180 +- vfs_unlink() for a branch
1181 +- mnt_drop_write() for a branch
1182 +- release the lock on a branch
1184 +3. Persistent Inode Number
1185 +One of the most important issue for a filesystem is to maintain inode
1186 +numbers. This is particularly important to support exporting a
1187 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1188 +backend block device for its own. But some storage is necessary to
1189 +keep and maintain the inode numbers. It may be a large space and may not
1190 +suit to keep in memory. Aufs rents some space from its first writable
1191 +branch filesystem (by default) and creates file(s) on it. These files
1192 +are created by aufs internally and removed soon (currently) keeping
1194 +Note: Because these files are removed, they are totally gone after
1195 + unmounting aufs. It means the inode numbers are not persistent
1196 + across unmount or reboot. I have a plan to make them really
1197 + persistent which will be important for aufs on NFS server.
1199 +4. Read/Write Files Internally (copy-on-write)
1200 +Because a branch can be readonly, when you write a file on it, aufs will
1201 +"copy-up" it to the upper writable branch internally. And then write the
1202 +originally requested thing to the file. Generally kernel doesn't
1203 +open/read/write file actively. In aufs, even a single write may cause a
1204 +internal "file copy". This behaviour is very similar to cp(1) command.
1206 +Some people may think it is better to pass such work to user space
1207 +helper, instead of doing in kernel space. Actually I am still thinking
1208 +about it. But currently I have implemented it in kernel space.
1209 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1210 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1211 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-11-01 23:48:34.199692595 +0100
1214 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1216 +# This program is free software; you can redistribute it and/or modify
1217 +# it under the terms of the GNU General Public License as published by
1218 +# the Free Software Foundation; either version 2 of the License, or
1219 +# (at your option) any later version.
1221 +# This program is distributed in the hope that it will be useful,
1222 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1223 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1224 +# GNU General Public License for more details.
1226 +# You should have received a copy of the GNU General Public License
1227 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1229 +Basic Aufs Internal Structure
1231 +Superblock/Inode/Dentry/File Objects
1232 +----------------------------------------------------------------------
1233 +As like an ordinary filesystem, aufs has its own
1234 +superblock/inode/dentry/file objects. All these objects have a
1235 +dynamically allocated array and store the same kind of pointers to the
1236 +lower filesystem, branch.
1237 +For example, when you build a union with one readwrite branch and one
1238 +readonly, mounted /au, /rw and /ro respectively.
1240 +- /ro/fileA exists but /rw/fileA
1242 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1243 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1244 +- [0] = NULL (because /rw/fileA doesn't exist)
1247 +This style of an array is essentially same to the aufs
1248 +superblock/inode/dentry/file objects.
1250 +Because aufs supports manipulating branches, ie. add/delete/change
1251 +branches dynamically, these objects has its own generation. When
1252 +branches are changed, the generation in aufs superblock is
1253 +incremented. And a generation in other object are compared when it is
1254 +accessed. When a generation in other objects are obsoleted, aufs
1255 +refreshes the internal array.
1259 +----------------------------------------------------------------------
1260 +Additionally aufs superblock has some data for policies to select one
1261 +among multiple writable branches, XIB files, pseudo-links and kobject.
1262 +See below in detail.
1263 +About the policies which supports copy-down a directory, see
1264 +wbr_policy.txt too.
1267 +Branch and XINO(External Inode Number Translation Table)
1268 +----------------------------------------------------------------------
1269 +Every branch has its own xino (external inode number translation table)
1270 +file. The xino file is created and unlinked by aufs internally. When two
1271 +members of a union exist on the same filesystem, they share the single
1273 +The struct of a xino file is simple, just a sequence of aufs inode
1274 +numbers which is indexed by the lower inode number.
1275 +In the above sample, assume the inode number of /ro/fileA is i111 and
1276 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1277 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1279 +When the inode numbers are not contiguous, the xino file will be sparse
1280 +which has a hole in it and doesn't consume as much disk space as it
1281 +might appear. If your branch filesystem consumes disk space for such
1282 +holes, then you should specify 'xino=' option at mounting aufs.
1284 +Aufs has a mount option to free the disk blocks for such holes in XINO
1285 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1286 +meet a problem of disk shortage due to XINO files, then you should try
1287 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1288 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1289 +the holes in XINO files.
1291 +Also a writable branch has three kinds of "whiteout bases". All these
1292 +are existed when the branch is joined to aufs, and their names are
1293 +whiteout-ed doubly, so that users will never see their names in aufs
1295 +1. a regular file which will be hardlinked to all whiteouts.
1296 +2. a directory to store a pseudo-link.
1297 +3. a directory to store an "orphan"-ed file temporary.
1300 + When you remove a file on a readonly branch, aufs handles it as a
1301 + logical deletion and creates a whiteout on the upper writable branch
1302 + as a hardlink of this file in order not to consume inode on the
1305 + See below, Pseudo-link.
1307 + When "fileC" exists on the lower readonly branch only and it is
1308 + opened and removed with its parent dir, and then user writes
1309 + something into it, then aufs copies-up fileC to this
1310 + directory. Because there is no other dir to store fileC. After
1311 + creating a file under this dir, the file is unlinked.
1313 +Because aufs supports manipulating branches, ie. add/delete/change
1314 +dynamically, a branch has its own id. When the branch order changes,
1315 +aufs finds the new index by searching the branch id.
1319 +----------------------------------------------------------------------
1320 +Assume "fileA" exists on the lower readonly branch only and it is
1321 +hardlinked to "fileB" on the branch. When you write something to fileA,
1322 +aufs copies-up it to the upper writable branch. Additionally aufs
1323 +creates a hardlink under the Pseudo-link Directory of the writable
1324 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1325 +simple list. If fileB is read after unlinking fileA, aufs returns
1326 +filedata from the pseudo-link instead of the lower readonly
1327 +branch. Because the pseudo-link is based upon the inode, to keep the
1328 +inode number by xino (see above) is essentially necessary.
1330 +All the hardlinks under the Pseudo-link Directory of the writable branch
1331 +should be restored in a proper location later. Aufs provides a utility
1332 +to do this. The userspace helpers executed at remounting and unmounting
1334 +During this utility is running, it puts aufs into the pseudo-link
1335 +maintenance mode. In this mode, only the process which began the
1336 +maintenance mode (and its child processes) is allowed to operate in
1337 +aufs. Some other processes which are not related to the pseudo-link will
1338 +be allowed to run too, but the rest have to return an error or wait
1339 +until the maintenance mode ends. If a process already acquires an inode
1340 +mutex (in VFS), it has to return an error.
1343 +XIB(external inode number bitmap)
1344 +----------------------------------------------------------------------
1345 +Addition to the xino file per a branch, aufs has an external inode number
1346 +bitmap in a superblock object. It is also an internal file such like a
1348 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1350 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1352 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1353 +reduce the number of consumed disk blocks for these files.
1356 +Virtual or Vertical Dir, and Readdir in Userspace
1357 +----------------------------------------------------------------------
1358 +In order to support multiple layers (branches), aufs readdir operation
1359 +constructs a virtual dir block on memory. For readdir, aufs calls
1360 +vfs_readdir() internally for each dir on branches, merges their entries
1361 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1362 +object. So the file object has its entry list until it is closed. The
1363 +entry list will be updated when the file position is zero and becomes
1364 +obsoleted. This decision is made in aufs automatically.
1366 +The dynamically allocated memory block for the name of entries has a
1367 +unit of 512 bytes (by default) and stores the names contiguously (no
1368 +padding). Another block for each entry is handled by kmem_cache too.
1369 +During building dir blocks, aufs creates hash list and judging whether
1370 +the entry is whiteouted by its upper branch or already listed.
1371 +The merged result is cached in the corresponding inode object and
1372 +maintained by a customizable life-time option.
1374 +Some people may call it can be a security hole or invite DoS attack
1375 +since the opened and once readdir-ed dir (file object) holds its entry
1376 +list and becomes a pressure for system memory. But I'd say it is similar
1377 +to files under /proc or /sys. The virtual files in them also holds a
1378 +memory page (generally) while they are opened. When an idea to reduce
1379 +memory for them is introduced, it will be applied to aufs too.
1380 +For those who really hate this situation, I've developed readdir(3)
1381 +library which operates this merging in userspace. You just need to set
1382 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1383 +kernel space for readdir(3).
1387 +----------------------------------------------------------------------
1388 +Aufs sometimes requires privilege access to a branch. For instance,
1389 +in copy-up/down operation. When a user process is going to make changes
1390 +to a file which exists in the lower readonly branch only, and the mode
1391 +of one of ancestor directories may not be writable by a user
1392 +process. Here aufs copy-up the file with its ancestors and they may
1393 +require privilege to set its owner/group/mode/etc.
1394 +This is a typical case of a application character of aufs (see
1397 +Aufs uses workqueue synchronously for this case. It creates its own
1398 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1399 +passes the request to call mkdir or write (for example), and wait for
1400 +its completion. This approach solves a problem of a signal handler
1402 +If aufs didn't adopt the workqueue and changed the privilege of the
1403 +process, then the process may receive the unexpected SIGXFSZ or other
1406 +Also aufs uses the system global workqueue ("events" kernel thread) too
1407 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1408 +whiteout base and etc. This is unrelated to a privilege.
1409 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1410 +superblock at the beginning, at the same time waits for the completion
1411 +of all queued asynchronous tasks.
1415 +----------------------------------------------------------------------
1416 +The whiteout in aufs is very similar to Unionfs's. That is represented
1417 +by its filename. UnionMount takes an approach of a file mode, but I am
1418 +afraid several utilities (find(1) or something) will have to support it.
1420 +Basically the whiteout represents "logical deletion" which stops aufs to
1421 +lookup further, but also it represents "dir is opaque" which also stop
1424 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1425 +In order to make several functions in a single systemcall to be
1426 +revertible, aufs adopts an approach to rename a directory to a temporary
1427 +unique whiteouted name.
1428 +For example, in rename(2) dir where the target dir already existed, aufs
1429 +renames the target dir to a temporary unique whiteouted name before the
1430 +actual rename on a branch, and then handles other actions (make it opaque,
1431 +update the attributes, etc). If an error happens in these actions, aufs
1432 +simply renames the whiteouted name back and returns an error. If all are
1433 +succeeded, aufs registers a function to remove the whiteouted unique
1434 +temporary name completely and asynchronously to the system global
1439 +----------------------------------------------------------------------
1440 +It is a well-known feature or concept.
1441 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1442 +internally and makes change to the new file on the upper writable branch.
1443 +When the trigger systemcall does not update the timestamps of the parent
1444 +dir, aufs reverts it after copy-up.
1447 +Move-down (aufs3.9 and later)
1448 +----------------------------------------------------------------------
1449 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1450 +the lower readonly branch to the upper writable branch when a user
1451 +changes something about the file.
1452 +"Move-down" is an opposite action of copy-up. Basically this action is
1453 +ran manually instead of automatically and internally.
1454 +For desgin and implementation, aufs has to consider these issues.
1455 +- whiteout for the file may exist on the lower branch.
1456 +- ancestor directories may not exist on the lower branch.
1457 +- diropq for the ancestor directories may exist on the upper branch.
1458 +- free space on the lower branch will reduce.
1459 +- another access to the file may happen during moving-down, including
1460 + UDBA (see "Revalidate Dentry and UDBA").
1461 +- the file should not be hard-linked nor pseudo-linked. they should be
1462 + handled by auplink utility later.
1464 +Sometimes users want to move-down a file from the upper writable branch
1465 +to the lower readonly or writable branch. For instance,
1466 +- the free space of the upper writable branch is going to run out.
1467 +- create a new intermediate branch between the upper and lower branch.
1470 +For this purpose, use "aumvdown" command in aufs-util.git.
1471 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1472 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1473 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-11-01 23:48:34.203025928 +0100
1476 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1478 +# This program is free software; you can redistribute it and/or modify
1479 +# it under the terms of the GNU General Public License as published by
1480 +# the Free Software Foundation; either version 2 of the License, or
1481 +# (at your option) any later version.
1483 +# This program is distributed in the hope that it will be useful,
1484 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1485 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1486 +# GNU General Public License for more details.
1488 +# You should have received a copy of the GNU General Public License
1489 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1491 +Support for a branch who has its ->atomic_open()
1492 +----------------------------------------------------------------------
1493 +The filesystems who implement its ->atomic_open() are not majority. For
1494 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1495 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1496 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1497 +sure whether all filesystems who have ->atomic_open() behave like this,
1498 +but NFSv4 surely returns the error.
1500 +In order to support ->atomic_open() for aufs, there are a few
1503 +A. Introduce aufs_atomic_open()
1504 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1506 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1507 + an aufs user Pip Cet's approach
1508 + - calls aufs_create(), VFS finish_open() and notify_change().
1509 + - pass fake-mode to finish_open(), and then correct the mode by
1511 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1512 + - no aufs_atomic_open().
1513 + - aufs_lookup() registers the TID to an aufs internal object.
1514 + - aufs_create() does nothing when the matching TID is registered, but
1515 + registers the mode.
1516 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1517 + TID is registered.
1518 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1520 + - no aufs_atomic_open().
1521 + - aufs_create() registers the TID to an internal object. this info
1522 + represents "this process created this file just now."
1523 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1524 + registered TID and re-try open() with superuser's credential.
1526 +Pros and cons for each approach.
1529 + - straightforward but highly depends upon VFS internal.
1530 + - the atomic behavaiour is kept.
1531 + - some of parameters such as nameidata are hard to reproduce for
1535 + - easy to implement.
1536 + - the atomic behavaiour is lost.
1538 + - the atomic behavaiour is kept.
1539 + - dirty and tricky.
1540 + - VFS checks whether the file is created correctly after calling
1541 + ->create(), which means this approach doesn't work.
1543 + - easy to implement.
1544 + - the atomic behavaiour is lost.
1545 + - to open a file with superuser's credential and give it to a user
1546 + process is a bad idea, since the file object keeps the credential
1547 + in it. It may affect LSM or something. This approach doesn't work
1550 +The approach A is ideal, but it hard to implement. So here is a
1551 +variation of A, which is to be implemented.
1553 +A-1. Introduce aufs_atomic_open()
1554 + - calls branch fs ->atomic_open() if exists. otherwise calls
1555 + vfs_create() and finish_open().
1556 + - the demerit is that the several checks after branch fs
1557 + ->atomic_open() are lost. in the ordinary case, the checks are
1558 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1559 + be implemented in aufs, but not all I am afraid.
1560 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1561 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1562 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-11-01 23:48:34.203025928 +0100
1565 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1567 +# This program is free software; you can redistribute it and/or modify
1568 +# it under the terms of the GNU General Public License as published by
1569 +# the Free Software Foundation; either version 2 of the License, or
1570 +# (at your option) any later version.
1572 +# This program is distributed in the hope that it will be useful,
1573 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1574 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1575 +# GNU General Public License for more details.
1577 +# You should have received a copy of the GNU General Public License
1578 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1581 +----------------------------------------------------------------------
1582 +Since aufs has a character of sub-VFS (see Introduction), it operates
1583 +lookup for branches as VFS does. It may be a heavy work. But almost all
1584 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1585 +directly connected to its parent. Digging down the directory hierarchy
1586 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1589 +When a branch is a remote filesystem, aufs basically relies upon its
1590 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1592 +For d_revalidate, aufs implements three levels of revalidate tests. See
1593 +"Revalidate Dentry and UDBA" in detail.
1596 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1597 +----------------------------------------------------------------------
1598 +Let's try case study.
1599 +- aufs has two branches, upper readwrite and lower readonly.
1601 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1602 +- user invoked "chmod a+rx /au/dirA"
1603 +- the internal copy-up is activated and "/rw/dirA" is created and its
1604 + permission bits are set to world readable.
1605 +- then "/au/dirA" becomes world readable?
1607 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1608 +or it may be a natively readonly filesystem. If aufs respects the lower
1609 +branch, it should not respond readdir request from other users. But user
1610 +allowed it by chmod. Should really aufs rejects showing the entries
1613 +To be honest, I don't have a good solution for this case. So aufs
1614 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1616 +When dirperm1 is specified, aufs checks only the highest one for the
1617 +directory permission, and shows the entries. Otherwise, as usual, checks
1618 +every dir existing on all branches and rejects the request.
1620 +As a side effect, dirperm1 option improves the performance of aufs
1621 +because the number of permission check is reduced when the number of
1625 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1626 +----------------------------------------------------------------------
1627 +Generally VFS helpers re-validate a dentry as a part of lookup.
1628 +0. digging down the directory hierarchy.
1629 +1. lock the parent dir by its i_mutex.
1630 +2. lookup the final (child) entry.
1632 +4. call the actual operation (create, unlink, etc.)
1633 +5. unlock the parent dir
1635 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1636 +called. Actually aufs implements it and checks the dentry on a branch is
1638 +But it is not enough. Because aufs has to release the lock for the
1639 +parent dir on a branch at the end of ->lookup() (step 2) and
1640 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1642 +If the file on a branch is changed directly, eg. bypassing aufs, after
1643 +aufs released the lock, then the subsequent operation may cause
1644 +something unpleasant result.
1646 +This situation is a result of VFS architecture, ->lookup() and
1647 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1648 +design from VFS's point of view. It is just not suitable for sub-VFS
1651 +Aufs supports such case by three level of revalidation which is
1652 +selectable by user.
1653 +1. Simple Revalidate
1654 + Addition to the native flow in VFS's, confirm the child-parent
1655 + relationship on the branch just after locking the parent dir on the
1656 + branch in the "actual operation" (step 4). When this validation
1657 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1658 + checks the validation of the dentry on branches.
1659 +2. Monitor Changes Internally by Inotify/Fsnotify
1660 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1661 + the dentry on the branch, and returns EBUSY if it finds different
1663 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1664 + during it is in cache. When the event is notified, aufs registers a
1665 + function to kernel 'events' thread by schedule_work(). And the
1666 + function sets some special status to the cached aufs dentry and inode
1667 + private data. If they are not cached, then aufs has nothing to
1668 + do. When the same file is accessed through aufs (step 0-3) later,
1669 + aufs will detect the status and refresh all necessary data.
1670 + In this mode, aufs has to ignore the event which is fired by aufs
1672 +3. No Extra Validation
1673 + This is the simplest test and doesn't add any additional revalidation
1674 + test, and skip the revalidation in step 4. It is useful and improves
1675 + aufs performance when system surely hide the aufs branches from user,
1676 + by over-mounting something (or another method).
1677 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1678 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1679 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-11-01 23:48:34.203025928 +0100
1682 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1684 +# This program is free software; you can redistribute it and/or modify
1685 +# it under the terms of the GNU General Public License as published by
1686 +# the Free Software Foundation; either version 2 of the License, or
1687 +# (at your option) any later version.
1689 +# This program is distributed in the hope that it will be useful,
1690 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1691 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1692 +# GNU General Public License for more details.
1694 +# You should have received a copy of the GNU General Public License
1695 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1697 +Branch Manipulation
1699 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1700 +and changing its permission/attribute, there are a lot of works to do.
1704 +----------------------------------------------------------------------
1705 +o Confirm the adding dir exists outside of aufs, including loopback
1706 + mount, and its various attributes.
1707 +o Initialize the xino file and whiteout bases if necessary.
1710 +o Check the owner/group/mode of the directory
1711 + When the owner/group/mode of the adding directory differs from the
1712 + existing branch, aufs issues a warning because it may impose a
1714 + For example, when a upper writable branch has a world writable empty
1715 + top directory, a malicious user can create any files on the writable
1716 + branch directly, like copy-up and modify manually. If something like
1717 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1718 + writable branch, and the writable branch is world-writable, then a
1719 + malicious guy may create /etc/passwd on the writable branch directly
1720 + and the infected file will be valid in aufs.
1721 + I am afraid it can be a security issue, but aufs can do nothing except
1722 + producing a warning.
1726 +----------------------------------------------------------------------
1727 +o Confirm the deleting branch is not busy
1728 + To be general, there is one merit to adopt "remount" interface to
1729 + manipulate branches. It is to discard caches. At deleting a branch,
1730 + aufs checks the still cached (and connected) dentries and inodes. If
1731 + there are any, then they are all in-use. An inode without its
1732 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1734 + For the cached one, aufs checks whether the same named entry exists on
1736 + If the cached one is a directory, because aufs provides a merged view
1737 + to users, as long as one dir is left on any branch aufs can show the
1738 + dir to users. In this case, the branch can be removed from aufs.
1739 + Otherwise aufs rejects deleting the branch.
1741 + If any file on the deleting branch is opened by aufs, then aufs
1745 +Modify the Permission of a Branch
1746 +----------------------------------------------------------------------
1747 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1750 +o rw --> ro: Confirm the modifying branch is not busy
1751 + Aufs rejects the request if any of these conditions are true.
1752 + - a file on the branch is mmap-ed.
1753 + - a regular file on the branch is opened for write and there is no
1754 + same named entry on the upper branch.
1755 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1756 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1757 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-11-01 23:48:34.203025928 +0100
1760 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1762 +# This program is free software; you can redistribute it and/or modify
1763 +# it under the terms of the GNU General Public License as published by
1764 +# the Free Software Foundation; either version 2 of the License, or
1765 +# (at your option) any later version.
1767 +# This program is distributed in the hope that it will be useful,
1768 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1769 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1770 +# GNU General Public License for more details.
1772 +# You should have received a copy of the GNU General Public License
1773 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1775 +Policies to Select One among Multiple Writable Branches
1776 +----------------------------------------------------------------------
1777 +When the number of writable branch is more than one, aufs has to decide
1778 +the target branch for file creation or copy-up. By default, the highest
1779 +writable branch which has the parent (or ancestor) dir of the target
1780 +file is chosen (top-down-parent policy).
1781 +By user's request, aufs implements some other policies to select the
1782 +writable branch, for file creation several policies, round-robin,
1783 +most-free-space, and other policies. For copy-up, top-down-parent,
1784 +bottom-up-parent, bottom-up and others.
1786 +As expected, the round-robin policy selects the branch in circular. When
1787 +you have two writable branches and creates 10 new files, 5 files will be
1788 +created for each branch. mkdir(2) systemcall is an exception. When you
1789 +create 10 new directories, all will be created on the same branch.
1790 +And the most-free-space policy selects the one which has most free
1791 +space among the writable branches. The amount of free space will be
1792 +checked by aufs internally, and users can specify its time interval.
1794 +The policies for copy-up is more simple,
1795 +top-down-parent is equivalent to the same named on in create policy,
1796 +bottom-up-parent selects the writable branch where the parent dir
1797 +exists and the nearest upper one from the copyup-source,
1798 +bottom-up selects the nearest upper writable branch from the
1799 +copyup-source, regardless the existence of the parent dir.
1801 +There are some rules or exceptions to apply these policies.
1802 +- If there is a readonly branch above the policy-selected branch and
1803 + the parent dir is marked as opaque (a variation of whiteout), or the
1804 + target (creating) file is whiteout-ed on the upper readonly branch,
1805 + then the result of the policy is ignored and the target file will be
1806 + created on the nearest upper writable branch than the readonly branch.
1807 +- If there is a writable branch above the policy-selected branch and
1808 + the parent dir is marked as opaque or the target file is whiteouted
1809 + on the branch, then the result of the policy is ignored and the target
1810 + file will be created on the highest one among the upper writable
1811 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1813 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1814 + They try selecting the branch where the source exists as possible
1815 + since copyup a large file will take long time. If it can't be,
1816 + ie. the branch where the source exists is readonly, then they will
1817 + follow the copyup policy.
1818 +- There is an exception for rename(2) when the target exists.
1819 + If the rename target exists, aufs compares the index of the branches
1820 + where the source and the target exists and selects the higher
1821 + one. If the selected branch is readonly, then aufs follows the
1823 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1824 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1825 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-11-01 23:48:34.203025928 +0100
1828 +// to view this graph, run dot(1) command in GRAPHVIZ.
1832 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1836 +aufs_rename -> whinfo [label="store/remove"];
1839 +inode_list [label="h_inum list in branch\ncache"];
1842 +whinode [label="h_inum list file"];
1845 +brmgmt [label="br_add/del/mod/umount"];
1847 +brmgmt -> inode_list [label="create/remove"];
1848 +brmgmt -> whinode [label="load/store"];
1850 +inode_list -> whinode [style=dashed,dir=both];
1852 +aufs_rename -> inode_list [label="add/del"];
1854 +aufs_lookup -> inode_list [label="search"];
1856 +aufs_lookup -> whinfo [label="load/remove"];
1858 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1859 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1860 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-11-01 23:48:34.203025928 +0100
1863 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1865 +# This program is free software; you can redistribute it and/or modify
1866 +# it under the terms of the GNU General Public License as published by
1867 +# the Free Software Foundation; either version 2 of the License, or
1868 +# (at your option) any later version.
1870 +# This program is distributed in the hope that it will be useful,
1871 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1872 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1873 +# GNU General Public License for more details.
1875 +# You should have received a copy of the GNU General Public License
1876 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1878 +Special handling for renaming a directory (DIRREN)
1879 +----------------------------------------------------------------------
1880 +First, let's assume we have a simple usecase.
1884 +- /ro/dirA and /ro/dirA/file exist too
1885 +- there is no dirB on both branches
1886 +- a user issues rename("dirA", "dirB")
1888 +Now, what should aufs behave against this rename(2)?
1889 +There are a few possible cases.
1892 + since dirA exists on a readonly branch which cannot be renamed.
1894 + it is possible to copy-up dirA (only the dir itself), but the child
1895 + entries ("file" in this case) should not be. it must be a bad
1896 + approach to copy-up recursively.
1897 +C. returns a success.
1898 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1899 + is a violation of aufs' policy.
1900 +D. construct an extra information which indicates that /ro/dirA should
1901 + be handled as the name of dirB.
1902 + overlayfs has a similar feature called REDIRECT.
1904 +Until now, aufs implements the case B only which returns EXDEV, and
1905 +expects the userspace application behaves like mv(1) which tries
1906 +issueing rename(2) recursively.
1908 +A new aufs feature called DIRREN is introduced which implements the case
1909 +D. There are several "extra information" added.
1911 +1. detailed info per renamed directory
1912 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1913 +2. the inode-number list of directories on a branch
1914 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1916 +The filename of "detailed info per directory" represents the lower
1917 +branch, and its format is
1918 +- a type of the branch id
1920 + + uuid (not implemented yet)
1923 +- the inode-number of the branch root dir
1925 +And it contains these info in a single regular file.
1927 +- branch's inode-number of the logically renamed dir
1928 +- the name of the before-renamed dir
1930 +The "detailed info per directory" file is created in aufs rename(2), and
1931 +loaded in any lookup.
1932 +The info is considered in lookup for the matching case only. Here
1933 +"matching" means that the root of branch (in the info filename) is same
1934 +to the current looking-up branch. After looking-up the before-renamed
1935 +name, the inode-number is compared. And the matched dentry is used.
1937 +The "inode-number list of directories" is a regular file which contains
1938 +simply the inode-numbers on the branch. The file is created or updated
1939 +in removing the branch, and loaded in adding the branch. Its lifetime is
1940 +equal to the branch.
1941 +The list is refered in lookup, and when the current target inode is
1942 +found in the list, the aufs tries loading the "detailed info per
1943 +directory" and get the changed and valid name of the dir.
1945 +Theoretically these "extra informaiton" may be able to be put into XATTR
1946 +in the dir inode. But aufs doesn't choose this way because
1947 +1. XATTR may not be supported by the branch (or its configuration)
1948 +2. XATTR may have its size limit.
1949 +3. XATTR may be less easy to convert than a regular file, when the
1950 + format of the info is changed in the future.
1951 +At the same time, I agree that the regular file approach is much slower
1952 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1955 +This DIRREN feature is enabled by aufs configuration, and is activated
1956 +by a new mount option.
1958 +For the more complicated case, there is a work with UDBA option, which
1959 +is to dected the direct access to the branches (by-passing aufs) and to
1960 +maintain the cashes in aufs. Since a single cached aufs dentry may
1961 +contains two names, before- and after-rename, the name comparision in
1962 +UDBA handler may not work correctly. In this case, the behaviour will be
1963 +equivalen to udba=reval case.
1964 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1965 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1966 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-11-01 23:48:34.203025928 +0100
1969 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1971 +# This program is free software; you can redistribute it and/or modify
1972 +# it under the terms of the GNU General Public License as published by
1973 +# the Free Software Foundation; either version 2 of the License, or
1974 +# (at your option) any later version.
1976 +# This program is distributed in the hope that it will be useful,
1977 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1978 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1979 +# GNU General Public License for more details.
1981 +# You should have received a copy of the GNU General Public License
1982 +# along with this program; if not, write to the Free Software
1983 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1986 +File-based Hierarchical Storage Management (FHSM)
1987 +----------------------------------------------------------------------
1988 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1989 +storage world. Aufs provides this feature as file-based with multiple
1990 +writable branches, based upon the principle of "Colder, the Lower".
1991 +Here the word "colder" means that the less used files, and "lower" means
1992 +that the position in the order of the stacked branches vertically.
1993 +These multiple writable branches are prioritized, ie. the topmost one
1994 +should be the fastest drive and be used heavily.
1996 +o Characters in aufs FHSM story
1997 +- aufs itself and a new branch attribute.
1998 +- a new ioctl interface to move-down and to establish a connection with
1999 + the daemon ("move-down" is a converse of "copy-up").
2000 +- userspace tool and daemon.
2002 +The userspace daemon establishes a connection with aufs and waits for
2003 +the notification. The notified information is very similar to struct
2004 +statfs containing the number of consumed blocks and inodes.
2005 +When the consumed blocks/inodes of a branch exceeds the user-specified
2006 +upper watermark, the daemon activates its move-down process until the
2007 +consumed blocks/inodes reaches the user-specified lower watermark.
2009 +The actual move-down is done by aufs based upon the request from
2010 +user-space since we need to maintain the inode number and the internal
2011 +pointer arrays in aufs.
2013 +Currently aufs FHSM handles the regular files only. Additionally they
2014 +must not be hard-linked nor pseudo-linked.
2017 +o Cowork of aufs and the user-space daemon
2018 + During the userspace daemon established the connection, aufs sends a
2019 + small notification to it whenever aufs writes something into the
2020 + writable branch. But it may cost high since aufs issues statfs(2)
2021 + internally. So user can specify a new option to cache the
2022 + info. Actually the notification is controlled by these factors.
2023 + + the specified cache time.
2024 + + classified as "force" by aufs internally.
2025 + Until the specified time expires, aufs doesn't send the info
2026 + except the forced cases. When aufs decide forcing, the info is always
2027 + notified to userspace.
2028 + For example, the number of free inodes is generally large enough and
2029 + the shortage of it happens rarely. So aufs doesn't force the
2030 + notification when creating a new file, directory and others. This is
2031 + the typical case which aufs doesn't force.
2032 + When aufs writes the actual filedata and the files consumes any of new
2033 + blocks, the aufs forces notifying.
2036 +o Interfaces in aufs
2037 +- New branch attribute.
2039 + Specifies that the branch is managed by FHSM feature. In other word,
2040 + participant in the FHSM.
2041 + When nofhsm is set to the branch, it will not be the source/target
2042 + branch of the move-down operation. This attribute is set
2043 + independently from coo and moo attributes, and if you want full
2044 + FHSM, you should specify them as well.
2045 +- New mount option.
2047 + Specifies a second to suppress many less important info to be
2050 + + AUFS_CTL_FHSM_FD
2051 + create a new file descriptor which userspace can read the notification
2052 + (a subset of struct statfs) from aufs.
2053 +- Module parameter 'brs'
2054 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2056 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2057 + When there are two or more branches with fhsm attributes,
2058 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2059 + terminates it. As a result of remounting and branch-manipulation, the
2060 + number of branches with fhsm attribute can be one. In this case,
2061 + /sbin/mount.aufs will terminate the user-space daemon.
2064 +Finally the operation is done as these steps in kernel-space.
2066 + + no one else is using the file.
2067 + + the file is not hard-linked.
2068 + + the file is not pseudo-linked.
2069 + + the file is a regular file.
2070 + + the parent dir is not opaqued.
2071 +- find the target writable branch.
2072 +- make sure the file is not whiteout-ed by the upper (than the target)
2074 +- make the parent dir on the target branch.
2075 +- mutex lock the inode on the branch.
2076 +- unlink the whiteout on the target branch (if exists).
2077 +- lookup and create the whiteout-ed temporary name on the target branch.
2078 +- copy the file as the whiteout-ed temporary name on the target branch.
2079 +- rename the whiteout-ed temporary name to the original name.
2080 +- unlink the file on the source branch.
2081 +- maintain the internal pointer array and the external inode number
2083 +- maintain the timestamps and other attributes of the parent dir and the
2086 +And of course, in every step, an error may happen. So the operation
2087 +should restore the original file state after an error happens.
2088 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2089 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2090 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-11-01 23:48:34.203025928 +0100
2093 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2095 +# This program is free software; you can redistribute it and/or modify
2096 +# it under the terms of the GNU General Public License as published by
2097 +# the Free Software Foundation; either version 2 of the License, or
2098 +# (at your option) any later version.
2100 +# This program is distributed in the hope that it will be useful,
2101 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2102 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2103 +# GNU General Public License for more details.
2105 +# You should have received a copy of the GNU General Public License
2106 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2108 +mmap(2) -- File Memory Mapping
2109 +----------------------------------------------------------------------
2110 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2111 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2113 +This approach is simple and good, but there is one problem.
2114 +Under /proc, several entries show the mmapped files by its path (with
2115 +device and inode number), and the printed path will be the path on the
2116 +branch fs's instead of virtual aufs's.
2117 +This is not a problem in most cases, but some utilities lsof(1) (and its
2118 +user) may expect the path on aufs.
2120 +To address this issue, aufs adds a new member called vm_prfile in struct
2121 +vm_area_struct (and struct vm_region). The original vm_file points to
2122 +the file on the branch fs in order to handle everything correctly as
2123 +usual. The new vm_prfile points to a virtual file in aufs, and the
2124 +show-functions in procfs refers to vm_prfile if it is set.
2125 +Also we need to maintain several other places where touching vm_file
2127 +- fork()/clone() copies vma and the reference count of vm_file is
2129 +- merging vma maintains the ref count too.
2131 +This is not a good approach. It just fakes the printed path. But it
2132 +leaves all behaviour around f_mapping unchanged. This is surely an
2134 +Actually aufs had adopted another complicated approach which calls
2135 +generic_file_mmap() and handles struct vm_operations_struct. In this
2136 +approach, aufs met a hard problem and I could not solve it without
2137 +switching the approach.
2139 +There may be one more another approach which is
2140 +- bind-mount the branch-root onto the aufs-root internally
2141 +- grab the new vfsmount (ie. struct mount)
2142 +- lazy-umount the branch-root internally
2143 +- in open(2) the aufs-file, open the branch-file with the hidden
2144 + vfsmount (instead of the original branch's vfsmount)
2145 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2146 + but it may be possible from userspace by the mount helper.
2148 +Adding the internal hidden vfsmount and using it in opening a file, the
2149 +file path under /proc will be printed correctly. This approach looks
2150 +smarter, but is not possible I am afraid.
2151 +- aufs-root may be bind-mount later. when it happens, another hidden
2152 + vfsmount will be required.
2153 +- it is hard to get the chance to bind-mount and lazy-umount
2154 + + in kernel-space, FS can have vfsmount in open(2) via
2155 + file->f_path, and aufs can know its vfsmount. But several locks are
2156 + already acquired, and if aufs tries to bind-mount and lazy-umount
2157 + here, then it may cause a deadlock.
2158 + + in user-space, bind-mount doesn't invoke the mount helper.
2159 +- since /proc shows dev and ino, aufs has to give vma these info. it
2160 + means a new member vm_prinode will be necessary. this is essentially
2161 + equivalent to vm_prfile described above.
2163 +I have to give up this "looks-smater" approach.
2164 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2165 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2166 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-11-01 23:48:34.203025928 +0100
2169 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2171 +# This program is free software; you can redistribute it and/or modify
2172 +# it under the terms of the GNU General Public License as published by
2173 +# the Free Software Foundation; either version 2 of the License, or
2174 +# (at your option) any later version.
2176 +# This program is distributed in the hope that it will be useful,
2177 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2178 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2179 +# GNU General Public License for more details.
2181 +# You should have received a copy of the GNU General Public License
2182 +# along with this program; if not, write to the Free Software
2183 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2186 +Listing XATTR/EA and getting the value
2187 +----------------------------------------------------------------------
2188 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2189 +shows the values from the topmost existing file. This behaviour is good
2190 +for the non-dir entries since the bahaviour exactly matches the shown
2191 +information. But for the directories, aufs considers all the same named
2192 +entries on the lower branches. Which means, if one of the lower entry
2193 +rejects readdir call, then aufs returns an error even if the topmost
2194 +entry allows it. This behaviour is necessary to respect the branch fs's
2195 +security, but can make users confused since the user-visible standard
2196 +attributes don't match the behaviour.
2197 +To address this issue, aufs has a mount option called dirperm1 which
2198 +checks the permission for the topmost entry only, and ignores the lower
2199 +entry's permission.
2201 +A similar issue can happen around XATTR.
2202 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2203 +always set. Otherwise these very unpleasant situation would happen.
2204 +- listxattr(2) may return the duplicated entries.
2205 +- users may not be able to remove or reset the XATTR forever,
2208 +XATTR/EA support in the internal (copy,move)-(up,down)
2209 +----------------------------------------------------------------------
2210 +Generally the extended attributes of inode are categorized as these.
2211 +- "security" for LSM and capability.
2212 +- "system" for posix ACL, 'acl' mount option is required for the branch
2214 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2215 +- "user" for userspace, 'user_xattr' mount option is required for the
2216 + branch fs generally.
2218 +Moreover there are some other categories. Aufs handles these rather
2219 +unpopular categories as the ordinary ones, ie. there is no special
2220 +condition nor exception.
2222 +In copy-up, the support for XATTR on the dst branch may differ from the
2223 +src branch. In this case, the copy-up operation will get an error and
2224 +the original user operation which triggered the copy-up will fail. It
2225 +can happen that even all copy-up will fail.
2226 +When both of src and dst branches support XATTR and if an error occurs
2227 +during copying XATTR, then the copy-up should fail obviously. That is a
2228 +good reason and aufs should return an error to userspace. But when only
2229 +the src branch support that XATTR, aufs should not return an error.
2230 +For example, the src branch supports ACL but the dst branch doesn't
2231 +because the dst branch may natively un-support it or temporary
2232 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2233 +may NOT return an error even if the XATTR is not supported. It is
2234 +totally up to the branch fs.
2236 +Anyway when the aufs internal copy-up gets an error from the dst branch
2237 +fs, then aufs tries removing the just copied entry and returns the error
2238 +to the userspace. The worst case of this situation will be all copy-up
2241 +For the copy-up operation, there two basic approaches.
2242 +- copy the specified XATTR only (by category above), and return the
2243 + error unconditionally if it happens.
2244 +- copy all XATTR, and ignore the error on the specified category only.
2246 +In order to support XATTR and to implement the correct behaviour, aufs
2247 +chooses the latter approach and introduces some new branch attributes,
2248 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2249 +They correspond to the XATTR namespaces (see above). Additionally, to be
2250 +convenient, "icex" is also provided which means all "icex*" attributes
2251 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2253 +The meaning of these attributes is to ignore the error from setting
2254 +XATTR on that branch.
2255 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2256 +error from the dst branch according to the specified attributes.
2258 +Some XATTR may have its default value. The default value may come from
2259 +the parent dir or the environment. If the default value is set at the
2260 +file creating-time, it will be overwritten by copy-up.
2261 +Some contradiction may happen I am afraid.
2262 +Do we need another attribute to stop copying XATTR? I am unsure. For
2263 +now, aufs implements the branch attributes to ignore the error.
2264 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2265 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2266 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-11-01 23:48:34.203025928 +0100
2269 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2271 +# This program is free software; you can redistribute it and/or modify
2272 +# it under the terms of the GNU General Public License as published by
2273 +# the Free Software Foundation; either version 2 of the License, or
2274 +# (at your option) any later version.
2276 +# This program is distributed in the hope that it will be useful,
2277 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2278 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2279 +# GNU General Public License for more details.
2281 +# You should have received a copy of the GNU General Public License
2282 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2284 +Export Aufs via NFS
2285 +----------------------------------------------------------------------
2286 +Here is an approach.
2287 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2289 +- iget_locked(): initialize aufs inode generation for a new inode, and
2290 + store it in xigen file.
2291 +- destroy_inode(): increment aufs inode generation and store it in xigen
2292 + file. it is necessary even if it is not unlinked, because any data of
2293 + inode may be changed by UDBA.
2294 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2295 + build file handle by
2296 + + branch id (4 bytes)
2297 + + superblock generation (4 bytes)
2298 + + inode number (4 or 8 bytes)
2299 + + parent dir inode number (4 or 8 bytes)
2300 + + inode generation (4 bytes))
2301 + + return value of exportfs_encode_fh() for the parent on a branch (4
2303 + + file handle for a branch (by exportfs_encode_fh())
2305 + + find the index of a branch from its id in handle, and check it is
2306 + still exist in aufs.
2307 + + 1st level: get the inode number from handle and search it in cache.
2308 + + 2nd level: if not found in cache, get the parent inode number from
2309 + the handle and search it in cache. and then open the found parent
2310 + dir, find the matching inode number by vfs_readdir() and get its
2311 + name, and call lookup_one_len() for the target dentry.
2312 + + 3rd level: if the parent dir is not cached, call
2313 + exportfs_decode_fh() for a branch and get the parent on a branch,
2314 + build a pathname of it, convert it a pathname in aufs, call
2315 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2317 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2318 + for every branch, but not itself. to get this, (currently) aufs
2319 + searches in current->nsproxy->mnt_ns list. it may not be a good
2320 + idea, but I didn't get other approach.
2321 + + test the generation of the gotten inode.
2322 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2323 + convert it into ESTALE for NFSD.
2324 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2325 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2326 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2327 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2328 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-11-01 23:48:34.203025928 +0100
2331 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2333 +# This program is free software; you can redistribute it and/or modify
2334 +# it under the terms of the GNU General Public License as published by
2335 +# the Free Software Foundation; either version 2 of the License, or
2336 +# (at your option) any later version.
2338 +# This program is distributed in the hope that it will be useful,
2339 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2340 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2341 +# GNU General Public License for more details.
2343 +# You should have received a copy of the GNU General Public License
2344 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2346 +Show Whiteout Mode (shwh)
2347 +----------------------------------------------------------------------
2348 +Generally aufs hides the name of whiteouts. But in some cases, to show
2349 +them is very useful for users. For instance, creating a new middle layer
2350 +(branch) by merging existing layers.
2352 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2353 +When you have three branches,
2354 +- Bottom: 'system', squashfs (underlying base system), read-only
2355 +- Middle: 'mods', squashfs, read-only
2356 +- Top: 'overlay', ram (tmpfs), read-write
2358 +The top layer is loaded at boot time and saved at shutdown, to preserve
2359 +the changes made to the system during the session.
2360 +When larger changes have been made, or smaller changes have accumulated,
2361 +the size of the saved top layer data grows. At this point, it would be
2362 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2363 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2364 +restoring save and load speed.
2366 +This merging is simplified by the use of another aufs mount, of just the
2367 +two overlay branches using the 'shwh' option.
2368 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2369 + aufs /livesys/merge_union
2371 +A merged view of these two branches is then available at
2372 +/livesys/merge_union, and the new feature is that the whiteouts are
2374 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2375 +writing to all branches. Also the default mode for all branches is 'ro'.
2376 +It is now possible to save the combined contents of the two overlay
2377 +branches to a new squashfs, e.g.:
2378 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2380 +This new squashfs archive can be stored on the boot device and the
2381 +initramfs will use it to replace the old one at the next boot.
2382 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2383 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2384 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-11-01 23:48:34.203025928 +0100
2387 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2389 +# This program is free software; you can redistribute it and/or modify
2390 +# it under the terms of the GNU General Public License as published by
2391 +# the Free Software Foundation; either version 2 of the License, or
2392 +# (at your option) any later version.
2394 +# This program is distributed in the hope that it will be useful,
2395 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2396 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2397 +# GNU General Public License for more details.
2399 +# You should have received a copy of the GNU General Public License
2400 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2402 +Dynamically customizable FS operations
2403 +----------------------------------------------------------------------
2404 +Generally FS operations (struct inode_operations, struct
2405 +address_space_operations, struct file_operations, etc.) are defined as
2406 +"static const", but it never means that FS have only one set of
2407 +operation. Some FS have multiple sets of them. For instance, ext2 has
2408 +three sets, one for XIP, for NOBH, and for normal.
2409 +Since aufs overrides and redirects these operations, sometimes aufs has
2410 +to change its behaviour according to the branch FS type. More importantly
2411 +VFS acts differently if a function (member in the struct) is set or
2412 +not. It means aufs should have several sets of operations and select one
2413 +among them according to the branch FS definition.
2415 +In order to solve this problem and not to affect the behaviour of VFS,
2416 +aufs defines these operations dynamically. For instance, aufs defines
2417 +dummy direct_IO function for struct address_space_operations, but it may
2418 +not be set to the address_space_operations actually. When the branch FS
2419 +doesn't have it, aufs doesn't set it to its address_space_operations
2420 +while the function definition itself is still alive. So the behaviour
2421 +itself will not change, and it will return an error when direct_IO is
2424 +The lifetime of these dynamically generated operation object is
2425 +maintained by aufs branch object. When the branch is removed from aufs,
2426 +the reference counter of the object is decremented. When it reaches
2427 +zero, the dynamically generated operation object will be freed.
2429 +This approach is designed to support AIO (io_submit), Direct I/O and
2431 +Currently this approach is applied to address_space_operations for
2432 +regular files only.
2433 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2434 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2435 +++ linux/Documentation/filesystems/aufs/README 2021-11-01 23:48:34.199692595 +0100
2438 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2444 +----------------------------------------
2445 +In the early days, aufs was entirely re-designed and re-implemented
2446 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2447 +improvements and implementations, it became totally different from
2448 +Unionfs while keeping the basic features.
2449 +Later, Unionfs Version 2.x series began taking some of the same
2450 +approaches to aufs1's.
2451 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2452 +University and his team.
2454 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2456 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2457 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2458 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2459 + or aufs1 from CVS on SourceForge.
2461 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2462 + According to Christoph Hellwig, linux rejects all union-type
2463 + filesystems but UnionMount.
2464 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2466 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2467 + UnionMount, and he pointed out an issue around a directory mutex
2468 + lock and aufs addressed it. But it is still unsure whether aufs will
2469 + be merged (or any other union solution).
2470 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2474 +----------------------------------------
2475 +- unite several directories into a single virtual filesystem. The member
2476 + directory is called as a branch.
2477 +- you can specify the permission flags to the branch, which are 'readonly',
2478 + 'readwrite' and 'whiteout-able.'
2479 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2480 + readonly branch are modifiable logically.
2481 +- dynamic branch manipulation, add, del.
2484 +Also there are many enhancements in aufs, such as:
2485 +- test only the highest one for the directory permission (dirperm1)
2486 +- copyup on open (coo=)
2487 +- 'move' policy for copy-up between two writable branches, after
2488 + checking free space.
2490 +- readdir(3) in userspace.
2491 +- keep inode number by external inode number table
2492 +- keep the timestamps of file/dir in internal copyup operation
2493 +- seekable directory, supporting NFS readdir.
2494 +- whiteout is hardlinked in order to reduce the consumption of inodes
2496 +- do not copyup, nor create a whiteout when it is unnecessary
2497 +- revert a single systemcall when an error occurs in aufs
2498 +- remount interface instead of ioctl
2499 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2500 +- loopback mounted filesystem as a branch
2501 +- kernel thread for removing the dir who has a plenty of whiteouts
2502 +- support copyup sparse file (a file which has a 'hole' in it)
2503 +- default permission flags for branches
2504 +- selectable permission flags for ro branch, whether whiteout can
2507 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2508 +- support multiple writable branches, some policies to select one
2509 + among multiple writable branches.
2510 +- a new semantics for link(2) and rename(2) to support multiple
2511 + writable branches.
2512 +- no glibc changes are required.
2513 +- pseudo hardlink (hardlink over branches)
2514 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2515 + including NFS or remote filesystem branch.
2516 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2519 +Currently these features are dropped temporary from aufs5.
2520 +See design/08plan.txt in detail.
2521 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2523 +- statistics of aufs thread (/sys/fs/aufs/stat)
2525 +Features or just an idea in the future (see also design/*.txt),
2526 +- reorder the branch index without del/re-add.
2527 +- permanent xino files for NFSD
2528 +- an option for refreshing the opened files after add/del branches
2529 +- light version, without branch manipulation. (unnecessary?)
2530 +- copyup in userspace
2531 +- inotify in userspace
2536 +----------------------------------------
2537 +There are three GIT trees for aufs5, aufs5-linux.git,
2538 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2540 +While the aufs-util is always necessary, you need either of aufs5-linux
2541 +or aufs5-standalone.
2543 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2544 +git://git.kernel.org/.../torvalds/linux.git.
2545 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2546 +build aufs5 as an external kernel module.
2547 +Several extra patches are not included in this tree. Only
2548 +aufs5-standalone tree contains them. They are described in the later
2549 +section "Configuration and Compilation."
2551 +On the other hand, the aufs5-standalone tree has only aufs source files
2552 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2553 +But you need to apply all aufs patches manually.
2555 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2556 +represents the linux kernel version, "linux-5.x". For instance,
2557 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2558 +"aufs5.x-rcN" branch.
2561 +$ git clone --reference /your/linux/git/tree \
2562 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2563 +- if you don't have linux GIT tree, then remove "--reference ..."
2564 +$ cd aufs5-linux.git
2565 +$ git checkout origin/aufs5.0
2567 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2568 +leave the patch-work to GIT.
2569 +$ cd /your/linux/git/tree
2570 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2572 +$ git checkout -b my5.0 v5.0
2573 +$ (add your local change...)
2574 +$ git pull aufs5 aufs5.0
2575 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2576 +- you may need to solve some conflicts between your_changes and
2577 + aufs5.0. in this case, git-rerere is recommended so that you can
2578 + solve the similar conflicts automatically when you upgrade to 5.1 or
2579 + later in the future.
2581 +o aufs5-standalone tree
2582 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2583 +$ cd aufs5-standalone.git
2584 +$ git checkout origin/aufs5.0
2587 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2588 +- note that the public aufs-util.git is on SourceForge instead of
2591 +$ git checkout origin/aufs5.0
2593 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2594 +The minor version number, 'x' in '5.x', of aufs may not always
2595 +follow the minor version number of the kernel.
2596 +Because changes in the kernel that cause the use of a new
2597 +minor version number do not always require changes to aufs-util.
2599 +Since aufs-util has its own minor version number, you may not be
2600 +able to find a GIT branch in aufs-util for your kernel's
2601 +exact minor version number.
2602 +In this case, you should git-checkout the branch for the
2603 +nearest lower number.
2605 +For (an unreleased) example:
2606 +If you are using "linux-5.10" and the "aufs5.10" branch
2607 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2608 +or something numerically smaller is the branch for your kernel.
2610 +Also you can view all branches by
2614 +3. Configuration and Compilation
2615 +----------------------------------------
2616 +Make sure you have git-checkout'ed the correct branch.
2618 +For aufs5-linux tree,
2619 +- enable CONFIG_AUFS_FS.
2620 +- set other aufs configurations if necessary.
2621 +- for aufs5.13 and later
2622 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2623 + also a caller of VFS functions for branch filesystems, subclassing of
2624 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2625 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2626 + need to customize some LOCKDEP numbers. Here are what I use on my
2628 + CONFIG_LOCKDEP_BITS=21
2629 + CONFIG_LOCKDEP_CHAINS_BITS=21
2630 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2632 +For aufs5-standalone tree,
2633 +There are several ways to build.
2636 +- apply ./aufs5-kbuild.patch to your kernel source files.
2637 +- apply ./aufs5-base.patch too.
2638 +- apply ./aufs5-mmap.patch too.
2639 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2640 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2641 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2642 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2643 +- enable CONFIG_AUFS_FS, you can select either
2645 +- and build your kernel as usual.
2646 +- install the built kernel.
2647 +- install the header files too by "make headers_install" to the
2648 + directory where you specify. By default, it is $PWD/usr.
2649 + "make help" shows a brief note for headers_install.
2650 +- and reboot your system.
2653 +- module only (CONFIG_AUFS_FS=m).
2654 +- apply ./aufs5-base.patch to your kernel source files.
2655 +- apply ./aufs5-mmap.patch too.
2656 +- apply ./aufs5-standalone.patch too.
2657 +- build your kernel, don't forget "make headers_install", and reboot.
2658 +- edit ./config.mk and set other aufs configurations if necessary.
2659 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2660 + every aufs configurations.
2661 +- build the module by simple "make".
2662 +- you can specify ${KDIR} make variable which points to your kernel
2664 +- install the files
2665 + + run "make install" to install the aufs module, or copy the built
2666 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2667 + + run "make install_headers" (instead of headers_install) to install
2668 + the modified aufs header file (you can specify DESTDIR which is
2669 + available in aufs standalone version's Makefile only), or copy
2670 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2671 + you like manually. By default, the target directory is $PWD/usr.
2672 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2673 + kernel source tree.
2675 +Note: The header file aufs_type.h is necessary to build aufs-util
2676 + as well as "make headers_install" in the kernel source tree.
2677 + headers_install is subject to be forgotten, but it is essentially
2678 + necessary, not only for building aufs-util.
2679 + You may not meet problems without headers_install in some older
2683 +- read README in aufs-util, build and install it
2684 +- note that your distribution may contain an obsoleted version of
2685 + aufs_type.h in /usr/include/linux or something. When you build aufs
2686 + utilities, make sure that your compiler refers the correct aufs header
2687 + file which is built by "make headers_install."
2688 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2689 + then run "make install_ulib" too. And refer to the aufs manual in
2692 +There several other patches in aufs5-standalone.git. They are all
2693 +optional. When you meet some problems, they will help you.
2694 +- aufs5-loopback.patch
2695 + Supports a nested loopback mount in a branch-fs. This patch is
2696 + unnecessary until aufs produces a message like "you may want to try
2697 + another patch for loopback file".
2699 + Modifies a system global kernel internal function get_next_ino() in
2700 + order to stop assigning 0 for an inode-number. Not directly related to
2701 + aufs, but recommended generally.
2703 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2704 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2705 + duplication of inode number, which is important for backup tools and
2706 + other utilities. When you find aufs XINO files for tmpfs branch
2707 + growing too much, try this patch.
2711 +----------------------------------------
2712 +At first, make sure aufs-util are installed, and please read the aufs
2713 +manual, aufs.5 in aufs-util.git tree.
2717 +$ mkdir /tmp/rw /tmp/aufs
2718 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2720 +Here is another example. The result is equivalent.
2721 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2723 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2724 +# mount -o remount,append:${HOME} /tmp/aufs
2726 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2727 +you modify a file under /tmp/aufs, the one on your home directory is
2728 +not affected, instead the same named file will be newly created under
2729 +/tmp/rw. And all of your modification to a file will be applied to
2730 +the one under /tmp/rw. This is called the file based Copy on Write
2732 +Aufs mount options are described in aufs.5.
2733 +If you run chroot or something and make your aufs as a root directory,
2734 +then you need to customize the shutdown script. See the aufs manual in
2737 +Additionally, there are some sample usages of aufs which are a
2738 +diskless system with network booting, and LiveCD over NFS.
2739 +See sample dir in CVS tree on SourceForge.
2743 +----------------------------------------
2744 +When you have any problems or strange behaviour in aufs, please let me
2746 +- /proc/mounts (instead of the output of mount(8))
2747 +- /sys/module/aufs/*
2748 +- /sys/fs/aufs/* (if you have them)
2749 +- /debug/aufs/* (if you have them)
2750 +- linux kernel version
2751 + if your kernel is not plain, for example modified by distributor,
2752 + the url where i can download its source is necessary too.
2753 +- aufs version which was printed at loading the module or booting the
2754 + system, instead of the date you downloaded.
2755 +- configuration (define/undefine CONFIG_AUFS_xxx)
2756 +- kernel configuration or /proc/config.gz (if you have it)
2757 +- LSM (linux security module, if you are using)
2758 +- behaviour which you think to be incorrect
2759 +- actual operation, reproducible one is better
2760 +- mailto: aufs-users at lists.sourceforge.net
2762 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2763 +and Feature Requests) on SourceForge. Please join and write to
2767 +6. Acknowledgements
2768 +----------------------------------------
2769 +Thanks to everyone who have tried and are using aufs, whoever
2770 +have reported a bug or any feedback.
2772 +Especially donators:
2773 +Tomas Matejicek(slax.org) made a donation (much more than once).
2774 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2775 + scripts) is making "doubling" donations.
2776 + Unfortunately I cannot list all of the donators, but I really
2778 + It ends Aug 2010, but the ordinary donation URL is still available.
2779 + <http://sourceforge.net/donate/index.php?group_id=167503>
2780 +Dai Itasaka made a donation (2007/8).
2781 +Chuck Smith made a donation (2008/4, 10 and 12).
2782 +Henk Schoneveld made a donation (2008/9).
2783 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2784 +Francois Dupoux made a donation (2008/11).
2785 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2786 + aufs2 GIT tree (2009/2).
2787 +William Grant made a donation (2009/3).
2788 +Patrick Lane made a donation (2009/4).
2789 +The Mail Archive (mail-archive.com) made donations (2009/5).
2790 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2791 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2792 +Pavel Pronskiy made a donation (2011/2).
2793 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2794 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2795 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2797 +Sam Liddicott made a donation (2011/9).
2798 +Era Scarecrow made a donation (2013/4).
2799 +Bor Ratajc made a donation (2013/4).
2800 +Alessandro Gorreta made a donation (2013/4).
2801 +POIRETTE Marc made a donation (2013/4).
2802 +Alessandro Gorreta made a donation (2013/4).
2803 +lauri kasvandik made a donation (2013/5).
2804 +"pemasu from Finland" made a donation (2013/7).
2805 +The Parted Magic Project made a donation (2013/9 and 11).
2806 +Pavel Barta made a donation (2013/10).
2807 +Nikolay Pertsev made a donation (2014/5).
2808 +James B made a donation (2014/7 and 2015/7).
2809 +Stefano Di Biase made a donation (2014/8).
2810 +Daniel Epellei made a donation (2015/1).
2811 +OmegaPhil made a donation (2016/1, 2018/4).
2812 +Tomasz Szewczyk made a donation (2016/4).
2813 +James Burry made a donation (2016/12).
2814 +Carsten Rose made a donation (2018/9).
2815 +Porteus Kiosk made a donation (2018/10).
2817 +Thank you very much.
2818 +Donations are always, including future donations, very important and
2819 +helpful for me to keep on developing aufs.
2823 +----------------------------------------
2824 +If you are an experienced user, no explanation is needed. Aufs is
2825 +just a linux filesystem.
2830 +# Local variables: ;
2833 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2834 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2835 +++ linux/fs/aufs/aufs.h 2021-11-01 23:48:34.203025928 +0100
2837 +/* SPDX-License-Identifier: GPL-2.0 */
2839 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2841 + * This program, aufs is free software; you can redistribute it and/or modify
2842 + * it under the terms of the GNU General Public License as published by
2843 + * the Free Software Foundation; either version 2 of the License, or
2844 + * (at your option) any later version.
2846 + * This program is distributed in the hope that it will be useful,
2847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2849 + * GNU General Public License for more details.
2851 + * You should have received a copy of the GNU General Public License
2852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2856 + * all header files
2864 +#define AuStub(type, name, body, ...) \
2865 + static inline type name(__VA_ARGS__) { body; }
2867 +#define AuStubVoid(name, ...) \
2868 + AuStub(void, name, , __VA_ARGS__)
2869 +#define AuStubInt0(name, ...) \
2870 + AuStub(int, name, return 0, __VA_ARGS__)
2874 +#include "branch.h"
2877 +#include "dbgaufs.h"
2878 +#include "dentry.h"
2880 +#include "dirren.h"
2883 +#include "fstype.h"
2888 +#include "module.h"
2892 +#include "sysaufs.h"
2897 +#endif /* __KERNEL__ */
2898 +#endif /* __AUFS_H__ */
2899 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2900 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2901 +++ linux/fs/aufs/branch.c 2021-11-01 23:48:34.203025928 +0100
2903 +// SPDX-License-Identifier: GPL-2.0
2905 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2907 + * This program, aufs is free software; you can redistribute it and/or modify
2908 + * it under the terms of the GNU General Public License as published by
2909 + * the Free Software Foundation; either version 2 of the License, or
2910 + * (at your option) any later version.
2912 + * This program is distributed in the hope that it will be useful,
2913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2915 + * GNU General Public License for more details.
2917 + * You should have received a copy of the GNU General Public License
2918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2922 + * branch management
2925 +#include <linux/compat.h>
2926 +#include <linux/statfs.h>
2930 + * free a single branch
2932 +static void au_br_do_free(struct au_branch *br)
2935 + struct au_wbr *wbr;
2936 + struct au_dykey **key;
2938 + au_hnotify_fin_br(br);
2939 + /* always, regardless the mount option */
2940 + au_dr_hino_free(&br->br_dirren);
2943 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2944 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2945 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2946 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2950 + for (i = 0; i < AuBrWh_Last; i++)
2951 + dput(wbr->wbr_wh[i]);
2952 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2953 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2956 + if (br->br_fhsm) {
2957 + au_br_fhsm_fin(br->br_fhsm);
2958 + au_kfree_try_rcu(br->br_fhsm);
2961 + key = br->br_dykey;
2962 + for (i = 0; i < AuBrDynOp; i++, key++)
2968 + /* recursive lock, s_umount of branch's */
2969 + /* synchronize_rcu(); */ /* why? */
2971 + path_put(&br->br_path);
2973 + au_kfree_rcu(wbr);
2974 + au_lcnt_wait_for_fin(&br->br_nfiles);
2975 + au_lcnt_wait_for_fin(&br->br_count);
2976 + /* I don't know why, but percpu_refcount requires this */
2977 + /* synchronize_rcu(); */
2982 + * frees all branches
2984 +void au_br_free(struct au_sbinfo *sbinfo)
2986 + aufs_bindex_t bmax;
2987 + struct au_branch **br;
2989 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2991 + bmax = sbinfo->si_bbot + 1;
2992 + br = sbinfo->si_branch;
2994 + au_br_do_free(*br++);
2998 + * find the index of a branch which is specified by @br_id.
3000 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3002 + aufs_bindex_t bindex, bbot;
3004 + bbot = au_sbbot(sb);
3005 + for (bindex = 0; bindex <= bbot; bindex++)
3006 + if (au_sbr_id(sb, bindex) == br_id)
3011 +/* ---------------------------------------------------------------------- */
3017 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3018 + struct dentry *h_root)
3020 + if (unlikely(h_adding == h_root
3021 + || au_test_loopback_overlap(sb, h_adding)))
3023 + if (h_adding->d_sb != h_root->d_sb)
3025 + return au_test_subdir(h_adding, h_root)
3026 + || au_test_subdir(h_root, h_adding);
3030 + * returns a newly allocated branch. @new_nbranch is a number of branches
3031 + * after adding a branch.
3033 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3036 + struct au_branch *add_branch;
3037 + struct dentry *root;
3038 + struct inode *inode;
3042 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3043 + if (unlikely(!add_branch))
3045 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3046 + if (unlikely(!add_branch->br_xino))
3048 + err = au_hnotify_init_br(add_branch, perm);
3049 + if (unlikely(err))
3052 + if (au_br_writable(perm)) {
3053 + /* may be freed separately at changing the branch permission */
3054 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3056 + if (unlikely(!add_branch->br_wbr))
3060 + if (au_br_fhsm(perm)) {
3061 + err = au_fhsm_br_alloc(add_branch);
3062 + if (unlikely(err))
3066 + root = sb->s_root;
3067 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3069 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3071 + inode = d_inode(root);
3072 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3076 + return add_branch; /* success */
3079 + au_kfree_rcu(add_branch->br_wbr);
3081 + au_hnotify_fin_br(add_branch);
3083 + au_xino_put(add_branch);
3085 + au_kfree_rcu(add_branch);
3087 + return ERR_PTR(err);
3091 + * test if the branch permission is legal or not.
3093 +static int test_br(struct inode *inode, int brperm, char *path)
3097 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3102 + pr_err("write permission for readonly mount or inode, %s\n", path);
3110 + * 0: success, the caller will add it
3111 + * plus: success, it is already unified, the caller should ignore it
3114 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3117 + aufs_bindex_t bbot, bindex;
3118 + struct dentry *root, *h_dentry;
3119 + struct inode *inode, *h_inode;
3121 + root = sb->s_root;
3122 + bbot = au_sbbot(sb);
3123 + if (unlikely(bbot >= 0
3124 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3128 + pr_err("%s duplicated\n", add->pathname);
3133 + err = -ENOSPC; /* -E2BIG; */
3134 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3135 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3136 + pr_err("number of branches exceeded %s\n", add->pathname);
3141 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3142 + pr_err("bad index %d\n", add->bindex);
3146 + inode = d_inode(add->path.dentry);
3148 + if (unlikely(!inode->i_nlink)) {
3149 + pr_err("no existence %s\n", add->pathname);
3154 + if (unlikely(inode->i_sb == sb)) {
3155 + pr_err("%s must be outside\n", add->pathname);
3159 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3160 + pr_err("unsupported filesystem, %s (%s)\n",
3161 + add->pathname, au_sbtype(inode->i_sb));
3165 + if (unlikely(inode->i_sb->s_stack_depth)) {
3166 + pr_err("already stacked, %s (%s)\n",
3167 + add->pathname, au_sbtype(inode->i_sb));
3171 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3172 + if (unlikely(err))
3176 + return 0; /* success */
3179 + for (bindex = 0; bindex <= bbot; bindex++)
3180 + if (unlikely(test_overlap(sb, add->path.dentry,
3181 + au_h_dptr(root, bindex)))) {
3182 + pr_err("%s is overlapped\n", add->pathname);
3187 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3188 + h_dentry = au_h_dptr(root, 0);
3189 + h_inode = d_inode(h_dentry);
3190 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3191 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3192 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3193 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3195 + i_uid_read(inode), i_gid_read(inode),
3196 + (inode->i_mode & S_IALLUGO),
3197 + i_uid_read(h_inode), i_gid_read(h_inode),
3198 + (h_inode->i_mode & S_IALLUGO));
3206 + * initialize or clean the whiteouts for an adding branch
3208 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3211 + int err, old_perm;
3212 + aufs_bindex_t bindex;
3213 + struct inode *h_inode;
3214 + struct au_wbr *wbr;
3215 + struct au_hinode *hdir;
3216 + struct dentry *h_dentry;
3218 + err = vfsub_mnt_want_write(au_br_mnt(br));
3219 + if (unlikely(err))
3223 + old_perm = br->br_perm;
3224 + br->br_perm = new_perm;
3227 + bindex = au_br_index(sb, br->br_id);
3228 + if (0 <= bindex) {
3229 + hdir = au_hi(d_inode(sb->s_root), bindex);
3230 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3232 + h_dentry = au_br_dentry(br);
3233 + h_inode = d_inode(h_dentry);
3234 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3237 + err = au_wh_init(br, sb);
3239 + wbr_wh_write_lock(wbr);
3240 + err = au_wh_init(br, sb);
3241 + wbr_wh_write_unlock(wbr);
3244 + au_hn_inode_unlock(hdir);
3246 + inode_unlock(h_inode);
3247 + vfsub_mnt_drop_write(au_br_mnt(br));
3248 + br->br_perm = old_perm;
3250 + if (!err && wbr && !au_br_writable(new_perm)) {
3251 + au_kfree_rcu(wbr);
3252 + br->br_wbr = NULL;
3259 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3263 + struct kstatfs kst;
3264 + struct au_wbr *wbr;
3267 + au_rw_init(&wbr->wbr_wh_rwsem);
3268 + atomic_set(&wbr->wbr_wh_running, 0);
3271 + * a limit for rmdir/rename a dir
3272 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3274 + err = vfs_statfs(&br->br_path, &kst);
3275 + if (unlikely(err))
3278 + if (kst.f_namelen >= NAME_MAX)
3279 + err = au_br_init_wh(sb, br, perm);
3281 + pr_err("%pd(%s), unsupported namelen %ld\n",
3283 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3289 +/* initialize a new branch */
3290 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3291 + struct au_opt_add *add)
3294 + struct au_branch *brbase;
3296 + struct inode *h_inode;
3299 + br->br_perm = add->perm;
3300 + br->br_path = add->path; /* set first, path_get() later */
3301 + spin_lock_init(&br->br_dykey_lock);
3302 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3303 + au_lcnt_init(&br->br_count, /*release*/NULL);
3304 + br->br_id = au_new_br_id(sb);
3305 + AuDebugOn(br->br_id < 0);
3307 + /* always, regardless the given option */
3308 + err = au_dr_br_init(sb, br, &add->path);
3309 + if (unlikely(err))
3312 + if (au_br_writable(add->perm)) {
3313 + err = au_wbr_init(br, sb, add->perm);
3314 + if (unlikely(err))
3318 + if (au_opt_test(au_mntflags(sb), XINO)) {
3319 + brbase = au_sbr(sb, 0);
3320 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3322 + h_inode = d_inode(add->path.dentry);
3323 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3324 + if (unlikely(err)) {
3325 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3330 + sysaufs_br_init(br);
3331 + path_get(&br->br_path);
3332 + goto out; /* success */
3335 + memset(&br->br_path, 0, sizeof(br->br_path));
3340 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3341 + struct au_branch *br, aufs_bindex_t bbot,
3342 + aufs_bindex_t amount)
3344 + struct au_branch **brp;
3346 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3348 + brp = sbinfo->si_branch + bindex;
3349 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3351 + sbinfo->si_bbot++;
3352 + if (unlikely(bbot < 0))
3353 + sbinfo->si_bbot = 0;
3356 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3357 + aufs_bindex_t bbot, aufs_bindex_t amount)
3359 + struct au_hdentry *hdp;
3361 + AuRwMustWriteLock(&dinfo->di_rwsem);
3363 + hdp = au_hdentry(dinfo, bindex);
3364 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3365 + au_h_dentry_init(hdp);
3367 + if (unlikely(bbot < 0))
3368 + dinfo->di_btop = 0;
3371 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3372 + aufs_bindex_t bbot, aufs_bindex_t amount)
3374 + struct au_hinode *hip;
3376 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3378 + hip = au_hinode(iinfo, bindex);
3379 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3380 + au_hinode_init(hip);
3382 + if (unlikely(bbot < 0))
3383 + iinfo->ii_btop = 0;
3386 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3387 + aufs_bindex_t bindex)
3389 + struct dentry *root, *h_dentry;
3390 + struct inode *root_inode, *h_inode;
3391 + aufs_bindex_t bbot, amount;
3393 + root = sb->s_root;
3394 + root_inode = d_inode(root);
3395 + bbot = au_sbbot(sb);
3396 + amount = bbot + 1 - bindex;
3397 + h_dentry = au_br_dentry(br);
3398 + au_sbilist_lock();
3399 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3400 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3401 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3402 + au_set_h_dptr(root, bindex, dget(h_dentry));
3403 + h_inode = d_inode(h_dentry);
3404 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3405 + au_sbilist_unlock();
3408 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3411 + aufs_bindex_t bbot, add_bindex;
3412 + struct dentry *root, *h_dentry;
3413 + struct inode *root_inode;
3414 + struct au_branch *add_branch;
3416 + root = sb->s_root;
3417 + root_inode = d_inode(root);
3418 + IMustLock(root_inode);
3419 + IiMustWriteLock(root_inode);
3420 + err = test_add(sb, add, remount);
3421 + if (unlikely(err < 0))
3425 + goto out; /* success */
3428 + bbot = au_sbbot(sb);
3429 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3430 + err = PTR_ERR(add_branch);
3431 + if (IS_ERR(add_branch))
3434 + err = au_br_init(add_branch, sb, add);
3435 + if (unlikely(err)) {
3436 + au_br_do_free(add_branch);
3440 + add_bindex = add->bindex;
3441 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3442 + au_br_do_add(sb, add_branch, add_bindex);
3443 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3444 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3446 + h_dentry = add->path.dentry;
3447 + if (!add_bindex) {
3448 + au_cpup_attr_all(root_inode, /*force*/1);
3449 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3451 + au_add_nlink(root_inode, d_inode(h_dentry));
3457 +/* ---------------------------------------------------------------------- */
3459 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3460 + unsigned long long max __maybe_unused,
3463 + unsigned long long n;
3464 + struct file **p, *f;
3465 + struct hlist_bl_head *files;
3466 + struct hlist_bl_node *pos;
3467 + struct au_finfo *finfo;
3471 + files = &au_sbi(sb)->si_files;
3472 + hlist_bl_lock(files);
3473 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3474 + f = finfo->fi_file;
3476 + && !special_file(file_inode(f)->i_mode)) {
3480 + AuDebugOn(n > max);
3483 + hlist_bl_unlock(files);
3488 +static struct file **au_farray_alloc(struct super_block *sb,
3489 + unsigned long long *max)
3491 + struct au_sbinfo *sbi;
3494 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3495 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3498 +static void au_farray_free(struct file **a, unsigned long long max)
3500 + unsigned long long ull;
3502 + for (ull = 0; ull < max; ull++)
3508 +/* ---------------------------------------------------------------------- */
3514 +/* to show the line number, do not make it inlined function */
3515 +#define AuVerbose(do_info, fmt, ...) do { \
3517 + pr_info(fmt, ##__VA_ARGS__); \
3520 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3521 + aufs_bindex_t bbot)
3523 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3526 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3527 + aufs_bindex_t bbot)
3529 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3533 + * test if the branch is deletable or not.
3535 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3536 + unsigned int sigen, const unsigned int verbose)
3538 + int err, i, j, ndentry;
3539 + aufs_bindex_t btop, bbot;
3540 + struct au_dcsub_pages dpages;
3541 + struct au_dpage *dpage;
3544 + err = au_dpages_init(&dpages, GFP_NOFS);
3545 + if (unlikely(err))
3547 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3548 + if (unlikely(err))
3551 + for (i = 0; !err && i < dpages.ndpage; i++) {
3552 + dpage = dpages.dpages + i;
3553 + ndentry = dpage->ndentry;
3554 + for (j = 0; !err && j < ndentry; j++) {
3555 + d = dpage->dentries[j];
3556 + AuDebugOn(au_dcount(d) <= 0);
3557 + if (!au_digen_test(d, sigen)) {
3558 + di_read_lock_child(d, AuLock_IR);
3559 + if (unlikely(au_dbrange_test(d))) {
3560 + di_read_unlock(d, AuLock_IR);
3564 + di_write_lock_child(d);
3565 + if (unlikely(au_dbrange_test(d))) {
3566 + di_write_unlock(d);
3569 + err = au_reval_dpath(d, sigen);
3571 + di_downgrade_lock(d, AuLock_IR);
3573 + di_write_unlock(d);
3578 + /* AuDbgDentry(d); */
3579 + btop = au_dbtop(d);
3580 + bbot = au_dbbot(d);
3581 + if (btop <= bindex
3583 + && au_h_dptr(d, bindex)
3584 + && au_test_dbusy(d, btop, bbot)) {
3586 + AuVerbose(verbose, "busy %pd\n", d);
3589 + di_read_unlock(d, AuLock_IR);
3594 + au_dpages_free(&dpages);
3599 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3600 + unsigned int sigen, const unsigned int verbose)
3603 + unsigned long long max, ull;
3604 + struct inode *i, **array;
3605 + aufs_bindex_t btop, bbot;
3607 + array = au_iarray_alloc(sb, &max);
3608 + err = PTR_ERR(array);
3609 + if (IS_ERR(array))
3613 + AuDbg("b%d\n", bindex);
3614 + for (ull = 0; !err && ull < max; ull++) {
3618 + if (i->i_ino == AUFS_ROOT_INO)
3621 + /* AuDbgInode(i); */
3622 + if (au_iigen(i, NULL) == sigen)
3623 + ii_read_lock_child(i);
3625 + ii_write_lock_child(i);
3626 + err = au_refresh_hinode_self(i);
3629 + ii_downgrade_lock(i);
3631 + ii_write_unlock(i);
3636 + btop = au_ibtop(i);
3637 + bbot = au_ibbot(i);
3638 + if (btop <= bindex
3640 + && au_h_iptr(i, bindex)
3641 + && au_test_ibusy(i, btop, bbot)) {
3643 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3646 + ii_read_unlock(i);
3648 + au_iarray_free(array, max);
3654 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3655 + const unsigned int verbose)
3658 + unsigned int sigen;
3660 + sigen = au_sigen(root->d_sb);
3661 + DiMustNoWaiters(root);
3662 + IiMustNoWaiters(d_inode(root));
3663 + di_write_unlock(root);
3664 + err = test_dentry_busy(root, bindex, sigen, verbose);
3666 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3667 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3672 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3673 + struct file **to_free, int *idx)
3676 + unsigned char matched, root;
3677 + aufs_bindex_t bindex, bbot;
3678 + struct au_fidir *fidir;
3679 + struct au_hfile *hfile;
3682 + root = IS_ROOT(file->f_path.dentry);
3685 + to_free[*idx] = file;
3691 + fidir = au_fi(file)->fi_hdir;
3692 + AuDebugOn(!fidir);
3693 + bbot = au_fbbot_dir(file);
3694 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3695 + hfile = fidir->fd_hfile + bindex;
3696 + if (!hfile->hf_file)
3699 + if (hfile->hf_br->br_id == br_id) {
3711 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3712 + struct file **to_free, int opened)
3715 + unsigned long long ull, max;
3716 + aufs_bindex_t btop;
3717 + struct file *file, **array;
3718 + struct dentry *root;
3719 + struct au_hfile *hfile;
3721 + array = au_farray_alloc(sb, &max);
3722 + err = PTR_ERR(array);
3723 + if (IS_ERR(array))
3728 + root = sb->s_root;
3729 + di_write_unlock(root);
3730 + for (ull = 0; ull < max; ull++) {
3731 + file = array[ull];
3732 + if (unlikely(!file))
3735 + /* AuDbg("%pD\n", file); */
3736 + fi_read_lock(file);
3737 + btop = au_fbtop(file);
3738 + if (!d_is_dir(file->f_path.dentry)) {
3739 + hfile = &au_fi(file)->fi_htop;
3740 + if (hfile->hf_br->br_id == br_id)
3743 + err = test_dir_busy(file, br_id, to_free, &idx);
3744 + fi_read_unlock(file);
3745 + if (unlikely(err))
3748 + di_write_lock_child(root);
3749 + au_farray_free(array, max);
3750 + AuDebugOn(idx > opened);
3756 +static void br_del_file(struct file **to_free, unsigned long long opened,
3757 + aufs_bindex_t br_id)
3759 + unsigned long long ull;
3760 + aufs_bindex_t bindex, btop, bbot, bfound;
3761 + struct file *file;
3762 + struct au_fidir *fidir;
3763 + struct au_hfile *hfile;
3765 + for (ull = 0; ull < opened; ull++) {
3766 + file = to_free[ull];
3767 + if (unlikely(!file))
3770 + /* AuDbg("%pD\n", file); */
3771 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3773 + fidir = au_fi(file)->fi_hdir;
3774 + AuDebugOn(!fidir);
3775 + fi_write_lock(file);
3776 + btop = au_fbtop(file);
3777 + bbot = au_fbbot_dir(file);
3778 + for (bindex = btop; bindex <= bbot; bindex++) {
3779 + hfile = fidir->fd_hfile + bindex;
3780 + if (!hfile->hf_file)
3783 + if (hfile->hf_br->br_id == br_id) {
3788 + AuDebugOn(bfound < 0);
3789 + au_set_h_fptr(file, bfound, NULL);
3790 + if (bfound == btop) {
3791 + for (btop++; btop <= bbot; btop++)
3792 + if (au_hf_dir(file, btop)) {
3793 + au_set_fbtop(file, btop);
3797 + fi_write_unlock(file);
3801 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3802 + const aufs_bindex_t bindex,
3803 + const aufs_bindex_t bbot)
3805 + struct au_branch **brp, **p;
3807 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3809 + brp = sbinfo->si_branch + bindex;
3810 + if (bindex < bbot)
3811 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3812 + sbinfo->si_branch[0 + bbot] = NULL;
3813 + sbinfo->si_bbot--;
3815 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3818 + sbinfo->si_branch = p;
3819 + /* harmless error */
3822 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3823 + const aufs_bindex_t bbot)
3825 + struct au_hdentry *hdp, *p;
3827 + AuRwMustWriteLock(&dinfo->di_rwsem);
3829 + hdp = au_hdentry(dinfo, bindex);
3830 + if (bindex < bbot)
3831 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3832 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3835 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3838 + dinfo->di_hdentry = p;
3839 + /* harmless error */
3842 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3843 + const aufs_bindex_t bbot)
3845 + struct au_hinode *hip, *p;
3847 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3849 + hip = au_hinode(iinfo, bindex);
3850 + if (bindex < bbot)
3851 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3852 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3855 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3858 + iinfo->ii_hinode = p;
3859 + /* harmless error */
3862 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3863 + struct au_branch *br)
3865 + aufs_bindex_t bbot;
3866 + struct au_sbinfo *sbinfo;
3867 + struct dentry *root, *h_root;
3868 + struct inode *inode, *h_inode;
3869 + struct au_hinode *hinode;
3871 + SiMustWriteLock(sb);
3873 + root = sb->s_root;
3874 + inode = d_inode(root);
3875 + sbinfo = au_sbi(sb);
3876 + bbot = sbinfo->si_bbot;
3878 + h_root = au_h_dptr(root, bindex);
3879 + hinode = au_hi(inode, bindex);
3880 + h_inode = au_igrab(hinode->hi_inode);
3883 + au_sbilist_lock();
3884 + au_br_do_del_brp(sbinfo, bindex, bbot);
3885 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3886 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3887 + au_sbilist_unlock();
3889 + /* ignore an error */
3890 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3894 + au_br_do_free(br);
3897 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3898 + unsigned long long max, void *arg)
3903 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3906 + unsigned long long opened;
3907 + unsigned int mnt_flags;
3908 + aufs_bindex_t bindex, bbot, br_id;
3909 + unsigned char do_wh, verbose;
3910 + struct au_branch *br;
3911 + struct au_wbr *wbr;
3912 + struct dentry *root;
3913 + struct file **to_free;
3918 + root = sb->s_root;
3919 + bindex = au_find_dbindex(root, del->h_path.dentry);
3922 + goto out; /* success */
3924 + pr_err("%s no such branch\n", del->pathname);
3927 + AuDbg("bindex b%d\n", bindex);
3930 + mnt_flags = au_mntflags(sb);
3931 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3932 + bbot = au_sbbot(sb);
3933 + if (unlikely(!bbot)) {
3934 + AuVerbose(verbose, "no more branches left\n");
3938 + br = au_sbr(sb, bindex);
3939 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3940 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3941 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3945 + br_id = br->br_id;
3946 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3947 + if (unlikely(opened)) {
3948 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3949 + err = PTR_ERR(to_free);
3950 + if (IS_ERR(to_free))
3953 + err = test_file_busy(sb, br_id, to_free, opened);
3954 + if (unlikely(err)) {
3955 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3961 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3963 + /* instead of WbrWhMustWriteLock(wbr) */
3964 + SiMustWriteLock(sb);
3965 + for (i = 0; i < AuBrWh_Last; i++) {
3966 + dput(wbr->wbr_wh[i]);
3967 + wbr->wbr_wh[i] = NULL;
3971 + err = test_children_busy(root, bindex, verbose);
3972 + if (unlikely(err)) {
3981 + * now we confirmed the branch is deletable.
3982 + * let's free the remaining opened dirs on the branch.
3984 + di_write_unlock(root);
3985 + br_del_file(to_free, opened, br_id);
3986 + di_write_lock_child(root);
3989 + sysaufs_brs_del(sb, bindex); /* remove successors */
3990 + dbgaufs_xino_del(br); /* remove one */
3991 + au_br_do_del(sb, bindex, br);
3992 + sysaufs_brs_add(sb, bindex); /* append successors */
3993 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3996 + au_cpup_attr_all(d_inode(root), /*force*/1);
3997 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3999 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4000 + if (au_opt_test(mnt_flags, PLINK))
4001 + au_plink_half_refresh(sb, br_id);
4003 + goto out; /* success */
4007 + rerr = au_br_init_wh(sb, br, br->br_perm);
4009 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4010 + del->pathname, rerr);
4013 + au_farray_free(to_free, opened);
4017 +/* ---------------------------------------------------------------------- */
4019 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4022 + aufs_bindex_t btop, bbot;
4023 + struct aufs_ibusy ibusy;
4024 + struct inode *inode, *h_inode;
4027 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4030 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4032 + /* VERIFY_WRITE */
4033 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4034 + if (unlikely(err)) {
4041 + si_read_lock(sb, AuLock_FLUSH);
4042 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4046 + ibusy.h_ino = 0; /* invalid */
4047 + inode = ilookup(sb, ibusy.ino);
4049 + || inode->i_ino == AUFS_ROOT_INO
4050 + || au_is_bad_inode(inode))
4053 + ii_read_lock_child(inode);
4054 + btop = au_ibtop(inode);
4055 + bbot = au_ibbot(inode);
4056 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4057 + h_inode = au_h_iptr(inode, ibusy.bindex);
4058 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4059 + ibusy.h_ino = h_inode->i_ino;
4061 + ii_read_unlock(inode);
4065 + si_read_unlock(sb);
4067 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4068 + if (unlikely(err)) {
4077 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4079 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4082 +#ifdef CONFIG_COMPAT
4083 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4085 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4089 +/* ---------------------------------------------------------------------- */
4092 + * change a branch permission
4095 +static void au_warn_ima(void)
4098 + /* since it doesn't support mark_files_ro() */
4099 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4103 +static int do_need_sigen_inc(int a, int b)
4105 + return au_br_whable(a) && !au_br_whable(b);
4108 +static int need_sigen_inc(int old, int new)
4110 + return do_need_sigen_inc(old, new)
4111 + || do_need_sigen_inc(new, old);
4114 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4117 + unsigned int mnt_flags;
4118 + unsigned long long ull, max;
4119 + aufs_bindex_t br_id;
4120 + unsigned char verbose, writer;
4121 + struct file *file, *hf, **array;
4122 + struct au_hfile *hfile;
4123 + struct inode *h_inode;
4125 + mnt_flags = au_mntflags(sb);
4126 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4128 + array = au_farray_alloc(sb, &max);
4129 + err = PTR_ERR(array);
4130 + if (IS_ERR(array))
4134 + br_id = au_sbr_id(sb, bindex);
4135 + for (ull = 0; ull < max; ull++) {
4136 + file = array[ull];
4137 + if (unlikely(!file))
4140 + /* AuDbg("%pD\n", file); */
4141 + fi_read_lock(file);
4142 + if (unlikely(au_test_mmapped(file))) {
4144 + AuVerbose(verbose, "mmapped %pD\n", file);
4146 + FiMustNoWaiters(file);
4147 + fi_read_unlock(file);
4151 + hfile = &au_fi(file)->fi_htop;
4152 + hf = hfile->hf_file;
4153 + if (!d_is_reg(file->f_path.dentry)
4154 + || !(file->f_mode & FMODE_WRITE)
4155 + || hfile->hf_br->br_id != br_id
4156 + || !(hf->f_mode & FMODE_WRITE))
4157 + array[ull] = NULL;
4163 + FiMustNoWaiters(file);
4164 + fi_read_unlock(file);
4172 + for (ull = 0; ull < max; ull++) {
4173 + file = array[ull];
4177 + /* todo: already flushed? */
4179 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4180 + * approach which resets f_mode and calls mnt_drop_write() and
4181 + * file_release_write() for each file, because the branch
4182 + * attribute in aufs world is totally different from the native
4185 + /* fi_read_lock(file); */
4186 + hfile = &au_fi(file)->fi_htop;
4187 + hf = hfile->hf_file;
4188 + /* fi_read_unlock(file); */
4189 + spin_lock(&hf->f_lock);
4190 + writer = !!(hf->f_mode & FMODE_WRITER);
4191 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4192 + spin_unlock(&hf->f_lock);
4194 + h_inode = file_inode(hf);
4195 + if (hf->f_mode & FMODE_READ)
4196 + i_readcount_inc(h_inode);
4197 + put_write_access(h_inode);
4198 + __mnt_drop_write(hf->f_path.mnt);
4203 + au_farray_free(array, max);
4209 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4213 + aufs_bindex_t bindex;
4214 + struct dentry *root;
4215 + struct au_branch *br;
4216 + struct au_br_fhsm *bf;
4218 + root = sb->s_root;
4219 + bindex = au_find_dbindex(root, mod->h_root);
4222 + return 0; /* success */
4224 + pr_err("%s no such branch\n", mod->path);
4227 + AuDbg("bindex b%d\n", bindex);
4229 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4230 + if (unlikely(err))
4233 + br = au_sbr(sb, bindex);
4234 + AuDebugOn(mod->h_root != au_br_dentry(br));
4235 + if (br->br_perm == mod->perm)
4236 + return 0; /* success */
4238 + /* pre-allocate for non-fhsm --> fhsm */
4240 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4241 + err = au_fhsm_br_alloc(br);
4242 + if (unlikely(err))
4245 + br->br_fhsm = NULL;
4248 + if (au_br_writable(br->br_perm)) {
4249 + /* remove whiteout base */
4250 + err = au_br_init_wh(sb, br, mod->perm);
4251 + if (unlikely(err))
4254 + if (!au_br_writable(mod->perm)) {
4255 + /* rw --> ro, file might be mmapped */
4256 + DiMustNoWaiters(root);
4257 + IiMustNoWaiters(d_inode(root));
4258 + di_write_unlock(root);
4259 + err = au_br_mod_files_ro(sb, bindex);
4260 + /* aufs_write_lock() calls ..._child() */
4261 + di_write_lock_child(root);
4263 + if (unlikely(err)) {
4265 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4268 + rerr = au_wbr_init(br, sb, br->br_perm);
4269 + if (unlikely(rerr)) {
4270 + AuIOErr("nested error %d (%d)\n",
4272 + br->br_perm = mod->perm;
4276 + } else if (au_br_writable(mod->perm)) {
4279 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4281 + err = au_wbr_init(br, sb, mod->perm);
4282 + if (unlikely(err)) {
4283 + au_kfree_rcu(br->br_wbr);
4284 + br->br_wbr = NULL;
4288 + if (unlikely(err))
4291 + if (au_br_fhsm(br->br_perm)) {
4292 + if (!au_br_fhsm(mod->perm)) {
4293 + /* fhsm --> non-fhsm */
4294 + au_br_fhsm_fin(br->br_fhsm);
4295 + au_kfree_rcu(br->br_fhsm);
4296 + br->br_fhsm = NULL;
4298 + } else if (au_br_fhsm(mod->perm))
4299 + /* non-fhsm --> fhsm */
4302 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4303 + br->br_perm = mod->perm;
4304 + goto out; /* success */
4307 + au_kfree_try_rcu(bf);
4313 +/* ---------------------------------------------------------------------- */
4315 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4318 + struct kstatfs kstfs;
4320 + err = vfs_statfs(&br->br_path, &kstfs);
4322 + stfs->f_blocks = kstfs.f_blocks;
4323 + stfs->f_bavail = kstfs.f_bavail;
4324 + stfs->f_files = kstfs.f_files;
4325 + stfs->f_ffree = kstfs.f_ffree;
4330 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4331 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4332 +++ linux/fs/aufs/branch.h 2021-11-01 23:48:34.203025928 +0100
4334 +/* SPDX-License-Identifier: GPL-2.0 */
4336 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4338 + * This program, aufs is free software; you can redistribute it and/or modify
4339 + * it under the terms of the GNU General Public License as published by
4340 + * the Free Software Foundation; either version 2 of the License, or
4341 + * (at your option) any later version.
4343 + * This program is distributed in the hope that it will be useful,
4344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4346 + * GNU General Public License for more details.
4348 + * You should have received a copy of the GNU General Public License
4349 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4353 + * branch filesystems and xino for them
4356 +#ifndef __AUFS_BRANCH_H__
4357 +#define __AUFS_BRANCH_H__
4361 +#include <linux/mount.h>
4362 +#include "dirren.h"
4368 +/* ---------------------------------------------------------------------- */
4372 + struct file **xi_file;
4373 + unsigned int xi_nfile;
4379 + /* reserved for future use */
4380 + /* unsigned long *bitmap; */
4381 + wait_queue_head_t wqh;
4384 + struct mutex xi_mtx; /* protects xi_file array */
4385 + struct hlist_bl_head xi_writing;
4387 + atomic_t xi_truncating;
4389 + struct kref xi_kref;
4392 +/* File-based Hierarchical Storage Management */
4393 +struct au_br_fhsm {
4394 +#ifdef CONFIG_AUFS_FHSM
4395 + struct mutex bf_lock;
4396 + unsigned long bf_jiffy;
4397 + struct aufs_stfs bf_stfs;
4402 +/* members for writable branch only */
4403 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4405 + struct au_rwsem wbr_wh_rwsem;
4406 + struct dentry *wbr_wh[AuBrWh_Last];
4407 + atomic_t wbr_wh_running;
4408 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4409 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4410 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4413 + unsigned long long wbr_bytes;
4416 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4417 +#define AuBrDynOp (AuDyLast * 4)
4419 +#ifdef CONFIG_AUFS_HFSNOTIFY
4420 +/* support for asynchronous destruction */
4421 +struct au_br_hfsnotify {
4422 + struct fsnotify_group *hfsn_group;
4426 +/* sysfs entries */
4427 +struct au_brsysfs {
4429 + struct attribute attr;
4438 +/* protected by superblock rwsem */
4440 + struct au_xino *br_xino;
4442 + aufs_bindex_t br_id;
4445 + struct path br_path;
4446 + spinlock_t br_dykey_lock;
4447 + struct au_dykey *br_dykey[AuBrDynOp];
4448 + au_lcnt_t br_nfiles; /* opened files */
4449 + au_lcnt_t br_count; /* in-use for other */
4451 + struct au_wbr *br_wbr;
4452 + struct au_br_fhsm *br_fhsm;
4454 +#ifdef CONFIG_AUFS_HFSNOTIFY
4455 + struct au_br_hfsnotify *br_hfsn;
4458 +#ifdef CONFIG_SYSFS
4459 + /* entries under sysfs per mount-point */
4460 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4463 +#ifdef CONFIG_DEBUG_FS
4464 + struct dentry *br_dbgaufs; /* xino */
4467 + struct au_dr_br br_dirren;
4470 +/* ---------------------------------------------------------------------- */
4472 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4474 + return br->br_path.mnt;
4477 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4479 + return br->br_path.dentry;
4482 +static inline struct user_namespace *au_br_userns(struct au_branch *br)
4484 + return mnt_user_ns(br->br_path.mnt);
4487 +static inline struct super_block *au_br_sb(struct au_branch *br)
4489 + return au_br_mnt(br)->mnt_sb;
4492 +static inline int au_br_rdonly(struct au_branch *br)
4494 + return (sb_rdonly(au_br_sb(br))
4495 + || !au_br_writable(br->br_perm))
4499 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4501 +#ifdef CONFIG_AUFS_HNOTIFY
4502 + return !(brperm & AuBrPerm_RR);
4508 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4510 + int err, exec_flag;
4513 + exec_flag = oflag & __FMODE_EXEC;
4514 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4520 +static inline void au_xino_get(struct au_branch *br)
4522 + struct au_xino *xi;
4526 + kref_get(&xi->xi_kref);
4529 +static inline int au_xino_count(struct au_branch *br)
4532 + struct au_xino *xi;
4537 + v = kref_read(&xi->xi_kref);
4542 +/* ---------------------------------------------------------------------- */
4546 +void au_br_free(struct au_sbinfo *sinfo);
4547 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4549 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4551 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4552 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4553 +#ifdef CONFIG_COMPAT
4554 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4557 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4560 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4563 +static const loff_t au_loff_max = LLONG_MAX;
4565 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4566 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4568 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4569 + struct file *copy_src);
4571 + struct au_xino *xi; /* switch between xino and xigen */
4573 + struct path *base;
4574 + struct file *copy_src;
4576 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4578 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4580 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4582 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4583 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4585 +int au_xib_trunc(struct super_block *sb);
4586 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4588 +struct au_xino *au_xino_alloc(unsigned int nfile);
4589 +int au_xino_put(struct au_branch *br);
4590 +struct file *au_xino_file1(struct au_xino *xi);
4592 +struct au_opt_xino;
4593 +void au_xino_clr(struct super_block *sb);
4594 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4595 +struct file *au_xino_def(struct super_block *sb);
4596 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4597 + struct path *base);
4599 +ino_t au_xino_new_ino(struct super_block *sb);
4600 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4602 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4603 + ino_t h_ino, int idx);
4604 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4607 +int au_xino_path(struct seq_file *seq, struct file *file);
4609 +/* ---------------------------------------------------------------------- */
4611 +/* @idx is signed to accept -1 meaning the first file */
4612 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4614 + struct file *file;
4621 + if (idx < xi->xi_nfile)
4622 + file = xi->xi_file[idx];
4624 + file = au_xino_file1(xi);
4630 +/* ---------------------------------------------------------------------- */
4632 +/* Superblock to branch */
4634 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4636 + return au_sbr(sb, bindex)->br_id;
4640 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4642 + return au_br_mnt(au_sbr(sb, bindex));
4646 +struct user_namespace *au_sbr_userns(struct super_block *sb, aufs_bindex_t bindex)
4648 + return au_br_userns(au_sbr(sb, bindex));
4652 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4654 + return au_br_sb(au_sbr(sb, bindex));
4657 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4659 + return au_sbr(sb, bindex)->br_perm;
4662 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4664 + return au_br_whable(au_sbr_perm(sb, bindex));
4667 +/* ---------------------------------------------------------------------- */
4669 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4670 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4671 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4672 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4674 +#define wbr_wh_read_trylock_nested(wbr) \
4675 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4676 +#define wbr_wh_write_trylock_nested(wbr) \
4677 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4680 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4681 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4682 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4684 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4685 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4686 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4688 +/* ---------------------------------------------------------------------- */
4690 +#ifdef CONFIG_AUFS_FHSM
4691 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4693 + mutex_init(&brfhsm->bf_lock);
4694 + brfhsm->bf_jiffy = 0;
4695 + brfhsm->bf_readable = 0;
4698 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4700 + mutex_destroy(&brfhsm->bf_lock);
4703 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4704 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4707 +#endif /* __KERNEL__ */
4708 +#endif /* __AUFS_BRANCH_H__ */
4709 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4710 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4711 +++ linux/fs/aufs/conf.mk 2021-11-01 23:48:34.203025928 +0100
4713 +# SPDX-License-Identifier: GPL-2.0
4715 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4719 +AuConfStr += ${1}=${${1}}
4723 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4725 + HNOTIFY HFSNOTIFY \
4737 +$(foreach i, ${AuConfAll}, \
4738 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4740 +AuConfName = ${obj}/conf.str
4741 +${AuConfName}.tmp: FORCE
4742 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4743 +${AuConfName}: ${AuConfName}.tmp
4744 + @diff -q $< $@ > /dev/null 2>&1 || { \
4745 + echo ' GEN ' $@; \
4749 +clean-files += ${AuConfName} ${AuConfName}.tmp
4750 +${obj}/sysfs.o: ${AuConfName}
4752 +-include ${srctree}/${src}/conf_priv.mk
4753 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4754 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4755 +++ linux/fs/aufs/cpup.c 2021-11-01 23:48:34.203025928 +0100
4757 +// SPDX-License-Identifier: GPL-2.0
4759 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4761 + * This program, aufs is free software; you can redistribute it and/or modify
4762 + * it under the terms of the GNU General Public License as published by
4763 + * the Free Software Foundation; either version 2 of the License, or
4764 + * (at your option) any later version.
4766 + * This program is distributed in the hope that it will be useful,
4767 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4768 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4769 + * GNU General Public License for more details.
4771 + * You should have received a copy of the GNU General Public License
4772 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4776 + * copy-up functions, see wbr_policy.c for copy-down
4779 +#include <linux/fs_stack.h>
4780 +#include <linux/mm.h>
4781 +#include <linux/task_work.h>
4784 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4786 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4787 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4789 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4791 + dst->i_flags |= iflags & ~mask;
4792 + if (au_test_fs_notime(dst->i_sb))
4793 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4796 +void au_cpup_attr_timesizes(struct inode *inode)
4798 + struct inode *h_inode;
4800 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4801 + fsstack_copy_attr_times(inode, h_inode);
4802 + fsstack_copy_inode_size(inode, h_inode);
4805 +void au_cpup_attr_nlink(struct inode *inode, int force)
4807 + struct inode *h_inode;
4808 + struct super_block *sb;
4809 + aufs_bindex_t bindex, bbot;
4812 + bindex = au_ibtop(inode);
4813 + h_inode = au_h_iptr(inode, bindex);
4815 + && !S_ISDIR(h_inode->i_mode)
4816 + && au_opt_test(au_mntflags(sb), PLINK)
4817 + && au_plink_test(inode))
4821 + * 0 can happen in revalidating.
4822 + * h_inode->i_mutex may not be held here, but it is harmless since once
4823 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4825 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4826 + * the incorrect link count.
4828 + set_nlink(inode, h_inode->i_nlink);
4831 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4832 + * it may includes whplink directory.
4834 + if (S_ISDIR(h_inode->i_mode)) {
4835 + bbot = au_ibbot(inode);
4836 + for (bindex++; bindex <= bbot; bindex++) {
4837 + h_inode = au_h_iptr(inode, bindex);
4839 + au_add_nlink(inode, h_inode);
4844 +void au_cpup_attr_changeable(struct inode *inode)
4846 + struct inode *h_inode;
4848 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4849 + inode->i_mode = h_inode->i_mode;
4850 + inode->i_uid = h_inode->i_uid;
4851 + inode->i_gid = h_inode->i_gid;
4852 + au_cpup_attr_timesizes(inode);
4853 + au_cpup_attr_flags(inode, h_inode->i_flags);
4856 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4858 + struct au_iinfo *iinfo = au_ii(inode);
4860 + IiMustWriteLock(inode);
4862 + iinfo->ii_higen = h_inode->i_generation;
4863 + iinfo->ii_hsb1 = h_inode->i_sb;
4866 +void au_cpup_attr_all(struct inode *inode, int force)
4868 + struct inode *h_inode;
4870 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4871 + au_cpup_attr_changeable(inode);
4872 + if (inode->i_nlink > 0)
4873 + au_cpup_attr_nlink(inode, force);
4874 + inode->i_rdev = h_inode->i_rdev;
4875 + inode->i_blkbits = h_inode->i_blkbits;
4876 + au_cpup_igen(inode, h_inode);
4879 +/* ---------------------------------------------------------------------- */
4881 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4883 +/* keep the timestamps of the parent dir when cpup */
4884 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4885 + struct path *h_path)
4887 + struct inode *h_inode;
4889 + dt->dt_dentry = dentry;
4890 + dt->dt_h_path = *h_path;
4891 + h_inode = d_inode(h_path->dentry);
4892 + dt->dt_atime = h_inode->i_atime;
4893 + dt->dt_mtime = h_inode->i_mtime;
4897 +void au_dtime_revert(struct au_dtime *dt)
4899 + struct iattr attr;
4902 + attr.ia_atime = dt->dt_atime;
4903 + attr.ia_mtime = dt->dt_mtime;
4904 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4905 + | ATTR_ATIME | ATTR_ATIME_SET;
4907 + /* no delegation since this is a directory */
4908 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4909 + if (unlikely(err))
4910 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4913 +/* ---------------------------------------------------------------------- */
4915 +/* internal use only */
4916 +struct au_cpup_reg_attr {
4919 + unsigned int iflags; /* inode->i_flags */
4922 +static noinline_for_stack
4923 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4924 + struct au_cpup_reg_attr *h_src_attr)
4926 + int err, sbits, icex;
4927 + unsigned int mnt_flags;
4928 + unsigned char verbose;
4930 + struct path h_path;
4931 + struct inode *h_isrc, *h_idst;
4932 + struct kstat *h_st;
4933 + struct au_branch *br;
4935 + br = au_sbr(dst->d_sb, bindex);
4936 + h_path.mnt = au_br_mnt(br);
4937 + h_path.dentry = au_h_dptr(dst, bindex);
4938 + h_idst = d_inode(h_path.dentry);
4939 + h_isrc = d_inode(h_src->dentry);
4940 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4941 + | ATTR_ATIME | ATTR_MTIME
4942 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4943 + if (h_src_attr && h_src_attr->valid) {
4944 + h_st = &h_src_attr->st;
4945 + ia.ia_uid = h_st->uid;
4946 + ia.ia_gid = h_st->gid;
4947 + ia.ia_atime = h_st->atime;
4948 + ia.ia_mtime = h_st->mtime;
4949 + if (h_idst->i_mode != h_st->mode
4950 + && !S_ISLNK(h_idst->i_mode)) {
4951 + ia.ia_valid |= ATTR_MODE;
4952 + ia.ia_mode = h_st->mode;
4954 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4955 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4957 + ia.ia_uid = h_isrc->i_uid;
4958 + ia.ia_gid = h_isrc->i_gid;
4959 + ia.ia_atime = h_isrc->i_atime;
4960 + ia.ia_mtime = h_isrc->i_mtime;
4961 + if (h_idst->i_mode != h_isrc->i_mode
4962 + && !S_ISLNK(h_idst->i_mode)) {
4963 + ia.ia_valid |= ATTR_MODE;
4964 + ia.ia_mode = h_isrc->i_mode;
4966 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4967 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4969 + /* no delegation since it is just created */
4970 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4972 + /* is this nfs only? */
4973 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4974 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4975 + ia.ia_mode = h_isrc->i_mode;
4976 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4979 + icex = br->br_perm & AuBrAttr_ICEX;
4981 + mnt_flags = au_mntflags(dst->d_sb);
4982 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4983 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4989 +/* ---------------------------------------------------------------------- */
4991 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4992 + char *buf, unsigned long blksize)
4995 + size_t sz, rbytes, wbytes;
4996 + unsigned char all_zero;
4998 + struct inode *h_inode;
4999 + /* reduce stack usage */
5002 + zp = page_address(ZERO_PAGE(0));
5003 + if (unlikely(!zp))
5004 + return -ENOMEM; /* possible? */
5009 + AuDbg("len %lld\n", len);
5011 + if (len < blksize)
5015 + /* todo: signal_pending? */
5016 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5017 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5020 + if (unlikely(err < 0))
5024 + if (len >= rbytes && rbytes == blksize)
5025 + all_zero = !memcmp(buf, zp, rbytes);
5032 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5034 + /* todo: signal_pending? */
5035 + if (unlikely(err == -EAGAIN || err == -EINTR))
5037 + if (unlikely(err < 0))
5042 + if (unlikely(err < 0))
5048 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5050 + if (unlikely(res < 0))
5057 + /* the last block may be a hole */
5058 + if (!err && all_zero) {
5059 + AuLabel(last hole);
5062 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5063 + /* nfs requires this step to make last hole */
5064 + /* is this only nfs? */
5066 + /* todo: signal_pending? */
5067 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5068 + } while (err == -EAGAIN || err == -EINTR);
5075 + ia->ia_size = dst->f_pos;
5076 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5077 + ia->ia_file = dst;
5078 + h_inode = file_inode(dst);
5079 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5080 + /* no delegation since it is just created */
5081 + err = vfsub_notify_change(&dst->f_path, ia,
5082 + /*delegated*/NULL);
5083 + inode_unlock(h_inode);
5090 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5093 + unsigned long blksize;
5094 + unsigned char do_kfree;
5096 + struct super_block *h_sb;
5099 + h_sb = file_inode(dst)->i_sb;
5100 + blksize = h_sb->s_blocksize;
5101 + if (!blksize || PAGE_SIZE < blksize)
5102 + blksize = PAGE_SIZE;
5103 + AuDbg("blksize %lu\n", blksize);
5104 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5106 + buf = kmalloc(blksize, GFP_NOFS);
5108 + buf = (void *)__get_free_page(GFP_NOFS);
5109 + if (unlikely(!buf))
5112 + if (len > (1 << 22))
5113 + AuDbg("copying a large file %lld\n", (long long)len);
5117 + err = au_do_copy_file(dst, src, len, buf, blksize);
5119 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5120 + au_kfree_do_rcu(buf);
5122 + free_page((unsigned long)buf);
5128 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5131 + struct super_block *h_src_sb;
5132 + struct inode *h_src_inode;
5134 + h_src_inode = file_inode(src);
5135 + h_src_sb = h_src_inode->i_sb;
5137 + /* XFS acquires inode_lock */
5138 + if (!au_test_xfs(h_src_sb))
5139 + err = au_copy_file(dst, src, len);
5141 + inode_unlock_shared(h_src_inode);
5142 + err = au_copy_file(dst, src, len);
5143 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5149 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5153 + struct super_block *h_src_sb;
5154 + struct inode *h_src_inode;
5156 + h_src_inode = file_inode(src);
5157 + h_src_sb = h_src_inode->i_sb;
5158 + if (h_src_sb != file_inode(dst)->i_sb
5159 + || !dst->f_op->remap_file_range) {
5160 + err = au_do_copy(dst, src, len);
5164 + if (!au_test_nfs(h_src_sb)) {
5165 + inode_unlock_shared(h_src_inode);
5166 + lo = vfsub_clone_file_range(src, dst, len);
5167 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5169 + lo = vfsub_clone_file_range(src, dst, len);
5172 + goto out; /* success */
5173 + } else if (lo >= 0)
5174 + /* todo: possible? */
5175 + /* paritially succeeded */
5176 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5177 + else if (lo != -EOPNOTSUPP) {
5178 + /* older XFS has a condition in cloning */
5183 + /* the backend fs on NFS may not support cloning */
5184 + err = au_do_copy(dst, src, len);
5192 + * to support a sparse file which is opened with O_APPEND,
5193 + * we need to close the file.
5195 +static int au_cp_regular(struct au_cp_generic *cpg)
5198 + enum { SRC, DST };
5200 + aufs_bindex_t bindex;
5201 + unsigned int flags;
5202 + struct dentry *dentry;
5204 + struct file *file;
5207 + .bindex = cpg->bsrc,
5208 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5211 + .bindex = cpg->bdst,
5212 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5213 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5216 + struct au_branch *br;
5217 + struct super_block *sb, *h_src_sb;
5218 + struct inode *h_src_inode;
5219 + struct task_struct *tsk = current;
5221 + /* bsrc branch can be ro/rw. */
5222 + sb = cpg->dentry->d_sb;
5224 + for (i = 0; i < 2; i++, f++) {
5225 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5226 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5227 + /*file*/NULL, f->force_wr);
5228 + if (IS_ERR(f->file)) {
5229 + err = PTR_ERR(f->file);
5237 + /* try stopping to update while we copyup */
5238 + h_src_inode = d_inode(file[SRC].dentry);
5239 + h_src_sb = h_src_inode->i_sb;
5240 + if (!au_test_nfs(h_src_sb))
5241 + IMustLock(h_src_inode);
5242 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5244 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5245 + if (tsk->flags & PF_KTHREAD)
5246 + __fput_sync(file[DST].file);
5248 + /* it happened actually */
5249 + fput(file[DST].file);
5252 + * we have to call both since we don't know which place the file
5256 + flush_delayed_fput();
5258 + br = au_sbr(sb, file[DST].bindex);
5259 + au_lcnt_dec(&br->br_nfiles);
5262 + fput(file[SRC].file);
5263 + br = au_sbr(sb, file[SRC].bindex);
5264 + au_lcnt_dec(&br->br_nfiles);
5269 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5270 + struct au_cpup_reg_attr *h_src_attr)
5274 + struct path h_path;
5275 + struct inode *h_src_inode, *h_dst_inode;
5278 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5279 + l = i_size_read(h_src_inode);
5280 + if (cpg->len == -1 || l < cpg->len)
5283 + /* try stopping to update while we are referencing */
5284 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5285 + au_pin_hdir_unlock(cpg->pin);
5287 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5288 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5289 + h_src_attr->iflags = h_src_inode->i_flags;
5290 + if (!au_test_nfs(h_src_inode->i_sb))
5291 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5293 + inode_unlock_shared(h_src_inode);
5294 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5295 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5297 + if (unlikely(err)) {
5298 + inode_unlock_shared(h_src_inode);
5301 + h_src_attr->valid = 1;
5302 + if (!au_test_nfs(h_src_inode->i_sb)) {
5303 + err = au_cp_regular(cpg);
5304 + inode_unlock_shared(h_src_inode);
5306 + inode_unlock_shared(h_src_inode);
5307 + err = au_cp_regular(cpg);
5309 + rerr = au_pin_hdir_relock(cpg->pin);
5313 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5314 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5315 + h_dst_inode = d_inode(h_path.dentry);
5316 + spin_lock(&h_dst_inode->i_lock);
5317 + h_dst_inode->i_state |= I_LINKABLE;
5318 + spin_unlock(&h_dst_inode->i_lock);
5325 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5326 + struct inode *h_dir)
5329 + DEFINE_DELAYED_CALL(done);
5332 + sym = vfs_get_link(h_src, &done);
5333 + err = PTR_ERR(sym);
5337 + err = vfsub_symlink(h_dir, h_path, sym);
5340 + do_delayed_call(&done);
5345 + * regardless 'acl' option, reset all ACL.
5346 + * All ACL will be copied up later from the original entry on the lower branch.
5348 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5351 + struct dentry *h_dentry;
5352 + struct inode *h_inode;
5353 + struct user_namespace *h_userns;
5355 + h_userns = mnt_user_ns(h_path->mnt);
5356 + h_dentry = h_path->dentry;
5357 + h_inode = d_inode(h_dentry);
5358 + /* forget_all_cached_acls(h_inode)); */
5359 + err = vfsub_removexattr(h_userns, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5361 + if (err == -EOPNOTSUPP)
5364 + err = vfsub_acl_chmod(h_userns, h_inode, mode);
5370 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5371 + struct inode *h_dir, struct path *h_path)
5374 + struct inode *dir, *inode;
5375 + struct user_namespace *h_userns;
5377 + h_userns = mnt_user_ns(h_path->mnt);
5378 + err = vfsub_removexattr(h_userns, h_path->dentry,
5379 + XATTR_NAME_POSIX_ACL_DEFAULT);
5381 + if (err == -EOPNOTSUPP)
5383 + if (unlikely(err))
5387 + * strange behaviour from the users view,
5388 + * particularly setattr case
5390 + dir = d_inode(dst_parent);
5391 + if (au_ibtop(dir) == cpg->bdst)
5392 + au_cpup_attr_nlink(dir, /*force*/1);
5393 + inode = d_inode(cpg->dentry);
5394 + au_cpup_attr_nlink(inode, /*force*/1);
5400 +static noinline_for_stack
5401 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5402 + struct au_cpup_reg_attr *h_src_attr)
5406 + unsigned int mnt_flags;
5407 + unsigned char isdir, isreg, force;
5408 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5409 + struct au_dtime dt;
5410 + struct path h_path;
5411 + struct dentry *h_src, *h_dst, *h_parent;
5412 + struct inode *h_inode, *h_dir;
5413 + struct super_block *sb;
5415 + /* bsrc branch can be ro/rw. */
5416 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5417 + h_inode = d_inode(h_src);
5418 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5420 + /* try stopping to be referenced while we are creating */
5421 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5422 + if (au_ftest_cpup(cpg->flags, RENAME))
5423 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5424 + AUFS_WH_PFX_LEN));
5425 + h_parent = h_dst->d_parent; /* dir inode is locked */
5426 + h_dir = d_inode(h_parent);
5428 + AuDebugOn(h_parent != h_dst->d_parent);
5430 + sb = cpg->dentry->d_sb;
5431 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5433 + h_path.dentry = h_parent;
5434 + au_dtime_store(&dt, dst_parent, &h_path);
5436 + h_path.dentry = h_dst;
5440 + mode = h_inode->i_mode;
5441 + switch (mode & S_IFMT) {
5444 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5446 + err = au_do_cpup_regular(cpg, h_src_attr);
5450 + err = vfsub_mkdir(h_dir, &h_path, mode);
5452 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5455 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5459 + AuDebugOn(!capable(CAP_MKNOD));
5463 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5466 + AuIOErr("Unknown inode type 0%o\n", mode);
5470 + err = au_reset_acl(h_dir, &h_path, mode);
5472 + mnt_flags = au_mntflags(sb);
5473 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5475 + && au_opt_test(mnt_flags, XINO)
5476 + && (h_inode->i_nlink == 1
5477 + || (h_inode->i_state & I_LINKABLE))
5478 + /* todo: unnecessary? */
5479 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5480 + && cpg->bdst < cpg->bsrc
5481 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5482 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5483 + /* ignore this error */
5488 + force = !!cpg->len;
5489 + if (cpg->len == -1)
5490 + force = !!i_size_read(h_inode);
5492 + au_fhsm_wrote(sb, cpg->bdst, force);
5496 + au_dtime_revert(&dt);
5500 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5503 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5504 + struct path h_ppath;
5505 + struct inode *h_dir;
5506 + aufs_bindex_t bdst;
5508 + dentry = cpg->dentry;
5510 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5511 + h_dentry = au_h_dptr(dentry, bdst);
5512 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5514 + au_set_h_dptr(dentry, bdst, NULL);
5515 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5517 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5518 + au_set_h_dptr(dentry, bdst, h_dentry);
5521 + parent = dget_parent(dentry);
5522 + h_ppath.dentry = au_h_dptr(parent, bdst);
5524 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5525 + if (IS_ERR(h_path->dentry))
5526 + err = PTR_ERR(h_path->dentry);
5528 + if (unlikely(err))
5531 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5532 + h_dir = d_inode(h_parent);
5534 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5535 + /* no delegation since it is just created */
5536 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5538 + dput(h_path->dentry);
5545 + * copyup the @dentry from @bsrc to @bdst.
5546 + * the caller must set the both of lower dentries.
5547 + * @len is for truncating when it is -1 copyup the entire file.
5548 + * in link/rename cases, @dst_parent may be different from the real one.
5549 + * basic->bsrc can be larger than basic->bdst.
5550 + * aufs doesn't touch the credential so
5551 + * security_inode_copy_up{,_xattr}() are unnecessary.
5553 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5556 + aufs_bindex_t old_ibtop;
5557 + unsigned char isdir, plink;
5558 + struct dentry *h_src, *h_dst, *h_parent;
5559 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5560 + struct super_block *sb;
5561 + struct au_branch *br;
5562 + struct path h_src_path;
5563 + /* to reduce stack size */
5565 + struct au_dtime dt;
5566 + struct path h_path;
5567 + struct au_cpup_reg_attr h_src_attr;
5571 + a = kmalloc(sizeof(*a), GFP_NOFS);
5574 + a->h_src_attr.valid = 0;
5576 + sb = cpg->dentry->d_sb;
5577 + br = au_sbr(sb, cpg->bdst);
5578 + a->h_path.mnt = au_br_mnt(br);
5579 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5580 + h_parent = h_dst->d_parent; /* dir inode is locked */
5581 + h_dir = d_inode(h_parent);
5584 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5585 + inode = d_inode(cpg->dentry);
5588 + dst_parent = dget_parent(cpg->dentry);
5592 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5593 + dst_inode = au_h_iptr(inode, cpg->bdst);
5595 + if (unlikely(!plink)) {
5597 + AuIOErr("hi%lu(i%lu) exists on b%d "
5598 + "but plink is disabled\n",
5599 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5603 + if (dst_inode->i_nlink) {
5604 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5606 + h_src = au_plink_lkup(inode, cpg->bdst);
5607 + err = PTR_ERR(h_src);
5608 + if (IS_ERR(h_src))
5610 + if (unlikely(d_is_negative(h_src))) {
5612 + AuIOErr("i%lu exists on b%d "
5613 + "but not pseudo-linked\n",
5614 + inode->i_ino, cpg->bdst);
5620 + a->h_path.dentry = h_parent;
5621 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5624 + a->h_path.dentry = h_dst;
5626 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5627 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5628 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5630 + au_dtime_revert(&a->dt);
5631 + if (unlikely(err == -EWOULDBLOCK)) {
5632 + pr_warn("cannot retry for NFSv4 delegation"
5633 + " for an internal link\n");
5639 + /* todo: cpup_wh_file? */
5641 + au_update_ibrange(inode, /*do_put_zero*/1);
5644 + isdir = S_ISDIR(inode->i_mode);
5645 + old_ibtop = au_ibtop(inode);
5646 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5647 + if (unlikely(err))
5649 + dst_inode = d_inode(h_dst);
5650 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5651 + /* todo: necessary? */
5652 + /* au_pin_hdir_unlock(cpg->pin); */
5654 + h_src_path.dentry = h_src;
5655 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5656 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5657 + if (unlikely(err)) {
5658 + /* todo: necessary? */
5659 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5660 + inode_unlock(dst_inode);
5664 + if (cpg->bdst < old_ibtop) {
5665 + if (S_ISREG(inode->i_mode)) {
5666 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5667 + if (unlikely(err)) {
5668 + /* ignore an error */
5669 + /* au_pin_hdir_relock(cpg->pin); */
5670 + inode_unlock(dst_inode);
5674 + au_set_ibtop(inode, cpg->bdst);
5676 + au_set_ibbot(inode, cpg->bdst);
5677 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5678 + au_hi_flags(inode, isdir));
5680 + /* todo: necessary? */
5681 + /* err = au_pin_hdir_relock(cpg->pin); */
5682 + inode_unlock(dst_inode);
5683 + if (unlikely(err))
5686 + src_inode = d_inode(h_src);
5688 + && (src_inode->i_nlink > 1
5689 + || src_inode->i_state & I_LINKABLE)
5691 + au_plink_append(inode, cpg->bdst, h_dst);
5693 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5694 + a->h_path.dentry = h_dst;
5695 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5698 + goto out_parent; /* success */
5702 + a->h_path.dentry = h_parent;
5703 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5704 + a->h_path.dentry = h_dst;
5706 + if (d_is_positive(h_dst)) {
5708 + /* no delegation since it is just created */
5709 + rerr = vfsub_unlink(h_dir, &a->h_path,
5710 + /*delegated*/NULL, /*force*/0);
5712 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5714 + au_dtime_revert(&a->dt);
5716 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5726 +#if 0 /* reserved */
5727 +struct au_cpup_single_args {
5729 + struct au_cp_generic *cpg;
5730 + struct dentry *dst_parent;
5733 +static void au_call_cpup_single(void *args)
5735 + struct au_cpup_single_args *a = args;
5737 + au_pin_hdir_acquire_nest(a->cpg->pin);
5738 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5739 + au_pin_hdir_release(a->cpg->pin);
5744 + * prevent SIGXFSZ in copy-up.
5745 + * testing CAP_MKNOD is for generic fs,
5746 + * but CAP_FSETID is for xfs only, currently.
5748 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5751 + struct super_block *sb;
5752 + struct inode *h_dir;
5755 + sb = au_pinned_parent(pin)->d_sb;
5756 + if (!au_wkq_test()
5757 + && (!au_sbi(sb)->si_plink_maint_pid
5758 + || au_plink_maint(sb, AuLock_NOPLM))) {
5759 + switch (mode & S_IFMT) {
5761 + /* no condition about RLIMIT_FSIZE and the file size */
5766 + do_sio = !capable(CAP_MKNOD);
5770 + do_sio = ((mode & (S_ISUID | S_ISGID))
5771 + && !capable(CAP_FSETID));
5772 + /* this workaround may be removed in the future */
5774 + h_dir = au_pinned_h_dir(pin);
5775 + do_sio = h_dir->i_mode & S_ISVTX;
5782 +#if 0 /* reserved */
5783 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5786 + struct dentry *h_dentry;
5788 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5789 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5790 + err = au_cpup_single(cpg, dst_parent);
5792 + struct au_cpup_single_args args = {
5795 + .dst_parent = dst_parent
5797 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5798 + if (unlikely(wkq_err))
5807 + * copyup the @dentry from the first active lower branch to @bdst,
5808 + * using au_cpup_single().
5810 +static int au_cpup_simple(struct au_cp_generic *cpg)
5813 + unsigned int flags_orig;
5814 + struct dentry *dentry;
5816 + AuDebugOn(cpg->bsrc < 0);
5818 + dentry = cpg->dentry;
5819 + DiMustWriteLock(dentry);
5821 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5823 + flags_orig = cpg->flags;
5824 + au_fset_cpup(cpg->flags, RENAME);
5825 + err = au_cpup_single(cpg, NULL);
5826 + cpg->flags = flags_orig;
5828 + return 0; /* success */
5831 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5832 + au_set_dbtop(dentry, cpg->bsrc);
5838 +struct au_cpup_simple_args {
5840 + struct au_cp_generic *cpg;
5843 +static void au_call_cpup_simple(void *args)
5845 + struct au_cpup_simple_args *a = args;
5847 + au_pin_hdir_acquire_nest(a->cpg->pin);
5848 + *a->errp = au_cpup_simple(a->cpg);
5849 + au_pin_hdir_release(a->cpg->pin);
5852 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5855 + struct dentry *dentry, *parent;
5856 + struct file *h_file;
5857 + struct inode *h_dir;
5858 + struct user_namespace *h_userns;
5860 + dentry = cpg->dentry;
5862 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5863 + AuDebugOn(cpg->bsrc < 0);
5864 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5865 + err = PTR_ERR(h_file);
5866 + if (IS_ERR(h_file))
5870 + parent = dget_parent(dentry);
5871 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5872 + h_userns = au_sbr_userns(dentry->d_sb, cpg->bdst);
5873 + if (!au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC | MAY_WRITE)
5874 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5875 + err = au_cpup_simple(cpg);
5877 + struct au_cpup_simple_args args = {
5881 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5882 + if (unlikely(wkq_err))
5888 + au_h_open_post(dentry, cpg->bsrc, h_file);
5894 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5896 + aufs_bindex_t bsrc, bbot;
5897 + struct dentry *dentry, *h_dentry;
5899 + if (cpg->bsrc < 0) {
5900 + dentry = cpg->dentry;
5901 + bbot = au_dbbot(dentry);
5902 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5903 + h_dentry = au_h_dptr(dentry, bsrc);
5905 + AuDebugOn(d_is_negative(h_dentry));
5909 + AuDebugOn(bsrc > bbot);
5912 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5913 + return au_do_sio_cpup_simple(cpg);
5916 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5918 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5919 + return au_do_sio_cpup_simple(cpg);
5922 +/* ---------------------------------------------------------------------- */
5925 + * copyup the deleted file for writing.
5927 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5928 + struct file *file)
5931 + unsigned int flags_orig;
5932 + aufs_bindex_t bsrc_orig;
5933 + struct au_dinfo *dinfo;
5935 + struct au_hdentry *hd;
5936 + struct dentry *h_dentry;
5939 + dinfo = au_di(cpg->dentry);
5940 + AuRwMustWriteLock(&dinfo->di_rwsem);
5942 + bsrc_orig = cpg->bsrc;
5943 + cpg->bsrc = dinfo->di_btop;
5944 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5945 + hdst.h_dentry = hdst.hd->hd_dentry;
5946 + hdst.hd->hd_dentry = wh_dentry;
5947 + dinfo->di_btop = cpg->bdst;
5949 + hsrc.h_dentry = NULL;
5951 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5952 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5953 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5955 + flags_orig = cpg->flags;
5956 + cpg->flags = !AuCpup_DTIME;
5957 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5958 + cpg->flags = flags_orig;
5961 + err = au_reopen_nondir(file);
5962 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5964 + hdst.hd->hd_dentry = hdst.h_dentry;
5965 + dinfo->di_btop = cpg->bsrc;
5966 + cpg->bsrc = bsrc_orig;
5971 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5974 + aufs_bindex_t bdst;
5975 + struct au_dtime dt;
5976 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5977 + struct au_branch *br;
5978 + struct path h_path;
5980 + dentry = cpg->dentry;
5982 + br = au_sbr(dentry->d_sb, bdst);
5983 + parent = dget_parent(dentry);
5984 + h_parent = au_h_dptr(parent, bdst);
5985 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5986 + err = PTR_ERR(wh_dentry);
5987 + if (IS_ERR(wh_dentry))
5990 + h_path.dentry = h_parent;
5991 + h_path.mnt = au_br_mnt(br);
5992 + au_dtime_store(&dt, parent, &h_path);
5993 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5994 + if (unlikely(err))
5998 + h_path.dentry = wh_dentry;
5999 + if (!d_is_dir(wh_dentry)) {
6000 + /* no delegation since it is just created */
6001 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6002 + /*delegated*/NULL, /*force*/0);
6004 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6005 + if (unlikely(err)) {
6006 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6010 + au_dtime_revert(&dt);
6011 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6020 +struct au_cpup_wh_args {
6022 + struct au_cp_generic *cpg;
6023 + struct file *file;
6026 +static void au_call_cpup_wh(void *args)
6028 + struct au_cpup_wh_args *a = args;
6030 + au_pin_hdir_acquire_nest(a->cpg->pin);
6031 + *a->errp = au_cpup_wh(a->cpg, a->file);
6032 + au_pin_hdir_release(a->cpg->pin);
6035 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6038 + aufs_bindex_t bdst;
6039 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6040 + struct inode *dir, *h_dir, *h_tmpdir;
6041 + struct au_wbr *wbr;
6042 + struct au_pin wh_pin, *pin_orig;
6043 + struct user_namespace *h_userns;
6045 + dentry = cpg->dentry;
6047 + parent = dget_parent(dentry);
6048 + dir = d_inode(parent);
6051 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6054 + if (!h_dir->i_nlink) {
6055 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6056 + h_orph = wbr->wbr_orph;
6058 + h_parent = dget(au_h_dptr(parent, bdst));
6059 + au_set_h_dptr(parent, bdst, dget(h_orph));
6060 + h_tmpdir = d_inode(h_orph);
6061 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6063 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6064 + /* todo: au_h_open_pre()? */
6066 + pin_orig = cpg->pin;
6067 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6068 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6069 + cpg->pin = &wh_pin;
6072 + h_userns = au_sbr_userns(dentry->d_sb, bdst);
6073 + if (!au_test_h_perm_sio(h_userns, h_tmpdir, MAY_EXEC | MAY_WRITE)
6074 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6075 + err = au_cpup_wh(cpg, file);
6077 + struct au_cpup_wh_args args = {
6082 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6083 + if (unlikely(wkq_err))
6088 + inode_unlock(h_tmpdir);
6089 + /* todo: au_h_open_post()? */
6090 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6091 + au_set_h_dptr(parent, bdst, h_parent);
6092 + AuDebugOn(!pin_orig);
6093 + cpg->pin = pin_orig;
6101 +/* ---------------------------------------------------------------------- */
6104 + * generic routine for both of copy-up and copy-down.
6106 +/* cf. revalidate function in file.c */
6107 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6108 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6109 + struct au_pin *pin,
6110 + struct dentry *h_parent, void *arg),
6114 + struct au_pin pin;
6115 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6118 + parent = dget_parent(dentry);
6119 + if (IS_ROOT(parent))
6122 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6123 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6125 + /* do not use au_dpage */
6126 + real_parent = parent;
6129 + parent = dget_parent(dentry);
6130 + h_parent = au_h_dptr(parent, bdst);
6132 + goto out; /* success */
6134 + /* find top dir which is necessary to cpup */
6138 + parent = dget_parent(d);
6139 + di_read_lock_parent3(parent, !AuLock_IR);
6140 + h_parent = au_h_dptr(parent, bdst);
6141 + di_read_unlock(parent, !AuLock_IR);
6142 + } while (!h_parent);
6144 + if (d != real_parent)
6145 + di_write_lock_child3(d);
6147 + /* somebody else might create while we were sleeping */
6148 + h_dentry = au_h_dptr(d, bdst);
6149 + if (!h_dentry || d_is_negative(h_dentry)) {
6151 + au_update_dbtop(d);
6153 + au_pin_set_dentry(&pin, d);
6154 + err = au_do_pin(&pin);
6156 + err = cp(d, bdst, &pin, h_parent, arg);
6161 + if (d != real_parent)
6162 + di_write_unlock(d);
6163 + if (unlikely(err))
6172 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6173 + struct au_pin *pin,
6174 + struct dentry *h_parent __maybe_unused,
6175 + void *arg __maybe_unused)
6177 + struct au_cp_generic cpg = {
6183 + .flags = AuCpup_DTIME
6185 + return au_sio_cpup_simple(&cpg);
6188 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6190 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6193 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6196 + struct dentry *parent;
6197 + struct inode *dir;
6199 + parent = dget_parent(dentry);
6200 + dir = d_inode(parent);
6202 + if (au_h_iptr(dir, bdst))
6205 + di_read_unlock(parent, AuLock_IR);
6206 + di_write_lock_parent(parent);
6207 + /* someone else might change our inode while we were sleeping */
6208 + if (!au_h_iptr(dir, bdst))
6209 + err = au_cpup_dirs(dentry, bdst);
6210 + di_downgrade_lock(parent, AuLock_IR);
6216 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6217 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6218 +++ linux/fs/aufs/cpup.h 2021-11-01 23:48:34.203025928 +0100
6220 +/* SPDX-License-Identifier: GPL-2.0 */
6222 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6224 + * This program, aufs is free software; you can redistribute it and/or modify
6225 + * it under the terms of the GNU General Public License as published by
6226 + * the Free Software Foundation; either version 2 of the License, or
6227 + * (at your option) any later version.
6229 + * This program is distributed in the hope that it will be useful,
6230 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6231 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6232 + * GNU General Public License for more details.
6234 + * You should have received a copy of the GNU General Public License
6235 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6239 + * copy-up/down functions
6242 +#ifndef __AUFS_CPUP_H__
6243 +#define __AUFS_CPUP_H__
6247 +#include <linux/path.h>
6253 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6254 +void au_cpup_attr_timesizes(struct inode *inode);
6255 +void au_cpup_attr_nlink(struct inode *inode, int force);
6256 +void au_cpup_attr_changeable(struct inode *inode);
6257 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6258 +void au_cpup_attr_all(struct inode *inode, int force);
6260 +/* ---------------------------------------------------------------------- */
6262 +struct au_cp_generic {
6263 + struct dentry *dentry;
6264 + aufs_bindex_t bdst, bsrc;
6266 + struct au_pin *pin;
6267 + unsigned int flags;
6271 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6272 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6274 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6275 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6277 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6279 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6280 + the branch is marked as RO */
6282 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6283 +#undef AuCpup_HOPEN
6284 +#define AuCpup_HOPEN 0
6287 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6288 +#define au_fset_cpup(flags, name) \
6289 + do { (flags) |= AuCpup_##name; } while (0)
6290 +#define au_fclr_cpup(flags, name) \
6291 + do { (flags) &= ~AuCpup_##name; } while (0)
6293 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6294 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6295 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6296 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6298 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6299 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6300 + struct au_pin *pin,
6301 + struct dentry *h_parent, void *arg),
6303 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6304 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6306 +/* ---------------------------------------------------------------------- */
6308 +/* keep timestamps when copyup */
6310 + struct dentry *dt_dentry;
6311 + struct path dt_h_path;
6312 + struct timespec64 dt_atime, dt_mtime;
6314 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6315 + struct path *h_path);
6316 +void au_dtime_revert(struct au_dtime *dt);
6318 +#endif /* __KERNEL__ */
6319 +#endif /* __AUFS_CPUP_H__ */
6320 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6321 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6322 +++ linux/fs/aufs/dbgaufs.c 2021-11-01 23:48:34.203025928 +0100
6324 +// SPDX-License-Identifier: GPL-2.0
6326 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6328 + * This program, aufs is free software; you can redistribute it and/or modify
6329 + * it under the terms of the GNU General Public License as published by
6330 + * the Free Software Foundation; either version 2 of the License, or
6331 + * (at your option) any later version.
6333 + * This program is distributed in the hope that it will be useful,
6334 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6335 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6336 + * GNU General Public License for more details.
6338 + * You should have received a copy of the GNU General Public License
6339 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6343 + * debugfs interface
6346 +#include <linux/debugfs.h>
6349 +#ifndef CONFIG_SYSFS
6350 +#error DEBUG_FS depends upon SYSFS
6353 +static struct dentry *dbgaufs;
6354 +static const mode_t dbgaufs_mode = 0444;
6356 +/* 20 is max digits length of ulong 64 */
6357 +struct dbgaufs_arg {
6363 + * common function for all XINO files
6365 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6366 + struct file *file)
6370 + p = file->private_data;
6372 + /* this is struct dbgaufs_arg */
6373 + AuDebugOn(!au_kfree_sz_test(p));
6374 + au_kfree_do_rcu(p);
6379 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6384 + struct dbgaufs_arg *p;
6387 + p = kmalloc(sizeof(*p), GFP_NOFS);
6393 + file->private_data = p;
6397 + err = vfsub_getattr(&xf->f_path, &st);
6401 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6402 + cnt, st.blocks, st.blksize,
6403 + (long long)st.size);
6405 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6406 + st.blocks, st.blksize,
6407 + (long long)st.size);
6408 + AuDebugOn(p->n >= sizeof(p->a));
6410 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6418 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6419 + size_t count, loff_t *ppos)
6421 + struct dbgaufs_arg *p;
6423 + p = file->private_data;
6424 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6427 +/* ---------------------------------------------------------------------- */
6429 +struct dbgaufs_plink_arg {
6434 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6435 + struct file *file)
6437 + free_page((unsigned long)file->private_data);
6441 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6443 + int err, i, limit;
6444 + unsigned long n, sum;
6445 + struct dbgaufs_plink_arg *p;
6446 + struct au_sbinfo *sbinfo;
6447 + struct super_block *sb;
6448 + struct hlist_bl_head *hbl;
6451 + p = (void *)get_zeroed_page(GFP_NOFS);
6456 + sbinfo = inode->i_private;
6457 + sb = sbinfo->si_sb;
6458 + si_noflush_read_lock(sb);
6459 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6460 + limit = PAGE_SIZE - sizeof(p->n);
6462 + /* the number of buckets */
6463 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6468 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6470 + n = au_hbl_count(hbl);
6473 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6476 + if (unlikely(limit <= 0))
6479 + p->a[p->n - 1] = '\n';
6481 + /* the sum of plinks */
6482 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6485 + if (unlikely(limit <= 0))
6488 +#define str "1\n0\n0\n"
6489 + p->n = sizeof(str) - 1;
6490 + strcpy(p->a, str);
6493 + si_read_unlock(sb);
6496 + file->private_data = p;
6497 + goto out; /* success */
6500 + free_page((unsigned long)p);
6505 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6506 + size_t count, loff_t *ppos)
6508 + struct dbgaufs_plink_arg *p;
6510 + p = file->private_data;
6511 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6514 +static const struct file_operations dbgaufs_plink_fop = {
6515 + .owner = THIS_MODULE,
6516 + .open = dbgaufs_plink_open,
6517 + .release = dbgaufs_plink_release,
6518 + .read = dbgaufs_plink_read
6521 +/* ---------------------------------------------------------------------- */
6523 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6526 + struct au_sbinfo *sbinfo;
6527 + struct super_block *sb;
6529 + sbinfo = inode->i_private;
6530 + sb = sbinfo->si_sb;
6531 + si_noflush_read_lock(sb);
6532 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6533 + si_read_unlock(sb);
6537 +static const struct file_operations dbgaufs_xib_fop = {
6538 + .owner = THIS_MODULE,
6539 + .open = dbgaufs_xib_open,
6540 + .release = dbgaufs_xi_release,
6541 + .read = dbgaufs_xi_read
6544 +/* ---------------------------------------------------------------------- */
6546 +#define DbgaufsXi_PREFIX "xi"
6548 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6552 + aufs_bindex_t bindex;
6553 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6554 + struct au_sbinfo *sbinfo;
6555 + struct super_block *sb;
6556 + struct au_xino *xi;
6558 + struct qstr *name;
6559 + struct au_branch *br;
6562 + name = &file->f_path.dentry->d_name;
6563 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6564 + || memcmp(name->name, DbgaufsXi_PREFIX,
6565 + sizeof(DbgaufsXi_PREFIX) - 1)))
6568 + AuDebugOn(name->len >= sizeof(a));
6569 + memcpy(a, name->name, name->len);
6570 + a[name->len] = '\0';
6571 + p = strchr(a, '-');
6574 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6575 + if (unlikely(err))
6580 + err = kstrtol(p + 1, 10, &l);
6581 + if (unlikely(err))
6587 + sbinfo = inode->i_private;
6588 + sb = sbinfo->si_sb;
6589 + si_noflush_read_lock(sb);
6590 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6592 + br = au_sbr(sb, bindex);
6594 + if (unlikely(idx >= xi->xi_nfile))
6596 + xf = au_xino_file(xi, idx);
6598 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6599 + au_xino_count(br));
6602 + si_read_unlock(sb);
6608 +static const struct file_operations dbgaufs_xino_fop = {
6609 + .owner = THIS_MODULE,
6610 + .open = dbgaufs_xino_open,
6611 + .release = dbgaufs_xi_release,
6612 + .read = dbgaufs_xi_read
6615 +void dbgaufs_xino_del(struct au_branch *br)
6617 + struct dentry *dbgaufs;
6619 + dbgaufs = br->br_dbgaufs;
6623 + br->br_dbgaufs = NULL;
6624 + /* debugfs acquires the parent i_mutex */
6626 + debugfs_remove(dbgaufs);
6630 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6632 + aufs_bindex_t bbot;
6633 + struct au_branch *br;
6635 + if (!au_sbi(sb)->si_dbgaufs)
6638 + bbot = au_sbbot(sb);
6639 + for (; bindex <= bbot; bindex++) {
6640 + br = au_sbr(sb, bindex);
6641 + dbgaufs_xino_del(br);
6645 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6646 + unsigned int idx, struct dentry *parent,
6647 + struct au_sbinfo *sbinfo)
6649 + struct au_branch *br;
6651 + /* "xi" bindex(5) "-" idx(2) NULL */
6652 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6655 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6657 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6659 + br = au_sbr(sb, bindex);
6660 + if (br->br_dbgaufs) {
6661 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6663 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6664 + /* debugfs acquires the parent i_mutex */
6666 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6670 + pr_warn("failed renaming %pd/%s, ignored.\n",
6675 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6676 + sbinfo, &dbgaufs_xino_fop);
6678 + if (unlikely(!br->br_dbgaufs))
6679 + pr_warn("failed creating %pd/%s, ignored.\n",
6684 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6685 + struct dentry *parent, struct au_sbinfo *sbinfo)
6687 + struct au_branch *br;
6688 + struct au_xino *xi;
6691 + br = au_sbr(sb, bindex);
6693 + for (u = 0; u < xi->xi_nfile; u++)
6694 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6697 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6699 + struct au_sbinfo *sbinfo;
6700 + struct dentry *parent;
6701 + aufs_bindex_t bbot;
6703 + if (!au_opt_test(au_mntflags(sb), XINO))
6706 + sbinfo = au_sbi(sb);
6707 + parent = sbinfo->si_dbgaufs;
6711 + bbot = au_sbbot(sb);
6713 + for (; bindex <= bbot; bindex++)
6714 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6716 + for (; bbot >= bindex; bbot--)
6717 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6720 +/* ---------------------------------------------------------------------- */
6722 +#ifdef CONFIG_AUFS_EXPORT
6723 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6726 + struct au_sbinfo *sbinfo;
6727 + struct super_block *sb;
6729 + sbinfo = inode->i_private;
6730 + sb = sbinfo->si_sb;
6731 + si_noflush_read_lock(sb);
6732 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6733 + si_read_unlock(sb);
6737 +static const struct file_operations dbgaufs_xigen_fop = {
6738 + .owner = THIS_MODULE,
6739 + .open = dbgaufs_xigen_open,
6740 + .release = dbgaufs_xi_release,
6741 + .read = dbgaufs_xi_read
6744 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6749 + * This function is a dynamic '__init' function actually,
6750 + * so the tiny check for si_rwsem is unnecessary.
6752 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6755 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6756 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6757 + &dbgaufs_xigen_fop);
6758 + if (sbinfo->si_dbgaufs_xigen)
6764 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6768 +#endif /* CONFIG_AUFS_EXPORT */
6770 +/* ---------------------------------------------------------------------- */
6772 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6775 + * This function is a dynamic '__fin' function actually,
6776 + * so the tiny check for si_rwsem is unnecessary.
6778 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6780 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6781 + sbinfo->si_dbgaufs = NULL;
6784 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6787 + char name[SysaufsSiNameLen];
6790 + * This function is a dynamic '__init' function actually,
6791 + * so the tiny check for si_rwsem is unnecessary.
6793 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6797 + AuErr1("/debug/aufs is uninitialized\n");
6802 + sysaufs_name(sbinfo, name);
6803 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6804 + if (unlikely(!sbinfo->si_dbgaufs))
6807 + /* regardless plink/noplink option */
6808 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6809 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6810 + &dbgaufs_plink_fop);
6811 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6814 + /* regardless xino/noxino option */
6815 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6816 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6817 + &dbgaufs_xib_fop);
6818 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6821 + err = dbgaufs_xigen_init(sbinfo);
6823 + goto out; /* success */
6826 + dbgaufs_si_fin(sbinfo);
6828 + if (unlikely(err))
6829 + pr_err("debugfs/aufs failed\n");
6833 +/* ---------------------------------------------------------------------- */
6835 +void dbgaufs_fin(void)
6837 + debugfs_remove(dbgaufs);
6840 +int __init dbgaufs_init(void)
6845 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6850 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6851 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6852 +++ linux/fs/aufs/dbgaufs.h 2021-11-01 23:48:34.203025928 +0100
6854 +/* SPDX-License-Identifier: GPL-2.0 */
6856 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6858 + * This program, aufs is free software; you can redistribute it and/or modify
6859 + * it under the terms of the GNU General Public License as published by
6860 + * the Free Software Foundation; either version 2 of the License, or
6861 + * (at your option) any later version.
6863 + * This program is distributed in the hope that it will be useful,
6864 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6865 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6866 + * GNU General Public License for more details.
6868 + * You should have received a copy of the GNU General Public License
6869 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6873 + * debugfs interface
6876 +#ifndef __DBGAUFS_H__
6877 +#define __DBGAUFS_H__
6881 +struct super_block;
6885 +#ifdef CONFIG_DEBUG_FS
6887 +void dbgaufs_xino_del(struct au_branch *br);
6888 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6889 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6890 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6891 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6892 +void dbgaufs_fin(void);
6893 +int __init dbgaufs_init(void);
6895 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6896 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6897 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6899 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6900 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6901 +AuStubVoid(dbgaufs_fin, void)
6902 +AuStubInt0(__init dbgaufs_init, void)
6903 +#endif /* CONFIG_DEBUG_FS */
6905 +#endif /* __KERNEL__ */
6906 +#endif /* __DBGAUFS_H__ */
6907 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6908 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6909 +++ linux/fs/aufs/dcsub.c 2021-11-01 23:48:34.206359262 +0100
6911 +// SPDX-License-Identifier: GPL-2.0
6913 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6915 + * This program, aufs is free software; you can redistribute it and/or modify
6916 + * it under the terms of the GNU General Public License as published by
6917 + * the Free Software Foundation; either version 2 of the License, or
6918 + * (at your option) any later version.
6920 + * This program is distributed in the hope that it will be useful,
6921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6923 + * GNU General Public License for more details.
6925 + * You should have received a copy of the GNU General Public License
6926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6930 + * sub-routines for dentry cache
6935 +static void au_dpage_free(struct au_dpage *dpage)
6938 + struct dentry **p;
6940 + p = dpage->dentries;
6941 + for (i = 0; i < dpage->ndentry; i++)
6943 + free_page((unsigned long)dpage->dentries);
6946 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6952 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6953 + if (unlikely(!dpages->dpages))
6956 + p = (void *)__get_free_page(gfp);
6960 + dpages->dpages[0].ndentry = 0;
6961 + dpages->dpages[0].dentries = p;
6962 + dpages->ndpage = 1;
6963 + return 0; /* success */
6966 + au_kfree_try_rcu(dpages->dpages);
6971 +void au_dpages_free(struct au_dcsub_pages *dpages)
6974 + struct au_dpage *p;
6976 + p = dpages->dpages;
6977 + for (i = 0; i < dpages->ndpage; i++)
6978 + au_dpage_free(p++);
6979 + au_kfree_try_rcu(dpages->dpages);
6982 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6983 + struct dentry *dentry, gfp_t gfp)
6986 + struct au_dpage *dpage;
6989 + dpage = dpages->dpages + dpages->ndpage - 1;
6990 + sz = PAGE_SIZE / sizeof(dentry);
6991 + if (unlikely(dpage->ndentry >= sz)) {
6992 + AuLabel(new dpage);
6994 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6995 + p = au_kzrealloc(dpages->dpages, sz,
6996 + sz + sizeof(*dpages->dpages), gfp,
7001 + dpages->dpages = p;
7002 + dpage = dpages->dpages + dpages->ndpage;
7003 + p = (void *)__get_free_page(gfp);
7007 + dpage->ndentry = 0;
7008 + dpage->dentries = p;
7012 + AuDebugOn(au_dcount(dentry) <= 0);
7013 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7014 + return 0; /* success */
7020 +/* todo: BAD approach */
7021 +/* copied from linux/fs/dcache.c */
7029 +extern void d_walk(struct dentry *parent, void *data,
7030 + enum d_walk_ret (*enter)(void *, struct dentry *));
7032 +struct ac_dpages_arg {
7034 + struct au_dcsub_pages *dpages;
7035 + struct super_block *sb;
7036 + au_dpages_test test;
7040 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7042 + enum d_walk_ret ret;
7043 + struct ac_dpages_arg *arg = _arg;
7045 + ret = D_WALK_CONTINUE;
7046 + if (dentry->d_sb == arg->sb
7047 + && !IS_ROOT(dentry)
7048 + && au_dcount(dentry) > 0
7050 + && (!arg->test || arg->test(dentry, arg->arg))) {
7051 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7052 + if (unlikely(arg->err))
7053 + ret = D_WALK_QUIT;
7059 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7060 + au_dpages_test test, void *arg)
7062 + struct ac_dpages_arg args = {
7070 + d_walk(root, &args, au_call_dpages_append);
7075 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7076 + int do_include, au_dpages_test test, void *arg)
7081 + write_seqlock(&rename_lock);
7082 + spin_lock(&dentry->d_lock);
7084 + && au_dcount(dentry) > 0
7085 + && (!test || test(dentry, arg)))
7086 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7087 + spin_unlock(&dentry->d_lock);
7088 + if (unlikely(err))
7092 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7095 + while (!IS_ROOT(dentry)) {
7096 + dentry = dentry->d_parent; /* rename_lock is locked */
7097 + spin_lock(&dentry->d_lock);
7098 + if (au_dcount(dentry) > 0
7099 + && (!test || test(dentry, arg)))
7100 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7101 + spin_unlock(&dentry->d_lock);
7102 + if (unlikely(err))
7107 + write_sequnlock(&rename_lock);
7111 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7113 + return au_di(dentry) && dentry->d_sb == arg;
7116 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7117 + struct dentry *dentry, int do_include)
7119 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7120 + au_dcsub_dpages_aufs, dentry->d_sb);
7123 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7125 + struct path path[2] = {
7134 + return path_is_under(path + 0, path + 1);
7136 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7137 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7138 +++ linux/fs/aufs/dcsub.h 2021-11-01 23:48:34.206359262 +0100
7140 +/* SPDX-License-Identifier: GPL-2.0 */
7142 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7144 + * This program, aufs is free software; you can redistribute it and/or modify
7145 + * it under the terms of the GNU General Public License as published by
7146 + * the Free Software Foundation; either version 2 of the License, or
7147 + * (at your option) any later version.
7149 + * This program is distributed in the hope that it will be useful,
7150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7152 + * GNU General Public License for more details.
7154 + * You should have received a copy of the GNU General Public License
7155 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7159 + * sub-routines for dentry cache
7162 +#ifndef __AUFS_DCSUB_H__
7163 +#define __AUFS_DCSUB_H__
7167 +#include <linux/dcache.h>
7168 +#include <linux/fs.h>
7172 + struct dentry **dentries;
7175 +struct au_dcsub_pages {
7177 + struct au_dpage *dpages;
7180 +/* ---------------------------------------------------------------------- */
7183 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7184 +void au_dpages_free(struct au_dcsub_pages *dpages);
7185 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7186 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7187 + au_dpages_test test, void *arg);
7188 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7189 + int do_include, au_dpages_test test, void *arg);
7190 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7191 + struct dentry *dentry, int do_include);
7192 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7194 +/* ---------------------------------------------------------------------- */
7197 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7198 + * include/linux/dcache.h. Try them (in the future).
7201 +static inline int au_d_hashed_positive(struct dentry *d)
7204 + struct inode *inode = d_inode(d);
7207 + if (unlikely(d_unhashed(d)
7208 + || d_is_negative(d)
7209 + || !inode->i_nlink))
7214 +static inline int au_d_linkable(struct dentry *d)
7217 + struct inode *inode = d_inode(d);
7219 + err = au_d_hashed_positive(d);
7221 + && d_is_positive(d)
7222 + && (inode->i_state & I_LINKABLE))
7227 +static inline int au_d_alive(struct dentry *d)
7230 + struct inode *inode;
7234 + err = au_d_hashed_positive(d);
7236 + inode = d_inode(d);
7237 + if (unlikely(d_unlinked(d)
7238 + || d_is_negative(d)
7239 + || !inode->i_nlink))
7245 +static inline int au_alive_dir(struct dentry *d)
7249 + err = au_d_alive(d);
7250 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7255 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7257 + return a->len == b->len
7258 + && !memcmp(a->name, b->name, a->len);
7263 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7265 + * the type of d_lockref.count became int, but the inlined function d_count()
7266 + * still returns unsigned int.
7267 + * I don't know why. Maybe it is for every d_count() users?
7268 + * Anyway au_dcount() lives on.
7270 +static inline int au_dcount(struct dentry *d)
7272 + return (int)d_count(d);
7275 +#endif /* __KERNEL__ */
7276 +#endif /* __AUFS_DCSUB_H__ */
7277 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7278 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7279 +++ linux/fs/aufs/debug.c 2021-11-01 23:48:34.206359262 +0100
7281 +// SPDX-License-Identifier: GPL-2.0
7283 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7285 + * This program, aufs is free software; you can redistribute it and/or modify
7286 + * it under the terms of the GNU General Public License as published by
7287 + * the Free Software Foundation; either version 2 of the License, or
7288 + * (at your option) any later version.
7290 + * This program is distributed in the hope that it will be useful,
7291 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7292 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7293 + * GNU General Public License for more details.
7295 + * You should have received a copy of the GNU General Public License
7296 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7300 + * debug print functions
7303 +#include <linux/iversion.h>
7306 +/* Returns 0, or -errno. arg is in kp->arg. */
7307 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7311 + err = kstrtoint(val, 0, &n);
7321 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7322 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7327 + return sprintf(buffer, "%d", atomic_read(a));
7330 +static struct kernel_param_ops param_ops_atomic_t = {
7331 + .set = param_atomic_t_set,
7332 + .get = param_atomic_t_get
7333 + /* void (*free)(void *arg) */
7336 +atomic_t aufs_debug = ATOMIC_INIT(0);
7337 +MODULE_PARM_DESC(debug, "debug print");
7338 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7340 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7341 +char *au_plevel = KERN_DEBUG;
7342 +#define dpri(fmt, ...) do { \
7344 + && strcmp(au_plevel, KERN_DEBUG)) \
7345 + || au_debug_test()) \
7346 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7349 +/* ---------------------------------------------------------------------- */
7351 +void au_dpri_whlist(struct au_nhash *whlist)
7353 + unsigned long ul, n;
7354 + struct hlist_head *head;
7355 + struct au_vdir_wh *pos;
7357 + n = whlist->nh_num;
7358 + head = whlist->nh_head;
7359 + for (ul = 0; ul < n; ul++) {
7360 + hlist_for_each_entry(pos, head, wh_hash)
7361 + dpri("b%d, %.*s, %d\n",
7363 + pos->wh_str.len, pos->wh_str.name,
7369 +void au_dpri_vdir(struct au_vdir *vdir)
7372 + union au_vdir_deblk_p p;
7375 + if (!vdir || IS_ERR(vdir)) {
7376 + dpri("err %ld\n", PTR_ERR(vdir));
7380 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7381 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7382 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7383 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7384 + p.deblk = vdir->vd_deblk[ul];
7386 + dpri("[%lu]: %p\n", ul, o);
7390 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7391 + struct dentry *wh)
7396 + if (!inode || IS_ERR(inode)) {
7397 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7401 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7402 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7403 + && sizeof(inode->i_blocks) != sizeof(u64));
7405 + n = (void *)wh->d_name.name;
7406 + l = wh->d_name.len;
7409 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7410 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7412 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7413 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7414 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7415 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7416 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7417 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7418 + inode->i_generation,
7419 + l ? ", wh " : "", l, n);
7423 +void au_dpri_inode(struct inode *inode)
7425 + struct au_iinfo *iinfo;
7426 + struct au_hinode *hi;
7427 + aufs_bindex_t bindex;
7430 + err = do_pri_inode(-1, inode, -1, NULL);
7431 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7434 + iinfo = au_ii(inode);
7435 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7436 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7437 + if (iinfo->ii_btop < 0)
7440 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7441 + hi = au_hinode(iinfo, bindex);
7443 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7447 +void au_dpri_dalias(struct inode *inode)
7451 + spin_lock(&inode->i_lock);
7452 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7453 + au_dpri_dentry(d);
7454 + spin_unlock(&inode->i_lock);
7457 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7459 + struct dentry *wh = NULL;
7461 + struct inode *inode;
7462 + struct au_iinfo *iinfo;
7463 + struct au_hinode *hi;
7465 + if (!dentry || IS_ERR(dentry)) {
7466 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7469 + /* do not call dget_parent() here */
7470 + /* note: access d_xxx without d_lock */
7471 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7472 + bindex, dentry, dentry,
7473 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7474 + au_dcount(dentry), dentry->d_flags,
7475 + d_unhashed(dentry) ? "un" : "");
7478 + if (d_is_positive(dentry))
7479 + inode = d_inode(dentry);
7481 + && au_test_aufs(dentry->d_sb)
7483 + && !au_is_bad_inode(inode)) {
7484 + iinfo = au_ii(inode);
7485 + hi = au_hinode(iinfo, bindex);
7487 + wh = hi->hi_whdentry;
7489 + do_pri_inode(bindex, inode, hn, wh);
7493 +void au_dpri_dentry(struct dentry *dentry)
7495 + struct au_dinfo *dinfo;
7496 + aufs_bindex_t bindex;
7499 + err = do_pri_dentry(-1, dentry);
7500 + if (err || !au_test_aufs(dentry->d_sb))
7503 + dinfo = au_di(dentry);
7506 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7507 + dinfo->di_btop, dinfo->di_bbot,
7508 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7509 + dinfo->di_tmpfile);
7510 + if (dinfo->di_btop < 0)
7512 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7513 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7516 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7520 + if (!file || IS_ERR(file)) {
7521 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7526 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7527 + && au_test_aufs(file->f_path.dentry->d_sb)
7529 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7530 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7531 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7532 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7533 + file->f_version, file->f_pos, a);
7534 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7535 + do_pri_dentry(bindex, file->f_path.dentry);
7539 +void au_dpri_file(struct file *file)
7541 + struct au_finfo *finfo;
7542 + struct au_fidir *fidir;
7543 + struct au_hfile *hfile;
7544 + aufs_bindex_t bindex;
7547 + err = do_pri_file(-1, file);
7549 + || IS_ERR_OR_NULL(file->f_path.dentry)
7550 + || !au_test_aufs(file->f_path.dentry->d_sb))
7553 + finfo = au_fi(file);
7556 + if (finfo->fi_btop < 0)
7558 + fidir = finfo->fi_hdir;
7560 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7562 + for (bindex = finfo->fi_btop;
7563 + bindex >= 0 && bindex <= fidir->fd_bbot;
7565 + hfile = fidir->fd_hfile + bindex;
7566 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7570 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7572 + struct vfsmount *mnt;
7573 + struct super_block *sb;
7575 + if (!br || IS_ERR(br))
7577 + mnt = au_br_mnt(br);
7578 + if (!mnt || IS_ERR(mnt))
7581 + if (!sb || IS_ERR(sb))
7584 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7585 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7587 + bindex, br->br_perm, br->br_id, br->br_wbr,
7588 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7589 + sb->s_flags, sb->s_count,
7590 + atomic_read(&sb->s_active),
7591 + !!au_xino_file(br->br_xino, /*idx*/-1));
7595 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7599 +void au_dpri_sb(struct super_block *sb)
7601 + struct au_sbinfo *sbinfo;
7602 + aufs_bindex_t bindex;
7604 + /* to reduce stack size */
7606 + struct vfsmount mnt;
7607 + struct au_branch fake;
7610 + /* this function can be called from magic sysrq */
7611 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7612 + if (unlikely(!a)) {
7613 + dpri("no memory\n");
7617 + a->mnt.mnt_sb = sb;
7618 + a->fake.br_path.mnt = &a->mnt;
7619 + err = do_pri_br(-1, &a->fake);
7621 + dpri("dev 0x%x\n", sb->s_dev);
7622 + if (err || !au_test_aufs(sb))
7625 + sbinfo = au_sbi(sb);
7628 + dpri("nw %d, gen %u, kobj %d\n",
7629 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7630 + kref_read(&sbinfo->si_kobj.kref));
7631 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7632 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7635 +/* ---------------------------------------------------------------------- */
7637 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7639 + struct inode *h_inode, *inode = d_inode(dentry);
7640 + struct dentry *h_dentry;
7641 + aufs_bindex_t bindex, bbot, bi;
7643 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7646 + bbot = au_dbbot(dentry);
7647 + bi = au_ibbot(inode);
7650 + bindex = au_dbtop(dentry);
7651 + bi = au_ibtop(inode);
7655 + for (; bindex <= bbot; bindex++) {
7656 + h_dentry = au_h_dptr(dentry, bindex);
7659 + h_inode = au_h_iptr(inode, bindex);
7660 + if (unlikely(h_inode != d_inode(h_dentry))) {
7662 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7663 + AuDbgDentry(dentry);
7664 + AuDbgInode(inode);
7666 + if (au_test_fuse(h_inode->i_sb))
7674 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7677 + struct au_dcsub_pages dpages;
7678 + struct au_dpage *dpage;
7679 + struct dentry **dentries;
7681 + err = au_dpages_init(&dpages, GFP_NOFS);
7683 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7685 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7686 + dpage = dpages.dpages + i;
7687 + dentries = dpage->dentries;
7688 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7689 + AuDebugOn(au_digen_test(dentries[j], sigen));
7691 + au_dpages_free(&dpages);
7694 +void au_dbg_verify_kthread(void)
7696 + if (au_wkq_test()) {
7699 + * It may be recursive, but udba=notify between two aufs mounts,
7700 + * where a single ro branch is shared, is not a problem.
7706 +/* ---------------------------------------------------------------------- */
7708 +int __init au_debug_init(void)
7710 + aufs_bindex_t bindex;
7711 + struct au_vdir_destr destr;
7714 + AuDebugOn(bindex >= 0);
7717 + AuDebugOn(destr.len < NAME_MAX);
7719 +#ifdef CONFIG_4KSTACKS
7720 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7725 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7726 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7727 +++ linux/fs/aufs/debug.h 2021-11-01 23:48:34.206359262 +0100
7729 +/* SPDX-License-Identifier: GPL-2.0 */
7731 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7733 + * This program, aufs is free software; you can redistribute it and/or modify
7734 + * it under the terms of the GNU General Public License as published by
7735 + * the Free Software Foundation; either version 2 of the License, or
7736 + * (at your option) any later version.
7738 + * This program is distributed in the hope that it will be useful,
7739 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7740 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7741 + * GNU General Public License for more details.
7743 + * You should have received a copy of the GNU General Public License
7744 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7748 + * debug print functions
7751 +#ifndef __AUFS_DEBUG_H__
7752 +#define __AUFS_DEBUG_H__
7756 +#include <linux/atomic.h>
7757 +#include <linux/module.h>
7758 +#include <linux/kallsyms.h>
7759 +#include <linux/sysrq.h>
7761 +#ifdef CONFIG_AUFS_DEBUG
7762 +#define AuDebugOn(a) BUG_ON(a)
7764 +/* module parameter */
7765 +extern atomic_t aufs_debug;
7766 +static inline void au_debug_on(void)
7768 + atomic_inc(&aufs_debug);
7770 +static inline void au_debug_off(void)
7772 + atomic_dec_if_positive(&aufs_debug);
7775 +static inline int au_debug_test(void)
7777 + return atomic_read(&aufs_debug) > 0;
7780 +#define AuDebugOn(a) do {} while (0)
7781 +AuStubVoid(au_debug_on, void)
7782 +AuStubVoid(au_debug_off, void)
7783 +AuStubInt0(au_debug_test, void)
7784 +#endif /* CONFIG_AUFS_DEBUG */
7786 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7788 +/* ---------------------------------------------------------------------- */
7792 +#define AuDbg(fmt, ...) do { \
7793 + if (au_debug_test()) \
7794 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7796 +#define AuLabel(l) AuDbg(#l "\n")
7797 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7798 +#define AuWarn1(fmt, ...) do { \
7799 + static unsigned char _c; \
7801 + pr_warn(fmt, ##__VA_ARGS__); \
7804 +#define AuErr1(fmt, ...) do { \
7805 + static unsigned char _c; \
7807 + pr_err(fmt, ##__VA_ARGS__); \
7810 +#define AuIOErr1(fmt, ...) do { \
7811 + static unsigned char _c; \
7813 + AuIOErr(fmt, ##__VA_ARGS__); \
7816 +#define AuUnsupportMsg "This operation is not supported." \
7817 + " Please report this application to aufs-users ML."
7818 +#define AuUnsupport(fmt, ...) do { \
7819 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7823 +#define AuTraceErr(e) do { \
7824 + if (unlikely((e) < 0)) \
7825 + AuDbg("err %d\n", (int)(e)); \
7828 +#define AuTraceErrPtr(p) do { \
7830 + AuDbg("err %ld\n", PTR_ERR(p)); \
7833 +/* dirty macros for debug print, use with "%.*s" and caution */
7834 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7836 +/* ---------------------------------------------------------------------- */
7839 +#ifdef CONFIG_AUFS_DEBUG
7840 +extern struct mutex au_dbg_mtx;
7841 +extern char *au_plevel;
7843 +void au_dpri_whlist(struct au_nhash *whlist);
7845 +void au_dpri_vdir(struct au_vdir *vdir);
7847 +void au_dpri_inode(struct inode *inode);
7848 +void au_dpri_dalias(struct inode *inode);
7849 +void au_dpri_dentry(struct dentry *dentry);
7851 +void au_dpri_file(struct file *filp);
7852 +struct super_block;
7853 +void au_dpri_sb(struct super_block *sb);
7855 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7856 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7857 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7858 +void au_dbg_verify_kthread(void);
7860 +int __init au_debug_init(void);
7862 +#define AuDbgWhlist(w) do { \
7863 + mutex_lock(&au_dbg_mtx); \
7865 + au_dpri_whlist(w); \
7866 + mutex_unlock(&au_dbg_mtx); \
7869 +#define AuDbgVdir(v) do { \
7870 + mutex_lock(&au_dbg_mtx); \
7872 + au_dpri_vdir(v); \
7873 + mutex_unlock(&au_dbg_mtx); \
7876 +#define AuDbgInode(i) do { \
7877 + mutex_lock(&au_dbg_mtx); \
7879 + au_dpri_inode(i); \
7880 + mutex_unlock(&au_dbg_mtx); \
7883 +#define AuDbgDAlias(i) do { \
7884 + mutex_lock(&au_dbg_mtx); \
7886 + au_dpri_dalias(i); \
7887 + mutex_unlock(&au_dbg_mtx); \
7890 +#define AuDbgDentry(d) do { \
7891 + mutex_lock(&au_dbg_mtx); \
7893 + au_dpri_dentry(d); \
7894 + mutex_unlock(&au_dbg_mtx); \
7897 +#define AuDbgFile(f) do { \
7898 + mutex_lock(&au_dbg_mtx); \
7900 + au_dpri_file(f); \
7901 + mutex_unlock(&au_dbg_mtx); \
7904 +#define AuDbgSb(sb) do { \
7905 + mutex_lock(&au_dbg_mtx); \
7906 + AuDbg(#sb "\n"); \
7908 + mutex_unlock(&au_dbg_mtx); \
7911 +#define AuDbgSym(addr) do { \
7912 + char sym[KSYM_SYMBOL_LEN]; \
7913 + sprint_symbol(sym, (unsigned long)addr); \
7914 + AuDbg("%s\n", sym); \
7917 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7918 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7919 +AuStubVoid(au_dbg_verify_kthread, void)
7920 +AuStubInt0(__init au_debug_init, void)
7922 +#define AuDbgWhlist(w) do {} while (0)
7923 +#define AuDbgVdir(v) do {} while (0)
7924 +#define AuDbgInode(i) do {} while (0)
7925 +#define AuDbgDAlias(i) do {} while (0)
7926 +#define AuDbgDentry(d) do {} while (0)
7927 +#define AuDbgFile(f) do {} while (0)
7928 +#define AuDbgSb(sb) do {} while (0)
7929 +#define AuDbgSym(addr) do {} while (0)
7930 +#endif /* CONFIG_AUFS_DEBUG */
7932 +/* ---------------------------------------------------------------------- */
7934 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7935 +int __init au_sysrq_init(void);
7936 +void au_sysrq_fin(void);
7938 +#ifdef CONFIG_HW_CONSOLE
7939 +#define au_dbg_blocked() do { \
7941 + handle_sysrq('w'); \
7944 +AuStubVoid(au_dbg_blocked, void)
7948 +AuStubInt0(__init au_sysrq_init, void)
7949 +AuStubVoid(au_sysrq_fin, void)
7950 +AuStubVoid(au_dbg_blocked, void)
7951 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7953 +#endif /* __KERNEL__ */
7954 +#endif /* __AUFS_DEBUG_H__ */
7955 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7956 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7957 +++ linux/fs/aufs/dentry.c 2021-11-01 23:48:34.206359262 +0100
7959 +// SPDX-License-Identifier: GPL-2.0
7961 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7963 + * This program, aufs is free software; you can redistribute it and/or modify
7964 + * it under the terms of the GNU General Public License as published by
7965 + * the Free Software Foundation; either version 2 of the License, or
7966 + * (at your option) any later version.
7968 + * This program is distributed in the hope that it will be useful,
7969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7971 + * GNU General Public License for more details.
7973 + * You should have received a copy of the GNU General Public License
7974 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7978 + * lookup and dentry operations
7981 +#include <linux/iversion.h>
7982 +#include <linux/namei.h>
7986 + * returns positive/negative dentry, NULL or an error.
7987 + * NULL means whiteout-ed or not-found.
7989 +static struct dentry*
7990 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7991 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7993 + struct dentry *h_dentry;
7994 + struct inode *h_inode;
7995 + struct au_branch *br;
7996 + struct user_namespace *h_userns;
7997 + struct path h_path;
7998 + int wh_found, opq;
7999 + unsigned char wh_able;
8000 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8001 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8005 + br = au_sbr(dentry->d_sb, bindex);
8006 + h_path.dentry = h_parent;
8007 + h_path.mnt = au_br_mnt(br);
8008 + h_userns = au_br_userns(br);
8009 + wh_able = !!au_br_whable(br->br_perm);
8011 + wh_found = au_wh_test(h_userns, &h_path, &args->whname,
8013 + h_dentry = ERR_PTR(wh_found);
8016 + if (unlikely(wh_found < 0))
8019 + /* We found a whiteout */
8020 + /* au_set_dbbot(dentry, bindex); */
8021 + au_set_dbwh(dentry, bindex);
8023 + return NULL; /* success */
8027 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8029 + h_dentry = au_sio_lkup_one(h_userns, args->name, &h_path);
8030 + if (IS_ERR(h_dentry)) {
8031 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8037 + h_inode = d_inode(h_dentry);
8038 + if (d_is_negative(h_dentry)) {
8041 + } else if (wh_found
8042 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8044 + else if (au_ftest_lkup(args->flags, DIRREN)
8046 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8047 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8048 + (unsigned long long)h_inode->i_ino);
8052 + if (au_dbbot(dentry) <= bindex)
8053 + au_set_dbbot(dentry, bindex);
8054 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8055 + au_set_dbtop(dentry, bindex);
8056 + au_set_h_dptr(dentry, bindex, h_dentry);
8058 + if (!d_is_dir(h_dentry)
8060 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8061 + goto out; /* success */
8063 + h_path.dentry = h_dentry;
8064 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8065 + opq = au_diropq_test(h_userns, &h_path);
8066 + inode_unlock_shared(h_inode);
8068 + au_set_dbdiropq(dentry, bindex);
8069 + else if (unlikely(opq < 0)) {
8070 + au_set_h_dptr(dentry, bindex, NULL);
8071 + h_dentry = ERR_PTR(opq);
8082 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8084 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8085 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8091 + * returns the number of lower positive dentries,
8092 + * otherwise an error.
8093 + * can be called at unlinking with @type is zero.
8095 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8096 + unsigned int flags)
8098 + int npositive, err;
8099 + aufs_bindex_t bindex, btail, bdiropq;
8100 + unsigned char isdir, dirperm1, dirren;
8101 + struct au_do_lookup_args args = {
8103 + .name = &dentry->d_name
8105 + struct dentry *parent;
8106 + struct super_block *sb;
8108 + sb = dentry->d_sb;
8109 + err = au_test_shwh(sb, args.name);
8110 + if (unlikely(err))
8113 + err = au_wh_name_alloc(&args.whname, args.name);
8114 + if (unlikely(err))
8117 + isdir = !!d_is_dir(dentry);
8118 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8119 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8121 + au_fset_lkup(args.flags, DIRREN);
8124 + parent = dget_parent(dentry);
8125 + btail = au_dbtaildir(parent);
8126 + for (bindex = btop; bindex <= btail; bindex++) {
8127 + struct dentry *h_parent, *h_dentry;
8128 + struct inode *h_inode, *h_dir;
8129 + struct au_branch *br;
8131 + h_dentry = au_h_dptr(dentry, bindex);
8133 + if (d_is_positive(h_dentry))
8137 + h_parent = au_h_dptr(parent, bindex);
8138 + if (!h_parent || !d_is_dir(h_parent))
8142 + /* if the inum matches, then use the prepared name */
8143 + err = au_dr_lkup_name(&args, bindex);
8144 + if (unlikely(err))
8148 + h_dir = d_inode(h_parent);
8149 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8150 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8151 + inode_unlock_shared(h_dir);
8152 + err = PTR_ERR(h_dentry);
8153 + if (IS_ERR(h_dentry))
8156 + au_fclr_lkup(args.flags, ALLOW_NEG);
8158 + au_fset_lkup(args.flags, IGNORE_PERM);
8160 + if (au_dbwh(dentry) == bindex)
8164 + if (d_is_negative(h_dentry))
8166 + h_inode = d_inode(h_dentry);
8169 + args.type = h_inode->i_mode & S_IFMT;
8170 + if (args.type != S_IFDIR)
8173 + /* the type of lower may be different */
8174 + bdiropq = au_dbdiropq(dentry);
8175 + if (bdiropq >= 0 && bdiropq <= bindex)
8178 + br = au_sbr(sb, bindex);
8180 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8181 + /*add_ent*/NULL)) {
8182 + /* prepare next name to lookup */
8183 + err = au_dr_lkup(&args, dentry, bindex);
8184 + if (unlikely(err))
8190 + AuLabel(positive);
8191 + au_update_dbtop(dentry);
8194 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8195 + && au_dbtop(dentry) < 0)) {
8197 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8203 + au_kfree_try_rcu(args.whname.name);
8205 + au_dr_lkup_fin(&args);
8210 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
8211 + struct path *ppath)
8213 + struct dentry *dentry;
8216 + if (!au_test_h_perm_sio(userns, d_inode(ppath->dentry), MAY_EXEC))
8217 + dentry = vfsub_lkup_one(name, ppath);
8219 + struct vfsub_lkup_one_args args = {
8225 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8226 + if (unlikely(wkq_err))
8227 + dentry = ERR_PTR(wkq_err);
8234 + * lookup @dentry on @bindex which should be negative.
8236 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8239 + struct dentry *parent, *h_dentry;
8240 + struct au_branch *br;
8241 + struct user_namespace *h_userns;
8242 + struct path h_ppath;
8244 + parent = dget_parent(dentry);
8245 + br = au_sbr(dentry->d_sb, bindex);
8246 + h_ppath.dentry = au_h_dptr(parent, bindex);
8247 + h_ppath.mnt = au_br_mnt(br);
8248 + h_userns = au_br_userns(br);
8250 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8252 + h_dentry = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
8253 + err = PTR_ERR(h_dentry);
8254 + if (IS_ERR(h_dentry))
8256 + if (unlikely(d_is_positive(h_dentry))) {
8258 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8264 + if (bindex < au_dbtop(dentry))
8265 + au_set_dbtop(dentry, bindex);
8266 + if (au_dbbot(dentry) < bindex)
8267 + au_set_dbbot(dentry, bindex);
8268 + au_set_h_dptr(dentry, bindex, h_dentry);
8275 +/* ---------------------------------------------------------------------- */
8277 +/* subset of struct inode */
8279 + unsigned long i_ino;
8280 + /* unsigned int i_nlink; */
8286 + blkcnt_t i_blocks;
8291 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8293 + ia->i_ino = h_inode->i_ino;
8294 + /* ia->i_nlink = h_inode->i_nlink; */
8295 + ia->i_uid = h_inode->i_uid;
8296 + ia->i_gid = h_inode->i_gid;
8297 + ia->i_version = inode_query_iversion(h_inode);
8299 + ia->i_size = h_inode->i_size;
8300 + ia->i_blocks = h_inode->i_blocks;
8302 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8305 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8307 + return ia->i_ino != h_inode->i_ino
8308 + /* || ia->i_nlink != h_inode->i_nlink */
8309 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8310 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8311 + || !inode_eq_iversion(h_inode, ia->i_version)
8313 + || ia->i_size != h_inode->i_size
8314 + || ia->i_blocks != h_inode->i_blocks
8316 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8319 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8320 + struct au_branch *br)
8323 + struct au_iattr ia;
8324 + struct inode *h_inode;
8325 + struct dentry *h_d;
8326 + struct super_block *h_sb;
8327 + struct path h_ppath;
8330 + memset(&ia, -1, sizeof(ia));
8331 + h_sb = h_dentry->d_sb;
8333 + if (d_is_positive(h_dentry)) {
8334 + h_inode = d_inode(h_dentry);
8335 + au_iattr_save(&ia, h_inode);
8336 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8337 + /* nfs d_revalidate may return 0 for negative dentry */
8338 + /* fuse d_revalidate always return 0 for negative dentry */
8341 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8342 + h_ppath.dentry = h_parent;
8343 + h_ppath.mnt = au_br_mnt(br);
8344 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8345 + err = PTR_ERR(h_d);
8350 + if (unlikely(h_d != h_dentry
8351 + || d_inode(h_d) != h_inode
8352 + || (h_inode && au_iattr_test(&ia, h_inode))))
8353 + err = au_busy_or_stale();
8361 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8362 + struct dentry *h_parent, struct au_branch *br)
8367 + if (udba == AuOpt_UDBA_REVAL
8368 + && !au_test_fs_remote(h_dentry->d_sb)) {
8370 + err = (d_inode(h_dentry->d_parent) != h_dir);
8371 + } else if (udba != AuOpt_UDBA_NONE)
8372 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8377 +/* ---------------------------------------------------------------------- */
8379 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8382 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8383 + struct au_hdentry tmp, *p, *q;
8384 + struct au_dinfo *dinfo;
8385 + struct super_block *sb;
8387 + DiMustWriteLock(dentry);
8389 + sb = dentry->d_sb;
8390 + dinfo = au_di(dentry);
8391 + bbot = dinfo->di_bbot;
8392 + bwh = dinfo->di_bwh;
8393 + bdiropq = dinfo->di_bdiropq;
8394 + bindex = dinfo->di_btop;
8395 + p = au_hdentry(dinfo, bindex);
8396 + for (; bindex <= bbot; bindex++, p++) {
8397 + if (!p->hd_dentry)
8400 + new_bindex = au_br_index(sb, p->hd_id);
8401 + if (new_bindex == bindex)
8404 + if (dinfo->di_bwh == bindex)
8406 + if (dinfo->di_bdiropq == bindex)
8407 + bdiropq = new_bindex;
8408 + if (new_bindex < 0) {
8410 + p->hd_dentry = NULL;
8414 + /* swap two lower dentries, and loop again */
8415 + q = au_hdentry(dinfo, new_bindex);
8419 + if (tmp.hd_dentry) {
8425 + dinfo->di_bwh = -1;
8426 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8427 + dinfo->di_bwh = bwh;
8429 + dinfo->di_bdiropq = -1;
8431 + && bdiropq <= au_sbbot(sb)
8432 + && au_sbr_whable(sb, bdiropq))
8433 + dinfo->di_bdiropq = bdiropq;
8436 + dinfo->di_btop = -1;
8437 + dinfo->di_bbot = -1;
8438 + bbot = au_dbbot(parent);
8440 + p = au_hdentry(dinfo, bindex);
8441 + for (; bindex <= bbot; bindex++, p++)
8442 + if (p->hd_dentry) {
8443 + dinfo->di_btop = bindex;
8447 + if (dinfo->di_btop >= 0) {
8449 + p = au_hdentry(dinfo, bindex);
8450 + for (; bindex >= 0; bindex--, p--)
8451 + if (p->hd_dentry) {
8452 + dinfo->di_bbot = bindex;
8461 +static void au_do_hide(struct dentry *dentry)
8463 + struct inode *inode;
8465 + if (d_really_is_positive(dentry)) {
8466 + inode = d_inode(dentry);
8467 + if (!d_is_dir(dentry)) {
8468 + if (inode->i_nlink && !d_unhashed(dentry))
8469 + drop_nlink(inode);
8471 + clear_nlink(inode);
8472 + /* stop next lookup */
8473 + inode->i_flags |= S_DEAD;
8475 + smp_mb(); /* necessary? */
8480 +static int au_hide_children(struct dentry *parent)
8482 + int err, i, j, ndentry;
8483 + struct au_dcsub_pages dpages;
8484 + struct au_dpage *dpage;
8485 + struct dentry *dentry;
8487 + err = au_dpages_init(&dpages, GFP_NOFS);
8488 + if (unlikely(err))
8490 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8491 + if (unlikely(err))
8494 + /* in reverse order */
8495 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8496 + dpage = dpages.dpages + i;
8497 + ndentry = dpage->ndentry;
8498 + for (j = ndentry - 1; j >= 0; j--) {
8499 + dentry = dpage->dentries[j];
8500 + if (dentry != parent)
8501 + au_do_hide(dentry);
8506 + au_dpages_free(&dpages);
8511 +static void au_hide(struct dentry *dentry)
8515 + AuDbgDentry(dentry);
8516 + if (d_is_dir(dentry)) {
8517 + /* shrink_dcache_parent(dentry); */
8518 + err = au_hide_children(dentry);
8519 + if (unlikely(err))
8520 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8523 + au_do_hide(dentry);
8527 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8529 + * a dirty branch is added
8530 + * - on the top of layers
8531 + * - in the middle of layers
8532 + * - to the bottom of layers
8534 + * on the added branch there exists
8537 + * - a same named entry
8539 + * * negative --> positive
8540 + * * positive --> positive
8541 + * - type is unchanged
8542 + * - type is changed
8544 + * * negative --> negative
8545 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8548 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8549 + struct au_dinfo *tmp)
8552 + aufs_bindex_t bindex, bbot;
8554 + struct dentry *dentry;
8555 + struct inode *inode;
8557 + } orig_h, tmp_h = {
8560 + struct au_hdentry *hd;
8561 + struct inode *inode, *h_inode;
8562 + struct dentry *h_dentry;
8565 + AuDebugOn(dinfo->di_btop < 0);
8567 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8568 + orig_h.inode = NULL;
8569 + if (d_is_positive(orig_h.dentry)) {
8570 + orig_h.inode = d_inode(orig_h.dentry);
8571 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8573 + if (tmp->di_btop >= 0) {
8574 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8575 + if (d_is_positive(tmp_h.dentry)) {
8576 + tmp_h.inode = d_inode(tmp_h.dentry);
8577 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8582 + if (d_really_is_positive(dentry))
8583 + inode = d_inode(dentry);
8584 + if (!orig_h.inode) {
8585 + AuDbg("negative originally\n");
8591 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8592 + AuDebugOn(dinfo->di_bdiropq != -1);
8594 + if (!tmp_h.inode) {
8595 + AuDbg("negative --> negative\n");
8596 + /* should have only one negative lower */
8597 + if (tmp->di_btop >= 0
8598 + && tmp->di_btop < dinfo->di_btop) {
8599 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8600 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8601 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8602 + au_di_cp(dinfo, tmp);
8603 + hd = au_hdentry(tmp, tmp->di_btop);
8604 + au_set_h_dptr(dentry, tmp->di_btop,
8605 + dget(hd->hd_dentry));
8607 + au_dbg_verify_dinode(dentry);
8609 + AuDbg("negative --> positive\n");
8611 + * similar to the behaviour of creating with bypassing
8613 + * unhash it in order to force an error in the
8614 + * succeeding create operation.
8615 + * we should not set S_DEAD here.
8618 + /* au_di_swap(tmp, dinfo); */
8619 + au_dbg_verify_dinode(dentry);
8622 + AuDbg("positive originally\n");
8623 + /* inode may be NULL */
8624 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8625 + if (!tmp_h.inode) {
8626 + AuDbg("positive --> negative\n");
8627 + /* or bypassing aufs */
8629 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8630 + dinfo->di_bwh = tmp->di_bwh;
8632 + err = au_refresh_hinode_self(inode);
8633 + au_dbg_verify_dinode(dentry);
8634 + } else if (orig_h.mode == tmp_h.mode) {
8635 + AuDbg("positive --> positive, same type\n");
8636 + if (!S_ISDIR(orig_h.mode)
8637 + && dinfo->di_btop > tmp->di_btop) {
8639 + * similar to the behaviour of removing and
8644 + err = au_refresh_hinode_self(inode);
8645 + au_dbg_verify_dinode(dentry);
8647 + /* fill empty slots */
8648 + if (dinfo->di_btop > tmp->di_btop)
8649 + dinfo->di_btop = tmp->di_btop;
8650 + if (dinfo->di_bbot < tmp->di_bbot)
8651 + dinfo->di_bbot = tmp->di_bbot;
8652 + dinfo->di_bwh = tmp->di_bwh;
8653 + dinfo->di_bdiropq = tmp->di_bdiropq;
8654 + bbot = dinfo->di_bbot;
8655 + bindex = tmp->di_btop;
8656 + hd = au_hdentry(tmp, bindex);
8657 + for (; bindex <= bbot; bindex++, hd++) {
8658 + if (au_h_dptr(dentry, bindex))
8660 + h_dentry = hd->hd_dentry;
8663 + AuDebugOn(d_is_negative(h_dentry));
8664 + h_inode = d_inode(h_dentry);
8665 + AuDebugOn(orig_h.mode
8666 + != (h_inode->i_mode
8668 + au_set_h_dptr(dentry, bindex,
8672 + err = au_refresh_hinode(inode, dentry);
8673 + au_dbg_verify_dinode(dentry);
8676 + AuDbg("positive --> positive, different type\n");
8677 + /* similar to the behaviour of removing and creating */
8680 + err = au_refresh_hinode_self(inode);
8681 + au_dbg_verify_dinode(dentry);
8689 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8691 + const struct dentry_operations *dop
8692 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8693 + static const unsigned int mask
8694 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8696 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8698 + if (dentry->d_op == dop)
8701 + AuDbg("%pd\n", dentry);
8702 + spin_lock(&dentry->d_lock);
8703 + if (dop == &aufs_dop)
8704 + dentry->d_flags |= mask;
8706 + dentry->d_flags &= ~mask;
8707 + dentry->d_op = dop;
8708 + spin_unlock(&dentry->d_lock);
8711 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8713 + int err, ebrange, nbr;
8714 + unsigned int sigen;
8715 + struct au_dinfo *dinfo, *tmp;
8716 + struct super_block *sb;
8717 + struct inode *inode;
8719 + DiMustWriteLock(dentry);
8720 + AuDebugOn(IS_ROOT(dentry));
8721 + AuDebugOn(d_really_is_negative(parent));
8723 + sb = dentry->d_sb;
8724 + sigen = au_sigen(sb);
8725 + err = au_digen_test(parent, sigen);
8726 + if (unlikely(err))
8729 + nbr = au_sbbot(sb) + 1;
8730 + dinfo = au_di(dentry);
8731 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8732 + if (unlikely(err))
8734 + ebrange = au_dbrange_test(dentry);
8736 + ebrange = au_do_refresh_hdentry(dentry, parent);
8738 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8739 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8740 + if (d_really_is_positive(dentry)) {
8741 + inode = d_inode(dentry);
8742 + err = au_refresh_hinode_self(inode);
8744 + au_dbg_verify_dinode(dentry);
8746 + goto out_dgen; /* success */
8750 + /* temporary dinfo */
8751 + AuDbgDentry(dentry);
8753 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8754 + if (unlikely(!tmp))
8756 + au_di_swap(tmp, dinfo);
8757 + /* returns the number of positive dentries */
8759 + * if current working dir is removed, it returns an error.
8760 + * but the dentry is legal.
8762 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8763 + AuDbgDentry(dentry);
8764 + au_di_swap(tmp, dinfo);
8765 + if (err == -ENOENT)
8768 + /* compare/refresh by dinfo */
8769 + AuDbgDentry(dentry);
8770 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8771 + au_dbg_verify_dinode(dentry);
8774 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8775 + au_rw_write_unlock(&tmp->di_rwsem);
8777 + if (unlikely(err))
8781 + au_update_digen(dentry);
8783 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8784 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8785 + AuDbgDentry(dentry);
8791 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8792 + struct dentry *dentry, aufs_bindex_t bindex)
8797 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8800 + AuDbg("b%d\n", bindex);
8802 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8803 + * due to whiteout and branch permission.
8805 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8806 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8807 + /* it may return tri-state */
8808 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8810 + if (unlikely(valid < 0))
8820 +/* todo: remove this */
8821 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8822 + unsigned int flags, int do_udba, int dirren)
8825 + umode_t mode, h_mode;
8826 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8827 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8828 + struct inode *h_inode, *h_cached_inode;
8829 + struct dentry *h_dentry;
8830 + struct qstr *name, *h_name;
8837 + unhashed = !!d_unhashed(dentry);
8838 + is_root = !!IS_ROOT(dentry);
8839 + name = &dentry->d_name;
8840 + tmpfile = au_di(dentry)->di_tmpfile;
8843 + * Theoretically, REVAL test should be unnecessary in case of
8845 + * But {fs,i}notify doesn't fire some necessary events,
8846 + * IN_ATTRIB for atime/nlink/pageio
8847 + * Let's do REVAL test too.
8849 + if (do_udba && inode) {
8850 + mode = (inode->i_mode & S_IFMT);
8851 + plus = (inode->i_nlink > 0);
8852 + ibs = au_ibtop(inode);
8853 + ibe = au_ibbot(inode);
8856 + btop = au_dbtop(dentry);
8858 + if (inode && S_ISDIR(inode->i_mode))
8859 + btail = au_dbtaildir(dentry);
8860 + for (bindex = btop; bindex <= btail; bindex++) {
8861 + h_dentry = au_h_dptr(dentry, bindex);
8865 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8866 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8867 + spin_lock(&h_dentry->d_lock);
8868 + h_name = &h_dentry->d_name;
8869 + if (unlikely(do_udba
8872 + && (unhashed != !!d_unhashed(h_dentry)
8873 + || (!tmpfile && !dirren
8874 + && !au_qstreq(name, h_name))
8877 + && !(flags & LOOKUP_OPEN)
8878 + && (h_dentry->d_flags
8879 + & DCACHE_NFSFS_RENAMED)))
8883 + h_unhashed = d_unhashed(h_dentry);
8884 + spin_unlock(&h_dentry->d_lock);
8885 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8886 + unhashed, h_unhashed, dentry, h_dentry);
8889 + spin_unlock(&h_dentry->d_lock);
8891 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8892 + if (unlikely(err))
8893 + /* do not goto err, to keep the errno */
8896 + /* todo: plink too? */
8901 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8905 + if (d_is_positive(h_dentry))
8906 + h_inode = d_inode(h_dentry);
8909 + h_cached_inode = h_inode;
8911 + h_mode = (h_inode->i_mode & S_IFMT);
8912 + h_plus = (h_inode->i_nlink > 0);
8914 + if (inode && ibs <= bindex && bindex <= ibe)
8915 + h_cached_inode = au_h_iptr(inode, bindex);
8918 + if (unlikely(plus != h_plus && !tmpfile))
8921 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8923 + && !IS_ROOT(h_dentry)
8924 + && unhashed != d_unhashed(h_dentry)))
8927 + if (unlikely(mode != h_mode
8928 + || h_cached_inode != h_inode))
8941 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8942 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8945 + struct dentry *parent;
8947 + if (!au_digen_test(dentry, sigen))
8950 + parent = dget_parent(dentry);
8951 + di_read_lock_parent(parent, AuLock_IR);
8952 + AuDebugOn(au_digen_test(parent, sigen));
8953 + au_dbg_verify_gen(parent, sigen);
8954 + err = au_refresh_dentry(dentry, parent);
8955 + di_read_unlock(parent, AuLock_IR);
8961 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8964 + struct dentry *d, *parent;
8966 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8967 + return simple_reval_dpath(dentry, sigen);
8969 + /* slow loop, keep it simple and stupid */
8970 + /* cf: au_cpup_dirs() */
8973 + while (au_digen_test(dentry, sigen)) {
8977 + parent = dget_parent(d);
8978 + if (!au_digen_test(parent, sigen))
8984 + di_write_lock_child2(d);
8986 + /* someone might update our dentry while we were sleeping */
8987 + if (au_digen_test(d, sigen)) {
8989 + * todo: consolidate with simple_reval_dpath(),
8990 + * do_refresh() and au_reval_for_attr().
8992 + di_read_lock_parent(parent, AuLock_IR);
8993 + err = au_refresh_dentry(d, parent);
8994 + di_read_unlock(parent, AuLock_IR);
8998 + di_write_unlock(d);
9000 + if (unlikely(err))
9008 + * if valid returns 1, otherwise 0.
9010 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9013 + unsigned int sigen;
9014 + unsigned char do_udba, dirren;
9015 + struct super_block *sb;
9016 + struct inode *inode;
9018 + /* todo: support rcu-walk? */
9019 + if (flags & LOOKUP_RCU)
9023 + if (unlikely(!au_di(dentry)))
9027 + sb = dentry->d_sb;
9030 + * i_mutex of parent dir may be held,
9031 + * but we should not return 'invalid' due to busy.
9033 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9034 + if (unlikely(err)) {
9040 + if (d_really_is_positive(dentry))
9041 + inode = d_inode(dentry);
9042 + if (unlikely(inode && au_is_bad_inode(inode))) {
9047 + if (unlikely(au_dbrange_test(dentry))) {
9053 + sigen = au_sigen(sb);
9054 + if (au_digen_test(dentry, sigen)) {
9055 + AuDebugOn(IS_ROOT(dentry));
9056 + err = au_reval_dpath(dentry, sigen);
9057 + if (unlikely(err)) {
9062 + di_downgrade_lock(dentry, AuLock_IR);
9065 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9067 + && !(inode->i_state && I_LINKABLE)
9068 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9073 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9074 + if (do_udba && inode) {
9075 + aufs_bindex_t btop = au_ibtop(inode);
9076 + struct inode *h_inode;
9079 + h_inode = au_h_iptr(inode, btop);
9080 + if (h_inode && au_test_higen(inode, h_inode)) {
9087 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9088 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9089 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9091 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9097 + di_downgrade_lock(dentry, AuLock_IR);
9099 + aufs_read_unlock(dentry, AuLock_IR);
9104 + AuDbg("%pd invalid, %d\n", dentry, valid);
9110 +static void aufs_d_release(struct dentry *dentry)
9112 + if (au_di(dentry)) {
9113 + au_di_fin(dentry);
9114 + au_hn_di_reinit(dentry);
9118 +const struct dentry_operations aufs_dop = {
9119 + .d_revalidate = aufs_d_revalidate,
9120 + .d_weak_revalidate = aufs_d_revalidate,
9121 + .d_release = aufs_d_release
9124 +/* aufs_dop without d_revalidate */
9125 +const struct dentry_operations aufs_dop_noreval = {
9126 + .d_release = aufs_d_release
9128 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9129 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9130 +++ linux/fs/aufs/dentry.h 2021-11-01 23:48:34.206359262 +0100
9132 +/* SPDX-License-Identifier: GPL-2.0 */
9134 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9136 + * This program, aufs is free software; you can redistribute it and/or modify
9137 + * it under the terms of the GNU General Public License as published by
9138 + * the Free Software Foundation; either version 2 of the License, or
9139 + * (at your option) any later version.
9141 + * This program is distributed in the hope that it will be useful,
9142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9144 + * GNU General Public License for more details.
9146 + * You should have received a copy of the GNU General Public License
9147 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9151 + * lookup and dentry operations
9154 +#ifndef __AUFS_DENTRY_H__
9155 +#define __AUFS_DENTRY_H__
9159 +#include <linux/dcache.h>
9160 +#include "dirren.h"
9163 +struct au_hdentry {
9164 + struct dentry *hd_dentry;
9165 + aufs_bindex_t hd_id;
9169 + atomic_t di_generation;
9171 + struct au_rwsem di_rwsem;
9172 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9173 + unsigned char di_tmpfile; /* to allow the different name */
9174 + struct au_hdentry *di_hdentry;
9175 + struct rcu_head rcu;
9176 +} ____cacheline_aligned_in_smp;
9178 +/* ---------------------------------------------------------------------- */
9180 +/* flags for au_lkup_dentry() */
9181 +#define AuLkup_ALLOW_NEG 1
9182 +#define AuLkup_IGNORE_PERM (1 << 1)
9183 +#define AuLkup_DIRREN (1 << 2)
9184 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9185 +#define au_fset_lkup(flags, name) \
9186 + do { (flags) |= AuLkup_##name; } while (0)
9187 +#define au_fclr_lkup(flags, name) \
9188 + do { (flags) &= ~AuLkup_##name; } while (0)
9190 +#ifndef CONFIG_AUFS_DIRREN
9191 +#undef AuLkup_DIRREN
9192 +#define AuLkup_DIRREN 0
9195 +struct au_do_lookup_args {
9196 + unsigned int flags;
9198 + struct qstr whname, *name;
9199 + struct au_dr_lookup dirren;
9202 +/* ---------------------------------------------------------------------- */
9205 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9207 +struct dentry *au_sio_lkup_one(struct user_namespace *userns, struct qstr *name,
9208 + struct path *ppath);
9209 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9210 + struct dentry *h_parent, struct au_branch *br);
9212 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9213 + unsigned int flags);
9214 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9215 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9216 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9217 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9220 +void au_di_init_once(void *_di);
9221 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9222 +void au_di_free(struct au_dinfo *dinfo);
9223 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9224 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9225 +int au_di_init(struct dentry *dentry);
9226 +void au_di_fin(struct dentry *dentry);
9227 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9229 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9230 +void di_read_unlock(struct dentry *d, int flags);
9231 +void di_downgrade_lock(struct dentry *d, int flags);
9232 +void di_write_lock(struct dentry *d, unsigned int lsc);
9233 +void di_write_unlock(struct dentry *d);
9234 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9235 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9236 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9238 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9239 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9240 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9241 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9243 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9244 + struct dentry *h_dentry);
9245 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9246 +int au_dbrange_test(struct dentry *dentry);
9247 +void au_update_digen(struct dentry *dentry);
9248 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9249 +void au_update_dbtop(struct dentry *dentry);
9250 +void au_update_dbbot(struct dentry *dentry);
9251 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9253 +/* ---------------------------------------------------------------------- */
9255 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9257 + return dentry->d_fsdata;
9260 +/* ---------------------------------------------------------------------- */
9262 +/* lock subclass for dinfo */
9264 + AuLsc_DI_CHILD, /* child first */
9265 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9266 + AuLsc_DI_CHILD3, /* copyup dirs */
9270 + AuLsc_DI_TMP /* temp for replacing dinfo */
9274 + * di_read_lock_child, di_write_lock_child,
9275 + * di_read_lock_child2, di_write_lock_child2,
9276 + * di_read_lock_child3, di_write_lock_child3,
9277 + * di_read_lock_parent, di_write_lock_parent,
9278 + * di_read_lock_parent2, di_write_lock_parent2,
9279 + * di_read_lock_parent3, di_write_lock_parent3,
9281 +#define AuReadLockFunc(name, lsc) \
9282 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9283 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9285 +#define AuWriteLockFunc(name, lsc) \
9286 +static inline void di_write_lock_##name(struct dentry *d) \
9287 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9289 +#define AuRWLockFuncs(name, lsc) \
9290 + AuReadLockFunc(name, lsc) \
9291 + AuWriteLockFunc(name, lsc)
9293 +AuRWLockFuncs(child, CHILD);
9294 +AuRWLockFuncs(child2, CHILD2);
9295 +AuRWLockFuncs(child3, CHILD3);
9296 +AuRWLockFuncs(parent, PARENT);
9297 +AuRWLockFuncs(parent2, PARENT2);
9298 +AuRWLockFuncs(parent3, PARENT3);
9300 +#undef AuReadLockFunc
9301 +#undef AuWriteLockFunc
9302 +#undef AuRWLockFuncs
9304 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9305 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9306 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9308 +/* ---------------------------------------------------------------------- */
9310 +/* todo: memory barrier? */
9311 +static inline unsigned int au_digen(struct dentry *d)
9313 + return atomic_read(&au_di(d)->di_generation);
9316 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9318 + hdentry->hd_dentry = NULL;
9321 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9322 + aufs_bindex_t bindex)
9324 + return di->di_hdentry + bindex;
9327 +static inline void au_hdput(struct au_hdentry *hd)
9330 + dput(hd->hd_dentry);
9333 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9335 + DiMustAnyLock(dentry);
9336 + return au_di(dentry)->di_btop;
9339 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9341 + DiMustAnyLock(dentry);
9342 + return au_di(dentry)->di_bbot;
9345 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9347 + DiMustAnyLock(dentry);
9348 + return au_di(dentry)->di_bwh;
9351 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9353 + DiMustAnyLock(dentry);
9354 + return au_di(dentry)->di_bdiropq;
9357 +/* todo: hard/soft set? */
9358 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9360 + DiMustWriteLock(dentry);
9361 + au_di(dentry)->di_btop = bindex;
9364 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9366 + DiMustWriteLock(dentry);
9367 + au_di(dentry)->di_bbot = bindex;
9370 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9372 + DiMustWriteLock(dentry);
9373 + /* dbwh can be outside of btop - bbot range */
9374 + au_di(dentry)->di_bwh = bindex;
9377 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9379 + DiMustWriteLock(dentry);
9380 + au_di(dentry)->di_bdiropq = bindex;
9383 +/* ---------------------------------------------------------------------- */
9385 +#ifdef CONFIG_AUFS_HNOTIFY
9386 +static inline void au_digen_dec(struct dentry *d)
9388 + atomic_dec(&au_di(d)->di_generation);
9391 +static inline void au_hn_di_reinit(struct dentry *dentry)
9393 + dentry->d_fsdata = NULL;
9396 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9397 +#endif /* CONFIG_AUFS_HNOTIFY */
9399 +#endif /* __KERNEL__ */
9400 +#endif /* __AUFS_DENTRY_H__ */
9401 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9402 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9403 +++ linux/fs/aufs/dinfo.c 2021-11-01 23:48:34.206359262 +0100
9405 +// SPDX-License-Identifier: GPL-2.0
9407 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9409 + * This program, aufs is free software; you can redistribute it and/or modify
9410 + * it under the terms of the GNU General Public License as published by
9411 + * the Free Software Foundation; either version 2 of the License, or
9412 + * (at your option) any later version.
9414 + * This program is distributed in the hope that it will be useful,
9415 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9416 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9417 + * GNU General Public License for more details.
9419 + * You should have received a copy of the GNU General Public License
9420 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9424 + * dentry private data
9429 +void au_di_init_once(void *_dinfo)
9431 + struct au_dinfo *dinfo = _dinfo;
9433 + au_rw_init(&dinfo->di_rwsem);
9436 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9438 + struct au_dinfo *dinfo;
9441 + dinfo = au_cache_alloc_dinfo();
9442 + if (unlikely(!dinfo))
9445 + nbr = au_sbbot(sb) + 1;
9448 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9449 + if (dinfo->di_hdentry) {
9450 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9451 + dinfo->di_btop = -1;
9452 + dinfo->di_bbot = -1;
9453 + dinfo->di_bwh = -1;
9454 + dinfo->di_bdiropq = -1;
9455 + dinfo->di_tmpfile = 0;
9456 + for (i = 0; i < nbr; i++)
9457 + dinfo->di_hdentry[i].hd_id = -1;
9461 + au_cache_free_dinfo(dinfo);
9468 +void au_di_free(struct au_dinfo *dinfo)
9470 + struct au_hdentry *p;
9471 + aufs_bindex_t bbot, bindex;
9473 + /* dentry may not be revalidated */
9474 + bindex = dinfo->di_btop;
9475 + if (bindex >= 0) {
9476 + bbot = dinfo->di_bbot;
9477 + p = au_hdentry(dinfo, bindex);
9478 + while (bindex++ <= bbot)
9481 + au_kfree_try_rcu(dinfo->di_hdentry);
9482 + au_cache_free_dinfo(dinfo);
9485 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9487 + struct au_hdentry *p;
9490 + AuRwMustWriteLock(&a->di_rwsem);
9491 + AuRwMustWriteLock(&b->di_rwsem);
9493 +#define DiSwap(v, name) \
9495 + v = a->di_##name; \
9496 + a->di_##name = b->di_##name; \
9497 + b->di_##name = v; \
9500 + DiSwap(p, hdentry);
9504 + DiSwap(bi, bdiropq);
9510 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9512 + AuRwMustWriteLock(&dst->di_rwsem);
9513 + AuRwMustWriteLock(&src->di_rwsem);
9515 + dst->di_btop = src->di_btop;
9516 + dst->di_bbot = src->di_bbot;
9517 + dst->di_bwh = src->di_bwh;
9518 + dst->di_bdiropq = src->di_bdiropq;
9522 +int au_di_init(struct dentry *dentry)
9525 + struct super_block *sb;
9526 + struct au_dinfo *dinfo;
9529 + sb = dentry->d_sb;
9530 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9532 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9533 + /* smp_mb(); */ /* atomic_set */
9534 + dentry->d_fsdata = dinfo;
9541 +void au_di_fin(struct dentry *dentry)
9543 + struct au_dinfo *dinfo;
9545 + dinfo = au_di(dentry);
9546 + AuRwDestroy(&dinfo->di_rwsem);
9547 + au_di_free(dinfo);
9550 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9553 + struct au_hdentry *hdp;
9555 + AuRwMustWriteLock(&dinfo->di_rwsem);
9558 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9560 + sz = sizeof(*hdp);
9561 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9564 + dinfo->di_hdentry = hdp;
9571 +/* ---------------------------------------------------------------------- */
9573 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9576 + case AuLsc_DI_CHILD:
9577 + ii_write_lock_child(inode);
9579 + case AuLsc_DI_CHILD2:
9580 + ii_write_lock_child2(inode);
9582 + case AuLsc_DI_CHILD3:
9583 + ii_write_lock_child3(inode);
9585 + case AuLsc_DI_PARENT:
9586 + ii_write_lock_parent(inode);
9588 + case AuLsc_DI_PARENT2:
9589 + ii_write_lock_parent2(inode);
9591 + case AuLsc_DI_PARENT3:
9592 + ii_write_lock_parent3(inode);
9599 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9602 + case AuLsc_DI_CHILD:
9603 + ii_read_lock_child(inode);
9605 + case AuLsc_DI_CHILD2:
9606 + ii_read_lock_child2(inode);
9608 + case AuLsc_DI_CHILD3:
9609 + ii_read_lock_child3(inode);
9611 + case AuLsc_DI_PARENT:
9612 + ii_read_lock_parent(inode);
9614 + case AuLsc_DI_PARENT2:
9615 + ii_read_lock_parent2(inode);
9617 + case AuLsc_DI_PARENT3:
9618 + ii_read_lock_parent3(inode);
9625 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9627 + struct inode *inode;
9629 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9630 + if (d_really_is_positive(d)) {
9631 + inode = d_inode(d);
9632 + if (au_ftest_lock(flags, IW))
9633 + do_ii_write_lock(inode, lsc);
9634 + else if (au_ftest_lock(flags, IR))
9635 + do_ii_read_lock(inode, lsc);
9639 +void di_read_unlock(struct dentry *d, int flags)
9641 + struct inode *inode;
9643 + if (d_really_is_positive(d)) {
9644 + inode = d_inode(d);
9645 + if (au_ftest_lock(flags, IW)) {
9646 + au_dbg_verify_dinode(d);
9647 + ii_write_unlock(inode);
9648 + } else if (au_ftest_lock(flags, IR)) {
9649 + au_dbg_verify_dinode(d);
9650 + ii_read_unlock(inode);
9653 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9656 +void di_downgrade_lock(struct dentry *d, int flags)
9658 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9659 + ii_downgrade_lock(d_inode(d));
9660 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9663 +void di_write_lock(struct dentry *d, unsigned int lsc)
9665 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9666 + if (d_really_is_positive(d))
9667 + do_ii_write_lock(d_inode(d), lsc);
9670 +void di_write_unlock(struct dentry *d)
9672 + au_dbg_verify_dinode(d);
9673 + if (d_really_is_positive(d))
9674 + ii_write_unlock(d_inode(d));
9675 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9678 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9680 + AuDebugOn(d1 == d2
9681 + || d_inode(d1) == d_inode(d2)
9682 + || d1->d_sb != d2->d_sb);
9684 + if ((isdir && au_test_subdir(d1, d2))
9686 + di_write_lock_child(d1);
9687 + di_write_lock_child2(d2);
9689 + di_write_lock_child(d2);
9690 + di_write_lock_child2(d1);
9694 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9696 + AuDebugOn(d1 == d2
9697 + || d_inode(d1) == d_inode(d2)
9698 + || d1->d_sb != d2->d_sb);
9700 + if ((isdir && au_test_subdir(d1, d2))
9702 + di_write_lock_parent(d1);
9703 + di_write_lock_parent2(d2);
9705 + di_write_lock_parent(d2);
9706 + di_write_lock_parent2(d1);
9710 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9712 + di_write_unlock(d1);
9713 + if (d_inode(d1) == d_inode(d2))
9714 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9716 + di_write_unlock(d2);
9719 +/* ---------------------------------------------------------------------- */
9721 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9725 + DiMustAnyLock(dentry);
9727 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9729 + AuDebugOn(bindex < 0);
9730 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9731 + AuDebugOn(d && au_dcount(d) <= 0);
9736 + * extended version of au_h_dptr().
9737 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9740 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9742 + struct dentry *h_dentry;
9743 + struct inode *inode, *h_inode;
9745 + AuDebugOn(d_really_is_negative(dentry));
9748 + if (au_dbtop(dentry) <= bindex
9749 + && bindex <= au_dbbot(dentry))
9750 + h_dentry = au_h_dptr(dentry, bindex);
9751 + if (h_dentry && !au_d_linkable(h_dentry)) {
9753 + goto out; /* success */
9756 + inode = d_inode(dentry);
9757 + AuDebugOn(bindex < au_ibtop(inode));
9758 + AuDebugOn(au_ibbot(inode) < bindex);
9759 + h_inode = au_h_iptr(inode, bindex);
9760 + h_dentry = d_find_alias(h_inode);
9762 + if (!IS_ERR(h_dentry)) {
9763 + if (!au_d_linkable(h_dentry))
9764 + goto out; /* success */
9770 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9771 + h_dentry = au_plink_lkup(inode, bindex);
9772 + AuDebugOn(!h_dentry);
9773 + if (!IS_ERR(h_dentry)) {
9774 + if (!au_d_hashed_positive(h_dentry))
9775 + goto out; /* success */
9782 + AuDbgDentry(h_dentry);
9786 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9788 + aufs_bindex_t bbot, bwh;
9790 + bbot = au_dbbot(dentry);
9792 + bwh = au_dbwh(dentry);
9795 + if (0 < bwh && bwh < bbot)
9801 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9803 + aufs_bindex_t bbot, bopq;
9805 + bbot = au_dbtail(dentry);
9807 + bopq = au_dbdiropq(dentry);
9808 + if (0 <= bopq && bopq < bbot)
9814 +/* ---------------------------------------------------------------------- */
9816 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9817 + struct dentry *h_dentry)
9819 + struct au_dinfo *dinfo;
9820 + struct au_hdentry *hd;
9821 + struct au_branch *br;
9823 + DiMustWriteLock(dentry);
9825 + dinfo = au_di(dentry);
9826 + hd = au_hdentry(dinfo, bindex);
9828 + hd->hd_dentry = h_dentry;
9830 + br = au_sbr(dentry->d_sb, bindex);
9831 + hd->hd_id = br->br_id;
9835 +int au_dbrange_test(struct dentry *dentry)
9838 + aufs_bindex_t btop, bbot;
9841 + btop = au_dbtop(dentry);
9842 + bbot = au_dbbot(dentry);
9844 + AuDebugOn(bbot < 0 && btop > bbot);
9847 + AuDebugOn(bbot >= 0);
9853 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9858 + if (unlikely(au_digen(dentry) != sigen
9859 + || au_iigen_test(d_inode(dentry), sigen)))
9865 +void au_update_digen(struct dentry *dentry)
9867 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9868 + /* smp_mb(); */ /* atomic_set */
9871 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9873 + struct au_dinfo *dinfo;
9874 + struct dentry *h_d;
9875 + struct au_hdentry *hdp;
9876 + aufs_bindex_t bindex, bbot;
9878 + DiMustWriteLock(dentry);
9880 + dinfo = au_di(dentry);
9881 + if (!dinfo || dinfo->di_btop < 0)
9884 + if (do_put_zero) {
9885 + bbot = dinfo->di_bbot;
9886 + bindex = dinfo->di_btop;
9887 + hdp = au_hdentry(dinfo, bindex);
9888 + for (; bindex <= bbot; bindex++, hdp++) {
9889 + h_d = hdp->hd_dentry;
9890 + if (h_d && d_is_negative(h_d))
9891 + au_set_h_dptr(dentry, bindex, NULL);
9895 + dinfo->di_btop = 0;
9896 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9897 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9898 + if (hdp->hd_dentry)
9900 + if (dinfo->di_btop > dinfo->di_bbot) {
9901 + dinfo->di_btop = -1;
9902 + dinfo->di_bbot = -1;
9906 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9907 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9908 + if (hdp->hd_dentry)
9910 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9913 +void au_update_dbtop(struct dentry *dentry)
9915 + aufs_bindex_t bindex, bbot;
9916 + struct dentry *h_dentry;
9918 + bbot = au_dbbot(dentry);
9919 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9920 + h_dentry = au_h_dptr(dentry, bindex);
9923 + if (d_is_positive(h_dentry)) {
9924 + au_set_dbtop(dentry, bindex);
9927 + au_set_h_dptr(dentry, bindex, NULL);
9931 +void au_update_dbbot(struct dentry *dentry)
9933 + aufs_bindex_t bindex, btop;
9934 + struct dentry *h_dentry;
9936 + btop = au_dbtop(dentry);
9937 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9938 + h_dentry = au_h_dptr(dentry, bindex);
9941 + if (d_is_positive(h_dentry)) {
9942 + au_set_dbbot(dentry, bindex);
9945 + au_set_h_dptr(dentry, bindex, NULL);
9949 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9951 + aufs_bindex_t bindex, bbot;
9953 + bbot = au_dbbot(dentry);
9954 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9955 + if (au_h_dptr(dentry, bindex) == h_dentry)
9959 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9960 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9961 +++ linux/fs/aufs/dir.c 2021-11-01 23:48:34.206359262 +0100
9963 +// SPDX-License-Identifier: GPL-2.0
9965 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9967 + * This program, aufs is free software; you can redistribute it and/or modify
9968 + * it under the terms of the GNU General Public License as published by
9969 + * the Free Software Foundation; either version 2 of the License, or
9970 + * (at your option) any later version.
9972 + * This program is distributed in the hope that it will be useful,
9973 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9974 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9975 + * GNU General Public License for more details.
9977 + * You should have received a copy of the GNU General Public License
9978 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9982 + * directory operations
9985 +#include <linux/fs_stack.h>
9986 +#include <linux/iversion.h>
9989 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9991 + unsigned int nlink;
9993 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9995 + nlink = dir->i_nlink;
9996 + nlink += h_dir->i_nlink - 2;
9997 + if (h_dir->i_nlink < 2)
9999 + smp_mb(); /* for i_nlink */
10000 + /* 0 can happen in revaliding */
10001 + set_nlink(dir, nlink);
10004 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10006 + unsigned int nlink;
10008 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10010 + nlink = dir->i_nlink;
10011 + nlink -= h_dir->i_nlink - 2;
10012 + if (h_dir->i_nlink < 2)
10014 + smp_mb(); /* for i_nlink */
10015 + /* nlink == 0 means the branch-fs is broken */
10016 + set_nlink(dir, nlink);
10019 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10022 + aufs_bindex_t bindex, bbot;
10023 + struct file *h_file;
10024 + struct dentry *h_dentry;
10028 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10030 + bbot = au_fbbot_dir(file);
10031 + for (bindex = au_fbtop(file);
10032 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10034 + h_file = au_hf_dir(file, bindex);
10035 + if (h_file && file_inode(h_file))
10036 + sz += vfsub_f_size_read(h_file);
10039 + AuDebugOn(!dentry);
10040 + AuDebugOn(!d_is_dir(dentry));
10042 + bbot = au_dbtaildir(dentry);
10043 + for (bindex = au_dbtop(dentry);
10044 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10046 + h_dentry = au_h_dptr(dentry, bindex);
10047 + if (h_dentry && d_is_positive(h_dentry))
10048 + sz += i_size_read(d_inode(h_dentry));
10051 + if (sz < KMALLOC_MAX_SIZE)
10052 + sz = roundup_pow_of_two(sz);
10053 + if (sz > KMALLOC_MAX_SIZE)
10054 + sz = KMALLOC_MAX_SIZE;
10055 + else if (sz < NAME_MAX) {
10056 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10057 + sz = AUFS_RDBLK_DEF;
10062 +struct au_dir_ts_arg {
10063 + struct dentry *dentry;
10064 + aufs_bindex_t brid;
10067 +static void au_do_dir_ts(void *arg)
10069 + struct au_dir_ts_arg *a = arg;
10070 + struct au_dtime dt;
10071 + struct path h_path;
10072 + struct inode *dir, *h_dir;
10073 + struct super_block *sb;
10074 + struct au_branch *br;
10075 + struct au_hinode *hdir;
10077 + aufs_bindex_t btop, bindex;
10079 + sb = a->dentry->d_sb;
10080 + if (d_really_is_negative(a->dentry))
10082 + /* no dir->i_mutex lock */
10083 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10085 + dir = d_inode(a->dentry);
10086 + btop = au_ibtop(dir);
10087 + bindex = au_br_index(sb, a->brid);
10088 + if (bindex < btop)
10091 + br = au_sbr(sb, bindex);
10092 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10093 + if (!h_path.dentry)
10095 + h_path.mnt = au_br_mnt(br);
10096 + au_dtime_store(&dt, a->dentry, &h_path);
10098 + br = au_sbr(sb, btop);
10099 + if (!au_br_writable(br->br_perm))
10101 + h_path.dentry = au_h_dptr(a->dentry, btop);
10102 + h_path.mnt = au_br_mnt(br);
10103 + err = vfsub_mnt_want_write(h_path.mnt);
10106 + hdir = au_hi(dir, btop);
10107 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10108 + h_dir = au_h_iptr(dir, btop);
10109 + if (h_dir->i_nlink
10110 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10111 + dt.dt_h_path = h_path;
10112 + au_dtime_revert(&dt);
10114 + au_hn_inode_unlock(hdir);
10115 + vfsub_mnt_drop_write(h_path.mnt);
10116 + au_cpup_attr_timesizes(dir);
10119 + aufs_read_unlock(a->dentry, AuLock_DW);
10122 + au_nwt_done(&au_sbi(sb)->si_nowait);
10123 + au_kfree_try_rcu(arg);
10126 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10128 + int perm, wkq_err;
10129 + aufs_bindex_t btop;
10130 + struct au_dir_ts_arg *arg;
10131 + struct dentry *dentry;
10132 + struct super_block *sb;
10136 + dentry = d_find_any_alias(dir);
10137 + AuDebugOn(!dentry);
10138 + sb = dentry->d_sb;
10139 + btop = au_ibtop(dir);
10140 + if (btop == bindex) {
10141 + au_cpup_attr_timesizes(dir);
10145 + perm = au_sbr_perm(sb, btop);
10146 + if (!au_br_writable(perm))
10149 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10153 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10154 + arg->brid = au_sbr_id(sb, bindex);
10155 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10156 + if (unlikely(wkq_err)) {
10157 + pr_err("wkq %d\n", wkq_err);
10159 + au_kfree_try_rcu(arg);
10166 +/* ---------------------------------------------------------------------- */
10168 +static int reopen_dir(struct file *file)
10171 + unsigned int flags;
10172 + aufs_bindex_t bindex, btail, btop;
10173 + struct dentry *dentry, *h_dentry;
10174 + struct file *h_file;
10176 + /* open all lower dirs */
10177 + dentry = file->f_path.dentry;
10178 + btop = au_dbtop(dentry);
10179 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10180 + au_set_h_fptr(file, bindex, NULL);
10181 + au_set_fbtop(file, btop);
10183 + btail = au_dbtaildir(dentry);
10184 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10185 + au_set_h_fptr(file, bindex, NULL);
10186 + au_set_fbbot_dir(file, btail);
10188 + flags = vfsub_file_flags(file);
10189 + for (bindex = btop; bindex <= btail; bindex++) {
10190 + h_dentry = au_h_dptr(dentry, bindex);
10193 + h_file = au_hf_dir(file, bindex);
10197 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10198 + err = PTR_ERR(h_file);
10199 + if (IS_ERR(h_file))
10200 + goto out; /* close all? */
10201 + au_set_h_fptr(file, bindex, h_file);
10203 + au_update_figen(file);
10204 + /* todo: necessary? */
10205 + /* file->f_ra = h_file->f_ra; */
10212 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10215 + aufs_bindex_t bindex, btail;
10216 + struct dentry *dentry, *h_dentry;
10217 + struct vfsmount *mnt;
10219 + FiMustWriteLock(file);
10220 + AuDebugOn(h_file);
10223 + mnt = file->f_path.mnt;
10224 + dentry = file->f_path.dentry;
10225 + file->f_version = inode_query_iversion(d_inode(dentry));
10226 + bindex = au_dbtop(dentry);
10227 + au_set_fbtop(file, bindex);
10228 + btail = au_dbtaildir(dentry);
10229 + au_set_fbbot_dir(file, btail);
10230 + for (; !err && bindex <= btail; bindex++) {
10231 + h_dentry = au_h_dptr(dentry, bindex);
10235 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10236 + if (unlikely(err))
10238 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10239 + if (IS_ERR(h_file)) {
10240 + err = PTR_ERR(h_file);
10243 + au_set_h_fptr(file, bindex, h_file);
10245 + au_update_figen(file);
10246 + /* todo: necessary? */
10247 + /* file->f_ra = h_file->f_ra; */
10249 + return 0; /* success */
10252 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10253 + au_set_h_fptr(file, bindex, NULL);
10254 + au_set_fbtop(file, -1);
10255 + au_set_fbbot_dir(file, -1);
10260 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10261 + struct file *file)
10264 + struct super_block *sb;
10265 + struct au_fidir *fidir;
10268 + sb = file->f_path.dentry->d_sb;
10269 + si_read_lock(sb, AuLock_FLUSH);
10270 + fidir = au_fidir_alloc(sb);
10272 + struct au_do_open_args args = {
10273 + .open = do_open_dir,
10276 + err = au_do_open(file, &args);
10277 + if (unlikely(err))
10278 + au_kfree_rcu(fidir);
10280 + si_read_unlock(sb);
10284 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10285 + struct file *file)
10287 + struct au_vdir *vdir_cache;
10288 + struct au_finfo *finfo;
10289 + struct au_fidir *fidir;
10290 + struct au_hfile *hf;
10291 + aufs_bindex_t bindex, bbot;
10293 + finfo = au_fi(file);
10294 + fidir = finfo->fi_hdir;
10296 + au_hbl_del(&finfo->fi_hlist,
10297 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10298 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10300 + au_vdir_free(vdir_cache);
10302 + bindex = finfo->fi_btop;
10303 + if (bindex >= 0) {
10304 + hf = fidir->fd_hfile + bindex;
10306 + * calls fput() instead of filp_close(),
10307 + * since no dnotify or lock for the lower file.
10309 + bbot = fidir->fd_bbot;
10310 + for (; bindex <= bbot; bindex++, hf++)
10312 + au_hfput(hf, /*execed*/0);
10314 + au_kfree_rcu(fidir);
10315 + finfo->fi_hdir = NULL;
10317 + au_finfo_fin(file);
10321 +/* ---------------------------------------------------------------------- */
10323 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10326 + aufs_bindex_t bindex, bbot;
10327 + struct file *h_file;
10330 + bbot = au_fbbot_dir(file);
10331 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10332 + h_file = au_hf_dir(file, bindex);
10334 + err = vfsub_flush(h_file, id);
10339 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10341 + return au_do_flush(file, id, au_do_flush_dir);
10344 +/* ---------------------------------------------------------------------- */
10346 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10349 + aufs_bindex_t bbot, bindex;
10350 + struct inode *inode;
10351 + struct super_block *sb;
10354 + sb = dentry->d_sb;
10355 + inode = d_inode(dentry);
10356 + IMustLock(inode);
10357 + bbot = au_dbbot(dentry);
10358 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10359 + struct path h_path;
10361 + if (au_test_ro(sb, bindex, inode))
10363 + h_path.dentry = au_h_dptr(dentry, bindex);
10364 + if (!h_path.dentry)
10367 + h_path.mnt = au_sbr_mnt(sb, bindex);
10368 + err = vfsub_fsync(NULL, &h_path, datasync);
10374 +static int au_do_fsync_dir(struct file *file, int datasync)
10377 + aufs_bindex_t bbot, bindex;
10378 + struct file *h_file;
10379 + struct super_block *sb;
10380 + struct inode *inode;
10382 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10383 + if (unlikely(err))
10386 + inode = file_inode(file);
10387 + sb = inode->i_sb;
10388 + bbot = au_fbbot_dir(file);
10389 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10390 + h_file = au_hf_dir(file, bindex);
10391 + if (!h_file || au_test_ro(sb, bindex, inode))
10394 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10402 + * @file may be NULL
10404 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10408 + struct dentry *dentry;
10409 + struct inode *inode;
10410 + struct super_block *sb;
10413 + dentry = file->f_path.dentry;
10414 + inode = d_inode(dentry);
10415 + inode_lock(inode);
10416 + sb = dentry->d_sb;
10417 + si_noflush_read_lock(sb);
10419 + err = au_do_fsync_dir(file, datasync);
10421 + di_write_lock_child(dentry);
10422 + err = au_do_fsync_dir_no_file(dentry, datasync);
10424 + au_cpup_attr_timesizes(inode);
10425 + di_write_unlock(dentry);
10427 + fi_write_unlock(file);
10429 + si_read_unlock(sb);
10430 + inode_unlock(inode);
10434 +/* ---------------------------------------------------------------------- */
10436 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10439 + struct dentry *dentry;
10440 + struct inode *inode, *h_inode;
10441 + struct super_block *sb;
10443 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10445 + dentry = file->f_path.dentry;
10446 + inode = d_inode(dentry);
10447 + IMustLock(inode);
10449 + sb = dentry->d_sb;
10450 + si_read_lock(sb, AuLock_FLUSH);
10451 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10452 + if (unlikely(err))
10454 + err = au_alive_dir(dentry);
10456 + err = au_vdir_init(file);
10457 + di_downgrade_lock(dentry, AuLock_IR);
10458 + if (unlikely(err))
10461 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10462 + if (!au_test_nfsd()) {
10463 + err = au_vdir_fill_de(file, ctx);
10464 + fsstack_copy_attr_atime(inode, h_inode);
10467 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10468 + * encode_fh() and others.
10470 + atomic_inc(&h_inode->i_count);
10471 + di_read_unlock(dentry, AuLock_IR);
10472 + si_read_unlock(sb);
10473 + err = au_vdir_fill_de(file, ctx);
10474 + fsstack_copy_attr_atime(inode, h_inode);
10475 + fi_write_unlock(file);
10483 + di_read_unlock(dentry, AuLock_IR);
10484 + fi_write_unlock(file);
10486 + si_read_unlock(sb);
10490 +/* ---------------------------------------------------------------------- */
10492 +#define AuTestEmpty_WHONLY 1
10493 +#define AuTestEmpty_CALLED (1 << 1)
10494 +#define AuTestEmpty_SHWH (1 << 2)
10495 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10496 +#define au_fset_testempty(flags, name) \
10497 + do { (flags) |= AuTestEmpty_##name; } while (0)
10498 +#define au_fclr_testempty(flags, name) \
10499 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10501 +#ifndef CONFIG_AUFS_SHWH
10502 +#undef AuTestEmpty_SHWH
10503 +#define AuTestEmpty_SHWH 0
10506 +struct test_empty_arg {
10507 + struct dir_context ctx;
10508 + struct au_nhash *whlist;
10509 + unsigned int flags;
10511 + aufs_bindex_t bindex;
10514 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10515 + int namelen, loff_t offset __maybe_unused, u64 ino,
10516 + unsigned int d_type)
10518 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10520 + char *name = (void *)__name;
10523 + au_fset_testempty(arg->flags, CALLED);
10525 + if (name[0] == '.'
10526 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10527 + goto out; /* success */
10529 + if (namelen <= AUFS_WH_PFX_LEN
10530 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10531 + if (au_ftest_testempty(arg->flags, WHONLY)
10532 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10533 + arg->err = -ENOTEMPTY;
10537 + name += AUFS_WH_PFX_LEN;
10538 + namelen -= AUFS_WH_PFX_LEN;
10539 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10540 + arg->err = au_nhash_append_wh
10541 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10542 + au_ftest_testempty(arg->flags, SHWH));
10546 + AuTraceErr(arg->err);
10550 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10553 + struct file *h_file;
10554 + struct au_branch *br;
10556 + h_file = au_h_open(dentry, arg->bindex,
10557 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10558 + /*file*/NULL, /*force_wr*/0);
10559 + err = PTR_ERR(h_file);
10560 + if (IS_ERR(h_file))
10564 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10565 + && !file_inode(h_file)->i_nlink)
10570 + au_fclr_testempty(arg->flags, CALLED);
10572 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10575 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10579 + br = au_sbr(dentry->d_sb, arg->bindex);
10580 + au_lcnt_dec(&br->br_nfiles);
10585 +struct do_test_empty_args {
10587 + struct dentry *dentry;
10588 + struct test_empty_arg *arg;
10591 +static void call_do_test_empty(void *args)
10593 + struct do_test_empty_args *a = args;
10594 + *a->errp = do_test_empty(a->dentry, a->arg);
10597 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10599 + int err, wkq_err;
10600 + struct dentry *h_dentry;
10601 + struct inode *h_inode;
10602 + struct user_namespace *h_userns;
10604 + h_userns = au_sbr_userns(dentry->d_sb, arg->bindex);
10605 + h_dentry = au_h_dptr(dentry, arg->bindex);
10606 + h_inode = d_inode(h_dentry);
10607 + /* todo: i_mode changes anytime? */
10608 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10609 + err = au_test_h_perm_sio(h_userns, h_inode, MAY_EXEC | MAY_READ);
10610 + inode_unlock_shared(h_inode);
10612 + err = do_test_empty(dentry, arg);
10614 + struct do_test_empty_args args = {
10616 + .dentry = dentry,
10619 + unsigned int flags = arg->flags;
10621 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10622 + if (unlikely(wkq_err))
10624 + arg->flags = flags;
10630 +int au_test_empty_lower(struct dentry *dentry)
10633 + unsigned int rdhash;
10634 + aufs_bindex_t bindex, btop, btail;
10635 + struct au_nhash whlist;
10636 + struct test_empty_arg arg = {
10638 + .actor = test_empty_cb
10641 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10643 + SiMustAnyLock(dentry->d_sb);
10645 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10647 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10648 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10649 + if (unlikely(err))
10653 + arg.whlist = &whlist;
10654 + btop = au_dbtop(dentry);
10655 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10656 + au_fset_testempty(arg.flags, SHWH);
10657 + test_empty = do_test_empty;
10658 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10659 + test_empty = sio_test_empty;
10660 + arg.bindex = btop;
10661 + err = test_empty(dentry, &arg);
10662 + if (unlikely(err))
10665 + au_fset_testempty(arg.flags, WHONLY);
10666 + btail = au_dbtaildir(dentry);
10667 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10668 + struct dentry *h_dentry;
10670 + h_dentry = au_h_dptr(dentry, bindex);
10671 + if (h_dentry && d_is_positive(h_dentry)) {
10672 + arg.bindex = bindex;
10673 + err = test_empty(dentry, &arg);
10678 + au_nhash_wh_free(&whlist);
10683 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10686 + struct test_empty_arg arg = {
10688 + .actor = test_empty_cb
10691 + aufs_bindex_t bindex, btail;
10694 + arg.whlist = whlist;
10695 + arg.flags = AuTestEmpty_WHONLY;
10696 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10697 + au_fset_testempty(arg.flags, SHWH);
10698 + btail = au_dbtaildir(dentry);
10699 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10700 + struct dentry *h_dentry;
10702 + h_dentry = au_h_dptr(dentry, bindex);
10703 + if (h_dentry && d_is_positive(h_dentry)) {
10704 + arg.bindex = bindex;
10705 + err = sio_test_empty(dentry, &arg);
10712 +/* ---------------------------------------------------------------------- */
10714 +const struct file_operations aufs_dir_fop = {
10715 + .owner = THIS_MODULE,
10716 + .llseek = default_llseek,
10717 + .read = generic_read_dir,
10718 + .iterate_shared = aufs_iterate_shared,
10719 + .unlocked_ioctl = aufs_ioctl_dir,
10720 +#ifdef CONFIG_COMPAT
10721 + .compat_ioctl = aufs_compat_ioctl_dir,
10723 + .open = aufs_open_dir,
10724 + .release = aufs_release_dir,
10725 + .flush = aufs_flush_dir,
10726 + .fsync = aufs_fsync_dir
10728 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10729 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10730 +++ linux/fs/aufs/dir.h 2021-11-01 23:48:34.206359262 +0100
10732 +/* SPDX-License-Identifier: GPL-2.0 */
10734 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10736 + * This program, aufs is free software; you can redistribute it and/or modify
10737 + * it under the terms of the GNU General Public License as published by
10738 + * the Free Software Foundation; either version 2 of the License, or
10739 + * (at your option) any later version.
10741 + * This program is distributed in the hope that it will be useful,
10742 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10743 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10744 + * GNU General Public License for more details.
10746 + * You should have received a copy of the GNU General Public License
10747 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10751 + * directory operations
10754 +#ifndef __AUFS_DIR_H__
10755 +#define __AUFS_DIR_H__
10759 +#include <linux/fs.h>
10761 +/* ---------------------------------------------------------------------- */
10763 +/* need to be faster and smaller */
10766 + unsigned int nh_num;
10767 + struct hlist_head *nh_head;
10770 +struct au_vdir_destr {
10771 + unsigned char len;
10772 + unsigned char name[];
10775 +struct au_vdir_dehstr {
10776 + struct hlist_node hash;
10777 + struct au_vdir_destr *str;
10778 + struct rcu_head rcu;
10779 +} ____cacheline_aligned_in_smp;
10781 +struct au_vdir_de {
10783 + unsigned char de_type;
10784 + /* caution: packed */
10785 + struct au_vdir_destr de_str;
10788 +struct au_vdir_wh {
10789 + struct hlist_node wh_hash;
10790 +#ifdef CONFIG_AUFS_SHWH
10792 + aufs_bindex_t wh_bindex;
10793 + unsigned char wh_type;
10795 + aufs_bindex_t wh_bindex;
10797 + /* caution: packed */
10798 + struct au_vdir_destr wh_str;
10801 +union au_vdir_deblk_p {
10802 + unsigned char *deblk;
10803 + struct au_vdir_de *de;
10807 + unsigned char **vd_deblk;
10808 + unsigned long vd_nblk;
10810 + unsigned long ul;
10811 + union au_vdir_deblk_p p;
10815 + unsigned int vd_deblk_sz;
10816 + unsigned long vd_jiffy;
10817 + struct rcu_head rcu;
10818 +} ____cacheline_aligned_in_smp;
10820 +/* ---------------------------------------------------------------------- */
10823 +extern const struct file_operations aufs_dir_fop;
10824 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10825 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10826 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10827 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10828 +int au_test_empty_lower(struct dentry *dentry);
10829 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10832 +unsigned int au_rdhash_est(loff_t sz);
10833 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10834 +void au_nhash_wh_free(struct au_nhash *whlist);
10835 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10837 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10838 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10839 + unsigned int d_type, aufs_bindex_t bindex,
10840 + unsigned char shwh);
10841 +void au_vdir_free(struct au_vdir *vdir);
10842 +int au_vdir_init(struct file *file);
10843 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10846 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10848 +#ifdef CONFIG_AUFS_RDU
10850 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10851 +#ifdef CONFIG_COMPAT
10852 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10853 + unsigned long arg);
10856 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10857 + unsigned int cmd, unsigned long arg)
10858 +#ifdef CONFIG_COMPAT
10859 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10860 + unsigned int cmd, unsigned long arg)
10864 +#endif /* __KERNEL__ */
10865 +#endif /* __AUFS_DIR_H__ */
10866 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10867 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10868 +++ linux/fs/aufs/dirren.c 2021-11-01 23:48:34.206359262 +0100
10870 +// SPDX-License-Identifier: GPL-2.0
10872 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10874 + * This program, aufs is free software; you can redistribute it and/or modify
10875 + * it under the terms of the GNU General Public License as published by
10876 + * the Free Software Foundation; either version 2 of the License, or
10877 + * (at your option) any later version.
10879 + * This program is distributed in the hope that it will be useful,
10880 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10881 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10882 + * GNU General Public License for more details.
10884 + * You should have received a copy of the GNU General Public License
10885 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10889 + * special handling in renaming a directory
10890 + * in order to support looking-up the before-renamed name on the lower readonly
10894 +#include <linux/byteorder/generic.h>
10897 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10901 + idx = au_dr_ihash(ent->dr_h_ino);
10902 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10905 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10908 + struct hlist_bl_head *hbl;
10911 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10912 + hbl = dr->dr_h_ino + i;
10913 + hlist_bl_lock(hbl);
10914 + ret &= hlist_bl_empty(hbl);
10915 + hlist_bl_unlock(hbl);
10921 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10923 + struct au_dr_hino *found, *ent;
10924 + struct hlist_bl_head *hbl;
10925 + struct hlist_bl_node *pos;
10929 + idx = au_dr_ihash(ino);
10930 + hbl = dr->dr_h_ino + idx;
10931 + hlist_bl_lock(hbl);
10932 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10933 + if (ent->dr_h_ino == ino) {
10937 + hlist_bl_unlock(hbl);
10942 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10943 + struct au_dr_hino *add_ent)
10946 + struct hlist_bl_head *hbl;
10947 + struct hlist_bl_node *pos;
10948 + struct au_dr_hino *ent;
10951 + idx = au_dr_ihash(ino);
10952 + hbl = dr->dr_h_ino + idx;
10953 +#if 0 /* debug print */
10955 + struct hlist_bl_node *tmp;
10957 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10958 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10961 + hlist_bl_lock(hbl);
10962 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10963 + if (ent->dr_h_ino == ino) {
10967 + if (!found && add_ent)
10968 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10969 + hlist_bl_unlock(hbl);
10971 + if (!found && add_ent)
10972 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10977 +void au_dr_hino_free(struct au_dr_br *dr)
10980 + struct hlist_bl_head *hbl;
10981 + struct hlist_bl_node *pos, *tmp;
10982 + struct au_dr_hino *ent;
10984 + /* SiMustWriteLock(sb); */
10986 + for (i = 0; i < AuDirren_NHASH; i++) {
10987 + hbl = dr->dr_h_ino + i;
10988 + /* no spinlock since sbinfo must be write-locked */
10989 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10990 + au_kfree_rcu(ent);
10991 + INIT_HLIST_BL_HEAD(hbl);
10995 +/* returns the number of inodes or an error */
10996 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10997 + struct file *hinofile)
11001 + loff_t pos, oldsize;
11003 + struct inode *hinoinode;
11004 + struct hlist_bl_head *hbl;
11005 + struct hlist_bl_node *n1, *n2;
11006 + struct au_dr_hino *ent;
11008 + SiMustWriteLock(sb);
11009 + AuDebugOn(!au_br_writable(br->br_perm));
11011 + hinoinode = file_inode(hinofile);
11012 + oldsize = i_size_read(hinoinode);
11016 + hbl = br->br_dirren.dr_h_ino;
11017 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11018 + /* no bit-lock since sbinfo must be write-locked */
11019 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11020 + AuDbg("hi%llu, %pD2\n",
11021 + (unsigned long long)ent->dr_h_ino, hinofile);
11022 + u64 = cpu_to_be64(ent->dr_h_ino);
11023 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11024 + if (ssz == sizeof(u64))
11027 + /* write error */
11028 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11035 + /* regardless the error */
11036 + if (pos < oldsize) {
11037 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11045 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11052 + struct au_dr_hino *ent;
11053 + struct inode *hinoinode;
11054 + struct hlist_bl_head *hbl;
11058 + hbl = dr->dr_h_ino;
11059 + hinoinode = file_inode(hinofile);
11060 + sz = i_size_read(hinoinode);
11061 + AuDebugOn(sz % sizeof(u64));
11062 + n = sz / sizeof(u64);
11064 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11065 + if (unlikely(ssz != sizeof(u64))) {
11066 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11073 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11079 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11080 + AuDbg("hi%llu, %pD2\n",
11081 + (unsigned long long)ent->dr_h_ino, hinofile);
11082 + hidx = au_dr_ihash(ent->dr_h_ino);
11083 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11085 + goto out; /* success */
11088 + au_dr_hino_free(dr);
11095 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11096 + * @path is a switch to distinguish load and store.
11098 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11099 + struct au_branch *br, const struct path *path)
11102 + unsigned char load, suspend;
11103 + struct file *hinofile;
11104 + struct au_hinode *hdir;
11105 + struct inode *dir, *delegated;
11106 + struct path hinopath;
11107 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11108 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11110 + AuDebugOn(bindex < 0 && !br);
11111 + AuDebugOn(bindex >= 0 && br);
11116 + br = au_sbr(sb, bindex);
11119 + path = &br->br_path;
11120 + AuDebugOn(!au_br_writable(br->br_perm));
11121 + if (unlikely(!au_br_writable(br->br_perm)))
11127 + dir = d_inode(sb->s_root);
11128 + hdir = au_hinode(au_ii(dir), bindex);
11129 + dir = hdir->hi_inode;
11130 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11132 + dir = d_inode(path->dentry);
11133 + inode_lock_nested(dir, AuLsc_I_CHILD);
11135 + hinopath.mnt = path->mnt;
11136 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11137 + err = PTR_ERR(hinopath.dentry);
11138 + if (IS_ERR(hinopath.dentry))
11142 + flags = O_RDONLY;
11144 + if (d_is_negative(hinopath.dentry))
11145 + goto out_dput; /* success */
11147 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11148 + if (d_is_positive(hinopath.dentry)) {
11149 + delegated = NULL;
11150 + err = vfsub_unlink(dir, &hinopath, &delegated,
11153 + if (unlikely(err))
11154 + pr_err("ignored err %d, %pd2\n",
11155 + err, hinopath.dentry);
11156 + if (unlikely(err == -EWOULDBLOCK))
11161 + } else if (!d_is_positive(hinopath.dentry)) {
11162 + err = vfsub_create(dir, &hinopath, 0600,
11163 + /*want_excl*/false);
11165 + if (unlikely(err))
11168 + flags = O_WRONLY;
11170 + hinofile = vfsub_dentry_open(&hinopath, flags);
11172 + au_hn_inode_unlock(hdir);
11174 + inode_unlock(dir);
11175 + dput(hinopath.dentry);
11176 + AuTraceErrPtr(hinofile);
11177 + if (IS_ERR(hinofile)) {
11178 + err = PTR_ERR(hinofile);
11183 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11185 + err = au_dr_hino_store(sb, br, hinofile);
11190 + dput(hinopath.dentry);
11193 + au_hn_inode_unlock(hdir);
11195 + inode_unlock(dir);
11201 +/* ---------------------------------------------------------------------- */
11203 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11206 + struct kstatfs kstfs;
11208 + struct dentry *dentry;
11209 + struct super_block *sb;
11211 + err = vfs_statfs((void *)path, &kstfs);
11213 + if (unlikely(err))
11216 + /* todo: support for UUID */
11218 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11219 + brid->type = AuBrid_FSID;
11220 + brid->fsid = kstfs.f_fsid;
11222 + dentry = path->dentry;
11223 + sb = dentry->d_sb;
11226 + brid->type = AuBrid_DEV;
11235 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11236 + const struct path *path)
11239 + struct au_dr_br *dr;
11240 + struct hlist_bl_head *hbl;
11242 + dr = &br->br_dirren;
11243 + hbl = dr->dr_h_ino;
11244 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11245 + INIT_HLIST_BL_HEAD(hbl);
11247 + err = au_dr_brid_init(&dr->dr_brid, path);
11248 + if (unlikely(err))
11251 + if (au_opt_test(au_mntflags(sb), DIRREN))
11252 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11259 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11264 + if (au_br_writable(br->br_perm))
11265 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11267 + au_dr_hino_free(&br->br_dirren);
11272 +/* ---------------------------------------------------------------------- */
11274 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11275 + char *buf, size_t sz)
11278 + unsigned int major, minor;
11282 + err = snprintf(p, sz, "%d_", brid->type);
11283 + AuDebugOn(err > sz);
11286 + switch (brid->type) {
11287 + case AuBrid_Unset:
11289 + case AuBrid_UUID:
11290 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11292 + case AuBrid_FSID:
11293 + err = snprintf(p, sz, "%08x-%08x",
11294 + brid->fsid.val[0], brid->fsid.val[1]);
11297 + major = MAJOR(brid->dev);
11298 + minor = MINOR(brid->dev);
11299 + if (major <= 0xff && minor <= 0xff)
11300 + err = snprintf(p, sz, "%02x%02x", major, minor);
11302 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11305 + AuDebugOn(err > sz);
11308 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11309 + AuDebugOn(err > sz);
11316 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11319 + struct dentry *br_dentry;
11320 + struct inode *br_inode;
11322 + br_dentry = au_br_dentry(br);
11323 + br_inode = d_inode(br_dentry);
11324 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11325 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11326 + AuDebugOn(rlen > len);
11331 +/* ---------------------------------------------------------------------- */
11334 + * from the given @h_dentry, construct drinfo at @*fdata.
11335 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11338 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11339 + struct dentry *h_dentry,
11340 + unsigned char *allocated)
11343 + struct au_drinfo_fdata *f, *p;
11344 + struct au_drinfo *drinfo;
11345 + struct inode *h_inode;
11346 + struct qstr *qname;
11350 + h_inode = d_inode(h_dentry);
11351 + qname = &h_dentry->d_name;
11352 + drinfo = &f->drinfo;
11353 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11354 + drinfo->oldnamelen = qname->len;
11355 + if (*allocated < sizeof(*f) + qname->len) {
11356 + v = roundup_pow_of_two(*allocated + qname->len);
11357 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11358 + if (unlikely(!p)) {
11366 + drinfo = &f->drinfo;
11368 + memcpy(drinfo->oldname, qname->name, qname->len);
11369 + AuDbg("i%llu, %.*s\n",
11370 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11371 + drinfo->oldname);
11378 +/* callers have to free the return value */
11379 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11381 + struct au_drinfo *ret, *drinfo;
11382 + struct au_drinfo_fdata fdata;
11387 + ret = ERR_PTR(-EIO);
11389 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11390 + if (unlikely(ssz != sizeof(fdata))) {
11391 + AuIOErr("ssz %zd, %u, %pD2\n",
11392 + ssz, (unsigned int)sizeof(fdata), file);
11396 + fdata.magic = ntohl((__force __be32)fdata.magic);
11397 + switch (fdata.magic) {
11398 + case AUFS_DRINFO_MAGIC_V1:
11401 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11402 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11406 + drinfo = &fdata.drinfo;
11407 + len = drinfo->oldnamelen;
11409 + AuIOErr("broken drinfo %pD2\n", file);
11414 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11415 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11416 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11417 + (unsigned long long)drinfo->ino,
11418 + (unsigned long long)h_ino, file);
11419 + goto out; /* success */
11422 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11423 + if (unlikely(!ret)) {
11424 + ret = ERR_PTR(-ENOMEM);
11425 + AuTraceErrPtr(ret);
11430 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11431 + if (unlikely(ssz != len)) {
11432 + au_kfree_rcu(ret);
11433 + ret = ERR_PTR(-EIO);
11434 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11438 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11444 +/* ---------------------------------------------------------------------- */
11446 +/* in order to be revertible */
11447 +struct au_drinfo_rev_elm {
11449 + struct dentry *info_dentry;
11450 + struct au_drinfo *info_last;
11453 +struct au_drinfo_rev {
11454 + unsigned char already;
11455 + aufs_bindex_t nelm;
11456 + struct au_drinfo_rev_elm elm[];
11459 +/* todo: isn't it too large? */
11460 +struct au_drinfo_store {
11461 + struct path h_ppath;
11462 + struct dentry *h_dentry;
11463 + struct au_drinfo_fdata *fdata;
11464 + char *infoname; /* inside of whname, just after PFX */
11465 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11466 + aufs_bindex_t btgt, btail;
11467 + unsigned char no_sio,
11468 + allocated, /* current size of *fdata */
11469 + infonamelen, /* room size for p */
11470 + whnamelen, /* length of the generated name */
11471 + renameback; /* renamed back */
11474 +/* on rename(2) error, the caller should revert it using @elm */
11475 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11476 + struct au_drinfo_rev_elm *elm)
11481 + struct path infopath = {
11482 + .mnt = w->h_ppath.mnt
11484 + struct inode *h_dir, *h_inode, *delegated;
11485 + struct file *infofile;
11486 + struct qstr *qname;
11489 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11491 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11493 + AuTraceErrPtr(infopath.dentry);
11494 + if (IS_ERR(infopath.dentry)) {
11495 + err = PTR_ERR(infopath.dentry);
11500 + h_dir = d_inode(w->h_ppath.dentry);
11501 + if (elm && d_is_negative(infopath.dentry)) {
11502 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11504 + if (unlikely(err))
11506 + elm->created = 1;
11507 + elm->info_dentry = dget(infopath.dentry);
11510 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11511 + AuTraceErrPtr(infofile);
11512 + if (IS_ERR(infofile)) {
11513 + err = PTR_ERR(infofile);
11517 + h_inode = d_inode(infopath.dentry);
11518 + if (elm && i_size_read(h_inode)) {
11519 + h_inode = d_inode(w->h_dentry);
11520 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11521 + AuTraceErrPtr(elm->info_last);
11522 + if (IS_ERR(elm->info_last)) {
11523 + err = PTR_ERR(elm->info_last);
11524 + elm->info_last = NULL;
11525 + AuDebugOn(elm->info_dentry);
11530 + if (elm && w->renameback) {
11531 + delegated = NULL;
11532 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11534 + if (unlikely(err == -EWOULDBLOCK))
11540 + qname = &w->h_dentry->d_name;
11541 + len = sizeof(*w->fdata) + qname->len;
11543 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11544 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11545 + if (ssz == len) {
11546 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11547 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11548 + goto out_fput; /* success */
11553 + /* the caller should revert it using @elm */
11559 + dput(infopath.dentry);
11565 +struct au_call_drinfo_do_store_args {
11567 + struct au_drinfo_store *w;
11568 + struct au_drinfo_rev_elm *elm;
11571 +static void au_call_drinfo_do_store(void *args)
11573 + struct au_call_drinfo_do_store_args *a = args;
11575 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11578 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11579 + struct au_drinfo_rev_elm *elm)
11581 + int err, wkq_err;
11584 + err = au_drinfo_do_store(w, elm);
11586 + struct au_call_drinfo_do_store_args a = {
11591 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11592 + if (unlikely(wkq_err))
11600 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11601 + aufs_bindex_t btgt)
11605 + memset(w, 0, sizeof(*w));
11606 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11607 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11608 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11609 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11611 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11614 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11615 + if (unlikely(!w->fdata)) {
11619 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11626 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11628 + au_kfree_rcu(w->fdata);
11631 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11632 + struct au_drinfo_store *w)
11634 + struct au_drinfo_rev_elm *elm;
11635 + struct inode *h_dir, *delegated;
11637 + struct path infopath = {
11638 + .mnt = w->h_ppath.mnt
11641 + h_dir = d_inode(w->h_ppath.dentry);
11642 + IMustLock(h_dir);
11646 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11647 + AuDebugOn(elm->created && elm->info_last);
11648 + if (elm->created) {
11650 + delegated = NULL;
11651 + infopath.dentry = elm->info_dentry;
11652 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11655 + if (unlikely(err == -EWOULDBLOCK))
11657 + dput(elm->info_dentry);
11658 + } else if (elm->info_last) {
11660 + w->fdata->drinfo = *elm->info_last;
11661 + memcpy(w->fdata->drinfo.oldname,
11662 + elm->info_last->oldname,
11663 + elm->info_last->oldnamelen);
11664 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11665 + au_kfree_rcu(elm->info_last);
11667 + if (unlikely(err))
11668 + AuIOErr("%d, %s\n", err, w->whname);
11669 + /* go on even if err */
11673 +/* caller has to call au_dr_rename_fin() later */
11674 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11675 + struct qstr *dst_name, void *_rev)
11677 + int err, sz, nelm;
11678 + aufs_bindex_t bindex, btail;
11679 + struct au_drinfo_store work;
11680 + struct au_drinfo_rev *rev, **p;
11681 + struct au_drinfo_rev_elm *elm;
11682 + struct super_block *sb;
11683 + struct au_branch *br;
11684 + struct au_hinode *hdir;
11686 + err = au_drinfo_store_work_init(&work, btgt);
11688 + if (unlikely(err))
11692 + btail = au_dbtaildir(dentry);
11693 + nelm = btail - btgt;
11694 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11695 + rev = kcalloc(1, sz, GFP_NOFS);
11696 + if (unlikely(!rev)) {
11700 + rev->nelm = nelm;
11706 + sb = dentry->d_sb;
11707 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11708 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11709 + hdir = au_hi(d_inode(dentry), btgt);
11710 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11711 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11712 + work.h_dentry = au_h_dptr(dentry, bindex);
11713 + if (!work.h_dentry)
11716 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11717 + &work.allocated);
11719 + if (unlikely(err))
11722 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11723 + br = au_sbr(sb, bindex);
11724 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11725 + work.whnamelen += au_drinfo_name(br, work.infoname,
11726 + work.infonamelen);
11727 + AuDbg("whname %.*s, i%llu, %.*s\n",
11728 + work.whnamelen, work.whname,
11729 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11730 + work.fdata->drinfo.oldnamelen,
11731 + work.fdata->drinfo.oldname);
11733 + err = au_drinfo_store_sio(&work, elm);
11735 + if (unlikely(err))
11738 + if (unlikely(err)) {
11739 + /* revert all drinfo */
11740 + au_drinfo_store_rev(rev, &work);
11741 + au_kfree_try_rcu(rev);
11744 + au_hn_inode_unlock(hdir);
11747 + au_drinfo_store_work_fin(&work);
11752 +/* ---------------------------------------------------------------------- */
11754 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11755 + struct qstr *dst_name, void *_rev)
11757 + int err, already;
11759 + struct super_block *sb;
11760 + struct au_branch *br;
11761 + struct au_dr_br *dr;
11762 + struct dentry *h_dentry;
11763 + struct inode *h_inode;
11764 + struct au_dr_hino *ent;
11765 + struct au_drinfo_rev *rev, **p;
11767 + AuDbg("bindex %d\n", bindex);
11770 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11771 + if (unlikely(!ent))
11775 + br = au_sbr(sb, bindex);
11776 + dr = &br->br_dirren;
11777 + h_dentry = au_h_dptr(src, bindex);
11778 + h_inode = d_inode(h_dentry);
11779 + ino = h_inode->i_ino;
11780 + ent->dr_h_ino = ino;
11781 + already = au_dr_hino_test_add(dr, ino, ent);
11782 + AuDbg("b%d, hi%llu, already %d\n",
11783 + bindex, (unsigned long long)ino, already);
11785 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11790 + rev->already = already;
11791 + goto out; /* success */
11796 + au_dr_hino_del(dr, ent);
11797 + au_kfree_rcu(ent);
11804 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11806 + struct au_drinfo_rev *rev;
11807 + struct au_drinfo_rev_elm *elm;
11812 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11813 + dput(elm->info_dentry);
11814 + au_kfree_rcu(elm->info_last);
11816 + au_kfree_try_rcu(rev);
11819 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11822 + struct au_drinfo_store work;
11823 + struct au_drinfo_rev *rev = _rev;
11824 + struct super_block *sb;
11825 + struct au_branch *br;
11826 + struct inode *h_inode;
11827 + struct au_dr_br *dr;
11828 + struct au_dr_hino *ent;
11830 + err = au_drinfo_store_work_init(&work, btgt);
11831 + if (unlikely(err))
11835 + br = au_sbr(sb, btgt);
11836 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11837 + work.h_ppath.mnt = au_br_mnt(br);
11838 + au_drinfo_store_rev(rev, &work);
11839 + au_drinfo_store_work_fin(&work);
11840 + if (rev->already)
11843 + dr = &br->br_dirren;
11844 + h_inode = d_inode(work.h_ppath.dentry);
11845 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11847 + au_dr_hino_del(dr, ent);
11848 + au_kfree_rcu(ent);
11851 + au_kfree_try_rcu(rev);
11852 + if (unlikely(err))
11853 + pr_err("failed to remove dirren info\n");
11856 +/* ---------------------------------------------------------------------- */
11858 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11859 + char *whname, int whnamelen,
11860 + struct dentry **info_dentry)
11862 + struct au_drinfo *drinfo;
11864 + struct inode *h_dir;
11865 + struct path infopath;
11868 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11870 + *info_dentry = NULL;
11873 + h_dir = d_inode(h_ppath->dentry);
11874 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11875 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11876 + if (IS_ERR(infopath.dentry)) {
11877 + drinfo = (void *)infopath.dentry;
11881 + if (d_is_negative(infopath.dentry))
11882 + goto out_dput; /* success */
11884 + infopath.mnt = h_ppath->mnt;
11885 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11886 + inode_unlock_shared(h_dir);
11889 + drinfo = (void *)f;
11893 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11894 + if (IS_ERR_OR_NULL(drinfo))
11897 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11898 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11903 + dput(infopath.dentry);
11906 + inode_unlock_shared(h_dir);
11907 + AuTraceErrPtr(drinfo);
11911 +struct au_drinfo_do_load_args {
11912 + struct au_drinfo **drinfop;
11913 + struct path *h_ppath;
11916 + struct dentry **info_dentry;
11919 +static void au_call_drinfo_do_load(void *args)
11921 + struct au_drinfo_do_load_args *a = args;
11923 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11927 +struct au_drinfo_load {
11928 + struct path h_ppath;
11929 + struct qstr *qname;
11930 + unsigned char no_sio;
11932 + aufs_bindex_t ninfo;
11933 + struct au_drinfo **drinfo;
11936 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11937 + struct au_branch *br)
11939 + int err, wkq_err, whnamelen, e;
11940 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11941 + = AUFS_WH_DR_INFO_PFX;
11942 + struct au_drinfo *drinfo;
11943 + struct qstr oldname;
11944 + struct inode *h_dir, *delegated;
11945 + struct dentry *info_dentry;
11946 + struct path infopath;
11948 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11949 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11950 + sizeof(whname) - whnamelen);
11952 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11955 + struct au_drinfo_do_load_args args = {
11956 + .drinfop = &drinfo,
11957 + .h_ppath = &w->h_ppath,
11958 + .whname = whname,
11959 + .whnamelen = whnamelen,
11960 + .info_dentry = &info_dentry
11962 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11963 + if (unlikely(wkq_err))
11964 + drinfo = ERR_PTR(wkq_err);
11966 + err = PTR_ERR(drinfo);
11967 + if (IS_ERR_OR_NULL(drinfo))
11971 + oldname.len = drinfo->oldnamelen;
11972 + oldname.name = drinfo->oldname;
11973 + if (au_qstreq(w->qname, &oldname)) {
11974 + /* the name is renamed back */
11975 + au_kfree_rcu(drinfo);
11978 + infopath.dentry = info_dentry;
11979 + infopath.mnt = w->h_ppath.mnt;
11980 + h_dir = d_inode(w->h_ppath.dentry);
11981 + delegated = NULL;
11982 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11983 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11984 + inode_unlock(h_dir);
11986 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11987 + if (unlikely(e == -EWOULDBLOCK))
11990 + au_kfree_rcu(w->drinfo[bindex]);
11991 + w->drinfo[bindex] = drinfo;
11992 + dput(info_dentry);
11999 +/* ---------------------------------------------------------------------- */
12001 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12003 + struct au_drinfo **p = drinfo;
12006 + au_kfree_rcu(*drinfo++);
12007 + au_kfree_try_rcu(p);
12010 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12011 + aufs_bindex_t btgt)
12014 + struct au_drinfo_load w;
12015 + aufs_bindex_t bindex, bbot;
12016 + struct au_branch *br;
12017 + struct inode *h_dir;
12018 + struct au_dr_hino *ent;
12019 + struct super_block *sb;
12021 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12022 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12023 + AuLNPair(&lkup->whname), btgt);
12025 + sb = dentry->d_sb;
12026 + bbot = au_sbbot(sb);
12027 + w.ninfo = bbot + 1;
12028 + if (!lkup->dirren.drinfo) {
12029 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12030 + sizeof(*lkup->dirren.drinfo),
12032 + if (unlikely(!lkup->dirren.drinfo)) {
12036 + lkup->dirren.ninfo = w.ninfo;
12038 + w.drinfo = lkup->dirren.drinfo;
12039 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12040 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12041 + AuDebugOn(!w.h_ppath.dentry);
12042 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12043 + w.qname = &dentry->d_name;
12046 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12047 + br = au_sbr(sb, bindex);
12048 + err = au_drinfo_load(&w, bindex, br);
12049 + if (unlikely(err))
12051 + if (w.drinfo[bindex])
12055 + br = au_sbr(sb, btgt);
12056 + h_dir = d_inode(w.h_ppath.dentry);
12057 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12059 + au_dr_hino_del(&br->br_dirren, ent);
12060 + au_kfree_rcu(ent);
12062 + goto out; /* success */
12065 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12066 + lkup->dirren.ninfo = 0;
12067 + lkup->dirren.drinfo = NULL;
12073 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12075 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12078 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12081 + struct au_drinfo *drinfo;
12084 + if (!lkup->dirren.drinfo)
12086 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12087 + drinfo = lkup->dirren.drinfo[btgt];
12091 + au_kfree_try_rcu(lkup->whname.name);
12092 + lkup->whname.name = NULL;
12093 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12094 + lkup->dirren.dr_name.name = drinfo->oldname;
12095 + lkup->name = &lkup->dirren.dr_name;
12096 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12098 + AuDbg("name %.*s, whname %.*s, b%d\n",
12099 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12107 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12111 + struct au_drinfo *drinfo;
12114 + if (!lkup->dirren.drinfo)
12116 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12117 + drinfo = lkup->dirren.drinfo[bindex];
12121 + match = (drinfo->ino == h_ino);
12122 + AuDbg("match %d\n", match);
12128 +/* ---------------------------------------------------------------------- */
12130 +int au_dr_opt_set(struct super_block *sb)
12133 + aufs_bindex_t bindex, bbot;
12134 + struct au_branch *br;
12137 + bbot = au_sbbot(sb);
12138 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12139 + br = au_sbr(sb, bindex);
12140 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12146 +int au_dr_opt_flush(struct super_block *sb)
12149 + aufs_bindex_t bindex, bbot;
12150 + struct au_branch *br;
12153 + bbot = au_sbbot(sb);
12154 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12155 + br = au_sbr(sb, bindex);
12156 + if (au_br_writable(br->br_perm))
12157 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12163 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12166 + aufs_bindex_t bindex, bbot;
12167 + struct au_branch *br;
12171 + err = au_dr_opt_flush(sb);
12172 + if (unlikely(err))
12176 + bbot = au_sbbot(sb);
12177 + for (bindex = 0; bindex <= bbot; bindex++) {
12178 + br = au_sbr(sb, bindex);
12179 + au_dr_hino_free(&br->br_dirren);
12185 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12186 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12187 +++ linux/fs/aufs/dirren.h 2021-11-01 23:48:34.206359262 +0100
12189 +/* SPDX-License-Identifier: GPL-2.0 */
12191 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12193 + * This program, aufs is free software; you can redistribute it and/or modify
12194 + * it under the terms of the GNU General Public License as published by
12195 + * the Free Software Foundation; either version 2 of the License, or
12196 + * (at your option) any later version.
12198 + * This program is distributed in the hope that it will be useful,
12199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12201 + * GNU General Public License for more details.
12203 + * You should have received a copy of the GNU General Public License
12204 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12208 + * renamed dir info
12211 +#ifndef __AUFS_DIRREN_H__
12212 +#define __AUFS_DIRREN_H__
12216 +#include <linux/dcache.h>
12217 +#include <linux/statfs.h>
12218 +#include <linux/uuid.h>
12221 +#define AuDirren_NHASH 100
12223 +#ifdef CONFIG_AUFS_DIRREN
12224 +enum au_brid_type {
12231 +struct au_dr_brid {
12232 + enum au_brid_type type;
12234 + uuid_t uuid; /* unimplemented yet */
12240 +/* 20 is the max digits length of ulong 64 */
12241 +/* brid-type "_" uuid "_" inum */
12242 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12243 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12245 +struct au_dr_hino {
12246 + struct hlist_bl_node dr_hnode;
12251 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12252 + struct au_dr_brid dr_brid;
12255 +struct au_dr_lookup {
12256 + /* dr_name is pointed by struct au_do_lookup_args.name */
12257 + struct qstr dr_name; /* subset of dr_info */
12258 + aufs_bindex_t ninfo;
12259 + struct au_drinfo **drinfo;
12262 +struct au_dr_hino;
12264 +struct au_dr_br { };
12265 +struct au_dr_lookup { };
12268 +/* ---------------------------------------------------------------------- */
12271 +struct au_do_lookup_args;
12273 +#ifdef CONFIG_AUFS_DIRREN
12274 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12275 + struct au_dr_hino *add_ent);
12276 +void au_dr_hino_free(struct au_dr_br *dr);
12277 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12278 + const struct path *path);
12279 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12280 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12281 + struct qstr *dst_name, void *_rev);
12282 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12283 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12284 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12285 + aufs_bindex_t bindex);
12286 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12287 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12289 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12290 +int au_dr_opt_set(struct super_block *sb);
12291 +int au_dr_opt_flush(struct super_block *sb);
12292 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12294 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12295 + struct au_dr_hino *add_ent);
12296 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12297 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12298 + const struct path *path);
12299 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12300 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12301 + struct qstr *dst_name, void *_rev);
12302 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12303 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12305 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12306 + aufs_bindex_t bindex);
12307 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12308 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12309 + aufs_bindex_t bindex, ino_t h_ino);
12310 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12311 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12312 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12313 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12316 +/* ---------------------------------------------------------------------- */
12318 +#ifdef CONFIG_AUFS_DIRREN
12319 +static inline int au_dr_ihash(ino_t h_ino)
12321 + return h_ino % AuDirren_NHASH;
12324 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12327 +#endif /* __KERNEL__ */
12328 +#endif /* __AUFS_DIRREN_H__ */
12329 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12330 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12331 +++ linux/fs/aufs/dynop.c 2021-11-01 23:48:34.206359262 +0100
12333 +// SPDX-License-Identifier: GPL-2.0
12335 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12337 + * This program, aufs is free software; you can redistribute it and/or modify
12338 + * it under the terms of the GNU General Public License as published by
12339 + * the Free Software Foundation; either version 2 of the License, or
12340 + * (at your option) any later version.
12342 + * This program is distributed in the hope that it will be useful,
12343 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12344 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12345 + * GNU General Public License for more details.
12347 + * You should have received a copy of the GNU General Public License
12348 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12352 + * dynamically customizable operations for regular files
12357 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12360 + * How large will these lists be?
12361 + * Usually just a few elements, 20-30 at most for each, I guess.
12363 +static struct hlist_bl_head dynop[AuDyLast];
12365 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12366 + const void *h_op)
12368 + struct au_dykey *key, *tmp;
12369 + struct hlist_bl_node *pos;
12372 + hlist_bl_lock(hbl);
12373 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12374 + if (tmp->dk_op.dy_hop == h_op) {
12375 + if (kref_get_unless_zero(&tmp->dk_kref))
12379 + hlist_bl_unlock(hbl);
12384 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12386 + struct au_dykey **k, *found;
12387 + const void *h_op = key->dk_op.dy_hop;
12391 + k = br->br_dykey;
12392 + for (i = 0; i < AuBrDynOp; i++)
12394 + if (k[i]->dk_op.dy_hop == h_op) {
12401 + spin_lock(&br->br_dykey_lock);
12402 + for (; i < AuBrDynOp; i++)
12404 + if (k[i]->dk_op.dy_hop == h_op) {
12412 + spin_unlock(&br->br_dykey_lock);
12413 + BUG_ON(i == AuBrDynOp); /* expand the array */
12419 +/* kref_get() if @key is already added */
12420 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12422 + struct au_dykey *tmp, *found;
12423 + struct hlist_bl_node *pos;
12424 + const void *h_op = key->dk_op.dy_hop;
12427 + hlist_bl_lock(hbl);
12428 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12429 + if (tmp->dk_op.dy_hop == h_op) {
12430 + if (kref_get_unless_zero(&tmp->dk_kref))
12435 + hlist_bl_add_head(&key->dk_hnode, hbl);
12436 + hlist_bl_unlock(hbl);
12443 +static void dy_free_rcu(struct rcu_head *rcu)
12445 + struct au_dykey *key;
12447 + key = container_of(rcu, struct au_dykey, dk_rcu);
12452 +static void dy_free(struct kref *kref)
12454 + struct au_dykey *key;
12455 + struct hlist_bl_head *hbl;
12457 + key = container_of(kref, struct au_dykey, dk_kref);
12458 + hbl = dynop + key->dk_op.dy_type;
12459 + au_hbl_del(&key->dk_hnode, hbl);
12460 + call_rcu(&key->dk_rcu, dy_free_rcu);
12463 +void au_dy_put(struct au_dykey *key)
12465 + kref_put(&key->dk_kref, dy_free);
12468 +/* ---------------------------------------------------------------------- */
12470 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12472 +#ifdef CONFIG_AUFS_DEBUG
12473 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12474 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12476 +#define DyDbgDeclare(cnt) do {} while (0)
12477 +#define DyDbgInc(cnt) do {} while (0)
12480 +#define DySet(func, dst, src, h_op, h_sb) do { \
12482 + if (h_op->func) { \
12484 + dst.func = src.func; \
12486 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12490 +#define DySetForce(func, dst, src) do { \
12491 + AuDebugOn(!src.func); \
12493 + dst.func = src.func; \
12496 +#define DySetAop(func) \
12497 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12498 +#define DySetAopForce(func) \
12499 + DySetForce(func, dyaop->da_op, aufs_aop)
12501 +static void dy_aop(struct au_dykey *key, const void *h_op,
12502 + struct super_block *h_sb __maybe_unused)
12504 + struct au_dyaop *dyaop = (void *)key;
12505 + const struct address_space_operations *h_aop = h_op;
12506 + DyDbgDeclare(cnt);
12508 + AuDbg("%s\n", au_sbtype(h_sb));
12510 + DySetAop(writepage);
12511 + DySetAopForce(readpage); /* force */
12512 + DySetAop(writepages);
12513 + DySetAop(set_page_dirty);
12514 + DySetAop(readpages);
12515 + DySetAop(readahead);
12516 + DySetAop(write_begin);
12517 + DySetAop(write_end);
12519 + DySetAop(invalidatepage);
12520 + DySetAop(releasepage);
12521 + DySetAop(freepage);
12522 + /* this one will be changed according to an aufs mount option */
12523 + DySetAop(direct_IO);
12524 + DySetAop(migratepage);
12525 + DySetAop(isolate_page);
12526 + DySetAop(putback_page);
12527 + DySetAop(launder_page);
12528 + DySetAop(is_partially_uptodate);
12529 + DySetAop(is_dirty_writeback);
12530 + DySetAop(error_remove_page);
12531 + DySetAop(swap_activate);
12532 + DySetAop(swap_deactivate);
12534 + DyDbgSize(cnt, *h_aop);
12537 +/* ---------------------------------------------------------------------- */
12539 +static void dy_bug(struct kref *kref)
12544 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12546 + struct au_dykey *key, *old;
12547 + struct hlist_bl_head *hbl;
12550 + void (*set)(struct au_dykey *key, const void *h_op,
12551 + struct super_block *h_sb __maybe_unused);
12553 + static const struct op a[] = {
12555 + .sz = sizeof(struct au_dyaop),
12559 + const struct op *p;
12561 + hbl = dynop + op->dy_type;
12562 + key = dy_gfind_get(hbl, op->dy_hop);
12564 + goto out_add; /* success */
12566 + p = a + op->dy_type;
12567 + key = kzalloc(p->sz, GFP_NOFS);
12568 + if (unlikely(!key)) {
12569 + key = ERR_PTR(-ENOMEM);
12573 + key->dk_op.dy_hop = op->dy_hop;
12574 + kref_init(&key->dk_kref);
12575 + p->set(key, op->dy_hop, au_br_sb(br));
12576 + old = dy_gadd(hbl, key);
12578 + au_kfree_rcu(key);
12583 + old = dy_bradd(br, key);
12585 + /* its ref-count should never be zero here */
12586 + kref_put(&key->dk_kref, dy_bug);
12591 +/* ---------------------------------------------------------------------- */
12593 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12594 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12595 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12596 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12597 + * See the aufs manual in detail.
12599 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12602 + dyaop->da_op.direct_IO = NULL;
12604 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12607 +static struct au_dyaop *dy_aget(struct au_branch *br,
12608 + const struct address_space_operations *h_aop,
12611 + struct au_dyaop *dyaop;
12612 + struct au_dynop op;
12614 + op.dy_type = AuDy_AOP;
12615 + op.dy_haop = h_aop;
12616 + dyaop = (void *)dy_get(&op, br);
12617 + if (IS_ERR(dyaop))
12619 + dy_adx(dyaop, do_dx);
12625 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12626 + struct inode *h_inode)
12629 + struct super_block *sb;
12630 + struct au_branch *br;
12631 + struct au_dyaop *dyaop;
12633 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12634 + IiMustWriteLock(inode);
12636 + sb = inode->i_sb;
12637 + br = au_sbr(sb, bindex);
12638 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12639 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12640 + err = PTR_ERR(dyaop);
12641 + if (IS_ERR(dyaop))
12642 + /* unnecessary to call dy_fput() */
12646 + inode->i_mapping->a_ops = &dyaop->da_op;
12653 + * Is it safe to replace a_ops during the inode/file is in operation?
12654 + * Yes, I hope so.
12656 +int au_dy_irefresh(struct inode *inode)
12659 + aufs_bindex_t btop;
12660 + struct inode *h_inode;
12663 + if (S_ISREG(inode->i_mode)) {
12664 + btop = au_ibtop(inode);
12665 + h_inode = au_h_iptr(inode, btop);
12666 + err = au_dy_iaop(inode, btop, h_inode);
12671 +void au_dy_arefresh(int do_dx)
12673 + struct hlist_bl_head *hbl;
12674 + struct hlist_bl_node *pos;
12675 + struct au_dykey *key;
12677 + hbl = dynop + AuDy_AOP;
12678 + hlist_bl_lock(hbl);
12679 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12680 + dy_adx((void *)key, do_dx);
12681 + hlist_bl_unlock(hbl);
12684 +/* ---------------------------------------------------------------------- */
12686 +void __init au_dy_init(void)
12690 + for (i = 0; i < AuDyLast; i++)
12691 + INIT_HLIST_BL_HEAD(dynop + i);
12694 +void au_dy_fin(void)
12698 + for (i = 0; i < AuDyLast; i++)
12699 + WARN_ON(!hlist_bl_empty(dynop + i));
12701 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12702 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12703 +++ linux/fs/aufs/dynop.h 2021-11-01 23:48:34.206359262 +0100
12705 +/* SPDX-License-Identifier: GPL-2.0 */
12707 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12709 + * This program, aufs is free software; you can redistribute it and/or modify
12710 + * it under the terms of the GNU General Public License as published by
12711 + * the Free Software Foundation; either version 2 of the License, or
12712 + * (at your option) any later version.
12714 + * This program is distributed in the hope that it will be useful,
12715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12717 + * GNU General Public License for more details.
12719 + * You should have received a copy of the GNU General Public License
12720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12724 + * dynamically customizable operations (for regular files only)
12727 +#ifndef __AUFS_DYNOP_H__
12728 +#define __AUFS_DYNOP_H__
12732 +#include <linux/fs.h>
12733 +#include <linux/kref.h>
12735 +enum {AuDy_AOP, AuDyLast};
12740 + const void *dy_hop;
12741 + const struct address_space_operations *dy_haop;
12747 + struct hlist_bl_node dk_hnode;
12748 + struct rcu_head dk_rcu;
12750 + struct au_dynop dk_op;
12753 + * during I am in the branch local array, kref is gotten. when the
12754 + * branch is removed, kref is put.
12756 + struct kref dk_kref;
12759 +/* stop unioning since their sizes are very different from each other */
12761 + struct au_dykey da_key;
12762 + struct address_space_operations da_op; /* not const */
12764 +/* make sure that 'struct au_dykey *' can be any type */
12765 +static_assert(!offsetof(struct au_dyaop, da_key));
12767 +/* ---------------------------------------------------------------------- */
12771 +void au_dy_put(struct au_dykey *key);
12772 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12773 + struct inode *h_inode);
12774 +int au_dy_irefresh(struct inode *inode);
12775 +void au_dy_arefresh(int do_dio);
12777 +void __init au_dy_init(void);
12778 +void au_dy_fin(void);
12780 +#endif /* __KERNEL__ */
12781 +#endif /* __AUFS_DYNOP_H__ */
12782 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12783 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12784 +++ linux/fs/aufs/export.c 2021-11-01 23:48:34.206359262 +0100
12786 +// SPDX-License-Identifier: GPL-2.0
12788 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12790 + * This program, aufs is free software; you can redistribute it and/or modify
12791 + * it under the terms of the GNU General Public License as published by
12792 + * the Free Software Foundation; either version 2 of the License, or
12793 + * (at your option) any later version.
12795 + * This program is distributed in the hope that it will be useful,
12796 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12797 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12798 + * GNU General Public License for more details.
12800 + * You should have received a copy of the GNU General Public License
12801 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12808 +#include <linux/exportfs.h>
12809 +#include <linux/fs_struct.h>
12810 +#include <linux/namei.h>
12811 +#include <linux/nsproxy.h>
12812 +#include <linux/random.h>
12813 +#include <linux/writeback.h>
12817 +#ifdef CONFIG_AUFS_INO_T_64
12825 +static ino_t decode_ino(__u32 *a)
12829 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12831 +#ifdef CONFIG_AUFS_INO_T_64
12837 +static void encode_ino(__u32 *a, ino_t ino)
12843 +#ifdef CONFIG_AUFS_INO_T_64
12848 +/* NFS file handle */
12852 +#ifdef CONFIG_AUFS_INO_T_64
12853 + /* support 64bit inode number */
12866 + Fh_ino = Fh_ino1,
12867 + Fh_dir_ino = Fh_dir_ino1
12870 +static int au_test_anon(struct dentry *dentry)
12872 + /* note: read d_flags without d_lock */
12873 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12876 +int au_test_nfsd(void)
12879 + struct task_struct *tsk = current;
12880 + char comm[sizeof(tsk->comm)];
12883 + if (tsk->flags & PF_KTHREAD) {
12884 + get_task_comm(comm, tsk);
12885 + ret = !strcmp(comm, "nfsd");
12891 +/* ---------------------------------------------------------------------- */
12892 +/* inode generation external table */
12894 +void au_xigen_inc(struct inode *inode)
12899 + struct super_block *sb;
12900 + struct au_sbinfo *sbinfo;
12902 + sb = inode->i_sb;
12903 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12905 + sbinfo = au_sbi(sb);
12906 + pos = inode->i_ino;
12907 + pos *= sizeof(igen);
12908 + igen = inode->i_generation + 1;
12909 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12910 + if (sz == sizeof(igen))
12911 + return; /* success */
12913 + if (unlikely(sz >= 0))
12914 + AuIOErr("xigen error (%zd)\n", sz);
12917 +int au_xigen_new(struct inode *inode)
12922 + struct super_block *sb;
12923 + struct au_sbinfo *sbinfo;
12924 + struct file *file;
12927 + /* todo: dirty, at mount time */
12928 + if (inode->i_ino == AUFS_ROOT_INO)
12930 + sb = inode->i_sb;
12931 + SiMustAnyLock(sb);
12932 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12936 + pos = inode->i_ino;
12937 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12938 + AuIOErr1("too large i%lld\n", pos);
12941 + pos *= sizeof(inode->i_generation);
12944 + sbinfo = au_sbi(sb);
12945 + file = sbinfo->si_xigen;
12948 + if (vfsub_f_size_read(file)
12949 + < pos + sizeof(inode->i_generation)) {
12950 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12951 + sz = xino_fwrite(file, &inode->i_generation,
12952 + sizeof(inode->i_generation), &pos);
12954 + sz = xino_fread(file, &inode->i_generation,
12955 + sizeof(inode->i_generation), &pos);
12956 + if (sz == sizeof(inode->i_generation))
12957 + goto out; /* success */
12960 + if (unlikely(sz >= 0)) {
12962 + AuIOErr("xigen error (%zd)\n", sz);
12969 +int au_xigen_set(struct super_block *sb, struct path *path)
12972 + struct au_sbinfo *sbinfo;
12973 + struct file *file;
12975 + SiMustWriteLock(sb);
12977 + sbinfo = au_sbi(sb);
12978 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12979 + err = PTR_ERR(file);
12980 + if (IS_ERR(file))
12983 + if (sbinfo->si_xigen)
12984 + fput(sbinfo->si_xigen);
12985 + sbinfo->si_xigen = file;
12992 +void au_xigen_clr(struct super_block *sb)
12994 + struct au_sbinfo *sbinfo;
12996 + SiMustWriteLock(sb);
12998 + sbinfo = au_sbi(sb);
12999 + if (sbinfo->si_xigen) {
13000 + fput(sbinfo->si_xigen);
13001 + sbinfo->si_xigen = NULL;
13005 +/* ---------------------------------------------------------------------- */
13007 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13010 + struct dentry *dentry, *d;
13011 + struct inode *inode;
13012 + unsigned int sigen;
13015 + inode = ilookup(sb, ino);
13019 + dentry = ERR_PTR(-ESTALE);
13020 + sigen = au_sigen(sb);
13021 + if (unlikely(au_is_bad_inode(inode)
13022 + || IS_DEADDIR(inode)
13023 + || sigen != au_iigen(inode, NULL)))
13027 + if (!dir_ino || S_ISDIR(inode->i_mode))
13028 + dentry = d_find_alias(inode);
13030 + spin_lock(&inode->i_lock);
13031 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13032 + spin_lock(&d->d_lock);
13033 + if (!au_test_anon(d)
13034 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13035 + dentry = dget_dlock(d);
13036 + spin_unlock(&d->d_lock);
13039 + spin_unlock(&d->d_lock);
13041 + spin_unlock(&inode->i_lock);
13043 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13044 + /* need to refresh */
13052 + AuTraceErrPtr(dentry);
13056 +/* ---------------------------------------------------------------------- */
13058 +/* todo: dirty? */
13059 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13061 +struct au_compare_mnt_args {
13063 + struct super_block *sb;
13066 + struct vfsmount *mnt;
13069 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13071 + struct au_compare_mnt_args *a = arg;
13073 + if (mnt->mnt_sb != a->sb)
13075 + a->mnt = mntget(mnt);
13079 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13082 + struct path root;
13083 + struct au_compare_mnt_args args = {
13087 + get_fs_root(current->fs, &root);
13089 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13090 + rcu_read_unlock();
13093 + AuDebugOn(!args.mnt);
13097 +struct au_nfsd_si_lock {
13098 + unsigned int sigen;
13099 + aufs_bindex_t bindex, br_id;
13100 + unsigned char force_lock;
13103 +static int si_nfsd_read_lock(struct super_block *sb,
13104 + struct au_nfsd_si_lock *nsi_lock)
13107 + aufs_bindex_t bindex;
13109 + si_read_lock(sb, AuLock_FLUSH);
13111 + /* branch id may be wrapped around */
13113 + bindex = au_br_index(sb, nsi_lock->br_id);
13114 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13115 + goto out; /* success */
13119 + if (!nsi_lock->force_lock)
13120 + si_read_unlock(sb);
13123 + nsi_lock->bindex = bindex;
13127 +struct find_name_by_ino {
13128 + struct dir_context ctx;
13129 + int called, found;
13136 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13137 + loff_t offset, u64 ino, unsigned int d_type)
13139 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13143 + if (a->ino != ino)
13146 + memcpy(a->name, name, namelen);
13147 + a->namelen = namelen;
13152 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13153 + struct au_nfsd_si_lock *nsi_lock)
13155 + struct dentry *dentry, *parent;
13156 + struct file *file;
13157 + struct inode *dir;
13158 + struct find_name_by_ino arg = {
13160 + .actor = find_name_by_ino
13165 + parent = path->dentry;
13167 + si_read_unlock(parent->d_sb);
13168 + file = vfsub_dentry_open(path, au_dir_roflags);
13169 + dentry = (void *)file;
13170 + if (IS_ERR(file))
13173 + dentry = ERR_PTR(-ENOMEM);
13174 + arg.name = (void *)__get_free_page(GFP_NOFS);
13175 + if (unlikely(!arg.name))
13182 + err = vfsub_iterate_dir(file, &arg.ctx);
13183 + } while (!err && !arg.found && arg.called);
13184 + dentry = ERR_PTR(err);
13185 + if (unlikely(err))
13187 + /* instead of ENOENT */
13188 + dentry = ERR_PTR(-ESTALE);
13192 + /* do not call vfsub_lkup_one() */
13193 + dir = d_inode(parent);
13194 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13195 + AuTraceErrPtr(dentry);
13196 + if (IS_ERR(dentry))
13198 + AuDebugOn(au_test_anon(dentry));
13199 + if (unlikely(d_really_is_negative(dentry))) {
13201 + dentry = ERR_PTR(-ENOENT);
13205 + free_page((unsigned long)arg.name);
13209 + if (unlikely(nsi_lock
13210 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13211 + if (!IS_ERR(dentry)) {
13213 + dentry = ERR_PTR(-ESTALE);
13215 + AuTraceErrPtr(dentry);
13219 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13221 + struct au_nfsd_si_lock *nsi_lock)
13223 + struct dentry *dentry;
13224 + struct path path;
13226 + if (dir_ino != AUFS_ROOT_INO) {
13227 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13228 + dentry = path.dentry;
13229 + if (!path.dentry || IS_ERR(path.dentry))
13231 + AuDebugOn(au_test_anon(path.dentry));
13233 + path.dentry = dget(sb->s_root);
13235 + path.mnt = au_mnt_get(sb);
13236 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13240 + AuTraceErrPtr(dentry);
13244 +/* ---------------------------------------------------------------------- */
13246 +static int h_acceptable(void *expv, struct dentry *dentry)
13251 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13252 + char *buf, int len, struct super_block *sb)
13256 + struct path path;
13258 + p = d_path(h_rootpath, buf, len);
13263 + path.mnt = h_rootpath->mnt;
13264 + path.dentry = h_parent;
13265 + p = d_path(&path, buf, len);
13271 + path.mnt = au_mnt_get(sb);
13272 + path.dentry = sb->s_root;
13273 + p = d_path(&path, buf, len - strlen(p));
13274 + mntput(path.mnt);
13278 + p[strlen(p)] = '/';
13281 + AuTraceErrPtr(p);
13286 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13287 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13289 + struct dentry *dentry, *h_parent, *root;
13290 + struct super_block *h_sb;
13291 + char *pathname, *p;
13292 + struct vfsmount *h_mnt;
13293 + struct au_branch *br;
13295 + struct path path;
13297 + br = au_sbr(sb, nsi_lock->bindex);
13298 + h_mnt = au_br_mnt(br);
13299 + h_sb = h_mnt->mnt_sb;
13300 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13302 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13303 + fh_len - Fh_tail, fh[Fh_h_type],
13304 + h_acceptable, /*context*/NULL);
13306 + dentry = h_parent;
13307 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13308 + AuWarn1("%s decode_fh failed, %ld\n",
13309 + au_sbtype(h_sb), PTR_ERR(h_parent));
13313 + if (unlikely(au_test_anon(h_parent))) {
13314 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13315 + au_sbtype(h_sb));
13316 + goto out_h_parent;
13319 + dentry = ERR_PTR(-ENOMEM);
13320 + pathname = (void *)__get_free_page(GFP_NOFS);
13321 + if (unlikely(!pathname))
13322 + goto out_h_parent;
13324 + root = sb->s_root;
13325 + path.mnt = h_mnt;
13326 + di_read_lock_parent(root, !AuLock_IR);
13327 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13328 + di_read_unlock(root, !AuLock_IR);
13329 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13330 + dentry = (void *)p;
13332 + goto out_pathname;
13334 + si_read_unlock(sb);
13335 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13336 + dentry = ERR_PTR(err);
13337 + if (unlikely(err))
13340 + dentry = ERR_PTR(-ENOENT);
13341 + AuDebugOn(au_test_anon(path.dentry));
13342 + if (unlikely(d_really_is_negative(path.dentry)))
13345 + if (ino != d_inode(path.dentry)->i_ino)
13346 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13348 + dentry = dget(path.dentry);
13353 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13354 + if (!IS_ERR(dentry)) {
13356 + dentry = ERR_PTR(-ESTALE);
13359 + free_page((unsigned long)pathname);
13363 + AuTraceErrPtr(dentry);
13367 +/* ---------------------------------------------------------------------- */
13369 +static struct dentry *
13370 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13373 + struct dentry *dentry;
13374 + __u32 *fh = fid->raw;
13375 + struct au_branch *br;
13376 + ino_t ino, dir_ino;
13377 + struct au_nfsd_si_lock nsi_lock = {
13381 + dentry = ERR_PTR(-ESTALE);
13382 + /* it should never happen, but the file handle is unreliable */
13383 + if (unlikely(fh_len < Fh_tail))
13385 + nsi_lock.sigen = fh[Fh_sigen];
13386 + nsi_lock.br_id = fh[Fh_br_id];
13388 + /* branch id may be wrapped around */
13390 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13392 + nsi_lock.force_lock = 1;
13394 + /* is this inode still cached? */
13395 + ino = decode_ino(fh + Fh_ino);
13396 + /* it should never happen */
13397 + if (unlikely(ino == AUFS_ROOT_INO))
13400 + dir_ino = decode_ino(fh + Fh_dir_ino);
13401 + dentry = decode_by_ino(sb, ino, dir_ino);
13402 + if (IS_ERR(dentry))
13407 + /* is the parent dir cached? */
13408 + br = au_sbr(sb, nsi_lock.bindex);
13409 + au_lcnt_inc(&br->br_nfiles);
13410 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13411 + if (IS_ERR(dentry))
13416 + /* lookup path */
13417 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13418 + if (IS_ERR(dentry))
13420 + if (unlikely(!dentry))
13421 + /* todo?: make it ESTALE */
13425 + if (!au_digen_test(dentry, au_sigen(sb))
13426 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13427 + goto out_unlock; /* success */
13430 + dentry = ERR_PTR(-ESTALE);
13433 + au_lcnt_dec(&br->br_nfiles);
13434 + si_read_unlock(sb);
13436 + AuTraceErrPtr(dentry);
13440 +#if 0 /* reserved for future use */
13441 +/* support subtreecheck option */
13442 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13443 + int fh_len, int fh_type)
13445 + struct dentry *parent;
13446 + __u32 *fh = fid->raw;
13449 + dir_ino = decode_ino(fh + Fh_dir_ino);
13450 + parent = decode_by_ino(sb, dir_ino, 0);
13451 + if (IS_ERR(parent))
13454 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13455 + dir_ino, fh, fh_len);
13458 + AuTraceErrPtr(parent);
13463 +/* ---------------------------------------------------------------------- */
13465 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13466 + struct inode *dir)
13469 + aufs_bindex_t bindex;
13470 + struct super_block *sb, *h_sb;
13471 + struct dentry *dentry, *parent, *h_parent;
13472 + struct inode *h_dir;
13473 + struct au_branch *br;
13476 + if (unlikely(*max_len <= Fh_tail)) {
13477 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13481 + err = FILEID_ROOT;
13482 + if (inode->i_ino == AUFS_ROOT_INO) {
13483 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13488 + sb = inode->i_sb;
13489 + err = si_read_lock(sb, AuLock_FLUSH);
13490 + if (unlikely(err))
13493 +#ifdef CONFIG_AUFS_DEBUG
13494 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13495 + AuWarn1("NFS-exporting requires xino\n");
13499 + ii_read_lock_child(inode);
13500 + bindex = au_ibtop(inode);
13502 + dentry = d_find_any_alias(inode);
13503 + if (unlikely(!dentry))
13505 + AuDebugOn(au_test_anon(dentry));
13506 + parent = dget_parent(dentry);
13508 + if (unlikely(!parent))
13510 + if (d_really_is_positive(parent))
13511 + dir = d_inode(parent);
13514 + ii_read_lock_parent(dir);
13515 + h_dir = au_h_iptr(dir, bindex);
13516 + ii_read_unlock(dir);
13517 + if (unlikely(!h_dir))
13519 + h_parent = d_find_any_alias(h_dir);
13520 + if (unlikely(!h_parent))
13521 + goto out_hparent;
13524 + br = au_sbr(sb, bindex);
13525 + h_sb = au_br_sb(br);
13526 + if (unlikely(!h_sb->s_export_op)) {
13527 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13528 + goto out_hparent;
13531 + fh[Fh_br_id] = br->br_id;
13532 + fh[Fh_sigen] = au_sigen(sb);
13533 + encode_ino(fh + Fh_ino, inode->i_ino);
13534 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13535 + fh[Fh_igen] = inode->i_generation;
13537 + *max_len -= Fh_tail;
13538 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13540 + /*connectable or subtreecheck*/0);
13541 + err = fh[Fh_h_type];
13542 + *max_len += Fh_tail;
13543 + /* todo: macros? */
13544 + if (err != FILEID_INVALID)
13547 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13554 + ii_read_unlock(inode);
13555 + si_read_unlock(sb);
13557 + if (unlikely(err < 0))
13558 + err = FILEID_INVALID;
13562 +/* ---------------------------------------------------------------------- */
13564 +static int aufs_commit_metadata(struct inode *inode)
13567 + aufs_bindex_t bindex;
13568 + struct super_block *sb;
13569 + struct inode *h_inode;
13570 + int (*f)(struct inode *inode);
13572 + sb = inode->i_sb;
13573 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13574 + ii_write_lock_child(inode);
13575 + bindex = au_ibtop(inode);
13576 + AuDebugOn(bindex < 0);
13577 + h_inode = au_h_iptr(inode, bindex);
13579 + f = h_inode->i_sb->s_export_op->commit_metadata;
13581 + err = f(h_inode);
13583 + err = sync_inode_metadata(h_inode, /*wait*/1);
13585 + au_cpup_attr_timesizes(inode);
13586 + ii_write_unlock(inode);
13587 + si_read_unlock(sb);
13591 +/* ---------------------------------------------------------------------- */
13593 +static struct export_operations aufs_export_op = {
13594 + .fh_to_dentry = aufs_fh_to_dentry,
13595 + /* .fh_to_parent = aufs_fh_to_parent, */
13596 + .encode_fh = aufs_encode_fh,
13597 + .commit_metadata = aufs_commit_metadata
13600 +void au_export_init(struct super_block *sb)
13602 + struct au_sbinfo *sbinfo;
13605 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13606 + && IS_MODULE(CONFIG_EXPORTFS),
13607 + AUFS_NAME ": unsupported configuration "
13608 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13610 + sb->s_export_op = &aufs_export_op;
13611 + sbinfo = au_sbi(sb);
13612 + sbinfo->si_xigen = NULL;
13613 + get_random_bytes(&u, sizeof(u));
13614 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13615 + atomic_set(&sbinfo->si_xigen_next, u);
13617 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13618 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13619 +++ linux/fs/aufs/fhsm.c 2021-11-01 23:48:34.206359262 +0100
13621 +// SPDX-License-Identifier: GPL-2.0
13623 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13625 + * This program, aufs is free software; you can redistribute it and/or modify
13626 + * it under the terms of the GNU General Public License as published by
13627 + * the Free Software Foundation; either version 2 of the License, or
13628 + * (at your option) any later version.
13630 + * This program is distributed in the hope that it will be useful,
13631 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13632 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13633 + * GNU General Public License for more details.
13635 + * You should have received a copy of the GNU General Public License
13636 + * along with this program; if not, write to the Free Software
13637 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13641 + * File-based Hierarchy Storage Management
13644 +#include <linux/anon_inodes.h>
13645 +#include <linux/poll.h>
13646 +#include <linux/seq_file.h>
13647 +#include <linux/statfs.h>
13650 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13652 + struct au_sbinfo *sbinfo;
13653 + struct au_fhsm *fhsm;
13655 + SiMustAnyLock(sb);
13657 + sbinfo = au_sbi(sb);
13658 + fhsm = &sbinfo->si_fhsm;
13659 + AuDebugOn(!fhsm);
13660 + return fhsm->fhsm_bottom;
13663 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13665 + struct au_sbinfo *sbinfo;
13666 + struct au_fhsm *fhsm;
13668 + SiMustWriteLock(sb);
13670 + sbinfo = au_sbi(sb);
13671 + fhsm = &sbinfo->si_fhsm;
13672 + AuDebugOn(!fhsm);
13673 + fhsm->fhsm_bottom = bindex;
13676 +/* ---------------------------------------------------------------------- */
13678 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13680 + struct au_br_fhsm *bf;
13682 + bf = br->br_fhsm;
13683 + MtxMustLock(&bf->bf_lock);
13685 + return !bf->bf_readable
13686 + || time_after(jiffies,
13687 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13690 +/* ---------------------------------------------------------------------- */
13692 +static void au_fhsm_notify(struct super_block *sb, int val)
13694 + struct au_sbinfo *sbinfo;
13695 + struct au_fhsm *fhsm;
13697 + SiMustAnyLock(sb);
13699 + sbinfo = au_sbi(sb);
13700 + fhsm = &sbinfo->si_fhsm;
13701 + if (au_fhsm_pid(fhsm)
13702 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13703 + atomic_set(&fhsm->fhsm_readable, val);
13705 + wake_up(&fhsm->fhsm_wqh);
13709 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13710 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13713 + struct au_branch *br;
13714 + struct au_br_fhsm *bf;
13716 + br = au_sbr(sb, bindex);
13717 + AuDebugOn(au_br_rdonly(br));
13718 + bf = br->br_fhsm;
13722 + mutex_lock(&bf->bf_lock);
13724 + MtxMustLock(&bf->bf_lock);
13726 + /* sb->s_root for NFS is unreliable */
13727 + err = au_br_stfs(br, &bf->bf_stfs);
13728 + if (unlikely(err)) {
13729 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13733 + bf->bf_jiffy = jiffies;
13734 + bf->bf_readable = 1;
13736 + au_fhsm_notify(sb, /*val*/1);
13738 + *rstfs = bf->bf_stfs;
13742 + mutex_unlock(&bf->bf_lock);
13743 + au_fhsm_notify(sb, /*val*/1);
13748 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13751 + struct au_sbinfo *sbinfo;
13752 + struct au_fhsm *fhsm;
13753 + struct au_branch *br;
13754 + struct au_br_fhsm *bf;
13756 + AuDbg("b%d, force %d\n", bindex, force);
13757 + SiMustAnyLock(sb);
13759 + sbinfo = au_sbi(sb);
13760 + fhsm = &sbinfo->si_fhsm;
13761 + if (!au_ftest_si(sbinfo, FHSM)
13762 + || fhsm->fhsm_bottom == bindex)
13765 + br = au_sbr(sb, bindex);
13766 + bf = br->br_fhsm;
13768 + mutex_lock(&bf->bf_lock);
13770 + || au_fhsm_pid(fhsm)
13771 + || au_fhsm_test_jiffy(sbinfo, br))
13772 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13774 + mutex_unlock(&bf->bf_lock);
13777 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13779 + aufs_bindex_t bindex, bbot;
13780 + struct au_branch *br;
13782 + /* exclude the bottom */
13783 + bbot = au_fhsm_bottom(sb);
13784 + for (bindex = 0; bindex < bbot; bindex++) {
13785 + br = au_sbr(sb, bindex);
13786 + if (au_br_fhsm(br->br_perm))
13787 + au_fhsm_wrote(sb, bindex, force);
13791 +/* ---------------------------------------------------------------------- */
13793 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13796 + struct au_sbinfo *sbinfo;
13797 + struct au_fhsm *fhsm;
13800 + sbinfo = file->private_data;
13801 + fhsm = &sbinfo->si_fhsm;
13802 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13803 + if (atomic_read(&fhsm->fhsm_readable))
13804 + mask = EPOLLIN /* | EPOLLRDNORM */;
13807 + AuDbg("mask 0x%x\n", mask);
13811 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13812 + struct aufs_stfs *stfs, __s16 brid)
13816 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13818 + err = __put_user(brid, &stbr->brid);
13819 + if (unlikely(err))
13825 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13826 + struct aufs_stbr __user *stbr, size_t count)
13830 + aufs_bindex_t bindex, bbot;
13831 + struct au_branch *br;
13832 + struct au_br_fhsm *bf;
13834 + /* except the bottom branch */
13837 + bbot = au_fhsm_bottom(sb);
13838 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13839 + br = au_sbr(sb, bindex);
13840 + if (!au_br_fhsm(br->br_perm))
13843 + bf = br->br_fhsm;
13844 + mutex_lock(&bf->bf_lock);
13845 + if (bf->bf_readable) {
13847 + if (count >= sizeof(*stbr))
13848 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13851 + bf->bf_readable = 0;
13852 + count -= sizeof(*stbr);
13856 + mutex_unlock(&bf->bf_lock);
13859 + err = sizeof(*stbr) * nstbr;
13864 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13869 + aufs_bindex_t nfhsm, bindex, bbot;
13870 + struct au_sbinfo *sbinfo;
13871 + struct au_fhsm *fhsm;
13872 + struct au_branch *br;
13873 + struct super_block *sb;
13876 + sbinfo = file->private_data;
13877 + fhsm = &sbinfo->si_fhsm;
13879 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13880 + if (!atomic_read(&fhsm->fhsm_readable)) {
13881 + if (vfsub_file_flags(file) & O_NONBLOCK)
13884 + err = wait_event_interruptible_locked_irq
13886 + atomic_read(&fhsm->fhsm_readable));
13888 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13889 + if (unlikely(err))
13892 + /* sb may already be dead */
13893 + au_rw_read_lock(&sbinfo->si_rwsem);
13894 + readable = atomic_read(&fhsm->fhsm_readable);
13895 + if (readable > 0) {
13896 + sb = sbinfo->si_sb;
13898 + /* exclude the bottom branch */
13900 + bbot = au_fhsm_bottom(sb);
13901 + for (bindex = 0; bindex < bbot; bindex++) {
13902 + br = au_sbr(sb, bindex);
13903 + if (au_br_fhsm(br->br_perm))
13907 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13908 + atomic_set(&fhsm->fhsm_readable, 0);
13909 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13913 + au_rw_read_unlock(&sbinfo->si_rwsem);
13921 +static int au_fhsm_release(struct inode *inode, struct file *file)
13923 + struct au_sbinfo *sbinfo;
13924 + struct au_fhsm *fhsm;
13926 + /* sb may already be dead */
13927 + sbinfo = file->private_data;
13928 + fhsm = &sbinfo->si_fhsm;
13929 + spin_lock(&fhsm->fhsm_spin);
13930 + fhsm->fhsm_pid = 0;
13931 + spin_unlock(&fhsm->fhsm_spin);
13932 + kobject_put(&sbinfo->si_kobj);
13937 +static const struct file_operations au_fhsm_fops = {
13938 + .owner = THIS_MODULE,
13939 + .llseek = noop_llseek,
13940 + .read = au_fhsm_read,
13941 + .poll = au_fhsm_poll,
13942 + .release = au_fhsm_release
13945 +int au_fhsm_fd(struct super_block *sb, int oflags)
13948 + struct au_sbinfo *sbinfo;
13949 + struct au_fhsm *fhsm;
13952 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13956 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13960 + sbinfo = au_sbi(sb);
13961 + fhsm = &sbinfo->si_fhsm;
13962 + spin_lock(&fhsm->fhsm_spin);
13963 + if (!fhsm->fhsm_pid)
13964 + fhsm->fhsm_pid = current->pid;
13967 + spin_unlock(&fhsm->fhsm_spin);
13968 + if (unlikely(err))
13971 + oflags |= O_RDONLY;
13972 + /* oflags |= FMODE_NONOTIFY; */
13973 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13975 + if (unlikely(fd < 0))
13978 + /* succeed regardless 'fhsm' status */
13979 + kobject_get(&sbinfo->si_kobj);
13980 + si_noflush_read_lock(sb);
13981 + if (au_ftest_si(sbinfo, FHSM))
13982 + au_fhsm_wrote_all(sb, /*force*/0);
13983 + si_read_unlock(sb);
13984 + goto out; /* success */
13987 + spin_lock(&fhsm->fhsm_spin);
13988 + fhsm->fhsm_pid = 0;
13989 + spin_unlock(&fhsm->fhsm_spin);
13995 +/* ---------------------------------------------------------------------- */
13997 +int au_fhsm_br_alloc(struct au_branch *br)
14002 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14004 + au_br_fhsm_init(br->br_fhsm);
14011 +/* ---------------------------------------------------------------------- */
14013 +void au_fhsm_fin(struct super_block *sb)
14015 + au_fhsm_notify(sb, /*val*/-1);
14018 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14020 + struct au_fhsm *fhsm;
14022 + fhsm = &sbinfo->si_fhsm;
14023 + spin_lock_init(&fhsm->fhsm_spin);
14024 + init_waitqueue_head(&fhsm->fhsm_wqh);
14025 + atomic_set(&fhsm->fhsm_readable, 0);
14026 + fhsm->fhsm_expire
14027 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14028 + fhsm->fhsm_bottom = -1;
14031 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14033 + sbinfo->si_fhsm.fhsm_expire
14034 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14037 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14041 + if (!au_ftest_si(sbinfo, FHSM))
14044 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14045 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14046 + seq_printf(seq, ",fhsm_sec=%u", u);
14048 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14049 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14050 +++ linux/fs/aufs/file.c 2021-11-01 23:48:34.206359262 +0100
14052 +// SPDX-License-Identifier: GPL-2.0
14054 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14056 + * This program, aufs is free software; you can redistribute it and/or modify
14057 + * it under the terms of the GNU General Public License as published by
14058 + * the Free Software Foundation; either version 2 of the License, or
14059 + * (at your option) any later version.
14061 + * This program is distributed in the hope that it will be useful,
14062 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14063 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14064 + * GNU General Public License for more details.
14066 + * You should have received a copy of the GNU General Public License
14067 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14071 + * handling file/dir, and address_space operation
14074 +#ifdef CONFIG_AUFS_DEBUG
14075 +#include <linux/migrate.h>
14077 +#include <linux/pagemap.h>
14080 +/* drop flags for writing */
14081 +unsigned int au_file_roflags(unsigned int flags)
14083 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14084 + flags |= O_RDONLY | O_NOATIME;
14088 +/* common functions to regular file and dir */
14089 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14090 + struct file *file, int force_wr)
14092 + struct file *h_file;
14093 + struct dentry *h_dentry;
14094 + struct inode *h_inode;
14095 + struct super_block *sb;
14096 + struct au_branch *br;
14097 + struct path h_path;
14100 + /* a race condition can happen between open and unlink/rmdir */
14101 + h_file = ERR_PTR(-ENOENT);
14102 + h_dentry = au_h_dptr(dentry, bindex);
14103 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14105 + h_inode = d_inode(h_dentry);
14106 + spin_lock(&h_dentry->d_lock);
14107 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14108 + /* || !d_inode(dentry)->i_nlink */
14110 + spin_unlock(&h_dentry->d_lock);
14111 + if (unlikely(err))
14114 + sb = dentry->d_sb;
14115 + br = au_sbr(sb, bindex);
14116 + err = au_br_test_oflag(flags, br);
14117 + h_file = ERR_PTR(err);
14118 + if (unlikely(err))
14121 + /* drop flags for writing */
14122 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14123 + if (force_wr && !(flags & O_WRONLY))
14125 + flags = au_file_roflags(flags);
14127 + h_file = ERR_PTR(-EROFS);
14128 + flags = au_file_roflags(flags);
14129 + if (unlikely(vfsub_native_ro(h_inode)
14130 + || IS_APPEND(h_inode)))
14132 + flags &= ~O_ACCMODE;
14133 + flags |= O_WRONLY;
14136 + flags &= ~O_CREAT;
14137 + au_lcnt_inc(&br->br_nfiles);
14138 + h_path.dentry = h_dentry;
14139 + h_path.mnt = au_br_mnt(br);
14140 + h_file = vfsub_dentry_open(&h_path, flags);
14141 + if (IS_ERR(h_file))
14144 + if (flags & __FMODE_EXEC) {
14145 + err = deny_write_access(h_file);
14146 + if (unlikely(err)) {
14148 + h_file = ERR_PTR(err);
14152 + fsnotify_open(h_file);
14153 + goto out; /* success */
14156 + au_lcnt_dec(&br->br_nfiles);
14161 +static int au_cmoo(struct dentry *dentry)
14163 + int err, cmoo, matched;
14164 + unsigned int udba;
14165 + struct path h_path;
14166 + struct au_pin pin;
14167 + struct au_cp_generic cpg = {
14168 + .dentry = dentry,
14173 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14175 + struct inode *delegated;
14176 + struct super_block *sb;
14177 + struct au_sbinfo *sbinfo;
14178 + struct au_fhsm *fhsm;
14180 + struct au_branch *br;
14181 + struct dentry *parent;
14182 + struct au_hinode *hdir;
14184 + DiMustWriteLock(dentry);
14185 + IiMustWriteLock(d_inode(dentry));
14188 + if (IS_ROOT(dentry))
14190 + cpg.bsrc = au_dbtop(dentry);
14194 + sb = dentry->d_sb;
14195 + sbinfo = au_sbi(sb);
14196 + fhsm = &sbinfo->si_fhsm;
14197 + pid = au_fhsm_pid(fhsm);
14200 + && (current->pid == pid
14201 + || rcu_dereference(current->real_parent)->pid == pid));
14202 + rcu_read_unlock();
14206 + br = au_sbr(sb, cpg.bsrc);
14207 + cmoo = au_br_cmoo(br->br_perm);
14210 + if (!d_is_reg(dentry))
14211 + cmoo &= AuBrAttr_COO_ALL;
14215 + parent = dget_parent(dentry);
14216 + di_write_lock_parent(parent);
14217 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14219 + if (unlikely(err < 0)) {
14220 + err = 0; /* there is no upper writable branch */
14223 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14225 + /* do not respect the coo attrib for the target branch */
14226 + err = au_cpup_dirs(dentry, cpg.bdst);
14227 + if (unlikely(err))
14230 + di_downgrade_lock(parent, AuLock_IR);
14231 + udba = au_opt_udba(sb);
14232 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14233 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14234 + if (unlikely(err))
14237 + err = au_sio_cpup_simple(&cpg);
14239 + if (unlikely(err))
14241 + if (!(cmoo & AuBrWAttr_MOO))
14242 + goto out_parent; /* success */
14244 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14245 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14246 + if (unlikely(err))
14249 + h_path.mnt = au_br_mnt(br);
14250 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14251 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14252 + delegated = NULL;
14253 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14255 + /* todo: keep h_dentry or not? */
14256 + if (unlikely(err == -EWOULDBLOCK)) {
14257 + pr_warn("cannot retry for NFSv4 delegation"
14258 + " for an internal unlink\n");
14261 + if (unlikely(err)) {
14262 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14266 + goto out_parent; /* success */
14269 + di_downgrade_lock(parent, AuLock_IR);
14271 + di_read_unlock(parent, AuLock_IR);
14278 +int au_do_open(struct file *file, struct au_do_open_args *args)
14280 + int err, aopen = args->aopen;
14281 + struct dentry *dentry;
14282 + struct au_finfo *finfo;
14285 + err = au_finfo_init(file, args->fidir);
14288 + err = au_finfo_init(file, args->fidir);
14291 + if (unlikely(err))
14294 + dentry = file->f_path.dentry;
14295 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14296 + di_write_lock_child(dentry);
14297 + err = au_cmoo(dentry);
14298 + di_downgrade_lock(dentry, AuLock_IR);
14301 + err = args->open(file, vfsub_file_flags(file), NULL);
14304 + err = args->open(file, vfsub_file_flags(file),
14309 + di_read_unlock(dentry, AuLock_IR);
14311 + finfo = au_fi(file);
14313 + finfo->fi_file = file;
14314 + au_hbl_add(&finfo->fi_hlist,
14315 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14318 + fi_write_unlock(file);
14321 + fi_write_unlock(file);
14324 + if (unlikely(err)) {
14325 + finfo->fi_hdir = NULL;
14326 + au_finfo_fin(file);
14334 +int au_reopen_nondir(struct file *file)
14337 + aufs_bindex_t btop;
14338 + struct dentry *dentry;
14339 + struct au_branch *br;
14340 + struct file *h_file, *h_file_tmp;
14342 + dentry = file->f_path.dentry;
14343 + btop = au_dbtop(dentry);
14344 + br = au_sbr(dentry->d_sb, btop);
14345 + h_file_tmp = NULL;
14346 + if (au_fbtop(file) == btop) {
14347 + h_file = au_hf_top(file);
14348 + if (file->f_mode == h_file->f_mode)
14349 + return 0; /* success */
14350 + h_file_tmp = h_file;
14351 + get_file(h_file_tmp);
14352 + au_lcnt_inc(&br->br_nfiles);
14353 + au_set_h_fptr(file, btop, NULL);
14355 + AuDebugOn(au_fi(file)->fi_hdir);
14358 + * file exists on both of rw and ro
14359 + * open --> dbtop and fbtop are both 0
14360 + * prepend a branch as rw, "rw" become ro
14362 + * delete the top branch, "rw" becomes rw again
14363 + * --> dbtop is 1, fbtop is still 0
14364 + * write --> fbtop is 0 but dbtop is 1
14366 + /* AuDebugOn(au_fbtop(file) < btop); */
14368 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14369 + file, /*force_wr*/0);
14370 + err = PTR_ERR(h_file);
14371 + if (IS_ERR(h_file)) {
14372 + if (h_file_tmp) {
14374 + au_set_h_fptr(file, btop, h_file_tmp);
14375 + h_file_tmp = NULL;
14377 + goto out; /* todo: close all? */
14381 + au_set_fbtop(file, btop);
14382 + au_set_h_fptr(file, btop, h_file);
14383 + au_update_figen(file);
14384 + /* todo: necessary? */
14385 + /* file->f_ra = h_file->f_ra; */
14388 + if (h_file_tmp) {
14389 + fput(h_file_tmp);
14390 + au_lcnt_dec(&br->br_nfiles);
14395 +/* ---------------------------------------------------------------------- */
14397 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14398 + struct dentry *hi_wh)
14401 + aufs_bindex_t btop;
14402 + struct au_dinfo *dinfo;
14403 + struct dentry *h_dentry;
14404 + struct au_hdentry *hdp;
14406 + dinfo = au_di(file->f_path.dentry);
14407 + AuRwMustWriteLock(&dinfo->di_rwsem);
14409 + btop = dinfo->di_btop;
14410 + dinfo->di_btop = btgt;
14411 + hdp = au_hdentry(dinfo, btgt);
14412 + h_dentry = hdp->hd_dentry;
14413 + hdp->hd_dentry = hi_wh;
14414 + err = au_reopen_nondir(file);
14415 + hdp->hd_dentry = h_dentry;
14416 + dinfo->di_btop = btop;
14421 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14422 + aufs_bindex_t bcpup, struct au_pin *pin)
14425 + struct inode *inode, *h_inode;
14426 + struct dentry *h_dentry, *hi_wh;
14427 + struct au_cp_generic cpg = {
14428 + .dentry = file->f_path.dentry,
14435 + au_update_dbtop(cpg.dentry);
14436 + inode = d_inode(cpg.dentry);
14438 + if (au_dbtop(cpg.dentry) <= bcpup
14439 + && au_dbbot(cpg.dentry) >= bcpup) {
14440 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14441 + if (h_dentry && d_is_positive(h_dentry))
14442 + h_inode = d_inode(h_dentry);
14444 + hi_wh = au_hi_wh(inode, bcpup);
14445 + if (!hi_wh && !h_inode)
14446 + err = au_sio_cpup_wh(&cpg, file);
14448 + /* already copied-up after unlink */
14449 + err = au_reopen_wh(file, bcpup, hi_wh);
14452 + && (inode->i_nlink > 1
14453 + || (inode->i_state & I_LINKABLE))
14454 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14455 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14461 + * prepare the @file for writing.
14463 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14466 + aufs_bindex_t dbtop;
14467 + struct dentry *parent;
14468 + struct inode *inode;
14469 + struct super_block *sb;
14470 + struct file *h_file;
14471 + struct au_cp_generic cpg = {
14472 + .dentry = file->f_path.dentry,
14477 + .flags = AuCpup_DTIME
14480 + sb = cpg.dentry->d_sb;
14481 + inode = d_inode(cpg.dentry);
14482 + cpg.bsrc = au_fbtop(file);
14483 + err = au_test_ro(sb, cpg.bsrc, inode);
14484 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14485 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14490 + /* need to cpup or reopen */
14491 + parent = dget_parent(cpg.dentry);
14492 + di_write_lock_parent(parent);
14493 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14495 + if (unlikely(err < 0))
14499 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14500 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14501 + if (unlikely(err))
14505 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14506 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14507 + if (unlikely(err))
14510 + dbtop = au_dbtop(cpg.dentry);
14511 + if (dbtop <= cpg.bdst)
14512 + cpg.bsrc = cpg.bdst;
14514 + if (dbtop <= cpg.bdst /* just reopen */
14515 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14517 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14518 + if (IS_ERR(h_file))
14519 + err = PTR_ERR(h_file);
14521 + di_downgrade_lock(parent, AuLock_IR);
14522 + if (dbtop > cpg.bdst)
14523 + err = au_sio_cpup_simple(&cpg);
14525 + err = au_reopen_nondir(file);
14526 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14528 + } else { /* copyup as wh and reopen */
14530 + * since writable hfsplus branch is not supported,
14531 + * h_open_pre/post() are unnecessary.
14533 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14534 + di_downgrade_lock(parent, AuLock_IR);
14538 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14539 + goto out_dput; /* success */
14545 + di_downgrade_lock(parent, AuLock_IR);
14547 + di_read_unlock(parent, AuLock_IR);
14554 +/* ---------------------------------------------------------------------- */
14556 +int au_do_flush(struct file *file, fl_owner_t id,
14557 + int (*flush)(struct file *file, fl_owner_t id))
14560 + struct super_block *sb;
14561 + struct inode *inode;
14563 + inode = file_inode(file);
14564 + sb = inode->i_sb;
14565 + si_noflush_read_lock(sb);
14566 + fi_read_lock(file);
14567 + ii_read_lock_child(inode);
14569 + err = flush(file, id);
14570 + au_cpup_attr_timesizes(inode);
14572 + ii_read_unlock(inode);
14573 + fi_read_unlock(file);
14574 + si_read_unlock(sb);
14578 +/* ---------------------------------------------------------------------- */
14580 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14583 + struct au_pin pin;
14584 + struct au_finfo *finfo;
14585 + struct dentry *parent, *hi_wh;
14586 + struct inode *inode;
14587 + struct super_block *sb;
14588 + struct au_cp_generic cpg = {
14589 + .dentry = file->f_path.dentry,
14594 + .flags = AuCpup_DTIME
14597 + FiMustWriteLock(file);
14600 + finfo = au_fi(file);
14601 + sb = cpg.dentry->d_sb;
14602 + inode = d_inode(cpg.dentry);
14603 + cpg.bdst = au_ibtop(inode);
14604 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14607 + parent = dget_parent(cpg.dentry);
14608 + if (au_test_ro(sb, cpg.bdst, inode)) {
14609 + di_read_lock_parent(parent, !AuLock_IR);
14610 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14612 + di_read_unlock(parent, !AuLock_IR);
14613 + if (unlikely(err < 0))
14618 + di_read_lock_parent(parent, AuLock_IR);
14619 + hi_wh = au_hi_wh(inode, cpg.bdst);
14620 + if (!S_ISDIR(inode->i_mode)
14621 + && au_opt_test(au_mntflags(sb), PLINK)
14622 + && au_plink_test(inode)
14623 + && !d_unhashed(cpg.dentry)
14624 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14625 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14626 + if (unlikely(err))
14629 + /* always superio. */
14630 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14631 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14633 + err = au_sio_cpup_simple(&cpg);
14636 + } else if (hi_wh) {
14637 + /* already copied-up after unlink */
14638 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14639 + *need_reopen = 0;
14643 + di_read_unlock(parent, AuLock_IR);
14650 +static void au_do_refresh_dir(struct file *file)
14652 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14653 + struct au_hfile *p, tmp, *q;
14654 + struct au_finfo *finfo;
14655 + struct super_block *sb;
14656 + struct au_fidir *fidir;
14658 + FiMustWriteLock(file);
14660 + sb = file->f_path.dentry->d_sb;
14661 + finfo = au_fi(file);
14662 + fidir = finfo->fi_hdir;
14663 + AuDebugOn(!fidir);
14664 + p = fidir->fd_hfile + finfo->fi_btop;
14665 + brid = p->hf_br->br_id;
14666 + bbot = fidir->fd_bbot;
14667 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14671 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14672 + if (new_bindex == bindex)
14674 + if (new_bindex < 0) {
14675 + au_set_h_fptr(file, bindex, NULL);
14679 + /* swap two lower inode, and loop again */
14680 + q = fidir->fd_hfile + new_bindex;
14684 + if (tmp.hf_file) {
14690 + p = fidir->fd_hfile;
14691 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14692 + bbot = au_sbbot(sb);
14693 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14694 + finfo->fi_btop++, p++)
14695 + if (p->hf_file) {
14696 + if (file_inode(p->hf_file))
14698 + au_hfput(p, /*execed*/0);
14701 + bbot = au_br_index(sb, brid);
14702 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14703 + finfo->fi_btop++, p++)
14705 + au_hfput(p, /*execed*/0);
14706 + bbot = au_sbbot(sb);
14709 + p = fidir->fd_hfile + bbot;
14710 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14711 + fidir->fd_bbot--, p--)
14712 + if (p->hf_file) {
14713 + if (file_inode(p->hf_file))
14715 + au_hfput(p, /*execed*/0);
14717 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14721 + * after branch manipulating, refresh the file.
14723 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14725 + int err, need_reopen, nbr;
14726 + aufs_bindex_t bbot, bindex;
14727 + struct dentry *dentry;
14728 + struct super_block *sb;
14729 + struct au_finfo *finfo;
14730 + struct au_hfile *hfile;
14732 + dentry = file->f_path.dentry;
14733 + sb = dentry->d_sb;
14734 + nbr = au_sbbot(sb) + 1;
14735 + finfo = au_fi(file);
14736 + if (!finfo->fi_hdir) {
14737 + hfile = &finfo->fi_htop;
14738 + AuDebugOn(!hfile->hf_file);
14739 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14740 + AuDebugOn(bindex < 0);
14741 + if (bindex != finfo->fi_btop)
14742 + au_set_fbtop(file, bindex);
14744 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14745 + if (unlikely(err))
14747 + au_do_refresh_dir(file);
14752 + if (!au_test_mmapped(file))
14753 + err = au_file_refresh_by_inode(file, &need_reopen);
14754 + if (finfo->fi_hdir)
14755 + /* harmless if err */
14756 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14757 + if (!err && need_reopen && !d_unlinked(dentry))
14758 + err = reopen(file);
14760 + au_update_figen(file);
14761 + goto out; /* success */
14764 + /* error, close all lower files */
14765 + if (finfo->fi_hdir) {
14766 + bbot = au_fbbot_dir(file);
14767 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14768 + au_set_h_fptr(file, bindex, NULL);
14775 +/* common function to regular file and dir */
14776 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14777 + int wlock, unsigned int fi_lsc)
14780 + unsigned int sigen, figen;
14781 + aufs_bindex_t btop;
14782 + unsigned char pseudo_link;
14783 + struct dentry *dentry;
14784 + struct inode *inode;
14787 + dentry = file->f_path.dentry;
14788 + inode = d_inode(dentry);
14789 + sigen = au_sigen(dentry->d_sb);
14790 + fi_write_lock_nested(file, fi_lsc);
14791 + figen = au_figen(file);
14793 + di_write_lock_child(dentry);
14795 + di_write_lock_child2(dentry);
14796 + btop = au_dbtop(dentry);
14797 + pseudo_link = (btop != au_ibtop(inode));
14798 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14800 + di_downgrade_lock(dentry, AuLock_IR);
14801 + fi_downgrade_lock(file);
14803 + goto out; /* success */
14806 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14807 + if (au_digen_test(dentry, sigen)) {
14808 + err = au_reval_dpath(dentry, sigen);
14809 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14813 + err = refresh_file(file, reopen);
14816 + di_downgrade_lock(dentry, AuLock_IR);
14817 + fi_downgrade_lock(file);
14820 + di_write_unlock(dentry);
14821 + fi_write_unlock(file);
14828 +/* ---------------------------------------------------------------------- */
14830 +/* cf. aufs_nopage() */
14831 +/* for madvise(2) */
14832 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14834 + unlock_page(page);
14838 +/* it will never be called, but necessary to support O_DIRECT */
14839 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14840 +{ BUG(); return 0; }
14842 +/* they will never be called. */
14843 +#ifdef CONFIG_AUFS_DEBUG
14844 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14845 + loff_t pos, unsigned len, unsigned flags,
14846 + struct page **pagep, void **fsdata)
14847 +{ AuUnsupport(); return 0; }
14848 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14849 + loff_t pos, unsigned len, unsigned copied,
14850 + struct page *page, void *fsdata)
14851 +{ AuUnsupport(); return 0; }
14852 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14853 +{ AuUnsupport(); return 0; }
14855 +static int aufs_set_page_dirty(struct page *page)
14856 +{ AuUnsupport(); return 0; }
14857 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14858 + unsigned int length)
14859 +{ AuUnsupport(); }
14860 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14861 +{ AuUnsupport(); return 0; }
14862 +#if 0 /* called by memory compaction regardless file */
14863 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14864 + struct page *page, enum migrate_mode mode)
14865 +{ AuUnsupport(); return 0; }
14867 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14868 +{ AuUnsupport(); return true; }
14869 +static void aufs_putback_page(struct page *page)
14870 +{ AuUnsupport(); }
14871 +static int aufs_launder_page(struct page *page)
14872 +{ AuUnsupport(); return 0; }
14873 +static int aufs_is_partially_uptodate(struct page *page,
14874 + unsigned long from,
14875 + unsigned long count)
14876 +{ AuUnsupport(); return 0; }
14877 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14879 +{ AuUnsupport(); }
14880 +static int aufs_error_remove_page(struct address_space *mapping,
14881 + struct page *page)
14882 +{ AuUnsupport(); return 0; }
14883 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14885 +{ AuUnsupport(); return 0; }
14886 +static void aufs_swap_deactivate(struct file *file)
14887 +{ AuUnsupport(); }
14888 +#endif /* CONFIG_AUFS_DEBUG */
14890 +const struct address_space_operations aufs_aop = {
14891 + .readpage = aufs_readpage,
14892 + .direct_IO = aufs_direct_IO,
14893 +#ifdef CONFIG_AUFS_DEBUG
14894 + .writepage = aufs_writepage,
14895 + /* no writepages, because of writepage */
14896 + .set_page_dirty = aufs_set_page_dirty,
14897 + /* no readpages, because of readpage */
14898 + .write_begin = aufs_write_begin,
14899 + .write_end = aufs_write_end,
14900 + /* no bmap, no block device */
14901 + .invalidatepage = aufs_invalidatepage,
14902 + .releasepage = aufs_releasepage,
14903 + /* is fallback_migrate_page ok? */
14904 + /* .migratepage = aufs_migratepage, */
14905 + .isolate_page = aufs_isolate_page,
14906 + .putback_page = aufs_putback_page,
14907 + .launder_page = aufs_launder_page,
14908 + .is_partially_uptodate = aufs_is_partially_uptodate,
14909 + .is_dirty_writeback = aufs_is_dirty_writeback,
14910 + .error_remove_page = aufs_error_remove_page,
14911 + .swap_activate = aufs_swap_activate,
14912 + .swap_deactivate = aufs_swap_deactivate
14913 +#endif /* CONFIG_AUFS_DEBUG */
14915 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14916 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14917 +++ linux/fs/aufs/file.h 2021-11-01 23:48:34.206359262 +0100
14919 +/* SPDX-License-Identifier: GPL-2.0 */
14921 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14923 + * This program, aufs is free software; you can redistribute it and/or modify
14924 + * it under the terms of the GNU General Public License as published by
14925 + * the Free Software Foundation; either version 2 of the License, or
14926 + * (at your option) any later version.
14928 + * This program is distributed in the hope that it will be useful,
14929 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14930 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14931 + * GNU General Public License for more details.
14933 + * You should have received a copy of the GNU General Public License
14934 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14938 + * file operations
14941 +#ifndef __AUFS_FILE_H__
14942 +#define __AUFS_FILE_H__
14946 +#include <linux/file.h>
14947 +#include <linux/fs.h>
14948 +#include <linux/mm_types.h>
14949 +#include <linux/poll.h>
14950 +#include "rwsem.h"
14954 + struct file *hf_file;
14955 + struct au_branch *hf_br;
14960 + aufs_bindex_t fd_bbot;
14961 + aufs_bindex_t fd_nent;
14962 + struct au_vdir *fd_vdir_cache;
14963 + struct au_hfile fd_hfile[];
14966 +static inline int au_fidir_sz(int nent)
14968 + AuDebugOn(nent < 0);
14969 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14973 + atomic_t fi_generation;
14975 + struct au_rwsem fi_rwsem;
14976 + aufs_bindex_t fi_btop;
14978 + /* do not union them */
14979 + struct { /* for non-dir */
14980 + struct au_hfile fi_htop;
14981 + atomic_t fi_mmapped;
14983 + struct au_fidir *fi_hdir; /* for dir only */
14985 + struct hlist_bl_node fi_hlist;
14986 + struct file *fi_file; /* very ugly */
14987 + struct rcu_head rcu;
14988 +} ____cacheline_aligned_in_smp;
14990 +/* ---------------------------------------------------------------------- */
14993 +extern const struct address_space_operations aufs_aop;
14994 +unsigned int au_file_roflags(unsigned int flags);
14995 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14996 + struct file *file, int force_wr);
14997 +struct au_do_open_args {
14999 + int (*open)(struct file *file, int flags,
15000 + struct file *h_file);
15001 + struct au_fidir *fidir;
15002 + struct file *h_file;
15004 +int au_do_open(struct file *file, struct au_do_open_args *args);
15005 +int au_reopen_nondir(struct file *file);
15007 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15008 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15009 + int wlock, unsigned int fi_lsc);
15010 +int au_do_flush(struct file *file, fl_owner_t id,
15011 + int (*flush)(struct file *file, fl_owner_t id));
15014 +#ifdef CONFIG_AUFS_POLL
15015 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15018 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15020 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15022 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15023 + struct file *h_file);
15025 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15026 + aufs_bindex_t bindex, int force_wr)
15027 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15028 + struct file *h_file);
15032 +extern const struct file_operations aufs_file_fop;
15033 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15034 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15035 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15038 +void au_hfput(struct au_hfile *hf, int execed);
15039 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15040 + struct file *h_file);
15042 +void au_update_figen(struct file *file);
15043 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15044 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15046 +void au_fi_init_once(void *_fi);
15047 +void au_finfo_fin(struct file *file);
15048 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15051 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15052 +#ifdef CONFIG_COMPAT
15053 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15054 + unsigned long arg);
15055 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15056 + unsigned long arg);
15059 +/* ---------------------------------------------------------------------- */
15061 +static inline struct au_finfo *au_fi(struct file *file)
15063 + return file->private_data;
15066 +/* ---------------------------------------------------------------------- */
15068 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15069 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15070 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15071 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15073 +#define fi_read_trylock_nested(f) \
15074 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15075 +#define fi_write_trylock_nested(f) \
15076 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15079 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15080 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15081 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15083 +/* lock subclass for finfo */
15089 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15091 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15094 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15096 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15100 + * fi_read_lock_1, fi_write_lock_1,
15101 + * fi_read_lock_2, fi_write_lock_2
15103 +#define AuReadLockFunc(name) \
15104 +static inline void fi_read_lock_##name(struct file *f) \
15105 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15107 +#define AuWriteLockFunc(name) \
15108 +static inline void fi_write_lock_##name(struct file *f) \
15109 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15111 +#define AuRWLockFuncs(name) \
15112 + AuReadLockFunc(name) \
15113 + AuWriteLockFunc(name)
15118 +#undef AuReadLockFunc
15119 +#undef AuWriteLockFunc
15120 +#undef AuRWLockFuncs
15122 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15123 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15124 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15126 +/* ---------------------------------------------------------------------- */
15128 +/* todo: hard/soft set? */
15129 +static inline aufs_bindex_t au_fbtop(struct file *file)
15131 + FiMustAnyLock(file);
15132 + return au_fi(file)->fi_btop;
15135 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15137 + FiMustAnyLock(file);
15138 + AuDebugOn(!au_fi(file)->fi_hdir);
15139 + return au_fi(file)->fi_hdir->fd_bbot;
15142 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15144 + FiMustAnyLock(file);
15145 + AuDebugOn(!au_fi(file)->fi_hdir);
15146 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15149 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15151 + FiMustWriteLock(file);
15152 + au_fi(file)->fi_btop = bindex;
15155 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15157 + FiMustWriteLock(file);
15158 + AuDebugOn(!au_fi(file)->fi_hdir);
15159 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15162 +static inline void au_set_fvdir_cache(struct file *file,
15163 + struct au_vdir *vdir_cache)
15165 + FiMustWriteLock(file);
15166 + AuDebugOn(!au_fi(file)->fi_hdir);
15167 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15170 +static inline struct file *au_hf_top(struct file *file)
15172 + FiMustAnyLock(file);
15173 + AuDebugOn(au_fi(file)->fi_hdir);
15174 + return au_fi(file)->fi_htop.hf_file;
15177 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15179 + FiMustAnyLock(file);
15180 + AuDebugOn(!au_fi(file)->fi_hdir);
15181 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15184 +/* todo: memory barrier? */
15185 +static inline unsigned int au_figen(struct file *f)
15187 + return atomic_read(&au_fi(f)->fi_generation);
15190 +static inline void au_set_mmapped(struct file *f)
15192 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15194 + pr_warn("fi_mmapped wrapped around\n");
15195 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15199 +static inline void au_unset_mmapped(struct file *f)
15201 + atomic_dec(&au_fi(f)->fi_mmapped);
15204 +static inline int au_test_mmapped(struct file *f)
15206 + return atomic_read(&au_fi(f)->fi_mmapped);
15209 +/* customize vma->vm_file */
15211 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15212 + struct file *file)
15216 + f = vma->vm_file;
15218 + vma->vm_file = file;
15223 +#define AuDbgVmRegion(file, vma) do {} while (0)
15225 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15226 + struct file *file)
15228 + au_do_vm_file_reset(vma, file);
15231 +#define AuDbgVmRegion(file, vma) \
15232 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15234 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15235 + struct file *file)
15239 + au_do_vm_file_reset(vma, file);
15240 + f = vma->vm_region->vm_file;
15242 + vma->vm_region->vm_file = file;
15245 +#endif /* CONFIG_MMU */
15247 +/* handle vma->vm_prfile */
15248 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15249 + struct file *file)
15252 + vma->vm_prfile = file;
15253 +#ifndef CONFIG_MMU
15255 + vma->vm_region->vm_prfile = file;
15259 +#endif /* __KERNEL__ */
15260 +#endif /* __AUFS_FILE_H__ */
15261 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15262 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15263 +++ linux/fs/aufs/finfo.c 2021-11-01 23:48:34.206359262 +0100
15265 +// SPDX-License-Identifier: GPL-2.0
15267 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15269 + * This program, aufs is free software; you can redistribute it and/or modify
15270 + * it under the terms of the GNU General Public License as published by
15271 + * the Free Software Foundation; either version 2 of the License, or
15272 + * (at your option) any later version.
15274 + * This program is distributed in the hope that it will be useful,
15275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15277 + * GNU General Public License for more details.
15279 + * You should have received a copy of the GNU General Public License
15280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15284 + * file private data
15289 +void au_hfput(struct au_hfile *hf, int execed)
15292 + allow_write_access(hf->hf_file);
15293 + fput(hf->hf_file);
15294 + hf->hf_file = NULL;
15295 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15296 + hf->hf_br = NULL;
15299 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15301 + struct au_finfo *finfo = au_fi(file);
15302 + struct au_hfile *hf;
15303 + struct au_fidir *fidir;
15305 + fidir = finfo->fi_hdir;
15307 + AuDebugOn(finfo->fi_btop != bindex);
15308 + hf = &finfo->fi_htop;
15310 + hf = fidir->fd_hfile + bindex;
15312 + if (hf && hf->hf_file)
15313 + au_hfput(hf, vfsub_file_execed(file));
15315 + FiMustWriteLock(file);
15316 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15317 + hf->hf_file = val;
15318 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15322 +void au_update_figen(struct file *file)
15324 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15325 + /* smp_mb(); */ /* atomic_set */
15328 +/* ---------------------------------------------------------------------- */
15330 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15332 + struct au_fidir *fidir;
15335 + nbr = au_sbbot(sb) + 1;
15337 + nbr = 2; /* initial allocate for 2 branches */
15338 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15340 + fidir->fd_bbot = -1;
15341 + fidir->fd_nent = nbr;
15347 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15350 + struct au_fidir *fidir, *p;
15352 + AuRwMustWriteLock(&finfo->fi_rwsem);
15353 + fidir = finfo->fi_hdir;
15354 + AuDebugOn(!fidir);
15357 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15358 + GFP_NOFS, may_shrink);
15360 + p->fd_nent = nbr;
15361 + finfo->fi_hdir = p;
15368 +/* ---------------------------------------------------------------------- */
15370 +void au_finfo_fin(struct file *file)
15372 + struct au_finfo *finfo;
15374 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15376 + finfo = au_fi(file);
15377 + AuDebugOn(finfo->fi_hdir);
15378 + AuRwDestroy(&finfo->fi_rwsem);
15379 + au_cache_free_finfo(finfo);
15382 +void au_fi_init_once(void *_finfo)
15384 + struct au_finfo *finfo = _finfo;
15386 + au_rw_init(&finfo->fi_rwsem);
15389 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15392 + struct au_finfo *finfo;
15393 + struct dentry *dentry;
15396 + dentry = file->f_path.dentry;
15397 + finfo = au_cache_alloc_finfo();
15398 + if (unlikely(!finfo))
15402 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15403 + au_rw_write_lock(&finfo->fi_rwsem);
15404 + finfo->fi_btop = -1;
15405 + finfo->fi_hdir = fidir;
15406 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15407 + /* smp_mb(); */ /* atomic_set */
15409 + file->private_data = finfo;
15414 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15415 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15416 +++ linux/fs/aufs/f_op.c 2021-11-01 23:48:34.206359262 +0100
15418 +// SPDX-License-Identifier: GPL-2.0
15420 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15422 + * This program, aufs is free software; you can redistribute it and/or modify
15423 + * it under the terms of the GNU General Public License as published by
15424 + * the Free Software Foundation; either version 2 of the License, or
15425 + * (at your option) any later version.
15427 + * This program is distributed in the hope that it will be useful,
15428 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15429 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15430 + * GNU General Public License for more details.
15432 + * You should have received a copy of the GNU General Public License
15433 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15437 + * file and vm operations
15440 +#include <linux/aio.h>
15441 +#include <linux/fs_stack.h>
15442 +#include <linux/mman.h>
15443 +#include <linux/security.h>
15446 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15449 + aufs_bindex_t bindex;
15450 + struct dentry *dentry, *h_dentry;
15451 + struct au_finfo *finfo;
15452 + struct inode *h_inode;
15454 + FiMustWriteLock(file);
15457 + dentry = file->f_path.dentry;
15458 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15459 + finfo = au_fi(file);
15460 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15461 + atomic_set(&finfo->fi_mmapped, 0);
15462 + bindex = au_dbtop(dentry);
15464 + h_dentry = au_h_dptr(dentry, bindex);
15465 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15466 + if (unlikely(err))
15468 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15469 + if (IS_ERR(h_file)) {
15470 + err = PTR_ERR(h_file);
15474 + h_dentry = h_file->f_path.dentry;
15475 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15476 + if (unlikely(err))
15478 + /* br ref is already inc-ed */
15481 + if ((flags & __O_TMPFILE)
15482 + && !(flags & O_EXCL)) {
15483 + h_inode = file_inode(h_file);
15484 + spin_lock(&h_inode->i_lock);
15485 + h_inode->i_state |= I_LINKABLE;
15486 + spin_unlock(&h_inode->i_lock);
15488 + au_set_fbtop(file, bindex);
15489 + au_set_h_fptr(file, bindex, h_file);
15490 + au_update_figen(file);
15491 + /* todo: necessary? */
15492 + /* file->f_ra = h_file->f_ra; */
15498 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15499 + struct file *file)
15502 + struct super_block *sb;
15503 + struct au_do_open_args args = {
15504 + .open = au_do_open_nondir
15507 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15508 + file, vfsub_file_flags(file), file->f_mode);
15510 + sb = file->f_path.dentry->d_sb;
15511 + si_read_lock(sb, AuLock_FLUSH);
15512 + err = au_do_open(file, &args);
15513 + si_read_unlock(sb);
15517 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15519 + struct au_finfo *finfo;
15520 + aufs_bindex_t bindex;
15522 + finfo = au_fi(file);
15523 + au_hbl_del(&finfo->fi_hlist,
15524 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15525 + bindex = finfo->fi_btop;
15527 + au_set_h_fptr(file, bindex, NULL);
15529 + au_finfo_fin(file);
15533 +/* ---------------------------------------------------------------------- */
15535 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15538 + struct file *h_file;
15541 + h_file = au_hf_top(file);
15543 + err = vfsub_flush(h_file, id);
15547 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15549 + return au_do_flush(file, id, au_do_flush_nondir);
15552 +/* ---------------------------------------------------------------------- */
15554 + * read and write functions acquire [fdi]_rwsem once, but release before
15555 + * mmap_sem. This is because to stop a race condition between mmap(2).
15556 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15557 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15558 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15561 +/* Callers should call au_read_post() or fput() in the end */
15562 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15564 + struct file *h_file;
15567 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15569 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15570 + h_file = au_hf_top(file);
15571 + get_file(h_file);
15573 + fi_read_unlock(file);
15575 + h_file = ERR_PTR(err);
15580 +static void au_read_post(struct inode *inode, struct file *h_file)
15582 + /* update without lock, I don't think it a problem */
15583 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15587 +struct au_write_pre {
15589 + unsigned int lsc;
15593 + aufs_bindex_t btop;
15597 + * return with iinfo is write-locked
15598 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15601 +static struct file *au_write_pre(struct file *file, int do_ready,
15602 + struct au_write_pre *wpre)
15604 + struct file *h_file;
15605 + struct dentry *dentry;
15607 + unsigned int lsc;
15608 + struct au_pin pin;
15613 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15614 + h_file = ERR_PTR(err);
15615 + if (unlikely(err))
15618 + dentry = file->f_path.dentry;
15620 + err = au_ready_to_write(file, -1, &pin);
15621 + if (unlikely(err)) {
15622 + h_file = ERR_PTR(err);
15623 + di_write_unlock(dentry);
15628 + di_downgrade_lock(dentry, /*flags*/0);
15630 + wpre->btop = au_fbtop(file);
15631 + h_file = au_hf_top(file);
15632 + get_file(h_file);
15634 + wpre->blks = file_inode(h_file)->i_blocks;
15637 + di_read_unlock(dentry, /*flags*/0);
15640 + fi_write_unlock(file);
15645 +static void au_write_post(struct inode *inode, struct file *h_file,
15646 + struct au_write_pre *wpre, ssize_t written)
15648 + struct inode *h_inode;
15650 + au_cpup_attr_timesizes(inode);
15651 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15652 + h_inode = file_inode(h_file);
15653 + inode->i_mode = h_inode->i_mode;
15654 + ii_write_unlock(inode);
15655 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15657 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15658 + /*force*/h_inode->i_blocks > wpre->blks);
15663 + * todo: very ugly
15664 + * it locks both of i_mutex and si_rwsem for read in safe.
15665 + * if the plink maintenance mode continues forever (that is the problem),
15666 + * may loop forever.
15668 +static void au_mtx_and_read_lock(struct inode *inode)
15671 + struct super_block *sb = inode->i_sb;
15674 + inode_lock(inode);
15675 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15678 + inode_unlock(inode);
15679 + si_read_lock(sb, AuLock_NOPLMW);
15680 + si_read_unlock(sb);
15684 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15685 + struct iov_iter *iov_iter)
15688 + struct file *file;
15689 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15691 + err = security_file_permission(h_file, rw);
15692 + if (unlikely(err))
15695 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15697 + if (rw == MAY_READ)
15698 + iter = h_file->f_op->read_iter;
15699 + else if (rw == MAY_WRITE)
15700 + iter = h_file->f_op->write_iter;
15702 + file = kio->ki_filp;
15703 + kio->ki_filp = h_file;
15706 + err = iter(kio, iov_iter);
15709 + /* currently there is no such fs */
15711 + kio->ki_filp = file;
15717 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15720 + struct file *file, *h_file;
15721 + struct inode *inode;
15722 + struct super_block *sb;
15724 + file = kio->ki_filp;
15725 + inode = file_inode(file);
15726 + sb = inode->i_sb;
15727 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15729 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15730 + err = PTR_ERR(h_file);
15731 + if (IS_ERR(h_file))
15734 + if (au_test_loopback_kthread()) {
15735 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15736 + if (file->f_mapping != h_file->f_mapping) {
15737 + file->f_mapping = h_file->f_mapping;
15738 + smp_mb(); /* unnecessary? */
15741 + fi_read_unlock(file);
15743 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15744 + /* todo: necessary? */
15745 + /* file->f_ra = h_file->f_ra; */
15746 + au_read_post(inode, h_file);
15749 + si_read_unlock(sb);
15753 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15756 + struct au_write_pre wpre;
15757 + struct inode *inode;
15758 + struct file *file, *h_file;
15760 + file = kio->ki_filp;
15761 + inode = file_inode(file);
15762 + au_mtx_and_read_lock(inode);
15765 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15766 + err = PTR_ERR(h_file);
15767 + if (IS_ERR(h_file))
15770 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15771 + au_write_post(inode, h_file, &wpre, err);
15774 + si_read_unlock(inode->i_sb);
15775 + inode_unlock(inode);
15780 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15781 + * don't have their own .splice_{read,write} implimentations, and they use
15782 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15783 + * simple converters to f_op->iter_read() and ->iter_write().
15784 + * But we keep our own implementations because some non-mainlined FSes may have
15785 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15786 + * away an opportunity to co-work with aufs from them.
15788 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15789 + struct pipe_inode_info *pipe, size_t len,
15790 + unsigned int flags)
15793 + struct file *h_file;
15794 + struct inode *inode;
15795 + struct super_block *sb;
15797 + inode = file_inode(file);
15798 + sb = inode->i_sb;
15799 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15801 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15802 + err = PTR_ERR(h_file);
15803 + if (IS_ERR(h_file))
15806 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15807 + /* todo: necessary? */
15808 + /* file->f_ra = h_file->f_ra; */
15809 + au_read_post(inode, h_file);
15812 + si_read_unlock(sb);
15817 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15818 + size_t len, unsigned int flags)
15821 + struct au_write_pre wpre;
15822 + struct inode *inode;
15823 + struct file *h_file;
15825 + inode = file_inode(file);
15826 + au_mtx_and_read_lock(inode);
15829 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15830 + err = PTR_ERR(h_file);
15831 + if (IS_ERR(h_file))
15834 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15835 + au_write_post(inode, h_file, &wpre, err);
15838 + si_read_unlock(inode->i_sb);
15839 + inode_unlock(inode);
15843 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
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))
15861 + err = vfs_fallocate(h_file, mode, offset, len);
15863 + au_write_post(inode, h_file, &wpre, /*written*/1);
15866 + si_read_unlock(inode->i_sb);
15867 + inode_unlock(inode);
15871 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15872 + struct file *dst, loff_t dst_pos,
15873 + size_t len, unsigned int flags)
15876 + struct au_write_pre wpre;
15877 + enum { SRC, DST };
15879 + struct inode *inode;
15880 + struct file *h_file;
15881 + struct super_block *h_sb;
15883 +#define a_src a[SRC]
15884 +#define a_dst a[DST]
15887 + a_src.inode = file_inode(src);
15888 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15890 + a_dst.inode = file_inode(dst);
15891 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15894 + au_mtx_and_read_lock(a_dst.inode);
15896 + * in order to match the order in di_write_lock2_{child,parent}(),
15897 + * use f_path.dentry for this comparison.
15899 + if (src->f_path.dentry < dst->f_path.dentry) {
15900 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15901 + err = PTR_ERR(a_src.h_file);
15902 + if (IS_ERR(a_src.h_file))
15905 + wpre.lsc = AuLsc_FI_2;
15906 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15907 + err = PTR_ERR(a_dst.h_file);
15908 + if (IS_ERR(a_dst.h_file)) {
15909 + au_read_post(a_src.inode, a_src.h_file);
15913 + wpre.lsc = AuLsc_FI_1;
15914 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15915 + err = PTR_ERR(a_dst.h_file);
15916 + if (IS_ERR(a_dst.h_file))
15919 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15920 + err = PTR_ERR(a_src.h_file);
15921 + if (IS_ERR(a_src.h_file)) {
15922 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15929 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15930 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15931 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15937 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15938 + dst_pos, len, flags);
15941 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15942 + fi_read_unlock(src);
15943 + au_read_post(a_src.inode, a_src.h_file);
15945 + si_read_unlock(a_dst.inode->i_sb);
15946 + inode_unlock(a_dst.inode);
15953 +/* ---------------------------------------------------------------------- */
15956 + * The locking order around current->mmap_sem.
15957 + * - in most and regular cases
15958 + * file I/O syscall -- aufs_read() or something
15959 + * -- si_rwsem for read -- mmap_sem
15960 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15962 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15963 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15964 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15965 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15966 + * It means that when aufs acquires si_rwsem for write, the process should never
15967 + * acquire mmap_sem.
15969 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15970 + * problem either since any directory is not able to be mmap-ed.
15971 + * The similar scenario is applied to aufs_readlink() too.
15974 +#if 0 /* stop calling security_file_mmap() */
15975 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15976 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15978 +static unsigned long au_arch_prot_conv(unsigned long flags)
15980 + /* currently ppc64 only */
15981 +#ifdef CONFIG_PPC64
15982 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15983 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15984 + return AuConv_VM_PROT(flags, SAO);
15986 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15991 +static unsigned long au_prot_conv(unsigned long flags)
15993 + return AuConv_VM_PROT(flags, READ)
15994 + | AuConv_VM_PROT(flags, WRITE)
15995 + | AuConv_VM_PROT(flags, EXEC)
15996 + | au_arch_prot_conv(flags);
15999 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16000 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16002 +static unsigned long au_flag_conv(unsigned long flags)
16004 + return AuConv_VM_MAP(flags, GROWSDOWN)
16005 + | AuConv_VM_MAP(flags, DENYWRITE)
16006 + | AuConv_VM_MAP(flags, LOCKED);
16010 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16013 + const unsigned char wlock
16014 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16015 + struct super_block *sb;
16016 + struct file *h_file;
16017 + struct inode *inode;
16019 + AuDbgVmRegion(file, vma);
16021 + inode = file_inode(file);
16022 + sb = inode->i_sb;
16024 + si_read_lock(sb, AuLock_NOPLMW);
16026 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16028 + err = PTR_ERR(h_file);
16029 + if (IS_ERR(h_file))
16033 + au_set_mmapped(file);
16034 + au_vm_file_reset(vma, h_file);
16036 + * we cannot call security_mmap_file() here since it may acquire
16037 + * mmap_sem or i_mutex.
16039 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16040 + * au_flag_conv(vma->vm_flags));
16043 + err = call_mmap(h_file, vma);
16045 + au_vm_prfile_set(vma, file);
16046 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16047 + goto out_fput; /* success */
16049 + au_unset_mmapped(file);
16050 + au_vm_file_reset(vma, file);
16054 + ii_write_unlock(inode);
16059 + si_read_unlock(sb);
16065 +/* ---------------------------------------------------------------------- */
16067 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16071 + struct au_write_pre wpre;
16072 + struct inode *inode;
16073 + struct file *h_file;
16075 + err = 0; /* -EBADF; */ /* posix? */
16076 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16079 + inode = file_inode(file);
16080 + au_mtx_and_read_lock(inode);
16083 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16084 + err = PTR_ERR(h_file);
16085 + if (IS_ERR(h_file))
16088 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16089 + au_write_post(inode, h_file, &wpre, /*written*/0);
16092 + si_read_unlock(inode->i_sb);
16093 + inode_unlock(inode);
16098 +static int aufs_fasync(int fd, struct file *file, int flag)
16101 + struct file *h_file;
16102 + struct super_block *sb;
16104 + sb = file->f_path.dentry->d_sb;
16105 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16107 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16108 + err = PTR_ERR(h_file);
16109 + if (IS_ERR(h_file))
16112 + if (h_file->f_op->fasync)
16113 + err = h_file->f_op->fasync(fd, h_file, flag);
16114 + fput(h_file); /* instead of au_read_post() */
16117 + si_read_unlock(sb);
16121 +static int aufs_setfl(struct file *file, unsigned long arg)
16124 + struct file *h_file;
16125 + struct super_block *sb;
16127 + sb = file->f_path.dentry->d_sb;
16128 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16130 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16131 + err = PTR_ERR(h_file);
16132 + if (IS_ERR(h_file))
16135 + /* stop calling h_file->fasync */
16136 + arg |= vfsub_file_flags(file) & FASYNC;
16137 + err = setfl(/*unused fd*/-1, h_file, arg);
16138 + fput(h_file); /* instead of au_read_post() */
16141 + si_read_unlock(sb);
16145 +/* ---------------------------------------------------------------------- */
16147 +/* no one supports this operation, currently */
16148 +#if 0 /* reserved for future use */
16149 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16150 + size_t len, loff_t *pos, int more)
16155 +/* ---------------------------------------------------------------------- */
16157 +const struct file_operations aufs_file_fop = {
16158 + .owner = THIS_MODULE,
16160 + .llseek = default_llseek,
16162 + .read_iter = aufs_read_iter,
16163 + .write_iter = aufs_write_iter,
16165 +#ifdef CONFIG_AUFS_POLL
16166 + .poll = aufs_poll,
16168 + .unlocked_ioctl = aufs_ioctl_nondir,
16169 +#ifdef CONFIG_COMPAT
16170 + .compat_ioctl = aufs_compat_ioctl_nondir,
16172 + .mmap = aufs_mmap,
16173 + .open = aufs_open_nondir,
16174 + .flush = aufs_flush_nondir,
16175 + .release = aufs_release_nondir,
16176 + .fsync = aufs_fsync_nondir,
16177 + .fasync = aufs_fasync,
16178 + /* .sendpage = aufs_sendpage, */
16179 + .setfl = aufs_setfl,
16180 + .splice_write = aufs_splice_write,
16181 + .splice_read = aufs_splice_read,
16182 +#if 0 /* reserved for future use */
16183 + .aio_splice_write = aufs_aio_splice_write,
16184 + .aio_splice_read = aufs_aio_splice_read,
16186 + .fallocate = aufs_fallocate,
16187 + .copy_file_range = aufs_copy_file_range
16189 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16190 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16191 +++ linux/fs/aufs/fstype.h 2021-11-01 23:48:34.206359262 +0100
16193 +/* SPDX-License-Identifier: GPL-2.0 */
16195 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16197 + * This program, aufs is free software; you can redistribute it and/or modify
16198 + * it under the terms of the GNU General Public License as published by
16199 + * the Free Software Foundation; either version 2 of the License, or
16200 + * (at your option) any later version.
16202 + * This program is distributed in the hope that it will be useful,
16203 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16204 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16205 + * GNU General Public License for more details.
16207 + * You should have received a copy of the GNU General Public License
16208 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16212 + * judging filesystem type
16215 +#ifndef __AUFS_FSTYPE_H__
16216 +#define __AUFS_FSTYPE_H__
16220 +#include <linux/fs.h>
16221 +#include <linux/magic.h>
16222 +#include <linux/nfs_fs.h>
16223 +#include <linux/romfs_fs.h>
16225 +static inline int au_test_aufs(struct super_block *sb)
16227 + return sb->s_magic == AUFS_SUPER_MAGIC;
16230 +static inline const char *au_sbtype(struct super_block *sb)
16232 + return sb->s_type->name;
16235 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16237 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16238 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16244 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16246 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16247 + return sb->s_magic == ROMFS_MAGIC;
16253 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16255 +#if IS_ENABLED(CONFIG_CRAMFS)
16256 + return sb->s_magic == CRAMFS_MAGIC;
16261 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16263 +#if IS_ENABLED(CONFIG_NFS_FS)
16264 + return sb->s_magic == NFS_SUPER_MAGIC;
16270 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16272 +#if IS_ENABLED(CONFIG_FUSE_FS)
16273 + return sb->s_magic == FUSE_SUPER_MAGIC;
16279 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16281 +#if IS_ENABLED(CONFIG_XFS_FS)
16282 + return sb->s_magic == XFS_SB_MAGIC;
16288 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16290 +#ifdef CONFIG_TMPFS
16291 + return sb->s_magic == TMPFS_MAGIC;
16297 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16299 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16300 + return !strcmp(au_sbtype(sb), "ecryptfs");
16306 +static inline int au_test_ramfs(struct super_block *sb)
16308 + return sb->s_magic == RAMFS_MAGIC;
16311 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16313 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16314 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16320 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16322 +#ifdef CONFIG_PROC_FS
16323 + return sb->s_magic == PROC_SUPER_MAGIC;
16329 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16331 +#ifdef CONFIG_SYSFS
16332 + return sb->s_magic == SYSFS_MAGIC;
16338 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16340 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16341 + return sb->s_magic == CONFIGFS_MAGIC;
16347 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16349 +#if IS_ENABLED(CONFIG_MINIX_FS)
16350 + return sb->s_magic == MINIX3_SUPER_MAGIC
16351 + || sb->s_magic == MINIX2_SUPER_MAGIC
16352 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16353 + || sb->s_magic == MINIX_SUPER_MAGIC
16354 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16360 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16362 +#if IS_ENABLED(CONFIG_FAT_FS)
16363 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16369 +static inline int au_test_msdos(struct super_block *sb)
16371 + return au_test_fat(sb);
16374 +static inline int au_test_vfat(struct super_block *sb)
16376 + return au_test_fat(sb);
16379 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16381 +#ifdef CONFIG_SECURITYFS
16382 + return sb->s_magic == SECURITYFS_MAGIC;
16388 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16390 +#if IS_ENABLED(CONFIG_SQUASHFS)
16391 + return sb->s_magic == SQUASHFS_MAGIC;
16397 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16399 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16400 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16406 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16408 +#if IS_ENABLED(CONFIG_XENFS)
16409 + return sb->s_magic == XENFS_SUPER_MAGIC;
16415 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16417 +#ifdef CONFIG_DEBUG_FS
16418 + return sb->s_magic == DEBUGFS_MAGIC;
16424 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16426 +#if IS_ENABLED(CONFIG_NILFS)
16427 + return sb->s_magic == NILFS_SUPER_MAGIC;
16433 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16435 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16436 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16442 +/* ---------------------------------------------------------------------- */
16444 + * they can't be an aufs branch.
16446 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16449 +#ifndef CONFIG_AUFS_BR_RAMFS
16450 + au_test_ramfs(sb) ||
16452 + au_test_procfs(sb)
16453 + || au_test_sysfs(sb)
16454 + || au_test_configfs(sb)
16455 + || au_test_debugfs(sb)
16456 + || au_test_securityfs(sb)
16457 + || au_test_xenfs(sb)
16458 + || au_test_ecryptfs(sb)
16459 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16460 + || au_test_aufs(sb); /* will be supported in next version */
16463 +static inline int au_test_fs_remote(struct super_block *sb)
16465 + return !au_test_tmpfs(sb)
16466 +#ifdef CONFIG_AUFS_BR_RAMFS
16467 + && !au_test_ramfs(sb)
16469 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16472 +/* ---------------------------------------------------------------------- */
16475 + * Note: these functions (below) are created after reading ->getattr() in all
16476 + * filesystems under linux/fs. it means we have to do so in every update...
16480 + * some filesystems require getattr to refresh the inode attributes before
16482 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16483 + * and leave the work for d_revalidate()
16485 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16487 + return au_test_nfs(sb)
16488 + || au_test_fuse(sb)
16489 + /* || au_test_btrfs(sb) */ /* untested */
16494 + * filesystems which don't maintain i_size or i_blocks.
16496 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16498 + return au_test_xfs(sb)
16499 + || au_test_btrfs(sb)
16500 + || au_test_ubifs(sb)
16501 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16502 + /* || au_test_minix(sb) */ /* untested */
16507 + * filesystems which don't store the correct value in some of their inode
16510 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16512 + return au_test_fs_bad_iattr_size(sb)
16513 + || au_test_fat(sb)
16514 + || au_test_msdos(sb)
16515 + || au_test_vfat(sb);
16518 +/* they don't check i_nlink in link(2) */
16519 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16521 + return au_test_tmpfs(sb)
16522 +#ifdef CONFIG_AUFS_BR_RAMFS
16523 + || au_test_ramfs(sb)
16525 + || au_test_ubifs(sb)
16526 + || au_test_hfsplus(sb);
16530 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16532 +static inline int au_test_fs_notime(struct super_block *sb)
16534 + return au_test_nfs(sb)
16535 + || au_test_fuse(sb)
16536 + || au_test_ubifs(sb)
16540 +/* temporary support for i#1 in cramfs */
16541 +static inline int au_test_fs_unique_ino(struct inode *inode)
16543 + if (au_test_cramfs(inode->i_sb))
16544 + return inode->i_ino != 1;
16548 +/* ---------------------------------------------------------------------- */
16551 + * the filesystem where the xino files placed must support i/o after unlink and
16552 + * maintain i_size and i_blocks.
16554 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16556 + return au_test_fs_remote(sb)
16557 + || au_test_fs_bad_iattr_size(sb)
16558 + /* don't want unnecessary work for xino */
16559 + || au_test_aufs(sb)
16560 + || au_test_ecryptfs(sb)
16561 + || au_test_nilfs(sb);
16564 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16566 + return au_test_tmpfs(sb)
16567 + || au_test_ramfs(sb);
16571 + * test if the @sb is real-readonly.
16573 +static inline int au_test_fs_rr(struct super_block *sb)
16575 + return au_test_squashfs(sb)
16576 + || au_test_iso9660(sb)
16577 + || au_test_cramfs(sb)
16578 + || au_test_romfs(sb);
16582 + * test if the @inode is nfs with 'noacl' option
16583 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16585 +static inline int au_test_nfs_noacl(struct inode *inode)
16587 + return au_test_nfs(inode->i_sb)
16588 + /* && IS_POSIXACL(inode) */
16589 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16592 +#endif /* __KERNEL__ */
16593 +#endif /* __AUFS_FSTYPE_H__ */
16594 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16595 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16596 +++ linux/fs/aufs/hbl.h 2021-11-01 23:48:34.206359262 +0100
16598 +/* SPDX-License-Identifier: GPL-2.0 */
16600 + * Copyright (C) 2017-2021 Junjiro R. Okajima
16602 + * This program, aufs is free software; you can redistribute it and/or modify
16603 + * it under the terms of the GNU General Public License as published by
16604 + * the Free Software Foundation; either version 2 of the License, or
16605 + * (at your option) any later version.
16607 + * This program is distributed in the hope that it will be useful,
16608 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16609 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16610 + * GNU General Public License for more details.
16612 + * You should have received a copy of the GNU General Public License
16613 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16617 + * helpers for hlist_bl.h
16620 +#ifndef __AUFS_HBL_H__
16621 +#define __AUFS_HBL_H__
16625 +#include <linux/list_bl.h>
16627 +static inline void au_hbl_add(struct hlist_bl_node *node,
16628 + struct hlist_bl_head *hbl)
16630 + hlist_bl_lock(hbl);
16631 + hlist_bl_add_head(node, hbl);
16632 + hlist_bl_unlock(hbl);
16635 +static inline void au_hbl_del(struct hlist_bl_node *node,
16636 + struct hlist_bl_head *hbl)
16638 + hlist_bl_lock(hbl);
16639 + hlist_bl_del(node);
16640 + hlist_bl_unlock(hbl);
16643 +#define au_hbl_for_each(pos, head) \
16644 + for (pos = hlist_bl_first(head); \
16648 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16650 + unsigned long cnt;
16651 + struct hlist_bl_node *pos;
16654 + hlist_bl_lock(hbl);
16655 + au_hbl_for_each(pos, hbl)
16657 + hlist_bl_unlock(hbl);
16661 +#endif /* __KERNEL__ */
16662 +#endif /* __AUFS_HBL_H__ */
16663 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16664 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16665 +++ linux/fs/aufs/hfsnotify.c 2021-11-25 11:42:28.836641524 +0100
16667 +// SPDX-License-Identifier: GPL-2.0
16669 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16671 + * This program, aufs is free software; you can redistribute it and/or modify
16672 + * it under the terms of the GNU General Public License as published by
16673 + * the Free Software Foundation; either version 2 of the License, or
16674 + * (at your option) any later version.
16676 + * This program is distributed in the hope that it will be useful,
16677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16679 + * GNU General Public License for more details.
16681 + * You should have received a copy of the GNU General Public License
16682 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16686 + * fsnotify for the lower directories
16691 +/* FS_IN_IGNORED is unnecessary */
16692 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16693 + | FS_CREATE | FS_EVENT_ON_CHILD);
16694 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16695 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16697 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16699 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16701 + /* AuDbg("here\n"); */
16702 + au_cache_free_hnotify(hn);
16703 + smp_mb__before_atomic(); /* for atomic64_dec */
16704 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16705 + wake_up(&au_hfsn_wq);
16708 +static int au_hfsn_alloc(struct au_hinode *hinode)
16711 + struct au_hnotify *hn;
16712 + struct super_block *sb;
16713 + struct au_branch *br;
16714 + struct fsnotify_mark *mark;
16715 + aufs_bindex_t bindex;
16717 + hn = hinode->hi_notify;
16718 + sb = hn->hn_aufs_inode->i_sb;
16719 + bindex = au_br_index(sb, hinode->hi_id);
16720 + br = au_sbr(sb, bindex);
16721 + AuDebugOn(!br->br_hfsn);
16723 + mark = &hn->hn_mark;
16724 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16725 + mark->mask = AuHfsnMask;
16727 + * by udba rename or rmdir, aufs assign a new inode to the known
16728 + * h_inode, so specify 1 to allow dups.
16731 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16737 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16739 + struct fsnotify_mark *mark;
16740 + unsigned long long ull;
16741 + struct fsnotify_group *group;
16743 + ull = atomic64_inc_return(&au_hfsn_ifree);
16746 + mark = &hn->hn_mark;
16747 + spin_lock(&mark->lock);
16748 + group = mark->group;
16749 + fsnotify_get_group(group);
16750 + spin_unlock(&mark->lock);
16752 + fsnotify_destroy_mark(mark, group);
16753 + fsnotify_put_mark(mark);
16754 + fsnotify_put_group(group);
16757 + /* free hn by myself */
16761 +/* ---------------------------------------------------------------------- */
16763 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16765 + struct fsnotify_mark *mark;
16767 + mark = &hinode->hi_notify->hn_mark;
16768 + spin_lock(&mark->lock);
16770 + AuDebugOn(mark->mask & AuHfsnMask);
16771 + mark->mask |= AuHfsnMask;
16773 + AuDebugOn(!(mark->mask & AuHfsnMask));
16774 + mark->mask &= ~AuHfsnMask;
16776 + spin_unlock(&mark->lock);
16777 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16780 +/* ---------------------------------------------------------------------- */
16782 +/* #define AuDbgHnotify */
16783 +#ifdef AuDbgHnotify
16784 +static char *au_hfsn_name(u32 mask)
16786 +#ifdef CONFIG_AUFS_DEBUG
16787 +#define test_ret(flag) \
16789 + if (mask & flag) \
16792 + test_ret(FS_ACCESS);
16793 + test_ret(FS_MODIFY);
16794 + test_ret(FS_ATTRIB);
16795 + test_ret(FS_CLOSE_WRITE);
16796 + test_ret(FS_CLOSE_NOWRITE);
16797 + test_ret(FS_OPEN);
16798 + test_ret(FS_MOVED_FROM);
16799 + test_ret(FS_MOVED_TO);
16800 + test_ret(FS_CREATE);
16801 + test_ret(FS_DELETE);
16802 + test_ret(FS_DELETE_SELF);
16803 + test_ret(FS_MOVE_SELF);
16804 + test_ret(FS_UNMOUNT);
16805 + test_ret(FS_Q_OVERFLOW);
16806 + test_ret(FS_IN_IGNORED);
16807 + test_ret(FS_ISDIR);
16808 + test_ret(FS_IN_ONESHOT);
16809 + test_ret(FS_EVENT_ON_CHILD);
16818 +/* ---------------------------------------------------------------------- */
16820 +static void au_hfsn_free_group(struct fsnotify_group *group)
16822 + struct au_br_hfsnotify *hfsn = group->private;
16824 + /* AuDbg("here\n"); */
16825 + au_kfree_try_rcu(hfsn);
16828 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16829 + u32 mask, const void *data, int data_type,
16830 + struct inode *dir,
16831 + const struct qstr *file_name, u32 cookie,
16832 + struct fsnotify_iter_info *iter_info)
16835 + struct au_hnotify *hnotify;
16836 + struct inode *h_dir, *h_inode;
16837 + struct fsnotify_mark *inode_mark;
16839 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16842 + /* if FS_UNMOUNT happens, there must be another bug */
16843 + AuDebugOn(mask & FS_UNMOUNT);
16844 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16849 +#ifdef AuDbgHnotify
16851 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16852 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16853 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16854 + h_dir->i_ino, mask, au_hfsn_name(mask),
16855 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16856 + /* WARN_ON(1); */
16861 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16862 + AuDebugOn(!inode_mark);
16863 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16864 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16870 +static struct fsnotify_ops au_hfsn_ops = {
16871 + .handle_event = au_hfsn_handle_event,
16872 + .free_group_priv = au_hfsn_free_group,
16873 + .free_mark = au_hfsn_free_mark
16876 +/* ---------------------------------------------------------------------- */
16878 +static void au_hfsn_fin_br(struct au_branch *br)
16880 + struct au_br_hfsnotify *hfsn;
16882 + hfsn = br->br_hfsn;
16885 + fsnotify_put_group(hfsn->hfsn_group);
16890 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16893 + struct fsnotify_group *group;
16894 + struct au_br_hfsnotify *hfsn;
16897 + br->br_hfsn = NULL;
16898 + if (!au_br_hnotifyable(perm))
16902 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16903 + if (unlikely(!hfsn))
16907 + group = fsnotify_alloc_group(&au_hfsn_ops);
16908 + if (IS_ERR(group)) {
16909 + err = PTR_ERR(group);
16910 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16914 + group->private = hfsn;
16915 + hfsn->hfsn_group = group;
16916 + br->br_hfsn = hfsn;
16917 + goto out; /* success */
16920 + au_kfree_try_rcu(hfsn);
16925 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16930 + if (!br->br_hfsn)
16931 + err = au_hfsn_init_br(br, perm);
16936 +/* ---------------------------------------------------------------------- */
16938 +static void au_hfsn_fin(void)
16940 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16941 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16944 +const struct au_hnotify_op au_hnotify_op = {
16945 + .ctl = au_hfsn_ctl,
16946 + .alloc = au_hfsn_alloc,
16947 + .free = au_hfsn_free,
16949 + .fin = au_hfsn_fin,
16951 + .reset_br = au_hfsn_reset_br,
16952 + .fin_br = au_hfsn_fin_br,
16953 + .init_br = au_hfsn_init_br
16955 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16956 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16957 +++ linux/fs/aufs/hfsplus.c 2021-11-01 23:48:34.206359262 +0100
16959 +// SPDX-License-Identifier: GPL-2.0
16961 + * Copyright (C) 2010-2021 Junjiro R. Okajima
16963 + * This program, aufs is free software; you can redistribute it and/or modify
16964 + * it under the terms of the GNU General Public License as published by
16965 + * the Free Software Foundation; either version 2 of the License, or
16966 + * (at your option) any later version.
16968 + * This program is distributed in the hope that it will be useful,
16969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16971 + * GNU General Public License for more details.
16973 + * You should have received a copy of the GNU General Public License
16974 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16978 + * special support for filesystems which acquires an inode mutex
16979 + * at final closing a file, eg, hfsplus.
16981 + * This trick is very simple and stupid, just to open the file before really
16982 + * necessary open to tell hfsplus that this is not the final closing.
16983 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16984 + * and au_h_open_post() after releasing it.
16989 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16992 + struct file *h_file;
16993 + struct dentry *h_dentry;
16995 + h_dentry = au_h_dptr(dentry, bindex);
16996 + AuDebugOn(!h_dentry);
16997 + AuDebugOn(d_is_negative(h_dentry));
17000 + if (au_test_hfsplus(h_dentry->d_sb)
17001 + && d_is_reg(h_dentry))
17002 + h_file = au_h_open(dentry, bindex,
17003 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17004 + /*file*/NULL, force_wr);
17008 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17009 + struct file *h_file)
17011 + struct au_branch *br;
17015 + br = au_sbr(dentry->d_sb, bindex);
17016 + au_lcnt_dec(&br->br_nfiles);
17019 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17020 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17021 +++ linux/fs/aufs/hnotify.c 2021-11-01 23:48:34.209692595 +0100
17023 +// SPDX-License-Identifier: GPL-2.0
17025 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17027 + * This program, aufs is free software; you can redistribute it and/or modify
17028 + * it under the terms of the GNU General Public License as published by
17029 + * the Free Software Foundation; either version 2 of the License, or
17030 + * (at your option) any later version.
17032 + * This program is distributed in the hope that it will be useful,
17033 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17034 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17035 + * GNU General Public License for more details.
17037 + * You should have received a copy of the GNU General Public License
17038 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17042 + * abstraction to notify the direct changes on lower directories
17045 +/* #include <linux/iversion.h> */
17048 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17051 + struct au_hnotify *hn;
17054 + hn = au_cache_alloc_hnotify();
17056 + hn->hn_aufs_inode = inode;
17057 + hinode->hi_notify = hn;
17058 + err = au_hnotify_op.alloc(hinode);
17060 + if (unlikely(err)) {
17061 + hinode->hi_notify = NULL;
17062 + au_cache_free_hnotify(hn);
17064 + * The upper dir was removed by udba, but the same named
17065 + * dir left. In this case, aufs assigns a new inode
17066 + * number and set the monitor again.
17067 + * For the lower dir, the old monitor is still left.
17069 + if (err == -EEXIST)
17078 +void au_hn_free(struct au_hinode *hinode)
17080 + struct au_hnotify *hn;
17082 + hn = hinode->hi_notify;
17084 + hinode->hi_notify = NULL;
17085 + if (au_hnotify_op.free(hinode, hn))
17086 + au_cache_free_hnotify(hn);
17090 +/* ---------------------------------------------------------------------- */
17092 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17094 + if (hinode->hi_notify)
17095 + au_hnotify_op.ctl(hinode, do_set);
17098 +void au_hn_reset(struct inode *inode, unsigned int flags)
17100 + aufs_bindex_t bindex, bbot;
17101 + struct inode *hi;
17102 + struct dentry *iwhdentry;
17104 + bbot = au_ibbot(inode);
17105 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17106 + hi = au_h_iptr(inode, bindex);
17110 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17111 + iwhdentry = au_hi_wh(inode, bindex);
17115 + au_set_h_iptr(inode, bindex, NULL, 0);
17116 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17117 + flags & ~AuHi_XINO);
17120 + /* inode_unlock(hi); */
17124 +/* ---------------------------------------------------------------------- */
17126 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17129 + aufs_bindex_t bindex, bbot, bfound, btop;
17130 + struct inode *h_i;
17133 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17134 + pr_warn("branch root dir was changed\n");
17139 + bbot = au_ibbot(inode);
17140 + btop = au_ibtop(inode);
17141 +#if 0 /* reserved for future use */
17142 + if (bindex == bbot) {
17143 + /* keep this ino in rename case */
17147 + for (bindex = btop; bindex <= bbot; bindex++)
17148 + if (au_h_iptr(inode, bindex) == h_inode) {
17155 + for (bindex = btop; bindex <= bbot; bindex++) {
17156 + h_i = au_h_iptr(inode, bindex);
17160 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17161 + /* ignore this error */
17162 + /* bad action? */
17165 + /* children inode number will be broken */
17172 +static int hn_gen_tree(struct dentry *dentry)
17174 + int err, i, j, ndentry;
17175 + struct au_dcsub_pages dpages;
17176 + struct au_dpage *dpage;
17177 + struct dentry **dentries;
17179 + err = au_dpages_init(&dpages, GFP_NOFS);
17180 + if (unlikely(err))
17182 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17183 + if (unlikely(err))
17186 + for (i = 0; i < dpages.ndpage; i++) {
17187 + dpage = dpages.dpages + i;
17188 + dentries = dpage->dentries;
17189 + ndentry = dpage->ndentry;
17190 + for (j = 0; j < ndentry; j++) {
17191 + struct dentry *d;
17198 + if (d_really_is_positive(d))
17199 + /* todo: reset children xino?
17200 + cached children only? */
17201 + au_iigen_dec(d_inode(d));
17206 + au_dpages_free(&dpages);
17212 + * return 0 if processed.
17214 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17215 + const unsigned int isdir)
17218 + struct dentry *d;
17219 + struct qstr *dname;
17222 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17223 + pr_warn("branch root dir was changed\n");
17229 + AuDebugOn(!name);
17230 + au_iigen_dec(inode);
17231 + spin_lock(&inode->i_lock);
17232 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17233 + spin_lock(&d->d_lock);
17234 + dname = &d->d_name;
17235 + if (dname->len != nlen
17236 + && memcmp(dname->name, name, nlen)) {
17237 + spin_unlock(&d->d_lock);
17242 + spin_unlock(&d->d_lock);
17245 + spin_unlock(&inode->i_lock);
17247 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17248 + d = d_find_any_alias(inode);
17250 + au_iigen_dec(inode);
17254 + spin_lock(&d->d_lock);
17255 + dname = &d->d_name;
17256 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17257 + spin_unlock(&d->d_lock);
17258 + err = hn_gen_tree(d);
17259 + spin_lock(&d->d_lock);
17261 + spin_unlock(&d->d_lock);
17270 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17274 + if (IS_ROOT(dentry)) {
17275 + pr_warn("branch root dir was changed\n");
17281 + au_digen_dec(dentry);
17282 + if (d_really_is_positive(dentry))
17283 + au_iigen_dec(d_inode(dentry));
17285 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17286 + if (d_really_is_positive(dentry))
17287 + err = hn_gen_tree(dentry);
17294 +/* ---------------------------------------------------------------------- */
17296 +/* hnotify job flags */
17297 +#define AuHnJob_XINO0 1
17298 +#define AuHnJob_GEN (1 << 1)
17299 +#define AuHnJob_DIRENT (1 << 2)
17300 +#define AuHnJob_ISDIR (1 << 3)
17301 +#define AuHnJob_TRYXINO0 (1 << 4)
17302 +#define AuHnJob_MNTPNT (1 << 5)
17303 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17304 +#define au_fset_hnjob(flags, name) \
17305 + do { (flags) |= AuHnJob_##name; } while (0)
17306 +#define au_fclr_hnjob(flags, name) \
17307 + do { (flags) &= ~AuHnJob_##name; } while (0)
17315 +struct au_hnotify_args {
17316 + struct inode *h_dir, *dir, *h_child_inode;
17318 + unsigned int flags[AuHnLast];
17319 + unsigned int h_child_nlen;
17320 + char h_child_name[];
17323 +struct hn_job_args {
17324 + unsigned int flags;
17325 + struct inode *inode, *h_inode, *dir, *h_dir;
17326 + struct dentry *dentry;
17331 +static int hn_job(struct hn_job_args *a)
17333 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17337 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17338 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17340 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17343 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17344 + if (!a->h_inode->i_nlink
17345 + && !(a->h_inode->i_state & I_LINKABLE))
17346 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17347 + inode_unlock_shared(a->h_inode);
17350 + /* make the generation obsolete */
17351 + if (au_ftest_hnjob(a->flags, GEN)) {
17354 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17356 + if (e && a->dentry)
17357 + hn_gen_by_name(a->dentry, isdir);
17358 + /* ignore this error */
17361 + /* make dir entries obsolete */
17362 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17363 + struct au_vdir *vdir;
17365 + vdir = au_ivdir(a->inode);
17367 + vdir->vd_jiffy = 0;
17368 + /* IMustLock(a->inode); */
17369 + /* inode_inc_iversion(a->inode); */
17372 + /* can do nothing but warn */
17373 + if (au_ftest_hnjob(a->flags, MNTPNT)
17375 + && d_mountpoint(a->dentry))
17376 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17381 +/* ---------------------------------------------------------------------- */
17383 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17384 + struct inode *dir)
17386 + struct dentry *dentry, *d, *parent;
17387 + struct qstr *dname;
17389 + parent = d_find_any_alias(dir);
17394 + spin_lock(&parent->d_lock);
17395 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17396 + /* AuDbg("%pd\n", d); */
17397 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17398 + dname = &d->d_name;
17399 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17400 + goto cont_unlock;
17404 + goto cont_unlock;
17405 + if (au_dcount(d) > 0) {
17406 + dentry = dget_dlock(d);
17407 + spin_unlock(&d->d_lock);
17412 + spin_unlock(&d->d_lock);
17414 + spin_unlock(&parent->d_lock);
17418 + di_write_lock_child(dentry);
17423 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17424 + aufs_bindex_t bindex, ino_t h_ino)
17426 + struct inode *inode;
17431 + err = au_xino_read(sb, bindex, h_ino, &ino);
17433 + inode = ilookup(sb, ino);
17437 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17438 + pr_warn("wrong root branch\n");
17444 + ii_write_lock_child(inode);
17450 +static void au_hn_bh(void *_args)
17452 + struct au_hnotify_args *a = _args;
17453 + struct super_block *sb;
17454 + aufs_bindex_t bindex, bbot, bfound;
17455 + unsigned char xino, try_iput;
17457 + struct inode *inode;
17459 + struct hn_job_args args;
17460 + struct dentry *dentry;
17461 + struct au_sbinfo *sbinfo;
17463 + AuDebugOn(!_args);
17464 + AuDebugOn(!a->h_dir);
17465 + AuDebugOn(!a->dir);
17466 + AuDebugOn(!a->mask);
17467 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17468 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17469 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17474 + * do not lock a->dir->i_mutex here
17475 + * because of d_revalidate() may cause a deadlock.
17477 + sb = a->dir->i_sb;
17479 + sbinfo = au_sbi(sb);
17480 + AuDebugOn(!sbinfo);
17481 + si_write_lock(sb, AuLock_NOPLMW);
17483 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17484 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17485 + case FS_MOVED_FROM:
17486 + case FS_MOVED_TO:
17487 + AuWarn1("DIRREN with UDBA may not work correctly "
17488 + "for the direct rename(2)\n");
17491 + ii_read_lock_parent(a->dir);
17493 + bbot = au_ibbot(a->dir);
17494 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17495 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17499 + ii_read_unlock(a->dir);
17500 + if (unlikely(bfound < 0))
17503 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17505 + if (a->h_child_inode)
17506 + h_ino = a->h_child_inode->i_ino;
17508 + if (a->h_child_nlen
17509 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17510 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17511 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17514 + if (dentry && d_really_is_positive(dentry))
17515 + inode = d_inode(dentry);
17516 + if (xino && !inode && h_ino
17517 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17518 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17519 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17520 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17524 + args.flags = a->flags[AuHn_CHILD];
17525 + args.dentry = dentry;
17526 + args.inode = inode;
17527 + args.h_inode = a->h_child_inode;
17528 + args.dir = a->dir;
17529 + args.h_dir = a->h_dir;
17530 + args.h_name = a->h_child_name;
17531 + args.h_nlen = a->h_child_nlen;
17532 + err = hn_job(&args);
17534 + if (au_di(dentry))
17535 + di_write_unlock(dentry);
17538 + if (inode && try_iput) {
17539 + ii_write_unlock(inode);
17543 + ii_write_lock_parent(a->dir);
17544 + args.flags = a->flags[AuHn_PARENT];
17545 + args.dentry = NULL;
17546 + args.inode = a->dir;
17547 + args.h_inode = a->h_dir;
17549 + args.h_dir = NULL;
17550 + args.h_name = NULL;
17552 + err = hn_job(&args);
17553 + ii_write_unlock(a->dir);
17556 + iput(a->h_child_inode);
17559 + si_write_unlock(sb);
17560 + au_nwt_done(&sbinfo->si_nowait);
17564 +/* ---------------------------------------------------------------------- */
17566 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17567 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17570 + unsigned int flags[AuHnLast], f;
17571 + unsigned char isdir, isroot, wh;
17572 + struct inode *dir;
17573 + struct au_hnotify_args *args;
17574 + char *p, *h_child_name;
17577 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17578 + dir = igrab(hnotify->hn_aufs_inode);
17582 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17584 + h_child_name = (void *)h_child_qstr->name;
17585 + len = h_child_qstr->len;
17586 + if (h_child_name) {
17587 + if (len > AUFS_WH_PFX_LEN
17588 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17589 + h_child_name += AUFS_WH_PFX_LEN;
17590 + len -= AUFS_WH_PFX_LEN;
17596 + if (h_child_inode)
17597 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17598 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17599 + flags[AuHn_CHILD] = 0;
17601 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17602 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17603 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17604 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17605 + case FS_MOVED_FROM:
17606 + case FS_MOVED_TO:
17607 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17608 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17611 + AuDebugOn(!h_child_name);
17616 + * aufs never be able to get this child inode.
17617 + * revalidation should be in d_revalidate()
17618 + * by checking i_nlink, i_generation or d_unhashed().
17620 + AuDebugOn(!h_child_name);
17621 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17622 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17630 + h_child_inode = NULL;
17633 + /* iput() and kfree() will be called in au_hnotify() */
17634 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17635 + if (unlikely(!args)) {
17636 + AuErr1("no memory\n");
17640 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17641 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17642 + args->mask = mask;
17644 + args->h_dir = igrab(h_dir);
17645 + if (h_child_inode)
17646 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17647 + args->h_child_inode = h_child_inode;
17648 + args->h_child_nlen = len;
17650 + p = (void *)args;
17651 + p += sizeof(*args);
17652 + memcpy(p, h_child_name, len);
17656 + /* NFS fires the event for silly-renamed one from kworker */
17658 + if (!dir->i_nlink
17659 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17661 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17662 + if (unlikely(err)) {
17663 + pr_err("wkq %d\n", err);
17664 + iput(args->h_child_inode);
17665 + iput(args->h_dir);
17667 + au_kfree_rcu(args);
17674 +/* ---------------------------------------------------------------------- */
17676 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17680 + AuDebugOn(!(udba & AuOptMask_UDBA));
17683 + if (au_hnotify_op.reset_br)
17684 + err = au_hnotify_op.reset_br(udba, br, perm);
17689 +int au_hnotify_init_br(struct au_branch *br, int perm)
17694 + if (au_hnotify_op.init_br)
17695 + err = au_hnotify_op.init_br(br, perm);
17700 +void au_hnotify_fin_br(struct au_branch *br)
17702 + if (au_hnotify_op.fin_br)
17703 + au_hnotify_op.fin_br(br);
17706 +static void au_hn_destroy_cache(void)
17708 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17709 + au_cache[AuCache_HNOTIFY] = NULL;
17712 +int __init au_hnotify_init(void)
17717 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17718 + if (au_cache[AuCache_HNOTIFY]) {
17720 + if (au_hnotify_op.init)
17721 + err = au_hnotify_op.init();
17722 + if (unlikely(err))
17723 + au_hn_destroy_cache();
17729 +void au_hnotify_fin(void)
17731 + if (au_hnotify_op.fin)
17732 + au_hnotify_op.fin();
17734 + /* cf. au_cache_fin() */
17735 + if (au_cache[AuCache_HNOTIFY])
17736 + au_hn_destroy_cache();
17738 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17739 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17740 +++ linux/fs/aufs/iinfo.c 2021-11-01 23:48:34.209692595 +0100
17742 +// SPDX-License-Identifier: GPL-2.0
17744 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17746 + * This program, aufs is free software; you can redistribute it and/or modify
17747 + * it under the terms of the GNU General Public License as published by
17748 + * the Free Software Foundation; either version 2 of the License, or
17749 + * (at your option) any later version.
17751 + * This program is distributed in the hope that it will be useful,
17752 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17753 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17754 + * GNU General Public License for more details.
17756 + * You should have received a copy of the GNU General Public License
17757 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17761 + * inode private data
17766 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17768 + struct inode *h_inode;
17769 + struct au_hinode *hinode;
17771 + IiMustAnyLock(inode);
17773 + hinode = au_hinode(au_ii(inode), bindex);
17774 + h_inode = hinode->hi_inode;
17775 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17779 +/* todo: hard/soft set? */
17780 +void au_hiput(struct au_hinode *hinode)
17782 + au_hn_free(hinode);
17783 + dput(hinode->hi_whdentry);
17784 + iput(hinode->hi_inode);
17787 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17789 + unsigned int flags;
17790 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17793 + if (au_opt_test(mnt_flags, XINO))
17794 + au_fset_hi(flags, XINO);
17795 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17796 + au_fset_hi(flags, HNOTIFY);
17800 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17801 + struct inode *h_inode, unsigned int flags)
17803 + struct au_hinode *hinode;
17804 + struct inode *hi;
17805 + struct au_iinfo *iinfo = au_ii(inode);
17807 + IiMustWriteLock(inode);
17809 + hinode = au_hinode(iinfo, bindex);
17810 + hi = hinode->hi_inode;
17811 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17814 + au_hiput(hinode);
17815 + hinode->hi_inode = h_inode;
17818 + struct super_block *sb = inode->i_sb;
17819 + struct au_branch *br;
17821 + AuDebugOn(inode->i_mode
17822 + && (h_inode->i_mode & S_IFMT)
17823 + != (inode->i_mode & S_IFMT));
17824 + if (bindex == iinfo->ii_btop)
17825 + au_cpup_igen(inode, h_inode);
17826 + br = au_sbr(sb, bindex);
17827 + hinode->hi_id = br->br_id;
17828 + if (au_ftest_hi(flags, XINO)) {
17829 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17831 + if (unlikely(err))
17832 + AuIOErr1("failed au_xino_write() %d\n", err);
17835 + if (au_ftest_hi(flags, HNOTIFY)
17836 + && au_br_hnotifyable(br->br_perm)) {
17837 + err = au_hn_alloc(hinode, inode);
17838 + if (unlikely(err))
17839 + AuIOErr1("au_hn_alloc() %d\n", err);
17844 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17845 + struct dentry *h_wh)
17847 + struct au_hinode *hinode;
17849 + IiMustWriteLock(inode);
17851 + hinode = au_hinode(au_ii(inode), bindex);
17852 + AuDebugOn(hinode->hi_whdentry);
17853 + hinode->hi_whdentry = h_wh;
17856 +void au_update_iigen(struct inode *inode, int half)
17858 + struct au_iinfo *iinfo;
17859 + struct au_iigen *iigen;
17860 + unsigned int sigen;
17862 + sigen = au_sigen(inode->i_sb);
17863 + iinfo = au_ii(inode);
17864 + iigen = &iinfo->ii_generation;
17865 + spin_lock(&iigen->ig_spin);
17866 + iigen->ig_generation = sigen;
17868 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17870 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17871 + spin_unlock(&iigen->ig_spin);
17874 +/* it may be called at remount time, too */
17875 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17877 + struct au_iinfo *iinfo;
17878 + aufs_bindex_t bindex, bbot;
17880 + AuDebugOn(au_is_bad_inode(inode));
17881 + IiMustWriteLock(inode);
17883 + iinfo = au_ii(inode);
17884 + if (do_put_zero && iinfo->ii_btop >= 0) {
17885 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17887 + struct inode *h_i;
17889 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17892 + && !(h_i->i_state & I_LINKABLE))
17893 + au_set_h_iptr(inode, bindex, NULL, 0);
17897 + iinfo->ii_btop = -1;
17898 + iinfo->ii_bbot = -1;
17899 + bbot = au_sbbot(inode->i_sb);
17900 + for (bindex = 0; bindex <= bbot; bindex++)
17901 + if (au_hinode(iinfo, bindex)->hi_inode) {
17902 + iinfo->ii_btop = bindex;
17905 + if (iinfo->ii_btop >= 0)
17906 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17907 + if (au_hinode(iinfo, bindex)->hi_inode) {
17908 + iinfo->ii_bbot = bindex;
17911 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17914 +/* ---------------------------------------------------------------------- */
17916 +void au_icntnr_init_once(void *_c)
17918 + struct au_icntnr *c = _c;
17919 + struct au_iinfo *iinfo = &c->iinfo;
17921 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17922 + au_rw_init(&iinfo->ii_rwsem);
17923 + inode_init_once(&c->vfs_inode);
17926 +void au_hinode_init(struct au_hinode *hinode)
17928 + hinode->hi_inode = NULL;
17929 + hinode->hi_id = -1;
17930 + au_hn_init(hinode);
17931 + hinode->hi_whdentry = NULL;
17934 +int au_iinfo_init(struct inode *inode)
17936 + struct au_iinfo *iinfo;
17937 + struct super_block *sb;
17938 + struct au_hinode *hi;
17941 + sb = inode->i_sb;
17942 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17943 + nbr = au_sbbot(sb) + 1;
17944 + if (unlikely(nbr <= 0))
17946 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17948 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17950 + iinfo->ii_hinode = hi;
17951 + for (i = 0; i < nbr; i++, hi++)
17952 + au_hinode_init(hi);
17954 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17955 + iinfo->ii_btop = -1;
17956 + iinfo->ii_bbot = -1;
17957 + iinfo->ii_vdir = NULL;
17963 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17966 + struct au_hinode *hip;
17968 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17971 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17974 + iinfo->ii_hinode = hip;
17975 + i = iinfo->ii_bbot + 1;
17977 + for (; i < nbr; i++, hip++)
17978 + au_hinode_init(hip);
17985 +void au_iinfo_fin(struct inode *inode)
17987 + struct au_iinfo *iinfo;
17988 + struct au_hinode *hi;
17989 + struct super_block *sb;
17990 + aufs_bindex_t bindex, bbot;
17991 + const unsigned char unlinked = !inode->i_nlink;
17993 + AuDebugOn(au_is_bad_inode(inode));
17995 + sb = inode->i_sb;
17996 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
17997 + if (si_pid_test(sb))
17998 + au_xino_delete_inode(inode, unlinked);
18001 + * it is safe to hide the dependency between sbinfo and
18005 + si_noflush_read_lock(sb);
18006 + au_xino_delete_inode(inode, unlinked);
18007 + si_read_unlock(sb);
18011 + iinfo = au_ii(inode);
18012 + if (iinfo->ii_vdir)
18013 + au_vdir_free(iinfo->ii_vdir);
18015 + bindex = iinfo->ii_btop;
18016 + if (bindex >= 0) {
18017 + hi = au_hinode(iinfo, bindex);
18018 + bbot = iinfo->ii_bbot;
18019 + while (bindex++ <= bbot) {
18020 + if (hi->hi_inode)
18025 + au_kfree_rcu(iinfo->ii_hinode);
18026 + AuRwDestroy(&iinfo->ii_rwsem);
18028 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18029 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18030 +++ linux/fs/aufs/inode.c 2021-11-01 23:48:34.209692595 +0100
18032 +// SPDX-License-Identifier: GPL-2.0
18034 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18036 + * This program, aufs is free software; you can redistribute it and/or modify
18037 + * it under the terms of the GNU General Public License as published by
18038 + * the Free Software Foundation; either version 2 of the License, or
18039 + * (at your option) any later version.
18041 + * This program is distributed in the hope that it will be useful,
18042 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18043 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18044 + * GNU General Public License for more details.
18046 + * You should have received a copy of the GNU General Public License
18047 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18051 + * inode functions
18054 +#include <linux/iversion.h>
18057 +struct inode *au_igrab(struct inode *inode)
18060 + AuDebugOn(!atomic_read(&inode->i_count));
18066 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18068 + au_cpup_attr_all(inode, /*force*/0);
18069 + au_update_iigen(inode, /*half*/1);
18071 + inode_inc_iversion(inode);
18074 +static int au_ii_refresh(struct inode *inode, int *update)
18078 + aufs_bindex_t bindex, new_bindex;
18079 + struct super_block *sb;
18080 + struct au_iinfo *iinfo;
18081 + struct au_hinode *p, *q, tmp;
18083 + AuDebugOn(au_is_bad_inode(inode));
18084 + IiMustWriteLock(inode);
18087 + sb = inode->i_sb;
18088 + nbr = au_sbbot(sb) + 1;
18089 + type = inode->i_mode & S_IFMT;
18090 + iinfo = au_ii(inode);
18091 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18092 + if (unlikely(err))
18095 + AuDebugOn(iinfo->ii_btop < 0);
18096 + p = au_hinode(iinfo, iinfo->ii_btop);
18097 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18099 + if (!p->hi_inode)
18102 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18103 + new_bindex = au_br_index(sb, p->hi_id);
18104 + if (new_bindex == bindex)
18107 + if (new_bindex < 0) {
18110 + p->hi_inode = NULL;
18114 + if (new_bindex < iinfo->ii_btop)
18115 + iinfo->ii_btop = new_bindex;
18116 + if (iinfo->ii_bbot < new_bindex)
18117 + iinfo->ii_bbot = new_bindex;
18118 + /* swap two lower inode, and loop again */
18119 + q = au_hinode(iinfo, new_bindex);
18123 + if (tmp.hi_inode) {
18128 + au_update_ibrange(inode, /*do_put_zero*/0);
18129 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18130 + e = au_dy_irefresh(inode);
18131 + if (unlikely(e && !err))
18139 +void au_refresh_iop(struct inode *inode, int force_getattr)
18142 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18143 + const struct inode_operations *iop
18144 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18146 + if (inode->i_op == iop)
18149 + switch (inode->i_mode & S_IFMT) {
18151 + type = AuIop_DIR;
18154 + type = AuIop_SYMLINK;
18157 + type = AuIop_OTHER;
18161 + inode->i_op = iop + type;
18162 + /* unnecessary smp_wmb() */
18165 +int au_refresh_hinode_self(struct inode *inode)
18169 + err = au_ii_refresh(inode, &update);
18171 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18177 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18179 + int err, e, update;
18180 + unsigned int flags;
18182 + aufs_bindex_t bindex, bbot;
18183 + unsigned char isdir;
18184 + struct au_hinode *p;
18185 + struct au_iinfo *iinfo;
18187 + err = au_ii_refresh(inode, &update);
18188 + if (unlikely(err))
18192 + iinfo = au_ii(inode);
18193 + p = au_hinode(iinfo, iinfo->ii_btop);
18194 + mode = (inode->i_mode & S_IFMT);
18195 + isdir = S_ISDIR(mode);
18196 + flags = au_hi_flags(inode, isdir);
18197 + bbot = au_dbbot(dentry);
18198 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18199 + struct inode *h_i, *h_inode;
18200 + struct dentry *h_d;
18202 + h_d = au_h_dptr(dentry, bindex);
18203 + if (!h_d || d_is_negative(h_d))
18206 + h_inode = d_inode(h_d);
18207 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18208 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18209 + h_i = au_h_iptr(inode, bindex);
18211 + if (h_i == h_inode)
18217 + if (bindex < iinfo->ii_btop)
18218 + iinfo->ii_btop = bindex;
18219 + if (iinfo->ii_bbot < bindex)
18220 + iinfo->ii_bbot = bindex;
18221 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18224 + au_update_ibrange(inode, /*do_put_zero*/0);
18225 + e = au_dy_irefresh(inode);
18226 + if (unlikely(e && !err))
18229 + au_refresh_hinode_attr(inode, update && isdir);
18236 +static int set_inode(struct inode *inode, struct dentry *dentry)
18239 + unsigned int flags;
18241 + aufs_bindex_t bindex, btop, btail;
18242 + unsigned char isdir;
18243 + struct dentry *h_dentry;
18244 + struct inode *h_inode;
18245 + struct au_iinfo *iinfo;
18246 + const struct inode_operations *iop;
18248 + IiMustWriteLock(inode);
18252 + iop = au_sbi(inode->i_sb)->si_iop_array;
18253 + btop = au_dbtop(dentry);
18254 + h_dentry = au_h_dptr(dentry, btop);
18255 + h_inode = d_inode(h_dentry);
18256 + mode = h_inode->i_mode;
18257 + switch (mode & S_IFMT) {
18259 + btail = au_dbtail(dentry);
18260 + inode->i_op = iop + AuIop_OTHER;
18261 + inode->i_fop = &aufs_file_fop;
18262 + err = au_dy_iaop(inode, btop, h_inode);
18263 + if (unlikely(err))
18268 + btail = au_dbtaildir(dentry);
18269 + inode->i_op = iop + AuIop_DIR;
18270 + inode->i_fop = &aufs_dir_fop;
18273 + btail = au_dbtail(dentry);
18274 + inode->i_op = iop + AuIop_SYMLINK;
18280 + btail = au_dbtail(dentry);
18281 + inode->i_op = iop + AuIop_OTHER;
18282 + init_special_inode(inode, mode, h_inode->i_rdev);
18285 + AuIOErr("Unknown file type 0%o\n", mode);
18290 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18291 + flags = au_hi_flags(inode, isdir);
18292 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18293 + && au_ftest_hi(flags, HNOTIFY)
18294 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18295 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18296 + au_fclr_hi(flags, HNOTIFY);
18297 + iinfo = au_ii(inode);
18298 + iinfo->ii_btop = btop;
18299 + iinfo->ii_bbot = btail;
18300 + for (bindex = btop; bindex <= btail; bindex++) {
18301 + h_dentry = au_h_dptr(dentry, bindex);
18303 + au_set_h_iptr(inode, bindex,
18304 + au_igrab(d_inode(h_dentry)), flags);
18306 + au_cpup_attr_all(inode, /*force*/1);
18308 + * to force calling aufs_get_acl() every time,
18309 + * do not call cache_no_acl() for aufs inode.
18317 + * successful returns with iinfo write_locked
18319 + * zero: success, matched
18320 + * plus: no error, but unmatched
18322 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18325 + unsigned int gen, igflags;
18326 + aufs_bindex_t bindex, bbot;
18327 + struct inode *h_inode, *h_dinode;
18328 + struct dentry *h_dentry;
18331 + * before this function, if aufs got any iinfo lock, it must be only
18332 + * one, the parent dir.
18333 + * it can happen by UDBA and the obsoleted inode number.
18336 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18340 + ii_write_lock_new_child(inode);
18341 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18342 + h_dinode = d_inode(h_dentry);
18343 + bbot = au_ibbot(inode);
18344 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18345 + h_inode = au_h_iptr(inode, bindex);
18346 + if (!h_inode || h_inode != h_dinode)
18350 + gen = au_iigen(inode, &igflags);
18351 + if (gen == au_digen(dentry)
18352 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18355 + /* fully refresh inode using dentry */
18356 + err = au_refresh_hinode(inode, dentry);
18358 + au_update_iigen(inode, /*half*/0);
18362 + if (unlikely(err))
18363 + ii_write_unlock(inode);
18368 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18369 + unsigned int d_type, ino_t *ino)
18372 + const int isnondir = d_type != DT_DIR;
18374 + /* prevent hardlinked inode number from race condition */
18376 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18377 + if (unlikely(err))
18381 + err = au_xino_read(sb, bindex, h_ino, ino);
18382 + if (unlikely(err))
18383 + goto out_xinondir;
18387 + *ino = au_xino_new_ino(sb);
18388 + if (unlikely(!*ino))
18389 + goto out_xinondir;
18390 + err = au_xino_write(sb, bindex, h_ino, *ino);
18391 + if (unlikely(err))
18392 + goto out_xinondir;
18396 + if (isnondir && idx >= 0)
18397 + au_xinondir_leave(sb, bindex, h_ino, idx);
18402 +/* successful returns with iinfo write_locked */
18403 +/* todo: return with unlocked? */
18404 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18406 + struct inode *inode, *h_inode;
18407 + struct dentry *h_dentry;
18408 + struct super_block *sb;
18409 + ino_t h_ino, ino;
18410 + int err, idx, hlinked;
18411 + aufs_bindex_t btop;
18413 + sb = dentry->d_sb;
18414 + btop = au_dbtop(dentry);
18415 + h_dentry = au_h_dptr(dentry, btop);
18416 + h_inode = d_inode(h_dentry);
18417 + h_ino = h_inode->i_ino;
18418 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18422 + * stop 'race'-ing between hardlinks under different
18426 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18427 + inode = ERR_PTR(err);
18428 + if (unlikely(err))
18432 + err = au_xino_read(sb, btop, h_ino, &ino);
18433 + inode = ERR_PTR(err);
18434 + if (unlikely(err))
18435 + goto out_xinondir;
18438 + ino = au_xino_new_ino(sb);
18439 + if (unlikely(!ino)) {
18440 + inode = ERR_PTR(-EIO);
18441 + goto out_xinondir;
18445 + AuDbg("i%lu\n", (unsigned long)ino);
18446 + inode = au_iget_locked(sb, ino);
18447 + err = PTR_ERR(inode);
18448 + if (IS_ERR(inode))
18449 + goto out_xinondir;
18451 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18452 + if (inode->i_state & I_NEW) {
18453 + ii_write_lock_new_child(inode);
18454 + err = set_inode(inode, dentry);
18456 + unlock_new_inode(inode);
18457 + goto out_xinondir; /* success */
18461 + * iget_failed() calls iput(), but we need to call
18462 + * ii_write_unlock() after iget_failed(). so dirty hack for
18465 + atomic_inc(&inode->i_count);
18466 + iget_failed(inode);
18467 + ii_write_unlock(inode);
18468 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18469 + /* ignore this error */
18471 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18473 + * horrible race condition between lookup, readdir and copyup
18474 + * (or something).
18476 + if (hlinked && idx >= 0)
18477 + au_xinondir_leave(sb, btop, h_ino, idx);
18478 + err = reval_inode(inode, dentry);
18479 + if (unlikely(err < 0)) {
18484 + goto out; /* success */
18485 + else if (hlinked && idx >= 0) {
18486 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18487 + if (unlikely(err)) {
18489 + inode = ERR_PTR(err);
18495 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18496 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18497 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18498 + btop, au_sbtype(h_dentry->d_sb), dentry,
18499 + (unsigned long)h_ino, (unsigned long)ino);
18501 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18504 + if (hlinked && idx >= 0)
18505 + au_xinondir_leave(sb, btop, h_ino, idx);
18511 + inode = ERR_PTR(err);
18513 + if (hlinked && idx >= 0)
18514 + au_xinondir_leave(sb, btop, h_ino, idx);
18519 +/* ---------------------------------------------------------------------- */
18521 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18522 + struct inode *inode)
18525 + struct inode *hi;
18527 + err = au_br_rdonly(au_sbr(sb, bindex));
18529 + /* pseudo-link after flushed may happen out of bounds */
18532 + && au_ibtop(inode) <= bindex
18533 + && bindex <= au_ibbot(inode)) {
18535 + * permission check is unnecessary since vfsub routine
18536 + * will be called later
18538 + hi = au_h_iptr(inode, bindex);
18540 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18546 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18549 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18551 + return inode_permission(h_userns, h_inode, mask);
18554 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18557 + if (au_test_nfs(h_inode->i_sb)
18558 + && (mask & MAY_WRITE)
18559 + && S_ISDIR(h_inode->i_mode))
18560 + mask |= MAY_READ; /* force permission check */
18561 + return au_test_h_perm(h_userns, h_inode, mask);
18563 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18564 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18565 +++ linux/fs/aufs/inode.h 2021-11-01 23:48:34.209692595 +0100
18567 +/* SPDX-License-Identifier: GPL-2.0 */
18569 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18571 + * This program, aufs is free software; you can redistribute it and/or modify
18572 + * it under the terms of the GNU General Public License as published by
18573 + * the Free Software Foundation; either version 2 of the License, or
18574 + * (at your option) any later version.
18576 + * This program is distributed in the hope that it will be useful,
18577 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18578 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18579 + * GNU General Public License for more details.
18581 + * You should have received a copy of the GNU General Public License
18582 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18586 + * inode operations
18589 +#ifndef __AUFS_INODE_H__
18590 +#define __AUFS_INODE_H__
18594 +#include <linux/fsnotify.h>
18595 +#include "rwsem.h"
18599 +struct au_hnotify {
18600 +#ifdef CONFIG_AUFS_HNOTIFY
18601 +#ifdef CONFIG_AUFS_HFSNOTIFY
18602 + /* never use fsnotify_add_vfsmount_mark() */
18603 + struct fsnotify_mark hn_mark;
18605 + struct inode *hn_aufs_inode; /* no get/put */
18606 + struct rcu_head rcu;
18608 +} ____cacheline_aligned_in_smp;
18610 +struct au_hinode {
18611 + struct inode *hi_inode;
18612 + aufs_bindex_t hi_id;
18613 +#ifdef CONFIG_AUFS_HNOTIFY
18614 + struct au_hnotify *hi_notify;
18617 + /* reference to the copied-up whiteout with get/put */
18618 + struct dentry *hi_whdentry;
18622 +#define AuIG_HALF_REFRESHED 1
18623 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18624 +#define au_ig_fset(flags, name) \
18625 + do { (flags) |= AuIG_##name; } while (0)
18626 +#define au_ig_fclr(flags, name) \
18627 + do { (flags) &= ~AuIG_##name; } while (0)
18630 + spinlock_t ig_spin;
18631 + __u32 ig_generation, ig_flags;
18636 + struct au_iigen ii_generation;
18637 + struct super_block *ii_hsb1; /* no get/put */
18639 + struct au_rwsem ii_rwsem;
18640 + aufs_bindex_t ii_btop, ii_bbot;
18642 + struct au_hinode *ii_hinode;
18643 + struct au_vdir *ii_vdir;
18646 +struct au_icntnr {
18647 + struct au_iinfo iinfo;
18648 + struct inode vfs_inode;
18649 + struct hlist_bl_node plink;
18650 + struct rcu_head rcu;
18651 +} ____cacheline_aligned_in_smp;
18653 +/* au_pin flags */
18654 +#define AuPin_DI_LOCKED 1
18655 +#define AuPin_MNT_WRITE (1 << 1)
18656 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18657 +#define au_fset_pin(flags, name) \
18658 + do { (flags) |= AuPin_##name; } while (0)
18659 +#define au_fclr_pin(flags, name) \
18660 + do { (flags) &= ~AuPin_##name; } while (0)
18664 + struct dentry *dentry;
18665 + unsigned int udba;
18666 + unsigned char lsc_di, lsc_hi, flags;
18667 + aufs_bindex_t bindex;
18670 + struct dentry *parent;
18671 + struct au_hinode *hdir;
18672 + struct vfsmount *h_mnt;
18674 + /* temporary unlock/relock for copyup */
18675 + struct dentry *h_dentry, *h_parent;
18676 + struct au_branch *br;
18677 + struct task_struct *task;
18680 +void au_pin_hdir_unlock(struct au_pin *p);
18681 +int au_pin_hdir_lock(struct au_pin *p);
18682 +int au_pin_hdir_relock(struct au_pin *p);
18683 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18684 +void au_pin_hdir_release(struct au_pin *p);
18686 +/* ---------------------------------------------------------------------- */
18688 +static inline struct au_iinfo *au_ii(struct inode *inode)
18690 + BUG_ON(is_bad_inode(inode));
18691 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18694 +/* ---------------------------------------------------------------------- */
18697 +struct inode *au_igrab(struct inode *inode);
18698 +void au_refresh_iop(struct inode *inode, int force_getattr);
18699 +int au_refresh_hinode_self(struct inode *inode);
18700 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18701 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18702 + unsigned int d_type, ino_t *ino);
18703 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18704 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18705 + struct inode *inode);
18706 +int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
18708 +int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
18711 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18712 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18714 +#ifdef CONFIG_AUFS_SHWH
18715 + return au_ino(sb, bindex, h_ino, d_type, ino);
18728 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18729 + aufs_iop_nogetattr[AuIop_Last];
18731 +/* au_wr_dir flags */
18732 +#define AuWrDir_ADD_ENTRY 1
18733 +#define AuWrDir_ISDIR (1 << 1)
18734 +#define AuWrDir_TMPFILE (1 << 2)
18735 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18736 +#define au_fset_wrdir(flags, name) \
18737 + do { (flags) |= AuWrDir_##name; } while (0)
18738 +#define au_fclr_wrdir(flags, name) \
18739 + do { (flags) &= ~AuWrDir_##name; } while (0)
18741 +struct au_wr_dir_args {
18742 + aufs_bindex_t force_btgt;
18743 + unsigned char flags;
18745 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18746 + struct au_wr_dir_args *args);
18748 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18749 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18750 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18751 + unsigned int udba, unsigned char flags);
18752 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18753 + unsigned int udba, unsigned char flags) __must_check;
18754 +int au_do_pin(struct au_pin *pin) __must_check;
18755 +void au_unpin(struct au_pin *pin);
18756 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18758 +#define AuIcpup_DID_CPUP 1
18759 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18760 +#define au_fset_icpup(flags, name) \
18761 + do { (flags) |= AuIcpup_##name; } while (0)
18762 +#define au_fclr_icpup(flags, name) \
18763 + do { (flags) &= ~AuIcpup_##name; } while (0)
18765 +struct au_icpup_args {
18766 + unsigned char flags;
18767 + unsigned char pin_flags;
18768 + aufs_bindex_t btgt;
18769 + unsigned int udba;
18770 + struct au_pin pin;
18771 + struct path h_path;
18772 + struct inode *h_inode;
18775 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18776 + struct au_icpup_args *a);
18778 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18779 + struct path *h_path, int locked);
18782 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18783 + struct dentry *h_parent, int isdir);
18784 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
18785 + struct dentry *dentry, umode_t mode, dev_t dev);
18786 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
18787 + struct dentry *dentry, const char *symname);
18788 +int aufs_create(struct user_namespace *userns, struct inode *dir,
18789 + struct dentry *dentry, umode_t mode, bool want_excl);
18790 +struct vfsub_aopen_args;
18791 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18792 + struct vfsub_aopen_args *args);
18793 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
18794 + struct dentry *dentry, umode_t mode);
18795 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18796 + struct dentry *dentry);
18797 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
18798 + struct dentry *dentry, umode_t mode);
18801 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18802 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18803 + struct dentry *h_parent, int isdir);
18804 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18805 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18808 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18809 +int aufs_rename(struct user_namespace *userns,
18810 + struct inode *_src_dir, struct dentry *_src_dentry,
18811 + struct inode *_dst_dir, struct dentry *_dst_dentry,
18812 + unsigned int _flags);
18815 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18816 +void au_hiput(struct au_hinode *hinode);
18817 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18818 + struct dentry *h_wh);
18819 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18821 +/* hinode flags */
18822 +#define AuHi_XINO 1
18823 +#define AuHi_HNOTIFY (1 << 1)
18824 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18825 +#define au_fset_hi(flags, name) \
18826 + do { (flags) |= AuHi_##name; } while (0)
18827 +#define au_fclr_hi(flags, name) \
18828 + do { (flags) &= ~AuHi_##name; } while (0)
18830 +#ifndef CONFIG_AUFS_HNOTIFY
18831 +#undef AuHi_HNOTIFY
18832 +#define AuHi_HNOTIFY 0
18835 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18836 + struct inode *h_inode, unsigned int flags);
18838 +void au_update_iigen(struct inode *inode, int half);
18839 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18841 +void au_icntnr_init_once(void *_c);
18842 +void au_hinode_init(struct au_hinode *hinode);
18843 +int au_iinfo_init(struct inode *inode);
18844 +void au_iinfo_fin(struct inode *inode);
18845 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18847 +#ifdef CONFIG_PROC_FS
18849 +int au_plink_maint(struct super_block *sb, int flags);
18851 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18852 +int au_plink_maint_enter(struct super_block *sb);
18853 +#ifdef CONFIG_AUFS_DEBUG
18854 +void au_plink_list(struct super_block *sb);
18856 +AuStubVoid(au_plink_list, struct super_block *sb)
18858 +int au_plink_test(struct inode *inode);
18859 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18860 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18861 + struct dentry *h_dentry);
18862 +void au_plink_put(struct super_block *sb, int verbose);
18863 +void au_plink_clean(struct super_block *sb, int verbose);
18864 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18866 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18867 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18868 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18869 +AuStubVoid(au_plink_list, struct super_block *sb);
18870 +AuStubInt0(au_plink_test, struct inode *inode);
18871 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18872 + struct inode *inode, aufs_bindex_t bindex);
18873 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18874 + struct dentry *h_dentry);
18875 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18876 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18877 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18878 +#endif /* CONFIG_PROC_FS */
18880 +#ifdef CONFIG_AUFS_XATTR
18882 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
18883 + unsigned int verbose);
18884 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18885 +void au_xattr_init(struct super_block *sb);
18887 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
18888 + int ignore_flags, unsigned int verbose);
18889 +AuStubVoid(au_xattr_init, struct super_block *sb);
18892 +#ifdef CONFIG_FS_POSIX_ACL
18893 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu);
18894 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
18895 + struct posix_acl *acl, int type);
18898 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18904 +struct au_sxattr {
18908 + const char *name;
18909 + const void *value;
18914 + struct posix_acl *acl;
18919 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18920 + struct au_sxattr *arg);
18923 +/* ---------------------------------------------------------------------- */
18925 +/* lock subclass for iinfo */
18927 + AuLsc_II_CHILD, /* child first */
18928 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18929 + AuLsc_II_CHILD3, /* copyup dirs */
18930 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18931 + AuLsc_II_PARENT2,
18932 + AuLsc_II_PARENT3, /* copyup dirs */
18933 + AuLsc_II_NEW_CHILD
18937 + * ii_read_lock_child, ii_write_lock_child,
18938 + * ii_read_lock_child2, ii_write_lock_child2,
18939 + * ii_read_lock_child3, ii_write_lock_child3,
18940 + * ii_read_lock_parent, ii_write_lock_parent,
18941 + * ii_read_lock_parent2, ii_write_lock_parent2,
18942 + * ii_read_lock_parent3, ii_write_lock_parent3,
18943 + * ii_read_lock_new_child, ii_write_lock_new_child,
18945 +#define AuReadLockFunc(name, lsc) \
18946 +static inline void ii_read_lock_##name(struct inode *i) \
18948 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18951 +#define AuWriteLockFunc(name, lsc) \
18952 +static inline void ii_write_lock_##name(struct inode *i) \
18954 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18957 +#define AuRWLockFuncs(name, lsc) \
18958 + AuReadLockFunc(name, lsc) \
18959 + AuWriteLockFunc(name, lsc)
18961 +AuRWLockFuncs(child, CHILD);
18962 +AuRWLockFuncs(child2, CHILD2);
18963 +AuRWLockFuncs(child3, CHILD3);
18964 +AuRWLockFuncs(parent, PARENT);
18965 +AuRWLockFuncs(parent2, PARENT2);
18966 +AuRWLockFuncs(parent3, PARENT3);
18967 +AuRWLockFuncs(new_child, NEW_CHILD);
18969 +#undef AuReadLockFunc
18970 +#undef AuWriteLockFunc
18971 +#undef AuRWLockFuncs
18973 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18974 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18975 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18977 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18978 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18979 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18981 +/* ---------------------------------------------------------------------- */
18983 +static inline void au_icntnr_init(struct au_icntnr *c)
18985 +#ifdef CONFIG_AUFS_DEBUG
18986 + c->vfs_inode.i_mode = 0;
18990 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18992 + unsigned int gen;
18993 + struct au_iinfo *iinfo;
18994 + struct au_iigen *iigen;
18996 + iinfo = au_ii(inode);
18997 + iigen = &iinfo->ii_generation;
18998 + spin_lock(&iigen->ig_spin);
19000 + *igflags = iigen->ig_flags;
19001 + gen = iigen->ig_generation;
19002 + spin_unlock(&iigen->ig_spin);
19007 +/* tiny test for inode number */
19008 +/* tmpfs generation is too rough */
19009 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19011 + struct au_iinfo *iinfo;
19013 + iinfo = au_ii(inode);
19014 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19015 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19016 + && iinfo->ii_higen == h_inode->i_generation);
19019 +static inline void au_iigen_dec(struct inode *inode)
19021 + struct au_iinfo *iinfo;
19022 + struct au_iigen *iigen;
19024 + iinfo = au_ii(inode);
19025 + iigen = &iinfo->ii_generation;
19026 + spin_lock(&iigen->ig_spin);
19027 + iigen->ig_generation--;
19028 + spin_unlock(&iigen->ig_spin);
19031 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19036 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19042 +/* ---------------------------------------------------------------------- */
19044 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19045 + aufs_bindex_t bindex)
19047 + return iinfo->ii_hinode + bindex;
19050 +static inline int au_is_bad_inode(struct inode *inode)
19052 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19055 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19056 + aufs_bindex_t bindex)
19058 + IiMustAnyLock(inode);
19059 + return au_hinode(au_ii(inode), bindex)->hi_id;
19062 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19064 + IiMustAnyLock(inode);
19065 + return au_ii(inode)->ii_btop;
19068 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19070 + IiMustAnyLock(inode);
19071 + return au_ii(inode)->ii_bbot;
19074 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19076 + IiMustAnyLock(inode);
19077 + return au_ii(inode)->ii_vdir;
19080 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19082 + IiMustAnyLock(inode);
19083 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19086 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19088 + IiMustWriteLock(inode);
19089 + au_ii(inode)->ii_btop = bindex;
19092 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19094 + IiMustWriteLock(inode);
19095 + au_ii(inode)->ii_bbot = bindex;
19098 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19100 + IiMustWriteLock(inode);
19101 + au_ii(inode)->ii_vdir = vdir;
19104 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19106 + IiMustAnyLock(inode);
19107 + return au_hinode(au_ii(inode), bindex);
19110 +/* ---------------------------------------------------------------------- */
19112 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19115 + return pin->parent;
19119 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19121 + if (pin && pin->hdir)
19122 + return pin->hdir->hi_inode;
19126 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19129 + return pin->hdir;
19133 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19136 + pin->dentry = dentry;
19139 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19140 + unsigned char lflag)
19144 + au_fset_pin(pin->flags, DI_LOCKED);
19146 + au_fclr_pin(pin->flags, DI_LOCKED);
19150 +#if 0 /* reserved */
19151 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19154 + dput(pin->parent);
19155 + pin->parent = dget(parent);
19160 +/* ---------------------------------------------------------------------- */
19163 +#ifdef CONFIG_AUFS_HNOTIFY
19164 +struct au_hnotify_op {
19165 + void (*ctl)(struct au_hinode *hinode, int do_set);
19166 + int (*alloc)(struct au_hinode *hinode);
19169 + * if it returns true, the caller should free hinode->hi_notify,
19170 + * otherwise ->free() frees it.
19172 + int (*free)(struct au_hinode *hinode,
19173 + struct au_hnotify *hn) __must_check;
19175 + void (*fin)(void);
19176 + int (*init)(void);
19178 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19179 + void (*fin_br)(struct au_branch *br);
19180 + int (*init_br)(struct au_branch *br, int perm);
19184 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19185 +void au_hn_free(struct au_hinode *hinode);
19186 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19187 +void au_hn_reset(struct inode *inode, unsigned int flags);
19188 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19189 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19190 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19191 +int au_hnotify_init_br(struct au_branch *br, int perm);
19192 +void au_hnotify_fin_br(struct au_branch *br);
19193 +int __init au_hnotify_init(void);
19194 +void au_hnotify_fin(void);
19197 +extern const struct au_hnotify_op au_hnotify_op;
19200 +void au_hn_init(struct au_hinode *hinode)
19202 + hinode->hi_notify = NULL;
19205 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19207 + return hinode->hi_notify;
19211 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19212 + struct au_hinode *hinode __maybe_unused,
19213 + struct inode *inode __maybe_unused)
19214 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19215 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19216 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19217 + int do_set __maybe_unused)
19218 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19219 + unsigned int flags __maybe_unused)
19220 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19221 + struct au_branch *br __maybe_unused,
19222 + int perm __maybe_unused)
19223 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19224 + int perm __maybe_unused)
19225 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19226 +AuStubInt0(__init au_hnotify_init, void)
19227 +AuStubVoid(au_hnotify_fin, void)
19228 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19229 +#endif /* CONFIG_AUFS_HNOTIFY */
19231 +static inline void au_hn_suspend(struct au_hinode *hdir)
19233 + au_hn_ctl(hdir, /*do_set*/0);
19236 +static inline void au_hn_resume(struct au_hinode *hdir)
19238 + au_hn_ctl(hdir, /*do_set*/1);
19241 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19243 + inode_lock(hdir->hi_inode);
19244 + au_hn_suspend(hdir);
19247 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19248 + unsigned int sc __maybe_unused)
19250 + inode_lock_nested(hdir->hi_inode, sc);
19251 + au_hn_suspend(hdir);
19254 +#if 0 /* unused */
19255 +#include "vfsub.h"
19256 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19259 + inode_lock_shared_nested(hdir->hi_inode, sc);
19260 + au_hn_suspend(hdir);
19264 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19266 + au_hn_resume(hdir);
19267 + inode_unlock(hdir->hi_inode);
19270 +#endif /* __KERNEL__ */
19271 +#endif /* __AUFS_INODE_H__ */
19272 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19273 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19274 +++ linux/fs/aufs/ioctl.c 2021-11-01 23:48:34.209692595 +0100
19276 +// SPDX-License-Identifier: GPL-2.0
19278 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19280 + * This program, aufs is free software; you can redistribute it and/or modify
19281 + * it under the terms of the GNU General Public License as published by
19282 + * the Free Software Foundation; either version 2 of the License, or
19283 + * (at your option) any later version.
19285 + * This program is distributed in the hope that it will be useful,
19286 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19287 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19288 + * GNU General Public License for more details.
19290 + * You should have received a copy of the GNU General Public License
19291 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19296 + * plink-management and readdir in userspace.
19297 + * assist the pathconf(3) wrapper library.
19299 + * File-based Hierarchical Storage Management.
19302 +#include <linux/compat.h>
19303 +#include <linux/file.h>
19306 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19309 + aufs_bindex_t wbi, bindex, bbot;
19310 + struct file *h_file;
19311 + struct super_block *sb;
19312 + struct dentry *root;
19313 + struct au_branch *br;
19314 + struct aufs_wbr_fd wbrfd = {
19315 + .oflags = au_dir_roflags,
19318 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19319 + | O_NOATIME | O_CLOEXEC;
19321 + AuDebugOn(wbrfd.oflags & ~valid);
19324 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19325 + if (unlikely(err)) {
19331 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19332 + wbrfd.oflags |= au_dir_roflags;
19333 + AuDbg("0%o\n", wbrfd.oflags);
19334 + if (unlikely(wbrfd.oflags & ~valid))
19338 + fd = get_unused_fd_flags(0);
19340 + if (unlikely(fd < 0))
19343 + h_file = ERR_PTR(-EINVAL);
19346 + sb = path->dentry->d_sb;
19347 + root = sb->s_root;
19348 + aufs_read_lock(root, AuLock_IR);
19349 + bbot = au_sbbot(sb);
19350 + if (wbrfd.brid >= 0) {
19351 + wbi = au_br_index(sb, wbrfd.brid);
19352 + if (unlikely(wbi < 0 || wbi > bbot))
19356 + h_file = ERR_PTR(-ENOENT);
19357 + br = au_sbr(sb, wbi);
19358 + if (!au_br_writable(br->br_perm)) {
19362 + bindex = wbi + 1;
19364 + for (; bindex <= bbot; bindex++) {
19365 + br = au_sbr(sb, bindex);
19366 + if (au_br_writable(br->br_perm)) {
19368 + br = au_sbr(sb, wbi);
19373 + AuDbg("wbi %d\n", wbi);
19375 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19379 + aufs_read_unlock(root, AuLock_IR);
19380 + err = PTR_ERR(h_file);
19381 + if (IS_ERR(h_file))
19384 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19385 + fd_install(fd, h_file);
19387 + goto out; /* success */
19390 + put_unused_fd(fd);
19396 +/* ---------------------------------------------------------------------- */
19398 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19401 + struct dentry *dentry;
19404 + case AUFS_CTL_RDU:
19405 + case AUFS_CTL_RDU_INO:
19406 + err = au_rdu_ioctl(file, cmd, arg);
19409 + case AUFS_CTL_WBR_FD:
19410 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19413 + case AUFS_CTL_IBUSY:
19414 + err = au_ibusy_ioctl(file, arg);
19417 + case AUFS_CTL_BRINFO:
19418 + err = au_brinfo_ioctl(file, arg);
19421 + case AUFS_CTL_FHSM_FD:
19422 + dentry = file->f_path.dentry;
19423 + if (IS_ROOT(dentry))
19424 + err = au_fhsm_fd(dentry->d_sb, arg);
19430 + /* do not call the lower */
19431 + AuDbg("0x%x\n", cmd);
19439 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19444 + case AUFS_CTL_MVDOWN:
19445 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19448 + case AUFS_CTL_WBR_FD:
19449 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19453 + /* do not call the lower */
19454 + AuDbg("0x%x\n", cmd);
19462 +#ifdef CONFIG_COMPAT
19463 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19464 + unsigned long arg)
19469 + case AUFS_CTL_RDU:
19470 + case AUFS_CTL_RDU_INO:
19471 + err = au_rdu_compat_ioctl(file, cmd, arg);
19474 + case AUFS_CTL_IBUSY:
19475 + err = au_ibusy_compat_ioctl(file, arg);
19478 + case AUFS_CTL_BRINFO:
19479 + err = au_brinfo_compat_ioctl(file, arg);
19483 + err = aufs_ioctl_dir(file, cmd, arg);
19490 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19491 + unsigned long arg)
19493 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19496 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19497 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19498 +++ linux/fs/aufs/i_op_add.c 2021-11-01 23:48:34.209692595 +0100
19500 +// SPDX-License-Identifier: GPL-2.0
19502 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19504 + * This program, aufs is free software; you can redistribute it and/or modify
19505 + * it under the terms of the GNU General Public License as published by
19506 + * the Free Software Foundation; either version 2 of the License, or
19507 + * (at your option) any later version.
19509 + * This program is distributed in the hope that it will be useful,
19510 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19511 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19512 + * GNU General Public License for more details.
19514 + * You should have received a copy of the GNU General Public License
19515 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19519 + * inode operations (add entry)
19522 +#include <linux/iversion.h>
19526 + * final procedure of adding a new entry, except link(2).
19527 + * remove whiteout, instantiate, copyup the parent dir's times and size
19528 + * and update version.
19529 + * if it failed, re-create the removed whiteout.
19531 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19532 + struct dentry *wh_dentry, struct dentry *dentry)
19535 + aufs_bindex_t bwh;
19536 + struct path h_path;
19537 + struct super_block *sb;
19538 + struct inode *inode, *h_dir;
19539 + struct dentry *wh;
19544 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19545 + IMustLock(h_dir);
19546 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19547 + bwh = au_dbwh(dentry);
19548 + h_path.dentry = wh_dentry;
19549 + h_path.mnt = au_sbr_mnt(sb, bindex);
19550 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19552 + if (unlikely(err))
19556 + inode = au_new_inode(dentry, /*must_new*/1);
19557 + if (!IS_ERR(inode)) {
19558 + d_instantiate(dentry, inode);
19559 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19561 + au_dir_ts(dir, bindex);
19562 + inode_inc_iversion(dir);
19563 + au_fhsm_wrote(sb, bindex, /*force*/0);
19564 + return 0; /* success */
19567 + err = PTR_ERR(inode);
19572 + /* dir inode is locked */
19573 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19574 + rerr = PTR_ERR(wh);
19575 + if (IS_ERR(wh)) {
19576 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19577 + dentry, err, rerr);
19586 +static int au_d_may_add(struct dentry *dentry)
19591 + if (unlikely(d_unhashed(dentry)))
19593 + if (unlikely(d_really_is_positive(dentry)))
19599 + * simple tests for the adding inode operations.
19600 + * following the checks in vfs, plus the parent-child relationship.
19602 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19603 + struct dentry *h_parent, int isdir)
19607 + struct dentry *h_dentry;
19608 + struct inode *h_inode;
19610 + err = -ENAMETOOLONG;
19611 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19614 + h_dentry = au_h_dptr(dentry, bindex);
19615 + if (d_really_is_negative(dentry)) {
19617 + if (unlikely(d_is_positive(h_dentry)))
19620 + /* rename(2) case */
19622 + if (unlikely(d_is_negative(h_dentry)))
19624 + h_inode = d_inode(h_dentry);
19625 + if (unlikely(!h_inode->i_nlink))
19628 + h_mode = h_inode->i_mode;
19631 + if (unlikely(S_ISDIR(h_mode)))
19633 + } else if (unlikely(!S_ISDIR(h_mode))) {
19640 + /* expected parent dir is locked */
19641 + if (unlikely(h_parent != h_dentry->d_parent))
19650 + * initial procedure of adding a new entry.
19651 + * prepare writable branch and the parent dir, lock it,
19652 + * and lookup whiteout for the new entry.
19654 +static struct dentry*
19655 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19656 + struct dentry *src_dentry, struct au_pin *pin,
19657 + struct au_wr_dir_args *wr_dir_args)
19659 + struct dentry *wh_dentry, *h_parent;
19660 + struct super_block *sb;
19661 + struct au_branch *br;
19663 + unsigned int udba;
19664 + aufs_bindex_t bcpup;
19666 + AuDbg("%pd\n", dentry);
19668 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19670 + wh_dentry = ERR_PTR(err);
19671 + if (unlikely(err < 0))
19674 + sb = dentry->d_sb;
19675 + udba = au_opt_udba(sb);
19676 + err = au_pin(pin, dentry, bcpup, udba,
19677 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19678 + wh_dentry = ERR_PTR(err);
19679 + if (unlikely(err))
19682 + h_parent = au_pinned_h_parent(pin);
19683 + if (udba != AuOpt_UDBA_NONE
19684 + && au_dbtop(dentry) == bcpup)
19685 + err = au_may_add(dentry, bcpup, h_parent,
19686 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19687 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19688 + err = -ENAMETOOLONG;
19689 + wh_dentry = ERR_PTR(err);
19690 + if (unlikely(err))
19693 + br = au_sbr(sb, bcpup);
19695 + struct path tmp = {
19696 + .dentry = h_parent,
19697 + .mnt = au_br_mnt(br)
19699 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19702 + wh_dentry = NULL;
19703 + if (bcpup != au_dbwh(dentry))
19704 + goto out; /* success */
19707 + * ENAMETOOLONG here means that if we allowed create such name, then it
19708 + * would not be able to removed in the future. So we don't allow such
19709 + * name here and we don't handle ENAMETOOLONG differently here.
19711 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19714 + if (IS_ERR(wh_dentry))
19717 + return wh_dentry;
19720 +/* ---------------------------------------------------------------------- */
19722 +enum { Mknod, Symlink, Creat };
19723 +struct simple_arg {
19730 + struct vfsub_aopen_args *aopen;
19733 + const char *symname;
19742 +static int add_simple(struct inode *dir, struct dentry *dentry,
19743 + struct simple_arg *arg)
19746 + aufs_bindex_t btop;
19747 + unsigned char created;
19748 + const unsigned char try_aopen
19749 + = (arg->type == Creat && arg->u.c.try_aopen);
19750 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19751 + struct dentry *wh_dentry, *parent;
19752 + struct inode *h_dir;
19753 + struct super_block *sb;
19754 + struct au_branch *br;
19755 + /* to reduce stack size */
19757 + struct au_dtime dt;
19758 + struct au_pin pin;
19759 + struct path h_path;
19760 + struct au_wr_dir_args wr_dir_args;
19763 + AuDbg("%pd\n", dentry);
19767 + a = kmalloc(sizeof(*a), GFP_NOFS);
19768 + if (unlikely(!a))
19770 + a->wr_dir_args.force_btgt = -1;
19771 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19773 + parent = dentry->d_parent; /* dir inode is locked */
19774 + if (!try_aopen) {
19775 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19776 + if (unlikely(err))
19779 + err = au_d_may_add(dentry);
19780 + if (unlikely(err))
19783 + di_write_lock_parent(parent);
19784 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19785 + &a->pin, &a->wr_dir_args);
19786 + err = PTR_ERR(wh_dentry);
19787 + if (IS_ERR(wh_dentry))
19790 + btop = au_dbtop(dentry);
19791 + sb = dentry->d_sb;
19792 + br = au_sbr(sb, btop);
19793 + a->h_path.dentry = au_h_dptr(dentry, btop);
19794 + a->h_path.mnt = au_br_mnt(br);
19795 + h_dir = au_pinned_h_dir(&a->pin);
19796 + switch (arg->type) {
19798 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19799 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19800 + arg->u.c.want_excl);
19802 + if (!err && try_aopen)
19803 + aopen->file->f_mode |= FMODE_CREATED;
19806 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19807 + AuDbg("err %d\n", err);
19808 + AuDbgFile(aopen->file);
19809 + created = err >= 0
19810 + && !!(aopen->file->f_mode & FMODE_CREATED);
19814 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19818 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19825 + if (unlikely(err < 0))
19828 + err = epilog(dir, btop, wh_dentry, dentry);
19830 + goto out_unpin; /* success */
19833 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19834 + /* no delegation since it is just created */
19835 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19838 + AuIOErr("%pd revert failure(%d, %d)\n",
19839 + dentry, err, rerr);
19842 + au_dtime_revert(&a->dt);
19844 + if (try_aopen && h_dir->i_op->atomic_open
19845 + && (aopen->file->f_mode & FMODE_OPENED))
19846 + /* aopen->file is still opened */
19847 + au_lcnt_dec(&aopen->br->br_nfiles);
19850 + au_unpin(&a->pin);
19854 + di_write_unlock(parent);
19856 + if (unlikely(err)) {
19857 + au_update_dbtop(dentry);
19861 + aufs_read_unlock(dentry, AuLock_DW);
19868 +int aufs_mknod(struct user_namespace *userns, struct inode *dir,
19869 + struct dentry *dentry, umode_t mode, dev_t dev)
19871 + struct simple_arg arg = {
19878 + return add_simple(dir, dentry, &arg);
19881 +int aufs_symlink(struct user_namespace *userns, struct inode *dir,
19882 + struct dentry *dentry, const char *symname)
19884 + struct simple_arg arg = {
19886 + .u.s.symname = symname
19888 + return add_simple(dir, dentry, &arg);
19891 +int aufs_create(struct user_namespace *userns, struct inode *dir,
19892 + struct dentry *dentry, umode_t mode, bool want_excl)
19894 + struct simple_arg arg = {
19898 + .want_excl = want_excl
19901 + return add_simple(dir, dentry, &arg);
19904 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19905 + struct vfsub_aopen_args *aopen_args)
19907 + struct simple_arg arg = {
19910 + .mode = aopen_args->create_mode,
19911 + .want_excl = aopen_args->open_flag & O_EXCL,
19912 + .try_aopen = true,
19913 + .aopen = aopen_args
19916 + return add_simple(dir, dentry, &arg);
19919 +int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
19920 + struct dentry *dentry, umode_t mode)
19923 + aufs_bindex_t bindex;
19924 + struct super_block *sb;
19925 + struct dentry *parent, *h_parent, *h_dentry;
19926 + struct inode *h_dir, *inode;
19927 + struct vfsmount *h_mnt;
19928 + struct user_namespace *h_userns;
19929 + struct au_wr_dir_args wr_dir_args = {
19930 + .force_btgt = -1,
19931 + .flags = AuWrDir_TMPFILE
19934 + /* copy-up may happen */
19938 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19939 + if (unlikely(err))
19942 + err = au_di_init(dentry);
19943 + if (unlikely(err))
19947 + parent = d_find_any_alias(dir);
19948 + AuDebugOn(!parent);
19949 + di_write_lock_parent(parent);
19950 + if (unlikely(d_inode(parent) != dir))
19953 + err = au_digen_test(parent, au_sigen(sb));
19954 + if (unlikely(err))
19957 + bindex = au_dbtop(parent);
19958 + au_set_dbtop(dentry, bindex);
19959 + au_set_dbbot(dentry, bindex);
19960 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19962 + if (unlikely(err < 0))
19965 + err = -EOPNOTSUPP;
19966 + h_dir = au_h_iptr(dir, bindex);
19967 + if (unlikely(!h_dir->i_op->tmpfile))
19970 + h_mnt = au_sbr_mnt(sb, bindex);
19971 + err = vfsub_mnt_want_write(h_mnt);
19972 + if (unlikely(err))
19975 + h_userns = mnt_user_ns(h_mnt);
19976 + h_parent = au_h_dptr(parent, bindex);
19977 + h_dentry = vfs_tmpfile(h_userns, h_parent, mode, /*open_flag*/0);
19978 + if (IS_ERR(h_dentry)) {
19979 + err = PTR_ERR(h_dentry);
19983 + au_set_dbtop(dentry, bindex);
19984 + au_set_dbbot(dentry, bindex);
19985 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19986 + inode = au_new_inode(dentry, /*must_new*/1);
19987 + if (IS_ERR(inode)) {
19988 + err = PTR_ERR(inode);
19989 + au_set_h_dptr(dentry, bindex, NULL);
19990 + au_set_dbtop(dentry, -1);
19991 + au_set_dbbot(dentry, -1);
19993 + if (!inode->i_nlink)
19994 + set_nlink(inode, 1);
19995 + d_tmpfile(dentry, inode);
19996 + au_di(dentry)->di_tmpfile = 1;
19998 + /* update without i_mutex */
19999 + if (au_ibtop(dir) == au_dbtop(dentry))
20000 + au_cpup_attr_timesizes(dir);
20005 + vfsub_mnt_drop_write(h_mnt);
20007 + di_write_unlock(parent);
20009 + di_write_unlock(dentry);
20010 + if (unlikely(err)) {
20011 + au_di_fin(dentry);
20012 + dentry->d_fsdata = NULL;
20015 + si_read_unlock(sb);
20017 + inode_unlock(dir);
20021 +/* ---------------------------------------------------------------------- */
20023 +struct au_link_args {
20024 + aufs_bindex_t bdst, bsrc;
20025 + struct au_pin pin;
20026 + struct path h_path;
20027 + struct dentry *src_parent, *parent;
20030 +static int au_cpup_before_link(struct dentry *src_dentry,
20031 + struct au_link_args *a)
20034 + struct dentry *h_src_dentry;
20035 + struct au_cp_generic cpg = {
20036 + .dentry = src_dentry,
20041 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20044 + di_read_lock_parent(a->src_parent, AuLock_IR);
20045 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20046 + if (unlikely(err))
20049 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20050 + err = au_pin(&a->pin, src_dentry, a->bdst,
20051 + au_opt_udba(src_dentry->d_sb),
20052 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20053 + if (unlikely(err))
20056 + err = au_sio_cpup_simple(&cpg);
20057 + au_unpin(&a->pin);
20060 + di_read_unlock(a->src_parent, AuLock_IR);
20064 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20065 + struct au_link_args *a)
20068 + unsigned char plink;
20069 + aufs_bindex_t bbot;
20070 + struct dentry *h_src_dentry;
20071 + struct inode *h_inode, *inode, *delegated;
20072 + struct super_block *sb;
20073 + struct file *h_file;
20077 + sb = src_dentry->d_sb;
20078 + inode = d_inode(src_dentry);
20079 + if (au_ibtop(inode) <= a->bdst)
20080 + h_inode = au_h_iptr(inode, a->bdst);
20081 + if (!h_inode || !h_inode->i_nlink) {
20082 + /* copyup src_dentry as the name of dentry. */
20083 + bbot = au_dbbot(dentry);
20084 + if (bbot < a->bsrc)
20085 + au_set_dbbot(dentry, a->bsrc);
20086 + au_set_h_dptr(dentry, a->bsrc,
20087 + dget(au_h_dptr(src_dentry, a->bsrc)));
20088 + dget(a->h_path.dentry);
20089 + au_set_h_dptr(dentry, a->bdst, NULL);
20090 + AuDbg("temporary d_inode...\n");
20091 + spin_lock(&dentry->d_lock);
20092 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20093 + spin_unlock(&dentry->d_lock);
20094 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20095 + if (IS_ERR(h_file))
20096 + err = PTR_ERR(h_file);
20098 + struct au_cp_generic cpg = {
20099 + .dentry = dentry,
20104 + .flags = AuCpup_KEEPLINO
20106 + err = au_sio_cpup_simple(&cpg);
20107 + au_h_open_post(dentry, a->bsrc, h_file);
20109 + dput(a->h_path.dentry);
20110 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20112 + au_set_h_dptr(dentry, a->bdst,
20113 + a->h_path.dentry);
20115 + spin_lock(&dentry->d_lock);
20116 + dentry->d_inode = NULL; /* restore */
20117 + spin_unlock(&dentry->d_lock);
20118 + AuDbg("temporary d_inode...done\n");
20119 + au_set_h_dptr(dentry, a->bsrc, NULL);
20120 + au_set_dbbot(dentry, bbot);
20122 + /* the inode of src_dentry already exists on a.bdst branch */
20123 + h_src_dentry = d_find_alias(h_inode);
20124 + if (!h_src_dentry && au_plink_test(inode)) {
20126 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20127 + err = PTR_ERR(h_src_dentry);
20128 + if (IS_ERR(h_src_dentry))
20131 + if (unlikely(d_is_negative(h_src_dentry))) {
20132 + dput(h_src_dentry);
20133 + h_src_dentry = NULL;
20137 + if (h_src_dentry) {
20138 + delegated = NULL;
20139 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20140 + &a->h_path, &delegated);
20141 + if (unlikely(err == -EWOULDBLOCK)) {
20142 + pr_warn("cannot retry for NFSv4 delegation"
20143 + " for an internal link\n");
20146 + dput(h_src_dentry);
20148 + AuIOErr("no dentry found for hi%lu on b%d\n",
20149 + h_inode->i_ino, a->bdst);
20154 + if (!err && !plink)
20155 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20162 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20163 + struct dentry *dentry)
20166 + struct au_dtime dt;
20167 + struct au_link_args *a;
20168 + struct dentry *wh_dentry, *h_src_dentry;
20169 + struct inode *inode, *delegated;
20170 + struct super_block *sb;
20171 + struct au_wr_dir_args wr_dir_args = {
20172 + /* .force_btgt = -1, */
20173 + .flags = AuWrDir_ADD_ENTRY
20177 + inode = d_inode(src_dentry);
20178 + IMustLock(inode);
20181 + a = kzalloc(sizeof(*a), GFP_NOFS);
20182 + if (unlikely(!a))
20185 + a->parent = dentry->d_parent; /* dir inode is locked */
20186 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20187 + AuLock_NOPLM | AuLock_GEN);
20188 + if (unlikely(err))
20190 + err = au_d_linkable(src_dentry);
20191 + if (unlikely(err))
20193 + err = au_d_may_add(dentry);
20194 + if (unlikely(err))
20197 + a->src_parent = dget_parent(src_dentry);
20198 + wr_dir_args.force_btgt = au_ibtop(inode);
20200 + di_write_lock_parent(a->parent);
20201 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20202 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20204 + err = PTR_ERR(wh_dentry);
20205 + if (IS_ERR(wh_dentry))
20209 + sb = dentry->d_sb;
20210 + a->bdst = au_dbtop(dentry);
20211 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20212 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20213 + a->bsrc = au_ibtop(inode);
20214 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20215 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20216 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20217 + if (!h_src_dentry) {
20218 + a->bsrc = au_dbtop(src_dentry);
20219 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20220 + AuDebugOn(!h_src_dentry);
20221 + } else if (IS_ERR(h_src_dentry)) {
20222 + err = PTR_ERR(h_src_dentry);
20227 + * aufs doesn't touch the credential so
20228 + * security_dentry_create_files_as() is unnecessary.
20230 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20231 + if (a->bdst < a->bsrc
20232 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20233 + err = au_cpup_or_link(src_dentry, dentry, a);
20235 + delegated = NULL;
20236 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20237 + &a->h_path, &delegated);
20238 + if (unlikely(err == -EWOULDBLOCK)) {
20239 + pr_warn("cannot retry for NFSv4 delegation"
20240 + " for an internal link\n");
20244 + dput(h_src_dentry);
20247 + * copyup src_dentry to the branch we process,
20248 + * and then link(2) to it.
20250 + dput(h_src_dentry);
20251 + if (a->bdst < a->bsrc
20252 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20253 + au_unpin(&a->pin);
20254 + di_write_unlock(a->parent);
20255 + err = au_cpup_before_link(src_dentry, a);
20256 + di_write_lock_parent(a->parent);
20258 + err = au_pin(&a->pin, dentry, a->bdst,
20260 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20261 + if (unlikely(err))
20265 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20267 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20268 + delegated = NULL;
20269 + err = vfsub_link(h_src_dentry,
20270 + au_pinned_h_dir(&a->pin),
20271 + &a->h_path, &delegated);
20272 + if (unlikely(err == -EWOULDBLOCK)) {
20273 + pr_warn("cannot retry"
20274 + " for NFSv4 delegation"
20275 + " for an internal link\n");
20281 + if (unlikely(err))
20285 + a->h_path.dentry = wh_dentry;
20286 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20288 + if (unlikely(err))
20292 + au_dir_ts(dir, a->bdst);
20293 + inode_inc_iversion(dir);
20294 + inc_nlink(inode);
20295 + inode->i_ctime = dir->i_ctime;
20296 + d_instantiate(dentry, au_igrab(inode));
20297 + if (d_unhashed(a->h_path.dentry))
20298 + /* some filesystem calls d_drop() */
20300 + /* some filesystems consume an inode even hardlink */
20301 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20302 + goto out_unpin; /* success */
20305 + /* no delegation since it is just created */
20306 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20307 + /*delegated*/NULL, /*force*/0);
20308 + if (unlikely(rerr)) {
20309 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20312 + au_dtime_revert(&dt);
20314 + au_unpin(&a->pin);
20318 + di_write_unlock(a->parent);
20319 + dput(a->src_parent);
20321 + if (unlikely(err)) {
20322 + au_update_dbtop(dentry);
20325 + aufs_read_and_write_unlock2(dentry, src_dentry);
20333 +int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
20334 + struct dentry *dentry, umode_t mode)
20337 + aufs_bindex_t bindex;
20338 + unsigned char diropq;
20339 + struct path h_path;
20340 + struct dentry *wh_dentry, *parent, *opq_dentry;
20341 + struct inode *h_inode;
20342 + struct super_block *sb;
20344 + struct au_pin pin;
20345 + struct au_dtime dt;
20346 + } *a; /* reduce the stack usage */
20347 + struct au_wr_dir_args wr_dir_args = {
20348 + .force_btgt = -1,
20349 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20355 + a = kmalloc(sizeof(*a), GFP_NOFS);
20356 + if (unlikely(!a))
20359 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20360 + if (unlikely(err))
20362 + err = au_d_may_add(dentry);
20363 + if (unlikely(err))
20366 + parent = dentry->d_parent; /* dir inode is locked */
20367 + di_write_lock_parent(parent);
20368 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20369 + &a->pin, &wr_dir_args);
20370 + err = PTR_ERR(wh_dentry);
20371 + if (IS_ERR(wh_dentry))
20374 + sb = dentry->d_sb;
20375 + bindex = au_dbtop(dentry);
20376 + h_path.dentry = au_h_dptr(dentry, bindex);
20377 + h_path.mnt = au_sbr_mnt(sb, bindex);
20378 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20379 + if (unlikely(err))
20382 + /* make the dir opaque */
20384 + h_inode = d_inode(h_path.dentry);
20386 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20387 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20388 + opq_dentry = au_diropq_create(dentry, bindex);
20389 + inode_unlock(h_inode);
20390 + err = PTR_ERR(opq_dentry);
20391 + if (IS_ERR(opq_dentry))
20393 + dput(opq_dentry);
20397 + err = epilog(dir, bindex, wh_dentry, dentry);
20400 + goto out_unpin; /* success */
20405 + AuLabel(revert opq);
20406 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20407 + rerr = au_diropq_remove(dentry, bindex);
20408 + inode_unlock(h_inode);
20410 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20411 + dentry, err, rerr);
20417 + AuLabel(revert dir);
20418 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20420 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20421 + dentry, err, rerr);
20424 + au_dtime_revert(&a->dt);
20426 + au_unpin(&a->pin);
20429 + di_write_unlock(parent);
20431 + if (unlikely(err)) {
20432 + au_update_dbtop(dentry);
20435 + aufs_read_unlock(dentry, AuLock_DW);
20441 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20442 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20443 +++ linux/fs/aufs/i_op.c 2021-11-01 23:48:34.209692595 +0100
20445 +// SPDX-License-Identifier: GPL-2.0
20447 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20449 + * This program, aufs is free software; you can redistribute it and/or modify
20450 + * it under the terms of the GNU General Public License as published by
20451 + * the Free Software Foundation; either version 2 of the License, or
20452 + * (at your option) any later version.
20454 + * This program is distributed in the hope that it will be useful,
20455 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20457 + * GNU General Public License for more details.
20459 + * You should have received a copy of the GNU General Public License
20460 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20464 + * inode operations (except add/del/rename)
20467 +#include <linux/device_cgroup.h>
20468 +#include <linux/fs_stack.h>
20469 +#include <linux/iversion.h>
20470 +#include <linux/namei.h>
20471 +#include <linux/security.h>
20474 +static int h_permission(struct inode *h_inode, int mask,
20475 + struct path *h_path, int brperm)
20478 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20479 + struct user_namespace *h_userns;
20482 + if (write_mask && IS_IMMUTABLE(h_inode))
20486 + if (((mask & MAY_EXEC)
20487 + && S_ISREG(h_inode->i_mode)
20488 + && (path_noexec(h_path)
20489 + || !(h_inode->i_mode & 0111))))
20493 + * - skip the lower fs test in the case of write to ro branch.
20494 + * - nfs dir permission write check is optimized, but a policy for
20495 + * link/rename requires a real check.
20496 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20497 + * in this case, generic_permission() returns -EOPNOTSUPP.
20499 + h_userns = mnt_user_ns(h_path->mnt);
20500 + if ((write_mask && !au_br_writable(brperm))
20501 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20502 + && write_mask && !(mask & MAY_READ))
20503 + || !h_inode->i_op->permission) {
20504 + /* AuLabel(generic_permission); */
20505 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20506 + err = generic_permission(h_userns, h_inode, mask);
20507 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20508 + err = h_inode->i_op->permission(h_userns, h_inode,
20512 + /* AuLabel(h_inode->permission); */
20513 + err = h_inode->i_op->permission(h_userns, h_inode, mask);
20518 + err = devcgroup_inode_permission(h_inode, mask);
20520 + err = security_inode_permission(h_inode, mask);
20526 +static int aufs_permission(struct user_namespace *userns, struct inode *inode,
20530 + aufs_bindex_t bindex, bbot;
20531 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20532 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20533 + struct inode *h_inode;
20534 + struct super_block *sb;
20535 + struct au_branch *br;
20537 + /* todo: support rcu-walk? */
20538 + if (mask & MAY_NOT_BLOCK)
20541 + sb = inode->i_sb;
20542 + si_read_lock(sb, AuLock_FLUSH);
20543 + ii_read_lock_child(inode);
20544 +#if 0 /* reserved for future use */
20546 + * This test may be rather 'too much' since the test is essentially done
20547 + * in the aufs_lookup(). Theoretically it is possible that the inode
20548 + * generation doesn't match to the superblock's here. But it isn't a
20549 + * big deal I suppose.
20551 + err = au_iigen_test(inode, au_sigen(sb));
20552 + if (unlikely(err))
20558 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20559 + err = au_busy_or_stale();
20560 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20561 + if (unlikely(!h_inode
20562 + || (h_inode->i_mode & S_IFMT)
20563 + != (inode->i_mode & S_IFMT)))
20567 + bindex = au_ibtop(inode);
20568 + br = au_sbr(sb, bindex);
20569 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20572 + && !special_file(h_inode->i_mode)) {
20573 + /* test whether the upper writable branch exists */
20575 + for (; bindex >= 0; bindex--)
20576 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20584 + /* non-write to dir */
20586 + bbot = au_ibbot(inode);
20587 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20588 + h_inode = au_h_iptr(inode, bindex);
20590 + err = au_busy_or_stale();
20591 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20594 + br = au_sbr(sb, bindex);
20595 + err = h_permission(h_inode, mask, &br->br_path,
20601 + ii_read_unlock(inode);
20602 + si_read_unlock(sb);
20606 +/* ---------------------------------------------------------------------- */
20608 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20609 + unsigned int flags)
20611 + struct dentry *ret, *parent;
20612 + struct inode *inode;
20613 + struct super_block *sb;
20614 + int err, npositive;
20618 + /* todo: support rcu-walk? */
20619 + ret = ERR_PTR(-ECHILD);
20620 + if (flags & LOOKUP_RCU)
20623 + ret = ERR_PTR(-ENAMETOOLONG);
20624 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20628 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20629 + ret = ERR_PTR(err);
20630 + if (unlikely(err))
20633 + err = au_di_init(dentry);
20634 + ret = ERR_PTR(err);
20635 + if (unlikely(err))
20639 + npositive = 0; /* suppress a warning */
20640 + parent = dentry->d_parent; /* dir inode is locked */
20641 + di_read_lock_parent(parent, AuLock_IR);
20642 + err = au_alive_dir(parent);
20644 + err = au_digen_test(parent, au_sigen(sb));
20646 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20647 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20648 + AuLkup_ALLOW_NEG);
20651 + di_read_unlock(parent, AuLock_IR);
20652 + ret = ERR_PTR(err);
20653 + if (unlikely(err < 0))
20657 + inode = au_new_inode(dentry, /*must_new*/0);
20658 + if (IS_ERR(inode)) {
20659 + ret = (void *)inode;
20666 + atomic_inc(&inode->i_count);
20667 + ret = d_splice_alias(inode, dentry);
20668 +#if 0 /* reserved for future use */
20669 + if (unlikely(d_need_lookup(dentry))) {
20670 + spin_lock(&dentry->d_lock);
20671 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20672 + spin_unlock(&dentry->d_lock);
20676 + if (!IS_ERR(ret)) {
20678 + if (ret && ret != dentry)
20679 + ii_write_unlock(inode);
20681 + ii_write_unlock(inode);
20688 + di_write_unlock(dentry);
20690 + si_read_unlock(sb);
20695 +/* ---------------------------------------------------------------------- */
20698 + * very dirty and complicated aufs ->atomic_open().
20699 + * aufs_atomic_open()
20700 + * + au_aopen_or_create()
20702 + * + vfsub_atomic_open()
20703 + * + branch fs ->atomic_open()
20704 + * may call the actual 'open' for h_file
20705 + * + inc br_nfiles only if opened
20706 + * + au_aopen_no_open() or au_aopen_do_open()
20708 + * au_aopen_do_open()
20709 + * + finish_open()
20710 + * + au_do_aopen()
20711 + * + au_do_open() the body of all 'open'
20712 + * + au_do_open_nondir()
20713 + * set the passed h_file
20715 + * au_aopen_no_open()
20716 + * + finish_no_open()
20719 +struct aopen_node {
20720 + struct hlist_bl_node hblist;
20721 + struct file *file, *h_file;
20724 +static int au_do_aopen(struct inode *inode, struct file *file)
20726 + struct hlist_bl_head *aopen;
20727 + struct hlist_bl_node *pos;
20728 + struct aopen_node *node;
20729 + struct au_do_open_args args = {
20731 + .open = au_do_open_nondir
20734 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20735 + hlist_bl_lock(aopen);
20736 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20737 + if (node->file == file) {
20738 + args.h_file = node->h_file;
20741 + hlist_bl_unlock(aopen);
20742 + /* AuDebugOn(!args.h_file); */
20744 + return au_do_open(file, &args);
20747 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20748 + struct aopen_node *aopen_node)
20751 + struct hlist_bl_head *aopen;
20754 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20755 + au_hbl_add(&aopen_node->hblist, aopen);
20756 + err = finish_open(file, dentry, au_do_aopen);
20757 + au_hbl_del(&aopen_node->hblist, aopen);
20758 + /* AuDbgFile(file); */
20759 + AuDbg("%pd%s%s\n", dentry,
20760 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20761 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20767 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20773 + err = finish_no_open(file, dentry);
20779 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20780 + struct file *file, unsigned int open_flag,
20781 + umode_t create_mode)
20783 + int err, did_open;
20784 + unsigned int lkup_flags;
20785 + aufs_bindex_t bindex;
20786 + struct super_block *sb;
20787 + struct dentry *parent, *d;
20788 + struct vfsub_aopen_args args = {
20789 + .open_flag = open_flag,
20790 + .create_mode = create_mode
20792 + struct aopen_node aopen_node = {
20797 + AuDbg("open_flag 0%o\n", open_flag);
20798 + AuDbgDentry(dentry);
20801 + if (!au_di(dentry)) {
20802 + lkup_flags = LOOKUP_OPEN;
20803 + if (open_flag & O_CREAT)
20804 + lkup_flags |= LOOKUP_CREATE;
20805 + d = aufs_lookup(dir, dentry, lkup_flags);
20807 + err = PTR_ERR(d);
20812 + * obsoleted dentry found.
20813 + * another error will be returned later.
20819 + AuDbgDentry(dentry);
20822 + if (d_is_positive(dentry)
20823 + || d_unhashed(dentry)
20824 + || d_unlinked(dentry)
20825 + || !(open_flag & O_CREAT)) {
20826 + err = au_aopen_no_open(file, dentry);
20827 + goto out; /* success */
20830 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20831 + if (unlikely(err))
20834 + sb = dentry->d_sb;
20835 + parent = dentry->d_parent; /* dir is locked */
20836 + di_write_lock_parent(parent);
20837 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20838 + if (unlikely(err < 0))
20841 + AuDbgDentry(dentry);
20842 + if (d_is_positive(dentry)) {
20843 + err = au_aopen_no_open(file, dentry);
20844 + goto out_parent; /* success */
20847 + args.file = alloc_empty_file(file->f_flags, current_cred());
20848 + err = PTR_ERR(args.file);
20849 + if (IS_ERR(args.file))
20852 + bindex = au_dbtop(dentry);
20853 + err = au_aopen_or_create(dir, dentry, &args);
20855 + AuDbgFile(args.file);
20856 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20857 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20860 + args.file = NULL;
20862 + di_write_unlock(parent);
20863 + di_write_unlock(dentry);
20864 + if (unlikely(err < 0)) {
20871 + err = au_aopen_no_open(file, dentry);
20873 + aopen_node.h_file = args.file;
20874 + err = au_aopen_do_open(file, dentry, &aopen_node);
20876 + if (unlikely(err < 0)) {
20880 + au_lcnt_dec(&args.br->br_nfiles);
20882 + goto out_sb; /* success */
20885 + di_write_unlock(parent);
20886 + di_write_unlock(dentry);
20888 + si_read_unlock(sb);
20896 +/* ---------------------------------------------------------------------- */
20898 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20899 + const unsigned char add_entry, aufs_bindex_t bcpup,
20900 + aufs_bindex_t btop)
20903 + struct dentry *h_parent;
20904 + struct inode *h_dir;
20907 + IMustLock(d_inode(parent));
20909 + di_write_lock_parent(parent);
20912 + if (!au_h_dptr(parent, bcpup)) {
20913 + if (btop > bcpup)
20914 + err = au_cpup_dirs(dentry, bcpup);
20915 + else if (btop < bcpup)
20916 + err = au_cpdown_dirs(dentry, bcpup);
20920 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20921 + h_parent = au_h_dptr(parent, bcpup);
20922 + h_dir = d_inode(h_parent);
20923 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20924 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20925 + /* todo: no unlock here */
20926 + inode_unlock_shared(h_dir);
20928 + AuDbg("bcpup %d\n", bcpup);
20930 + if (d_really_is_negative(dentry))
20931 + au_set_h_dptr(dentry, btop, NULL);
20932 + au_update_dbrange(dentry, /*do_put_zero*/0);
20937 + di_write_unlock(parent);
20939 + err = bcpup; /* success */
20946 + * decide the branch and the parent dir where we will create a new entry.
20947 + * returns new bindex or an error.
20948 + * copyup the parent dir if needed.
20950 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20951 + struct au_wr_dir_args *args)
20954 + unsigned int flags;
20955 + aufs_bindex_t bcpup, btop, src_btop;
20956 + const unsigned char add_entry
20957 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20958 + | au_ftest_wrdir(args->flags, TMPFILE);
20959 + struct super_block *sb;
20960 + struct dentry *parent;
20961 + struct au_sbinfo *sbinfo;
20963 + sb = dentry->d_sb;
20964 + sbinfo = au_sbi(sb);
20965 + parent = dget_parent(dentry);
20966 + btop = au_dbtop(dentry);
20968 + if (args->force_btgt < 0) {
20969 + if (src_dentry) {
20970 + src_btop = au_dbtop(src_dentry);
20971 + if (src_btop < btop)
20972 + bcpup = src_btop;
20973 + } else if (add_entry) {
20975 + if (au_ftest_wrdir(args->flags, ISDIR))
20976 + au_fset_wbr(flags, DIR);
20977 + err = AuWbrCreate(sbinfo, dentry, flags);
20981 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20983 + err = AuWbrCopyup(sbinfo, dentry);
20985 + if (!IS_ROOT(dentry)) {
20986 + di_read_lock_parent(parent, !AuLock_IR);
20987 + err = AuWbrCopyup(sbinfo, dentry);
20988 + di_read_unlock(parent, !AuLock_IR);
20990 + err = AuWbrCopyup(sbinfo, dentry);
20993 + if (unlikely(err < 0))
20997 + bcpup = args->force_btgt;
20998 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
21001 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
21003 + if (bcpup == btop)
21004 + goto out; /* success */
21006 + /* copyup the new parent into the branch we process */
21007 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
21009 + if (d_really_is_negative(dentry)) {
21010 + au_set_h_dptr(dentry, btop, NULL);
21011 + au_set_dbtop(dentry, bcpup);
21012 + au_set_dbbot(dentry, bcpup);
21014 + AuDebugOn(add_entry
21015 + && !au_ftest_wrdir(args->flags, TMPFILE)
21016 + && !au_h_dptr(dentry, bcpup));
21024 +/* ---------------------------------------------------------------------- */
21026 +void au_pin_hdir_unlock(struct au_pin *p)
21029 + au_hn_inode_unlock(p->hdir);
21032 +int au_pin_hdir_lock(struct au_pin *p)
21040 + /* even if an error happens later, keep this lock */
21041 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21044 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21049 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21050 + p->h_parent, p->br);
21056 +int au_pin_hdir_relock(struct au_pin *p)
21059 + struct inode *h_i;
21060 + struct dentry *h_d[] = {
21065 + err = au_pin_hdir_lock(p);
21066 + if (unlikely(err))
21069 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21072 + if (d_is_positive(h_d[i])) {
21073 + h_i = d_inode(h_d[i]);
21074 + err = !h_i->i_nlink;
21082 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21084 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21087 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21090 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21091 + p->lsc_hi, 0, NULL, _RET_IP_);
21092 + au_pin_hdir_set_owner(p, current);
21096 +void au_pin_hdir_release(struct au_pin *p)
21099 + au_pin_hdir_set_owner(p, p->task);
21100 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21104 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21106 + if (pin && pin->parent)
21107 + return au_h_dptr(pin->parent, pin->bindex);
21111 +void au_unpin(struct au_pin *p)
21114 + au_pin_hdir_unlock(p);
21115 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21116 + vfsub_mnt_drop_write(p->h_mnt);
21120 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21121 + di_read_unlock(p->parent, AuLock_IR);
21122 + iput(p->hdir->hi_inode);
21124 + p->parent = NULL;
21127 + /* do not clear p->task */
21130 +int au_do_pin(struct au_pin *p)
21133 + struct super_block *sb;
21134 + struct inode *h_dir;
21137 + sb = p->dentry->d_sb;
21138 + p->br = au_sbr(sb, p->bindex);
21139 + if (IS_ROOT(p->dentry)) {
21140 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21141 + p->h_mnt = au_br_mnt(p->br);
21142 + err = vfsub_mnt_want_write(p->h_mnt);
21143 + if (unlikely(err)) {
21144 + au_fclr_pin(p->flags, MNT_WRITE);
21151 + p->h_dentry = NULL;
21152 + if (p->bindex <= au_dbbot(p->dentry))
21153 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21155 + p->parent = dget_parent(p->dentry);
21156 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21157 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21160 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21161 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21163 + h_dir = p->hdir->hi_inode;
21167 + * if DI_LOCKED is not set, then p->parent may be different
21168 + * and h_parent can be NULL.
21170 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21172 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21173 + di_read_unlock(p->parent, AuLock_IR);
21175 + p->parent = NULL;
21179 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21180 + p->h_mnt = au_br_mnt(p->br);
21181 + err = vfsub_mnt_want_write(p->h_mnt);
21182 + if (unlikely(err)) {
21183 + au_fclr_pin(p->flags, MNT_WRITE);
21184 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21185 + di_read_unlock(p->parent, AuLock_IR);
21187 + p->parent = NULL;
21193 + err = au_pin_hdir_lock(p);
21195 + goto out; /* success */
21200 + pr_err("err %d\n", err);
21201 + err = au_busy_or_stale();
21206 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21207 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21208 + unsigned int udba, unsigned char flags)
21210 + p->dentry = dentry;
21212 + p->lsc_di = lsc_di;
21213 + p->lsc_hi = lsc_hi;
21214 + p->flags = flags;
21215 + p->bindex = bindex;
21217 + p->parent = NULL;
21221 + p->h_dentry = NULL;
21222 + p->h_parent = NULL;
21224 + p->task = current;
21227 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21228 + unsigned int udba, unsigned char flags)
21230 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21232 + return au_do_pin(pin);
21235 +/* ---------------------------------------------------------------------- */
21238 + * ->setattr() and ->getattr() are called in various cases.
21239 + * chmod, stat: dentry is revalidated.
21240 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21242 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21244 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21245 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21248 + struct dentry *parent;
21251 + if (au_digen_test(dentry, sigen)) {
21252 + parent = dget_parent(dentry);
21253 + di_read_lock_parent(parent, AuLock_IR);
21254 + err = au_refresh_dentry(dentry, parent);
21255 + di_read_unlock(parent, AuLock_IR);
21263 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21264 + struct au_icpup_args *a)
21268 + aufs_bindex_t btop, ibtop;
21269 + struct dentry *hi_wh, *parent;
21270 + struct inode *inode;
21271 + struct au_wr_dir_args wr_dir_args = {
21272 + .force_btgt = -1,
21276 + if (d_is_dir(dentry))
21277 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21278 + /* plink or hi_wh() case */
21279 + btop = au_dbtop(dentry);
21280 + inode = d_inode(dentry);
21281 + ibtop = au_ibtop(inode);
21282 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21283 + wr_dir_args.force_btgt = ibtop;
21284 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21285 + if (unlikely(err < 0))
21289 + au_fset_icpup(a->flags, DID_CPUP);
21292 + a->pin_flags = AuPin_MNT_WRITE;
21294 + if (!IS_ROOT(dentry)) {
21295 + au_fset_pin(a->pin_flags, DI_LOCKED);
21296 + parent = dget_parent(dentry);
21297 + di_write_lock_parent(parent);
21300 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21301 + if (unlikely(err))
21305 + a->h_path.dentry = au_h_dptr(dentry, btop);
21306 + a->h_inode = d_inode(a->h_path.dentry);
21307 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21308 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21309 + if (ia->ia_size < i_size_read(a->h_inode))
21310 + sz = ia->ia_size;
21311 + inode_unlock_shared(a->h_inode);
21315 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21316 + hi_wh = au_hi_wh(inode, a->btgt);
21318 + struct au_cp_generic cpg = {
21319 + .dentry = dentry,
21325 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21326 + if (unlikely(err))
21328 + hi_wh = au_hi_wh(inode, a->btgt);
21329 + /* todo: revalidate hi_wh? */
21334 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21335 + di_downgrade_lock(parent, AuLock_IR);
21339 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21340 + goto out; /* success */
21342 + if (!d_unhashed(dentry)) {
21343 + struct au_cp_generic cpg = {
21344 + .dentry = dentry,
21349 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21351 + err = au_sio_cpup_simple(&cpg);
21353 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21354 + } else if (!hi_wh)
21355 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21357 + a->h_path.dentry = hi_wh; /* do not dget here */
21360 + a->h_inode = d_inode(a->h_path.dentry);
21362 + goto out; /* success */
21363 + au_unpin(&a->pin);
21366 + di_write_unlock(parent);
21371 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21375 +static int aufs_setattr(struct user_namespace *userns, struct dentry *dentry,
21376 + struct iattr *ia)
21379 + struct inode *inode, *delegated;
21380 + struct super_block *sb;
21381 + struct file *file;
21382 + struct au_icpup_args *a;
21383 + struct user_namespace *h_userns;
21385 + inode = d_inode(dentry);
21386 + IMustLock(inode);
21388 + err = setattr_prepare(userns, dentry, ia);
21389 + if (unlikely(err))
21393 + a = kzalloc(sizeof(*a), GFP_NOFS);
21394 + if (unlikely(!a))
21397 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21398 + ia->ia_valid &= ~ATTR_MODE;
21401 + sb = dentry->d_sb;
21402 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21403 + if (unlikely(err))
21406 + if (ia->ia_valid & ATTR_FILE) {
21407 + /* currently ftruncate(2) only */
21408 + AuDebugOn(!d_is_reg(dentry));
21409 + file = ia->ia_file;
21410 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21412 + if (unlikely(err))
21414 + ia->ia_file = au_hf_top(file);
21415 + a->udba = AuOpt_UDBA_NONE;
21417 + /* fchmod() doesn't pass ia_file */
21418 + a->udba = au_opt_udba(sb);
21419 + di_write_lock_child(dentry);
21420 + /* no d_unlinked(), to set UDBA_NONE for root */
21421 + if (d_unhashed(dentry))
21422 + a->udba = AuOpt_UDBA_NONE;
21423 + if (a->udba != AuOpt_UDBA_NONE) {
21424 + AuDebugOn(IS_ROOT(dentry));
21425 + err = au_reval_for_attr(dentry, au_sigen(sb));
21426 + if (unlikely(err))
21431 + err = au_pin_and_icpup(dentry, ia, a);
21432 + if (unlikely(err < 0))
21434 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21435 + ia->ia_file = NULL;
21436 + ia->ia_valid &= ~ATTR_FILE;
21439 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21440 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21441 + == (ATTR_MODE | ATTR_CTIME)) {
21442 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21443 + if (unlikely(err))
21445 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21446 + && (ia->ia_valid & ATTR_CTIME)) {
21447 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21448 + if (unlikely(err))
21452 + if (ia->ia_valid & ATTR_SIZE) {
21455 + if (ia->ia_size < i_size_read(inode))
21457 + truncate_setsize(inode, ia->ia_size);
21460 + if (ia->ia_valid & ATTR_FILE)
21462 + inode_unlock(a->h_inode);
21463 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21464 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21466 + delegated = NULL;
21468 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21470 + err = break_deleg_wait(&delegated);
21478 + * regardless aufs 'acl' option setting.
21479 + * why don't all acl-aware fs call this func from their ->setattr()?
21481 + if (!err && (ia->ia_valid & ATTR_MODE)) {
21482 + h_userns = mnt_user_ns(a->h_path.mnt);
21483 + err = vfsub_acl_chmod(h_userns, a->h_inode, ia->ia_mode);
21486 + au_cpup_attr_changeable(inode);
21489 + inode_unlock(a->h_inode);
21490 + au_unpin(&a->pin);
21491 + if (unlikely(err))
21492 + au_update_dbtop(dentry);
21494 + di_write_unlock(dentry);
21496 + fi_write_unlock(file);
21497 + ia->ia_file = file;
21498 + ia->ia_valid |= ATTR_FILE;
21501 + si_read_unlock(sb);
21509 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21510 +static int au_h_path_to_set_attr(struct dentry *dentry,
21511 + struct au_icpup_args *a, struct path *h_path)
21514 + struct super_block *sb;
21516 + sb = dentry->d_sb;
21517 + a->udba = au_opt_udba(sb);
21518 + /* no d_unlinked(), to set UDBA_NONE for root */
21519 + if (d_unhashed(dentry))
21520 + a->udba = AuOpt_UDBA_NONE;
21521 + if (a->udba != AuOpt_UDBA_NONE) {
21522 + AuDebugOn(IS_ROOT(dentry));
21523 + err = au_reval_for_attr(dentry, au_sigen(sb));
21524 + if (unlikely(err))
21527 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21528 + if (unlikely(err < 0))
21531 + h_path->dentry = a->h_path.dentry;
21532 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21538 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21539 + struct au_sxattr *arg)
21542 + struct path h_path;
21543 + struct super_block *sb;
21544 + struct au_icpup_args *a;
21545 + struct inode *h_inode;
21546 + struct user_namespace *h_userns;
21548 + IMustLock(inode);
21551 + a = kzalloc(sizeof(*a), GFP_NOFS);
21552 + if (unlikely(!a))
21555 + sb = dentry->d_sb;
21556 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21557 + if (unlikely(err))
21560 + h_path.dentry = NULL; /* silence gcc */
21561 + di_write_lock_child(dentry);
21562 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21563 + if (unlikely(err))
21565 + h_userns = mnt_user_ns(h_path.mnt);
21567 + inode_unlock(a->h_inode);
21568 + switch (arg->type) {
21569 + case AU_XATTR_SET:
21570 + AuDebugOn(d_is_negative(h_path.dentry));
21571 + err = vfsub_setxattr(h_userns, h_path.dentry,
21572 + arg->u.set.name, arg->u.set.value,
21573 + arg->u.set.size, arg->u.set.flags);
21576 + err = -EOPNOTSUPP;
21577 + h_inode = d_inode(h_path.dentry);
21578 + if (h_inode->i_op->set_acl) {
21579 + /* this will call posix_acl_update_mode */
21580 + err = h_inode->i_op->set_acl(h_userns, h_inode,
21581 + arg->u.acl_set.acl,
21582 + arg->u.acl_set.type);
21587 + au_cpup_attr_timesizes(inode);
21589 + au_unpin(&a->pin);
21590 + if (unlikely(err))
21591 + au_update_dbtop(dentry);
21594 + di_write_unlock(dentry);
21595 + si_read_unlock(sb);
21604 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21605 + unsigned int nlink)
21609 + inode->i_mode = st->mode;
21610 + /* don't i_[ug]id_write() here */
21611 + inode->i_uid = st->uid;
21612 + inode->i_gid = st->gid;
21613 + inode->i_atime = st->atime;
21614 + inode->i_mtime = st->mtime;
21615 + inode->i_ctime = st->ctime;
21617 + au_cpup_attr_nlink(inode, /*force*/0);
21618 + if (S_ISDIR(inode->i_mode)) {
21619 + n = inode->i_nlink;
21622 + smp_mb(); /* for i_nlink */
21623 + /* 0 can happen */
21624 + set_nlink(inode, n);
21627 + spin_lock(&inode->i_lock);
21628 + inode->i_blocks = st->blocks;
21629 + i_size_write(inode, st->size);
21630 + spin_unlock(&inode->i_lock);
21634 + * common routine for aufs_getattr() and au_getxattr().
21635 + * returns zero or negative (an error).
21636 + * @dentry will be read-locked in success.
21638 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21639 + struct path *h_path, int locked)
21642 + unsigned int mnt_flags, sigen;
21643 + unsigned char udba_none;
21644 + aufs_bindex_t bindex;
21645 + struct super_block *sb, *h_sb;
21647 + h_path->mnt = NULL;
21648 + h_path->dentry = NULL;
21651 + sb = dentry->d_sb;
21652 + mnt_flags = au_mntflags(sb);
21653 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21655 + if (unlikely(locked))
21656 + goto body; /* skip locking dinfo */
21658 + /* support fstat(2) */
21659 + if (!d_unlinked(dentry) && !udba_none) {
21660 + sigen = au_sigen(sb);
21661 + err = au_digen_test(dentry, sigen);
21663 + di_read_lock_child(dentry, AuLock_IR);
21664 + err = au_dbrange_test(dentry);
21665 + if (unlikely(err)) {
21666 + di_read_unlock(dentry, AuLock_IR);
21670 + AuDebugOn(IS_ROOT(dentry));
21671 + di_write_lock_child(dentry);
21672 + err = au_dbrange_test(dentry);
21674 + err = au_reval_for_attr(dentry, sigen);
21676 + di_downgrade_lock(dentry, AuLock_IR);
21678 + di_write_unlock(dentry);
21683 + di_read_lock_child(dentry, AuLock_IR);
21687 + inode = d_inode(dentry);
21688 + if (unlikely(!inode))
21691 + bindex = au_ibtop(inode);
21692 + h_path->mnt = au_sbr_mnt(sb, bindex);
21693 + h_sb = h_path->mnt->mnt_sb;
21695 + && !au_test_fs_bad_iattr(h_sb)
21697 + goto out; /* success */
21699 + if (au_dbtop(dentry) == bindex)
21700 + h_path->dentry = au_h_dptr(dentry, bindex);
21701 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21702 + h_path->dentry = au_plink_lkup(inode, bindex);
21703 + if (IS_ERR(h_path->dentry))
21704 + /* pretending success */
21705 + h_path->dentry = NULL;
21707 + dput(h_path->dentry);
21714 +static int aufs_getattr(struct user_namespace *userns, const struct path *path,
21715 + struct kstat *st, u32 request, unsigned int query)
21718 + unsigned char positive;
21719 + struct path h_path;
21720 + struct dentry *dentry;
21721 + struct inode *inode;
21722 + struct super_block *sb;
21724 + dentry = path->dentry;
21725 + inode = d_inode(dentry);
21726 + sb = dentry->d_sb;
21727 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21728 + if (unlikely(err))
21730 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21732 + if (unlikely(err))
21734 + if (unlikely(!h_path.dentry))
21735 + /* illegally overlapped or something */
21736 + goto out_fill; /* pretending success */
21738 + positive = d_is_positive(h_path.dentry);
21740 + /* no vfsub version */
21741 + err = vfs_getattr(&h_path, st, request, query);
21744 + au_refresh_iattr(inode, st,
21745 + d_inode(h_path.dentry)->i_nlink);
21746 + goto out_fill; /* success */
21752 + generic_fillattr(userns, inode, st);
21754 + di_read_unlock(dentry, AuLock_IR);
21756 + si_read_unlock(sb);
21762 +/* ---------------------------------------------------------------------- */
21764 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21765 + struct delayed_call *done)
21768 + struct dentry *h_dentry;
21769 + struct inode *h_inode;
21771 + aufs_bindex_t bindex;
21773 + ret = NULL; /* suppress a warning */
21778 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21779 + if (unlikely(err))
21782 + err = au_d_hashed_positive(dentry);
21783 + if (unlikely(err))
21787 + inode = d_inode(dentry);
21788 + bindex = au_ibtop(inode);
21789 + h_inode = au_h_iptr(inode, bindex);
21790 + if (unlikely(!h_inode->i_op->get_link))
21795 + if (au_dbtop(dentry) <= bindex) {
21796 + h_dentry = au_h_dptr(dentry, bindex);
21801 + h_dentry = d_find_any_alias(h_inode);
21802 + if (IS_ERR(h_dentry)) {
21803 + err = PTR_ERR(h_dentry);
21807 + if (unlikely(!h_dentry))
21811 + AuDbg("%ps\n", h_inode->i_op->get_link);
21812 + AuDbgDentry(h_dentry);
21813 + ret = vfs_get_link(h_dentry, done);
21816 + err = PTR_ERR(ret);
21819 + aufs_read_unlock(dentry, AuLock_IR);
21821 + if (unlikely(err))
21822 + ret = ERR_PTR(err);
21823 + AuTraceErrPtr(ret);
21827 +/* ---------------------------------------------------------------------- */
21829 +static int au_is_special(struct inode *inode)
21831 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21834 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21838 + aufs_bindex_t bindex;
21839 + struct super_block *sb;
21840 + struct inode *h_inode;
21841 + struct vfsmount *h_mnt;
21843 + sb = inode->i_sb;
21844 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21845 + "unexpected s_flags 0x%lx", sb->s_flags);
21847 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21849 + si_read_lock(sb, AuLock_FLUSH);
21850 + ii_write_lock_child(inode);
21853 + bindex = au_ibtop(inode);
21854 + h_inode = au_h_iptr(inode, bindex);
21855 + if (!au_test_ro(sb, bindex, inode)) {
21856 + h_mnt = au_sbr_mnt(sb, bindex);
21857 + err = vfsub_mnt_want_write(h_mnt);
21859 + err = vfsub_update_time(h_inode, ts, flags);
21860 + vfsub_mnt_drop_write(h_mnt);
21862 + } else if (au_is_special(h_inode)) {
21864 + * Never copy-up here.
21865 + * These special files may already be opened and used for
21866 + * communicating. If we copied it up, then the communication
21867 + * would be corrupted.
21869 + AuWarn1("timestamps for i%lu are ignored "
21870 + "since it is on readonly branch (hi%lu).\n",
21871 + inode->i_ino, h_inode->i_ino);
21872 + } else if (flags & ~S_ATIME) {
21874 + AuIOErr1("unexpected flags 0x%x\n", flags);
21879 + au_cpup_attr_timesizes(inode);
21880 + ii_write_unlock(inode);
21881 + si_read_unlock(sb);
21884 + if (!err && (flags & S_VERSION))
21885 + inode_inc_iversion(inode);
21890 +/* ---------------------------------------------------------------------- */
21892 +/* no getattr version will be set by module.c:aufs_init() */
21893 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21895 + [AuIop_SYMLINK] = {
21896 + .permission = aufs_permission,
21897 +#ifdef CONFIG_FS_POSIX_ACL
21898 + .get_acl = aufs_get_acl,
21899 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21902 + .setattr = aufs_setattr,
21903 + .getattr = aufs_getattr,
21905 +#ifdef CONFIG_AUFS_XATTR
21906 + .listxattr = aufs_listxattr,
21909 + .get_link = aufs_get_link,
21911 + /* .update_time = aufs_update_time */
21914 + .create = aufs_create,
21915 + .lookup = aufs_lookup,
21916 + .link = aufs_link,
21917 + .unlink = aufs_unlink,
21918 + .symlink = aufs_symlink,
21919 + .mkdir = aufs_mkdir,
21920 + .rmdir = aufs_rmdir,
21921 + .mknod = aufs_mknod,
21922 + .rename = aufs_rename,
21924 + .permission = aufs_permission,
21925 +#ifdef CONFIG_FS_POSIX_ACL
21926 + .get_acl = aufs_get_acl,
21927 + .set_acl = aufs_set_acl,
21930 + .setattr = aufs_setattr,
21931 + .getattr = aufs_getattr,
21933 +#ifdef CONFIG_AUFS_XATTR
21934 + .listxattr = aufs_listxattr,
21937 + .update_time = aufs_update_time,
21938 + .atomic_open = aufs_atomic_open,
21939 + .tmpfile = aufs_tmpfile
21941 + [AuIop_OTHER] = {
21942 + .permission = aufs_permission,
21943 +#ifdef CONFIG_FS_POSIX_ACL
21944 + .get_acl = aufs_get_acl,
21945 + .set_acl = aufs_set_acl,
21948 + .setattr = aufs_setattr,
21949 + .getattr = aufs_getattr,
21951 +#ifdef CONFIG_AUFS_XATTR
21952 + .listxattr = aufs_listxattr,
21955 + .update_time = aufs_update_time
21958 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21959 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21960 +++ linux/fs/aufs/i_op_del.c 2021-11-01 23:48:34.209692595 +0100
21962 +// SPDX-License-Identifier: GPL-2.0
21964 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21966 + * This program, aufs is free software; you can redistribute it and/or modify
21967 + * it under the terms of the GNU General Public License as published by
21968 + * the Free Software Foundation; either version 2 of the License, or
21969 + * (at your option) any later version.
21971 + * This program is distributed in the hope that it will be useful,
21972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21974 + * GNU General Public License for more details.
21976 + * You should have received a copy of the GNU General Public License
21977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21981 + * inode operations (del entry)
21984 +#include <linux/iversion.h>
21988 + * decide if a new whiteout for @dentry is necessary or not.
21989 + * when it is necessary, prepare the parent dir for the upper branch whose
21990 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21991 + * be done by caller.
21993 + * 0: wh is unnecessary
21994 + * plus: wh is necessary
21997 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21999 + int need_wh, err;
22000 + aufs_bindex_t btop;
22001 + struct super_block *sb;
22003 + sb = dentry->d_sb;
22004 + btop = au_dbtop(dentry);
22005 + if (*bcpup < 0) {
22007 + if (au_test_ro(sb, btop, d_inode(dentry))) {
22008 + err = AuWbrCopyup(au_sbi(sb), dentry);
22010 + if (unlikely(err < 0))
22014 + AuDebugOn(btop < *bcpup
22015 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
22016 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
22018 + if (*bcpup != btop) {
22019 + err = au_cpup_dirs(dentry, *bcpup);
22020 + if (unlikely(err))
22024 + struct au_dinfo *dinfo, *tmp;
22026 + need_wh = -ENOMEM;
22027 + dinfo = au_di(dentry);
22028 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22030 + au_di_cp(tmp, dinfo);
22031 + au_di_swap(tmp, dinfo);
22032 + /* returns the number of positive dentries */
22033 + need_wh = au_lkup_dentry(dentry, btop + 1,
22034 + /* AuLkup_IGNORE_PERM */ 0);
22035 + au_di_swap(tmp, dinfo);
22036 + au_rw_write_unlock(&tmp->di_rwsem);
22040 + AuDbg("need_wh %d\n", need_wh);
22048 + * simple tests for the del-entry operations.
22049 + * following the checks in vfs, plus the parent-child relationship.
22051 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22052 + struct dentry *h_parent, int isdir)
22056 + struct dentry *h_dentry, *h_latest;
22057 + struct inode *h_inode;
22058 + struct path h_ppath;
22059 + struct super_block *sb;
22060 + struct au_branch *br;
22061 + struct user_namespace *h_userns;
22063 + h_dentry = au_h_dptr(dentry, bindex);
22064 + if (d_really_is_positive(dentry)) {
22066 + if (unlikely(d_is_negative(h_dentry)))
22068 + h_inode = d_inode(h_dentry);
22069 + if (unlikely(!h_inode->i_nlink))
22072 + h_mode = h_inode->i_mode;
22075 + if (unlikely(S_ISDIR(h_mode)))
22077 + } else if (unlikely(!S_ISDIR(h_mode))) {
22082 + /* rename(2) case */
22084 + if (unlikely(d_is_positive(h_dentry)))
22089 + /* expected parent dir is locked */
22090 + if (unlikely(h_parent != h_dentry->d_parent))
22095 + * rmdir a dir may break the consistency on some filesystem.
22096 + * let's try heavy test.
22099 + sb = dentry->d_sb;
22100 + br = au_sbr(sb, bindex);
22101 + h_userns = au_br_userns(br);
22102 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
22103 + && au_test_h_perm(h_userns, d_inode(h_parent),
22104 + MAY_EXEC | MAY_WRITE)))
22107 + h_ppath.dentry = h_parent;
22108 + h_ppath.mnt = au_br_mnt(br);
22109 + h_latest = au_sio_lkup_one(h_userns, &dentry->d_name, &h_ppath);
22111 + if (IS_ERR(h_latest))
22113 + if (h_latest == h_dentry)
22122 + * decide the branch where we operate for @dentry. the branch index will be set
22123 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22124 + * dir for reverting.
22125 + * when a new whiteout is necessary, create it.
22127 +static struct dentry*
22128 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22129 + struct au_dtime *dt, struct au_pin *pin)
22131 + struct dentry *wh_dentry;
22132 + struct super_block *sb;
22133 + struct path h_path;
22134 + int err, need_wh;
22135 + unsigned int udba;
22136 + aufs_bindex_t bcpup;
22138 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22139 + wh_dentry = ERR_PTR(need_wh);
22140 + if (unlikely(need_wh < 0))
22143 + sb = dentry->d_sb;
22144 + udba = au_opt_udba(sb);
22146 + err = au_pin(pin, dentry, bcpup, udba,
22147 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22148 + wh_dentry = ERR_PTR(err);
22149 + if (unlikely(err))
22152 + h_path.dentry = au_pinned_h_parent(pin);
22153 + if (udba != AuOpt_UDBA_NONE
22154 + && au_dbtop(dentry) == bcpup) {
22155 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22156 + wh_dentry = ERR_PTR(err);
22157 + if (unlikely(err))
22161 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22162 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22163 + wh_dentry = NULL;
22165 + goto out; /* success, no need to create whiteout */
22167 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22168 + if (IS_ERR(wh_dentry))
22171 + /* returns with the parent is locked and wh_dentry is dget-ed */
22172 + goto out; /* success */
22177 + return wh_dentry;
22181 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22182 + * in order to be revertible and save time for removing many child whiteouts
22184 + * returns 1 when there are too many child whiteout and caller should remove
22185 + * them asynchronously. returns 0 when the number of children is enough small to
22186 + * remove now or the branch fs is a remote fs.
22187 + * otherwise return an error.
22189 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22190 + struct au_nhash *whlist, struct inode *dir)
22192 + int rmdir_later, err, dirwh;
22193 + struct dentry *h_dentry;
22194 + struct super_block *sb;
22195 + struct inode *inode;
22197 + sb = dentry->d_sb;
22198 + SiMustAnyLock(sb);
22199 + h_dentry = au_h_dptr(dentry, bindex);
22200 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22201 + if (unlikely(err))
22204 + /* stop monitoring */
22205 + inode = d_inode(dentry);
22206 + au_hn_free(au_hi(inode, bindex));
22208 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22209 + dirwh = au_sbi(sb)->si_dirwh;
22210 + rmdir_later = (dirwh <= 1);
22211 + if (!rmdir_later)
22212 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22215 + return rmdir_later;
22218 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22219 + if (unlikely(err)) {
22220 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22221 + h_dentry, bindex, err);
22231 + * final procedure for deleting a entry.
22232 + * maintain dentry and iattr.
22234 +static void epilog(struct inode *dir, struct dentry *dentry,
22235 + aufs_bindex_t bindex)
22237 + struct inode *inode;
22239 + inode = d_inode(dentry);
22241 + inode->i_ctime = dir->i_ctime;
22243 + au_dir_ts(dir, bindex);
22244 + inode_inc_iversion(dir);
22248 + * when an error happened, remove the created whiteout and revert everything.
22250 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22251 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22252 + struct dentry *dentry, struct au_dtime *dt)
22255 + struct path h_path = {
22256 + .dentry = wh_dentry,
22257 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22260 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22262 + au_set_dbwh(dentry, bwh);
22263 + au_dtime_revert(dt);
22267 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22271 +/* ---------------------------------------------------------------------- */
22273 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22276 + aufs_bindex_t bwh, bindex, btop;
22277 + struct inode *inode, *h_dir, *delegated;
22278 + struct dentry *parent, *wh_dentry;
22279 + /* to reduce stack size */
22281 + struct au_dtime dt;
22282 + struct au_pin pin;
22283 + struct path h_path;
22289 + a = kmalloc(sizeof(*a), GFP_NOFS);
22290 + if (unlikely(!a))
22293 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22294 + if (unlikely(err))
22296 + err = au_d_hashed_positive(dentry);
22297 + if (unlikely(err))
22299 + inode = d_inode(dentry);
22300 + IMustLock(inode);
22302 + if (unlikely(d_is_dir(dentry)))
22303 + goto out_unlock; /* possible? */
22305 + btop = au_dbtop(dentry);
22306 + bwh = au_dbwh(dentry);
22308 + parent = dentry->d_parent; /* dir inode is locked */
22309 + di_write_lock_parent(parent);
22310 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22312 + err = PTR_ERR(wh_dentry);
22313 + if (IS_ERR(wh_dentry))
22316 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22317 + a->h_path.dentry = au_h_dptr(dentry, btop);
22318 + dget(a->h_path.dentry);
22319 + if (bindex == btop) {
22320 + h_dir = au_pinned_h_dir(&a->pin);
22321 + delegated = NULL;
22322 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22323 + if (unlikely(err == -EWOULDBLOCK)) {
22324 + pr_warn("cannot retry for NFSv4 delegation"
22325 + " for an internal unlink\n");
22329 + /* dir inode is locked */
22330 + h_dir = d_inode(wh_dentry->d_parent);
22331 + IMustLock(h_dir);
22336 + vfsub_drop_nlink(inode);
22337 + epilog(dir, dentry, bindex);
22339 + /* update target timestamps */
22340 + if (bindex == btop) {
22341 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22343 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22345 + /* todo: this timestamp may be reverted later */
22346 + inode->i_ctime = h_dir->i_ctime;
22347 + goto out_unpin; /* success */
22354 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22361 + au_unpin(&a->pin);
22363 + dput(a->h_path.dentry);
22365 + di_write_unlock(parent);
22367 + aufs_read_unlock(dentry, AuLock_DW);
22374 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22376 + int err, rmdir_later;
22377 + aufs_bindex_t bwh, bindex, btop;
22378 + struct inode *inode;
22379 + struct dentry *parent, *wh_dentry, *h_dentry;
22380 + struct au_whtmp_rmdir *args;
22381 + /* to reduce stack size */
22383 + struct au_dtime dt;
22384 + struct au_pin pin;
22390 + a = kmalloc(sizeof(*a), GFP_NOFS);
22391 + if (unlikely(!a))
22394 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22395 + if (unlikely(err))
22397 + err = au_alive_dir(dentry);
22398 + if (unlikely(err))
22400 + inode = d_inode(dentry);
22401 + IMustLock(inode);
22403 + if (unlikely(!d_is_dir(dentry)))
22404 + goto out_unlock; /* possible? */
22407 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22408 + if (unlikely(!args))
22411 + parent = dentry->d_parent; /* dir inode is locked */
22412 + di_write_lock_parent(parent);
22413 + err = au_test_empty(dentry, &args->whlist);
22414 + if (unlikely(err))
22417 + btop = au_dbtop(dentry);
22418 + bwh = au_dbwh(dentry);
22420 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22422 + err = PTR_ERR(wh_dentry);
22423 + if (IS_ERR(wh_dentry))
22426 + h_dentry = au_h_dptr(dentry, btop);
22429 + if (bindex == btop) {
22430 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22432 + rmdir_later = err;
22436 + /* stop monitoring */
22437 + au_hn_free(au_hi(inode, btop));
22439 + /* dir inode is locked */
22440 + IMustLock(d_inode(wh_dentry->d_parent));
22445 + vfsub_dead_dir(inode);
22446 + au_set_dbdiropq(dentry, -1);
22447 + epilog(dir, dentry, bindex);
22449 + if (rmdir_later) {
22450 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22454 + goto out_unpin; /* success */
22462 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22469 + au_unpin(&a->pin);
22473 + di_write_unlock(parent);
22475 + au_whtmp_rmdir_free(args);
22477 + aufs_read_unlock(dentry, AuLock_DW);
22484 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22485 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22486 +++ linux/fs/aufs/i_op_ren.c 2021-11-01 23:48:34.209692595 +0100
22488 +// SPDX-License-Identifier: GPL-2.0
22490 + * Copyright (C) 2005-2021 Junjiro R. Okajima
22492 + * This program, aufs is free software; you can redistribute it and/or modify
22493 + * it under the terms of the GNU General Public License as published by
22494 + * the Free Software Foundation; either version 2 of the License, or
22495 + * (at your option) any later version.
22497 + * This program is distributed in the hope that it will be useful,
22498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22500 + * GNU General Public License for more details.
22502 + * You should have received a copy of the GNU General Public License
22503 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22507 + * inode operation (rename entry)
22508 + * todo: this is crazy monster
22511 +#include <linux/iversion.h>
22514 +enum { AuSRC, AuDST, AuSrcDst };
22515 +enum { AuPARENT, AuCHILD, AuParentChild };
22517 +#define AuRen_ISDIR_SRC 1
22518 +#define AuRen_ISDIR_DST (1 << 1)
22519 +#define AuRen_ISSAMEDIR (1 << 2)
22520 +#define AuRen_WHSRC (1 << 3)
22521 +#define AuRen_WHDST (1 << 4)
22522 +#define AuRen_MNT_WRITE (1 << 5)
22523 +#define AuRen_DT_DSTDIR (1 << 6)
22524 +#define AuRen_DIROPQ_SRC (1 << 7)
22525 +#define AuRen_DIROPQ_DST (1 << 8)
22526 +#define AuRen_DIRREN (1 << 9)
22527 +#define AuRen_DROPPED_SRC (1 << 10)
22528 +#define AuRen_DROPPED_DST (1 << 11)
22529 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22530 +#define au_fset_ren(flags, name) \
22531 + do { (flags) |= AuRen_##name; } while (0)
22532 +#define au_fclr_ren(flags, name) \
22533 + do { (flags) &= ~AuRen_##name; } while (0)
22535 +#ifndef CONFIG_AUFS_DIRREN
22536 +#undef AuRen_DIRREN
22537 +#define AuRen_DIRREN 0
22540 +struct au_ren_args {
22542 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22544 + struct inode *dir, *inode;
22545 + struct au_hinode *hdir, *hinode;
22546 + struct au_dtime dt[AuParentChild];
22547 + aufs_bindex_t btop, bdiropq;
22550 +#define src_dentry sd[AuSRC].dentry
22551 +#define src_dir sd[AuSRC].dir
22552 +#define src_inode sd[AuSRC].inode
22553 +#define src_h_dentry sd[AuSRC].h_dentry
22554 +#define src_parent sd[AuSRC].parent
22555 +#define src_h_parent sd[AuSRC].h_parent
22556 +#define src_wh_dentry sd[AuSRC].wh_dentry
22557 +#define src_hdir sd[AuSRC].hdir
22558 +#define src_hinode sd[AuSRC].hinode
22559 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22560 +#define src_dt sd[AuSRC].dt
22561 +#define src_btop sd[AuSRC].btop
22562 +#define src_bdiropq sd[AuSRC].bdiropq
22564 +#define dst_dentry sd[AuDST].dentry
22565 +#define dst_dir sd[AuDST].dir
22566 +#define dst_inode sd[AuDST].inode
22567 +#define dst_h_dentry sd[AuDST].h_dentry
22568 +#define dst_parent sd[AuDST].parent
22569 +#define dst_h_parent sd[AuDST].h_parent
22570 +#define dst_wh_dentry sd[AuDST].wh_dentry
22571 +#define dst_hdir sd[AuDST].hdir
22572 +#define dst_hinode sd[AuDST].hinode
22573 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22574 +#define dst_dt sd[AuDST].dt
22575 +#define dst_btop sd[AuDST].btop
22576 +#define dst_bdiropq sd[AuDST].bdiropq
22578 + struct dentry *h_trap;
22579 + struct au_branch *br;
22580 + struct path h_path;
22581 + struct au_nhash whlist;
22582 + aufs_bindex_t btgt, src_bwh;
22585 + unsigned short auren_flags;
22586 + unsigned char flags; /* syscall parameter */
22587 + unsigned char exchange;
22590 + struct au_whtmp_rmdir *thargs;
22591 + struct dentry *h_dst;
22592 + struct au_hinode *h_root;
22595 +/* ---------------------------------------------------------------------- */
22598 + * functions for reverting.
22599 + * when an error happened in a single rename systemcall, we should revert
22600 + * everything as if nothing happened.
22601 + * we don't need to revert the copied-up/down the parent dir since they are
22605 +#define RevertFailure(fmt, ...) do { \
22606 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22607 + ##__VA_ARGS__, err, rerr); \
22611 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22614 + struct dentry *d;
22615 +#define src_or_dst(member) a->sd[idx].member
22617 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22618 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22619 + rerr = au_diropq_remove(d, a->btgt);
22620 + au_hn_inode_unlock(src_or_dst(hinode));
22621 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22623 + RevertFailure("remove diropq %pd", d);
22625 +#undef src_or_dst_
22628 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22630 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22631 + au_ren_do_rev_diropq(err, a, AuSRC);
22632 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22633 + au_ren_do_rev_diropq(err, a, AuDST);
22636 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22639 + struct inode *delegated;
22640 + struct path h_ppath = {
22641 + .dentry = a->src_h_parent,
22642 + .mnt = a->h_path.mnt
22645 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
22646 + rerr = PTR_ERR(a->h_path.dentry);
22647 + if (IS_ERR(a->h_path.dentry)) {
22648 + RevertFailure("lkup one %pd", a->src_dentry);
22652 + delegated = NULL;
22653 + rerr = vfsub_rename(a->dst_h_dir,
22654 + au_h_dptr(a->src_dentry, a->btgt),
22655 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22656 + if (unlikely(rerr == -EWOULDBLOCK)) {
22657 + pr_warn("cannot retry for NFSv4 delegation"
22658 + " for an internal rename\n");
22661 + d_drop(a->h_path.dentry);
22662 + dput(a->h_path.dentry);
22663 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22665 + RevertFailure("rename %pd", a->src_dentry);
22668 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22671 + struct inode *delegated;
22672 + struct path h_ppath = {
22673 + .dentry = a->dst_h_parent,
22674 + .mnt = a->h_path.mnt
22677 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
22678 + rerr = PTR_ERR(a->h_path.dentry);
22679 + if (IS_ERR(a->h_path.dentry)) {
22680 + RevertFailure("lkup one %pd", a->dst_dentry);
22683 + if (d_is_positive(a->h_path.dentry)) {
22684 + d_drop(a->h_path.dentry);
22685 + dput(a->h_path.dentry);
22689 + delegated = NULL;
22690 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22691 + &delegated, a->flags);
22692 + if (unlikely(rerr == -EWOULDBLOCK)) {
22693 + pr_warn("cannot retry for NFSv4 delegation"
22694 + " for an internal rename\n");
22697 + d_drop(a->h_path.dentry);
22698 + dput(a->h_path.dentry);
22700 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22702 + RevertFailure("rename %pd", a->h_dst);
22705 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22709 + a->h_path.dentry = a->src_wh_dentry;
22710 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22711 + au_set_dbwh(a->src_dentry, a->src_bwh);
22713 + RevertFailure("unlink %pd", a->src_wh_dentry);
22715 +#undef RevertFailure
22717 +/* ---------------------------------------------------------------------- */
22720 + * when we have to copyup the renaming entry, do it with the rename-target name
22721 + * in order to minimize the cost (the later actual rename is unnecessary).
22722 + * otherwise rename it on the target branch.
22724 +static int au_ren_or_cpup(struct au_ren_args *a)
22727 + struct dentry *d;
22728 + struct inode *delegated;
22730 + d = a->src_dentry;
22731 + if (au_dbtop(d) == a->btgt) {
22732 + a->h_path.dentry = a->dst_h_dentry;
22733 + AuDebugOn(au_dbtop(d) != a->btgt);
22734 + delegated = NULL;
22735 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22736 + a->dst_h_dir, &a->h_path, &delegated,
22738 + if (unlikely(err == -EWOULDBLOCK)) {
22739 + pr_warn("cannot retry for NFSv4 delegation"
22740 + " for an internal rename\n");
22746 + if (!err && a->h_dst)
22747 + /* it will be set to dinfo later */
22753 +/* cf. aufs_rmdir() */
22754 +static int au_ren_del_whtmp(struct au_ren_args *a)
22757 + struct inode *dir;
22759 + dir = a->dst_dir;
22760 + SiMustAnyLock(dir->i_sb);
22761 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22762 + au_sbi(dir->i_sb)->si_dirwh)
22763 + || au_test_fs_remote(a->h_dst->d_sb)) {
22764 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22765 + if (unlikely(err))
22766 + pr_warn("failed removing whtmp dir %pd (%d), "
22767 + "ignored.\n", a->h_dst, err);
22769 + au_nhash_wh_free(&a->thargs->whlist);
22770 + a->thargs->whlist = a->whlist;
22771 + a->whlist.nh_num = 0;
22772 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22774 + a->thargs = NULL;
22780 +/* make it 'opaque' dir. */
22781 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22784 + struct dentry *d, *diropq;
22785 +#define src_or_dst(member) a->sd[idx].member
22788 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22789 + src_or_dst(bdiropq) = au_dbdiropq(d);
22790 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22791 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22792 + diropq = au_diropq_create(d, a->btgt);
22793 + au_hn_inode_unlock(src_or_dst(hinode));
22794 + if (IS_ERR(diropq))
22795 + err = PTR_ERR(diropq);
22799 +#undef src_or_dst_
22803 +static int au_ren_diropq(struct au_ren_args *a)
22806 + unsigned char always;
22807 + struct dentry *d;
22810 + d = a->dst_dentry; /* already renamed on the branch */
22811 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22812 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22813 + && !au_ftest_ren(a->auren_flags, DIRREN)
22814 + && a->btgt != au_dbdiropq(a->src_dentry)
22815 + && (a->dst_wh_dentry
22816 + || a->btgt <= au_dbdiropq(d)
22817 + /* hide the lower to keep xino */
22818 + /* the lowers may not be a dir, but we hide them anyway */
22819 + || a->btgt < au_dbbot(d)
22822 + err = au_ren_do_diropq(a, AuSRC);
22823 + if (unlikely(err))
22825 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22827 + if (!a->exchange)
22828 + goto out; /* success */
22830 + d = a->src_dentry; /* already renamed on the branch */
22831 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22832 + && a->btgt != au_dbdiropq(a->dst_dentry)
22833 + && (a->btgt < au_dbdiropq(d)
22834 + || a->btgt < au_dbbot(d)
22836 + AuDbgDentry(a->src_dentry);
22837 + AuDbgDentry(a->dst_dentry);
22838 + err = au_ren_do_diropq(a, AuDST);
22839 + if (unlikely(err))
22840 + goto out_rev_src;
22841 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22843 + goto out; /* success */
22846 + AuDbg("err %d, reverting src\n", err);
22847 + au_ren_rev_diropq(err, a);
22852 +static int do_rename(struct au_ren_args *a)
22855 + struct dentry *d, *h_d;
22857 + if (!a->exchange) {
22858 + /* prepare workqueue args for asynchronous rmdir */
22859 + h_d = a->dst_h_dentry;
22860 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22861 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22862 + && d_is_positive(h_d)) {
22864 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22866 + if (unlikely(!a->thargs))
22868 + a->h_dst = dget(h_d);
22871 + /* create whiteout for src_dentry */
22872 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22873 + a->src_bwh = au_dbwh(a->src_dentry);
22874 + AuDebugOn(a->src_bwh >= 0);
22875 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22876 + a->src_h_parent);
22877 + err = PTR_ERR(a->src_wh_dentry);
22878 + if (IS_ERR(a->src_wh_dentry))
22882 + /* lookup whiteout for dentry */
22883 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22884 + h_d = au_wh_lkup(a->dst_h_parent,
22885 + &a->dst_dentry->d_name, a->br);
22886 + err = PTR_ERR(h_d);
22889 + if (d_is_negative(h_d))
22892 + a->dst_wh_dentry = h_d;
22895 + /* rename dentry to tmpwh */
22897 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22898 + if (unlikely(err))
22901 + d = a->dst_dentry;
22902 + au_set_h_dptr(d, a->btgt, NULL);
22903 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22904 + if (unlikely(err))
22906 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22910 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22911 +#if 0 /* debugging */
22912 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22913 + && d_is_positive(a->dst_h_dentry)
22914 + && a->src_btop != a->btgt);
22917 + /* rename by vfs_rename or cpup */
22918 + err = au_ren_or_cpup(a);
22919 + if (unlikely(err))
22920 + /* leave the copied-up one */
22923 + /* make dir opaque */
22924 + err = au_ren_diropq(a);
22925 + if (unlikely(err))
22928 + /* update target timestamps */
22929 + if (a->exchange) {
22930 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22931 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22932 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22933 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22935 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22936 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22937 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22938 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22940 + if (!a->exchange) {
22941 + /* remove whiteout for dentry */
22942 + if (a->dst_wh_dentry) {
22943 + a->h_path.dentry = a->dst_wh_dentry;
22944 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22946 + if (unlikely(err))
22950 + /* remove whtmp */
22952 + au_ren_del_whtmp(a); /* ignore this error */
22954 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22957 + goto out_success;
22960 + au_ren_rev_diropq(err, a);
22962 + au_ren_rev_rename(err, a);
22966 + au_ren_rev_whtmp(err, a);
22968 + dput(a->dst_wh_dentry);
22969 + a->dst_wh_dentry = NULL;
22971 + if (a->src_wh_dentry)
22972 + au_ren_rev_whsrc(err, a);
22974 + dput(a->src_wh_dentry);
22975 + dput(a->dst_wh_dentry);
22979 + au_whtmp_rmdir_free(a->thargs);
22980 + a->thargs = NULL;
22986 +/* ---------------------------------------------------------------------- */
22989 + * test if @dentry dir can be rename destination or not.
22990 + * success means, it is a logically empty dir.
22992 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22994 + return au_test_empty(dentry, whlist);
22998 + * test if @a->src_dentry dir can be rename source or not.
22999 + * if it can, return 0.
23001 + * - it is a logically empty dir.
23002 + * - or, it exists on writable branch and has no children including whiteouts
23003 + * on the lower branch unless DIRREN is on.
23005 +static int may_rename_srcdir(struct au_ren_args *a)
23008 + unsigned int rdhash;
23009 + aufs_bindex_t btop, btgt;
23010 + struct dentry *dentry;
23011 + struct super_block *sb;
23012 + struct au_sbinfo *sbinfo;
23014 + dentry = a->src_dentry;
23015 + sb = dentry->d_sb;
23016 + sbinfo = au_sbi(sb);
23017 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
23018 + au_fset_ren(a->auren_flags, DIRREN);
23021 + btop = au_dbtop(dentry);
23022 + if (btop != btgt) {
23023 + struct au_nhash whlist;
23025 + SiMustAnyLock(sb);
23026 + rdhash = sbinfo->si_rdhash;
23028 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
23030 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
23031 + if (unlikely(err))
23033 + err = au_test_empty(dentry, &whlist);
23034 + au_nhash_wh_free(&whlist);
23038 + if (btop == au_dbtaildir(dentry))
23039 + return 0; /* success */
23041 + err = au_test_empty_lower(dentry);
23044 + if (err == -ENOTEMPTY) {
23045 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23048 + AuWarn1("renaming dir who has child(ren) on multiple "
23049 + "branches, is not supported\n");
23056 +/* side effect: sets whlist and h_dentry */
23057 +static int au_ren_may_dir(struct au_ren_args *a)
23060 + unsigned int rdhash;
23061 + struct dentry *d;
23063 + d = a->dst_dentry;
23064 + SiMustAnyLock(d->d_sb);
23067 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23068 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23070 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23071 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23072 + if (unlikely(err))
23075 + if (!a->exchange) {
23076 + au_set_dbtop(d, a->dst_btop);
23077 + err = may_rename_dstdir(d, &a->whlist);
23078 + au_set_dbtop(d, a->btgt);
23080 + err = may_rename_srcdir(a);
23082 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23083 + if (unlikely(err))
23086 + d = a->src_dentry;
23087 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23088 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23089 + err = may_rename_srcdir(a);
23090 + if (unlikely(err)) {
23091 + au_nhash_wh_free(&a->whlist);
23092 + a->whlist.nh_num = 0;
23099 +/* ---------------------------------------------------------------------- */
23102 + * simple tests for rename.
23103 + * following the checks in vfs, plus the parent-child relationship.
23105 +static int au_may_ren(struct au_ren_args *a)
23108 + struct inode *h_inode;
23110 + if (a->src_btop == a->btgt) {
23111 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23112 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23113 + if (unlikely(err))
23116 + if (unlikely(a->src_h_dentry == a->h_trap))
23121 + if (a->dst_btop != a->btgt)
23124 + err = -ENOTEMPTY;
23125 + if (unlikely(a->dst_h_dentry == a->h_trap))
23129 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23130 + if (d_really_is_negative(a->dst_dentry)) {
23131 + if (d_is_negative(a->dst_h_dentry))
23132 + err = au_may_add(a->dst_dentry, a->btgt,
23133 + a->dst_h_parent, isdir);
23135 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23137 + h_inode = d_inode(a->dst_h_dentry);
23138 + if (h_inode->i_nlink)
23139 + err = au_may_del(a->dst_dentry, a->btgt,
23140 + a->dst_h_parent, isdir);
23144 + if (unlikely(err == -ENOENT || err == -EEXIST))
23150 +/* ---------------------------------------------------------------------- */
23155 + * - src_dir and dir by lock_rename()
23156 + * - inode if exists
23159 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23161 + * + di_write_lock2_child()
23162 + * + di_write_lock_child()
23163 + * + ii_write_lock_child()
23164 + * + di_write_lock_child2()
23165 + * + ii_write_lock_child2()
23166 + * + src_parent and parent
23167 + * + di_write_lock_parent()
23168 + * + ii_write_lock_parent()
23169 + * + di_write_lock_parent2()
23170 + * + ii_write_lock_parent2()
23171 + * + lower src_dir and dir by vfsub_lock_rename()
23172 + * + verify the every relationships between child and parent. if any
23173 + * of them failed, unlock all and return -EBUSY.
23175 +static void au_ren_unlock(struct au_ren_args *a)
23177 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23178 + a->dst_h_parent, a->dst_hdir);
23179 + if (au_ftest_ren(a->auren_flags, DIRREN)
23181 + au_hn_inode_unlock(a->h_root);
23182 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23183 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23186 +static int au_ren_lock(struct au_ren_args *a)
23189 + unsigned int udba;
23192 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23193 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23194 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23195 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23197 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23198 + if (unlikely(err))
23200 + au_fset_ren(a->auren_flags, MNT_WRITE);
23201 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23202 + struct dentry *root;
23203 + struct inode *dir;
23206 + * sbinfo is already locked, so this ii_read_lock is
23207 + * unnecessary. but our debugging feature checks it.
23209 + root = a->src_inode->i_sb->s_root;
23210 + if (root != a->src_parent && root != a->dst_parent) {
23211 + dir = d_inode(root);
23212 + ii_read_lock_parent3(dir);
23213 + a->h_root = au_hi(dir, a->btgt);
23214 + ii_read_unlock(dir);
23215 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23218 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23219 + a->dst_h_parent, a->dst_hdir);
23220 + udba = au_opt_udba(a->src_dentry->d_sb);
23221 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23222 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23223 + err = au_busy_or_stale();
23224 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23225 + err = au_h_verify(a->src_h_dentry, udba,
23226 + d_inode(a->src_h_parent), a->src_h_parent,
23228 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23229 + err = au_h_verify(a->dst_h_dentry, udba,
23230 + d_inode(a->dst_h_parent), a->dst_h_parent,
23233 + goto out; /* success */
23235 + err = au_busy_or_stale();
23236 + au_ren_unlock(a);
23242 +/* ---------------------------------------------------------------------- */
23244 +static void au_ren_refresh_dir(struct au_ren_args *a)
23246 + struct inode *dir;
23248 + dir = a->dst_dir;
23249 + inode_inc_iversion(dir);
23250 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23251 + /* is this updating defined in POSIX? */
23252 + au_cpup_attr_timesizes(a->src_inode);
23253 + au_cpup_attr_nlink(dir, /*force*/1);
23255 + au_dir_ts(dir, a->btgt);
23257 + if (a->exchange) {
23258 + dir = a->src_dir;
23259 + inode_inc_iversion(dir);
23260 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23261 + /* is this updating defined in POSIX? */
23262 + au_cpup_attr_timesizes(a->dst_inode);
23263 + au_cpup_attr_nlink(dir, /*force*/1);
23265 + au_dir_ts(dir, a->btgt);
23268 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23271 + dir = a->src_dir;
23272 + inode_inc_iversion(dir);
23273 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23274 + au_cpup_attr_nlink(dir, /*force*/1);
23275 + au_dir_ts(dir, a->btgt);
23278 +static void au_ren_refresh(struct au_ren_args *a)
23280 + aufs_bindex_t bbot, bindex;
23281 + struct dentry *d, *h_d;
23282 + struct inode *i, *h_i;
23283 + struct super_block *sb;
23285 + d = a->dst_dentry;
23288 + /* already dget-ed by au_ren_or_cpup() */
23289 + au_set_h_dptr(d, a->btgt, a->h_dst);
23291 + i = a->dst_inode;
23293 + if (!a->exchange) {
23294 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23295 + vfsub_drop_nlink(i);
23297 + vfsub_dead_dir(i);
23298 + au_cpup_attr_timesizes(i);
23300 + au_update_dbrange(d, /*do_put_zero*/1);
23302 + au_cpup_attr_nlink(i, /*force*/1);
23305 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23306 + au_set_h_dptr(d, bindex, NULL);
23307 + bbot = au_dbbot(d);
23308 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23309 + au_set_h_dptr(d, bindex, NULL);
23310 + au_update_dbrange(d, /*do_put_zero*/0);
23314 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23315 + d_drop(a->src_dentry);
23316 + if (au_ftest_ren(a->auren_flags, DIRREN))
23317 + au_set_dbwh(a->src_dentry, -1);
23321 + d = a->src_dentry;
23322 + au_set_dbwh(d, -1);
23323 + bbot = au_dbbot(d);
23324 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23325 + h_d = au_h_dptr(d, bindex);
23327 + au_set_h_dptr(d, bindex, NULL);
23329 + au_set_dbbot(d, a->btgt);
23332 + i = a->src_inode;
23333 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23334 + return; /* success */
23336 + bbot = au_ibbot(i);
23337 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23338 + h_i = au_h_iptr(i, bindex);
23340 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23341 + /* ignore this error */
23342 + au_set_h_iptr(i, bindex, NULL, 0);
23345 + au_set_ibbot(i, a->btgt);
23348 +/* ---------------------------------------------------------------------- */
23350 +/* mainly for link(2) and rename(2) */
23351 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23353 + aufs_bindex_t bdiropq, bwh;
23354 + struct dentry *parent;
23355 + struct au_branch *br;
23357 + parent = dentry->d_parent;
23358 + IMustLock(d_inode(parent)); /* dir is locked */
23360 + bdiropq = au_dbdiropq(parent);
23361 + bwh = au_dbwh(dentry);
23362 + br = au_sbr(dentry->d_sb, btgt);
23363 + if (au_br_rdonly(br)
23364 + || (0 <= bdiropq && bdiropq < btgt)
23365 + || (0 <= bwh && bwh < btgt))
23368 + AuDbg("btgt %d\n", btgt);
23372 +/* sets src_btop, dst_btop and btgt */
23373 +static int au_ren_wbr(struct au_ren_args *a)
23376 + struct au_wr_dir_args wr_dir_args = {
23377 + /* .force_btgt = -1, */
23378 + .flags = AuWrDir_ADD_ENTRY
23381 + a->src_btop = au_dbtop(a->src_dentry);
23382 + a->dst_btop = au_dbtop(a->dst_dentry);
23383 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23384 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23385 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23386 + wr_dir_args.force_btgt = a->src_btop;
23387 + if (a->dst_inode && a->dst_btop < a->src_btop)
23388 + wr_dir_args.force_btgt = a->dst_btop;
23389 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23390 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23393 + au_update_dbtop(a->dst_dentry);
23398 +static void au_ren_dt(struct au_ren_args *a)
23400 + a->h_path.dentry = a->src_h_parent;
23401 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23402 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23403 + a->h_path.dentry = a->dst_h_parent;
23404 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23407 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23408 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23412 + a->h_path.dentry = a->src_h_dentry;
23413 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23414 + if (d_is_positive(a->dst_h_dentry)) {
23415 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23416 + a->h_path.dentry = a->dst_h_dentry;
23417 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23421 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23423 + struct dentry *h_d;
23424 + struct inode *h_inode;
23426 + au_dtime_revert(a->src_dt + AuPARENT);
23427 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23428 + au_dtime_revert(a->dst_dt + AuPARENT);
23430 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23431 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23432 + h_inode = d_inode(h_d);
23433 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23434 + au_dtime_revert(a->src_dt + AuCHILD);
23435 + inode_unlock(h_inode);
23437 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23438 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23439 + h_inode = d_inode(h_d);
23440 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23441 + au_dtime_revert(a->dst_dt + AuCHILD);
23442 + inode_unlock(h_inode);
23447 +/* ---------------------------------------------------------------------- */
23449 +int aufs_rename(struct user_namespace *userns,
23450 + struct inode *_src_dir, struct dentry *_src_dentry,
23451 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23452 + unsigned int _flags)
23454 + int err, lock_flags;
23456 + /* reduce stack space */
23457 + struct au_ren_args *a;
23458 + struct au_pin pin;
23460 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23461 + IMustLock(_src_dir);
23462 + IMustLock(_dst_dir);
23465 + if (unlikely(_flags & RENAME_WHITEOUT))
23469 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23470 + a = kzalloc(sizeof(*a), GFP_NOFS);
23471 + if (unlikely(!a))
23474 + a->flags = _flags;
23475 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23476 + && RENAME_EXCHANGE > U8_MAX);
23477 + a->exchange = _flags & RENAME_EXCHANGE;
23478 + a->src_dir = _src_dir;
23479 + a->src_dentry = _src_dentry;
23480 + a->src_inode = NULL;
23481 + if (d_really_is_positive(a->src_dentry))
23482 + a->src_inode = d_inode(a->src_dentry);
23483 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23484 + a->dst_dir = _dst_dir;
23485 + a->dst_dentry = _dst_dentry;
23486 + a->dst_inode = NULL;
23487 + if (d_really_is_positive(a->dst_dentry))
23488 + a->dst_inode = d_inode(a->dst_dentry);
23489 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23490 + if (a->dst_inode) {
23492 + * if EXCHANGE && src is non-dir && dst is dir,
23493 + * dst is not locked.
23495 + /* IMustLock(a->dst_inode); */
23496 + au_igrab(a->dst_inode);
23500 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23501 + if (d_is_dir(a->src_dentry)) {
23502 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23503 + if (unlikely(!a->exchange
23504 + && d_really_is_positive(a->dst_dentry)
23505 + && !d_is_dir(a->dst_dentry)))
23507 + lock_flags |= AuLock_DIRS;
23509 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23510 + au_fset_ren(a->auren_flags, ISDIR_DST);
23511 + if (unlikely(!a->exchange
23512 + && d_really_is_positive(a->src_dentry)
23513 + && !d_is_dir(a->src_dentry)))
23515 + lock_flags |= AuLock_DIRS;
23517 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23519 + if (unlikely(err))
23522 + err = au_d_hashed_positive(a->src_dentry);
23523 + if (unlikely(err))
23526 + if (a->dst_inode) {
23528 + * If it is a dir, VFS unhash it before this
23529 + * function. It means we cannot rely upon d_unhashed().
23531 + if (unlikely(!a->dst_inode->i_nlink))
23533 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23534 + err = au_d_hashed_positive(a->dst_dentry);
23535 + if (unlikely(err && !a->exchange))
23537 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23539 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23543 + * is it possible?
23544 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23545 + * there may exist a problem somewhere else.
23548 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23551 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23552 + di_write_lock_parent(a->dst_parent);
23554 + /* which branch we process */
23555 + err = au_ren_wbr(a);
23556 + if (unlikely(err < 0))
23558 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23559 + a->h_path.mnt = au_br_mnt(a->br);
23561 + /* are they available to be renamed */
23562 + err = au_ren_may_dir(a);
23563 + if (unlikely(err))
23564 + goto out_children;
23566 + /* prepare the writable parent dir on the same branch */
23567 + if (a->dst_btop == a->btgt) {
23568 + au_fset_ren(a->auren_flags, WHDST);
23570 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23571 + if (unlikely(err))
23572 + goto out_children;
23576 + if (!a->exchange) {
23577 + if (a->src_dir != a->dst_dir) {
23579 + * this temporary unlock is safe,
23580 + * because both dir->i_mutex are locked.
23582 + di_write_unlock(a->dst_parent);
23583 + di_write_lock_parent(a->src_parent);
23584 + err = au_wr_dir_need_wh(a->src_dentry,
23585 + au_ftest_ren(a->auren_flags,
23588 + di_write_unlock(a->src_parent);
23589 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23591 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23593 + err = au_wr_dir_need_wh(a->src_dentry,
23594 + au_ftest_ren(a->auren_flags,
23598 + if (unlikely(err < 0))
23599 + goto out_children;
23601 + au_fset_ren(a->auren_flags, WHSRC);
23604 + if (a->src_btop != a->btgt) {
23605 + err = au_pin(&pin, a->src_dentry, a->btgt,
23606 + au_opt_udba(a->src_dentry->d_sb),
23607 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23609 + struct au_cp_generic cpg = {
23610 + .dentry = a->src_dentry,
23612 + .bsrc = a->src_btop,
23615 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23617 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23618 + err = au_sio_cpup_simple(&cpg);
23621 + if (unlikely(err))
23622 + goto out_children;
23623 + a->src_btop = a->btgt;
23624 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23625 + if (!a->exchange)
23626 + au_fset_ren(a->auren_flags, WHSRC);
23630 + if (a->exchange && a->dst_inode
23631 + && a->dst_btop != a->btgt) {
23632 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23633 + au_opt_udba(a->dst_dentry->d_sb),
23634 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23636 + struct au_cp_generic cpg = {
23637 + .dentry = a->dst_dentry,
23639 + .bsrc = a->dst_btop,
23642 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23644 + err = au_sio_cpup_simple(&cpg);
23647 + if (unlikely(err))
23648 + goto out_children;
23649 + a->dst_btop = a->btgt;
23650 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23653 + /* lock them all */
23654 + err = au_ren_lock(a);
23655 + if (unlikely(err))
23656 + /* leave the copied-up one */
23657 + goto out_children;
23659 + if (!a->exchange) {
23660 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23661 + err = au_may_ren(a);
23662 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23663 + err = -ENAMETOOLONG;
23664 + if (unlikely(err))
23668 + /* store timestamps to be revertible */
23671 + /* store dirren info */
23672 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23673 + err = au_dr_rename(a->src_dentry, a->btgt,
23674 + &a->dst_dentry->d_name, &rev);
23676 + if (unlikely(err))
23681 + err = do_rename(a);
23682 + if (unlikely(err))
23685 + if (au_ftest_ren(a->auren_flags, DIRREN))
23686 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23688 + /* update dir attributes */
23689 + au_ren_refresh_dir(a);
23691 + /* dput/iput all lower dentries */
23692 + au_ren_refresh(a);
23694 + goto out_hdir; /* success */
23697 + if (au_ftest_ren(a->auren_flags, DIRREN))
23698 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23700 + au_ren_rev_dt(err, a);
23702 + au_ren_unlock(a);
23704 + au_nhash_wh_free(&a->whlist);
23705 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23706 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23707 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23708 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23712 + if (d_unhashed(a->src_dentry))
23713 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23714 + if (d_unhashed(a->dst_dentry))
23715 + au_fset_ren(a->auren_flags, DROPPED_DST);
23716 + if (!a->exchange)
23717 + d_move(a->src_dentry, a->dst_dentry);
23719 + d_exchange(a->src_dentry, a->dst_dentry);
23720 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23721 + d_drop(a->dst_dentry);
23723 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23724 + d_drop(a->src_dentry);
23726 + au_update_dbtop(a->dst_dentry);
23727 + if (!a->dst_inode)
23728 + d_drop(a->dst_dentry);
23730 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23731 + di_write_unlock(a->dst_parent);
23733 + di_write_unlock2(a->src_parent, a->dst_parent);
23735 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23737 + iput(a->dst_inode);
23739 + au_whtmp_rmdir_free(a->thargs);
23745 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23746 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23747 +++ linux/fs/aufs/Kconfig 2021-11-01 23:48:34.203025928 +0100
23749 +# SPDX-License-Identifier: GPL-2.0
23751 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23753 + Aufs is a stackable unification filesystem such as Unionfs,
23754 + which unifies several directories and provides a merged single
23756 + In the early days, aufs was entirely re-designed and
23757 + re-implemented Unionfs Version 1.x series. Introducing many
23758 + original ideas, approaches and improvements, it becomes totally
23759 + different from Unionfs while keeping the basic features.
23763 + prompt "Maximum number of branches"
23764 + default AUFS_BRANCH_MAX_127
23766 + Specifies the maximum number of branches (or member directories)
23767 + in a single aufs. The larger value consumes more system
23768 + resources and has a minor impact to performance.
23769 +config AUFS_BRANCH_MAX_127
23772 + Specifies the maximum number of branches (or member directories)
23773 + in a single aufs. The larger value consumes more system
23774 + resources and has a minor impact to performance.
23775 +config AUFS_BRANCH_MAX_511
23778 + Specifies the maximum number of branches (or member directories)
23779 + in a single aufs. The larger value consumes more system
23780 + resources and has a minor impact to performance.
23781 +config AUFS_BRANCH_MAX_1023
23784 + Specifies the maximum number of branches (or member directories)
23785 + in a single aufs. The larger value consumes more system
23786 + resources and has a minor impact to performance.
23787 +config AUFS_BRANCH_MAX_32767
23790 + Specifies the maximum number of branches (or member directories)
23791 + in a single aufs. The larger value consumes more system
23792 + resources and has a minor impact to performance.
23795 +config AUFS_SBILIST
23797 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23800 + Automatic configuration for internal use.
23801 + When aufs supports Magic SysRq or /proc, enabled automatically.
23803 +config AUFS_HNOTIFY
23804 + bool "Detect direct branch access (bypassing aufs)"
23806 + If you want to modify files on branches directly, eg. bypassing aufs,
23807 + and want aufs to detect the changes of them fully, then enable this
23808 + option and use 'udba=notify' mount option.
23809 + Currently there is only one available configuration, "fsnotify".
23810 + It will have a negative impact to the performance.
23811 + See detail in aufs.5.
23814 + prompt "method" if AUFS_HNOTIFY
23815 + default AUFS_HFSNOTIFY
23816 +config AUFS_HFSNOTIFY
23821 +config AUFS_EXPORT
23822 + bool "NFS-exportable aufs"
23823 + depends on EXPORTFS
23825 + If you want to export your mounted aufs via NFS, then enable this
23826 + option. There are several requirements for this configuration.
23827 + See detail in aufs.5.
23829 +config AUFS_INO_T_64
23831 + depends on AUFS_EXPORT
23832 + depends on 64BIT && !(ALPHA || S390)
23835 + Automatic configuration for internal use.
23836 + /* typedef unsigned long/int __kernel_ino_t */
23837 + /* alpha and s390x are int */
23840 + bool "support for XATTR/EA (including Security Labels)"
23842 + If your branch fs supports XATTR/EA and you want to make them
23843 + available in aufs too, then enable this opsion and specify the
23844 + branch attributes for EA.
23845 + See detail in aufs.5.
23848 + bool "File-based Hierarchical Storage Management"
23850 + Hierarchical Storage Management (or HSM) is a well-known feature
23851 + in the storage world. Aufs provides this feature as file-based.
23852 + with multiple branches.
23853 + These multiple branches are prioritized, ie. the topmost one
23854 + should be the fastest drive and be used heavily.
23857 + bool "Readdir in userspace"
23859 + Aufs has two methods to provide a merged view for a directory,
23860 + by a user-space library and by kernel-space natively. The latter
23861 + is always enabled but sometimes large and slow.
23862 + If you enable this option, install the library in aufs2-util
23863 + package, and set some environment variables for your readdir(3),
23864 + then the work will be handled in user-space which generally
23865 + shows better performance in most cases.
23866 + See detail in aufs.5.
23868 +config AUFS_DIRREN
23869 + bool "Workaround for rename(2)-ing a directory"
23871 + By default, aufs returns EXDEV error in renameing a dir who has
23872 + his child on the lower branch, since it is a bad idea to issue
23873 + rename(2) internally for every lower branch. But user may not
23874 + accept this behaviour. So here is a workaround to allow such
23875 + rename(2) and store some extra infromation on the writable
23876 + branch. Obviously this costs high (and I don't like it).
23877 + To use this feature, you need to enable this configuration AND
23878 + to specify the mount option `dirren.'
23879 + See details in aufs.5 and the design documents.
23882 + bool "Show whiteouts"
23884 + If you want to make the whiteouts in aufs visible, then enable
23885 + this option and specify 'shwh' mount option. Although it may
23886 + sounds like philosophy or something, but in technically it
23887 + simply shows the name of whiteout with keeping its behaviour.
23889 +config AUFS_BR_RAMFS
23890 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23892 + If you want to use ramfs as an aufs branch fs, then enable this
23893 + option. Generally tmpfs is recommended.
23894 + Aufs prohibited them to be a branch fs by default, because
23895 + initramfs becomes unusable after switch_root or something
23896 + generally. If you sets initramfs as an aufs branch and boot your
23897 + system by switch_root, you will meet a problem easily since the
23898 + files in initramfs may be inaccessible.
23899 + Unless you are going to use ramfs as an aufs branch fs without
23900 + switch_root or something, leave it N.
23902 +config AUFS_BR_FUSE
23903 + bool "Fuse fs as an aufs branch"
23904 + depends on FUSE_FS
23907 + If you want to use fuse-based userspace filesystem as an aufs
23908 + branch fs, then enable this option.
23909 + It implements the internal poll(2) operation which is
23910 + implemented by fuse only (curretnly).
23915 + Automatic configuration for internal use.
23917 +config AUFS_BR_HFSPLUS
23918 + bool "Hfsplus as an aufs branch"
23919 + depends on HFSPLUS_FS
23922 + If you want to use hfsplus fs as an aufs branch fs, then enable
23923 + this option. This option introduces a small overhead at
23924 + copying-up a file on hfsplus.
23926 +config AUFS_BDEV_LOOP
23928 + depends on BLK_DEV_LOOP
23931 + Automatic configuration for internal use.
23932 + Convert =[ym] into =y.
23935 + bool "Debug aufs"
23937 + Enable this to compile aufs internal debug code.
23938 + It will have a negative impact to the performance.
23940 +config AUFS_MAGIC_SYSRQ
23942 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23945 + Automatic configuration for internal use.
23946 + When aufs supports Magic SysRq, enabled automatically.
23948 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23949 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23950 +++ linux/fs/aufs/lcnt.h 2021-11-01 23:48:34.209692595 +0100
23952 +/* SPDX-License-Identifier: GPL-2.0 */
23954 + * Copyright (C) 2018-2021 Junjiro R. Okajima
23956 + * This program, aufs is free software; you can redistribute it and/or modify
23957 + * it under the terms of the GNU General Public License as published by
23958 + * the Free Software Foundation; either version 2 of the License, or
23959 + * (at your option) any later version.
23961 + * This program is distributed in the hope that it will be useful,
23962 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23963 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23964 + * GNU General Public License for more details.
23966 + * You should have received a copy of the GNU General Public License
23967 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23971 + * simple long counter wrapper
23974 +#ifndef __AUFS_LCNT_H__
23975 +#define __AUFS_LCNT_H__
23979 +#include "debug.h"
23981 +#define AuLCntATOMIC 1
23982 +#define AuLCntPCPUCNT 2
23984 + * why does percpu_refcount require extra synchronize_rcu()s in
23985 + * au_br_do_free()
23987 +#define AuLCntPCPUREF 3
23989 +/* #define AuLCntChosen AuLCntATOMIC */
23990 +#define AuLCntChosen AuLCntPCPUCNT
23991 +/* #define AuLCntChosen AuLCntPCPUREF */
23993 +#if AuLCntChosen == AuLCntATOMIC
23994 +#include <linux/atomic.h>
23996 +typedef atomic_long_t au_lcnt_t;
23998 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24000 + atomic_long_set(cnt, 0);
24004 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24009 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
24010 + int do_sync __maybe_unused)
24015 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24017 + atomic_long_inc(cnt);
24020 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24022 + atomic_long_dec(cnt);
24025 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24027 + return atomic_long_read(cnt);
24031 +#if AuLCntChosen == AuLCntPCPUCNT
24032 +#include <linux/percpu_counter.h>
24034 +typedef struct percpu_counter au_lcnt_t;
24036 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
24038 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24041 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24046 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24048 + percpu_counter_destroy(cnt);
24051 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24053 + percpu_counter_inc(cnt);
24056 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24058 + percpu_counter_dec(cnt);
24061 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24065 + n = percpu_counter_sum(cnt);
24067 + if (LONG_MAX != LLONG_MAX
24069 + AuWarn1("%s\n", "wrap-around");
24075 +#if AuLCntChosen == AuLCntPCPUREF
24076 +#include <linux/percpu-refcount.h>
24078 +typedef struct percpu_ref au_lcnt_t;
24080 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24083 + release = percpu_ref_exit;
24084 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24087 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24089 + synchronize_rcu();
24092 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24094 + percpu_ref_kill(cnt);
24096 + au_lcnt_wait_for_fin(cnt);
24099 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24101 + percpu_ref_get(cnt);
24104 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24106 + percpu_ref_put(cnt);
24110 + * avoid calling this func as possible.
24112 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24116 + percpu_ref_switch_to_atomic_sync(cnt);
24117 + l = atomic_long_read(&cnt->count);
24119 + percpu_ref_switch_to_percpu(cnt);
24121 + /* percpu_ref is initialized by 1 instead of 0 */
24126 +#ifdef CONFIG_AUFS_DEBUG
24127 +#define AuLCntZero(val) do { \
24130 + AuDbg("%s = %ld\n", #val, l); \
24133 +#define AuLCntZero(val) do {} while (0)
24136 +#endif /* __KERNEL__ */
24137 +#endif /* __AUFS_LCNT_H__ */
24138 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24139 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24140 +++ linux/fs/aufs/loop.c 2021-11-01 23:48:34.209692595 +0100
24142 +// SPDX-License-Identifier: GPL-2.0
24144 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24146 + * This program, aufs is free software; you can redistribute it and/or modify
24147 + * it under the terms of the GNU General Public License as published by
24148 + * the Free Software Foundation; either version 2 of the License, or
24149 + * (at your option) any later version.
24151 + * This program is distributed in the hope that it will be useful,
24152 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24153 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24154 + * GNU General Public License for more details.
24156 + * You should have received a copy of the GNU General Public License
24157 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24161 + * support for loopback block device as a branch
24166 +/* added into drivers/block/loop.c */
24167 +static struct file *(*backing_file_func)(struct super_block *sb);
24170 + * test if two lower dentries have overlapping branches.
24172 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24174 + struct super_block *h_sb;
24175 + struct file *backing_file;
24177 + if (unlikely(!backing_file_func)) {
24178 + /* don't load "loop" module here */
24179 + backing_file_func = symbol_get(loop_backing_file);
24180 + if (unlikely(!backing_file_func))
24181 + /* "loop" module is not loaded */
24185 + h_sb = h_adding->d_sb;
24186 + backing_file = backing_file_func(h_sb);
24187 + if (!backing_file)
24190 + h_adding = backing_file->f_path.dentry;
24192 + * h_adding can be local NFS.
24193 + * in this case aufs cannot detect the loop.
24195 + if (unlikely(h_adding->d_sb == sb))
24197 + return !!au_test_subdir(h_adding, sb->s_root);
24200 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24201 +int au_test_loopback_kthread(void)
24204 + struct task_struct *tsk = current;
24205 + char c, comm[sizeof(tsk->comm)];
24208 + if (tsk->flags & PF_KTHREAD) {
24209 + get_task_comm(comm, tsk);
24211 + ret = ('0' <= c && c <= '9'
24212 + && !strncmp(comm, "loop", 4));
24218 +/* ---------------------------------------------------------------------- */
24220 +#define au_warn_loopback_step 16
24221 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24222 +static unsigned long *au_warn_loopback_array;
24224 +void au_warn_loopback(struct super_block *h_sb)
24226 + int i, new_nelem;
24227 + unsigned long *a, magic;
24228 + static DEFINE_SPINLOCK(spin);
24230 + magic = h_sb->s_magic;
24231 + spin_lock(&spin);
24232 + a = au_warn_loopback_array;
24233 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24234 + if (a[i] == magic) {
24235 + spin_unlock(&spin);
24239 + /* h_sb is new to us, print it */
24240 + if (i < au_warn_loopback_nelem) {
24245 + /* expand the array */
24246 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24247 + a = au_kzrealloc(au_warn_loopback_array,
24248 + au_warn_loopback_nelem * sizeof(unsigned long),
24249 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24250 + /*may_shrink*/0);
24252 + au_warn_loopback_nelem = new_nelem;
24253 + au_warn_loopback_array = a;
24258 + spin_unlock(&spin);
24259 + AuWarn1("realloc failed, ignored\n");
24263 + spin_unlock(&spin);
24264 + pr_warn("you may want to try another patch for loopback file "
24265 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24268 +int au_loopback_init(void)
24271 + struct super_block *sb __maybe_unused;
24273 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24276 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24277 + sizeof(unsigned long), GFP_NOFS);
24278 + if (unlikely(!au_warn_loopback_array))
24284 +void au_loopback_fin(void)
24286 + if (backing_file_func)
24287 + symbol_put(loop_backing_file);
24288 + au_kfree_try_rcu(au_warn_loopback_array);
24290 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24291 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24292 +++ linux/fs/aufs/loop.h 2021-11-01 23:48:34.209692595 +0100
24294 +/* SPDX-License-Identifier: GPL-2.0 */
24296 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24298 + * This program, aufs is free software; you can redistribute it and/or modify
24299 + * it under the terms of the GNU General Public License as published by
24300 + * the Free Software Foundation; either version 2 of the License, or
24301 + * (at your option) any later version.
24303 + * This program is distributed in the hope that it will be useful,
24304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24306 + * GNU General Public License for more details.
24308 + * You should have received a copy of the GNU General Public License
24309 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24313 + * support for loopback mount as a branch
24316 +#ifndef __AUFS_LOOP_H__
24317 +#define __AUFS_LOOP_H__
24322 +struct super_block;
24324 +#ifdef CONFIG_AUFS_BDEV_LOOP
24325 +/* drivers/block/loop.c */
24326 +struct file *loop_backing_file(struct super_block *sb);
24329 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24330 +int au_test_loopback_kthread(void);
24331 +void au_warn_loopback(struct super_block *h_sb);
24333 +int au_loopback_init(void);
24334 +void au_loopback_fin(void);
24336 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24338 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24339 + struct dentry *h_adding)
24340 +AuStubInt0(au_test_loopback_kthread, void)
24341 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24343 +AuStubInt0(au_loopback_init, void)
24344 +AuStubVoid(au_loopback_fin, void)
24345 +#endif /* BLK_DEV_LOOP */
24347 +#endif /* __KERNEL__ */
24348 +#endif /* __AUFS_LOOP_H__ */
24349 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24350 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24351 +++ linux/fs/aufs/magic.mk 2021-11-01 23:48:34.209692595 +0100
24353 +# SPDX-License-Identifier: GPL-2.0
24355 +# defined in ${srctree}/fs/fuse/inode.c
24357 +ifdef CONFIG_FUSE_FS
24358 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24361 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24363 +ifdef CONFIG_XFS_FS
24364 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24367 +# defined in ${srctree}/fs/configfs/mount.c
24369 +ifdef CONFIG_CONFIGFS_FS
24370 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24373 +# defined in ${srctree}/fs/ubifs/ubifs.h
24375 +ifdef CONFIG_UBIFS_FS
24376 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24379 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24381 +ifdef CONFIG_HFSPLUS_FS
24382 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24384 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24385 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24386 +++ linux/fs/aufs/Makefile 2021-11-01 23:48:34.203025928 +0100
24388 +# SPDX-License-Identifier: GPL-2.0
24390 +include ${src}/magic.mk
24391 +ifeq (${CONFIG_AUFS_FS},m)
24392 +include ${src}/conf.mk
24394 +-include ${src}/priv_def.mk
24396 +# cf. include/linux/kernel.h
24398 +ccflags-y += -DDEBUG
24399 +# sparse requires the full pathname
24401 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24403 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24406 +obj-$(CONFIG_AUFS_FS) += aufs.o
24407 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24408 + wkq.o vfsub.o dcsub.o \
24409 + cpup.o whout.o wbr_policy.o \
24410 + dinfo.o dentry.o \
24412 + finfo.o file.o f_op.o \
24414 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24418 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24419 +aufs-$(CONFIG_SYSFS) += sysfs.o
24420 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24421 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24422 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24423 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24424 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24425 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24426 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24427 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24428 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24429 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24430 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24431 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24432 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24433 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24434 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24435 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24436 +++ linux/fs/aufs/module.c 2021-11-01 23:48:34.209692595 +0100
24438 +// SPDX-License-Identifier: GPL-2.0
24440 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24442 + * This program, aufs is free software; you can redistribute it and/or modify
24443 + * it under the terms of the GNU General Public License as published by
24444 + * the Free Software Foundation; either version 2 of the License, or
24445 + * (at your option) any later version.
24447 + * This program is distributed in the hope that it will be useful,
24448 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24449 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24450 + * GNU General Public License for more details.
24452 + * You should have received a copy of the GNU General Public License
24453 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24457 + * module global variables and operations
24460 +#include <linux/module.h>
24461 +#include <linux/seq_file.h>
24464 +/* shrinkable realloc */
24465 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24473 +#if 0 /* unused */
24480 + AuDebugOn(!new_sz);
24483 + diff = au_kmidx_sub(sz, new_sz);
24489 + /* expand or SLOB */
24490 + p = krealloc(p, new_sz, gfp);
24491 + else if (new_sz < sz && may_shrink) {
24495 + q = kmalloc(new_sz, gfp);
24498 + memcpy(q, p, new_sz);
24499 + au_kfree_try_rcu(p);
24510 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24513 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24514 + if (p && new_sz > nused)
24515 + memset(p + nused, 0, new_sz - nused);
24519 +/* ---------------------------------------------------------------------- */
24523 +struct kmem_cache *au_cache[AuCache_Last];
24525 +static void au_cache_fin(void)
24530 + * Make sure all delayed rcu free inodes are flushed before we
24535 + /* excluding AuCache_HNOTIFY */
24536 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24537 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24538 + kmem_cache_destroy(au_cache[i]);
24539 + au_cache[i] = NULL;
24543 +static int __init au_cache_init(void)
24545 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24546 + if (au_cache[AuCache_DINFO])
24547 + /* SLAB_DESTROY_BY_RCU */
24548 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24549 + au_icntnr_init_once);
24550 + if (au_cache[AuCache_ICNTNR])
24551 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24552 + au_fi_init_once);
24553 + if (au_cache[AuCache_FINFO])
24554 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24555 + if (au_cache[AuCache_VDIR])
24556 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24557 + if (au_cache[AuCache_DEHSTR])
24564 +/* ---------------------------------------------------------------------- */
24566 +int au_dir_roflags;
24568 +#ifdef CONFIG_AUFS_SBILIST
24570 + * iterate_supers_type() doesn't protect us from
24571 + * remounting (branch management)
24573 +struct hlist_bl_head au_sbilist;
24577 + * functions for module interface.
24579 +MODULE_LICENSE("GPL");
24580 +/* MODULE_LICENSE("GPL v2"); */
24581 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24582 +MODULE_DESCRIPTION(AUFS_NAME
24583 + " -- Advanced multi layered unification filesystem");
24584 +MODULE_VERSION(AUFS_VERSION);
24585 +MODULE_ALIAS_FS(AUFS_NAME);
24587 +/* this module parameter has no meaning when SYSFS is disabled */
24588 +int sysaufs_brs = 1;
24589 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24590 +module_param_named(brs, sysaufs_brs, int, 0444);
24592 +/* this module parameter has no meaning when USER_NS is disabled */
24594 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24595 +module_param_named(allow_userns, au_userns, bool, 0444);
24597 +/* ---------------------------------------------------------------------- */
24599 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24601 +int au_seq_path(struct seq_file *seq, struct path *path)
24605 + err = seq_path(seq, path, au_esc_chars);
24614 +/* ---------------------------------------------------------------------- */
24616 +static int __init aufs_init(void)
24621 + p = au_esc_chars;
24622 + for (i = 1; i <= ' '; i++)
24628 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24630 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24631 + for (i = 0; i < AuIop_Last; i++)
24632 + aufs_iop_nogetattr[i].getattr = NULL;
24634 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24636 + au_sbilist_init();
24637 + sysaufs_brs_init();
24640 + err = sysaufs_init();
24641 + if (unlikely(err))
24643 + err = dbgaufs_init();
24644 + if (unlikely(err))
24645 + goto out_sysaufs;
24646 + err = au_procfs_init();
24647 + if (unlikely(err))
24648 + goto out_dbgaufs;
24649 + err = au_wkq_init();
24650 + if (unlikely(err))
24652 + err = au_loopback_init();
24653 + if (unlikely(err))
24655 + err = au_hnotify_init();
24656 + if (unlikely(err))
24657 + goto out_loopback;
24658 + err = au_sysrq_init();
24659 + if (unlikely(err))
24661 + err = au_cache_init();
24662 + if (unlikely(err))
24665 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24666 + err = register_filesystem(&aufs_fs_type);
24667 + if (unlikely(err))
24670 + /* since we define pr_fmt, call printk directly */
24671 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24672 + goto out; /* success */
24679 + au_hnotify_fin();
24681 + au_loopback_fin();
24695 +static void __exit aufs_exit(void)
24697 + unregister_filesystem(&aufs_fs_type);
24700 + au_hnotify_fin();
24701 + au_loopback_fin();
24709 +module_init(aufs_init);
24710 +module_exit(aufs_exit);
24711 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24712 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24713 +++ linux/fs/aufs/module.h 2021-11-01 23:48:34.209692595 +0100
24715 +/* SPDX-License-Identifier: GPL-2.0 */
24717 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24719 + * This program, aufs is free software; you can redistribute it and/or modify
24720 + * it under the terms of the GNU General Public License as published by
24721 + * the Free Software Foundation; either version 2 of the License, or
24722 + * (at your option) any later version.
24724 + * This program is distributed in the hope that it will be useful,
24725 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24726 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24727 + * GNU General Public License for more details.
24729 + * You should have received a copy of the GNU General Public License
24730 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24734 + * module initialization and module-global
24737 +#ifndef __AUFS_MODULE_H__
24738 +#define __AUFS_MODULE_H__
24742 +#include <linux/slab.h>
24743 +#include "debug.h"
24744 +#include "dentry.h"
24747 +#include "inode.h"
24752 +/* module parameters */
24753 +extern int sysaufs_brs;
24754 +extern bool au_userns;
24756 +/* ---------------------------------------------------------------------- */
24758 +extern int au_dir_roflags;
24760 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24761 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24765 + * Comparing the size of the object with sizeof(struct rcu_head)
24766 + * case 1: object is always larger
24767 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24768 + * case 2: object is always smaller
24769 + * --> au_kfree_small()
24770 + * case 3: object can be any size
24771 + * --> au_kfree_try_rcu()
24774 +static inline void au_kfree_do_rcu(const void *p)
24777 + struct rcu_head rcu;
24778 + } *a = (void *)p;
24780 + kfree_rcu(a, rcu);
24783 +#define au_kfree_rcu(_p) do { \
24784 + typeof(_p) p = (_p); \
24785 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24787 + au_kfree_do_rcu(p); \
24790 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24791 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24793 +static inline void au_kfree_try_rcu(const void *p)
24797 + if (au_kfree_sz_test(p))
24798 + au_kfree_do_rcu(p);
24803 +static inline void au_kfree_small(const void *p)
24807 + AuDebugOn(au_kfree_sz_test(p));
24811 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24813 +#ifndef CONFIG_SLOB
24814 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
24816 + return -1; /* SLOB is untested */
24820 +int au_seq_path(struct seq_file *seq, struct path *path);
24822 +#ifdef CONFIG_PROC_FS
24824 +int __init au_procfs_init(void);
24825 +void au_procfs_fin(void);
24827 +AuStubInt0(au_procfs_init, void);
24828 +AuStubVoid(au_procfs_fin, void);
24831 +/* ---------------------------------------------------------------------- */
24840 + AuCache_HNOTIFY, /* must be last */
24844 +extern struct kmem_cache *au_cache[AuCache_Last];
24846 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24847 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24848 +#define AuCacheCtor(type, ctor) \
24849 + kmem_cache_create(#type, sizeof(struct type), \
24850 + __alignof__(struct type), AuCacheFlags, ctor)
24852 +#define AuCacheFuncs(name, index) \
24853 + static inline struct au_##name *au_cache_alloc_##name(void) \
24854 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24855 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24856 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24858 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24859 + { void *p = rcu; \
24860 + p -= offsetof(struct au_##name, rcu); \
24861 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24862 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24863 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24864 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24866 + static inline void au_cache_free_##name(struct au_##name *p) \
24867 + { /* au_cache_free_##name##_norcu(p); */ \
24868 + au_cache_free_##name##_rcu(p); }
24870 +AuCacheFuncs(dinfo, DINFO);
24871 +AuCacheFuncs(icntnr, ICNTNR);
24872 +AuCacheFuncs(finfo, FINFO);
24873 +AuCacheFuncs(vdir, VDIR);
24874 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24875 +#ifdef CONFIG_AUFS_HNOTIFY
24876 +AuCacheFuncs(hnotify, HNOTIFY);
24879 +#endif /* __KERNEL__ */
24880 +#endif /* __AUFS_MODULE_H__ */
24881 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24882 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24883 +++ linux/fs/aufs/mvdown.c 2021-11-01 23:48:34.209692595 +0100
24885 +// SPDX-License-Identifier: GPL-2.0
24887 + * Copyright (C) 2011-2021 Junjiro R. Okajima
24889 + * This program, aufs is free software; you can redistribute it and/or modify
24890 + * it under the terms of the GNU General Public License as published by
24891 + * the Free Software Foundation; either version 2 of the License, or
24892 + * (at your option) any later version.
24894 + * This program is distributed in the hope that it will be useful,
24895 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24896 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24897 + * GNU General Public License for more details.
24899 + * You should have received a copy of the GNU General Public License
24900 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24904 + * move-down, opposite of copy-up
24909 +struct au_mvd_args {
24911 + struct super_block *h_sb;
24912 + struct dentry *h_parent;
24913 + struct au_hinode *hdir;
24914 + struct inode *h_dir, *h_inode;
24915 + struct au_pin pin;
24916 + } info[AUFS_MVDOWN_NARRAY];
24918 + struct aufs_mvdown mvdown;
24919 + struct dentry *dentry, *parent;
24920 + struct inode *inode, *dir;
24921 + struct super_block *sb;
24922 + aufs_bindex_t bopq, bwh, bfound;
24923 + unsigned char rename_lock;
24926 +#define mvd_errno mvdown.au_errno
24927 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24928 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24929 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24930 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24932 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24933 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24934 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24935 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24936 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24937 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24939 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24940 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24941 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24942 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24943 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24944 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24946 +#define AU_MVD_PR(flag, ...) do { \
24948 + pr_err(__VA_ARGS__); \
24951 +static int find_lower_writable(struct au_mvd_args *a)
24953 + struct super_block *sb;
24954 + aufs_bindex_t bindex, bbot;
24955 + struct au_branch *br;
24958 + bindex = a->mvd_bsrc;
24959 + bbot = au_sbbot(sb);
24960 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24961 + for (bindex++; bindex <= bbot; bindex++) {
24962 + br = au_sbr(sb, bindex);
24963 + if (au_br_fhsm(br->br_perm)
24964 + && !sb_rdonly(au_br_sb(br)))
24967 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24968 + for (bindex++; bindex <= bbot; bindex++) {
24969 + br = au_sbr(sb, bindex);
24970 + if (!au_br_rdonly(br))
24974 + for (bindex++; bindex <= bbot; bindex++) {
24975 + br = au_sbr(sb, bindex);
24976 + if (!sb_rdonly(au_br_sb(br))) {
24977 + if (au_br_rdonly(br))
24979 + |= AUFS_MVDOWN_ROLOWER_R;
24987 +/* make the parent dir on bdst */
24988 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24993 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24994 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24995 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24996 + a->mvd_h_dst_parent = NULL;
24997 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24998 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24999 + if (!a->mvd_h_dst_parent) {
25000 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
25001 + if (unlikely(err)) {
25002 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
25005 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
25013 +/* lock them all */
25014 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
25017 + struct dentry *h_trap;
25019 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
25020 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
25021 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
25022 + au_opt_udba(a->sb),
25023 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25025 + if (unlikely(err)) {
25026 + AU_MVD_PR(dmsg, "pin_dst failed\n");
25030 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
25031 + a->rename_lock = 0;
25032 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25033 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
25034 + au_opt_udba(a->sb),
25035 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25036 + err = au_do_pin(&a->mvd_pin_src);
25038 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25039 + if (unlikely(err)) {
25040 + AU_MVD_PR(dmsg, "pin_src failed\n");
25043 + goto out; /* success */
25046 + a->rename_lock = 1;
25047 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25048 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25049 + au_opt_udba(a->sb),
25050 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25052 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25053 + if (unlikely(err)) {
25054 + AU_MVD_PR(dmsg, "pin_src failed\n");
25055 + au_pin_hdir_lock(&a->mvd_pin_dst);
25058 + au_pin_hdir_unlock(&a->mvd_pin_src);
25059 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25060 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25062 + err = (h_trap != a->mvd_h_src_parent);
25064 + err = (h_trap != a->mvd_h_dst_parent);
25066 + BUG_ON(err); /* it should never happen */
25067 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25070 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25071 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25072 + au_pin_hdir_lock(&a->mvd_pin_src);
25073 + au_unpin(&a->mvd_pin_src);
25074 + au_pin_hdir_lock(&a->mvd_pin_dst);
25077 + goto out; /* success */
25080 + au_unpin(&a->mvd_pin_dst);
25086 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25088 + if (!a->rename_lock)
25089 + au_unpin(&a->mvd_pin_src);
25091 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25092 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25093 + au_pin_hdir_lock(&a->mvd_pin_src);
25094 + au_unpin(&a->mvd_pin_src);
25095 + au_pin_hdir_lock(&a->mvd_pin_dst);
25097 + au_unpin(&a->mvd_pin_dst);
25100 +/* copy-down the file */
25101 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25104 + struct au_cp_generic cpg = {
25105 + .dentry = a->dentry,
25106 + .bdst = a->mvd_bdst,
25107 + .bsrc = a->mvd_bsrc,
25109 + .pin = &a->mvd_pin_dst,
25110 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25113 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25114 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25115 + au_fset_cpup(cpg.flags, OVERWRITE);
25116 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25117 + au_fset_cpup(cpg.flags, RWDST);
25118 + err = au_sio_cpdown_simple(&cpg);
25119 + if (unlikely(err))
25120 + AU_MVD_PR(dmsg, "cpdown failed\n");
25127 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25130 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25133 + struct path h_path;
25134 + struct au_branch *br;
25135 + struct inode *delegated;
25137 + br = au_sbr(a->sb, a->mvd_bdst);
25138 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25139 + err = PTR_ERR(h_path.dentry);
25140 + if (IS_ERR(h_path.dentry)) {
25141 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25146 + if (d_is_positive(h_path.dentry)) {
25147 + h_path.mnt = au_br_mnt(br);
25148 + delegated = NULL;
25149 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25150 + &delegated, /*force*/0);
25151 + if (unlikely(err == -EWOULDBLOCK)) {
25152 + pr_warn("cannot retry for NFSv4 delegation"
25153 + " for an internal unlink\n");
25156 + if (unlikely(err))
25157 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25159 + dput(h_path.dentry);
25167 + * unlink the topmost h_dentry
25169 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25172 + struct path h_path;
25173 + struct inode *delegated;
25175 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25176 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25177 + delegated = NULL;
25178 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25179 + if (unlikely(err == -EWOULDBLOCK)) {
25180 + pr_warn("cannot retry for NFSv4 delegation"
25181 + " for an internal unlink\n");
25184 + if (unlikely(err))
25185 + AU_MVD_PR(dmsg, "unlink failed\n");
25191 +/* Since mvdown succeeded, we ignore an error of this function */
25192 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25195 + struct au_branch *br;
25197 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25198 + br = au_sbr(a->sb, a->mvd_bsrc);
25199 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25201 + br = au_sbr(a->sb, a->mvd_bdst);
25202 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25203 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25206 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25208 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25212 + * copy-down the file and unlink the bsrc file.
25213 + * - unlink the bdst whout if exist
25214 + * - copy-down the file (with whtmp name and rename)
25215 + * - unlink the bsrc file
25217 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25221 + err = au_do_mkdir(dmsg, a);
25223 + err = au_do_lock(dmsg, a);
25224 + if (unlikely(err))
25228 + * do not revert the activities we made on bdst since they should be
25229 + * harmless in aufs.
25232 + err = au_do_cpdown(dmsg, a);
25234 + err = au_do_unlink_wh(dmsg, a);
25235 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25236 + err = au_do_unlink(dmsg, a);
25237 + if (unlikely(err))
25240 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25241 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25242 + if (find_lower_writable(a) < 0)
25243 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25245 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25246 + au_do_stfs(dmsg, a);
25248 + /* maintain internal array */
25249 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25250 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25251 + au_set_dbtop(a->dentry, a->mvd_bdst);
25252 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25253 + au_set_ibtop(a->inode, a->mvd_bdst);
25255 + /* hide the lower */
25256 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25257 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25258 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25259 + au_set_ibbot(a->inode, a->mvd_bsrc);
25261 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25262 + au_set_dbbot(a->dentry, a->mvd_bdst);
25263 + if (au_ibbot(a->inode) < a->mvd_bdst)
25264 + au_set_ibbot(a->inode, a->mvd_bdst);
25267 + au_do_unlock(dmsg, a);
25273 +/* ---------------------------------------------------------------------- */
25275 +/* make sure the file is idle */
25276 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25278 + int err, plinked;
25281 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25282 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25283 + && au_dcount(a->dentry) == 1
25284 + && atomic_read(&a->inode->i_count) == 1
25285 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25286 + && (!plinked || !au_plink_test(a->inode))
25287 + && a->inode->i_nlink == 1)
25292 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25293 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25294 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25295 + a->mvd_h_src_inode->i_nlink,
25296 + plinked, plinked ? au_plink_test(a->inode) : 0);
25303 +/* make sure the parent dir is fine */
25304 +static int au_mvd_args_parent(const unsigned char dmsg,
25305 + struct au_mvd_args *a)
25308 + aufs_bindex_t bindex;
25311 + if (unlikely(au_alive_dir(a->parent))) {
25313 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25317 + a->bopq = au_dbdiropq(a->parent);
25318 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25319 + AuDbg("b%d\n", bindex);
25320 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25321 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25323 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25324 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25325 + a->bopq, a->mvd_bdst);
25333 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25334 + struct au_mvd_args *a)
25337 + struct au_dinfo *dinfo, *tmp;
25339 + /* lookup the next lower positive entry */
25341 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25342 + if (unlikely(!tmp))
25347 + dinfo = au_di(a->dentry);
25348 + au_di_cp(tmp, dinfo);
25349 + au_di_swap(tmp, dinfo);
25351 + /* returns the number of positive dentries */
25352 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25353 + /* AuLkup_IGNORE_PERM */ 0);
25355 + a->bwh = au_dbwh(a->dentry);
25356 + else if (err > 0)
25357 + a->bfound = au_dbtop(a->dentry);
25359 + au_di_swap(tmp, dinfo);
25360 + au_rw_write_unlock(&tmp->di_rwsem);
25362 + if (unlikely(err < 0))
25363 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25366 + * here, we have these cases.
25368 + * no positive dentry under bsrc. there are more sub-cases.
25370 + * there no whiteout, we can safely move-down.
25373 + * bsrc < bwh && bwh < bdst
25374 + * there is a whiteout on RO branch. cannot proceed.
25376 + * there is a whiteout on the RW target branch. it should
25379 + * there is a whiteout somewhere unrelated branch.
25380 + * -1 < bfound && bfound <= bsrc
25383 + * found, but it is on RO branch between bsrc and bdst. cannot
25386 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25389 + * found, after we create the file on bdst, it will be hidden.
25392 + AuDebugOn(a->bfound == -1
25394 + && a->bwh <= a->mvd_bsrc);
25395 + AuDebugOn(-1 < a->bfound
25396 + && a->bfound <= a->mvd_bsrc);
25399 + if (a->bfound == -1
25400 + && a->mvd_bsrc < a->bwh
25402 + && a->bwh < a->mvd_bdst) {
25403 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25404 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25405 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25407 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25408 + a->mvd_errno = EAU_MVDOWN_UPPER;
25409 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25410 + a->mvd_bdst, a->bfound);
25414 + err = 0; /* success */
25421 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25426 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25427 + && a->bfound == a->mvd_bdst)
25433 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25436 + struct au_branch *br;
25439 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25443 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25444 + a->mvd_bsrc = au_ibtop(a->inode);
25446 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25447 + if (unlikely(a->mvd_bsrc < 0
25448 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25449 + || au_dbbot(a->dentry) < a->mvd_bsrc
25450 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25451 + || (a->mvd_bsrc < au_ibtop(a->inode)
25452 + || au_ibbot(a->inode) < a->mvd_bsrc
25453 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25454 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25455 + AU_MVD_PR(dmsg, "no upper\n");
25459 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25460 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25461 + AU_MVD_PR(dmsg, "on the bottom\n");
25464 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25465 + br = au_sbr(a->sb, a->mvd_bsrc);
25466 + err = au_br_rdonly(br);
25467 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25468 + if (unlikely(err))
25470 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25471 + || IS_APPEND(a->mvd_h_src_inode))) {
25473 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25479 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25480 + a->mvd_bdst = find_lower_writable(a);
25481 + if (unlikely(a->mvd_bdst < 0)) {
25482 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25483 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25487 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25488 + if (unlikely(a->mvd_bdst < 0
25489 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25490 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25491 + AU_MVD_PR(dmsg, "no lower brid\n");
25496 + err = au_mvd_args_busy(dmsg, a);
25498 + err = au_mvd_args_parent(dmsg, a);
25500 + err = au_mvd_args_intermediate(dmsg, a);
25502 + err = au_mvd_args_exist(dmsg, a);
25504 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25511 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25514 + unsigned char dmsg;
25515 + struct au_mvd_args *args;
25516 + struct inode *inode;
25518 + inode = d_inode(dentry);
25520 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25524 + args = kmalloc(sizeof(*args), GFP_NOFS);
25525 + if (unlikely(!args))
25528 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25530 + /* VERIFY_WRITE */
25531 + err = !access_ok(uarg, sizeof(*uarg));
25532 + if (unlikely(err)) {
25537 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25538 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25539 + args->mvdown.au_errno = 0;
25540 + args->dentry = dentry;
25541 + args->inode = inode;
25542 + args->sb = dentry->d_sb;
25545 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25546 + args->parent = dget_parent(dentry);
25547 + args->dir = d_inode(args->parent);
25548 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25549 + dput(args->parent);
25550 + if (unlikely(args->parent != dentry->d_parent)) {
25551 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25555 + inode_lock_nested(inode, I_MUTEX_CHILD);
25556 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25557 + if (unlikely(err))
25560 + di_write_lock_parent(args->parent);
25561 + err = au_mvd_args(dmsg, args);
25562 + if (unlikely(err))
25565 + err = au_do_mvdown(dmsg, args);
25566 + if (unlikely(err))
25569 + au_cpup_attr_timesizes(args->dir);
25570 + au_cpup_attr_timesizes(inode);
25571 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25572 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25573 + /* au_digen_dec(dentry); */
25576 + di_write_unlock(args->parent);
25577 + aufs_read_unlock(dentry, AuLock_DW);
25579 + inode_unlock(inode);
25581 + inode_unlock(args->dir);
25583 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25586 + au_kfree_rcu(args);
25591 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25592 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25593 +++ linux/fs/aufs/opts.c 2021-11-01 23:48:34.209692595 +0100
25595 +// SPDX-License-Identifier: GPL-2.0
25597 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25599 + * This program, aufs is free software; you can redistribute it and/or modify
25600 + * it under the terms of the GNU General Public License as published by
25601 + * the Free Software Foundation; either version 2 of the License, or
25602 + * (at your option) any later version.
25604 + * This program is distributed in the hope that it will be useful,
25605 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25606 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25607 + * GNU General Public License for more details.
25609 + * You should have received a copy of the GNU General Public License
25610 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25614 + * mount options/flags
25617 +#include <linux/namei.h>
25618 +#include <linux/types.h> /* a distribution requires */
25619 +#include <linux/parser.h>
25622 +/* ---------------------------------------------------------------------- */
25626 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25627 + Opt_idel, Opt_imod,
25628 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25629 + Opt_rdblk_def, Opt_rdhash_def,
25630 + Opt_xino, Opt_noxino,
25631 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25632 + Opt_trunc_xino_path, Opt_itrunc_xino,
25633 + Opt_trunc_xib, Opt_notrunc_xib,
25634 + Opt_shwh, Opt_noshwh,
25635 + Opt_plink, Opt_noplink, Opt_list_plink,
25637 + Opt_dio, Opt_nodio,
25638 + Opt_diropq_a, Opt_diropq_w,
25639 + Opt_warn_perm, Opt_nowarn_perm,
25640 + Opt_wbr_copyup, Opt_wbr_create,
25642 + Opt_verbose, Opt_noverbose,
25643 + Opt_sum, Opt_nosum, Opt_wsum,
25644 + Opt_dirperm1, Opt_nodirperm1,
25645 + Opt_dirren, Opt_nodirren,
25646 + Opt_acl, Opt_noacl,
25647 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25650 +static match_table_t options = {
25651 + {Opt_br, "br=%s"},
25652 + {Opt_br, "br:%s"},
25654 + {Opt_add, "add=%d:%s"},
25655 + {Opt_add, "add:%d:%s"},
25656 + {Opt_add, "ins=%d:%s"},
25657 + {Opt_add, "ins:%d:%s"},
25658 + {Opt_append, "append=%s"},
25659 + {Opt_append, "append:%s"},
25660 + {Opt_prepend, "prepend=%s"},
25661 + {Opt_prepend, "prepend:%s"},
25663 + {Opt_del, "del=%s"},
25664 + {Opt_del, "del:%s"},
25665 + /* {Opt_idel, "idel:%d"}, */
25666 + {Opt_mod, "mod=%s"},
25667 + {Opt_mod, "mod:%s"},
25668 + /* {Opt_imod, "imod:%d:%s"}, */
25670 + {Opt_dirwh, "dirwh=%d"},
25672 + {Opt_xino, "xino=%s"},
25673 + {Opt_noxino, "noxino"},
25674 + {Opt_trunc_xino, "trunc_xino"},
25675 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25676 + {Opt_notrunc_xino, "notrunc_xino"},
25677 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25678 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25679 + /* {Opt_zxino, "zxino=%s"}, */
25680 + {Opt_trunc_xib, "trunc_xib"},
25681 + {Opt_notrunc_xib, "notrunc_xib"},
25683 +#ifdef CONFIG_PROC_FS
25684 + {Opt_plink, "plink"},
25686 + {Opt_ignore_silent, "plink"},
25689 + {Opt_noplink, "noplink"},
25691 +#ifdef CONFIG_AUFS_DEBUG
25692 + {Opt_list_plink, "list_plink"},
25695 + {Opt_udba, "udba=%s"},
25697 + {Opt_dio, "dio"},
25698 + {Opt_nodio, "nodio"},
25700 +#ifdef CONFIG_AUFS_DIRREN
25701 + {Opt_dirren, "dirren"},
25702 + {Opt_nodirren, "nodirren"},
25704 + {Opt_ignore, "dirren"},
25705 + {Opt_ignore_silent, "nodirren"},
25708 +#ifdef CONFIG_AUFS_FHSM
25709 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25711 + {Opt_ignore, "fhsm_sec=%d"},
25714 + {Opt_diropq_a, "diropq=always"},
25715 + {Opt_diropq_a, "diropq=a"},
25716 + {Opt_diropq_w, "diropq=whiteouted"},
25717 + {Opt_diropq_w, "diropq=w"},
25719 + {Opt_warn_perm, "warn_perm"},
25720 + {Opt_nowarn_perm, "nowarn_perm"},
25722 + /* keep them temporary */
25723 + {Opt_ignore_silent, "nodlgt"},
25724 + {Opt_ignore, "clean_plink"},
25726 +#ifdef CONFIG_AUFS_SHWH
25727 + {Opt_shwh, "shwh"},
25729 + {Opt_noshwh, "noshwh"},
25731 + {Opt_dirperm1, "dirperm1"},
25732 + {Opt_nodirperm1, "nodirperm1"},
25734 + {Opt_verbose, "verbose"},
25735 + {Opt_verbose, "v"},
25736 + {Opt_noverbose, "noverbose"},
25737 + {Opt_noverbose, "quiet"},
25738 + {Opt_noverbose, "q"},
25739 + {Opt_noverbose, "silent"},
25741 + {Opt_sum, "sum"},
25742 + {Opt_nosum, "nosum"},
25743 + {Opt_wsum, "wsum"},
25745 + {Opt_rdcache, "rdcache=%d"},
25746 + {Opt_rdblk, "rdblk=%d"},
25747 + {Opt_rdblk_def, "rdblk=def"},
25748 + {Opt_rdhash, "rdhash=%d"},
25749 + {Opt_rdhash_def, "rdhash=def"},
25751 + {Opt_wbr_create, "create=%s"},
25752 + {Opt_wbr_create, "create_policy=%s"},
25753 + {Opt_wbr_copyup, "cpup=%s"},
25754 + {Opt_wbr_copyup, "copyup=%s"},
25755 + {Opt_wbr_copyup, "copyup_policy=%s"},
25757 + /* generic VFS flag */
25758 +#ifdef CONFIG_FS_POSIX_ACL
25759 + {Opt_acl, "acl"},
25760 + {Opt_noacl, "noacl"},
25762 + {Opt_ignore, "acl"},
25763 + {Opt_ignore_silent, "noacl"},
25766 + /* internal use for the scripts */
25767 + {Opt_ignore_silent, "si=%s"},
25769 + {Opt_br, "dirs=%s"},
25770 + {Opt_ignore, "debug=%d"},
25771 + {Opt_ignore, "delete=whiteout"},
25772 + {Opt_ignore, "delete=all"},
25773 + {Opt_ignore, "imap=%s"},
25775 + /* temporary workaround, due to old mount(8)? */
25776 + {Opt_ignore_silent, "relatime"},
25781 +/* ---------------------------------------------------------------------- */
25783 +static const char *au_parser_pattern(int val, match_table_t tbl)
25785 + struct match_token *p;
25788 + while (p->pattern) {
25789 + if (p->token == val)
25790 + return p->pattern;
25797 +static const char *au_optstr(int *val, match_table_t tbl)
25799 + struct match_token *p;
25806 + while (p->pattern) {
25808 + && (v & p->token) == p->token) {
25809 + *val &= ~p->token;
25810 + return p->pattern;
25819 +/* ---------------------------------------------------------------------- */
25821 +static match_table_t brperm = {
25822 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25823 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25824 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25828 +static match_table_t brattr = {
25830 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25831 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25832 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25833 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25834 +#ifdef CONFIG_AUFS_FHSM
25835 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25837 +#ifdef CONFIG_AUFS_XATTR
25838 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25839 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25840 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25841 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25842 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25843 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25846 + /* ro/rr branch */
25847 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25850 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25851 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25856 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25863 + p = strchr(str, '+');
25866 + v = match_token(str, table, args);
25868 + if (v & AuBrAttr_CMOO_Mask)
25869 + attr &= ~AuBrAttr_CMOO_Mask;
25874 + pr_warn("ignored branch attribute %s\n", str);
25884 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25892 + p = au_optstr(&perm, brattr);
25895 + memcpy(q, p, sz + 1);
25901 + p = au_optstr(&perm, brattr);
25905 + memcpy(q, p, sz + 1);
25911 + return q - str->a;
25914 +static int noinline_for_stack br_perm_val(char *perm)
25916 + int val, bad, sz;
25918 + substring_t args[MAX_OPT_ARGS];
25919 + au_br_perm_str_t attr;
25921 + p = strchr(perm, '+');
25924 + val = match_token(perm, brperm, args);
25928 + pr_warn("ignored branch permission %s\n", perm);
25929 + val = AuBrPerm_RO;
25935 + val |= br_attr_val(p + 1, brattr, args);
25938 + switch (val & AuBrPerm_Mask) {
25939 + case AuBrPerm_RO:
25940 + case AuBrPerm_RR:
25941 + bad = val & AuBrWAttr_Mask;
25942 + val &= ~AuBrWAttr_Mask;
25944 + case AuBrPerm_RW:
25945 + bad = val & AuBrRAttr_Mask;
25946 + val &= ~AuBrRAttr_Mask;
25951 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25952 + * does not treat it as an error, just warning.
25953 + * this is a tiny guard for the user operation.
25955 + if (val & AuBrAttr_UNPIN) {
25956 + bad |= AuBrAttr_UNPIN;
25957 + val &= ~AuBrAttr_UNPIN;
25960 + if (unlikely(bad)) {
25961 + sz = au_do_optstr_br_attr(&attr, bad);
25963 + pr_warn("ignored branch attribute %s\n", attr.a);
25970 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25972 + au_br_perm_str_t attr;
25978 + p = au_optstr(&perm, brperm);
25979 + AuDebugOn(!p || !*p);
25981 + memcpy(q, p, sz + 1);
25984 + sz = au_do_optstr_br_attr(&attr, perm);
25987 + memcpy(q, attr.a, sz + 1);
25990 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25993 +/* ---------------------------------------------------------------------- */
25995 +static match_table_t udbalevel = {
25996 + {AuOpt_UDBA_REVAL, "reval"},
25997 + {AuOpt_UDBA_NONE, "none"},
25998 +#ifdef CONFIG_AUFS_HNOTIFY
25999 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
26000 +#ifdef CONFIG_AUFS_HFSNOTIFY
26001 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
26007 +static int noinline_for_stack udba_val(char *str)
26009 + substring_t args[MAX_OPT_ARGS];
26011 + return match_token(str, udbalevel, args);
26014 +const char *au_optstr_udba(int udba)
26016 + return au_parser_pattern(udba, udbalevel);
26019 +/* ---------------------------------------------------------------------- */
26021 +static match_table_t au_wbr_create_policy = {
26022 + {AuWbrCreate_TDP, "tdp"},
26023 + {AuWbrCreate_TDP, "top-down-parent"},
26024 + {AuWbrCreate_RR, "rr"},
26025 + {AuWbrCreate_RR, "round-robin"},
26026 + {AuWbrCreate_MFS, "mfs"},
26027 + {AuWbrCreate_MFS, "most-free-space"},
26028 + {AuWbrCreate_MFSV, "mfs:%d"},
26029 + {AuWbrCreate_MFSV, "most-free-space:%d"},
26031 + /* top-down regardless the parent, and then mfs */
26032 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
26033 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
26035 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
26036 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
26037 + {AuWbrCreate_PMFS, "pmfs"},
26038 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26039 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26040 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26045 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26046 + struct au_opt_wbr_create *create)
26049 + unsigned long long ull;
26052 + if (!match_u64(arg, &ull))
26053 + create->mfsrr_watermark = ull;
26055 + pr_err("bad integer in %s\n", str);
26062 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26063 + struct au_opt_wbr_create *create)
26068 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26069 + create->mfs_second = n;
26071 + pr_err("bad integer in %s\n", str);
26078 +static int noinline_for_stack
26079 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26082 + substring_t args[MAX_OPT_ARGS];
26084 + err = match_token(str, au_wbr_create_policy, args);
26085 + create->wbr_create = err;
26087 + case AuWbrCreate_MFSRRV:
26088 + case AuWbrCreate_TDMFSV:
26089 + case AuWbrCreate_PMFSRRV:
26090 + e = au_wbr_mfs_wmark(&args[0], str, create);
26092 + e = au_wbr_mfs_sec(&args[1], str, create);
26096 + case AuWbrCreate_MFSRR:
26097 + case AuWbrCreate_TDMFS:
26098 + case AuWbrCreate_PMFSRR:
26099 + e = au_wbr_mfs_wmark(&args[0], str, create);
26100 + if (unlikely(e)) {
26105 + case AuWbrCreate_MFS:
26106 + case AuWbrCreate_PMFS:
26107 + create->mfs_second = AUFS_MFS_DEF_SEC;
26109 + case AuWbrCreate_MFSV:
26110 + case AuWbrCreate_PMFSV:
26111 + e = au_wbr_mfs_sec(&args[0], str, create);
26120 +const char *au_optstr_wbr_create(int wbr_create)
26122 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26125 +static match_table_t au_wbr_copyup_policy = {
26126 + {AuWbrCopyup_TDP, "tdp"},
26127 + {AuWbrCopyup_TDP, "top-down-parent"},
26128 + {AuWbrCopyup_BUP, "bup"},
26129 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26130 + {AuWbrCopyup_BU, "bu"},
26131 + {AuWbrCopyup_BU, "bottom-up"},
26135 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26137 + substring_t args[MAX_OPT_ARGS];
26139 + return match_token(str, au_wbr_copyup_policy, args);
26142 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26144 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26147 +/* ---------------------------------------------------------------------- */
26149 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26151 +static void dump_opts(struct au_opts *opts)
26153 +#ifdef CONFIG_AUFS_DEBUG
26154 + /* reduce stack space */
26156 + struct au_opt_add *add;
26157 + struct au_opt_del *del;
26158 + struct au_opt_mod *mod;
26159 + struct au_opt_xino *xino;
26160 + struct au_opt_xino_itrunc *xino_itrunc;
26161 + struct au_opt_wbr_create *create;
26163 + struct au_opt *opt;
26166 + while (opt->type != Opt_tail) {
26167 + switch (opt->type) {
26169 + u.add = &opt->add;
26170 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26171 + u.add->bindex, u.add->pathname, u.add->perm,
26172 + u.add->path.dentry);
26176 + u.del = &opt->del;
26177 + AuDbg("del {%s, %p}\n",
26178 + u.del->pathname, u.del->h_path.dentry);
26182 + u.mod = &opt->mod;
26183 + AuDbg("mod {%s, 0x%x, %p}\n",
26184 + u.mod->path, u.mod->perm, u.mod->h_root);
26187 + u.add = &opt->add;
26188 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26189 + u.add->bindex, u.add->pathname, u.add->perm,
26190 + u.add->path.dentry);
26192 + case Opt_prepend:
26193 + u.add = &opt->add;
26194 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26195 + u.add->bindex, u.add->pathname, u.add->perm,
26196 + u.add->path.dentry);
26199 + AuDbg("dirwh %d\n", opt->dirwh);
26201 + case Opt_rdcache:
26202 + AuDbg("rdcache %d\n", opt->rdcache);
26205 + AuDbg("rdblk %u\n", opt->rdblk);
26207 + case Opt_rdblk_def:
26208 + AuDbg("rdblk_def\n");
26211 + AuDbg("rdhash %u\n", opt->rdhash);
26213 + case Opt_rdhash_def:
26214 + AuDbg("rdhash_def\n");
26217 + u.xino = &opt->xino;
26218 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26220 + case Opt_trunc_xino:
26221 + AuLabel(trunc_xino);
26223 + case Opt_notrunc_xino:
26224 + AuLabel(notrunc_xino);
26226 + case Opt_trunc_xino_path:
26227 + case Opt_itrunc_xino:
26228 + u.xino_itrunc = &opt->xino_itrunc;
26229 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26234 + case Opt_trunc_xib:
26235 + AuLabel(trunc_xib);
26237 + case Opt_notrunc_xib:
26238 + AuLabel(notrunc_xib);
26246 + case Opt_dirperm1:
26247 + AuLabel(dirperm1);
26249 + case Opt_nodirperm1:
26250 + AuLabel(nodirperm1);
26255 + case Opt_noplink:
26256 + AuLabel(noplink);
26258 + case Opt_list_plink:
26259 + AuLabel(list_plink);
26262 + AuDbg("udba %d, %s\n",
26263 + opt->udba, au_optstr_udba(opt->udba));
26271 + case Opt_diropq_a:
26272 + AuLabel(diropq_a);
26274 + case Opt_diropq_w:
26275 + AuLabel(diropq_w);
26277 + case Opt_warn_perm:
26278 + AuLabel(warn_perm);
26280 + case Opt_nowarn_perm:
26281 + AuLabel(nowarn_perm);
26283 + case Opt_verbose:
26284 + AuLabel(verbose);
26286 + case Opt_noverbose:
26287 + AuLabel(noverbose);
26298 + case Opt_wbr_create:
26299 + u.create = &opt->wbr_create;
26300 + AuDbg("create %d, %s\n", u.create->wbr_create,
26301 + au_optstr_wbr_create(u.create->wbr_create));
26302 + switch (u.create->wbr_create) {
26303 + case AuWbrCreate_MFSV:
26304 + case AuWbrCreate_PMFSV:
26305 + AuDbg("%d sec\n", u.create->mfs_second);
26307 + case AuWbrCreate_MFSRR:
26308 + case AuWbrCreate_TDMFS:
26309 + AuDbg("%llu watermark\n",
26310 + u.create->mfsrr_watermark);
26312 + case AuWbrCreate_MFSRRV:
26313 + case AuWbrCreate_TDMFSV:
26314 + case AuWbrCreate_PMFSRRV:
26315 + AuDbg("%llu watermark, %d sec\n",
26316 + u.create->mfsrr_watermark,
26317 + u.create->mfs_second);
26321 + case Opt_wbr_copyup:
26322 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26323 + au_optstr_wbr_copyup(opt->wbr_copyup));
26325 + case Opt_fhsm_sec:
26326 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26331 + case Opt_nodirren:
26332 + AuLabel(nodirren);
26348 +void au_opts_free(struct au_opts *opts)
26350 + struct au_opt *opt;
26353 + while (opt->type != Opt_tail) {
26354 + switch (opt->type) {
26357 + case Opt_prepend:
26358 + path_put(&opt->add.path);
26362 + path_put(&opt->del.h_path);
26366 + dput(opt->mod.h_root);
26369 + fput(opt->xino.file);
26376 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26377 + aufs_bindex_t bindex)
26380 + struct au_opt_add *add = &opt->add;
26383 + add->bindex = bindex;
26384 + add->perm = AuBrPerm_RO;
26385 + add->pathname = opt_str;
26386 + p = strchr(opt_str, '=');
26390 + add->perm = br_perm_val(p);
26393 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26396 + add->perm = AuBrPerm_RO;
26397 + if (au_test_fs_rr(add->path.dentry->d_sb))
26398 + add->perm = AuBrPerm_RR;
26399 + else if (!bindex && !(sb_flags & SB_RDONLY))
26400 + add->perm = AuBrPerm_RW;
26402 + opt->type = Opt_add;
26405 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26412 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26416 + del->pathname = args[0].from;
26417 + AuDbg("del path %s\n", del->pathname);
26419 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26420 + if (unlikely(err))
26421 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26426 +#if 0 /* reserved for future use */
26427 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26428 + struct au_opt_del *del, substring_t args[])
26431 + struct dentry *root;
26434 + root = sb->s_root;
26435 + aufs_read_lock(root, AuLock_FLUSH);
26436 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26437 + pr_err("out of bounds, %d\n", bindex);
26442 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26443 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26446 + aufs_read_unlock(root, !AuLock_IR);
26451 +static int noinline_for_stack
26452 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26455 + struct path path;
26459 + mod->path = args[0].from;
26460 + p = strchr(mod->path, '=');
26461 + if (unlikely(!p)) {
26462 + pr_err("no permission %s\n", args[0].from);
26467 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26468 + if (unlikely(err)) {
26469 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26473 + mod->perm = br_perm_val(p);
26474 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26475 + mod->h_root = dget(path.dentry);
26482 +#if 0 /* reserved for future use */
26483 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26484 + struct au_opt_mod *mod, substring_t args[])
26487 + struct dentry *root;
26490 + root = sb->s_root;
26491 + aufs_read_lock(root, AuLock_FLUSH);
26492 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26493 + pr_err("out of bounds, %d\n", bindex);
26498 + mod->perm = br_perm_val(args[1].from);
26499 + AuDbg("mod path %s, perm 0x%x, %s\n",
26500 + mod->path, mod->perm, args[1].from);
26501 + mod->h_root = dget(au_h_dptr(root, bindex));
26504 + aufs_read_unlock(root, !AuLock_IR);
26509 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26510 + substring_t args[])
26513 + struct file *file;
26515 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26516 + err = PTR_ERR(file);
26517 + if (IS_ERR(file))
26521 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26523 + pr_err("%s must be outside\n", args[0].from);
26528 + xino->file = file;
26529 + xino->path = args[0].from;
26535 +static int noinline_for_stack
26536 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26537 + struct au_opt_xino_itrunc *xino_itrunc,
26538 + substring_t args[])
26541 + aufs_bindex_t bbot, bindex;
26542 + struct path path;
26543 + struct dentry *root;
26545 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26546 + if (unlikely(err)) {
26547 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26551 + xino_itrunc->bindex = -1;
26552 + root = sb->s_root;
26553 + aufs_read_lock(root, AuLock_FLUSH);
26554 + bbot = au_sbbot(sb);
26555 + for (bindex = 0; bindex <= bbot; bindex++) {
26556 + if (au_h_dptr(root, bindex) == path.dentry) {
26557 + xino_itrunc->bindex = bindex;
26561 + aufs_read_unlock(root, !AuLock_IR);
26564 + if (unlikely(xino_itrunc->bindex < 0)) {
26565 + pr_err("no such branch %s\n", args[0].from);
26573 +/* called without aufs lock */
26574 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26576 + int err, n, token;
26577 + aufs_bindex_t bindex;
26578 + unsigned char skipped;
26579 + struct dentry *root;
26580 + struct au_opt *opt, *opt_tail;
26582 + /* reduce the stack space */
26584 + struct au_opt_xino_itrunc *xino_itrunc;
26585 + struct au_opt_wbr_create *create;
26588 + substring_t args[MAX_OPT_ARGS];
26592 + a = kmalloc(sizeof(*a), GFP_NOFS);
26593 + if (unlikely(!a))
26596 + root = sb->s_root;
26600 + opt_tail = opt + opts->max_opt - 1;
26601 + opt->type = Opt_tail;
26602 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26605 + token = match_token(opt_str, options, a->args);
26609 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26611 + err = opt_add(opt, opt_str, opts->sb_flags,
26613 + if (unlikely(!err && ++opt > opt_tail)) {
26617 + opt->type = Opt_tail;
26622 + if (unlikely(match_int(&a->args[0], &n))) {
26623 + pr_err("bad integer in %s\n", opt_str);
26627 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26630 + opt->type = token;
26633 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26634 + /*dummy bindex*/1);
26636 + opt->type = token;
26638 + case Opt_prepend:
26639 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26642 + opt->type = token;
26645 + err = au_opts_parse_del(&opt->del, a->args);
26647 + opt->type = token;
26649 +#if 0 /* reserved for future use */
26651 + del->pathname = "(indexed)";
26652 + if (unlikely(match_int(&args[0], &n))) {
26653 + pr_err("bad integer in %s\n", opt_str);
26656 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26658 + opt->type = token;
26662 + err = au_opts_parse_mod(&opt->mod, a->args);
26664 + opt->type = token;
26666 +#ifdef IMOD /* reserved for future use */
26668 + u.mod->path = "(indexed)";
26669 + if (unlikely(match_int(&a->args[0], &n))) {
26670 + pr_err("bad integer in %s\n", opt_str);
26673 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26675 + opt->type = token;
26679 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26681 + opt->type = token;
26684 + case Opt_trunc_xino_path:
26685 + err = au_opts_parse_xino_itrunc_path
26686 + (sb, &opt->xino_itrunc, a->args);
26688 + opt->type = token;
26691 + case Opt_itrunc_xino:
26692 + u.xino_itrunc = &opt->xino_itrunc;
26693 + if (unlikely(match_int(&a->args[0], &n))) {
26694 + pr_err("bad integer in %s\n", opt_str);
26697 + u.xino_itrunc->bindex = n;
26698 + aufs_read_lock(root, AuLock_FLUSH);
26699 + if (n < 0 || au_sbbot(sb) < n) {
26700 + pr_err("out of bounds, %d\n", n);
26701 + aufs_read_unlock(root, !AuLock_IR);
26704 + aufs_read_unlock(root, !AuLock_IR);
26706 + opt->type = token;
26710 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26713 + opt->type = token;
26716 + case Opt_rdcache:
26717 + if (unlikely(match_int(&a->args[0], &n))) {
26718 + pr_err("bad integer in %s\n", opt_str);
26721 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26722 + pr_err("rdcache must be smaller than %d\n",
26723 + AUFS_RDCACHE_MAX);
26726 + opt->rdcache = n;
26728 + opt->type = token;
26731 + if (unlikely(match_int(&a->args[0], &n)
26733 + || n > KMALLOC_MAX_SIZE)) {
26734 + pr_err("bad integer in %s\n", opt_str);
26737 + if (unlikely(n && n < NAME_MAX)) {
26738 + pr_err("rdblk must be larger than %d\n",
26744 + opt->type = token;
26747 + if (unlikely(match_int(&a->args[0], &n)
26749 + || n * sizeof(struct hlist_head)
26750 + > KMALLOC_MAX_SIZE)) {
26751 + pr_err("bad integer in %s\n", opt_str);
26756 + opt->type = token;
26759 + case Opt_trunc_xino:
26760 + case Opt_notrunc_xino:
26762 + case Opt_trunc_xib:
26763 + case Opt_notrunc_xib:
26766 + case Opt_dirperm1:
26767 + case Opt_nodirperm1:
26769 + case Opt_noplink:
26770 + case Opt_list_plink:
26773 + case Opt_diropq_a:
26774 + case Opt_diropq_w:
26775 + case Opt_warn_perm:
26776 + case Opt_nowarn_perm:
26777 + case Opt_verbose:
26778 + case Opt_noverbose:
26782 + case Opt_rdblk_def:
26783 + case Opt_rdhash_def:
26785 + case Opt_nodirren:
26789 + opt->type = token;
26793 + opt->udba = udba_val(a->args[0].from);
26794 + if (opt->udba >= 0) {
26796 + opt->type = token;
26798 + pr_err("wrong value, %s\n", opt_str);
26801 + case Opt_wbr_create:
26802 + u.create = &opt->wbr_create;
26803 + u.create->wbr_create
26804 + = au_wbr_create_val(a->args[0].from, u.create);
26805 + if (u.create->wbr_create >= 0) {
26807 + opt->type = token;
26809 + pr_err("wrong value, %s\n", opt_str);
26811 + case Opt_wbr_copyup:
26812 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26813 + if (opt->wbr_copyup >= 0) {
26815 + opt->type = token;
26817 + pr_err("wrong value, %s\n", opt_str);
26820 + case Opt_fhsm_sec:
26821 + if (unlikely(match_int(&a->args[0], &n)
26823 + pr_err("bad integer in %s\n", opt_str);
26826 + if (sysaufs_brs) {
26827 + opt->fhsm_second = n;
26828 + opt->type = token;
26830 + pr_warn("ignored %s\n", opt_str);
26835 + pr_warn("ignored %s\n", opt_str);
26837 + case Opt_ignore_silent:
26842 + pr_err("unknown option %s\n", opt_str);
26846 + if (!err && !skipped) {
26847 + if (unlikely(++opt > opt_tail)) {
26850 + opt->type = Opt_tail;
26853 + opt->type = Opt_tail;
26859 + if (unlikely(err))
26860 + au_opts_free(opts);
26866 +static int au_opt_wbr_create(struct super_block *sb,
26867 + struct au_opt_wbr_create *create)
26870 + struct au_sbinfo *sbinfo;
26872 + SiMustWriteLock(sb);
26874 + err = 1; /* handled */
26875 + sbinfo = au_sbi(sb);
26876 + if (sbinfo->si_wbr_create_ops->fin) {
26877 + err = sbinfo->si_wbr_create_ops->fin(sb);
26882 + sbinfo->si_wbr_create = create->wbr_create;
26883 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26884 + switch (create->wbr_create) {
26885 + case AuWbrCreate_MFSRRV:
26886 + case AuWbrCreate_MFSRR:
26887 + case AuWbrCreate_TDMFS:
26888 + case AuWbrCreate_TDMFSV:
26889 + case AuWbrCreate_PMFSRR:
26890 + case AuWbrCreate_PMFSRRV:
26891 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26893 + case AuWbrCreate_MFS:
26894 + case AuWbrCreate_MFSV:
26895 + case AuWbrCreate_PMFS:
26896 + case AuWbrCreate_PMFSV:
26897 + sbinfo->si_wbr_mfs.mfs_expire
26898 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26902 + if (sbinfo->si_wbr_create_ops->init)
26903 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26910 + * plus: processed without an error
26911 + * zero: unprocessed
26913 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26914 + struct au_opts *opts)
26917 + struct au_sbinfo *sbinfo;
26919 + SiMustWriteLock(sb);
26921 + err = 1; /* handled */
26922 + sbinfo = au_sbi(sb);
26923 + switch (opt->type) {
26925 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26926 + sbinfo->si_mntflags |= opt->udba;
26927 + opts->given_udba |= opt->udba;
26931 + au_opt_set(sbinfo->si_mntflags, PLINK);
26933 + case Opt_noplink:
26934 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26935 + au_plink_put(sb, /*verbose*/1);
26936 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26938 + case Opt_list_plink:
26939 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26940 + au_plink_list(sb);
26944 + au_opt_set(sbinfo->si_mntflags, DIO);
26945 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26948 + au_opt_clr(sbinfo->si_mntflags, DIO);
26949 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26952 + case Opt_fhsm_sec:
26953 + au_fhsm_set(sbinfo, opt->fhsm_second);
26956 + case Opt_diropq_a:
26957 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26959 + case Opt_diropq_w:
26960 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26963 + case Opt_warn_perm:
26964 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26966 + case Opt_nowarn_perm:
26967 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26970 + case Opt_verbose:
26971 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26973 + case Opt_noverbose:
26974 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26978 + au_opt_set(sbinfo->si_mntflags, SUM);
26981 + au_opt_clr(sbinfo->si_mntflags, SUM);
26982 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26985 + au_opt_clr(sbinfo->si_mntflags, SUM);
26986 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26989 + case Opt_wbr_create:
26990 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26992 + case Opt_wbr_copyup:
26993 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26994 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26998 + sbinfo->si_dirwh = opt->dirwh;
27001 + case Opt_rdcache:
27002 + sbinfo->si_rdcache
27003 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27006 + sbinfo->si_rdblk = opt->rdblk;
27008 + case Opt_rdblk_def:
27009 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
27012 + sbinfo->si_rdhash = opt->rdhash;
27014 + case Opt_rdhash_def:
27015 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
27019 + au_opt_set(sbinfo->si_mntflags, SHWH);
27022 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27025 + case Opt_dirperm1:
27026 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27028 + case Opt_nodirperm1:
27029 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27032 + case Opt_trunc_xino:
27033 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27035 + case Opt_notrunc_xino:
27036 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27039 + case Opt_trunc_xino_path:
27040 + case Opt_itrunc_xino:
27041 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27047 + case Opt_trunc_xib:
27048 + au_fset_opts(opts->flags, TRUNC_XIB);
27050 + case Opt_notrunc_xib:
27051 + au_fclr_opts(opts->flags, TRUNC_XIB);
27056 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27057 + err = au_dr_opt_set(sb);
27062 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27064 + case Opt_nodirren:
27066 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27067 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27073 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27077 + sb->s_flags |= SB_POSIXACL;
27080 + sb->s_flags &= ~SB_POSIXACL;
27092 + * returns tri-state.
27093 + * plus: processed without an error
27094 + * zero: unprocessed
27097 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27098 + struct au_opts *opts)
27100 + int err, do_refresh;
27103 + switch (opt->type) {
27105 + opt->add.bindex = au_sbbot(sb) + 1;
27106 + if (opt->add.bindex < 0)
27107 + opt->add.bindex = 0;
27109 + /* Always goto add, not fallthrough */
27110 + case Opt_prepend:
27111 + opt->add.bindex = 0;
27113 + add: /* indented label */
27115 + err = au_br_add(sb, &opt->add,
27116 + au_ftest_opts(opts->flags, REMOUNT));
27119 + au_fset_opts(opts->flags, REFRESH);
27125 + err = au_br_del(sb, &opt->del,
27126 + au_ftest_opts(opts->flags, REMOUNT));
27129 + au_fset_opts(opts->flags, TRUNC_XIB);
27130 + au_fset_opts(opts->flags, REFRESH);
27136 + err = au_br_mod(sb, &opt->mod,
27137 + au_ftest_opts(opts->flags, REMOUNT),
27142 + au_fset_opts(opts->flags, REFRESH);
27149 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27150 + struct au_opt_xino **opt_xino,
27151 + struct au_opts *opts)
27156 + switch (opt->type) {
27158 + err = au_xino_set(sb, &opt->xino,
27159 + !!au_ftest_opts(opts->flags, REMOUNT));
27160 + if (unlikely(err))
27163 + *opt_xino = &opt->xino;
27168 + *opt_xino = (void *)-1;
27175 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27176 + unsigned int pending)
27179 + aufs_bindex_t bindex, bbot;
27180 + unsigned char do_plink, skip, do_free, can_no_dreval;
27181 + struct au_branch *br;
27182 + struct au_wbr *wbr;
27183 + struct dentry *root, *dentry;
27184 + struct inode *dir, *h_dir;
27185 + struct au_sbinfo *sbinfo;
27186 + struct au_hinode *hdir;
27188 + SiMustAnyLock(sb);
27190 + sbinfo = au_sbi(sb);
27191 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27193 + if (!(sb_flags & SB_RDONLY)) {
27194 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27195 + pr_warn("first branch should be rw\n");
27196 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27197 + pr_warn_once("shwh should be used with ro\n");
27200 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27201 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27202 + pr_warn_once("udba=*notify requires xino\n");
27204 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27205 + pr_warn_once("dirperm1 breaks the protection"
27206 + " by the permission bits on the lower branch\n");
27210 + root = sb->s_root;
27211 + dir = d_inode(root);
27212 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27213 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27215 + bbot = au_sbbot(sb);
27216 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27218 + h_dir = au_h_iptr(dir, bindex);
27219 + br = au_sbr(sb, bindex);
27221 + if ((br->br_perm & AuBrAttr_ICEX)
27222 + && !h_dir->i_op->listxattr)
27223 + br->br_perm &= ~AuBrAttr_ICEX;
27224 +#if 0 /* untested */
27225 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27226 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27227 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27231 + wbr = br->br_wbr;
27233 + wbr_wh_read_lock(wbr);
27235 + if (!au_br_writable(br->br_perm)) {
27238 + || (!wbr->wbr_whbase
27239 + && !wbr->wbr_plink
27240 + && !wbr->wbr_orph));
27241 + } else if (!au_br_wh_linkable(br->br_perm)) {
27242 + /* skip = (!br->br_whbase && !br->br_orph); */
27243 + skip = (!wbr || !wbr->wbr_whbase);
27244 + if (skip && wbr) {
27246 + skip = !!wbr->wbr_plink;
27248 + skip = !wbr->wbr_plink;
27251 + /* skip = (br->br_whbase && br->br_ohph); */
27252 + skip = (wbr && wbr->wbr_whbase);
27255 + skip = !!wbr->wbr_plink;
27257 + skip = !wbr->wbr_plink;
27261 + wbr_wh_read_unlock(wbr);
27263 + if (can_no_dreval) {
27264 + dentry = br->br_path.dentry;
27265 + spin_lock(&dentry->d_lock);
27266 + if (dentry->d_flags &
27267 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27268 + can_no_dreval = 0;
27269 + spin_unlock(&dentry->d_lock);
27272 + if (au_br_fhsm(br->br_perm)) {
27274 + AuDebugOn(!br->br_fhsm);
27280 + hdir = au_hi(dir, bindex);
27281 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27283 + wbr_wh_write_lock(wbr);
27284 + err = au_wh_init(br, sb);
27286 + wbr_wh_write_unlock(wbr);
27287 + au_hn_inode_unlock(hdir);
27289 + if (!err && do_free) {
27290 + au_kfree_rcu(wbr);
27291 + br->br_wbr = NULL;
27295 + if (can_no_dreval)
27296 + au_fset_si(sbinfo, NO_DREVAL);
27298 + au_fclr_si(sbinfo, NO_DREVAL);
27301 + au_fset_si(sbinfo, FHSM);
27302 + for (bindex = bbot; bindex >= 0; bindex--) {
27303 + br = au_sbr(sb, bindex);
27304 + if (au_br_fhsm(br->br_perm)) {
27305 + au_fhsm_set_bottom(sb, bindex);
27310 + au_fclr_si(sbinfo, FHSM);
27311 + au_fhsm_set_bottom(sb, -1);
27317 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27320 + unsigned int tmp;
27321 + aufs_bindex_t bindex, bbot;
27322 + struct au_opt *opt;
27323 + struct au_opt_xino *opt_xino, xino;
27324 + struct au_sbinfo *sbinfo;
27325 + struct au_branch *br;
27326 + struct inode *dir;
27328 + SiMustWriteLock(sb);
27333 + while (err >= 0 && opt->type != Opt_tail)
27334 + err = au_opt_simple(sb, opt++, opts);
27337 + else if (unlikely(err < 0))
27340 + /* disable xino and udba temporary */
27341 + sbinfo = au_sbi(sb);
27342 + tmp = sbinfo->si_mntflags;
27343 + au_opt_clr(sbinfo->si_mntflags, XINO);
27344 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27347 + while (err >= 0 && opt->type != Opt_tail)
27348 + err = au_opt_br(sb, opt++, opts);
27351 + else if (unlikely(err < 0))
27354 + bbot = au_sbbot(sb);
27355 + if (unlikely(bbot < 0)) {
27357 + pr_err("no branches\n");
27361 + if (au_opt_test(tmp, XINO))
27362 + au_opt_set(sbinfo->si_mntflags, XINO);
27364 + while (!err && opt->type != Opt_tail)
27365 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27366 + if (unlikely(err))
27369 + err = au_opts_verify(sb, sb->s_flags, tmp);
27370 + if (unlikely(err))
27373 + /* restore xino */
27374 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27375 + xino.file = au_xino_def(sb);
27376 + err = PTR_ERR(xino.file);
27377 + if (IS_ERR(xino.file))
27380 + err = au_xino_set(sb, &xino, /*remount*/0);
27382 + if (unlikely(err))
27386 + /* restore udba */
27387 + tmp &= AuOptMask_UDBA;
27388 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27389 + sbinfo->si_mntflags |= tmp;
27390 + bbot = au_sbbot(sb);
27391 + for (bindex = 0; bindex <= bbot; bindex++) {
27392 + br = au_sbr(sb, bindex);
27393 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27394 + if (unlikely(err))
27395 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27397 + /* go on even if err */
27399 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27400 + dir = d_inode(sb->s_root);
27401 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27408 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27411 + unsigned char no_dreval;
27412 + struct inode *dir;
27413 + struct au_opt_xino *opt_xino;
27414 + struct au_opt *opt;
27415 + struct au_sbinfo *sbinfo;
27417 + SiMustWriteLock(sb);
27419 + err = au_dr_opt_flush(sb);
27420 + if (unlikely(err))
27422 + au_fset_opts(opts->flags, DR_FLUSHED);
27424 + dir = d_inode(sb->s_root);
27425 + sbinfo = au_sbi(sb);
27428 + while (err >= 0 && opt->type != Opt_tail) {
27429 + err = au_opt_simple(sb, opt, opts);
27431 + err = au_opt_br(sb, opt, opts);
27433 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27439 + /* go on even err */
27441 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27442 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27443 + if (unlikely(rerr && !err))
27446 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27447 + au_fset_opts(opts->flags, REFRESH_IDOP);
27449 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27450 + rerr = au_xib_trunc(sb);
27451 + if (unlikely(rerr && !err))
27455 + /* will be handled by the caller */
27456 + if (!au_ftest_opts(opts->flags, REFRESH)
27457 + && (opts->given_udba
27458 + || au_opt_test(sbinfo->si_mntflags, XINO)
27459 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27461 + au_fset_opts(opts->flags, REFRESH);
27463 + AuDbg("status 0x%x\n", opts->flags);
27469 +/* ---------------------------------------------------------------------- */
27471 +unsigned int au_opt_udba(struct super_block *sb)
27473 + return au_mntflags(sb) & AuOptMask_UDBA;
27475 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27476 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27477 +++ linux/fs/aufs/opts.h 2021-11-01 23:48:34.209692595 +0100
27479 +/* SPDX-License-Identifier: GPL-2.0 */
27481 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27483 + * This program, aufs is free software; you can redistribute it and/or modify
27484 + * it under the terms of the GNU General Public License as published by
27485 + * the Free Software Foundation; either version 2 of the License, or
27486 + * (at your option) any later version.
27488 + * This program is distributed in the hope that it will be useful,
27489 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27490 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27491 + * GNU General Public License for more details.
27493 + * You should have received a copy of the GNU General Public License
27494 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27498 + * mount options/flags
27501 +#ifndef __AUFS_OPTS_H__
27502 +#define __AUFS_OPTS_H__
27506 +#include <linux/path.h>
27510 +/* ---------------------------------------------------------------------- */
27513 +#define AuOpt_XINO 1 /* external inode number bitmap
27514 + and translation table */
27515 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27516 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27517 +#define AuOpt_UDBA_REVAL (1 << 3)
27518 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27519 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27520 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27521 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27523 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27524 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27525 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27526 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27527 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27528 +#define AuOpt_DIO (1 << 14) /* direct io */
27529 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27531 +#ifndef CONFIG_AUFS_HNOTIFY
27532 +#undef AuOpt_UDBA_HNOTIFY
27533 +#define AuOpt_UDBA_HNOTIFY 0
27535 +#ifndef CONFIG_AUFS_DIRREN
27536 +#undef AuOpt_DIRREN
27537 +#define AuOpt_DIRREN 0
27539 +#ifndef CONFIG_AUFS_SHWH
27541 +#define AuOpt_SHWH 0
27544 +#define AuOpt_Def (AuOpt_XINO \
27545 + | AuOpt_UDBA_REVAL \
27547 + /* | AuOpt_DIRPERM1 */ \
27548 + | AuOpt_WARN_PERM)
27549 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27550 + | AuOpt_UDBA_REVAL \
27551 + | AuOpt_UDBA_HNOTIFY)
27553 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27554 +#define au_opt_set(flags, name) do { \
27555 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27556 + ((flags) |= AuOpt_##name); \
27558 +#define au_opt_set_udba(flags, name) do { \
27559 + (flags) &= ~AuOptMask_UDBA; \
27560 + ((flags) |= AuOpt_##name); \
27562 +#define au_opt_clr(flags, name) do { \
27563 + ((flags) &= ~AuOpt_##name); \
27566 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27568 +#ifdef CONFIG_PROC_FS
27571 + return mntflags & ~AuOpt_PLINK;
27575 +/* ---------------------------------------------------------------------- */
27577 +/* policies to select one among multiple writable branches */
27579 + AuWbrCreate_TDP, /* top down parent */
27580 + AuWbrCreate_RR, /* round robin */
27581 + AuWbrCreate_MFS, /* most free space */
27582 + AuWbrCreate_MFSV, /* mfs with seconds */
27583 + AuWbrCreate_MFSRR, /* mfs then rr */
27584 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27585 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27586 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27587 + AuWbrCreate_PMFS, /* parent and mfs */
27588 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27589 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27590 + AuWbrCreate_PMFSRRV, /* plus seconds */
27592 + AuWbrCreate_Def = AuWbrCreate_TDP
27596 + AuWbrCopyup_TDP, /* top down parent */
27597 + AuWbrCopyup_BUP, /* bottom up parent */
27598 + AuWbrCopyup_BU, /* bottom up */
27600 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27603 +/* ---------------------------------------------------------------------- */
27605 +struct au_opt_add {
27606 + aufs_bindex_t bindex;
27609 + struct path path;
27612 +struct au_opt_del {
27614 + struct path h_path;
27617 +struct au_opt_mod {
27620 + struct dentry *h_root;
27623 +struct au_opt_xino {
27625 + struct file *file;
27628 +struct au_opt_xino_itrunc {
27629 + aufs_bindex_t bindex;
27632 +struct au_opt_wbr_create {
27635 + unsigned long long mfsrr_watermark;
27641 + struct au_opt_xino xino;
27642 + struct au_opt_xino_itrunc xino_itrunc;
27643 + struct au_opt_add add;
27644 + struct au_opt_del del;
27645 + struct au_opt_mod mod;
27648 + unsigned int rdblk;
27649 + unsigned int rdhash;
27651 + struct au_opt_wbr_create wbr_create;
27653 + unsigned int fhsm_second;
27658 +#define AuOpts_REMOUNT 1
27659 +#define AuOpts_REFRESH (1 << 1)
27660 +#define AuOpts_TRUNC_XIB (1 << 2)
27661 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27662 +#define AuOpts_REFRESH_IDOP (1 << 4)
27663 +#define AuOpts_DR_FLUSHED (1 << 5)
27664 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27665 +#define au_fset_opts(flags, name) \
27666 + do { (flags) |= AuOpts_##name; } while (0)
27667 +#define au_fclr_opts(flags, name) \
27668 + do { (flags) &= ~AuOpts_##name; } while (0)
27670 +#ifndef CONFIG_AUFS_DIRREN
27671 +#undef AuOpts_DR_FLUSHED
27672 +#define AuOpts_DR_FLUSHED 0
27676 + struct au_opt *opt;
27679 + unsigned int given_udba;
27680 + unsigned int flags;
27681 + unsigned long sb_flags;
27684 +/* ---------------------------------------------------------------------- */
27687 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27688 +const char *au_optstr_udba(int udba);
27689 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27690 +const char *au_optstr_wbr_create(int wbr_create);
27692 +void au_opts_free(struct au_opts *opts);
27693 +struct super_block;
27694 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27695 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27696 + unsigned int pending);
27697 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27698 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27700 +unsigned int au_opt_udba(struct super_block *sb);
27702 +#endif /* __KERNEL__ */
27703 +#endif /* __AUFS_OPTS_H__ */
27704 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27705 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27706 +++ linux/fs/aufs/plink.c 2021-11-01 23:48:34.209692595 +0100
27708 +// SPDX-License-Identifier: GPL-2.0
27710 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27712 + * This program, aufs is free software; you can redistribute it and/or modify
27713 + * it under the terms of the GNU General Public License as published by
27714 + * the Free Software Foundation; either version 2 of the License, or
27715 + * (at your option) any later version.
27717 + * This program is distributed in the hope that it will be useful,
27718 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27719 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27720 + * GNU General Public License for more details.
27722 + * You should have received a copy of the GNU General Public License
27723 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27733 + * the pseudo-link maintenance mode.
27734 + * during a user process maintains the pseudo-links,
27735 + * prohibit adding a new plink and branch manipulation.
27739 + * For entry functions which will handle plink, and i_mutex is already held
27741 + * They cannot wait and should return an error at once.
27742 + * Callers has to check the error.
27744 + * For entry functions which will handle plink, but i_mutex is not held
27746 + * They can wait the plink maintenance mode to finish.
27748 + * They behave like F_SETLK and F_SETLKW.
27749 + * If the caller never handle plink, then both flags are unnecessary.
27752 +int au_plink_maint(struct super_block *sb, int flags)
27756 + struct task_struct *parent, *prev;
27757 + struct au_sbinfo *sbi;
27759 + SiMustAnyLock(sb);
27762 + if (!au_opt_test(au_mntflags(sb), PLINK))
27765 + sbi = au_sbi(sb);
27766 + pid = sbi->si_plink_maint_pid;
27767 + if (!pid || pid == current->pid)
27770 + /* todo: it highly depends upon /sbin/mount.aufs */
27772 + parent = current;
27776 + parent = rcu_dereference(parent->real_parent);
27777 + if (parent == prev)
27779 + ppid = task_pid_vnr(parent);
27780 + if (pid == ppid) {
27781 + rcu_read_unlock();
27786 + rcu_read_unlock();
27788 + if (au_ftest_lock(flags, NOPLMW)) {
27789 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27790 + /* AuDebugOn(!lockdep_depth(current)); */
27791 + while (sbi->si_plink_maint_pid) {
27792 + si_read_unlock(sb);
27793 + /* gave up wake_up_bit() */
27794 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27796 + if (au_ftest_lock(flags, FLUSH))
27797 + au_nwt_flush(&sbi->si_nowait);
27798 + si_noflush_read_lock(sb);
27800 + } else if (au_ftest_lock(flags, NOPLM)) {
27801 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27809 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27811 + spin_lock(&sbinfo->si_plink_maint_lock);
27812 + sbinfo->si_plink_maint_pid = 0;
27813 + spin_unlock(&sbinfo->si_plink_maint_lock);
27814 + wake_up_all(&sbinfo->si_plink_wq);
27817 +int au_plink_maint_enter(struct super_block *sb)
27820 + struct au_sbinfo *sbinfo;
27823 + sbinfo = au_sbi(sb);
27824 + /* make sure i am the only one in this fs */
27825 + si_write_lock(sb, AuLock_FLUSH);
27826 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27827 + spin_lock(&sbinfo->si_plink_maint_lock);
27828 + if (!sbinfo->si_plink_maint_pid)
27829 + sbinfo->si_plink_maint_pid = current->pid;
27832 + spin_unlock(&sbinfo->si_plink_maint_lock);
27834 + si_write_unlock(sb);
27839 +/* ---------------------------------------------------------------------- */
27841 +#ifdef CONFIG_AUFS_DEBUG
27842 +void au_plink_list(struct super_block *sb)
27845 + struct au_sbinfo *sbinfo;
27846 + struct hlist_bl_head *hbl;
27847 + struct hlist_bl_node *pos;
27848 + struct au_icntnr *icntnr;
27850 + SiMustAnyLock(sb);
27852 + sbinfo = au_sbi(sb);
27853 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27854 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27856 + for (i = 0; i < AuPlink_NHASH; i++) {
27857 + hbl = sbinfo->si_plink + i;
27858 + hlist_bl_lock(hbl);
27859 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27860 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27861 + hlist_bl_unlock(hbl);
27866 +/* is the inode pseudo-linked? */
27867 +int au_plink_test(struct inode *inode)
27870 + struct au_sbinfo *sbinfo;
27871 + struct hlist_bl_head *hbl;
27872 + struct hlist_bl_node *pos;
27873 + struct au_icntnr *icntnr;
27875 + sbinfo = au_sbi(inode->i_sb);
27876 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27877 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27878 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27881 + i = au_plink_hash(inode->i_ino);
27882 + hbl = sbinfo->si_plink + i;
27883 + hlist_bl_lock(hbl);
27884 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27885 + if (&icntnr->vfs_inode == inode) {
27889 + hlist_bl_unlock(hbl);
27893 +/* ---------------------------------------------------------------------- */
27896 + * generate a name for plink.
27897 + * the file will be stored under AUFS_WH_PLINKDIR.
27899 +/* 20 is max digits length of ulong 64 */
27900 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27902 +static int plink_name(char *name, int len, struct inode *inode,
27903 + aufs_bindex_t bindex)
27906 + struct inode *h_inode;
27908 + h_inode = au_h_iptr(inode, bindex);
27909 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27913 +struct au_do_plink_lkup_args {
27914 + struct dentry **errp;
27915 + struct qstr *tgtname;
27916 + struct path *h_ppath;
27919 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27920 + struct path *h_ppath)
27922 + struct dentry *h_dentry;
27923 + struct inode *h_inode;
27925 + h_inode = d_inode(h_ppath->dentry);
27926 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27927 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
27928 + inode_unlock_shared(h_inode);
27933 +static void au_call_do_plink_lkup(void *args)
27935 + struct au_do_plink_lkup_args *a = args;
27936 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
27939 +/* lookup the plink-ed @inode under the branch at @bindex */
27940 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27942 + struct dentry *h_dentry;
27943 + struct au_branch *br;
27944 + struct path h_ppath;
27946 + char a[PLINK_NAME_LEN];
27947 + struct qstr tgtname = QSTR_INIT(a, 0);
27949 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27951 + br = au_sbr(inode->i_sb, bindex);
27952 + h_ppath.dentry = br->br_wbr->wbr_plink;
27953 + h_ppath.mnt = au_br_mnt(br);
27954 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27956 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27957 + struct au_do_plink_lkup_args args = {
27958 + .errp = &h_dentry,
27959 + .tgtname = &tgtname,
27960 + .h_ppath = &h_ppath
27963 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27964 + if (unlikely(wkq_err))
27965 + h_dentry = ERR_PTR(wkq_err);
27967 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
27972 +/* create a pseudo-link */
27973 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
27974 + struct dentry *h_dentry)
27977 + struct path h_path;
27978 + struct inode *h_dir, *delegated;
27980 + h_dir = d_inode(h_ppath->dentry);
27981 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27982 + h_path.mnt = h_ppath->mnt;
27984 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
27985 + err = PTR_ERR(h_path.dentry);
27986 + if (IS_ERR(h_path.dentry))
27990 + /* wh.plink dir is not monitored */
27991 + /* todo: is it really safe? */
27992 + if (d_is_positive(h_path.dentry)
27993 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27994 + delegated = NULL;
27995 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27996 + if (unlikely(err == -EWOULDBLOCK)) {
27997 + pr_warn("cannot retry for NFSv4 delegation"
27998 + " for an internal unlink\n");
28001 + dput(h_path.dentry);
28002 + h_path.dentry = NULL;
28006 + if (!err && d_is_negative(h_path.dentry)) {
28007 + delegated = NULL;
28008 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28009 + if (unlikely(err == -EWOULDBLOCK)) {
28010 + pr_warn("cannot retry for NFSv4 delegation"
28011 + " for an internal link\n");
28015 + dput(h_path.dentry);
28018 + inode_unlock(h_dir);
28022 +struct do_whplink_args {
28024 + struct qstr *tgt;
28025 + struct path *h_ppath;
28026 + struct dentry *h_dentry;
28029 +static void call_do_whplink(void *args)
28031 + struct do_whplink_args *a = args;
28032 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28035 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28036 + aufs_bindex_t bindex)
28038 + int err, wkq_err;
28039 + struct au_branch *br;
28040 + struct au_wbr *wbr;
28041 + struct path h_ppath;
28042 + char a[PLINK_NAME_LEN];
28043 + struct qstr tgtname = QSTR_INIT(a, 0);
28045 + br = au_sbr(inode->i_sb, bindex);
28046 + wbr = br->br_wbr;
28047 + h_ppath.dentry = wbr->wbr_plink;
28048 + h_ppath.mnt = au_br_mnt(br);
28049 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28051 + /* always superio. */
28052 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28053 + struct do_whplink_args args = {
28056 + .h_ppath = &h_ppath,
28057 + .h_dentry = h_dentry
28059 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28060 + if (unlikely(wkq_err))
28063 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28069 + * create a new pseudo-link for @h_dentry on @bindex.
28070 + * the linked inode is held in aufs @inode.
28072 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28073 + struct dentry *h_dentry)
28075 + struct super_block *sb;
28076 + struct au_sbinfo *sbinfo;
28077 + struct hlist_bl_head *hbl;
28078 + struct hlist_bl_node *pos;
28079 + struct au_icntnr *icntnr;
28080 + int found, err, cnt, i;
28082 + sb = inode->i_sb;
28083 + sbinfo = au_sbi(sb);
28084 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28085 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28087 + found = au_plink_test(inode);
28091 + i = au_plink_hash(inode->i_ino);
28092 + hbl = sbinfo->si_plink + i;
28095 + hlist_bl_lock(hbl);
28096 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28097 + if (&icntnr->vfs_inode == inode) {
28103 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28104 + hlist_bl_add_head(&icntnr->plink, hbl);
28106 + hlist_bl_unlock(hbl);
28108 + cnt = au_hbl_count(hbl);
28109 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28110 + if (cnt > AUFS_PLINK_WARN)
28111 + AuWarn1(msg ", %d\n", cnt);
28113 + err = whplink(h_dentry, inode, bindex);
28114 + if (unlikely(err)) {
28115 + pr_warn("err %d, damaged pseudo link.\n", err);
28116 + au_hbl_del(&icntnr->plink, hbl);
28117 + iput(&icntnr->vfs_inode);
28120 + iput(&icntnr->vfs_inode);
28123 +/* free all plinks */
28124 +void au_plink_put(struct super_block *sb, int verbose)
28127 + struct au_sbinfo *sbinfo;
28128 + struct hlist_bl_head *hbl;
28129 + struct hlist_bl_node *pos, *tmp;
28130 + struct au_icntnr *icntnr;
28132 + SiMustWriteLock(sb);
28134 + sbinfo = au_sbi(sb);
28135 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28136 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28138 + /* no spin_lock since sbinfo is write-locked */
28140 + for (i = 0; i < AuPlink_NHASH; i++) {
28141 + hbl = sbinfo->si_plink + i;
28142 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28143 + pr_warn("pseudo-link is not flushed");
28146 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28147 + iput(&icntnr->vfs_inode);
28148 + INIT_HLIST_BL_HEAD(hbl);
28152 +void au_plink_clean(struct super_block *sb, int verbose)
28154 + struct dentry *root;
28156 + root = sb->s_root;
28157 + aufs_write_lock(root);
28158 + if (au_opt_test(au_mntflags(sb), PLINK))
28159 + au_plink_put(sb, verbose);
28160 + aufs_write_unlock(root);
28163 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28166 + aufs_bindex_t btop, bbot, bindex;
28169 + btop = au_ibtop(inode);
28170 + bbot = au_ibbot(inode);
28172 + for (bindex = btop; bindex <= bbot; bindex++) {
28173 + if (!au_h_iptr(inode, bindex)
28174 + || au_ii_br_id(inode, bindex) != br_id)
28176 + au_set_h_iptr(inode, bindex, NULL, 0);
28181 + for (bindex = btop; bindex <= bbot; bindex++)
28182 + if (au_h_iptr(inode, bindex)) {
28192 +/* free the plinks on a branch specified by @br_id */
28193 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28195 + struct au_sbinfo *sbinfo;
28196 + struct hlist_bl_head *hbl;
28197 + struct hlist_bl_node *pos, *tmp;
28198 + struct au_icntnr *icntnr;
28199 + struct inode *inode;
28202 + SiMustWriteLock(sb);
28204 + sbinfo = au_sbi(sb);
28205 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28206 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28208 + /* no bit_lock since sbinfo is write-locked */
28209 + for (i = 0; i < AuPlink_NHASH; i++) {
28210 + hbl = sbinfo->si_plink + i;
28211 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28212 + inode = au_igrab(&icntnr->vfs_inode);
28213 + ii_write_lock_child(inode);
28214 + do_put = au_plink_do_half_refresh(inode, br_id);
28216 + hlist_bl_del(&icntnr->plink);
28219 + ii_write_unlock(inode);
28224 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28225 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28226 +++ linux/fs/aufs/poll.c 2021-11-01 23:48:34.209692595 +0100
28228 +// SPDX-License-Identifier: GPL-2.0
28230 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28232 + * This program, aufs is free software; you can redistribute it and/or modify
28233 + * it under the terms of the GNU General Public License as published by
28234 + * the Free Software Foundation; either version 2 of the License, or
28235 + * (at your option) any later version.
28237 + * This program is distributed in the hope that it will be useful,
28238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28240 + * GNU General Public License for more details.
28242 + * You should have received a copy of the GNU General Public License
28243 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28248 + * There is only one filesystem which implements ->poll operation, currently.
28253 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28256 + struct file *h_file;
28257 + struct super_block *sb;
28259 + /* We should pretend an error happened. */
28260 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28261 + sb = file->f_path.dentry->d_sb;
28262 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28264 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28265 + if (IS_ERR(h_file)) {
28266 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28270 + mask = vfs_poll(h_file, pt);
28271 + fput(h_file); /* instead of au_read_post() */
28274 + si_read_unlock(sb);
28275 + if (mask & EPOLLERR)
28276 + AuDbg("mask 0x%x\n", mask);
28279 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28280 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28281 +++ linux/fs/aufs/posix_acl.c 2021-11-01 23:48:34.209692595 +0100
28283 +// SPDX-License-Identifier: GPL-2.0
28285 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28287 + * This program, aufs is free software; you can redistribute it and/or modify
28288 + * it under the terms of the GNU General Public License as published by
28289 + * the Free Software Foundation; either version 2 of the License, or
28290 + * (at your option) any later version.
28292 + * This program is distributed in the hope that it will be useful,
28293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28295 + * GNU General Public License for more details.
28297 + * You should have received a copy of the GNU General Public License
28298 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28302 + * posix acl operations
28305 +#include <linux/fs.h>
28308 +struct posix_acl *aufs_get_acl(struct inode *inode, int type, bool rcu)
28310 + struct posix_acl *acl;
28312 + aufs_bindex_t bindex;
28313 + struct inode *h_inode;
28314 + struct super_block *sb;
28316 + acl = ERR_PTR(-ECHILD);
28321 + sb = inode->i_sb;
28322 + si_read_lock(sb, AuLock_FLUSH);
28323 + ii_read_lock_child(inode);
28324 + if (!(sb->s_flags & SB_POSIXACL))
28327 + bindex = au_ibtop(inode);
28328 + h_inode = au_h_iptr(inode, bindex);
28329 + if (unlikely(!h_inode
28330 + || ((h_inode->i_mode & S_IFMT)
28331 + != (inode->i_mode & S_IFMT)))) {
28332 + err = au_busy_or_stale();
28333 + acl = ERR_PTR(err);
28337 + /* always topmost only */
28338 + acl = get_acl(h_inode, type);
28340 + forget_cached_acl(inode, type);
28342 + set_cached_acl(inode, type, acl);
28345 + ii_read_unlock(inode);
28346 + si_read_unlock(sb);
28349 + AuTraceErrPtr(acl);
28353 +int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
28354 + struct posix_acl *acl, int type)
28358 + struct dentry *dentry;
28359 + struct au_sxattr arg = {
28360 + .type = AU_ACL_SET,
28367 + IMustLock(inode);
28369 + if (inode->i_ino == AUFS_ROOT_INO)
28370 + dentry = dget(inode->i_sb->s_root);
28372 + dentry = d_find_alias(inode);
28374 + dentry = d_find_any_alias(inode);
28376 + pr_warn("cannot handle this inode, "
28377 + "please report to aufs-users ML\n");
28383 + ssz = au_sxattr(dentry, inode, &arg);
28384 + /* forget even it if succeeds since the branch might set differently */
28385 + forget_cached_acl(inode, type);
28394 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28395 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28396 +++ linux/fs/aufs/procfs.c 2021-11-01 23:48:34.209692595 +0100
28398 +// SPDX-License-Identifier: GPL-2.0
28400 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28402 + * This program, aufs is free software; you can redistribute it and/or modify
28403 + * it under the terms of the GNU General Public License as published by
28404 + * the Free Software Foundation; either version 2 of the License, or
28405 + * (at your option) any later version.
28407 + * This program is distributed in the hope that it will be useful,
28408 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28409 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28410 + * GNU General Public License for more details.
28412 + * You should have received a copy of the GNU General Public License
28413 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28417 + * procfs interfaces
28420 +#include <linux/proc_fs.h>
28423 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28425 + struct au_sbinfo *sbinfo;
28427 + sbinfo = file->private_data;
28429 + au_plink_maint_leave(sbinfo);
28430 + kobject_put(&sbinfo->si_kobj);
28436 +static void au_procfs_plm_write_clean(struct file *file)
28438 + struct au_sbinfo *sbinfo;
28440 + sbinfo = file->private_data;
28442 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28445 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28448 + struct super_block *sb;
28449 + struct au_sbinfo *sbinfo;
28450 + struct hlist_bl_node *pos;
28453 + if (unlikely(file->private_data))
28457 + /* don't use au_sbilist_lock() here */
28458 + hlist_bl_lock(&au_sbilist);
28459 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28460 + if (id == sysaufs_si_id(sbinfo)) {
28461 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28462 + sb = sbinfo->si_sb;
28465 + hlist_bl_unlock(&au_sbilist);
28468 + if (unlikely(!sb))
28471 + err = au_plink_maint_enter(sb);
28473 + /* keep kobject_get() */
28474 + file->private_data = sbinfo;
28476 + kobject_put(&sbinfo->si_kobj);
28482 + * Accept a valid "si=xxxx" only.
28483 + * Once it is accepted successfully, accept "clean" too.
28485 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28486 + size_t count, loff_t *ppos)
28489 + unsigned long id;
28490 + /* last newline is allowed */
28491 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28494 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28498 + if (unlikely(count > sizeof(buf)))
28501 + err = copy_from_user(buf, ubuf, count);
28502 + if (unlikely(err)) {
28509 + if (!strcmp("clean", buf)) {
28510 + au_procfs_plm_write_clean(file);
28511 + goto out_success;
28512 + } else if (unlikely(strncmp("si=", buf, 3)))
28515 + err = kstrtoul(buf + 3, 16, &id);
28516 + if (unlikely(err))
28519 + err = au_procfs_plm_write_si(file, id);
28520 + if (unlikely(err))
28524 + err = count; /* success */
28529 +static const struct proc_ops au_procfs_plm_op = {
28530 + .proc_write = au_procfs_plm_write,
28531 + .proc_release = au_procfs_plm_release
28534 +/* ---------------------------------------------------------------------- */
28536 +static struct proc_dir_entry *au_procfs_dir;
28538 +void au_procfs_fin(void)
28540 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28541 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28544 +int __init au_procfs_init(void)
28547 + struct proc_dir_entry *entry;
28550 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28551 + if (unlikely(!au_procfs_dir))
28554 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28555 + au_procfs_dir, &au_procfs_plm_op);
28556 + if (unlikely(!entry))
28560 + goto out; /* success */
28564 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28568 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28569 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28570 +++ linux/fs/aufs/rdu.c 2021-11-01 23:48:34.209692595 +0100
28572 +// SPDX-License-Identifier: GPL-2.0
28574 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28576 + * This program, aufs is free software; you can redistribute it and/or modify
28577 + * it under the terms of the GNU General Public License as published by
28578 + * the Free Software Foundation; either version 2 of the License, or
28579 + * (at your option) any later version.
28581 + * This program is distributed in the hope that it will be useful,
28582 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28583 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28584 + * GNU General Public License for more details.
28586 + * You should have received a copy of the GNU General Public License
28587 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28591 + * readdir in userspace.
28594 +#include <linux/compat.h>
28595 +#include <linux/fs_stack.h>
28596 +#include <linux/security.h>
28599 +/* bits for struct aufs_rdu.flags */
28600 +#define AuRdu_CALLED 1
28601 +#define AuRdu_CONT (1 << 1)
28602 +#define AuRdu_FULL (1 << 2)
28603 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28604 +#define au_fset_rdu(flags, name) \
28605 + do { (flags) |= AuRdu_##name; } while (0)
28606 +#define au_fclr_rdu(flags, name) \
28607 + do { (flags) &= ~AuRdu_##name; } while (0)
28609 +struct au_rdu_arg {
28610 + struct dir_context ctx;
28611 + struct aufs_rdu *rdu;
28612 + union au_rdu_ent_ul ent;
28613 + unsigned long end;
28615 + struct super_block *sb;
28619 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28620 + loff_t offset, u64 h_ino, unsigned int d_type)
28623 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28624 + struct aufs_rdu *rdu = arg->rdu;
28625 + struct au_rdu_ent ent;
28629 + au_fset_rdu(rdu->cookie.flags, CALLED);
28630 + len = au_rdu_len(nlen);
28631 + if (arg->ent.ul + len < arg->end) {
28633 + ent.bindex = rdu->cookie.bindex;
28634 + ent.type = d_type;
28636 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28637 + ent.type = DT_UNKNOWN;
28639 + /* unnecessary to support mmap_sem since this is a dir */
28641 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28643 + if (copy_to_user(arg->ent.e->name, name, nlen))
28645 + /* the terminating NULL */
28646 + if (__put_user(0, arg->ent.e->name + nlen))
28649 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28650 + arg->ent.ul += len;
28654 + au_fset_rdu(rdu->cookie.flags, FULL);
28656 + rdu->tail = arg->ent;
28660 + /* AuTraceErr(err); */
28664 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28668 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28670 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28671 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28673 + if (unlikely(offset != cookie->h_pos))
28679 + au_fclr_rdu(cookie->flags, CALLED);
28681 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28685 + && au_ftest_rdu(cookie->flags, CALLED)
28686 + && !au_ftest_rdu(cookie->flags, FULL));
28687 + cookie->h_pos = h_file->f_pos;
28694 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28697 + aufs_bindex_t bbot;
28698 + struct au_rdu_arg arg = {
28700 + .actor = au_rdu_fill
28703 + struct dentry *dentry;
28704 + struct inode *inode;
28705 + struct file *h_file;
28706 + struct au_rdu_cookie *cookie = &rdu->cookie;
28708 + /* VERIFY_WRITE */
28709 + err = !access_ok(rdu->ent.e, rdu->sz);
28710 + if (unlikely(err)) {
28716 + rdu->tail = rdu->ent;
28719 + arg.ent = rdu->ent;
28720 + arg.end = arg.ent.ul;
28721 + arg.end += rdu->sz;
28724 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28727 + err = security_file_permission(file, MAY_READ);
28729 + if (unlikely(err))
28732 + dentry = file->f_path.dentry;
28733 + inode = d_inode(dentry);
28734 + inode_lock_shared(inode);
28736 + arg.sb = inode->i_sb;
28737 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28738 + if (unlikely(err))
28740 + err = au_alive_dir(dentry);
28741 + if (unlikely(err))
28743 + /* todo: reval? */
28744 + fi_read_lock(file);
28747 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28748 + && cookie->generation != au_figen(file)))
28753 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28755 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28757 + bbot = au_fbtop(file);
28758 + if (cookie->bindex < bbot)
28759 + cookie->bindex = bbot;
28760 + bbot = au_fbbot_dir(file);
28761 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28762 + for (; !err && cookie->bindex <= bbot;
28763 + cookie->bindex++, cookie->h_pos = 0) {
28764 + h_file = au_hf_dir(file, cookie->bindex);
28768 + au_fclr_rdu(cookie->flags, FULL);
28769 + err = au_rdu_do(h_file, &arg);
28771 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28774 + AuDbg("rent %llu\n", rdu->rent);
28776 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28777 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28778 + au_fset_rdu(cookie->flags, CONT);
28779 + cookie->generation = au_figen(file);
28782 + ii_read_lock_child(inode);
28783 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28784 + ii_read_unlock(inode);
28787 + fi_read_unlock(file);
28789 + si_read_unlock(arg.sb);
28791 + inode_unlock_shared(inode);
28797 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28801 + unsigned long long nent;
28802 + union au_rdu_ent_ul *u;
28803 + struct au_rdu_ent ent;
28804 + struct super_block *sb;
28807 + nent = rdu->nent;
28809 + sb = file->f_path.dentry->d_sb;
28810 + si_read_lock(sb, AuLock_FLUSH);
28811 + while (nent-- > 0) {
28812 + /* unnecessary to support mmap_sem since this is a dir */
28813 + err = copy_from_user(&ent, u->e, sizeof(ent));
28815 + /* VERIFY_WRITE */
28816 + err = !access_ok(&u->e->ino, sizeof(ino));
28817 + if (unlikely(err)) {
28823 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28825 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28827 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28829 + if (unlikely(err)) {
28834 + err = __put_user(ino, &u->e->ino);
28835 + if (unlikely(err)) {
28840 + u->ul += au_rdu_len(ent.nlen);
28842 + si_read_unlock(sb);
28847 +/* ---------------------------------------------------------------------- */
28849 +static int au_rdu_verify(struct aufs_rdu *rdu)
28851 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28852 + "%llu, b%d, 0x%x, g%u}\n",
28853 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28855 + rdu->rent, rdu->shwh, rdu->full,
28856 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28857 + rdu->cookie.generation);
28859 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28863 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28867 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28870 + struct aufs_rdu rdu;
28871 + void __user *p = (void __user *)arg;
28873 + err = copy_from_user(&rdu, p, sizeof(rdu));
28874 + if (unlikely(err)) {
28879 + err = au_rdu_verify(&rdu);
28880 + if (unlikely(err))
28884 + case AUFS_CTL_RDU:
28885 + err = au_rdu(file, &rdu);
28886 + if (unlikely(err))
28889 + e = copy_to_user(p, &rdu, sizeof(rdu));
28890 + if (unlikely(e)) {
28895 + case AUFS_CTL_RDU_INO:
28896 + err = au_rdu_ino(file, &rdu);
28900 + /* err = -ENOTTY; */
28909 +#ifdef CONFIG_COMPAT
28910 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28913 + struct aufs_rdu rdu;
28914 + void __user *p = compat_ptr(arg);
28916 + /* todo: get_user()? */
28917 + err = copy_from_user(&rdu, p, sizeof(rdu));
28918 + if (unlikely(err)) {
28923 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28924 + err = au_rdu_verify(&rdu);
28925 + if (unlikely(err))
28929 + case AUFS_CTL_RDU:
28930 + err = au_rdu(file, &rdu);
28931 + if (unlikely(err))
28934 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28935 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28936 + e = copy_to_user(p, &rdu, sizeof(rdu));
28937 + if (unlikely(e)) {
28942 + case AUFS_CTL_RDU_INO:
28943 + err = au_rdu_ino(file, &rdu);
28947 + /* err = -ENOTTY; */
28956 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28957 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28958 +++ linux/fs/aufs/rwsem.h 2021-11-01 23:48:34.209692595 +0100
28960 +/* SPDX-License-Identifier: GPL-2.0 */
28962 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28964 + * This program, aufs is free software; you can redistribute it and/or modify
28965 + * it under the terms of the GNU General Public License as published by
28966 + * the Free Software Foundation; either version 2 of the License, or
28967 + * (at your option) any later version.
28969 + * This program is distributed in the hope that it will be useful,
28970 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28971 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28972 + * GNU General Public License for more details.
28974 + * You should have received a copy of the GNU General Public License
28975 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28979 + * simple read-write semaphore wrappers
28982 +#ifndef __AUFS_RWSEM_H__
28983 +#define __AUFS_RWSEM_H__
28987 +#include "debug.h"
28989 +/* in the future, the name 'au_rwsem' will be totally gone */
28990 +#define au_rwsem rw_semaphore
28992 +/* to debug easier, do not make them inlined functions */
28993 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28995 +#ifdef CONFIG_LOCKDEP
28996 +/* rwsem_is_locked() is unusable */
28997 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28998 + && !lockdep_recursing(current) \
29000 + && !lockdep_is_held_type(rw, 1))
29001 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29002 + && !lockdep_recursing(current) \
29004 + && !lockdep_is_held_type(rw, 0))
29005 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29006 + && !lockdep_recursing(current) \
29008 + && !lockdep_is_held(rw))
29009 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29010 + && !lockdep_recursing(current) \
29012 + && lockdep_is_held(rw))
29014 +#define AuRwMustReadLock(rw) do {} while (0)
29015 +#define AuRwMustWriteLock(rw) do {} while (0)
29016 +#define AuRwMustAnyLock(rw) do {} while (0)
29017 +#define AuRwDestroy(rw) do {} while (0)
29020 +#define au_rw_init(rw) init_rwsem(rw)
29022 +#define au_rw_init_wlock(rw) do { \
29023 + au_rw_init(rw); \
29024 + down_write(rw); \
29027 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29028 + au_rw_init(rw); \
29029 + down_write_nested(rw, lsc); \
29032 +#define au_rw_read_lock(rw) down_read(rw)
29033 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29034 +#define au_rw_read_unlock(rw) up_read(rw)
29035 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29036 +#define au_rw_write_lock(rw) down_write(rw)
29037 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29038 +#define au_rw_write_unlock(rw) up_write(rw)
29039 +/* why is not _nested version defined? */
29040 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29041 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29043 +#endif /* __KERNEL__ */
29044 +#endif /* __AUFS_RWSEM_H__ */
29045 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29046 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29047 +++ linux/fs/aufs/sbinfo.c 2021-11-01 23:48:34.213025928 +0100
29049 +// SPDX-License-Identifier: GPL-2.0
29051 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29053 + * This program, aufs is free software; you can redistribute it and/or modify
29054 + * it under the terms of the GNU General Public License as published by
29055 + * the Free Software Foundation; either version 2 of the License, or
29056 + * (at your option) any later version.
29058 + * This program is distributed in the hope that it will be useful,
29059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29061 + * GNU General Public License for more details.
29063 + * You should have received a copy of the GNU General Public License
29064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29068 + * superblock private data
29071 +#include <linux/iversion.h>
29075 + * they are necessary regardless sysfs is disabled.
29077 +void au_si_free(struct kobject *kobj)
29080 + struct au_sbinfo *sbinfo;
29081 + char *locked __maybe_unused; /* debug only */
29083 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29084 + for (i = 0; i < AuPlink_NHASH; i++)
29085 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29086 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29088 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29089 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29090 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29091 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29093 + dbgaufs_si_fin(sbinfo);
29094 + au_rw_write_lock(&sbinfo->si_rwsem);
29095 + au_br_free(sbinfo);
29096 + au_rw_write_unlock(&sbinfo->si_rwsem);
29098 + au_kfree_try_rcu(sbinfo->si_branch);
29099 + mutex_destroy(&sbinfo->si_xib_mtx);
29100 + AuRwDestroy(&sbinfo->si_rwsem);
29102 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29103 + /* si_nfiles is waited too */
29104 + au_kfree_rcu(sbinfo);
29107 +int au_si_alloc(struct super_block *sb)
29110 + struct au_sbinfo *sbinfo;
29113 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29114 + if (unlikely(!sbinfo))
29117 + /* will be reallocated separately */
29118 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29119 + if (unlikely(!sbinfo->si_branch))
29122 + err = sysaufs_si_init(sbinfo);
29124 + dbgaufs_si_null(sbinfo);
29125 + err = dbgaufs_si_init(sbinfo);
29126 + if (unlikely(err))
29127 + kobject_put(&sbinfo->si_kobj);
29129 + if (unlikely(err))
29132 + au_nwt_init(&sbinfo->si_nowait);
29133 + au_rw_init_wlock(&sbinfo->si_rwsem);
29135 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29136 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29138 + sbinfo->si_bbot = -1;
29139 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29141 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29142 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29143 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29144 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29146 + au_fhsm_init(sbinfo);
29148 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29150 + sbinfo->si_xino_jiffy = jiffies;
29151 + sbinfo->si_xino_expire
29152 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29153 + mutex_init(&sbinfo->si_xib_mtx);
29154 + /* leave si_xib_last_pindex and si_xib_next_bit */
29156 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29158 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29159 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29160 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29161 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29163 + for (i = 0; i < AuPlink_NHASH; i++)
29164 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29165 + init_waitqueue_head(&sbinfo->si_plink_wq);
29166 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29168 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29170 + /* with getattr by default */
29171 + sbinfo->si_iop_array = aufs_iop;
29173 + /* leave other members for sysaufs and si_mnt. */
29174 + sbinfo->si_sb = sb;
29175 + sb->s_fs_info = sbinfo;
29177 + return 0; /* success */
29180 + au_kfree_try_rcu(sbinfo->si_branch);
29182 + au_kfree_rcu(sbinfo);
29187 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29190 + struct au_branch **brp;
29192 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29195 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29196 + if (unlikely(!sz))
29197 + sz = sizeof(*brp);
29198 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29201 + sbinfo->si_branch = brp;
29208 +/* ---------------------------------------------------------------------- */
29210 +unsigned int au_sigen_inc(struct super_block *sb)
29212 + unsigned int gen;
29213 + struct inode *inode;
29215 + SiMustWriteLock(sb);
29217 + gen = ++au_sbi(sb)->si_generation;
29218 + au_update_digen(sb->s_root);
29219 + inode = d_inode(sb->s_root);
29220 + au_update_iigen(inode, /*half*/0);
29221 + inode_inc_iversion(inode);
29225 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29227 + aufs_bindex_t br_id;
29229 + struct au_sbinfo *sbinfo;
29231 + SiMustWriteLock(sb);
29233 + sbinfo = au_sbi(sb);
29234 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29235 + br_id = ++sbinfo->si_last_br_id;
29236 + AuDebugOn(br_id < 0);
29237 + if (br_id && au_br_index(sb, br_id) < 0)
29244 +/* ---------------------------------------------------------------------- */
29246 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29247 +int si_read_lock(struct super_block *sb, int flags)
29252 + if (au_ftest_lock(flags, FLUSH))
29253 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29255 + si_noflush_read_lock(sb);
29256 + err = au_plink_maint(sb, flags);
29257 + if (unlikely(err))
29258 + si_read_unlock(sb);
29263 +int si_write_lock(struct super_block *sb, int flags)
29267 + if (au_ftest_lock(flags, FLUSH))
29268 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29270 + si_noflush_write_lock(sb);
29271 + err = au_plink_maint(sb, flags);
29272 + if (unlikely(err))
29273 + si_write_unlock(sb);
29278 +/* dentry and super_block lock. call at entry point */
29279 +int aufs_read_lock(struct dentry *dentry, int flags)
29282 + struct super_block *sb;
29284 + sb = dentry->d_sb;
29285 + err = si_read_lock(sb, flags);
29286 + if (unlikely(err))
29289 + if (au_ftest_lock(flags, DW))
29290 + di_write_lock_child(dentry);
29292 + di_read_lock_child(dentry, flags);
29294 + if (au_ftest_lock(flags, GEN)) {
29295 + err = au_digen_test(dentry, au_sigen(sb));
29296 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29297 + AuDebugOn(!err && au_dbrange_test(dentry));
29299 + err = au_dbrange_test(dentry);
29300 + if (unlikely(err))
29301 + aufs_read_unlock(dentry, flags);
29308 +void aufs_read_unlock(struct dentry *dentry, int flags)
29310 + if (au_ftest_lock(flags, DW))
29311 + di_write_unlock(dentry);
29313 + di_read_unlock(dentry, flags);
29314 + si_read_unlock(dentry->d_sb);
29317 +void aufs_write_lock(struct dentry *dentry)
29319 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29320 + di_write_lock_child(dentry);
29323 +void aufs_write_unlock(struct dentry *dentry)
29325 + di_write_unlock(dentry);
29326 + si_write_unlock(dentry->d_sb);
29329 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29332 + unsigned int sigen;
29333 + struct super_block *sb;
29336 + err = si_read_lock(sb, flags);
29337 + if (unlikely(err))
29340 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29342 + if (au_ftest_lock(flags, GEN)) {
29343 + sigen = au_sigen(sb);
29344 + err = au_digen_test(d1, sigen);
29345 + AuDebugOn(!err && au_dbrange_test(d1));
29347 + err = au_digen_test(d2, sigen);
29348 + AuDebugOn(!err && au_dbrange_test(d2));
29350 + if (unlikely(err))
29351 + aufs_read_and_write_unlock2(d1, d2);
29358 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29360 + di_write_unlock2(d1, d2);
29361 + si_read_unlock(d1->d_sb);
29363 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29364 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29365 +++ linux/fs/aufs/super.c 2021-11-25 11:42:28.836641524 +0100
29367 +// SPDX-License-Identifier: GPL-2.0
29369 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29371 + * This program, aufs is free software; you can redistribute it and/or modify
29372 + * it under the terms of the GNU General Public License as published by
29373 + * the Free Software Foundation; either version 2 of the License, or
29374 + * (at your option) any later version.
29376 + * This program is distributed in the hope that it will be useful,
29377 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29378 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29379 + * GNU General Public License for more details.
29381 + * You should have received a copy of the GNU General Public License
29382 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29386 + * mount and super_block operations
29389 +#include <linux/iversion.h>
29390 +#include <linux/mm.h>
29391 +#include <linux/seq_file.h>
29392 +#include <linux/statfs.h>
29393 +#include <linux/vmalloc.h>
29397 + * super_operations
29399 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29401 + struct au_icntnr *c;
29403 + c = au_cache_alloc_icntnr();
29405 + au_icntnr_init(c);
29406 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29407 + c->iinfo.ii_hinode = NULL;
29408 + return &c->vfs_inode;
29413 +static void aufs_destroy_inode(struct inode *inode)
29415 + if (!au_is_bad_inode(inode))
29416 + au_iinfo_fin(inode);
29419 +static void aufs_free_inode(struct inode *inode)
29421 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29424 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29426 + struct inode *inode;
29429 + inode = iget_locked(sb, ino);
29430 + if (unlikely(!inode)) {
29431 + inode = ERR_PTR(-ENOMEM);
29434 + if (!(inode->i_state & I_NEW))
29437 + err = au_xigen_new(inode);
29439 + err = au_iinfo_init(inode);
29441 + inode_inc_iversion(inode);
29443 + iget_failed(inode);
29444 + inode = ERR_PTR(err);
29448 + /* never return NULL */
29449 + AuDebugOn(!inode);
29450 + AuTraceErrPtr(inode);
29454 +/* lock free root dinfo */
29455 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29458 + aufs_bindex_t bindex, bbot;
29459 + struct path path;
29460 + struct au_hdentry *hdp;
29461 + struct au_branch *br;
29462 + au_br_perm_str_t perm;
29465 + bbot = au_sbbot(sb);
29467 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29468 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29469 + br = au_sbr(sb, bindex);
29470 + path.mnt = au_br_mnt(br);
29471 + path.dentry = hdp->hd_dentry;
29472 + err = au_seq_path(seq, &path);
29474 + au_optstr_br_perm(&perm, br->br_perm);
29475 + seq_printf(seq, "=%s", perm.a);
29476 + if (bindex != bbot)
29477 + seq_putc(seq, ':');
29480 + if (unlikely(err || seq_has_overflowed(seq)))
29486 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29487 + const char *append)
29492 + while (*pat != ':')
29495 + strcpy(p, append);
29496 + AuDebugOn(strlen(fmt) >= len);
29499 +static void au_show_wbr_create(struct seq_file *m, int v,
29500 + struct au_sbinfo *sbinfo)
29504 + struct au_wbr_mfs *mfs;
29506 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29508 + seq_puts(m, ",create=");
29509 + pat = au_optstr_wbr_create(v);
29510 + mfs = &sbinfo->si_wbr_mfs;
29512 + case AuWbrCreate_TDP:
29513 + case AuWbrCreate_RR:
29514 + case AuWbrCreate_MFS:
29515 + case AuWbrCreate_PMFS:
29516 + seq_puts(m, pat);
29518 + case AuWbrCreate_MFSRR:
29519 + case AuWbrCreate_TDMFS:
29520 + case AuWbrCreate_PMFSRR:
29521 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29522 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29524 + case AuWbrCreate_MFSV:
29525 + case AuWbrCreate_PMFSV:
29526 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29527 + seq_printf(m, fmt,
29528 + jiffies_to_msecs(mfs->mfs_expire)
29531 + case AuWbrCreate_MFSRRV:
29532 + case AuWbrCreate_TDMFSV:
29533 + case AuWbrCreate_PMFSRRV:
29534 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29535 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29536 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29543 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29545 +#ifdef CONFIG_SYSFS
29549 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29550 + aufs_bindex_t bindex, brid;
29551 + struct qstr *name;
29553 + struct dentry *d, *h_root;
29554 + struct au_branch *br;
29556 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29559 + f = au_sbi(sb)->si_xib;
29563 + /* stop printing the default xino path on the first writable branch */
29565 + bindex = au_xi_root(sb, f->f_path.dentry);
29566 + if (bindex >= 0) {
29567 + br = au_sbr_sb(sb, bindex);
29568 + h_root = au_br_dentry(br);
29571 + d = f->f_path.dentry;
29572 + name = &d->d_name;
29573 + /* safe ->d_parent because the file is unlinked */
29574 + if (d->d_parent == h_root
29575 + && name->len == len
29576 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29579 + seq_puts(seq, ",xino=");
29580 + err = au_xino_path(seq, f);
29587 +/* seq_file will re-call me in case of too long string */
29588 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29591 + unsigned int mnt_flags, v;
29592 + struct super_block *sb;
29593 + struct au_sbinfo *sbinfo;
29595 +#define AuBool(name, str) do { \
29596 + v = au_opt_test(mnt_flags, name); \
29597 + if (v != au_opt_test(AuOpt_Def, name)) \
29598 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29601 +#define AuStr(name, str) do { \
29602 + v = mnt_flags & AuOptMask_##name; \
29603 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29604 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29607 +#define AuUInt(name, str, val) do { \
29608 + if (val != AUFS_##name##_DEF) \
29609 + seq_printf(m, "," #str "=%u", val); \
29612 + sb = dentry->d_sb;
29613 + if (sb->s_flags & SB_POSIXACL)
29614 + seq_puts(m, ",acl");
29615 +#if 0 /* reserved for future use */
29616 + if (sb->s_flags & SB_I_VERSION)
29617 + seq_puts(m, ",i_version");
29620 + /* lock free root dinfo */
29621 + si_noflush_read_lock(sb);
29622 + sbinfo = au_sbi(sb);
29623 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29625 + mnt_flags = au_mntflags(sb);
29626 + if (au_opt_test(mnt_flags, XINO)) {
29627 + err = au_show_xino(m, sb);
29628 + if (unlikely(err))
29631 + seq_puts(m, ",noxino");
29633 + AuBool(TRUNC_XINO, trunc_xino);
29634 + AuStr(UDBA, udba);
29635 + AuBool(SHWH, shwh);
29636 + AuBool(PLINK, plink);
29637 + AuBool(DIO, dio);
29638 + AuBool(DIRPERM1, dirperm1);
29640 + v = sbinfo->si_wbr_create;
29641 + if (v != AuWbrCreate_Def)
29642 + au_show_wbr_create(m, v, sbinfo);
29644 + v = sbinfo->si_wbr_copyup;
29645 + if (v != AuWbrCopyup_Def)
29646 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29648 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29649 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29650 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29652 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29654 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29655 + AuUInt(RDCACHE, rdcache, v);
29657 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29658 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29660 + au_fhsm_show(m, sbinfo);
29662 + AuBool(DIRREN, dirren);
29663 + AuBool(SUM, sum);
29664 + /* AuBool(SUM_W, wsum); */
29665 + AuBool(WARN_PERM, warn_perm);
29666 + AuBool(VERBOSE, verbose);
29669 + /* be sure to print "br:" last */
29670 + if (!sysaufs_brs) {
29671 + seq_puts(m, ",br:");
29672 + au_show_brs(m, sb);
29674 + si_read_unlock(sb);
29682 +/* ---------------------------------------------------------------------- */
29684 +/* sum mode which returns the summation for statfs(2) */
29686 +static u64 au_add_till_max(u64 a, u64 b)
29694 + return ULLONG_MAX;
29697 +static u64 au_mul_till_max(u64 a, long mul)
29705 + return ULLONG_MAX;
29708 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29711 + long bsize, factor;
29712 + u64 blocks, bfree, bavail, files, ffree;
29713 + aufs_bindex_t bbot, bindex, i;
29714 + unsigned char shared;
29715 + struct path h_path;
29716 + struct super_block *h_sb;
29719 + bsize = LONG_MAX;
29725 + bbot = au_sbbot(sb);
29726 + for (bindex = 0; bindex <= bbot; bindex++) {
29727 + h_path.mnt = au_sbr_mnt(sb, bindex);
29728 + h_sb = h_path.mnt->mnt_sb;
29730 + for (i = 0; !shared && i < bindex; i++)
29731 + shared = (au_sbr_sb(sb, i) == h_sb);
29735 + /* sb->s_root for NFS is unreliable */
29736 + h_path.dentry = h_path.mnt->mnt_root;
29737 + err = vfs_statfs(&h_path, buf);
29738 + if (unlikely(err))
29741 + if (bsize > buf->f_bsize) {
29743 + * we will reduce bsize, so we have to expand blocks
29744 + * etc. to match them again
29746 + factor = (bsize / buf->f_bsize);
29747 + blocks = au_mul_till_max(blocks, factor);
29748 + bfree = au_mul_till_max(bfree, factor);
29749 + bavail = au_mul_till_max(bavail, factor);
29750 + bsize = buf->f_bsize;
29753 + factor = (buf->f_bsize / bsize);
29754 + blocks = au_add_till_max(blocks,
29755 + au_mul_till_max(buf->f_blocks, factor));
29756 + bfree = au_add_till_max(bfree,
29757 + au_mul_till_max(buf->f_bfree, factor));
29758 + bavail = au_add_till_max(bavail,
29759 + au_mul_till_max(buf->f_bavail, factor));
29760 + files = au_add_till_max(files, buf->f_files);
29761 + ffree = au_add_till_max(ffree, buf->f_ffree);
29764 + buf->f_bsize = bsize;
29765 + buf->f_blocks = blocks;
29766 + buf->f_bfree = bfree;
29767 + buf->f_bavail = bavail;
29768 + buf->f_files = files;
29769 + buf->f_ffree = ffree;
29770 + buf->f_frsize = 0;
29776 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29779 + struct path h_path;
29780 + struct super_block *sb;
29782 + /* lock free root dinfo */
29783 + sb = dentry->d_sb;
29784 + si_noflush_read_lock(sb);
29785 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29786 + /* sb->s_root for NFS is unreliable */
29787 + h_path.mnt = au_sbr_mnt(sb, 0);
29788 + h_path.dentry = h_path.mnt->mnt_root;
29789 + err = vfs_statfs(&h_path, buf);
29791 + err = au_statfs_sum(sb, buf);
29792 + si_read_unlock(sb);
29795 + buf->f_type = AUFS_SUPER_MAGIC;
29796 + buf->f_namelen = AUFS_MAX_NAMELEN;
29797 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29799 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29804 +/* ---------------------------------------------------------------------- */
29806 +static int aufs_sync_fs(struct super_block *sb, int wait)
29809 + aufs_bindex_t bbot, bindex;
29810 + struct au_branch *br;
29811 + struct super_block *h_sb;
29814 + si_noflush_read_lock(sb);
29815 + bbot = au_sbbot(sb);
29816 + for (bindex = 0; bindex <= bbot; bindex++) {
29817 + br = au_sbr(sb, bindex);
29818 + if (!au_br_writable(br->br_perm))
29821 + h_sb = au_sbr_sb(sb, bindex);
29822 + e = vfsub_sync_filesystem(h_sb, wait);
29823 + if (unlikely(e && !err))
29825 + /* go on even if an error happens */
29827 + si_read_unlock(sb);
29832 +/* ---------------------------------------------------------------------- */
29834 +/* final actions when unmounting a file system */
29835 +static void aufs_put_super(struct super_block *sb)
29837 + struct au_sbinfo *sbinfo;
29839 + sbinfo = au_sbi(sb);
29841 + kobject_put(&sbinfo->si_kobj);
29844 +/* ---------------------------------------------------------------------- */
29846 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29847 + struct super_block *sb, void *arg)
29850 + unsigned long long n, sz;
29857 + if (*hint > ULLONG_MAX / sizeof(array)) {
29858 + array = ERR_PTR(-EMFILE);
29859 + pr_err("hint %llu\n", *hint);
29863 + sz = sizeof(array) * *hint;
29864 + array = kzalloc(sz, GFP_NOFS);
29865 + if (unlikely(!array))
29866 + array = vzalloc(sz);
29867 + if (unlikely(!array)) {
29868 + array = ERR_PTR(-ENOMEM);
29872 + n = cb(sb, array, *hint, arg);
29873 + AuDebugOn(n > *hint);
29880 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29881 + unsigned long long max __maybe_unused,
29884 + unsigned long long n;
29885 + struct inode **p, *inode;
29886 + struct list_head *head;
29891 + spin_lock(&sb->s_inode_list_lock);
29892 + list_for_each_entry(inode, head, i_sb_list) {
29893 + if (!au_is_bad_inode(inode)
29894 + && au_ii(inode)->ii_btop >= 0) {
29895 + spin_lock(&inode->i_lock);
29896 + if (atomic_read(&inode->i_count)) {
29900 + AuDebugOn(n > max);
29902 + spin_unlock(&inode->i_lock);
29905 + spin_unlock(&sb->s_inode_list_lock);
29910 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29912 + struct au_sbinfo *sbi;
29914 + sbi = au_sbi(sb);
29915 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29916 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29919 +void au_iarray_free(struct inode **a, unsigned long long max)
29921 + unsigned long long ull;
29923 + for (ull = 0; ull < max; ull++)
29928 +/* ---------------------------------------------------------------------- */
29931 + * refresh dentry and inode at remount time.
29933 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29934 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29935 + struct dentry *parent)
29939 + di_write_lock_child(dentry);
29940 + di_read_lock_parent(parent, AuLock_IR);
29941 + err = au_refresh_dentry(dentry, parent);
29942 + if (!err && dir_flags)
29943 + au_hn_reset(d_inode(dentry), dir_flags);
29944 + di_read_unlock(parent, AuLock_IR);
29945 + di_write_unlock(dentry);
29950 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29951 + struct au_sbinfo *sbinfo,
29952 + const unsigned int dir_flags, unsigned int do_idop)
29955 + struct dentry *parent;
29958 + parent = dget_parent(dentry);
29959 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29960 + if (d_really_is_positive(dentry)) {
29961 + if (!d_is_dir(dentry))
29962 + err = au_do_refresh(dentry, /*dir_flags*/0,
29965 + err = au_do_refresh(dentry, dir_flags, parent);
29966 + if (unlikely(err))
29967 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29970 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29971 + AuDbgDentry(dentry);
29977 + au_refresh_dop(dentry, /*force_reval*/0);
29979 + au_refresh_dop(dentry, /*force_reval*/1);
29985 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29987 + int err, i, j, ndentry, e;
29988 + unsigned int sigen;
29989 + struct au_dcsub_pages dpages;
29990 + struct au_dpage *dpage;
29991 + struct dentry **dentries, *d;
29992 + struct au_sbinfo *sbinfo;
29993 + struct dentry *root = sb->s_root;
29994 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29997 + au_refresh_dop(root, /*force_reval*/0);
29999 + err = au_dpages_init(&dpages, GFP_NOFS);
30000 + if (unlikely(err))
30002 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30003 + if (unlikely(err))
30006 + sigen = au_sigen(sb);
30007 + sbinfo = au_sbi(sb);
30008 + for (i = 0; i < dpages.ndpage; i++) {
30009 + dpage = dpages.dpages + i;
30010 + dentries = dpage->dentries;
30011 + ndentry = dpage->ndentry;
30012 + for (j = 0; j < ndentry; j++) {
30014 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30016 + if (unlikely(e && !err))
30018 + /* go on even err */
30023 + au_dpages_free(&dpages);
30028 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30031 + unsigned int sigen;
30032 + unsigned long long max, ull;
30033 + struct inode *inode, **array;
30035 + array = au_iarray_alloc(sb, &max);
30036 + err = PTR_ERR(array);
30037 + if (IS_ERR(array))
30041 + sigen = au_sigen(sb);
30042 + for (ull = 0; ull < max; ull++) {
30043 + inode = array[ull];
30044 + if (unlikely(!inode))
30048 + ii_write_lock_child(inode);
30049 + if (au_iigen(inode, NULL) != sigen) {
30050 + e = au_refresh_hinode_self(inode);
30051 + if (unlikely(e)) {
30052 + au_refresh_iop(inode, /*force_getattr*/1);
30053 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30056 + /* go on even if err */
30059 + if (!e && do_idop)
30060 + au_refresh_iop(inode, /*force_getattr*/0);
30061 + ii_write_unlock(inode);
30064 + au_iarray_free(array, max);
30070 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30073 + unsigned int udba;
30074 + aufs_bindex_t bindex, bbot;
30075 + struct dentry *root;
30076 + struct inode *inode;
30077 + struct au_branch *br;
30078 + struct au_sbinfo *sbi;
30080 + au_sigen_inc(sb);
30081 + sbi = au_sbi(sb);
30082 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30084 + root = sb->s_root;
30085 + DiMustNoWaiters(root);
30086 + inode = d_inode(root);
30087 + IiMustNoWaiters(inode);
30089 + udba = au_opt_udba(sb);
30090 + bbot = au_sbbot(sb);
30091 + for (bindex = 0; bindex <= bbot; bindex++) {
30092 + br = au_sbr(sb, bindex);
30093 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30094 + if (unlikely(err))
30095 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30097 + /* go on even if err */
30099 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30102 + if (au_ftest_si(sbi, NO_DREVAL)) {
30103 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30104 + sb->s_d_op = &aufs_dop_noreval;
30105 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30106 + sbi->si_iop_array = aufs_iop_nogetattr;
30108 + AuDebugOn(sb->s_d_op == &aufs_dop);
30109 + sb->s_d_op = &aufs_dop;
30110 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30111 + sbi->si_iop_array = aufs_iop;
30113 + pr_info("reset to %ps and %ps\n",
30114 + sb->s_d_op, sbi->si_iop_array);
30117 + di_write_unlock(root);
30118 + err = au_refresh_d(sb, do_idop);
30119 + e = au_refresh_i(sb, do_idop);
30120 + if (unlikely(e && !err))
30122 + /* aufs_write_lock() calls ..._child() */
30123 + di_write_lock_child(root);
30125 + au_cpup_attr_all(inode, /*force*/1);
30127 + if (unlikely(err))
30128 + AuIOErr("refresh failed, ignored, %d\n", err);
30131 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30132 +static int cvt_err(int err)
30146 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30149 + unsigned int mntflags;
30150 + struct au_opts opts = {
30153 + struct dentry *root;
30154 + struct inode *inode;
30155 + struct au_sbinfo *sbinfo;
30158 + root = sb->s_root;
30159 + if (!data || !*data) {
30160 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30162 + di_write_lock_child(root);
30163 + err = au_opts_verify(sb, *flags, /*pending*/0);
30164 + aufs_write_unlock(root);
30170 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30171 + if (unlikely(!opts.opt))
30173 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30174 + opts.flags = AuOpts_REMOUNT;
30175 + opts.sb_flags = *flags;
30177 + /* parse it before aufs lock */
30178 + err = au_opts_parse(sb, data, &opts);
30179 + if (unlikely(err))
30182 + sbinfo = au_sbi(sb);
30183 + inode = d_inode(root);
30184 + inode_lock(inode);
30185 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30186 + if (unlikely(err))
30188 + di_write_lock_child(root);
30190 + /* au_opts_remount() may return an error */
30191 + err = au_opts_remount(sb, &opts);
30192 + au_opts_free(&opts);
30194 + if (au_ftest_opts(opts.flags, REFRESH))
30195 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30197 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30198 + mntflags = au_mntflags(sb);
30199 + do_dx = !!au_opt_test(mntflags, DIO);
30200 + au_dy_arefresh(do_dx);
30203 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30204 + aufs_write_unlock(root);
30207 + inode_unlock(inode);
30209 + free_page((unsigned long)opts.opt);
30211 + err = cvt_err(err);
30216 +static const struct super_operations aufs_sop = {
30217 + .alloc_inode = aufs_alloc_inode,
30218 + .destroy_inode = aufs_destroy_inode,
30219 + .free_inode = aufs_free_inode,
30220 + /* always deleting, no clearing */
30221 + .drop_inode = generic_delete_inode,
30222 + .show_options = aufs_show_options,
30223 + .statfs = aufs_statfs,
30224 + .put_super = aufs_put_super,
30225 + .sync_fs = aufs_sync_fs,
30226 + .remount_fs = aufs_remount_fs
30229 +/* ---------------------------------------------------------------------- */
30231 +static int alloc_root(struct super_block *sb)
30234 + struct inode *inode;
30235 + struct dentry *root;
30238 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30239 + err = PTR_ERR(inode);
30240 + if (IS_ERR(inode))
30243 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30244 + inode->i_fop = &aufs_dir_fop;
30245 + inode->i_mode = S_IFDIR;
30246 + set_nlink(inode, 2);
30247 + unlock_new_inode(inode);
30249 + root = d_make_root(inode);
30250 + if (unlikely(!root))
30252 + err = PTR_ERR(root);
30253 + if (IS_ERR(root))
30256 + err = au_di_init(root);
30258 + sb->s_root = root;
30259 + return 0; /* success */
30267 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30268 + int silent __maybe_unused)
30271 + struct au_opts opts = {
30274 + struct au_sbinfo *sbinfo;
30275 + struct dentry *root;
30276 + struct inode *inode;
30277 + char *arg = raw_data;
30279 + if (unlikely(!arg || !*arg)) {
30281 + pr_err("no arg\n");
30286 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30287 + if (unlikely(!opts.opt))
30289 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30290 + opts.sb_flags = sb->s_flags;
30292 + err = au_si_alloc(sb);
30293 + if (unlikely(err))
30295 + sbinfo = au_sbi(sb);
30297 + /* all timestamps always follow the ones on the branch */
30298 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30299 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30300 + sb->s_op = &aufs_sop;
30301 + sb->s_d_op = &aufs_dop;
30302 + sb->s_magic = AUFS_SUPER_MAGIC;
30303 + sb->s_maxbytes = 0;
30304 + sb->s_stack_depth = 1;
30305 + au_export_init(sb);
30306 + au_xattr_init(sb);
30308 + err = alloc_root(sb);
30309 + if (unlikely(err)) {
30310 + si_write_unlock(sb);
30313 + root = sb->s_root;
30314 + inode = d_inode(root);
30317 + * actually we can parse options regardless aufs lock here.
30318 + * but at remount time, parsing must be done before aufs lock.
30319 + * so we follow the same rule.
30321 + ii_write_lock_parent(inode);
30322 + aufs_write_unlock(root);
30323 + err = au_opts_parse(sb, arg, &opts);
30324 + if (unlikely(err))
30327 + /* lock vfs_inode first, then aufs. */
30328 + inode_lock(inode);
30329 + aufs_write_lock(root);
30330 + err = au_opts_mount(sb, &opts);
30331 + au_opts_free(&opts);
30332 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30333 + sb->s_d_op = &aufs_dop_noreval;
30334 + pr_info("%ps\n", sb->s_d_op);
30335 + au_refresh_dop(root, /*force_reval*/0);
30336 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30337 + au_refresh_iop(inode, /*force_getattr*/0);
30339 + aufs_write_unlock(root);
30340 + inode_unlock(inode);
30342 + goto out_opts; /* success */
30346 + sb->s_root = NULL;
30348 + kobject_put(&sbinfo->si_kobj);
30349 + sb->s_fs_info = NULL;
30351 + free_page((unsigned long)opts.opt);
30354 + err = cvt_err(err);
30359 +/* ---------------------------------------------------------------------- */
30361 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30362 + const char *dev_name __maybe_unused,
30365 + struct dentry *root;
30367 + /* all timestamps always follow the ones on the branch */
30368 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30369 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30370 + if (IS_ERR(root))
30373 + au_sbilist_add(root->d_sb);
30379 +static void aufs_kill_sb(struct super_block *sb)
30381 + struct au_sbinfo *sbinfo;
30383 + sbinfo = au_sbi(sb);
30385 + au_sbilist_del(sb);
30386 + aufs_write_lock(sb->s_root);
30388 + if (sbinfo->si_wbr_create_ops->fin)
30389 + sbinfo->si_wbr_create_ops->fin(sb);
30390 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30391 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30392 + au_remount_refresh(sb, /*do_idop*/0);
30394 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30395 + au_plink_put(sb, /*verbose*/1);
30397 + au_dr_opt_flush(sb);
30398 + sbinfo->si_sb = NULL;
30399 + aufs_write_unlock(sb->s_root);
30400 + au_nwt_flush(&sbinfo->si_nowait);
30402 + kill_anon_super(sb);
30405 +struct file_system_type aufs_fs_type = {
30406 + .name = AUFS_FSTYPE,
30407 + /* a race between rename and others */
30408 + .fs_flags = FS_RENAME_DOES_D_MOVE
30410 + /*| FS_ALLOW_IDMAP*/
30412 + .mount = aufs_mount,
30413 + .kill_sb = aufs_kill_sb,
30414 + /* no need to __module_get() and module_put(). */
30415 + .owner = THIS_MODULE,
30417 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30418 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30419 +++ linux/fs/aufs/super.h 2021-11-01 23:48:34.213025928 +0100
30421 +/* SPDX-License-Identifier: GPL-2.0 */
30423 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30425 + * This program, aufs is free software; you can redistribute it and/or modify
30426 + * it under the terms of the GNU General Public License as published by
30427 + * the Free Software Foundation; either version 2 of the License, or
30428 + * (at your option) any later version.
30430 + * This program is distributed in the hope that it will be useful,
30431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30433 + * GNU General Public License for more details.
30435 + * You should have received a copy of the GNU General Public License
30436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30440 + * super_block operations
30443 +#ifndef __AUFS_SUPER_H__
30444 +#define __AUFS_SUPER_H__
30448 +#include <linux/fs.h>
30449 +#include <linux/kobject.h>
30452 +#include "rwsem.h"
30455 +/* policies to select one among multiple writable branches */
30456 +struct au_wbr_copyup_operations {
30457 + int (*copyup)(struct dentry *dentry);
30460 +#define AuWbr_DIR 1 /* target is a dir */
30461 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30463 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30464 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30465 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30467 +struct au_wbr_create_operations {
30468 + int (*create)(struct dentry *dentry, unsigned int flags);
30469 + int (*init)(struct super_block *sb);
30470 + int (*fin)(struct super_block *sb);
30473 +struct au_wbr_mfs {
30474 + struct mutex mfs_lock; /* protect this structure */
30475 + unsigned long mfs_jiffy;
30476 + unsigned long mfs_expire;
30477 + aufs_bindex_t mfs_bindex;
30479 + unsigned long long mfsrr_bytes;
30480 + unsigned long long mfsrr_watermark;
30483 +#define AuPlink_NHASH 100
30484 +static inline int au_plink_hash(ino_t ino)
30486 + return ino % AuPlink_NHASH;
30489 +/* File-based Hierarchical Storage Management */
30491 +#ifdef CONFIG_AUFS_FHSM
30492 + /* allow only one process who can receive the notification */
30493 + spinlock_t fhsm_spin;
30495 + wait_queue_head_t fhsm_wqh;
30496 + atomic_t fhsm_readable;
30498 + /* these are protected by si_rwsem */
30499 + unsigned long fhsm_expire;
30500 + aufs_bindex_t fhsm_bottom;
30505 +struct au_sbinfo {
30506 + /* nowait tasks in the system-wide workqueue */
30507 + struct au_nowait_tasks si_nowait;
30510 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30511 + * rwsem for au_sbinfo is necessary.
30513 + struct au_rwsem si_rwsem;
30516 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30519 + au_lcnt_t si_ninodes, si_nfiles;
30521 + /* branch management */
30522 + unsigned int si_generation;
30524 + /* see AuSi_ flags */
30525 + unsigned char au_si_status;
30527 + aufs_bindex_t si_bbot;
30529 + /* dirty trick to keep br_id plus */
30530 + unsigned int si_last_br_id :
30531 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30532 + struct au_branch **si_branch;
30534 + /* policy to select a writable branch */
30535 + unsigned char si_wbr_copyup;
30536 + unsigned char si_wbr_create;
30537 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30538 + struct au_wbr_create_operations *si_wbr_create_ops;
30540 + /* round robin */
30541 + atomic_t si_wbr_rr_next;
30543 + /* most free space */
30544 + struct au_wbr_mfs si_wbr_mfs;
30546 + /* File-based Hierarchical Storage Management */
30547 + struct au_fhsm si_fhsm;
30549 + /* mount flags */
30550 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30551 + unsigned int si_mntflags;
30553 + /* external inode number (bitmap and translation table) */
30554 + loff_t si_ximaxent; /* max entries in a xino */
30556 + struct file *si_xib;
30557 + struct mutex si_xib_mtx; /* protect xib members */
30558 + unsigned long *si_xib_buf;
30559 + unsigned long si_xib_last_pindex;
30560 + int si_xib_next_bit;
30562 + unsigned long si_xino_jiffy;
30563 + unsigned long si_xino_expire;
30564 + /* reserved for future use */
30565 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30567 +#ifdef CONFIG_AUFS_EXPORT
30568 + /* i_generation */
30569 + /* todo: make xigen file an array to support many inode numbers */
30570 + struct file *si_xigen;
30571 + atomic_t si_xigen_next;
30574 + /* dirty trick to support atomic_open */
30575 + struct hlist_bl_head si_aopen;
30577 + /* vdir parameters */
30578 + unsigned long si_rdcache; /* max cache time in jiffies */
30579 + unsigned int si_rdblk; /* deblk size */
30580 + unsigned int si_rdhash; /* hash size */
30583 + * If the number of whiteouts are larger than si_dirwh, leave all of
30584 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30585 + * future fsck.aufs or kernel thread will remove them later.
30586 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30588 + unsigned int si_dirwh;
30590 + /* pseudo_link list */
30591 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30592 + wait_queue_head_t si_plink_wq;
30593 + spinlock_t si_plink_maint_lock;
30594 + pid_t si_plink_maint_pid;
30597 + struct hlist_bl_head si_files;
30599 + /* with/without getattr, brother of sb->s_d_op */
30600 + const struct inode_operations *si_iop_array;
30603 + * sysfs and lifetime management.
30604 + * this is not a small structure and it may be a waste of memory in case
30605 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30606 + * but using sysfs is majority.
30608 + struct kobject si_kobj;
30609 +#ifdef CONFIG_DEBUG_FS
30610 + struct dentry *si_dbgaufs;
30611 + struct dentry *si_dbgaufs_plink;
30612 + struct dentry *si_dbgaufs_xib;
30613 +#ifdef CONFIG_AUFS_EXPORT
30614 + struct dentry *si_dbgaufs_xigen;
30618 +#ifdef CONFIG_AUFS_SBILIST
30619 + struct hlist_bl_node si_list;
30622 + /* dirty, necessary for unmounting, sysfs and sysrq */
30623 + struct super_block *si_sb;
30626 +/* sbinfo status flags */
30628 + * set true when refresh_dirs() failed at remount time.
30629 + * then try refreshing dirs at access time again.
30630 + * if it is false, refreshing dirs at access time is unnecessary
30632 +#define AuSi_FAILED_REFRESH_DIR 1
30633 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30634 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30636 +#ifndef CONFIG_AUFS_FHSM
30638 +#define AuSi_FHSM 0
30641 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30642 + unsigned int flag)
30644 + AuRwMustAnyLock(&sbi->si_rwsem);
30645 + return sbi->au_si_status & flag;
30647 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30648 +#define au_fset_si(sbinfo, name) do { \
30649 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30650 + (sbinfo)->au_si_status |= AuSi_##name; \
30652 +#define au_fclr_si(sbinfo, name) do { \
30653 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30654 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30657 +/* ---------------------------------------------------------------------- */
30659 +/* policy to select one among writable branches */
30660 +#define AuWbrCopyup(sbinfo, ...) \
30661 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30662 +#define AuWbrCreate(sbinfo, ...) \
30663 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30665 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30666 +#define AuLock_DW 1 /* write-lock dentry */
30667 +#define AuLock_IR (1 << 1) /* read-lock inode */
30668 +#define AuLock_IW (1 << 2) /* write-lock inode */
30669 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30670 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30671 + /* except RENAME_EXCHANGE */
30672 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30673 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30674 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30675 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30676 +#define au_fset_lock(flags, name) \
30677 + do { (flags) |= AuLock_##name; } while (0)
30678 +#define au_fclr_lock(flags, name) \
30679 + do { (flags) &= ~AuLock_##name; } while (0)
30681 +/* ---------------------------------------------------------------------- */
30684 +extern struct file_system_type aufs_fs_type;
30685 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30686 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30687 + unsigned long long max, void *arg);
30688 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30689 + struct super_block *sb, void *arg);
30690 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30691 +void au_iarray_free(struct inode **a, unsigned long long max);
30694 +void au_si_free(struct kobject *kobj);
30695 +int au_si_alloc(struct super_block *sb);
30696 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30698 +unsigned int au_sigen_inc(struct super_block *sb);
30699 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30701 +int si_read_lock(struct super_block *sb, int flags);
30702 +int si_write_lock(struct super_block *sb, int flags);
30703 +int aufs_read_lock(struct dentry *dentry, int flags);
30704 +void aufs_read_unlock(struct dentry *dentry, int flags);
30705 +void aufs_write_lock(struct dentry *dentry);
30706 +void aufs_write_unlock(struct dentry *dentry);
30707 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30708 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30710 +/* wbr_policy.c */
30711 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30712 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30713 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30714 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30715 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30718 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30720 +#ifdef CONFIG_AUFS_FHSM
30723 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30727 + spin_lock(&fhsm->fhsm_spin);
30728 + pid = fhsm->fhsm_pid;
30729 + spin_unlock(&fhsm->fhsm_spin);
30734 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30735 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30736 +int au_fhsm_fd(struct super_block *sb, int oflags);
30737 +int au_fhsm_br_alloc(struct au_branch *br);
30738 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30739 +void au_fhsm_fin(struct super_block *sb);
30740 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30741 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30742 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30744 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30746 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30747 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30748 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30749 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30750 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30751 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30752 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30753 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30754 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30757 +/* ---------------------------------------------------------------------- */
30759 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30761 + return sb->s_fs_info;
30764 +/* ---------------------------------------------------------------------- */
30766 +#ifdef CONFIG_AUFS_EXPORT
30767 +int au_test_nfsd(void);
30768 +void au_export_init(struct super_block *sb);
30769 +void au_xigen_inc(struct inode *inode);
30770 +int au_xigen_new(struct inode *inode);
30771 +int au_xigen_set(struct super_block *sb, struct path *path);
30772 +void au_xigen_clr(struct super_block *sb);
30774 +static inline int au_busy_or_stale(void)
30776 + if (!au_test_nfsd())
30781 +AuStubInt0(au_test_nfsd, void)
30782 +AuStubVoid(au_export_init, struct super_block *sb)
30783 +AuStubVoid(au_xigen_inc, struct inode *inode)
30784 +AuStubInt0(au_xigen_new, struct inode *inode)
30785 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30786 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30787 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30788 +#endif /* CONFIG_AUFS_EXPORT */
30790 +/* ---------------------------------------------------------------------- */
30792 +#ifdef CONFIG_AUFS_SBILIST
30794 +extern struct hlist_bl_head au_sbilist;
30796 +static inline void au_sbilist_init(void)
30798 + INIT_HLIST_BL_HEAD(&au_sbilist);
30801 +static inline void au_sbilist_add(struct super_block *sb)
30803 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30806 +static inline void au_sbilist_del(struct super_block *sb)
30808 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30811 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30812 +static inline void au_sbilist_lock(void)
30814 + hlist_bl_lock(&au_sbilist);
30817 +static inline void au_sbilist_unlock(void)
30819 + hlist_bl_unlock(&au_sbilist);
30821 +#define AuGFP_SBILIST GFP_ATOMIC
30823 +AuStubVoid(au_sbilist_lock, void)
30824 +AuStubVoid(au_sbilist_unlock, void)
30825 +#define AuGFP_SBILIST GFP_NOFS
30826 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30828 +AuStubVoid(au_sbilist_init, void)
30829 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30830 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30831 +AuStubVoid(au_sbilist_lock, void)
30832 +AuStubVoid(au_sbilist_unlock, void)
30833 +#define AuGFP_SBILIST GFP_NOFS
30836 +/* ---------------------------------------------------------------------- */
30838 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30841 + * This function is a dynamic '__init' function actually,
30842 + * so the tiny check for si_rwsem is unnecessary.
30844 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30845 +#ifdef CONFIG_DEBUG_FS
30846 + sbinfo->si_dbgaufs = NULL;
30847 + sbinfo->si_dbgaufs_plink = NULL;
30848 + sbinfo->si_dbgaufs_xib = NULL;
30849 +#ifdef CONFIG_AUFS_EXPORT
30850 + sbinfo->si_dbgaufs_xigen = NULL;
30855 +/* ---------------------------------------------------------------------- */
30857 +/* current->atomic_flags */
30858 +/* this value should never corrupt the ones defined in linux/sched.h */
30859 +#define PFA_AUFS 0x10
30861 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30862 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30863 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30865 +static inline int si_pid_test(struct super_block *sb)
30867 + return !!task_test_aufs(current);
30870 +static inline void si_pid_clr(struct super_block *sb)
30872 + AuDebugOn(!task_test_aufs(current));
30873 + task_clear_aufs(current);
30876 +static inline void si_pid_set(struct super_block *sb)
30878 + AuDebugOn(task_test_aufs(current));
30879 + task_set_aufs(current);
30882 +/* ---------------------------------------------------------------------- */
30884 +/* lock superblock. mainly for entry point functions */
30885 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30886 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30887 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30888 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30890 +#define __si_read_trylock_nested(sb) \
30891 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30892 +#define __si_write_trylock_nested(sb) \
30893 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30896 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30897 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30898 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30900 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30901 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30902 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30904 +static inline void si_noflush_read_lock(struct super_block *sb)
30906 + __si_read_lock(sb);
30910 +static inline int si_noflush_read_trylock(struct super_block *sb)
30914 + locked = __si_read_trylock(sb);
30920 +static inline void si_noflush_write_lock(struct super_block *sb)
30922 + __si_write_lock(sb);
30926 +static inline int si_noflush_write_trylock(struct super_block *sb)
30930 + locked = __si_write_trylock(sb);
30936 +#if 0 /* reserved */
30937 +static inline int si_read_trylock(struct super_block *sb, int flags)
30939 + if (au_ftest_lock(flags, FLUSH))
30940 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30941 + return si_noflush_read_trylock(sb);
30945 +static inline void si_read_unlock(struct super_block *sb)
30948 + __si_read_unlock(sb);
30951 +#if 0 /* reserved */
30952 +static inline int si_write_trylock(struct super_block *sb, int flags)
30954 + if (au_ftest_lock(flags, FLUSH))
30955 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30956 + return si_noflush_write_trylock(sb);
30960 +static inline void si_write_unlock(struct super_block *sb)
30963 + __si_write_unlock(sb);
30966 +#if 0 /* reserved */
30967 +static inline void si_downgrade_lock(struct super_block *sb)
30969 + __si_downgrade_lock(sb);
30973 +/* ---------------------------------------------------------------------- */
30975 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30977 + SiMustAnyLock(sb);
30978 + return au_sbi(sb)->si_bbot;
30981 +static inline unsigned int au_mntflags(struct super_block *sb)
30983 + SiMustAnyLock(sb);
30984 + return au_sbi(sb)->si_mntflags;
30987 +static inline unsigned int au_sigen(struct super_block *sb)
30989 + SiMustAnyLock(sb);
30990 + return au_sbi(sb)->si_generation;
30993 +static inline struct au_branch *au_sbr(struct super_block *sb,
30994 + aufs_bindex_t bindex)
30996 + SiMustAnyLock(sb);
30997 + return au_sbi(sb)->si_branch[0 + bindex];
31000 +static inline loff_t au_xi_maxent(struct super_block *sb)
31002 + SiMustAnyLock(sb);
31003 + return au_sbi(sb)->si_ximaxent;
31006 +#endif /* __KERNEL__ */
31007 +#endif /* __AUFS_SUPER_H__ */
31008 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31009 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31010 +++ linux/fs/aufs/sysaufs.c 2021-11-01 23:48:34.213025928 +0100
31012 +// SPDX-License-Identifier: GPL-2.0
31014 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31016 + * This program, aufs is free software; you can redistribute it and/or modify
31017 + * it under the terms of the GNU General Public License as published by
31018 + * the Free Software Foundation; either version 2 of the License, or
31019 + * (at your option) any later version.
31021 + * This program is distributed in the hope that it will be useful,
31022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31024 + * GNU General Public License for more details.
31026 + * You should have received a copy of the GNU General Public License
31027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31031 + * sysfs interface and lifetime management
31032 + * they are necessary regardless sysfs is disabled.
31035 +#include <linux/random.h>
31038 +unsigned long sysaufs_si_mask;
31039 +struct kset *sysaufs_kset;
31041 +#define AuSiAttr(_name) { \
31042 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31043 + .show = sysaufs_si_##_name, \
31046 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31047 +struct attribute *sysaufs_si_attrs[] = {
31048 + &sysaufs_si_attr_xi_path.attr,
31052 +static const struct sysfs_ops au_sbi_ops = {
31053 + .show = sysaufs_si_show
31056 +static struct kobj_type au_sbi_ktype = {
31057 + .release = au_si_free,
31058 + .sysfs_ops = &au_sbi_ops,
31059 + .default_attrs = sysaufs_si_attrs
31062 +/* ---------------------------------------------------------------------- */
31064 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31068 + sbinfo->si_kobj.kset = sysaufs_kset;
31069 + /* cf. sysaufs_name() */
31070 + err = kobject_init_and_add
31071 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31072 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31077 +void sysaufs_fin(void)
31079 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31080 + kset_unregister(sysaufs_kset);
31083 +int __init sysaufs_init(void)
31088 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31089 + } while (!sysaufs_si_mask);
31092 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31093 + if (unlikely(!sysaufs_kset))
31095 + err = PTR_ERR(sysaufs_kset);
31096 + if (IS_ERR(sysaufs_kset))
31098 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31099 + if (unlikely(err))
31100 + kset_unregister(sysaufs_kset);
31105 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31106 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31107 +++ linux/fs/aufs/sysaufs.h 2021-11-01 23:48:34.213025928 +0100
31109 +/* SPDX-License-Identifier: GPL-2.0 */
31111 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31113 + * This program, aufs is free software; you can redistribute it and/or modify
31114 + * it under the terms of the GNU General Public License as published by
31115 + * the Free Software Foundation; either version 2 of the License, or
31116 + * (at your option) any later version.
31118 + * This program is distributed in the hope that it will be useful,
31119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31121 + * GNU General Public License for more details.
31123 + * You should have received a copy of the GNU General Public License
31124 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31128 + * sysfs interface and mount lifetime management
31131 +#ifndef __SYSAUFS_H__
31132 +#define __SYSAUFS_H__
31136 +#include <linux/sysfs.h>
31137 +#include "module.h"
31139 +struct super_block;
31142 +struct sysaufs_si_attr {
31143 + struct attribute attr;
31144 + int (*show)(struct seq_file *seq, struct super_block *sb);
31147 +/* ---------------------------------------------------------------------- */
31150 +extern unsigned long sysaufs_si_mask;
31151 +extern struct kset *sysaufs_kset;
31152 +extern struct attribute *sysaufs_si_attrs[];
31153 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31154 +int __init sysaufs_init(void);
31155 +void sysaufs_fin(void);
31157 +/* ---------------------------------------------------------------------- */
31159 +/* some people doesn't like to show a pointer in kernel */
31160 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31162 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31165 +#define SysaufsSiNamePrefix "si_"
31166 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31167 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31169 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31170 + sysaufs_si_id(sbinfo));
31174 +#ifdef CONFIG_SYSFS
31176 +extern struct attribute_group *sysaufs_attr_group;
31178 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31179 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31181 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31182 +#ifdef CONFIG_COMPAT
31183 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31186 +void sysaufs_br_init(struct au_branch *br);
31187 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31188 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31190 +#define sysaufs_brs_init() do {} while (0)
31193 +#define sysaufs_attr_group NULL
31195 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31196 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31197 + struct attribute *attr, char *buf)
31198 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31199 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31200 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31202 +static inline void sysaufs_brs_init(void)
31207 +#endif /* CONFIG_SYSFS */
31209 +#endif /* __KERNEL__ */
31210 +#endif /* __SYSAUFS_H__ */
31211 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31212 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31213 +++ linux/fs/aufs/sysfs.c 2021-11-01 23:48:34.213025928 +0100
31215 +// SPDX-License-Identifier: GPL-2.0
31217 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31219 + * This program, aufs is free software; you can redistribute it and/or modify
31220 + * it under the terms of the GNU General Public License as published by
31221 + * the Free Software Foundation; either version 2 of the License, or
31222 + * (at your option) any later version.
31224 + * This program is distributed in the hope that it will be useful,
31225 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31226 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31227 + * GNU General Public License for more details.
31229 + * You should have received a copy of the GNU General Public License
31230 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31234 + * sysfs interface
31237 +#include <linux/compat.h>
31238 +#include <linux/seq_file.h>
31241 +#ifdef CONFIG_AUFS_FS_MODULE
31242 +/* this entry violates the "one line per file" policy of sysfs */
31243 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31247 + static char *conf =
31248 +/* this file is generated at compiling */
31249 +#include "conf.str"
31252 + err = snprintf(buf, PAGE_SIZE, conf);
31253 + if (unlikely(err >= PAGE_SIZE))
31258 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31261 +static struct attribute *au_attr[] = {
31262 +#ifdef CONFIG_AUFS_FS_MODULE
31263 + &au_config_attr.attr,
31265 + NULL, /* need to NULL terminate the list of attributes */
31268 +static struct attribute_group sysaufs_attr_group_body = {
31272 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31274 +/* ---------------------------------------------------------------------- */
31276 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31280 + SiMustAnyLock(sb);
31283 + if (au_opt_test(au_mntflags(sb), XINO)) {
31284 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31285 + seq_putc(seq, '\n');
31291 + * the lifetime of branch is independent from the entry under sysfs.
31292 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31295 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31296 + aufs_bindex_t bindex, int idx)
31299 + struct path path;
31300 + struct dentry *root;
31301 + struct au_branch *br;
31302 + au_br_perm_str_t perm;
31304 + AuDbg("b%d\n", bindex);
31307 + root = sb->s_root;
31308 + di_read_lock_parent(root, !AuLock_IR);
31309 + br = au_sbr(sb, bindex);
31312 + case AuBrSysfs_BR:
31313 + path.mnt = au_br_mnt(br);
31314 + path.dentry = au_h_dptr(root, bindex);
31315 + err = au_seq_path(seq, &path);
31317 + au_optstr_br_perm(&perm, br->br_perm);
31318 + seq_printf(seq, "=%s\n", perm.a);
31321 + case AuBrSysfs_BRID:
31322 + seq_printf(seq, "%d\n", br->br_id);
31325 + di_read_unlock(root, !AuLock_IR);
31326 + if (unlikely(err || seq_has_overflowed(seq)))
31332 +/* ---------------------------------------------------------------------- */
31334 +static struct seq_file *au_seq(char *p, ssize_t len)
31336 + struct seq_file *seq;
31338 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31340 + /* mutex_init(&seq.lock); */
31343 + return seq; /* success */
31346 + seq = ERR_PTR(-ENOMEM);
31350 +#define SysaufsBr_PREFIX "br"
31351 +#define SysaufsBrid_PREFIX "brid"
31353 +/* todo: file size may exceed PAGE_SIZE */
31354 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31360 + aufs_bindex_t bbot;
31361 + struct au_sbinfo *sbinfo;
31362 + struct super_block *sb;
31363 + struct seq_file *seq;
31365 + struct attribute **cattr;
31367 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31368 + sb = sbinfo->si_sb;
31371 + * prevent a race condition between sysfs and aufs.
31372 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31373 + * prohibits maintaining the sysfs entries.
31374 + * hew we acquire read lock after sysfs_get_active_two().
31375 + * on the other hand, the remount process may maintain the sysfs/aufs
31376 + * entries after acquiring write lock.
31377 + * it can cause a deadlock.
31378 + * simply we gave up processing read here.
31381 + if (unlikely(!si_noflush_read_trylock(sb)))
31384 + seq = au_seq(buf, PAGE_SIZE);
31385 + err = PTR_ERR(seq);
31389 + name = (void *)attr->name;
31390 + cattr = sysaufs_si_attrs;
31392 + if (!strcmp(name, (*cattr)->name)) {
31393 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31400 + if (!strncmp(name, SysaufsBrid_PREFIX,
31401 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31402 + idx = AuBrSysfs_BRID;
31403 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31404 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31405 + sizeof(SysaufsBr_PREFIX) - 1)) {
31406 + idx = AuBrSysfs_BR;
31407 + name += sizeof(SysaufsBr_PREFIX) - 1;
31411 + err = kstrtol(name, 10, &l);
31413 + bbot = au_sbbot(sb);
31415 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31422 + err = seq->count;
31423 + /* sysfs limit */
31424 + if (unlikely(err == PAGE_SIZE))
31427 + au_kfree_rcu(seq);
31429 + si_read_unlock(sb);
31434 +/* ---------------------------------------------------------------------- */
31436 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31440 + aufs_bindex_t bindex, bbot;
31443 + struct seq_file *seq;
31444 + struct au_branch *br;
31446 + si_read_lock(sb, AuLock_FLUSH);
31447 + bbot = au_sbbot(sb);
31453 + buf = (void *)__get_free_page(GFP_NOFS);
31454 + if (unlikely(!buf))
31457 + seq = au_seq(buf, PAGE_SIZE);
31458 + err = PTR_ERR(seq);
31462 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31463 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31464 + /* VERIFY_WRITE */
31465 + err = !access_ok(arg, sizeof(*arg));
31466 + if (unlikely(err))
31469 + br = au_sbr(sb, bindex);
31470 + brid = br->br_id;
31471 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31472 + err = __put_user(brid, &arg->id);
31473 + if (unlikely(err))
31476 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31477 + err = __put_user(br->br_perm, &arg->perm);
31478 + if (unlikely(err))
31481 + err = au_seq_path(seq, &br->br_path);
31482 + if (unlikely(err))
31484 + seq_putc(seq, '\0');
31485 + if (!seq_has_overflowed(seq)) {
31486 + err = copy_to_user(arg->path, seq->buf, seq->count);
31488 + if (unlikely(err))
31495 + if (unlikely(err))
31499 + au_kfree_rcu(seq);
31501 + free_page((unsigned long)buf);
31503 + si_read_unlock(sb);
31507 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31509 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31512 +#ifdef CONFIG_COMPAT
31513 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31515 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31519 +/* ---------------------------------------------------------------------- */
31521 +void sysaufs_br_init(struct au_branch *br)
31524 + struct au_brsysfs *br_sysfs;
31525 + struct attribute *attr;
31527 + br_sysfs = br->br_sysfs;
31528 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31529 + attr = &br_sysfs->attr;
31530 + sysfs_attr_init(attr);
31531 + attr->name = br_sysfs->name;
31532 + attr->mode = 0444;
31537 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31539 + struct au_branch *br;
31540 + struct kobject *kobj;
31541 + struct au_brsysfs *br_sysfs;
31543 + aufs_bindex_t bbot;
31545 + if (!sysaufs_brs)
31548 + kobj = &au_sbi(sb)->si_kobj;
31549 + bbot = au_sbbot(sb);
31550 + for (; bindex <= bbot; bindex++) {
31551 + br = au_sbr(sb, bindex);
31552 + br_sysfs = br->br_sysfs;
31553 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31554 + sysfs_remove_file(kobj, &br_sysfs->attr);
31560 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31563 + aufs_bindex_t bbot;
31564 + struct kobject *kobj;
31565 + struct au_branch *br;
31566 + struct au_brsysfs *br_sysfs;
31568 + if (!sysaufs_brs)
31571 + kobj = &au_sbi(sb)->si_kobj;
31572 + bbot = au_sbbot(sb);
31573 + for (; bindex <= bbot; bindex++) {
31574 + br = au_sbr(sb, bindex);
31575 + br_sysfs = br->br_sysfs;
31576 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31577 + SysaufsBr_PREFIX "%d", bindex);
31578 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31579 + SysaufsBrid_PREFIX "%d", bindex);
31580 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31581 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31582 + if (unlikely(err))
31583 + pr_warn("failed %s under sysfs(%d)\n",
31584 + br_sysfs->name, err);
31589 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31590 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31591 +++ linux/fs/aufs/sysrq.c 2021-11-01 23:48:34.213025928 +0100
31593 +// SPDX-License-Identifier: GPL-2.0
31595 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31597 + * This program, aufs is free software; you can redistribute it and/or modify
31598 + * it under the terms of the GNU General Public License as published by
31599 + * the Free Software Foundation; either version 2 of the License, or
31600 + * (at your option) any later version.
31602 + * This program is distributed in the hope that it will be useful,
31603 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31604 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31605 + * GNU General Public License for more details.
31607 + * You should have received a copy of the GNU General Public License
31608 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31612 + * magic sysrq handler
31615 +/* #include <linux/sysrq.h> */
31616 +#include <linux/writeback.h>
31619 +/* ---------------------------------------------------------------------- */
31621 +static void sysrq_sb(struct super_block *sb)
31624 + struct au_sbinfo *sbinfo;
31625 + struct file *file;
31626 + struct hlist_bl_head *files;
31627 + struct hlist_bl_node *pos;
31628 + struct au_finfo *finfo;
31631 + plevel = au_plevel;
31632 + au_plevel = KERN_WARNING;
31634 + /* since we define pr_fmt, call printk directly */
31635 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31637 + sbinfo = au_sbi(sb);
31638 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31639 + pr("superblock\n");
31642 +#if 0 /* reserved */
31644 + int err, i, j, ndentry;
31645 + struct au_dcsub_pages dpages;
31646 + struct au_dpage *dpage;
31648 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31649 + if (unlikely(err))
31651 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31653 + for (i = 0; i < dpages.ndpage; i++) {
31654 + dpage = dpages.dpages + i;
31655 + ndentry = dpage->ndentry;
31656 + for (j = 0; j < ndentry; j++)
31657 + au_dpri_dentry(dpage->dentries[j]);
31659 + au_dpages_free(&dpages);
31663 + pr("isolated inode\n");
31664 + spin_lock(&sb->s_inode_list_lock);
31665 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31666 + spin_lock(&i->i_lock);
31667 + if (hlist_empty(&i->i_dentry))
31668 + au_dpri_inode(i);
31669 + spin_unlock(&i->i_lock);
31671 + spin_unlock(&sb->s_inode_list_lock);
31674 + files = &au_sbi(sb)->si_files;
31675 + hlist_bl_lock(files);
31676 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31679 + file = finfo->fi_file;
31680 + mode = file_inode(file)->i_mode;
31681 + if (!special_file(mode))
31682 + au_dpri_file(file);
31684 + hlist_bl_unlock(files);
31688 + au_plevel = plevel;
31691 +/* ---------------------------------------------------------------------- */
31693 +/* module parameter */
31694 +static char *aufs_sysrq_key = "a";
31695 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31696 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31698 +static void au_sysrq(int key __maybe_unused)
31700 + struct au_sbinfo *sbinfo;
31701 + struct hlist_bl_node *pos;
31704 + au_sbilist_lock();
31705 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31706 + sysrq_sb(sbinfo->si_sb);
31707 + au_sbilist_unlock();
31711 +static struct sysrq_key_op au_sysrq_op = {
31712 + .handler = au_sysrq,
31713 + .help_msg = "Aufs",
31714 + .action_msg = "Aufs",
31715 + .enable_mask = SYSRQ_ENABLE_DUMP
31718 +/* ---------------------------------------------------------------------- */
31720 +int __init au_sysrq_init(void)
31726 + key = *aufs_sysrq_key;
31727 + if ('a' <= key && key <= 'z')
31728 + err = register_sysrq_key(key, &au_sysrq_op);
31729 + if (unlikely(err))
31730 + pr_err("err %d, sysrq=%c\n", err, key);
31734 +void au_sysrq_fin(void)
31738 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31739 + if (unlikely(err))
31740 + pr_err("err %d (ignored)\n", err);
31742 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31743 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31744 +++ linux/fs/aufs/vdir.c 2021-11-01 23:48:34.213025928 +0100
31746 +// SPDX-License-Identifier: GPL-2.0
31748 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31750 + * This program, aufs is free software; you can redistribute it and/or modify
31751 + * it under the terms of the GNU General Public License as published by
31752 + * the Free Software Foundation; either version 2 of the License, or
31753 + * (at your option) any later version.
31755 + * This program is distributed in the hope that it will be useful,
31756 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31757 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31758 + * GNU General Public License for more details.
31760 + * You should have received a copy of the GNU General Public License
31761 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31765 + * virtual or vertical directory
31768 +#include <linux/iversion.h>
31771 +static unsigned int calc_size(int nlen)
31773 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31776 +static int set_deblk_end(union au_vdir_deblk_p *p,
31777 + union au_vdir_deblk_p *deblk_end)
31779 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31780 + p->de->de_str.len = 0;
31784 + return -1; /* error */
31787 +/* returns true or false */
31788 +static int is_deblk_end(union au_vdir_deblk_p *p,
31789 + union au_vdir_deblk_p *deblk_end)
31791 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31792 + return !p->de->de_str.len;
31796 +static unsigned char *last_deblk(struct au_vdir *vdir)
31798 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31801 +/* ---------------------------------------------------------------------- */
31803 +/* estimate the appropriate size for name hash table */
31804 +unsigned int au_rdhash_est(loff_t sz)
31812 + if (sz < AUFS_RDHASH_DEF)
31813 + n = AUFS_RDHASH_DEF;
31814 + /* pr_info("n %u\n", n); */
31819 + * the allocated memory has to be freed by
31820 + * au_nhash_wh_free() or au_nhash_de_free().
31822 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31824 + struct hlist_head *head;
31828 + sz = sizeof(*nhash->nh_head) * num_hash;
31829 + head = kmalloc(sz, gfp);
31831 + nhash->nh_num = num_hash;
31832 + nhash->nh_head = head;
31833 + for (u = 0; u < num_hash; u++)
31834 + INIT_HLIST_HEAD(head++);
31835 + return 0; /* success */
31841 +static void nhash_count(struct hlist_head *head)
31843 +#if 0 /* debugging */
31845 + struct hlist_node *pos;
31848 + hlist_for_each(pos, head)
31850 + pr_info("%lu\n", n);
31854 +static void au_nhash_wh_do_free(struct hlist_head *head)
31856 + struct au_vdir_wh *pos;
31857 + struct hlist_node *node;
31859 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31860 + au_kfree_rcu(pos);
31863 +static void au_nhash_de_do_free(struct hlist_head *head)
31865 + struct au_vdir_dehstr *pos;
31866 + struct hlist_node *node;
31868 + hlist_for_each_entry_safe(pos, node, head, hash)
31869 + au_cache_free_vdir_dehstr(pos);
31872 +static void au_nhash_do_free(struct au_nhash *nhash,
31873 + void (*free)(struct hlist_head *head))
31876 + struct hlist_head *head;
31878 + n = nhash->nh_num;
31882 + head = nhash->nh_head;
31883 + while (n-- > 0) {
31884 + nhash_count(head);
31887 + au_kfree_try_rcu(nhash->nh_head);
31890 +void au_nhash_wh_free(struct au_nhash *whlist)
31892 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31895 +static void au_nhash_de_free(struct au_nhash *delist)
31897 + au_nhash_do_free(delist, au_nhash_de_do_free);
31900 +/* ---------------------------------------------------------------------- */
31902 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31906 + unsigned int u, n;
31907 + struct hlist_head *head;
31908 + struct au_vdir_wh *pos;
31911 + n = whlist->nh_num;
31912 + head = whlist->nh_head;
31913 + for (u = 0; u < n; u++, head++)
31914 + hlist_for_each_entry(pos, head, wh_hash)
31915 + if (pos->wh_bindex == btgt && ++num > limit)
31920 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31921 + unsigned char *name,
31922 + unsigned int len)
31925 + /* const unsigned int magic_bit = 12; */
31927 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31934 + /* v = hash_long(v, magic_bit); */
31935 + v %= nhash->nh_num;
31936 + return nhash->nh_head + v;
31939 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31942 + return str->len == nlen && !memcmp(str->name, name, nlen);
31945 +/* returns found or not */
31946 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31948 + struct hlist_head *head;
31949 + struct au_vdir_wh *pos;
31950 + struct au_vdir_destr *str;
31952 + head = au_name_hash(whlist, name, nlen);
31953 + hlist_for_each_entry(pos, head, wh_hash) {
31954 + str = &pos->wh_str;
31955 + AuDbg("%.*s\n", str->len, str->name);
31956 + if (au_nhash_test_name(str, name, nlen))
31962 +/* returns found(true) or not */
31963 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31965 + struct hlist_head *head;
31966 + struct au_vdir_dehstr *pos;
31967 + struct au_vdir_destr *str;
31969 + head = au_name_hash(delist, name, nlen);
31970 + hlist_for_each_entry(pos, head, hash) {
31972 + AuDbg("%.*s\n", str->len, str->name);
31973 + if (au_nhash_test_name(str, name, nlen))
31979 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31980 + unsigned char d_type)
31982 +#ifdef CONFIG_AUFS_SHWH
31983 + wh->wh_ino = ino;
31984 + wh->wh_type = d_type;
31988 +/* ---------------------------------------------------------------------- */
31990 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31991 + unsigned int d_type, aufs_bindex_t bindex,
31992 + unsigned char shwh)
31995 + struct au_vdir_destr *str;
31996 + struct au_vdir_wh *wh;
31998 + AuDbg("%.*s\n", nlen, name);
31999 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32002 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32003 + if (unlikely(!wh))
32007 + wh->wh_bindex = bindex;
32009 + au_shwh_init_wh(wh, ino, d_type);
32010 + str = &wh->wh_str;
32012 + memcpy(str->name, name, nlen);
32013 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32020 +static int append_deblk(struct au_vdir *vdir)
32023 + unsigned long ul;
32024 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32025 + union au_vdir_deblk_p p, deblk_end;
32026 + unsigned char **o;
32029 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32030 + GFP_NOFS, /*may_shrink*/0);
32031 + if (unlikely(!o))
32034 + vdir->vd_deblk = o;
32035 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32037 + ul = vdir->vd_nblk++;
32038 + vdir->vd_deblk[ul] = p.deblk;
32039 + vdir->vd_last.ul = ul;
32040 + vdir->vd_last.p.deblk = p.deblk;
32041 + deblk_end.deblk = p.deblk + deblk_sz;
32042 + err = set_deblk_end(&p, &deblk_end);
32049 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32050 + unsigned int d_type, struct au_nhash *delist)
32054 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32055 + union au_vdir_deblk_p p, *room, deblk_end;
32056 + struct au_vdir_dehstr *dehstr;
32058 + p.deblk = last_deblk(vdir);
32059 + deblk_end.deblk = p.deblk + deblk_sz;
32060 + room = &vdir->vd_last.p;
32061 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32062 + || !is_deblk_end(room, &deblk_end));
32064 + sz = calc_size(nlen);
32065 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32066 + err = append_deblk(vdir);
32067 + if (unlikely(err))
32070 + p.deblk = last_deblk(vdir);
32071 + deblk_end.deblk = p.deblk + deblk_sz;
32073 + AuDebugOn(room->deblk != p.deblk);
32077 + dehstr = au_cache_alloc_vdir_dehstr();
32078 + if (unlikely(!dehstr))
32081 + dehstr->str = &room->de->de_str;
32082 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32083 + room->de->de_ino = ino;
32084 + room->de->de_type = d_type;
32085 + room->de->de_str.len = nlen;
32086 + memcpy(room->de->de_str.name, name, nlen);
32089 + room->deblk += sz;
32090 + if (unlikely(set_deblk_end(room, &deblk_end)))
32091 + err = append_deblk(vdir);
32098 +/* ---------------------------------------------------------------------- */
32100 +void au_vdir_free(struct au_vdir *vdir)
32102 + unsigned char **deblk;
32104 + deblk = vdir->vd_deblk;
32105 + while (vdir->vd_nblk--)
32106 + au_kfree_try_rcu(*deblk++);
32107 + au_kfree_try_rcu(vdir->vd_deblk);
32108 + au_cache_free_vdir(vdir);
32111 +static struct au_vdir *alloc_vdir(struct file *file)
32113 + struct au_vdir *vdir;
32114 + struct super_block *sb;
32117 + sb = file->f_path.dentry->d_sb;
32118 + SiMustAnyLock(sb);
32121 + vdir = au_cache_alloc_vdir();
32122 + if (unlikely(!vdir))
32125 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32126 + if (unlikely(!vdir->vd_deblk))
32129 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32130 + if (!vdir->vd_deblk_sz) {
32131 + /* estimate the appropriate size for deblk */
32132 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32133 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32135 + vdir->vd_nblk = 0;
32136 + vdir->vd_version = 0;
32137 + vdir->vd_jiffy = 0;
32138 + err = append_deblk(vdir);
32140 + return vdir; /* success */
32142 + au_kfree_try_rcu(vdir->vd_deblk);
32145 + au_cache_free_vdir(vdir);
32147 + vdir = ERR_PTR(err);
32151 +static int reinit_vdir(struct au_vdir *vdir)
32154 + union au_vdir_deblk_p p, deblk_end;
32156 + while (vdir->vd_nblk > 1) {
32157 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32158 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32161 + p.deblk = vdir->vd_deblk[0];
32162 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32163 + err = set_deblk_end(&p, &deblk_end);
32164 + /* keep vd_dblk_sz */
32165 + vdir->vd_last.ul = 0;
32166 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32167 + vdir->vd_version = 0;
32168 + vdir->vd_jiffy = 0;
32173 +/* ---------------------------------------------------------------------- */
32175 +#define AuFillVdir_CALLED 1
32176 +#define AuFillVdir_WHABLE (1 << 1)
32177 +#define AuFillVdir_SHWH (1 << 2)
32178 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32179 +#define au_fset_fillvdir(flags, name) \
32180 + do { (flags) |= AuFillVdir_##name; } while (0)
32181 +#define au_fclr_fillvdir(flags, name) \
32182 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32184 +#ifndef CONFIG_AUFS_SHWH
32185 +#undef AuFillVdir_SHWH
32186 +#define AuFillVdir_SHWH 0
32189 +struct fillvdir_arg {
32190 + struct dir_context ctx;
32191 + struct file *file;
32192 + struct au_vdir *vdir;
32193 + struct au_nhash delist;
32194 + struct au_nhash whlist;
32195 + aufs_bindex_t bindex;
32196 + unsigned int flags;
32200 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32201 + loff_t offset __maybe_unused, u64 h_ino,
32202 + unsigned int d_type)
32204 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32205 + char *name = (void *)__name;
32206 + struct super_block *sb;
32208 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32211 + sb = arg->file->f_path.dentry->d_sb;
32212 + au_fset_fillvdir(arg->flags, CALLED);
32214 + if (nlen <= AUFS_WH_PFX_LEN
32215 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32216 + if (test_known(&arg->delist, name, nlen)
32217 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32218 + goto out; /* already exists or whiteouted */
32220 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32222 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32223 + d_type = DT_UNKNOWN;
32224 + arg->err = append_de(arg->vdir, name, nlen, ino,
32225 + d_type, &arg->delist);
32227 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32228 + name += AUFS_WH_PFX_LEN;
32229 + nlen -= AUFS_WH_PFX_LEN;
32230 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32231 + goto out; /* already whiteouted */
32233 + ino = 0; /* just to suppress a warning */
32235 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32238 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32239 + d_type = DT_UNKNOWN;
32240 + arg->err = au_nhash_append_wh
32241 + (&arg->whlist, name, nlen, ino, d_type,
32242 + arg->bindex, shwh);
32248 + arg->vdir->vd_jiffy = jiffies;
32250 + AuTraceErr(arg->err);
32254 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32255 + struct au_nhash *whlist, struct au_nhash *delist)
32257 +#ifdef CONFIG_AUFS_SHWH
32259 + unsigned int nh, u;
32260 + struct hlist_head *head;
32261 + struct au_vdir_wh *pos;
32262 + struct hlist_node *n;
32264 + struct au_vdir_destr *destr;
32266 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32269 + o = p = (void *)__get_free_page(GFP_NOFS);
32270 + if (unlikely(!p))
32274 + nh = whlist->nh_num;
32275 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32276 + p += AUFS_WH_PFX_LEN;
32277 + for (u = 0; u < nh; u++) {
32278 + head = whlist->nh_head + u;
32279 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32280 + destr = &pos->wh_str;
32281 + memcpy(p, destr->name, destr->len);
32282 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32283 + pos->wh_ino, pos->wh_type, delist);
32284 + if (unlikely(err))
32289 + free_page((unsigned long)o);
32299 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32302 + unsigned int rdhash;
32304 + aufs_bindex_t bbot, bindex, btop;
32305 + unsigned char shwh;
32306 + struct file *hf, *file;
32307 + struct super_block *sb;
32309 + file = arg->file;
32310 + sb = file->f_path.dentry->d_sb;
32311 + SiMustAnyLock(sb);
32313 + rdhash = au_sbi(sb)->si_rdhash;
32315 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32316 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32317 + if (unlikely(err))
32319 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32320 + if (unlikely(err))
32326 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32328 + au_fset_fillvdir(arg->flags, SHWH);
32330 + btop = au_fbtop(file);
32331 + bbot = au_fbbot_dir(file);
32332 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32333 + hf = au_hf_dir(file, bindex);
32337 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32339 + if (unlikely(offset))
32342 + arg->bindex = bindex;
32343 + au_fclr_fillvdir(arg->flags, WHABLE);
32345 + || (bindex != bbot
32346 + && au_br_whable(au_sbr_perm(sb, bindex))))
32347 + au_fset_fillvdir(arg->flags, WHABLE);
32350 + au_fclr_fillvdir(arg->flags, CALLED);
32352 + err = vfsub_iterate_dir(hf, &arg->ctx);
32355 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32358 + * dir_relax() may be good for concurrency, but aufs should not
32359 + * use it since it will cause a lockdep problem.
32363 + if (!err && shwh)
32364 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32366 + au_nhash_wh_free(&arg->whlist);
32369 + au_nhash_de_free(&arg->delist);
32374 +static int read_vdir(struct file *file, int may_read)
32377 + unsigned long expire;
32378 + unsigned char do_read;
32379 + struct fillvdir_arg arg = {
32381 + .actor = fillvdir
32384 + struct inode *inode;
32385 + struct au_vdir *vdir, *allocated;
32388 + inode = file_inode(file);
32389 + IMustLock(inode);
32390 + IiMustWriteLock(inode);
32391 + SiMustAnyLock(inode->i_sb);
32393 + allocated = NULL;
32395 + expire = au_sbi(inode->i_sb)->si_rdcache;
32396 + vdir = au_ivdir(inode);
32399 + vdir = alloc_vdir(file);
32400 + err = PTR_ERR(vdir);
32401 + if (IS_ERR(vdir))
32404 + allocated = vdir;
32405 + } else if (may_read
32406 + && (!inode_eq_iversion(inode, vdir->vd_version)
32407 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32409 + err = reinit_vdir(vdir);
32410 + if (unlikely(err))
32415 + return 0; /* success */
32419 + err = au_do_read_vdir(&arg);
32421 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32422 + vdir->vd_version = inode_query_iversion(inode);
32423 + vdir->vd_last.ul = 0;
32424 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32426 + au_set_ivdir(inode, allocated);
32427 + } else if (allocated)
32428 + au_vdir_free(allocated);
32434 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32437 + unsigned long ul, n;
32438 + const unsigned int deblk_sz = src->vd_deblk_sz;
32440 + AuDebugOn(tgt->vd_nblk != 1);
32443 + if (tgt->vd_nblk < src->vd_nblk) {
32444 + unsigned char **p;
32446 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32447 + GFP_NOFS, /*may_shrink*/0);
32448 + if (unlikely(!p))
32450 + tgt->vd_deblk = p;
32453 + if (tgt->vd_deblk_sz != deblk_sz) {
32454 + unsigned char *p;
32456 + tgt->vd_deblk_sz = deblk_sz;
32457 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32458 + /*may_shrink*/1);
32459 + if (unlikely(!p))
32461 + tgt->vd_deblk[0] = p;
32463 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32464 + tgt->vd_version = src->vd_version;
32465 + tgt->vd_jiffy = src->vd_jiffy;
32467 + n = src->vd_nblk;
32468 + for (ul = 1; ul < n; ul++) {
32469 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32471 + if (unlikely(!tgt->vd_deblk[ul]))
32475 + tgt->vd_nblk = n;
32476 + tgt->vd_last.ul = tgt->vd_last.ul;
32477 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32478 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32479 + - src->vd_deblk[src->vd_last.ul];
32481 + return 0; /* success */
32484 + rerr = reinit_vdir(tgt);
32489 +int au_vdir_init(struct file *file)
32492 + struct inode *inode;
32493 + struct au_vdir *vdir_cache, *allocated;
32495 + /* test file->f_pos here instead of ctx->pos */
32496 + err = read_vdir(file, !file->f_pos);
32497 + if (unlikely(err))
32500 + allocated = NULL;
32501 + vdir_cache = au_fvdir_cache(file);
32502 + if (!vdir_cache) {
32503 + vdir_cache = alloc_vdir(file);
32504 + err = PTR_ERR(vdir_cache);
32505 + if (IS_ERR(vdir_cache))
32507 + allocated = vdir_cache;
32508 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32509 + /* test file->f_pos here instead of ctx->pos */
32510 + err = reinit_vdir(vdir_cache);
32511 + if (unlikely(err))
32514 + return 0; /* success */
32516 + inode = file_inode(file);
32517 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32519 + file->f_version = inode_query_iversion(inode);
32521 + au_set_fvdir_cache(file, allocated);
32522 + } else if (allocated)
32523 + au_vdir_free(allocated);
32529 +static loff_t calc_offset(struct au_vdir *vdir)
32532 + union au_vdir_deblk_p p;
32534 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32535 + offset = vdir->vd_last.p.deblk - p.deblk;
32536 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32540 +/* returns true or false */
32541 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32544 + unsigned int deblk_sz;
32545 + unsigned long ul, n;
32547 + union au_vdir_deblk_p p, deblk_end;
32548 + struct au_vdir *vdir_cache;
32551 + vdir_cache = au_fvdir_cache(file);
32552 + offset = calc_offset(vdir_cache);
32553 + AuDbg("offset %lld\n", offset);
32554 + if (ctx->pos == offset)
32557 + vdir_cache->vd_last.ul = 0;
32558 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32563 + deblk_sz = vdir_cache->vd_deblk_sz;
32564 + ul = div64_u64(ctx->pos, deblk_sz);
32565 + AuDbg("ul %lu\n", ul);
32566 + if (ul >= vdir_cache->vd_nblk)
32569 + n = vdir_cache->vd_nblk;
32570 + for (; ul < n; ul++) {
32571 + p.deblk = vdir_cache->vd_deblk[ul];
32572 + deblk_end.deblk = p.deblk + deblk_sz;
32574 + offset *= deblk_sz;
32575 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32578 + l = calc_size(p.de->de_str.len);
32582 + if (!is_deblk_end(&p, &deblk_end)) {
32584 + vdir_cache->vd_last.ul = ul;
32585 + vdir_cache->vd_last.p = p;
32593 + AuDbg("valid %d\n", !valid);
32597 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32599 + unsigned int l, deblk_sz;
32600 + union au_vdir_deblk_p deblk_end;
32601 + struct au_vdir *vdir_cache;
32602 + struct au_vdir_de *de;
32604 + if (!seek_vdir(file, ctx))
32607 + vdir_cache = au_fvdir_cache(file);
32608 + deblk_sz = vdir_cache->vd_deblk_sz;
32610 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32611 + deblk_end.deblk += deblk_sz;
32612 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32613 + de = vdir_cache->vd_last.p.de;
32614 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32615 + de->de_str.len, de->de_str.name, ctx->pos,
32616 + (unsigned long)de->de_ino, de->de_type);
32617 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32618 + de->de_str.len, de->de_ino,
32620 + /* todo: ignore the error caused by udba? */
32621 + /* return err; */
32625 + l = calc_size(de->de_str.len);
32626 + vdir_cache->vd_last.p.deblk += l;
32629 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32630 + vdir_cache->vd_last.ul++;
32631 + vdir_cache->vd_last.p.deblk
32632 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32633 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32642 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32643 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32644 +++ linux/fs/aufs/vfsub.c 2021-11-25 11:42:28.836641524 +0100
32646 +// SPDX-License-Identifier: GPL-2.0
32648 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32650 + * This program, aufs is free software; you can redistribute it and/or modify
32651 + * it under the terms of the GNU General Public License as published by
32652 + * the Free Software Foundation; either version 2 of the License, or
32653 + * (at your option) any later version.
32655 + * This program is distributed in the hope that it will be useful,
32656 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32657 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32658 + * GNU General Public License for more details.
32660 + * You should have received a copy of the GNU General Public License
32661 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32665 + * sub-routines for VFS
32668 +#include <linux/mnt_namespace.h>
32669 +#include <linux/namei.h>
32670 +#include <linux/nsproxy.h>
32671 +#include <linux/security.h>
32672 +#include <linux/splice.h>
32675 +#ifdef CONFIG_AUFS_BR_FUSE
32676 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32678 + if (!au_test_fuse(h_sb) || !au_userns)
32681 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32685 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32690 + down_read(&h_sb->s_umount);
32691 + err = __sync_filesystem(h_sb, wait);
32692 + up_read(&h_sb->s_umount);
32698 +/* ---------------------------------------------------------------------- */
32700 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32704 + struct super_block *h_sb;
32707 + * Always needs h_path->mnt for LSM or FUSE branch.
32709 + AuDebugOn(!h_path->mnt);
32711 + /* for remote fs, leave work for its getattr or d_revalidate */
32712 + /* for bad i_attr fs, handle them in aufs_getattr() */
32713 + /* still some fs may acquire i_mutex. we need to skip them */
32717 + h_sb = h_path->dentry->d_sb;
32718 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32720 + err = vfsub_getattr(h_path, &st);
32725 +/* ---------------------------------------------------------------------- */
32727 +struct file *vfsub_dentry_open(struct path *path, int flags)
32729 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32733 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32735 + struct file *file;
32738 + file = filp_open(path,
32739 + oflags /* | __FMODE_NONOTIFY */,
32742 + if (IS_ERR(file))
32744 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32751 + * Ideally this function should call VFS:do_last() in order to keep all its
32752 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32753 + * structure such as nameidata. This is a second (or third) best approach.
32754 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32756 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32757 + struct vfsub_aopen_args *args)
32760 + struct au_branch *br = args->br;
32761 + struct file *file = args->file;
32762 + /* copied from linux/fs/namei.c:atomic_open() */
32763 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32766 + AuDebugOn(!dir->i_op->atomic_open);
32768 + err = au_br_test_oflag(args->open_flag, br);
32769 + if (unlikely(err))
32772 + au_lcnt_inc(&br->br_nfiles);
32773 + file->f_path.dentry = DENTRY_NOT_SET;
32774 + file->f_path.mnt = au_br_mnt(br);
32775 + AuDbg("%ps\n", dir->i_op->atomic_open);
32776 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32777 + args->create_mode);
32778 + if (unlikely(err < 0)) {
32779 + au_lcnt_dec(&br->br_nfiles);
32783 + /* temporary workaround for nfsv4 branch */
32784 + if (au_test_nfs(dir->i_sb))
32785 + nfs_mark_for_revalidate(dir);
32787 + if (file->f_mode & FMODE_CREATED)
32788 + fsnotify_create(dir, dentry);
32789 + if (!(file->f_mode & FMODE_OPENED)) {
32790 + au_lcnt_dec(&br->br_nfiles);
32794 + /* todo: call VFS:may_open() here */
32795 + /* todo: ima_file_check() too? */
32796 + if (!err && (args->open_flag & __FMODE_EXEC))
32797 + err = deny_write_access(file);
32799 + fsnotify_open(file);
32801 + au_lcnt_dec(&br->br_nfiles);
32802 + /* note that the file is created and still opened */
32808 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32812 + err = kern_path(name, flags, path);
32813 + if (!err && d_is_positive(path->dentry))
32814 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32818 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32819 + struct path *ppath, int len)
32821 + struct path path;
32823 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
32824 + if (IS_ERR(path.dentry))
32826 + if (d_is_positive(path.dentry)) {
32827 + path.mnt = ppath->mnt;
32828 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32832 + AuTraceErrPtr(path.dentry);
32833 + return path.dentry;
32836 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
32839 + struct path path;
32841 + /* VFS checks it too, but by WARN_ON_ONCE() */
32842 + IMustLock(d_inode(ppath->dentry));
32844 + path.dentry = lookup_one_len(name, ppath->dentry, len);
32845 + if (IS_ERR(path.dentry))
32847 + if (d_is_positive(path.dentry)) {
32848 + path.mnt = ppath->mnt;
32849 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32853 + AuTraceErrPtr(path.dentry);
32854 + return path.dentry;
32857 +void vfsub_call_lkup_one(void *args)
32859 + struct vfsub_lkup_one_args *a = args;
32860 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
32863 +/* ---------------------------------------------------------------------- */
32865 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32866 + struct dentry *d2, struct au_hinode *hdir2)
32868 + struct dentry *d;
32871 + d = lock_rename(d1, d2);
32873 + au_hn_suspend(hdir1);
32874 + if (hdir1 != hdir2)
32875 + au_hn_suspend(hdir2);
32880 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32881 + struct dentry *d2, struct au_hinode *hdir2)
32883 + au_hn_resume(hdir1);
32884 + if (hdir1 != hdir2)
32885 + au_hn_resume(hdir2);
32887 + unlock_rename(d1, d2);
32891 +/* ---------------------------------------------------------------------- */
32893 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32896 + struct dentry *d;
32897 + struct user_namespace *userns;
32901 + d = path->dentry;
32902 + path->dentry = d->d_parent;
32903 + err = security_path_mknod(path, d, mode, 0);
32904 + path->dentry = d;
32905 + if (unlikely(err))
32907 + userns = mnt_user_ns(path->mnt);
32910 + err = vfs_create(userns, dir, path->dentry, mode, want_excl);
32913 + struct path tmp = *path;
32916 + vfsub_update_h_iattr(&tmp, &did);
32918 + tmp.dentry = path->dentry->d_parent;
32919 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32928 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32931 + struct dentry *d;
32932 + struct user_namespace *userns;
32936 + d = path->dentry;
32937 + path->dentry = d->d_parent;
32938 + err = security_path_symlink(path, d, symname);
32939 + path->dentry = d;
32940 + if (unlikely(err))
32942 + userns = mnt_user_ns(path->mnt);
32945 + err = vfs_symlink(userns, dir, path->dentry, symname);
32948 + struct path tmp = *path;
32951 + vfsub_update_h_iattr(&tmp, &did);
32953 + tmp.dentry = path->dentry->d_parent;
32954 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32963 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32966 + struct dentry *d;
32967 + struct user_namespace *userns;
32971 + d = path->dentry;
32972 + path->dentry = d->d_parent;
32973 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32974 + path->dentry = d;
32975 + if (unlikely(err))
32977 + userns = mnt_user_ns(path->mnt);
32980 + err = vfs_mknod(userns, dir, path->dentry, mode, dev);
32983 + struct path tmp = *path;
32986 + vfsub_update_h_iattr(&tmp, &did);
32988 + tmp.dentry = path->dentry->d_parent;
32989 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32998 +static int au_test_nlink(struct inode *inode)
33000 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33002 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33003 + || inode->i_nlink < link_max)
33008 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33009 + struct inode **delegated_inode)
33012 + struct dentry *d;
33013 + struct user_namespace *userns;
33017 + err = au_test_nlink(d_inode(src_dentry));
33018 + if (unlikely(err))
33021 + /* we don't call may_linkat() */
33022 + d = path->dentry;
33023 + path->dentry = d->d_parent;
33024 + err = security_path_link(src_dentry, path, d);
33025 + path->dentry = d;
33026 + if (unlikely(err))
33028 + userns = mnt_user_ns(path->mnt);
33031 + err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
33034 + struct path tmp = *path;
33037 + /* fuse has different memory inode for the same inumber */
33038 + vfsub_update_h_iattr(&tmp, &did);
33040 + tmp.dentry = path->dentry->d_parent;
33041 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33042 + tmp.dentry = src_dentry;
33043 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33052 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33053 + struct inode *dir, struct path *path,
33054 + struct inode **delegated_inode, unsigned int flags)
33057 + struct renamedata rd;
33058 + struct path tmp = {
33061 + struct dentry *d;
33064 + IMustLock(src_dir);
33066 + d = path->dentry;
33067 + path->dentry = d->d_parent;
33068 + tmp.dentry = src_dentry->d_parent;
33069 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33070 + path->dentry = d;
33071 + if (unlikely(err))
33074 + rd.old_mnt_userns = mnt_user_ns(path->mnt);
33075 + rd.old_dir = src_dir;
33076 + rd.old_dentry = src_dentry;
33077 + rd.new_mnt_userns = rd.old_mnt_userns;
33078 + rd.new_dir = dir;
33079 + rd.new_dentry = path->dentry;
33080 + rd.delegated_inode = delegated_inode;
33081 + rd.flags = flags;
33083 + err = vfs_rename(&rd);
33088 + tmp.dentry = d->d_parent;
33089 + vfsub_update_h_iattr(&tmp, &did);
33091 + tmp.dentry = src_dentry;
33092 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33093 + tmp.dentry = src_dentry->d_parent;
33094 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33103 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33106 + struct dentry *d;
33107 + struct user_namespace *userns;
33111 + d = path->dentry;
33112 + path->dentry = d->d_parent;
33113 + err = security_path_mkdir(path, d, mode);
33114 + path->dentry = d;
33115 + if (unlikely(err))
33117 + userns = mnt_user_ns(path->mnt);
33120 + err = vfs_mkdir(userns, dir, path->dentry, mode);
33123 + struct path tmp = *path;
33126 + vfsub_update_h_iattr(&tmp, &did);
33128 + tmp.dentry = path->dentry->d_parent;
33129 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33138 +int vfsub_rmdir(struct inode *dir, struct path *path)
33141 + struct dentry *d;
33142 + struct user_namespace *userns;
33146 + d = path->dentry;
33147 + path->dentry = d->d_parent;
33148 + err = security_path_rmdir(path, d);
33149 + path->dentry = d;
33150 + if (unlikely(err))
33152 + userns = mnt_user_ns(path->mnt);
33155 + err = vfs_rmdir(userns, dir, path->dentry);
33158 + struct path tmp = {
33159 + .dentry = path->dentry->d_parent,
33163 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33170 +/* ---------------------------------------------------------------------- */
33172 +/* todo: support mmap_sem? */
33173 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33179 + err = vfs_read(file, ubuf, count, ppos);
33182 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33186 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33192 + err = kernel_read(file, kbuf, count, ppos);
33196 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33200 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33206 + err = vfs_write(file, ubuf, count, ppos);
33209 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33213 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33218 + err = kernel_write(file, kbuf, count, ppos);
33221 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33225 +int vfsub_flush(struct file *file, fl_owner_t id)
33230 + if (file->f_op->flush) {
33231 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33232 + err = file->f_op->flush(file, id);
33235 + err = file->f_op->flush(file, id);
33239 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33245 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33249 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33252 + err = iterate_dir(file, ctx);
33255 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33260 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33261 + struct pipe_inode_info *pipe, size_t len,
33262 + unsigned int flags)
33267 + err = do_splice_to(in, ppos, pipe, len, flags);
33269 + file_accessed(in);
33271 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33275 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33276 + loff_t *ppos, size_t len, unsigned int flags)
33281 + err = do_splice_from(pipe, out, ppos, len, flags);
33284 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33288 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33292 + /* file can be NULL */
33294 + err = vfs_fsync(file, datasync);
33298 + AuDebugOn(!file);
33299 + path = &file->f_path;
33301 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33306 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33307 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33308 + struct file *h_file)
33311 + struct inode *h_inode;
33312 + struct super_block *h_sb;
33313 + struct user_namespace *h_userns;
33316 + err = vfsub_truncate(h_path, length);
33320 + h_inode = d_inode(h_path->dentry);
33321 + h_sb = h_inode->i_sb;
33323 + sb_start_write(h_sb);
33325 + err = security_path_truncate(h_path);
33327 + h_userns = mnt_user_ns(h_path->mnt);
33329 + err = do_truncate(h_userns, h_path->dentry, length, attr,
33334 + sb_end_write(h_sb);
33341 +/* ---------------------------------------------------------------------- */
33343 +struct au_vfsub_mkdir_args {
33345 + struct inode *dir;
33346 + struct path *path;
33350 +static void au_call_vfsub_mkdir(void *args)
33352 + struct au_vfsub_mkdir_args *a = args;
33353 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33356 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33358 + int err, do_sio, wkq_err;
33359 + struct user_namespace *userns;
33361 + userns = mnt_user_ns(path->mnt);
33362 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33365 + err = vfsub_mkdir(dir, path, mode);
33368 + struct au_vfsub_mkdir_args args = {
33374 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33375 + if (unlikely(wkq_err))
33382 +struct au_vfsub_rmdir_args {
33384 + struct inode *dir;
33385 + struct path *path;
33388 +static void au_call_vfsub_rmdir(void *args)
33390 + struct au_vfsub_rmdir_args *a = args;
33391 + *a->errp = vfsub_rmdir(a->dir, a->path);
33394 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33396 + int err, do_sio, wkq_err;
33397 + struct user_namespace *userns;
33399 + userns = mnt_user_ns(path->mnt);
33400 + do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
33403 + err = vfsub_rmdir(dir, path);
33406 + struct au_vfsub_rmdir_args args = {
33411 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33412 + if (unlikely(wkq_err))
33419 +/* ---------------------------------------------------------------------- */
33421 +struct notify_change_args {
33423 + struct path *path;
33424 + struct iattr *ia;
33425 + struct inode **delegated_inode;
33428 +static void call_notify_change(void *args)
33430 + struct notify_change_args *a = args;
33431 + struct inode *h_inode;
33432 + struct user_namespace *userns;
33434 + h_inode = d_inode(a->path->dentry);
33435 + IMustLock(h_inode);
33437 + *a->errp = -EPERM;
33438 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33439 + userns = mnt_user_ns(a->path->mnt);
33441 + *a->errp = notify_change(userns, a->path->dentry, a->ia,
33442 + a->delegated_inode);
33445 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33447 + AuTraceErr(*a->errp);
33450 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33451 + struct inode **delegated_inode)
33454 + struct notify_change_args args = {
33458 + .delegated_inode = delegated_inode
33461 + call_notify_change(&args);
33466 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33467 + struct inode **delegated_inode)
33469 + int err, wkq_err;
33470 + struct notify_change_args args = {
33474 + .delegated_inode = delegated_inode
33477 + wkq_err = au_wkq_wait(call_notify_change, &args);
33478 + if (unlikely(wkq_err))
33484 +/* ---------------------------------------------------------------------- */
33486 +struct unlink_args {
33488 + struct inode *dir;
33489 + struct path *path;
33490 + struct inode **delegated_inode;
33493 +static void call_unlink(void *args)
33495 + struct unlink_args *a = args;
33496 + struct dentry *d = a->path->dentry;
33497 + struct inode *h_inode;
33498 + struct user_namespace *userns;
33499 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33500 + && au_dcount(d) == 1);
33502 + IMustLock(a->dir);
33504 + a->path->dentry = d->d_parent;
33505 + *a->errp = security_path_unlink(a->path, d);
33506 + a->path->dentry = d;
33507 + if (unlikely(*a->errp))
33510 + if (!stop_sillyrename)
33513 + if (d_is_positive(d)) {
33514 + h_inode = d_inode(d);
33518 + userns = mnt_user_ns(a->path->mnt);
33520 + *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
33523 + struct path tmp = {
33524 + .dentry = d->d_parent,
33525 + .mnt = a->path->mnt
33527 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33530 + if (!stop_sillyrename)
33535 + AuTraceErr(*a->errp);
33539 + * @dir: must be locked.
33540 + * @dentry: target dentry.
33542 +int vfsub_unlink(struct inode *dir, struct path *path,
33543 + struct inode **delegated_inode, int force)
33546 + struct unlink_args args = {
33550 + .delegated_inode = delegated_inode
33554 + call_unlink(&args);
33558 + wkq_err = au_wkq_wait(call_unlink, &args);
33559 + if (unlikely(wkq_err))
33565 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33566 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33567 +++ linux/fs/aufs/vfsub.h 2021-11-25 11:42:28.836641524 +0100
33569 +/* SPDX-License-Identifier: GPL-2.0 */
33571 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33573 + * This program, aufs is free software; you can redistribute it and/or modify
33574 + * it under the terms of the GNU General Public License as published by
33575 + * the Free Software Foundation; either version 2 of the License, or
33576 + * (at your option) any later version.
33578 + * This program is distributed in the hope that it will be useful,
33579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33581 + * GNU General Public License for more details.
33583 + * You should have received a copy of the GNU General Public License
33584 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33588 + * sub-routines for VFS
33591 +#ifndef __AUFS_VFSUB_H__
33592 +#define __AUFS_VFSUB_H__
33596 +#include <linux/fs.h>
33597 +#include <linux/mount.h>
33598 +#include <linux/posix_acl.h>
33599 +#include <linux/xattr.h>
33600 +#include "debug.h"
33602 +/* copied from linux/fs/internal.h */
33603 +/* todo: BAD approach!! */
33604 +extern void __mnt_drop_write(struct vfsmount *);
33605 +extern struct file *alloc_empty_file(int, const struct cred *);
33607 +/* ---------------------------------------------------------------------- */
33609 +/* lock subclass for lower inode */
33610 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33611 +/* reduce? gave up. */
33613 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33614 + AuLsc_I_PARENT, /* lower inode, parent first */
33615 + AuLsc_I_PARENT2, /* copyup dirs */
33616 + AuLsc_I_PARENT3, /* copyup wh */
33622 +/* to debug easier, do not make them inlined functions */
33623 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33624 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33626 +/* ---------------------------------------------------------------------- */
33628 +static inline void vfsub_drop_nlink(struct inode *inode)
33630 + AuDebugOn(!inode->i_nlink);
33631 + drop_nlink(inode);
33634 +static inline void vfsub_dead_dir(struct inode *inode)
33636 + AuDebugOn(!S_ISDIR(inode->i_mode));
33637 + inode->i_flags |= S_DEAD;
33638 + clear_nlink(inode);
33641 +static inline int vfsub_native_ro(struct inode *inode)
33643 + return sb_rdonly(inode->i_sb)
33644 + || IS_RDONLY(inode)
33645 + /* || IS_APPEND(inode) */
33646 + || IS_IMMUTABLE(inode);
33649 +#ifdef CONFIG_AUFS_BR_FUSE
33650 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33652 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33655 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33657 +/* ---------------------------------------------------------------------- */
33659 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33660 +struct file *vfsub_dentry_open(struct path *path, int flags);
33661 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33663 +struct vfsub_aopen_args {
33664 + struct file *file;
33665 + unsigned int open_flag;
33666 + umode_t create_mode;
33667 + struct au_branch *br;
33669 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33670 + struct vfsub_aopen_args *args);
33671 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33673 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33674 + struct path *ppath, int len);
33675 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33678 +struct vfsub_lkup_one_args {
33679 + struct dentry **errp;
33680 + struct qstr *name;
33681 + struct path *ppath;
33684 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33685 + struct path *ppath)
33687 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33690 +void vfsub_call_lkup_one(void *args);
33692 +/* ---------------------------------------------------------------------- */
33694 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33699 + err = mnt_want_write(mnt);
33704 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33707 + mnt_drop_write(mnt);
33711 +#if 0 /* reserved */
33712 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33715 + mnt_drop_write_file(file);
33720 +/* ---------------------------------------------------------------------- */
33723 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33724 + struct dentry *d2, struct au_hinode *hdir2);
33725 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33726 + struct dentry *d2, struct au_hinode *hdir2);
33728 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33730 +int vfsub_symlink(struct inode *dir, struct path *path,
33731 + const char *symname);
33732 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33733 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33734 + struct path *path, struct inode **delegated_inode);
33735 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33736 + struct inode *hdir, struct path *path,
33737 + struct inode **delegated_inode, unsigned int flags);
33738 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33739 +int vfsub_rmdir(struct inode *dir, struct path *path);
33741 +/* ---------------------------------------------------------------------- */
33743 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33745 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33747 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33749 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33751 +int vfsub_flush(struct file *file, fl_owner_t id);
33752 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33754 +static inline loff_t vfsub_f_size_read(struct file *file)
33756 + return i_size_read(file_inode(file));
33759 +static inline unsigned int vfsub_file_flags(struct file *file)
33761 + unsigned int flags;
33763 + spin_lock(&file->f_lock);
33764 + flags = file->f_flags;
33765 + spin_unlock(&file->f_lock);
33770 +static inline int vfsub_file_execed(struct file *file)
33772 + /* todo: direct access f_flags */
33773 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33776 +#if 0 /* reserved */
33777 +static inline void vfsub_file_accessed(struct file *h_file)
33779 + file_accessed(h_file);
33780 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33784 +#if 0 /* reserved */
33785 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33786 + struct dentry *h_dentry)
33788 + struct path h_path = {
33789 + .dentry = h_dentry,
33792 + touch_atime(&h_path);
33793 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33797 +static inline int vfsub_update_time(struct inode *h_inode,
33798 + struct timespec64 *ts, int flags)
33800 + return inode_update_time(h_inode, ts, flags);
33801 + /* no vfsub_update_h_iattr() since we don't have struct path */
33804 +#ifdef CONFIG_FS_POSIX_ACL
33805 +static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
33806 + struct inode *h_inode, umode_t h_mode)
33810 + err = posix_acl_chmod(h_userns, h_inode, h_mode);
33811 + if (err == -EOPNOTSUPP)
33816 +AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
33817 + struct inode *h_inode, umode_t h_mode);
33820 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33821 + struct pipe_inode_info *pipe, size_t len,
33822 + unsigned int flags);
33823 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33824 + loff_t *ppos, size_t len, unsigned int flags);
33826 +static inline long vfsub_truncate(struct path *path, loff_t length)
33831 + err = vfs_truncate(path, length);
33836 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33837 + struct file *h_file);
33838 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33841 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33844 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33850 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33856 +/* copy_file_range(2) is a systemcall */
33857 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33858 + struct file *dst, loff_t dst_pos,
33859 + size_t len, unsigned int flags)
33864 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33870 +/* ---------------------------------------------------------------------- */
33872 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33877 + err = vfs_llseek(file, offset, origin);
33882 +/* ---------------------------------------------------------------------- */
33884 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33885 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33886 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33887 + struct inode **delegated_inode);
33888 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33889 + struct inode **delegated_inode);
33890 +int vfsub_unlink(struct inode *dir, struct path *path,
33891 + struct inode **delegated_inode, int force);
33893 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33895 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33898 +/* ---------------------------------------------------------------------- */
33900 +static inline int vfsub_setxattr(struct user_namespace *userns,
33901 + struct dentry *dentry, const char *name,
33902 + const void *value, size_t size, int flags)
33907 + err = vfs_setxattr(userns, dentry, name, value, size, flags);
33913 +static inline int vfsub_removexattr(struct user_namespace *userns,
33914 + struct dentry *dentry, const char *name)
33919 + err = vfs_removexattr(userns, dentry, name);
33925 +#endif /* __KERNEL__ */
33926 +#endif /* __AUFS_VFSUB_H__ */
33927 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33928 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33929 +++ linux/fs/aufs/wbr_policy.c 2021-11-01 23:48:34.213025928 +0100
33931 +// SPDX-License-Identifier: GPL-2.0
33933 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33935 + * This program, aufs is free software; you can redistribute it and/or modify
33936 + * it under the terms of the GNU General Public License as published by
33937 + * the Free Software Foundation; either version 2 of the License, or
33938 + * (at your option) any later version.
33940 + * This program is distributed in the hope that it will be useful,
33941 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33942 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33943 + * GNU General Public License for more details.
33945 + * You should have received a copy of the GNU General Public License
33946 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33950 + * policies for selecting one among multiple writable branches
33953 +#include <linux/statfs.h>
33956 +/* subset of cpup_attr() */
33957 +static noinline_for_stack
33958 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33962 + struct inode *h_isrc;
33964 + h_isrc = d_inode(h_src);
33965 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33966 + ia.ia_mode = h_isrc->i_mode;
33967 + ia.ia_uid = h_isrc->i_uid;
33968 + ia.ia_gid = h_isrc->i_gid;
33969 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33970 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33971 + /* no delegation since it is just created */
33972 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33974 + /* is this nfs only? */
33975 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33976 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33977 + ia.ia_mode = h_isrc->i_mode;
33978 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33984 +#define AuCpdown_PARENT_OPQ 1
33985 +#define AuCpdown_WHED (1 << 1)
33986 +#define AuCpdown_MADE_DIR (1 << 2)
33987 +#define AuCpdown_DIROPQ (1 << 3)
33988 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33989 +#define au_fset_cpdown(flags, name) \
33990 + do { (flags) |= AuCpdown_##name; } while (0)
33991 +#define au_fclr_cpdown(flags, name) \
33992 + do { (flags) &= ~AuCpdown_##name; } while (0)
33994 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33995 + unsigned int *flags)
33998 + struct dentry *opq_dentry;
34000 + opq_dentry = au_diropq_create(dentry, bdst);
34001 + err = PTR_ERR(opq_dentry);
34002 + if (IS_ERR(opq_dentry))
34004 + dput(opq_dentry);
34005 + au_fset_cpdown(*flags, DIROPQ);
34011 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34012 + struct inode *dir, aufs_bindex_t bdst)
34015 + struct path h_path;
34016 + struct au_branch *br;
34018 + br = au_sbr(dentry->d_sb, bdst);
34019 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34020 + err = PTR_ERR(h_path.dentry);
34021 + if (IS_ERR(h_path.dentry))
34025 + if (d_is_positive(h_path.dentry)) {
34026 + h_path.mnt = au_br_mnt(br);
34027 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34030 + dput(h_path.dentry);
34036 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34037 + struct au_pin *pin,
34038 + struct dentry *h_parent, void *arg)
34041 + aufs_bindex_t bopq, btop;
34042 + struct path h_path;
34043 + struct dentry *parent;
34044 + struct inode *h_dir, *h_inode, *inode, *dir;
34045 + unsigned int *flags = arg;
34047 + btop = au_dbtop(dentry);
34048 + /* dentry is di-locked */
34049 + parent = dget_parent(dentry);
34050 + dir = d_inode(parent);
34051 + h_dir = d_inode(h_parent);
34052 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34053 + IMustLock(h_dir);
34055 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34056 + if (unlikely(err < 0))
34058 + h_path.dentry = au_h_dptr(dentry, bdst);
34059 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34060 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34061 + if (unlikely(err))
34063 + au_fset_cpdown(*flags, MADE_DIR);
34065 + bopq = au_dbdiropq(dentry);
34066 + au_fclr_cpdown(*flags, WHED);
34067 + au_fclr_cpdown(*flags, DIROPQ);
34068 + if (au_dbwh(dentry) == bdst)
34069 + au_fset_cpdown(*flags, WHED);
34070 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34071 + au_fset_cpdown(*flags, PARENT_OPQ);
34072 + h_inode = d_inode(h_path.dentry);
34073 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34074 + if (au_ftest_cpdown(*flags, WHED)) {
34075 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34076 + if (unlikely(err)) {
34077 + inode_unlock(h_inode);
34082 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34083 + inode_unlock(h_inode);
34084 + if (unlikely(err))
34087 + if (au_ftest_cpdown(*flags, WHED)) {
34088 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34089 + if (unlikely(err))
34093 + inode = d_inode(dentry);
34094 + if (au_ibbot(inode) < bdst)
34095 + au_set_ibbot(inode, bdst);
34096 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34097 + au_hi_flags(inode, /*isdir*/1));
34098 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34099 + goto out; /* success */
34103 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34104 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34105 + rerr = au_diropq_remove(dentry, bdst);
34106 + inode_unlock(h_inode);
34107 + if (unlikely(rerr)) {
34108 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34109 + dentry, bdst, rerr);
34115 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34116 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34117 + if (unlikely(rerr)) {
34118 + AuIOErr("failed removing %pd b%d (%d)\n",
34119 + dentry, bdst, rerr);
34124 + au_set_h_dptr(dentry, bdst, NULL);
34125 + if (au_dbbot(dentry) == bdst)
34126 + au_update_dbbot(dentry);
34132 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34135 + unsigned int flags;
34138 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34143 +/* ---------------------------------------------------------------------- */
34145 +/* policies for create */
34147 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34149 + int err, i, j, ndentry;
34150 + aufs_bindex_t bopq;
34151 + struct au_dcsub_pages dpages;
34152 + struct au_dpage *dpage;
34153 + struct dentry **dentries, *parent, *d;
34155 + err = au_dpages_init(&dpages, GFP_NOFS);
34156 + if (unlikely(err))
34158 + parent = dget_parent(dentry);
34159 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34160 + if (unlikely(err))
34164 + for (i = 0; i < dpages.ndpage; i++) {
34165 + dpage = dpages.dpages + i;
34166 + dentries = dpage->dentries;
34167 + ndentry = dpage->ndentry;
34168 + for (j = 0; j < ndentry; j++) {
34170 + di_read_lock_parent2(d, !AuLock_IR);
34171 + bopq = au_dbdiropq(d);
34172 + di_read_unlock(d, !AuLock_IR);
34173 + if (bopq >= 0 && bopq < err)
34180 + au_dpages_free(&dpages);
34185 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34187 + for (; bindex >= 0; bindex--)
34188 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34193 +/* top down parent */
34194 +static int au_wbr_create_tdp(struct dentry *dentry,
34195 + unsigned int flags __maybe_unused)
34198 + aufs_bindex_t btop, bindex;
34199 + struct super_block *sb;
34200 + struct dentry *parent, *h_parent;
34202 + sb = dentry->d_sb;
34203 + btop = au_dbtop(dentry);
34205 + if (!au_br_rdonly(au_sbr(sb, btop)))
34209 + parent = dget_parent(dentry);
34210 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34211 + h_parent = au_h_dptr(parent, bindex);
34212 + if (!h_parent || d_is_negative(h_parent))
34215 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34222 + /* bottom up here */
34223 + if (unlikely(err < 0)) {
34224 + err = au_wbr_bu(sb, btop - 1);
34226 + err = au_wbr_nonopq(dentry, err);
34230 + AuDbg("b%d\n", err);
34234 +/* ---------------------------------------------------------------------- */
34236 +/* an exception for the policy other than tdp */
34237 +static int au_wbr_create_exp(struct dentry *dentry)
34240 + aufs_bindex_t bwh, bdiropq;
34241 + struct dentry *parent;
34244 + bwh = au_dbwh(dentry);
34245 + parent = dget_parent(dentry);
34246 + bdiropq = au_dbdiropq(parent);
34248 + if (bdiropq >= 0)
34249 + err = min(bdiropq, bwh);
34252 + AuDbg("%d\n", err);
34253 + } else if (bdiropq >= 0) {
34255 + AuDbg("%d\n", err);
34260 + err = au_wbr_nonopq(dentry, err);
34262 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34265 + AuDbg("%d\n", err);
34269 +/* ---------------------------------------------------------------------- */
34272 +static int au_wbr_create_init_rr(struct super_block *sb)
34276 + err = au_wbr_bu(sb, au_sbbot(sb));
34277 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34280 + AuDbg("b%d\n", err);
34284 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34288 + aufs_bindex_t bindex, bbot;
34289 + struct super_block *sb;
34292 + err = au_wbr_create_exp(dentry);
34296 + sb = dentry->d_sb;
34297 + next = &au_sbi(sb)->si_wbr_rr_next;
34298 + bbot = au_sbbot(sb);
34300 + for (bindex = 0; bindex <= bbot; bindex++) {
34301 + if (!au_ftest_wbr(flags, DIR)) {
34302 + err = atomic_dec_return(next) + 1;
34303 + /* modulo for 0 is meaningless */
34304 + if (unlikely(!err))
34305 + err = atomic_dec_return(next) + 1;
34307 + err = atomic_read(next);
34308 + AuDbg("%d\n", err);
34311 + AuDbg("%d\n", err);
34312 + if (!au_br_rdonly(au_sbr(sb, err)))
34318 + err = au_wbr_nonopq(dentry, err);
34321 + AuDbg("%d\n", err);
34325 +/* ---------------------------------------------------------------------- */
34327 +/* most free space */
34328 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34330 + struct super_block *sb;
34331 + struct au_branch *br;
34332 + struct au_wbr_mfs *mfs;
34333 + struct dentry *h_parent;
34334 + aufs_bindex_t bindex, bbot;
34336 + unsigned long long b, bavail;
34337 + struct path h_path;
34338 + /* reduce the stack usage */
34339 + struct kstatfs *st;
34341 + st = kmalloc(sizeof(*st), GFP_NOFS);
34342 + if (unlikely(!st)) {
34343 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34348 + sb = dentry->d_sb;
34349 + mfs = &au_sbi(sb)->si_wbr_mfs;
34350 + MtxMustLock(&mfs->mfs_lock);
34351 + mfs->mfs_bindex = -EROFS;
34352 + mfs->mfsrr_bytes = 0;
34355 + bbot = au_sbbot(sb);
34357 + bindex = au_dbtop(parent);
34358 + bbot = au_dbtaildir(parent);
34361 + for (; bindex <= bbot; bindex++) {
34363 + h_parent = au_h_dptr(parent, bindex);
34364 + if (!h_parent || d_is_negative(h_parent))
34367 + br = au_sbr(sb, bindex);
34368 + if (au_br_rdonly(br))
34371 + /* sb->s_root for NFS is unreliable */
34372 + h_path.mnt = au_br_mnt(br);
34373 + h_path.dentry = h_path.mnt->mnt_root;
34374 + err = vfs_statfs(&h_path, st);
34375 + if (unlikely(err)) {
34376 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34380 + /* when the available size is equal, select the lower one */
34381 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34382 + || sizeof(b) < sizeof(st->f_bsize));
34383 + b = st->f_bavail * st->f_bsize;
34384 + br->br_wbr->wbr_bytes = b;
34385 + if (b >= bavail) {
34387 + mfs->mfs_bindex = bindex;
34388 + mfs->mfs_jiffy = jiffies;
34392 + mfs->mfsrr_bytes = bavail;
34393 + AuDbg("b%d\n", mfs->mfs_bindex);
34394 + au_kfree_rcu(st);
34397 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34400 + struct dentry *parent;
34401 + struct super_block *sb;
34402 + struct au_wbr_mfs *mfs;
34404 + err = au_wbr_create_exp(dentry);
34408 + sb = dentry->d_sb;
34410 + if (au_ftest_wbr(flags, PARENT))
34411 + parent = dget_parent(dentry);
34412 + mfs = &au_sbi(sb)->si_wbr_mfs;
34413 + mutex_lock(&mfs->mfs_lock);
34414 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34415 + || mfs->mfs_bindex < 0
34416 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34417 + au_mfs(dentry, parent);
34418 + mutex_unlock(&mfs->mfs_lock);
34419 + err = mfs->mfs_bindex;
34423 + err = au_wbr_nonopq(dentry, err);
34426 + AuDbg("b%d\n", err);
34430 +static int au_wbr_create_init_mfs(struct super_block *sb)
34432 + struct au_wbr_mfs *mfs;
34434 + mfs = &au_sbi(sb)->si_wbr_mfs;
34435 + mutex_init(&mfs->mfs_lock);
34436 + mfs->mfs_jiffy = 0;
34437 + mfs->mfs_bindex = -EROFS;
34442 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34444 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34448 +/* ---------------------------------------------------------------------- */
34450 +/* top down regardless parent, and then mfs */
34451 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34452 + unsigned int flags __maybe_unused)
34455 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34456 + unsigned long long watermark;
34457 + struct super_block *sb;
34458 + struct au_wbr_mfs *mfs;
34459 + struct au_branch *br;
34460 + struct dentry *parent;
34462 + sb = dentry->d_sb;
34463 + mfs = &au_sbi(sb)->si_wbr_mfs;
34464 + mutex_lock(&mfs->mfs_lock);
34465 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34466 + || mfs->mfs_bindex < 0)
34467 + au_mfs(dentry, /*parent*/NULL);
34468 + watermark = mfs->mfsrr_watermark;
34469 + bmfs = mfs->mfs_bindex;
34470 + mutex_unlock(&mfs->mfs_lock);
34472 + /* another style of au_wbr_create_exp() */
34473 + bwh = au_dbwh(dentry);
34474 + parent = dget_parent(dentry);
34475 + btail = au_dbtaildir(parent);
34476 + if (bwh >= 0 && bwh < btail)
34479 + err = au_wbr_nonopq(dentry, btail);
34480 + if (unlikely(err < 0))
34484 + for (bindex = 0; bindex <= btail; bindex++) {
34485 + br = au_sbr(sb, bindex);
34486 + if (au_br_rdonly(br))
34488 + if (br->br_wbr->wbr_bytes > watermark) {
34499 + AuDbg("b%d\n", err);
34503 +/* ---------------------------------------------------------------------- */
34505 +/* most free space and then round robin */
34506 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34509 + struct au_wbr_mfs *mfs;
34511 + err = au_wbr_create_mfs(dentry, flags);
34513 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34514 + mutex_lock(&mfs->mfs_lock);
34515 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34516 + err = au_wbr_create_rr(dentry, flags);
34517 + mutex_unlock(&mfs->mfs_lock);
34520 + AuDbg("b%d\n", err);
34524 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34528 + au_wbr_create_init_mfs(sb); /* ignore */
34529 + err = au_wbr_create_init_rr(sb);
34534 +/* ---------------------------------------------------------------------- */
34536 +/* top down parent and most free space */
34537 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34540 + unsigned long long b;
34541 + aufs_bindex_t bindex, btop, bbot;
34542 + struct super_block *sb;
34543 + struct dentry *parent, *h_parent;
34544 + struct au_branch *br;
34546 + err = au_wbr_create_tdp(dentry, flags);
34547 + if (unlikely(err < 0))
34549 + parent = dget_parent(dentry);
34550 + btop = au_dbtop(parent);
34551 + bbot = au_dbtaildir(parent);
34552 + if (btop == bbot)
34553 + goto out_parent; /* success */
34555 + e2 = au_wbr_create_mfs(dentry, flags);
34557 + goto out_parent; /* success */
34559 + /* when the available size is equal, select upper one */
34560 + sb = dentry->d_sb;
34561 + br = au_sbr(sb, err);
34562 + b = br->br_wbr->wbr_bytes;
34563 + AuDbg("b%d, %llu\n", err, b);
34565 + for (bindex = btop; bindex <= bbot; bindex++) {
34566 + h_parent = au_h_dptr(parent, bindex);
34567 + if (!h_parent || d_is_negative(h_parent))
34570 + br = au_sbr(sb, bindex);
34571 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34572 + b = br->br_wbr->wbr_bytes;
34574 + AuDbg("b%d, %llu\n", err, b);
34579 + err = au_wbr_nonopq(dentry, err);
34584 + AuDbg("b%d\n", err);
34588 +/* ---------------------------------------------------------------------- */
34591 + * - top down parent
34592 + * - most free space with parent
34593 + * - most free space round-robin regardless parent
34595 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34598 + unsigned long long watermark;
34599 + struct super_block *sb;
34600 + struct au_branch *br;
34601 + struct au_wbr_mfs *mfs;
34603 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34604 + if (unlikely(err < 0))
34607 + sb = dentry->d_sb;
34608 + br = au_sbr(sb, err);
34609 + mfs = &au_sbi(sb)->si_wbr_mfs;
34610 + mutex_lock(&mfs->mfs_lock);
34611 + watermark = mfs->mfsrr_watermark;
34612 + mutex_unlock(&mfs->mfs_lock);
34613 + if (br->br_wbr->wbr_bytes < watermark)
34614 + /* regardless the parent dir */
34615 + err = au_wbr_create_mfsrr(dentry, flags);
34618 + AuDbg("b%d\n", err);
34622 +/* ---------------------------------------------------------------------- */
34624 +/* policies for copyup */
34626 +/* top down parent */
34627 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34629 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34632 +/* bottom up parent */
34633 +static int au_wbr_copyup_bup(struct dentry *dentry)
34636 + aufs_bindex_t bindex, btop;
34637 + struct dentry *parent, *h_parent;
34638 + struct super_block *sb;
34641 + sb = dentry->d_sb;
34642 + parent = dget_parent(dentry);
34643 + btop = au_dbtop(parent);
34644 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34645 + h_parent = au_h_dptr(parent, bindex);
34646 + if (!h_parent || d_is_negative(h_parent))
34649 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34656 + /* bottom up here */
34657 + if (unlikely(err < 0))
34658 + err = au_wbr_bu(sb, btop - 1);
34660 + AuDbg("b%d\n", err);
34665 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34669 + err = au_wbr_bu(dentry->d_sb, btop);
34670 + AuDbg("b%d\n", err);
34672 + err = au_wbr_nonopq(dentry, err);
34674 + AuDbg("b%d\n", err);
34678 +static int au_wbr_copyup_bu(struct dentry *dentry)
34681 + aufs_bindex_t btop;
34683 + btop = au_dbtop(dentry);
34684 + err = au_wbr_do_copyup_bu(dentry, btop);
34688 +/* ---------------------------------------------------------------------- */
34690 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34691 + [AuWbrCopyup_TDP] = {
34692 + .copyup = au_wbr_copyup_tdp
34694 + [AuWbrCopyup_BUP] = {
34695 + .copyup = au_wbr_copyup_bup
34697 + [AuWbrCopyup_BU] = {
34698 + .copyup = au_wbr_copyup_bu
34702 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34703 + [AuWbrCreate_TDP] = {
34704 + .create = au_wbr_create_tdp
34706 + [AuWbrCreate_RR] = {
34707 + .create = au_wbr_create_rr,
34708 + .init = au_wbr_create_init_rr
34710 + [AuWbrCreate_MFS] = {
34711 + .create = au_wbr_create_mfs,
34712 + .init = au_wbr_create_init_mfs,
34713 + .fin = au_wbr_create_fin_mfs
34715 + [AuWbrCreate_MFSV] = {
34716 + .create = au_wbr_create_mfs,
34717 + .init = au_wbr_create_init_mfs,
34718 + .fin = au_wbr_create_fin_mfs
34720 + [AuWbrCreate_MFSRR] = {
34721 + .create = au_wbr_create_mfsrr,
34722 + .init = au_wbr_create_init_mfsrr,
34723 + .fin = au_wbr_create_fin_mfs
34725 + [AuWbrCreate_MFSRRV] = {
34726 + .create = au_wbr_create_mfsrr,
34727 + .init = au_wbr_create_init_mfsrr,
34728 + .fin = au_wbr_create_fin_mfs
34730 + [AuWbrCreate_TDMFS] = {
34731 + .create = au_wbr_create_tdmfs,
34732 + .init = au_wbr_create_init_mfs,
34733 + .fin = au_wbr_create_fin_mfs
34735 + [AuWbrCreate_TDMFSV] = {
34736 + .create = au_wbr_create_tdmfs,
34737 + .init = au_wbr_create_init_mfs,
34738 + .fin = au_wbr_create_fin_mfs
34740 + [AuWbrCreate_PMFS] = {
34741 + .create = au_wbr_create_pmfs,
34742 + .init = au_wbr_create_init_mfs,
34743 + .fin = au_wbr_create_fin_mfs
34745 + [AuWbrCreate_PMFSV] = {
34746 + .create = au_wbr_create_pmfs,
34747 + .init = au_wbr_create_init_mfs,
34748 + .fin = au_wbr_create_fin_mfs
34750 + [AuWbrCreate_PMFSRR] = {
34751 + .create = au_wbr_create_pmfsrr,
34752 + .init = au_wbr_create_init_mfsrr,
34753 + .fin = au_wbr_create_fin_mfs
34755 + [AuWbrCreate_PMFSRRV] = {
34756 + .create = au_wbr_create_pmfsrr,
34757 + .init = au_wbr_create_init_mfsrr,
34758 + .fin = au_wbr_create_fin_mfs
34761 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34762 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34763 +++ linux/fs/aufs/whout.c 2021-11-01 23:48:34.213025928 +0100
34765 +// SPDX-License-Identifier: GPL-2.0
34767 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34769 + * This program, aufs is free software; you can redistribute it and/or modify
34770 + * it under the terms of the GNU General Public License as published by
34771 + * the Free Software Foundation; either version 2 of the License, or
34772 + * (at your option) any later version.
34774 + * This program is distributed in the hope that it will be useful,
34775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34777 + * GNU General Public License for more details.
34779 + * You should have received a copy of the GNU General Public License
34780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34784 + * whiteout for logical deletion and opaque directory
34789 +#define WH_MASK 0444
34792 + * If a directory contains this file, then it is opaque. We start with the
34793 + * .wh. flag so that it is blocked by lookup.
34795 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34796 + sizeof(AUFS_WH_DIROPQ) - 1);
34799 + * generate whiteout name, which is NOT terminated by NULL.
34800 + * @name: original d_name.name
34801 + * @len: original d_name.len
34802 + * @wh: whiteout qstr
34803 + * returns zero when succeeds, otherwise error.
34804 + * succeeded value as wh->name should be freed by kfree().
34806 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34810 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34811 + return -ENAMETOOLONG;
34813 + wh->len = name->len + AUFS_WH_PFX_LEN;
34814 + p = kmalloc(wh->len, GFP_NOFS);
34817 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34818 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34825 +/* ---------------------------------------------------------------------- */
34828 + * test if the @wh_name exists under @h_ppath.
34829 + * @try_sio specifies the necessary of super-io.
34831 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
34832 + struct qstr *wh_name, int try_sio)
34835 + struct dentry *wh_dentry;
34838 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
34840 + wh_dentry = au_sio_lkup_one(h_userns, wh_name, h_ppath);
34841 + err = PTR_ERR(wh_dentry);
34842 + if (IS_ERR(wh_dentry)) {
34843 + if (err == -ENAMETOOLONG)
34849 + if (d_is_negative(wh_dentry))
34850 + goto out_wh; /* success */
34853 + if (d_is_reg(wh_dentry))
34854 + goto out_wh; /* success */
34857 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34858 + wh_dentry, d_inode(wh_dentry)->i_mode);
34867 + * test if the @h_path->dentry sets opaque or not.
34869 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path)
34872 + struct inode *h_dir;
34874 + h_dir = d_inode(h_path->dentry);
34875 + err = au_wh_test(h_userns, h_path, &diropq_name,
34876 + au_test_h_perm_sio(h_userns, h_dir, MAY_EXEC));
34881 + * returns a negative dentry whose name is unique and temporary.
34883 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34884 + struct qstr *prefix)
34886 + struct dentry *dentry;
34888 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34890 + /* strict atomic_t is unnecessary here */
34891 + static unsigned short cnt;
34893 + struct path h_ppath;
34894 + struct user_namespace *h_userns;
34896 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34899 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34900 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34901 + dentry = ERR_PTR(-ENAMETOOLONG);
34902 + if (unlikely(qs.len > NAME_MAX))
34904 + dentry = ERR_PTR(-ENOMEM);
34905 + name = kmalloc(qs.len + 1, GFP_NOFS);
34906 + if (unlikely(!name))
34910 + /* doubly whiteout-ed */
34911 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34912 + p = name + AUFS_WH_PFX_LEN * 2;
34913 + memcpy(p, prefix->name, prefix->len);
34914 + p += prefix->len;
34916 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34918 + h_ppath.dentry = h_parent;
34919 + h_ppath.mnt = au_br_mnt(br);
34920 + h_userns = au_br_userns(br);
34922 + for (i = 0; i < 3; i++) {
34923 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34924 + dentry = au_sio_lkup_one(h_userns, &qs, &h_ppath);
34925 + if (IS_ERR(dentry) || d_is_negative(dentry))
34929 + /* pr_warn("could not get random name\n"); */
34930 + dentry = ERR_PTR(-EEXIST);
34931 + AuDbg("%.*s\n", AuLNPair(&qs));
34935 + if (name != defname)
34936 + au_kfree_try_rcu(name);
34938 + AuTraceErrPtr(dentry);
34943 + * rename the @h_dentry on @br to the whiteouted temporary name.
34945 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34948 + struct path h_path = {
34949 + .mnt = au_br_mnt(br)
34951 + struct inode *h_dir, *delegated;
34952 + struct dentry *h_parent;
34954 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34955 + h_dir = d_inode(h_parent);
34956 + IMustLock(h_dir);
34958 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34959 + err = PTR_ERR(h_path.dentry);
34960 + if (IS_ERR(h_path.dentry))
34963 + /* under the same dir, no need to lock_rename() */
34964 + delegated = NULL;
34965 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34968 + if (unlikely(err == -EWOULDBLOCK)) {
34969 + pr_warn("cannot retry for NFSv4 delegation"
34970 + " for an internal rename\n");
34973 + dput(h_path.dentry);
34980 +/* ---------------------------------------------------------------------- */
34982 + * functions for removing a whiteout
34985 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34988 + struct inode *delegated;
34991 + * forces superio when the dir has a sticky bit.
34992 + * this may be a violation of unix fs semantics.
34994 + force = (h_dir->i_mode & S_ISVTX)
34995 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34996 + delegated = NULL;
34997 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34998 + if (unlikely(err == -EWOULDBLOCK)) {
34999 + pr_warn("cannot retry for NFSv4 delegation"
35000 + " for an internal unlink\n");
35006 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35007 + struct dentry *dentry)
35011 + err = do_unlink_wh(h_dir, h_path);
35012 + if (!err && dentry)
35013 + au_set_dbwh(dentry, -1);
35018 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35021 + struct path h_path;
35024 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35025 + if (IS_ERR(h_path.dentry))
35026 + err = PTR_ERR(h_path.dentry);
35028 + if (d_is_reg(h_path.dentry)) {
35029 + h_path.mnt = h_ppath->mnt;
35030 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35032 + dput(h_path.dentry);
35038 +/* ---------------------------------------------------------------------- */
35040 + * initialize/clean whiteout for a branch
35043 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35047 + struct inode *delegated;
35049 + if (d_is_negative(whpath->dentry))
35053 + err = vfsub_rmdir(h_dir, whpath);
35055 + delegated = NULL;
35056 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35057 + if (unlikely(err == -EWOULDBLOCK)) {
35058 + pr_warn("cannot retry for NFSv4 delegation"
35059 + " for an internal unlink\n");
35063 + if (unlikely(err))
35064 + pr_warn("failed removing %pd (%d), ignored.\n",
35065 + whpath->dentry, err);
35068 +static int test_linkable(struct dentry *h_root)
35070 + struct inode *h_dir = d_inode(h_root);
35072 + if (h_dir->i_op->link)
35075 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35076 + h_root, au_sbtype(h_root->d_sb));
35077 + return -ENOSYS; /* the branch doesn't have its ->link() */
35080 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35081 +static int au_whdir(struct inode *h_dir, struct path *path)
35086 + if (d_is_negative(path->dentry)) {
35089 + if (au_test_nfs(path->dentry->d_sb))
35091 + err = vfsub_mkdir(h_dir, path, mode);
35092 + } else if (d_is_dir(path->dentry))
35095 + pr_err("unknown %pd exists\n", path->dentry);
35100 +struct au_wh_base {
35101 + const struct qstr *name;
35102 + struct dentry *dentry;
35105 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35106 + struct path *h_path)
35108 + h_path->dentry = base[AuBrWh_BASE].dentry;
35109 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35110 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35111 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35112 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35113 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35117 + * returns tri-state,
35118 + * minus: error, caller should print the message
35120 + * plus: error, caller should NOT print the message
35122 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35123 + int do_plink, struct au_wh_base base[],
35124 + struct path *h_path)
35127 + struct inode *h_dir;
35129 + h_dir = d_inode(h_root);
35130 + h_path->dentry = base[AuBrWh_BASE].dentry;
35131 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35132 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35134 + err = test_linkable(h_root);
35135 + if (unlikely(err)) {
35140 + err = au_whdir(h_dir, h_path);
35141 + if (unlikely(err))
35143 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35145 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35146 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35147 + err = au_whdir(h_dir, h_path);
35148 + if (unlikely(err))
35150 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35157 + * for the moment, aufs supports the branch filesystem which does not support
35158 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35159 + * copyup failed. finally, such filesystem will not be used as the writable
35162 + * returns tri-state, see above.
35164 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35165 + int do_plink, struct au_wh_base base[],
35166 + struct path *h_path)
35169 + struct inode *h_dir;
35171 + WbrWhMustWriteLock(wbr);
35173 + err = test_linkable(h_root);
35174 + if (unlikely(err)) {
35180 + * todo: should this create be done in /sbin/mount.aufs helper?
35183 + h_dir = d_inode(h_root);
35184 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35185 + h_path->dentry = base[AuBrWh_BASE].dentry;
35186 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35187 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35190 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35191 + if (unlikely(err))
35194 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35196 + err = au_whdir(h_dir, h_path);
35197 + if (unlikely(err))
35199 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35201 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35202 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35204 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35205 + err = au_whdir(h_dir, h_path);
35206 + if (unlikely(err))
35208 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35215 + * initialize the whiteout base file/dir for @br.
35217 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35220 + const unsigned char do_plink
35221 + = !!au_opt_test(au_mntflags(sb), PLINK);
35222 + struct inode *h_dir;
35223 + struct path path = br->br_path;
35224 + struct dentry *h_root = path.dentry;
35225 + struct au_wbr *wbr = br->br_wbr;
35226 + static const struct qstr base_name[] = {
35227 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35228 + sizeof(AUFS_BASE_NAME) - 1),
35229 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35230 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35231 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35232 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35234 + struct au_wh_base base[] = {
35235 + [AuBrWh_BASE] = {
35236 + .name = base_name + AuBrWh_BASE,
35239 + [AuBrWh_PLINK] = {
35240 + .name = base_name + AuBrWh_PLINK,
35243 + [AuBrWh_ORPH] = {
35244 + .name = base_name + AuBrWh_ORPH,
35250 + WbrWhMustWriteLock(wbr);
35252 + for (i = 0; i < AuBrWh_Last; i++) {
35253 + /* doubly whiteouted */
35254 + struct dentry *d;
35256 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35257 + err = PTR_ERR(d);
35261 + base[i].dentry = d;
35263 + && wbr->wbr_wh[i]
35264 + && wbr->wbr_wh[i] != base[i].dentry);
35268 + for (i = 0; i < AuBrWh_Last; i++) {
35269 + dput(wbr->wbr_wh[i]);
35270 + wbr->wbr_wh[i] = NULL;
35274 + if (!au_br_writable(br->br_perm)) {
35275 + h_dir = d_inode(h_root);
35276 + au_wh_init_ro(h_dir, base, &path);
35277 + } else if (!au_br_wh_linkable(br->br_perm)) {
35278 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35284 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35290 + goto out; /* success */
35293 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35294 + err, h_root, au_sbtype(h_root->d_sb));
35296 + for (i = 0; i < AuBrWh_Last; i++)
35297 + dput(base[i].dentry);
35301 +/* ---------------------------------------------------------------------- */
35303 + * whiteouts are all hard-linked usually.
35304 + * when its link count reaches a ceiling, we create a new whiteout base
35305 + * asynchronously.
35308 +struct reinit_br_wh {
35309 + struct super_block *sb;
35310 + struct au_branch *br;
35313 +static void reinit_br_wh(void *arg)
35316 + aufs_bindex_t bindex;
35317 + struct path h_path;
35318 + struct reinit_br_wh *a = arg;
35319 + struct au_wbr *wbr;
35320 + struct inode *dir, *delegated;
35321 + struct dentry *h_root;
35322 + struct au_hinode *hdir;
35325 + wbr = a->br->br_wbr;
35326 + /* big aufs lock */
35327 + si_noflush_write_lock(a->sb);
35328 + if (!au_br_writable(a->br->br_perm))
35330 + bindex = au_br_index(a->sb, a->br->br_id);
35331 + if (unlikely(bindex < 0))
35334 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35335 + dir = d_inode(a->sb->s_root);
35336 + hdir = au_hi(dir, bindex);
35337 + h_root = au_h_dptr(a->sb->s_root, bindex);
35338 + AuDebugOn(h_root != au_br_dentry(a->br));
35340 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35341 + wbr_wh_write_lock(wbr);
35342 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35345 + h_path.dentry = wbr->wbr_whbase;
35346 + h_path.mnt = au_br_mnt(a->br);
35347 + delegated = NULL;
35348 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35350 + if (unlikely(err == -EWOULDBLOCK)) {
35351 + pr_warn("cannot retry for NFSv4 delegation"
35352 + " for an internal unlink\n");
35356 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35359 + dput(wbr->wbr_whbase);
35360 + wbr->wbr_whbase = NULL;
35362 + err = au_wh_init(a->br, a->sb);
35363 + wbr_wh_write_unlock(wbr);
35364 + au_hn_inode_unlock(hdir);
35365 + di_read_unlock(a->sb->s_root, AuLock_IR);
35367 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35371 + atomic_dec(&wbr->wbr_wh_running);
35372 + au_lcnt_dec(&a->br->br_count);
35373 + si_write_unlock(a->sb);
35374 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35376 + if (unlikely(err))
35377 + AuIOErr("err %d\n", err);
35380 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35382 + int do_dec, wkq_err;
35383 + struct reinit_br_wh *arg;
35386 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35389 + /* ignore ENOMEM */
35390 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35393 + * dec(wh_running), kfree(arg) and dec(br_count)
35394 + * in reinit function
35398 + au_lcnt_inc(&br->br_count);
35399 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35400 + if (unlikely(wkq_err)) {
35401 + atomic_dec(&br->br_wbr->wbr_wh_running);
35402 + au_lcnt_dec(&br->br_count);
35403 + au_kfree_rcu(arg);
35410 + atomic_dec(&br->br_wbr->wbr_wh_running);
35413 +/* ---------------------------------------------------------------------- */
35416 + * create the whiteout @wh.
35418 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35419 + struct dentry *wh)
35422 + struct path h_path = {
35425 + struct au_branch *br;
35426 + struct au_wbr *wbr;
35427 + struct dentry *h_parent;
35428 + struct inode *h_dir, *delegated;
35430 + h_parent = wh->d_parent; /* dir inode is locked */
35431 + h_dir = d_inode(h_parent);
35432 + IMustLock(h_dir);
35434 + br = au_sbr(sb, bindex);
35435 + h_path.mnt = au_br_mnt(br);
35436 + wbr = br->br_wbr;
35437 + wbr_wh_read_lock(wbr);
35438 + if (wbr->wbr_whbase) {
35439 + delegated = NULL;
35440 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35441 + if (unlikely(err == -EWOULDBLOCK)) {
35442 + pr_warn("cannot retry for NFSv4 delegation"
35443 + " for an internal link\n");
35446 + if (!err || err != -EMLINK)
35449 + /* link count full. re-initialize br_whbase. */
35450 + kick_reinit_br_wh(sb, br);
35453 + /* return this error in this context */
35454 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35456 + au_fhsm_wrote(sb, bindex, /*force*/0);
35459 + wbr_wh_read_unlock(wbr);
35463 +/* ---------------------------------------------------------------------- */
35466 + * create or remove the diropq.
35468 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35469 + unsigned int flags)
35471 + struct dentry *opq_dentry;
35472 + struct super_block *sb;
35473 + struct au_branch *br;
35474 + struct path h_path;
35477 + sb = dentry->d_sb;
35478 + br = au_sbr(sb, bindex);
35479 + h_path.dentry = au_h_dptr(dentry, bindex);
35480 + h_path.mnt = au_br_mnt(br);
35481 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35482 + if (IS_ERR(opq_dentry))
35485 + if (au_ftest_diropq(flags, CREATE)) {
35486 + err = link_or_create_wh(sb, bindex, opq_dentry);
35488 + au_set_dbdiropq(dentry, bindex);
35489 + goto out; /* success */
35492 + h_path.dentry = opq_dentry;
35493 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35495 + au_set_dbdiropq(dentry, -1);
35497 + dput(opq_dentry);
35498 + opq_dentry = ERR_PTR(err);
35501 + return opq_dentry;
35504 +struct do_diropq_args {
35505 + struct dentry **errp;
35506 + struct dentry *dentry;
35507 + aufs_bindex_t bindex;
35508 + unsigned int flags;
35511 +static void call_do_diropq(void *args)
35513 + struct do_diropq_args *a = args;
35514 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35517 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35518 + unsigned int flags)
35520 + struct dentry *diropq, *h_dentry;
35521 + struct user_namespace *h_userns;
35523 + h_userns = au_sbr_userns(dentry->d_sb, bindex);
35524 + h_dentry = au_h_dptr(dentry, bindex);
35525 + if (!au_test_h_perm_sio(h_userns, d_inode(h_dentry),
35526 + MAY_EXEC | MAY_WRITE))
35527 + diropq = do_diropq(dentry, bindex, flags);
35530 + struct do_diropq_args args = {
35532 + .dentry = dentry,
35533 + .bindex = bindex,
35537 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35538 + if (unlikely(wkq_err))
35539 + diropq = ERR_PTR(wkq_err);
35545 +/* ---------------------------------------------------------------------- */
35548 + * lookup whiteout dentry.
35549 + * @h_parent: lower parent dentry which must exist and be locked
35550 + * @base_name: name of dentry which will be whiteouted
35551 + * returns dentry for whiteout.
35553 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35554 + struct au_branch *br)
35557 + struct qstr wh_name;
35558 + struct dentry *wh_dentry;
35559 + struct path h_path;
35561 + err = au_wh_name_alloc(&wh_name, base_name);
35562 + wh_dentry = ERR_PTR(err);
35564 + h_path.dentry = h_parent;
35565 + h_path.mnt = au_br_mnt(br);
35566 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35567 + au_kfree_try_rcu(wh_name.name);
35569 + return wh_dentry;
35573 + * link/create a whiteout for @dentry on @bindex.
35575 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35576 + struct dentry *h_parent)
35578 + struct dentry *wh_dentry;
35579 + struct super_block *sb;
35582 + sb = dentry->d_sb;
35583 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35584 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35585 + err = link_or_create_wh(sb, bindex, wh_dentry);
35587 + au_set_dbwh(dentry, bindex);
35588 + au_fhsm_wrote(sb, bindex, /*force*/0);
35591 + wh_dentry = ERR_PTR(err);
35595 + return wh_dentry;
35598 +/* ---------------------------------------------------------------------- */
35600 +/* Delete all whiteouts in this directory on branch bindex. */
35601 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35602 + aufs_bindex_t bindex)
35605 + unsigned long ul, n;
35606 + struct qstr wh_name;
35608 + struct hlist_head *head;
35609 + struct au_vdir_wh *pos;
35610 + struct au_vdir_destr *str;
35613 + p = (void *)__get_free_page(GFP_NOFS);
35614 + wh_name.name = p;
35615 + if (unlikely(!wh_name.name))
35619 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35620 + p += AUFS_WH_PFX_LEN;
35621 + n = whlist->nh_num;
35622 + head = whlist->nh_head;
35623 + for (ul = 0; !err && ul < n; ul++, head++) {
35624 + hlist_for_each_entry(pos, head, wh_hash) {
35625 + if (pos->wh_bindex != bindex)
35628 + str = &pos->wh_str;
35629 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35630 + memcpy(p, str->name, str->len);
35631 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35632 + err = unlink_wh_name(h_path, &wh_name);
35637 + AuIOErr("whiteout name too long %.*s\n",
35638 + str->len, str->name);
35643 + free_page((unsigned long)wh_name.name);
35649 +struct del_wh_children_args {
35651 + struct path *h_path;
35652 + struct au_nhash *whlist;
35653 + aufs_bindex_t bindex;
35656 +static void call_del_wh_children(void *args)
35658 + struct del_wh_children_args *a = args;
35659 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35662 +/* ---------------------------------------------------------------------- */
35664 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35666 + struct au_whtmp_rmdir *whtmp;
35668 + unsigned int rdhash;
35670 + SiMustAnyLock(sb);
35672 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35673 + if (unlikely(!whtmp)) {
35674 + whtmp = ERR_PTR(-ENOMEM);
35678 + /* no estimation for dir size */
35679 + rdhash = au_sbi(sb)->si_rdhash;
35681 + rdhash = AUFS_RDHASH_DEF;
35682 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35683 + if (unlikely(err)) {
35684 + au_kfree_rcu(whtmp);
35685 + whtmp = ERR_PTR(err);
35692 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35695 + au_lcnt_dec(&whtmp->br->br_count);
35696 + dput(whtmp->wh_dentry);
35697 + iput(whtmp->dir);
35698 + au_nhash_wh_free(&whtmp->whlist);
35699 + au_kfree_rcu(whtmp);
35703 + * rmdir the whiteouted temporary named dir @h_dentry.
35704 + * @whlist: whiteouted children.
35706 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35707 + struct dentry *wh_dentry, struct au_nhash *whlist)
35710 + unsigned int h_nlink;
35711 + struct path wh_path;
35712 + struct inode *wh_inode, *h_dir;
35713 + struct au_branch *br;
35714 + struct user_namespace *h_userns;
35716 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35717 + IMustLock(h_dir);
35719 + br = au_sbr(dir->i_sb, bindex);
35720 + wh_path.dentry = wh_dentry;
35721 + wh_path.mnt = au_br_mnt(br);
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_path, whlist, bindex);
35734 + struct del_wh_children_args args = {
35736 + .h_path = &wh_path,
35737 + .whlist = whlist,
35741 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35742 + if (unlikely(wkq_err))
35745 + inode_unlock(wh_inode);
35748 + h_nlink = h_dir->i_nlink;
35749 + err = vfsub_rmdir(h_dir, &wh_path);
35750 + /* some fs doesn't change the parent nlink in some cases */
35751 + h_nlink -= h_dir->i_nlink;
35755 + if (au_ibtop(dir) == bindex) {
35756 + /* todo: dir->i_mutex is necessary */
35757 + au_cpup_attr_timesizes(dir);
35759 + vfsub_drop_nlink(dir);
35761 + return 0; /* success */
35764 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35768 +static void call_rmdir_whtmp(void *args)
35771 + aufs_bindex_t bindex;
35772 + struct au_whtmp_rmdir *a = args;
35773 + struct super_block *sb;
35774 + struct dentry *h_parent;
35775 + struct inode *h_dir;
35776 + struct au_hinode *hdir;
35778 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35779 + /* inode_lock(a->dir); */
35781 + sb = a->dir->i_sb;
35782 + si_read_lock(sb, !AuLock_FLUSH);
35783 + if (!au_br_writable(a->br->br_perm))
35785 + bindex = au_br_index(sb, a->br->br_id);
35786 + if (unlikely(bindex < 0))
35790 + ii_write_lock_parent(a->dir);
35791 + h_parent = dget_parent(a->wh_dentry);
35792 + h_dir = d_inode(h_parent);
35793 + hdir = au_hi(a->dir, bindex);
35794 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35795 + if (unlikely(err))
35797 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35798 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35801 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35802 + au_hn_inode_unlock(hdir);
35803 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35807 + ii_write_unlock(a->dir);
35809 + /* inode_unlock(a->dir); */
35810 + au_whtmp_rmdir_free(a);
35811 + si_read_unlock(sb);
35812 + au_nwt_done(&au_sbi(sb)->si_nowait);
35813 + if (unlikely(err))
35814 + AuIOErr("err %d\n", err);
35817 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35818 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35821 + struct super_block *sb;
35825 + /* all post-process will be done in do_rmdir_whtmp(). */
35827 + args->dir = au_igrab(dir);
35828 + args->br = au_sbr(sb, bindex);
35829 + au_lcnt_inc(&args->br->br_count);
35830 + args->wh_dentry = dget(wh_dentry);
35831 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35832 + if (unlikely(wkq_err)) {
35833 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35834 + au_whtmp_rmdir_free(args);
35837 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35838 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35839 +++ linux/fs/aufs/whout.h 2021-11-01 23:48:34.213025928 +0100
35841 +/* SPDX-License-Identifier: GPL-2.0 */
35843 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35845 + * This program, aufs is free software; you can redistribute it and/or modify
35846 + * it under the terms of the GNU General Public License as published by
35847 + * the Free Software Foundation; either version 2 of the License, or
35848 + * (at your option) any later version.
35850 + * This program is distributed in the hope that it will be useful,
35851 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35852 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35853 + * GNU General Public License for more details.
35855 + * You should have received a copy of the GNU General Public License
35856 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35860 + * whiteout for logical deletion and opaque directory
35863 +#ifndef __AUFS_WHOUT_H__
35864 +#define __AUFS_WHOUT_H__
35871 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35872 +int au_wh_test(struct user_namespace *h_userns, struct path *h_ppath,
35873 + struct qstr *wh_name, int try_sio);
35874 +int au_diropq_test(struct user_namespace *h_userns, struct path *h_path);
35876 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35877 + struct qstr *prefix);
35878 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35879 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35880 + struct dentry *dentry);
35881 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35883 +/* diropq flags */
35884 +#define AuDiropq_CREATE 1
35885 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35886 +#define au_fset_diropq(flags, name) \
35887 + do { (flags) |= AuDiropq_##name; } while (0)
35888 +#define au_fclr_diropq(flags, name) \
35889 + do { (flags) &= ~AuDiropq_##name; } while (0)
35891 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35892 + unsigned int flags);
35893 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35894 + struct au_branch *br);
35895 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35896 + struct dentry *h_parent);
35898 +/* real rmdir for the whiteout-ed dir */
35899 +struct au_whtmp_rmdir {
35900 + struct inode *dir;
35901 + struct au_branch *br;
35902 + struct dentry *wh_dentry;
35903 + struct au_nhash whlist;
35906 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35907 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35908 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35909 + struct dentry *wh_dentry, struct au_nhash *whlist);
35910 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35911 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35913 +/* ---------------------------------------------------------------------- */
35915 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35916 + aufs_bindex_t bindex)
35918 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35921 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35923 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35926 +#endif /* __KERNEL__ */
35927 +#endif /* __AUFS_WHOUT_H__ */
35928 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35929 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35930 +++ linux/fs/aufs/wkq.c 2021-11-01 23:48:34.213025928 +0100
35932 +// SPDX-License-Identifier: GPL-2.0
35934 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35936 + * This program, aufs is free software; you can redistribute it and/or modify
35937 + * it under the terms of the GNU General Public License as published by
35938 + * the Free Software Foundation; either version 2 of the License, or
35939 + * (at your option) any later version.
35941 + * This program is distributed in the hope that it will be useful,
35942 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35943 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35944 + * GNU General Public License for more details.
35946 + * You should have received a copy of the GNU General Public License
35947 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35951 + * workqueue for asynchronous/super-io operations
35952 + * todo: try new credential scheme
35955 +#include <linux/module.h>
35958 +/* internal workqueue named AUFS_WKQ_NAME */
35960 +static struct workqueue_struct *au_wkq;
35962 +struct au_wkinfo {
35963 + struct work_struct wk;
35964 + struct kobject *kobj;
35966 + unsigned int flags; /* see wkq.h */
35968 + au_wkq_func_t func;
35971 +#ifdef CONFIG_LOCKDEP
35973 + struct held_lock **hlock;
35976 + struct completion *comp;
35979 +/* ---------------------------------------------------------------------- */
35981 + * Aufs passes some operations to the workqueue such as the internal copyup.
35982 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35983 + * job run by workqueue depends upon the locks acquired in the other task.
35984 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35985 + * information too. And the job in the workqueue restores the info in order to
35986 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35987 + * correctly and expectedly.
35990 +#ifndef CONFIG_LOCKDEP
35991 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35992 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35993 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35994 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35995 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35997 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35999 + wkinfo->hlock = NULL;
36000 + wkinfo->dont_check = 0;
36007 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36009 + static DEFINE_SPINLOCK(spin);
36012 + struct lock_class_key *key;
36014 + { .name = "&sbinfo->si_rwsem" },
36015 + { .name = "&finfo->fi_rwsem" },
36016 + { .name = "&dinfo->di_rwsem" },
36017 + { .name = "&iinfo->ii_rwsem" }
36022 + /* lockless read from 'set.' see below */
36023 + if (set == ARRAY_SIZE(a)) {
36024 + for (i = 0; i < ARRAY_SIZE(a); i++)
36025 + if (a[i].key == key)
36030 + spin_lock(&spin);
36032 + for (i = 0; i < ARRAY_SIZE(a); i++)
36033 + if (a[i].key == key) {
36034 + spin_unlock(&spin);
36037 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36039 + if (unlikely(a[i].key == key)) { /* rare but possible */
36040 + spin_unlock(&spin);
36045 + if (strstr(a[i].name, name)) {
36047 + * the order of these three lines is important for the
36048 + * lockless read above.
36051 + spin_unlock(&spin);
36053 + /* AuDbg("%d, %s\n", set, name); */
36057 + spin_unlock(&spin);
36066 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36069 + struct task_struct *curr;
36070 + struct held_lock **hl, *held_locks, *p;
36074 + wkinfo->dont_check = lockdep_recursing(curr);
36075 + if (wkinfo->dont_check)
36077 + n = curr->lockdep_depth;
36082 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36083 + if (unlikely(!wkinfo->hlock))
36087 +#if 0 /* left for debugging */
36088 + if (0 && au_debug_test())
36089 + lockdep_print_held_locks(curr);
36091 + held_locks = curr->held_locks;
36092 + hl = wkinfo->hlock;
36094 + p = held_locks++;
36095 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36104 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36106 + au_kfree_try_rcu(wkinfo->hlock);
36109 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36111 + struct held_lock *p, **hl = wkinfo->hlock;
36114 + if (wkinfo->dont_check)
36118 + while ((p = *hl++)) { /* assignment */
36119 + subclass = lockdep_hlock_class(p)->subclass;
36120 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36122 + rwsem_acquire_read(p->instance, subclass, 0,
36123 + /*p->acquire_ip*/_RET_IP_);
36125 + rwsem_acquire(p->instance, subclass, 0,
36126 + /*p->acquire_ip*/_RET_IP_);
36130 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36132 + struct held_lock *p, **hl = wkinfo->hlock;
36134 + if (wkinfo->dont_check)
36138 + while ((p = *hl++)) /* assignment */
36139 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36143 +static void wkq_func(struct work_struct *wk)
36145 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36147 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36148 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36150 + au_wkq_lockdep_pre(wkinfo);
36151 + wkinfo->func(wkinfo->args);
36152 + au_wkq_lockdep_post(wkinfo);
36153 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36154 + complete(wkinfo->comp);
36156 + kobject_put(wkinfo->kobj);
36157 + module_put(THIS_MODULE); /* todo: ?? */
36158 + au_kfree_rcu(wkinfo);
36163 + * Since struct completion is large, try allocating it dynamically.
36165 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36167 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36169 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36171 + init_completion(*comp);
36172 + wkinfo->comp = *comp;
36178 +static void au_wkq_comp_free(struct completion *comp)
36180 + au_kfree_rcu(comp);
36183 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36185 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36186 + if (au_wkq_test()) {
36187 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36188 + " due to a dead dir by UDBA,"
36189 + " or async xino write?\n");
36190 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36193 + au_dbg_verify_kthread();
36195 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36196 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36197 + queue_work(au_wkq, &wkinfo->wk);
36199 + INIT_WORK(&wkinfo->wk, wkq_func);
36200 + schedule_work(&wkinfo->wk);
36205 + * Be careful. It is easy to make deadlock happen.
36206 + * processA: lock, wkq and wait
36207 + * processB: wkq and wait, lock in wkq
36210 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36213 + AuWkqCompDeclare(comp);
36214 + struct au_wkinfo wkinfo = {
36220 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36221 + if (unlikely(err))
36223 + err = au_wkq_lockdep_alloc(&wkinfo);
36224 + if (unlikely(err))
36227 + au_wkq_run(&wkinfo);
36228 + /* no timeout, no interrupt */
36229 + wait_for_completion(wkinfo.comp);
36231 + au_wkq_lockdep_free(&wkinfo);
36234 + au_wkq_comp_free(comp);
36236 + destroy_work_on_stack(&wkinfo.wk);
36241 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36242 + * problem in a concurrent umounting.
36244 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36245 + unsigned int flags)
36248 + struct au_wkinfo *wkinfo;
36250 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36253 + * wkq_func() must free this wkinfo.
36254 + * it highly depends upon the implementation of workqueue.
36257 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36259 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36260 + wkinfo->flags = flags & ~AuWkq_WAIT;
36261 + wkinfo->func = func;
36262 + wkinfo->args = args;
36263 + wkinfo->comp = NULL;
36264 + au_wkq_lockdep_init(wkinfo);
36265 + kobject_get(wkinfo->kobj);
36266 + __module_get(THIS_MODULE); /* todo: ?? */
36268 + au_wkq_run(wkinfo);
36271 + au_nwt_done(&au_sbi(sb)->si_nowait);
36277 +/* ---------------------------------------------------------------------- */
36279 +void au_nwt_init(struct au_nowait_tasks *nwt)
36281 + atomic_set(&nwt->nw_len, 0);
36282 + /* smp_mb(); */ /* atomic_set */
36283 + init_waitqueue_head(&nwt->nw_wq);
36286 +void au_wkq_fin(void)
36288 + destroy_workqueue(au_wkq);
36291 +int __init au_wkq_init(void)
36296 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36297 + if (IS_ERR(au_wkq))
36298 + err = PTR_ERR(au_wkq);
36299 + else if (!au_wkq)
36304 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36305 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36306 +++ linux/fs/aufs/wkq.h 2021-11-01 23:48:34.213025928 +0100
36308 +/* SPDX-License-Identifier: GPL-2.0 */
36310 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36312 + * This program, aufs is free software; you can redistribute it and/or modify
36313 + * it under the terms of the GNU General Public License as published by
36314 + * the Free Software Foundation; either version 2 of the License, or
36315 + * (at your option) any later version.
36317 + * This program is distributed in the hope that it will be useful,
36318 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36319 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36320 + * GNU General Public License for more details.
36322 + * You should have received a copy of the GNU General Public License
36323 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36327 + * workqueue for asynchronous/super-io operations
36328 + * todo: try new credentials management scheme
36331 +#ifndef __AUFS_WKQ_H__
36332 +#define __AUFS_WKQ_H__
36336 +#include <linux/wait.h>
36338 +struct super_block;
36340 +/* ---------------------------------------------------------------------- */
36343 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36345 +struct au_nowait_tasks {
36347 + wait_queue_head_t nw_wq;
36350 +/* ---------------------------------------------------------------------- */
36352 +typedef void (*au_wkq_func_t)(void *args);
36355 +#define AuWkq_WAIT 1
36356 +#define AuWkq_NEST (1 << 1)
36357 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36358 +#define au_fset_wkq(flags, name) \
36359 + do { (flags) |= AuWkq_##name; } while (0)
36360 +#define au_fclr_wkq(flags, name) \
36361 + do { (flags) &= ~AuWkq_##name; } while (0)
36364 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36365 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36366 + unsigned int flags);
36367 +void au_nwt_init(struct au_nowait_tasks *nwt);
36368 +int __init au_wkq_init(void);
36369 +void au_wkq_fin(void);
36371 +/* ---------------------------------------------------------------------- */
36373 +static inline int au_wkq_test(void)
36375 + return current->flags & PF_WQ_WORKER;
36378 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36380 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36383 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36385 + if (atomic_dec_and_test(&nwt->nw_len))
36386 + wake_up_all(&nwt->nw_wq);
36389 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36391 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36395 +#endif /* __KERNEL__ */
36396 +#endif /* __AUFS_WKQ_H__ */
36397 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36398 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36399 +++ linux/fs/aufs/xattr.c 2021-11-01 23:48:34.213025928 +0100
36401 +// SPDX-License-Identifier: GPL-2.0
36403 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36405 + * This program, aufs is free software; you can redistribute it and/or modify
36406 + * it under the terms of the GNU General Public License as published by
36407 + * the Free Software Foundation; either version 2 of the License, or
36408 + * (at your option) any later version.
36410 + * This program is distributed in the hope that it will be useful,
36411 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36412 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36413 + * GNU General Public License for more details.
36415 + * You should have received a copy of the GNU General Public License
36416 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36420 + * handling xattr functions
36423 +#include <linux/fs.h>
36424 +#include <linux/posix_acl_xattr.h>
36425 +#include <linux/xattr.h>
36428 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36430 + if (!ignore_flags)
36438 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36443 +#define cmp(brattr, prefix) do { \
36444 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36445 + XATTR_##prefix##_PREFIX_LEN)) { \
36446 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36452 + cmp(SEC, SECURITY);
36453 + cmp(SYS, SYSTEM);
36454 + cmp(TR, TRUSTED);
36458 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36465 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36467 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36468 + char *name, char **buf, unsigned int ignore_flags,
36469 + unsigned int verbose)
36473 + struct inode *h_idst;
36474 + struct dentry *h_dst_dentry, *h_src_dentry;
36475 + struct user_namespace *h_dst_userns, *h_src_userns;
36477 + h_src_userns = mnt_user_ns(h_src->mnt);
36478 + h_src_dentry = h_src->dentry;
36479 + ssz = vfs_getxattr_alloc(h_src_userns, h_src_dentry, name, buf, 0,
36482 + if (unlikely(err <= 0)) {
36483 + if (err == -ENODATA
36484 + || (err == -EOPNOTSUPP
36485 + && ((ignore_flags & au_xattr_out_of_list)
36486 + || (au_test_nfs_noacl(d_inode(h_src_dentry))
36487 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36489 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36492 + if (err && (verbose || au_debug_test()))
36493 + pr_err("%s, err %d\n", name, err);
36497 + /* unlock it temporary */
36498 + h_dst_userns = mnt_user_ns(h_dst->mnt);
36499 + h_dst_dentry = h_dst->dentry;
36500 + h_idst = d_inode(h_dst_dentry);
36501 + inode_unlock(h_idst);
36502 + err = vfsub_setxattr(h_dst_userns, h_dst_dentry, name, *buf, ssz,
36504 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36505 + if (unlikely(err)) {
36506 + if (verbose || au_debug_test())
36507 + pr_err("%s, err %d\n", name, err);
36508 + err = au_xattr_ignore(err, name, ignore_flags);
36515 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36516 + unsigned int verbose)
36518 + int err, unlocked, acl_access, acl_default;
36520 + struct dentry *h_dst_dentry, *h_src_dentry;
36521 + struct inode *h_isrc, *h_idst;
36522 + char *value, *p, *o, *e;
36524 + /* try stopping to update the source inode while we are referencing */
36525 + /* there should not be the parent-child relationship between them */
36526 + h_dst_dentry = h_dst->dentry;
36527 + h_idst = d_inode(h_dst_dentry);
36528 + h_src_dentry = h_src->dentry;
36529 + h_isrc = d_inode(h_src_dentry);
36530 + inode_unlock(h_idst);
36531 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36532 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36535 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36536 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36538 + if (unlikely(err < 0)) {
36540 + if (err == -ENODATA
36541 + || err == -EOPNOTSUPP)
36542 + err = 0; /* ignore */
36551 + p = kmalloc(ssz, GFP_NOFS);
36553 + if (unlikely(!p))
36555 + err = vfs_listxattr(h_src_dentry, p, ssz);
36557 + inode_unlock_shared(h_isrc);
36559 + AuDbg("err %d, ssz %zd\n", err, ssz);
36560 + if (unlikely(err < 0))
36568 + while (!err && p < e) {
36569 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36570 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36571 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36572 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36574 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36576 + p += strlen(p) + 1;
36579 + ignore_flags |= au_xattr_out_of_list;
36580 + if (!err && !acl_access) {
36581 + err = au_do_cpup_xattr(h_dst, h_src,
36582 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36583 + ignore_flags, verbose);
36586 + if (!err && !acl_default) {
36587 + err = au_do_cpup_xattr(h_dst, h_src,
36588 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36589 + ignore_flags, verbose);
36593 + au_kfree_try_rcu(value);
36596 + au_kfree_try_rcu(o);
36599 + inode_unlock_shared(h_isrc);
36604 +/* ---------------------------------------------------------------------- */
36606 +static int au_smack_reentering(struct super_block *sb)
36608 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36610 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36611 + * i_op->getxattr(). ouch.
36613 + return si_pid_test(sb);
36624 +struct au_lgxattr {
36632 + const char *name;
36639 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36640 + struct au_lgxattr *arg)
36644 + struct path h_path;
36645 + struct super_block *sb;
36647 + sb = dentry->d_sb;
36648 + reenter = au_smack_reentering(sb);
36650 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36651 + if (unlikely(err))
36654 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36655 + if (unlikely(err))
36657 + if (unlikely(!h_path.dentry))
36658 + /* illegally overlapped or something */
36659 + goto out_di; /* pretending success */
36661 + /* always topmost entry only */
36662 + switch (arg->type) {
36663 + case AU_XATTR_LIST:
36664 + err = vfs_listxattr(h_path.dentry,
36665 + arg->u.list.list, arg->u.list.size);
36667 + case AU_XATTR_GET:
36668 + AuDebugOn(d_is_negative(h_path.dentry));
36669 + err = vfs_getxattr(mnt_user_ns(h_path.mnt), h_path.dentry,
36670 + arg->u.get.name, arg->u.get.value,
36671 + arg->u.get.size);
36677 + di_read_unlock(dentry, AuLock_IR);
36680 + si_read_unlock(sb);
36686 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36688 + struct au_lgxattr arg = {
36689 + .type = AU_XATTR_LIST,
36696 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36699 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36700 + const char *name, void *value, size_t size)
36702 + struct au_lgxattr arg = {
36703 + .type = AU_XATTR_GET,
36711 + return au_lgxattr(dentry, inode, &arg);
36714 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36715 + const char *name, const void *value, size_t size,
36718 + struct au_sxattr arg = {
36719 + .type = AU_XATTR_SET,
36728 + return au_sxattr(dentry, inode, &arg);
36731 +/* ---------------------------------------------------------------------- */
36733 +static int au_xattr_get(const struct xattr_handler *handler,
36734 + struct dentry *dentry, struct inode *inode,
36735 + const char *name, void *buffer, size_t size)
36737 + return au_getxattr(dentry, inode, name, buffer, size);
36740 +static int au_xattr_set(const struct xattr_handler *handler,
36741 + struct user_namespace *userns,
36742 + struct dentry *dentry, struct inode *inode,
36743 + const char *name, const void *value, size_t size,
36746 + return au_setxattr(dentry, inode, name, value, size, flags);
36749 +static const struct xattr_handler au_xattr_handler = {
36752 + .get = au_xattr_get,
36753 + .set = au_xattr_set
36756 +static const struct xattr_handler *au_xattr_handlers[] = {
36757 +#ifdef CONFIG_FS_POSIX_ACL
36758 + &posix_acl_access_xattr_handler,
36759 + &posix_acl_default_xattr_handler,
36761 + &au_xattr_handler, /* must be last */
36765 +void au_xattr_init(struct super_block *sb)
36767 + sb->s_xattr = au_xattr_handlers;
36769 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36770 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36771 +++ linux/fs/aufs/xino.c 2021-11-01 23:48:34.213025928 +0100
36773 +// SPDX-License-Identifier: GPL-2.0
36775 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36777 + * This program, aufs is free software; you can redistribute it and/or modify
36778 + * it under the terms of the GNU General Public License as published by
36779 + * the Free Software Foundation; either version 2 of the License, or
36780 + * (at your option) any later version.
36782 + * This program is distributed in the hope that it will be useful,
36783 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36784 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36785 + * GNU General Public License for more details.
36787 + * You should have received a copy of the GNU General Public License
36788 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36792 + * external inode number translation table and bitmap
36794 + * things to consider
36796 + * + au_xino object
36797 + * + XINO files (xino, xib, xigen)
36798 + * + dynamic debugfs entries (xiN)
36799 + * + static debugfs entries (xib, xigen)
36800 + * + static sysfs entry (xi_path)
36801 + * - several entry points to handle them.
36802 + * + mount(2) without xino option (default)
36803 + * + mount(2) with xino option
36804 + * + mount(2) with noxino option
36806 + * + remount with add/del branches
36807 + * + remount with xino/noxino options
36810 +#include <linux/seq_file.h>
36811 +#include <linux/statfs.h>
36814 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36815 + aufs_bindex_t bbot,
36816 + struct super_block *h_sb)
36818 + /* todo: try binary-search if the branches are many */
36819 + for (; btop <= bbot; btop++)
36820 + if (h_sb == au_sbr_sb(sb, btop))
36826 + * find another branch who is on the same filesystem of the specified
36827 + * branch{@btgt}. search until @bbot.
36829 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36830 + aufs_bindex_t bbot)
36832 + aufs_bindex_t bindex;
36833 + struct super_block *tgt_sb;
36835 + tgt_sb = au_sbr_sb(sb, btgt);
36836 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36838 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36843 +/* ---------------------------------------------------------------------- */
36846 + * stop unnecessary notify events at creating xino files
36849 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36851 + aufs_bindex_t bfound, bindex, bbot;
36852 + struct dentry *parent;
36853 + struct au_branch *br;
36856 + parent = dentry->d_parent; /* safe d_parent access */
36857 + bbot = au_sbbot(sb);
36858 + for (bindex = 0; bindex <= bbot; bindex++) {
36859 + br = au_sbr(sb, bindex);
36860 + if (au_br_dentry(br) == parent) {
36866 + AuDbg("bfound b%d\n", bfound);
36870 +struct au_xino_lock_dir {
36871 + struct au_hinode *hdir;
36872 + struct dentry *parent;
36873 + struct inode *dir;
36876 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36877 + unsigned int lsc)
36879 + struct dentry *parent;
36880 + struct inode *dir;
36882 + parent = dget_parent(dentry);
36883 + dir = d_inode(parent);
36884 + inode_lock_nested(dir, lsc);
36885 +#if 0 /* it should not happen */
36886 + spin_lock(&dentry->d_lock);
36887 + if (unlikely(dentry->d_parent != parent)) {
36888 + spin_unlock(&dentry->d_lock);
36889 + inode_unlock(dir);
36894 + spin_unlock(&dentry->d_lock);
36901 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36902 + struct au_xino_lock_dir *ldir)
36904 + aufs_bindex_t bindex;
36906 + ldir->hdir = NULL;
36907 + bindex = au_xi_root(sb, xipath->dentry);
36908 + if (bindex >= 0) {
36909 + /* rw branch root */
36910 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36911 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36914 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36916 + ldir->dir = d_inode(ldir->parent);
36920 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36923 + au_hn_inode_unlock(ldir->hdir);
36925 + inode_unlock(ldir->dir);
36926 + dput(ldir->parent);
36930 +/* ---------------------------------------------------------------------- */
36933 + * create and set a new xino file
36935 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36938 + struct file *file;
36939 + struct dentry *h_parent, *d;
36940 + struct inode *h_dir, *inode;
36942 + static DEFINE_MUTEX(mtx);
36945 + * at mount-time, and the xino file is the default path,
36946 + * hnotify is disabled so we have no notify events to ignore.
36947 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36950 + mutex_lock(&mtx);
36951 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36952 + /* | __FMODE_NONOTIFY */,
36954 + if (IS_ERR(file)) {
36956 + mutex_unlock(&mtx);
36958 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36962 + /* keep file count */
36964 + d = file->f_path.dentry;
36965 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36967 + mutex_unlock(&mtx);
36968 + /* mnt_want_write() is unnecessary here */
36969 + h_dir = d_inode(h_parent);
36970 + inode = file_inode(file);
36971 + /* no delegation since it is just created */
36972 + if (inode->i_nlink)
36973 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36975 + inode_unlock(h_dir);
36977 + if (unlikely(err)) {
36979 + pr_err("unlink %s(%d)\n", fpath, err);
36984 + if (unlikely(sb == d->d_sb)) {
36986 + pr_err("%s must be outside\n", fpath);
36989 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36991 + pr_err("xino doesn't support %s(%s)\n",
36992 + fpath, au_sbtype(d->d_sb));
36995 + return file; /* success */
36999 + file = ERR_PTR(err);
37004 + * create a new xinofile at the same place/path as @base.
37006 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37007 + struct file *copy_src)
37009 + struct file *file;
37010 + struct dentry *dentry;
37011 + struct inode *dir, *delegated;
37012 + struct qstr *name;
37013 + struct path ppath, path;
37014 + int err, do_unlock;
37015 + struct au_xino_lock_dir ldir;
37018 + au_xino_lock_dir(sb, base, &ldir);
37019 + dentry = base->dentry;
37020 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37021 + ppath.mnt = base->mnt;
37022 + dir = d_inode(ppath.dentry);
37025 + name = &dentry->d_name;
37026 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37027 + if (IS_ERR(path.dentry)) {
37028 + file = (void *)path.dentry;
37029 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37033 + /* no need to mnt_want_write() since we call dentry_open() later */
37034 + err = vfs_create(mnt_user_ns(base->mnt), dir, path.dentry, 0666, NULL);
37035 + if (unlikely(err)) {
37036 + file = ERR_PTR(err);
37037 + pr_err("%pd create err %d\n", dentry, err);
37041 + path.mnt = base->mnt;
37042 + file = vfsub_dentry_open(&path,
37043 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37044 + /* | __FMODE_NONOTIFY */);
37045 + if (IS_ERR(file)) {
37046 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37050 + delegated = NULL;
37051 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37052 + au_xino_unlock_dir(&ldir);
37054 + if (unlikely(err == -EWOULDBLOCK)) {
37055 + pr_warn("cannot retry for NFSv4 delegation"
37056 + " for an internal unlink\n");
37059 + if (unlikely(err)) {
37060 + pr_err("%pd unlink err %d\n", dentry, err);
37065 + /* no one can touch copy_src xino */
37066 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37067 + if (unlikely(err)) {
37068 + pr_err("%pd copy err %d\n", dentry, err);
37072 + goto out_dput; /* success */
37076 + file = ERR_PTR(err);
37078 + dput(path.dentry);
37081 + au_xino_unlock_dir(&ldir);
37085 +struct file *au_xino_file1(struct au_xino *xi)
37087 + struct file *file;
37088 + unsigned int u, nfile;
37091 + nfile = xi->xi_nfile;
37092 + for (u = 0; u < nfile; u++) {
37093 + file = xi->xi_file[u];
37101 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37112 + if (idx < xi->xi_nfile) {
37113 + f = xi->xi_file[idx];
37117 + p = au_kzrealloc(xi->xi_file,
37118 + sizeof(*xi->xi_file) * xi->xi_nfile,
37119 + sizeof(*xi->xi_file) * (idx + 1),
37120 + GFP_NOFS, /*may_shrink*/0);
37122 + MtxMustLock(&xi->xi_mtx);
37124 + xi->xi_nfile = idx + 1;
37132 + xi->xi_file[idx] = file;
37139 + * if @xinew->xi is not set, then create new xigen file.
37141 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37143 + struct file *file;
37146 + SiMustAnyLock(sb);
37148 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37149 + if (IS_ERR(file)) {
37150 + err = PTR_ERR(file);
37151 + pr_err("%s[%d], err %d\n",
37152 + xinew->xi ? "xino" : "xigen",
37153 + xinew->idx, err);
37158 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37161 + /* todo: make xigen file an array */
37162 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37165 + if (unlikely(err))
37166 + file = ERR_PTR(err);
37172 +/* ---------------------------------------------------------------------- */
37175 + * truncate xino files
37177 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37178 + int idx, struct kstatfs *st)
37182 + struct file *file, *new_xino;
37183 + struct au_xi_new xinew = {
37188 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37189 + file = au_xino_file(xinew.xi, idx);
37193 + xinew.base = &file->f_path;
37194 + err = vfs_statfs(xinew.base, st);
37195 + if (unlikely(err)) {
37196 + AuErr1("statfs err %d, ignored\n", err);
37201 + blocks = file_inode(file)->i_blocks;
37202 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37203 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37205 + xinew.copy_src = file;
37206 + new_xino = au_xi_new(sb, &xinew);
37207 + if (IS_ERR(new_xino)) {
37208 + err = PTR_ERR(new_xino);
37209 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37213 + err = vfs_statfs(&new_xino->f_path, st);
37215 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37216 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37217 + st->f_bfree, st->f_blocks);
37219 + AuErr1("statfs err %d, ignored\n", err);
37227 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37230 + unsigned long jiffy;
37231 + aufs_bindex_t bbot;
37232 + struct kstatfs *st;
37233 + struct au_branch *br;
37234 + struct au_xino *xi;
37237 + st = kmalloc(sizeof(*st), GFP_NOFS);
37238 + if (unlikely(!st))
37242 + bbot = au_sbbot(sb);
37243 + if (unlikely(bindex < 0 || bbot < bindex))
37248 + br = au_sbr(sb, bindex);
37249 + xi = br->br_xino;
37250 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37251 + err = au_xino_do_trunc(sb, bindex, i, st);
37253 + au_sbi(sb)->si_xino_jiffy = jiffy;
37256 + au_kfree_rcu(st);
37261 +struct xino_do_trunc_args {
37262 + struct super_block *sb;
37263 + struct au_branch *br;
37267 +static void xino_do_trunc(void *_args)
37269 + struct xino_do_trunc_args *args = _args;
37270 + struct super_block *sb;
37271 + struct au_branch *br;
37272 + struct inode *dir;
37274 + aufs_bindex_t bindex;
37278 + dir = d_inode(sb->s_root);
37282 + si_noflush_write_lock(sb);
37283 + ii_read_lock_parent(dir);
37284 + bindex = au_br_index(sb, br->br_id);
37285 + err = au_xino_trunc(sb, bindex, idx);
37286 + ii_read_unlock(dir);
37287 + if (unlikely(err))
37288 + pr_warn("err b%d, (%d)\n", bindex, err);
37289 + atomic_dec(&br->br_xino->xi_truncating);
37290 + au_lcnt_dec(&br->br_count);
37291 + si_write_unlock(sb);
37292 + au_nwt_done(&au_sbi(sb)->si_nowait);
37293 + au_kfree_rcu(args);
37297 + * returns the index in the xi_file array whose corresponding file is necessary
37298 + * to truncate, or -1 which means no need to truncate.
37300 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37304 + struct kstatfs st;
37305 + struct au_sbinfo *sbinfo;
37306 + struct au_xino *xi;
37307 + struct file *file;
37309 + /* todo: si_xino_expire and the ratio should be customizable */
37310 + sbinfo = au_sbi(sb);
37311 + if (time_before(jiffies,
37312 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37315 + /* truncation border */
37316 + xi = br->br_xino;
37317 + for (u = 0; u < xi->xi_nfile; u++) {
37318 + file = au_xino_file(xi, u);
37322 + err = vfs_statfs(&file->f_path, &st);
37323 + if (unlikely(err)) {
37324 + AuErr1("statfs err %d, ignored\n", err);
37327 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37328 + >= AUFS_XINO_DEF_TRUNC)
37335 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37338 + struct xino_do_trunc_args *args;
37341 + idx = xino_trunc_test(sb, br);
37345 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37348 + /* lock and kfree() will be called in trunc_xino() */
37349 + args = kmalloc(sizeof(*args), GFP_NOFS);
37350 + if (unlikely(!args)) {
37351 + AuErr1("no memory\n");
37355 + au_lcnt_inc(&br->br_count);
37359 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37361 + return; /* success */
37363 + pr_err("wkq %d\n", wkq_err);
37364 + au_lcnt_dec(&br->br_count);
37365 + au_kfree_rcu(args);
37368 + atomic_dec(&br->br_xino->xi_truncating);
37371 +/* ---------------------------------------------------------------------- */
37373 +struct au_xi_calc {
37378 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37379 + struct au_xi_calc *calc)
37383 + maxent = au_xi_maxent(sb);
37384 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37385 + calc->pos *= sizeof(ino_t);
37388 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37389 + struct au_xi_calc *calc)
37392 + struct file *file;
37393 + struct au_xino *xi = br->br_xino;
37394 + struct au_xi_new xinew = {
37398 + SiMustAnyLock(sb);
37404 + mutex_lock(&xi->xi_mtx);
37405 + file = au_xino_file(xi, calc->idx);
37409 + file = au_xino_file(xi, /*idx*/-1);
37410 + AuDebugOn(!file);
37411 + xinew.idx = calc->idx;
37412 + xinew.base = &file->f_path;
37413 + /* xinew.copy_src = NULL; */
37414 + file = au_xi_new(sb, &xinew);
37415 + if (IS_ERR(file))
37416 + err = PTR_ERR(file);
37419 + mutex_unlock(&xi->xi_mtx);
37424 +struct au_xino_do_new_async_args {
37425 + struct super_block *sb;
37426 + struct au_branch *br;
37427 + struct au_xi_calc calc;
37431 +struct au_xi_writing {
37432 + struct hlist_bl_node node;
37433 + ino_t h_ino, ino;
37436 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37439 +static void au_xino_call_do_new_async(void *args)
37441 + struct au_xino_do_new_async_args *a = args;
37442 + struct au_branch *br;
37443 + struct super_block *sb;
37444 + struct au_sbinfo *sbi;
37445 + struct inode *root;
37446 + struct file *file;
37447 + struct au_xi_writing *del, *p;
37448 + struct hlist_bl_head *hbl;
37449 + struct hlist_bl_node *pos;
37454 + sbi = au_sbi(sb);
37455 + si_noflush_read_lock(sb);
37456 + root = d_inode(sb->s_root);
37457 + ii_read_lock_child(root);
37458 + err = au_xino_do_new_async(sb, br, &a->calc);
37459 + if (unlikely(err)) {
37460 + AuIOErr("err %d\n", err);
37464 + file = au_xino_file(br->br_xino, a->calc.idx);
37465 + AuDebugOn(!file);
37466 + err = au_xino_do_write(file, &a->calc, a->ino);
37467 + if (unlikely(err)) {
37468 + AuIOErr("err %d\n", err);
37473 + hbl = &br->br_xino->xi_writing;
37474 + hlist_bl_lock(hbl);
37475 + au_hbl_for_each(pos, hbl) {
37476 + p = container_of(pos, struct au_xi_writing, node);
37477 + if (p->ino == a->ino) {
37479 + hlist_bl_del(&p->node);
37483 + hlist_bl_unlock(hbl);
37484 + au_kfree_rcu(del);
37487 + au_lcnt_dec(&br->br_count);
37488 + ii_read_unlock(root);
37489 + si_read_unlock(sb);
37490 + au_nwt_done(&sbi->si_nowait);
37495 + * create a new xino file asynchronously
37497 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37498 + struct au_xi_calc *calc, ino_t ino)
37501 + struct au_xino_do_new_async_args *arg;
37504 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37505 + if (unlikely(!arg))
37510 + arg->calc = *calc;
37512 + au_lcnt_inc(&br->br_count);
37513 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37514 + if (unlikely(err)) {
37515 + pr_err("wkq %d\n", err);
37516 + au_lcnt_dec(&br->br_count);
37517 + au_kfree_rcu(arg);
37525 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37526 + * at the position of @h_ino.
37528 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37533 + struct au_xi_calc calc;
37534 + struct au_sbinfo *sbinfo;
37535 + struct file *file;
37536 + struct au_xino *xi;
37537 + struct hlist_bl_head *hbl;
37538 + struct hlist_bl_node *pos;
37539 + struct au_xi_writing *p;
37542 + if (!au_opt_test(au_mntflags(sb), XINO))
37543 + return 0; /* no xino */
37546 + au_xi_calc(sb, h_ino, &calc);
37547 + xi = au_sbr(sb, bindex)->br_xino;
37548 + file = au_xino_file(xi, calc.idx);
37550 + hbl = &xi->xi_writing;
37551 + hlist_bl_lock(hbl);
37552 + au_hbl_for_each(pos, hbl) {
37553 + p = container_of(pos, struct au_xi_writing, node);
37554 + if (p->h_ino == h_ino) {
37555 + AuDbg("hi%llu, i%llu, found\n",
37556 + (u64)p->h_ino, (u64)p->ino);
37561 + hlist_bl_unlock(hbl);
37563 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37564 + return 0; /* no xino */
37566 + sbinfo = au_sbi(sb);
37567 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37568 + if (sz == sizeof(*ino))
37569 + return 0; /* success */
37572 + if (unlikely(sz >= 0)) {
37574 + AuIOErr("xino read error (%zd)\n", sz);
37579 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37584 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37585 + if (sz == sizeof(ino))
37586 + return 0; /* success */
37588 + AuIOErr("write failed (%zd)\n", sz);
37593 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37594 + * at the position of @h_ino.
37595 + * even if @ino is zero, it is written to the xinofile and means no entry.
37596 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37597 + * try truncating it.
37599 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37603 + unsigned int mnt_flags;
37604 + struct au_xi_calc calc;
37605 + struct file *file;
37606 + struct au_branch *br;
37607 + struct au_xino *xi;
37608 + struct au_xi_writing *p;
37610 + SiMustAnyLock(sb);
37612 + mnt_flags = au_mntflags(sb);
37613 + if (!au_opt_test(mnt_flags, XINO))
37616 + au_xi_calc(sb, h_ino, &calc);
37617 + br = au_sbr(sb, bindex);
37618 + xi = br->br_xino;
37619 + file = au_xino_file(xi, calc.idx);
37621 + /* store the inum pair into the list */
37622 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37623 + p->h_ino = h_ino;
37625 + au_hbl_add(&p->node, &xi->xi_writing);
37627 + /* create and write a new xino file asynchronously */
37628 + err = au_xino_new_async(sb, br, &calc, ino);
37630 + return 0; /* success */
37634 + err = au_xino_do_write(file, &calc, ino);
37636 + br = au_sbr(sb, bindex);
37637 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37638 + && au_test_fs_trunc_xino(au_br_sb(br)))
37639 + xino_try_trunc(sb, br);
37640 + return 0; /* success */
37644 + AuIOErr("write failed (%d)\n", err);
37648 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37651 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37652 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37656 + const int prevent_endless = 10;
37660 + err = vfsub_read_k(file, kbuf, size, pos);
37661 + if (err == -EINTR
37662 + && !au_wkq_test()
37663 + && fatal_signal_pending(current)) {
37664 + err = xino_fread_wkq(file, kbuf, size, pos);
37665 + BUG_ON(err == -EINTR);
37667 + } while (i++ < prevent_endless
37668 + && (err == -EAGAIN || err == -EINTR));
37670 +#if 0 /* reserved for future use */
37672 + fsnotify_access(file->f_path.dentry);
37678 +struct xino_fread_args {
37680 + struct file *file;
37686 +static void call_xino_fread(void *args)
37688 + struct xino_fread_args *a = args;
37689 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37692 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37697 + struct xino_fread_args args = {
37705 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37706 + if (unlikely(wkq_err))
37712 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37715 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37720 + const int prevent_endless = 10;
37724 + err = vfsub_write_k(file, kbuf, size, pos);
37725 + if (err == -EINTR
37726 + && !au_wkq_test()
37727 + && fatal_signal_pending(current)) {
37728 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37729 + BUG_ON(err == -EINTR);
37731 + } while (i++ < prevent_endless
37732 + && (err == -EAGAIN || err == -EINTR));
37734 +#if 0 /* reserved for future use */
37736 + fsnotify_modify(file->f_path.dentry);
37742 +struct do_xino_fwrite_args {
37744 + struct file *file;
37750 +static void call_do_xino_fwrite(void *args)
37752 + struct do_xino_fwrite_args *a = args;
37753 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37756 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37761 + struct do_xino_fwrite_args args = {
37770 + * it breaks RLIMIT_FSIZE and normal user's limit,
37771 + * users should care about quota and real 'filesystem full.'
37773 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37774 + if (unlikely(wkq_err))
37780 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37784 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37786 + err = do_xino_fwrite(file, buf, size, pos);
37790 + err = xino_fwrite_wkq(file, buf, size, pos);
37797 +/* ---------------------------------------------------------------------- */
37800 + * inode number bitmap
37802 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37803 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37807 + AuDebugOn(bit < 0 || page_bits <= bit);
37808 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37812 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37814 + AuDebugOn(ino < AUFS_FIRST_INO);
37815 + ino -= AUFS_FIRST_INO;
37816 + *pindex = ino / page_bits;
37817 + *bit = ino % page_bits;
37820 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37825 + struct au_sbinfo *sbinfo;
37826 + struct file *xib;
37827 + unsigned long *p;
37829 + sbinfo = au_sbi(sb);
37830 + MtxMustLock(&sbinfo->si_xib_mtx);
37831 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37832 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37834 + if (pindex == sbinfo->si_xib_last_pindex)
37837 + xib = sbinfo->si_xib;
37838 + p = sbinfo->si_xib_buf;
37839 + pos = sbinfo->si_xib_last_pindex;
37840 + pos *= PAGE_SIZE;
37841 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37842 + if (unlikely(sz != PAGE_SIZE))
37846 + pos *= PAGE_SIZE;
37847 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37848 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37850 + memset(p, 0, PAGE_SIZE);
37851 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37853 + if (sz == PAGE_SIZE) {
37854 + sbinfo->si_xib_last_pindex = pindex;
37855 + return 0; /* success */
37859 + AuIOErr1("write failed (%zd)\n", sz);
37866 +static void au_xib_clear_bit(struct inode *inode)
37869 + unsigned long pindex;
37870 + struct super_block *sb;
37871 + struct au_sbinfo *sbinfo;
37873 + AuDebugOn(inode->i_nlink);
37875 + sb = inode->i_sb;
37876 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37877 + AuDebugOn(page_bits <= bit);
37878 + sbinfo = au_sbi(sb);
37879 + mutex_lock(&sbinfo->si_xib_mtx);
37880 + err = xib_pindex(sb, pindex);
37882 + clear_bit(bit, sbinfo->si_xib_buf);
37883 + sbinfo->si_xib_next_bit = bit;
37885 + mutex_unlock(&sbinfo->si_xib_mtx);
37888 +/* ---------------------------------------------------------------------- */
37891 + * truncate a xino bitmap file
37895 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37899 + unsigned long pindex;
37900 + loff_t pos, pend;
37901 + struct au_sbinfo *sbinfo;
37903 + unsigned long *p;
37906 + sbinfo = au_sbi(sb);
37907 + MtxMustLock(&sbinfo->si_xib_mtx);
37908 + p = sbinfo->si_xib_buf;
37909 + pend = vfsub_f_size_read(file);
37911 + while (pos < pend) {
37912 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37914 + if (unlikely(sz <= 0))
37918 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37919 + if (unlikely(*ino < AUFS_FIRST_INO))
37922 + xib_calc_bit(*ino, &pindex, &bit);
37923 + AuDebugOn(page_bits <= bit);
37924 + err = xib_pindex(sb, pindex);
37936 +static int xib_restore(struct super_block *sb)
37939 + unsigned int nfile;
37940 + aufs_bindex_t bindex, bbot;
37942 + struct au_branch *br;
37943 + struct au_xino *xi;
37944 + struct file *file;
37947 + page = (void *)__get_free_page(GFP_NOFS);
37948 + if (unlikely(!page))
37952 + bbot = au_sbbot(sb);
37953 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37954 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37955 + br = au_sbr(sb, bindex);
37956 + xi = br->br_xino;
37957 + nfile = xi->xi_nfile;
37958 + for (i = 0; i < nfile; i++) {
37959 + file = au_xino_file(xi, i);
37961 + err = do_xib_restore(sb, file, page);
37964 + AuDbg("skip shared b%d\n", bindex);
37965 + free_page((unsigned long)page);
37971 +int au_xib_trunc(struct super_block *sb)
37976 + struct au_sbinfo *sbinfo;
37977 + unsigned long *p;
37978 + struct file *file;
37980 + SiMustWriteLock(sb);
37983 + sbinfo = au_sbi(sb);
37984 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37987 + file = sbinfo->si_xib;
37988 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37991 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37992 + err = PTR_ERR(file);
37993 + if (IS_ERR(file))
37995 + fput(sbinfo->si_xib);
37996 + sbinfo->si_xib = file;
37998 + p = sbinfo->si_xib_buf;
37999 + memset(p, 0, PAGE_SIZE);
38001 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38002 + if (unlikely(sz != PAGE_SIZE)) {
38004 + AuIOErr("err %d\n", err);
38010 + mutex_lock(&sbinfo->si_xib_mtx);
38011 + /* mnt_want_write() is unnecessary here */
38012 + err = xib_restore(sb);
38013 + mutex_unlock(&sbinfo->si_xib_mtx);
38019 +/* ---------------------------------------------------------------------- */
38021 +struct au_xino *au_xino_alloc(unsigned int nfile)
38023 + struct au_xino *xi;
38025 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38026 + if (unlikely(!xi))
38028 + xi->xi_nfile = nfile;
38029 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38030 + if (unlikely(!xi->xi_file))
38033 + xi->xi_nondir.total = 8; /* initial size */
38034 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38036 + if (unlikely(!xi->xi_nondir.array))
38039 + spin_lock_init(&xi->xi_nondir.spin);
38040 + init_waitqueue_head(&xi->xi_nondir.wqh);
38041 + mutex_init(&xi->xi_mtx);
38042 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38043 + atomic_set(&xi->xi_truncating, 0);
38044 + kref_init(&xi->xi_kref);
38045 + goto out; /* success */
38048 + au_kfree_try_rcu(xi->xi_file);
38050 + au_kfree_rcu(xi);
38056 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38059 + struct au_xino *xi;
38062 + xi = au_xino_alloc(idx + 1);
38063 + if (unlikely(!xi)) {
38070 + xi->xi_file[idx] = file;
38071 + AuDebugOn(br->br_xino);
38072 + br->br_xino = xi;
38078 +static void au_xino_release(struct kref *kref)
38080 + struct au_xino *xi;
38082 + unsigned long ul;
38083 + struct hlist_bl_head *hbl;
38084 + struct hlist_bl_node *pos, *n;
38085 + struct au_xi_writing *p;
38087 + xi = container_of(kref, struct au_xino, xi_kref);
38088 + for (i = 0; i < xi->xi_nfile; i++)
38089 + if (xi->xi_file[i])
38090 + fput(xi->xi_file[i]);
38091 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38092 + AuDebugOn(xi->xi_nondir.array[i]);
38093 + mutex_destroy(&xi->xi_mtx);
38094 + hbl = &xi->xi_writing;
38095 + ul = au_hbl_count(hbl);
38096 + if (unlikely(ul)) {
38097 + pr_warn("xi_writing %lu\n", ul);
38098 + hlist_bl_lock(hbl);
38099 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38100 + hlist_bl_del(&p->node);
38101 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38104 + hlist_bl_unlock(hbl);
38106 + au_kfree_try_rcu(xi->xi_file);
38107 + au_kfree_try_rcu(xi->xi_nondir.array);
38108 + au_kfree_rcu(xi);
38111 +int au_xino_put(struct au_branch *br)
38114 + struct au_xino *xi;
38117 + xi = br->br_xino;
38119 + br->br_xino = NULL;
38120 + ret = kref_put(&xi->xi_kref, au_xino_release);
38126 +/* ---------------------------------------------------------------------- */
38129 + * xino mount option handlers
38133 +static void xino_clear_xib(struct super_block *sb)
38135 + struct au_sbinfo *sbinfo;
38137 + SiMustWriteLock(sb);
38139 + sbinfo = au_sbi(sb);
38140 + if (sbinfo->si_xib)
38141 + fput(sbinfo->si_xib);
38142 + sbinfo->si_xib = NULL;
38143 + if (sbinfo->si_xib_buf)
38144 + free_page((unsigned long)sbinfo->si_xib_buf);
38145 + sbinfo->si_xib_buf = NULL;
38148 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38152 + struct au_sbinfo *sbinfo;
38153 + struct file *file;
38154 + struct super_block *xi_sb;
38156 + SiMustWriteLock(sb);
38158 + sbinfo = au_sbi(sb);
38159 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38160 + err = PTR_ERR(file);
38161 + if (IS_ERR(file))
38163 + if (sbinfo->si_xib)
38164 + fput(sbinfo->si_xib);
38165 + sbinfo->si_xib = file;
38166 + xi_sb = file_inode(file)->i_sb;
38167 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38168 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38170 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38171 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38174 + sbinfo->si_ximaxent /= sizeof(ino_t);
38177 + if (!sbinfo->si_xib_buf)
38178 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38179 + if (unlikely(!sbinfo->si_xib_buf))
38182 + sbinfo->si_xib_last_pindex = 0;
38183 + sbinfo->si_xib_next_bit = 0;
38184 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38186 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38187 + if (unlikely(err != PAGE_SIZE))
38191 + goto out; /* success */
38194 + if (sbinfo->si_xib_buf)
38195 + free_page((unsigned long)sbinfo->si_xib_buf);
38196 + sbinfo->si_xib_buf = NULL;
38200 + fput(sbinfo->si_xib);
38201 + sbinfo->si_xib = NULL;
38207 +/* xino for each branch */
38208 +static void xino_clear_br(struct super_block *sb)
38210 + aufs_bindex_t bindex, bbot;
38211 + struct au_branch *br;
38213 + bbot = au_sbbot(sb);
38214 + for (bindex = 0; bindex <= bbot; bindex++) {
38215 + br = au_sbr(sb, bindex);
38221 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38222 + aufs_bindex_t bshared)
38224 + struct au_branch *brshared;
38226 + brshared = au_sbr(sb, bshared);
38227 + AuDebugOn(!brshared->br_xino);
38228 + AuDebugOn(!brshared->br_xino->xi_file);
38229 + if (br->br_xino != brshared->br_xino) {
38230 + au_xino_get(brshared);
38232 + br->br_xino = brshared->br_xino;
38236 +struct au_xino_do_set_br {
38237 + struct au_branch *br;
38239 + aufs_bindex_t bshared;
38242 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38243 + struct au_xino_do_set_br *args)
38246 + struct au_xi_calc calc;
38247 + struct file *file;
38248 + struct au_branch *br;
38249 + struct au_xi_new xinew = {
38254 + xinew.xi = br->br_xino;
38255 + au_xi_calc(sb, args->h_ino, &calc);
38256 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38257 + if (args->bshared >= 0)
38258 + /* shared xino */
38259 + au_xino_set_br_shared(sb, br, args->bshared);
38260 + else if (!xinew.xi) {
38262 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38263 + if (unlikely(err))
38267 + /* force re-creating */
38268 + xinew.xi = br->br_xino;
38269 + xinew.idx = calc.idx;
38270 + mutex_lock(&xinew.xi->xi_mtx);
38271 + file = au_xi_new(sb, &xinew);
38272 + mutex_unlock(&xinew.xi->xi_mtx);
38273 + err = PTR_ERR(file);
38274 + if (IS_ERR(file))
38276 + AuDebugOn(!file);
38278 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38279 + if (unlikely(err))
38287 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38290 + aufs_bindex_t bindex, bbot;
38291 + struct au_xino_do_set_br args;
38292 + struct inode *inode;
38294 + SiMustWriteLock(sb);
38296 + bbot = au_sbbot(sb);
38297 + inode = d_inode(sb->s_root);
38298 + for (bindex = 0; bindex <= bbot; bindex++) {
38299 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38300 + args.br = au_sbr(sb, bindex);
38301 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38302 + err = au_xino_do_set_br(sb, path, &args);
38303 + if (unlikely(err))
38311 +void au_xino_clr(struct super_block *sb)
38313 + struct au_sbinfo *sbinfo;
38315 + au_xigen_clr(sb);
38316 + xino_clear_xib(sb);
38317 + xino_clear_br(sb);
38318 + dbgaufs_brs_del(sb, 0);
38319 + sbinfo = au_sbi(sb);
38320 + /* lvalue, do not call au_mntflags() */
38321 + au_opt_clr(sbinfo->si_mntflags, XINO);
38324 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38327 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38328 + struct qstr *dname, *cur_name;
38329 + struct file *cur_xino;
38330 + struct au_sbinfo *sbinfo;
38331 + struct path *path, *cur_path;
38333 + SiMustWriteLock(sb);
38336 + sbinfo = au_sbi(sb);
38337 + path = &xiopt->file->f_path;
38338 + dentry = path->dentry;
38339 + parent = dget_parent(dentry);
38342 + cur_xino = sbinfo->si_xib;
38344 + cur_path = &cur_xino->f_path;
38345 + cur_dentry = cur_path->dentry;
38346 + cur_parent = dget_parent(cur_dentry);
38347 + cur_name = &cur_dentry->d_name;
38348 + dname = &dentry->d_name;
38349 + skip = (cur_parent == parent
38350 + && au_qstreq(dname, cur_name));
38351 + dput(cur_parent);
38357 + au_opt_set(sbinfo->si_mntflags, XINO);
38358 + err = au_xino_set_xib(sb, path);
38359 + /* si_x{read,write} are set */
38361 + err = au_xigen_set(sb, path);
38363 + err = au_xino_set_br(sb, path);
38365 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38366 + goto out; /* success */
38370 + AuIOErr("failed setting xino(%d).\n", err);
38379 + * create a xinofile at the default place/path.
38381 +struct file *au_xino_def(struct super_block *sb)
38383 + struct file *file;
38385 + struct au_branch *br;
38386 + struct super_block *h_sb;
38387 + struct path path;
38388 + aufs_bindex_t bbot, bindex, bwr;
38391 + bbot = au_sbbot(sb);
38393 + for (bindex = 0; bindex <= bbot; bindex++) {
38394 + br = au_sbr(sb, bindex);
38395 + if (au_br_writable(br->br_perm)
38396 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38403 + file = ERR_PTR(-ENOMEM);
38404 + page = (void *)__get_free_page(GFP_NOFS);
38405 + if (unlikely(!page))
38407 + path.mnt = au_br_mnt(br);
38408 + path.dentry = au_h_dptr(sb->s_root, bwr);
38409 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38410 + file = (void *)p;
38411 + if (!IS_ERR(p)) {
38412 + strcat(p, "/" AUFS_XINO_FNAME);
38413 + AuDbg("%s\n", p);
38414 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38416 + free_page((unsigned long)page);
38418 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38420 + if (IS_ERR(file))
38422 + h_sb = file->f_path.dentry->d_sb;
38423 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38424 + pr_err("xino doesn't support %s(%s)\n",
38425 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38427 + file = ERR_PTR(-EINVAL);
38435 +/* ---------------------------------------------------------------------- */
38438 + * initialize the xinofile for the specified branch @br
38439 + * at the place/path where @base_file indicates.
38440 + * test whether another branch is on the same filesystem or not,
38441 + * if found then share the xinofile with another branch.
38443 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38444 + struct path *base)
38447 + struct au_xino_do_set_br args = {
38452 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38454 + err = au_xino_do_set_br(sb, base, &args);
38455 + if (unlikely(err))
38461 +/* ---------------------------------------------------------------------- */
38464 + * get an unused inode number from bitmap
38466 +ino_t au_xino_new_ino(struct super_block *sb)
38469 + unsigned long *p, pindex, ul, pend;
38470 + struct au_sbinfo *sbinfo;
38471 + struct file *file;
38472 + int free_bit, err;
38474 + if (!au_opt_test(au_mntflags(sb), XINO))
38475 + return iunique(sb, AUFS_FIRST_INO);
38477 + sbinfo = au_sbi(sb);
38478 + mutex_lock(&sbinfo->si_xib_mtx);
38479 + p = sbinfo->si_xib_buf;
38480 + free_bit = sbinfo->si_xib_next_bit;
38481 + if (free_bit < page_bits && !test_bit(free_bit, p))
38482 + goto out; /* success */
38483 + free_bit = find_first_zero_bit(p, page_bits);
38484 + if (free_bit < page_bits)
38485 + goto out; /* success */
38487 + pindex = sbinfo->si_xib_last_pindex;
38488 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38489 + err = xib_pindex(sb, ul);
38490 + if (unlikely(err))
38492 + free_bit = find_first_zero_bit(p, page_bits);
38493 + if (free_bit < page_bits)
38494 + goto out; /* success */
38497 + file = sbinfo->si_xib;
38498 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38499 + for (ul = pindex + 1; ul <= pend; ul++) {
38500 + err = xib_pindex(sb, ul);
38501 + if (unlikely(err))
38503 + free_bit = find_first_zero_bit(p, page_bits);
38504 + if (free_bit < page_bits)
38505 + goto out; /* success */
38510 + set_bit(free_bit, p);
38511 + sbinfo->si_xib_next_bit = free_bit + 1;
38512 + pindex = sbinfo->si_xib_last_pindex;
38513 + mutex_unlock(&sbinfo->si_xib_mtx);
38514 + ino = xib_calc_ino(pindex, free_bit);
38515 + AuDbg("i%lu\n", (unsigned long)ino);
38518 + mutex_unlock(&sbinfo->si_xib_mtx);
38523 +/* for s_op->delete_inode() */
38524 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38527 + unsigned int mnt_flags;
38528 + aufs_bindex_t bindex, bbot, bi;
38529 + unsigned char try_trunc;
38530 + struct au_iinfo *iinfo;
38531 + struct super_block *sb;
38532 + struct au_hinode *hi;
38533 + struct inode *h_inode;
38534 + struct au_branch *br;
38535 + struct au_xi_calc calc;
38536 + struct file *file;
38538 + AuDebugOn(au_is_bad_inode(inode));
38540 + sb = inode->i_sb;
38541 + mnt_flags = au_mntflags(sb);
38542 + if (!au_opt_test(mnt_flags, XINO)
38543 + || inode->i_ino == AUFS_ROOT_INO)
38547 + au_xigen_inc(inode);
38548 + au_xib_clear_bit(inode);
38551 + iinfo = au_ii(inode);
38552 + bindex = iinfo->ii_btop;
38556 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38557 + hi = au_hinode(iinfo, bindex);
38558 + bbot = iinfo->ii_bbot;
38559 + for (; bindex <= bbot; bindex++, hi++) {
38560 + h_inode = hi->hi_inode;
38562 + || (!unlinked && h_inode->i_nlink))
38565 + /* inode may not be revalidated */
38566 + bi = au_br_index(sb, hi->hi_id);
38570 + br = au_sbr(sb, bi);
38571 + au_xi_calc(sb, h_inode->i_ino, &calc);
38572 + file = au_xino_file(br->br_xino, calc.idx);
38573 + if (IS_ERR_OR_NULL(file))
38576 + err = au_xino_do_write(file, &calc, /*ino*/0);
38577 + if (!err && try_trunc
38578 + && au_test_fs_trunc_xino(au_br_sb(br)))
38579 + xino_try_trunc(sb, br);
38583 +/* ---------------------------------------------------------------------- */
38585 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38587 + int found, total, i;
38590 + total = xi->xi_nondir.total;
38591 + for (i = 0; i < total; i++) {
38592 + if (xi->xi_nondir.array[i] != h_ino)
38601 +static int au_xinondir_expand(struct au_xino *xi)
38606 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38609 + sz = xi->xi_nondir.total * sizeof(ino_t);
38610 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38612 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38613 + /*may_shrink*/0);
38615 + xi->xi_nondir.array = p;
38616 + xi->xi_nondir.total <<= 1;
38617 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38625 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38626 + ino_t h_ino, int idx)
38628 + struct au_xino *xi;
38630 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38631 + xi = au_sbr(sb, bindex)->br_xino;
38632 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38634 + spin_lock(&xi->xi_nondir.spin);
38635 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38636 + xi->xi_nondir.array[idx] = 0;
38637 + spin_unlock(&xi->xi_nondir.spin);
38638 + wake_up_all(&xi->xi_nondir.wqh);
38641 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38644 + int err, found, empty;
38645 + struct au_xino *xi;
38649 + if (!au_opt_test(au_mntflags(sb), XINO))
38650 + goto out; /* no xino */
38652 + xi = au_sbr(sb, bindex)->br_xino;
38655 + spin_lock(&xi->xi_nondir.spin);
38656 + found = au_xinondir_find(xi, h_ino);
38657 + if (found == -1) {
38658 + empty = au_xinondir_find(xi, /*h_ino*/0);
38659 + if (empty == -1) {
38660 + empty = xi->xi_nondir.total;
38661 + err = au_xinondir_expand(xi);
38662 + if (unlikely(err))
38665 + xi->xi_nondir.array[empty] = h_ino;
38668 + spin_unlock(&xi->xi_nondir.spin);
38669 + wait_event(xi->xi_nondir.wqh,
38670 + xi->xi_nondir.array[found] != h_ino);
38675 + spin_unlock(&xi->xi_nondir.spin);
38680 +/* ---------------------------------------------------------------------- */
38682 +int au_xino_path(struct seq_file *seq, struct file *file)
38686 + err = au_seq_path(seq, &file->f_path);
38687 + if (unlikely(err))
38690 +#define Deleted "\\040(deleted)"
38691 + seq->count -= sizeof(Deleted) - 1;
38692 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38693 + sizeof(Deleted) - 1));
38699 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38700 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38701 +++ linux/include/uapi/linux/aufs_type.h 2021-11-25 11:42:28.836641524 +0100
38703 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38705 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38707 + * This program, aufs is free software; you can redistribute it and/or modify
38708 + * it under the terms of the GNU General Public License as published by
38709 + * the Free Software Foundation; either version 2 of the License, or
38710 + * (at your option) any later version.
38712 + * This program is distributed in the hope that it will be useful,
38713 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38714 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38715 + * GNU General Public License for more details.
38717 + * You should have received a copy of the GNU General Public License
38718 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38721 +#ifndef __AUFS_TYPE_H__
38722 +#define __AUFS_TYPE_H__
38724 +#define AUFS_NAME "aufs"
38728 + * define it before including all other headers.
38729 + * sched.h may use pr_* macros before defining "current", so define the
38730 + * no-current version first, and re-define later.
38732 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38733 +#include <linux/sched.h>
38735 +#define pr_fmt(fmt) \
38736 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38737 + (int)sizeof(current->comm), current->comm, current->pid
38738 +#include <linux/limits.h>
38740 +#include <stdint.h>
38741 +#include <sys/types.h>
38742 +#include <limits.h>
38743 +#endif /* __KERNEL__ */
38745 +#define AUFS_VERSION "5.15-20211115"
38747 +/* todo? move this to linux-2.6.19/include/magic.h */
38748 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38750 +/* ---------------------------------------------------------------------- */
38753 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38754 +typedef int8_t aufs_bindex_t;
38755 +#define AUFS_BRANCH_MAX 127
38757 +typedef int16_t aufs_bindex_t;
38758 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38759 +#define AUFS_BRANCH_MAX 511
38760 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38761 +#define AUFS_BRANCH_MAX 1023
38762 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38763 +#define AUFS_BRANCH_MAX 32767
38767 +#ifndef AUFS_BRANCH_MAX
38768 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38770 +#endif /* __KERNEL__ */
38772 +/* ---------------------------------------------------------------------- */
38774 +#define AUFS_FSTYPE AUFS_NAME
38776 +#define AUFS_ROOT_INO 2
38777 +#define AUFS_FIRST_INO 11
38779 +#define AUFS_WH_PFX ".wh."
38780 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38781 +#define AUFS_WH_TMP_LEN 4
38782 +/* a limit for rmdir/rename a dir and copyup */
38783 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38784 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38786 + - AUFS_WH_TMP_LEN) /* hex */
38787 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38788 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38789 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38790 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38791 +#define AUFS_DIRWH_DEF 3
38792 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38793 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38794 +#define AUFS_RDBLK_DEF 512 /* bytes */
38795 +#define AUFS_RDHASH_DEF 32
38796 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38797 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38798 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38799 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38800 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38802 +/* pseudo-link maintenace under /proc */
38803 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38804 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38805 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38807 +/* dirren, renamed dir */
38808 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38809 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38810 +/* whiteouted doubly */
38811 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38812 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38814 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38815 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38817 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38818 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38819 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38821 +/* doubly whiteouted */
38822 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38823 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38824 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38826 +/* branch permissions and attributes */
38827 +#define AUFS_BRPERM_RW "rw"
38828 +#define AUFS_BRPERM_RO "ro"
38829 +#define AUFS_BRPERM_RR "rr"
38830 +#define AUFS_BRATTR_COO_REG "coo_reg"
38831 +#define AUFS_BRATTR_COO_ALL "coo_all"
38832 +#define AUFS_BRATTR_FHSM "fhsm"
38833 +#define AUFS_BRATTR_UNPIN "unpin"
38834 +#define AUFS_BRATTR_ICEX "icex"
38835 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38836 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38837 +#define AUFS_BRATTR_ICEX_TR "icextr"
38838 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38839 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38840 +#define AUFS_BRRATTR_WH "wh"
38841 +#define AUFS_BRWATTR_NLWH "nolwh"
38842 +#define AUFS_BRWATTR_MOO "moo"
38844 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38845 +#define AuBrPerm_RO (1 << 1) /* readonly */
38846 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38847 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38849 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38850 +#define AuBrAttr_COO_ALL (1 << 4)
38851 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38853 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38854 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38855 + branch. meaningless since
38856 + linux-3.18-rc1 */
38858 +/* ignore error in copying XATTR */
38859 +#define AuBrAttr_ICEX_SEC (1 << 7)
38860 +#define AuBrAttr_ICEX_SYS (1 << 8)
38861 +#define AuBrAttr_ICEX_TR (1 << 9)
38862 +#define AuBrAttr_ICEX_USR (1 << 10)
38863 +#define AuBrAttr_ICEX_OTH (1 << 11)
38864 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38865 + | AuBrAttr_ICEX_SYS \
38866 + | AuBrAttr_ICEX_TR \
38867 + | AuBrAttr_ICEX_USR \
38868 + | AuBrAttr_ICEX_OTH)
38870 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38871 +#define AuBrRAttr_Mask AuBrRAttr_WH
38873 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38874 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38875 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38877 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38879 +/* #warning test userspace */
38881 +#ifndef CONFIG_AUFS_FHSM
38882 +#undef AuBrAttr_FHSM
38883 +#define AuBrAttr_FHSM 0
38885 +#ifndef CONFIG_AUFS_XATTR
38886 +#undef AuBrAttr_ICEX
38887 +#define AuBrAttr_ICEX 0
38888 +#undef AuBrAttr_ICEX_SEC
38889 +#define AuBrAttr_ICEX_SEC 0
38890 +#undef AuBrAttr_ICEX_SYS
38891 +#define AuBrAttr_ICEX_SYS 0
38892 +#undef AuBrAttr_ICEX_TR
38893 +#define AuBrAttr_ICEX_TR 0
38894 +#undef AuBrAttr_ICEX_USR
38895 +#define AuBrAttr_ICEX_USR 0
38896 +#undef AuBrAttr_ICEX_OTH
38897 +#define AuBrAttr_ICEX_OTH 0
38901 +/* the longest combination */
38902 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38903 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38904 + "+" AUFS_BRATTR_COO_REG \
38905 + "+" AUFS_BRATTR_FHSM \
38906 + "+" AUFS_BRATTR_UNPIN \
38907 + "+" AUFS_BRATTR_ICEX_SEC \
38908 + "+" AUFS_BRATTR_ICEX_SYS \
38909 + "+" AUFS_BRATTR_ICEX_USR \
38910 + "+" AUFS_BRATTR_ICEX_OTH \
38911 + "+" AUFS_BRWATTR_NLWH)
38914 + char a[AuBrPermStrSz];
38915 +} au_br_perm_str_t;
38917 +static inline int au_br_writable(int brperm)
38919 + return brperm & AuBrPerm_RW;
38922 +static inline int au_br_whable(int brperm)
38924 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38927 +static inline int au_br_wh_linkable(int brperm)
38929 + return !(brperm & AuBrWAttr_NoLinkWH);
38932 +static inline int au_br_cmoo(int brperm)
38934 + return brperm & AuBrAttr_CMOO_Mask;
38937 +static inline int au_br_fhsm(int brperm)
38939 + return brperm & AuBrAttr_FHSM;
38942 +/* ---------------------------------------------------------------------- */
38946 + /* readdir in userspace */
38950 + AuCtl_WBR_FD, /* pathconf wrapper */
38951 + AuCtl_IBUSY, /* busy inode */
38952 + AuCtl_MVDOWN, /* move-down */
38953 + AuCtl_BR, /* info about branches */
38954 + AuCtl_FHSM_FD /* connection for fhsm */
38957 +/* borrowed from linux/include/linux/kernel.h */
38959 +#ifdef _GNU_SOURCE
38960 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38962 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38964 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38967 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38969 +#define __aligned(x) __attribute__((aligned(x)))
38974 +#define __packed __attribute__((packed))
38978 +struct au_rdu_cookie {
38983 + uint32_t generation;
38986 +struct au_rdu_ent {
38995 +static inline int au_rdu_len(int nlen)
38997 + /* include the terminating NULL */
38998 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38999 + sizeof(uint64_t));
39002 +union au_rdu_ent_ul {
39003 + struct au_rdu_ent __user *e;
39015 + uint64_t sz; /* AuCtl_RDU */
39016 + uint64_t nent; /* AuCtl_RDU_INO */
39018 + union au_rdu_ent_ul ent;
39019 + uint16_t verify[AufsCtlRduV_End];
39021 + /* input/output */
39025 + union au_rdu_ent_ul tail;
39026 + /* number of entries which were added in a single call */
39031 + struct au_rdu_cookie cookie;
39034 +/* ---------------------------------------------------------------------- */
39036 +/* dirren. the branch is identified by the filename who contains this */
39037 +struct au_drinfo {
39040 + uint8_t oldnamelen;
39041 + uint64_t _padding;
39043 + uint8_t oldname[];
39046 +struct au_drinfo_fdata {
39048 + struct au_drinfo drinfo;
39051 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39053 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39055 +/* ---------------------------------------------------------------------- */
39057 +struct aufs_wbr_fd {
39062 +/* ---------------------------------------------------------------------- */
39064 +struct aufs_ibusy {
39065 + uint64_t ino, h_ino;
39069 +/* ---------------------------------------------------------------------- */
39071 +/* error code for move-down */
39072 +/* the actual message strings are implemented in aufs-util.git */
39074 + EAU_MVDOWN_OPAQUE = 1,
39075 + EAU_MVDOWN_WHITEOUT,
39076 + EAU_MVDOWN_UPPER,
39077 + EAU_MVDOWN_BOTTOM,
39078 + EAU_MVDOWN_NOUPPER,
39079 + EAU_MVDOWN_NOLOWERBR,
39083 +/* flags for move-down */
39084 +#define AUFS_MVDOWN_DMSG 1
39085 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39086 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39087 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39088 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39089 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39090 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39091 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39092 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39093 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39094 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39095 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39096 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39098 +/* index for move-down */
39100 + AUFS_MVDOWN_UPPER,
39101 + AUFS_MVDOWN_LOWER,
39102 + AUFS_MVDOWN_NARRAY
39106 + * additional info of move-down
39107 + * number of free blocks and inodes.
39108 + * subset of struct kstatfs, but smaller and always 64bit.
39110 +struct aufs_stfs {
39111 + uint64_t f_blocks;
39112 + uint64_t f_bavail;
39113 + uint64_t f_files;
39114 + uint64_t f_ffree;
39117 +struct aufs_stbr {
39118 + int16_t brid; /* optional input */
39119 + int16_t bindex; /* output */
39120 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39123 +struct aufs_mvdown {
39124 + uint32_t flags; /* input/output */
39125 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39126 + int8_t au_errno; /* output */
39129 +/* ---------------------------------------------------------------------- */
39131 +union aufs_brinfo {
39132 + /* PATH_MAX may differ between kernel-space and user-space */
39133 + char _spacer[4096];
39141 +/* ---------------------------------------------------------------------- */
39143 +#define AuCtlType 'A'
39144 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39145 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39146 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39147 + struct aufs_wbr_fd)
39148 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39149 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39150 + struct aufs_mvdown)
39151 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39152 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39154 +#endif /* __AUFS_TYPE_H__ */
39155 SPDX-License-Identifier: GPL-2.0
39156 aufs5.15 loopback patch
39158 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39159 index a62b132cbd551..79cf20555c2b1 100644
39160 --- a/drivers/block/loop.c
39161 +++ b/drivers/block/loop.c
39162 @@ -685,6 +685,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39166 +static struct file *loop_real_file(struct file *file)
39168 + struct file *f = NULL;
39170 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39171 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39175 static void loop_reread_partitions(struct loop_device *lo)
39178 @@ -742,6 +751,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39180 struct file *file = fget(arg);
39181 struct file *old_file;
39182 + struct file *f, *virt_file = NULL, *old_virt_file;
39186 @@ -761,11 +771,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39187 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39190 + f = loop_real_file(file);
39192 + virt_file = file;
39197 error = loop_validate_file(file, bdev);
39201 old_file = lo->lo_backing_file;
39202 + old_virt_file = lo->lo_backing_virt_file;
39206 @@ -778,6 +796,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39207 blk_mq_freeze_queue(lo->lo_queue);
39208 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39209 lo->lo_backing_file = file;
39210 + lo->lo_backing_virt_file = virt_file;
39211 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39212 mapping_set_gfp_mask(file->f_mapping,
39213 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39214 @@ -800,6 +819,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39218 + if (old_virt_file)
39219 + fput(old_virt_file);
39221 loop_reread_partitions(lo);
39223 @@ -808,6 +829,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39224 loop_global_unlock(lo, is_loop);
39232 @@ -1208,6 +1231,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39233 const struct loop_config *config)
39235 struct file *file = fget(config->fd);
39236 + struct file *f, *virt_file = NULL;
39237 struct inode *inode;
39238 struct address_space *mapping;
39240 @@ -1223,6 +1247,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39241 /* This is safe, since we have a reference from open(). */
39242 __module_get(THIS_MODULE);
39244 + f = loop_real_file(file);
39246 + virt_file = file;
39252 * If we don't hold exclusive handle for the device, upgrade to it
39253 * here to avoid changing device under exclusive owner.
39254 @@ -1288,6 +1319,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39255 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39256 lo->lo_device = bdev;
39257 lo->lo_backing_file = file;
39258 + lo->lo_backing_virt_file = virt_file;
39259 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39260 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39262 @@ -1338,6 +1370,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39263 bd_abort_claiming(bdev, loop_configure);
39268 /* This is safe: open() is still holding a reference. */
39269 module_put(THIS_MODULE);
39271 @@ -1346,6 +1380,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39272 static int __loop_clr_fd(struct loop_device *lo, bool release)
39274 struct file *filp = NULL;
39275 + struct file *virt_filp = lo->lo_backing_virt_file;
39276 gfp_t gfp = lo->old_gfp_mask;
39277 struct block_device *bdev = lo->lo_device;
39279 @@ -1397,6 +1432,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39281 spin_lock_irq(&lo->lo_lock);
39282 lo->lo_backing_file = NULL;
39283 + lo->lo_backing_virt_file = NULL;
39284 spin_unlock_irq(&lo->lo_lock);
39286 loop_release_xfer(lo);
39287 @@ -1477,6 +1513,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39296 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39297 index 04c88dd6eabd6..0ff3ba22ee170 100644
39298 --- a/drivers/block/loop.h
39299 +++ b/drivers/block/loop.h
39300 @@ -46,7 +46,7 @@ struct loop_device {
39301 int (*ioctl)(struct loop_device *, int cmd,
39302 unsigned long arg);
39304 - struct file * lo_backing_file;
39305 + struct file *lo_backing_file, *lo_backing_virt_file;
39306 struct block_device *lo_device;
39309 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39310 index 99ceca1440449..e49dfe8550329 100644
39311 --- a/fs/aufs/f_op.c
39312 +++ b/fs/aufs/f_op.c
39313 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39314 if (IS_ERR(h_file))
39317 - if (au_test_loopback_kthread()) {
39318 + if (0 && au_test_loopback_kthread()) {
39319 au_warn_loopback(h_file->f_path.dentry->d_sb);
39320 if (file->f_mapping != h_file->f_mapping) {
39321 file->f_mapping = h_file->f_mapping;
39322 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39323 index 74347bd75b380..5ef888a1d53f4 100644
39324 --- a/fs/aufs/loop.c
39325 +++ b/fs/aufs/loop.c
39326 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39327 symbol_put(loop_backing_file);
39328 au_kfree_try_rcu(au_warn_loopback_array);
39331 +/* ---------------------------------------------------------------------- */
39333 +/* support the loopback block device insude aufs */
39335 +struct file *aufs_real_loop(struct file *file)
39339 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39340 + fi_read_lock(file);
39341 + f = au_hf_top(file);
39342 + fi_read_unlock(file);
39346 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39347 index 7293bee427f96..3345c098d0d47 100644
39348 --- a/fs/aufs/loop.h
39349 +++ b/fs/aufs/loop.h
39350 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39352 int au_loopback_init(void);
39353 void au_loopback_fin(void);
39355 +struct file *aufs_real_loop(struct file *file);
39357 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39359 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39361 AuStubInt0(au_loopback_init, void)
39362 AuStubVoid(au_loopback_fin, void)
39364 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39365 #endif /* BLK_DEV_LOOP */
39367 #endif /* __KERNEL__ */
39368 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39369 index ae38857541533..af32f0960e595 100644
39370 --- a/fs/aufs/super.c
39371 +++ b/fs/aufs/super.c
39372 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39373 .statfs = aufs_statfs,
39374 .put_super = aufs_put_super,
39375 .sync_fs = aufs_sync_fs,
39376 - .remount_fs = aufs_remount_fs
39377 + .remount_fs = aufs_remount_fs,
39378 +#ifdef CONFIG_AUFS_BDEV_LOOP
39379 + .real_loop = aufs_real_loop
39383 /* ---------------------------------------------------------------------- */
39384 diff --git a/include/linux/fs.h b/include/linux/fs.h
39385 index 376ddf1965aa2..adb8c854de599 100644
39386 --- a/include/linux/fs.h
39387 +++ b/include/linux/fs.h
39388 @@ -2226,6 +2226,10 @@ struct super_operations {
39389 struct shrink_control *);
39390 long (*free_cached_objects)(struct super_block *,
39391 struct shrink_control *);
39392 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39394 + struct file *(*real_loop)(struct file *);