1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index da524c4d7b7e0..50ab89368c2b5 100644
8 @@ -288,6 +288,7 @@ source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/erofs/Kconfig"
11 source "fs/vboxsf/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 999d1a23f036c..0cd76857ca764 100644
20 @@ -136,3 +136,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index bfc1b86e3e733..cf773a5624338 100644
32 @@ -3017,6 +3017,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index e5ff328f09175..39d539df0349d 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -761,6 +761,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index 97e81a844a966..a7522ebbca659 100644
85 @@ -1292,7 +1292,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 05b36b28f2e87..e747a47a97da4 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/inode.c b/fs/inode.c
117 index 6442d97d9a4ab..e4a25c3fa9e55 100644
120 @@ -1769,7 +1769,7 @@ EXPORT_SYMBOL(generic_update_time);
121 * This does the actual work of updating an inodes time or version. Must have
122 * had called mnt_want_write() before calling this.
124 -static int update_time(struct inode *inode, struct timespec64 *time, int flags)
125 +int update_time(struct inode *inode, struct timespec64 *time, int flags)
127 if (inode->i_op->update_time)
128 return inode->i_op->update_time(inode, time, flags);
129 diff --git a/fs/namespace.c b/fs/namespace.c
130 index 9d33909d0f9e3..3e16fc64df8b8 100644
133 @@ -792,6 +792,12 @@ static inline int check_mnt(struct mount *mnt)
134 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137 +/* for aufs, CONFIG_AUFS_BR_FUSE */
138 +int is_current_mnt_ns(struct vfsmount *mnt)
140 + return check_mnt(real_mount(mnt));
144 * vfsmount lock must be held for write
146 diff --git a/fs/splice.c b/fs/splice.c
147 index 866d5c2367b23..55b5356262085 100644
150 @@ -756,8 +756,8 @@ static int warn_unsupported(struct file *file, const char *op)
152 * Attempt to initiate a splice from pipe to file.
154 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
155 - loff_t *ppos, size_t len, unsigned int flags)
156 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
157 + loff_t *ppos, size_t len, unsigned int flags)
159 if (unlikely(!out->f_op->splice_write))
160 return warn_unsupported(out, "write");
161 @@ -767,9 +767,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
163 * Attempt to initiate a splice from a file to a pipe.
165 -static long do_splice_to(struct file *in, loff_t *ppos,
166 - struct pipe_inode_info *pipe, size_t len,
167 - unsigned int flags)
168 +long do_splice_to(struct file *in, loff_t *ppos,
169 + struct pipe_inode_info *pipe, size_t len,
170 + unsigned int flags)
174 diff --git a/fs/sync.c b/fs/sync.c
175 index 1373a610dc784..b7b5a0a0df6ff 100644
179 * wait == 1 case since in that case write_inode() functions do
180 * sync_dirty_buffer() and thus effectively write one block at a time.
182 -static int __sync_filesystem(struct super_block *sb, int wait)
183 +int __sync_filesystem(struct super_block *sb, int wait)
187 diff --git a/include/linux/fs.h b/include/linux/fs.h
188 index fd47deea7c176..91f3fbe5b57ff 100644
189 --- a/include/linux/fs.h
190 +++ b/include/linux/fs.h
191 @@ -1330,6 +1330,7 @@ extern void fasync_free(struct fasync_struct *);
192 /* can be called from interrupts */
193 extern void kill_fasync(struct fasync_struct **, int, int);
195 +extern int setfl(int fd, struct file *filp, unsigned long arg);
196 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
197 extern int f_setown(struct file *filp, unsigned long arg, int force);
198 extern void f_delown(struct file *filp);
199 @@ -1841,6 +1842,7 @@ struct file_operations {
200 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
201 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
202 int (*check_flags)(int);
203 + int (*setfl)(struct file *, unsigned long);
204 int (*flock) (struct file *, int, struct file_lock *);
205 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
206 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
207 @@ -2326,6 +2328,7 @@ extern int current_umask(void);
208 extern void ihold(struct inode * inode);
209 extern void iput(struct inode *);
210 extern int generic_update_time(struct inode *, struct timespec64 *, int);
211 +extern int update_time(struct inode *, struct timespec64 *, int);
214 extern struct kobject *fs_kobj;
215 @@ -2562,6 +2565,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
218 void emergency_thaw_all(void);
219 +extern int __sync_filesystem(struct super_block *, int);
220 extern int sync_filesystem(struct super_block *);
221 extern const struct file_operations def_blk_fops;
222 extern const struct file_operations def_chr_fops;
223 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
224 index b9e9adec73e8b..e152c49cc3163 100644
225 --- a/include/linux/lockdep.h
226 +++ b/include/linux/lockdep.h
227 @@ -241,6 +241,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
228 return lock->key == key;
231 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
236 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
237 index 8f882f5881e87..6b9808f098435 100644
238 --- a/include/linux/mnt_namespace.h
239 +++ b/include/linux/mnt_namespace.h
240 @@ -7,12 +7,15 @@ struct mnt_namespace;
242 struct user_namespace;
246 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
247 struct user_namespace *, struct fs_struct *);
248 extern void put_mnt_ns(struct mnt_namespace *ns);
249 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
251 +extern int is_current_mnt_ns(struct vfsmount *mnt);
253 extern const struct file_operations proc_mounts_operations;
254 extern const struct file_operations proc_mountinfo_operations;
255 extern const struct file_operations proc_mountstats_operations;
256 diff --git a/include/linux/splice.h b/include/linux/splice.h
257 index a55179fd60fc3..8e21c53cf8831 100644
258 --- a/include/linux/splice.h
259 +++ b/include/linux/splice.h
260 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
262 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
263 extern const struct pipe_buf_operations default_pipe_buf_ops;
265 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
266 + loff_t *ppos, size_t len, unsigned int flags);
267 +extern long do_splice_to(struct file *in, loff_t *ppos,
268 + struct pipe_inode_info *pipe, size_t len,
269 + unsigned int flags);
271 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
272 index bdaf4829098c0..5c3bff75de111 100644
273 --- a/kernel/locking/lockdep.c
274 +++ b/kernel/locking/lockdep.c
275 @@ -188,7 +188,7 @@ static
276 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
277 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
279 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
280 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
282 unsigned int class_idx = hlock->class_idx;
284 @@ -209,6 +209,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
286 return lock_classes + class_idx;
288 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
290 #ifdef CONFIG_LOCK_STAT
291 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
292 SPDX-License-Identifier: GPL-2.0
295 diff --git a/fs/proc/base.c b/fs/proc/base.c
296 index b3422cda2a91e..bda8e8ece7208 100644
299 @@ -2184,7 +2184,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
301 vma = find_exact_vma(mm, vm_start, vm_end);
302 if (vma && vma->vm_file) {
303 - *path = vma->vm_file->f_path;
304 + *path = vma_pr_or_file(vma)->f_path;
308 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
309 index 13452b32e2bd5..38acccfef9d49 100644
310 --- a/fs/proc/nommu.c
311 +++ b/fs/proc/nommu.c
312 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
313 file = region->vm_file;
316 - struct inode *inode = file_inode(region->vm_file);
317 + struct inode *inode;
319 + file = vmr_pr_or_file(region);
320 + inode = file_inode(file);
321 dev = inode->i_sb->s_dev;
324 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
325 index 602e3a52884d8..a36614b84de16 100644
326 --- a/fs/proc/task_mmu.c
327 +++ b/fs/proc/task_mmu.c
328 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
329 const char *name = NULL;
332 - struct inode *inode = file_inode(vma->vm_file);
333 + struct inode *inode;
335 + file = vma_pr_or_file(vma);
336 + inode = file_inode(file);
337 dev = inode->i_sb->s_dev;
339 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
340 @@ -1862,7 +1865,7 @@ static int show_numa_map(struct seq_file *m, void *v)
341 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
342 struct vm_area_struct *vma = v;
343 struct numa_maps *md = &numa_priv->md;
344 - struct file *file = vma->vm_file;
345 + struct file *file = vma_pr_or_file(vma);
346 struct mm_struct *mm = vma->vm_mm;
347 struct mempolicy *pol;
349 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
350 index a6d21fc0033c6..02c2de31196e0 100644
351 --- a/fs/proc/task_nommu.c
352 +++ b/fs/proc/task_nommu.c
353 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
357 - struct inode *inode = file_inode(vma->vm_file);
358 + struct inode *inode;
360 + file = vma_pr_or_file(vma);
361 + inode = file_inode(file);
362 dev = inode->i_sb->s_dev;
364 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
365 diff --git a/include/linux/mm.h b/include/linux/mm.h
366 index ecdf8a8cd6aeb..d9b3ec02ecbef 100644
367 --- a/include/linux/mm.h
368 +++ b/include/linux/mm.h
369 @@ -1715,6 +1715,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
370 unmap_mapping_range(mapping, holebegin, holelen, 0);
373 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
374 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
376 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
377 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
379 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
381 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
383 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
384 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
387 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
388 +extern void vmr_do_fput(struct vm_region *, const char[], int);
390 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
392 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
393 +#endif /* !CONFIG_MMU */
395 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
396 void *buf, int len, unsigned int gup_flags);
397 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
398 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
399 index 07d9acb5b19c4..2f395ab624f38 100644
400 --- a/include/linux/mm_types.h
401 +++ b/include/linux/mm_types.h
402 @@ -278,6 +278,7 @@ struct vm_region {
403 unsigned long vm_top; /* region allocated to here */
404 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
405 struct file *vm_file; /* the backing file or NULL */
406 + struct file *vm_prfile; /* the virtual backing file or NULL */
408 int vm_usage; /* region usage count (access under nommu_region_sem) */
409 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
410 @@ -357,6 +358,7 @@ struct vm_area_struct {
411 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
413 struct file * vm_file; /* File we map to (can be NULL). */
414 + struct file *vm_prfile; /* shadow of vm_file */
415 void * vm_private_data; /* was vm_pte (shared mem) */
418 diff --git a/kernel/fork.c b/kernel/fork.c
419 index d66cd1014211b..a2addc21d63fc 100644
422 @@ -555,7 +555,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
423 struct inode *inode = file_inode(file);
424 struct address_space *mapping = file->f_mapping;
428 if (tmp->vm_flags & VM_DENYWRITE)
429 put_write_access(inode);
430 i_mmap_lock_write(mapping);
431 diff --git a/mm/Makefile b/mm/Makefile
432 index b6cd2fffa4922..784e2cebe1eac 100644
435 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
436 mm_init.o percpu.o slab_common.o \
437 compaction.o vmacache.o \
438 interval_tree.o list_lru.o workingset.o \
439 - debug.o gup.o mmap_lock.o $(mmu-y)
440 + prfile.o debug.o gup.o mmap_lock.o $(mmu-y)
442 # Give 'page_alloc' its own module-parameter namespace
443 page-alloc-y := page_alloc.o
444 diff --git a/mm/filemap.c b/mm/filemap.c
445 index aa0e0fb046700..d883a19f4237e 100644
448 @@ -2993,7 +2993,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
449 vm_fault_t ret = VM_FAULT_LOCKED;
451 sb_start_pagefault(mapping->host->i_sb);
452 - file_update_time(vmf->vma->vm_file);
453 + vma_file_update_time(vmf->vma);
455 if (page->mapping != mapping) {
457 diff --git a/mm/mmap.c b/mm/mmap.c
458 index dc7206032387c..09b10e20c097c 100644
461 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
462 if (vma->vm_ops && vma->vm_ops->close)
463 vma->vm_ops->close(vma);
465 - fput(vma->vm_file);
467 mpol_put(vma_policy(vma));
470 @@ -951,7 +951,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
473 uprobe_munmap(next, next->vm_start, next->vm_end);
478 anon_vma_merge(vma, next);
479 @@ -1897,7 +1897,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
483 - fput(vma->vm_file);
487 /* Undo any partial mapping done by a device driver. */
488 @@ -2757,7 +2757,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
492 - get_file(new->vm_file);
495 if (new->vm_ops && new->vm_ops->open)
496 new->vm_ops->open(new);
497 @@ -2776,7 +2776,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
498 if (new->vm_ops && new->vm_ops->close)
499 new->vm_ops->close(new);
501 - fput(new->vm_file);
503 unlink_anon_vmas(new);
505 mpol_put(vma_policy(new));
506 @@ -2969,7 +2969,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
507 struct vm_area_struct *vma;
508 unsigned long populate = 0;
509 unsigned long ret = -EINVAL;
511 + struct file *file, *prfile;
513 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
514 current->comm, current->pid);
515 @@ -3044,10 +3044,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
519 - file = get_file(vma->vm_file);
521 + file = vma->vm_file;
522 + prfile = vma->vm_prfile;
523 ret = do_mmap(vma->vm_file, start, size,
524 prot, flags, pgoff, &populate, NULL);
525 + if (!IS_ERR_VALUE(ret) && file && prfile) {
526 + struct vm_area_struct *new_vma;
528 + new_vma = find_vma(mm, ret);
529 + if (!new_vma->vm_prfile)
530 + new_vma->vm_prfile = prfile;
531 + if (new_vma != vma)
535 + * two fput()s instead of vma_fput(vma),
536 + * coz vma may not be available anymore.
542 mmap_write_unlock(mm);
544 @@ -3334,7 +3351,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
545 if (anon_vma_clone(new_vma, vma))
546 goto out_free_mempol;
547 if (new_vma->vm_file)
548 - get_file(new_vma->vm_file);
549 + vma_get_file(new_vma);
550 if (new_vma->vm_ops && new_vma->vm_ops->open)
551 new_vma->vm_ops->open(new_vma);
552 vma_link(mm, new_vma, prev, rb_link, rb_parent);
553 diff --git a/mm/nommu.c b/mm/nommu.c
554 index 870fea12823e6..edbc99eee5b6b 100644
557 @@ -533,7 +533,7 @@ static void __put_nommu_region(struct vm_region *region)
558 up_write(&nommu_region_sem);
561 - fput(region->vm_file);
564 /* IO memory and memory shared directly out of the pagecache
565 * from ramfs/tmpfs mustn't be released here */
566 @@ -665,7 +665,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
567 if (vma->vm_ops && vma->vm_ops->close)
568 vma->vm_ops->close(vma);
570 - fput(vma->vm_file);
572 put_nommu_region(vma->vm_region);
575 @@ -1188,7 +1188,7 @@ unsigned long do_mmap(struct file *file,
576 goto error_just_free;
579 - fput(region->vm_file);
581 kmem_cache_free(vm_region_jar, region);
584 @@ -1265,10 +1265,10 @@ unsigned long do_mmap(struct file *file,
585 up_write(&nommu_region_sem);
588 - fput(region->vm_file);
590 kmem_cache_free(vm_region_jar, region);
592 - fput(vma->vm_file);
597 diff --git a/mm/prfile.c b/mm/prfile.c
599 index 0000000000000..00d51187c3250
603 +// SPDX-License-Identifier: GPL-2.0
605 + * Mainly for aufs which mmap(2) different file and wants to print different
606 + * path in /proc/PID/maps.
607 + * Call these functions via macros defined in linux/mm.h.
609 + * See Documentation/filesystems/aufs/design/06mmap.txt
611 + * Copyright (c) 2014-2020 Junjro R. Okajima
612 + * Copyright (c) 2014 Ian Campbell
615 +#include <linux/mm.h>
616 +#include <linux/file.h>
617 +#include <linux/fs.h>
619 +/* #define PRFILE_TRACE */
620 +static inline void prfile_trace(struct file *f, struct file *pr,
621 + const char func[], int line, const char func2[])
625 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
629 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
632 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
635 + file_update_time(f);
637 + file_update_time(pr);
640 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
643 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
645 + prfile_trace(f, pr, func, line, __func__);
646 + return (f && pr) ? pr : f;
649 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
651 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
653 + prfile_trace(f, pr, func, line, __func__);
659 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
661 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
663 + prfile_trace(f, pr, func, line, __func__);
670 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
673 + struct file *f = region->vm_file, *pr = region->vm_prfile;
675 + prfile_trace(f, pr, func, line, __func__);
676 + return (f && pr) ? pr : f;
679 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
681 + struct file *f = region->vm_file, *pr = region->vm_prfile;
683 + prfile_trace(f, pr, func, line, __func__);
688 +#endif /* !CONFIG_MMU */
689 SPDX-License-Identifier: GPL-2.0
690 aufs5.11 standalone patch
692 diff --git a/fs/dcache.c b/fs/dcache.c
693 index a7522ebbca659..d429c984133ca 100644
696 @@ -1397,6 +1397,7 @@ void d_walk(struct dentry *parent, void *data,
700 +EXPORT_SYMBOL_GPL(d_walk);
703 struct vfsmount *mnt;
704 @@ -2942,6 +2943,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
706 write_sequnlock(&rename_lock);
708 +EXPORT_SYMBOL_GPL(d_exchange);
711 * d_ancestor - search for an ancestor
712 diff --git a/fs/exec.c b/fs/exec.c
713 index 5d4d52039105c..adc75877cdee7 100644
716 @@ -114,6 +114,7 @@ bool path_noexec(const struct path *path)
717 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
718 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
720 +EXPORT_SYMBOL_GPL(path_noexec);
724 diff --git a/fs/fcntl.c b/fs/fcntl.c
725 index e747a47a97da4..d6211ff25c9a4 100644
728 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
732 +EXPORT_SYMBOL_GPL(setfl);
734 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
736 diff --git a/fs/file_table.c b/fs/file_table.c
737 index 45437f8e1003e..786af52904fcf 100644
738 --- a/fs/file_table.c
739 +++ b/fs/file_table.c
740 @@ -161,6 +161,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
742 return ERR_PTR(-ENFILE);
744 +EXPORT_SYMBOL_GPL(alloc_empty_file);
747 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
748 @@ -375,6 +376,7 @@ void __fput_sync(struct file *file)
752 +EXPORT_SYMBOL_GPL(__fput_sync);
754 void __init files_init(void)
756 diff --git a/fs/inode.c b/fs/inode.c
757 index e4a25c3fa9e55..497326faa1247 100644
760 @@ -1775,6 +1775,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
761 return inode->i_op->update_time(inode, time, flags);
762 return generic_update_time(inode, time, flags);
764 +EXPORT_SYMBOL_GPL(update_time);
767 * touch_atime - update the access time
768 diff --git a/fs/namespace.c b/fs/namespace.c
769 index 3e16fc64df8b8..eed3453ec40a8 100644
772 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
773 mnt_dec_writers(real_mount(mnt));
776 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
779 * mnt_drop_write - give up write access to a mount
780 @@ -797,6 +798,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
782 return check_mnt(real_mount(mnt));
784 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
787 * vfsmount lock must be held for write
788 @@ -1967,6 +1969,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
792 +EXPORT_SYMBOL_GPL(iterate_mounts);
794 static void lock_mnt_tree(struct mount *mnt)
796 diff --git a/fs/notify/group.c b/fs/notify/group.c
797 index a4a4b1c64d32a..86dc2efb1850c 100644
798 --- a/fs/notify/group.c
799 +++ b/fs/notify/group.c
800 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
802 refcount_inc(&group->refcnt);
804 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
807 * Drop a reference to a group. Free it if it's through.
808 diff --git a/fs/open.c b/fs/open.c
809 index 1e06e443a5651..c3bbb8aafcd1a 100644
812 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
813 inode_unlock(dentry->d_inode);
816 +EXPORT_SYMBOL_GPL(do_truncate);
818 long vfs_truncate(const struct path *path, loff_t length)
820 diff --git a/fs/read_write.c b/fs/read_write.c
821 index 75f764b434184..7582bb3fb634b 100644
822 --- a/fs/read_write.c
823 +++ b/fs/read_write.c
824 @@ -503,6 +503,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
828 +EXPORT_SYMBOL_GPL(vfs_read);
830 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
832 @@ -613,6 +614,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
833 file_end_write(file);
836 +EXPORT_SYMBOL_GPL(vfs_write);
838 /* file_ppos returns &file->f_pos or NULL if file is stream */
839 static inline loff_t *file_ppos(struct file *file)
840 diff --git a/fs/splice.c b/fs/splice.c
841 index 55b5356262085..c13ac0fbac318 100644
844 @@ -763,6 +763,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
845 return warn_unsupported(out, "write");
846 return out->f_op->splice_write(pipe, out, ppos, len, flags);
848 +EXPORT_SYMBOL_GPL(do_splice_from);
851 * Attempt to initiate a splice from a file to a pipe.
852 @@ -787,6 +788,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
853 return warn_unsupported(in, "read");
854 return in->f_op->splice_read(in, ppos, pipe, len, flags);
856 +EXPORT_SYMBOL_GPL(do_splice_to);
859 * splice_direct_to_actor - splices data directly between two non-pipes
860 diff --git a/fs/sync.c b/fs/sync.c
861 index b7b5a0a0df6ff..fa5c7fba7f1ba 100644
864 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
865 sb->s_op->sync_fs(sb, wait);
866 return __sync_blockdev(sb->s_bdev, wait);
868 +EXPORT_SYMBOL_GPL(__sync_filesystem);
871 * Write out and wait upon all dirty data associated with this
872 diff --git a/fs/xattr.c b/fs/xattr.c
873 index fd57153b1f617..d8e9d0d6853ef 100644
876 @@ -371,6 +371,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
877 *xattr_value = value;
880 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
883 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
884 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
885 index 5c3bff75de111..ff00031462623 100644
886 --- a/kernel/locking/lockdep.c
887 +++ b/kernel/locking/lockdep.c
888 @@ -209,6 +209,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
890 return lock_classes + class_idx;
892 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
893 #define hlock_class(hlock) lockdep_hlock_class(hlock)
895 #ifdef CONFIG_LOCK_STAT
896 diff --git a/kernel/task_work.c b/kernel/task_work.c
897 index 9cde961875c0a..ac8c79dc81813 100644
898 --- a/kernel/task_work.c
899 +++ b/kernel/task_work.c
900 @@ -143,3 +143,4 @@ void task_work_run(void)
904 +EXPORT_SYMBOL_GPL(task_work_run);
905 diff --git a/security/security.c b/security/security.c
906 index 7b09cfbae94f7..3e060cc948262 100644
907 --- a/security/security.c
908 +++ b/security/security.c
909 @@ -1094,6 +1094,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
911 return call_int_hook(path_rmdir, 0, dir, dentry);
913 +EXPORT_SYMBOL_GPL(security_path_rmdir);
915 int security_path_unlink(const struct path *dir, struct dentry *dentry)
917 @@ -1110,6 +1111,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
919 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
921 +EXPORT_SYMBOL_GPL(security_path_symlink);
923 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
924 struct dentry *new_dentry)
925 @@ -1118,6 +1120,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
927 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
929 +EXPORT_SYMBOL_GPL(security_path_link);
931 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
932 const struct path *new_dir, struct dentry *new_dentry,
933 @@ -1145,6 +1148,7 @@ int security_path_truncate(const struct path *path)
935 return call_int_hook(path_truncate, 0, path);
937 +EXPORT_SYMBOL_GPL(security_path_truncate);
939 int security_path_chmod(const struct path *path, umode_t mode)
941 @@ -1152,6 +1156,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
943 return call_int_hook(path_chmod, 0, path, mode);
945 +EXPORT_SYMBOL_GPL(security_path_chmod);
947 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
949 @@ -1159,6 +1164,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
951 return call_int_hook(path_chown, 0, path, uid, gid);
953 +EXPORT_SYMBOL_GPL(security_path_chown);
955 int security_path_chroot(const struct path *path)
957 @@ -1259,6 +1265,7 @@ int security_inode_permission(struct inode *inode, int mask)
959 return call_int_hook(inode_permission, 0, inode, mask);
961 +EXPORT_SYMBOL_GPL(security_inode_permission);
963 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
965 @@ -1451,6 +1458,7 @@ int security_file_permission(struct file *file, int mask)
967 return fsnotify_perm(file, mask);
969 +EXPORT_SYMBOL_GPL(security_file_permission);
971 int security_file_alloc(struct file *file)
973 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
974 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
975 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-02-24 13:33:42.737680181 +0100
977 +What: /debug/aufs/si_<id>/
979 +Contact: J. R. Okajima <hooanon05g@gmail.com>
981 + Under /debug/aufs, a directory named si_<id> is created
982 + per aufs mount, where <id> is a unique id generated
985 +What: /debug/aufs/si_<id>/plink
987 +Contact: J. R. Okajima <hooanon05g@gmail.com>
989 + It has three lines and shows the information about the
990 + pseudo-link. The first line is a single number
991 + representing a number of buckets. The second line is a
992 + number of pseudo-links per buckets (separated by a
993 + blank). The last line is a single number representing a
994 + total number of psedo-links.
995 + When the aufs mount option 'noplink' is specified, it
996 + will show "1\n0\n0\n".
998 +What: /debug/aufs/si_<id>/xib
1000 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1002 + It shows the consumed blocks by xib (External Inode Number
1003 + Bitmap), its block size and file size.
1004 + When the aufs mount option 'noxino' is specified, it
1005 + will be empty. About XINO files, see the aufs manual.
1007 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1009 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1011 + It shows the consumed blocks by xino (External Inode Number
1012 + Translation Table), its link count, block size and file
1014 + Due to the file size limit, there may exist multiple
1015 + xino files per branch. In this case, "-N" is added to
1016 + the filename and it corresponds to the index of the
1017 + internal xino array. "-0" is omitted.
1018 + When the aufs mount option 'noxino' is specified, Those
1019 + entries won't exist. About XINO files, see the aufs
1022 +What: /debug/aufs/si_<id>/xigen
1024 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1026 + It shows the consumed blocks by xigen (External Inode
1027 + Generation Table), its block size and file size.
1028 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1030 + When the aufs mount option 'noxino' is specified, it
1031 + will be empty. About XINO files, see the aufs manual.
1032 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1033 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1034 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-02-24 13:33:42.737680181 +0100
1036 +What: /sys/fs/aufs/si_<id>/
1038 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1040 + Under /sys/fs/aufs, a directory named si_<id> is created
1041 + per aufs mount, where <id> is a unique id generated
1044 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1046 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1048 + It shows the abolute path of a member directory (which
1049 + is called branch) in aufs, and its permission.
1051 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1053 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1055 + It shows the id of a member directory (which is called
1058 +What: /sys/fs/aufs/si_<id>/xi_path
1060 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1062 + It shows the abolute path of XINO (External Inode Number
1063 + Bitmap, Translation Table and Generation Table) file
1064 + even if it is the default path.
1065 + When the aufs mount option 'noxino' is specified, it
1066 + will be empty. About XINO files, see the aufs manual.
1067 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1068 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1069 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-02-24 13:33:42.737680181 +0100
1072 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1074 +# This program is free software; you can redistribute it and/or modify
1075 +# it under the terms of the GNU General Public License as published by
1076 +# the Free Software Foundation; either version 2 of the License, or
1077 +# (at your option) any later version.
1079 +# This program is distributed in the hope that it will be useful,
1080 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1081 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1082 +# GNU General Public License for more details.
1084 +# You should have received a copy of the GNU General Public License
1085 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1088 +----------------------------------------
1090 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1091 +1. abbrev. for "advanced multi-layered unification filesystem".
1092 +2. abbrev. for "another unionfs".
1093 +3. abbrev. for "auf das" in German which means "on the" in English.
1094 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1095 + But "Filesystem aufs Filesystem" is hard to understand.
1096 +4. abbrev. for "African Urban Fashion Show".
1098 +AUFS is a filesystem with features:
1099 +- multi layered stackable unification filesystem, the member directory
1100 + is called as a branch.
1101 +- branch permission and attribute, 'readonly', 'real-readonly',
1102 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1104 +- internal "file copy-on-write".
1105 +- logical deletion, whiteout.
1106 +- dynamic branch manipulation, adding, deleting and changing permission.
1107 +- allow bypassing aufs, user's direct branch access.
1108 +- external inode number translation table and bitmap which maintains the
1109 + persistent aufs inode number.
1110 +- seekable directory, including NFS readdir.
1111 +- file mapping, mmap and sharing pages.
1112 +- pseudo-link, hardlink over branches.
1113 +- loopback mounted filesystem as a branch.
1114 +- several policies to select one among multiple writable branches.
1115 +- revert a single systemcall when an error occurs in aufs.
1119 +Multi Layered Stackable Unification Filesystem
1120 +----------------------------------------------------------------------
1121 +Most people already knows what it is.
1122 +It is a filesystem which unifies several directories and provides a
1123 +merged single directory. When users access a file, the access will be
1124 +passed/re-directed/converted (sorry, I am not sure which English word is
1125 +correct) to the real file on the member filesystem. The member
1126 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1127 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1128 +readonly branch is handled by creating 'whiteout' on the upper writable
1131 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1132 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1133 +different approaches to implement the merged-view.
1134 +The former tries putting it into VFS, and the latter implements as a
1135 +separate filesystem.
1136 +(If I misunderstand about these implementations, please let me know and
1137 +I shall correct it. Because it is a long time ago when I read their
1138 +source files last time).
1140 +UnionMount's approach will be able to small, but may be hard to share
1141 +branches between several UnionMount since the whiteout in it is
1142 +implemented in the inode on branch filesystem and always
1143 +shared. According to Bharata's post, readdir does not seems to be
1145 +There are several missing features known in this implementations such as
1146 +- for users, the inode number may change silently. eg. copy-up.
1147 +- link(2) may break by copy-up.
1148 +- read(2) may get an obsoleted filedata (fstat(2) too).
1149 +- fcntl(F_SETLK) may be broken by copy-up.
1150 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1153 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1154 +merged into mainline. This is another implementation of UnionMount as a
1155 +separated filesystem. All the limitations and known problems which
1156 +UnionMount are equally inherited to "overlay" filesystem.
1158 +Unionfs has a longer history. When I started implementing a stackable
1159 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1160 +inode, dentry and file objects and they have an array pointing lower
1161 +same kind objects. After contributing many patches for Unionfs, I
1162 +re-started my project AUFS (Jun 2006).
1164 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1165 +implemented my own ideas, approaches and enhancements and it became
1166 +totally different one.
1168 +Comparing DM snapshot and fs based implementation
1169 +- the number of bytes to be copied between devices is much smaller.
1170 +- the type of filesystem must be one and only.
1171 +- the fs must be writable, no readonly fs, even for the lower original
1172 + device. so the compression fs will not be usable. but if we use
1173 + loopback mount, we may address this issue.
1175 + mount /cdrom/squashfs.img /sq
1176 + losetup /sq/ext2.img
1177 + losetup /somewhere/cow
1178 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1179 +- it will be difficult (or needs more operations) to extract the
1180 + difference between the original device and COW.
1181 +- DM snapshot-merge may help a lot when users try merging. in the
1182 + fs-layer union, users will use rsync(1).
1184 +You may want to read my old paper "Filesystems in LiveCD"
1185 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1188 +Several characters/aspects/persona of aufs
1189 +----------------------------------------------------------------------
1191 +Aufs has several characters, aspects or persona.
1192 +1. a filesystem, callee of VFS helper
1193 +2. sub-VFS, caller of VFS helper for branches
1194 +3. a virtual filesystem which maintains persistent inode number
1195 +4. reader/writer of files on branches such like an application
1197 +1. Callee of VFS Helper
1198 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1199 +unlink(2) from an application reaches sys_unlink() kernel function and
1200 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1201 +calls filesystem specific unlink operation. Actually aufs implements the
1202 +unlink operation but it behaves like a redirector.
1204 +2. Caller of VFS Helper for Branches
1205 +aufs_unlink() passes the unlink request to the branch filesystem as if
1206 +it were called from VFS. So the called unlink operation of the branch
1207 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1208 +every necessary pre/post operation for the branch filesystem.
1209 +- acquire the lock for the parent dir on a branch
1210 +- lookup in a branch
1211 +- revalidate dentry on a branch
1212 +- mnt_want_write() for a branch
1213 +- vfs_unlink() for a branch
1214 +- mnt_drop_write() for a branch
1215 +- release the lock on a branch
1217 +3. Persistent Inode Number
1218 +One of the most important issue for a filesystem is to maintain inode
1219 +numbers. This is particularly important to support exporting a
1220 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1221 +backend block device for its own. But some storage is necessary to
1222 +keep and maintain the inode numbers. It may be a large space and may not
1223 +suit to keep in memory. Aufs rents some space from its first writable
1224 +branch filesystem (by default) and creates file(s) on it. These files
1225 +are created by aufs internally and removed soon (currently) keeping
1227 +Note: Because these files are removed, they are totally gone after
1228 + unmounting aufs. It means the inode numbers are not persistent
1229 + across unmount or reboot. I have a plan to make them really
1230 + persistent which will be important for aufs on NFS server.
1232 +4. Read/Write Files Internally (copy-on-write)
1233 +Because a branch can be readonly, when you write a file on it, aufs will
1234 +"copy-up" it to the upper writable branch internally. And then write the
1235 +originally requested thing to the file. Generally kernel doesn't
1236 +open/read/write file actively. In aufs, even a single write may cause a
1237 +internal "file copy". This behaviour is very similar to cp(1) command.
1239 +Some people may think it is better to pass such work to user space
1240 +helper, instead of doing in kernel space. Actually I am still thinking
1241 +about it. But currently I have implemented it in kernel space.
1242 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1243 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1244 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-02-24 13:33:42.737680181 +0100
1247 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1249 +# This program is free software; you can redistribute it and/or modify
1250 +# it under the terms of the GNU General Public License as published by
1251 +# the Free Software Foundation; either version 2 of the License, or
1252 +# (at your option) any later version.
1254 +# This program is distributed in the hope that it will be useful,
1255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1257 +# GNU General Public License for more details.
1259 +# You should have received a copy of the GNU General Public License
1260 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1262 +Basic Aufs Internal Structure
1264 +Superblock/Inode/Dentry/File Objects
1265 +----------------------------------------------------------------------
1266 +As like an ordinary filesystem, aufs has its own
1267 +superblock/inode/dentry/file objects. All these objects have a
1268 +dynamically allocated array and store the same kind of pointers to the
1269 +lower filesystem, branch.
1270 +For example, when you build a union with one readwrite branch and one
1271 +readonly, mounted /au, /rw and /ro respectively.
1273 +- /ro/fileA exists but /rw/fileA
1275 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1276 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1277 +- [0] = NULL (because /rw/fileA doesn't exist)
1280 +This style of an array is essentially same to the aufs
1281 +superblock/inode/dentry/file objects.
1283 +Because aufs supports manipulating branches, ie. add/delete/change
1284 +branches dynamically, these objects has its own generation. When
1285 +branches are changed, the generation in aufs superblock is
1286 +incremented. And a generation in other object are compared when it is
1287 +accessed. When a generation in other objects are obsoleted, aufs
1288 +refreshes the internal array.
1292 +----------------------------------------------------------------------
1293 +Additionally aufs superblock has some data for policies to select one
1294 +among multiple writable branches, XIB files, pseudo-links and kobject.
1295 +See below in detail.
1296 +About the policies which supports copy-down a directory, see
1297 +wbr_policy.txt too.
1300 +Branch and XINO(External Inode Number Translation Table)
1301 +----------------------------------------------------------------------
1302 +Every branch has its own xino (external inode number translation table)
1303 +file. The xino file is created and unlinked by aufs internally. When two
1304 +members of a union exist on the same filesystem, they share the single
1306 +The struct of a xino file is simple, just a sequence of aufs inode
1307 +numbers which is indexed by the lower inode number.
1308 +In the above sample, assume the inode number of /ro/fileA is i111 and
1309 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1310 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1312 +When the inode numbers are not contiguous, the xino file will be sparse
1313 +which has a hole in it and doesn't consume as much disk space as it
1314 +might appear. If your branch filesystem consumes disk space for such
1315 +holes, then you should specify 'xino=' option at mounting aufs.
1317 +Aufs has a mount option to free the disk blocks for such holes in XINO
1318 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1319 +meet a problem of disk shortage due to XINO files, then you should try
1320 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1321 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1322 +the holes in XINO files.
1324 +Also a writable branch has three kinds of "whiteout bases". All these
1325 +are existed when the branch is joined to aufs, and their names are
1326 +whiteout-ed doubly, so that users will never see their names in aufs
1328 +1. a regular file which will be hardlinked to all whiteouts.
1329 +2. a directory to store a pseudo-link.
1330 +3. a directory to store an "orphan"-ed file temporary.
1333 + When you remove a file on a readonly branch, aufs handles it as a
1334 + logical deletion and creates a whiteout on the upper writable branch
1335 + as a hardlink of this file in order not to consume inode on the
1338 + See below, Pseudo-link.
1340 + When "fileC" exists on the lower readonly branch only and it is
1341 + opened and removed with its parent dir, and then user writes
1342 + something into it, then aufs copies-up fileC to this
1343 + directory. Because there is no other dir to store fileC. After
1344 + creating a file under this dir, the file is unlinked.
1346 +Because aufs supports manipulating branches, ie. add/delete/change
1347 +dynamically, a branch has its own id. When the branch order changes,
1348 +aufs finds the new index by searching the branch id.
1352 +----------------------------------------------------------------------
1353 +Assume "fileA" exists on the lower readonly branch only and it is
1354 +hardlinked to "fileB" on the branch. When you write something to fileA,
1355 +aufs copies-up it to the upper writable branch. Additionally aufs
1356 +creates a hardlink under the Pseudo-link Directory of the writable
1357 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1358 +simple list. If fileB is read after unlinking fileA, aufs returns
1359 +filedata from the pseudo-link instead of the lower readonly
1360 +branch. Because the pseudo-link is based upon the inode, to keep the
1361 +inode number by xino (see above) is essentially necessary.
1363 +All the hardlinks under the Pseudo-link Directory of the writable branch
1364 +should be restored in a proper location later. Aufs provides a utility
1365 +to do this. The userspace helpers executed at remounting and unmounting
1367 +During this utility is running, it puts aufs into the pseudo-link
1368 +maintenance mode. In this mode, only the process which began the
1369 +maintenance mode (and its child processes) is allowed to operate in
1370 +aufs. Some other processes which are not related to the pseudo-link will
1371 +be allowed to run too, but the rest have to return an error or wait
1372 +until the maintenance mode ends. If a process already acquires an inode
1373 +mutex (in VFS), it has to return an error.
1376 +XIB(external inode number bitmap)
1377 +----------------------------------------------------------------------
1378 +Addition to the xino file per a branch, aufs has an external inode number
1379 +bitmap in a superblock object. It is also an internal file such like a
1381 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1383 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1385 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1386 +reduce the number of consumed disk blocks for these files.
1389 +Virtual or Vertical Dir, and Readdir in Userspace
1390 +----------------------------------------------------------------------
1391 +In order to support multiple layers (branches), aufs readdir operation
1392 +constructs a virtual dir block on memory. For readdir, aufs calls
1393 +vfs_readdir() internally for each dir on branches, merges their entries
1394 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1395 +object. So the file object has its entry list until it is closed. The
1396 +entry list will be updated when the file position is zero and becomes
1397 +obsoleted. This decision is made in aufs automatically.
1399 +The dynamically allocated memory block for the name of entries has a
1400 +unit of 512 bytes (by default) and stores the names contiguously (no
1401 +padding). Another block for each entry is handled by kmem_cache too.
1402 +During building dir blocks, aufs creates hash list and judging whether
1403 +the entry is whiteouted by its upper branch or already listed.
1404 +The merged result is cached in the corresponding inode object and
1405 +maintained by a customizable life-time option.
1407 +Some people may call it can be a security hole or invite DoS attack
1408 +since the opened and once readdir-ed dir (file object) holds its entry
1409 +list and becomes a pressure for system memory. But I'd say it is similar
1410 +to files under /proc or /sys. The virtual files in them also holds a
1411 +memory page (generally) while they are opened. When an idea to reduce
1412 +memory for them is introduced, it will be applied to aufs too.
1413 +For those who really hate this situation, I've developed readdir(3)
1414 +library which operates this merging in userspace. You just need to set
1415 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1416 +kernel space for readdir(3).
1420 +----------------------------------------------------------------------
1421 +Aufs sometimes requires privilege access to a branch. For instance,
1422 +in copy-up/down operation. When a user process is going to make changes
1423 +to a file which exists in the lower readonly branch only, and the mode
1424 +of one of ancestor directories may not be writable by a user
1425 +process. Here aufs copy-up the file with its ancestors and they may
1426 +require privilege to set its owner/group/mode/etc.
1427 +This is a typical case of a application character of aufs (see
1430 +Aufs uses workqueue synchronously for this case. It creates its own
1431 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1432 +passes the request to call mkdir or write (for example), and wait for
1433 +its completion. This approach solves a problem of a signal handler
1435 +If aufs didn't adopt the workqueue and changed the privilege of the
1436 +process, then the process may receive the unexpected SIGXFSZ or other
1439 +Also aufs uses the system global workqueue ("events" kernel thread) too
1440 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1441 +whiteout base and etc. This is unrelated to a privilege.
1442 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1443 +superblock at the beginning, at the same time waits for the completion
1444 +of all queued asynchronous tasks.
1448 +----------------------------------------------------------------------
1449 +The whiteout in aufs is very similar to Unionfs's. That is represented
1450 +by its filename. UnionMount takes an approach of a file mode, but I am
1451 +afraid several utilities (find(1) or something) will have to support it.
1453 +Basically the whiteout represents "logical deletion" which stops aufs to
1454 +lookup further, but also it represents "dir is opaque" which also stop
1457 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1458 +In order to make several functions in a single systemcall to be
1459 +revertible, aufs adopts an approach to rename a directory to a temporary
1460 +unique whiteouted name.
1461 +For example, in rename(2) dir where the target dir already existed, aufs
1462 +renames the target dir to a temporary unique whiteouted name before the
1463 +actual rename on a branch, and then handles other actions (make it opaque,
1464 +update the attributes, etc). If an error happens in these actions, aufs
1465 +simply renames the whiteouted name back and returns an error. If all are
1466 +succeeded, aufs registers a function to remove the whiteouted unique
1467 +temporary name completely and asynchronously to the system global
1472 +----------------------------------------------------------------------
1473 +It is a well-known feature or concept.
1474 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1475 +internally and makes change to the new file on the upper writable branch.
1476 +When the trigger systemcall does not update the timestamps of the parent
1477 +dir, aufs reverts it after copy-up.
1480 +Move-down (aufs3.9 and later)
1481 +----------------------------------------------------------------------
1482 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1483 +the lower readonly branch to the upper writable branch when a user
1484 +changes something about the file.
1485 +"Move-down" is an opposite action of copy-up. Basically this action is
1486 +ran manually instead of automatically and internally.
1487 +For desgin and implementation, aufs has to consider these issues.
1488 +- whiteout for the file may exist on the lower branch.
1489 +- ancestor directories may not exist on the lower branch.
1490 +- diropq for the ancestor directories may exist on the upper branch.
1491 +- free space on the lower branch will reduce.
1492 +- another access to the file may happen during moving-down, including
1493 + UDBA (see "Revalidate Dentry and UDBA").
1494 +- the file should not be hard-linked nor pseudo-linked. they should be
1495 + handled by auplink utility later.
1497 +Sometimes users want to move-down a file from the upper writable branch
1498 +to the lower readonly or writable branch. For instance,
1499 +- the free space of the upper writable branch is going to run out.
1500 +- create a new intermediate branch between the upper and lower branch.
1503 +For this purpose, use "aumvdown" command in aufs-util.git.
1504 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1505 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1506 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-02-24 13:33:42.737680181 +0100
1509 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1511 +# This program is free software; you can redistribute it and/or modify
1512 +# it under the terms of the GNU General Public License as published by
1513 +# the Free Software Foundation; either version 2 of the License, or
1514 +# (at your option) any later version.
1516 +# This program is distributed in the hope that it will be useful,
1517 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1518 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1519 +# GNU General Public License for more details.
1521 +# You should have received a copy of the GNU General Public License
1522 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1524 +Support for a branch who has its ->atomic_open()
1525 +----------------------------------------------------------------------
1526 +The filesystems who implement its ->atomic_open() are not majority. For
1527 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1528 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1529 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1530 +sure whether all filesystems who have ->atomic_open() behave like this,
1531 +but NFSv4 surely returns the error.
1533 +In order to support ->atomic_open() for aufs, there are a few
1536 +A. Introduce aufs_atomic_open()
1537 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1539 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1540 + an aufs user Pip Cet's approach
1541 + - calls aufs_create(), VFS finish_open() and notify_change().
1542 + - pass fake-mode to finish_open(), and then correct the mode by
1544 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1545 + - no aufs_atomic_open().
1546 + - aufs_lookup() registers the TID to an aufs internal object.
1547 + - aufs_create() does nothing when the matching TID is registered, but
1548 + registers the mode.
1549 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1550 + TID is registered.
1551 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1553 + - no aufs_atomic_open().
1554 + - aufs_create() registers the TID to an internal object. this info
1555 + represents "this process created this file just now."
1556 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1557 + registered TID and re-try open() with superuser's credential.
1559 +Pros and cons for each approach.
1562 + - straightforward but highly depends upon VFS internal.
1563 + - the atomic behavaiour is kept.
1564 + - some of parameters such as nameidata are hard to reproduce for
1568 + - easy to implement.
1569 + - the atomic behavaiour is lost.
1571 + - the atomic behavaiour is kept.
1572 + - dirty and tricky.
1573 + - VFS checks whether the file is created correctly after calling
1574 + ->create(), which means this approach doesn't work.
1576 + - easy to implement.
1577 + - the atomic behavaiour is lost.
1578 + - to open a file with superuser's credential and give it to a user
1579 + process is a bad idea, since the file object keeps the credential
1580 + in it. It may affect LSM or something. This approach doesn't work
1583 +The approach A is ideal, but it hard to implement. So here is a
1584 +variation of A, which is to be implemented.
1586 +A-1. Introduce aufs_atomic_open()
1587 + - calls branch fs ->atomic_open() if exists. otherwise calls
1588 + vfs_create() and finish_open().
1589 + - the demerit is that the several checks after branch fs
1590 + ->atomic_open() are lost. in the ordinary case, the checks are
1591 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1592 + be implemented in aufs, but not all I am afraid.
1593 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1594 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1595 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-02-24 13:33:42.737680181 +0100
1598 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1600 +# This program is free software; you can redistribute it and/or modify
1601 +# it under the terms of the GNU General Public License as published by
1602 +# the Free Software Foundation; either version 2 of the License, or
1603 +# (at your option) any later version.
1605 +# This program is distributed in the hope that it will be useful,
1606 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1607 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1608 +# GNU General Public License for more details.
1610 +# You should have received a copy of the GNU General Public License
1611 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1614 +----------------------------------------------------------------------
1615 +Since aufs has a character of sub-VFS (see Introduction), it operates
1616 +lookup for branches as VFS does. It may be a heavy work. But almost all
1617 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1618 +directly connected to its parent. Digging down the directory hierarchy
1619 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1622 +When a branch is a remote filesystem, aufs basically relies upon its
1623 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1625 +For d_revalidate, aufs implements three levels of revalidate tests. See
1626 +"Revalidate Dentry and UDBA" in detail.
1629 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1630 +----------------------------------------------------------------------
1631 +Let's try case study.
1632 +- aufs has two branches, upper readwrite and lower readonly.
1634 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1635 +- user invoked "chmod a+rx /au/dirA"
1636 +- the internal copy-up is activated and "/rw/dirA" is created and its
1637 + permission bits are set to world readable.
1638 +- then "/au/dirA" becomes world readable?
1640 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1641 +or it may be a natively readonly filesystem. If aufs respects the lower
1642 +branch, it should not respond readdir request from other users. But user
1643 +allowed it by chmod. Should really aufs rejects showing the entries
1646 +To be honest, I don't have a good solution for this case. So aufs
1647 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1649 +When dirperm1 is specified, aufs checks only the highest one for the
1650 +directory permission, and shows the entries. Otherwise, as usual, checks
1651 +every dir existing on all branches and rejects the request.
1653 +As a side effect, dirperm1 option improves the performance of aufs
1654 +because the number of permission check is reduced when the number of
1658 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1659 +----------------------------------------------------------------------
1660 +Generally VFS helpers re-validate a dentry as a part of lookup.
1661 +0. digging down the directory hierarchy.
1662 +1. lock the parent dir by its i_mutex.
1663 +2. lookup the final (child) entry.
1665 +4. call the actual operation (create, unlink, etc.)
1666 +5. unlock the parent dir
1668 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1669 +called. Actually aufs implements it and checks the dentry on a branch is
1671 +But it is not enough. Because aufs has to release the lock for the
1672 +parent dir on a branch at the end of ->lookup() (step 2) and
1673 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1675 +If the file on a branch is changed directly, eg. bypassing aufs, after
1676 +aufs released the lock, then the subsequent operation may cause
1677 +something unpleasant result.
1679 +This situation is a result of VFS architecture, ->lookup() and
1680 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1681 +design from VFS's point of view. It is just not suitable for sub-VFS
1684 +Aufs supports such case by three level of revalidation which is
1685 +selectable by user.
1686 +1. Simple Revalidate
1687 + Addition to the native flow in VFS's, confirm the child-parent
1688 + relationship on the branch just after locking the parent dir on the
1689 + branch in the "actual operation" (step 4). When this validation
1690 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1691 + checks the validation of the dentry on branches.
1692 +2. Monitor Changes Internally by Inotify/Fsnotify
1693 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1694 + the dentry on the branch, and returns EBUSY if it finds different
1696 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1697 + during it is in cache. When the event is notified, aufs registers a
1698 + function to kernel 'events' thread by schedule_work(). And the
1699 + function sets some special status to the cached aufs dentry and inode
1700 + private data. If they are not cached, then aufs has nothing to
1701 + do. When the same file is accessed through aufs (step 0-3) later,
1702 + aufs will detect the status and refresh all necessary data.
1703 + In this mode, aufs has to ignore the event which is fired by aufs
1705 +3. No Extra Validation
1706 + This is the simplest test and doesn't add any additional revalidation
1707 + test, and skip the revalidation in step 4. It is useful and improves
1708 + aufs performance when system surely hide the aufs branches from user,
1709 + by over-mounting something (or another method).
1710 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1711 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1712 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-02-24 13:33:42.737680181 +0100
1715 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1717 +# This program is free software; you can redistribute it and/or modify
1718 +# it under the terms of the GNU General Public License as published by
1719 +# the Free Software Foundation; either version 2 of the License, or
1720 +# (at your option) any later version.
1722 +# This program is distributed in the hope that it will be useful,
1723 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1724 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1725 +# GNU General Public License for more details.
1727 +# You should have received a copy of the GNU General Public License
1728 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1730 +Branch Manipulation
1732 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1733 +and changing its permission/attribute, there are a lot of works to do.
1737 +----------------------------------------------------------------------
1738 +o Confirm the adding dir exists outside of aufs, including loopback
1739 + mount, and its various attributes.
1740 +o Initialize the xino file and whiteout bases if necessary.
1743 +o Check the owner/group/mode of the directory
1744 + When the owner/group/mode of the adding directory differs from the
1745 + existing branch, aufs issues a warning because it may impose a
1747 + For example, when a upper writable branch has a world writable empty
1748 + top directory, a malicious user can create any files on the writable
1749 + branch directly, like copy-up and modify manually. If something like
1750 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1751 + writable branch, and the writable branch is world-writable, then a
1752 + malicious guy may create /etc/passwd on the writable branch directly
1753 + and the infected file will be valid in aufs.
1754 + I am afraid it can be a security issue, but aufs can do nothing except
1755 + producing a warning.
1759 +----------------------------------------------------------------------
1760 +o Confirm the deleting branch is not busy
1761 + To be general, there is one merit to adopt "remount" interface to
1762 + manipulate branches. It is to discard caches. At deleting a branch,
1763 + aufs checks the still cached (and connected) dentries and inodes. If
1764 + there are any, then they are all in-use. An inode without its
1765 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1767 + For the cached one, aufs checks whether the same named entry exists on
1769 + If the cached one is a directory, because aufs provides a merged view
1770 + to users, as long as one dir is left on any branch aufs can show the
1771 + dir to users. In this case, the branch can be removed from aufs.
1772 + Otherwise aufs rejects deleting the branch.
1774 + If any file on the deleting branch is opened by aufs, then aufs
1778 +Modify the Permission of a Branch
1779 +----------------------------------------------------------------------
1780 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1783 +o rw --> ro: Confirm the modifying branch is not busy
1784 + Aufs rejects the request if any of these conditions are true.
1785 + - a file on the branch is mmap-ed.
1786 + - a regular file on the branch is opened for write and there is no
1787 + same named entry on the upper branch.
1788 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1789 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1790 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-02-24 13:33:42.737680181 +0100
1793 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1795 +# This program is free software; you can redistribute it and/or modify
1796 +# it under the terms of the GNU General Public License as published by
1797 +# the Free Software Foundation; either version 2 of the License, or
1798 +# (at your option) any later version.
1800 +# This program is distributed in the hope that it will be useful,
1801 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1802 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1803 +# GNU General Public License for more details.
1805 +# You should have received a copy of the GNU General Public License
1806 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1808 +Policies to Select One among Multiple Writable Branches
1809 +----------------------------------------------------------------------
1810 +When the number of writable branch is more than one, aufs has to decide
1811 +the target branch for file creation or copy-up. By default, the highest
1812 +writable branch which has the parent (or ancestor) dir of the target
1813 +file is chosen (top-down-parent policy).
1814 +By user's request, aufs implements some other policies to select the
1815 +writable branch, for file creation several policies, round-robin,
1816 +most-free-space, and other policies. For copy-up, top-down-parent,
1817 +bottom-up-parent, bottom-up and others.
1819 +As expected, the round-robin policy selects the branch in circular. When
1820 +you have two writable branches and creates 10 new files, 5 files will be
1821 +created for each branch. mkdir(2) systemcall is an exception. When you
1822 +create 10 new directories, all will be created on the same branch.
1823 +And the most-free-space policy selects the one which has most free
1824 +space among the writable branches. The amount of free space will be
1825 +checked by aufs internally, and users can specify its time interval.
1827 +The policies for copy-up is more simple,
1828 +top-down-parent is equivalent to the same named on in create policy,
1829 +bottom-up-parent selects the writable branch where the parent dir
1830 +exists and the nearest upper one from the copyup-source,
1831 +bottom-up selects the nearest upper writable branch from the
1832 +copyup-source, regardless the existence of the parent dir.
1834 +There are some rules or exceptions to apply these policies.
1835 +- If there is a readonly branch above the policy-selected branch and
1836 + the parent dir is marked as opaque (a variation of whiteout), or the
1837 + target (creating) file is whiteout-ed on the upper readonly branch,
1838 + then the result of the policy is ignored and the target file will be
1839 + created on the nearest upper writable branch than the readonly branch.
1840 +- If there is a writable branch above the policy-selected branch and
1841 + the parent dir is marked as opaque or the target file is whiteouted
1842 + on the branch, then the result of the policy is ignored and the target
1843 + file will be created on the highest one among the upper writable
1844 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1846 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1847 + They try selecting the branch where the source exists as possible
1848 + since copyup a large file will take long time. If it can't be,
1849 + ie. the branch where the source exists is readonly, then they will
1850 + follow the copyup policy.
1851 +- There is an exception for rename(2) when the target exists.
1852 + If the rename target exists, aufs compares the index of the branches
1853 + where the source and the target exists and selects the higher
1854 + one. If the selected branch is readonly, then aufs follows the
1856 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1857 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1858 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-02-24 13:33:42.737680181 +0100
1861 +// to view this graph, run dot(1) command in GRAPHVIZ.
1865 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1869 +aufs_rename -> whinfo [label="store/remove"];
1872 +inode_list [label="h_inum list in branch\ncache"];
1875 +whinode [label="h_inum list file"];
1878 +brmgmt [label="br_add/del/mod/umount"];
1880 +brmgmt -> inode_list [label="create/remove"];
1881 +brmgmt -> whinode [label="load/store"];
1883 +inode_list -> whinode [style=dashed,dir=both];
1885 +aufs_rename -> inode_list [label="add/del"];
1887 +aufs_lookup -> inode_list [label="search"];
1889 +aufs_lookup -> whinfo [label="load/remove"];
1891 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1892 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1893 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-02-24 13:33:42.737680181 +0100
1896 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1898 +# This program is free software; you can redistribute it and/or modify
1899 +# it under the terms of the GNU General Public License as published by
1900 +# the Free Software Foundation; either version 2 of the License, or
1901 +# (at your option) any later version.
1903 +# This program is distributed in the hope that it will be useful,
1904 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1905 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1906 +# GNU General Public License for more details.
1908 +# You should have received a copy of the GNU General Public License
1909 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1911 +Special handling for renaming a directory (DIRREN)
1912 +----------------------------------------------------------------------
1913 +First, let's assume we have a simple usecase.
1917 +- /ro/dirA and /ro/dirA/file exist too
1918 +- there is no dirB on both branches
1919 +- a user issues rename("dirA", "dirB")
1921 +Now, what should aufs behave against this rename(2)?
1922 +There are a few possible cases.
1925 + since dirA exists on a readonly branch which cannot be renamed.
1927 + it is possible to copy-up dirA (only the dir itself), but the child
1928 + entries ("file" in this case) should not be. it must be a bad
1929 + approach to copy-up recursively.
1930 +C. returns a success.
1931 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1932 + is a violation of aufs' policy.
1933 +D. construct an extra information which indicates that /ro/dirA should
1934 + be handled as the name of dirB.
1935 + overlayfs has a similar feature called REDIRECT.
1937 +Until now, aufs implements the case B only which returns EXDEV, and
1938 +expects the userspace application behaves like mv(1) which tries
1939 +issueing rename(2) recursively.
1941 +A new aufs feature called DIRREN is introduced which implements the case
1942 +D. There are several "extra information" added.
1944 +1. detailed info per renamed directory
1945 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1946 +2. the inode-number list of directories on a branch
1947 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1949 +The filename of "detailed info per directory" represents the lower
1950 +branch, and its format is
1951 +- a type of the branch id
1953 + + uuid (not implemented yet)
1956 +- the inode-number of the branch root dir
1958 +And it contains these info in a single regular file.
1960 +- branch's inode-number of the logically renamed dir
1961 +- the name of the before-renamed dir
1963 +The "detailed info per directory" file is created in aufs rename(2), and
1964 +loaded in any lookup.
1965 +The info is considered in lookup for the matching case only. Here
1966 +"matching" means that the root of branch (in the info filename) is same
1967 +to the current looking-up branch. After looking-up the before-renamed
1968 +name, the inode-number is compared. And the matched dentry is used.
1970 +The "inode-number list of directories" is a regular file which contains
1971 +simply the inode-numbers on the branch. The file is created or updated
1972 +in removing the branch, and loaded in adding the branch. Its lifetime is
1973 +equal to the branch.
1974 +The list is refered in lookup, and when the current target inode is
1975 +found in the list, the aufs tries loading the "detailed info per
1976 +directory" and get the changed and valid name of the dir.
1978 +Theoretically these "extra informaiton" may be able to be put into XATTR
1979 +in the dir inode. But aufs doesn't choose this way because
1980 +1. XATTR may not be supported by the branch (or its configuration)
1981 +2. XATTR may have its size limit.
1982 +3. XATTR may be less easy to convert than a regular file, when the
1983 + format of the info is changed in the future.
1984 +At the same time, I agree that the regular file approach is much slower
1985 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1988 +This DIRREN feature is enabled by aufs configuration, and is activated
1989 +by a new mount option.
1991 +For the more complicated case, there is a work with UDBA option, which
1992 +is to dected the direct access to the branches (by-passing aufs) and to
1993 +maintain the cashes in aufs. Since a single cached aufs dentry may
1994 +contains two names, before- and after-rename, the name comparision in
1995 +UDBA handler may not work correctly. In this case, the behaviour will be
1996 +equivalen to udba=reval case.
1997 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1998 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1999 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-02-24 13:33:42.737680181 +0100
2002 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2004 +# This program is free software; you can redistribute it and/or modify
2005 +# it under the terms of the GNU General Public License as published by
2006 +# the Free Software Foundation; either version 2 of the License, or
2007 +# (at your option) any later version.
2009 +# This program is distributed in the hope that it will be useful,
2010 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2011 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2012 +# GNU General Public License for more details.
2014 +# You should have received a copy of the GNU General Public License
2015 +# along with this program; if not, write to the Free Software
2016 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2019 +File-based Hierarchical Storage Management (FHSM)
2020 +----------------------------------------------------------------------
2021 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2022 +storage world. Aufs provides this feature as file-based with multiple
2023 +writable branches, based upon the principle of "Colder, the Lower".
2024 +Here the word "colder" means that the less used files, and "lower" means
2025 +that the position in the order of the stacked branches vertically.
2026 +These multiple writable branches are prioritized, ie. the topmost one
2027 +should be the fastest drive and be used heavily.
2029 +o Characters in aufs FHSM story
2030 +- aufs itself and a new branch attribute.
2031 +- a new ioctl interface to move-down and to establish a connection with
2032 + the daemon ("move-down" is a converse of "copy-up").
2033 +- userspace tool and daemon.
2035 +The userspace daemon establishes a connection with aufs and waits for
2036 +the notification. The notified information is very similar to struct
2037 +statfs containing the number of consumed blocks and inodes.
2038 +When the consumed blocks/inodes of a branch exceeds the user-specified
2039 +upper watermark, the daemon activates its move-down process until the
2040 +consumed blocks/inodes reaches the user-specified lower watermark.
2042 +The actual move-down is done by aufs based upon the request from
2043 +user-space since we need to maintain the inode number and the internal
2044 +pointer arrays in aufs.
2046 +Currently aufs FHSM handles the regular files only. Additionally they
2047 +must not be hard-linked nor pseudo-linked.
2050 +o Cowork of aufs and the user-space daemon
2051 + During the userspace daemon established the connection, aufs sends a
2052 + small notification to it whenever aufs writes something into the
2053 + writable branch. But it may cost high since aufs issues statfs(2)
2054 + internally. So user can specify a new option to cache the
2055 + info. Actually the notification is controlled by these factors.
2056 + + the specified cache time.
2057 + + classified as "force" by aufs internally.
2058 + Until the specified time expires, aufs doesn't send the info
2059 + except the forced cases. When aufs decide forcing, the info is always
2060 + notified to userspace.
2061 + For example, the number of free inodes is generally large enough and
2062 + the shortage of it happens rarely. So aufs doesn't force the
2063 + notification when creating a new file, directory and others. This is
2064 + the typical case which aufs doesn't force.
2065 + When aufs writes the actual filedata and the files consumes any of new
2066 + blocks, the aufs forces notifying.
2069 +o Interfaces in aufs
2070 +- New branch attribute.
2072 + Specifies that the branch is managed by FHSM feature. In other word,
2073 + participant in the FHSM.
2074 + When nofhsm is set to the branch, it will not be the source/target
2075 + branch of the move-down operation. This attribute is set
2076 + independently from coo and moo attributes, and if you want full
2077 + FHSM, you should specify them as well.
2078 +- New mount option.
2080 + Specifies a second to suppress many less important info to be
2083 + + AUFS_CTL_FHSM_FD
2084 + create a new file descriptor which userspace can read the notification
2085 + (a subset of struct statfs) from aufs.
2086 +- Module parameter 'brs'
2087 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2089 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2090 + When there are two or more branches with fhsm attributes,
2091 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2092 + terminates it. As a result of remounting and branch-manipulation, the
2093 + number of branches with fhsm attribute can be one. In this case,
2094 + /sbin/mount.aufs will terminate the user-space daemon.
2097 +Finally the operation is done as these steps in kernel-space.
2099 + + no one else is using the file.
2100 + + the file is not hard-linked.
2101 + + the file is not pseudo-linked.
2102 + + the file is a regular file.
2103 + + the parent dir is not opaqued.
2104 +- find the target writable branch.
2105 +- make sure the file is not whiteout-ed by the upper (than the target)
2107 +- make the parent dir on the target branch.
2108 +- mutex lock the inode on the branch.
2109 +- unlink the whiteout on the target branch (if exists).
2110 +- lookup and create the whiteout-ed temporary name on the target branch.
2111 +- copy the file as the whiteout-ed temporary name on the target branch.
2112 +- rename the whiteout-ed temporary name to the original name.
2113 +- unlink the file on the source branch.
2114 +- maintain the internal pointer array and the external inode number
2116 +- maintain the timestamps and other attributes of the parent dir and the
2119 +And of course, in every step, an error may happen. So the operation
2120 +should restore the original file state after an error happens.
2121 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2122 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2123 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-02-24 13:33:42.737680181 +0100
2126 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2128 +# This program is free software; you can redistribute it and/or modify
2129 +# it under the terms of the GNU General Public License as published by
2130 +# the Free Software Foundation; either version 2 of the License, or
2131 +# (at your option) any later version.
2133 +# This program is distributed in the hope that it will be useful,
2134 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2135 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2136 +# GNU General Public License for more details.
2138 +# You should have received a copy of the GNU General Public License
2139 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2141 +mmap(2) -- File Memory Mapping
2142 +----------------------------------------------------------------------
2143 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2144 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2146 +This approach is simple and good, but there is one problem.
2147 +Under /proc, several entries show the mmapped files by its path (with
2148 +device and inode number), and the printed path will be the path on the
2149 +branch fs's instead of virtual aufs's.
2150 +This is not a problem in most cases, but some utilities lsof(1) (and its
2151 +user) may expect the path on aufs.
2153 +To address this issue, aufs adds a new member called vm_prfile in struct
2154 +vm_area_struct (and struct vm_region). The original vm_file points to
2155 +the file on the branch fs in order to handle everything correctly as
2156 +usual. The new vm_prfile points to a virtual file in aufs, and the
2157 +show-functions in procfs refers to vm_prfile if it is set.
2158 +Also we need to maintain several other places where touching vm_file
2160 +- fork()/clone() copies vma and the reference count of vm_file is
2162 +- merging vma maintains the ref count too.
2164 +This is not a good approach. It just fakes the printed path. But it
2165 +leaves all behaviour around f_mapping unchanged. This is surely an
2167 +Actually aufs had adopted another complicated approach which calls
2168 +generic_file_mmap() and handles struct vm_operations_struct. In this
2169 +approach, aufs met a hard problem and I could not solve it without
2170 +switching the approach.
2172 +There may be one more another approach which is
2173 +- bind-mount the branch-root onto the aufs-root internally
2174 +- grab the new vfsmount (ie. struct mount)
2175 +- lazy-umount the branch-root internally
2176 +- in open(2) the aufs-file, open the branch-file with the hidden
2177 + vfsmount (instead of the original branch's vfsmount)
2178 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2179 + but it may be possible from userspace by the mount helper.
2181 +Adding the internal hidden vfsmount and using it in opening a file, the
2182 +file path under /proc will be printed correctly. This approach looks
2183 +smarter, but is not possible I am afraid.
2184 +- aufs-root may be bind-mount later. when it happens, another hidden
2185 + vfsmount will be required.
2186 +- it is hard to get the chance to bind-mount and lazy-umount
2187 + + in kernel-space, FS can have vfsmount in open(2) via
2188 + file->f_path, and aufs can know its vfsmount. But several locks are
2189 + already acquired, and if aufs tries to bind-mount and lazy-umount
2190 + here, then it may cause a deadlock.
2191 + + in user-space, bind-mount doesn't invoke the mount helper.
2192 +- since /proc shows dev and ino, aufs has to give vma these info. it
2193 + means a new member vm_prinode will be necessary. this is essentially
2194 + equivalent to vm_prfile described above.
2196 +I have to give up this "looks-smater" approach.
2197 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2198 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2199 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-02-24 13:33:42.737680181 +0100
2202 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2204 +# This program is free software; you can redistribute it and/or modify
2205 +# it under the terms of the GNU General Public License as published by
2206 +# the Free Software Foundation; either version 2 of the License, or
2207 +# (at your option) any later version.
2209 +# This program is distributed in the hope that it will be useful,
2210 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2211 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2212 +# GNU General Public License for more details.
2214 +# You should have received a copy of the GNU General Public License
2215 +# along with this program; if not, write to the Free Software
2216 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2219 +Listing XATTR/EA and getting the value
2220 +----------------------------------------------------------------------
2221 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2222 +shows the values from the topmost existing file. This behaviour is good
2223 +for the non-dir entries since the bahaviour exactly matches the shown
2224 +information. But for the directories, aufs considers all the same named
2225 +entries on the lower branches. Which means, if one of the lower entry
2226 +rejects readdir call, then aufs returns an error even if the topmost
2227 +entry allows it. This behaviour is necessary to respect the branch fs's
2228 +security, but can make users confused since the user-visible standard
2229 +attributes don't match the behaviour.
2230 +To address this issue, aufs has a mount option called dirperm1 which
2231 +checks the permission for the topmost entry only, and ignores the lower
2232 +entry's permission.
2234 +A similar issue can happen around XATTR.
2235 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2236 +always set. Otherwise these very unpleasant situation would happen.
2237 +- listxattr(2) may return the duplicated entries.
2238 +- users may not be able to remove or reset the XATTR forever,
2241 +XATTR/EA support in the internal (copy,move)-(up,down)
2242 +----------------------------------------------------------------------
2243 +Generally the extended attributes of inode are categorized as these.
2244 +- "security" for LSM and capability.
2245 +- "system" for posix ACL, 'acl' mount option is required for the branch
2247 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2248 +- "user" for userspace, 'user_xattr' mount option is required for the
2249 + branch fs generally.
2251 +Moreover there are some other categories. Aufs handles these rather
2252 +unpopular categories as the ordinary ones, ie. there is no special
2253 +condition nor exception.
2255 +In copy-up, the support for XATTR on the dst branch may differ from the
2256 +src branch. In this case, the copy-up operation will get an error and
2257 +the original user operation which triggered the copy-up will fail. It
2258 +can happen that even all copy-up will fail.
2259 +When both of src and dst branches support XATTR and if an error occurs
2260 +during copying XATTR, then the copy-up should fail obviously. That is a
2261 +good reason and aufs should return an error to userspace. But when only
2262 +the src branch support that XATTR, aufs should not return an error.
2263 +For example, the src branch supports ACL but the dst branch doesn't
2264 +because the dst branch may natively un-support it or temporary
2265 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2266 +may NOT return an error even if the XATTR is not supported. It is
2267 +totally up to the branch fs.
2269 +Anyway when the aufs internal copy-up gets an error from the dst branch
2270 +fs, then aufs tries removing the just copied entry and returns the error
2271 +to the userspace. The worst case of this situation will be all copy-up
2274 +For the copy-up operation, there two basic approaches.
2275 +- copy the specified XATTR only (by category above), and return the
2276 + error unconditionally if it happens.
2277 +- copy all XATTR, and ignore the error on the specified category only.
2279 +In order to support XATTR and to implement the correct behaviour, aufs
2280 +chooses the latter approach and introduces some new branch attributes,
2281 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2282 +They correspond to the XATTR namespaces (see above). Additionally, to be
2283 +convenient, "icex" is also provided which means all "icex*" attributes
2284 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2286 +The meaning of these attributes is to ignore the error from setting
2287 +XATTR on that branch.
2288 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2289 +error from the dst branch according to the specified attributes.
2291 +Some XATTR may have its default value. The default value may come from
2292 +the parent dir or the environment. If the default value is set at the
2293 +file creating-time, it will be overwritten by copy-up.
2294 +Some contradiction may happen I am afraid.
2295 +Do we need another attribute to stop copying XATTR? I am unsure. For
2296 +now, aufs implements the branch attributes to ignore the error.
2297 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2298 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2299 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-02-24 13:33:42.737680181 +0100
2302 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2304 +# This program is free software; you can redistribute it and/or modify
2305 +# it under the terms of the GNU General Public License as published by
2306 +# the Free Software Foundation; either version 2 of the License, or
2307 +# (at your option) any later version.
2309 +# This program is distributed in the hope that it will be useful,
2310 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2311 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2312 +# GNU General Public License for more details.
2314 +# You should have received a copy of the GNU General Public License
2315 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2317 +Export Aufs via NFS
2318 +----------------------------------------------------------------------
2319 +Here is an approach.
2320 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2322 +- iget_locked(): initialize aufs inode generation for a new inode, and
2323 + store it in xigen file.
2324 +- destroy_inode(): increment aufs inode generation and store it in xigen
2325 + file. it is necessary even if it is not unlinked, because any data of
2326 + inode may be changed by UDBA.
2327 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2328 + build file handle by
2329 + + branch id (4 bytes)
2330 + + superblock generation (4 bytes)
2331 + + inode number (4 or 8 bytes)
2332 + + parent dir inode number (4 or 8 bytes)
2333 + + inode generation (4 bytes))
2334 + + return value of exportfs_encode_fh() for the parent on a branch (4
2336 + + file handle for a branch (by exportfs_encode_fh())
2338 + + find the index of a branch from its id in handle, and check it is
2339 + still exist in aufs.
2340 + + 1st level: get the inode number from handle and search it in cache.
2341 + + 2nd level: if not found in cache, get the parent inode number from
2342 + the handle and search it in cache. and then open the found parent
2343 + dir, find the matching inode number by vfs_readdir() and get its
2344 + name, and call lookup_one_len() for the target dentry.
2345 + + 3rd level: if the parent dir is not cached, call
2346 + exportfs_decode_fh() for a branch and get the parent on a branch,
2347 + build a pathname of it, convert it a pathname in aufs, call
2348 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2350 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2351 + for every branch, but not itself. to get this, (currently) aufs
2352 + searches in current->nsproxy->mnt_ns list. it may not be a good
2353 + idea, but I didn't get other approach.
2354 + + test the generation of the gotten inode.
2355 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2356 + convert it into ESTALE for NFSD.
2357 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2358 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2359 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2360 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2361 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-02-24 13:33:42.737680181 +0100
2364 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2366 +# This program is free software; you can redistribute it and/or modify
2367 +# it under the terms of the GNU General Public License as published by
2368 +# the Free Software Foundation; either version 2 of the License, or
2369 +# (at your option) any later version.
2371 +# This program is distributed in the hope that it will be useful,
2372 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2373 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2374 +# GNU General Public License for more details.
2376 +# You should have received a copy of the GNU General Public License
2377 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2379 +Show Whiteout Mode (shwh)
2380 +----------------------------------------------------------------------
2381 +Generally aufs hides the name of whiteouts. But in some cases, to show
2382 +them is very useful for users. For instance, creating a new middle layer
2383 +(branch) by merging existing layers.
2385 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2386 +When you have three branches,
2387 +- Bottom: 'system', squashfs (underlying base system), read-only
2388 +- Middle: 'mods', squashfs, read-only
2389 +- Top: 'overlay', ram (tmpfs), read-write
2391 +The top layer is loaded at boot time and saved at shutdown, to preserve
2392 +the changes made to the system during the session.
2393 +When larger changes have been made, or smaller changes have accumulated,
2394 +the size of the saved top layer data grows. At this point, it would be
2395 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2396 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2397 +restoring save and load speed.
2399 +This merging is simplified by the use of another aufs mount, of just the
2400 +two overlay branches using the 'shwh' option.
2401 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2402 + aufs /livesys/merge_union
2404 +A merged view of these two branches is then available at
2405 +/livesys/merge_union, and the new feature is that the whiteouts are
2407 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2408 +writing to all branches. Also the default mode for all branches is 'ro'.
2409 +It is now possible to save the combined contents of the two overlay
2410 +branches to a new squashfs, e.g.:
2411 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2413 +This new squashfs archive can be stored on the boot device and the
2414 +initramfs will use it to replace the old one at the next boot.
2415 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2416 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2417 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-02-24 13:33:42.737680181 +0100
2420 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2422 +# This program is free software; you can redistribute it and/or modify
2423 +# it under the terms of the GNU General Public License as published by
2424 +# the Free Software Foundation; either version 2 of the License, or
2425 +# (at your option) any later version.
2427 +# This program is distributed in the hope that it will be useful,
2428 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2429 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2430 +# GNU General Public License for more details.
2432 +# You should have received a copy of the GNU General Public License
2433 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2435 +Dynamically customizable FS operations
2436 +----------------------------------------------------------------------
2437 +Generally FS operations (struct inode_operations, struct
2438 +address_space_operations, struct file_operations, etc.) are defined as
2439 +"static const", but it never means that FS have only one set of
2440 +operation. Some FS have multiple sets of them. For instance, ext2 has
2441 +three sets, one for XIP, for NOBH, and for normal.
2442 +Since aufs overrides and redirects these operations, sometimes aufs has
2443 +to change its behaviour according to the branch FS type. More importantly
2444 +VFS acts differently if a function (member in the struct) is set or
2445 +not. It means aufs should have several sets of operations and select one
2446 +among them according to the branch FS definition.
2448 +In order to solve this problem and not to affect the behaviour of VFS,
2449 +aufs defines these operations dynamically. For instance, aufs defines
2450 +dummy direct_IO function for struct address_space_operations, but it may
2451 +not be set to the address_space_operations actually. When the branch FS
2452 +doesn't have it, aufs doesn't set it to its address_space_operations
2453 +while the function definition itself is still alive. So the behaviour
2454 +itself will not change, and it will return an error when direct_IO is
2457 +The lifetime of these dynamically generated operation object is
2458 +maintained by aufs branch object. When the branch is removed from aufs,
2459 +the reference counter of the object is decremented. When it reaches
2460 +zero, the dynamically generated operation object will be freed.
2462 +This approach is designed to support AIO (io_submit), Direct I/O and
2464 +Currently this approach is applied to address_space_operations for
2465 +regular files only.
2466 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2467 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2468 +++ linux/Documentation/filesystems/aufs/README 2021-02-24 13:33:42.737680181 +0100
2471 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2477 +----------------------------------------
2478 +In the early days, aufs was entirely re-designed and re-implemented
2479 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2480 +improvements and implementations, it became totally different from
2481 +Unionfs while keeping the basic features.
2482 +Later, Unionfs Version 2.x series began taking some of the same
2483 +approaches to aufs1's.
2484 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2485 +University and his team.
2487 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2489 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2490 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2491 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2492 + or aufs1 from CVS on SourceForge.
2494 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2495 + According to Christoph Hellwig, linux rejects all union-type
2496 + filesystems but UnionMount.
2497 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2499 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2500 + UnionMount, and he pointed out an issue around a directory mutex
2501 + lock and aufs addressed it. But it is still unsure whether aufs will
2502 + be merged (or any other union solution).
2503 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2507 +----------------------------------------
2508 +- unite several directories into a single virtual filesystem. The member
2509 + directory is called as a branch.
2510 +- you can specify the permission flags to the branch, which are 'readonly',
2511 + 'readwrite' and 'whiteout-able.'
2512 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2513 + readonly branch are modifiable logically.
2514 +- dynamic branch manipulation, add, del.
2517 +Also there are many enhancements in aufs, such as:
2518 +- test only the highest one for the directory permission (dirperm1)
2519 +- copyup on open (coo=)
2520 +- 'move' policy for copy-up between two writable branches, after
2521 + checking free space.
2523 +- readdir(3) in userspace.
2524 +- keep inode number by external inode number table
2525 +- keep the timestamps of file/dir in internal copyup operation
2526 +- seekable directory, supporting NFS readdir.
2527 +- whiteout is hardlinked in order to reduce the consumption of inodes
2529 +- do not copyup, nor create a whiteout when it is unnecessary
2530 +- revert a single systemcall when an error occurs in aufs
2531 +- remount interface instead of ioctl
2532 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2533 +- loopback mounted filesystem as a branch
2534 +- kernel thread for removing the dir who has a plenty of whiteouts
2535 +- support copyup sparse file (a file which has a 'hole' in it)
2536 +- default permission flags for branches
2537 +- selectable permission flags for ro branch, whether whiteout can
2540 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2541 +- support multiple writable branches, some policies to select one
2542 + among multiple writable branches.
2543 +- a new semantics for link(2) and rename(2) to support multiple
2544 + writable branches.
2545 +- no glibc changes are required.
2546 +- pseudo hardlink (hardlink over branches)
2547 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2548 + including NFS or remote filesystem branch.
2549 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2552 +Currently these features are dropped temporary from aufs5.
2553 +See design/08plan.txt in detail.
2554 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2556 +- statistics of aufs thread (/sys/fs/aufs/stat)
2558 +Features or just an idea in the future (see also design/*.txt),
2559 +- reorder the branch index without del/re-add.
2560 +- permanent xino files for NFSD
2561 +- an option for refreshing the opened files after add/del branches
2562 +- light version, without branch manipulation. (unnecessary?)
2563 +- copyup in userspace
2564 +- inotify in userspace
2569 +----------------------------------------
2570 +There are three GIT trees for aufs5, aufs5-linux.git,
2571 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2573 +While the aufs-util is always necessary, you need either of aufs5-linux
2574 +or aufs5-standalone.
2576 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2577 +git://git.kernel.org/.../torvalds/linux.git.
2578 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2579 +build aufs5 as an external kernel module.
2580 +Several extra patches are not included in this tree. Only
2581 +aufs5-standalone tree contains them. They are described in the later
2582 +section "Configuration and Compilation."
2584 +On the other hand, the aufs5-standalone tree has only aufs source files
2585 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2586 +But you need to apply all aufs patches manually.
2588 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2589 +represents the linux kernel version, "linux-5.x". For instance,
2590 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2591 +"aufs5.x-rcN" branch.
2594 +$ git clone --reference /your/linux/git/tree \
2595 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2596 +- if you don't have linux GIT tree, then remove "--reference ..."
2597 +$ cd aufs5-linux.git
2598 +$ git checkout origin/aufs5.0
2600 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2601 +leave the patch-work to GIT.
2602 +$ cd /your/linux/git/tree
2603 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2605 +$ git checkout -b my5.0 v5.0
2606 +$ (add your local change...)
2607 +$ git pull aufs5 aufs5.0
2608 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2609 +- you may need to solve some conflicts between your_changes and
2610 + aufs5.0. in this case, git-rerere is recommended so that you can
2611 + solve the similar conflicts automatically when you upgrade to 5.1 or
2612 + later in the future.
2614 +o aufs5-standalone tree
2615 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2616 +$ cd aufs5-standalone.git
2617 +$ git checkout origin/aufs5.0
2620 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2621 +- note that the public aufs-util.git is on SourceForge instead of
2624 +$ git checkout origin/aufs5.0
2626 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2627 +The minor version number, 'x' in '5.x', of aufs may not always
2628 +follow the minor version number of the kernel.
2629 +Because changes in the kernel that cause the use of a new
2630 +minor version number do not always require changes to aufs-util.
2632 +Since aufs-util has its own minor version number, you may not be
2633 +able to find a GIT branch in aufs-util for your kernel's
2634 +exact minor version number.
2635 +In this case, you should git-checkout the branch for the
2636 +nearest lower number.
2638 +For (an unreleased) example:
2639 +If you are using "linux-5.10" and the "aufs5.10" branch
2640 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2641 +or something numerically smaller is the branch for your kernel.
2643 +Also you can view all branches by
2647 +3. Configuration and Compilation
2648 +----------------------------------------
2649 +Make sure you have git-checkout'ed the correct branch.
2651 +For aufs5-linux tree,
2652 +- enable CONFIG_AUFS_FS.
2653 +- set other aufs configurations if necessary.
2655 +For aufs5-standalone tree,
2656 +There are several ways to build.
2659 +- apply ./aufs5-kbuild.patch to your kernel source files.
2660 +- apply ./aufs5-base.patch too.
2661 +- apply ./aufs5-mmap.patch too.
2662 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2663 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2664 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2665 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2666 +- enable CONFIG_AUFS_FS, you can select either
2668 +- and build your kernel as usual.
2669 +- install the built kernel.
2670 +- install the header files too by "make headers_install" to the
2671 + directory where you specify. By default, it is $PWD/usr.
2672 + "make help" shows a brief note for headers_install.
2673 +- and reboot your system.
2676 +- module only (CONFIG_AUFS_FS=m).
2677 +- apply ./aufs5-base.patch to your kernel source files.
2678 +- apply ./aufs5-mmap.patch too.
2679 +- apply ./aufs5-standalone.patch too.
2680 +- build your kernel, don't forget "make headers_install", and reboot.
2681 +- edit ./config.mk and set other aufs configurations if necessary.
2682 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2683 + every aufs configurations.
2684 +- build the module by simple "make".
2685 +- you can specify ${KDIR} make variable which points to your kernel
2687 +- install the files
2688 + + run "make install" to install the aufs module, or copy the built
2689 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2690 + + run "make install_headers" (instead of headers_install) to install
2691 + the modified aufs header file (you can specify DESTDIR which is
2692 + available in aufs standalone version's Makefile only), or copy
2693 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2694 + you like manually. By default, the target directory is $PWD/usr.
2695 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2696 + kernel source tree.
2698 +Note: The header file aufs_type.h is necessary to build aufs-util
2699 + as well as "make headers_install" in the kernel source tree.
2700 + headers_install is subject to be forgotten, but it is essentially
2701 + necessary, not only for building aufs-util.
2702 + You may not meet problems without headers_install in some older
2706 +- read README in aufs-util, build and install it
2707 +- note that your distribution may contain an obsoleted version of
2708 + aufs_type.h in /usr/include/linux or something. When you build aufs
2709 + utilities, make sure that your compiler refers the correct aufs header
2710 + file which is built by "make headers_install."
2711 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2712 + then run "make install_ulib" too. And refer to the aufs manual in
2715 +There several other patches in aufs5-standalone.git. They are all
2716 +optional. When you meet some problems, they will help you.
2717 +- aufs5-loopback.patch
2718 + Supports a nested loopback mount in a branch-fs. This patch is
2719 + unnecessary until aufs produces a message like "you may want to try
2720 + another patch for loopback file".
2721 +- proc_mounts.patch
2722 + When there are many mountpoints and many mount(2)/umount(2) are
2723 + running, then /proc/mounts may not show the all mountpoints. This
2724 + patch makes /proc/mounts always show the full mountpoints list.
2725 + If you don't want to apply this patch and meet such problem, then you
2726 + need to increase the value of 'ProcMounts_Times' make-variable in
2727 + aufs-util.git as a second best solution.
2729 + Modifies a system global kernel internal function get_next_ino() in
2730 + order to stop assigning 0 for an inode-number. Not directly related to
2731 + aufs, but recommended generally.
2733 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2734 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2735 + duplication of inode number, which is important for backup tools and
2736 + other utilities. When you find aufs XINO files for tmpfs branch
2737 + growing too much, try this patch.
2738 +- lockdep-debug.patch
2739 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2740 + also a caller of VFS functions for branch filesystems, subclassing of
2741 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2742 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2743 + need to apply this debug patch to expand several constant values.
2744 + If you don't know what LOCKDEP is, then you don't have apply this
2749 +----------------------------------------
2750 +At first, make sure aufs-util are installed, and please read the aufs
2751 +manual, aufs.5 in aufs-util.git tree.
2755 +$ mkdir /tmp/rw /tmp/aufs
2756 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2758 +Here is another example. The result is equivalent.
2759 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2761 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2762 +# mount -o remount,append:${HOME} /tmp/aufs
2764 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2765 +you modify a file under /tmp/aufs, the one on your home directory is
2766 +not affected, instead the same named file will be newly created under
2767 +/tmp/rw. And all of your modification to a file will be applied to
2768 +the one under /tmp/rw. This is called the file based Copy on Write
2770 +Aufs mount options are described in aufs.5.
2771 +If you run chroot or something and make your aufs as a root directory,
2772 +then you need to customize the shutdown script. See the aufs manual in
2775 +Additionally, there are some sample usages of aufs which are a
2776 +diskless system with network booting, and LiveCD over NFS.
2777 +See sample dir in CVS tree on SourceForge.
2781 +----------------------------------------
2782 +When you have any problems or strange behaviour in aufs, please let me
2784 +- /proc/mounts (instead of the output of mount(8))
2785 +- /sys/module/aufs/*
2786 +- /sys/fs/aufs/* (if you have them)
2787 +- /debug/aufs/* (if you have them)
2788 +- linux kernel version
2789 + if your kernel is not plain, for example modified by distributor,
2790 + the url where i can download its source is necessary too.
2791 +- aufs version which was printed at loading the module or booting the
2792 + system, instead of the date you downloaded.
2793 +- configuration (define/undefine CONFIG_AUFS_xxx)
2794 +- kernel configuration or /proc/config.gz (if you have it)
2795 +- LSM (linux security module, if you are using)
2796 +- behaviour which you think to be incorrect
2797 +- actual operation, reproducible one is better
2798 +- mailto: aufs-users at lists.sourceforge.net
2800 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2801 +and Feature Requests) on SourceForge. Please join and write to
2805 +6. Acknowledgements
2806 +----------------------------------------
2807 +Thanks to everyone who have tried and are using aufs, whoever
2808 +have reported a bug or any feedback.
2810 +Especially donators:
2811 +Tomas Matejicek(slax.org) made a donation (much more than once).
2812 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2813 + scripts) is making "doubling" donations.
2814 + Unfortunately I cannot list all of the donators, but I really
2816 + It ends Aug 2010, but the ordinary donation URL is still available.
2817 + <http://sourceforge.net/donate/index.php?group_id=167503>
2818 +Dai Itasaka made a donation (2007/8).
2819 +Chuck Smith made a donation (2008/4, 10 and 12).
2820 +Henk Schoneveld made a donation (2008/9).
2821 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2822 +Francois Dupoux made a donation (2008/11).
2823 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2824 + aufs2 GIT tree (2009/2).
2825 +William Grant made a donation (2009/3).
2826 +Patrick Lane made a donation (2009/4).
2827 +The Mail Archive (mail-archive.com) made donations (2009/5).
2828 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2829 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2830 +Pavel Pronskiy made a donation (2011/2).
2831 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2832 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2833 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2835 +Sam Liddicott made a donation (2011/9).
2836 +Era Scarecrow made a donation (2013/4).
2837 +Bor Ratajc made a donation (2013/4).
2838 +Alessandro Gorreta made a donation (2013/4).
2839 +POIRETTE Marc made a donation (2013/4).
2840 +Alessandro Gorreta made a donation (2013/4).
2841 +lauri kasvandik made a donation (2013/5).
2842 +"pemasu from Finland" made a donation (2013/7).
2843 +The Parted Magic Project made a donation (2013/9 and 11).
2844 +Pavel Barta made a donation (2013/10).
2845 +Nikolay Pertsev made a donation (2014/5).
2846 +James B made a donation (2014/7 and 2015/7).
2847 +Stefano Di Biase made a donation (2014/8).
2848 +Daniel Epellei made a donation (2015/1).
2849 +OmegaPhil made a donation (2016/1, 2018/4).
2850 +Tomasz Szewczyk made a donation (2016/4).
2851 +James Burry made a donation (2016/12).
2852 +Carsten Rose made a donation (2018/9).
2853 +Porteus Kiosk made a donation (2018/10).
2855 +Thank you very much.
2856 +Donations are always, including future donations, very important and
2857 +helpful for me to keep on developing aufs.
2861 +----------------------------------------
2862 +If you are an experienced user, no explanation is needed. Aufs is
2863 +just a linux filesystem.
2868 +# Local variables: ;
2871 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2872 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2873 +++ linux/fs/aufs/aufs.h 2021-02-24 13:33:42.741013619 +0100
2875 +/* SPDX-License-Identifier: GPL-2.0 */
2877 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2879 + * This program, aufs is free software; you can redistribute it and/or modify
2880 + * it under the terms of the GNU General Public License as published by
2881 + * the Free Software Foundation; either version 2 of the License, or
2882 + * (at your option) any later version.
2884 + * This program is distributed in the hope that it will be useful,
2885 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2886 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2887 + * GNU General Public License for more details.
2889 + * You should have received a copy of the GNU General Public License
2890 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2894 + * all header files
2902 +#define AuStub(type, name, body, ...) \
2903 + static inline type name(__VA_ARGS__) { body; }
2905 +#define AuStubVoid(name, ...) \
2906 + AuStub(void, name, , __VA_ARGS__)
2907 +#define AuStubInt0(name, ...) \
2908 + AuStub(int, name, return 0, __VA_ARGS__)
2912 +#include "branch.h"
2915 +#include "dbgaufs.h"
2916 +#include "dentry.h"
2918 +#include "dirren.h"
2921 +#include "fstype.h"
2926 +#include "module.h"
2930 +#include "sysaufs.h"
2935 +#endif /* __KERNEL__ */
2936 +#endif /* __AUFS_H__ */
2937 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2938 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2939 +++ linux/fs/aufs/branch.c 2021-02-24 13:33:42.741013619 +0100
2941 +// SPDX-License-Identifier: GPL-2.0
2943 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2945 + * This program, aufs is free software; you can redistribute it and/or modify
2946 + * it under the terms of the GNU General Public License as published by
2947 + * the Free Software Foundation; either version 2 of the License, or
2948 + * (at your option) any later version.
2950 + * This program is distributed in the hope that it will be useful,
2951 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2952 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2953 + * GNU General Public License for more details.
2955 + * You should have received a copy of the GNU General Public License
2956 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2960 + * branch management
2963 +#include <linux/compat.h>
2964 +#include <linux/statfs.h>
2968 + * free a single branch
2970 +static void au_br_do_free(struct au_branch *br)
2973 + struct au_wbr *wbr;
2974 + struct au_dykey **key;
2976 + au_hnotify_fin_br(br);
2977 + /* always, regardless the mount option */
2978 + au_dr_hino_free(&br->br_dirren);
2981 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2982 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2983 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2984 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2988 + for (i = 0; i < AuBrWh_Last; i++)
2989 + dput(wbr->wbr_wh[i]);
2990 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2991 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2994 + if (br->br_fhsm) {
2995 + au_br_fhsm_fin(br->br_fhsm);
2996 + au_kfree_try_rcu(br->br_fhsm);
2999 + key = br->br_dykey;
3000 + for (i = 0; i < AuBrDynOp; i++, key++)
3006 + /* recursive lock, s_umount of branch's */
3007 + /* synchronize_rcu(); */ /* why? */
3009 + path_put(&br->br_path);
3011 + au_kfree_rcu(wbr);
3012 + au_lcnt_wait_for_fin(&br->br_nfiles);
3013 + au_lcnt_wait_for_fin(&br->br_count);
3014 + /* I don't know why, but percpu_refcount requires this */
3015 + /* synchronize_rcu(); */
3020 + * frees all branches
3022 +void au_br_free(struct au_sbinfo *sbinfo)
3024 + aufs_bindex_t bmax;
3025 + struct au_branch **br;
3027 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3029 + bmax = sbinfo->si_bbot + 1;
3030 + br = sbinfo->si_branch;
3032 + au_br_do_free(*br++);
3036 + * find the index of a branch which is specified by @br_id.
3038 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3040 + aufs_bindex_t bindex, bbot;
3042 + bbot = au_sbbot(sb);
3043 + for (bindex = 0; bindex <= bbot; bindex++)
3044 + if (au_sbr_id(sb, bindex) == br_id)
3049 +/* ---------------------------------------------------------------------- */
3055 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3056 + struct dentry *h_root)
3058 + if (unlikely(h_adding == h_root
3059 + || au_test_loopback_overlap(sb, h_adding)))
3061 + if (h_adding->d_sb != h_root->d_sb)
3063 + return au_test_subdir(h_adding, h_root)
3064 + || au_test_subdir(h_root, h_adding);
3068 + * returns a newly allocated branch. @new_nbranch is a number of branches
3069 + * after adding a branch.
3071 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3074 + struct au_branch *add_branch;
3075 + struct dentry *root;
3076 + struct inode *inode;
3080 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3081 + if (unlikely(!add_branch))
3083 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3084 + if (unlikely(!add_branch->br_xino))
3086 + err = au_hnotify_init_br(add_branch, perm);
3087 + if (unlikely(err))
3090 + if (au_br_writable(perm)) {
3091 + /* may be freed separately at changing the branch permission */
3092 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3094 + if (unlikely(!add_branch->br_wbr))
3098 + if (au_br_fhsm(perm)) {
3099 + err = au_fhsm_br_alloc(add_branch);
3100 + if (unlikely(err))
3104 + root = sb->s_root;
3105 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3107 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3109 + inode = d_inode(root);
3110 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3114 + return add_branch; /* success */
3117 + au_kfree_rcu(add_branch->br_wbr);
3119 + au_hnotify_fin_br(add_branch);
3121 + au_xino_put(add_branch);
3123 + au_kfree_rcu(add_branch);
3125 + return ERR_PTR(err);
3129 + * test if the branch permission is legal or not.
3131 +static int test_br(struct inode *inode, int brperm, char *path)
3135 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3140 + pr_err("write permission for readonly mount or inode, %s\n", path);
3148 + * 0: success, the caller will add it
3149 + * plus: success, it is already unified, the caller should ignore it
3152 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3155 + aufs_bindex_t bbot, bindex;
3156 + struct dentry *root, *h_dentry;
3157 + struct inode *inode, *h_inode;
3159 + root = sb->s_root;
3160 + bbot = au_sbbot(sb);
3161 + if (unlikely(bbot >= 0
3162 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3166 + pr_err("%s duplicated\n", add->pathname);
3171 + err = -ENOSPC; /* -E2BIG; */
3172 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3173 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3174 + pr_err("number of branches exceeded %s\n", add->pathname);
3179 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3180 + pr_err("bad index %d\n", add->bindex);
3184 + inode = d_inode(add->path.dentry);
3186 + if (unlikely(!inode->i_nlink)) {
3187 + pr_err("no existence %s\n", add->pathname);
3192 + if (unlikely(inode->i_sb == sb)) {
3193 + pr_err("%s must be outside\n", add->pathname);
3197 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3198 + pr_err("unsupported filesystem, %s (%s)\n",
3199 + add->pathname, au_sbtype(inode->i_sb));
3203 + if (unlikely(inode->i_sb->s_stack_depth)) {
3204 + pr_err("already stacked, %s (%s)\n",
3205 + add->pathname, au_sbtype(inode->i_sb));
3209 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3210 + if (unlikely(err))
3214 + return 0; /* success */
3217 + for (bindex = 0; bindex <= bbot; bindex++)
3218 + if (unlikely(test_overlap(sb, add->path.dentry,
3219 + au_h_dptr(root, bindex)))) {
3220 + pr_err("%s is overlapped\n", add->pathname);
3225 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3226 + h_dentry = au_h_dptr(root, 0);
3227 + h_inode = d_inode(h_dentry);
3228 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3229 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3230 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3231 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3233 + i_uid_read(inode), i_gid_read(inode),
3234 + (inode->i_mode & S_IALLUGO),
3235 + i_uid_read(h_inode), i_gid_read(h_inode),
3236 + (h_inode->i_mode & S_IALLUGO));
3244 + * initialize or clean the whiteouts for an adding branch
3246 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3249 + int err, old_perm;
3250 + aufs_bindex_t bindex;
3251 + struct inode *h_inode;
3252 + struct au_wbr *wbr;
3253 + struct au_hinode *hdir;
3254 + struct dentry *h_dentry;
3256 + err = vfsub_mnt_want_write(au_br_mnt(br));
3257 + if (unlikely(err))
3261 + old_perm = br->br_perm;
3262 + br->br_perm = new_perm;
3265 + bindex = au_br_index(sb, br->br_id);
3266 + if (0 <= bindex) {
3267 + hdir = au_hi(d_inode(sb->s_root), bindex);
3268 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3270 + h_dentry = au_br_dentry(br);
3271 + h_inode = d_inode(h_dentry);
3272 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3275 + err = au_wh_init(br, sb);
3277 + wbr_wh_write_lock(wbr);
3278 + err = au_wh_init(br, sb);
3279 + wbr_wh_write_unlock(wbr);
3282 + au_hn_inode_unlock(hdir);
3284 + inode_unlock(h_inode);
3285 + vfsub_mnt_drop_write(au_br_mnt(br));
3286 + br->br_perm = old_perm;
3288 + if (!err && wbr && !au_br_writable(new_perm)) {
3289 + au_kfree_rcu(wbr);
3290 + br->br_wbr = NULL;
3297 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3301 + struct kstatfs kst;
3302 + struct au_wbr *wbr;
3305 + au_rw_init(&wbr->wbr_wh_rwsem);
3306 + atomic_set(&wbr->wbr_wh_running, 0);
3309 + * a limit for rmdir/rename a dir
3310 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3312 + err = vfs_statfs(&br->br_path, &kst);
3313 + if (unlikely(err))
3316 + if (kst.f_namelen >= NAME_MAX)
3317 + err = au_br_init_wh(sb, br, perm);
3319 + pr_err("%pd(%s), unsupported namelen %ld\n",
3321 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3327 +/* initialize a new branch */
3328 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3329 + struct au_opt_add *add)
3332 + struct au_branch *brbase;
3334 + struct inode *h_inode;
3337 + br->br_perm = add->perm;
3338 + br->br_path = add->path; /* set first, path_get() later */
3339 + spin_lock_init(&br->br_dykey_lock);
3340 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3341 + au_lcnt_init(&br->br_count, /*release*/NULL);
3342 + br->br_id = au_new_br_id(sb);
3343 + AuDebugOn(br->br_id < 0);
3345 + /* always, regardless the given option */
3346 + err = au_dr_br_init(sb, br, &add->path);
3347 + if (unlikely(err))
3350 + if (au_br_writable(add->perm)) {
3351 + err = au_wbr_init(br, sb, add->perm);
3352 + if (unlikely(err))
3356 + if (au_opt_test(au_mntflags(sb), XINO)) {
3357 + brbase = au_sbr(sb, 0);
3358 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3360 + h_inode = d_inode(add->path.dentry);
3361 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3362 + if (unlikely(err)) {
3363 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3368 + sysaufs_br_init(br);
3369 + path_get(&br->br_path);
3370 + goto out; /* success */
3373 + memset(&br->br_path, 0, sizeof(br->br_path));
3378 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3379 + struct au_branch *br, aufs_bindex_t bbot,
3380 + aufs_bindex_t amount)
3382 + struct au_branch **brp;
3384 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3386 + brp = sbinfo->si_branch + bindex;
3387 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3389 + sbinfo->si_bbot++;
3390 + if (unlikely(bbot < 0))
3391 + sbinfo->si_bbot = 0;
3394 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3395 + aufs_bindex_t bbot, aufs_bindex_t amount)
3397 + struct au_hdentry *hdp;
3399 + AuRwMustWriteLock(&dinfo->di_rwsem);
3401 + hdp = au_hdentry(dinfo, bindex);
3402 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3403 + au_h_dentry_init(hdp);
3405 + if (unlikely(bbot < 0))
3406 + dinfo->di_btop = 0;
3409 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3410 + aufs_bindex_t bbot, aufs_bindex_t amount)
3412 + struct au_hinode *hip;
3414 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3416 + hip = au_hinode(iinfo, bindex);
3417 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3418 + au_hinode_init(hip);
3420 + if (unlikely(bbot < 0))
3421 + iinfo->ii_btop = 0;
3424 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3425 + aufs_bindex_t bindex)
3427 + struct dentry *root, *h_dentry;
3428 + struct inode *root_inode, *h_inode;
3429 + aufs_bindex_t bbot, amount;
3431 + root = sb->s_root;
3432 + root_inode = d_inode(root);
3433 + bbot = au_sbbot(sb);
3434 + amount = bbot + 1 - bindex;
3435 + h_dentry = au_br_dentry(br);
3436 + au_sbilist_lock();
3437 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3438 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3439 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3440 + au_set_h_dptr(root, bindex, dget(h_dentry));
3441 + h_inode = d_inode(h_dentry);
3442 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3443 + au_sbilist_unlock();
3446 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3449 + aufs_bindex_t bbot, add_bindex;
3450 + struct dentry *root, *h_dentry;
3451 + struct inode *root_inode;
3452 + struct au_branch *add_branch;
3454 + root = sb->s_root;
3455 + root_inode = d_inode(root);
3456 + IMustLock(root_inode);
3457 + IiMustWriteLock(root_inode);
3458 + err = test_add(sb, add, remount);
3459 + if (unlikely(err < 0))
3463 + goto out; /* success */
3466 + bbot = au_sbbot(sb);
3467 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3468 + err = PTR_ERR(add_branch);
3469 + if (IS_ERR(add_branch))
3472 + err = au_br_init(add_branch, sb, add);
3473 + if (unlikely(err)) {
3474 + au_br_do_free(add_branch);
3478 + add_bindex = add->bindex;
3479 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3480 + au_br_do_add(sb, add_branch, add_bindex);
3481 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3482 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3484 + h_dentry = add->path.dentry;
3485 + if (!add_bindex) {
3486 + au_cpup_attr_all(root_inode, /*force*/1);
3487 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3489 + au_add_nlink(root_inode, d_inode(h_dentry));
3495 +/* ---------------------------------------------------------------------- */
3497 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3498 + unsigned long long max __maybe_unused,
3501 + unsigned long long n;
3502 + struct file **p, *f;
3503 + struct hlist_bl_head *files;
3504 + struct hlist_bl_node *pos;
3505 + struct au_finfo *finfo;
3509 + files = &au_sbi(sb)->si_files;
3510 + hlist_bl_lock(files);
3511 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3512 + f = finfo->fi_file;
3514 + && !special_file(file_inode(f)->i_mode)) {
3518 + AuDebugOn(n > max);
3521 + hlist_bl_unlock(files);
3526 +static struct file **au_farray_alloc(struct super_block *sb,
3527 + unsigned long long *max)
3529 + struct au_sbinfo *sbi;
3532 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3533 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3536 +static void au_farray_free(struct file **a, unsigned long long max)
3538 + unsigned long long ull;
3540 + for (ull = 0; ull < max; ull++)
3546 +/* ---------------------------------------------------------------------- */
3552 +/* to show the line number, do not make it inlined function */
3553 +#define AuVerbose(do_info, fmt, ...) do { \
3555 + pr_info(fmt, ##__VA_ARGS__); \
3558 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3559 + aufs_bindex_t bbot)
3561 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3564 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3565 + aufs_bindex_t bbot)
3567 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3571 + * test if the branch is deletable or not.
3573 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3574 + unsigned int sigen, const unsigned int verbose)
3576 + int err, i, j, ndentry;
3577 + aufs_bindex_t btop, bbot;
3578 + struct au_dcsub_pages dpages;
3579 + struct au_dpage *dpage;
3582 + err = au_dpages_init(&dpages, GFP_NOFS);
3583 + if (unlikely(err))
3585 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3586 + if (unlikely(err))
3589 + for (i = 0; !err && i < dpages.ndpage; i++) {
3590 + dpage = dpages.dpages + i;
3591 + ndentry = dpage->ndentry;
3592 + for (j = 0; !err && j < ndentry; j++) {
3593 + d = dpage->dentries[j];
3594 + AuDebugOn(au_dcount(d) <= 0);
3595 + if (!au_digen_test(d, sigen)) {
3596 + di_read_lock_child(d, AuLock_IR);
3597 + if (unlikely(au_dbrange_test(d))) {
3598 + di_read_unlock(d, AuLock_IR);
3602 + di_write_lock_child(d);
3603 + if (unlikely(au_dbrange_test(d))) {
3604 + di_write_unlock(d);
3607 + err = au_reval_dpath(d, sigen);
3609 + di_downgrade_lock(d, AuLock_IR);
3611 + di_write_unlock(d);
3616 + /* AuDbgDentry(d); */
3617 + btop = au_dbtop(d);
3618 + bbot = au_dbbot(d);
3619 + if (btop <= bindex
3621 + && au_h_dptr(d, bindex)
3622 + && au_test_dbusy(d, btop, bbot)) {
3624 + AuVerbose(verbose, "busy %pd\n", d);
3627 + di_read_unlock(d, AuLock_IR);
3632 + au_dpages_free(&dpages);
3637 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3638 + unsigned int sigen, const unsigned int verbose)
3641 + unsigned long long max, ull;
3642 + struct inode *i, **array;
3643 + aufs_bindex_t btop, bbot;
3645 + array = au_iarray_alloc(sb, &max);
3646 + err = PTR_ERR(array);
3647 + if (IS_ERR(array))
3651 + AuDbg("b%d\n", bindex);
3652 + for (ull = 0; !err && ull < max; ull++) {
3656 + if (i->i_ino == AUFS_ROOT_INO)
3659 + /* AuDbgInode(i); */
3660 + if (au_iigen(i, NULL) == sigen)
3661 + ii_read_lock_child(i);
3663 + ii_write_lock_child(i);
3664 + err = au_refresh_hinode_self(i);
3667 + ii_downgrade_lock(i);
3669 + ii_write_unlock(i);
3674 + btop = au_ibtop(i);
3675 + bbot = au_ibbot(i);
3676 + if (btop <= bindex
3678 + && au_h_iptr(i, bindex)
3679 + && au_test_ibusy(i, btop, bbot)) {
3681 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3684 + ii_read_unlock(i);
3686 + au_iarray_free(array, max);
3692 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3693 + const unsigned int verbose)
3696 + unsigned int sigen;
3698 + sigen = au_sigen(root->d_sb);
3699 + DiMustNoWaiters(root);
3700 + IiMustNoWaiters(d_inode(root));
3701 + di_write_unlock(root);
3702 + err = test_dentry_busy(root, bindex, sigen, verbose);
3704 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3705 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3710 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3711 + struct file **to_free, int *idx)
3714 + unsigned char matched, root;
3715 + aufs_bindex_t bindex, bbot;
3716 + struct au_fidir *fidir;
3717 + struct au_hfile *hfile;
3720 + root = IS_ROOT(file->f_path.dentry);
3723 + to_free[*idx] = file;
3729 + fidir = au_fi(file)->fi_hdir;
3730 + AuDebugOn(!fidir);
3731 + bbot = au_fbbot_dir(file);
3732 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3733 + hfile = fidir->fd_hfile + bindex;
3734 + if (!hfile->hf_file)
3737 + if (hfile->hf_br->br_id == br_id) {
3749 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3750 + struct file **to_free, int opened)
3753 + unsigned long long ull, max;
3754 + aufs_bindex_t btop;
3755 + struct file *file, **array;
3756 + struct dentry *root;
3757 + struct au_hfile *hfile;
3759 + array = au_farray_alloc(sb, &max);
3760 + err = PTR_ERR(array);
3761 + if (IS_ERR(array))
3766 + root = sb->s_root;
3767 + di_write_unlock(root);
3768 + for (ull = 0; ull < max; ull++) {
3769 + file = array[ull];
3770 + if (unlikely(!file))
3773 + /* AuDbg("%pD\n", file); */
3774 + fi_read_lock(file);
3775 + btop = au_fbtop(file);
3776 + if (!d_is_dir(file->f_path.dentry)) {
3777 + hfile = &au_fi(file)->fi_htop;
3778 + if (hfile->hf_br->br_id == br_id)
3781 + err = test_dir_busy(file, br_id, to_free, &idx);
3782 + fi_read_unlock(file);
3783 + if (unlikely(err))
3786 + di_write_lock_child(root);
3787 + au_farray_free(array, max);
3788 + AuDebugOn(idx > opened);
3794 +static void br_del_file(struct file **to_free, unsigned long long opened,
3795 + aufs_bindex_t br_id)
3797 + unsigned long long ull;
3798 + aufs_bindex_t bindex, btop, bbot, bfound;
3799 + struct file *file;
3800 + struct au_fidir *fidir;
3801 + struct au_hfile *hfile;
3803 + for (ull = 0; ull < opened; ull++) {
3804 + file = to_free[ull];
3805 + if (unlikely(!file))
3808 + /* AuDbg("%pD\n", file); */
3809 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3811 + fidir = au_fi(file)->fi_hdir;
3812 + AuDebugOn(!fidir);
3813 + fi_write_lock(file);
3814 + btop = au_fbtop(file);
3815 + bbot = au_fbbot_dir(file);
3816 + for (bindex = btop; bindex <= bbot; bindex++) {
3817 + hfile = fidir->fd_hfile + bindex;
3818 + if (!hfile->hf_file)
3821 + if (hfile->hf_br->br_id == br_id) {
3826 + AuDebugOn(bfound < 0);
3827 + au_set_h_fptr(file, bfound, NULL);
3828 + if (bfound == btop) {
3829 + for (btop++; btop <= bbot; btop++)
3830 + if (au_hf_dir(file, btop)) {
3831 + au_set_fbtop(file, btop);
3835 + fi_write_unlock(file);
3839 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3840 + const aufs_bindex_t bindex,
3841 + const aufs_bindex_t bbot)
3843 + struct au_branch **brp, **p;
3845 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3847 + brp = sbinfo->si_branch + bindex;
3848 + if (bindex < bbot)
3849 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3850 + sbinfo->si_branch[0 + bbot] = NULL;
3851 + sbinfo->si_bbot--;
3853 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3856 + sbinfo->si_branch = p;
3857 + /* harmless error */
3860 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3861 + const aufs_bindex_t bbot)
3863 + struct au_hdentry *hdp, *p;
3865 + AuRwMustWriteLock(&dinfo->di_rwsem);
3867 + hdp = au_hdentry(dinfo, bindex);
3868 + if (bindex < bbot)
3869 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3870 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3873 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3876 + dinfo->di_hdentry = p;
3877 + /* harmless error */
3880 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3881 + const aufs_bindex_t bbot)
3883 + struct au_hinode *hip, *p;
3885 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3887 + hip = au_hinode(iinfo, bindex);
3888 + if (bindex < bbot)
3889 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3890 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3893 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3896 + iinfo->ii_hinode = p;
3897 + /* harmless error */
3900 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3901 + struct au_branch *br)
3903 + aufs_bindex_t bbot;
3904 + struct au_sbinfo *sbinfo;
3905 + struct dentry *root, *h_root;
3906 + struct inode *inode, *h_inode;
3907 + struct au_hinode *hinode;
3909 + SiMustWriteLock(sb);
3911 + root = sb->s_root;
3912 + inode = d_inode(root);
3913 + sbinfo = au_sbi(sb);
3914 + bbot = sbinfo->si_bbot;
3916 + h_root = au_h_dptr(root, bindex);
3917 + hinode = au_hi(inode, bindex);
3918 + h_inode = au_igrab(hinode->hi_inode);
3921 + au_sbilist_lock();
3922 + au_br_do_del_brp(sbinfo, bindex, bbot);
3923 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3924 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3925 + au_sbilist_unlock();
3927 + /* ignore an error */
3928 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3932 + au_br_do_free(br);
3935 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3936 + unsigned long long max, void *arg)
3941 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3944 + unsigned long long opened;
3945 + unsigned int mnt_flags;
3946 + aufs_bindex_t bindex, bbot, br_id;
3947 + unsigned char do_wh, verbose;
3948 + struct au_branch *br;
3949 + struct au_wbr *wbr;
3950 + struct dentry *root;
3951 + struct file **to_free;
3956 + root = sb->s_root;
3957 + bindex = au_find_dbindex(root, del->h_path.dentry);
3960 + goto out; /* success */
3962 + pr_err("%s no such branch\n", del->pathname);
3965 + AuDbg("bindex b%d\n", bindex);
3968 + mnt_flags = au_mntflags(sb);
3969 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3970 + bbot = au_sbbot(sb);
3971 + if (unlikely(!bbot)) {
3972 + AuVerbose(verbose, "no more branches left\n");
3976 + br = au_sbr(sb, bindex);
3977 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3978 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3979 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3983 + br_id = br->br_id;
3984 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3985 + if (unlikely(opened)) {
3986 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3987 + err = PTR_ERR(to_free);
3988 + if (IS_ERR(to_free))
3991 + err = test_file_busy(sb, br_id, to_free, opened);
3992 + if (unlikely(err)) {
3993 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3999 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4001 + /* instead of WbrWhMustWriteLock(wbr) */
4002 + SiMustWriteLock(sb);
4003 + for (i = 0; i < AuBrWh_Last; i++) {
4004 + dput(wbr->wbr_wh[i]);
4005 + wbr->wbr_wh[i] = NULL;
4009 + err = test_children_busy(root, bindex, verbose);
4010 + if (unlikely(err)) {
4019 + * now we confirmed the branch is deletable.
4020 + * let's free the remaining opened dirs on the branch.
4022 + di_write_unlock(root);
4023 + br_del_file(to_free, opened, br_id);
4024 + di_write_lock_child(root);
4027 + sysaufs_brs_del(sb, bindex); /* remove successors */
4028 + dbgaufs_xino_del(br); /* remove one */
4029 + au_br_do_del(sb, bindex, br);
4030 + sysaufs_brs_add(sb, bindex); /* append successors */
4031 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4034 + au_cpup_attr_all(d_inode(root), /*force*/1);
4035 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4037 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4038 + if (au_opt_test(mnt_flags, PLINK))
4039 + au_plink_half_refresh(sb, br_id);
4041 + goto out; /* success */
4045 + rerr = au_br_init_wh(sb, br, br->br_perm);
4047 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4048 + del->pathname, rerr);
4051 + au_farray_free(to_free, opened);
4055 +/* ---------------------------------------------------------------------- */
4057 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4060 + aufs_bindex_t btop, bbot;
4061 + struct aufs_ibusy ibusy;
4062 + struct inode *inode, *h_inode;
4065 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4068 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4070 + /* VERIFY_WRITE */
4071 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4072 + if (unlikely(err)) {
4079 + si_read_lock(sb, AuLock_FLUSH);
4080 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4084 + ibusy.h_ino = 0; /* invalid */
4085 + inode = ilookup(sb, ibusy.ino);
4087 + || inode->i_ino == AUFS_ROOT_INO
4088 + || au_is_bad_inode(inode))
4091 + ii_read_lock_child(inode);
4092 + btop = au_ibtop(inode);
4093 + bbot = au_ibbot(inode);
4094 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4095 + h_inode = au_h_iptr(inode, ibusy.bindex);
4096 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4097 + ibusy.h_ino = h_inode->i_ino;
4099 + ii_read_unlock(inode);
4103 + si_read_unlock(sb);
4105 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4106 + if (unlikely(err)) {
4115 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4117 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4120 +#ifdef CONFIG_COMPAT
4121 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4123 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4127 +/* ---------------------------------------------------------------------- */
4130 + * change a branch permission
4133 +static void au_warn_ima(void)
4136 + /* since it doesn't support mark_files_ro() */
4137 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4141 +static int do_need_sigen_inc(int a, int b)
4143 + return au_br_whable(a) && !au_br_whable(b);
4146 +static int need_sigen_inc(int old, int new)
4148 + return do_need_sigen_inc(old, new)
4149 + || do_need_sigen_inc(new, old);
4152 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4155 + unsigned int mnt_flags;
4156 + unsigned long long ull, max;
4157 + aufs_bindex_t br_id;
4158 + unsigned char verbose, writer;
4159 + struct file *file, *hf, **array;
4160 + struct au_hfile *hfile;
4161 + struct inode *h_inode;
4163 + mnt_flags = au_mntflags(sb);
4164 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4166 + array = au_farray_alloc(sb, &max);
4167 + err = PTR_ERR(array);
4168 + if (IS_ERR(array))
4172 + br_id = au_sbr_id(sb, bindex);
4173 + for (ull = 0; ull < max; ull++) {
4174 + file = array[ull];
4175 + if (unlikely(!file))
4178 + /* AuDbg("%pD\n", file); */
4179 + fi_read_lock(file);
4180 + if (unlikely(au_test_mmapped(file))) {
4182 + AuVerbose(verbose, "mmapped %pD\n", file);
4184 + FiMustNoWaiters(file);
4185 + fi_read_unlock(file);
4189 + hfile = &au_fi(file)->fi_htop;
4190 + hf = hfile->hf_file;
4191 + if (!d_is_reg(file->f_path.dentry)
4192 + || !(file->f_mode & FMODE_WRITE)
4193 + || hfile->hf_br->br_id != br_id
4194 + || !(hf->f_mode & FMODE_WRITE))
4195 + array[ull] = NULL;
4201 + FiMustNoWaiters(file);
4202 + fi_read_unlock(file);
4210 + for (ull = 0; ull < max; ull++) {
4211 + file = array[ull];
4215 + /* todo: already flushed? */
4217 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4218 + * approach which resets f_mode and calls mnt_drop_write() and
4219 + * file_release_write() for each file, because the branch
4220 + * attribute in aufs world is totally different from the native
4223 + /* fi_read_lock(file); */
4224 + hfile = &au_fi(file)->fi_htop;
4225 + hf = hfile->hf_file;
4226 + /* fi_read_unlock(file); */
4227 + spin_lock(&hf->f_lock);
4228 + writer = !!(hf->f_mode & FMODE_WRITER);
4229 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4230 + spin_unlock(&hf->f_lock);
4232 + h_inode = file_inode(hf);
4233 + if (hf->f_mode & FMODE_READ)
4234 + i_readcount_inc(h_inode);
4235 + put_write_access(h_inode);
4236 + __mnt_drop_write(hf->f_path.mnt);
4241 + au_farray_free(array, max);
4247 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4251 + aufs_bindex_t bindex;
4252 + struct dentry *root;
4253 + struct au_branch *br;
4254 + struct au_br_fhsm *bf;
4256 + root = sb->s_root;
4257 + bindex = au_find_dbindex(root, mod->h_root);
4260 + return 0; /* success */
4262 + pr_err("%s no such branch\n", mod->path);
4265 + AuDbg("bindex b%d\n", bindex);
4267 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4268 + if (unlikely(err))
4271 + br = au_sbr(sb, bindex);
4272 + AuDebugOn(mod->h_root != au_br_dentry(br));
4273 + if (br->br_perm == mod->perm)
4274 + return 0; /* success */
4276 + /* pre-allocate for non-fhsm --> fhsm */
4278 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4279 + err = au_fhsm_br_alloc(br);
4280 + if (unlikely(err))
4283 + br->br_fhsm = NULL;
4286 + if (au_br_writable(br->br_perm)) {
4287 + /* remove whiteout base */
4288 + err = au_br_init_wh(sb, br, mod->perm);
4289 + if (unlikely(err))
4292 + if (!au_br_writable(mod->perm)) {
4293 + /* rw --> ro, file might be mmapped */
4294 + DiMustNoWaiters(root);
4295 + IiMustNoWaiters(d_inode(root));
4296 + di_write_unlock(root);
4297 + err = au_br_mod_files_ro(sb, bindex);
4298 + /* aufs_write_lock() calls ..._child() */
4299 + di_write_lock_child(root);
4301 + if (unlikely(err)) {
4303 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4306 + rerr = au_wbr_init(br, sb, br->br_perm);
4307 + if (unlikely(rerr)) {
4308 + AuIOErr("nested error %d (%d)\n",
4310 + br->br_perm = mod->perm;
4314 + } else if (au_br_writable(mod->perm)) {
4317 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4319 + err = au_wbr_init(br, sb, mod->perm);
4320 + if (unlikely(err)) {
4321 + au_kfree_rcu(br->br_wbr);
4322 + br->br_wbr = NULL;
4326 + if (unlikely(err))
4329 + if (au_br_fhsm(br->br_perm)) {
4330 + if (!au_br_fhsm(mod->perm)) {
4331 + /* fhsm --> non-fhsm */
4332 + au_br_fhsm_fin(br->br_fhsm);
4333 + au_kfree_rcu(br->br_fhsm);
4334 + br->br_fhsm = NULL;
4336 + } else if (au_br_fhsm(mod->perm))
4337 + /* non-fhsm --> fhsm */
4340 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4341 + br->br_perm = mod->perm;
4342 + goto out; /* success */
4345 + au_kfree_try_rcu(bf);
4351 +/* ---------------------------------------------------------------------- */
4353 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4356 + struct kstatfs kstfs;
4358 + err = vfs_statfs(&br->br_path, &kstfs);
4360 + stfs->f_blocks = kstfs.f_blocks;
4361 + stfs->f_bavail = kstfs.f_bavail;
4362 + stfs->f_files = kstfs.f_files;
4363 + stfs->f_ffree = kstfs.f_ffree;
4368 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4369 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4370 +++ linux/fs/aufs/branch.h 2021-02-24 13:33:42.741013619 +0100
4372 +/* SPDX-License-Identifier: GPL-2.0 */
4374 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4376 + * This program, aufs is free software; you can redistribute it and/or modify
4377 + * it under the terms of the GNU General Public License as published by
4378 + * the Free Software Foundation; either version 2 of the License, or
4379 + * (at your option) any later version.
4381 + * This program is distributed in the hope that it will be useful,
4382 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4383 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4384 + * GNU General Public License for more details.
4386 + * You should have received a copy of the GNU General Public License
4387 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4391 + * branch filesystems and xino for them
4394 +#ifndef __AUFS_BRANCH_H__
4395 +#define __AUFS_BRANCH_H__
4399 +#include <linux/mount.h>
4400 +#include "dirren.h"
4406 +/* ---------------------------------------------------------------------- */
4410 + struct file **xi_file;
4411 + unsigned int xi_nfile;
4417 + /* reserved for future use */
4418 + /* unsigned long *bitmap; */
4419 + wait_queue_head_t wqh;
4422 + struct mutex xi_mtx; /* protects xi_file array */
4423 + struct hlist_bl_head xi_writing;
4425 + atomic_t xi_truncating;
4427 + struct kref xi_kref;
4430 +/* File-based Hierarchical Storage Management */
4431 +struct au_br_fhsm {
4432 +#ifdef CONFIG_AUFS_FHSM
4433 + struct mutex bf_lock;
4434 + unsigned long bf_jiffy;
4435 + struct aufs_stfs bf_stfs;
4440 +/* members for writable branch only */
4441 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4443 + struct au_rwsem wbr_wh_rwsem;
4444 + struct dentry *wbr_wh[AuBrWh_Last];
4445 + atomic_t wbr_wh_running;
4446 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4447 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4448 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4451 + unsigned long long wbr_bytes;
4454 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4455 +#define AuBrDynOp (AuDyLast * 4)
4457 +#ifdef CONFIG_AUFS_HFSNOTIFY
4458 +/* support for asynchronous destruction */
4459 +struct au_br_hfsnotify {
4460 + struct fsnotify_group *hfsn_group;
4464 +/* sysfs entries */
4465 +struct au_brsysfs {
4467 + struct attribute attr;
4476 +/* protected by superblock rwsem */
4478 + struct au_xino *br_xino;
4480 + aufs_bindex_t br_id;
4483 + struct path br_path;
4484 + spinlock_t br_dykey_lock;
4485 + struct au_dykey *br_dykey[AuBrDynOp];
4486 + au_lcnt_t br_nfiles; /* opened files */
4487 + au_lcnt_t br_count; /* in-use for other */
4489 + struct au_wbr *br_wbr;
4490 + struct au_br_fhsm *br_fhsm;
4492 +#ifdef CONFIG_AUFS_HFSNOTIFY
4493 + struct au_br_hfsnotify *br_hfsn;
4496 +#ifdef CONFIG_SYSFS
4497 + /* entries under sysfs per mount-point */
4498 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4501 +#ifdef CONFIG_DEBUG_FS
4502 + struct dentry *br_dbgaufs; /* xino */
4505 + struct au_dr_br br_dirren;
4508 +/* ---------------------------------------------------------------------- */
4510 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4512 + return br->br_path.mnt;
4515 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4517 + return br->br_path.dentry;
4520 +static inline struct super_block *au_br_sb(struct au_branch *br)
4522 + return au_br_mnt(br)->mnt_sb;
4525 +static inline int au_br_rdonly(struct au_branch *br)
4527 + return (sb_rdonly(au_br_sb(br))
4528 + || !au_br_writable(br->br_perm))
4532 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4534 +#ifdef CONFIG_AUFS_HNOTIFY
4535 + return !(brperm & AuBrPerm_RR);
4541 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4543 + int err, exec_flag;
4546 + exec_flag = oflag & __FMODE_EXEC;
4547 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4553 +static inline void au_xino_get(struct au_branch *br)
4555 + struct au_xino *xi;
4559 + kref_get(&xi->xi_kref);
4562 +static inline int au_xino_count(struct au_branch *br)
4565 + struct au_xino *xi;
4570 + v = kref_read(&xi->xi_kref);
4575 +/* ---------------------------------------------------------------------- */
4579 +void au_br_free(struct au_sbinfo *sinfo);
4580 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4582 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4584 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4585 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4586 +#ifdef CONFIG_COMPAT
4587 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4590 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4593 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4596 +static const loff_t au_loff_max = LLONG_MAX;
4598 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4599 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4601 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4602 + struct file *copy_src);
4604 + struct au_xino *xi; /* switch between xino and xigen */
4606 + struct path *base;
4607 + struct file *copy_src;
4609 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4611 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4613 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4615 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4616 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4618 +int au_xib_trunc(struct super_block *sb);
4619 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4621 +struct au_xino *au_xino_alloc(unsigned int nfile);
4622 +int au_xino_put(struct au_branch *br);
4623 +struct file *au_xino_file1(struct au_xino *xi);
4625 +struct au_opt_xino;
4626 +void au_xino_clr(struct super_block *sb);
4627 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4628 +struct file *au_xino_def(struct super_block *sb);
4629 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4630 + struct path *base);
4632 +ino_t au_xino_new_ino(struct super_block *sb);
4633 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4635 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4636 + ino_t h_ino, int idx);
4637 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4640 +int au_xino_path(struct seq_file *seq, struct file *file);
4642 +/* ---------------------------------------------------------------------- */
4644 +/* @idx is signed to accept -1 meaning the first file */
4645 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4647 + struct file *file;
4654 + if (idx < xi->xi_nfile)
4655 + file = xi->xi_file[idx];
4657 + file = au_xino_file1(xi);
4663 +/* ---------------------------------------------------------------------- */
4665 +/* Superblock to branch */
4667 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4669 + return au_sbr(sb, bindex)->br_id;
4673 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4675 + return au_br_mnt(au_sbr(sb, bindex));
4679 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4681 + return au_br_sb(au_sbr(sb, bindex));
4684 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4686 + return au_sbr(sb, bindex)->br_perm;
4689 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4691 + return au_br_whable(au_sbr_perm(sb, bindex));
4694 +/* ---------------------------------------------------------------------- */
4696 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4697 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4698 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4699 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4701 +#define wbr_wh_read_trylock_nested(wbr) \
4702 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4703 +#define wbr_wh_write_trylock_nested(wbr) \
4704 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4707 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4708 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4709 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4711 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4712 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4713 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4715 +/* ---------------------------------------------------------------------- */
4717 +#ifdef CONFIG_AUFS_FHSM
4718 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4720 + mutex_init(&brfhsm->bf_lock);
4721 + brfhsm->bf_jiffy = 0;
4722 + brfhsm->bf_readable = 0;
4725 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4727 + mutex_destroy(&brfhsm->bf_lock);
4730 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4731 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4734 +#endif /* __KERNEL__ */
4735 +#endif /* __AUFS_BRANCH_H__ */
4736 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4737 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4738 +++ linux/fs/aufs/conf.mk 2021-02-24 13:33:42.741013619 +0100
4740 +# SPDX-License-Identifier: GPL-2.0
4742 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4746 +AuConfStr += ${1}=${${1}}
4750 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4752 + HNOTIFY HFSNOTIFY \
4764 +$(foreach i, ${AuConfAll}, \
4765 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4767 +AuConfName = ${obj}/conf.str
4768 +${AuConfName}.tmp: FORCE
4769 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4770 +${AuConfName}: ${AuConfName}.tmp
4771 + @diff -q $< $@ > /dev/null 2>&1 || { \
4772 + echo ' GEN ' $@; \
4776 +clean-files += ${AuConfName} ${AuConfName}.tmp
4777 +${obj}/sysfs.o: ${AuConfName}
4779 +-include ${srctree}/${src}/conf_priv.mk
4780 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4781 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4782 +++ linux/fs/aufs/cpup.c 2021-02-24 13:33:42.741013619 +0100
4784 +// SPDX-License-Identifier: GPL-2.0
4786 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4788 + * This program, aufs is free software; you can redistribute it and/or modify
4789 + * it under the terms of the GNU General Public License as published by
4790 + * the Free Software Foundation; either version 2 of the License, or
4791 + * (at your option) any later version.
4793 + * This program is distributed in the hope that it will be useful,
4794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4796 + * GNU General Public License for more details.
4798 + * You should have received a copy of the GNU General Public License
4799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4803 + * copy-up functions, see wbr_policy.c for copy-down
4806 +#include <linux/fs_stack.h>
4807 +#include <linux/mm.h>
4808 +#include <linux/task_work.h>
4811 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4813 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4814 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4816 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4818 + dst->i_flags |= iflags & ~mask;
4819 + if (au_test_fs_notime(dst->i_sb))
4820 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4823 +void au_cpup_attr_timesizes(struct inode *inode)
4825 + struct inode *h_inode;
4827 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4828 + fsstack_copy_attr_times(inode, h_inode);
4829 + fsstack_copy_inode_size(inode, h_inode);
4832 +void au_cpup_attr_nlink(struct inode *inode, int force)
4834 + struct inode *h_inode;
4835 + struct super_block *sb;
4836 + aufs_bindex_t bindex, bbot;
4839 + bindex = au_ibtop(inode);
4840 + h_inode = au_h_iptr(inode, bindex);
4842 + && !S_ISDIR(h_inode->i_mode)
4843 + && au_opt_test(au_mntflags(sb), PLINK)
4844 + && au_plink_test(inode))
4848 + * 0 can happen in revalidating.
4849 + * h_inode->i_mutex may not be held here, but it is harmless since once
4850 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4852 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4853 + * the incorrect link count.
4855 + set_nlink(inode, h_inode->i_nlink);
4858 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4859 + * it may includes whplink directory.
4861 + if (S_ISDIR(h_inode->i_mode)) {
4862 + bbot = au_ibbot(inode);
4863 + for (bindex++; bindex <= bbot; bindex++) {
4864 + h_inode = au_h_iptr(inode, bindex);
4866 + au_add_nlink(inode, h_inode);
4871 +void au_cpup_attr_changeable(struct inode *inode)
4873 + struct inode *h_inode;
4875 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4876 + inode->i_mode = h_inode->i_mode;
4877 + inode->i_uid = h_inode->i_uid;
4878 + inode->i_gid = h_inode->i_gid;
4879 + au_cpup_attr_timesizes(inode);
4880 + au_cpup_attr_flags(inode, h_inode->i_flags);
4883 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4885 + struct au_iinfo *iinfo = au_ii(inode);
4887 + IiMustWriteLock(inode);
4889 + iinfo->ii_higen = h_inode->i_generation;
4890 + iinfo->ii_hsb1 = h_inode->i_sb;
4893 +void au_cpup_attr_all(struct inode *inode, int force)
4895 + struct inode *h_inode;
4897 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4898 + au_cpup_attr_changeable(inode);
4899 + if (inode->i_nlink > 0)
4900 + au_cpup_attr_nlink(inode, force);
4901 + inode->i_rdev = h_inode->i_rdev;
4902 + inode->i_blkbits = h_inode->i_blkbits;
4903 + au_cpup_igen(inode, h_inode);
4906 +/* ---------------------------------------------------------------------- */
4908 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4910 +/* keep the timestamps of the parent dir when cpup */
4911 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4912 + struct path *h_path)
4914 + struct inode *h_inode;
4916 + dt->dt_dentry = dentry;
4917 + dt->dt_h_path = *h_path;
4918 + h_inode = d_inode(h_path->dentry);
4919 + dt->dt_atime = h_inode->i_atime;
4920 + dt->dt_mtime = h_inode->i_mtime;
4924 +void au_dtime_revert(struct au_dtime *dt)
4926 + struct iattr attr;
4929 + attr.ia_atime = dt->dt_atime;
4930 + attr.ia_mtime = dt->dt_mtime;
4931 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4932 + | ATTR_ATIME | ATTR_ATIME_SET;
4934 + /* no delegation since this is a directory */
4935 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4936 + if (unlikely(err))
4937 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4940 +/* ---------------------------------------------------------------------- */
4942 +/* internal use only */
4943 +struct au_cpup_reg_attr {
4946 + unsigned int iflags; /* inode->i_flags */
4949 +static noinline_for_stack
4950 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4951 + struct au_cpup_reg_attr *h_src_attr)
4953 + int err, sbits, icex;
4954 + unsigned int mnt_flags;
4955 + unsigned char verbose;
4957 + struct path h_path;
4958 + struct inode *h_isrc, *h_idst;
4959 + struct kstat *h_st;
4960 + struct au_branch *br;
4962 + h_path.dentry = au_h_dptr(dst, bindex);
4963 + h_idst = d_inode(h_path.dentry);
4964 + br = au_sbr(dst->d_sb, bindex);
4965 + h_path.mnt = au_br_mnt(br);
4966 + h_isrc = d_inode(h_src);
4967 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4968 + | ATTR_ATIME | ATTR_MTIME
4969 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4970 + if (h_src_attr && h_src_attr->valid) {
4971 + h_st = &h_src_attr->st;
4972 + ia.ia_uid = h_st->uid;
4973 + ia.ia_gid = h_st->gid;
4974 + ia.ia_atime = h_st->atime;
4975 + ia.ia_mtime = h_st->mtime;
4976 + if (h_idst->i_mode != h_st->mode
4977 + && !S_ISLNK(h_idst->i_mode)) {
4978 + ia.ia_valid |= ATTR_MODE;
4979 + ia.ia_mode = h_st->mode;
4981 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4982 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4984 + ia.ia_uid = h_isrc->i_uid;
4985 + ia.ia_gid = h_isrc->i_gid;
4986 + ia.ia_atime = h_isrc->i_atime;
4987 + ia.ia_mtime = h_isrc->i_mtime;
4988 + if (h_idst->i_mode != h_isrc->i_mode
4989 + && !S_ISLNK(h_idst->i_mode)) {
4990 + ia.ia_valid |= ATTR_MODE;
4991 + ia.ia_mode = h_isrc->i_mode;
4993 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4994 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4996 + /* no delegation since it is just created */
4997 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4999 + /* is this nfs only? */
5000 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5001 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5002 + ia.ia_mode = h_isrc->i_mode;
5003 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5006 + icex = br->br_perm & AuBrAttr_ICEX;
5008 + mnt_flags = au_mntflags(dst->d_sb);
5009 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5010 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5016 +/* ---------------------------------------------------------------------- */
5018 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5019 + char *buf, unsigned long blksize)
5022 + size_t sz, rbytes, wbytes;
5023 + unsigned char all_zero;
5025 + struct inode *h_inode;
5026 + /* reduce stack usage */
5029 + zp = page_address(ZERO_PAGE(0));
5030 + if (unlikely(!zp))
5031 + return -ENOMEM; /* possible? */
5036 + AuDbg("len %lld\n", len);
5038 + if (len < blksize)
5042 + /* todo: signal_pending? */
5043 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5044 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5047 + if (unlikely(err < 0))
5051 + if (len >= rbytes && rbytes == blksize)
5052 + all_zero = !memcmp(buf, zp, rbytes);
5059 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5061 + /* todo: signal_pending? */
5062 + if (unlikely(err == -EAGAIN || err == -EINTR))
5064 + if (unlikely(err < 0))
5069 + if (unlikely(err < 0))
5075 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5077 + if (unlikely(res < 0))
5084 + /* the last block may be a hole */
5085 + if (!err && all_zero) {
5086 + AuLabel(last hole);
5089 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5090 + /* nfs requires this step to make last hole */
5091 + /* is this only nfs? */
5093 + /* todo: signal_pending? */
5094 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5095 + } while (err == -EAGAIN || err == -EINTR);
5102 + ia->ia_size = dst->f_pos;
5103 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5104 + ia->ia_file = dst;
5105 + h_inode = file_inode(dst);
5106 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5107 + /* no delegation since it is just created */
5108 + err = vfsub_notify_change(&dst->f_path, ia,
5109 + /*delegated*/NULL);
5110 + inode_unlock(h_inode);
5117 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5120 + unsigned long blksize;
5121 + unsigned char do_kfree;
5123 + struct super_block *h_sb;
5126 + h_sb = file_inode(dst)->i_sb;
5127 + blksize = h_sb->s_blocksize;
5128 + if (!blksize || PAGE_SIZE < blksize)
5129 + blksize = PAGE_SIZE;
5130 + AuDbg("blksize %lu\n", blksize);
5131 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5133 + buf = kmalloc(blksize, GFP_NOFS);
5135 + buf = (void *)__get_free_page(GFP_NOFS);
5136 + if (unlikely(!buf))
5139 + if (len > (1 << 22))
5140 + AuDbg("copying a large file %lld\n", (long long)len);
5144 + err = au_do_copy_file(dst, src, len, buf, blksize);
5146 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5147 + au_kfree_do_rcu(buf);
5149 + free_page((unsigned long)buf);
5155 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5158 + struct super_block *h_src_sb;
5159 + struct inode *h_src_inode;
5161 + h_src_inode = file_inode(src);
5162 + h_src_sb = h_src_inode->i_sb;
5164 + /* XFS acquires inode_lock */
5165 + if (!au_test_xfs(h_src_sb))
5166 + err = au_copy_file(dst, src, len);
5168 + inode_unlock_shared(h_src_inode);
5169 + err = au_copy_file(dst, src, len);
5170 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5176 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5180 + struct super_block *h_src_sb;
5181 + struct inode *h_src_inode;
5183 + h_src_inode = file_inode(src);
5184 + h_src_sb = h_src_inode->i_sb;
5185 + if (h_src_sb != file_inode(dst)->i_sb
5186 + || !dst->f_op->remap_file_range) {
5187 + err = au_do_copy(dst, src, len);
5191 + if (!au_test_nfs(h_src_sb)) {
5192 + inode_unlock_shared(h_src_inode);
5193 + lo = vfsub_clone_file_range(src, dst, len);
5194 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5196 + lo = vfsub_clone_file_range(src, dst, len);
5199 + goto out; /* success */
5200 + } else if (lo >= 0)
5201 + /* todo: possible? */
5202 + /* paritially succeeded */
5203 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5204 + else if (lo != -EOPNOTSUPP) {
5205 + /* older XFS has a condition in cloning */
5210 + /* the backend fs on NFS may not support cloning */
5211 + err = au_do_copy(dst, src, len);
5219 + * to support a sparse file which is opened with O_APPEND,
5220 + * we need to close the file.
5222 +static int au_cp_regular(struct au_cp_generic *cpg)
5225 + enum { SRC, DST };
5227 + aufs_bindex_t bindex;
5228 + unsigned int flags;
5229 + struct dentry *dentry;
5231 + struct file *file;
5234 + .bindex = cpg->bsrc,
5235 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5238 + .bindex = cpg->bdst,
5239 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5240 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5243 + struct au_branch *br;
5244 + struct super_block *sb, *h_src_sb;
5245 + struct inode *h_src_inode;
5246 + struct task_struct *tsk = current;
5248 + /* bsrc branch can be ro/rw. */
5249 + sb = cpg->dentry->d_sb;
5251 + for (i = 0; i < 2; i++, f++) {
5252 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5253 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5254 + /*file*/NULL, f->force_wr);
5255 + if (IS_ERR(f->file)) {
5256 + err = PTR_ERR(f->file);
5264 + /* try stopping to update while we copyup */
5265 + h_src_inode = d_inode(file[SRC].dentry);
5266 + h_src_sb = h_src_inode->i_sb;
5267 + if (!au_test_nfs(h_src_sb))
5268 + IMustLock(h_src_inode);
5269 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5271 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5272 + if (tsk->flags & PF_KTHREAD)
5273 + __fput_sync(file[DST].file);
5275 + /* it happened actually */
5276 + fput(file[DST].file);
5279 + * we have to call both since we don't know which place the file
5283 + flush_delayed_fput();
5285 + br = au_sbr(sb, file[DST].bindex);
5286 + au_lcnt_dec(&br->br_nfiles);
5289 + fput(file[SRC].file);
5290 + br = au_sbr(sb, file[SRC].bindex);
5291 + au_lcnt_dec(&br->br_nfiles);
5296 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5297 + struct au_cpup_reg_attr *h_src_attr)
5301 + struct path h_path;
5302 + struct inode *h_src_inode, *h_dst_inode;
5305 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5306 + l = i_size_read(h_src_inode);
5307 + if (cpg->len == -1 || l < cpg->len)
5310 + /* try stopping to update while we are referencing */
5311 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5312 + au_pin_hdir_unlock(cpg->pin);
5314 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5315 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5316 + h_src_attr->iflags = h_src_inode->i_flags;
5317 + if (!au_test_nfs(h_src_inode->i_sb))
5318 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5320 + inode_unlock_shared(h_src_inode);
5321 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5322 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5324 + if (unlikely(err)) {
5325 + inode_unlock_shared(h_src_inode);
5328 + h_src_attr->valid = 1;
5329 + if (!au_test_nfs(h_src_inode->i_sb)) {
5330 + err = au_cp_regular(cpg);
5331 + inode_unlock_shared(h_src_inode);
5333 + inode_unlock_shared(h_src_inode);
5334 + err = au_cp_regular(cpg);
5336 + rerr = au_pin_hdir_relock(cpg->pin);
5340 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5341 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5342 + h_dst_inode = d_inode(h_path.dentry);
5343 + spin_lock(&h_dst_inode->i_lock);
5344 + h_dst_inode->i_state |= I_LINKABLE;
5345 + spin_unlock(&h_dst_inode->i_lock);
5352 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5353 + struct inode *h_dir)
5356 + DEFINE_DELAYED_CALL(done);
5359 + sym = vfs_get_link(h_src, &done);
5360 + err = PTR_ERR(sym);
5364 + err = vfsub_symlink(h_dir, h_path, sym);
5367 + do_delayed_call(&done);
5372 + * regardless 'acl' option, reset all ACL.
5373 + * All ACL will be copied up later from the original entry on the lower branch.
5375 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5378 + struct dentry *h_dentry;
5379 + struct inode *h_inode;
5381 + h_dentry = h_path->dentry;
5382 + h_inode = d_inode(h_dentry);
5383 + /* forget_all_cached_acls(h_inode)); */
5384 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5386 + if (err == -EOPNOTSUPP)
5389 + err = vfsub_acl_chmod(h_inode, mode);
5395 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5396 + struct inode *h_dir, struct path *h_path)
5399 + struct inode *dir, *inode;
5401 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5403 + if (err == -EOPNOTSUPP)
5405 + if (unlikely(err))
5409 + * strange behaviour from the users view,
5410 + * particularly setattr case
5412 + dir = d_inode(dst_parent);
5413 + if (au_ibtop(dir) == cpg->bdst)
5414 + au_cpup_attr_nlink(dir, /*force*/1);
5415 + inode = d_inode(cpg->dentry);
5416 + au_cpup_attr_nlink(inode, /*force*/1);
5422 +static noinline_for_stack
5423 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5424 + struct au_cpup_reg_attr *h_src_attr)
5428 + unsigned int mnt_flags;
5429 + unsigned char isdir, isreg, force;
5430 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5431 + struct au_dtime dt;
5432 + struct path h_path;
5433 + struct dentry *h_src, *h_dst, *h_parent;
5434 + struct inode *h_inode, *h_dir;
5435 + struct super_block *sb;
5437 + /* bsrc branch can be ro/rw. */
5438 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5439 + h_inode = d_inode(h_src);
5440 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5442 + /* try stopping to be referenced while we are creating */
5443 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5444 + if (au_ftest_cpup(cpg->flags, RENAME))
5445 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5446 + AUFS_WH_PFX_LEN));
5447 + h_parent = h_dst->d_parent; /* dir inode is locked */
5448 + h_dir = d_inode(h_parent);
5450 + AuDebugOn(h_parent != h_dst->d_parent);
5452 + sb = cpg->dentry->d_sb;
5453 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5455 + h_path.dentry = h_parent;
5456 + au_dtime_store(&dt, dst_parent, &h_path);
5458 + h_path.dentry = h_dst;
5462 + mode = h_inode->i_mode;
5463 + switch (mode & S_IFMT) {
5466 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5468 + err = au_do_cpup_regular(cpg, h_src_attr);
5472 + err = vfsub_mkdir(h_dir, &h_path, mode);
5474 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5477 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5481 + AuDebugOn(!capable(CAP_MKNOD));
5485 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5488 + AuIOErr("Unknown inode type 0%o\n", mode);
5492 + err = au_reset_acl(h_dir, &h_path, mode);
5494 + mnt_flags = au_mntflags(sb);
5495 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5497 + && au_opt_test(mnt_flags, XINO)
5498 + && (h_inode->i_nlink == 1
5499 + || (h_inode->i_state & I_LINKABLE))
5500 + /* todo: unnecessary? */
5501 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5502 + && cpg->bdst < cpg->bsrc
5503 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5504 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5505 + /* ignore this error */
5510 + force = !!cpg->len;
5511 + if (cpg->len == -1)
5512 + force = !!i_size_read(h_inode);
5514 + au_fhsm_wrote(sb, cpg->bdst, force);
5518 + au_dtime_revert(&dt);
5522 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5525 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5526 + struct inode *h_dir;
5527 + aufs_bindex_t bdst;
5529 + dentry = cpg->dentry;
5531 + h_dentry = au_h_dptr(dentry, bdst);
5532 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5534 + au_set_h_dptr(dentry, bdst, NULL);
5535 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5537 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5538 + au_set_h_dptr(dentry, bdst, h_dentry);
5541 + parent = dget_parent(dentry);
5542 + h_parent = au_h_dptr(parent, bdst);
5544 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5545 + if (IS_ERR(h_path->dentry))
5546 + err = PTR_ERR(h_path->dentry);
5548 + if (unlikely(err))
5551 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5552 + h_dir = d_inode(h_parent);
5554 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5555 + /* no delegation since it is just created */
5556 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5558 + dput(h_path->dentry);
5565 + * copyup the @dentry from @bsrc to @bdst.
5566 + * the caller must set the both of lower dentries.
5567 + * @len is for truncating when it is -1 copyup the entire file.
5568 + * in link/rename cases, @dst_parent may be different from the real one.
5569 + * basic->bsrc can be larger than basic->bdst.
5570 + * aufs doesn't touch the credential so
5571 + * security_inode_copy_up{,_xattr}() are unnecessary.
5573 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5576 + aufs_bindex_t old_ibtop;
5577 + unsigned char isdir, plink;
5578 + struct dentry *h_src, *h_dst, *h_parent;
5579 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5580 + struct super_block *sb;
5581 + struct au_branch *br;
5582 + /* to reduce stack size */
5584 + struct au_dtime dt;
5585 + struct path h_path;
5586 + struct au_cpup_reg_attr h_src_attr;
5590 + a = kmalloc(sizeof(*a), GFP_NOFS);
5593 + a->h_src_attr.valid = 0;
5595 + sb = cpg->dentry->d_sb;
5596 + br = au_sbr(sb, cpg->bdst);
5597 + a->h_path.mnt = au_br_mnt(br);
5598 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5599 + h_parent = h_dst->d_parent; /* dir inode is locked */
5600 + h_dir = d_inode(h_parent);
5603 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5604 + inode = d_inode(cpg->dentry);
5607 + dst_parent = dget_parent(cpg->dentry);
5611 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5612 + dst_inode = au_h_iptr(inode, cpg->bdst);
5614 + if (unlikely(!plink)) {
5616 + AuIOErr("hi%lu(i%lu) exists on b%d "
5617 + "but plink is disabled\n",
5618 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5622 + if (dst_inode->i_nlink) {
5623 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5625 + h_src = au_plink_lkup(inode, cpg->bdst);
5626 + err = PTR_ERR(h_src);
5627 + if (IS_ERR(h_src))
5629 + if (unlikely(d_is_negative(h_src))) {
5631 + AuIOErr("i%lu exists on b%d "
5632 + "but not pseudo-linked\n",
5633 + inode->i_ino, cpg->bdst);
5639 + a->h_path.dentry = h_parent;
5640 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5643 + a->h_path.dentry = h_dst;
5645 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5646 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5647 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5649 + au_dtime_revert(&a->dt);
5650 + if (unlikely(err == -EWOULDBLOCK)) {
5651 + pr_warn("cannot retry for NFSv4 delegation"
5652 + " for an internal link\n");
5658 + /* todo: cpup_wh_file? */
5660 + au_update_ibrange(inode, /*do_put_zero*/1);
5663 + isdir = S_ISDIR(inode->i_mode);
5664 + old_ibtop = au_ibtop(inode);
5665 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5666 + if (unlikely(err))
5668 + dst_inode = d_inode(h_dst);
5669 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5670 + /* todo: necessary? */
5671 + /* au_pin_hdir_unlock(cpg->pin); */
5673 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5674 + if (unlikely(err)) {
5675 + /* todo: necessary? */
5676 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5677 + inode_unlock(dst_inode);
5681 + if (cpg->bdst < old_ibtop) {
5682 + if (S_ISREG(inode->i_mode)) {
5683 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5684 + if (unlikely(err)) {
5685 + /* ignore an error */
5686 + /* au_pin_hdir_relock(cpg->pin); */
5687 + inode_unlock(dst_inode);
5691 + au_set_ibtop(inode, cpg->bdst);
5693 + au_set_ibbot(inode, cpg->bdst);
5694 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5695 + au_hi_flags(inode, isdir));
5697 + /* todo: necessary? */
5698 + /* err = au_pin_hdir_relock(cpg->pin); */
5699 + inode_unlock(dst_inode);
5700 + if (unlikely(err))
5703 + src_inode = d_inode(h_src);
5705 + && (src_inode->i_nlink > 1
5706 + || src_inode->i_state & I_LINKABLE)
5708 + au_plink_append(inode, cpg->bdst, h_dst);
5710 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5711 + a->h_path.dentry = h_dst;
5712 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5715 + goto out_parent; /* success */
5719 + a->h_path.dentry = h_parent;
5720 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5721 + a->h_path.dentry = h_dst;
5723 + if (d_is_positive(h_dst)) {
5725 + /* no delegation since it is just created */
5726 + rerr = vfsub_unlink(h_dir, &a->h_path,
5727 + /*delegated*/NULL, /*force*/0);
5729 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5731 + au_dtime_revert(&a->dt);
5733 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5743 +#if 0 /* reserved */
5744 +struct au_cpup_single_args {
5746 + struct au_cp_generic *cpg;
5747 + struct dentry *dst_parent;
5750 +static void au_call_cpup_single(void *args)
5752 + struct au_cpup_single_args *a = args;
5754 + au_pin_hdir_acquire_nest(a->cpg->pin);
5755 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5756 + au_pin_hdir_release(a->cpg->pin);
5761 + * prevent SIGXFSZ in copy-up.
5762 + * testing CAP_MKNOD is for generic fs,
5763 + * but CAP_FSETID is for xfs only, currently.
5765 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5768 + struct super_block *sb;
5769 + struct inode *h_dir;
5772 + sb = au_pinned_parent(pin)->d_sb;
5773 + if (!au_wkq_test()
5774 + && (!au_sbi(sb)->si_plink_maint_pid
5775 + || au_plink_maint(sb, AuLock_NOPLM))) {
5776 + switch (mode & S_IFMT) {
5778 + /* no condition about RLIMIT_FSIZE and the file size */
5783 + do_sio = !capable(CAP_MKNOD);
5787 + do_sio = ((mode & (S_ISUID | S_ISGID))
5788 + && !capable(CAP_FSETID));
5789 + /* this workaround may be removed in the future */
5791 + h_dir = au_pinned_h_dir(pin);
5792 + do_sio = h_dir->i_mode & S_ISVTX;
5799 +#if 0 /* reserved */
5800 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5803 + struct dentry *h_dentry;
5805 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5806 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5807 + err = au_cpup_single(cpg, dst_parent);
5809 + struct au_cpup_single_args args = {
5812 + .dst_parent = dst_parent
5814 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5815 + if (unlikely(wkq_err))
5824 + * copyup the @dentry from the first active lower branch to @bdst,
5825 + * using au_cpup_single().
5827 +static int au_cpup_simple(struct au_cp_generic *cpg)
5830 + unsigned int flags_orig;
5831 + struct dentry *dentry;
5833 + AuDebugOn(cpg->bsrc < 0);
5835 + dentry = cpg->dentry;
5836 + DiMustWriteLock(dentry);
5838 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5840 + flags_orig = cpg->flags;
5841 + au_fset_cpup(cpg->flags, RENAME);
5842 + err = au_cpup_single(cpg, NULL);
5843 + cpg->flags = flags_orig;
5845 + return 0; /* success */
5848 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5849 + au_set_dbtop(dentry, cpg->bsrc);
5855 +struct au_cpup_simple_args {
5857 + struct au_cp_generic *cpg;
5860 +static void au_call_cpup_simple(void *args)
5862 + struct au_cpup_simple_args *a = args;
5864 + au_pin_hdir_acquire_nest(a->cpg->pin);
5865 + *a->errp = au_cpup_simple(a->cpg);
5866 + au_pin_hdir_release(a->cpg->pin);
5869 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5872 + struct dentry *dentry, *parent;
5873 + struct file *h_file;
5874 + struct inode *h_dir;
5876 + dentry = cpg->dentry;
5878 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5879 + AuDebugOn(cpg->bsrc < 0);
5880 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5881 + err = PTR_ERR(h_file);
5882 + if (IS_ERR(h_file))
5886 + parent = dget_parent(dentry);
5887 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5888 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5889 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5890 + err = au_cpup_simple(cpg);
5892 + struct au_cpup_simple_args args = {
5896 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5897 + if (unlikely(wkq_err))
5903 + au_h_open_post(dentry, cpg->bsrc, h_file);
5909 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5911 + aufs_bindex_t bsrc, bbot;
5912 + struct dentry *dentry, *h_dentry;
5914 + if (cpg->bsrc < 0) {
5915 + dentry = cpg->dentry;
5916 + bbot = au_dbbot(dentry);
5917 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5918 + h_dentry = au_h_dptr(dentry, bsrc);
5920 + AuDebugOn(d_is_negative(h_dentry));
5924 + AuDebugOn(bsrc > bbot);
5927 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5928 + return au_do_sio_cpup_simple(cpg);
5931 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5933 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5934 + return au_do_sio_cpup_simple(cpg);
5937 +/* ---------------------------------------------------------------------- */
5940 + * copyup the deleted file for writing.
5942 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5943 + struct file *file)
5946 + unsigned int flags_orig;
5947 + aufs_bindex_t bsrc_orig;
5948 + struct au_dinfo *dinfo;
5950 + struct au_hdentry *hd;
5951 + struct dentry *h_dentry;
5954 + dinfo = au_di(cpg->dentry);
5955 + AuRwMustWriteLock(&dinfo->di_rwsem);
5957 + bsrc_orig = cpg->bsrc;
5958 + cpg->bsrc = dinfo->di_btop;
5959 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5960 + hdst.h_dentry = hdst.hd->hd_dentry;
5961 + hdst.hd->hd_dentry = wh_dentry;
5962 + dinfo->di_btop = cpg->bdst;
5964 + hsrc.h_dentry = NULL;
5966 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5967 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5968 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5970 + flags_orig = cpg->flags;
5971 + cpg->flags = !AuCpup_DTIME;
5972 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5973 + cpg->flags = flags_orig;
5976 + err = au_reopen_nondir(file);
5977 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5979 + hdst.hd->hd_dentry = hdst.h_dentry;
5980 + dinfo->di_btop = cpg->bsrc;
5981 + cpg->bsrc = bsrc_orig;
5986 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5989 + aufs_bindex_t bdst;
5990 + struct au_dtime dt;
5991 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5992 + struct au_branch *br;
5993 + struct path h_path;
5995 + dentry = cpg->dentry;
5997 + br = au_sbr(dentry->d_sb, bdst);
5998 + parent = dget_parent(dentry);
5999 + h_parent = au_h_dptr(parent, bdst);
6000 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6001 + err = PTR_ERR(wh_dentry);
6002 + if (IS_ERR(wh_dentry))
6005 + h_path.dentry = h_parent;
6006 + h_path.mnt = au_br_mnt(br);
6007 + au_dtime_store(&dt, parent, &h_path);
6008 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6009 + if (unlikely(err))
6013 + h_path.dentry = wh_dentry;
6014 + if (!d_is_dir(wh_dentry)) {
6015 + /* no delegation since it is just created */
6016 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6017 + /*delegated*/NULL, /*force*/0);
6019 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6020 + if (unlikely(err)) {
6021 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6025 + au_dtime_revert(&dt);
6026 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6035 +struct au_cpup_wh_args {
6037 + struct au_cp_generic *cpg;
6038 + struct file *file;
6041 +static void au_call_cpup_wh(void *args)
6043 + struct au_cpup_wh_args *a = args;
6045 + au_pin_hdir_acquire_nest(a->cpg->pin);
6046 + *a->errp = au_cpup_wh(a->cpg, a->file);
6047 + au_pin_hdir_release(a->cpg->pin);
6050 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6053 + aufs_bindex_t bdst;
6054 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6055 + struct inode *dir, *h_dir, *h_tmpdir;
6056 + struct au_wbr *wbr;
6057 + struct au_pin wh_pin, *pin_orig;
6059 + dentry = cpg->dentry;
6061 + parent = dget_parent(dentry);
6062 + dir = d_inode(parent);
6065 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6068 + if (!h_dir->i_nlink) {
6069 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6070 + h_orph = wbr->wbr_orph;
6072 + h_parent = dget(au_h_dptr(parent, bdst));
6073 + au_set_h_dptr(parent, bdst, dget(h_orph));
6074 + h_tmpdir = d_inode(h_orph);
6075 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6077 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6078 + /* todo: au_h_open_pre()? */
6080 + pin_orig = cpg->pin;
6081 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6082 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6083 + cpg->pin = &wh_pin;
6086 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6087 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6088 + err = au_cpup_wh(cpg, file);
6090 + struct au_cpup_wh_args args = {
6095 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6096 + if (unlikely(wkq_err))
6101 + inode_unlock(h_tmpdir);
6102 + /* todo: au_h_open_post()? */
6103 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6104 + au_set_h_dptr(parent, bdst, h_parent);
6105 + AuDebugOn(!pin_orig);
6106 + cpg->pin = pin_orig;
6114 +/* ---------------------------------------------------------------------- */
6117 + * generic routine for both of copy-up and copy-down.
6119 +/* cf. revalidate function in file.c */
6120 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6121 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6122 + struct au_pin *pin,
6123 + struct dentry *h_parent, void *arg),
6127 + struct au_pin pin;
6128 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6131 + parent = dget_parent(dentry);
6132 + if (IS_ROOT(parent))
6135 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6136 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6138 + /* do not use au_dpage */
6139 + real_parent = parent;
6142 + parent = dget_parent(dentry);
6143 + h_parent = au_h_dptr(parent, bdst);
6145 + goto out; /* success */
6147 + /* find top dir which is necessary to cpup */
6151 + parent = dget_parent(d);
6152 + di_read_lock_parent3(parent, !AuLock_IR);
6153 + h_parent = au_h_dptr(parent, bdst);
6154 + di_read_unlock(parent, !AuLock_IR);
6155 + } while (!h_parent);
6157 + if (d != real_parent)
6158 + di_write_lock_child3(d);
6160 + /* somebody else might create while we were sleeping */
6161 + h_dentry = au_h_dptr(d, bdst);
6162 + if (!h_dentry || d_is_negative(h_dentry)) {
6164 + au_update_dbtop(d);
6166 + au_pin_set_dentry(&pin, d);
6167 + err = au_do_pin(&pin);
6169 + err = cp(d, bdst, &pin, h_parent, arg);
6174 + if (d != real_parent)
6175 + di_write_unlock(d);
6176 + if (unlikely(err))
6185 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6186 + struct au_pin *pin,
6187 + struct dentry *h_parent __maybe_unused,
6188 + void *arg __maybe_unused)
6190 + struct au_cp_generic cpg = {
6196 + .flags = AuCpup_DTIME
6198 + return au_sio_cpup_simple(&cpg);
6201 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6203 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6206 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6209 + struct dentry *parent;
6210 + struct inode *dir;
6212 + parent = dget_parent(dentry);
6213 + dir = d_inode(parent);
6215 + if (au_h_iptr(dir, bdst))
6218 + di_read_unlock(parent, AuLock_IR);
6219 + di_write_lock_parent(parent);
6220 + /* someone else might change our inode while we were sleeping */
6221 + if (!au_h_iptr(dir, bdst))
6222 + err = au_cpup_dirs(dentry, bdst);
6223 + di_downgrade_lock(parent, AuLock_IR);
6229 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6230 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6231 +++ linux/fs/aufs/cpup.h 2021-02-24 13:33:42.741013619 +0100
6233 +/* SPDX-License-Identifier: GPL-2.0 */
6235 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6237 + * This program, aufs is free software; you can redistribute it and/or modify
6238 + * it under the terms of the GNU General Public License as published by
6239 + * the Free Software Foundation; either version 2 of the License, or
6240 + * (at your option) any later version.
6242 + * This program is distributed in the hope that it will be useful,
6243 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6244 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6245 + * GNU General Public License for more details.
6247 + * You should have received a copy of the GNU General Public License
6248 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6252 + * copy-up/down functions
6255 +#ifndef __AUFS_CPUP_H__
6256 +#define __AUFS_CPUP_H__
6260 +#include <linux/path.h>
6266 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6267 +void au_cpup_attr_timesizes(struct inode *inode);
6268 +void au_cpup_attr_nlink(struct inode *inode, int force);
6269 +void au_cpup_attr_changeable(struct inode *inode);
6270 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6271 +void au_cpup_attr_all(struct inode *inode, int force);
6273 +/* ---------------------------------------------------------------------- */
6275 +struct au_cp_generic {
6276 + struct dentry *dentry;
6277 + aufs_bindex_t bdst, bsrc;
6279 + struct au_pin *pin;
6280 + unsigned int flags;
6284 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6285 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6287 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6288 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6290 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6292 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6293 + the branch is marked as RO */
6295 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6296 +#undef AuCpup_HOPEN
6297 +#define AuCpup_HOPEN 0
6300 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6301 +#define au_fset_cpup(flags, name) \
6302 + do { (flags) |= AuCpup_##name; } while (0)
6303 +#define au_fclr_cpup(flags, name) \
6304 + do { (flags) &= ~AuCpup_##name; } while (0)
6306 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6307 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6308 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6309 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6311 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6312 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6313 + struct au_pin *pin,
6314 + struct dentry *h_parent, void *arg),
6316 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6317 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6319 +/* ---------------------------------------------------------------------- */
6321 +/* keep timestamps when copyup */
6323 + struct dentry *dt_dentry;
6324 + struct path dt_h_path;
6325 + struct timespec64 dt_atime, dt_mtime;
6327 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6328 + struct path *h_path);
6329 +void au_dtime_revert(struct au_dtime *dt);
6331 +#endif /* __KERNEL__ */
6332 +#endif /* __AUFS_CPUP_H__ */
6333 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6334 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6335 +++ linux/fs/aufs/dbgaufs.c 2021-02-24 13:33:42.741013619 +0100
6337 +// SPDX-License-Identifier: GPL-2.0
6339 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6341 + * This program, aufs is free software; you can redistribute it and/or modify
6342 + * it under the terms of the GNU General Public License as published by
6343 + * the Free Software Foundation; either version 2 of the License, or
6344 + * (at your option) any later version.
6346 + * This program is distributed in the hope that it will be useful,
6347 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6348 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6349 + * GNU General Public License for more details.
6351 + * You should have received a copy of the GNU General Public License
6352 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6356 + * debugfs interface
6359 +#include <linux/debugfs.h>
6362 +#ifndef CONFIG_SYSFS
6363 +#error DEBUG_FS depends upon SYSFS
6366 +static struct dentry *dbgaufs;
6367 +static const mode_t dbgaufs_mode = 0444;
6369 +/* 20 is max digits length of ulong 64 */
6370 +struct dbgaufs_arg {
6376 + * common function for all XINO files
6378 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6379 + struct file *file)
6383 + p = file->private_data;
6385 + /* this is struct dbgaufs_arg */
6386 + AuDebugOn(!au_kfree_sz_test(p));
6387 + au_kfree_do_rcu(p);
6392 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6397 + struct dbgaufs_arg *p;
6400 + p = kmalloc(sizeof(*p), GFP_NOFS);
6406 + file->private_data = p;
6410 + err = vfsub_getattr(&xf->f_path, &st);
6414 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6415 + cnt, st.blocks, st.blksize,
6416 + (long long)st.size);
6418 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6419 + st.blocks, st.blksize,
6420 + (long long)st.size);
6421 + AuDebugOn(p->n >= sizeof(p->a));
6423 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6431 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6432 + size_t count, loff_t *ppos)
6434 + struct dbgaufs_arg *p;
6436 + p = file->private_data;
6437 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6440 +/* ---------------------------------------------------------------------- */
6442 +struct dbgaufs_plink_arg {
6447 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6448 + struct file *file)
6450 + free_page((unsigned long)file->private_data);
6454 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6456 + int err, i, limit;
6457 + unsigned long n, sum;
6458 + struct dbgaufs_plink_arg *p;
6459 + struct au_sbinfo *sbinfo;
6460 + struct super_block *sb;
6461 + struct hlist_bl_head *hbl;
6464 + p = (void *)get_zeroed_page(GFP_NOFS);
6469 + sbinfo = inode->i_private;
6470 + sb = sbinfo->si_sb;
6471 + si_noflush_read_lock(sb);
6472 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6473 + limit = PAGE_SIZE - sizeof(p->n);
6475 + /* the number of buckets */
6476 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6481 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6483 + n = au_hbl_count(hbl);
6486 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6489 + if (unlikely(limit <= 0))
6492 + p->a[p->n - 1] = '\n';
6494 + /* the sum of plinks */
6495 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6498 + if (unlikely(limit <= 0))
6501 +#define str "1\n0\n0\n"
6502 + p->n = sizeof(str) - 1;
6503 + strcpy(p->a, str);
6506 + si_read_unlock(sb);
6509 + file->private_data = p;
6510 + goto out; /* success */
6513 + free_page((unsigned long)p);
6518 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6519 + size_t count, loff_t *ppos)
6521 + struct dbgaufs_plink_arg *p;
6523 + p = file->private_data;
6524 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6527 +static const struct file_operations dbgaufs_plink_fop = {
6528 + .owner = THIS_MODULE,
6529 + .open = dbgaufs_plink_open,
6530 + .release = dbgaufs_plink_release,
6531 + .read = dbgaufs_plink_read
6534 +/* ---------------------------------------------------------------------- */
6536 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6539 + struct au_sbinfo *sbinfo;
6540 + struct super_block *sb;
6542 + sbinfo = inode->i_private;
6543 + sb = sbinfo->si_sb;
6544 + si_noflush_read_lock(sb);
6545 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6546 + si_read_unlock(sb);
6550 +static const struct file_operations dbgaufs_xib_fop = {
6551 + .owner = THIS_MODULE,
6552 + .open = dbgaufs_xib_open,
6553 + .release = dbgaufs_xi_release,
6554 + .read = dbgaufs_xi_read
6557 +/* ---------------------------------------------------------------------- */
6559 +#define DbgaufsXi_PREFIX "xi"
6561 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6565 + aufs_bindex_t bindex;
6566 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6567 + struct au_sbinfo *sbinfo;
6568 + struct super_block *sb;
6569 + struct au_xino *xi;
6571 + struct qstr *name;
6572 + struct au_branch *br;
6575 + name = &file->f_path.dentry->d_name;
6576 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6577 + || memcmp(name->name, DbgaufsXi_PREFIX,
6578 + sizeof(DbgaufsXi_PREFIX) - 1)))
6581 + AuDebugOn(name->len >= sizeof(a));
6582 + memcpy(a, name->name, name->len);
6583 + a[name->len] = '\0';
6584 + p = strchr(a, '-');
6587 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6588 + if (unlikely(err))
6593 + err = kstrtol(p + 1, 10, &l);
6594 + if (unlikely(err))
6600 + sbinfo = inode->i_private;
6601 + sb = sbinfo->si_sb;
6602 + si_noflush_read_lock(sb);
6603 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6605 + br = au_sbr(sb, bindex);
6607 + if (unlikely(idx >= xi->xi_nfile))
6609 + xf = au_xino_file(xi, idx);
6611 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6612 + au_xino_count(br));
6615 + si_read_unlock(sb);
6621 +static const struct file_operations dbgaufs_xino_fop = {
6622 + .owner = THIS_MODULE,
6623 + .open = dbgaufs_xino_open,
6624 + .release = dbgaufs_xi_release,
6625 + .read = dbgaufs_xi_read
6628 +void dbgaufs_xino_del(struct au_branch *br)
6630 + struct dentry *dbgaufs;
6632 + dbgaufs = br->br_dbgaufs;
6636 + br->br_dbgaufs = NULL;
6637 + /* debugfs acquires the parent i_mutex */
6639 + debugfs_remove(dbgaufs);
6643 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6645 + aufs_bindex_t bbot;
6646 + struct au_branch *br;
6648 + if (!au_sbi(sb)->si_dbgaufs)
6651 + bbot = au_sbbot(sb);
6652 + for (; bindex <= bbot; bindex++) {
6653 + br = au_sbr(sb, bindex);
6654 + dbgaufs_xino_del(br);
6658 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6659 + unsigned int idx, struct dentry *parent,
6660 + struct au_sbinfo *sbinfo)
6662 + struct au_branch *br;
6664 + /* "xi" bindex(5) "-" idx(2) NULL */
6665 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6668 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6670 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6672 + br = au_sbr(sb, bindex);
6673 + if (br->br_dbgaufs) {
6674 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6676 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6677 + /* debugfs acquires the parent i_mutex */
6679 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6683 + pr_warn("failed renaming %pd/%s, ignored.\n",
6688 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6689 + sbinfo, &dbgaufs_xino_fop);
6691 + if (unlikely(!br->br_dbgaufs))
6692 + pr_warn("failed creating %pd/%s, ignored.\n",
6697 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6698 + struct dentry *parent, struct au_sbinfo *sbinfo)
6700 + struct au_branch *br;
6701 + struct au_xino *xi;
6704 + br = au_sbr(sb, bindex);
6706 + for (u = 0; u < xi->xi_nfile; u++)
6707 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6710 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6712 + struct au_sbinfo *sbinfo;
6713 + struct dentry *parent;
6714 + aufs_bindex_t bbot;
6716 + if (!au_opt_test(au_mntflags(sb), XINO))
6719 + sbinfo = au_sbi(sb);
6720 + parent = sbinfo->si_dbgaufs;
6724 + bbot = au_sbbot(sb);
6726 + for (; bindex <= bbot; bindex++)
6727 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6729 + for (; bbot >= bindex; bbot--)
6730 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6733 +/* ---------------------------------------------------------------------- */
6735 +#ifdef CONFIG_AUFS_EXPORT
6736 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6739 + struct au_sbinfo *sbinfo;
6740 + struct super_block *sb;
6742 + sbinfo = inode->i_private;
6743 + sb = sbinfo->si_sb;
6744 + si_noflush_read_lock(sb);
6745 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6746 + si_read_unlock(sb);
6750 +static const struct file_operations dbgaufs_xigen_fop = {
6751 + .owner = THIS_MODULE,
6752 + .open = dbgaufs_xigen_open,
6753 + .release = dbgaufs_xi_release,
6754 + .read = dbgaufs_xi_read
6757 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6762 + * This function is a dynamic '__init' function actually,
6763 + * so the tiny check for si_rwsem is unnecessary.
6765 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6768 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6769 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6770 + &dbgaufs_xigen_fop);
6771 + if (sbinfo->si_dbgaufs_xigen)
6777 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6781 +#endif /* CONFIG_AUFS_EXPORT */
6783 +/* ---------------------------------------------------------------------- */
6785 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6788 + * This function is a dynamic '__fin' function actually,
6789 + * so the tiny check for si_rwsem is unnecessary.
6791 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6793 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6794 + sbinfo->si_dbgaufs = NULL;
6797 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6800 + char name[SysaufsSiNameLen];
6803 + * This function is a dynamic '__init' function actually,
6804 + * so the tiny check for si_rwsem is unnecessary.
6806 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6810 + AuErr1("/debug/aufs is uninitialized\n");
6815 + sysaufs_name(sbinfo, name);
6816 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6817 + if (unlikely(!sbinfo->si_dbgaufs))
6820 + /* regardless plink/noplink option */
6821 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6822 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6823 + &dbgaufs_plink_fop);
6824 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6827 + /* regardless xino/noxino option */
6828 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6829 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6830 + &dbgaufs_xib_fop);
6831 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6834 + err = dbgaufs_xigen_init(sbinfo);
6836 + goto out; /* success */
6839 + dbgaufs_si_fin(sbinfo);
6841 + if (unlikely(err))
6842 + pr_err("debugfs/aufs failed\n");
6846 +/* ---------------------------------------------------------------------- */
6848 +void dbgaufs_fin(void)
6850 + debugfs_remove(dbgaufs);
6853 +int __init dbgaufs_init(void)
6858 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6863 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6864 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6865 +++ linux/fs/aufs/dbgaufs.h 2021-02-24 13:33:42.741013619 +0100
6867 +/* SPDX-License-Identifier: GPL-2.0 */
6869 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6871 + * This program, aufs is free software; you can redistribute it and/or modify
6872 + * it under the terms of the GNU General Public License as published by
6873 + * the Free Software Foundation; either version 2 of the License, or
6874 + * (at your option) any later version.
6876 + * This program is distributed in the hope that it will be useful,
6877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6879 + * GNU General Public License for more details.
6881 + * You should have received a copy of the GNU General Public License
6882 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6886 + * debugfs interface
6889 +#ifndef __DBGAUFS_H__
6890 +#define __DBGAUFS_H__
6894 +struct super_block;
6898 +#ifdef CONFIG_DEBUG_FS
6900 +void dbgaufs_xino_del(struct au_branch *br);
6901 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6902 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6903 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6904 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6905 +void dbgaufs_fin(void);
6906 +int __init dbgaufs_init(void);
6908 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6909 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6910 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6912 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6913 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6914 +AuStubVoid(dbgaufs_fin, void)
6915 +AuStubInt0(__init dbgaufs_init, void)
6916 +#endif /* CONFIG_DEBUG_FS */
6918 +#endif /* __KERNEL__ */
6919 +#endif /* __DBGAUFS_H__ */
6920 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6921 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6922 +++ linux/fs/aufs/dcsub.c 2021-02-24 13:33:42.741013619 +0100
6924 +// SPDX-License-Identifier: GPL-2.0
6926 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6928 + * This program, aufs is free software; you can redistribute it and/or modify
6929 + * it under the terms of the GNU General Public License as published by
6930 + * the Free Software Foundation; either version 2 of the License, or
6931 + * (at your option) any later version.
6933 + * This program is distributed in the hope that it will be useful,
6934 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6935 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6936 + * GNU General Public License for more details.
6938 + * You should have received a copy of the GNU General Public License
6939 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6943 + * sub-routines for dentry cache
6948 +static void au_dpage_free(struct au_dpage *dpage)
6951 + struct dentry **p;
6953 + p = dpage->dentries;
6954 + for (i = 0; i < dpage->ndentry; i++)
6956 + free_page((unsigned long)dpage->dentries);
6959 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6965 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6966 + if (unlikely(!dpages->dpages))
6969 + p = (void *)__get_free_page(gfp);
6973 + dpages->dpages[0].ndentry = 0;
6974 + dpages->dpages[0].dentries = p;
6975 + dpages->ndpage = 1;
6976 + return 0; /* success */
6979 + au_kfree_try_rcu(dpages->dpages);
6984 +void au_dpages_free(struct au_dcsub_pages *dpages)
6987 + struct au_dpage *p;
6989 + p = dpages->dpages;
6990 + for (i = 0; i < dpages->ndpage; i++)
6991 + au_dpage_free(p++);
6992 + au_kfree_try_rcu(dpages->dpages);
6995 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6996 + struct dentry *dentry, gfp_t gfp)
6999 + struct au_dpage *dpage;
7002 + dpage = dpages->dpages + dpages->ndpage - 1;
7003 + sz = PAGE_SIZE / sizeof(dentry);
7004 + if (unlikely(dpage->ndentry >= sz)) {
7005 + AuLabel(new dpage);
7007 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7008 + p = au_kzrealloc(dpages->dpages, sz,
7009 + sz + sizeof(*dpages->dpages), gfp,
7014 + dpages->dpages = p;
7015 + dpage = dpages->dpages + dpages->ndpage;
7016 + p = (void *)__get_free_page(gfp);
7020 + dpage->ndentry = 0;
7021 + dpage->dentries = p;
7025 + AuDebugOn(au_dcount(dentry) <= 0);
7026 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7027 + return 0; /* success */
7033 +/* todo: BAD approach */
7034 +/* copied from linux/fs/dcache.c */
7042 +extern void d_walk(struct dentry *parent, void *data,
7043 + enum d_walk_ret (*enter)(void *, struct dentry *));
7045 +struct ac_dpages_arg {
7047 + struct au_dcsub_pages *dpages;
7048 + struct super_block *sb;
7049 + au_dpages_test test;
7053 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7055 + enum d_walk_ret ret;
7056 + struct ac_dpages_arg *arg = _arg;
7058 + ret = D_WALK_CONTINUE;
7059 + if (dentry->d_sb == arg->sb
7060 + && !IS_ROOT(dentry)
7061 + && au_dcount(dentry) > 0
7063 + && (!arg->test || arg->test(dentry, arg->arg))) {
7064 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7065 + if (unlikely(arg->err))
7066 + ret = D_WALK_QUIT;
7072 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7073 + au_dpages_test test, void *arg)
7075 + struct ac_dpages_arg args = {
7083 + d_walk(root, &args, au_call_dpages_append);
7088 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7089 + int do_include, au_dpages_test test, void *arg)
7094 + write_seqlock(&rename_lock);
7095 + spin_lock(&dentry->d_lock);
7097 + && au_dcount(dentry) > 0
7098 + && (!test || test(dentry, arg)))
7099 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7100 + spin_unlock(&dentry->d_lock);
7101 + if (unlikely(err))
7105 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7108 + while (!IS_ROOT(dentry)) {
7109 + dentry = dentry->d_parent; /* rename_lock is locked */
7110 + spin_lock(&dentry->d_lock);
7111 + if (au_dcount(dentry) > 0
7112 + && (!test || test(dentry, arg)))
7113 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7114 + spin_unlock(&dentry->d_lock);
7115 + if (unlikely(err))
7120 + write_sequnlock(&rename_lock);
7124 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7126 + return au_di(dentry) && dentry->d_sb == arg;
7129 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7130 + struct dentry *dentry, int do_include)
7132 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7133 + au_dcsub_dpages_aufs, dentry->d_sb);
7136 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7138 + struct path path[2] = {
7147 + return path_is_under(path + 0, path + 1);
7149 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7150 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7151 +++ linux/fs/aufs/dcsub.h 2021-02-24 13:33:42.741013619 +0100
7153 +/* SPDX-License-Identifier: GPL-2.0 */
7155 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7157 + * This program, aufs is free software; you can redistribute it and/or modify
7158 + * it under the terms of the GNU General Public License as published by
7159 + * the Free Software Foundation; either version 2 of the License, or
7160 + * (at your option) any later version.
7162 + * This program is distributed in the hope that it will be useful,
7163 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7164 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7165 + * GNU General Public License for more details.
7167 + * You should have received a copy of the GNU General Public License
7168 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7172 + * sub-routines for dentry cache
7175 +#ifndef __AUFS_DCSUB_H__
7176 +#define __AUFS_DCSUB_H__
7180 +#include <linux/dcache.h>
7181 +#include <linux/fs.h>
7185 + struct dentry **dentries;
7188 +struct au_dcsub_pages {
7190 + struct au_dpage *dpages;
7193 +/* ---------------------------------------------------------------------- */
7196 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7197 +void au_dpages_free(struct au_dcsub_pages *dpages);
7198 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7199 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7200 + au_dpages_test test, void *arg);
7201 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7202 + int do_include, au_dpages_test test, void *arg);
7203 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7204 + struct dentry *dentry, int do_include);
7205 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7207 +/* ---------------------------------------------------------------------- */
7210 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7211 + * include/linux/dcache.h. Try them (in the future).
7214 +static inline int au_d_hashed_positive(struct dentry *d)
7217 + struct inode *inode = d_inode(d);
7220 + if (unlikely(d_unhashed(d)
7221 + || d_is_negative(d)
7222 + || !inode->i_nlink))
7227 +static inline int au_d_linkable(struct dentry *d)
7230 + struct inode *inode = d_inode(d);
7232 + err = au_d_hashed_positive(d);
7234 + && d_is_positive(d)
7235 + && (inode->i_state & I_LINKABLE))
7240 +static inline int au_d_alive(struct dentry *d)
7243 + struct inode *inode;
7247 + err = au_d_hashed_positive(d);
7249 + inode = d_inode(d);
7250 + if (unlikely(d_unlinked(d)
7251 + || d_is_negative(d)
7252 + || !inode->i_nlink))
7258 +static inline int au_alive_dir(struct dentry *d)
7262 + err = au_d_alive(d);
7263 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7268 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7270 + return a->len == b->len
7271 + && !memcmp(a->name, b->name, a->len);
7276 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7278 + * the type of d_lockref.count became int, but the inlined function d_count()
7279 + * still returns unsigned int.
7280 + * I don't know why. Maybe it is for every d_count() users?
7281 + * Anyway au_dcount() lives on.
7283 +static inline int au_dcount(struct dentry *d)
7285 + return (int)d_count(d);
7288 +#endif /* __KERNEL__ */
7289 +#endif /* __AUFS_DCSUB_H__ */
7290 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7291 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7292 +++ linux/fs/aufs/debug.c 2021-02-24 13:33:42.741013619 +0100
7294 +// SPDX-License-Identifier: GPL-2.0
7296 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7298 + * This program, aufs is free software; you can redistribute it and/or modify
7299 + * it under the terms of the GNU General Public License as published by
7300 + * the Free Software Foundation; either version 2 of the License, or
7301 + * (at your option) any later version.
7303 + * This program is distributed in the hope that it will be useful,
7304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7306 + * GNU General Public License for more details.
7308 + * You should have received a copy of the GNU General Public License
7309 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7313 + * debug print functions
7316 +#include <linux/iversion.h>
7319 +/* Returns 0, or -errno. arg is in kp->arg. */
7320 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7324 + err = kstrtoint(val, 0, &n);
7334 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7335 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7340 + return sprintf(buffer, "%d", atomic_read(a));
7343 +static struct kernel_param_ops param_ops_atomic_t = {
7344 + .set = param_atomic_t_set,
7345 + .get = param_atomic_t_get
7346 + /* void (*free)(void *arg) */
7349 +atomic_t aufs_debug = ATOMIC_INIT(0);
7350 +MODULE_PARM_DESC(debug, "debug print");
7351 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7353 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7354 +char *au_plevel = KERN_DEBUG;
7355 +#define dpri(fmt, ...) do { \
7357 + && strcmp(au_plevel, KERN_DEBUG)) \
7358 + || au_debug_test()) \
7359 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7362 +/* ---------------------------------------------------------------------- */
7364 +void au_dpri_whlist(struct au_nhash *whlist)
7366 + unsigned long ul, n;
7367 + struct hlist_head *head;
7368 + struct au_vdir_wh *pos;
7370 + n = whlist->nh_num;
7371 + head = whlist->nh_head;
7372 + for (ul = 0; ul < n; ul++) {
7373 + hlist_for_each_entry(pos, head, wh_hash)
7374 + dpri("b%d, %.*s, %d\n",
7376 + pos->wh_str.len, pos->wh_str.name,
7382 +void au_dpri_vdir(struct au_vdir *vdir)
7385 + union au_vdir_deblk_p p;
7388 + if (!vdir || IS_ERR(vdir)) {
7389 + dpri("err %ld\n", PTR_ERR(vdir));
7393 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7394 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7395 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7396 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7397 + p.deblk = vdir->vd_deblk[ul];
7399 + dpri("[%lu]: %p\n", ul, o);
7403 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7404 + struct dentry *wh)
7409 + if (!inode || IS_ERR(inode)) {
7410 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7414 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7415 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7416 + && sizeof(inode->i_blocks) != sizeof(u64));
7418 + n = (void *)wh->d_name.name;
7419 + l = wh->d_name.len;
7422 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7423 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7425 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7426 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7427 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7428 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7429 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7430 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7431 + inode->i_generation,
7432 + l ? ", wh " : "", l, n);
7436 +void au_dpri_inode(struct inode *inode)
7438 + struct au_iinfo *iinfo;
7439 + struct au_hinode *hi;
7440 + aufs_bindex_t bindex;
7443 + err = do_pri_inode(-1, inode, -1, NULL);
7444 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7447 + iinfo = au_ii(inode);
7448 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7449 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7450 + if (iinfo->ii_btop < 0)
7453 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7454 + hi = au_hinode(iinfo, bindex);
7456 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7460 +void au_dpri_dalias(struct inode *inode)
7464 + spin_lock(&inode->i_lock);
7465 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7466 + au_dpri_dentry(d);
7467 + spin_unlock(&inode->i_lock);
7470 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7472 + struct dentry *wh = NULL;
7474 + struct inode *inode;
7475 + struct au_iinfo *iinfo;
7476 + struct au_hinode *hi;
7478 + if (!dentry || IS_ERR(dentry)) {
7479 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7482 + /* do not call dget_parent() here */
7483 + /* note: access d_xxx without d_lock */
7484 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7485 + bindex, dentry, dentry,
7486 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7487 + au_dcount(dentry), dentry->d_flags,
7488 + d_unhashed(dentry) ? "un" : "");
7491 + if (d_is_positive(dentry))
7492 + inode = d_inode(dentry);
7494 + && au_test_aufs(dentry->d_sb)
7496 + && !au_is_bad_inode(inode)) {
7497 + iinfo = au_ii(inode);
7498 + hi = au_hinode(iinfo, bindex);
7500 + wh = hi->hi_whdentry;
7502 + do_pri_inode(bindex, inode, hn, wh);
7506 +void au_dpri_dentry(struct dentry *dentry)
7508 + struct au_dinfo *dinfo;
7509 + aufs_bindex_t bindex;
7512 + err = do_pri_dentry(-1, dentry);
7513 + if (err || !au_test_aufs(dentry->d_sb))
7516 + dinfo = au_di(dentry);
7519 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7520 + dinfo->di_btop, dinfo->di_bbot,
7521 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7522 + dinfo->di_tmpfile);
7523 + if (dinfo->di_btop < 0)
7525 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7526 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7529 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7533 + if (!file || IS_ERR(file)) {
7534 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7539 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7540 + && au_test_aufs(file->f_path.dentry->d_sb)
7542 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7543 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7544 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7545 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7546 + file->f_version, file->f_pos, a);
7547 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7548 + do_pri_dentry(bindex, file->f_path.dentry);
7552 +void au_dpri_file(struct file *file)
7554 + struct au_finfo *finfo;
7555 + struct au_fidir *fidir;
7556 + struct au_hfile *hfile;
7557 + aufs_bindex_t bindex;
7560 + err = do_pri_file(-1, file);
7562 + || IS_ERR_OR_NULL(file->f_path.dentry)
7563 + || !au_test_aufs(file->f_path.dentry->d_sb))
7566 + finfo = au_fi(file);
7569 + if (finfo->fi_btop < 0)
7571 + fidir = finfo->fi_hdir;
7573 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7575 + for (bindex = finfo->fi_btop;
7576 + bindex >= 0 && bindex <= fidir->fd_bbot;
7578 + hfile = fidir->fd_hfile + bindex;
7579 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7583 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7585 + struct vfsmount *mnt;
7586 + struct super_block *sb;
7588 + if (!br || IS_ERR(br))
7590 + mnt = au_br_mnt(br);
7591 + if (!mnt || IS_ERR(mnt))
7594 + if (!sb || IS_ERR(sb))
7597 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7598 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7600 + bindex, br->br_perm, br->br_id, br->br_wbr,
7601 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7602 + sb->s_flags, sb->s_count,
7603 + atomic_read(&sb->s_active),
7604 + !!au_xino_file(br->br_xino, /*idx*/-1));
7608 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7612 +void au_dpri_sb(struct super_block *sb)
7614 + struct au_sbinfo *sbinfo;
7615 + aufs_bindex_t bindex;
7617 + /* to reduce stack size */
7619 + struct vfsmount mnt;
7620 + struct au_branch fake;
7623 + /* this function can be called from magic sysrq */
7624 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7625 + if (unlikely(!a)) {
7626 + dpri("no memory\n");
7630 + a->mnt.mnt_sb = sb;
7631 + a->fake.br_path.mnt = &a->mnt;
7632 + err = do_pri_br(-1, &a->fake);
7634 + dpri("dev 0x%x\n", sb->s_dev);
7635 + if (err || !au_test_aufs(sb))
7638 + sbinfo = au_sbi(sb);
7641 + dpri("nw %d, gen %u, kobj %d\n",
7642 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7643 + kref_read(&sbinfo->si_kobj.kref));
7644 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7645 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7648 +/* ---------------------------------------------------------------------- */
7650 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7652 + struct inode *h_inode, *inode = d_inode(dentry);
7653 + struct dentry *h_dentry;
7654 + aufs_bindex_t bindex, bbot, bi;
7656 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7659 + bbot = au_dbbot(dentry);
7660 + bi = au_ibbot(inode);
7663 + bindex = au_dbtop(dentry);
7664 + bi = au_ibtop(inode);
7668 + for (; bindex <= bbot; bindex++) {
7669 + h_dentry = au_h_dptr(dentry, bindex);
7672 + h_inode = au_h_iptr(inode, bindex);
7673 + if (unlikely(h_inode != d_inode(h_dentry))) {
7675 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7676 + AuDbgDentry(dentry);
7677 + AuDbgInode(inode);
7684 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7687 + struct au_dcsub_pages dpages;
7688 + struct au_dpage *dpage;
7689 + struct dentry **dentries;
7691 + err = au_dpages_init(&dpages, GFP_NOFS);
7693 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7695 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7696 + dpage = dpages.dpages + i;
7697 + dentries = dpage->dentries;
7698 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7699 + AuDebugOn(au_digen_test(dentries[j], sigen));
7701 + au_dpages_free(&dpages);
7704 +void au_dbg_verify_kthread(void)
7706 + if (au_wkq_test()) {
7709 + * It may be recursive, but udba=notify between two aufs mounts,
7710 + * where a single ro branch is shared, is not a problem.
7716 +/* ---------------------------------------------------------------------- */
7718 +int __init au_debug_init(void)
7720 + aufs_bindex_t bindex;
7721 + struct au_vdir_destr destr;
7724 + AuDebugOn(bindex >= 0);
7727 + AuDebugOn(destr.len < NAME_MAX);
7729 +#ifdef CONFIG_4KSTACKS
7730 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7735 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7736 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7737 +++ linux/fs/aufs/debug.h 2021-02-24 13:33:42.741013619 +0100
7739 +/* SPDX-License-Identifier: GPL-2.0 */
7741 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7743 + * This program, aufs is free software; you can redistribute it and/or modify
7744 + * it under the terms of the GNU General Public License as published by
7745 + * the Free Software Foundation; either version 2 of the License, or
7746 + * (at your option) any later version.
7748 + * This program is distributed in the hope that it will be useful,
7749 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7750 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7751 + * GNU General Public License for more details.
7753 + * You should have received a copy of the GNU General Public License
7754 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7758 + * debug print functions
7761 +#ifndef __AUFS_DEBUG_H__
7762 +#define __AUFS_DEBUG_H__
7766 +#include <linux/atomic.h>
7767 +#include <linux/module.h>
7768 +#include <linux/kallsyms.h>
7769 +#include <linux/sysrq.h>
7771 +#ifdef CONFIG_AUFS_DEBUG
7772 +#define AuDebugOn(a) BUG_ON(a)
7774 +/* module parameter */
7775 +extern atomic_t aufs_debug;
7776 +static inline void au_debug_on(void)
7778 + atomic_inc(&aufs_debug);
7780 +static inline void au_debug_off(void)
7782 + atomic_dec_if_positive(&aufs_debug);
7785 +static inline int au_debug_test(void)
7787 + return atomic_read(&aufs_debug) > 0;
7790 +#define AuDebugOn(a) do {} while (0)
7791 +AuStubVoid(au_debug_on, void)
7792 +AuStubVoid(au_debug_off, void)
7793 +AuStubInt0(au_debug_test, void)
7794 +#endif /* CONFIG_AUFS_DEBUG */
7796 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7798 +/* ---------------------------------------------------------------------- */
7802 +#define AuDbg(fmt, ...) do { \
7803 + if (au_debug_test()) \
7804 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7806 +#define AuLabel(l) AuDbg(#l "\n")
7807 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7808 +#define AuWarn1(fmt, ...) do { \
7809 + static unsigned char _c; \
7811 + pr_warn(fmt, ##__VA_ARGS__); \
7814 +#define AuErr1(fmt, ...) do { \
7815 + static unsigned char _c; \
7817 + pr_err(fmt, ##__VA_ARGS__); \
7820 +#define AuIOErr1(fmt, ...) do { \
7821 + static unsigned char _c; \
7823 + AuIOErr(fmt, ##__VA_ARGS__); \
7826 +#define AuUnsupportMsg "This operation is not supported." \
7827 + " Please report this application to aufs-users ML."
7828 +#define AuUnsupport(fmt, ...) do { \
7829 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7833 +#define AuTraceErr(e) do { \
7834 + if (unlikely((e) < 0)) \
7835 + AuDbg("err %d\n", (int)(e)); \
7838 +#define AuTraceErrPtr(p) do { \
7840 + AuDbg("err %ld\n", PTR_ERR(p)); \
7843 +/* dirty macros for debug print, use with "%.*s" and caution */
7844 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7846 +/* ---------------------------------------------------------------------- */
7849 +#ifdef CONFIG_AUFS_DEBUG
7850 +extern struct mutex au_dbg_mtx;
7851 +extern char *au_plevel;
7853 +void au_dpri_whlist(struct au_nhash *whlist);
7855 +void au_dpri_vdir(struct au_vdir *vdir);
7857 +void au_dpri_inode(struct inode *inode);
7858 +void au_dpri_dalias(struct inode *inode);
7859 +void au_dpri_dentry(struct dentry *dentry);
7861 +void au_dpri_file(struct file *filp);
7862 +struct super_block;
7863 +void au_dpri_sb(struct super_block *sb);
7865 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7866 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7867 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7868 +void au_dbg_verify_kthread(void);
7870 +int __init au_debug_init(void);
7872 +#define AuDbgWhlist(w) do { \
7873 + mutex_lock(&au_dbg_mtx); \
7875 + au_dpri_whlist(w); \
7876 + mutex_unlock(&au_dbg_mtx); \
7879 +#define AuDbgVdir(v) do { \
7880 + mutex_lock(&au_dbg_mtx); \
7882 + au_dpri_vdir(v); \
7883 + mutex_unlock(&au_dbg_mtx); \
7886 +#define AuDbgInode(i) do { \
7887 + mutex_lock(&au_dbg_mtx); \
7889 + au_dpri_inode(i); \
7890 + mutex_unlock(&au_dbg_mtx); \
7893 +#define AuDbgDAlias(i) do { \
7894 + mutex_lock(&au_dbg_mtx); \
7896 + au_dpri_dalias(i); \
7897 + mutex_unlock(&au_dbg_mtx); \
7900 +#define AuDbgDentry(d) do { \
7901 + mutex_lock(&au_dbg_mtx); \
7903 + au_dpri_dentry(d); \
7904 + mutex_unlock(&au_dbg_mtx); \
7907 +#define AuDbgFile(f) do { \
7908 + mutex_lock(&au_dbg_mtx); \
7910 + au_dpri_file(f); \
7911 + mutex_unlock(&au_dbg_mtx); \
7914 +#define AuDbgSb(sb) do { \
7915 + mutex_lock(&au_dbg_mtx); \
7916 + AuDbg(#sb "\n"); \
7918 + mutex_unlock(&au_dbg_mtx); \
7921 +#define AuDbgSym(addr) do { \
7922 + char sym[KSYM_SYMBOL_LEN]; \
7923 + sprint_symbol(sym, (unsigned long)addr); \
7924 + AuDbg("%s\n", sym); \
7927 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7928 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7929 +AuStubVoid(au_dbg_verify_kthread, void)
7930 +AuStubInt0(__init au_debug_init, void)
7932 +#define AuDbgWhlist(w) do {} while (0)
7933 +#define AuDbgVdir(v) do {} while (0)
7934 +#define AuDbgInode(i) do {} while (0)
7935 +#define AuDbgDAlias(i) do {} while (0)
7936 +#define AuDbgDentry(d) do {} while (0)
7937 +#define AuDbgFile(f) do {} while (0)
7938 +#define AuDbgSb(sb) do {} while (0)
7939 +#define AuDbgSym(addr) do {} while (0)
7940 +#endif /* CONFIG_AUFS_DEBUG */
7942 +/* ---------------------------------------------------------------------- */
7944 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7945 +int __init au_sysrq_init(void);
7946 +void au_sysrq_fin(void);
7948 +#ifdef CONFIG_HW_CONSOLE
7949 +#define au_dbg_blocked() do { \
7951 + handle_sysrq('w'); \
7954 +AuStubVoid(au_dbg_blocked, void)
7958 +AuStubInt0(__init au_sysrq_init, void)
7959 +AuStubVoid(au_sysrq_fin, void)
7960 +AuStubVoid(au_dbg_blocked, void)
7961 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7963 +#endif /* __KERNEL__ */
7964 +#endif /* __AUFS_DEBUG_H__ */
7965 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7966 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7967 +++ linux/fs/aufs/dentry.c 2021-02-24 13:33:42.741013619 +0100
7969 +// SPDX-License-Identifier: GPL-2.0
7971 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7973 + * This program, aufs is free software; you can redistribute it and/or modify
7974 + * it under the terms of the GNU General Public License as published by
7975 + * the Free Software Foundation; either version 2 of the License, or
7976 + * (at your option) any later version.
7978 + * This program is distributed in the hope that it will be useful,
7979 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7980 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7981 + * GNU General Public License for more details.
7983 + * You should have received a copy of the GNU General Public License
7984 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7988 + * lookup and dentry operations
7991 +#include <linux/iversion.h>
7992 +#include <linux/namei.h>
7996 + * returns positive/negative dentry, NULL or an error.
7997 + * NULL means whiteout-ed or not-found.
7999 +static struct dentry*
8000 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8001 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8003 + struct dentry *h_dentry;
8004 + struct inode *h_inode;
8005 + struct au_branch *br;
8006 + int wh_found, opq;
8007 + unsigned char wh_able;
8008 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8009 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8013 + br = au_sbr(dentry->d_sb, bindex);
8014 + wh_able = !!au_br_whable(br->br_perm);
8016 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8017 + h_dentry = ERR_PTR(wh_found);
8020 + if (unlikely(wh_found < 0))
8023 + /* We found a whiteout */
8024 + /* au_set_dbbot(dentry, bindex); */
8025 + au_set_dbwh(dentry, bindex);
8027 + return NULL; /* success */
8031 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8033 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8034 + if (IS_ERR(h_dentry)) {
8035 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8041 + h_inode = d_inode(h_dentry);
8042 + if (d_is_negative(h_dentry)) {
8045 + } else if (wh_found
8046 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8048 + else if (au_ftest_lkup(args->flags, DIRREN)
8050 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8051 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8052 + (unsigned long long)h_inode->i_ino);
8056 + if (au_dbbot(dentry) <= bindex)
8057 + au_set_dbbot(dentry, bindex);
8058 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8059 + au_set_dbtop(dentry, bindex);
8060 + au_set_h_dptr(dentry, bindex, h_dentry);
8062 + if (!d_is_dir(h_dentry)
8064 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8065 + goto out; /* success */
8067 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8068 + opq = au_diropq_test(h_dentry);
8069 + inode_unlock_shared(h_inode);
8071 + au_set_dbdiropq(dentry, bindex);
8072 + else if (unlikely(opq < 0)) {
8073 + au_set_h_dptr(dentry, bindex, NULL);
8074 + h_dentry = ERR_PTR(opq);
8085 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8087 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8088 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8094 + * returns the number of lower positive dentries,
8095 + * otherwise an error.
8096 + * can be called at unlinking with @type is zero.
8098 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8099 + unsigned int flags)
8101 + int npositive, err;
8102 + aufs_bindex_t bindex, btail, bdiropq;
8103 + unsigned char isdir, dirperm1, dirren;
8104 + struct au_do_lookup_args args = {
8106 + .name = &dentry->d_name
8108 + struct dentry *parent;
8109 + struct super_block *sb;
8111 + sb = dentry->d_sb;
8112 + err = au_test_shwh(sb, args.name);
8113 + if (unlikely(err))
8116 + err = au_wh_name_alloc(&args.whname, args.name);
8117 + if (unlikely(err))
8120 + isdir = !!d_is_dir(dentry);
8121 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8122 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8124 + au_fset_lkup(args.flags, DIRREN);
8127 + parent = dget_parent(dentry);
8128 + btail = au_dbtaildir(parent);
8129 + for (bindex = btop; bindex <= btail; bindex++) {
8130 + struct dentry *h_parent, *h_dentry;
8131 + struct inode *h_inode, *h_dir;
8132 + struct au_branch *br;
8134 + h_dentry = au_h_dptr(dentry, bindex);
8136 + if (d_is_positive(h_dentry))
8140 + h_parent = au_h_dptr(parent, bindex);
8141 + if (!h_parent || !d_is_dir(h_parent))
8145 + /* if the inum matches, then use the prepared name */
8146 + err = au_dr_lkup_name(&args, bindex);
8147 + if (unlikely(err))
8151 + h_dir = d_inode(h_parent);
8152 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8153 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8154 + inode_unlock_shared(h_dir);
8155 + err = PTR_ERR(h_dentry);
8156 + if (IS_ERR(h_dentry))
8159 + au_fclr_lkup(args.flags, ALLOW_NEG);
8161 + au_fset_lkup(args.flags, IGNORE_PERM);
8163 + if (au_dbwh(dentry) == bindex)
8167 + if (d_is_negative(h_dentry))
8169 + h_inode = d_inode(h_dentry);
8172 + args.type = h_inode->i_mode & S_IFMT;
8173 + if (args.type != S_IFDIR)
8176 + /* the type of lower may be different */
8177 + bdiropq = au_dbdiropq(dentry);
8178 + if (bdiropq >= 0 && bdiropq <= bindex)
8181 + br = au_sbr(sb, bindex);
8183 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8184 + /*add_ent*/NULL)) {
8185 + /* prepare next name to lookup */
8186 + err = au_dr_lkup(&args, dentry, bindex);
8187 + if (unlikely(err))
8193 + AuLabel(positive);
8194 + au_update_dbtop(dentry);
8197 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8198 + && au_dbtop(dentry) < 0)) {
8200 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8206 + au_kfree_try_rcu(args.whname.name);
8208 + au_dr_lkup_fin(&args);
8213 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8215 + struct dentry *dentry;
8218 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8219 + dentry = vfsub_lkup_one(name, parent);
8221 + struct vfsub_lkup_one_args args = {
8227 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8228 + if (unlikely(wkq_err))
8229 + dentry = ERR_PTR(wkq_err);
8236 + * lookup @dentry on @bindex which should be negative.
8238 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8241 + struct dentry *parent, *h_parent, *h_dentry;
8242 + struct au_branch *br;
8244 + parent = dget_parent(dentry);
8245 + h_parent = au_h_dptr(parent, bindex);
8246 + br = au_sbr(dentry->d_sb, bindex);
8248 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8250 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8251 + err = PTR_ERR(h_dentry);
8252 + if (IS_ERR(h_dentry))
8254 + if (unlikely(d_is_positive(h_dentry))) {
8256 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8262 + if (bindex < au_dbtop(dentry))
8263 + au_set_dbtop(dentry, bindex);
8264 + if (au_dbbot(dentry) < bindex)
8265 + au_set_dbbot(dentry, bindex);
8266 + au_set_h_dptr(dentry, bindex, h_dentry);
8273 +/* ---------------------------------------------------------------------- */
8275 +/* subset of struct inode */
8277 + unsigned long i_ino;
8278 + /* unsigned int i_nlink; */
8284 + blkcnt_t i_blocks;
8289 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8291 + ia->i_ino = h_inode->i_ino;
8292 + /* ia->i_nlink = h_inode->i_nlink; */
8293 + ia->i_uid = h_inode->i_uid;
8294 + ia->i_gid = h_inode->i_gid;
8295 + ia->i_version = inode_query_iversion(h_inode);
8297 + ia->i_size = h_inode->i_size;
8298 + ia->i_blocks = h_inode->i_blocks;
8300 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8303 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8305 + return ia->i_ino != h_inode->i_ino
8306 + /* || ia->i_nlink != h_inode->i_nlink */
8307 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8308 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8309 + || !inode_eq_iversion(h_inode, ia->i_version)
8311 + || ia->i_size != h_inode->i_size
8312 + || ia->i_blocks != h_inode->i_blocks
8314 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8317 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8318 + struct au_branch *br)
8321 + struct au_iattr ia;
8322 + struct inode *h_inode;
8323 + struct dentry *h_d;
8324 + struct super_block *h_sb;
8327 + memset(&ia, -1, sizeof(ia));
8328 + h_sb = h_dentry->d_sb;
8330 + if (d_is_positive(h_dentry)) {
8331 + h_inode = d_inode(h_dentry);
8332 + au_iattr_save(&ia, h_inode);
8333 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8334 + /* nfs d_revalidate may return 0 for negative dentry */
8335 + /* fuse d_revalidate always return 0 for negative dentry */
8338 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8339 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8340 + err = PTR_ERR(h_d);
8345 + if (unlikely(h_d != h_dentry
8346 + || d_inode(h_d) != h_inode
8347 + || (h_inode && au_iattr_test(&ia, h_inode))))
8348 + err = au_busy_or_stale();
8356 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8357 + struct dentry *h_parent, struct au_branch *br)
8362 + if (udba == AuOpt_UDBA_REVAL
8363 + && !au_test_fs_remote(h_dentry->d_sb)) {
8365 + err = (d_inode(h_dentry->d_parent) != h_dir);
8366 + } else if (udba != AuOpt_UDBA_NONE)
8367 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8372 +/* ---------------------------------------------------------------------- */
8374 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8377 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8378 + struct au_hdentry tmp, *p, *q;
8379 + struct au_dinfo *dinfo;
8380 + struct super_block *sb;
8382 + DiMustWriteLock(dentry);
8384 + sb = dentry->d_sb;
8385 + dinfo = au_di(dentry);
8386 + bbot = dinfo->di_bbot;
8387 + bwh = dinfo->di_bwh;
8388 + bdiropq = dinfo->di_bdiropq;
8389 + bindex = dinfo->di_btop;
8390 + p = au_hdentry(dinfo, bindex);
8391 + for (; bindex <= bbot; bindex++, p++) {
8392 + if (!p->hd_dentry)
8395 + new_bindex = au_br_index(sb, p->hd_id);
8396 + if (new_bindex == bindex)
8399 + if (dinfo->di_bwh == bindex)
8401 + if (dinfo->di_bdiropq == bindex)
8402 + bdiropq = new_bindex;
8403 + if (new_bindex < 0) {
8405 + p->hd_dentry = NULL;
8409 + /* swap two lower dentries, and loop again */
8410 + q = au_hdentry(dinfo, new_bindex);
8414 + if (tmp.hd_dentry) {
8420 + dinfo->di_bwh = -1;
8421 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8422 + dinfo->di_bwh = bwh;
8424 + dinfo->di_bdiropq = -1;
8426 + && bdiropq <= au_sbbot(sb)
8427 + && au_sbr_whable(sb, bdiropq))
8428 + dinfo->di_bdiropq = bdiropq;
8431 + dinfo->di_btop = -1;
8432 + dinfo->di_bbot = -1;
8433 + bbot = au_dbbot(parent);
8435 + p = au_hdentry(dinfo, bindex);
8436 + for (; bindex <= bbot; bindex++, p++)
8437 + if (p->hd_dentry) {
8438 + dinfo->di_btop = bindex;
8442 + if (dinfo->di_btop >= 0) {
8444 + p = au_hdentry(dinfo, bindex);
8445 + for (; bindex >= 0; bindex--, p--)
8446 + if (p->hd_dentry) {
8447 + dinfo->di_bbot = bindex;
8456 +static void au_do_hide(struct dentry *dentry)
8458 + struct inode *inode;
8460 + if (d_really_is_positive(dentry)) {
8461 + inode = d_inode(dentry);
8462 + if (!d_is_dir(dentry)) {
8463 + if (inode->i_nlink && !d_unhashed(dentry))
8464 + drop_nlink(inode);
8466 + clear_nlink(inode);
8467 + /* stop next lookup */
8468 + inode->i_flags |= S_DEAD;
8470 + smp_mb(); /* necessary? */
8475 +static int au_hide_children(struct dentry *parent)
8477 + int err, i, j, ndentry;
8478 + struct au_dcsub_pages dpages;
8479 + struct au_dpage *dpage;
8480 + struct dentry *dentry;
8482 + err = au_dpages_init(&dpages, GFP_NOFS);
8483 + if (unlikely(err))
8485 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8486 + if (unlikely(err))
8489 + /* in reverse order */
8490 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8491 + dpage = dpages.dpages + i;
8492 + ndentry = dpage->ndentry;
8493 + for (j = ndentry - 1; j >= 0; j--) {
8494 + dentry = dpage->dentries[j];
8495 + if (dentry != parent)
8496 + au_do_hide(dentry);
8501 + au_dpages_free(&dpages);
8506 +static void au_hide(struct dentry *dentry)
8510 + AuDbgDentry(dentry);
8511 + if (d_is_dir(dentry)) {
8512 + /* shrink_dcache_parent(dentry); */
8513 + err = au_hide_children(dentry);
8514 + if (unlikely(err))
8515 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8518 + au_do_hide(dentry);
8522 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8524 + * a dirty branch is added
8525 + * - on the top of layers
8526 + * - in the middle of layers
8527 + * - to the bottom of layers
8529 + * on the added branch there exists
8532 + * - a same named entry
8534 + * * negative --> positive
8535 + * * positive --> positive
8536 + * - type is unchanged
8537 + * - type is changed
8539 + * * negative --> negative
8540 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8543 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8544 + struct au_dinfo *tmp)
8547 + aufs_bindex_t bindex, bbot;
8549 + struct dentry *dentry;
8550 + struct inode *inode;
8552 + } orig_h, tmp_h = {
8555 + struct au_hdentry *hd;
8556 + struct inode *inode, *h_inode;
8557 + struct dentry *h_dentry;
8560 + AuDebugOn(dinfo->di_btop < 0);
8562 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8563 + orig_h.inode = NULL;
8564 + if (d_is_positive(orig_h.dentry)) {
8565 + orig_h.inode = d_inode(orig_h.dentry);
8566 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8568 + if (tmp->di_btop >= 0) {
8569 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8570 + if (d_is_positive(tmp_h.dentry)) {
8571 + tmp_h.inode = d_inode(tmp_h.dentry);
8572 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8577 + if (d_really_is_positive(dentry))
8578 + inode = d_inode(dentry);
8579 + if (!orig_h.inode) {
8580 + AuDbg("negative originally\n");
8586 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8587 + AuDebugOn(dinfo->di_bdiropq != -1);
8589 + if (!tmp_h.inode) {
8590 + AuDbg("negative --> negative\n");
8591 + /* should have only one negative lower */
8592 + if (tmp->di_btop >= 0
8593 + && tmp->di_btop < dinfo->di_btop) {
8594 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8595 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8596 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8597 + au_di_cp(dinfo, tmp);
8598 + hd = au_hdentry(tmp, tmp->di_btop);
8599 + au_set_h_dptr(dentry, tmp->di_btop,
8600 + dget(hd->hd_dentry));
8602 + au_dbg_verify_dinode(dentry);
8604 + AuDbg("negative --> positive\n");
8606 + * similar to the behaviour of creating with bypassing
8608 + * unhash it in order to force an error in the
8609 + * succeeding create operation.
8610 + * we should not set S_DEAD here.
8613 + /* au_di_swap(tmp, dinfo); */
8614 + au_dbg_verify_dinode(dentry);
8617 + AuDbg("positive originally\n");
8618 + /* inode may be NULL */
8619 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8620 + if (!tmp_h.inode) {
8621 + AuDbg("positive --> negative\n");
8622 + /* or bypassing aufs */
8624 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8625 + dinfo->di_bwh = tmp->di_bwh;
8627 + err = au_refresh_hinode_self(inode);
8628 + au_dbg_verify_dinode(dentry);
8629 + } else if (orig_h.mode == tmp_h.mode) {
8630 + AuDbg("positive --> positive, same type\n");
8631 + if (!S_ISDIR(orig_h.mode)
8632 + && dinfo->di_btop > tmp->di_btop) {
8634 + * similar to the behaviour of removing and
8639 + err = au_refresh_hinode_self(inode);
8640 + au_dbg_verify_dinode(dentry);
8642 + /* fill empty slots */
8643 + if (dinfo->di_btop > tmp->di_btop)
8644 + dinfo->di_btop = tmp->di_btop;
8645 + if (dinfo->di_bbot < tmp->di_bbot)
8646 + dinfo->di_bbot = tmp->di_bbot;
8647 + dinfo->di_bwh = tmp->di_bwh;
8648 + dinfo->di_bdiropq = tmp->di_bdiropq;
8649 + bbot = dinfo->di_bbot;
8650 + bindex = tmp->di_btop;
8651 + hd = au_hdentry(tmp, bindex);
8652 + for (; bindex <= bbot; bindex++, hd++) {
8653 + if (au_h_dptr(dentry, bindex))
8655 + h_dentry = hd->hd_dentry;
8658 + AuDebugOn(d_is_negative(h_dentry));
8659 + h_inode = d_inode(h_dentry);
8660 + AuDebugOn(orig_h.mode
8661 + != (h_inode->i_mode
8663 + au_set_h_dptr(dentry, bindex,
8667 + err = au_refresh_hinode(inode, dentry);
8668 + au_dbg_verify_dinode(dentry);
8671 + AuDbg("positive --> positive, different type\n");
8672 + /* similar to the behaviour of removing and creating */
8675 + err = au_refresh_hinode_self(inode);
8676 + au_dbg_verify_dinode(dentry);
8684 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8686 + const struct dentry_operations *dop
8687 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8688 + static const unsigned int mask
8689 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8691 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8693 + if (dentry->d_op == dop)
8696 + AuDbg("%pd\n", dentry);
8697 + spin_lock(&dentry->d_lock);
8698 + if (dop == &aufs_dop)
8699 + dentry->d_flags |= mask;
8701 + dentry->d_flags &= ~mask;
8702 + dentry->d_op = dop;
8703 + spin_unlock(&dentry->d_lock);
8706 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8708 + int err, ebrange, nbr;
8709 + unsigned int sigen;
8710 + struct au_dinfo *dinfo, *tmp;
8711 + struct super_block *sb;
8712 + struct inode *inode;
8714 + DiMustWriteLock(dentry);
8715 + AuDebugOn(IS_ROOT(dentry));
8716 + AuDebugOn(d_really_is_negative(parent));
8718 + sb = dentry->d_sb;
8719 + sigen = au_sigen(sb);
8720 + err = au_digen_test(parent, sigen);
8721 + if (unlikely(err))
8724 + nbr = au_sbbot(sb) + 1;
8725 + dinfo = au_di(dentry);
8726 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8727 + if (unlikely(err))
8729 + ebrange = au_dbrange_test(dentry);
8731 + ebrange = au_do_refresh_hdentry(dentry, parent);
8733 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8734 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8735 + if (d_really_is_positive(dentry)) {
8736 + inode = d_inode(dentry);
8737 + err = au_refresh_hinode_self(inode);
8739 + au_dbg_verify_dinode(dentry);
8741 + goto out_dgen; /* success */
8745 + /* temporary dinfo */
8746 + AuDbgDentry(dentry);
8748 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8749 + if (unlikely(!tmp))
8751 + au_di_swap(tmp, dinfo);
8752 + /* returns the number of positive dentries */
8754 + * if current working dir is removed, it returns an error.
8755 + * but the dentry is legal.
8757 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8758 + AuDbgDentry(dentry);
8759 + au_di_swap(tmp, dinfo);
8760 + if (err == -ENOENT)
8763 + /* compare/refresh by dinfo */
8764 + AuDbgDentry(dentry);
8765 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8766 + au_dbg_verify_dinode(dentry);
8769 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8770 + au_rw_write_unlock(&tmp->di_rwsem);
8772 + if (unlikely(err))
8776 + au_update_digen(dentry);
8778 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8779 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8780 + AuDbgDentry(dentry);
8786 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8787 + struct dentry *dentry, aufs_bindex_t bindex)
8792 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8795 + AuDbg("b%d\n", bindex);
8797 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8798 + * due to whiteout and branch permission.
8800 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8801 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8802 + /* it may return tri-state */
8803 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8805 + if (unlikely(valid < 0))
8815 +/* todo: remove this */
8816 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8817 + unsigned int flags, int do_udba, int dirren)
8820 + umode_t mode, h_mode;
8821 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8822 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8823 + struct inode *h_inode, *h_cached_inode;
8824 + struct dentry *h_dentry;
8825 + struct qstr *name, *h_name;
8832 + unhashed = !!d_unhashed(dentry);
8833 + is_root = !!IS_ROOT(dentry);
8834 + name = &dentry->d_name;
8835 + tmpfile = au_di(dentry)->di_tmpfile;
8838 + * Theoretically, REVAL test should be unnecessary in case of
8840 + * But {fs,i}notify doesn't fire some necessary events,
8841 + * IN_ATTRIB for atime/nlink/pageio
8842 + * Let's do REVAL test too.
8844 + if (do_udba && inode) {
8845 + mode = (inode->i_mode & S_IFMT);
8846 + plus = (inode->i_nlink > 0);
8847 + ibs = au_ibtop(inode);
8848 + ibe = au_ibbot(inode);
8851 + btop = au_dbtop(dentry);
8853 + if (inode && S_ISDIR(inode->i_mode))
8854 + btail = au_dbtaildir(dentry);
8855 + for (bindex = btop; bindex <= btail; bindex++) {
8856 + h_dentry = au_h_dptr(dentry, bindex);
8860 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8861 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8862 + spin_lock(&h_dentry->d_lock);
8863 + h_name = &h_dentry->d_name;
8864 + if (unlikely(do_udba
8867 + && (unhashed != !!d_unhashed(h_dentry)
8868 + || (!tmpfile && !dirren
8869 + && !au_qstreq(name, h_name))
8872 + && !(flags & LOOKUP_OPEN)
8873 + && (h_dentry->d_flags
8874 + & DCACHE_NFSFS_RENAMED)))
8878 + h_unhashed = d_unhashed(h_dentry);
8879 + spin_unlock(&h_dentry->d_lock);
8880 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8881 + unhashed, h_unhashed, dentry, h_dentry);
8884 + spin_unlock(&h_dentry->d_lock);
8886 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8887 + if (unlikely(err))
8888 + /* do not goto err, to keep the errno */
8891 + /* todo: plink too? */
8896 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8900 + if (d_is_positive(h_dentry))
8901 + h_inode = d_inode(h_dentry);
8904 + h_cached_inode = h_inode;
8906 + h_mode = (h_inode->i_mode & S_IFMT);
8907 + h_plus = (h_inode->i_nlink > 0);
8909 + if (inode && ibs <= bindex && bindex <= ibe)
8910 + h_cached_inode = au_h_iptr(inode, bindex);
8913 + if (unlikely(plus != h_plus && !tmpfile))
8916 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8918 + && !IS_ROOT(h_dentry)
8919 + && unhashed != d_unhashed(h_dentry)))
8922 + if (unlikely(mode != h_mode
8923 + || h_cached_inode != h_inode))
8936 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8937 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8940 + struct dentry *parent;
8942 + if (!au_digen_test(dentry, sigen))
8945 + parent = dget_parent(dentry);
8946 + di_read_lock_parent(parent, AuLock_IR);
8947 + AuDebugOn(au_digen_test(parent, sigen));
8948 + au_dbg_verify_gen(parent, sigen);
8949 + err = au_refresh_dentry(dentry, parent);
8950 + di_read_unlock(parent, AuLock_IR);
8956 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8959 + struct dentry *d, *parent;
8961 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8962 + return simple_reval_dpath(dentry, sigen);
8964 + /* slow loop, keep it simple and stupid */
8965 + /* cf: au_cpup_dirs() */
8968 + while (au_digen_test(dentry, sigen)) {
8972 + parent = dget_parent(d);
8973 + if (!au_digen_test(parent, sigen))
8979 + di_write_lock_child2(d);
8981 + /* someone might update our dentry while we were sleeping */
8982 + if (au_digen_test(d, sigen)) {
8984 + * todo: consolidate with simple_reval_dpath(),
8985 + * do_refresh() and au_reval_for_attr().
8987 + di_read_lock_parent(parent, AuLock_IR);
8988 + err = au_refresh_dentry(d, parent);
8989 + di_read_unlock(parent, AuLock_IR);
8993 + di_write_unlock(d);
8995 + if (unlikely(err))
9003 + * if valid returns 1, otherwise 0.
9005 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9008 + unsigned int sigen;
9009 + unsigned char do_udba, dirren;
9010 + struct super_block *sb;
9011 + struct inode *inode;
9013 + /* todo: support rcu-walk? */
9014 + if (flags & LOOKUP_RCU)
9018 + if (unlikely(!au_di(dentry)))
9022 + sb = dentry->d_sb;
9025 + * i_mutex of parent dir may be held,
9026 + * but we should not return 'invalid' due to busy.
9028 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9029 + if (unlikely(err)) {
9035 + if (d_really_is_positive(dentry))
9036 + inode = d_inode(dentry);
9037 + if (unlikely(inode && au_is_bad_inode(inode))) {
9042 + if (unlikely(au_dbrange_test(dentry))) {
9048 + sigen = au_sigen(sb);
9049 + if (au_digen_test(dentry, sigen)) {
9050 + AuDebugOn(IS_ROOT(dentry));
9051 + err = au_reval_dpath(dentry, sigen);
9052 + if (unlikely(err)) {
9057 + di_downgrade_lock(dentry, AuLock_IR);
9060 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9062 + && !(inode->i_state && I_LINKABLE)
9063 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9068 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9069 + if (do_udba && inode) {
9070 + aufs_bindex_t btop = au_ibtop(inode);
9071 + struct inode *h_inode;
9074 + h_inode = au_h_iptr(inode, btop);
9075 + if (h_inode && au_test_higen(inode, h_inode)) {
9082 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9083 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9084 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9086 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9092 + di_downgrade_lock(dentry, AuLock_IR);
9094 + aufs_read_unlock(dentry, AuLock_IR);
9099 + AuDbg("%pd invalid, %d\n", dentry, valid);
9105 +static void aufs_d_release(struct dentry *dentry)
9107 + if (au_di(dentry)) {
9108 + au_di_fin(dentry);
9109 + au_hn_di_reinit(dentry);
9113 +const struct dentry_operations aufs_dop = {
9114 + .d_revalidate = aufs_d_revalidate,
9115 + .d_weak_revalidate = aufs_d_revalidate,
9116 + .d_release = aufs_d_release
9119 +/* aufs_dop without d_revalidate */
9120 +const struct dentry_operations aufs_dop_noreval = {
9121 + .d_release = aufs_d_release
9123 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9124 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9125 +++ linux/fs/aufs/dentry.h 2021-02-24 13:33:42.741013619 +0100
9127 +/* SPDX-License-Identifier: GPL-2.0 */
9129 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9131 + * This program, aufs is free software; you can redistribute it and/or modify
9132 + * it under the terms of the GNU General Public License as published by
9133 + * the Free Software Foundation; either version 2 of the License, or
9134 + * (at your option) any later version.
9136 + * This program is distributed in the hope that it will be useful,
9137 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9138 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9139 + * GNU General Public License for more details.
9141 + * You should have received a copy of the GNU General Public License
9142 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9146 + * lookup and dentry operations
9149 +#ifndef __AUFS_DENTRY_H__
9150 +#define __AUFS_DENTRY_H__
9154 +#include <linux/dcache.h>
9155 +#include "dirren.h"
9158 +struct au_hdentry {
9159 + struct dentry *hd_dentry;
9160 + aufs_bindex_t hd_id;
9164 + atomic_t di_generation;
9166 + struct au_rwsem di_rwsem;
9167 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9168 + unsigned char di_tmpfile; /* to allow the different name */
9169 + struct au_hdentry *di_hdentry;
9170 + struct rcu_head rcu;
9171 +} ____cacheline_aligned_in_smp;
9173 +/* ---------------------------------------------------------------------- */
9175 +/* flags for au_lkup_dentry() */
9176 +#define AuLkup_ALLOW_NEG 1
9177 +#define AuLkup_IGNORE_PERM (1 << 1)
9178 +#define AuLkup_DIRREN (1 << 2)
9179 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9180 +#define au_fset_lkup(flags, name) \
9181 + do { (flags) |= AuLkup_##name; } while (0)
9182 +#define au_fclr_lkup(flags, name) \
9183 + do { (flags) &= ~AuLkup_##name; } while (0)
9185 +#ifndef CONFIG_AUFS_DIRREN
9186 +#undef AuLkup_DIRREN
9187 +#define AuLkup_DIRREN 0
9190 +struct au_do_lookup_args {
9191 + unsigned int flags;
9193 + struct qstr whname, *name;
9194 + struct au_dr_lookup dirren;
9197 +/* ---------------------------------------------------------------------- */
9200 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9202 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9203 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9204 + struct dentry *h_parent, struct au_branch *br);
9206 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9207 + unsigned int flags);
9208 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9209 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9210 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9211 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9214 +void au_di_init_once(void *_di);
9215 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9216 +void au_di_free(struct au_dinfo *dinfo);
9217 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9218 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9219 +int au_di_init(struct dentry *dentry);
9220 +void au_di_fin(struct dentry *dentry);
9221 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9223 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9224 +void di_read_unlock(struct dentry *d, int flags);
9225 +void di_downgrade_lock(struct dentry *d, int flags);
9226 +void di_write_lock(struct dentry *d, unsigned int lsc);
9227 +void di_write_unlock(struct dentry *d);
9228 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9229 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9230 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9232 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9233 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9234 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9235 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9237 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9238 + struct dentry *h_dentry);
9239 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9240 +int au_dbrange_test(struct dentry *dentry);
9241 +void au_update_digen(struct dentry *dentry);
9242 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9243 +void au_update_dbtop(struct dentry *dentry);
9244 +void au_update_dbbot(struct dentry *dentry);
9245 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9247 +/* ---------------------------------------------------------------------- */
9249 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9251 + return dentry->d_fsdata;
9254 +/* ---------------------------------------------------------------------- */
9256 +/* lock subclass for dinfo */
9258 + AuLsc_DI_CHILD, /* child first */
9259 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9260 + AuLsc_DI_CHILD3, /* copyup dirs */
9264 + AuLsc_DI_TMP /* temp for replacing dinfo */
9268 + * di_read_lock_child, di_write_lock_child,
9269 + * di_read_lock_child2, di_write_lock_child2,
9270 + * di_read_lock_child3, di_write_lock_child3,
9271 + * di_read_lock_parent, di_write_lock_parent,
9272 + * di_read_lock_parent2, di_write_lock_parent2,
9273 + * di_read_lock_parent3, di_write_lock_parent3,
9275 +#define AuReadLockFunc(name, lsc) \
9276 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9277 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9279 +#define AuWriteLockFunc(name, lsc) \
9280 +static inline void di_write_lock_##name(struct dentry *d) \
9281 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9283 +#define AuRWLockFuncs(name, lsc) \
9284 + AuReadLockFunc(name, lsc) \
9285 + AuWriteLockFunc(name, lsc)
9287 +AuRWLockFuncs(child, CHILD);
9288 +AuRWLockFuncs(child2, CHILD2);
9289 +AuRWLockFuncs(child3, CHILD3);
9290 +AuRWLockFuncs(parent, PARENT);
9291 +AuRWLockFuncs(parent2, PARENT2);
9292 +AuRWLockFuncs(parent3, PARENT3);
9294 +#undef AuReadLockFunc
9295 +#undef AuWriteLockFunc
9296 +#undef AuRWLockFuncs
9298 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9299 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9300 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9302 +/* ---------------------------------------------------------------------- */
9304 +/* todo: memory barrier? */
9305 +static inline unsigned int au_digen(struct dentry *d)
9307 + return atomic_read(&au_di(d)->di_generation);
9310 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9312 + hdentry->hd_dentry = NULL;
9315 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9316 + aufs_bindex_t bindex)
9318 + return di->di_hdentry + bindex;
9321 +static inline void au_hdput(struct au_hdentry *hd)
9324 + dput(hd->hd_dentry);
9327 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9329 + DiMustAnyLock(dentry);
9330 + return au_di(dentry)->di_btop;
9333 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9335 + DiMustAnyLock(dentry);
9336 + return au_di(dentry)->di_bbot;
9339 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9341 + DiMustAnyLock(dentry);
9342 + return au_di(dentry)->di_bwh;
9345 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9347 + DiMustAnyLock(dentry);
9348 + return au_di(dentry)->di_bdiropq;
9351 +/* todo: hard/soft set? */
9352 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9354 + DiMustWriteLock(dentry);
9355 + au_di(dentry)->di_btop = bindex;
9358 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9360 + DiMustWriteLock(dentry);
9361 + au_di(dentry)->di_bbot = bindex;
9364 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9366 + DiMustWriteLock(dentry);
9367 + /* dbwh can be outside of btop - bbot range */
9368 + au_di(dentry)->di_bwh = bindex;
9371 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9373 + DiMustWriteLock(dentry);
9374 + au_di(dentry)->di_bdiropq = bindex;
9377 +/* ---------------------------------------------------------------------- */
9379 +#ifdef CONFIG_AUFS_HNOTIFY
9380 +static inline void au_digen_dec(struct dentry *d)
9382 + atomic_dec(&au_di(d)->di_generation);
9385 +static inline void au_hn_di_reinit(struct dentry *dentry)
9387 + dentry->d_fsdata = NULL;
9390 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9391 +#endif /* CONFIG_AUFS_HNOTIFY */
9393 +#endif /* __KERNEL__ */
9394 +#endif /* __AUFS_DENTRY_H__ */
9395 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9396 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9397 +++ linux/fs/aufs/dinfo.c 2021-02-24 13:33:42.741013619 +0100
9399 +// SPDX-License-Identifier: GPL-2.0
9401 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9403 + * This program, aufs is free software; you can redistribute it and/or modify
9404 + * it under the terms of the GNU General Public License as published by
9405 + * the Free Software Foundation; either version 2 of the License, or
9406 + * (at your option) any later version.
9408 + * This program is distributed in the hope that it will be useful,
9409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9411 + * GNU General Public License for more details.
9413 + * You should have received a copy of the GNU General Public License
9414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9418 + * dentry private data
9423 +void au_di_init_once(void *_dinfo)
9425 + struct au_dinfo *dinfo = _dinfo;
9427 + au_rw_init(&dinfo->di_rwsem);
9430 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9432 + struct au_dinfo *dinfo;
9435 + dinfo = au_cache_alloc_dinfo();
9436 + if (unlikely(!dinfo))
9439 + nbr = au_sbbot(sb) + 1;
9442 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9443 + if (dinfo->di_hdentry) {
9444 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9445 + dinfo->di_btop = -1;
9446 + dinfo->di_bbot = -1;
9447 + dinfo->di_bwh = -1;
9448 + dinfo->di_bdiropq = -1;
9449 + dinfo->di_tmpfile = 0;
9450 + for (i = 0; i < nbr; i++)
9451 + dinfo->di_hdentry[i].hd_id = -1;
9455 + au_cache_free_dinfo(dinfo);
9462 +void au_di_free(struct au_dinfo *dinfo)
9464 + struct au_hdentry *p;
9465 + aufs_bindex_t bbot, bindex;
9467 + /* dentry may not be revalidated */
9468 + bindex = dinfo->di_btop;
9469 + if (bindex >= 0) {
9470 + bbot = dinfo->di_bbot;
9471 + p = au_hdentry(dinfo, bindex);
9472 + while (bindex++ <= bbot)
9475 + au_kfree_try_rcu(dinfo->di_hdentry);
9476 + au_cache_free_dinfo(dinfo);
9479 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9481 + struct au_hdentry *p;
9484 + AuRwMustWriteLock(&a->di_rwsem);
9485 + AuRwMustWriteLock(&b->di_rwsem);
9487 +#define DiSwap(v, name) \
9489 + v = a->di_##name; \
9490 + a->di_##name = b->di_##name; \
9491 + b->di_##name = v; \
9494 + DiSwap(p, hdentry);
9498 + DiSwap(bi, bdiropq);
9504 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9506 + AuRwMustWriteLock(&dst->di_rwsem);
9507 + AuRwMustWriteLock(&src->di_rwsem);
9509 + dst->di_btop = src->di_btop;
9510 + dst->di_bbot = src->di_bbot;
9511 + dst->di_bwh = src->di_bwh;
9512 + dst->di_bdiropq = src->di_bdiropq;
9516 +int au_di_init(struct dentry *dentry)
9519 + struct super_block *sb;
9520 + struct au_dinfo *dinfo;
9523 + sb = dentry->d_sb;
9524 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9526 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9527 + /* smp_mb(); */ /* atomic_set */
9528 + dentry->d_fsdata = dinfo;
9535 +void au_di_fin(struct dentry *dentry)
9537 + struct au_dinfo *dinfo;
9539 + dinfo = au_di(dentry);
9540 + AuRwDestroy(&dinfo->di_rwsem);
9541 + au_di_free(dinfo);
9544 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9547 + struct au_hdentry *hdp;
9549 + AuRwMustWriteLock(&dinfo->di_rwsem);
9552 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9554 + sz = sizeof(*hdp);
9555 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9558 + dinfo->di_hdentry = hdp;
9565 +/* ---------------------------------------------------------------------- */
9567 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9570 + case AuLsc_DI_CHILD:
9571 + ii_write_lock_child(inode);
9573 + case AuLsc_DI_CHILD2:
9574 + ii_write_lock_child2(inode);
9576 + case AuLsc_DI_CHILD3:
9577 + ii_write_lock_child3(inode);
9579 + case AuLsc_DI_PARENT:
9580 + ii_write_lock_parent(inode);
9582 + case AuLsc_DI_PARENT2:
9583 + ii_write_lock_parent2(inode);
9585 + case AuLsc_DI_PARENT3:
9586 + ii_write_lock_parent3(inode);
9593 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9596 + case AuLsc_DI_CHILD:
9597 + ii_read_lock_child(inode);
9599 + case AuLsc_DI_CHILD2:
9600 + ii_read_lock_child2(inode);
9602 + case AuLsc_DI_CHILD3:
9603 + ii_read_lock_child3(inode);
9605 + case AuLsc_DI_PARENT:
9606 + ii_read_lock_parent(inode);
9608 + case AuLsc_DI_PARENT2:
9609 + ii_read_lock_parent2(inode);
9611 + case AuLsc_DI_PARENT3:
9612 + ii_read_lock_parent3(inode);
9619 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9621 + struct inode *inode;
9623 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9624 + if (d_really_is_positive(d)) {
9625 + inode = d_inode(d);
9626 + if (au_ftest_lock(flags, IW))
9627 + do_ii_write_lock(inode, lsc);
9628 + else if (au_ftest_lock(flags, IR))
9629 + do_ii_read_lock(inode, lsc);
9633 +void di_read_unlock(struct dentry *d, int flags)
9635 + struct inode *inode;
9637 + if (d_really_is_positive(d)) {
9638 + inode = d_inode(d);
9639 + if (au_ftest_lock(flags, IW)) {
9640 + au_dbg_verify_dinode(d);
9641 + ii_write_unlock(inode);
9642 + } else if (au_ftest_lock(flags, IR)) {
9643 + au_dbg_verify_dinode(d);
9644 + ii_read_unlock(inode);
9647 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9650 +void di_downgrade_lock(struct dentry *d, int flags)
9652 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9653 + ii_downgrade_lock(d_inode(d));
9654 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9657 +void di_write_lock(struct dentry *d, unsigned int lsc)
9659 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9660 + if (d_really_is_positive(d))
9661 + do_ii_write_lock(d_inode(d), lsc);
9664 +void di_write_unlock(struct dentry *d)
9666 + au_dbg_verify_dinode(d);
9667 + if (d_really_is_positive(d))
9668 + ii_write_unlock(d_inode(d));
9669 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9672 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9674 + AuDebugOn(d1 == d2
9675 + || d_inode(d1) == d_inode(d2)
9676 + || d1->d_sb != d2->d_sb);
9678 + if ((isdir && au_test_subdir(d1, d2))
9680 + di_write_lock_child(d1);
9681 + di_write_lock_child2(d2);
9683 + di_write_lock_child(d2);
9684 + di_write_lock_child2(d1);
9688 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9690 + AuDebugOn(d1 == d2
9691 + || d_inode(d1) == d_inode(d2)
9692 + || d1->d_sb != d2->d_sb);
9694 + if ((isdir && au_test_subdir(d1, d2))
9696 + di_write_lock_parent(d1);
9697 + di_write_lock_parent2(d2);
9699 + di_write_lock_parent(d2);
9700 + di_write_lock_parent2(d1);
9704 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9706 + di_write_unlock(d1);
9707 + if (d_inode(d1) == d_inode(d2))
9708 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9710 + di_write_unlock(d2);
9713 +/* ---------------------------------------------------------------------- */
9715 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9719 + DiMustAnyLock(dentry);
9721 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9723 + AuDebugOn(bindex < 0);
9724 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9725 + AuDebugOn(d && au_dcount(d) <= 0);
9730 + * extended version of au_h_dptr().
9731 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9734 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9736 + struct dentry *h_dentry;
9737 + struct inode *inode, *h_inode;
9739 + AuDebugOn(d_really_is_negative(dentry));
9742 + if (au_dbtop(dentry) <= bindex
9743 + && bindex <= au_dbbot(dentry))
9744 + h_dentry = au_h_dptr(dentry, bindex);
9745 + if (h_dentry && !au_d_linkable(h_dentry)) {
9747 + goto out; /* success */
9750 + inode = d_inode(dentry);
9751 + AuDebugOn(bindex < au_ibtop(inode));
9752 + AuDebugOn(au_ibbot(inode) < bindex);
9753 + h_inode = au_h_iptr(inode, bindex);
9754 + h_dentry = d_find_alias(h_inode);
9756 + if (!IS_ERR(h_dentry)) {
9757 + if (!au_d_linkable(h_dentry))
9758 + goto out; /* success */
9764 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9765 + h_dentry = au_plink_lkup(inode, bindex);
9766 + AuDebugOn(!h_dentry);
9767 + if (!IS_ERR(h_dentry)) {
9768 + if (!au_d_hashed_positive(h_dentry))
9769 + goto out; /* success */
9776 + AuDbgDentry(h_dentry);
9780 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9782 + aufs_bindex_t bbot, bwh;
9784 + bbot = au_dbbot(dentry);
9786 + bwh = au_dbwh(dentry);
9789 + if (0 < bwh && bwh < bbot)
9795 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9797 + aufs_bindex_t bbot, bopq;
9799 + bbot = au_dbtail(dentry);
9801 + bopq = au_dbdiropq(dentry);
9802 + if (0 <= bopq && bopq < bbot)
9808 +/* ---------------------------------------------------------------------- */
9810 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9811 + struct dentry *h_dentry)
9813 + struct au_dinfo *dinfo;
9814 + struct au_hdentry *hd;
9815 + struct au_branch *br;
9817 + DiMustWriteLock(dentry);
9819 + dinfo = au_di(dentry);
9820 + hd = au_hdentry(dinfo, bindex);
9822 + hd->hd_dentry = h_dentry;
9824 + br = au_sbr(dentry->d_sb, bindex);
9825 + hd->hd_id = br->br_id;
9829 +int au_dbrange_test(struct dentry *dentry)
9832 + aufs_bindex_t btop, bbot;
9835 + btop = au_dbtop(dentry);
9836 + bbot = au_dbbot(dentry);
9838 + AuDebugOn(bbot < 0 && btop > bbot);
9841 + AuDebugOn(bbot >= 0);
9847 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9852 + if (unlikely(au_digen(dentry) != sigen
9853 + || au_iigen_test(d_inode(dentry), sigen)))
9859 +void au_update_digen(struct dentry *dentry)
9861 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9862 + /* smp_mb(); */ /* atomic_set */
9865 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9867 + struct au_dinfo *dinfo;
9868 + struct dentry *h_d;
9869 + struct au_hdentry *hdp;
9870 + aufs_bindex_t bindex, bbot;
9872 + DiMustWriteLock(dentry);
9874 + dinfo = au_di(dentry);
9875 + if (!dinfo || dinfo->di_btop < 0)
9878 + if (do_put_zero) {
9879 + bbot = dinfo->di_bbot;
9880 + bindex = dinfo->di_btop;
9881 + hdp = au_hdentry(dinfo, bindex);
9882 + for (; bindex <= bbot; bindex++, hdp++) {
9883 + h_d = hdp->hd_dentry;
9884 + if (h_d && d_is_negative(h_d))
9885 + au_set_h_dptr(dentry, bindex, NULL);
9889 + dinfo->di_btop = 0;
9890 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9891 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9892 + if (hdp->hd_dentry)
9894 + if (dinfo->di_btop > dinfo->di_bbot) {
9895 + dinfo->di_btop = -1;
9896 + dinfo->di_bbot = -1;
9900 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9901 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9902 + if (hdp->hd_dentry)
9904 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9907 +void au_update_dbtop(struct dentry *dentry)
9909 + aufs_bindex_t bindex, bbot;
9910 + struct dentry *h_dentry;
9912 + bbot = au_dbbot(dentry);
9913 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9914 + h_dentry = au_h_dptr(dentry, bindex);
9917 + if (d_is_positive(h_dentry)) {
9918 + au_set_dbtop(dentry, bindex);
9921 + au_set_h_dptr(dentry, bindex, NULL);
9925 +void au_update_dbbot(struct dentry *dentry)
9927 + aufs_bindex_t bindex, btop;
9928 + struct dentry *h_dentry;
9930 + btop = au_dbtop(dentry);
9931 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9932 + h_dentry = au_h_dptr(dentry, bindex);
9935 + if (d_is_positive(h_dentry)) {
9936 + au_set_dbbot(dentry, bindex);
9939 + au_set_h_dptr(dentry, bindex, NULL);
9943 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9945 + aufs_bindex_t bindex, bbot;
9947 + bbot = au_dbbot(dentry);
9948 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9949 + if (au_h_dptr(dentry, bindex) == h_dentry)
9953 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9954 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9955 +++ linux/fs/aufs/dir.c 2021-02-24 13:33:42.741013619 +0100
9957 +// SPDX-License-Identifier: GPL-2.0
9959 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9961 + * This program, aufs is free software; you can redistribute it and/or modify
9962 + * it under the terms of the GNU General Public License as published by
9963 + * the Free Software Foundation; either version 2 of the License, or
9964 + * (at your option) any later version.
9966 + * This program is distributed in the hope that it will be useful,
9967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9969 + * GNU General Public License for more details.
9971 + * You should have received a copy of the GNU General Public License
9972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9976 + * directory operations
9979 +#include <linux/fs_stack.h>
9980 +#include <linux/iversion.h>
9983 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9985 + unsigned int nlink;
9987 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9989 + nlink = dir->i_nlink;
9990 + nlink += h_dir->i_nlink - 2;
9991 + if (h_dir->i_nlink < 2)
9993 + smp_mb(); /* for i_nlink */
9994 + /* 0 can happen in revaliding */
9995 + set_nlink(dir, nlink);
9998 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10000 + unsigned int nlink;
10002 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10004 + nlink = dir->i_nlink;
10005 + nlink -= h_dir->i_nlink - 2;
10006 + if (h_dir->i_nlink < 2)
10008 + smp_mb(); /* for i_nlink */
10009 + /* nlink == 0 means the branch-fs is broken */
10010 + set_nlink(dir, nlink);
10013 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10016 + aufs_bindex_t bindex, bbot;
10017 + struct file *h_file;
10018 + struct dentry *h_dentry;
10022 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10024 + bbot = au_fbbot_dir(file);
10025 + for (bindex = au_fbtop(file);
10026 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10028 + h_file = au_hf_dir(file, bindex);
10029 + if (h_file && file_inode(h_file))
10030 + sz += vfsub_f_size_read(h_file);
10033 + AuDebugOn(!dentry);
10034 + AuDebugOn(!d_is_dir(dentry));
10036 + bbot = au_dbtaildir(dentry);
10037 + for (bindex = au_dbtop(dentry);
10038 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10040 + h_dentry = au_h_dptr(dentry, bindex);
10041 + if (h_dentry && d_is_positive(h_dentry))
10042 + sz += i_size_read(d_inode(h_dentry));
10045 + if (sz < KMALLOC_MAX_SIZE)
10046 + sz = roundup_pow_of_two(sz);
10047 + if (sz > KMALLOC_MAX_SIZE)
10048 + sz = KMALLOC_MAX_SIZE;
10049 + else if (sz < NAME_MAX) {
10050 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10051 + sz = AUFS_RDBLK_DEF;
10056 +struct au_dir_ts_arg {
10057 + struct dentry *dentry;
10058 + aufs_bindex_t brid;
10061 +static void au_do_dir_ts(void *arg)
10063 + struct au_dir_ts_arg *a = arg;
10064 + struct au_dtime dt;
10065 + struct path h_path;
10066 + struct inode *dir, *h_dir;
10067 + struct super_block *sb;
10068 + struct au_branch *br;
10069 + struct au_hinode *hdir;
10071 + aufs_bindex_t btop, bindex;
10073 + sb = a->dentry->d_sb;
10074 + if (d_really_is_negative(a->dentry))
10076 + /* no dir->i_mutex lock */
10077 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10079 + dir = d_inode(a->dentry);
10080 + btop = au_ibtop(dir);
10081 + bindex = au_br_index(sb, a->brid);
10082 + if (bindex < btop)
10085 + br = au_sbr(sb, bindex);
10086 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10087 + if (!h_path.dentry)
10089 + h_path.mnt = au_br_mnt(br);
10090 + au_dtime_store(&dt, a->dentry, &h_path);
10092 + br = au_sbr(sb, btop);
10093 + if (!au_br_writable(br->br_perm))
10095 + h_path.dentry = au_h_dptr(a->dentry, btop);
10096 + h_path.mnt = au_br_mnt(br);
10097 + err = vfsub_mnt_want_write(h_path.mnt);
10100 + hdir = au_hi(dir, btop);
10101 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10102 + h_dir = au_h_iptr(dir, btop);
10103 + if (h_dir->i_nlink
10104 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10105 + dt.dt_h_path = h_path;
10106 + au_dtime_revert(&dt);
10108 + au_hn_inode_unlock(hdir);
10109 + vfsub_mnt_drop_write(h_path.mnt);
10110 + au_cpup_attr_timesizes(dir);
10113 + aufs_read_unlock(a->dentry, AuLock_DW);
10116 + au_nwt_done(&au_sbi(sb)->si_nowait);
10117 + au_kfree_try_rcu(arg);
10120 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10122 + int perm, wkq_err;
10123 + aufs_bindex_t btop;
10124 + struct au_dir_ts_arg *arg;
10125 + struct dentry *dentry;
10126 + struct super_block *sb;
10130 + dentry = d_find_any_alias(dir);
10131 + AuDebugOn(!dentry);
10132 + sb = dentry->d_sb;
10133 + btop = au_ibtop(dir);
10134 + if (btop == bindex) {
10135 + au_cpup_attr_timesizes(dir);
10139 + perm = au_sbr_perm(sb, btop);
10140 + if (!au_br_writable(perm))
10143 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10147 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10148 + arg->brid = au_sbr_id(sb, bindex);
10149 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10150 + if (unlikely(wkq_err)) {
10151 + pr_err("wkq %d\n", wkq_err);
10153 + au_kfree_try_rcu(arg);
10160 +/* ---------------------------------------------------------------------- */
10162 +static int reopen_dir(struct file *file)
10165 + unsigned int flags;
10166 + aufs_bindex_t bindex, btail, btop;
10167 + struct dentry *dentry, *h_dentry;
10168 + struct file *h_file;
10170 + /* open all lower dirs */
10171 + dentry = file->f_path.dentry;
10172 + btop = au_dbtop(dentry);
10173 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10174 + au_set_h_fptr(file, bindex, NULL);
10175 + au_set_fbtop(file, btop);
10177 + btail = au_dbtaildir(dentry);
10178 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10179 + au_set_h_fptr(file, bindex, NULL);
10180 + au_set_fbbot_dir(file, btail);
10182 + flags = vfsub_file_flags(file);
10183 + for (bindex = btop; bindex <= btail; bindex++) {
10184 + h_dentry = au_h_dptr(dentry, bindex);
10187 + h_file = au_hf_dir(file, bindex);
10191 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10192 + err = PTR_ERR(h_file);
10193 + if (IS_ERR(h_file))
10194 + goto out; /* close all? */
10195 + au_set_h_fptr(file, bindex, h_file);
10197 + au_update_figen(file);
10198 + /* todo: necessary? */
10199 + /* file->f_ra = h_file->f_ra; */
10206 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10209 + aufs_bindex_t bindex, btail;
10210 + struct dentry *dentry, *h_dentry;
10211 + struct vfsmount *mnt;
10213 + FiMustWriteLock(file);
10214 + AuDebugOn(h_file);
10217 + mnt = file->f_path.mnt;
10218 + dentry = file->f_path.dentry;
10219 + file->f_version = inode_query_iversion(d_inode(dentry));
10220 + bindex = au_dbtop(dentry);
10221 + au_set_fbtop(file, bindex);
10222 + btail = au_dbtaildir(dentry);
10223 + au_set_fbbot_dir(file, btail);
10224 + for (; !err && bindex <= btail; bindex++) {
10225 + h_dentry = au_h_dptr(dentry, bindex);
10229 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10230 + if (unlikely(err))
10232 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10233 + if (IS_ERR(h_file)) {
10234 + err = PTR_ERR(h_file);
10237 + au_set_h_fptr(file, bindex, h_file);
10239 + au_update_figen(file);
10240 + /* todo: necessary? */
10241 + /* file->f_ra = h_file->f_ra; */
10243 + return 0; /* success */
10246 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10247 + au_set_h_fptr(file, bindex, NULL);
10248 + au_set_fbtop(file, -1);
10249 + au_set_fbbot_dir(file, -1);
10254 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10255 + struct file *file)
10258 + struct super_block *sb;
10259 + struct au_fidir *fidir;
10262 + sb = file->f_path.dentry->d_sb;
10263 + si_read_lock(sb, AuLock_FLUSH);
10264 + fidir = au_fidir_alloc(sb);
10266 + struct au_do_open_args args = {
10267 + .open = do_open_dir,
10270 + err = au_do_open(file, &args);
10271 + if (unlikely(err))
10272 + au_kfree_rcu(fidir);
10274 + si_read_unlock(sb);
10278 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10279 + struct file *file)
10281 + struct au_vdir *vdir_cache;
10282 + struct au_finfo *finfo;
10283 + struct au_fidir *fidir;
10284 + struct au_hfile *hf;
10285 + aufs_bindex_t bindex, bbot;
10287 + finfo = au_fi(file);
10288 + fidir = finfo->fi_hdir;
10290 + au_hbl_del(&finfo->fi_hlist,
10291 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10292 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10294 + au_vdir_free(vdir_cache);
10296 + bindex = finfo->fi_btop;
10297 + if (bindex >= 0) {
10298 + hf = fidir->fd_hfile + bindex;
10300 + * calls fput() instead of filp_close(),
10301 + * since no dnotify or lock for the lower file.
10303 + bbot = fidir->fd_bbot;
10304 + for (; bindex <= bbot; bindex++, hf++)
10306 + au_hfput(hf, /*execed*/0);
10308 + au_kfree_rcu(fidir);
10309 + finfo->fi_hdir = NULL;
10311 + au_finfo_fin(file);
10315 +/* ---------------------------------------------------------------------- */
10317 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10320 + aufs_bindex_t bindex, bbot;
10321 + struct file *h_file;
10324 + bbot = au_fbbot_dir(file);
10325 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10326 + h_file = au_hf_dir(file, bindex);
10328 + err = vfsub_flush(h_file, id);
10333 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10335 + return au_do_flush(file, id, au_do_flush_dir);
10338 +/* ---------------------------------------------------------------------- */
10340 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10343 + aufs_bindex_t bbot, bindex;
10344 + struct inode *inode;
10345 + struct super_block *sb;
10348 + sb = dentry->d_sb;
10349 + inode = d_inode(dentry);
10350 + IMustLock(inode);
10351 + bbot = au_dbbot(dentry);
10352 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10353 + struct path h_path;
10355 + if (au_test_ro(sb, bindex, inode))
10357 + h_path.dentry = au_h_dptr(dentry, bindex);
10358 + if (!h_path.dentry)
10361 + h_path.mnt = au_sbr_mnt(sb, bindex);
10362 + err = vfsub_fsync(NULL, &h_path, datasync);
10368 +static int au_do_fsync_dir(struct file *file, int datasync)
10371 + aufs_bindex_t bbot, bindex;
10372 + struct file *h_file;
10373 + struct super_block *sb;
10374 + struct inode *inode;
10376 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10377 + if (unlikely(err))
10380 + inode = file_inode(file);
10381 + sb = inode->i_sb;
10382 + bbot = au_fbbot_dir(file);
10383 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10384 + h_file = au_hf_dir(file, bindex);
10385 + if (!h_file || au_test_ro(sb, bindex, inode))
10388 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10396 + * @file may be NULL
10398 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10402 + struct dentry *dentry;
10403 + struct inode *inode;
10404 + struct super_block *sb;
10407 + dentry = file->f_path.dentry;
10408 + inode = d_inode(dentry);
10409 + inode_lock(inode);
10410 + sb = dentry->d_sb;
10411 + si_noflush_read_lock(sb);
10413 + err = au_do_fsync_dir(file, datasync);
10415 + di_write_lock_child(dentry);
10416 + err = au_do_fsync_dir_no_file(dentry, datasync);
10418 + au_cpup_attr_timesizes(inode);
10419 + di_write_unlock(dentry);
10421 + fi_write_unlock(file);
10423 + si_read_unlock(sb);
10424 + inode_unlock(inode);
10428 +/* ---------------------------------------------------------------------- */
10430 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10433 + struct dentry *dentry;
10434 + struct inode *inode, *h_inode;
10435 + struct super_block *sb;
10437 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10439 + dentry = file->f_path.dentry;
10440 + inode = d_inode(dentry);
10441 + IMustLock(inode);
10443 + sb = dentry->d_sb;
10444 + si_read_lock(sb, AuLock_FLUSH);
10445 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10446 + if (unlikely(err))
10448 + err = au_alive_dir(dentry);
10450 + err = au_vdir_init(file);
10451 + di_downgrade_lock(dentry, AuLock_IR);
10452 + if (unlikely(err))
10455 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10456 + if (!au_test_nfsd()) {
10457 + err = au_vdir_fill_de(file, ctx);
10458 + fsstack_copy_attr_atime(inode, h_inode);
10461 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10462 + * encode_fh() and others.
10464 + atomic_inc(&h_inode->i_count);
10465 + di_read_unlock(dentry, AuLock_IR);
10466 + si_read_unlock(sb);
10467 + err = au_vdir_fill_de(file, ctx);
10468 + fsstack_copy_attr_atime(inode, h_inode);
10469 + fi_write_unlock(file);
10477 + di_read_unlock(dentry, AuLock_IR);
10478 + fi_write_unlock(file);
10480 + si_read_unlock(sb);
10484 +/* ---------------------------------------------------------------------- */
10486 +#define AuTestEmpty_WHONLY 1
10487 +#define AuTestEmpty_CALLED (1 << 1)
10488 +#define AuTestEmpty_SHWH (1 << 2)
10489 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10490 +#define au_fset_testempty(flags, name) \
10491 + do { (flags) |= AuTestEmpty_##name; } while (0)
10492 +#define au_fclr_testempty(flags, name) \
10493 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10495 +#ifndef CONFIG_AUFS_SHWH
10496 +#undef AuTestEmpty_SHWH
10497 +#define AuTestEmpty_SHWH 0
10500 +struct test_empty_arg {
10501 + struct dir_context ctx;
10502 + struct au_nhash *whlist;
10503 + unsigned int flags;
10505 + aufs_bindex_t bindex;
10508 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10509 + int namelen, loff_t offset __maybe_unused, u64 ino,
10510 + unsigned int d_type)
10512 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10514 + char *name = (void *)__name;
10517 + au_fset_testempty(arg->flags, CALLED);
10519 + if (name[0] == '.'
10520 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10521 + goto out; /* success */
10523 + if (namelen <= AUFS_WH_PFX_LEN
10524 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10525 + if (au_ftest_testempty(arg->flags, WHONLY)
10526 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10527 + arg->err = -ENOTEMPTY;
10531 + name += AUFS_WH_PFX_LEN;
10532 + namelen -= AUFS_WH_PFX_LEN;
10533 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10534 + arg->err = au_nhash_append_wh
10535 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10536 + au_ftest_testempty(arg->flags, SHWH));
10540 + AuTraceErr(arg->err);
10544 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10547 + struct file *h_file;
10548 + struct au_branch *br;
10550 + h_file = au_h_open(dentry, arg->bindex,
10551 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10552 + /*file*/NULL, /*force_wr*/0);
10553 + err = PTR_ERR(h_file);
10554 + if (IS_ERR(h_file))
10558 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10559 + && !file_inode(h_file)->i_nlink)
10564 + au_fclr_testempty(arg->flags, CALLED);
10566 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10569 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10573 + br = au_sbr(dentry->d_sb, arg->bindex);
10574 + au_lcnt_dec(&br->br_nfiles);
10579 +struct do_test_empty_args {
10581 + struct dentry *dentry;
10582 + struct test_empty_arg *arg;
10585 +static void call_do_test_empty(void *args)
10587 + struct do_test_empty_args *a = args;
10588 + *a->errp = do_test_empty(a->dentry, a->arg);
10591 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10593 + int err, wkq_err;
10594 + struct dentry *h_dentry;
10595 + struct inode *h_inode;
10597 + h_dentry = au_h_dptr(dentry, arg->bindex);
10598 + h_inode = d_inode(h_dentry);
10599 + /* todo: i_mode changes anytime? */
10600 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10601 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10602 + inode_unlock_shared(h_inode);
10604 + err = do_test_empty(dentry, arg);
10606 + struct do_test_empty_args args = {
10608 + .dentry = dentry,
10611 + unsigned int flags = arg->flags;
10613 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10614 + if (unlikely(wkq_err))
10616 + arg->flags = flags;
10622 +int au_test_empty_lower(struct dentry *dentry)
10625 + unsigned int rdhash;
10626 + aufs_bindex_t bindex, btop, btail;
10627 + struct au_nhash whlist;
10628 + struct test_empty_arg arg = {
10630 + .actor = test_empty_cb
10633 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10635 + SiMustAnyLock(dentry->d_sb);
10637 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10639 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10640 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10641 + if (unlikely(err))
10645 + arg.whlist = &whlist;
10646 + btop = au_dbtop(dentry);
10647 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10648 + au_fset_testempty(arg.flags, SHWH);
10649 + test_empty = do_test_empty;
10650 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10651 + test_empty = sio_test_empty;
10652 + arg.bindex = btop;
10653 + err = test_empty(dentry, &arg);
10654 + if (unlikely(err))
10657 + au_fset_testempty(arg.flags, WHONLY);
10658 + btail = au_dbtaildir(dentry);
10659 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10660 + struct dentry *h_dentry;
10662 + h_dentry = au_h_dptr(dentry, bindex);
10663 + if (h_dentry && d_is_positive(h_dentry)) {
10664 + arg.bindex = bindex;
10665 + err = test_empty(dentry, &arg);
10670 + au_nhash_wh_free(&whlist);
10675 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10678 + struct test_empty_arg arg = {
10680 + .actor = test_empty_cb
10683 + aufs_bindex_t bindex, btail;
10686 + arg.whlist = whlist;
10687 + arg.flags = AuTestEmpty_WHONLY;
10688 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10689 + au_fset_testempty(arg.flags, SHWH);
10690 + btail = au_dbtaildir(dentry);
10691 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10692 + struct dentry *h_dentry;
10694 + h_dentry = au_h_dptr(dentry, bindex);
10695 + if (h_dentry && d_is_positive(h_dentry)) {
10696 + arg.bindex = bindex;
10697 + err = sio_test_empty(dentry, &arg);
10704 +/* ---------------------------------------------------------------------- */
10706 +const struct file_operations aufs_dir_fop = {
10707 + .owner = THIS_MODULE,
10708 + .llseek = default_llseek,
10709 + .read = generic_read_dir,
10710 + .iterate_shared = aufs_iterate_shared,
10711 + .unlocked_ioctl = aufs_ioctl_dir,
10712 +#ifdef CONFIG_COMPAT
10713 + .compat_ioctl = aufs_compat_ioctl_dir,
10715 + .open = aufs_open_dir,
10716 + .release = aufs_release_dir,
10717 + .flush = aufs_flush_dir,
10718 + .fsync = aufs_fsync_dir
10720 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10721 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10722 +++ linux/fs/aufs/dir.h 2021-02-24 13:33:42.741013619 +0100
10724 +/* SPDX-License-Identifier: GPL-2.0 */
10726 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10728 + * This program, aufs is free software; you can redistribute it and/or modify
10729 + * it under the terms of the GNU General Public License as published by
10730 + * the Free Software Foundation; either version 2 of the License, or
10731 + * (at your option) any later version.
10733 + * This program is distributed in the hope that it will be useful,
10734 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10735 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10736 + * GNU General Public License for more details.
10738 + * You should have received a copy of the GNU General Public License
10739 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10743 + * directory operations
10746 +#ifndef __AUFS_DIR_H__
10747 +#define __AUFS_DIR_H__
10751 +#include <linux/fs.h>
10753 +/* ---------------------------------------------------------------------- */
10755 +/* need to be faster and smaller */
10758 + unsigned int nh_num;
10759 + struct hlist_head *nh_head;
10762 +struct au_vdir_destr {
10763 + unsigned char len;
10764 + unsigned char name[];
10767 +struct au_vdir_dehstr {
10768 + struct hlist_node hash;
10769 + struct au_vdir_destr *str;
10770 + struct rcu_head rcu;
10771 +} ____cacheline_aligned_in_smp;
10773 +struct au_vdir_de {
10775 + unsigned char de_type;
10776 + /* caution: packed */
10777 + struct au_vdir_destr de_str;
10780 +struct au_vdir_wh {
10781 + struct hlist_node wh_hash;
10782 +#ifdef CONFIG_AUFS_SHWH
10784 + aufs_bindex_t wh_bindex;
10785 + unsigned char wh_type;
10787 + aufs_bindex_t wh_bindex;
10789 + /* caution: packed */
10790 + struct au_vdir_destr wh_str;
10793 +union au_vdir_deblk_p {
10794 + unsigned char *deblk;
10795 + struct au_vdir_de *de;
10799 + unsigned char **vd_deblk;
10800 + unsigned long vd_nblk;
10802 + unsigned long ul;
10803 + union au_vdir_deblk_p p;
10807 + unsigned int vd_deblk_sz;
10808 + unsigned long vd_jiffy;
10809 + struct rcu_head rcu;
10810 +} ____cacheline_aligned_in_smp;
10812 +/* ---------------------------------------------------------------------- */
10815 +extern const struct file_operations aufs_dir_fop;
10816 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10817 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10818 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10819 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10820 +int au_test_empty_lower(struct dentry *dentry);
10821 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10824 +unsigned int au_rdhash_est(loff_t sz);
10825 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10826 +void au_nhash_wh_free(struct au_nhash *whlist);
10827 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10829 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10830 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10831 + unsigned int d_type, aufs_bindex_t bindex,
10832 + unsigned char shwh);
10833 +void au_vdir_free(struct au_vdir *vdir);
10834 +int au_vdir_init(struct file *file);
10835 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10838 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10840 +#ifdef CONFIG_AUFS_RDU
10842 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10843 +#ifdef CONFIG_COMPAT
10844 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10845 + unsigned long arg);
10848 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10849 + unsigned int cmd, unsigned long arg)
10850 +#ifdef CONFIG_COMPAT
10851 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10852 + unsigned int cmd, unsigned long arg)
10856 +#endif /* __KERNEL__ */
10857 +#endif /* __AUFS_DIR_H__ */
10858 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10859 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10860 +++ linux/fs/aufs/dirren.c 2021-02-24 13:33:42.741013619 +0100
10862 +// SPDX-License-Identifier: GPL-2.0
10864 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10866 + * This program, aufs is free software; you can redistribute it and/or modify
10867 + * it under the terms of the GNU General Public License as published by
10868 + * the Free Software Foundation; either version 2 of the License, or
10869 + * (at your option) any later version.
10871 + * This program is distributed in the hope that it will be useful,
10872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10874 + * GNU General Public License for more details.
10876 + * You should have received a copy of the GNU General Public License
10877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10881 + * special handling in renaming a directory
10882 + * in order to support looking-up the before-renamed name on the lower readonly
10886 +#include <linux/byteorder/generic.h>
10889 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10893 + idx = au_dr_ihash(ent->dr_h_ino);
10894 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10897 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10900 + struct hlist_bl_head *hbl;
10903 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10904 + hbl = dr->dr_h_ino + i;
10905 + hlist_bl_lock(hbl);
10906 + ret &= hlist_bl_empty(hbl);
10907 + hlist_bl_unlock(hbl);
10913 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10915 + struct au_dr_hino *found, *ent;
10916 + struct hlist_bl_head *hbl;
10917 + struct hlist_bl_node *pos;
10921 + idx = au_dr_ihash(ino);
10922 + hbl = dr->dr_h_ino + idx;
10923 + hlist_bl_lock(hbl);
10924 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10925 + if (ent->dr_h_ino == ino) {
10929 + hlist_bl_unlock(hbl);
10934 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10935 + struct au_dr_hino *add_ent)
10938 + struct hlist_bl_head *hbl;
10939 + struct hlist_bl_node *pos;
10940 + struct au_dr_hino *ent;
10943 + idx = au_dr_ihash(ino);
10944 + hbl = dr->dr_h_ino + idx;
10945 +#if 0 /* debug print */
10947 + struct hlist_bl_node *tmp;
10949 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10950 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10953 + hlist_bl_lock(hbl);
10954 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10955 + if (ent->dr_h_ino == ino) {
10959 + if (!found && add_ent)
10960 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10961 + hlist_bl_unlock(hbl);
10963 + if (!found && add_ent)
10964 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10969 +void au_dr_hino_free(struct au_dr_br *dr)
10972 + struct hlist_bl_head *hbl;
10973 + struct hlist_bl_node *pos, *tmp;
10974 + struct au_dr_hino *ent;
10976 + /* SiMustWriteLock(sb); */
10978 + for (i = 0; i < AuDirren_NHASH; i++) {
10979 + hbl = dr->dr_h_ino + i;
10980 + /* no spinlock since sbinfo must be write-locked */
10981 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10982 + au_kfree_rcu(ent);
10983 + INIT_HLIST_BL_HEAD(hbl);
10987 +/* returns the number of inodes or an error */
10988 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10989 + struct file *hinofile)
10993 + loff_t pos, oldsize;
10995 + struct inode *hinoinode;
10996 + struct hlist_bl_head *hbl;
10997 + struct hlist_bl_node *n1, *n2;
10998 + struct au_dr_hino *ent;
11000 + SiMustWriteLock(sb);
11001 + AuDebugOn(!au_br_writable(br->br_perm));
11003 + hinoinode = file_inode(hinofile);
11004 + oldsize = i_size_read(hinoinode);
11008 + hbl = br->br_dirren.dr_h_ino;
11009 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11010 + /* no bit-lock since sbinfo must be write-locked */
11011 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11012 + AuDbg("hi%llu, %pD2\n",
11013 + (unsigned long long)ent->dr_h_ino, hinofile);
11014 + u64 = cpu_to_be64(ent->dr_h_ino);
11015 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11016 + if (ssz == sizeof(u64))
11019 + /* write error */
11020 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11027 + /* regardless the error */
11028 + if (pos < oldsize) {
11029 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11037 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11044 + struct au_dr_hino *ent;
11045 + struct inode *hinoinode;
11046 + struct hlist_bl_head *hbl;
11050 + hbl = dr->dr_h_ino;
11051 + hinoinode = file_inode(hinofile);
11052 + sz = i_size_read(hinoinode);
11053 + AuDebugOn(sz % sizeof(u64));
11054 + n = sz / sizeof(u64);
11056 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11057 + if (unlikely(ssz != sizeof(u64))) {
11058 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11065 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11071 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11072 + AuDbg("hi%llu, %pD2\n",
11073 + (unsigned long long)ent->dr_h_ino, hinofile);
11074 + hidx = au_dr_ihash(ent->dr_h_ino);
11075 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11077 + goto out; /* success */
11080 + au_dr_hino_free(dr);
11087 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11088 + * @path is a switch to distinguish load and store.
11090 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11091 + struct au_branch *br, const struct path *path)
11094 + unsigned char load, suspend;
11095 + struct file *hinofile;
11096 + struct au_hinode *hdir;
11097 + struct inode *dir, *delegated;
11098 + struct path hinopath;
11099 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11100 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11102 + AuDebugOn(bindex < 0 && !br);
11103 + AuDebugOn(bindex >= 0 && br);
11108 + br = au_sbr(sb, bindex);
11111 + path = &br->br_path;
11112 + AuDebugOn(!au_br_writable(br->br_perm));
11113 + if (unlikely(!au_br_writable(br->br_perm)))
11119 + dir = d_inode(sb->s_root);
11120 + hdir = au_hinode(au_ii(dir), bindex);
11121 + dir = hdir->hi_inode;
11122 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11124 + dir = d_inode(path->dentry);
11125 + inode_lock_nested(dir, AuLsc_I_CHILD);
11127 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11128 + err = PTR_ERR(hinopath.dentry);
11129 + if (IS_ERR(hinopath.dentry))
11133 + flags = O_RDONLY;
11135 + if (d_is_negative(hinopath.dentry))
11136 + goto out_dput; /* success */
11138 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11139 + if (d_is_positive(hinopath.dentry)) {
11140 + delegated = NULL;
11141 + err = vfsub_unlink(dir, &hinopath, &delegated,
11144 + if (unlikely(err))
11145 + pr_err("ignored err %d, %pd2\n",
11146 + err, hinopath.dentry);
11147 + if (unlikely(err == -EWOULDBLOCK))
11152 + } else if (!d_is_positive(hinopath.dentry)) {
11153 + err = vfsub_create(dir, &hinopath, 0600,
11154 + /*want_excl*/false);
11156 + if (unlikely(err))
11159 + flags = O_WRONLY;
11161 + hinopath.mnt = path->mnt;
11162 + hinofile = vfsub_dentry_open(&hinopath, flags);
11164 + au_hn_inode_unlock(hdir);
11166 + inode_unlock(dir);
11167 + dput(hinopath.dentry);
11168 + AuTraceErrPtr(hinofile);
11169 + if (IS_ERR(hinofile)) {
11170 + err = PTR_ERR(hinofile);
11175 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11177 + err = au_dr_hino_store(sb, br, hinofile);
11182 + dput(hinopath.dentry);
11185 + au_hn_inode_unlock(hdir);
11187 + inode_unlock(dir);
11193 +/* ---------------------------------------------------------------------- */
11195 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11198 + struct kstatfs kstfs;
11200 + struct dentry *dentry;
11201 + struct super_block *sb;
11203 + err = vfs_statfs((void *)path, &kstfs);
11205 + if (unlikely(err))
11208 + /* todo: support for UUID */
11210 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11211 + brid->type = AuBrid_FSID;
11212 + brid->fsid = kstfs.f_fsid;
11214 + dentry = path->dentry;
11215 + sb = dentry->d_sb;
11218 + brid->type = AuBrid_DEV;
11227 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11228 + const struct path *path)
11231 + struct au_dr_br *dr;
11232 + struct hlist_bl_head *hbl;
11234 + dr = &br->br_dirren;
11235 + hbl = dr->dr_h_ino;
11236 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11237 + INIT_HLIST_BL_HEAD(hbl);
11239 + err = au_dr_brid_init(&dr->dr_brid, path);
11240 + if (unlikely(err))
11243 + if (au_opt_test(au_mntflags(sb), DIRREN))
11244 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11251 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11256 + if (au_br_writable(br->br_perm))
11257 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11259 + au_dr_hino_free(&br->br_dirren);
11264 +/* ---------------------------------------------------------------------- */
11266 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11267 + char *buf, size_t sz)
11270 + unsigned int major, minor;
11274 + err = snprintf(p, sz, "%d_", brid->type);
11275 + AuDebugOn(err > sz);
11278 + switch (brid->type) {
11279 + case AuBrid_Unset:
11281 + case AuBrid_UUID:
11282 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11284 + case AuBrid_FSID:
11285 + err = snprintf(p, sz, "%08x-%08x",
11286 + brid->fsid.val[0], brid->fsid.val[1]);
11289 + major = MAJOR(brid->dev);
11290 + minor = MINOR(brid->dev);
11291 + if (major <= 0xff && minor <= 0xff)
11292 + err = snprintf(p, sz, "%02x%02x", major, minor);
11294 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11297 + AuDebugOn(err > sz);
11300 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11301 + AuDebugOn(err > sz);
11308 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11311 + struct dentry *br_dentry;
11312 + struct inode *br_inode;
11314 + br_dentry = au_br_dentry(br);
11315 + br_inode = d_inode(br_dentry);
11316 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11317 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11318 + AuDebugOn(rlen > len);
11323 +/* ---------------------------------------------------------------------- */
11326 + * from the given @h_dentry, construct drinfo at @*fdata.
11327 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11330 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11331 + struct dentry *h_dentry,
11332 + unsigned char *allocated)
11335 + struct au_drinfo_fdata *f, *p;
11336 + struct au_drinfo *drinfo;
11337 + struct inode *h_inode;
11338 + struct qstr *qname;
11342 + h_inode = d_inode(h_dentry);
11343 + qname = &h_dentry->d_name;
11344 + drinfo = &f->drinfo;
11345 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11346 + drinfo->oldnamelen = qname->len;
11347 + if (*allocated < sizeof(*f) + qname->len) {
11348 + v = roundup_pow_of_two(*allocated + qname->len);
11349 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11350 + if (unlikely(!p)) {
11358 + drinfo = &f->drinfo;
11360 + memcpy(drinfo->oldname, qname->name, qname->len);
11361 + AuDbg("i%llu, %.*s\n",
11362 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11363 + drinfo->oldname);
11370 +/* callers have to free the return value */
11371 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11373 + struct au_drinfo *ret, *drinfo;
11374 + struct au_drinfo_fdata fdata;
11379 + ret = ERR_PTR(-EIO);
11381 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11382 + if (unlikely(ssz != sizeof(fdata))) {
11383 + AuIOErr("ssz %zd, %u, %pD2\n",
11384 + ssz, (unsigned int)sizeof(fdata), file);
11388 + fdata.magic = ntohl((__force __be32)fdata.magic);
11389 + switch (fdata.magic) {
11390 + case AUFS_DRINFO_MAGIC_V1:
11393 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11394 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11398 + drinfo = &fdata.drinfo;
11399 + len = drinfo->oldnamelen;
11401 + AuIOErr("broken drinfo %pD2\n", file);
11406 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11407 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11408 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11409 + (unsigned long long)drinfo->ino,
11410 + (unsigned long long)h_ino, file);
11411 + goto out; /* success */
11414 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11415 + if (unlikely(!ret)) {
11416 + ret = ERR_PTR(-ENOMEM);
11417 + AuTraceErrPtr(ret);
11422 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11423 + if (unlikely(ssz != len)) {
11424 + au_kfree_rcu(ret);
11425 + ret = ERR_PTR(-EIO);
11426 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11430 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11436 +/* ---------------------------------------------------------------------- */
11438 +/* in order to be revertible */
11439 +struct au_drinfo_rev_elm {
11441 + struct dentry *info_dentry;
11442 + struct au_drinfo *info_last;
11445 +struct au_drinfo_rev {
11446 + unsigned char already;
11447 + aufs_bindex_t nelm;
11448 + struct au_drinfo_rev_elm elm[];
11451 +/* todo: isn't it too large? */
11452 +struct au_drinfo_store {
11453 + struct path h_ppath;
11454 + struct dentry *h_dentry;
11455 + struct au_drinfo_fdata *fdata;
11456 + char *infoname; /* inside of whname, just after PFX */
11457 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11458 + aufs_bindex_t btgt, btail;
11459 + unsigned char no_sio,
11460 + allocated, /* current size of *fdata */
11461 + infonamelen, /* room size for p */
11462 + whnamelen, /* length of the generated name */
11463 + renameback; /* renamed back */
11466 +/* on rename(2) error, the caller should revert it using @elm */
11467 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11468 + struct au_drinfo_rev_elm *elm)
11473 + struct path infopath = {
11474 + .mnt = w->h_ppath.mnt
11476 + struct inode *h_dir, *h_inode, *delegated;
11477 + struct file *infofile;
11478 + struct qstr *qname;
11481 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11483 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11485 + AuTraceErrPtr(infopath.dentry);
11486 + if (IS_ERR(infopath.dentry)) {
11487 + err = PTR_ERR(infopath.dentry);
11492 + h_dir = d_inode(w->h_ppath.dentry);
11493 + if (elm && d_is_negative(infopath.dentry)) {
11494 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11496 + if (unlikely(err))
11498 + elm->created = 1;
11499 + elm->info_dentry = dget(infopath.dentry);
11502 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11503 + AuTraceErrPtr(infofile);
11504 + if (IS_ERR(infofile)) {
11505 + err = PTR_ERR(infofile);
11509 + h_inode = d_inode(infopath.dentry);
11510 + if (elm && i_size_read(h_inode)) {
11511 + h_inode = d_inode(w->h_dentry);
11512 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11513 + AuTraceErrPtr(elm->info_last);
11514 + if (IS_ERR(elm->info_last)) {
11515 + err = PTR_ERR(elm->info_last);
11516 + elm->info_last = NULL;
11517 + AuDebugOn(elm->info_dentry);
11522 + if (elm && w->renameback) {
11523 + delegated = NULL;
11524 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11526 + if (unlikely(err == -EWOULDBLOCK))
11532 + qname = &w->h_dentry->d_name;
11533 + len = sizeof(*w->fdata) + qname->len;
11535 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11536 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11537 + if (ssz == len) {
11538 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11539 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11540 + goto out_fput; /* success */
11545 + /* the caller should revert it using @elm */
11551 + dput(infopath.dentry);
11557 +struct au_call_drinfo_do_store_args {
11559 + struct au_drinfo_store *w;
11560 + struct au_drinfo_rev_elm *elm;
11563 +static void au_call_drinfo_do_store(void *args)
11565 + struct au_call_drinfo_do_store_args *a = args;
11567 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11570 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11571 + struct au_drinfo_rev_elm *elm)
11573 + int err, wkq_err;
11576 + err = au_drinfo_do_store(w, elm);
11578 + struct au_call_drinfo_do_store_args a = {
11583 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11584 + if (unlikely(wkq_err))
11592 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11593 + aufs_bindex_t btgt)
11597 + memset(w, 0, sizeof(*w));
11598 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11599 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11600 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11601 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11603 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11606 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11607 + if (unlikely(!w->fdata)) {
11611 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11618 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11620 + au_kfree_rcu(w->fdata);
11623 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11624 + struct au_drinfo_store *w)
11626 + struct au_drinfo_rev_elm *elm;
11627 + struct inode *h_dir, *delegated;
11629 + struct path infopath = {
11630 + .mnt = w->h_ppath.mnt
11633 + h_dir = d_inode(w->h_ppath.dentry);
11634 + IMustLock(h_dir);
11638 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11639 + AuDebugOn(elm->created && elm->info_last);
11640 + if (elm->created) {
11642 + delegated = NULL;
11643 + infopath.dentry = elm->info_dentry;
11644 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11647 + if (unlikely(err == -EWOULDBLOCK))
11649 + dput(elm->info_dentry);
11650 + } else if (elm->info_last) {
11652 + w->fdata->drinfo = *elm->info_last;
11653 + memcpy(w->fdata->drinfo.oldname,
11654 + elm->info_last->oldname,
11655 + elm->info_last->oldnamelen);
11656 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11657 + au_kfree_rcu(elm->info_last);
11659 + if (unlikely(err))
11660 + AuIOErr("%d, %s\n", err, w->whname);
11661 + /* go on even if err */
11665 +/* caller has to call au_dr_rename_fin() later */
11666 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11667 + struct qstr *dst_name, void *_rev)
11669 + int err, sz, nelm;
11670 + aufs_bindex_t bindex, btail;
11671 + struct au_drinfo_store work;
11672 + struct au_drinfo_rev *rev, **p;
11673 + struct au_drinfo_rev_elm *elm;
11674 + struct super_block *sb;
11675 + struct au_branch *br;
11676 + struct au_hinode *hdir;
11678 + err = au_drinfo_store_work_init(&work, btgt);
11680 + if (unlikely(err))
11684 + btail = au_dbtaildir(dentry);
11685 + nelm = btail - btgt;
11686 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11687 + rev = kcalloc(1, sz, GFP_NOFS);
11688 + if (unlikely(!rev)) {
11692 + rev->nelm = nelm;
11698 + sb = dentry->d_sb;
11699 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11700 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11701 + hdir = au_hi(d_inode(dentry), btgt);
11702 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11703 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11704 + work.h_dentry = au_h_dptr(dentry, bindex);
11705 + if (!work.h_dentry)
11708 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11709 + &work.allocated);
11711 + if (unlikely(err))
11714 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11715 + br = au_sbr(sb, bindex);
11716 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11717 + work.whnamelen += au_drinfo_name(br, work.infoname,
11718 + work.infonamelen);
11719 + AuDbg("whname %.*s, i%llu, %.*s\n",
11720 + work.whnamelen, work.whname,
11721 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11722 + work.fdata->drinfo.oldnamelen,
11723 + work.fdata->drinfo.oldname);
11725 + err = au_drinfo_store_sio(&work, elm);
11727 + if (unlikely(err))
11730 + if (unlikely(err)) {
11731 + /* revert all drinfo */
11732 + au_drinfo_store_rev(rev, &work);
11733 + au_kfree_try_rcu(rev);
11736 + au_hn_inode_unlock(hdir);
11739 + au_drinfo_store_work_fin(&work);
11744 +/* ---------------------------------------------------------------------- */
11746 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11747 + struct qstr *dst_name, void *_rev)
11749 + int err, already;
11751 + struct super_block *sb;
11752 + struct au_branch *br;
11753 + struct au_dr_br *dr;
11754 + struct dentry *h_dentry;
11755 + struct inode *h_inode;
11756 + struct au_dr_hino *ent;
11757 + struct au_drinfo_rev *rev, **p;
11759 + AuDbg("bindex %d\n", bindex);
11762 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11763 + if (unlikely(!ent))
11767 + br = au_sbr(sb, bindex);
11768 + dr = &br->br_dirren;
11769 + h_dentry = au_h_dptr(src, bindex);
11770 + h_inode = d_inode(h_dentry);
11771 + ino = h_inode->i_ino;
11772 + ent->dr_h_ino = ino;
11773 + already = au_dr_hino_test_add(dr, ino, ent);
11774 + AuDbg("b%d, hi%llu, already %d\n",
11775 + bindex, (unsigned long long)ino, already);
11777 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11782 + rev->already = already;
11783 + goto out; /* success */
11788 + au_dr_hino_del(dr, ent);
11789 + au_kfree_rcu(ent);
11796 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11798 + struct au_drinfo_rev *rev;
11799 + struct au_drinfo_rev_elm *elm;
11804 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11805 + dput(elm->info_dentry);
11806 + au_kfree_rcu(elm->info_last);
11808 + au_kfree_try_rcu(rev);
11811 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11814 + struct au_drinfo_store work;
11815 + struct au_drinfo_rev *rev = _rev;
11816 + struct super_block *sb;
11817 + struct au_branch *br;
11818 + struct inode *h_inode;
11819 + struct au_dr_br *dr;
11820 + struct au_dr_hino *ent;
11822 + err = au_drinfo_store_work_init(&work, btgt);
11823 + if (unlikely(err))
11827 + br = au_sbr(sb, btgt);
11828 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11829 + work.h_ppath.mnt = au_br_mnt(br);
11830 + au_drinfo_store_rev(rev, &work);
11831 + au_drinfo_store_work_fin(&work);
11832 + if (rev->already)
11835 + dr = &br->br_dirren;
11836 + h_inode = d_inode(work.h_ppath.dentry);
11837 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11839 + au_dr_hino_del(dr, ent);
11840 + au_kfree_rcu(ent);
11843 + au_kfree_try_rcu(rev);
11844 + if (unlikely(err))
11845 + pr_err("failed to remove dirren info\n");
11848 +/* ---------------------------------------------------------------------- */
11850 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11851 + char *whname, int whnamelen,
11852 + struct dentry **info_dentry)
11854 + struct au_drinfo *drinfo;
11856 + struct inode *h_dir;
11857 + struct path infopath;
11860 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11862 + *info_dentry = NULL;
11865 + h_dir = d_inode(h_ppath->dentry);
11866 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11867 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11869 + if (IS_ERR(infopath.dentry)) {
11870 + drinfo = (void *)infopath.dentry;
11874 + if (d_is_negative(infopath.dentry))
11875 + goto out_dput; /* success */
11877 + infopath.mnt = h_ppath->mnt;
11878 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11879 + inode_unlock_shared(h_dir);
11882 + drinfo = (void *)f;
11886 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11887 + if (IS_ERR_OR_NULL(drinfo))
11890 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11891 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11896 + dput(infopath.dentry);
11899 + inode_unlock_shared(h_dir);
11900 + AuTraceErrPtr(drinfo);
11904 +struct au_drinfo_do_load_args {
11905 + struct au_drinfo **drinfop;
11906 + struct path *h_ppath;
11909 + struct dentry **info_dentry;
11912 +static void au_call_drinfo_do_load(void *args)
11914 + struct au_drinfo_do_load_args *a = args;
11916 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11920 +struct au_drinfo_load {
11921 + struct path h_ppath;
11922 + struct qstr *qname;
11923 + unsigned char no_sio;
11925 + aufs_bindex_t ninfo;
11926 + struct au_drinfo **drinfo;
11929 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11930 + struct au_branch *br)
11932 + int err, wkq_err, whnamelen, e;
11933 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11934 + = AUFS_WH_DR_INFO_PFX;
11935 + struct au_drinfo *drinfo;
11936 + struct qstr oldname;
11937 + struct inode *h_dir, *delegated;
11938 + struct dentry *info_dentry;
11939 + struct path infopath;
11941 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11942 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11943 + sizeof(whname) - whnamelen);
11945 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11948 + struct au_drinfo_do_load_args args = {
11949 + .drinfop = &drinfo,
11950 + .h_ppath = &w->h_ppath,
11951 + .whname = whname,
11952 + .whnamelen = whnamelen,
11953 + .info_dentry = &info_dentry
11955 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11956 + if (unlikely(wkq_err))
11957 + drinfo = ERR_PTR(wkq_err);
11959 + err = PTR_ERR(drinfo);
11960 + if (IS_ERR_OR_NULL(drinfo))
11964 + oldname.len = drinfo->oldnamelen;
11965 + oldname.name = drinfo->oldname;
11966 + if (au_qstreq(w->qname, &oldname)) {
11967 + /* the name is renamed back */
11968 + au_kfree_rcu(drinfo);
11971 + infopath.dentry = info_dentry;
11972 + infopath.mnt = w->h_ppath.mnt;
11973 + h_dir = d_inode(w->h_ppath.dentry);
11974 + delegated = NULL;
11975 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11976 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11977 + inode_unlock(h_dir);
11979 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11980 + if (unlikely(e == -EWOULDBLOCK))
11983 + au_kfree_rcu(w->drinfo[bindex]);
11984 + w->drinfo[bindex] = drinfo;
11985 + dput(info_dentry);
11992 +/* ---------------------------------------------------------------------- */
11994 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11996 + struct au_drinfo **p = drinfo;
11999 + au_kfree_rcu(*drinfo++);
12000 + au_kfree_try_rcu(p);
12003 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12004 + aufs_bindex_t btgt)
12007 + struct au_drinfo_load w;
12008 + aufs_bindex_t bindex, bbot;
12009 + struct au_branch *br;
12010 + struct inode *h_dir;
12011 + struct au_dr_hino *ent;
12012 + struct super_block *sb;
12014 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12015 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12016 + AuLNPair(&lkup->whname), btgt);
12018 + sb = dentry->d_sb;
12019 + bbot = au_sbbot(sb);
12020 + w.ninfo = bbot + 1;
12021 + if (!lkup->dirren.drinfo) {
12022 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12023 + sizeof(*lkup->dirren.drinfo),
12025 + if (unlikely(!lkup->dirren.drinfo)) {
12029 + lkup->dirren.ninfo = w.ninfo;
12031 + w.drinfo = lkup->dirren.drinfo;
12032 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12033 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12034 + AuDebugOn(!w.h_ppath.dentry);
12035 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12036 + w.qname = &dentry->d_name;
12039 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12040 + br = au_sbr(sb, bindex);
12041 + err = au_drinfo_load(&w, bindex, br);
12042 + if (unlikely(err))
12044 + if (w.drinfo[bindex])
12048 + br = au_sbr(sb, btgt);
12049 + h_dir = d_inode(w.h_ppath.dentry);
12050 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12052 + au_dr_hino_del(&br->br_dirren, ent);
12053 + au_kfree_rcu(ent);
12055 + goto out; /* success */
12058 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12059 + lkup->dirren.ninfo = 0;
12060 + lkup->dirren.drinfo = NULL;
12066 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12068 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12071 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12074 + struct au_drinfo *drinfo;
12077 + if (!lkup->dirren.drinfo)
12079 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12080 + drinfo = lkup->dirren.drinfo[btgt];
12084 + au_kfree_try_rcu(lkup->whname.name);
12085 + lkup->whname.name = NULL;
12086 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12087 + lkup->dirren.dr_name.name = drinfo->oldname;
12088 + lkup->name = &lkup->dirren.dr_name;
12089 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12091 + AuDbg("name %.*s, whname %.*s, b%d\n",
12092 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12100 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12104 + struct au_drinfo *drinfo;
12107 + if (!lkup->dirren.drinfo)
12109 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12110 + drinfo = lkup->dirren.drinfo[bindex];
12114 + match = (drinfo->ino == h_ino);
12115 + AuDbg("match %d\n", match);
12121 +/* ---------------------------------------------------------------------- */
12123 +int au_dr_opt_set(struct super_block *sb)
12126 + aufs_bindex_t bindex, bbot;
12127 + struct au_branch *br;
12130 + bbot = au_sbbot(sb);
12131 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12132 + br = au_sbr(sb, bindex);
12133 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12139 +int au_dr_opt_flush(struct super_block *sb)
12142 + aufs_bindex_t bindex, bbot;
12143 + struct au_branch *br;
12146 + bbot = au_sbbot(sb);
12147 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12148 + br = au_sbr(sb, bindex);
12149 + if (au_br_writable(br->br_perm))
12150 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12156 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12159 + aufs_bindex_t bindex, bbot;
12160 + struct au_branch *br;
12164 + err = au_dr_opt_flush(sb);
12165 + if (unlikely(err))
12169 + bbot = au_sbbot(sb);
12170 + for (bindex = 0; bindex <= bbot; bindex++) {
12171 + br = au_sbr(sb, bindex);
12172 + au_dr_hino_free(&br->br_dirren);
12178 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12179 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12180 +++ linux/fs/aufs/dirren.h 2021-02-24 13:33:42.741013619 +0100
12182 +/* SPDX-License-Identifier: GPL-2.0 */
12184 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12186 + * This program, aufs is free software; you can redistribute it and/or modify
12187 + * it under the terms of the GNU General Public License as published by
12188 + * the Free Software Foundation; either version 2 of the License, or
12189 + * (at your option) any later version.
12191 + * This program is distributed in the hope that it will be useful,
12192 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12193 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12194 + * GNU General Public License for more details.
12196 + * You should have received a copy of the GNU General Public License
12197 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12201 + * renamed dir info
12204 +#ifndef __AUFS_DIRREN_H__
12205 +#define __AUFS_DIRREN_H__
12209 +#include <linux/dcache.h>
12210 +#include <linux/statfs.h>
12211 +#include <linux/uuid.h>
12214 +#define AuDirren_NHASH 100
12216 +#ifdef CONFIG_AUFS_DIRREN
12217 +enum au_brid_type {
12224 +struct au_dr_brid {
12225 + enum au_brid_type type;
12227 + uuid_t uuid; /* unimplemented yet */
12233 +/* 20 is the max digits length of ulong 64 */
12234 +/* brid-type "_" uuid "_" inum */
12235 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12236 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12238 +struct au_dr_hino {
12239 + struct hlist_bl_node dr_hnode;
12244 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12245 + struct au_dr_brid dr_brid;
12248 +struct au_dr_lookup {
12249 + /* dr_name is pointed by struct au_do_lookup_args.name */
12250 + struct qstr dr_name; /* subset of dr_info */
12251 + aufs_bindex_t ninfo;
12252 + struct au_drinfo **drinfo;
12255 +struct au_dr_hino;
12257 +struct au_dr_br { };
12258 +struct au_dr_lookup { };
12261 +/* ---------------------------------------------------------------------- */
12264 +struct au_do_lookup_args;
12266 +#ifdef CONFIG_AUFS_DIRREN
12267 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12268 + struct au_dr_hino *add_ent);
12269 +void au_dr_hino_free(struct au_dr_br *dr);
12270 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12271 + const struct path *path);
12272 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12273 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12274 + struct qstr *dst_name, void *_rev);
12275 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12276 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12277 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12278 + aufs_bindex_t bindex);
12279 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12280 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12282 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12283 +int au_dr_opt_set(struct super_block *sb);
12284 +int au_dr_opt_flush(struct super_block *sb);
12285 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12287 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12288 + struct au_dr_hino *add_ent);
12289 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12290 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12291 + const struct path *path);
12292 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12293 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12294 + struct qstr *dst_name, void *_rev);
12295 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12296 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12298 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12299 + aufs_bindex_t bindex);
12300 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12301 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12302 + aufs_bindex_t bindex, ino_t h_ino);
12303 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12304 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12305 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12306 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12309 +/* ---------------------------------------------------------------------- */
12311 +#ifdef CONFIG_AUFS_DIRREN
12312 +static inline int au_dr_ihash(ino_t h_ino)
12314 + return h_ino % AuDirren_NHASH;
12317 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12320 +#endif /* __KERNEL__ */
12321 +#endif /* __AUFS_DIRREN_H__ */
12322 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12323 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12324 +++ linux/fs/aufs/dynop.c 2021-02-24 13:33:42.744347058 +0100
12326 +// SPDX-License-Identifier: GPL-2.0
12328 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12330 + * This program, aufs is free software; you can redistribute it and/or modify
12331 + * it under the terms of the GNU General Public License as published by
12332 + * the Free Software Foundation; either version 2 of the License, or
12333 + * (at your option) any later version.
12335 + * This program is distributed in the hope that it will be useful,
12336 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12338 + * GNU General Public License for more details.
12340 + * You should have received a copy of the GNU General Public License
12341 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12345 + * dynamically customizable operations for regular files
12350 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12353 + * How large will these lists be?
12354 + * Usually just a few elements, 20-30 at most for each, I guess.
12356 +static struct hlist_bl_head dynop[AuDyLast];
12358 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12359 + const void *h_op)
12361 + struct au_dykey *key, *tmp;
12362 + struct hlist_bl_node *pos;
12365 + hlist_bl_lock(hbl);
12366 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12367 + if (tmp->dk_op.dy_hop == h_op) {
12368 + if (kref_get_unless_zero(&tmp->dk_kref))
12372 + hlist_bl_unlock(hbl);
12377 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12379 + struct au_dykey **k, *found;
12380 + const void *h_op = key->dk_op.dy_hop;
12384 + k = br->br_dykey;
12385 + for (i = 0; i < AuBrDynOp; i++)
12387 + if (k[i]->dk_op.dy_hop == h_op) {
12394 + spin_lock(&br->br_dykey_lock);
12395 + for (; i < AuBrDynOp; i++)
12397 + if (k[i]->dk_op.dy_hop == h_op) {
12405 + spin_unlock(&br->br_dykey_lock);
12406 + BUG_ON(i == AuBrDynOp); /* expand the array */
12412 +/* kref_get() if @key is already added */
12413 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12415 + struct au_dykey *tmp, *found;
12416 + struct hlist_bl_node *pos;
12417 + const void *h_op = key->dk_op.dy_hop;
12420 + hlist_bl_lock(hbl);
12421 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12422 + if (tmp->dk_op.dy_hop == h_op) {
12423 + if (kref_get_unless_zero(&tmp->dk_kref))
12428 + hlist_bl_add_head(&key->dk_hnode, hbl);
12429 + hlist_bl_unlock(hbl);
12436 +static void dy_free_rcu(struct rcu_head *rcu)
12438 + struct au_dykey *key;
12440 + key = container_of(rcu, struct au_dykey, dk_rcu);
12445 +static void dy_free(struct kref *kref)
12447 + struct au_dykey *key;
12448 + struct hlist_bl_head *hbl;
12450 + key = container_of(kref, struct au_dykey, dk_kref);
12451 + hbl = dynop + key->dk_op.dy_type;
12452 + au_hbl_del(&key->dk_hnode, hbl);
12453 + call_rcu(&key->dk_rcu, dy_free_rcu);
12456 +void au_dy_put(struct au_dykey *key)
12458 + kref_put(&key->dk_kref, dy_free);
12461 +/* ---------------------------------------------------------------------- */
12463 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12465 +#ifdef CONFIG_AUFS_DEBUG
12466 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12467 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12469 +#define DyDbgDeclare(cnt) do {} while (0)
12470 +#define DyDbgInc(cnt) do {} while (0)
12473 +#define DySet(func, dst, src, h_op, h_sb) do { \
12475 + if (h_op->func) { \
12477 + dst.func = src.func; \
12479 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12483 +#define DySetForce(func, dst, src) do { \
12484 + AuDebugOn(!src.func); \
12486 + dst.func = src.func; \
12489 +#define DySetAop(func) \
12490 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12491 +#define DySetAopForce(func) \
12492 + DySetForce(func, dyaop->da_op, aufs_aop)
12494 +static void dy_aop(struct au_dykey *key, const void *h_op,
12495 + struct super_block *h_sb __maybe_unused)
12497 + struct au_dyaop *dyaop = (void *)key;
12498 + const struct address_space_operations *h_aop = h_op;
12499 + DyDbgDeclare(cnt);
12501 + AuDbg("%s\n", au_sbtype(h_sb));
12503 + DySetAop(writepage);
12504 + DySetAopForce(readpage); /* force */
12505 + DySetAop(writepages);
12506 + DySetAop(set_page_dirty);
12507 + DySetAop(readpages);
12508 + DySetAop(readahead);
12509 + DySetAop(write_begin);
12510 + DySetAop(write_end);
12512 + DySetAop(invalidatepage);
12513 + DySetAop(releasepage);
12514 + DySetAop(freepage);
12515 + /* this one will be changed according to an aufs mount option */
12516 + DySetAop(direct_IO);
12517 + DySetAop(migratepage);
12518 + DySetAop(isolate_page);
12519 + DySetAop(putback_page);
12520 + DySetAop(launder_page);
12521 + DySetAop(is_partially_uptodate);
12522 + DySetAop(is_dirty_writeback);
12523 + DySetAop(error_remove_page);
12524 + DySetAop(swap_activate);
12525 + DySetAop(swap_deactivate);
12527 + DyDbgSize(cnt, *h_aop);
12530 +/* ---------------------------------------------------------------------- */
12532 +static void dy_bug(struct kref *kref)
12537 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12539 + struct au_dykey *key, *old;
12540 + struct hlist_bl_head *hbl;
12543 + void (*set)(struct au_dykey *key, const void *h_op,
12544 + struct super_block *h_sb __maybe_unused);
12546 + static const struct op a[] = {
12548 + .sz = sizeof(struct au_dyaop),
12552 + const struct op *p;
12554 + hbl = dynop + op->dy_type;
12555 + key = dy_gfind_get(hbl, op->dy_hop);
12557 + goto out_add; /* success */
12559 + p = a + op->dy_type;
12560 + key = kzalloc(p->sz, GFP_NOFS);
12561 + if (unlikely(!key)) {
12562 + key = ERR_PTR(-ENOMEM);
12566 + key->dk_op.dy_hop = op->dy_hop;
12567 + kref_init(&key->dk_kref);
12568 + p->set(key, op->dy_hop, au_br_sb(br));
12569 + old = dy_gadd(hbl, key);
12571 + au_kfree_rcu(key);
12576 + old = dy_bradd(br, key);
12578 + /* its ref-count should never be zero here */
12579 + kref_put(&key->dk_kref, dy_bug);
12584 +/* ---------------------------------------------------------------------- */
12586 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12587 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12588 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12589 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12590 + * See the aufs manual in detail.
12592 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12595 + dyaop->da_op.direct_IO = NULL;
12597 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12600 +static struct au_dyaop *dy_aget(struct au_branch *br,
12601 + const struct address_space_operations *h_aop,
12604 + struct au_dyaop *dyaop;
12605 + struct au_dynop op;
12607 + op.dy_type = AuDy_AOP;
12608 + op.dy_haop = h_aop;
12609 + dyaop = (void *)dy_get(&op, br);
12610 + if (IS_ERR(dyaop))
12612 + dy_adx(dyaop, do_dx);
12618 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12619 + struct inode *h_inode)
12622 + struct super_block *sb;
12623 + struct au_branch *br;
12624 + struct au_dyaop *dyaop;
12626 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12627 + IiMustWriteLock(inode);
12629 + sb = inode->i_sb;
12630 + br = au_sbr(sb, bindex);
12631 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12632 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12633 + err = PTR_ERR(dyaop);
12634 + if (IS_ERR(dyaop))
12635 + /* unnecessary to call dy_fput() */
12639 + inode->i_mapping->a_ops = &dyaop->da_op;
12646 + * Is it safe to replace a_ops during the inode/file is in operation?
12647 + * Yes, I hope so.
12649 +int au_dy_irefresh(struct inode *inode)
12652 + aufs_bindex_t btop;
12653 + struct inode *h_inode;
12656 + if (S_ISREG(inode->i_mode)) {
12657 + btop = au_ibtop(inode);
12658 + h_inode = au_h_iptr(inode, btop);
12659 + err = au_dy_iaop(inode, btop, h_inode);
12664 +void au_dy_arefresh(int do_dx)
12666 + struct hlist_bl_head *hbl;
12667 + struct hlist_bl_node *pos;
12668 + struct au_dykey *key;
12670 + hbl = dynop + AuDy_AOP;
12671 + hlist_bl_lock(hbl);
12672 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12673 + dy_adx((void *)key, do_dx);
12674 + hlist_bl_unlock(hbl);
12677 +/* ---------------------------------------------------------------------- */
12679 +void __init au_dy_init(void)
12683 + for (i = 0; i < AuDyLast; i++)
12684 + INIT_HLIST_BL_HEAD(dynop + i);
12687 +void au_dy_fin(void)
12691 + for (i = 0; i < AuDyLast; i++)
12692 + WARN_ON(!hlist_bl_empty(dynop + i));
12694 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12695 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12696 +++ linux/fs/aufs/dynop.h 2021-02-24 13:33:42.744347058 +0100
12698 +/* SPDX-License-Identifier: GPL-2.0 */
12700 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12702 + * This program, aufs is free software; you can redistribute it and/or modify
12703 + * it under the terms of the GNU General Public License as published by
12704 + * the Free Software Foundation; either version 2 of the License, or
12705 + * (at your option) any later version.
12707 + * This program is distributed in the hope that it will be useful,
12708 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12709 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12710 + * GNU General Public License for more details.
12712 + * You should have received a copy of the GNU General Public License
12713 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12717 + * dynamically customizable operations (for regular files only)
12720 +#ifndef __AUFS_DYNOP_H__
12721 +#define __AUFS_DYNOP_H__
12725 +#include <linux/fs.h>
12726 +#include <linux/kref.h>
12728 +enum {AuDy_AOP, AuDyLast};
12733 + const void *dy_hop;
12734 + const struct address_space_operations *dy_haop;
12740 + struct hlist_bl_node dk_hnode;
12741 + struct rcu_head dk_rcu;
12743 + struct au_dynop dk_op;
12746 + * during I am in the branch local array, kref is gotten. when the
12747 + * branch is removed, kref is put.
12749 + struct kref dk_kref;
12752 +/* stop unioning since their sizes are very different from each other */
12754 + struct au_dykey da_key;
12755 + struct address_space_operations da_op; /* not const */
12757 +/* make sure that 'struct au_dykey *' can be any type */
12758 +static_assert(!offsetof(struct au_dyaop, da_key));
12760 +/* ---------------------------------------------------------------------- */
12764 +void au_dy_put(struct au_dykey *key);
12765 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12766 + struct inode *h_inode);
12767 +int au_dy_irefresh(struct inode *inode);
12768 +void au_dy_arefresh(int do_dio);
12770 +void __init au_dy_init(void);
12771 +void au_dy_fin(void);
12773 +#endif /* __KERNEL__ */
12774 +#endif /* __AUFS_DYNOP_H__ */
12775 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12776 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12777 +++ linux/fs/aufs/export.c 2021-02-24 13:33:42.744347058 +0100
12779 +// SPDX-License-Identifier: GPL-2.0
12781 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12783 + * This program, aufs is free software; you can redistribute it and/or modify
12784 + * it under the terms of the GNU General Public License as published by
12785 + * the Free Software Foundation; either version 2 of the License, or
12786 + * (at your option) any later version.
12788 + * This program is distributed in the hope that it will be useful,
12789 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12790 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12791 + * GNU General Public License for more details.
12793 + * You should have received a copy of the GNU General Public License
12794 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12801 +#include <linux/exportfs.h>
12802 +#include <linux/fs_struct.h>
12803 +#include <linux/namei.h>
12804 +#include <linux/nsproxy.h>
12805 +#include <linux/random.h>
12806 +#include <linux/writeback.h>
12810 +#ifdef CONFIG_AUFS_INO_T_64
12818 +static ino_t decode_ino(__u32 *a)
12822 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12824 +#ifdef CONFIG_AUFS_INO_T_64
12830 +static void encode_ino(__u32 *a, ino_t ino)
12836 +#ifdef CONFIG_AUFS_INO_T_64
12841 +/* NFS file handle */
12845 +#ifdef CONFIG_AUFS_INO_T_64
12846 + /* support 64bit inode number */
12859 + Fh_ino = Fh_ino1,
12860 + Fh_dir_ino = Fh_dir_ino1
12863 +static int au_test_anon(struct dentry *dentry)
12865 + /* note: read d_flags without d_lock */
12866 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12869 +int au_test_nfsd(void)
12872 + struct task_struct *tsk = current;
12873 + char comm[sizeof(tsk->comm)];
12876 + if (tsk->flags & PF_KTHREAD) {
12877 + get_task_comm(comm, tsk);
12878 + ret = !strcmp(comm, "nfsd");
12884 +/* ---------------------------------------------------------------------- */
12885 +/* inode generation external table */
12887 +void au_xigen_inc(struct inode *inode)
12892 + struct super_block *sb;
12893 + struct au_sbinfo *sbinfo;
12895 + sb = inode->i_sb;
12896 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12898 + sbinfo = au_sbi(sb);
12899 + pos = inode->i_ino;
12900 + pos *= sizeof(igen);
12901 + igen = inode->i_generation + 1;
12902 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12903 + if (sz == sizeof(igen))
12904 + return; /* success */
12906 + if (unlikely(sz >= 0))
12907 + AuIOErr("xigen error (%zd)\n", sz);
12910 +int au_xigen_new(struct inode *inode)
12915 + struct super_block *sb;
12916 + struct au_sbinfo *sbinfo;
12917 + struct file *file;
12920 + /* todo: dirty, at mount time */
12921 + if (inode->i_ino == AUFS_ROOT_INO)
12923 + sb = inode->i_sb;
12924 + SiMustAnyLock(sb);
12925 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12929 + pos = inode->i_ino;
12930 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12931 + AuIOErr1("too large i%lld\n", pos);
12934 + pos *= sizeof(inode->i_generation);
12937 + sbinfo = au_sbi(sb);
12938 + file = sbinfo->si_xigen;
12941 + if (vfsub_f_size_read(file)
12942 + < pos + sizeof(inode->i_generation)) {
12943 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12944 + sz = xino_fwrite(file, &inode->i_generation,
12945 + sizeof(inode->i_generation), &pos);
12947 + sz = xino_fread(file, &inode->i_generation,
12948 + sizeof(inode->i_generation), &pos);
12949 + if (sz == sizeof(inode->i_generation))
12950 + goto out; /* success */
12953 + if (unlikely(sz >= 0)) {
12955 + AuIOErr("xigen error (%zd)\n", sz);
12962 +int au_xigen_set(struct super_block *sb, struct path *path)
12965 + struct au_sbinfo *sbinfo;
12966 + struct file *file;
12968 + SiMustWriteLock(sb);
12970 + sbinfo = au_sbi(sb);
12971 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12972 + err = PTR_ERR(file);
12973 + if (IS_ERR(file))
12976 + if (sbinfo->si_xigen)
12977 + fput(sbinfo->si_xigen);
12978 + sbinfo->si_xigen = file;
12985 +void au_xigen_clr(struct super_block *sb)
12987 + struct au_sbinfo *sbinfo;
12989 + SiMustWriteLock(sb);
12991 + sbinfo = au_sbi(sb);
12992 + if (sbinfo->si_xigen) {
12993 + fput(sbinfo->si_xigen);
12994 + sbinfo->si_xigen = NULL;
12998 +/* ---------------------------------------------------------------------- */
13000 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13003 + struct dentry *dentry, *d;
13004 + struct inode *inode;
13005 + unsigned int sigen;
13008 + inode = ilookup(sb, ino);
13012 + dentry = ERR_PTR(-ESTALE);
13013 + sigen = au_sigen(sb);
13014 + if (unlikely(au_is_bad_inode(inode)
13015 + || IS_DEADDIR(inode)
13016 + || sigen != au_iigen(inode, NULL)))
13020 + if (!dir_ino || S_ISDIR(inode->i_mode))
13021 + dentry = d_find_alias(inode);
13023 + spin_lock(&inode->i_lock);
13024 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13025 + spin_lock(&d->d_lock);
13026 + if (!au_test_anon(d)
13027 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13028 + dentry = dget_dlock(d);
13029 + spin_unlock(&d->d_lock);
13032 + spin_unlock(&d->d_lock);
13034 + spin_unlock(&inode->i_lock);
13036 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13037 + /* need to refresh */
13045 + AuTraceErrPtr(dentry);
13049 +/* ---------------------------------------------------------------------- */
13051 +/* todo: dirty? */
13052 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13054 +struct au_compare_mnt_args {
13056 + struct super_block *sb;
13059 + struct vfsmount *mnt;
13062 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13064 + struct au_compare_mnt_args *a = arg;
13066 + if (mnt->mnt_sb != a->sb)
13068 + a->mnt = mntget(mnt);
13072 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13075 + struct path root;
13076 + struct au_compare_mnt_args args = {
13080 + get_fs_root(current->fs, &root);
13082 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13083 + rcu_read_unlock();
13086 + AuDebugOn(!args.mnt);
13090 +struct au_nfsd_si_lock {
13091 + unsigned int sigen;
13092 + aufs_bindex_t bindex, br_id;
13093 + unsigned char force_lock;
13096 +static int si_nfsd_read_lock(struct super_block *sb,
13097 + struct au_nfsd_si_lock *nsi_lock)
13100 + aufs_bindex_t bindex;
13102 + si_read_lock(sb, AuLock_FLUSH);
13104 + /* branch id may be wrapped around */
13106 + bindex = au_br_index(sb, nsi_lock->br_id);
13107 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13108 + goto out; /* success */
13112 + if (!nsi_lock->force_lock)
13113 + si_read_unlock(sb);
13116 + nsi_lock->bindex = bindex;
13120 +struct find_name_by_ino {
13121 + struct dir_context ctx;
13122 + int called, found;
13129 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13130 + loff_t offset, u64 ino, unsigned int d_type)
13132 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13136 + if (a->ino != ino)
13139 + memcpy(a->name, name, namelen);
13140 + a->namelen = namelen;
13145 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13146 + struct au_nfsd_si_lock *nsi_lock)
13148 + struct dentry *dentry, *parent;
13149 + struct file *file;
13150 + struct inode *dir;
13151 + struct find_name_by_ino arg = {
13153 + .actor = find_name_by_ino
13158 + parent = path->dentry;
13160 + si_read_unlock(parent->d_sb);
13161 + file = vfsub_dentry_open(path, au_dir_roflags);
13162 + dentry = (void *)file;
13163 + if (IS_ERR(file))
13166 + dentry = ERR_PTR(-ENOMEM);
13167 + arg.name = (void *)__get_free_page(GFP_NOFS);
13168 + if (unlikely(!arg.name))
13175 + err = vfsub_iterate_dir(file, &arg.ctx);
13176 + } while (!err && !arg.found && arg.called);
13177 + dentry = ERR_PTR(err);
13178 + if (unlikely(err))
13180 + /* instead of ENOENT */
13181 + dentry = ERR_PTR(-ESTALE);
13185 + /* do not call vfsub_lkup_one() */
13186 + dir = d_inode(parent);
13187 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13188 + AuTraceErrPtr(dentry);
13189 + if (IS_ERR(dentry))
13191 + AuDebugOn(au_test_anon(dentry));
13192 + if (unlikely(d_really_is_negative(dentry))) {
13194 + dentry = ERR_PTR(-ENOENT);
13198 + free_page((unsigned long)arg.name);
13202 + if (unlikely(nsi_lock
13203 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13204 + if (!IS_ERR(dentry)) {
13206 + dentry = ERR_PTR(-ESTALE);
13208 + AuTraceErrPtr(dentry);
13212 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13214 + struct au_nfsd_si_lock *nsi_lock)
13216 + struct dentry *dentry;
13217 + struct path path;
13219 + if (dir_ino != AUFS_ROOT_INO) {
13220 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13221 + dentry = path.dentry;
13222 + if (!path.dentry || IS_ERR(path.dentry))
13224 + AuDebugOn(au_test_anon(path.dentry));
13226 + path.dentry = dget(sb->s_root);
13228 + path.mnt = au_mnt_get(sb);
13229 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13233 + AuTraceErrPtr(dentry);
13237 +/* ---------------------------------------------------------------------- */
13239 +static int h_acceptable(void *expv, struct dentry *dentry)
13244 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13245 + char *buf, int len, struct super_block *sb)
13249 + struct path path;
13251 + p = d_path(h_rootpath, buf, len);
13256 + path.mnt = h_rootpath->mnt;
13257 + path.dentry = h_parent;
13258 + p = d_path(&path, buf, len);
13264 + path.mnt = au_mnt_get(sb);
13265 + path.dentry = sb->s_root;
13266 + p = d_path(&path, buf, len - strlen(p));
13267 + mntput(path.mnt);
13271 + p[strlen(p)] = '/';
13274 + AuTraceErrPtr(p);
13279 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13280 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13282 + struct dentry *dentry, *h_parent, *root;
13283 + struct super_block *h_sb;
13284 + char *pathname, *p;
13285 + struct vfsmount *h_mnt;
13286 + struct au_branch *br;
13288 + struct path path;
13290 + br = au_sbr(sb, nsi_lock->bindex);
13291 + h_mnt = au_br_mnt(br);
13292 + h_sb = h_mnt->mnt_sb;
13293 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13295 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13296 + fh_len - Fh_tail, fh[Fh_h_type],
13297 + h_acceptable, /*context*/NULL);
13299 + dentry = h_parent;
13300 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13301 + AuWarn1("%s decode_fh failed, %ld\n",
13302 + au_sbtype(h_sb), PTR_ERR(h_parent));
13306 + if (unlikely(au_test_anon(h_parent))) {
13307 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13308 + au_sbtype(h_sb));
13309 + goto out_h_parent;
13312 + dentry = ERR_PTR(-ENOMEM);
13313 + pathname = (void *)__get_free_page(GFP_NOFS);
13314 + if (unlikely(!pathname))
13315 + goto out_h_parent;
13317 + root = sb->s_root;
13318 + path.mnt = h_mnt;
13319 + di_read_lock_parent(root, !AuLock_IR);
13320 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13321 + di_read_unlock(root, !AuLock_IR);
13322 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13323 + dentry = (void *)p;
13325 + goto out_pathname;
13327 + si_read_unlock(sb);
13328 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13329 + dentry = ERR_PTR(err);
13330 + if (unlikely(err))
13333 + dentry = ERR_PTR(-ENOENT);
13334 + AuDebugOn(au_test_anon(path.dentry));
13335 + if (unlikely(d_really_is_negative(path.dentry)))
13338 + if (ino != d_inode(path.dentry)->i_ino)
13339 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13341 + dentry = dget(path.dentry);
13346 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13347 + if (!IS_ERR(dentry)) {
13349 + dentry = ERR_PTR(-ESTALE);
13352 + free_page((unsigned long)pathname);
13356 + AuTraceErrPtr(dentry);
13360 +/* ---------------------------------------------------------------------- */
13362 +static struct dentry *
13363 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13366 + struct dentry *dentry;
13367 + __u32 *fh = fid->raw;
13368 + struct au_branch *br;
13369 + ino_t ino, dir_ino;
13370 + struct au_nfsd_si_lock nsi_lock = {
13374 + dentry = ERR_PTR(-ESTALE);
13375 + /* it should never happen, but the file handle is unreliable */
13376 + if (unlikely(fh_len < Fh_tail))
13378 + nsi_lock.sigen = fh[Fh_sigen];
13379 + nsi_lock.br_id = fh[Fh_br_id];
13381 + /* branch id may be wrapped around */
13383 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13385 + nsi_lock.force_lock = 1;
13387 + /* is this inode still cached? */
13388 + ino = decode_ino(fh + Fh_ino);
13389 + /* it should never happen */
13390 + if (unlikely(ino == AUFS_ROOT_INO))
13393 + dir_ino = decode_ino(fh + Fh_dir_ino);
13394 + dentry = decode_by_ino(sb, ino, dir_ino);
13395 + if (IS_ERR(dentry))
13400 + /* is the parent dir cached? */
13401 + br = au_sbr(sb, nsi_lock.bindex);
13402 + au_lcnt_inc(&br->br_nfiles);
13403 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13404 + if (IS_ERR(dentry))
13409 + /* lookup path */
13410 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13411 + if (IS_ERR(dentry))
13413 + if (unlikely(!dentry))
13414 + /* todo?: make it ESTALE */
13418 + if (!au_digen_test(dentry, au_sigen(sb))
13419 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13420 + goto out_unlock; /* success */
13423 + dentry = ERR_PTR(-ESTALE);
13426 + au_lcnt_dec(&br->br_nfiles);
13427 + si_read_unlock(sb);
13429 + AuTraceErrPtr(dentry);
13433 +#if 0 /* reserved for future use */
13434 +/* support subtreecheck option */
13435 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13436 + int fh_len, int fh_type)
13438 + struct dentry *parent;
13439 + __u32 *fh = fid->raw;
13442 + dir_ino = decode_ino(fh + Fh_dir_ino);
13443 + parent = decode_by_ino(sb, dir_ino, 0);
13444 + if (IS_ERR(parent))
13447 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13448 + dir_ino, fh, fh_len);
13451 + AuTraceErrPtr(parent);
13456 +/* ---------------------------------------------------------------------- */
13458 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13459 + struct inode *dir)
13462 + aufs_bindex_t bindex;
13463 + struct super_block *sb, *h_sb;
13464 + struct dentry *dentry, *parent, *h_parent;
13465 + struct inode *h_dir;
13466 + struct au_branch *br;
13469 + if (unlikely(*max_len <= Fh_tail)) {
13470 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13474 + err = FILEID_ROOT;
13475 + if (inode->i_ino == AUFS_ROOT_INO) {
13476 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13481 + sb = inode->i_sb;
13482 + err = si_read_lock(sb, AuLock_FLUSH);
13483 + if (unlikely(err))
13486 +#ifdef CONFIG_AUFS_DEBUG
13487 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13488 + AuWarn1("NFS-exporting requires xino\n");
13492 + ii_read_lock_child(inode);
13493 + bindex = au_ibtop(inode);
13495 + dentry = d_find_any_alias(inode);
13496 + if (unlikely(!dentry))
13498 + AuDebugOn(au_test_anon(dentry));
13499 + parent = dget_parent(dentry);
13501 + if (unlikely(!parent))
13503 + if (d_really_is_positive(parent))
13504 + dir = d_inode(parent);
13507 + ii_read_lock_parent(dir);
13508 + h_dir = au_h_iptr(dir, bindex);
13509 + ii_read_unlock(dir);
13510 + if (unlikely(!h_dir))
13512 + h_parent = d_find_any_alias(h_dir);
13513 + if (unlikely(!h_parent))
13514 + goto out_hparent;
13517 + br = au_sbr(sb, bindex);
13518 + h_sb = au_br_sb(br);
13519 + if (unlikely(!h_sb->s_export_op)) {
13520 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13521 + goto out_hparent;
13524 + fh[Fh_br_id] = br->br_id;
13525 + fh[Fh_sigen] = au_sigen(sb);
13526 + encode_ino(fh + Fh_ino, inode->i_ino);
13527 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13528 + fh[Fh_igen] = inode->i_generation;
13530 + *max_len -= Fh_tail;
13531 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13533 + /*connectable or subtreecheck*/0);
13534 + err = fh[Fh_h_type];
13535 + *max_len += Fh_tail;
13536 + /* todo: macros? */
13537 + if (err != FILEID_INVALID)
13540 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13547 + ii_read_unlock(inode);
13548 + si_read_unlock(sb);
13550 + if (unlikely(err < 0))
13551 + err = FILEID_INVALID;
13555 +/* ---------------------------------------------------------------------- */
13557 +static int aufs_commit_metadata(struct inode *inode)
13560 + aufs_bindex_t bindex;
13561 + struct super_block *sb;
13562 + struct inode *h_inode;
13563 + int (*f)(struct inode *inode);
13565 + sb = inode->i_sb;
13566 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13567 + ii_write_lock_child(inode);
13568 + bindex = au_ibtop(inode);
13569 + AuDebugOn(bindex < 0);
13570 + h_inode = au_h_iptr(inode, bindex);
13572 + f = h_inode->i_sb->s_export_op->commit_metadata;
13574 + err = f(h_inode);
13576 + struct writeback_control wbc = {
13577 + .sync_mode = WB_SYNC_ALL,
13578 + .nr_to_write = 0 /* metadata only */
13581 + err = sync_inode(h_inode, &wbc);
13584 + au_cpup_attr_timesizes(inode);
13585 + ii_write_unlock(inode);
13586 + si_read_unlock(sb);
13590 +/* ---------------------------------------------------------------------- */
13592 +static struct export_operations aufs_export_op = {
13593 + .fh_to_dentry = aufs_fh_to_dentry,
13594 + /* .fh_to_parent = aufs_fh_to_parent, */
13595 + .encode_fh = aufs_encode_fh,
13596 + .commit_metadata = aufs_commit_metadata
13599 +void au_export_init(struct super_block *sb)
13601 + struct au_sbinfo *sbinfo;
13604 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13605 + && IS_MODULE(CONFIG_EXPORTFS),
13606 + AUFS_NAME ": unsupported configuration "
13607 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13609 + sb->s_export_op = &aufs_export_op;
13610 + sbinfo = au_sbi(sb);
13611 + sbinfo->si_xigen = NULL;
13612 + get_random_bytes(&u, sizeof(u));
13613 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13614 + atomic_set(&sbinfo->si_xigen_next, u);
13616 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13617 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13618 +++ linux/fs/aufs/fhsm.c 2021-02-24 13:33:42.744347058 +0100
13620 +// SPDX-License-Identifier: GPL-2.0
13622 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13624 + * This program, aufs is free software; you can redistribute it and/or modify
13625 + * it under the terms of the GNU General Public License as published by
13626 + * the Free Software Foundation; either version 2 of the License, or
13627 + * (at your option) any later version.
13629 + * This program is distributed in the hope that it will be useful,
13630 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13631 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13632 + * GNU General Public License for more details.
13634 + * You should have received a copy of the GNU General Public License
13635 + * along with this program; if not, write to the Free Software
13636 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13640 + * File-based Hierarchy Storage Management
13643 +#include <linux/anon_inodes.h>
13644 +#include <linux/poll.h>
13645 +#include <linux/seq_file.h>
13646 +#include <linux/statfs.h>
13649 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13651 + struct au_sbinfo *sbinfo;
13652 + struct au_fhsm *fhsm;
13654 + SiMustAnyLock(sb);
13656 + sbinfo = au_sbi(sb);
13657 + fhsm = &sbinfo->si_fhsm;
13658 + AuDebugOn(!fhsm);
13659 + return fhsm->fhsm_bottom;
13662 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13664 + struct au_sbinfo *sbinfo;
13665 + struct au_fhsm *fhsm;
13667 + SiMustWriteLock(sb);
13669 + sbinfo = au_sbi(sb);
13670 + fhsm = &sbinfo->si_fhsm;
13671 + AuDebugOn(!fhsm);
13672 + fhsm->fhsm_bottom = bindex;
13675 +/* ---------------------------------------------------------------------- */
13677 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13679 + struct au_br_fhsm *bf;
13681 + bf = br->br_fhsm;
13682 + MtxMustLock(&bf->bf_lock);
13684 + return !bf->bf_readable
13685 + || time_after(jiffies,
13686 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13689 +/* ---------------------------------------------------------------------- */
13691 +static void au_fhsm_notify(struct super_block *sb, int val)
13693 + struct au_sbinfo *sbinfo;
13694 + struct au_fhsm *fhsm;
13696 + SiMustAnyLock(sb);
13698 + sbinfo = au_sbi(sb);
13699 + fhsm = &sbinfo->si_fhsm;
13700 + if (au_fhsm_pid(fhsm)
13701 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13702 + atomic_set(&fhsm->fhsm_readable, val);
13704 + wake_up(&fhsm->fhsm_wqh);
13708 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13709 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13712 + struct au_branch *br;
13713 + struct au_br_fhsm *bf;
13715 + br = au_sbr(sb, bindex);
13716 + AuDebugOn(au_br_rdonly(br));
13717 + bf = br->br_fhsm;
13721 + mutex_lock(&bf->bf_lock);
13723 + MtxMustLock(&bf->bf_lock);
13725 + /* sb->s_root for NFS is unreliable */
13726 + err = au_br_stfs(br, &bf->bf_stfs);
13727 + if (unlikely(err)) {
13728 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13732 + bf->bf_jiffy = jiffies;
13733 + bf->bf_readable = 1;
13735 + au_fhsm_notify(sb, /*val*/1);
13737 + *rstfs = bf->bf_stfs;
13741 + mutex_unlock(&bf->bf_lock);
13742 + au_fhsm_notify(sb, /*val*/1);
13747 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13750 + struct au_sbinfo *sbinfo;
13751 + struct au_fhsm *fhsm;
13752 + struct au_branch *br;
13753 + struct au_br_fhsm *bf;
13755 + AuDbg("b%d, force %d\n", bindex, force);
13756 + SiMustAnyLock(sb);
13758 + sbinfo = au_sbi(sb);
13759 + fhsm = &sbinfo->si_fhsm;
13760 + if (!au_ftest_si(sbinfo, FHSM)
13761 + || fhsm->fhsm_bottom == bindex)
13764 + br = au_sbr(sb, bindex);
13765 + bf = br->br_fhsm;
13767 + mutex_lock(&bf->bf_lock);
13769 + || au_fhsm_pid(fhsm)
13770 + || au_fhsm_test_jiffy(sbinfo, br))
13771 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13773 + mutex_unlock(&bf->bf_lock);
13776 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13778 + aufs_bindex_t bindex, bbot;
13779 + struct au_branch *br;
13781 + /* exclude the bottom */
13782 + bbot = au_fhsm_bottom(sb);
13783 + for (bindex = 0; bindex < bbot; bindex++) {
13784 + br = au_sbr(sb, bindex);
13785 + if (au_br_fhsm(br->br_perm))
13786 + au_fhsm_wrote(sb, bindex, force);
13790 +/* ---------------------------------------------------------------------- */
13792 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13795 + struct au_sbinfo *sbinfo;
13796 + struct au_fhsm *fhsm;
13799 + sbinfo = file->private_data;
13800 + fhsm = &sbinfo->si_fhsm;
13801 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13802 + if (atomic_read(&fhsm->fhsm_readable))
13803 + mask = EPOLLIN /* | EPOLLRDNORM */;
13806 + AuDbg("mask 0x%x\n", mask);
13810 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13811 + struct aufs_stfs *stfs, __s16 brid)
13815 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13817 + err = __put_user(brid, &stbr->brid);
13818 + if (unlikely(err))
13824 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13825 + struct aufs_stbr __user *stbr, size_t count)
13829 + aufs_bindex_t bindex, bbot;
13830 + struct au_branch *br;
13831 + struct au_br_fhsm *bf;
13833 + /* except the bottom branch */
13836 + bbot = au_fhsm_bottom(sb);
13837 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13838 + br = au_sbr(sb, bindex);
13839 + if (!au_br_fhsm(br->br_perm))
13842 + bf = br->br_fhsm;
13843 + mutex_lock(&bf->bf_lock);
13844 + if (bf->bf_readable) {
13846 + if (count >= sizeof(*stbr))
13847 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13850 + bf->bf_readable = 0;
13851 + count -= sizeof(*stbr);
13855 + mutex_unlock(&bf->bf_lock);
13858 + err = sizeof(*stbr) * nstbr;
13863 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13868 + aufs_bindex_t nfhsm, bindex, bbot;
13869 + struct au_sbinfo *sbinfo;
13870 + struct au_fhsm *fhsm;
13871 + struct au_branch *br;
13872 + struct super_block *sb;
13875 + sbinfo = file->private_data;
13876 + fhsm = &sbinfo->si_fhsm;
13878 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13879 + if (!atomic_read(&fhsm->fhsm_readable)) {
13880 + if (vfsub_file_flags(file) & O_NONBLOCK)
13883 + err = wait_event_interruptible_locked_irq
13885 + atomic_read(&fhsm->fhsm_readable));
13887 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13888 + if (unlikely(err))
13891 + /* sb may already be dead */
13892 + au_rw_read_lock(&sbinfo->si_rwsem);
13893 + readable = atomic_read(&fhsm->fhsm_readable);
13894 + if (readable > 0) {
13895 + sb = sbinfo->si_sb;
13897 + /* exclude the bottom branch */
13899 + bbot = au_fhsm_bottom(sb);
13900 + for (bindex = 0; bindex < bbot; bindex++) {
13901 + br = au_sbr(sb, bindex);
13902 + if (au_br_fhsm(br->br_perm))
13906 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13907 + atomic_set(&fhsm->fhsm_readable, 0);
13908 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13912 + au_rw_read_unlock(&sbinfo->si_rwsem);
13920 +static int au_fhsm_release(struct inode *inode, struct file *file)
13922 + struct au_sbinfo *sbinfo;
13923 + struct au_fhsm *fhsm;
13925 + /* sb may already be dead */
13926 + sbinfo = file->private_data;
13927 + fhsm = &sbinfo->si_fhsm;
13928 + spin_lock(&fhsm->fhsm_spin);
13929 + fhsm->fhsm_pid = 0;
13930 + spin_unlock(&fhsm->fhsm_spin);
13931 + kobject_put(&sbinfo->si_kobj);
13936 +static const struct file_operations au_fhsm_fops = {
13937 + .owner = THIS_MODULE,
13938 + .llseek = noop_llseek,
13939 + .read = au_fhsm_read,
13940 + .poll = au_fhsm_poll,
13941 + .release = au_fhsm_release
13944 +int au_fhsm_fd(struct super_block *sb, int oflags)
13947 + struct au_sbinfo *sbinfo;
13948 + struct au_fhsm *fhsm;
13951 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13955 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13959 + sbinfo = au_sbi(sb);
13960 + fhsm = &sbinfo->si_fhsm;
13961 + spin_lock(&fhsm->fhsm_spin);
13962 + if (!fhsm->fhsm_pid)
13963 + fhsm->fhsm_pid = current->pid;
13966 + spin_unlock(&fhsm->fhsm_spin);
13967 + if (unlikely(err))
13970 + oflags |= O_RDONLY;
13971 + /* oflags |= FMODE_NONOTIFY; */
13972 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13974 + if (unlikely(fd < 0))
13977 + /* succeed regardless 'fhsm' status */
13978 + kobject_get(&sbinfo->si_kobj);
13979 + si_noflush_read_lock(sb);
13980 + if (au_ftest_si(sbinfo, FHSM))
13981 + au_fhsm_wrote_all(sb, /*force*/0);
13982 + si_read_unlock(sb);
13983 + goto out; /* success */
13986 + spin_lock(&fhsm->fhsm_spin);
13987 + fhsm->fhsm_pid = 0;
13988 + spin_unlock(&fhsm->fhsm_spin);
13994 +/* ---------------------------------------------------------------------- */
13996 +int au_fhsm_br_alloc(struct au_branch *br)
14001 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14003 + au_br_fhsm_init(br->br_fhsm);
14010 +/* ---------------------------------------------------------------------- */
14012 +void au_fhsm_fin(struct super_block *sb)
14014 + au_fhsm_notify(sb, /*val*/-1);
14017 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14019 + struct au_fhsm *fhsm;
14021 + fhsm = &sbinfo->si_fhsm;
14022 + spin_lock_init(&fhsm->fhsm_spin);
14023 + init_waitqueue_head(&fhsm->fhsm_wqh);
14024 + atomic_set(&fhsm->fhsm_readable, 0);
14025 + fhsm->fhsm_expire
14026 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14027 + fhsm->fhsm_bottom = -1;
14030 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14032 + sbinfo->si_fhsm.fhsm_expire
14033 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14036 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14040 + if (!au_ftest_si(sbinfo, FHSM))
14043 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14044 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14045 + seq_printf(seq, ",fhsm_sec=%u", u);
14047 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14048 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14049 +++ linux/fs/aufs/file.c 2021-02-24 13:33:42.744347058 +0100
14051 +// SPDX-License-Identifier: GPL-2.0
14053 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14055 + * This program, aufs is free software; you can redistribute it and/or modify
14056 + * it under the terms of the GNU General Public License as published by
14057 + * the Free Software Foundation; either version 2 of the License, or
14058 + * (at your option) any later version.
14060 + * This program is distributed in the hope that it will be useful,
14061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14063 + * GNU General Public License for more details.
14065 + * You should have received a copy of the GNU General Public License
14066 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14070 + * handling file/dir, and address_space operation
14073 +#ifdef CONFIG_AUFS_DEBUG
14074 +#include <linux/migrate.h>
14076 +#include <linux/pagemap.h>
14079 +/* drop flags for writing */
14080 +unsigned int au_file_roflags(unsigned int flags)
14082 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14083 + flags |= O_RDONLY | O_NOATIME;
14087 +/* common functions to regular file and dir */
14088 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14089 + struct file *file, int force_wr)
14091 + struct file *h_file;
14092 + struct dentry *h_dentry;
14093 + struct inode *h_inode;
14094 + struct super_block *sb;
14095 + struct au_branch *br;
14096 + struct path h_path;
14099 + /* a race condition can happen between open and unlink/rmdir */
14100 + h_file = ERR_PTR(-ENOENT);
14101 + h_dentry = au_h_dptr(dentry, bindex);
14102 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14104 + h_inode = d_inode(h_dentry);
14105 + spin_lock(&h_dentry->d_lock);
14106 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14107 + /* || !d_inode(dentry)->i_nlink */
14109 + spin_unlock(&h_dentry->d_lock);
14110 + if (unlikely(err))
14113 + sb = dentry->d_sb;
14114 + br = au_sbr(sb, bindex);
14115 + err = au_br_test_oflag(flags, br);
14116 + h_file = ERR_PTR(err);
14117 + if (unlikely(err))
14120 + /* drop flags for writing */
14121 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14122 + if (force_wr && !(flags & O_WRONLY))
14124 + flags = au_file_roflags(flags);
14126 + h_file = ERR_PTR(-EROFS);
14127 + flags = au_file_roflags(flags);
14128 + if (unlikely(vfsub_native_ro(h_inode)
14129 + || IS_APPEND(h_inode)))
14131 + flags &= ~O_ACCMODE;
14132 + flags |= O_WRONLY;
14135 + flags &= ~O_CREAT;
14136 + au_lcnt_inc(&br->br_nfiles);
14137 + h_path.dentry = h_dentry;
14138 + h_path.mnt = au_br_mnt(br);
14139 + h_file = vfsub_dentry_open(&h_path, flags);
14140 + if (IS_ERR(h_file))
14143 + if (flags & __FMODE_EXEC) {
14144 + err = deny_write_access(h_file);
14145 + if (unlikely(err)) {
14147 + h_file = ERR_PTR(err);
14151 + fsnotify_open(h_file);
14152 + goto out; /* success */
14155 + au_lcnt_dec(&br->br_nfiles);
14160 +static int au_cmoo(struct dentry *dentry)
14162 + int err, cmoo, matched;
14163 + unsigned int udba;
14164 + struct path h_path;
14165 + struct au_pin pin;
14166 + struct au_cp_generic cpg = {
14167 + .dentry = dentry,
14172 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14174 + struct inode *delegated;
14175 + struct super_block *sb;
14176 + struct au_sbinfo *sbinfo;
14177 + struct au_fhsm *fhsm;
14179 + struct au_branch *br;
14180 + struct dentry *parent;
14181 + struct au_hinode *hdir;
14183 + DiMustWriteLock(dentry);
14184 + IiMustWriteLock(d_inode(dentry));
14187 + if (IS_ROOT(dentry))
14189 + cpg.bsrc = au_dbtop(dentry);
14193 + sb = dentry->d_sb;
14194 + sbinfo = au_sbi(sb);
14195 + fhsm = &sbinfo->si_fhsm;
14196 + pid = au_fhsm_pid(fhsm);
14199 + && (current->pid == pid
14200 + || rcu_dereference(current->real_parent)->pid == pid));
14201 + rcu_read_unlock();
14205 + br = au_sbr(sb, cpg.bsrc);
14206 + cmoo = au_br_cmoo(br->br_perm);
14209 + if (!d_is_reg(dentry))
14210 + cmoo &= AuBrAttr_COO_ALL;
14214 + parent = dget_parent(dentry);
14215 + di_write_lock_parent(parent);
14216 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14218 + if (unlikely(err < 0)) {
14219 + err = 0; /* there is no upper writable branch */
14222 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14224 + /* do not respect the coo attrib for the target branch */
14225 + err = au_cpup_dirs(dentry, cpg.bdst);
14226 + if (unlikely(err))
14229 + di_downgrade_lock(parent, AuLock_IR);
14230 + udba = au_opt_udba(sb);
14231 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14232 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14233 + if (unlikely(err))
14236 + err = au_sio_cpup_simple(&cpg);
14238 + if (unlikely(err))
14240 + if (!(cmoo & AuBrWAttr_MOO))
14241 + goto out_parent; /* success */
14243 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14244 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14245 + if (unlikely(err))
14248 + h_path.mnt = au_br_mnt(br);
14249 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14250 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14251 + delegated = NULL;
14252 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14254 + /* todo: keep h_dentry or not? */
14255 + if (unlikely(err == -EWOULDBLOCK)) {
14256 + pr_warn("cannot retry for NFSv4 delegation"
14257 + " for an internal unlink\n");
14260 + if (unlikely(err)) {
14261 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14265 + goto out_parent; /* success */
14268 + di_downgrade_lock(parent, AuLock_IR);
14270 + di_read_unlock(parent, AuLock_IR);
14277 +int au_do_open(struct file *file, struct au_do_open_args *args)
14279 + int err, aopen = args->aopen;
14280 + struct dentry *dentry;
14281 + struct au_finfo *finfo;
14284 + err = au_finfo_init(file, args->fidir);
14287 + err = au_finfo_init(file, args->fidir);
14290 + if (unlikely(err))
14293 + dentry = file->f_path.dentry;
14294 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14295 + di_write_lock_child(dentry);
14296 + err = au_cmoo(dentry);
14297 + di_downgrade_lock(dentry, AuLock_IR);
14300 + err = args->open(file, vfsub_file_flags(file), NULL);
14303 + err = args->open(file, vfsub_file_flags(file),
14308 + di_read_unlock(dentry, AuLock_IR);
14310 + finfo = au_fi(file);
14312 + finfo->fi_file = file;
14313 + au_hbl_add(&finfo->fi_hlist,
14314 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14317 + fi_write_unlock(file);
14320 + fi_write_unlock(file);
14323 + if (unlikely(err)) {
14324 + finfo->fi_hdir = NULL;
14325 + au_finfo_fin(file);
14333 +int au_reopen_nondir(struct file *file)
14336 + aufs_bindex_t btop;
14337 + struct dentry *dentry;
14338 + struct au_branch *br;
14339 + struct file *h_file, *h_file_tmp;
14341 + dentry = file->f_path.dentry;
14342 + btop = au_dbtop(dentry);
14343 + br = au_sbr(dentry->d_sb, btop);
14344 + h_file_tmp = NULL;
14345 + if (au_fbtop(file) == btop) {
14346 + h_file = au_hf_top(file);
14347 + if (file->f_mode == h_file->f_mode)
14348 + return 0; /* success */
14349 + h_file_tmp = h_file;
14350 + get_file(h_file_tmp);
14351 + au_lcnt_inc(&br->br_nfiles);
14352 + au_set_h_fptr(file, btop, NULL);
14354 + AuDebugOn(au_fi(file)->fi_hdir);
14357 + * file exists on both of rw and ro
14358 + * open --> dbtop and fbtop are both 0
14359 + * prepend a branch as rw, "rw" become ro
14361 + * delete the top branch, "rw" becomes rw again
14362 + * --> dbtop is 1, fbtop is still 0
14363 + * write --> fbtop is 0 but dbtop is 1
14365 + /* AuDebugOn(au_fbtop(file) < btop); */
14367 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14368 + file, /*force_wr*/0);
14369 + err = PTR_ERR(h_file);
14370 + if (IS_ERR(h_file)) {
14371 + if (h_file_tmp) {
14373 + au_set_h_fptr(file, btop, h_file_tmp);
14374 + h_file_tmp = NULL;
14376 + goto out; /* todo: close all? */
14380 + au_set_fbtop(file, btop);
14381 + au_set_h_fptr(file, btop, h_file);
14382 + au_update_figen(file);
14383 + /* todo: necessary? */
14384 + /* file->f_ra = h_file->f_ra; */
14387 + if (h_file_tmp) {
14388 + fput(h_file_tmp);
14389 + au_lcnt_dec(&br->br_nfiles);
14394 +/* ---------------------------------------------------------------------- */
14396 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14397 + struct dentry *hi_wh)
14400 + aufs_bindex_t btop;
14401 + struct au_dinfo *dinfo;
14402 + struct dentry *h_dentry;
14403 + struct au_hdentry *hdp;
14405 + dinfo = au_di(file->f_path.dentry);
14406 + AuRwMustWriteLock(&dinfo->di_rwsem);
14408 + btop = dinfo->di_btop;
14409 + dinfo->di_btop = btgt;
14410 + hdp = au_hdentry(dinfo, btgt);
14411 + h_dentry = hdp->hd_dentry;
14412 + hdp->hd_dentry = hi_wh;
14413 + err = au_reopen_nondir(file);
14414 + hdp->hd_dentry = h_dentry;
14415 + dinfo->di_btop = btop;
14420 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14421 + aufs_bindex_t bcpup, struct au_pin *pin)
14424 + struct inode *inode, *h_inode;
14425 + struct dentry *h_dentry, *hi_wh;
14426 + struct au_cp_generic cpg = {
14427 + .dentry = file->f_path.dentry,
14434 + au_update_dbtop(cpg.dentry);
14435 + inode = d_inode(cpg.dentry);
14437 + if (au_dbtop(cpg.dentry) <= bcpup
14438 + && au_dbbot(cpg.dentry) >= bcpup) {
14439 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14440 + if (h_dentry && d_is_positive(h_dentry))
14441 + h_inode = d_inode(h_dentry);
14443 + hi_wh = au_hi_wh(inode, bcpup);
14444 + if (!hi_wh && !h_inode)
14445 + err = au_sio_cpup_wh(&cpg, file);
14447 + /* already copied-up after unlink */
14448 + err = au_reopen_wh(file, bcpup, hi_wh);
14451 + && (inode->i_nlink > 1
14452 + || (inode->i_state & I_LINKABLE))
14453 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14454 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14460 + * prepare the @file for writing.
14462 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14465 + aufs_bindex_t dbtop;
14466 + struct dentry *parent;
14467 + struct inode *inode;
14468 + struct super_block *sb;
14469 + struct file *h_file;
14470 + struct au_cp_generic cpg = {
14471 + .dentry = file->f_path.dentry,
14476 + .flags = AuCpup_DTIME
14479 + sb = cpg.dentry->d_sb;
14480 + inode = d_inode(cpg.dentry);
14481 + cpg.bsrc = au_fbtop(file);
14482 + err = au_test_ro(sb, cpg.bsrc, inode);
14483 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14484 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14489 + /* need to cpup or reopen */
14490 + parent = dget_parent(cpg.dentry);
14491 + di_write_lock_parent(parent);
14492 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14494 + if (unlikely(err < 0))
14498 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14499 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14500 + if (unlikely(err))
14504 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14505 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14506 + if (unlikely(err))
14509 + dbtop = au_dbtop(cpg.dentry);
14510 + if (dbtop <= cpg.bdst)
14511 + cpg.bsrc = cpg.bdst;
14513 + if (dbtop <= cpg.bdst /* just reopen */
14514 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14516 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14517 + if (IS_ERR(h_file))
14518 + err = PTR_ERR(h_file);
14520 + di_downgrade_lock(parent, AuLock_IR);
14521 + if (dbtop > cpg.bdst)
14522 + err = au_sio_cpup_simple(&cpg);
14524 + err = au_reopen_nondir(file);
14525 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14527 + } else { /* copyup as wh and reopen */
14529 + * since writable hfsplus branch is not supported,
14530 + * h_open_pre/post() are unnecessary.
14532 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14533 + di_downgrade_lock(parent, AuLock_IR);
14537 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14538 + goto out_dput; /* success */
14544 + di_downgrade_lock(parent, AuLock_IR);
14546 + di_read_unlock(parent, AuLock_IR);
14553 +/* ---------------------------------------------------------------------- */
14555 +int au_do_flush(struct file *file, fl_owner_t id,
14556 + int (*flush)(struct file *file, fl_owner_t id))
14559 + struct super_block *sb;
14560 + struct inode *inode;
14562 + inode = file_inode(file);
14563 + sb = inode->i_sb;
14564 + si_noflush_read_lock(sb);
14565 + fi_read_lock(file);
14566 + ii_read_lock_child(inode);
14568 + err = flush(file, id);
14569 + au_cpup_attr_timesizes(inode);
14571 + ii_read_unlock(inode);
14572 + fi_read_unlock(file);
14573 + si_read_unlock(sb);
14577 +/* ---------------------------------------------------------------------- */
14579 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14582 + struct au_pin pin;
14583 + struct au_finfo *finfo;
14584 + struct dentry *parent, *hi_wh;
14585 + struct inode *inode;
14586 + struct super_block *sb;
14587 + struct au_cp_generic cpg = {
14588 + .dentry = file->f_path.dentry,
14593 + .flags = AuCpup_DTIME
14596 + FiMustWriteLock(file);
14599 + finfo = au_fi(file);
14600 + sb = cpg.dentry->d_sb;
14601 + inode = d_inode(cpg.dentry);
14602 + cpg.bdst = au_ibtop(inode);
14603 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14606 + parent = dget_parent(cpg.dentry);
14607 + if (au_test_ro(sb, cpg.bdst, inode)) {
14608 + di_read_lock_parent(parent, !AuLock_IR);
14609 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14611 + di_read_unlock(parent, !AuLock_IR);
14612 + if (unlikely(err < 0))
14617 + di_read_lock_parent(parent, AuLock_IR);
14618 + hi_wh = au_hi_wh(inode, cpg.bdst);
14619 + if (!S_ISDIR(inode->i_mode)
14620 + && au_opt_test(au_mntflags(sb), PLINK)
14621 + && au_plink_test(inode)
14622 + && !d_unhashed(cpg.dentry)
14623 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14624 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14625 + if (unlikely(err))
14628 + /* always superio. */
14629 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14630 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14632 + err = au_sio_cpup_simple(&cpg);
14635 + } else if (hi_wh) {
14636 + /* already copied-up after unlink */
14637 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14638 + *need_reopen = 0;
14642 + di_read_unlock(parent, AuLock_IR);
14649 +static void au_do_refresh_dir(struct file *file)
14651 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14652 + struct au_hfile *p, tmp, *q;
14653 + struct au_finfo *finfo;
14654 + struct super_block *sb;
14655 + struct au_fidir *fidir;
14657 + FiMustWriteLock(file);
14659 + sb = file->f_path.dentry->d_sb;
14660 + finfo = au_fi(file);
14661 + fidir = finfo->fi_hdir;
14662 + AuDebugOn(!fidir);
14663 + p = fidir->fd_hfile + finfo->fi_btop;
14664 + brid = p->hf_br->br_id;
14665 + bbot = fidir->fd_bbot;
14666 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14670 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14671 + if (new_bindex == bindex)
14673 + if (new_bindex < 0) {
14674 + au_set_h_fptr(file, bindex, NULL);
14678 + /* swap two lower inode, and loop again */
14679 + q = fidir->fd_hfile + new_bindex;
14683 + if (tmp.hf_file) {
14689 + p = fidir->fd_hfile;
14690 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14691 + bbot = au_sbbot(sb);
14692 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14693 + finfo->fi_btop++, p++)
14694 + if (p->hf_file) {
14695 + if (file_inode(p->hf_file))
14697 + au_hfput(p, /*execed*/0);
14700 + bbot = au_br_index(sb, brid);
14701 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14702 + finfo->fi_btop++, p++)
14704 + au_hfput(p, /*execed*/0);
14705 + bbot = au_sbbot(sb);
14708 + p = fidir->fd_hfile + bbot;
14709 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14710 + fidir->fd_bbot--, p--)
14711 + if (p->hf_file) {
14712 + if (file_inode(p->hf_file))
14714 + au_hfput(p, /*execed*/0);
14716 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14720 + * after branch manipulating, refresh the file.
14722 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14724 + int err, need_reopen, nbr;
14725 + aufs_bindex_t bbot, bindex;
14726 + struct dentry *dentry;
14727 + struct super_block *sb;
14728 + struct au_finfo *finfo;
14729 + struct au_hfile *hfile;
14731 + dentry = file->f_path.dentry;
14732 + sb = dentry->d_sb;
14733 + nbr = au_sbbot(sb) + 1;
14734 + finfo = au_fi(file);
14735 + if (!finfo->fi_hdir) {
14736 + hfile = &finfo->fi_htop;
14737 + AuDebugOn(!hfile->hf_file);
14738 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14739 + AuDebugOn(bindex < 0);
14740 + if (bindex != finfo->fi_btop)
14741 + au_set_fbtop(file, bindex);
14743 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14744 + if (unlikely(err))
14746 + au_do_refresh_dir(file);
14751 + if (!au_test_mmapped(file))
14752 + err = au_file_refresh_by_inode(file, &need_reopen);
14753 + if (finfo->fi_hdir)
14754 + /* harmless if err */
14755 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14756 + if (!err && need_reopen && !d_unlinked(dentry))
14757 + err = reopen(file);
14759 + au_update_figen(file);
14760 + goto out; /* success */
14763 + /* error, close all lower files */
14764 + if (finfo->fi_hdir) {
14765 + bbot = au_fbbot_dir(file);
14766 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14767 + au_set_h_fptr(file, bindex, NULL);
14774 +/* common function to regular file and dir */
14775 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14776 + int wlock, unsigned int fi_lsc)
14779 + unsigned int sigen, figen;
14780 + aufs_bindex_t btop;
14781 + unsigned char pseudo_link;
14782 + struct dentry *dentry;
14783 + struct inode *inode;
14786 + dentry = file->f_path.dentry;
14787 + inode = d_inode(dentry);
14788 + sigen = au_sigen(dentry->d_sb);
14789 + fi_write_lock_nested(file, fi_lsc);
14790 + figen = au_figen(file);
14792 + di_write_lock_child(dentry);
14794 + di_write_lock_child2(dentry);
14795 + btop = au_dbtop(dentry);
14796 + pseudo_link = (btop != au_ibtop(inode));
14797 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14799 + di_downgrade_lock(dentry, AuLock_IR);
14800 + fi_downgrade_lock(file);
14802 + goto out; /* success */
14805 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14806 + if (au_digen_test(dentry, sigen)) {
14807 + err = au_reval_dpath(dentry, sigen);
14808 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14812 + err = refresh_file(file, reopen);
14815 + di_downgrade_lock(dentry, AuLock_IR);
14816 + fi_downgrade_lock(file);
14819 + di_write_unlock(dentry);
14820 + fi_write_unlock(file);
14827 +/* ---------------------------------------------------------------------- */
14829 +/* cf. aufs_nopage() */
14830 +/* for madvise(2) */
14831 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14833 + unlock_page(page);
14837 +/* it will never be called, but necessary to support O_DIRECT */
14838 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14839 +{ BUG(); return 0; }
14841 +/* they will never be called. */
14842 +#ifdef CONFIG_AUFS_DEBUG
14843 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14844 + loff_t pos, unsigned len, unsigned flags,
14845 + struct page **pagep, void **fsdata)
14846 +{ AuUnsupport(); return 0; }
14847 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14848 + loff_t pos, unsigned len, unsigned copied,
14849 + struct page *page, void *fsdata)
14850 +{ AuUnsupport(); return 0; }
14851 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14852 +{ AuUnsupport(); return 0; }
14854 +static int aufs_set_page_dirty(struct page *page)
14855 +{ AuUnsupport(); return 0; }
14856 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14857 + unsigned int length)
14858 +{ AuUnsupport(); }
14859 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14860 +{ AuUnsupport(); return 0; }
14861 +#if 0 /* called by memory compaction regardless file */
14862 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14863 + struct page *page, enum migrate_mode mode)
14864 +{ AuUnsupport(); return 0; }
14866 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14867 +{ AuUnsupport(); return true; }
14868 +static void aufs_putback_page(struct page *page)
14869 +{ AuUnsupport(); }
14870 +static int aufs_launder_page(struct page *page)
14871 +{ AuUnsupport(); return 0; }
14872 +static int aufs_is_partially_uptodate(struct page *page,
14873 + unsigned long from,
14874 + unsigned long count)
14875 +{ AuUnsupport(); return 0; }
14876 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14878 +{ AuUnsupport(); }
14879 +static int aufs_error_remove_page(struct address_space *mapping,
14880 + struct page *page)
14881 +{ AuUnsupport(); return 0; }
14882 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14884 +{ AuUnsupport(); return 0; }
14885 +static void aufs_swap_deactivate(struct file *file)
14886 +{ AuUnsupport(); }
14887 +#endif /* CONFIG_AUFS_DEBUG */
14889 +const struct address_space_operations aufs_aop = {
14890 + .readpage = aufs_readpage,
14891 + .direct_IO = aufs_direct_IO,
14892 +#ifdef CONFIG_AUFS_DEBUG
14893 + .writepage = aufs_writepage,
14894 + /* no writepages, because of writepage */
14895 + .set_page_dirty = aufs_set_page_dirty,
14896 + /* no readpages, because of readpage */
14897 + .write_begin = aufs_write_begin,
14898 + .write_end = aufs_write_end,
14899 + /* no bmap, no block device */
14900 + .invalidatepage = aufs_invalidatepage,
14901 + .releasepage = aufs_releasepage,
14902 + /* is fallback_migrate_page ok? */
14903 + /* .migratepage = aufs_migratepage, */
14904 + .isolate_page = aufs_isolate_page,
14905 + .putback_page = aufs_putback_page,
14906 + .launder_page = aufs_launder_page,
14907 + .is_partially_uptodate = aufs_is_partially_uptodate,
14908 + .is_dirty_writeback = aufs_is_dirty_writeback,
14909 + .error_remove_page = aufs_error_remove_page,
14910 + .swap_activate = aufs_swap_activate,
14911 + .swap_deactivate = aufs_swap_deactivate
14912 +#endif /* CONFIG_AUFS_DEBUG */
14914 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14915 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14916 +++ linux/fs/aufs/file.h 2021-02-24 13:33:42.744347058 +0100
14918 +/* SPDX-License-Identifier: GPL-2.0 */
14920 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14922 + * This program, aufs is free software; you can redistribute it and/or modify
14923 + * it under the terms of the GNU General Public License as published by
14924 + * the Free Software Foundation; either version 2 of the License, or
14925 + * (at your option) any later version.
14927 + * This program is distributed in the hope that it will be useful,
14928 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14929 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14930 + * GNU General Public License for more details.
14932 + * You should have received a copy of the GNU General Public License
14933 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14937 + * file operations
14940 +#ifndef __AUFS_FILE_H__
14941 +#define __AUFS_FILE_H__
14945 +#include <linux/file.h>
14946 +#include <linux/fs.h>
14947 +#include <linux/mm_types.h>
14948 +#include <linux/poll.h>
14949 +#include "rwsem.h"
14953 + struct file *hf_file;
14954 + struct au_branch *hf_br;
14959 + aufs_bindex_t fd_bbot;
14960 + aufs_bindex_t fd_nent;
14961 + struct au_vdir *fd_vdir_cache;
14962 + struct au_hfile fd_hfile[];
14965 +static inline int au_fidir_sz(int nent)
14967 + AuDebugOn(nent < 0);
14968 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14972 + atomic_t fi_generation;
14974 + struct au_rwsem fi_rwsem;
14975 + aufs_bindex_t fi_btop;
14977 + /* do not union them */
14978 + struct { /* for non-dir */
14979 + struct au_hfile fi_htop;
14980 + atomic_t fi_mmapped;
14982 + struct au_fidir *fi_hdir; /* for dir only */
14984 + struct hlist_bl_node fi_hlist;
14985 + struct file *fi_file; /* very ugly */
14986 + struct rcu_head rcu;
14987 +} ____cacheline_aligned_in_smp;
14989 +/* ---------------------------------------------------------------------- */
14992 +extern const struct address_space_operations aufs_aop;
14993 +unsigned int au_file_roflags(unsigned int flags);
14994 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14995 + struct file *file, int force_wr);
14996 +struct au_do_open_args {
14998 + int (*open)(struct file *file, int flags,
14999 + struct file *h_file);
15000 + struct au_fidir *fidir;
15001 + struct file *h_file;
15003 +int au_do_open(struct file *file, struct au_do_open_args *args);
15004 +int au_reopen_nondir(struct file *file);
15006 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15007 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15008 + int wlock, unsigned int fi_lsc);
15009 +int au_do_flush(struct file *file, fl_owner_t id,
15010 + int (*flush)(struct file *file, fl_owner_t id));
15013 +#ifdef CONFIG_AUFS_POLL
15014 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15017 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15019 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15021 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15022 + struct file *h_file);
15024 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15025 + aufs_bindex_t bindex, int force_wr)
15026 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15027 + struct file *h_file);
15031 +extern const struct file_operations aufs_file_fop;
15032 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15033 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15034 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15037 +void au_hfput(struct au_hfile *hf, int execed);
15038 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15039 + struct file *h_file);
15041 +void au_update_figen(struct file *file);
15042 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15043 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15045 +void au_fi_init_once(void *_fi);
15046 +void au_finfo_fin(struct file *file);
15047 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15050 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15051 +#ifdef CONFIG_COMPAT
15052 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15053 + unsigned long arg);
15054 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15055 + unsigned long arg);
15058 +/* ---------------------------------------------------------------------- */
15060 +static inline struct au_finfo *au_fi(struct file *file)
15062 + return file->private_data;
15065 +/* ---------------------------------------------------------------------- */
15067 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15068 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15069 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15070 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15072 +#define fi_read_trylock_nested(f) \
15073 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15074 +#define fi_write_trylock_nested(f) \
15075 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15078 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15079 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15080 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15082 +/* lock subclass for finfo */
15088 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15090 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15093 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15095 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15099 + * fi_read_lock_1, fi_write_lock_1,
15100 + * fi_read_lock_2, fi_write_lock_2
15102 +#define AuReadLockFunc(name) \
15103 +static inline void fi_read_lock_##name(struct file *f) \
15104 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15106 +#define AuWriteLockFunc(name) \
15107 +static inline void fi_write_lock_##name(struct file *f) \
15108 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15110 +#define AuRWLockFuncs(name) \
15111 + AuReadLockFunc(name) \
15112 + AuWriteLockFunc(name)
15117 +#undef AuReadLockFunc
15118 +#undef AuWriteLockFunc
15119 +#undef AuRWLockFuncs
15121 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15122 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15123 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15125 +/* ---------------------------------------------------------------------- */
15127 +/* todo: hard/soft set? */
15128 +static inline aufs_bindex_t au_fbtop(struct file *file)
15130 + FiMustAnyLock(file);
15131 + return au_fi(file)->fi_btop;
15134 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15136 + FiMustAnyLock(file);
15137 + AuDebugOn(!au_fi(file)->fi_hdir);
15138 + return au_fi(file)->fi_hdir->fd_bbot;
15141 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15143 + FiMustAnyLock(file);
15144 + AuDebugOn(!au_fi(file)->fi_hdir);
15145 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15148 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15150 + FiMustWriteLock(file);
15151 + au_fi(file)->fi_btop = bindex;
15154 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15156 + FiMustWriteLock(file);
15157 + AuDebugOn(!au_fi(file)->fi_hdir);
15158 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15161 +static inline void au_set_fvdir_cache(struct file *file,
15162 + struct au_vdir *vdir_cache)
15164 + FiMustWriteLock(file);
15165 + AuDebugOn(!au_fi(file)->fi_hdir);
15166 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15169 +static inline struct file *au_hf_top(struct file *file)
15171 + FiMustAnyLock(file);
15172 + AuDebugOn(au_fi(file)->fi_hdir);
15173 + return au_fi(file)->fi_htop.hf_file;
15176 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15178 + FiMustAnyLock(file);
15179 + AuDebugOn(!au_fi(file)->fi_hdir);
15180 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15183 +/* todo: memory barrier? */
15184 +static inline unsigned int au_figen(struct file *f)
15186 + return atomic_read(&au_fi(f)->fi_generation);
15189 +static inline void au_set_mmapped(struct file *f)
15191 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15193 + pr_warn("fi_mmapped wrapped around\n");
15194 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15198 +static inline void au_unset_mmapped(struct file *f)
15200 + atomic_dec(&au_fi(f)->fi_mmapped);
15203 +static inline int au_test_mmapped(struct file *f)
15205 + return atomic_read(&au_fi(f)->fi_mmapped);
15208 +/* customize vma->vm_file */
15210 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15211 + struct file *file)
15215 + f = vma->vm_file;
15217 + vma->vm_file = file;
15222 +#define AuDbgVmRegion(file, vma) do {} while (0)
15224 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15225 + struct file *file)
15227 + au_do_vm_file_reset(vma, file);
15230 +#define AuDbgVmRegion(file, vma) \
15231 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15233 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15234 + struct file *file)
15238 + au_do_vm_file_reset(vma, file);
15239 + f = vma->vm_region->vm_file;
15241 + vma->vm_region->vm_file = file;
15244 +#endif /* CONFIG_MMU */
15246 +/* handle vma->vm_prfile */
15247 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15248 + struct file *file)
15251 + vma->vm_prfile = file;
15252 +#ifndef CONFIG_MMU
15254 + vma->vm_region->vm_prfile = file;
15258 +#endif /* __KERNEL__ */
15259 +#endif /* __AUFS_FILE_H__ */
15260 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15261 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15262 +++ linux/fs/aufs/finfo.c 2021-02-24 13:33:42.744347058 +0100
15264 +// SPDX-License-Identifier: GPL-2.0
15266 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15268 + * This program, aufs is free software; you can redistribute it and/or modify
15269 + * it under the terms of the GNU General Public License as published by
15270 + * the Free Software Foundation; either version 2 of the License, or
15271 + * (at your option) any later version.
15273 + * This program is distributed in the hope that it will be useful,
15274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15276 + * GNU General Public License for more details.
15278 + * You should have received a copy of the GNU General Public License
15279 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15283 + * file private data
15288 +void au_hfput(struct au_hfile *hf, int execed)
15291 + allow_write_access(hf->hf_file);
15292 + fput(hf->hf_file);
15293 + hf->hf_file = NULL;
15294 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15295 + hf->hf_br = NULL;
15298 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15300 + struct au_finfo *finfo = au_fi(file);
15301 + struct au_hfile *hf;
15302 + struct au_fidir *fidir;
15304 + fidir = finfo->fi_hdir;
15306 + AuDebugOn(finfo->fi_btop != bindex);
15307 + hf = &finfo->fi_htop;
15309 + hf = fidir->fd_hfile + bindex;
15311 + if (hf && hf->hf_file)
15312 + au_hfput(hf, vfsub_file_execed(file));
15314 + FiMustWriteLock(file);
15315 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15316 + hf->hf_file = val;
15317 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15321 +void au_update_figen(struct file *file)
15323 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15324 + /* smp_mb(); */ /* atomic_set */
15327 +/* ---------------------------------------------------------------------- */
15329 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15331 + struct au_fidir *fidir;
15334 + nbr = au_sbbot(sb) + 1;
15336 + nbr = 2; /* initial allocate for 2 branches */
15337 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15339 + fidir->fd_bbot = -1;
15340 + fidir->fd_nent = nbr;
15346 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15349 + struct au_fidir *fidir, *p;
15351 + AuRwMustWriteLock(&finfo->fi_rwsem);
15352 + fidir = finfo->fi_hdir;
15353 + AuDebugOn(!fidir);
15356 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15357 + GFP_NOFS, may_shrink);
15359 + p->fd_nent = nbr;
15360 + finfo->fi_hdir = p;
15367 +/* ---------------------------------------------------------------------- */
15369 +void au_finfo_fin(struct file *file)
15371 + struct au_finfo *finfo;
15373 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15375 + finfo = au_fi(file);
15376 + AuDebugOn(finfo->fi_hdir);
15377 + AuRwDestroy(&finfo->fi_rwsem);
15378 + au_cache_free_finfo(finfo);
15381 +void au_fi_init_once(void *_finfo)
15383 + struct au_finfo *finfo = _finfo;
15385 + au_rw_init(&finfo->fi_rwsem);
15388 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15391 + struct au_finfo *finfo;
15392 + struct dentry *dentry;
15395 + dentry = file->f_path.dentry;
15396 + finfo = au_cache_alloc_finfo();
15397 + if (unlikely(!finfo))
15401 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15402 + au_rw_write_lock(&finfo->fi_rwsem);
15403 + finfo->fi_btop = -1;
15404 + finfo->fi_hdir = fidir;
15405 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15406 + /* smp_mb(); */ /* atomic_set */
15408 + file->private_data = finfo;
15413 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15414 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15415 +++ linux/fs/aufs/f_op.c 2021-02-24 13:33:42.744347058 +0100
15417 +// SPDX-License-Identifier: GPL-2.0
15419 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15421 + * This program, aufs is free software; you can redistribute it and/or modify
15422 + * it under the terms of the GNU General Public License as published by
15423 + * the Free Software Foundation; either version 2 of the License, or
15424 + * (at your option) any later version.
15426 + * This program is distributed in the hope that it will be useful,
15427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15429 + * GNU General Public License for more details.
15431 + * You should have received a copy of the GNU General Public License
15432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15436 + * file and vm operations
15439 +#include <linux/aio.h>
15440 +#include <linux/fs_stack.h>
15441 +#include <linux/mman.h>
15442 +#include <linux/security.h>
15445 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15448 + aufs_bindex_t bindex;
15449 + struct dentry *dentry, *h_dentry;
15450 + struct au_finfo *finfo;
15451 + struct inode *h_inode;
15453 + FiMustWriteLock(file);
15456 + dentry = file->f_path.dentry;
15457 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15458 + finfo = au_fi(file);
15459 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15460 + atomic_set(&finfo->fi_mmapped, 0);
15461 + bindex = au_dbtop(dentry);
15463 + h_dentry = au_h_dptr(dentry, bindex);
15464 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15465 + if (unlikely(err))
15467 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15468 + if (IS_ERR(h_file)) {
15469 + err = PTR_ERR(h_file);
15473 + h_dentry = h_file->f_path.dentry;
15474 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15475 + if (unlikely(err))
15477 + /* br ref is already inc-ed */
15480 + if ((flags & __O_TMPFILE)
15481 + && !(flags & O_EXCL)) {
15482 + h_inode = file_inode(h_file);
15483 + spin_lock(&h_inode->i_lock);
15484 + h_inode->i_state |= I_LINKABLE;
15485 + spin_unlock(&h_inode->i_lock);
15487 + au_set_fbtop(file, bindex);
15488 + au_set_h_fptr(file, bindex, h_file);
15489 + au_update_figen(file);
15490 + /* todo: necessary? */
15491 + /* file->f_ra = h_file->f_ra; */
15497 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15498 + struct file *file)
15501 + struct super_block *sb;
15502 + struct au_do_open_args args = {
15503 + .open = au_do_open_nondir
15506 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15507 + file, vfsub_file_flags(file), file->f_mode);
15509 + sb = file->f_path.dentry->d_sb;
15510 + si_read_lock(sb, AuLock_FLUSH);
15511 + err = au_do_open(file, &args);
15512 + si_read_unlock(sb);
15516 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15518 + struct au_finfo *finfo;
15519 + aufs_bindex_t bindex;
15521 + finfo = au_fi(file);
15522 + au_hbl_del(&finfo->fi_hlist,
15523 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15524 + bindex = finfo->fi_btop;
15526 + au_set_h_fptr(file, bindex, NULL);
15528 + au_finfo_fin(file);
15532 +/* ---------------------------------------------------------------------- */
15534 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15537 + struct file *h_file;
15540 + h_file = au_hf_top(file);
15542 + err = vfsub_flush(h_file, id);
15546 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15548 + return au_do_flush(file, id, au_do_flush_nondir);
15551 +/* ---------------------------------------------------------------------- */
15553 + * read and write functions acquire [fdi]_rwsem once, but release before
15554 + * mmap_sem. This is because to stop a race condition between mmap(2).
15555 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15556 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15557 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15560 +/* Callers should call au_read_post() or fput() in the end */
15561 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15563 + struct file *h_file;
15566 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15568 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15569 + h_file = au_hf_top(file);
15570 + get_file(h_file);
15572 + fi_read_unlock(file);
15574 + h_file = ERR_PTR(err);
15579 +static void au_read_post(struct inode *inode, struct file *h_file)
15581 + /* update without lock, I don't think it a problem */
15582 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15586 +struct au_write_pre {
15588 + unsigned int lsc;
15592 + aufs_bindex_t btop;
15596 + * return with iinfo is write-locked
15597 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15600 +static struct file *au_write_pre(struct file *file, int do_ready,
15601 + struct au_write_pre *wpre)
15603 + struct file *h_file;
15604 + struct dentry *dentry;
15606 + unsigned int lsc;
15607 + struct au_pin pin;
15612 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15613 + h_file = ERR_PTR(err);
15614 + if (unlikely(err))
15617 + dentry = file->f_path.dentry;
15619 + err = au_ready_to_write(file, -1, &pin);
15620 + if (unlikely(err)) {
15621 + h_file = ERR_PTR(err);
15622 + di_write_unlock(dentry);
15627 + di_downgrade_lock(dentry, /*flags*/0);
15629 + wpre->btop = au_fbtop(file);
15630 + h_file = au_hf_top(file);
15631 + get_file(h_file);
15633 + wpre->blks = file_inode(h_file)->i_blocks;
15636 + di_read_unlock(dentry, /*flags*/0);
15639 + fi_write_unlock(file);
15644 +static void au_write_post(struct inode *inode, struct file *h_file,
15645 + struct au_write_pre *wpre, ssize_t written)
15647 + struct inode *h_inode;
15649 + au_cpup_attr_timesizes(inode);
15650 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15651 + h_inode = file_inode(h_file);
15652 + inode->i_mode = h_inode->i_mode;
15653 + ii_write_unlock(inode);
15654 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15656 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15657 + /*force*/h_inode->i_blocks > wpre->blks);
15662 + * todo: very ugly
15663 + * it locks both of i_mutex and si_rwsem for read in safe.
15664 + * if the plink maintenance mode continues forever (that is the problem),
15665 + * may loop forever.
15667 +static void au_mtx_and_read_lock(struct inode *inode)
15670 + struct super_block *sb = inode->i_sb;
15673 + inode_lock(inode);
15674 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15677 + inode_unlock(inode);
15678 + si_read_lock(sb, AuLock_NOPLMW);
15679 + si_read_unlock(sb);
15683 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15684 + struct iov_iter *iov_iter)
15687 + struct file *file;
15688 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15690 + err = security_file_permission(h_file, rw);
15691 + if (unlikely(err))
15694 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15696 + if (rw == MAY_READ)
15697 + iter = h_file->f_op->read_iter;
15698 + else if (rw == MAY_WRITE)
15699 + iter = h_file->f_op->write_iter;
15701 + file = kio->ki_filp;
15702 + kio->ki_filp = h_file;
15705 + err = iter(kio, iov_iter);
15708 + /* currently there is no such fs */
15710 + kio->ki_filp = file;
15716 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15719 + struct file *file, *h_file;
15720 + struct inode *inode;
15721 + struct super_block *sb;
15723 + file = kio->ki_filp;
15724 + inode = file_inode(file);
15725 + sb = inode->i_sb;
15726 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15728 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15729 + err = PTR_ERR(h_file);
15730 + if (IS_ERR(h_file))
15733 + if (au_test_loopback_kthread()) {
15734 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15735 + if (file->f_mapping != h_file->f_mapping) {
15736 + file->f_mapping = h_file->f_mapping;
15737 + smp_mb(); /* unnecessary? */
15740 + fi_read_unlock(file);
15742 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15743 + /* todo: necessary? */
15744 + /* file->f_ra = h_file->f_ra; */
15745 + au_read_post(inode, h_file);
15748 + si_read_unlock(sb);
15752 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15755 + struct au_write_pre wpre;
15756 + struct inode *inode;
15757 + struct file *file, *h_file;
15759 + file = kio->ki_filp;
15760 + inode = file_inode(file);
15761 + au_mtx_and_read_lock(inode);
15764 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15765 + err = PTR_ERR(h_file);
15766 + if (IS_ERR(h_file))
15769 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15770 + au_write_post(inode, h_file, &wpre, err);
15773 + si_read_unlock(inode->i_sb);
15774 + inode_unlock(inode);
15778 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15779 + struct pipe_inode_info *pipe, size_t len,
15780 + unsigned int flags)
15783 + struct file *h_file;
15784 + struct inode *inode;
15785 + struct super_block *sb;
15787 + inode = file_inode(file);
15788 + sb = inode->i_sb;
15789 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15791 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15792 + err = PTR_ERR(h_file);
15793 + if (IS_ERR(h_file))
15796 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15797 + /* todo: necessary? */
15798 + /* file->f_ra = h_file->f_ra; */
15799 + au_read_post(inode, h_file);
15802 + si_read_unlock(sb);
15807 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15808 + size_t len, unsigned int flags)
15811 + struct au_write_pre wpre;
15812 + struct inode *inode;
15813 + struct file *h_file;
15815 + inode = file_inode(file);
15816 + au_mtx_and_read_lock(inode);
15819 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15820 + err = PTR_ERR(h_file);
15821 + if (IS_ERR(h_file))
15824 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15825 + au_write_post(inode, h_file, &wpre, err);
15828 + si_read_unlock(inode->i_sb);
15829 + inode_unlock(inode);
15833 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15837 + struct au_write_pre wpre;
15838 + struct inode *inode;
15839 + struct file *h_file;
15841 + inode = file_inode(file);
15842 + au_mtx_and_read_lock(inode);
15845 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15846 + err = PTR_ERR(h_file);
15847 + if (IS_ERR(h_file))
15851 + err = vfs_fallocate(h_file, mode, offset, len);
15853 + au_write_post(inode, h_file, &wpre, /*written*/1);
15856 + si_read_unlock(inode->i_sb);
15857 + inode_unlock(inode);
15861 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15862 + struct file *dst, loff_t dst_pos,
15863 + size_t len, unsigned int flags)
15866 + struct au_write_pre wpre;
15867 + enum { SRC, DST };
15869 + struct inode *inode;
15870 + struct file *h_file;
15871 + struct super_block *h_sb;
15873 +#define a_src a[SRC]
15874 +#define a_dst a[DST]
15877 + a_src.inode = file_inode(src);
15878 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15880 + a_dst.inode = file_inode(dst);
15881 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15884 + au_mtx_and_read_lock(a_dst.inode);
15886 + * in order to match the order in di_write_lock2_{child,parent}(),
15887 + * use f_path.dentry for this comparison.
15889 + if (src->f_path.dentry < dst->f_path.dentry) {
15890 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15891 + err = PTR_ERR(a_src.h_file);
15892 + if (IS_ERR(a_src.h_file))
15895 + wpre.lsc = AuLsc_FI_2;
15896 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15897 + err = PTR_ERR(a_dst.h_file);
15898 + if (IS_ERR(a_dst.h_file)) {
15899 + au_read_post(a_src.inode, a_src.h_file);
15903 + wpre.lsc = AuLsc_FI_1;
15904 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15905 + err = PTR_ERR(a_dst.h_file);
15906 + if (IS_ERR(a_dst.h_file))
15909 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15910 + err = PTR_ERR(a_src.h_file);
15911 + if (IS_ERR(a_src.h_file)) {
15912 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15919 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15920 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15921 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15927 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15928 + dst_pos, len, flags);
15931 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15932 + fi_read_unlock(src);
15933 + au_read_post(a_src.inode, a_src.h_file);
15935 + si_read_unlock(a_dst.inode->i_sb);
15936 + inode_unlock(a_dst.inode);
15943 +/* ---------------------------------------------------------------------- */
15946 + * The locking order around current->mmap_sem.
15947 + * - in most and regular cases
15948 + * file I/O syscall -- aufs_read() or something
15949 + * -- si_rwsem for read -- mmap_sem
15950 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15952 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15953 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15954 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15955 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15956 + * It means that when aufs acquires si_rwsem for write, the process should never
15957 + * acquire mmap_sem.
15959 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15960 + * problem either since any directory is not able to be mmap-ed.
15961 + * The similar scenario is applied to aufs_readlink() too.
15964 +#if 0 /* stop calling security_file_mmap() */
15965 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15966 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15968 +static unsigned long au_arch_prot_conv(unsigned long flags)
15970 + /* currently ppc64 only */
15971 +#ifdef CONFIG_PPC64
15972 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15973 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15974 + return AuConv_VM_PROT(flags, SAO);
15976 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15981 +static unsigned long au_prot_conv(unsigned long flags)
15983 + return AuConv_VM_PROT(flags, READ)
15984 + | AuConv_VM_PROT(flags, WRITE)
15985 + | AuConv_VM_PROT(flags, EXEC)
15986 + | au_arch_prot_conv(flags);
15989 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15990 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15992 +static unsigned long au_flag_conv(unsigned long flags)
15994 + return AuConv_VM_MAP(flags, GROWSDOWN)
15995 + | AuConv_VM_MAP(flags, DENYWRITE)
15996 + | AuConv_VM_MAP(flags, LOCKED);
16000 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16003 + const unsigned char wlock
16004 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16005 + struct super_block *sb;
16006 + struct file *h_file;
16007 + struct inode *inode;
16009 + AuDbgVmRegion(file, vma);
16011 + inode = file_inode(file);
16012 + sb = inode->i_sb;
16014 + si_read_lock(sb, AuLock_NOPLMW);
16016 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16018 + err = PTR_ERR(h_file);
16019 + if (IS_ERR(h_file))
16023 + au_set_mmapped(file);
16024 + au_vm_file_reset(vma, h_file);
16026 + * we cannot call security_mmap_file() here since it may acquire
16027 + * mmap_sem or i_mutex.
16029 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16030 + * au_flag_conv(vma->vm_flags));
16033 + err = call_mmap(h_file, vma);
16035 + au_vm_prfile_set(vma, file);
16036 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16037 + goto out_fput; /* success */
16039 + au_unset_mmapped(file);
16040 + au_vm_file_reset(vma, file);
16044 + ii_write_unlock(inode);
16049 + si_read_unlock(sb);
16055 +/* ---------------------------------------------------------------------- */
16057 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16061 + struct au_write_pre wpre;
16062 + struct inode *inode;
16063 + struct file *h_file;
16065 + err = 0; /* -EBADF; */ /* posix? */
16066 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16069 + inode = file_inode(file);
16070 + au_mtx_and_read_lock(inode);
16073 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16074 + err = PTR_ERR(h_file);
16075 + if (IS_ERR(h_file))
16078 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16079 + au_write_post(inode, h_file, &wpre, /*written*/0);
16082 + si_read_unlock(inode->i_sb);
16083 + inode_unlock(inode);
16088 +static int aufs_fasync(int fd, struct file *file, int flag)
16091 + struct file *h_file;
16092 + struct super_block *sb;
16094 + sb = file->f_path.dentry->d_sb;
16095 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16097 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16098 + err = PTR_ERR(h_file);
16099 + if (IS_ERR(h_file))
16102 + if (h_file->f_op->fasync)
16103 + err = h_file->f_op->fasync(fd, h_file, flag);
16104 + fput(h_file); /* instead of au_read_post() */
16107 + si_read_unlock(sb);
16111 +static int aufs_setfl(struct file *file, unsigned long arg)
16114 + struct file *h_file;
16115 + struct super_block *sb;
16117 + sb = file->f_path.dentry->d_sb;
16118 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16120 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16121 + err = PTR_ERR(h_file);
16122 + if (IS_ERR(h_file))
16125 + /* stop calling h_file->fasync */
16126 + arg |= vfsub_file_flags(file) & FASYNC;
16127 + err = setfl(/*unused fd*/-1, h_file, arg);
16128 + fput(h_file); /* instead of au_read_post() */
16131 + si_read_unlock(sb);
16135 +/* ---------------------------------------------------------------------- */
16137 +/* no one supports this operation, currently */
16138 +#if 0 /* reserved for future use */
16139 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16140 + size_t len, loff_t *pos, int more)
16145 +/* ---------------------------------------------------------------------- */
16147 +const struct file_operations aufs_file_fop = {
16148 + .owner = THIS_MODULE,
16150 + .llseek = default_llseek,
16152 + .read_iter = aufs_read_iter,
16153 + .write_iter = aufs_write_iter,
16155 +#ifdef CONFIG_AUFS_POLL
16156 + .poll = aufs_poll,
16158 + .unlocked_ioctl = aufs_ioctl_nondir,
16159 +#ifdef CONFIG_COMPAT
16160 + .compat_ioctl = aufs_compat_ioctl_nondir,
16162 + .mmap = aufs_mmap,
16163 + .open = aufs_open_nondir,
16164 + .flush = aufs_flush_nondir,
16165 + .release = aufs_release_nondir,
16166 + .fsync = aufs_fsync_nondir,
16167 + .fasync = aufs_fasync,
16168 + /* .sendpage = aufs_sendpage, */
16169 + .setfl = aufs_setfl,
16170 + .splice_write = aufs_splice_write,
16171 + .splice_read = aufs_splice_read,
16172 +#if 0 /* reserved for future use */
16173 + .aio_splice_write = aufs_aio_splice_write,
16174 + .aio_splice_read = aufs_aio_splice_read,
16176 + .fallocate = aufs_fallocate,
16177 + .copy_file_range = aufs_copy_file_range
16179 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16180 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16181 +++ linux/fs/aufs/fstype.h 2021-02-24 13:33:42.744347058 +0100
16183 +/* SPDX-License-Identifier: GPL-2.0 */
16185 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16187 + * This program, aufs is free software; you can redistribute it and/or modify
16188 + * it under the terms of the GNU General Public License as published by
16189 + * the Free Software Foundation; either version 2 of the License, or
16190 + * (at your option) any later version.
16192 + * This program is distributed in the hope that it will be useful,
16193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16195 + * GNU General Public License for more details.
16197 + * You should have received a copy of the GNU General Public License
16198 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16202 + * judging filesystem type
16205 +#ifndef __AUFS_FSTYPE_H__
16206 +#define __AUFS_FSTYPE_H__
16210 +#include <linux/fs.h>
16211 +#include <linux/magic.h>
16212 +#include <linux/nfs_fs.h>
16213 +#include <linux/romfs_fs.h>
16215 +static inline int au_test_aufs(struct super_block *sb)
16217 + return sb->s_magic == AUFS_SUPER_MAGIC;
16220 +static inline const char *au_sbtype(struct super_block *sb)
16222 + return sb->s_type->name;
16225 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16227 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16228 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16234 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16236 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16237 + return sb->s_magic == ROMFS_MAGIC;
16243 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16245 +#if IS_ENABLED(CONFIG_CRAMFS)
16246 + return sb->s_magic == CRAMFS_MAGIC;
16251 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16253 +#if IS_ENABLED(CONFIG_NFS_FS)
16254 + return sb->s_magic == NFS_SUPER_MAGIC;
16260 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16262 +#if IS_ENABLED(CONFIG_FUSE_FS)
16263 + return sb->s_magic == FUSE_SUPER_MAGIC;
16269 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16271 +#if IS_ENABLED(CONFIG_XFS_FS)
16272 + return sb->s_magic == XFS_SB_MAGIC;
16278 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16280 +#ifdef CONFIG_TMPFS
16281 + return sb->s_magic == TMPFS_MAGIC;
16287 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16289 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16290 + return !strcmp(au_sbtype(sb), "ecryptfs");
16296 +static inline int au_test_ramfs(struct super_block *sb)
16298 + return sb->s_magic == RAMFS_MAGIC;
16301 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16303 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16304 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16310 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16312 +#ifdef CONFIG_PROC_FS
16313 + return sb->s_magic == PROC_SUPER_MAGIC;
16319 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16321 +#ifdef CONFIG_SYSFS
16322 + return sb->s_magic == SYSFS_MAGIC;
16328 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16330 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16331 + return sb->s_magic == CONFIGFS_MAGIC;
16337 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16339 +#if IS_ENABLED(CONFIG_MINIX_FS)
16340 + return sb->s_magic == MINIX3_SUPER_MAGIC
16341 + || sb->s_magic == MINIX2_SUPER_MAGIC
16342 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16343 + || sb->s_magic == MINIX_SUPER_MAGIC
16344 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16350 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16352 +#if IS_ENABLED(CONFIG_FAT_FS)
16353 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16359 +static inline int au_test_msdos(struct super_block *sb)
16361 + return au_test_fat(sb);
16364 +static inline int au_test_vfat(struct super_block *sb)
16366 + return au_test_fat(sb);
16369 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16371 +#ifdef CONFIG_SECURITYFS
16372 + return sb->s_magic == SECURITYFS_MAGIC;
16378 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16380 +#if IS_ENABLED(CONFIG_SQUASHFS)
16381 + return sb->s_magic == SQUASHFS_MAGIC;
16387 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16389 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16390 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16396 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16398 +#if IS_ENABLED(CONFIG_XENFS)
16399 + return sb->s_magic == XENFS_SUPER_MAGIC;
16405 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16407 +#ifdef CONFIG_DEBUG_FS
16408 + return sb->s_magic == DEBUGFS_MAGIC;
16414 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16416 +#if IS_ENABLED(CONFIG_NILFS)
16417 + return sb->s_magic == NILFS_SUPER_MAGIC;
16423 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16425 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16426 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16432 +/* ---------------------------------------------------------------------- */
16434 + * they can't be an aufs branch.
16436 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16439 +#ifndef CONFIG_AUFS_BR_RAMFS
16440 + au_test_ramfs(sb) ||
16442 + au_test_procfs(sb)
16443 + || au_test_sysfs(sb)
16444 + || au_test_configfs(sb)
16445 + || au_test_debugfs(sb)
16446 + || au_test_securityfs(sb)
16447 + || au_test_xenfs(sb)
16448 + || au_test_ecryptfs(sb)
16449 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16450 + || au_test_aufs(sb); /* will be supported in next version */
16453 +static inline int au_test_fs_remote(struct super_block *sb)
16455 + return !au_test_tmpfs(sb)
16456 +#ifdef CONFIG_AUFS_BR_RAMFS
16457 + && !au_test_ramfs(sb)
16459 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16462 +/* ---------------------------------------------------------------------- */
16465 + * Note: these functions (below) are created after reading ->getattr() in all
16466 + * filesystems under linux/fs. it means we have to do so in every update...
16470 + * some filesystems require getattr to refresh the inode attributes before
16472 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16473 + * and leave the work for d_revalidate()
16475 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16477 + return au_test_nfs(sb)
16478 + || au_test_fuse(sb)
16479 + /* || au_test_btrfs(sb) */ /* untested */
16484 + * filesystems which don't maintain i_size or i_blocks.
16486 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16488 + return au_test_xfs(sb)
16489 + || au_test_btrfs(sb)
16490 + || au_test_ubifs(sb)
16491 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16492 + /* || au_test_minix(sb) */ /* untested */
16497 + * filesystems which don't store the correct value in some of their inode
16500 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16502 + return au_test_fs_bad_iattr_size(sb)
16503 + || au_test_fat(sb)
16504 + || au_test_msdos(sb)
16505 + || au_test_vfat(sb);
16508 +/* they don't check i_nlink in link(2) */
16509 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16511 + return au_test_tmpfs(sb)
16512 +#ifdef CONFIG_AUFS_BR_RAMFS
16513 + || au_test_ramfs(sb)
16515 + || au_test_ubifs(sb)
16516 + || au_test_hfsplus(sb);
16520 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16522 +static inline int au_test_fs_notime(struct super_block *sb)
16524 + return au_test_nfs(sb)
16525 + || au_test_fuse(sb)
16526 + || au_test_ubifs(sb)
16530 +/* temporary support for i#1 in cramfs */
16531 +static inline int au_test_fs_unique_ino(struct inode *inode)
16533 + if (au_test_cramfs(inode->i_sb))
16534 + return inode->i_ino != 1;
16538 +/* ---------------------------------------------------------------------- */
16541 + * the filesystem where the xino files placed must support i/o after unlink and
16542 + * maintain i_size and i_blocks.
16544 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16546 + return au_test_fs_remote(sb)
16547 + || au_test_fs_bad_iattr_size(sb)
16548 + /* don't want unnecessary work for xino */
16549 + || au_test_aufs(sb)
16550 + || au_test_ecryptfs(sb)
16551 + || au_test_nilfs(sb);
16554 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16556 + return au_test_tmpfs(sb)
16557 + || au_test_ramfs(sb);
16561 + * test if the @sb is real-readonly.
16563 +static inline int au_test_fs_rr(struct super_block *sb)
16565 + return au_test_squashfs(sb)
16566 + || au_test_iso9660(sb)
16567 + || au_test_cramfs(sb)
16568 + || au_test_romfs(sb);
16572 + * test if the @inode is nfs with 'noacl' option
16573 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16575 +static inline int au_test_nfs_noacl(struct inode *inode)
16577 + return au_test_nfs(inode->i_sb)
16578 + /* && IS_POSIXACL(inode) */
16579 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16582 +#endif /* __KERNEL__ */
16583 +#endif /* __AUFS_FSTYPE_H__ */
16584 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16585 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16586 +++ linux/fs/aufs/hbl.h 2021-02-24 13:33:42.744347058 +0100
16588 +/* SPDX-License-Identifier: GPL-2.0 */
16590 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16592 + * This program, aufs is free software; you can redistribute it and/or modify
16593 + * it under the terms of the GNU General Public License as published by
16594 + * the Free Software Foundation; either version 2 of the License, or
16595 + * (at your option) any later version.
16597 + * This program is distributed in the hope that it will be useful,
16598 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16599 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16600 + * GNU General Public License for more details.
16602 + * You should have received a copy of the GNU General Public License
16603 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16607 + * helpers for hlist_bl.h
16610 +#ifndef __AUFS_HBL_H__
16611 +#define __AUFS_HBL_H__
16615 +#include <linux/list_bl.h>
16617 +static inline void au_hbl_add(struct hlist_bl_node *node,
16618 + struct hlist_bl_head *hbl)
16620 + hlist_bl_lock(hbl);
16621 + hlist_bl_add_head(node, hbl);
16622 + hlist_bl_unlock(hbl);
16625 +static inline void au_hbl_del(struct hlist_bl_node *node,
16626 + struct hlist_bl_head *hbl)
16628 + hlist_bl_lock(hbl);
16629 + hlist_bl_del(node);
16630 + hlist_bl_unlock(hbl);
16633 +#define au_hbl_for_each(pos, head) \
16634 + for (pos = hlist_bl_first(head); \
16638 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16640 + unsigned long cnt;
16641 + struct hlist_bl_node *pos;
16644 + hlist_bl_lock(hbl);
16645 + au_hbl_for_each(pos, hbl)
16647 + hlist_bl_unlock(hbl);
16651 +#endif /* __KERNEL__ */
16652 +#endif /* __AUFS_HBL_H__ */
16653 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16654 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16655 +++ linux/fs/aufs/hfsnotify.c 2021-02-24 13:33:42.744347058 +0100
16657 +// SPDX-License-Identifier: GPL-2.0
16659 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16661 + * This program, aufs is free software; you can redistribute it and/or modify
16662 + * it under the terms of the GNU General Public License as published by
16663 + * the Free Software Foundation; either version 2 of the License, or
16664 + * (at your option) any later version.
16666 + * This program is distributed in the hope that it will be useful,
16667 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16668 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16669 + * GNU General Public License for more details.
16671 + * You should have received a copy of the GNU General Public License
16672 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16676 + * fsnotify for the lower directories
16681 +/* FS_IN_IGNORED is unnecessary */
16682 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16683 + | FS_CREATE | FS_EVENT_ON_CHILD);
16684 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16685 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16687 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16689 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16691 + /* AuDbg("here\n"); */
16692 + au_cache_free_hnotify(hn);
16693 + smp_mb__before_atomic(); /* for atomic64_dec */
16694 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16695 + wake_up(&au_hfsn_wq);
16698 +static int au_hfsn_alloc(struct au_hinode *hinode)
16701 + struct au_hnotify *hn;
16702 + struct super_block *sb;
16703 + struct au_branch *br;
16704 + struct fsnotify_mark *mark;
16705 + aufs_bindex_t bindex;
16707 + hn = hinode->hi_notify;
16708 + sb = hn->hn_aufs_inode->i_sb;
16709 + bindex = au_br_index(sb, hinode->hi_id);
16710 + br = au_sbr(sb, bindex);
16711 + AuDebugOn(!br->br_hfsn);
16713 + mark = &hn->hn_mark;
16714 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16715 + mark->mask = AuHfsnMask;
16717 + * by udba rename or rmdir, aufs assign a new inode to the known
16718 + * h_inode, so specify 1 to allow dups.
16721 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16727 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16729 + struct fsnotify_mark *mark;
16730 + unsigned long long ull;
16731 + struct fsnotify_group *group;
16733 + ull = atomic64_inc_return(&au_hfsn_ifree);
16736 + mark = &hn->hn_mark;
16737 + spin_lock(&mark->lock);
16738 + group = mark->group;
16739 + fsnotify_get_group(group);
16740 + spin_unlock(&mark->lock);
16742 + fsnotify_destroy_mark(mark, group);
16743 + fsnotify_put_mark(mark);
16744 + fsnotify_put_group(group);
16747 + /* free hn by myself */
16751 +/* ---------------------------------------------------------------------- */
16753 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16755 + struct fsnotify_mark *mark;
16757 + mark = &hinode->hi_notify->hn_mark;
16758 + spin_lock(&mark->lock);
16760 + AuDebugOn(mark->mask & AuHfsnMask);
16761 + mark->mask |= AuHfsnMask;
16763 + AuDebugOn(!(mark->mask & AuHfsnMask));
16764 + mark->mask &= ~AuHfsnMask;
16766 + spin_unlock(&mark->lock);
16767 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16770 +/* ---------------------------------------------------------------------- */
16772 +/* #define AuDbgHnotify */
16773 +#ifdef AuDbgHnotify
16774 +static char *au_hfsn_name(u32 mask)
16776 +#ifdef CONFIG_AUFS_DEBUG
16777 +#define test_ret(flag) \
16779 + if (mask & flag) \
16782 + test_ret(FS_ACCESS);
16783 + test_ret(FS_MODIFY);
16784 + test_ret(FS_ATTRIB);
16785 + test_ret(FS_CLOSE_WRITE);
16786 + test_ret(FS_CLOSE_NOWRITE);
16787 + test_ret(FS_OPEN);
16788 + test_ret(FS_MOVED_FROM);
16789 + test_ret(FS_MOVED_TO);
16790 + test_ret(FS_CREATE);
16791 + test_ret(FS_DELETE);
16792 + test_ret(FS_DELETE_SELF);
16793 + test_ret(FS_MOVE_SELF);
16794 + test_ret(FS_UNMOUNT);
16795 + test_ret(FS_Q_OVERFLOW);
16796 + test_ret(FS_IN_IGNORED);
16797 + test_ret(FS_ISDIR);
16798 + test_ret(FS_IN_ONESHOT);
16799 + test_ret(FS_EVENT_ON_CHILD);
16808 +/* ---------------------------------------------------------------------- */
16810 +static void au_hfsn_free_group(struct fsnotify_group *group)
16812 + struct au_br_hfsnotify *hfsn = group->private;
16814 + /* AuDbg("here\n"); */
16815 + au_kfree_try_rcu(hfsn);
16818 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16819 + u32 mask, const void *data, int data_type,
16820 + struct inode *dir,
16821 + const struct qstr *file_name, u32 cookie,
16822 + struct fsnotify_iter_info *iter_info)
16825 + struct au_hnotify *hnotify;
16826 + struct inode *h_dir, *h_inode;
16827 + struct fsnotify_mark *inode_mark;
16829 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16832 + /* if FS_UNMOUNT happens, there must be another bug */
16833 + AuDebugOn(mask & FS_UNMOUNT);
16834 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16839 +#ifdef AuDbgHnotify
16841 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16842 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16843 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16844 + h_dir->i_ino, mask, au_hfsn_name(mask),
16845 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16846 + /* WARN_ON(1); */
16851 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16852 + AuDebugOn(!inode_mark);
16853 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16854 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16860 +static struct fsnotify_ops au_hfsn_ops = {
16861 + .handle_event = au_hfsn_handle_event,
16862 + .free_group_priv = au_hfsn_free_group,
16863 + .free_mark = au_hfsn_free_mark
16866 +/* ---------------------------------------------------------------------- */
16868 +static void au_hfsn_fin_br(struct au_branch *br)
16870 + struct au_br_hfsnotify *hfsn;
16872 + hfsn = br->br_hfsn;
16875 + fsnotify_put_group(hfsn->hfsn_group);
16880 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16883 + struct fsnotify_group *group;
16884 + struct au_br_hfsnotify *hfsn;
16887 + br->br_hfsn = NULL;
16888 + if (!au_br_hnotifyable(perm))
16892 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16893 + if (unlikely(!hfsn))
16897 + group = fsnotify_alloc_group(&au_hfsn_ops);
16898 + if (IS_ERR(group)) {
16899 + err = PTR_ERR(group);
16900 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16904 + group->private = hfsn;
16905 + hfsn->hfsn_group = group;
16906 + br->br_hfsn = hfsn;
16907 + goto out; /* success */
16910 + au_kfree_try_rcu(hfsn);
16915 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16920 + if (!br->br_hfsn)
16921 + err = au_hfsn_init_br(br, perm);
16926 +/* ---------------------------------------------------------------------- */
16928 +static void au_hfsn_fin(void)
16930 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16931 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16934 +const struct au_hnotify_op au_hnotify_op = {
16935 + .ctl = au_hfsn_ctl,
16936 + .alloc = au_hfsn_alloc,
16937 + .free = au_hfsn_free,
16939 + .fin = au_hfsn_fin,
16941 + .reset_br = au_hfsn_reset_br,
16942 + .fin_br = au_hfsn_fin_br,
16943 + .init_br = au_hfsn_init_br
16945 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16946 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16947 +++ linux/fs/aufs/hfsplus.c 2021-02-24 13:33:42.744347058 +0100
16949 +// SPDX-License-Identifier: GPL-2.0
16951 + * Copyright (C) 2010-2020 Junjiro R. Okajima
16953 + * This program, aufs is free software; you can redistribute it and/or modify
16954 + * it under the terms of the GNU General Public License as published by
16955 + * the Free Software Foundation; either version 2 of the License, or
16956 + * (at your option) any later version.
16958 + * This program is distributed in the hope that it will be useful,
16959 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16960 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16961 + * GNU General Public License for more details.
16963 + * You should have received a copy of the GNU General Public License
16964 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16968 + * special support for filesystems which acquires an inode mutex
16969 + * at final closing a file, eg, hfsplus.
16971 + * This trick is very simple and stupid, just to open the file before really
16972 + * necessary open to tell hfsplus that this is not the final closing.
16973 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16974 + * and au_h_open_post() after releasing it.
16979 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16982 + struct file *h_file;
16983 + struct dentry *h_dentry;
16985 + h_dentry = au_h_dptr(dentry, bindex);
16986 + AuDebugOn(!h_dentry);
16987 + AuDebugOn(d_is_negative(h_dentry));
16990 + if (au_test_hfsplus(h_dentry->d_sb)
16991 + && d_is_reg(h_dentry))
16992 + h_file = au_h_open(dentry, bindex,
16993 + O_RDONLY | O_NOATIME | O_LARGEFILE,
16994 + /*file*/NULL, force_wr);
16998 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
16999 + struct file *h_file)
17001 + struct au_branch *br;
17005 + br = au_sbr(dentry->d_sb, bindex);
17006 + au_lcnt_dec(&br->br_nfiles);
17009 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17010 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17011 +++ linux/fs/aufs/hnotify.c 2021-02-24 13:33:42.744347058 +0100
17013 +// SPDX-License-Identifier: GPL-2.0
17015 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17017 + * This program, aufs is free software; you can redistribute it and/or modify
17018 + * it under the terms of the GNU General Public License as published by
17019 + * the Free Software Foundation; either version 2 of the License, or
17020 + * (at your option) any later version.
17022 + * This program is distributed in the hope that it will be useful,
17023 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17024 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17025 + * GNU General Public License for more details.
17027 + * You should have received a copy of the GNU General Public License
17028 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17032 + * abstraction to notify the direct changes on lower directories
17035 +/* #include <linux/iversion.h> */
17038 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17041 + struct au_hnotify *hn;
17044 + hn = au_cache_alloc_hnotify();
17046 + hn->hn_aufs_inode = inode;
17047 + hinode->hi_notify = hn;
17048 + err = au_hnotify_op.alloc(hinode);
17050 + if (unlikely(err)) {
17051 + hinode->hi_notify = NULL;
17052 + au_cache_free_hnotify(hn);
17054 + * The upper dir was removed by udba, but the same named
17055 + * dir left. In this case, aufs assigns a new inode
17056 + * number and set the monitor again.
17057 + * For the lower dir, the old monitor is still left.
17059 + if (err == -EEXIST)
17068 +void au_hn_free(struct au_hinode *hinode)
17070 + struct au_hnotify *hn;
17072 + hn = hinode->hi_notify;
17074 + hinode->hi_notify = NULL;
17075 + if (au_hnotify_op.free(hinode, hn))
17076 + au_cache_free_hnotify(hn);
17080 +/* ---------------------------------------------------------------------- */
17082 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17084 + if (hinode->hi_notify)
17085 + au_hnotify_op.ctl(hinode, do_set);
17088 +void au_hn_reset(struct inode *inode, unsigned int flags)
17090 + aufs_bindex_t bindex, bbot;
17091 + struct inode *hi;
17092 + struct dentry *iwhdentry;
17094 + bbot = au_ibbot(inode);
17095 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17096 + hi = au_h_iptr(inode, bindex);
17100 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17101 + iwhdentry = au_hi_wh(inode, bindex);
17105 + au_set_h_iptr(inode, bindex, NULL, 0);
17106 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17107 + flags & ~AuHi_XINO);
17110 + /* inode_unlock(hi); */
17114 +/* ---------------------------------------------------------------------- */
17116 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17119 + aufs_bindex_t bindex, bbot, bfound, btop;
17120 + struct inode *h_i;
17123 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17124 + pr_warn("branch root dir was changed\n");
17129 + bbot = au_ibbot(inode);
17130 + btop = au_ibtop(inode);
17131 +#if 0 /* reserved for future use */
17132 + if (bindex == bbot) {
17133 + /* keep this ino in rename case */
17137 + for (bindex = btop; bindex <= bbot; bindex++)
17138 + if (au_h_iptr(inode, bindex) == h_inode) {
17145 + for (bindex = btop; bindex <= bbot; bindex++) {
17146 + h_i = au_h_iptr(inode, bindex);
17150 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17151 + /* ignore this error */
17152 + /* bad action? */
17155 + /* children inode number will be broken */
17162 +static int hn_gen_tree(struct dentry *dentry)
17164 + int err, i, j, ndentry;
17165 + struct au_dcsub_pages dpages;
17166 + struct au_dpage *dpage;
17167 + struct dentry **dentries;
17169 + err = au_dpages_init(&dpages, GFP_NOFS);
17170 + if (unlikely(err))
17172 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17173 + if (unlikely(err))
17176 + for (i = 0; i < dpages.ndpage; i++) {
17177 + dpage = dpages.dpages + i;
17178 + dentries = dpage->dentries;
17179 + ndentry = dpage->ndentry;
17180 + for (j = 0; j < ndentry; j++) {
17181 + struct dentry *d;
17188 + if (d_really_is_positive(d))
17189 + /* todo: reset children xino?
17190 + cached children only? */
17191 + au_iigen_dec(d_inode(d));
17196 + au_dpages_free(&dpages);
17202 + * return 0 if processed.
17204 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17205 + const unsigned int isdir)
17208 + struct dentry *d;
17209 + struct qstr *dname;
17212 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17213 + pr_warn("branch root dir was changed\n");
17219 + AuDebugOn(!name);
17220 + au_iigen_dec(inode);
17221 + spin_lock(&inode->i_lock);
17222 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17223 + spin_lock(&d->d_lock);
17224 + dname = &d->d_name;
17225 + if (dname->len != nlen
17226 + && memcmp(dname->name, name, nlen)) {
17227 + spin_unlock(&d->d_lock);
17232 + spin_unlock(&d->d_lock);
17235 + spin_unlock(&inode->i_lock);
17237 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17238 + d = d_find_any_alias(inode);
17240 + au_iigen_dec(inode);
17244 + spin_lock(&d->d_lock);
17245 + dname = &d->d_name;
17246 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17247 + spin_unlock(&d->d_lock);
17248 + err = hn_gen_tree(d);
17249 + spin_lock(&d->d_lock);
17251 + spin_unlock(&d->d_lock);
17260 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17264 + if (IS_ROOT(dentry)) {
17265 + pr_warn("branch root dir was changed\n");
17271 + au_digen_dec(dentry);
17272 + if (d_really_is_positive(dentry))
17273 + au_iigen_dec(d_inode(dentry));
17275 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17276 + if (d_really_is_positive(dentry))
17277 + err = hn_gen_tree(dentry);
17284 +/* ---------------------------------------------------------------------- */
17286 +/* hnotify job flags */
17287 +#define AuHnJob_XINO0 1
17288 +#define AuHnJob_GEN (1 << 1)
17289 +#define AuHnJob_DIRENT (1 << 2)
17290 +#define AuHnJob_ISDIR (1 << 3)
17291 +#define AuHnJob_TRYXINO0 (1 << 4)
17292 +#define AuHnJob_MNTPNT (1 << 5)
17293 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17294 +#define au_fset_hnjob(flags, name) \
17295 + do { (flags) |= AuHnJob_##name; } while (0)
17296 +#define au_fclr_hnjob(flags, name) \
17297 + do { (flags) &= ~AuHnJob_##name; } while (0)
17305 +struct au_hnotify_args {
17306 + struct inode *h_dir, *dir, *h_child_inode;
17308 + unsigned int flags[AuHnLast];
17309 + unsigned int h_child_nlen;
17310 + char h_child_name[];
17313 +struct hn_job_args {
17314 + unsigned int flags;
17315 + struct inode *inode, *h_inode, *dir, *h_dir;
17316 + struct dentry *dentry;
17321 +static int hn_job(struct hn_job_args *a)
17323 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17327 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17328 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17330 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17333 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17334 + if (!a->h_inode->i_nlink
17335 + && !(a->h_inode->i_state & I_LINKABLE))
17336 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17337 + inode_unlock_shared(a->h_inode);
17340 + /* make the generation obsolete */
17341 + if (au_ftest_hnjob(a->flags, GEN)) {
17344 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17346 + if (e && a->dentry)
17347 + hn_gen_by_name(a->dentry, isdir);
17348 + /* ignore this error */
17351 + /* make dir entries obsolete */
17352 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17353 + struct au_vdir *vdir;
17355 + vdir = au_ivdir(a->inode);
17357 + vdir->vd_jiffy = 0;
17358 + /* IMustLock(a->inode); */
17359 + /* inode_inc_iversion(a->inode); */
17362 + /* can do nothing but warn */
17363 + if (au_ftest_hnjob(a->flags, MNTPNT)
17365 + && d_mountpoint(a->dentry))
17366 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17371 +/* ---------------------------------------------------------------------- */
17373 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17374 + struct inode *dir)
17376 + struct dentry *dentry, *d, *parent;
17377 + struct qstr *dname;
17379 + parent = d_find_any_alias(dir);
17384 + spin_lock(&parent->d_lock);
17385 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17386 + /* AuDbg("%pd\n", d); */
17387 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17388 + dname = &d->d_name;
17389 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17390 + goto cont_unlock;
17394 + goto cont_unlock;
17395 + if (au_dcount(d) > 0) {
17396 + dentry = dget_dlock(d);
17397 + spin_unlock(&d->d_lock);
17402 + spin_unlock(&d->d_lock);
17404 + spin_unlock(&parent->d_lock);
17408 + di_write_lock_child(dentry);
17413 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17414 + aufs_bindex_t bindex, ino_t h_ino)
17416 + struct inode *inode;
17421 + err = au_xino_read(sb, bindex, h_ino, &ino);
17423 + inode = ilookup(sb, ino);
17427 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17428 + pr_warn("wrong root branch\n");
17434 + ii_write_lock_child(inode);
17440 +static void au_hn_bh(void *_args)
17442 + struct au_hnotify_args *a = _args;
17443 + struct super_block *sb;
17444 + aufs_bindex_t bindex, bbot, bfound;
17445 + unsigned char xino, try_iput;
17447 + struct inode *inode;
17449 + struct hn_job_args args;
17450 + struct dentry *dentry;
17451 + struct au_sbinfo *sbinfo;
17453 + AuDebugOn(!_args);
17454 + AuDebugOn(!a->h_dir);
17455 + AuDebugOn(!a->dir);
17456 + AuDebugOn(!a->mask);
17457 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17458 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17459 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17464 + * do not lock a->dir->i_mutex here
17465 + * because of d_revalidate() may cause a deadlock.
17467 + sb = a->dir->i_sb;
17469 + sbinfo = au_sbi(sb);
17470 + AuDebugOn(!sbinfo);
17471 + si_write_lock(sb, AuLock_NOPLMW);
17473 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17474 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17475 + case FS_MOVED_FROM:
17476 + case FS_MOVED_TO:
17477 + AuWarn1("DIRREN with UDBA may not work correctly "
17478 + "for the direct rename(2)\n");
17481 + ii_read_lock_parent(a->dir);
17483 + bbot = au_ibbot(a->dir);
17484 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17485 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17489 + ii_read_unlock(a->dir);
17490 + if (unlikely(bfound < 0))
17493 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17495 + if (a->h_child_inode)
17496 + h_ino = a->h_child_inode->i_ino;
17498 + if (a->h_child_nlen
17499 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17500 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17501 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17504 + if (dentry && d_really_is_positive(dentry))
17505 + inode = d_inode(dentry);
17506 + if (xino && !inode && h_ino
17507 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17508 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17509 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17510 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17514 + args.flags = a->flags[AuHn_CHILD];
17515 + args.dentry = dentry;
17516 + args.inode = inode;
17517 + args.h_inode = a->h_child_inode;
17518 + args.dir = a->dir;
17519 + args.h_dir = a->h_dir;
17520 + args.h_name = a->h_child_name;
17521 + args.h_nlen = a->h_child_nlen;
17522 + err = hn_job(&args);
17524 + if (au_di(dentry))
17525 + di_write_unlock(dentry);
17528 + if (inode && try_iput) {
17529 + ii_write_unlock(inode);
17533 + ii_write_lock_parent(a->dir);
17534 + args.flags = a->flags[AuHn_PARENT];
17535 + args.dentry = NULL;
17536 + args.inode = a->dir;
17537 + args.h_inode = a->h_dir;
17539 + args.h_dir = NULL;
17540 + args.h_name = NULL;
17542 + err = hn_job(&args);
17543 + ii_write_unlock(a->dir);
17546 + iput(a->h_child_inode);
17549 + si_write_unlock(sb);
17550 + au_nwt_done(&sbinfo->si_nowait);
17554 +/* ---------------------------------------------------------------------- */
17556 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17557 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17560 + unsigned int flags[AuHnLast], f;
17561 + unsigned char isdir, isroot, wh;
17562 + struct inode *dir;
17563 + struct au_hnotify_args *args;
17564 + char *p, *h_child_name;
17567 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17568 + dir = igrab(hnotify->hn_aufs_inode);
17572 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17574 + h_child_name = (void *)h_child_qstr->name;
17575 + len = h_child_qstr->len;
17576 + if (h_child_name) {
17577 + if (len > AUFS_WH_PFX_LEN
17578 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17579 + h_child_name += AUFS_WH_PFX_LEN;
17580 + len -= AUFS_WH_PFX_LEN;
17586 + if (h_child_inode)
17587 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17588 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17589 + flags[AuHn_CHILD] = 0;
17591 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17592 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17593 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17594 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17595 + case FS_MOVED_FROM:
17596 + case FS_MOVED_TO:
17597 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17598 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17601 + AuDebugOn(!h_child_name);
17606 + * aufs never be able to get this child inode.
17607 + * revalidation should be in d_revalidate()
17608 + * by checking i_nlink, i_generation or d_unhashed().
17610 + AuDebugOn(!h_child_name);
17611 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17612 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17620 + h_child_inode = NULL;
17623 + /* iput() and kfree() will be called in au_hnotify() */
17624 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17625 + if (unlikely(!args)) {
17626 + AuErr1("no memory\n");
17630 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17631 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17632 + args->mask = mask;
17634 + args->h_dir = igrab(h_dir);
17635 + if (h_child_inode)
17636 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17637 + args->h_child_inode = h_child_inode;
17638 + args->h_child_nlen = len;
17640 + p = (void *)args;
17641 + p += sizeof(*args);
17642 + memcpy(p, h_child_name, len);
17646 + /* NFS fires the event for silly-renamed one from kworker */
17648 + if (!dir->i_nlink
17649 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17651 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17652 + if (unlikely(err)) {
17653 + pr_err("wkq %d\n", err);
17654 + iput(args->h_child_inode);
17655 + iput(args->h_dir);
17657 + au_kfree_rcu(args);
17664 +/* ---------------------------------------------------------------------- */
17666 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17670 + AuDebugOn(!(udba & AuOptMask_UDBA));
17673 + if (au_hnotify_op.reset_br)
17674 + err = au_hnotify_op.reset_br(udba, br, perm);
17679 +int au_hnotify_init_br(struct au_branch *br, int perm)
17684 + if (au_hnotify_op.init_br)
17685 + err = au_hnotify_op.init_br(br, perm);
17690 +void au_hnotify_fin_br(struct au_branch *br)
17692 + if (au_hnotify_op.fin_br)
17693 + au_hnotify_op.fin_br(br);
17696 +static void au_hn_destroy_cache(void)
17698 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17699 + au_cache[AuCache_HNOTIFY] = NULL;
17702 +int __init au_hnotify_init(void)
17707 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17708 + if (au_cache[AuCache_HNOTIFY]) {
17710 + if (au_hnotify_op.init)
17711 + err = au_hnotify_op.init();
17712 + if (unlikely(err))
17713 + au_hn_destroy_cache();
17719 +void au_hnotify_fin(void)
17721 + if (au_hnotify_op.fin)
17722 + au_hnotify_op.fin();
17724 + /* cf. au_cache_fin() */
17725 + if (au_cache[AuCache_HNOTIFY])
17726 + au_hn_destroy_cache();
17728 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17729 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17730 +++ linux/fs/aufs/iinfo.c 2021-02-24 13:33:42.744347058 +0100
17732 +// SPDX-License-Identifier: GPL-2.0
17734 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17736 + * This program, aufs is free software; you can redistribute it and/or modify
17737 + * it under the terms of the GNU General Public License as published by
17738 + * the Free Software Foundation; either version 2 of the License, or
17739 + * (at your option) any later version.
17741 + * This program is distributed in the hope that it will be useful,
17742 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17743 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17744 + * GNU General Public License for more details.
17746 + * You should have received a copy of the GNU General Public License
17747 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17751 + * inode private data
17756 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17758 + struct inode *h_inode;
17759 + struct au_hinode *hinode;
17761 + IiMustAnyLock(inode);
17763 + hinode = au_hinode(au_ii(inode), bindex);
17764 + h_inode = hinode->hi_inode;
17765 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17769 +/* todo: hard/soft set? */
17770 +void au_hiput(struct au_hinode *hinode)
17772 + au_hn_free(hinode);
17773 + dput(hinode->hi_whdentry);
17774 + iput(hinode->hi_inode);
17777 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17779 + unsigned int flags;
17780 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17783 + if (au_opt_test(mnt_flags, XINO))
17784 + au_fset_hi(flags, XINO);
17785 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17786 + au_fset_hi(flags, HNOTIFY);
17790 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17791 + struct inode *h_inode, unsigned int flags)
17793 + struct au_hinode *hinode;
17794 + struct inode *hi;
17795 + struct au_iinfo *iinfo = au_ii(inode);
17797 + IiMustWriteLock(inode);
17799 + hinode = au_hinode(iinfo, bindex);
17800 + hi = hinode->hi_inode;
17801 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17804 + au_hiput(hinode);
17805 + hinode->hi_inode = h_inode;
17808 + struct super_block *sb = inode->i_sb;
17809 + struct au_branch *br;
17811 + AuDebugOn(inode->i_mode
17812 + && (h_inode->i_mode & S_IFMT)
17813 + != (inode->i_mode & S_IFMT));
17814 + if (bindex == iinfo->ii_btop)
17815 + au_cpup_igen(inode, h_inode);
17816 + br = au_sbr(sb, bindex);
17817 + hinode->hi_id = br->br_id;
17818 + if (au_ftest_hi(flags, XINO)) {
17819 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17821 + if (unlikely(err))
17822 + AuIOErr1("failed au_xino_write() %d\n", err);
17825 + if (au_ftest_hi(flags, HNOTIFY)
17826 + && au_br_hnotifyable(br->br_perm)) {
17827 + err = au_hn_alloc(hinode, inode);
17828 + if (unlikely(err))
17829 + AuIOErr1("au_hn_alloc() %d\n", err);
17834 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17835 + struct dentry *h_wh)
17837 + struct au_hinode *hinode;
17839 + IiMustWriteLock(inode);
17841 + hinode = au_hinode(au_ii(inode), bindex);
17842 + AuDebugOn(hinode->hi_whdentry);
17843 + hinode->hi_whdentry = h_wh;
17846 +void au_update_iigen(struct inode *inode, int half)
17848 + struct au_iinfo *iinfo;
17849 + struct au_iigen *iigen;
17850 + unsigned int sigen;
17852 + sigen = au_sigen(inode->i_sb);
17853 + iinfo = au_ii(inode);
17854 + iigen = &iinfo->ii_generation;
17855 + spin_lock(&iigen->ig_spin);
17856 + iigen->ig_generation = sigen;
17858 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17860 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17861 + spin_unlock(&iigen->ig_spin);
17864 +/* it may be called at remount time, too */
17865 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17867 + struct au_iinfo *iinfo;
17868 + aufs_bindex_t bindex, bbot;
17870 + AuDebugOn(au_is_bad_inode(inode));
17871 + IiMustWriteLock(inode);
17873 + iinfo = au_ii(inode);
17874 + if (do_put_zero && iinfo->ii_btop >= 0) {
17875 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17877 + struct inode *h_i;
17879 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17882 + && !(h_i->i_state & I_LINKABLE))
17883 + au_set_h_iptr(inode, bindex, NULL, 0);
17887 + iinfo->ii_btop = -1;
17888 + iinfo->ii_bbot = -1;
17889 + bbot = au_sbbot(inode->i_sb);
17890 + for (bindex = 0; bindex <= bbot; bindex++)
17891 + if (au_hinode(iinfo, bindex)->hi_inode) {
17892 + iinfo->ii_btop = bindex;
17895 + if (iinfo->ii_btop >= 0)
17896 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17897 + if (au_hinode(iinfo, bindex)->hi_inode) {
17898 + iinfo->ii_bbot = bindex;
17901 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17904 +/* ---------------------------------------------------------------------- */
17906 +void au_icntnr_init_once(void *_c)
17908 + struct au_icntnr *c = _c;
17909 + struct au_iinfo *iinfo = &c->iinfo;
17911 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17912 + au_rw_init(&iinfo->ii_rwsem);
17913 + inode_init_once(&c->vfs_inode);
17916 +void au_hinode_init(struct au_hinode *hinode)
17918 + hinode->hi_inode = NULL;
17919 + hinode->hi_id = -1;
17920 + au_hn_init(hinode);
17921 + hinode->hi_whdentry = NULL;
17924 +int au_iinfo_init(struct inode *inode)
17926 + struct au_iinfo *iinfo;
17927 + struct super_block *sb;
17928 + struct au_hinode *hi;
17931 + sb = inode->i_sb;
17932 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17933 + nbr = au_sbbot(sb) + 1;
17934 + if (unlikely(nbr <= 0))
17936 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17938 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17940 + iinfo->ii_hinode = hi;
17941 + for (i = 0; i < nbr; i++, hi++)
17942 + au_hinode_init(hi);
17944 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17945 + iinfo->ii_btop = -1;
17946 + iinfo->ii_bbot = -1;
17947 + iinfo->ii_vdir = NULL;
17953 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17956 + struct au_hinode *hip;
17958 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17961 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17964 + iinfo->ii_hinode = hip;
17965 + i = iinfo->ii_bbot + 1;
17967 + for (; i < nbr; i++, hip++)
17968 + au_hinode_init(hip);
17975 +void au_iinfo_fin(struct inode *inode)
17977 + struct au_iinfo *iinfo;
17978 + struct au_hinode *hi;
17979 + struct super_block *sb;
17980 + aufs_bindex_t bindex, bbot;
17981 + const unsigned char unlinked = !inode->i_nlink;
17983 + AuDebugOn(au_is_bad_inode(inode));
17985 + sb = inode->i_sb;
17986 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
17987 + if (si_pid_test(sb))
17988 + au_xino_delete_inode(inode, unlinked);
17991 + * it is safe to hide the dependency between sbinfo and
17995 + si_noflush_read_lock(sb);
17996 + au_xino_delete_inode(inode, unlinked);
17997 + si_read_unlock(sb);
18001 + iinfo = au_ii(inode);
18002 + if (iinfo->ii_vdir)
18003 + au_vdir_free(iinfo->ii_vdir);
18005 + bindex = iinfo->ii_btop;
18006 + if (bindex >= 0) {
18007 + hi = au_hinode(iinfo, bindex);
18008 + bbot = iinfo->ii_bbot;
18009 + while (bindex++ <= bbot) {
18010 + if (hi->hi_inode)
18015 + au_kfree_rcu(iinfo->ii_hinode);
18016 + AuRwDestroy(&iinfo->ii_rwsem);
18018 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18019 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18020 +++ linux/fs/aufs/inode.c 2021-02-24 13:33:42.744347058 +0100
18022 +// SPDX-License-Identifier: GPL-2.0
18024 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18026 + * This program, aufs is free software; you can redistribute it and/or modify
18027 + * it under the terms of the GNU General Public License as published by
18028 + * the Free Software Foundation; either version 2 of the License, or
18029 + * (at your option) any later version.
18031 + * This program is distributed in the hope that it will be useful,
18032 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18033 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18034 + * GNU General Public License for more details.
18036 + * You should have received a copy of the GNU General Public License
18037 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18041 + * inode functions
18044 +#include <linux/iversion.h>
18047 +struct inode *au_igrab(struct inode *inode)
18050 + AuDebugOn(!atomic_read(&inode->i_count));
18056 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18058 + au_cpup_attr_all(inode, /*force*/0);
18059 + au_update_iigen(inode, /*half*/1);
18061 + inode_inc_iversion(inode);
18064 +static int au_ii_refresh(struct inode *inode, int *update)
18068 + aufs_bindex_t bindex, new_bindex;
18069 + struct super_block *sb;
18070 + struct au_iinfo *iinfo;
18071 + struct au_hinode *p, *q, tmp;
18073 + AuDebugOn(au_is_bad_inode(inode));
18074 + IiMustWriteLock(inode);
18077 + sb = inode->i_sb;
18078 + nbr = au_sbbot(sb) + 1;
18079 + type = inode->i_mode & S_IFMT;
18080 + iinfo = au_ii(inode);
18081 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18082 + if (unlikely(err))
18085 + AuDebugOn(iinfo->ii_btop < 0);
18086 + p = au_hinode(iinfo, iinfo->ii_btop);
18087 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18089 + if (!p->hi_inode)
18092 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18093 + new_bindex = au_br_index(sb, p->hi_id);
18094 + if (new_bindex == bindex)
18097 + if (new_bindex < 0) {
18100 + p->hi_inode = NULL;
18104 + if (new_bindex < iinfo->ii_btop)
18105 + iinfo->ii_btop = new_bindex;
18106 + if (iinfo->ii_bbot < new_bindex)
18107 + iinfo->ii_bbot = new_bindex;
18108 + /* swap two lower inode, and loop again */
18109 + q = au_hinode(iinfo, new_bindex);
18113 + if (tmp.hi_inode) {
18118 + au_update_ibrange(inode, /*do_put_zero*/0);
18119 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18120 + e = au_dy_irefresh(inode);
18121 + if (unlikely(e && !err))
18129 +void au_refresh_iop(struct inode *inode, int force_getattr)
18132 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18133 + const struct inode_operations *iop
18134 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18136 + if (inode->i_op == iop)
18139 + switch (inode->i_mode & S_IFMT) {
18141 + type = AuIop_DIR;
18144 + type = AuIop_SYMLINK;
18147 + type = AuIop_OTHER;
18151 + inode->i_op = iop + type;
18152 + /* unnecessary smp_wmb() */
18155 +int au_refresh_hinode_self(struct inode *inode)
18159 + err = au_ii_refresh(inode, &update);
18161 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18167 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18169 + int err, e, update;
18170 + unsigned int flags;
18172 + aufs_bindex_t bindex, bbot;
18173 + unsigned char isdir;
18174 + struct au_hinode *p;
18175 + struct au_iinfo *iinfo;
18177 + err = au_ii_refresh(inode, &update);
18178 + if (unlikely(err))
18182 + iinfo = au_ii(inode);
18183 + p = au_hinode(iinfo, iinfo->ii_btop);
18184 + mode = (inode->i_mode & S_IFMT);
18185 + isdir = S_ISDIR(mode);
18186 + flags = au_hi_flags(inode, isdir);
18187 + bbot = au_dbbot(dentry);
18188 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18189 + struct inode *h_i, *h_inode;
18190 + struct dentry *h_d;
18192 + h_d = au_h_dptr(dentry, bindex);
18193 + if (!h_d || d_is_negative(h_d))
18196 + h_inode = d_inode(h_d);
18197 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18198 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18199 + h_i = au_h_iptr(inode, bindex);
18201 + if (h_i == h_inode)
18207 + if (bindex < iinfo->ii_btop)
18208 + iinfo->ii_btop = bindex;
18209 + if (iinfo->ii_bbot < bindex)
18210 + iinfo->ii_bbot = bindex;
18211 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18214 + au_update_ibrange(inode, /*do_put_zero*/0);
18215 + e = au_dy_irefresh(inode);
18216 + if (unlikely(e && !err))
18219 + au_refresh_hinode_attr(inode, update && isdir);
18226 +static int set_inode(struct inode *inode, struct dentry *dentry)
18229 + unsigned int flags;
18231 + aufs_bindex_t bindex, btop, btail;
18232 + unsigned char isdir;
18233 + struct dentry *h_dentry;
18234 + struct inode *h_inode;
18235 + struct au_iinfo *iinfo;
18236 + const struct inode_operations *iop;
18238 + IiMustWriteLock(inode);
18242 + iop = au_sbi(inode->i_sb)->si_iop_array;
18243 + btop = au_dbtop(dentry);
18244 + h_dentry = au_h_dptr(dentry, btop);
18245 + h_inode = d_inode(h_dentry);
18246 + mode = h_inode->i_mode;
18247 + switch (mode & S_IFMT) {
18249 + btail = au_dbtail(dentry);
18250 + inode->i_op = iop + AuIop_OTHER;
18251 + inode->i_fop = &aufs_file_fop;
18252 + err = au_dy_iaop(inode, btop, h_inode);
18253 + if (unlikely(err))
18258 + btail = au_dbtaildir(dentry);
18259 + inode->i_op = iop + AuIop_DIR;
18260 + inode->i_fop = &aufs_dir_fop;
18263 + btail = au_dbtail(dentry);
18264 + inode->i_op = iop + AuIop_SYMLINK;
18270 + btail = au_dbtail(dentry);
18271 + inode->i_op = iop + AuIop_OTHER;
18272 + init_special_inode(inode, mode, h_inode->i_rdev);
18275 + AuIOErr("Unknown file type 0%o\n", mode);
18280 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18281 + flags = au_hi_flags(inode, isdir);
18282 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18283 + && au_ftest_hi(flags, HNOTIFY)
18284 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18285 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18286 + au_fclr_hi(flags, HNOTIFY);
18287 + iinfo = au_ii(inode);
18288 + iinfo->ii_btop = btop;
18289 + iinfo->ii_bbot = btail;
18290 + for (bindex = btop; bindex <= btail; bindex++) {
18291 + h_dentry = au_h_dptr(dentry, bindex);
18293 + au_set_h_iptr(inode, bindex,
18294 + au_igrab(d_inode(h_dentry)), flags);
18296 + au_cpup_attr_all(inode, /*force*/1);
18298 + * to force calling aufs_get_acl() every time,
18299 + * do not call cache_no_acl() for aufs inode.
18307 + * successful returns with iinfo write_locked
18309 + * zero: success, matched
18310 + * plus: no error, but unmatched
18312 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18315 + unsigned int gen, igflags;
18316 + aufs_bindex_t bindex, bbot;
18317 + struct inode *h_inode, *h_dinode;
18318 + struct dentry *h_dentry;
18321 + * before this function, if aufs got any iinfo lock, it must be only
18322 + * one, the parent dir.
18323 + * it can happen by UDBA and the obsoleted inode number.
18326 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18330 + ii_write_lock_new_child(inode);
18331 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18332 + h_dinode = d_inode(h_dentry);
18333 + bbot = au_ibbot(inode);
18334 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18335 + h_inode = au_h_iptr(inode, bindex);
18336 + if (!h_inode || h_inode != h_dinode)
18340 + gen = au_iigen(inode, &igflags);
18341 + if (gen == au_digen(dentry)
18342 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18345 + /* fully refresh inode using dentry */
18346 + err = au_refresh_hinode(inode, dentry);
18348 + au_update_iigen(inode, /*half*/0);
18352 + if (unlikely(err))
18353 + ii_write_unlock(inode);
18358 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18359 + unsigned int d_type, ino_t *ino)
18362 + const int isnondir = d_type != DT_DIR;
18364 + /* prevent hardlinked inode number from race condition */
18366 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18367 + if (unlikely(err))
18371 + err = au_xino_read(sb, bindex, h_ino, ino);
18372 + if (unlikely(err))
18373 + goto out_xinondir;
18377 + *ino = au_xino_new_ino(sb);
18378 + if (unlikely(!*ino))
18379 + goto out_xinondir;
18380 + err = au_xino_write(sb, bindex, h_ino, *ino);
18381 + if (unlikely(err))
18382 + goto out_xinondir;
18386 + if (isnondir && idx >= 0)
18387 + au_xinondir_leave(sb, bindex, h_ino, idx);
18392 +/* successful returns with iinfo write_locked */
18393 +/* todo: return with unlocked? */
18394 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18396 + struct inode *inode, *h_inode;
18397 + struct dentry *h_dentry;
18398 + struct super_block *sb;
18399 + ino_t h_ino, ino;
18400 + int err, idx, hlinked;
18401 + aufs_bindex_t btop;
18403 + sb = dentry->d_sb;
18404 + btop = au_dbtop(dentry);
18405 + h_dentry = au_h_dptr(dentry, btop);
18406 + h_inode = d_inode(h_dentry);
18407 + h_ino = h_inode->i_ino;
18408 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18412 + * stop 'race'-ing between hardlinks under different
18416 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18417 + inode = ERR_PTR(err);
18418 + if (unlikely(err))
18422 + err = au_xino_read(sb, btop, h_ino, &ino);
18423 + inode = ERR_PTR(err);
18424 + if (unlikely(err))
18425 + goto out_xinondir;
18428 + ino = au_xino_new_ino(sb);
18429 + if (unlikely(!ino)) {
18430 + inode = ERR_PTR(-EIO);
18431 + goto out_xinondir;
18435 + AuDbg("i%lu\n", (unsigned long)ino);
18436 + inode = au_iget_locked(sb, ino);
18437 + err = PTR_ERR(inode);
18438 + if (IS_ERR(inode))
18439 + goto out_xinondir;
18441 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18442 + if (inode->i_state & I_NEW) {
18443 + ii_write_lock_new_child(inode);
18444 + err = set_inode(inode, dentry);
18446 + unlock_new_inode(inode);
18447 + goto out_xinondir; /* success */
18451 + * iget_failed() calls iput(), but we need to call
18452 + * ii_write_unlock() after iget_failed(). so dirty hack for
18455 + atomic_inc(&inode->i_count);
18456 + iget_failed(inode);
18457 + ii_write_unlock(inode);
18458 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18459 + /* ignore this error */
18461 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18463 + * horrible race condition between lookup, readdir and copyup
18464 + * (or something).
18466 + if (hlinked && idx >= 0)
18467 + au_xinondir_leave(sb, btop, h_ino, idx);
18468 + err = reval_inode(inode, dentry);
18469 + if (unlikely(err < 0)) {
18474 + goto out; /* success */
18475 + else if (hlinked && idx >= 0) {
18476 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18477 + if (unlikely(err)) {
18479 + inode = ERR_PTR(err);
18485 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18486 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18487 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18488 + btop, au_sbtype(h_dentry->d_sb), dentry,
18489 + (unsigned long)h_ino, (unsigned long)ino);
18491 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18494 + if (hlinked && idx >= 0)
18495 + au_xinondir_leave(sb, btop, h_ino, idx);
18501 + inode = ERR_PTR(err);
18503 + if (hlinked && idx >= 0)
18504 + au_xinondir_leave(sb, btop, h_ino, idx);
18509 +/* ---------------------------------------------------------------------- */
18511 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18512 + struct inode *inode)
18515 + struct inode *hi;
18517 + err = au_br_rdonly(au_sbr(sb, bindex));
18519 + /* pseudo-link after flushed may happen out of bounds */
18522 + && au_ibtop(inode) <= bindex
18523 + && bindex <= au_ibbot(inode)) {
18525 + * permission check is unnecessary since vfsub routine
18526 + * will be called later
18528 + hi = au_h_iptr(inode, bindex);
18530 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18536 +int au_test_h_perm(struct inode *h_inode, int mask)
18538 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18540 + return inode_permission(h_inode, mask);
18543 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18545 + if (au_test_nfs(h_inode->i_sb)
18546 + && (mask & MAY_WRITE)
18547 + && S_ISDIR(h_inode->i_mode))
18548 + mask |= MAY_READ; /* force permission check */
18549 + return au_test_h_perm(h_inode, mask);
18551 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18552 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18553 +++ linux/fs/aufs/inode.h 2021-02-24 13:33:42.744347058 +0100
18555 +/* SPDX-License-Identifier: GPL-2.0 */
18557 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18559 + * This program, aufs is free software; you can redistribute it and/or modify
18560 + * it under the terms of the GNU General Public License as published by
18561 + * the Free Software Foundation; either version 2 of the License, or
18562 + * (at your option) any later version.
18564 + * This program is distributed in the hope that it will be useful,
18565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18567 + * GNU General Public License for more details.
18569 + * You should have received a copy of the GNU General Public License
18570 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18574 + * inode operations
18577 +#ifndef __AUFS_INODE_H__
18578 +#define __AUFS_INODE_H__
18582 +#include <linux/fsnotify.h>
18583 +#include "rwsem.h"
18587 +struct au_hnotify {
18588 +#ifdef CONFIG_AUFS_HNOTIFY
18589 +#ifdef CONFIG_AUFS_HFSNOTIFY
18590 + /* never use fsnotify_add_vfsmount_mark() */
18591 + struct fsnotify_mark hn_mark;
18593 + struct inode *hn_aufs_inode; /* no get/put */
18594 + struct rcu_head rcu;
18596 +} ____cacheline_aligned_in_smp;
18598 +struct au_hinode {
18599 + struct inode *hi_inode;
18600 + aufs_bindex_t hi_id;
18601 +#ifdef CONFIG_AUFS_HNOTIFY
18602 + struct au_hnotify *hi_notify;
18605 + /* reference to the copied-up whiteout with get/put */
18606 + struct dentry *hi_whdentry;
18610 +#define AuIG_HALF_REFRESHED 1
18611 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18612 +#define au_ig_fset(flags, name) \
18613 + do { (flags) |= AuIG_##name; } while (0)
18614 +#define au_ig_fclr(flags, name) \
18615 + do { (flags) &= ~AuIG_##name; } while (0)
18618 + spinlock_t ig_spin;
18619 + __u32 ig_generation, ig_flags;
18624 + struct au_iigen ii_generation;
18625 + struct super_block *ii_hsb1; /* no get/put */
18627 + struct au_rwsem ii_rwsem;
18628 + aufs_bindex_t ii_btop, ii_bbot;
18630 + struct au_hinode *ii_hinode;
18631 + struct au_vdir *ii_vdir;
18634 +struct au_icntnr {
18635 + struct au_iinfo iinfo;
18636 + struct inode vfs_inode;
18637 + struct hlist_bl_node plink;
18638 + struct rcu_head rcu;
18639 +} ____cacheline_aligned_in_smp;
18641 +/* au_pin flags */
18642 +#define AuPin_DI_LOCKED 1
18643 +#define AuPin_MNT_WRITE (1 << 1)
18644 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18645 +#define au_fset_pin(flags, name) \
18646 + do { (flags) |= AuPin_##name; } while (0)
18647 +#define au_fclr_pin(flags, name) \
18648 + do { (flags) &= ~AuPin_##name; } while (0)
18652 + struct dentry *dentry;
18653 + unsigned int udba;
18654 + unsigned char lsc_di, lsc_hi, flags;
18655 + aufs_bindex_t bindex;
18658 + struct dentry *parent;
18659 + struct au_hinode *hdir;
18660 + struct vfsmount *h_mnt;
18662 + /* temporary unlock/relock for copyup */
18663 + struct dentry *h_dentry, *h_parent;
18664 + struct au_branch *br;
18665 + struct task_struct *task;
18668 +void au_pin_hdir_unlock(struct au_pin *p);
18669 +int au_pin_hdir_lock(struct au_pin *p);
18670 +int au_pin_hdir_relock(struct au_pin *p);
18671 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18672 +void au_pin_hdir_release(struct au_pin *p);
18674 +/* ---------------------------------------------------------------------- */
18676 +static inline struct au_iinfo *au_ii(struct inode *inode)
18678 + BUG_ON(is_bad_inode(inode));
18679 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18682 +/* ---------------------------------------------------------------------- */
18685 +struct inode *au_igrab(struct inode *inode);
18686 +void au_refresh_iop(struct inode *inode, int force_getattr);
18687 +int au_refresh_hinode_self(struct inode *inode);
18688 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18689 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18690 + unsigned int d_type, ino_t *ino);
18691 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18692 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18693 + struct inode *inode);
18694 +int au_test_h_perm(struct inode *h_inode, int mask);
18695 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18697 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18698 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18700 +#ifdef CONFIG_AUFS_SHWH
18701 + return au_ino(sb, bindex, h_ino, d_type, ino);
18714 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18715 + aufs_iop_nogetattr[AuIop_Last];
18717 +/* au_wr_dir flags */
18718 +#define AuWrDir_ADD_ENTRY 1
18719 +#define AuWrDir_ISDIR (1 << 1)
18720 +#define AuWrDir_TMPFILE (1 << 2)
18721 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18722 +#define au_fset_wrdir(flags, name) \
18723 + do { (flags) |= AuWrDir_##name; } while (0)
18724 +#define au_fclr_wrdir(flags, name) \
18725 + do { (flags) &= ~AuWrDir_##name; } while (0)
18727 +struct au_wr_dir_args {
18728 + aufs_bindex_t force_btgt;
18729 + unsigned char flags;
18731 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18732 + struct au_wr_dir_args *args);
18734 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18735 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18736 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18737 + unsigned int udba, unsigned char flags);
18738 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18739 + unsigned int udba, unsigned char flags) __must_check;
18740 +int au_do_pin(struct au_pin *pin) __must_check;
18741 +void au_unpin(struct au_pin *pin);
18742 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18744 +#define AuIcpup_DID_CPUP 1
18745 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18746 +#define au_fset_icpup(flags, name) \
18747 + do { (flags) |= AuIcpup_##name; } while (0)
18748 +#define au_fclr_icpup(flags, name) \
18749 + do { (flags) &= ~AuIcpup_##name; } while (0)
18751 +struct au_icpup_args {
18752 + unsigned char flags;
18753 + unsigned char pin_flags;
18754 + aufs_bindex_t btgt;
18755 + unsigned int udba;
18756 + struct au_pin pin;
18757 + struct path h_path;
18758 + struct inode *h_inode;
18761 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18762 + struct au_icpup_args *a);
18764 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18765 + struct path *h_path, int locked);
18768 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18769 + struct dentry *h_parent, int isdir);
18770 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18772 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18773 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18775 +struct vfsub_aopen_args;
18776 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18777 + struct vfsub_aopen_args *args);
18778 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18779 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18780 + struct dentry *dentry);
18781 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18784 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18785 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18786 + struct dentry *h_parent, int isdir);
18787 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18788 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18791 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18792 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18793 + struct inode *dir, struct dentry *dentry,
18794 + unsigned int flags);
18797 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18798 +void au_hiput(struct au_hinode *hinode);
18799 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18800 + struct dentry *h_wh);
18801 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18803 +/* hinode flags */
18804 +#define AuHi_XINO 1
18805 +#define AuHi_HNOTIFY (1 << 1)
18806 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18807 +#define au_fset_hi(flags, name) \
18808 + do { (flags) |= AuHi_##name; } while (0)
18809 +#define au_fclr_hi(flags, name) \
18810 + do { (flags) &= ~AuHi_##name; } while (0)
18812 +#ifndef CONFIG_AUFS_HNOTIFY
18813 +#undef AuHi_HNOTIFY
18814 +#define AuHi_HNOTIFY 0
18817 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18818 + struct inode *h_inode, unsigned int flags);
18820 +void au_update_iigen(struct inode *inode, int half);
18821 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18823 +void au_icntnr_init_once(void *_c);
18824 +void au_hinode_init(struct au_hinode *hinode);
18825 +int au_iinfo_init(struct inode *inode);
18826 +void au_iinfo_fin(struct inode *inode);
18827 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18829 +#ifdef CONFIG_PROC_FS
18831 +int au_plink_maint(struct super_block *sb, int flags);
18833 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18834 +int au_plink_maint_enter(struct super_block *sb);
18835 +#ifdef CONFIG_AUFS_DEBUG
18836 +void au_plink_list(struct super_block *sb);
18838 +AuStubVoid(au_plink_list, struct super_block *sb)
18840 +int au_plink_test(struct inode *inode);
18841 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18842 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18843 + struct dentry *h_dentry);
18844 +void au_plink_put(struct super_block *sb, int verbose);
18845 +void au_plink_clean(struct super_block *sb, int verbose);
18846 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18848 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18849 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18850 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18851 +AuStubVoid(au_plink_list, struct super_block *sb);
18852 +AuStubInt0(au_plink_test, struct inode *inode);
18853 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18854 + struct inode *inode, aufs_bindex_t bindex);
18855 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18856 + struct dentry *h_dentry);
18857 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18858 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18859 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18860 +#endif /* CONFIG_PROC_FS */
18862 +#ifdef CONFIG_AUFS_XATTR
18864 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18865 + unsigned int verbose);
18866 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18867 +void au_xattr_init(struct super_block *sb);
18869 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18870 + int ignore_flags, unsigned int verbose);
18871 +AuStubVoid(au_xattr_init, struct super_block *sb);
18874 +#ifdef CONFIG_FS_POSIX_ACL
18875 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18876 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18879 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18885 +struct au_sxattr {
18889 + const char *name;
18890 + const void *value;
18895 + struct posix_acl *acl;
18900 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18901 + struct au_sxattr *arg);
18904 +/* ---------------------------------------------------------------------- */
18906 +/* lock subclass for iinfo */
18908 + AuLsc_II_CHILD, /* child first */
18909 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18910 + AuLsc_II_CHILD3, /* copyup dirs */
18911 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18912 + AuLsc_II_PARENT2,
18913 + AuLsc_II_PARENT3, /* copyup dirs */
18914 + AuLsc_II_NEW_CHILD
18918 + * ii_read_lock_child, ii_write_lock_child,
18919 + * ii_read_lock_child2, ii_write_lock_child2,
18920 + * ii_read_lock_child3, ii_write_lock_child3,
18921 + * ii_read_lock_parent, ii_write_lock_parent,
18922 + * ii_read_lock_parent2, ii_write_lock_parent2,
18923 + * ii_read_lock_parent3, ii_write_lock_parent3,
18924 + * ii_read_lock_new_child, ii_write_lock_new_child,
18926 +#define AuReadLockFunc(name, lsc) \
18927 +static inline void ii_read_lock_##name(struct inode *i) \
18929 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18932 +#define AuWriteLockFunc(name, lsc) \
18933 +static inline void ii_write_lock_##name(struct inode *i) \
18935 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18938 +#define AuRWLockFuncs(name, lsc) \
18939 + AuReadLockFunc(name, lsc) \
18940 + AuWriteLockFunc(name, lsc)
18942 +AuRWLockFuncs(child, CHILD);
18943 +AuRWLockFuncs(child2, CHILD2);
18944 +AuRWLockFuncs(child3, CHILD3);
18945 +AuRWLockFuncs(parent, PARENT);
18946 +AuRWLockFuncs(parent2, PARENT2);
18947 +AuRWLockFuncs(parent3, PARENT3);
18948 +AuRWLockFuncs(new_child, NEW_CHILD);
18950 +#undef AuReadLockFunc
18951 +#undef AuWriteLockFunc
18952 +#undef AuRWLockFuncs
18954 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18955 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18956 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18958 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18959 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18960 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18962 +/* ---------------------------------------------------------------------- */
18964 +static inline void au_icntnr_init(struct au_icntnr *c)
18966 +#ifdef CONFIG_AUFS_DEBUG
18967 + c->vfs_inode.i_mode = 0;
18971 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18973 + unsigned int gen;
18974 + struct au_iinfo *iinfo;
18975 + struct au_iigen *iigen;
18977 + iinfo = au_ii(inode);
18978 + iigen = &iinfo->ii_generation;
18979 + spin_lock(&iigen->ig_spin);
18981 + *igflags = iigen->ig_flags;
18982 + gen = iigen->ig_generation;
18983 + spin_unlock(&iigen->ig_spin);
18988 +/* tiny test for inode number */
18989 +/* tmpfs generation is too rough */
18990 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
18992 + struct au_iinfo *iinfo;
18994 + iinfo = au_ii(inode);
18995 + AuRwMustAnyLock(&iinfo->ii_rwsem);
18996 + return !(iinfo->ii_hsb1 == h_inode->i_sb
18997 + && iinfo->ii_higen == h_inode->i_generation);
19000 +static inline void au_iigen_dec(struct inode *inode)
19002 + struct au_iinfo *iinfo;
19003 + struct au_iigen *iigen;
19005 + iinfo = au_ii(inode);
19006 + iigen = &iinfo->ii_generation;
19007 + spin_lock(&iigen->ig_spin);
19008 + iigen->ig_generation--;
19009 + spin_unlock(&iigen->ig_spin);
19012 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19017 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19023 +/* ---------------------------------------------------------------------- */
19025 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19026 + aufs_bindex_t bindex)
19028 + return iinfo->ii_hinode + bindex;
19031 +static inline int au_is_bad_inode(struct inode *inode)
19033 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19036 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19037 + aufs_bindex_t bindex)
19039 + IiMustAnyLock(inode);
19040 + return au_hinode(au_ii(inode), bindex)->hi_id;
19043 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19045 + IiMustAnyLock(inode);
19046 + return au_ii(inode)->ii_btop;
19049 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19051 + IiMustAnyLock(inode);
19052 + return au_ii(inode)->ii_bbot;
19055 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19057 + IiMustAnyLock(inode);
19058 + return au_ii(inode)->ii_vdir;
19061 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19063 + IiMustAnyLock(inode);
19064 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19067 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19069 + IiMustWriteLock(inode);
19070 + au_ii(inode)->ii_btop = bindex;
19073 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19075 + IiMustWriteLock(inode);
19076 + au_ii(inode)->ii_bbot = bindex;
19079 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19081 + IiMustWriteLock(inode);
19082 + au_ii(inode)->ii_vdir = vdir;
19085 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19087 + IiMustAnyLock(inode);
19088 + return au_hinode(au_ii(inode), bindex);
19091 +/* ---------------------------------------------------------------------- */
19093 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19096 + return pin->parent;
19100 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19102 + if (pin && pin->hdir)
19103 + return pin->hdir->hi_inode;
19107 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19110 + return pin->hdir;
19114 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19117 + pin->dentry = dentry;
19120 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19121 + unsigned char lflag)
19125 + au_fset_pin(pin->flags, DI_LOCKED);
19127 + au_fclr_pin(pin->flags, DI_LOCKED);
19131 +#if 0 /* reserved */
19132 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19135 + dput(pin->parent);
19136 + pin->parent = dget(parent);
19141 +/* ---------------------------------------------------------------------- */
19144 +#ifdef CONFIG_AUFS_HNOTIFY
19145 +struct au_hnotify_op {
19146 + void (*ctl)(struct au_hinode *hinode, int do_set);
19147 + int (*alloc)(struct au_hinode *hinode);
19150 + * if it returns true, the caller should free hinode->hi_notify,
19151 + * otherwise ->free() frees it.
19153 + int (*free)(struct au_hinode *hinode,
19154 + struct au_hnotify *hn) __must_check;
19156 + void (*fin)(void);
19157 + int (*init)(void);
19159 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19160 + void (*fin_br)(struct au_branch *br);
19161 + int (*init_br)(struct au_branch *br, int perm);
19165 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19166 +void au_hn_free(struct au_hinode *hinode);
19167 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19168 +void au_hn_reset(struct inode *inode, unsigned int flags);
19169 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19170 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19171 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19172 +int au_hnotify_init_br(struct au_branch *br, int perm);
19173 +void au_hnotify_fin_br(struct au_branch *br);
19174 +int __init au_hnotify_init(void);
19175 +void au_hnotify_fin(void);
19178 +extern const struct au_hnotify_op au_hnotify_op;
19181 +void au_hn_init(struct au_hinode *hinode)
19183 + hinode->hi_notify = NULL;
19186 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19188 + return hinode->hi_notify;
19192 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19193 + struct au_hinode *hinode __maybe_unused,
19194 + struct inode *inode __maybe_unused)
19195 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19196 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19197 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19198 + int do_set __maybe_unused)
19199 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19200 + unsigned int flags __maybe_unused)
19201 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19202 + struct au_branch *br __maybe_unused,
19203 + int perm __maybe_unused)
19204 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19205 + int perm __maybe_unused)
19206 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19207 +AuStubInt0(__init au_hnotify_init, void)
19208 +AuStubVoid(au_hnotify_fin, void)
19209 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19210 +#endif /* CONFIG_AUFS_HNOTIFY */
19212 +static inline void au_hn_suspend(struct au_hinode *hdir)
19214 + au_hn_ctl(hdir, /*do_set*/0);
19217 +static inline void au_hn_resume(struct au_hinode *hdir)
19219 + au_hn_ctl(hdir, /*do_set*/1);
19222 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19224 + inode_lock(hdir->hi_inode);
19225 + au_hn_suspend(hdir);
19228 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19229 + unsigned int sc __maybe_unused)
19231 + inode_lock_nested(hdir->hi_inode, sc);
19232 + au_hn_suspend(hdir);
19235 +#if 0 /* unused */
19236 +#include "vfsub.h"
19237 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19240 + inode_lock_shared_nested(hdir->hi_inode, sc);
19241 + au_hn_suspend(hdir);
19245 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19247 + au_hn_resume(hdir);
19248 + inode_unlock(hdir->hi_inode);
19251 +#endif /* __KERNEL__ */
19252 +#endif /* __AUFS_INODE_H__ */
19253 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19254 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19255 +++ linux/fs/aufs/ioctl.c 2021-02-24 13:33:42.744347058 +0100
19257 +// SPDX-License-Identifier: GPL-2.0
19259 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19261 + * This program, aufs is free software; you can redistribute it and/or modify
19262 + * it under the terms of the GNU General Public License as published by
19263 + * the Free Software Foundation; either version 2 of the License, or
19264 + * (at your option) any later version.
19266 + * This program is distributed in the hope that it will be useful,
19267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19269 + * GNU General Public License for more details.
19271 + * You should have received a copy of the GNU General Public License
19272 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19277 + * plink-management and readdir in userspace.
19278 + * assist the pathconf(3) wrapper library.
19280 + * File-based Hierarchical Storage Management.
19283 +#include <linux/compat.h>
19284 +#include <linux/file.h>
19287 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19290 + aufs_bindex_t wbi, bindex, bbot;
19291 + struct file *h_file;
19292 + struct super_block *sb;
19293 + struct dentry *root;
19294 + struct au_branch *br;
19295 + struct aufs_wbr_fd wbrfd = {
19296 + .oflags = au_dir_roflags,
19299 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19300 + | O_NOATIME | O_CLOEXEC;
19302 + AuDebugOn(wbrfd.oflags & ~valid);
19305 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19306 + if (unlikely(err)) {
19312 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19313 + wbrfd.oflags |= au_dir_roflags;
19314 + AuDbg("0%o\n", wbrfd.oflags);
19315 + if (unlikely(wbrfd.oflags & ~valid))
19319 + fd = get_unused_fd_flags(0);
19321 + if (unlikely(fd < 0))
19324 + h_file = ERR_PTR(-EINVAL);
19327 + sb = path->dentry->d_sb;
19328 + root = sb->s_root;
19329 + aufs_read_lock(root, AuLock_IR);
19330 + bbot = au_sbbot(sb);
19331 + if (wbrfd.brid >= 0) {
19332 + wbi = au_br_index(sb, wbrfd.brid);
19333 + if (unlikely(wbi < 0 || wbi > bbot))
19337 + h_file = ERR_PTR(-ENOENT);
19338 + br = au_sbr(sb, wbi);
19339 + if (!au_br_writable(br->br_perm)) {
19343 + bindex = wbi + 1;
19345 + for (; bindex <= bbot; bindex++) {
19346 + br = au_sbr(sb, bindex);
19347 + if (au_br_writable(br->br_perm)) {
19349 + br = au_sbr(sb, wbi);
19354 + AuDbg("wbi %d\n", wbi);
19356 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19360 + aufs_read_unlock(root, AuLock_IR);
19361 + err = PTR_ERR(h_file);
19362 + if (IS_ERR(h_file))
19365 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19366 + fd_install(fd, h_file);
19368 + goto out; /* success */
19371 + put_unused_fd(fd);
19377 +/* ---------------------------------------------------------------------- */
19379 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19382 + struct dentry *dentry;
19385 + case AUFS_CTL_RDU:
19386 + case AUFS_CTL_RDU_INO:
19387 + err = au_rdu_ioctl(file, cmd, arg);
19390 + case AUFS_CTL_WBR_FD:
19391 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19394 + case AUFS_CTL_IBUSY:
19395 + err = au_ibusy_ioctl(file, arg);
19398 + case AUFS_CTL_BRINFO:
19399 + err = au_brinfo_ioctl(file, arg);
19402 + case AUFS_CTL_FHSM_FD:
19403 + dentry = file->f_path.dentry;
19404 + if (IS_ROOT(dentry))
19405 + err = au_fhsm_fd(dentry->d_sb, arg);
19411 + /* do not call the lower */
19412 + AuDbg("0x%x\n", cmd);
19420 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19425 + case AUFS_CTL_MVDOWN:
19426 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19429 + case AUFS_CTL_WBR_FD:
19430 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19434 + /* do not call the lower */
19435 + AuDbg("0x%x\n", cmd);
19443 +#ifdef CONFIG_COMPAT
19444 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19445 + unsigned long arg)
19450 + case AUFS_CTL_RDU:
19451 + case AUFS_CTL_RDU_INO:
19452 + err = au_rdu_compat_ioctl(file, cmd, arg);
19455 + case AUFS_CTL_IBUSY:
19456 + err = au_ibusy_compat_ioctl(file, arg);
19459 + case AUFS_CTL_BRINFO:
19460 + err = au_brinfo_compat_ioctl(file, arg);
19464 + err = aufs_ioctl_dir(file, cmd, arg);
19471 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19472 + unsigned long arg)
19474 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19477 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19478 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19479 +++ linux/fs/aufs/i_op_add.c 2021-02-24 13:33:42.744347058 +0100
19481 +// SPDX-License-Identifier: GPL-2.0
19483 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19485 + * This program, aufs is free software; you can redistribute it and/or modify
19486 + * it under the terms of the GNU General Public License as published by
19487 + * the Free Software Foundation; either version 2 of the License, or
19488 + * (at your option) any later version.
19490 + * This program is distributed in the hope that it will be useful,
19491 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19492 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19493 + * GNU General Public License for more details.
19495 + * You should have received a copy of the GNU General Public License
19496 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19500 + * inode operations (add entry)
19503 +#include <linux/iversion.h>
19507 + * final procedure of adding a new entry, except link(2).
19508 + * remove whiteout, instantiate, copyup the parent dir's times and size
19509 + * and update version.
19510 + * if it failed, re-create the removed whiteout.
19512 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19513 + struct dentry *wh_dentry, struct dentry *dentry)
19516 + aufs_bindex_t bwh;
19517 + struct path h_path;
19518 + struct super_block *sb;
19519 + struct inode *inode, *h_dir;
19520 + struct dentry *wh;
19525 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19526 + IMustLock(h_dir);
19527 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19528 + bwh = au_dbwh(dentry);
19529 + h_path.dentry = wh_dentry;
19530 + h_path.mnt = au_sbr_mnt(sb, bindex);
19531 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19533 + if (unlikely(err))
19537 + inode = au_new_inode(dentry, /*must_new*/1);
19538 + if (!IS_ERR(inode)) {
19539 + d_instantiate(dentry, inode);
19540 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19542 + au_dir_ts(dir, bindex);
19543 + inode_inc_iversion(dir);
19544 + au_fhsm_wrote(sb, bindex, /*force*/0);
19545 + return 0; /* success */
19548 + err = PTR_ERR(inode);
19553 + /* dir inode is locked */
19554 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19555 + rerr = PTR_ERR(wh);
19556 + if (IS_ERR(wh)) {
19557 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19558 + dentry, err, rerr);
19567 +static int au_d_may_add(struct dentry *dentry)
19572 + if (unlikely(d_unhashed(dentry)))
19574 + if (unlikely(d_really_is_positive(dentry)))
19580 + * simple tests for the adding inode operations.
19581 + * following the checks in vfs, plus the parent-child relationship.
19583 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19584 + struct dentry *h_parent, int isdir)
19588 + struct dentry *h_dentry;
19589 + struct inode *h_inode;
19591 + err = -ENAMETOOLONG;
19592 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19595 + h_dentry = au_h_dptr(dentry, bindex);
19596 + if (d_really_is_negative(dentry)) {
19598 + if (unlikely(d_is_positive(h_dentry)))
19601 + /* rename(2) case */
19603 + if (unlikely(d_is_negative(h_dentry)))
19605 + h_inode = d_inode(h_dentry);
19606 + if (unlikely(!h_inode->i_nlink))
19609 + h_mode = h_inode->i_mode;
19612 + if (unlikely(S_ISDIR(h_mode)))
19614 + } else if (unlikely(!S_ISDIR(h_mode))) {
19621 + /* expected parent dir is locked */
19622 + if (unlikely(h_parent != h_dentry->d_parent))
19631 + * initial procedure of adding a new entry.
19632 + * prepare writable branch and the parent dir, lock it,
19633 + * and lookup whiteout for the new entry.
19635 +static struct dentry*
19636 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19637 + struct dentry *src_dentry, struct au_pin *pin,
19638 + struct au_wr_dir_args *wr_dir_args)
19640 + struct dentry *wh_dentry, *h_parent;
19641 + struct super_block *sb;
19642 + struct au_branch *br;
19644 + unsigned int udba;
19645 + aufs_bindex_t bcpup;
19647 + AuDbg("%pd\n", dentry);
19649 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19651 + wh_dentry = ERR_PTR(err);
19652 + if (unlikely(err < 0))
19655 + sb = dentry->d_sb;
19656 + udba = au_opt_udba(sb);
19657 + err = au_pin(pin, dentry, bcpup, udba,
19658 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19659 + wh_dentry = ERR_PTR(err);
19660 + if (unlikely(err))
19663 + h_parent = au_pinned_h_parent(pin);
19664 + if (udba != AuOpt_UDBA_NONE
19665 + && au_dbtop(dentry) == bcpup)
19666 + err = au_may_add(dentry, bcpup, h_parent,
19667 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19668 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19669 + err = -ENAMETOOLONG;
19670 + wh_dentry = ERR_PTR(err);
19671 + if (unlikely(err))
19674 + br = au_sbr(sb, bcpup);
19676 + struct path tmp = {
19677 + .dentry = h_parent,
19678 + .mnt = au_br_mnt(br)
19680 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19683 + wh_dentry = NULL;
19684 + if (bcpup != au_dbwh(dentry))
19685 + goto out; /* success */
19688 + * ENAMETOOLONG here means that if we allowed create such name, then it
19689 + * would not be able to removed in the future. So we don't allow such
19690 + * name here and we don't handle ENAMETOOLONG differently here.
19692 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19695 + if (IS_ERR(wh_dentry))
19698 + return wh_dentry;
19701 +/* ---------------------------------------------------------------------- */
19703 +enum { Mknod, Symlink, Creat };
19704 +struct simple_arg {
19711 + struct vfsub_aopen_args *aopen;
19714 + const char *symname;
19723 +static int add_simple(struct inode *dir, struct dentry *dentry,
19724 + struct simple_arg *arg)
19727 + aufs_bindex_t btop;
19728 + unsigned char created;
19729 + const unsigned char try_aopen
19730 + = (arg->type == Creat && arg->u.c.try_aopen);
19731 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19732 + struct dentry *wh_dentry, *parent;
19733 + struct inode *h_dir;
19734 + struct super_block *sb;
19735 + struct au_branch *br;
19736 + /* to reduce stack size */
19738 + struct au_dtime dt;
19739 + struct au_pin pin;
19740 + struct path h_path;
19741 + struct au_wr_dir_args wr_dir_args;
19744 + AuDbg("%pd\n", dentry);
19748 + a = kmalloc(sizeof(*a), GFP_NOFS);
19749 + if (unlikely(!a))
19751 + a->wr_dir_args.force_btgt = -1;
19752 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19754 + parent = dentry->d_parent; /* dir inode is locked */
19755 + if (!try_aopen) {
19756 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19757 + if (unlikely(err))
19760 + err = au_d_may_add(dentry);
19761 + if (unlikely(err))
19764 + di_write_lock_parent(parent);
19765 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19766 + &a->pin, &a->wr_dir_args);
19767 + err = PTR_ERR(wh_dentry);
19768 + if (IS_ERR(wh_dentry))
19771 + btop = au_dbtop(dentry);
19772 + sb = dentry->d_sb;
19773 + br = au_sbr(sb, btop);
19774 + a->h_path.dentry = au_h_dptr(dentry, btop);
19775 + a->h_path.mnt = au_br_mnt(br);
19776 + h_dir = au_pinned_h_dir(&a->pin);
19777 + switch (arg->type) {
19779 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19780 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19781 + arg->u.c.want_excl);
19783 + if (!err && try_aopen)
19784 + aopen->file->f_mode |= FMODE_CREATED;
19787 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19788 + AuDbg("err %d\n", err);
19789 + AuDbgFile(aopen->file);
19790 + created = err >= 0
19791 + && !!(aopen->file->f_mode & FMODE_CREATED);
19795 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19799 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19806 + if (unlikely(err < 0))
19809 + err = epilog(dir, btop, wh_dentry, dentry);
19811 + goto out_unpin; /* success */
19814 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19815 + /* no delegation since it is just created */
19816 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19819 + AuIOErr("%pd revert failure(%d, %d)\n",
19820 + dentry, err, rerr);
19823 + au_dtime_revert(&a->dt);
19825 + if (try_aopen && h_dir->i_op->atomic_open
19826 + && (aopen->file->f_mode & FMODE_OPENED))
19827 + /* aopen->file is still opened */
19828 + au_lcnt_dec(&aopen->br->br_nfiles);
19831 + au_unpin(&a->pin);
19835 + di_write_unlock(parent);
19837 + if (unlikely(err)) {
19838 + au_update_dbtop(dentry);
19842 + aufs_read_unlock(dentry, AuLock_DW);
19849 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19852 + struct simple_arg arg = {
19859 + return add_simple(dir, dentry, &arg);
19862 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19864 + struct simple_arg arg = {
19866 + .u.s.symname = symname
19868 + return add_simple(dir, dentry, &arg);
19871 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19874 + struct simple_arg arg = {
19878 + .want_excl = want_excl
19881 + return add_simple(dir, dentry, &arg);
19884 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19885 + struct vfsub_aopen_args *aopen_args)
19887 + struct simple_arg arg = {
19890 + .mode = aopen_args->create_mode,
19891 + .want_excl = aopen_args->open_flag & O_EXCL,
19892 + .try_aopen = true,
19893 + .aopen = aopen_args
19896 + return add_simple(dir, dentry, &arg);
19899 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19902 + aufs_bindex_t bindex;
19903 + struct super_block *sb;
19904 + struct dentry *parent, *h_parent, *h_dentry;
19905 + struct inode *h_dir, *inode;
19906 + struct vfsmount *h_mnt;
19907 + struct au_wr_dir_args wr_dir_args = {
19908 + .force_btgt = -1,
19909 + .flags = AuWrDir_TMPFILE
19912 + /* copy-up may happen */
19916 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19917 + if (unlikely(err))
19920 + err = au_di_init(dentry);
19921 + if (unlikely(err))
19925 + parent = d_find_any_alias(dir);
19926 + AuDebugOn(!parent);
19927 + di_write_lock_parent(parent);
19928 + if (unlikely(d_inode(parent) != dir))
19931 + err = au_digen_test(parent, au_sigen(sb));
19932 + if (unlikely(err))
19935 + bindex = au_dbtop(parent);
19936 + au_set_dbtop(dentry, bindex);
19937 + au_set_dbbot(dentry, bindex);
19938 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19940 + if (unlikely(err < 0))
19943 + err = -EOPNOTSUPP;
19944 + h_dir = au_h_iptr(dir, bindex);
19945 + if (unlikely(!h_dir->i_op->tmpfile))
19948 + h_mnt = au_sbr_mnt(sb, bindex);
19949 + err = vfsub_mnt_want_write(h_mnt);
19950 + if (unlikely(err))
19953 + h_parent = au_h_dptr(parent, bindex);
19954 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
19955 + if (IS_ERR(h_dentry)) {
19956 + err = PTR_ERR(h_dentry);
19960 + au_set_dbtop(dentry, bindex);
19961 + au_set_dbbot(dentry, bindex);
19962 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19963 + inode = au_new_inode(dentry, /*must_new*/1);
19964 + if (IS_ERR(inode)) {
19965 + err = PTR_ERR(inode);
19966 + au_set_h_dptr(dentry, bindex, NULL);
19967 + au_set_dbtop(dentry, -1);
19968 + au_set_dbbot(dentry, -1);
19970 + if (!inode->i_nlink)
19971 + set_nlink(inode, 1);
19972 + d_tmpfile(dentry, inode);
19973 + au_di(dentry)->di_tmpfile = 1;
19975 + /* update without i_mutex */
19976 + if (au_ibtop(dir) == au_dbtop(dentry))
19977 + au_cpup_attr_timesizes(dir);
19982 + vfsub_mnt_drop_write(h_mnt);
19984 + di_write_unlock(parent);
19986 + di_write_unlock(dentry);
19987 + if (unlikely(err)) {
19988 + au_di_fin(dentry);
19989 + dentry->d_fsdata = NULL;
19992 + si_read_unlock(sb);
19994 + inode_unlock(dir);
19998 +/* ---------------------------------------------------------------------- */
20000 +struct au_link_args {
20001 + aufs_bindex_t bdst, bsrc;
20002 + struct au_pin pin;
20003 + struct path h_path;
20004 + struct dentry *src_parent, *parent;
20007 +static int au_cpup_before_link(struct dentry *src_dentry,
20008 + struct au_link_args *a)
20011 + struct dentry *h_src_dentry;
20012 + struct au_cp_generic cpg = {
20013 + .dentry = src_dentry,
20018 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20021 + di_read_lock_parent(a->src_parent, AuLock_IR);
20022 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20023 + if (unlikely(err))
20026 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20027 + err = au_pin(&a->pin, src_dentry, a->bdst,
20028 + au_opt_udba(src_dentry->d_sb),
20029 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20030 + if (unlikely(err))
20033 + err = au_sio_cpup_simple(&cpg);
20034 + au_unpin(&a->pin);
20037 + di_read_unlock(a->src_parent, AuLock_IR);
20041 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20042 + struct au_link_args *a)
20045 + unsigned char plink;
20046 + aufs_bindex_t bbot;
20047 + struct dentry *h_src_dentry;
20048 + struct inode *h_inode, *inode, *delegated;
20049 + struct super_block *sb;
20050 + struct file *h_file;
20054 + sb = src_dentry->d_sb;
20055 + inode = d_inode(src_dentry);
20056 + if (au_ibtop(inode) <= a->bdst)
20057 + h_inode = au_h_iptr(inode, a->bdst);
20058 + if (!h_inode || !h_inode->i_nlink) {
20059 + /* copyup src_dentry as the name of dentry. */
20060 + bbot = au_dbbot(dentry);
20061 + if (bbot < a->bsrc)
20062 + au_set_dbbot(dentry, a->bsrc);
20063 + au_set_h_dptr(dentry, a->bsrc,
20064 + dget(au_h_dptr(src_dentry, a->bsrc)));
20065 + dget(a->h_path.dentry);
20066 + au_set_h_dptr(dentry, a->bdst, NULL);
20067 + AuDbg("temporary d_inode...\n");
20068 + spin_lock(&dentry->d_lock);
20069 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20070 + spin_unlock(&dentry->d_lock);
20071 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20072 + if (IS_ERR(h_file))
20073 + err = PTR_ERR(h_file);
20075 + struct au_cp_generic cpg = {
20076 + .dentry = dentry,
20081 + .flags = AuCpup_KEEPLINO
20083 + err = au_sio_cpup_simple(&cpg);
20084 + au_h_open_post(dentry, a->bsrc, h_file);
20086 + dput(a->h_path.dentry);
20087 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20089 + au_set_h_dptr(dentry, a->bdst,
20090 + a->h_path.dentry);
20092 + spin_lock(&dentry->d_lock);
20093 + dentry->d_inode = NULL; /* restore */
20094 + spin_unlock(&dentry->d_lock);
20095 + AuDbg("temporary d_inode...done\n");
20096 + au_set_h_dptr(dentry, a->bsrc, NULL);
20097 + au_set_dbbot(dentry, bbot);
20099 + /* the inode of src_dentry already exists on a.bdst branch */
20100 + h_src_dentry = d_find_alias(h_inode);
20101 + if (!h_src_dentry && au_plink_test(inode)) {
20103 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20104 + err = PTR_ERR(h_src_dentry);
20105 + if (IS_ERR(h_src_dentry))
20108 + if (unlikely(d_is_negative(h_src_dentry))) {
20109 + dput(h_src_dentry);
20110 + h_src_dentry = NULL;
20114 + if (h_src_dentry) {
20115 + delegated = NULL;
20116 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20117 + &a->h_path, &delegated);
20118 + if (unlikely(err == -EWOULDBLOCK)) {
20119 + pr_warn("cannot retry for NFSv4 delegation"
20120 + " for an internal link\n");
20123 + dput(h_src_dentry);
20125 + AuIOErr("no dentry found for hi%lu on b%d\n",
20126 + h_inode->i_ino, a->bdst);
20131 + if (!err && !plink)
20132 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20139 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20140 + struct dentry *dentry)
20143 + struct au_dtime dt;
20144 + struct au_link_args *a;
20145 + struct dentry *wh_dentry, *h_src_dentry;
20146 + struct inode *inode, *delegated;
20147 + struct super_block *sb;
20148 + struct au_wr_dir_args wr_dir_args = {
20149 + /* .force_btgt = -1, */
20150 + .flags = AuWrDir_ADD_ENTRY
20154 + inode = d_inode(src_dentry);
20155 + IMustLock(inode);
20158 + a = kzalloc(sizeof(*a), GFP_NOFS);
20159 + if (unlikely(!a))
20162 + a->parent = dentry->d_parent; /* dir inode is locked */
20163 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20164 + AuLock_NOPLM | AuLock_GEN);
20165 + if (unlikely(err))
20167 + err = au_d_linkable(src_dentry);
20168 + if (unlikely(err))
20170 + err = au_d_may_add(dentry);
20171 + if (unlikely(err))
20174 + a->src_parent = dget_parent(src_dentry);
20175 + wr_dir_args.force_btgt = au_ibtop(inode);
20177 + di_write_lock_parent(a->parent);
20178 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20179 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20181 + err = PTR_ERR(wh_dentry);
20182 + if (IS_ERR(wh_dentry))
20186 + sb = dentry->d_sb;
20187 + a->bdst = au_dbtop(dentry);
20188 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20189 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20190 + a->bsrc = au_ibtop(inode);
20191 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20192 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20193 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20194 + if (!h_src_dentry) {
20195 + a->bsrc = au_dbtop(src_dentry);
20196 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20197 + AuDebugOn(!h_src_dentry);
20198 + } else if (IS_ERR(h_src_dentry)) {
20199 + err = PTR_ERR(h_src_dentry);
20204 + * aufs doesn't touch the credential so
20205 + * security_dentry_create_files_as() is unnecessary.
20207 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20208 + if (a->bdst < a->bsrc
20209 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20210 + err = au_cpup_or_link(src_dentry, dentry, a);
20212 + delegated = NULL;
20213 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20214 + &a->h_path, &delegated);
20215 + if (unlikely(err == -EWOULDBLOCK)) {
20216 + pr_warn("cannot retry for NFSv4 delegation"
20217 + " for an internal link\n");
20221 + dput(h_src_dentry);
20224 + * copyup src_dentry to the branch we process,
20225 + * and then link(2) to it.
20227 + dput(h_src_dentry);
20228 + if (a->bdst < a->bsrc
20229 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20230 + au_unpin(&a->pin);
20231 + di_write_unlock(a->parent);
20232 + err = au_cpup_before_link(src_dentry, a);
20233 + di_write_lock_parent(a->parent);
20235 + err = au_pin(&a->pin, dentry, a->bdst,
20237 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20238 + if (unlikely(err))
20242 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20244 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20245 + delegated = NULL;
20246 + err = vfsub_link(h_src_dentry,
20247 + au_pinned_h_dir(&a->pin),
20248 + &a->h_path, &delegated);
20249 + if (unlikely(err == -EWOULDBLOCK)) {
20250 + pr_warn("cannot retry"
20251 + " for NFSv4 delegation"
20252 + " for an internal link\n");
20258 + if (unlikely(err))
20262 + a->h_path.dentry = wh_dentry;
20263 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20265 + if (unlikely(err))
20269 + au_dir_ts(dir, a->bdst);
20270 + inode_inc_iversion(dir);
20271 + inc_nlink(inode);
20272 + inode->i_ctime = dir->i_ctime;
20273 + d_instantiate(dentry, au_igrab(inode));
20274 + if (d_unhashed(a->h_path.dentry))
20275 + /* some filesystem calls d_drop() */
20277 + /* some filesystems consume an inode even hardlink */
20278 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20279 + goto out_unpin; /* success */
20282 + /* no delegation since it is just created */
20283 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20284 + /*delegated*/NULL, /*force*/0);
20285 + if (unlikely(rerr)) {
20286 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20289 + au_dtime_revert(&dt);
20291 + au_unpin(&a->pin);
20295 + di_write_unlock(a->parent);
20296 + dput(a->src_parent);
20298 + if (unlikely(err)) {
20299 + au_update_dbtop(dentry);
20302 + aufs_read_and_write_unlock2(dentry, src_dentry);
20310 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20313 + aufs_bindex_t bindex;
20314 + unsigned char diropq;
20315 + struct path h_path;
20316 + struct dentry *wh_dentry, *parent, *opq_dentry;
20317 + struct inode *h_inode;
20318 + struct super_block *sb;
20320 + struct au_pin pin;
20321 + struct au_dtime dt;
20322 + } *a; /* reduce the stack usage */
20323 + struct au_wr_dir_args wr_dir_args = {
20324 + .force_btgt = -1,
20325 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20331 + a = kmalloc(sizeof(*a), GFP_NOFS);
20332 + if (unlikely(!a))
20335 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20336 + if (unlikely(err))
20338 + err = au_d_may_add(dentry);
20339 + if (unlikely(err))
20342 + parent = dentry->d_parent; /* dir inode is locked */
20343 + di_write_lock_parent(parent);
20344 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20345 + &a->pin, &wr_dir_args);
20346 + err = PTR_ERR(wh_dentry);
20347 + if (IS_ERR(wh_dentry))
20350 + sb = dentry->d_sb;
20351 + bindex = au_dbtop(dentry);
20352 + h_path.dentry = au_h_dptr(dentry, bindex);
20353 + h_path.mnt = au_sbr_mnt(sb, bindex);
20354 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20355 + if (unlikely(err))
20358 + /* make the dir opaque */
20360 + h_inode = d_inode(h_path.dentry);
20362 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20363 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20364 + opq_dentry = au_diropq_create(dentry, bindex);
20365 + inode_unlock(h_inode);
20366 + err = PTR_ERR(opq_dentry);
20367 + if (IS_ERR(opq_dentry))
20369 + dput(opq_dentry);
20373 + err = epilog(dir, bindex, wh_dentry, dentry);
20376 + goto out_unpin; /* success */
20381 + AuLabel(revert opq);
20382 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20383 + rerr = au_diropq_remove(dentry, bindex);
20384 + inode_unlock(h_inode);
20386 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20387 + dentry, err, rerr);
20393 + AuLabel(revert dir);
20394 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20396 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20397 + dentry, err, rerr);
20400 + au_dtime_revert(&a->dt);
20402 + au_unpin(&a->pin);
20405 + di_write_unlock(parent);
20407 + if (unlikely(err)) {
20408 + au_update_dbtop(dentry);
20411 + aufs_read_unlock(dentry, AuLock_DW);
20417 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20418 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20419 +++ linux/fs/aufs/i_op.c 2021-02-24 13:33:42.744347058 +0100
20421 +// SPDX-License-Identifier: GPL-2.0
20423 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20425 + * This program, aufs is free software; you can redistribute it and/or modify
20426 + * it under the terms of the GNU General Public License as published by
20427 + * the Free Software Foundation; either version 2 of the License, or
20428 + * (at your option) any later version.
20430 + * This program is distributed in the hope that it will be useful,
20431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20433 + * GNU General Public License for more details.
20435 + * You should have received a copy of the GNU General Public License
20436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20440 + * inode operations (except add/del/rename)
20443 +#include <linux/device_cgroup.h>
20444 +#include <linux/fs_stack.h>
20445 +#include <linux/iversion.h>
20446 +#include <linux/namei.h>
20447 +#include <linux/security.h>
20450 +static int h_permission(struct inode *h_inode, int mask,
20451 + struct path *h_path, int brperm)
20454 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20457 + if (write_mask && IS_IMMUTABLE(h_inode))
20461 + if (((mask & MAY_EXEC)
20462 + && S_ISREG(h_inode->i_mode)
20463 + && (path_noexec(h_path)
20464 + || !(h_inode->i_mode & 0111))))
20468 + * - skip the lower fs test in the case of write to ro branch.
20469 + * - nfs dir permission write check is optimized, but a policy for
20470 + * link/rename requires a real check.
20471 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20472 + * in this case, generic_permission() returns -EOPNOTSUPP.
20474 + if ((write_mask && !au_br_writable(brperm))
20475 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20476 + && write_mask && !(mask & MAY_READ))
20477 + || !h_inode->i_op->permission) {
20478 + /* AuLabel(generic_permission); */
20479 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20480 + err = generic_permission(h_inode, mask);
20481 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20482 + err = h_inode->i_op->permission(h_inode, mask);
20485 + /* AuLabel(h_inode->permission); */
20486 + err = h_inode->i_op->permission(h_inode, mask);
20491 + err = devcgroup_inode_permission(h_inode, mask);
20493 + err = security_inode_permission(h_inode, mask);
20499 +static int aufs_permission(struct inode *inode, int mask)
20502 + aufs_bindex_t bindex, bbot;
20503 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20504 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20505 + struct inode *h_inode;
20506 + struct super_block *sb;
20507 + struct au_branch *br;
20509 + /* todo: support rcu-walk? */
20510 + if (mask & MAY_NOT_BLOCK)
20513 + sb = inode->i_sb;
20514 + si_read_lock(sb, AuLock_FLUSH);
20515 + ii_read_lock_child(inode);
20516 +#if 0 /* reserved for future use */
20518 + * This test may be rather 'too much' since the test is essentially done
20519 + * in the aufs_lookup(). Theoretically it is possible that the inode
20520 + * generation doesn't match to the superblock's here. But it isn't a
20521 + * big deal I suppose.
20523 + err = au_iigen_test(inode, au_sigen(sb));
20524 + if (unlikely(err))
20530 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20531 + err = au_busy_or_stale();
20532 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20533 + if (unlikely(!h_inode
20534 + || (h_inode->i_mode & S_IFMT)
20535 + != (inode->i_mode & S_IFMT)))
20539 + bindex = au_ibtop(inode);
20540 + br = au_sbr(sb, bindex);
20541 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20544 + && !special_file(h_inode->i_mode)) {
20545 + /* test whether the upper writable branch exists */
20547 + for (; bindex >= 0; bindex--)
20548 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20556 + /* non-write to dir */
20558 + bbot = au_ibbot(inode);
20559 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20560 + h_inode = au_h_iptr(inode, bindex);
20562 + err = au_busy_or_stale();
20563 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20566 + br = au_sbr(sb, bindex);
20567 + err = h_permission(h_inode, mask, &br->br_path,
20573 + ii_read_unlock(inode);
20574 + si_read_unlock(sb);
20578 +/* ---------------------------------------------------------------------- */
20580 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20581 + unsigned int flags)
20583 + struct dentry *ret, *parent;
20584 + struct inode *inode;
20585 + struct super_block *sb;
20586 + int err, npositive;
20590 + /* todo: support rcu-walk? */
20591 + ret = ERR_PTR(-ECHILD);
20592 + if (flags & LOOKUP_RCU)
20595 + ret = ERR_PTR(-ENAMETOOLONG);
20596 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20600 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20601 + ret = ERR_PTR(err);
20602 + if (unlikely(err))
20605 + err = au_di_init(dentry);
20606 + ret = ERR_PTR(err);
20607 + if (unlikely(err))
20611 + npositive = 0; /* suppress a warning */
20612 + parent = dentry->d_parent; /* dir inode is locked */
20613 + di_read_lock_parent(parent, AuLock_IR);
20614 + err = au_alive_dir(parent);
20616 + err = au_digen_test(parent, au_sigen(sb));
20618 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20619 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20620 + AuLkup_ALLOW_NEG);
20623 + di_read_unlock(parent, AuLock_IR);
20624 + ret = ERR_PTR(err);
20625 + if (unlikely(err < 0))
20629 + inode = au_new_inode(dentry, /*must_new*/0);
20630 + if (IS_ERR(inode)) {
20631 + ret = (void *)inode;
20638 + atomic_inc(&inode->i_count);
20639 + ret = d_splice_alias(inode, dentry);
20640 +#if 0 /* reserved for future use */
20641 + if (unlikely(d_need_lookup(dentry))) {
20642 + spin_lock(&dentry->d_lock);
20643 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20644 + spin_unlock(&dentry->d_lock);
20648 + if (!IS_ERR(ret)) {
20650 + if (ret && ret != dentry)
20651 + ii_write_unlock(inode);
20653 + ii_write_unlock(inode);
20660 + di_write_unlock(dentry);
20662 + si_read_unlock(sb);
20667 +/* ---------------------------------------------------------------------- */
20670 + * very dirty and complicated aufs ->atomic_open().
20671 + * aufs_atomic_open()
20672 + * + au_aopen_or_create()
20674 + * + vfsub_atomic_open()
20675 + * + branch fs ->atomic_open()
20676 + * may call the actual 'open' for h_file
20677 + * + inc br_nfiles only if opened
20678 + * + au_aopen_no_open() or au_aopen_do_open()
20680 + * au_aopen_do_open()
20681 + * + finish_open()
20682 + * + au_do_aopen()
20683 + * + au_do_open() the body of all 'open'
20684 + * + au_do_open_nondir()
20685 + * set the passed h_file
20687 + * au_aopen_no_open()
20688 + * + finish_no_open()
20691 +struct aopen_node {
20692 + struct hlist_bl_node hblist;
20693 + struct file *file, *h_file;
20696 +static int au_do_aopen(struct inode *inode, struct file *file)
20698 + struct hlist_bl_head *aopen;
20699 + struct hlist_bl_node *pos;
20700 + struct aopen_node *node;
20701 + struct au_do_open_args args = {
20703 + .open = au_do_open_nondir
20706 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20707 + hlist_bl_lock(aopen);
20708 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20709 + if (node->file == file) {
20710 + args.h_file = node->h_file;
20713 + hlist_bl_unlock(aopen);
20714 + /* AuDebugOn(!args.h_file); */
20716 + return au_do_open(file, &args);
20719 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20720 + struct aopen_node *aopen_node)
20723 + struct hlist_bl_head *aopen;
20726 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20727 + au_hbl_add(&aopen_node->hblist, aopen);
20728 + err = finish_open(file, dentry, au_do_aopen);
20729 + au_hbl_del(&aopen_node->hblist, aopen);
20730 + /* AuDbgFile(file); */
20731 + AuDbg("%pd%s%s\n", dentry,
20732 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20733 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20739 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20745 + err = finish_no_open(file, dentry);
20751 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20752 + struct file *file, unsigned int open_flag,
20753 + umode_t create_mode)
20755 + int err, did_open;
20756 + unsigned int lkup_flags;
20757 + aufs_bindex_t bindex;
20758 + struct super_block *sb;
20759 + struct dentry *parent, *d;
20760 + struct vfsub_aopen_args args = {
20761 + .open_flag = open_flag,
20762 + .create_mode = create_mode
20764 + struct aopen_node aopen_node = {
20769 + AuDbg("open_flag 0%o\n", open_flag);
20770 + AuDbgDentry(dentry);
20773 + if (!au_di(dentry)) {
20774 + lkup_flags = LOOKUP_OPEN;
20775 + if (open_flag & O_CREAT)
20776 + lkup_flags |= LOOKUP_CREATE;
20777 + d = aufs_lookup(dir, dentry, lkup_flags);
20779 + err = PTR_ERR(d);
20784 + * obsoleted dentry found.
20785 + * another error will be returned later.
20791 + AuDbgDentry(dentry);
20794 + if (d_is_positive(dentry)
20795 + || d_unhashed(dentry)
20796 + || d_unlinked(dentry)
20797 + || !(open_flag & O_CREAT)) {
20798 + err = au_aopen_no_open(file, dentry);
20799 + goto out; /* success */
20802 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20803 + if (unlikely(err))
20806 + sb = dentry->d_sb;
20807 + parent = dentry->d_parent; /* dir is locked */
20808 + di_write_lock_parent(parent);
20809 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20810 + if (unlikely(err < 0))
20813 + AuDbgDentry(dentry);
20814 + if (d_is_positive(dentry)) {
20815 + err = au_aopen_no_open(file, dentry);
20816 + goto out_parent; /* success */
20819 + args.file = alloc_empty_file(file->f_flags, current_cred());
20820 + err = PTR_ERR(args.file);
20821 + if (IS_ERR(args.file))
20824 + bindex = au_dbtop(dentry);
20825 + err = au_aopen_or_create(dir, dentry, &args);
20827 + AuDbgFile(args.file);
20828 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20829 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20832 + args.file = NULL;
20834 + di_write_unlock(parent);
20835 + di_write_unlock(dentry);
20836 + if (unlikely(err < 0)) {
20843 + err = au_aopen_no_open(file, dentry);
20845 + aopen_node.h_file = args.file;
20846 + err = au_aopen_do_open(file, dentry, &aopen_node);
20848 + if (unlikely(err < 0)) {
20852 + au_lcnt_dec(&args.br->br_nfiles);
20854 + goto out_sb; /* success */
20857 + di_write_unlock(parent);
20858 + di_write_unlock(dentry);
20860 + si_read_unlock(sb);
20868 +/* ---------------------------------------------------------------------- */
20870 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20871 + const unsigned char add_entry, aufs_bindex_t bcpup,
20872 + aufs_bindex_t btop)
20875 + struct dentry *h_parent;
20876 + struct inode *h_dir;
20879 + IMustLock(d_inode(parent));
20881 + di_write_lock_parent(parent);
20884 + if (!au_h_dptr(parent, bcpup)) {
20885 + if (btop > bcpup)
20886 + err = au_cpup_dirs(dentry, bcpup);
20887 + else if (btop < bcpup)
20888 + err = au_cpdown_dirs(dentry, bcpup);
20892 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20893 + h_parent = au_h_dptr(parent, bcpup);
20894 + h_dir = d_inode(h_parent);
20895 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20896 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20897 + /* todo: no unlock here */
20898 + inode_unlock_shared(h_dir);
20900 + AuDbg("bcpup %d\n", bcpup);
20902 + if (d_really_is_negative(dentry))
20903 + au_set_h_dptr(dentry, btop, NULL);
20904 + au_update_dbrange(dentry, /*do_put_zero*/0);
20909 + di_write_unlock(parent);
20911 + err = bcpup; /* success */
20918 + * decide the branch and the parent dir where we will create a new entry.
20919 + * returns new bindex or an error.
20920 + * copyup the parent dir if needed.
20922 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20923 + struct au_wr_dir_args *args)
20926 + unsigned int flags;
20927 + aufs_bindex_t bcpup, btop, src_btop;
20928 + const unsigned char add_entry
20929 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20930 + | au_ftest_wrdir(args->flags, TMPFILE);
20931 + struct super_block *sb;
20932 + struct dentry *parent;
20933 + struct au_sbinfo *sbinfo;
20935 + sb = dentry->d_sb;
20936 + sbinfo = au_sbi(sb);
20937 + parent = dget_parent(dentry);
20938 + btop = au_dbtop(dentry);
20940 + if (args->force_btgt < 0) {
20941 + if (src_dentry) {
20942 + src_btop = au_dbtop(src_dentry);
20943 + if (src_btop < btop)
20944 + bcpup = src_btop;
20945 + } else if (add_entry) {
20947 + if (au_ftest_wrdir(args->flags, ISDIR))
20948 + au_fset_wbr(flags, DIR);
20949 + err = AuWbrCreate(sbinfo, dentry, flags);
20953 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20955 + err = AuWbrCopyup(sbinfo, dentry);
20957 + if (!IS_ROOT(dentry)) {
20958 + di_read_lock_parent(parent, !AuLock_IR);
20959 + err = AuWbrCopyup(sbinfo, dentry);
20960 + di_read_unlock(parent, !AuLock_IR);
20962 + err = AuWbrCopyup(sbinfo, dentry);
20965 + if (unlikely(err < 0))
20969 + bcpup = args->force_btgt;
20970 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20973 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20975 + if (bcpup == btop)
20976 + goto out; /* success */
20978 + /* copyup the new parent into the branch we process */
20979 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20981 + if (d_really_is_negative(dentry)) {
20982 + au_set_h_dptr(dentry, btop, NULL);
20983 + au_set_dbtop(dentry, bcpup);
20984 + au_set_dbbot(dentry, bcpup);
20986 + AuDebugOn(add_entry
20987 + && !au_ftest_wrdir(args->flags, TMPFILE)
20988 + && !au_h_dptr(dentry, bcpup));
20996 +/* ---------------------------------------------------------------------- */
20998 +void au_pin_hdir_unlock(struct au_pin *p)
21001 + au_hn_inode_unlock(p->hdir);
21004 +int au_pin_hdir_lock(struct au_pin *p)
21012 + /* even if an error happens later, keep this lock */
21013 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21016 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21021 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21022 + p->h_parent, p->br);
21028 +int au_pin_hdir_relock(struct au_pin *p)
21031 + struct inode *h_i;
21032 + struct dentry *h_d[] = {
21037 + err = au_pin_hdir_lock(p);
21038 + if (unlikely(err))
21041 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21044 + if (d_is_positive(h_d[i])) {
21045 + h_i = d_inode(h_d[i]);
21046 + err = !h_i->i_nlink;
21054 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21056 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21059 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21062 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21063 + p->lsc_hi, 0, NULL, _RET_IP_);
21064 + au_pin_hdir_set_owner(p, current);
21068 +void au_pin_hdir_release(struct au_pin *p)
21071 + au_pin_hdir_set_owner(p, p->task);
21072 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21076 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21078 + if (pin && pin->parent)
21079 + return au_h_dptr(pin->parent, pin->bindex);
21083 +void au_unpin(struct au_pin *p)
21086 + au_pin_hdir_unlock(p);
21087 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21088 + vfsub_mnt_drop_write(p->h_mnt);
21092 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21093 + di_read_unlock(p->parent, AuLock_IR);
21094 + iput(p->hdir->hi_inode);
21096 + p->parent = NULL;
21099 + /* do not clear p->task */
21102 +int au_do_pin(struct au_pin *p)
21105 + struct super_block *sb;
21106 + struct inode *h_dir;
21109 + sb = p->dentry->d_sb;
21110 + p->br = au_sbr(sb, p->bindex);
21111 + if (IS_ROOT(p->dentry)) {
21112 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21113 + p->h_mnt = au_br_mnt(p->br);
21114 + err = vfsub_mnt_want_write(p->h_mnt);
21115 + if (unlikely(err)) {
21116 + au_fclr_pin(p->flags, MNT_WRITE);
21123 + p->h_dentry = NULL;
21124 + if (p->bindex <= au_dbbot(p->dentry))
21125 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21127 + p->parent = dget_parent(p->dentry);
21128 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21129 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21132 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21133 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21135 + h_dir = p->hdir->hi_inode;
21139 + * if DI_LOCKED is not set, then p->parent may be different
21140 + * and h_parent can be NULL.
21142 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21144 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21145 + di_read_unlock(p->parent, AuLock_IR);
21147 + p->parent = NULL;
21151 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21152 + p->h_mnt = au_br_mnt(p->br);
21153 + err = vfsub_mnt_want_write(p->h_mnt);
21154 + if (unlikely(err)) {
21155 + au_fclr_pin(p->flags, MNT_WRITE);
21156 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21157 + di_read_unlock(p->parent, AuLock_IR);
21159 + p->parent = NULL;
21165 + err = au_pin_hdir_lock(p);
21167 + goto out; /* success */
21172 + pr_err("err %d\n", err);
21173 + err = au_busy_or_stale();
21178 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21179 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21180 + unsigned int udba, unsigned char flags)
21182 + p->dentry = dentry;
21184 + p->lsc_di = lsc_di;
21185 + p->lsc_hi = lsc_hi;
21186 + p->flags = flags;
21187 + p->bindex = bindex;
21189 + p->parent = NULL;
21193 + p->h_dentry = NULL;
21194 + p->h_parent = NULL;
21196 + p->task = current;
21199 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21200 + unsigned int udba, unsigned char flags)
21202 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21204 + return au_do_pin(pin);
21207 +/* ---------------------------------------------------------------------- */
21210 + * ->setattr() and ->getattr() are called in various cases.
21211 + * chmod, stat: dentry is revalidated.
21212 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21214 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21216 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21217 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21220 + struct dentry *parent;
21223 + if (au_digen_test(dentry, sigen)) {
21224 + parent = dget_parent(dentry);
21225 + di_read_lock_parent(parent, AuLock_IR);
21226 + err = au_refresh_dentry(dentry, parent);
21227 + di_read_unlock(parent, AuLock_IR);
21235 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21236 + struct au_icpup_args *a)
21240 + aufs_bindex_t btop, ibtop;
21241 + struct dentry *hi_wh, *parent;
21242 + struct inode *inode;
21243 + struct au_wr_dir_args wr_dir_args = {
21244 + .force_btgt = -1,
21248 + if (d_is_dir(dentry))
21249 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21250 + /* plink or hi_wh() case */
21251 + btop = au_dbtop(dentry);
21252 + inode = d_inode(dentry);
21253 + ibtop = au_ibtop(inode);
21254 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21255 + wr_dir_args.force_btgt = ibtop;
21256 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21257 + if (unlikely(err < 0))
21261 + au_fset_icpup(a->flags, DID_CPUP);
21264 + a->pin_flags = AuPin_MNT_WRITE;
21266 + if (!IS_ROOT(dentry)) {
21267 + au_fset_pin(a->pin_flags, DI_LOCKED);
21268 + parent = dget_parent(dentry);
21269 + di_write_lock_parent(parent);
21272 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21273 + if (unlikely(err))
21277 + a->h_path.dentry = au_h_dptr(dentry, btop);
21278 + a->h_inode = d_inode(a->h_path.dentry);
21279 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21280 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21281 + if (ia->ia_size < i_size_read(a->h_inode))
21282 + sz = ia->ia_size;
21283 + inode_unlock_shared(a->h_inode);
21287 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21288 + hi_wh = au_hi_wh(inode, a->btgt);
21290 + struct au_cp_generic cpg = {
21291 + .dentry = dentry,
21297 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21298 + if (unlikely(err))
21300 + hi_wh = au_hi_wh(inode, a->btgt);
21301 + /* todo: revalidate hi_wh? */
21306 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21307 + di_downgrade_lock(parent, AuLock_IR);
21311 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21312 + goto out; /* success */
21314 + if (!d_unhashed(dentry)) {
21315 + struct au_cp_generic cpg = {
21316 + .dentry = dentry,
21321 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21323 + err = au_sio_cpup_simple(&cpg);
21325 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21326 + } else if (!hi_wh)
21327 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21329 + a->h_path.dentry = hi_wh; /* do not dget here */
21332 + a->h_inode = d_inode(a->h_path.dentry);
21334 + goto out; /* success */
21335 + au_unpin(&a->pin);
21338 + di_write_unlock(parent);
21343 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21347 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21350 + struct inode *inode, *delegated;
21351 + struct super_block *sb;
21352 + struct file *file;
21353 + struct au_icpup_args *a;
21355 + inode = d_inode(dentry);
21356 + IMustLock(inode);
21358 + err = setattr_prepare(dentry, ia);
21359 + if (unlikely(err))
21363 + a = kzalloc(sizeof(*a), GFP_NOFS);
21364 + if (unlikely(!a))
21367 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21368 + ia->ia_valid &= ~ATTR_MODE;
21371 + sb = dentry->d_sb;
21372 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21373 + if (unlikely(err))
21376 + if (ia->ia_valid & ATTR_FILE) {
21377 + /* currently ftruncate(2) only */
21378 + AuDebugOn(!d_is_reg(dentry));
21379 + file = ia->ia_file;
21380 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21382 + if (unlikely(err))
21384 + ia->ia_file = au_hf_top(file);
21385 + a->udba = AuOpt_UDBA_NONE;
21387 + /* fchmod() doesn't pass ia_file */
21388 + a->udba = au_opt_udba(sb);
21389 + di_write_lock_child(dentry);
21390 + /* no d_unlinked(), to set UDBA_NONE for root */
21391 + if (d_unhashed(dentry))
21392 + a->udba = AuOpt_UDBA_NONE;
21393 + if (a->udba != AuOpt_UDBA_NONE) {
21394 + AuDebugOn(IS_ROOT(dentry));
21395 + err = au_reval_for_attr(dentry, au_sigen(sb));
21396 + if (unlikely(err))
21401 + err = au_pin_and_icpup(dentry, ia, a);
21402 + if (unlikely(err < 0))
21404 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21405 + ia->ia_file = NULL;
21406 + ia->ia_valid &= ~ATTR_FILE;
21409 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21410 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21411 + == (ATTR_MODE | ATTR_CTIME)) {
21412 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21413 + if (unlikely(err))
21415 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21416 + && (ia->ia_valid & ATTR_CTIME)) {
21417 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21418 + if (unlikely(err))
21422 + if (ia->ia_valid & ATTR_SIZE) {
21425 + if (ia->ia_size < i_size_read(inode))
21427 + truncate_setsize(inode, ia->ia_size);
21430 + if (ia->ia_valid & ATTR_FILE)
21432 + inode_unlock(a->h_inode);
21433 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21434 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21436 + delegated = NULL;
21438 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21440 + err = break_deleg_wait(&delegated);
21448 + * regardless aufs 'acl' option setting.
21449 + * why don't all acl-aware fs call this func from their ->setattr()?
21451 + if (!err && (ia->ia_valid & ATTR_MODE))
21452 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21454 + au_cpup_attr_changeable(inode);
21457 + inode_unlock(a->h_inode);
21458 + au_unpin(&a->pin);
21459 + if (unlikely(err))
21460 + au_update_dbtop(dentry);
21462 + di_write_unlock(dentry);
21464 + fi_write_unlock(file);
21465 + ia->ia_file = file;
21466 + ia->ia_valid |= ATTR_FILE;
21469 + si_read_unlock(sb);
21477 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21478 +static int au_h_path_to_set_attr(struct dentry *dentry,
21479 + struct au_icpup_args *a, struct path *h_path)
21482 + struct super_block *sb;
21484 + sb = dentry->d_sb;
21485 + a->udba = au_opt_udba(sb);
21486 + /* no d_unlinked(), to set UDBA_NONE for root */
21487 + if (d_unhashed(dentry))
21488 + a->udba = AuOpt_UDBA_NONE;
21489 + if (a->udba != AuOpt_UDBA_NONE) {
21490 + AuDebugOn(IS_ROOT(dentry));
21491 + err = au_reval_for_attr(dentry, au_sigen(sb));
21492 + if (unlikely(err))
21495 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21496 + if (unlikely(err < 0))
21499 + h_path->dentry = a->h_path.dentry;
21500 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21506 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21507 + struct au_sxattr *arg)
21510 + struct path h_path;
21511 + struct super_block *sb;
21512 + struct au_icpup_args *a;
21513 + struct inode *h_inode;
21515 + IMustLock(inode);
21518 + a = kzalloc(sizeof(*a), GFP_NOFS);
21519 + if (unlikely(!a))
21522 + sb = dentry->d_sb;
21523 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21524 + if (unlikely(err))
21527 + h_path.dentry = NULL; /* silence gcc */
21528 + di_write_lock_child(dentry);
21529 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21530 + if (unlikely(err))
21533 + inode_unlock(a->h_inode);
21534 + switch (arg->type) {
21535 + case AU_XATTR_SET:
21536 + AuDebugOn(d_is_negative(h_path.dentry));
21537 + err = vfsub_setxattr(h_path.dentry,
21538 + arg->u.set.name, arg->u.set.value,
21539 + arg->u.set.size, arg->u.set.flags);
21542 + err = -EOPNOTSUPP;
21543 + h_inode = d_inode(h_path.dentry);
21544 + if (h_inode->i_op->set_acl)
21545 + /* this will call posix_acl_update_mode */
21546 + err = h_inode->i_op->set_acl(h_inode,
21547 + arg->u.acl_set.acl,
21548 + arg->u.acl_set.type);
21552 + au_cpup_attr_timesizes(inode);
21554 + au_unpin(&a->pin);
21555 + if (unlikely(err))
21556 + au_update_dbtop(dentry);
21559 + di_write_unlock(dentry);
21560 + si_read_unlock(sb);
21569 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21570 + unsigned int nlink)
21574 + inode->i_mode = st->mode;
21575 + /* don't i_[ug]id_write() here */
21576 + inode->i_uid = st->uid;
21577 + inode->i_gid = st->gid;
21578 + inode->i_atime = st->atime;
21579 + inode->i_mtime = st->mtime;
21580 + inode->i_ctime = st->ctime;
21582 + au_cpup_attr_nlink(inode, /*force*/0);
21583 + if (S_ISDIR(inode->i_mode)) {
21584 + n = inode->i_nlink;
21587 + smp_mb(); /* for i_nlink */
21588 + /* 0 can happen */
21589 + set_nlink(inode, n);
21592 + spin_lock(&inode->i_lock);
21593 + inode->i_blocks = st->blocks;
21594 + i_size_write(inode, st->size);
21595 + spin_unlock(&inode->i_lock);
21599 + * common routine for aufs_getattr() and au_getxattr().
21600 + * returns zero or negative (an error).
21601 + * @dentry will be read-locked in success.
21603 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21604 + struct path *h_path, int locked)
21607 + unsigned int mnt_flags, sigen;
21608 + unsigned char udba_none;
21609 + aufs_bindex_t bindex;
21610 + struct super_block *sb, *h_sb;
21612 + h_path->mnt = NULL;
21613 + h_path->dentry = NULL;
21616 + sb = dentry->d_sb;
21617 + mnt_flags = au_mntflags(sb);
21618 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21620 + if (unlikely(locked))
21621 + goto body; /* skip locking dinfo */
21623 + /* support fstat(2) */
21624 + if (!d_unlinked(dentry) && !udba_none) {
21625 + sigen = au_sigen(sb);
21626 + err = au_digen_test(dentry, sigen);
21628 + di_read_lock_child(dentry, AuLock_IR);
21629 + err = au_dbrange_test(dentry);
21630 + if (unlikely(err)) {
21631 + di_read_unlock(dentry, AuLock_IR);
21635 + AuDebugOn(IS_ROOT(dentry));
21636 + di_write_lock_child(dentry);
21637 + err = au_dbrange_test(dentry);
21639 + err = au_reval_for_attr(dentry, sigen);
21641 + di_downgrade_lock(dentry, AuLock_IR);
21643 + di_write_unlock(dentry);
21648 + di_read_lock_child(dentry, AuLock_IR);
21652 + inode = d_inode(dentry);
21653 + if (unlikely(!inode))
21656 + bindex = au_ibtop(inode);
21657 + h_path->mnt = au_sbr_mnt(sb, bindex);
21658 + h_sb = h_path->mnt->mnt_sb;
21660 + && !au_test_fs_bad_iattr(h_sb)
21662 + goto out; /* success */
21664 + if (au_dbtop(dentry) == bindex)
21665 + h_path->dentry = au_h_dptr(dentry, bindex);
21666 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21667 + h_path->dentry = au_plink_lkup(inode, bindex);
21668 + if (IS_ERR(h_path->dentry))
21669 + /* pretending success */
21670 + h_path->dentry = NULL;
21672 + dput(h_path->dentry);
21679 +static int aufs_getattr(const struct path *path, struct kstat *st,
21680 + u32 request, unsigned int query)
21683 + unsigned char positive;
21684 + struct path h_path;
21685 + struct dentry *dentry;
21686 + struct inode *inode;
21687 + struct super_block *sb;
21689 + dentry = path->dentry;
21690 + inode = d_inode(dentry);
21691 + sb = dentry->d_sb;
21692 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21693 + if (unlikely(err))
21695 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21697 + if (unlikely(err))
21699 + if (unlikely(!h_path.dentry))
21700 + /* illegally overlapped or something */
21701 + goto out_fill; /* pretending success */
21703 + positive = d_is_positive(h_path.dentry);
21705 + /* no vfsub version */
21706 + err = vfs_getattr(&h_path, st, request, query);
21709 + au_refresh_iattr(inode, st,
21710 + d_inode(h_path.dentry)->i_nlink);
21711 + goto out_fill; /* success */
21717 + generic_fillattr(inode, st);
21719 + di_read_unlock(dentry, AuLock_IR);
21721 + si_read_unlock(sb);
21727 +/* ---------------------------------------------------------------------- */
21729 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21730 + struct delayed_call *done)
21733 + struct dentry *h_dentry;
21734 + struct inode *h_inode;
21736 + aufs_bindex_t bindex;
21738 + ret = NULL; /* suppress a warning */
21743 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21744 + if (unlikely(err))
21747 + err = au_d_hashed_positive(dentry);
21748 + if (unlikely(err))
21752 + inode = d_inode(dentry);
21753 + bindex = au_ibtop(inode);
21754 + h_inode = au_h_iptr(inode, bindex);
21755 + if (unlikely(!h_inode->i_op->get_link))
21760 + if (au_dbtop(dentry) <= bindex) {
21761 + h_dentry = au_h_dptr(dentry, bindex);
21766 + h_dentry = d_find_any_alias(h_inode);
21767 + if (IS_ERR(h_dentry)) {
21768 + err = PTR_ERR(h_dentry);
21772 + if (unlikely(!h_dentry))
21776 + AuDbg("%ps\n", h_inode->i_op->get_link);
21777 + AuDbgDentry(h_dentry);
21778 + ret = vfs_get_link(h_dentry, done);
21781 + err = PTR_ERR(ret);
21784 + aufs_read_unlock(dentry, AuLock_IR);
21786 + if (unlikely(err))
21787 + ret = ERR_PTR(err);
21788 + AuTraceErrPtr(ret);
21792 +/* ---------------------------------------------------------------------- */
21794 +static int au_is_special(struct inode *inode)
21796 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21799 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21803 + aufs_bindex_t bindex;
21804 + struct super_block *sb;
21805 + struct inode *h_inode;
21806 + struct vfsmount *h_mnt;
21808 + sb = inode->i_sb;
21809 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21810 + "unexpected s_flags 0x%lx", sb->s_flags);
21812 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21814 + si_read_lock(sb, AuLock_FLUSH);
21815 + ii_write_lock_child(inode);
21818 + bindex = au_ibtop(inode);
21819 + h_inode = au_h_iptr(inode, bindex);
21820 + if (!au_test_ro(sb, bindex, inode)) {
21821 + h_mnt = au_sbr_mnt(sb, bindex);
21822 + err = vfsub_mnt_want_write(h_mnt);
21824 + err = vfsub_update_time(h_inode, ts, flags);
21825 + vfsub_mnt_drop_write(h_mnt);
21827 + } else if (au_is_special(h_inode)) {
21829 + * Never copy-up here.
21830 + * These special files may already be opened and used for
21831 + * communicating. If we copied it up, then the communication
21832 + * would be corrupted.
21834 + AuWarn1("timestamps for i%lu are ignored "
21835 + "since it is on readonly branch (hi%lu).\n",
21836 + inode->i_ino, h_inode->i_ino);
21837 + } else if (flags & ~S_ATIME) {
21839 + AuIOErr1("unexpected flags 0x%x\n", flags);
21844 + au_cpup_attr_timesizes(inode);
21845 + ii_write_unlock(inode);
21846 + si_read_unlock(sb);
21849 + if (!err && (flags & S_VERSION))
21850 + inode_inc_iversion(inode);
21855 +/* ---------------------------------------------------------------------- */
21857 +/* no getattr version will be set by module.c:aufs_init() */
21858 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21860 + [AuIop_SYMLINK] = {
21861 + .permission = aufs_permission,
21862 +#ifdef CONFIG_FS_POSIX_ACL
21863 + .get_acl = aufs_get_acl,
21864 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21867 + .setattr = aufs_setattr,
21868 + .getattr = aufs_getattr,
21870 +#ifdef CONFIG_AUFS_XATTR
21871 + .listxattr = aufs_listxattr,
21874 + .get_link = aufs_get_link,
21876 + /* .update_time = aufs_update_time */
21879 + .create = aufs_create,
21880 + .lookup = aufs_lookup,
21881 + .link = aufs_link,
21882 + .unlink = aufs_unlink,
21883 + .symlink = aufs_symlink,
21884 + .mkdir = aufs_mkdir,
21885 + .rmdir = aufs_rmdir,
21886 + .mknod = aufs_mknod,
21887 + .rename = aufs_rename,
21889 + .permission = aufs_permission,
21890 +#ifdef CONFIG_FS_POSIX_ACL
21891 + .get_acl = aufs_get_acl,
21892 + .set_acl = aufs_set_acl,
21895 + .setattr = aufs_setattr,
21896 + .getattr = aufs_getattr,
21898 +#ifdef CONFIG_AUFS_XATTR
21899 + .listxattr = aufs_listxattr,
21902 + .update_time = aufs_update_time,
21903 + .atomic_open = aufs_atomic_open,
21904 + .tmpfile = aufs_tmpfile
21906 + [AuIop_OTHER] = {
21907 + .permission = aufs_permission,
21908 +#ifdef CONFIG_FS_POSIX_ACL
21909 + .get_acl = aufs_get_acl,
21910 + .set_acl = aufs_set_acl,
21913 + .setattr = aufs_setattr,
21914 + .getattr = aufs_getattr,
21916 +#ifdef CONFIG_AUFS_XATTR
21917 + .listxattr = aufs_listxattr,
21920 + .update_time = aufs_update_time
21923 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21924 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21925 +++ linux/fs/aufs/i_op_del.c 2021-02-24 13:33:42.744347058 +0100
21927 +// SPDX-License-Identifier: GPL-2.0
21929 + * Copyright (C) 2005-2020 Junjiro R. Okajima
21931 + * This program, aufs is free software; you can redistribute it and/or modify
21932 + * it under the terms of the GNU General Public License as published by
21933 + * the Free Software Foundation; either version 2 of the License, or
21934 + * (at your option) any later version.
21936 + * This program is distributed in the hope that it will be useful,
21937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21939 + * GNU General Public License for more details.
21941 + * You should have received a copy of the GNU General Public License
21942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21946 + * inode operations (del entry)
21949 +#include <linux/iversion.h>
21953 + * decide if a new whiteout for @dentry is necessary or not.
21954 + * when it is necessary, prepare the parent dir for the upper branch whose
21955 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21956 + * be done by caller.
21958 + * 0: wh is unnecessary
21959 + * plus: wh is necessary
21962 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21964 + int need_wh, err;
21965 + aufs_bindex_t btop;
21966 + struct super_block *sb;
21968 + sb = dentry->d_sb;
21969 + btop = au_dbtop(dentry);
21970 + if (*bcpup < 0) {
21972 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21973 + err = AuWbrCopyup(au_sbi(sb), dentry);
21975 + if (unlikely(err < 0))
21979 + AuDebugOn(btop < *bcpup
21980 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
21981 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
21983 + if (*bcpup != btop) {
21984 + err = au_cpup_dirs(dentry, *bcpup);
21985 + if (unlikely(err))
21989 + struct au_dinfo *dinfo, *tmp;
21991 + need_wh = -ENOMEM;
21992 + dinfo = au_di(dentry);
21993 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
21995 + au_di_cp(tmp, dinfo);
21996 + au_di_swap(tmp, dinfo);
21997 + /* returns the number of positive dentries */
21998 + need_wh = au_lkup_dentry(dentry, btop + 1,
21999 + /* AuLkup_IGNORE_PERM */ 0);
22000 + au_di_swap(tmp, dinfo);
22001 + au_rw_write_unlock(&tmp->di_rwsem);
22005 + AuDbg("need_wh %d\n", need_wh);
22013 + * simple tests for the del-entry operations.
22014 + * following the checks in vfs, plus the parent-child relationship.
22016 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22017 + struct dentry *h_parent, int isdir)
22021 + struct dentry *h_dentry, *h_latest;
22022 + struct inode *h_inode;
22024 + h_dentry = au_h_dptr(dentry, bindex);
22025 + if (d_really_is_positive(dentry)) {
22027 + if (unlikely(d_is_negative(h_dentry)))
22029 + h_inode = d_inode(h_dentry);
22030 + if (unlikely(!h_inode->i_nlink))
22033 + h_mode = h_inode->i_mode;
22036 + if (unlikely(S_ISDIR(h_mode)))
22038 + } else if (unlikely(!S_ISDIR(h_mode))) {
22043 + /* rename(2) case */
22045 + if (unlikely(d_is_positive(h_dentry)))
22050 + /* expected parent dir is locked */
22051 + if (unlikely(h_parent != h_dentry->d_parent))
22056 + * rmdir a dir may break the consistency on some filesystem.
22057 + * let's try heavy test.
22060 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22061 + && au_test_h_perm(d_inode(h_parent),
22062 + MAY_EXEC | MAY_WRITE)))
22065 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22067 + if (IS_ERR(h_latest))
22069 + if (h_latest == h_dentry)
22078 + * decide the branch where we operate for @dentry. the branch index will be set
22079 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22080 + * dir for reverting.
22081 + * when a new whiteout is necessary, create it.
22083 +static struct dentry*
22084 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22085 + struct au_dtime *dt, struct au_pin *pin)
22087 + struct dentry *wh_dentry;
22088 + struct super_block *sb;
22089 + struct path h_path;
22090 + int err, need_wh;
22091 + unsigned int udba;
22092 + aufs_bindex_t bcpup;
22094 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22095 + wh_dentry = ERR_PTR(need_wh);
22096 + if (unlikely(need_wh < 0))
22099 + sb = dentry->d_sb;
22100 + udba = au_opt_udba(sb);
22102 + err = au_pin(pin, dentry, bcpup, udba,
22103 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22104 + wh_dentry = ERR_PTR(err);
22105 + if (unlikely(err))
22108 + h_path.dentry = au_pinned_h_parent(pin);
22109 + if (udba != AuOpt_UDBA_NONE
22110 + && au_dbtop(dentry) == bcpup) {
22111 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22112 + wh_dentry = ERR_PTR(err);
22113 + if (unlikely(err))
22117 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22118 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22119 + wh_dentry = NULL;
22121 + goto out; /* success, no need to create whiteout */
22123 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22124 + if (IS_ERR(wh_dentry))
22127 + /* returns with the parent is locked and wh_dentry is dget-ed */
22128 + goto out; /* success */
22133 + return wh_dentry;
22137 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22138 + * in order to be revertible and save time for removing many child whiteouts
22140 + * returns 1 when there are too many child whiteout and caller should remove
22141 + * them asynchronously. returns 0 when the number of children is enough small to
22142 + * remove now or the branch fs is a remote fs.
22143 + * otherwise return an error.
22145 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22146 + struct au_nhash *whlist, struct inode *dir)
22148 + int rmdir_later, err, dirwh;
22149 + struct dentry *h_dentry;
22150 + struct super_block *sb;
22151 + struct inode *inode;
22153 + sb = dentry->d_sb;
22154 + SiMustAnyLock(sb);
22155 + h_dentry = au_h_dptr(dentry, bindex);
22156 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22157 + if (unlikely(err))
22160 + /* stop monitoring */
22161 + inode = d_inode(dentry);
22162 + au_hn_free(au_hi(inode, bindex));
22164 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22165 + dirwh = au_sbi(sb)->si_dirwh;
22166 + rmdir_later = (dirwh <= 1);
22167 + if (!rmdir_later)
22168 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22171 + return rmdir_later;
22174 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22175 + if (unlikely(err)) {
22176 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22177 + h_dentry, bindex, err);
22187 + * final procedure for deleting a entry.
22188 + * maintain dentry and iattr.
22190 +static void epilog(struct inode *dir, struct dentry *dentry,
22191 + aufs_bindex_t bindex)
22193 + struct inode *inode;
22195 + inode = d_inode(dentry);
22197 + inode->i_ctime = dir->i_ctime;
22199 + au_dir_ts(dir, bindex);
22200 + inode_inc_iversion(dir);
22204 + * when an error happened, remove the created whiteout and revert everything.
22206 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22207 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22208 + struct dentry *dentry, struct au_dtime *dt)
22211 + struct path h_path = {
22212 + .dentry = wh_dentry,
22213 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22216 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22218 + au_set_dbwh(dentry, bwh);
22219 + au_dtime_revert(dt);
22223 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22227 +/* ---------------------------------------------------------------------- */
22229 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22232 + aufs_bindex_t bwh, bindex, btop;
22233 + struct inode *inode, *h_dir, *delegated;
22234 + struct dentry *parent, *wh_dentry;
22235 + /* to reduce stack size */
22237 + struct au_dtime dt;
22238 + struct au_pin pin;
22239 + struct path h_path;
22245 + a = kmalloc(sizeof(*a), GFP_NOFS);
22246 + if (unlikely(!a))
22249 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22250 + if (unlikely(err))
22252 + err = au_d_hashed_positive(dentry);
22253 + if (unlikely(err))
22255 + inode = d_inode(dentry);
22256 + IMustLock(inode);
22258 + if (unlikely(d_is_dir(dentry)))
22259 + goto out_unlock; /* possible? */
22261 + btop = au_dbtop(dentry);
22262 + bwh = au_dbwh(dentry);
22264 + parent = dentry->d_parent; /* dir inode is locked */
22265 + di_write_lock_parent(parent);
22266 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22268 + err = PTR_ERR(wh_dentry);
22269 + if (IS_ERR(wh_dentry))
22272 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22273 + a->h_path.dentry = au_h_dptr(dentry, btop);
22274 + dget(a->h_path.dentry);
22275 + if (bindex == btop) {
22276 + h_dir = au_pinned_h_dir(&a->pin);
22277 + delegated = NULL;
22278 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22279 + if (unlikely(err == -EWOULDBLOCK)) {
22280 + pr_warn("cannot retry for NFSv4 delegation"
22281 + " for an internal unlink\n");
22285 + /* dir inode is locked */
22286 + h_dir = d_inode(wh_dentry->d_parent);
22287 + IMustLock(h_dir);
22292 + vfsub_drop_nlink(inode);
22293 + epilog(dir, dentry, bindex);
22295 + /* update target timestamps */
22296 + if (bindex == btop) {
22297 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22299 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22301 + /* todo: this timestamp may be reverted later */
22302 + inode->i_ctime = h_dir->i_ctime;
22303 + goto out_unpin; /* success */
22310 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22317 + au_unpin(&a->pin);
22319 + dput(a->h_path.dentry);
22321 + di_write_unlock(parent);
22323 + aufs_read_unlock(dentry, AuLock_DW);
22330 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22332 + int err, rmdir_later;
22333 + aufs_bindex_t bwh, bindex, btop;
22334 + struct inode *inode;
22335 + struct dentry *parent, *wh_dentry, *h_dentry;
22336 + struct au_whtmp_rmdir *args;
22337 + /* to reduce stack size */
22339 + struct au_dtime dt;
22340 + struct au_pin pin;
22346 + a = kmalloc(sizeof(*a), GFP_NOFS);
22347 + if (unlikely(!a))
22350 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22351 + if (unlikely(err))
22353 + err = au_alive_dir(dentry);
22354 + if (unlikely(err))
22356 + inode = d_inode(dentry);
22357 + IMustLock(inode);
22359 + if (unlikely(!d_is_dir(dentry)))
22360 + goto out_unlock; /* possible? */
22363 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22364 + if (unlikely(!args))
22367 + parent = dentry->d_parent; /* dir inode is locked */
22368 + di_write_lock_parent(parent);
22369 + err = au_test_empty(dentry, &args->whlist);
22370 + if (unlikely(err))
22373 + btop = au_dbtop(dentry);
22374 + bwh = au_dbwh(dentry);
22376 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22378 + err = PTR_ERR(wh_dentry);
22379 + if (IS_ERR(wh_dentry))
22382 + h_dentry = au_h_dptr(dentry, btop);
22385 + if (bindex == btop) {
22386 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22388 + rmdir_later = err;
22392 + /* stop monitoring */
22393 + au_hn_free(au_hi(inode, btop));
22395 + /* dir inode is locked */
22396 + IMustLock(d_inode(wh_dentry->d_parent));
22401 + vfsub_dead_dir(inode);
22402 + au_set_dbdiropq(dentry, -1);
22403 + epilog(dir, dentry, bindex);
22405 + if (rmdir_later) {
22406 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22410 + goto out_unpin; /* success */
22418 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22425 + au_unpin(&a->pin);
22429 + di_write_unlock(parent);
22431 + au_whtmp_rmdir_free(args);
22433 + aufs_read_unlock(dentry, AuLock_DW);
22440 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22441 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22442 +++ linux/fs/aufs/i_op_ren.c 2021-02-24 13:33:42.744347058 +0100
22444 +// SPDX-License-Identifier: GPL-2.0
22446 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22448 + * This program, aufs is free software; you can redistribute it and/or modify
22449 + * it under the terms of the GNU General Public License as published by
22450 + * the Free Software Foundation; either version 2 of the License, or
22451 + * (at your option) any later version.
22453 + * This program is distributed in the hope that it will be useful,
22454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22456 + * GNU General Public License for more details.
22458 + * You should have received a copy of the GNU General Public License
22459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22463 + * inode operation (rename entry)
22464 + * todo: this is crazy monster
22467 +#include <linux/iversion.h>
22470 +enum { AuSRC, AuDST, AuSrcDst };
22471 +enum { AuPARENT, AuCHILD, AuParentChild };
22473 +#define AuRen_ISDIR_SRC 1
22474 +#define AuRen_ISDIR_DST (1 << 1)
22475 +#define AuRen_ISSAMEDIR (1 << 2)
22476 +#define AuRen_WHSRC (1 << 3)
22477 +#define AuRen_WHDST (1 << 4)
22478 +#define AuRen_MNT_WRITE (1 << 5)
22479 +#define AuRen_DT_DSTDIR (1 << 6)
22480 +#define AuRen_DIROPQ_SRC (1 << 7)
22481 +#define AuRen_DIROPQ_DST (1 << 8)
22482 +#define AuRen_DIRREN (1 << 9)
22483 +#define AuRen_DROPPED_SRC (1 << 10)
22484 +#define AuRen_DROPPED_DST (1 << 11)
22485 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22486 +#define au_fset_ren(flags, name) \
22487 + do { (flags) |= AuRen_##name; } while (0)
22488 +#define au_fclr_ren(flags, name) \
22489 + do { (flags) &= ~AuRen_##name; } while (0)
22491 +#ifndef CONFIG_AUFS_DIRREN
22492 +#undef AuRen_DIRREN
22493 +#define AuRen_DIRREN 0
22496 +struct au_ren_args {
22498 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22500 + struct inode *dir, *inode;
22501 + struct au_hinode *hdir, *hinode;
22502 + struct au_dtime dt[AuParentChild];
22503 + aufs_bindex_t btop, bdiropq;
22506 +#define src_dentry sd[AuSRC].dentry
22507 +#define src_dir sd[AuSRC].dir
22508 +#define src_inode sd[AuSRC].inode
22509 +#define src_h_dentry sd[AuSRC].h_dentry
22510 +#define src_parent sd[AuSRC].parent
22511 +#define src_h_parent sd[AuSRC].h_parent
22512 +#define src_wh_dentry sd[AuSRC].wh_dentry
22513 +#define src_hdir sd[AuSRC].hdir
22514 +#define src_hinode sd[AuSRC].hinode
22515 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22516 +#define src_dt sd[AuSRC].dt
22517 +#define src_btop sd[AuSRC].btop
22518 +#define src_bdiropq sd[AuSRC].bdiropq
22520 +#define dst_dentry sd[AuDST].dentry
22521 +#define dst_dir sd[AuDST].dir
22522 +#define dst_inode sd[AuDST].inode
22523 +#define dst_h_dentry sd[AuDST].h_dentry
22524 +#define dst_parent sd[AuDST].parent
22525 +#define dst_h_parent sd[AuDST].h_parent
22526 +#define dst_wh_dentry sd[AuDST].wh_dentry
22527 +#define dst_hdir sd[AuDST].hdir
22528 +#define dst_hinode sd[AuDST].hinode
22529 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22530 +#define dst_dt sd[AuDST].dt
22531 +#define dst_btop sd[AuDST].btop
22532 +#define dst_bdiropq sd[AuDST].bdiropq
22534 + struct dentry *h_trap;
22535 + struct au_branch *br;
22536 + struct path h_path;
22537 + struct au_nhash whlist;
22538 + aufs_bindex_t btgt, src_bwh;
22541 + unsigned short auren_flags;
22542 + unsigned char flags; /* syscall parameter */
22543 + unsigned char exchange;
22546 + struct au_whtmp_rmdir *thargs;
22547 + struct dentry *h_dst;
22548 + struct au_hinode *h_root;
22551 +/* ---------------------------------------------------------------------- */
22554 + * functions for reverting.
22555 + * when an error happened in a single rename systemcall, we should revert
22556 + * everything as if nothing happened.
22557 + * we don't need to revert the copied-up/down the parent dir since they are
22561 +#define RevertFailure(fmt, ...) do { \
22562 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22563 + ##__VA_ARGS__, err, rerr); \
22567 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22570 + struct dentry *d;
22571 +#define src_or_dst(member) a->sd[idx].member
22573 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22574 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22575 + rerr = au_diropq_remove(d, a->btgt);
22576 + au_hn_inode_unlock(src_or_dst(hinode));
22577 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22579 + RevertFailure("remove diropq %pd", d);
22581 +#undef src_or_dst_
22584 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22586 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22587 + au_ren_do_rev_diropq(err, a, AuSRC);
22588 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22589 + au_ren_do_rev_diropq(err, a, AuDST);
22592 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22595 + struct inode *delegated;
22597 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22598 + a->src_h_parent);
22599 + rerr = PTR_ERR(a->h_path.dentry);
22600 + if (IS_ERR(a->h_path.dentry)) {
22601 + RevertFailure("lkup one %pd", a->src_dentry);
22605 + delegated = NULL;
22606 + rerr = vfsub_rename(a->dst_h_dir,
22607 + au_h_dptr(a->src_dentry, a->btgt),
22608 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22609 + if (unlikely(rerr == -EWOULDBLOCK)) {
22610 + pr_warn("cannot retry for NFSv4 delegation"
22611 + " for an internal rename\n");
22614 + d_drop(a->h_path.dentry);
22615 + dput(a->h_path.dentry);
22616 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22618 + RevertFailure("rename %pd", a->src_dentry);
22621 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22624 + struct inode *delegated;
22626 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22627 + a->dst_h_parent);
22628 + rerr = PTR_ERR(a->h_path.dentry);
22629 + if (IS_ERR(a->h_path.dentry)) {
22630 + RevertFailure("lkup one %pd", a->dst_dentry);
22633 + if (d_is_positive(a->h_path.dentry)) {
22634 + d_drop(a->h_path.dentry);
22635 + dput(a->h_path.dentry);
22639 + delegated = NULL;
22640 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22641 + &delegated, a->flags);
22642 + if (unlikely(rerr == -EWOULDBLOCK)) {
22643 + pr_warn("cannot retry for NFSv4 delegation"
22644 + " for an internal rename\n");
22647 + d_drop(a->h_path.dentry);
22648 + dput(a->h_path.dentry);
22650 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22652 + RevertFailure("rename %pd", a->h_dst);
22655 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22659 + a->h_path.dentry = a->src_wh_dentry;
22660 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22661 + au_set_dbwh(a->src_dentry, a->src_bwh);
22663 + RevertFailure("unlink %pd", a->src_wh_dentry);
22665 +#undef RevertFailure
22667 +/* ---------------------------------------------------------------------- */
22670 + * when we have to copyup the renaming entry, do it with the rename-target name
22671 + * in order to minimize the cost (the later actual rename is unnecessary).
22672 + * otherwise rename it on the target branch.
22674 +static int au_ren_or_cpup(struct au_ren_args *a)
22677 + struct dentry *d;
22678 + struct inode *delegated;
22680 + d = a->src_dentry;
22681 + if (au_dbtop(d) == a->btgt) {
22682 + a->h_path.dentry = a->dst_h_dentry;
22683 + AuDebugOn(au_dbtop(d) != a->btgt);
22684 + delegated = NULL;
22685 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22686 + a->dst_h_dir, &a->h_path, &delegated,
22688 + if (unlikely(err == -EWOULDBLOCK)) {
22689 + pr_warn("cannot retry for NFSv4 delegation"
22690 + " for an internal rename\n");
22696 + if (!err && a->h_dst)
22697 + /* it will be set to dinfo later */
22703 +/* cf. aufs_rmdir() */
22704 +static int au_ren_del_whtmp(struct au_ren_args *a)
22707 + struct inode *dir;
22709 + dir = a->dst_dir;
22710 + SiMustAnyLock(dir->i_sb);
22711 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22712 + au_sbi(dir->i_sb)->si_dirwh)
22713 + || au_test_fs_remote(a->h_dst->d_sb)) {
22714 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22715 + if (unlikely(err))
22716 + pr_warn("failed removing whtmp dir %pd (%d), "
22717 + "ignored.\n", a->h_dst, err);
22719 + au_nhash_wh_free(&a->thargs->whlist);
22720 + a->thargs->whlist = a->whlist;
22721 + a->whlist.nh_num = 0;
22722 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22724 + a->thargs = NULL;
22730 +/* make it 'opaque' dir. */
22731 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22734 + struct dentry *d, *diropq;
22735 +#define src_or_dst(member) a->sd[idx].member
22738 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22739 + src_or_dst(bdiropq) = au_dbdiropq(d);
22740 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22741 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22742 + diropq = au_diropq_create(d, a->btgt);
22743 + au_hn_inode_unlock(src_or_dst(hinode));
22744 + if (IS_ERR(diropq))
22745 + err = PTR_ERR(diropq);
22749 +#undef src_or_dst_
22753 +static int au_ren_diropq(struct au_ren_args *a)
22756 + unsigned char always;
22757 + struct dentry *d;
22760 + d = a->dst_dentry; /* already renamed on the branch */
22761 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22762 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22763 + && !au_ftest_ren(a->auren_flags, DIRREN)
22764 + && a->btgt != au_dbdiropq(a->src_dentry)
22765 + && (a->dst_wh_dentry
22766 + || a->btgt <= au_dbdiropq(d)
22767 + /* hide the lower to keep xino */
22768 + /* the lowers may not be a dir, but we hide them anyway */
22769 + || a->btgt < au_dbbot(d)
22772 + err = au_ren_do_diropq(a, AuSRC);
22773 + if (unlikely(err))
22775 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22777 + if (!a->exchange)
22778 + goto out; /* success */
22780 + d = a->src_dentry; /* already renamed on the branch */
22781 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22782 + && a->btgt != au_dbdiropq(a->dst_dentry)
22783 + && (a->btgt < au_dbdiropq(d)
22784 + || a->btgt < au_dbbot(d)
22786 + AuDbgDentry(a->src_dentry);
22787 + AuDbgDentry(a->dst_dentry);
22788 + err = au_ren_do_diropq(a, AuDST);
22789 + if (unlikely(err))
22790 + goto out_rev_src;
22791 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22793 + goto out; /* success */
22796 + AuDbg("err %d, reverting src\n", err);
22797 + au_ren_rev_diropq(err, a);
22802 +static int do_rename(struct au_ren_args *a)
22805 + struct dentry *d, *h_d;
22807 + if (!a->exchange) {
22808 + /* prepare workqueue args for asynchronous rmdir */
22809 + h_d = a->dst_h_dentry;
22810 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22811 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22812 + && d_is_positive(h_d)) {
22814 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22816 + if (unlikely(!a->thargs))
22818 + a->h_dst = dget(h_d);
22821 + /* create whiteout for src_dentry */
22822 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22823 + a->src_bwh = au_dbwh(a->src_dentry);
22824 + AuDebugOn(a->src_bwh >= 0);
22825 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22826 + a->src_h_parent);
22827 + err = PTR_ERR(a->src_wh_dentry);
22828 + if (IS_ERR(a->src_wh_dentry))
22832 + /* lookup whiteout for dentry */
22833 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22834 + h_d = au_wh_lkup(a->dst_h_parent,
22835 + &a->dst_dentry->d_name, a->br);
22836 + err = PTR_ERR(h_d);
22839 + if (d_is_negative(h_d))
22842 + a->dst_wh_dentry = h_d;
22845 + /* rename dentry to tmpwh */
22847 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22848 + if (unlikely(err))
22851 + d = a->dst_dentry;
22852 + au_set_h_dptr(d, a->btgt, NULL);
22853 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22854 + if (unlikely(err))
22856 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22860 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22861 +#if 0 /* debugging */
22862 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22863 + && d_is_positive(a->dst_h_dentry)
22864 + && a->src_btop != a->btgt);
22867 + /* rename by vfs_rename or cpup */
22868 + err = au_ren_or_cpup(a);
22869 + if (unlikely(err))
22870 + /* leave the copied-up one */
22873 + /* make dir opaque */
22874 + err = au_ren_diropq(a);
22875 + if (unlikely(err))
22878 + /* update target timestamps */
22879 + if (a->exchange) {
22880 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22881 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22882 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22883 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22885 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22886 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22887 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22888 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22890 + if (!a->exchange) {
22891 + /* remove whiteout for dentry */
22892 + if (a->dst_wh_dentry) {
22893 + a->h_path.dentry = a->dst_wh_dentry;
22894 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22896 + if (unlikely(err))
22900 + /* remove whtmp */
22902 + au_ren_del_whtmp(a); /* ignore this error */
22904 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22907 + goto out_success;
22910 + au_ren_rev_diropq(err, a);
22912 + au_ren_rev_rename(err, a);
22916 + au_ren_rev_whtmp(err, a);
22918 + dput(a->dst_wh_dentry);
22919 + a->dst_wh_dentry = NULL;
22921 + if (a->src_wh_dentry)
22922 + au_ren_rev_whsrc(err, a);
22924 + dput(a->src_wh_dentry);
22925 + dput(a->dst_wh_dentry);
22929 + au_whtmp_rmdir_free(a->thargs);
22930 + a->thargs = NULL;
22936 +/* ---------------------------------------------------------------------- */
22939 + * test if @dentry dir can be rename destination or not.
22940 + * success means, it is a logically empty dir.
22942 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22944 + return au_test_empty(dentry, whlist);
22948 + * test if @a->src_dentry dir can be rename source or not.
22949 + * if it can, return 0.
22951 + * - it is a logically empty dir.
22952 + * - or, it exists on writable branch and has no children including whiteouts
22953 + * on the lower branch unless DIRREN is on.
22955 +static int may_rename_srcdir(struct au_ren_args *a)
22958 + unsigned int rdhash;
22959 + aufs_bindex_t btop, btgt;
22960 + struct dentry *dentry;
22961 + struct super_block *sb;
22962 + struct au_sbinfo *sbinfo;
22964 + dentry = a->src_dentry;
22965 + sb = dentry->d_sb;
22966 + sbinfo = au_sbi(sb);
22967 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22968 + au_fset_ren(a->auren_flags, DIRREN);
22971 + btop = au_dbtop(dentry);
22972 + if (btop != btgt) {
22973 + struct au_nhash whlist;
22975 + SiMustAnyLock(sb);
22976 + rdhash = sbinfo->si_rdhash;
22978 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
22980 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
22981 + if (unlikely(err))
22983 + err = au_test_empty(dentry, &whlist);
22984 + au_nhash_wh_free(&whlist);
22988 + if (btop == au_dbtaildir(dentry))
22989 + return 0; /* success */
22991 + err = au_test_empty_lower(dentry);
22994 + if (err == -ENOTEMPTY) {
22995 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
22998 + AuWarn1("renaming dir who has child(ren) on multiple "
22999 + "branches, is not supported\n");
23006 +/* side effect: sets whlist and h_dentry */
23007 +static int au_ren_may_dir(struct au_ren_args *a)
23010 + unsigned int rdhash;
23011 + struct dentry *d;
23013 + d = a->dst_dentry;
23014 + SiMustAnyLock(d->d_sb);
23017 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23018 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23020 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23021 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23022 + if (unlikely(err))
23025 + if (!a->exchange) {
23026 + au_set_dbtop(d, a->dst_btop);
23027 + err = may_rename_dstdir(d, &a->whlist);
23028 + au_set_dbtop(d, a->btgt);
23030 + err = may_rename_srcdir(a);
23032 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23033 + if (unlikely(err))
23036 + d = a->src_dentry;
23037 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23038 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23039 + err = may_rename_srcdir(a);
23040 + if (unlikely(err)) {
23041 + au_nhash_wh_free(&a->whlist);
23042 + a->whlist.nh_num = 0;
23049 +/* ---------------------------------------------------------------------- */
23052 + * simple tests for rename.
23053 + * following the checks in vfs, plus the parent-child relationship.
23055 +static int au_may_ren(struct au_ren_args *a)
23058 + struct inode *h_inode;
23060 + if (a->src_btop == a->btgt) {
23061 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23062 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23063 + if (unlikely(err))
23066 + if (unlikely(a->src_h_dentry == a->h_trap))
23071 + if (a->dst_btop != a->btgt)
23074 + err = -ENOTEMPTY;
23075 + if (unlikely(a->dst_h_dentry == a->h_trap))
23079 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23080 + if (d_really_is_negative(a->dst_dentry)) {
23081 + if (d_is_negative(a->dst_h_dentry))
23082 + err = au_may_add(a->dst_dentry, a->btgt,
23083 + a->dst_h_parent, isdir);
23085 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23087 + h_inode = d_inode(a->dst_h_dentry);
23088 + if (h_inode->i_nlink)
23089 + err = au_may_del(a->dst_dentry, a->btgt,
23090 + a->dst_h_parent, isdir);
23094 + if (unlikely(err == -ENOENT || err == -EEXIST))
23100 +/* ---------------------------------------------------------------------- */
23105 + * - src_dir and dir by lock_rename()
23106 + * - inode if exists
23109 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23111 + * + di_write_lock2_child()
23112 + * + di_write_lock_child()
23113 + * + ii_write_lock_child()
23114 + * + di_write_lock_child2()
23115 + * + ii_write_lock_child2()
23116 + * + src_parent and parent
23117 + * + di_write_lock_parent()
23118 + * + ii_write_lock_parent()
23119 + * + di_write_lock_parent2()
23120 + * + ii_write_lock_parent2()
23121 + * + lower src_dir and dir by vfsub_lock_rename()
23122 + * + verify the every relationships between child and parent. if any
23123 + * of them failed, unlock all and return -EBUSY.
23125 +static void au_ren_unlock(struct au_ren_args *a)
23127 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23128 + a->dst_h_parent, a->dst_hdir);
23129 + if (au_ftest_ren(a->auren_flags, DIRREN)
23131 + au_hn_inode_unlock(a->h_root);
23132 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23133 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23136 +static int au_ren_lock(struct au_ren_args *a)
23139 + unsigned int udba;
23142 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23143 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23144 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23145 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23147 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23148 + if (unlikely(err))
23150 + au_fset_ren(a->auren_flags, MNT_WRITE);
23151 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23152 + struct dentry *root;
23153 + struct inode *dir;
23156 + * sbinfo is already locked, so this ii_read_lock is
23157 + * unnecessary. but our debugging feature checks it.
23159 + root = a->src_inode->i_sb->s_root;
23160 + if (root != a->src_parent && root != a->dst_parent) {
23161 + dir = d_inode(root);
23162 + ii_read_lock_parent3(dir);
23163 + a->h_root = au_hi(dir, a->btgt);
23164 + ii_read_unlock(dir);
23165 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23168 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23169 + a->dst_h_parent, a->dst_hdir);
23170 + udba = au_opt_udba(a->src_dentry->d_sb);
23171 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23172 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23173 + err = au_busy_or_stale();
23174 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23175 + err = au_h_verify(a->src_h_dentry, udba,
23176 + d_inode(a->src_h_parent), a->src_h_parent,
23178 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23179 + err = au_h_verify(a->dst_h_dentry, udba,
23180 + d_inode(a->dst_h_parent), a->dst_h_parent,
23183 + goto out; /* success */
23185 + err = au_busy_or_stale();
23186 + au_ren_unlock(a);
23192 +/* ---------------------------------------------------------------------- */
23194 +static void au_ren_refresh_dir(struct au_ren_args *a)
23196 + struct inode *dir;
23198 + dir = a->dst_dir;
23199 + inode_inc_iversion(dir);
23200 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23201 + /* is this updating defined in POSIX? */
23202 + au_cpup_attr_timesizes(a->src_inode);
23203 + au_cpup_attr_nlink(dir, /*force*/1);
23205 + au_dir_ts(dir, a->btgt);
23207 + if (a->exchange) {
23208 + dir = a->src_dir;
23209 + inode_inc_iversion(dir);
23210 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23211 + /* is this updating defined in POSIX? */
23212 + au_cpup_attr_timesizes(a->dst_inode);
23213 + au_cpup_attr_nlink(dir, /*force*/1);
23215 + au_dir_ts(dir, a->btgt);
23218 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23221 + dir = a->src_dir;
23222 + inode_inc_iversion(dir);
23223 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23224 + au_cpup_attr_nlink(dir, /*force*/1);
23225 + au_dir_ts(dir, a->btgt);
23228 +static void au_ren_refresh(struct au_ren_args *a)
23230 + aufs_bindex_t bbot, bindex;
23231 + struct dentry *d, *h_d;
23232 + struct inode *i, *h_i;
23233 + struct super_block *sb;
23235 + d = a->dst_dentry;
23238 + /* already dget-ed by au_ren_or_cpup() */
23239 + au_set_h_dptr(d, a->btgt, a->h_dst);
23241 + i = a->dst_inode;
23243 + if (!a->exchange) {
23244 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23245 + vfsub_drop_nlink(i);
23247 + vfsub_dead_dir(i);
23248 + au_cpup_attr_timesizes(i);
23250 + au_update_dbrange(d, /*do_put_zero*/1);
23252 + au_cpup_attr_nlink(i, /*force*/1);
23255 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23256 + au_set_h_dptr(d, bindex, NULL);
23257 + bbot = au_dbbot(d);
23258 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23259 + au_set_h_dptr(d, bindex, NULL);
23260 + au_update_dbrange(d, /*do_put_zero*/0);
23264 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23265 + d_drop(a->src_dentry);
23266 + if (au_ftest_ren(a->auren_flags, DIRREN))
23267 + au_set_dbwh(a->src_dentry, -1);
23271 + d = a->src_dentry;
23272 + au_set_dbwh(d, -1);
23273 + bbot = au_dbbot(d);
23274 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23275 + h_d = au_h_dptr(d, bindex);
23277 + au_set_h_dptr(d, bindex, NULL);
23279 + au_set_dbbot(d, a->btgt);
23282 + i = a->src_inode;
23283 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23284 + return; /* success */
23286 + bbot = au_ibbot(i);
23287 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23288 + h_i = au_h_iptr(i, bindex);
23290 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23291 + /* ignore this error */
23292 + au_set_h_iptr(i, bindex, NULL, 0);
23295 + au_set_ibbot(i, a->btgt);
23298 +/* ---------------------------------------------------------------------- */
23300 +/* mainly for link(2) and rename(2) */
23301 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23303 + aufs_bindex_t bdiropq, bwh;
23304 + struct dentry *parent;
23305 + struct au_branch *br;
23307 + parent = dentry->d_parent;
23308 + IMustLock(d_inode(parent)); /* dir is locked */
23310 + bdiropq = au_dbdiropq(parent);
23311 + bwh = au_dbwh(dentry);
23312 + br = au_sbr(dentry->d_sb, btgt);
23313 + if (au_br_rdonly(br)
23314 + || (0 <= bdiropq && bdiropq < btgt)
23315 + || (0 <= bwh && bwh < btgt))
23318 + AuDbg("btgt %d\n", btgt);
23322 +/* sets src_btop, dst_btop and btgt */
23323 +static int au_ren_wbr(struct au_ren_args *a)
23326 + struct au_wr_dir_args wr_dir_args = {
23327 + /* .force_btgt = -1, */
23328 + .flags = AuWrDir_ADD_ENTRY
23331 + a->src_btop = au_dbtop(a->src_dentry);
23332 + a->dst_btop = au_dbtop(a->dst_dentry);
23333 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23334 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23335 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23336 + wr_dir_args.force_btgt = a->src_btop;
23337 + if (a->dst_inode && a->dst_btop < a->src_btop)
23338 + wr_dir_args.force_btgt = a->dst_btop;
23339 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23340 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23343 + au_update_dbtop(a->dst_dentry);
23348 +static void au_ren_dt(struct au_ren_args *a)
23350 + a->h_path.dentry = a->src_h_parent;
23351 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23352 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23353 + a->h_path.dentry = a->dst_h_parent;
23354 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23357 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23358 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23362 + a->h_path.dentry = a->src_h_dentry;
23363 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23364 + if (d_is_positive(a->dst_h_dentry)) {
23365 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23366 + a->h_path.dentry = a->dst_h_dentry;
23367 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23371 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23373 + struct dentry *h_d;
23374 + struct inode *h_inode;
23376 + au_dtime_revert(a->src_dt + AuPARENT);
23377 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23378 + au_dtime_revert(a->dst_dt + AuPARENT);
23380 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23381 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23382 + h_inode = d_inode(h_d);
23383 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23384 + au_dtime_revert(a->src_dt + AuCHILD);
23385 + inode_unlock(h_inode);
23387 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23388 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23389 + h_inode = d_inode(h_d);
23390 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23391 + au_dtime_revert(a->dst_dt + AuCHILD);
23392 + inode_unlock(h_inode);
23397 +/* ---------------------------------------------------------------------- */
23399 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23400 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23401 + unsigned int _flags)
23403 + int err, lock_flags;
23405 + /* reduce stack space */
23406 + struct au_ren_args *a;
23407 + struct au_pin pin;
23409 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23410 + IMustLock(_src_dir);
23411 + IMustLock(_dst_dir);
23414 + if (unlikely(_flags & RENAME_WHITEOUT))
23418 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23419 + a = kzalloc(sizeof(*a), GFP_NOFS);
23420 + if (unlikely(!a))
23423 + a->flags = _flags;
23424 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23425 + && RENAME_EXCHANGE > U8_MAX);
23426 + a->exchange = _flags & RENAME_EXCHANGE;
23427 + a->src_dir = _src_dir;
23428 + a->src_dentry = _src_dentry;
23429 + a->src_inode = NULL;
23430 + if (d_really_is_positive(a->src_dentry))
23431 + a->src_inode = d_inode(a->src_dentry);
23432 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23433 + a->dst_dir = _dst_dir;
23434 + a->dst_dentry = _dst_dentry;
23435 + a->dst_inode = NULL;
23436 + if (d_really_is_positive(a->dst_dentry))
23437 + a->dst_inode = d_inode(a->dst_dentry);
23438 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23439 + if (a->dst_inode) {
23441 + * if EXCHANGE && src is non-dir && dst is dir,
23442 + * dst is not locked.
23444 + /* IMustLock(a->dst_inode); */
23445 + au_igrab(a->dst_inode);
23449 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23450 + if (d_is_dir(a->src_dentry)) {
23451 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23452 + if (unlikely(!a->exchange
23453 + && d_really_is_positive(a->dst_dentry)
23454 + && !d_is_dir(a->dst_dentry)))
23456 + lock_flags |= AuLock_DIRS;
23458 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23459 + au_fset_ren(a->auren_flags, ISDIR_DST);
23460 + if (unlikely(!a->exchange
23461 + && d_really_is_positive(a->src_dentry)
23462 + && !d_is_dir(a->src_dentry)))
23464 + lock_flags |= AuLock_DIRS;
23466 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23468 + if (unlikely(err))
23471 + err = au_d_hashed_positive(a->src_dentry);
23472 + if (unlikely(err))
23475 + if (a->dst_inode) {
23477 + * If it is a dir, VFS unhash it before this
23478 + * function. It means we cannot rely upon d_unhashed().
23480 + if (unlikely(!a->dst_inode->i_nlink))
23482 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23483 + err = au_d_hashed_positive(a->dst_dentry);
23484 + if (unlikely(err && !a->exchange))
23486 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23488 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23492 + * is it possible?
23493 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23494 + * there may exist a problem somewhere else.
23497 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23500 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23501 + di_write_lock_parent(a->dst_parent);
23503 + /* which branch we process */
23504 + err = au_ren_wbr(a);
23505 + if (unlikely(err < 0))
23507 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23508 + a->h_path.mnt = au_br_mnt(a->br);
23510 + /* are they available to be renamed */
23511 + err = au_ren_may_dir(a);
23512 + if (unlikely(err))
23513 + goto out_children;
23515 + /* prepare the writable parent dir on the same branch */
23516 + if (a->dst_btop == a->btgt) {
23517 + au_fset_ren(a->auren_flags, WHDST);
23519 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23520 + if (unlikely(err))
23521 + goto out_children;
23525 + if (!a->exchange) {
23526 + if (a->src_dir != a->dst_dir) {
23528 + * this temporary unlock is safe,
23529 + * because both dir->i_mutex are locked.
23531 + di_write_unlock(a->dst_parent);
23532 + di_write_lock_parent(a->src_parent);
23533 + err = au_wr_dir_need_wh(a->src_dentry,
23534 + au_ftest_ren(a->auren_flags,
23537 + di_write_unlock(a->src_parent);
23538 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23540 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23542 + err = au_wr_dir_need_wh(a->src_dentry,
23543 + au_ftest_ren(a->auren_flags,
23547 + if (unlikely(err < 0))
23548 + goto out_children;
23550 + au_fset_ren(a->auren_flags, WHSRC);
23553 + if (a->src_btop != a->btgt) {
23554 + err = au_pin(&pin, a->src_dentry, a->btgt,
23555 + au_opt_udba(a->src_dentry->d_sb),
23556 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23558 + struct au_cp_generic cpg = {
23559 + .dentry = a->src_dentry,
23561 + .bsrc = a->src_btop,
23564 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23566 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23567 + err = au_sio_cpup_simple(&cpg);
23570 + if (unlikely(err))
23571 + goto out_children;
23572 + a->src_btop = a->btgt;
23573 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23574 + if (!a->exchange)
23575 + au_fset_ren(a->auren_flags, WHSRC);
23579 + if (a->exchange && a->dst_inode
23580 + && a->dst_btop != a->btgt) {
23581 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23582 + au_opt_udba(a->dst_dentry->d_sb),
23583 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23585 + struct au_cp_generic cpg = {
23586 + .dentry = a->dst_dentry,
23588 + .bsrc = a->dst_btop,
23591 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23593 + err = au_sio_cpup_simple(&cpg);
23596 + if (unlikely(err))
23597 + goto out_children;
23598 + a->dst_btop = a->btgt;
23599 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23602 + /* lock them all */
23603 + err = au_ren_lock(a);
23604 + if (unlikely(err))
23605 + /* leave the copied-up one */
23606 + goto out_children;
23608 + if (!a->exchange) {
23609 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23610 + err = au_may_ren(a);
23611 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23612 + err = -ENAMETOOLONG;
23613 + if (unlikely(err))
23617 + /* store timestamps to be revertible */
23620 + /* store dirren info */
23621 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23622 + err = au_dr_rename(a->src_dentry, a->btgt,
23623 + &a->dst_dentry->d_name, &rev);
23625 + if (unlikely(err))
23630 + err = do_rename(a);
23631 + if (unlikely(err))
23634 + if (au_ftest_ren(a->auren_flags, DIRREN))
23635 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23637 + /* update dir attributes */
23638 + au_ren_refresh_dir(a);
23640 + /* dput/iput all lower dentries */
23641 + au_ren_refresh(a);
23643 + goto out_hdir; /* success */
23646 + if (au_ftest_ren(a->auren_flags, DIRREN))
23647 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23649 + au_ren_rev_dt(err, a);
23651 + au_ren_unlock(a);
23653 + au_nhash_wh_free(&a->whlist);
23654 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23655 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23656 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23657 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23661 + if (d_unhashed(a->src_dentry))
23662 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23663 + if (d_unhashed(a->dst_dentry))
23664 + au_fset_ren(a->auren_flags, DROPPED_DST);
23665 + if (!a->exchange)
23666 + d_move(a->src_dentry, a->dst_dentry);
23668 + d_exchange(a->src_dentry, a->dst_dentry);
23669 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23670 + d_drop(a->dst_dentry);
23672 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23673 + d_drop(a->src_dentry);
23675 + au_update_dbtop(a->dst_dentry);
23676 + if (!a->dst_inode)
23677 + d_drop(a->dst_dentry);
23679 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23680 + di_write_unlock(a->dst_parent);
23682 + di_write_unlock2(a->src_parent, a->dst_parent);
23684 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23686 + iput(a->dst_inode);
23688 + au_whtmp_rmdir_free(a->thargs);
23694 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23695 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23696 +++ linux/fs/aufs/Kconfig 2021-02-24 13:33:42.741013619 +0100
23698 +# SPDX-License-Identifier: GPL-2.0
23700 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23702 + Aufs is a stackable unification filesystem such as Unionfs,
23703 + which unifies several directories and provides a merged single
23705 + In the early days, aufs was entirely re-designed and
23706 + re-implemented Unionfs Version 1.x series. Introducing many
23707 + original ideas, approaches and improvements, it becomes totally
23708 + different from Unionfs while keeping the basic features.
23712 + prompt "Maximum number of branches"
23713 + default AUFS_BRANCH_MAX_127
23715 + Specifies the maximum number of branches (or member directories)
23716 + in a single aufs. The larger value consumes more system
23717 + resources and has a minor impact to performance.
23718 +config AUFS_BRANCH_MAX_127
23721 + Specifies the maximum number of branches (or member directories)
23722 + in a single aufs. The larger value consumes more system
23723 + resources and has a minor impact to performance.
23724 +config AUFS_BRANCH_MAX_511
23727 + Specifies the maximum number of branches (or member directories)
23728 + in a single aufs. The larger value consumes more system
23729 + resources and has a minor impact to performance.
23730 +config AUFS_BRANCH_MAX_1023
23733 + Specifies the maximum number of branches (or member directories)
23734 + in a single aufs. The larger value consumes more system
23735 + resources and has a minor impact to performance.
23736 +config AUFS_BRANCH_MAX_32767
23739 + Specifies the maximum number of branches (or member directories)
23740 + in a single aufs. The larger value consumes more system
23741 + resources and has a minor impact to performance.
23744 +config AUFS_SBILIST
23746 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23749 + Automatic configuration for internal use.
23750 + When aufs supports Magic SysRq or /proc, enabled automatically.
23752 +config AUFS_HNOTIFY
23753 + bool "Detect direct branch access (bypassing aufs)"
23755 + If you want to modify files on branches directly, eg. bypassing aufs,
23756 + and want aufs to detect the changes of them fully, then enable this
23757 + option and use 'udba=notify' mount option.
23758 + Currently there is only one available configuration, "fsnotify".
23759 + It will have a negative impact to the performance.
23760 + See detail in aufs.5.
23763 + prompt "method" if AUFS_HNOTIFY
23764 + default AUFS_HFSNOTIFY
23765 +config AUFS_HFSNOTIFY
23770 +config AUFS_EXPORT
23771 + bool "NFS-exportable aufs"
23772 + depends on EXPORTFS
23774 + If you want to export your mounted aufs via NFS, then enable this
23775 + option. There are several requirements for this configuration.
23776 + See detail in aufs.5.
23778 +config AUFS_INO_T_64
23780 + depends on AUFS_EXPORT
23781 + depends on 64BIT && !(ALPHA || S390)
23784 + Automatic configuration for internal use.
23785 + /* typedef unsigned long/int __kernel_ino_t */
23786 + /* alpha and s390x are int */
23789 + bool "support for XATTR/EA (including Security Labels)"
23791 + If your branch fs supports XATTR/EA and you want to make them
23792 + available in aufs too, then enable this opsion and specify the
23793 + branch attributes for EA.
23794 + See detail in aufs.5.
23797 + bool "File-based Hierarchical Storage Management"
23799 + Hierarchical Storage Management (or HSM) is a well-known feature
23800 + in the storage world. Aufs provides this feature as file-based.
23801 + with multiple branches.
23802 + These multiple branches are prioritized, ie. the topmost one
23803 + should be the fastest drive and be used heavily.
23806 + bool "Readdir in userspace"
23808 + Aufs has two methods to provide a merged view for a directory,
23809 + by a user-space library and by kernel-space natively. The latter
23810 + is always enabled but sometimes large and slow.
23811 + If you enable this option, install the library in aufs2-util
23812 + package, and set some environment variables for your readdir(3),
23813 + then the work will be handled in user-space which generally
23814 + shows better performance in most cases.
23815 + See detail in aufs.5.
23817 +config AUFS_DIRREN
23818 + bool "Workaround for rename(2)-ing a directory"
23820 + By default, aufs returns EXDEV error in renameing a dir who has
23821 + his child on the lower branch, since it is a bad idea to issue
23822 + rename(2) internally for every lower branch. But user may not
23823 + accept this behaviour. So here is a workaround to allow such
23824 + rename(2) and store some extra infromation on the writable
23825 + branch. Obviously this costs high (and I don't like it).
23826 + To use this feature, you need to enable this configuration AND
23827 + to specify the mount option `dirren.'
23828 + See details in aufs.5 and the design documents.
23831 + bool "Show whiteouts"
23833 + If you want to make the whiteouts in aufs visible, then enable
23834 + this option and specify 'shwh' mount option. Although it may
23835 + sounds like philosophy or something, but in technically it
23836 + simply shows the name of whiteout with keeping its behaviour.
23838 +config AUFS_BR_RAMFS
23839 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23841 + If you want to use ramfs as an aufs branch fs, then enable this
23842 + option. Generally tmpfs is recommended.
23843 + Aufs prohibited them to be a branch fs by default, because
23844 + initramfs becomes unusable after switch_root or something
23845 + generally. If you sets initramfs as an aufs branch and boot your
23846 + system by switch_root, you will meet a problem easily since the
23847 + files in initramfs may be inaccessible.
23848 + Unless you are going to use ramfs as an aufs branch fs without
23849 + switch_root or something, leave it N.
23851 +config AUFS_BR_FUSE
23852 + bool "Fuse fs as an aufs branch"
23853 + depends on FUSE_FS
23856 + If you want to use fuse-based userspace filesystem as an aufs
23857 + branch fs, then enable this option.
23858 + It implements the internal poll(2) operation which is
23859 + implemented by fuse only (curretnly).
23864 + Automatic configuration for internal use.
23866 +config AUFS_BR_HFSPLUS
23867 + bool "Hfsplus as an aufs branch"
23868 + depends on HFSPLUS_FS
23871 + If you want to use hfsplus fs as an aufs branch fs, then enable
23872 + this option. This option introduces a small overhead at
23873 + copying-up a file on hfsplus.
23875 +config AUFS_BDEV_LOOP
23877 + depends on BLK_DEV_LOOP
23880 + Automatic configuration for internal use.
23881 + Convert =[ym] into =y.
23884 + bool "Debug aufs"
23886 + Enable this to compile aufs internal debug code.
23887 + It will have a negative impact to the performance.
23889 +config AUFS_MAGIC_SYSRQ
23891 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23894 + Automatic configuration for internal use.
23895 + When aufs supports Magic SysRq, enabled automatically.
23897 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23898 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23899 +++ linux/fs/aufs/lcnt.h 2021-02-24 13:33:42.747680497 +0100
23901 +/* SPDX-License-Identifier: GPL-2.0 */
23903 + * Copyright (C) 2018-2020 Junjiro R. Okajima
23905 + * This program, aufs is free software; you can redistribute it and/or modify
23906 + * it under the terms of the GNU General Public License as published by
23907 + * the Free Software Foundation; either version 2 of the License, or
23908 + * (at your option) any later version.
23910 + * This program is distributed in the hope that it will be useful,
23911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23913 + * GNU General Public License for more details.
23915 + * You should have received a copy of the GNU General Public License
23916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23920 + * simple long counter wrapper
23923 +#ifndef __AUFS_LCNT_H__
23924 +#define __AUFS_LCNT_H__
23928 +#include "debug.h"
23930 +#define AuLCntATOMIC 1
23931 +#define AuLCntPCPUCNT 2
23933 + * why does percpu_refcount require extra synchronize_rcu()s in
23934 + * au_br_do_free()
23936 +#define AuLCntPCPUREF 3
23938 +/* #define AuLCntChosen AuLCntATOMIC */
23939 +#define AuLCntChosen AuLCntPCPUCNT
23940 +/* #define AuLCntChosen AuLCntPCPUREF */
23942 +#if AuLCntChosen == AuLCntATOMIC
23943 +#include <linux/atomic.h>
23945 +typedef atomic_long_t au_lcnt_t;
23947 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23949 + atomic_long_set(cnt, 0);
23953 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23958 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
23959 + int do_sync __maybe_unused)
23964 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
23966 + atomic_long_inc(cnt);
23969 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
23971 + atomic_long_dec(cnt);
23974 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
23976 + return atomic_long_read(cnt);
23980 +#if AuLCntChosen == AuLCntPCPUCNT
23981 +#include <linux/percpu_counter.h>
23983 +typedef struct percpu_counter au_lcnt_t;
23985 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23987 + return percpu_counter_init(cnt, 0, GFP_NOFS);
23990 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23995 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
23997 + percpu_counter_destroy(cnt);
24000 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24002 + percpu_counter_inc(cnt);
24005 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24007 + percpu_counter_dec(cnt);
24010 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24014 + n = percpu_counter_sum(cnt);
24016 + if (LONG_MAX != LLONG_MAX
24018 + AuWarn1("%s\n", "wrap-around");
24024 +#if AuLCntChosen == AuLCntPCPUREF
24025 +#include <linux/percpu-refcount.h>
24027 +typedef struct percpu_ref au_lcnt_t;
24029 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24032 + release = percpu_ref_exit;
24033 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24036 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24038 + synchronize_rcu();
24041 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24043 + percpu_ref_kill(cnt);
24045 + au_lcnt_wait_for_fin(cnt);
24048 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24050 + percpu_ref_get(cnt);
24053 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24055 + percpu_ref_put(cnt);
24059 + * avoid calling this func as possible.
24061 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24065 + percpu_ref_switch_to_atomic_sync(cnt);
24066 + l = atomic_long_read(&cnt->count);
24068 + percpu_ref_switch_to_percpu(cnt);
24070 + /* percpu_ref is initialized by 1 instead of 0 */
24075 +#ifdef CONFIG_AUFS_DEBUG
24076 +#define AuLCntZero(val) do { \
24079 + AuDbg("%s = %ld\n", #val, l); \
24082 +#define AuLCntZero(val) do {} while (0)
24085 +#endif /* __KERNEL__ */
24086 +#endif /* __AUFS_LCNT_H__ */
24087 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24088 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24089 +++ linux/fs/aufs/loop.c 2021-02-24 13:33:42.747680497 +0100
24091 +// SPDX-License-Identifier: GPL-2.0
24093 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24095 + * This program, aufs is free software; you can redistribute it and/or modify
24096 + * it under the terms of the GNU General Public License as published by
24097 + * the Free Software Foundation; either version 2 of the License, or
24098 + * (at your option) any later version.
24100 + * This program is distributed in the hope that it will be useful,
24101 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24102 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24103 + * GNU General Public License for more details.
24105 + * You should have received a copy of the GNU General Public License
24106 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24110 + * support for loopback block device as a branch
24115 +/* added into drivers/block/loop.c */
24116 +static struct file *(*backing_file_func)(struct super_block *sb);
24119 + * test if two lower dentries have overlapping branches.
24121 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24123 + struct super_block *h_sb;
24124 + struct file *backing_file;
24126 + if (unlikely(!backing_file_func)) {
24127 + /* don't load "loop" module here */
24128 + backing_file_func = symbol_get(loop_backing_file);
24129 + if (unlikely(!backing_file_func))
24130 + /* "loop" module is not loaded */
24134 + h_sb = h_adding->d_sb;
24135 + backing_file = backing_file_func(h_sb);
24136 + if (!backing_file)
24139 + h_adding = backing_file->f_path.dentry;
24141 + * h_adding can be local NFS.
24142 + * in this case aufs cannot detect the loop.
24144 + if (unlikely(h_adding->d_sb == sb))
24146 + return !!au_test_subdir(h_adding, sb->s_root);
24149 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24150 +int au_test_loopback_kthread(void)
24153 + struct task_struct *tsk = current;
24154 + char c, comm[sizeof(tsk->comm)];
24157 + if (tsk->flags & PF_KTHREAD) {
24158 + get_task_comm(comm, tsk);
24160 + ret = ('0' <= c && c <= '9'
24161 + && !strncmp(comm, "loop", 4));
24167 +/* ---------------------------------------------------------------------- */
24169 +#define au_warn_loopback_step 16
24170 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24171 +static unsigned long *au_warn_loopback_array;
24173 +void au_warn_loopback(struct super_block *h_sb)
24175 + int i, new_nelem;
24176 + unsigned long *a, magic;
24177 + static DEFINE_SPINLOCK(spin);
24179 + magic = h_sb->s_magic;
24180 + spin_lock(&spin);
24181 + a = au_warn_loopback_array;
24182 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24183 + if (a[i] == magic) {
24184 + spin_unlock(&spin);
24188 + /* h_sb is new to us, print it */
24189 + if (i < au_warn_loopback_nelem) {
24194 + /* expand the array */
24195 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24196 + a = au_kzrealloc(au_warn_loopback_array,
24197 + au_warn_loopback_nelem * sizeof(unsigned long),
24198 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24199 + /*may_shrink*/0);
24201 + au_warn_loopback_nelem = new_nelem;
24202 + au_warn_loopback_array = a;
24207 + spin_unlock(&spin);
24208 + AuWarn1("realloc failed, ignored\n");
24212 + spin_unlock(&spin);
24213 + pr_warn("you may want to try another patch for loopback file "
24214 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24217 +int au_loopback_init(void)
24220 + struct super_block *sb __maybe_unused;
24222 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24225 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24226 + sizeof(unsigned long), GFP_NOFS);
24227 + if (unlikely(!au_warn_loopback_array))
24233 +void au_loopback_fin(void)
24235 + if (backing_file_func)
24236 + symbol_put(loop_backing_file);
24237 + au_kfree_try_rcu(au_warn_loopback_array);
24239 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24240 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24241 +++ linux/fs/aufs/loop.h 2021-02-24 13:33:42.747680497 +0100
24243 +/* SPDX-License-Identifier: GPL-2.0 */
24245 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24247 + * This program, aufs is free software; you can redistribute it and/or modify
24248 + * it under the terms of the GNU General Public License as published by
24249 + * the Free Software Foundation; either version 2 of the License, or
24250 + * (at your option) any later version.
24252 + * This program is distributed in the hope that it will be useful,
24253 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24254 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24255 + * GNU General Public License for more details.
24257 + * You should have received a copy of the GNU General Public License
24258 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24262 + * support for loopback mount as a branch
24265 +#ifndef __AUFS_LOOP_H__
24266 +#define __AUFS_LOOP_H__
24271 +struct super_block;
24273 +#ifdef CONFIG_AUFS_BDEV_LOOP
24274 +/* drivers/block/loop.c */
24275 +struct file *loop_backing_file(struct super_block *sb);
24278 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24279 +int au_test_loopback_kthread(void);
24280 +void au_warn_loopback(struct super_block *h_sb);
24282 +int au_loopback_init(void);
24283 +void au_loopback_fin(void);
24285 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24287 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24288 + struct dentry *h_adding)
24289 +AuStubInt0(au_test_loopback_kthread, void)
24290 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24292 +AuStubInt0(au_loopback_init, void)
24293 +AuStubVoid(au_loopback_fin, void)
24294 +#endif /* BLK_DEV_LOOP */
24296 +#endif /* __KERNEL__ */
24297 +#endif /* __AUFS_LOOP_H__ */
24298 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24299 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24300 +++ linux/fs/aufs/magic.mk 2021-02-24 13:33:42.747680497 +0100
24302 +# SPDX-License-Identifier: GPL-2.0
24304 +# defined in ${srctree}/fs/fuse/inode.c
24306 +ifdef CONFIG_FUSE_FS
24307 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24310 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24312 +ifdef CONFIG_XFS_FS
24313 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24316 +# defined in ${srctree}/fs/configfs/mount.c
24318 +ifdef CONFIG_CONFIGFS_FS
24319 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24322 +# defined in ${srctree}/fs/ubifs/ubifs.h
24324 +ifdef CONFIG_UBIFS_FS
24325 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24328 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24330 +ifdef CONFIG_HFSPLUS_FS
24331 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24333 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24334 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24335 +++ linux/fs/aufs/Makefile 2021-02-24 13:33:42.741013619 +0100
24337 +# SPDX-License-Identifier: GPL-2.0
24339 +include ${src}/magic.mk
24340 +ifeq (${CONFIG_AUFS_FS},m)
24341 +include ${src}/conf.mk
24343 +-include ${src}/priv_def.mk
24345 +# cf. include/linux/kernel.h
24347 +ccflags-y += -DDEBUG
24348 +# sparse requires the full pathname
24350 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24352 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24355 +obj-$(CONFIG_AUFS_FS) += aufs.o
24356 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24357 + wkq.o vfsub.o dcsub.o \
24358 + cpup.o whout.o wbr_policy.o \
24359 + dinfo.o dentry.o \
24361 + finfo.o file.o f_op.o \
24363 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24367 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24368 +aufs-$(CONFIG_SYSFS) += sysfs.o
24369 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24370 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24371 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24372 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24373 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24374 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24375 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24376 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24377 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24378 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24379 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24380 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24381 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24382 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24383 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24384 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24385 +++ linux/fs/aufs/module.c 2021-02-24 13:33:42.747680497 +0100
24387 +// SPDX-License-Identifier: GPL-2.0
24389 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24391 + * This program, aufs is free software; you can redistribute it and/or modify
24392 + * it under the terms of the GNU General Public License as published by
24393 + * the Free Software Foundation; either version 2 of the License, or
24394 + * (at your option) any later version.
24396 + * This program is distributed in the hope that it will be useful,
24397 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24398 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24399 + * GNU General Public License for more details.
24401 + * You should have received a copy of the GNU General Public License
24402 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24406 + * module global variables and operations
24409 +#include <linux/module.h>
24410 +#include <linux/seq_file.h>
24413 +/* shrinkable realloc */
24414 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24422 +#if 0 /* unused */
24429 + AuDebugOn(!new_sz);
24432 + diff = au_kmidx_sub(sz, new_sz);
24438 + /* expand or SLOB */
24439 + p = krealloc(p, new_sz, gfp);
24440 + else if (new_sz < sz && may_shrink) {
24444 + q = kmalloc(new_sz, gfp);
24447 + memcpy(q, p, new_sz);
24448 + au_kfree_try_rcu(p);
24459 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24462 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24463 + if (p && new_sz > nused)
24464 + memset(p + nused, 0, new_sz - nused);
24468 +/* ---------------------------------------------------------------------- */
24472 +struct kmem_cache *au_cache[AuCache_Last];
24474 +static void au_cache_fin(void)
24479 + * Make sure all delayed rcu free inodes are flushed before we
24484 + /* excluding AuCache_HNOTIFY */
24485 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24486 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24487 + kmem_cache_destroy(au_cache[i]);
24488 + au_cache[i] = NULL;
24492 +static int __init au_cache_init(void)
24494 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24495 + if (au_cache[AuCache_DINFO])
24496 + /* SLAB_DESTROY_BY_RCU */
24497 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24498 + au_icntnr_init_once);
24499 + if (au_cache[AuCache_ICNTNR])
24500 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24501 + au_fi_init_once);
24502 + if (au_cache[AuCache_FINFO])
24503 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24504 + if (au_cache[AuCache_VDIR])
24505 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24506 + if (au_cache[AuCache_DEHSTR])
24513 +/* ---------------------------------------------------------------------- */
24515 +int au_dir_roflags;
24517 +#ifdef CONFIG_AUFS_SBILIST
24519 + * iterate_supers_type() doesn't protect us from
24520 + * remounting (branch management)
24522 +struct hlist_bl_head au_sbilist;
24526 + * functions for module interface.
24528 +MODULE_LICENSE("GPL");
24529 +/* MODULE_LICENSE("GPL v2"); */
24530 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24531 +MODULE_DESCRIPTION(AUFS_NAME
24532 + " -- Advanced multi layered unification filesystem");
24533 +MODULE_VERSION(AUFS_VERSION);
24534 +MODULE_ALIAS_FS(AUFS_NAME);
24536 +/* this module parameter has no meaning when SYSFS is disabled */
24537 +int sysaufs_brs = 1;
24538 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24539 +module_param_named(brs, sysaufs_brs, int, 0444);
24541 +/* this module parameter has no meaning when USER_NS is disabled */
24543 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24544 +module_param_named(allow_userns, au_userns, bool, 0444);
24546 +/* ---------------------------------------------------------------------- */
24548 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24550 +int au_seq_path(struct seq_file *seq, struct path *path)
24554 + err = seq_path(seq, path, au_esc_chars);
24563 +/* ---------------------------------------------------------------------- */
24565 +static int __init aufs_init(void)
24570 + p = au_esc_chars;
24571 + for (i = 1; i <= ' '; i++)
24577 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24579 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24580 + for (i = 0; i < AuIop_Last; i++)
24581 + aufs_iop_nogetattr[i].getattr = NULL;
24583 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24585 + au_sbilist_init();
24586 + sysaufs_brs_init();
24589 + err = sysaufs_init();
24590 + if (unlikely(err))
24592 + err = dbgaufs_init();
24593 + if (unlikely(err))
24594 + goto out_sysaufs;
24595 + err = au_procfs_init();
24596 + if (unlikely(err))
24597 + goto out_dbgaufs;
24598 + err = au_wkq_init();
24599 + if (unlikely(err))
24601 + err = au_loopback_init();
24602 + if (unlikely(err))
24604 + err = au_hnotify_init();
24605 + if (unlikely(err))
24606 + goto out_loopback;
24607 + err = au_sysrq_init();
24608 + if (unlikely(err))
24610 + err = au_cache_init();
24611 + if (unlikely(err))
24614 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24615 + err = register_filesystem(&aufs_fs_type);
24616 + if (unlikely(err))
24619 + /* since we define pr_fmt, call printk directly */
24620 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24621 + goto out; /* success */
24628 + au_hnotify_fin();
24630 + au_loopback_fin();
24644 +static void __exit aufs_exit(void)
24646 + unregister_filesystem(&aufs_fs_type);
24649 + au_hnotify_fin();
24650 + au_loopback_fin();
24658 +module_init(aufs_init);
24659 +module_exit(aufs_exit);
24660 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24661 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24662 +++ linux/fs/aufs/module.h 2021-02-24 13:33:42.747680497 +0100
24664 +/* SPDX-License-Identifier: GPL-2.0 */
24666 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24668 + * This program, aufs is free software; you can redistribute it and/or modify
24669 + * it under the terms of the GNU General Public License as published by
24670 + * the Free Software Foundation; either version 2 of the License, or
24671 + * (at your option) any later version.
24673 + * This program is distributed in the hope that it will be useful,
24674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24676 + * GNU General Public License for more details.
24678 + * You should have received a copy of the GNU General Public License
24679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24683 + * module initialization and module-global
24686 +#ifndef __AUFS_MODULE_H__
24687 +#define __AUFS_MODULE_H__
24691 +#include <linux/slab.h>
24692 +#include "debug.h"
24693 +#include "dentry.h"
24696 +#include "inode.h"
24701 +/* module parameters */
24702 +extern int sysaufs_brs;
24703 +extern bool au_userns;
24705 +/* ---------------------------------------------------------------------- */
24707 +extern int au_dir_roflags;
24709 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24710 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24714 + * Comparing the size of the object with sizeof(struct rcu_head)
24715 + * case 1: object is always larger
24716 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24717 + * case 2: object is always smaller
24718 + * --> au_kfree_small()
24719 + * case 3: object can be any size
24720 + * --> au_kfree_try_rcu()
24723 +static inline void au_kfree_do_rcu(const void *p)
24726 + struct rcu_head rcu;
24727 + } *a = (void *)p;
24729 + kfree_rcu(a, rcu);
24732 +#define au_kfree_rcu(_p) do { \
24733 + typeof(_p) p = (_p); \
24734 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24736 + au_kfree_do_rcu(p); \
24739 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24740 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24742 +static inline void au_kfree_try_rcu(const void *p)
24746 + if (au_kfree_sz_test(p))
24747 + au_kfree_do_rcu(p);
24752 +static inline void au_kfree_small(const void *p)
24756 + AuDebugOn(au_kfree_sz_test(p));
24760 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24762 +#ifndef CONFIG_SLOB
24763 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24765 + return -1; /* SLOB is untested */
24769 +int au_seq_path(struct seq_file *seq, struct path *path);
24771 +#ifdef CONFIG_PROC_FS
24773 +int __init au_procfs_init(void);
24774 +void au_procfs_fin(void);
24776 +AuStubInt0(au_procfs_init, void);
24777 +AuStubVoid(au_procfs_fin, void);
24780 +/* ---------------------------------------------------------------------- */
24789 + AuCache_HNOTIFY, /* must be last */
24793 +extern struct kmem_cache *au_cache[AuCache_Last];
24795 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24796 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24797 +#define AuCacheCtor(type, ctor) \
24798 + kmem_cache_create(#type, sizeof(struct type), \
24799 + __alignof__(struct type), AuCacheFlags, ctor)
24801 +#define AuCacheFuncs(name, index) \
24802 + static inline struct au_##name *au_cache_alloc_##name(void) \
24803 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24804 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24805 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24807 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24808 + { void *p = rcu; \
24809 + p -= offsetof(struct au_##name, rcu); \
24810 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24811 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24812 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24813 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24815 + static inline void au_cache_free_##name(struct au_##name *p) \
24816 + { /* au_cache_free_##name##_norcu(p); */ \
24817 + au_cache_free_##name##_rcu(p); }
24819 +AuCacheFuncs(dinfo, DINFO);
24820 +AuCacheFuncs(icntnr, ICNTNR);
24821 +AuCacheFuncs(finfo, FINFO);
24822 +AuCacheFuncs(vdir, VDIR);
24823 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24824 +#ifdef CONFIG_AUFS_HNOTIFY
24825 +AuCacheFuncs(hnotify, HNOTIFY);
24828 +#endif /* __KERNEL__ */
24829 +#endif /* __AUFS_MODULE_H__ */
24830 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24831 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24832 +++ linux/fs/aufs/mvdown.c 2021-02-24 13:33:42.747680497 +0100
24834 +// SPDX-License-Identifier: GPL-2.0
24836 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24838 + * This program, aufs is free software; you can redistribute it and/or modify
24839 + * it under the terms of the GNU General Public License as published by
24840 + * the Free Software Foundation; either version 2 of the License, or
24841 + * (at your option) any later version.
24843 + * This program is distributed in the hope that it will be useful,
24844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24846 + * GNU General Public License for more details.
24848 + * You should have received a copy of the GNU General Public License
24849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24853 + * move-down, opposite of copy-up
24858 +struct au_mvd_args {
24860 + struct super_block *h_sb;
24861 + struct dentry *h_parent;
24862 + struct au_hinode *hdir;
24863 + struct inode *h_dir, *h_inode;
24864 + struct au_pin pin;
24865 + } info[AUFS_MVDOWN_NARRAY];
24867 + struct aufs_mvdown mvdown;
24868 + struct dentry *dentry, *parent;
24869 + struct inode *inode, *dir;
24870 + struct super_block *sb;
24871 + aufs_bindex_t bopq, bwh, bfound;
24872 + unsigned char rename_lock;
24875 +#define mvd_errno mvdown.au_errno
24876 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24877 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24878 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24879 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24881 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24882 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24883 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24884 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24885 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24886 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24888 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24889 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24890 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24891 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24892 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24893 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24895 +#define AU_MVD_PR(flag, ...) do { \
24897 + pr_err(__VA_ARGS__); \
24900 +static int find_lower_writable(struct au_mvd_args *a)
24902 + struct super_block *sb;
24903 + aufs_bindex_t bindex, bbot;
24904 + struct au_branch *br;
24907 + bindex = a->mvd_bsrc;
24908 + bbot = au_sbbot(sb);
24909 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24910 + for (bindex++; bindex <= bbot; bindex++) {
24911 + br = au_sbr(sb, bindex);
24912 + if (au_br_fhsm(br->br_perm)
24913 + && !sb_rdonly(au_br_sb(br)))
24916 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24917 + for (bindex++; bindex <= bbot; bindex++) {
24918 + br = au_sbr(sb, bindex);
24919 + if (!au_br_rdonly(br))
24923 + for (bindex++; bindex <= bbot; bindex++) {
24924 + br = au_sbr(sb, bindex);
24925 + if (!sb_rdonly(au_br_sb(br))) {
24926 + if (au_br_rdonly(br))
24928 + |= AUFS_MVDOWN_ROLOWER_R;
24936 +/* make the parent dir on bdst */
24937 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24942 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24943 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24944 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24945 + a->mvd_h_dst_parent = NULL;
24946 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24947 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24948 + if (!a->mvd_h_dst_parent) {
24949 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24950 + if (unlikely(err)) {
24951 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24954 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24962 +/* lock them all */
24963 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24966 + struct dentry *h_trap;
24968 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24969 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24970 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24971 + au_opt_udba(a->sb),
24972 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24974 + if (unlikely(err)) {
24975 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24979 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24980 + a->rename_lock = 0;
24981 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24982 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24983 + au_opt_udba(a->sb),
24984 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24985 + err = au_do_pin(&a->mvd_pin_src);
24987 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24988 + if (unlikely(err)) {
24989 + AU_MVD_PR(dmsg, "pin_src failed\n");
24992 + goto out; /* success */
24995 + a->rename_lock = 1;
24996 + au_pin_hdir_unlock(&a->mvd_pin_dst);
24997 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24998 + au_opt_udba(a->sb),
24999 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25001 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25002 + if (unlikely(err)) {
25003 + AU_MVD_PR(dmsg, "pin_src failed\n");
25004 + au_pin_hdir_lock(&a->mvd_pin_dst);
25007 + au_pin_hdir_unlock(&a->mvd_pin_src);
25008 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25009 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25011 + err = (h_trap != a->mvd_h_src_parent);
25013 + err = (h_trap != a->mvd_h_dst_parent);
25015 + BUG_ON(err); /* it should never happen */
25016 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25019 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25020 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25021 + au_pin_hdir_lock(&a->mvd_pin_src);
25022 + au_unpin(&a->mvd_pin_src);
25023 + au_pin_hdir_lock(&a->mvd_pin_dst);
25026 + goto out; /* success */
25029 + au_unpin(&a->mvd_pin_dst);
25035 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25037 + if (!a->rename_lock)
25038 + au_unpin(&a->mvd_pin_src);
25040 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25041 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25042 + au_pin_hdir_lock(&a->mvd_pin_src);
25043 + au_unpin(&a->mvd_pin_src);
25044 + au_pin_hdir_lock(&a->mvd_pin_dst);
25046 + au_unpin(&a->mvd_pin_dst);
25049 +/* copy-down the file */
25050 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25053 + struct au_cp_generic cpg = {
25054 + .dentry = a->dentry,
25055 + .bdst = a->mvd_bdst,
25056 + .bsrc = a->mvd_bsrc,
25058 + .pin = &a->mvd_pin_dst,
25059 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25062 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25063 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25064 + au_fset_cpup(cpg.flags, OVERWRITE);
25065 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25066 + au_fset_cpup(cpg.flags, RWDST);
25067 + err = au_sio_cpdown_simple(&cpg);
25068 + if (unlikely(err))
25069 + AU_MVD_PR(dmsg, "cpdown failed\n");
25076 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25079 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25082 + struct path h_path;
25083 + struct au_branch *br;
25084 + struct inode *delegated;
25086 + br = au_sbr(a->sb, a->mvd_bdst);
25087 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25088 + err = PTR_ERR(h_path.dentry);
25089 + if (IS_ERR(h_path.dentry)) {
25090 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25095 + if (d_is_positive(h_path.dentry)) {
25096 + h_path.mnt = au_br_mnt(br);
25097 + delegated = NULL;
25098 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25099 + &delegated, /*force*/0);
25100 + if (unlikely(err == -EWOULDBLOCK)) {
25101 + pr_warn("cannot retry for NFSv4 delegation"
25102 + " for an internal unlink\n");
25105 + if (unlikely(err))
25106 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25108 + dput(h_path.dentry);
25116 + * unlink the topmost h_dentry
25118 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25121 + struct path h_path;
25122 + struct inode *delegated;
25124 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25125 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25126 + delegated = NULL;
25127 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25128 + if (unlikely(err == -EWOULDBLOCK)) {
25129 + pr_warn("cannot retry for NFSv4 delegation"
25130 + " for an internal unlink\n");
25133 + if (unlikely(err))
25134 + AU_MVD_PR(dmsg, "unlink failed\n");
25140 +/* Since mvdown succeeded, we ignore an error of this function */
25141 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25144 + struct au_branch *br;
25146 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25147 + br = au_sbr(a->sb, a->mvd_bsrc);
25148 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25150 + br = au_sbr(a->sb, a->mvd_bdst);
25151 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25152 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25155 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25157 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25161 + * copy-down the file and unlink the bsrc file.
25162 + * - unlink the bdst whout if exist
25163 + * - copy-down the file (with whtmp name and rename)
25164 + * - unlink the bsrc file
25166 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25170 + err = au_do_mkdir(dmsg, a);
25172 + err = au_do_lock(dmsg, a);
25173 + if (unlikely(err))
25177 + * do not revert the activities we made on bdst since they should be
25178 + * harmless in aufs.
25181 + err = au_do_cpdown(dmsg, a);
25183 + err = au_do_unlink_wh(dmsg, a);
25184 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25185 + err = au_do_unlink(dmsg, a);
25186 + if (unlikely(err))
25189 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25190 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25191 + if (find_lower_writable(a) < 0)
25192 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25194 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25195 + au_do_stfs(dmsg, a);
25197 + /* maintain internal array */
25198 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25199 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25200 + au_set_dbtop(a->dentry, a->mvd_bdst);
25201 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25202 + au_set_ibtop(a->inode, a->mvd_bdst);
25204 + /* hide the lower */
25205 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25206 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25207 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25208 + au_set_ibbot(a->inode, a->mvd_bsrc);
25210 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25211 + au_set_dbbot(a->dentry, a->mvd_bdst);
25212 + if (au_ibbot(a->inode) < a->mvd_bdst)
25213 + au_set_ibbot(a->inode, a->mvd_bdst);
25216 + au_do_unlock(dmsg, a);
25222 +/* ---------------------------------------------------------------------- */
25224 +/* make sure the file is idle */
25225 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25227 + int err, plinked;
25230 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25231 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25232 + && au_dcount(a->dentry) == 1
25233 + && atomic_read(&a->inode->i_count) == 1
25234 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25235 + && (!plinked || !au_plink_test(a->inode))
25236 + && a->inode->i_nlink == 1)
25241 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25242 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25243 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25244 + a->mvd_h_src_inode->i_nlink,
25245 + plinked, plinked ? au_plink_test(a->inode) : 0);
25252 +/* make sure the parent dir is fine */
25253 +static int au_mvd_args_parent(const unsigned char dmsg,
25254 + struct au_mvd_args *a)
25257 + aufs_bindex_t bindex;
25260 + if (unlikely(au_alive_dir(a->parent))) {
25262 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25266 + a->bopq = au_dbdiropq(a->parent);
25267 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25268 + AuDbg("b%d\n", bindex);
25269 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25270 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25272 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25273 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25274 + a->bopq, a->mvd_bdst);
25282 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25283 + struct au_mvd_args *a)
25286 + struct au_dinfo *dinfo, *tmp;
25288 + /* lookup the next lower positive entry */
25290 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25291 + if (unlikely(!tmp))
25296 + dinfo = au_di(a->dentry);
25297 + au_di_cp(tmp, dinfo);
25298 + au_di_swap(tmp, dinfo);
25300 + /* returns the number of positive dentries */
25301 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25302 + /* AuLkup_IGNORE_PERM */ 0);
25304 + a->bwh = au_dbwh(a->dentry);
25305 + else if (err > 0)
25306 + a->bfound = au_dbtop(a->dentry);
25308 + au_di_swap(tmp, dinfo);
25309 + au_rw_write_unlock(&tmp->di_rwsem);
25311 + if (unlikely(err < 0))
25312 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25315 + * here, we have these cases.
25317 + * no positive dentry under bsrc. there are more sub-cases.
25319 + * there no whiteout, we can safely move-down.
25322 + * bsrc < bwh && bwh < bdst
25323 + * there is a whiteout on RO branch. cannot proceed.
25325 + * there is a whiteout on the RW target branch. it should
25328 + * there is a whiteout somewhere unrelated branch.
25329 + * -1 < bfound && bfound <= bsrc
25332 + * found, but it is on RO branch between bsrc and bdst. cannot
25335 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25338 + * found, after we create the file on bdst, it will be hidden.
25341 + AuDebugOn(a->bfound == -1
25343 + && a->bwh <= a->mvd_bsrc);
25344 + AuDebugOn(-1 < a->bfound
25345 + && a->bfound <= a->mvd_bsrc);
25348 + if (a->bfound == -1
25349 + && a->mvd_bsrc < a->bwh
25351 + && a->bwh < a->mvd_bdst) {
25352 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25353 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25354 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25356 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25357 + a->mvd_errno = EAU_MVDOWN_UPPER;
25358 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25359 + a->mvd_bdst, a->bfound);
25363 + err = 0; /* success */
25370 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25375 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25376 + && a->bfound == a->mvd_bdst)
25382 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25385 + struct au_branch *br;
25388 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25392 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25393 + a->mvd_bsrc = au_ibtop(a->inode);
25395 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25396 + if (unlikely(a->mvd_bsrc < 0
25397 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25398 + || au_dbbot(a->dentry) < a->mvd_bsrc
25399 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25400 + || (a->mvd_bsrc < au_ibtop(a->inode)
25401 + || au_ibbot(a->inode) < a->mvd_bsrc
25402 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25403 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25404 + AU_MVD_PR(dmsg, "no upper\n");
25408 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25409 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25410 + AU_MVD_PR(dmsg, "on the bottom\n");
25413 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25414 + br = au_sbr(a->sb, a->mvd_bsrc);
25415 + err = au_br_rdonly(br);
25416 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25417 + if (unlikely(err))
25419 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25420 + || IS_APPEND(a->mvd_h_src_inode))) {
25422 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25428 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25429 + a->mvd_bdst = find_lower_writable(a);
25430 + if (unlikely(a->mvd_bdst < 0)) {
25431 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25432 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25436 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25437 + if (unlikely(a->mvd_bdst < 0
25438 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25439 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25440 + AU_MVD_PR(dmsg, "no lower brid\n");
25445 + err = au_mvd_args_busy(dmsg, a);
25447 + err = au_mvd_args_parent(dmsg, a);
25449 + err = au_mvd_args_intermediate(dmsg, a);
25451 + err = au_mvd_args_exist(dmsg, a);
25453 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25460 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25463 + unsigned char dmsg;
25464 + struct au_mvd_args *args;
25465 + struct inode *inode;
25467 + inode = d_inode(dentry);
25469 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25473 + args = kmalloc(sizeof(*args), GFP_NOFS);
25474 + if (unlikely(!args))
25477 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25479 + /* VERIFY_WRITE */
25480 + err = !access_ok(uarg, sizeof(*uarg));
25481 + if (unlikely(err)) {
25486 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25487 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25488 + args->mvdown.au_errno = 0;
25489 + args->dentry = dentry;
25490 + args->inode = inode;
25491 + args->sb = dentry->d_sb;
25494 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25495 + args->parent = dget_parent(dentry);
25496 + args->dir = d_inode(args->parent);
25497 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25498 + dput(args->parent);
25499 + if (unlikely(args->parent != dentry->d_parent)) {
25500 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25504 + inode_lock_nested(inode, I_MUTEX_CHILD);
25505 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25506 + if (unlikely(err))
25509 + di_write_lock_parent(args->parent);
25510 + err = au_mvd_args(dmsg, args);
25511 + if (unlikely(err))
25514 + err = au_do_mvdown(dmsg, args);
25515 + if (unlikely(err))
25518 + au_cpup_attr_timesizes(args->dir);
25519 + au_cpup_attr_timesizes(inode);
25520 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25521 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25522 + /* au_digen_dec(dentry); */
25525 + di_write_unlock(args->parent);
25526 + aufs_read_unlock(dentry, AuLock_DW);
25528 + inode_unlock(inode);
25530 + inode_unlock(args->dir);
25532 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25535 + au_kfree_rcu(args);
25540 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25541 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25542 +++ linux/fs/aufs/opts.c 2021-02-24 13:33:42.747680497 +0100
25544 +// SPDX-License-Identifier: GPL-2.0
25546 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25548 + * This program, aufs is free software; you can redistribute it and/or modify
25549 + * it under the terms of the GNU General Public License as published by
25550 + * the Free Software Foundation; either version 2 of the License, or
25551 + * (at your option) any later version.
25553 + * This program is distributed in the hope that it will be useful,
25554 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25555 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25556 + * GNU General Public License for more details.
25558 + * You should have received a copy of the GNU General Public License
25559 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25563 + * mount options/flags
25566 +#include <linux/namei.h>
25567 +#include <linux/types.h> /* a distribution requires */
25568 +#include <linux/parser.h>
25571 +/* ---------------------------------------------------------------------- */
25575 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25576 + Opt_idel, Opt_imod,
25577 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25578 + Opt_rdblk_def, Opt_rdhash_def,
25579 + Opt_xino, Opt_noxino,
25580 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25581 + Opt_trunc_xino_path, Opt_itrunc_xino,
25582 + Opt_trunc_xib, Opt_notrunc_xib,
25583 + Opt_shwh, Opt_noshwh,
25584 + Opt_plink, Opt_noplink, Opt_list_plink,
25586 + Opt_dio, Opt_nodio,
25587 + Opt_diropq_a, Opt_diropq_w,
25588 + Opt_warn_perm, Opt_nowarn_perm,
25589 + Opt_wbr_copyup, Opt_wbr_create,
25591 + Opt_verbose, Opt_noverbose,
25592 + Opt_sum, Opt_nosum, Opt_wsum,
25593 + Opt_dirperm1, Opt_nodirperm1,
25594 + Opt_dirren, Opt_nodirren,
25595 + Opt_acl, Opt_noacl,
25596 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25599 +static match_table_t options = {
25600 + {Opt_br, "br=%s"},
25601 + {Opt_br, "br:%s"},
25603 + {Opt_add, "add=%d:%s"},
25604 + {Opt_add, "add:%d:%s"},
25605 + {Opt_add, "ins=%d:%s"},
25606 + {Opt_add, "ins:%d:%s"},
25607 + {Opt_append, "append=%s"},
25608 + {Opt_append, "append:%s"},
25609 + {Opt_prepend, "prepend=%s"},
25610 + {Opt_prepend, "prepend:%s"},
25612 + {Opt_del, "del=%s"},
25613 + {Opt_del, "del:%s"},
25614 + /* {Opt_idel, "idel:%d"}, */
25615 + {Opt_mod, "mod=%s"},
25616 + {Opt_mod, "mod:%s"},
25617 + /* {Opt_imod, "imod:%d:%s"}, */
25619 + {Opt_dirwh, "dirwh=%d"},
25621 + {Opt_xino, "xino=%s"},
25622 + {Opt_noxino, "noxino"},
25623 + {Opt_trunc_xino, "trunc_xino"},
25624 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25625 + {Opt_notrunc_xino, "notrunc_xino"},
25626 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25627 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25628 + /* {Opt_zxino, "zxino=%s"}, */
25629 + {Opt_trunc_xib, "trunc_xib"},
25630 + {Opt_notrunc_xib, "notrunc_xib"},
25632 +#ifdef CONFIG_PROC_FS
25633 + {Opt_plink, "plink"},
25635 + {Opt_ignore_silent, "plink"},
25638 + {Opt_noplink, "noplink"},
25640 +#ifdef CONFIG_AUFS_DEBUG
25641 + {Opt_list_plink, "list_plink"},
25644 + {Opt_udba, "udba=%s"},
25646 + {Opt_dio, "dio"},
25647 + {Opt_nodio, "nodio"},
25649 +#ifdef CONFIG_AUFS_DIRREN
25650 + {Opt_dirren, "dirren"},
25651 + {Opt_nodirren, "nodirren"},
25653 + {Opt_ignore, "dirren"},
25654 + {Opt_ignore_silent, "nodirren"},
25657 +#ifdef CONFIG_AUFS_FHSM
25658 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25660 + {Opt_ignore, "fhsm_sec=%d"},
25663 + {Opt_diropq_a, "diropq=always"},
25664 + {Opt_diropq_a, "diropq=a"},
25665 + {Opt_diropq_w, "diropq=whiteouted"},
25666 + {Opt_diropq_w, "diropq=w"},
25668 + {Opt_warn_perm, "warn_perm"},
25669 + {Opt_nowarn_perm, "nowarn_perm"},
25671 + /* keep them temporary */
25672 + {Opt_ignore_silent, "nodlgt"},
25673 + {Opt_ignore, "clean_plink"},
25675 +#ifdef CONFIG_AUFS_SHWH
25676 + {Opt_shwh, "shwh"},
25678 + {Opt_noshwh, "noshwh"},
25680 + {Opt_dirperm1, "dirperm1"},
25681 + {Opt_nodirperm1, "nodirperm1"},
25683 + {Opt_verbose, "verbose"},
25684 + {Opt_verbose, "v"},
25685 + {Opt_noverbose, "noverbose"},
25686 + {Opt_noverbose, "quiet"},
25687 + {Opt_noverbose, "q"},
25688 + {Opt_noverbose, "silent"},
25690 + {Opt_sum, "sum"},
25691 + {Opt_nosum, "nosum"},
25692 + {Opt_wsum, "wsum"},
25694 + {Opt_rdcache, "rdcache=%d"},
25695 + {Opt_rdblk, "rdblk=%d"},
25696 + {Opt_rdblk_def, "rdblk=def"},
25697 + {Opt_rdhash, "rdhash=%d"},
25698 + {Opt_rdhash_def, "rdhash=def"},
25700 + {Opt_wbr_create, "create=%s"},
25701 + {Opt_wbr_create, "create_policy=%s"},
25702 + {Opt_wbr_copyup, "cpup=%s"},
25703 + {Opt_wbr_copyup, "copyup=%s"},
25704 + {Opt_wbr_copyup, "copyup_policy=%s"},
25706 + /* generic VFS flag */
25707 +#ifdef CONFIG_FS_POSIX_ACL
25708 + {Opt_acl, "acl"},
25709 + {Opt_noacl, "noacl"},
25711 + {Opt_ignore, "acl"},
25712 + {Opt_ignore_silent, "noacl"},
25715 + /* internal use for the scripts */
25716 + {Opt_ignore_silent, "si=%s"},
25718 + {Opt_br, "dirs=%s"},
25719 + {Opt_ignore, "debug=%d"},
25720 + {Opt_ignore, "delete=whiteout"},
25721 + {Opt_ignore, "delete=all"},
25722 + {Opt_ignore, "imap=%s"},
25724 + /* temporary workaround, due to old mount(8)? */
25725 + {Opt_ignore_silent, "relatime"},
25730 +/* ---------------------------------------------------------------------- */
25732 +static const char *au_parser_pattern(int val, match_table_t tbl)
25734 + struct match_token *p;
25737 + while (p->pattern) {
25738 + if (p->token == val)
25739 + return p->pattern;
25746 +static const char *au_optstr(int *val, match_table_t tbl)
25748 + struct match_token *p;
25755 + while (p->pattern) {
25757 + && (v & p->token) == p->token) {
25758 + *val &= ~p->token;
25759 + return p->pattern;
25768 +/* ---------------------------------------------------------------------- */
25770 +static match_table_t brperm = {
25771 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25772 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25773 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25777 +static match_table_t brattr = {
25779 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25780 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25781 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25782 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25783 +#ifdef CONFIG_AUFS_FHSM
25784 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25786 +#ifdef CONFIG_AUFS_XATTR
25787 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25788 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25789 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25790 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25791 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25792 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25795 + /* ro/rr branch */
25796 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25799 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25800 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25805 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25812 + p = strchr(str, '+');
25815 + v = match_token(str, table, args);
25817 + if (v & AuBrAttr_CMOO_Mask)
25818 + attr &= ~AuBrAttr_CMOO_Mask;
25823 + pr_warn("ignored branch attribute %s\n", str);
25833 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25841 + p = au_optstr(&perm, brattr);
25844 + memcpy(q, p, sz + 1);
25850 + p = au_optstr(&perm, brattr);
25854 + memcpy(q, p, sz + 1);
25860 + return q - str->a;
25863 +static int noinline_for_stack br_perm_val(char *perm)
25865 + int val, bad, sz;
25867 + substring_t args[MAX_OPT_ARGS];
25868 + au_br_perm_str_t attr;
25870 + p = strchr(perm, '+');
25873 + val = match_token(perm, brperm, args);
25877 + pr_warn("ignored branch permission %s\n", perm);
25878 + val = AuBrPerm_RO;
25884 + val |= br_attr_val(p + 1, brattr, args);
25887 + switch (val & AuBrPerm_Mask) {
25888 + case AuBrPerm_RO:
25889 + case AuBrPerm_RR:
25890 + bad = val & AuBrWAttr_Mask;
25891 + val &= ~AuBrWAttr_Mask;
25893 + case AuBrPerm_RW:
25894 + bad = val & AuBrRAttr_Mask;
25895 + val &= ~AuBrRAttr_Mask;
25900 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25901 + * does not treat it as an error, just warning.
25902 + * this is a tiny guard for the user operation.
25904 + if (val & AuBrAttr_UNPIN) {
25905 + bad |= AuBrAttr_UNPIN;
25906 + val &= ~AuBrAttr_UNPIN;
25909 + if (unlikely(bad)) {
25910 + sz = au_do_optstr_br_attr(&attr, bad);
25912 + pr_warn("ignored branch attribute %s\n", attr.a);
25919 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25921 + au_br_perm_str_t attr;
25927 + p = au_optstr(&perm, brperm);
25928 + AuDebugOn(!p || !*p);
25930 + memcpy(q, p, sz + 1);
25933 + sz = au_do_optstr_br_attr(&attr, perm);
25936 + memcpy(q, attr.a, sz + 1);
25939 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25942 +/* ---------------------------------------------------------------------- */
25944 +static match_table_t udbalevel = {
25945 + {AuOpt_UDBA_REVAL, "reval"},
25946 + {AuOpt_UDBA_NONE, "none"},
25947 +#ifdef CONFIG_AUFS_HNOTIFY
25948 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25949 +#ifdef CONFIG_AUFS_HFSNOTIFY
25950 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25956 +static int noinline_for_stack udba_val(char *str)
25958 + substring_t args[MAX_OPT_ARGS];
25960 + return match_token(str, udbalevel, args);
25963 +const char *au_optstr_udba(int udba)
25965 + return au_parser_pattern(udba, udbalevel);
25968 +/* ---------------------------------------------------------------------- */
25970 +static match_table_t au_wbr_create_policy = {
25971 + {AuWbrCreate_TDP, "tdp"},
25972 + {AuWbrCreate_TDP, "top-down-parent"},
25973 + {AuWbrCreate_RR, "rr"},
25974 + {AuWbrCreate_RR, "round-robin"},
25975 + {AuWbrCreate_MFS, "mfs"},
25976 + {AuWbrCreate_MFS, "most-free-space"},
25977 + {AuWbrCreate_MFSV, "mfs:%d"},
25978 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25980 + /* top-down regardless the parent, and then mfs */
25981 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25982 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25984 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25985 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25986 + {AuWbrCreate_PMFS, "pmfs"},
25987 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25988 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25989 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
25994 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
25995 + struct au_opt_wbr_create *create)
25998 + unsigned long long ull;
26001 + if (!match_u64(arg, &ull))
26002 + create->mfsrr_watermark = ull;
26004 + pr_err("bad integer in %s\n", str);
26011 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26012 + struct au_opt_wbr_create *create)
26017 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26018 + create->mfs_second = n;
26020 + pr_err("bad integer in %s\n", str);
26027 +static int noinline_for_stack
26028 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26031 + substring_t args[MAX_OPT_ARGS];
26033 + err = match_token(str, au_wbr_create_policy, args);
26034 + create->wbr_create = err;
26036 + case AuWbrCreate_MFSRRV:
26037 + case AuWbrCreate_TDMFSV:
26038 + case AuWbrCreate_PMFSRRV:
26039 + e = au_wbr_mfs_wmark(&args[0], str, create);
26041 + e = au_wbr_mfs_sec(&args[1], str, create);
26045 + case AuWbrCreate_MFSRR:
26046 + case AuWbrCreate_TDMFS:
26047 + case AuWbrCreate_PMFSRR:
26048 + e = au_wbr_mfs_wmark(&args[0], str, create);
26049 + if (unlikely(e)) {
26054 + case AuWbrCreate_MFS:
26055 + case AuWbrCreate_PMFS:
26056 + create->mfs_second = AUFS_MFS_DEF_SEC;
26058 + case AuWbrCreate_MFSV:
26059 + case AuWbrCreate_PMFSV:
26060 + e = au_wbr_mfs_sec(&args[0], str, create);
26069 +const char *au_optstr_wbr_create(int wbr_create)
26071 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26074 +static match_table_t au_wbr_copyup_policy = {
26075 + {AuWbrCopyup_TDP, "tdp"},
26076 + {AuWbrCopyup_TDP, "top-down-parent"},
26077 + {AuWbrCopyup_BUP, "bup"},
26078 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26079 + {AuWbrCopyup_BU, "bu"},
26080 + {AuWbrCopyup_BU, "bottom-up"},
26084 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26086 + substring_t args[MAX_OPT_ARGS];
26088 + return match_token(str, au_wbr_copyup_policy, args);
26091 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26093 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26096 +/* ---------------------------------------------------------------------- */
26098 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26100 +static void dump_opts(struct au_opts *opts)
26102 +#ifdef CONFIG_AUFS_DEBUG
26103 + /* reduce stack space */
26105 + struct au_opt_add *add;
26106 + struct au_opt_del *del;
26107 + struct au_opt_mod *mod;
26108 + struct au_opt_xino *xino;
26109 + struct au_opt_xino_itrunc *xino_itrunc;
26110 + struct au_opt_wbr_create *create;
26112 + struct au_opt *opt;
26115 + while (opt->type != Opt_tail) {
26116 + switch (opt->type) {
26118 + u.add = &opt->add;
26119 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26120 + u.add->bindex, u.add->pathname, u.add->perm,
26121 + u.add->path.dentry);
26125 + u.del = &opt->del;
26126 + AuDbg("del {%s, %p}\n",
26127 + u.del->pathname, u.del->h_path.dentry);
26131 + u.mod = &opt->mod;
26132 + AuDbg("mod {%s, 0x%x, %p}\n",
26133 + u.mod->path, u.mod->perm, u.mod->h_root);
26136 + u.add = &opt->add;
26137 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26138 + u.add->bindex, u.add->pathname, u.add->perm,
26139 + u.add->path.dentry);
26141 + case Opt_prepend:
26142 + u.add = &opt->add;
26143 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26144 + u.add->bindex, u.add->pathname, u.add->perm,
26145 + u.add->path.dentry);
26148 + AuDbg("dirwh %d\n", opt->dirwh);
26150 + case Opt_rdcache:
26151 + AuDbg("rdcache %d\n", opt->rdcache);
26154 + AuDbg("rdblk %u\n", opt->rdblk);
26156 + case Opt_rdblk_def:
26157 + AuDbg("rdblk_def\n");
26160 + AuDbg("rdhash %u\n", opt->rdhash);
26162 + case Opt_rdhash_def:
26163 + AuDbg("rdhash_def\n");
26166 + u.xino = &opt->xino;
26167 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26169 + case Opt_trunc_xino:
26170 + AuLabel(trunc_xino);
26172 + case Opt_notrunc_xino:
26173 + AuLabel(notrunc_xino);
26175 + case Opt_trunc_xino_path:
26176 + case Opt_itrunc_xino:
26177 + u.xino_itrunc = &opt->xino_itrunc;
26178 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26183 + case Opt_trunc_xib:
26184 + AuLabel(trunc_xib);
26186 + case Opt_notrunc_xib:
26187 + AuLabel(notrunc_xib);
26195 + case Opt_dirperm1:
26196 + AuLabel(dirperm1);
26198 + case Opt_nodirperm1:
26199 + AuLabel(nodirperm1);
26204 + case Opt_noplink:
26205 + AuLabel(noplink);
26207 + case Opt_list_plink:
26208 + AuLabel(list_plink);
26211 + AuDbg("udba %d, %s\n",
26212 + opt->udba, au_optstr_udba(opt->udba));
26220 + case Opt_diropq_a:
26221 + AuLabel(diropq_a);
26223 + case Opt_diropq_w:
26224 + AuLabel(diropq_w);
26226 + case Opt_warn_perm:
26227 + AuLabel(warn_perm);
26229 + case Opt_nowarn_perm:
26230 + AuLabel(nowarn_perm);
26232 + case Opt_verbose:
26233 + AuLabel(verbose);
26235 + case Opt_noverbose:
26236 + AuLabel(noverbose);
26247 + case Opt_wbr_create:
26248 + u.create = &opt->wbr_create;
26249 + AuDbg("create %d, %s\n", u.create->wbr_create,
26250 + au_optstr_wbr_create(u.create->wbr_create));
26251 + switch (u.create->wbr_create) {
26252 + case AuWbrCreate_MFSV:
26253 + case AuWbrCreate_PMFSV:
26254 + AuDbg("%d sec\n", u.create->mfs_second);
26256 + case AuWbrCreate_MFSRR:
26257 + case AuWbrCreate_TDMFS:
26258 + AuDbg("%llu watermark\n",
26259 + u.create->mfsrr_watermark);
26261 + case AuWbrCreate_MFSRRV:
26262 + case AuWbrCreate_TDMFSV:
26263 + case AuWbrCreate_PMFSRRV:
26264 + AuDbg("%llu watermark, %d sec\n",
26265 + u.create->mfsrr_watermark,
26266 + u.create->mfs_second);
26270 + case Opt_wbr_copyup:
26271 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26272 + au_optstr_wbr_copyup(opt->wbr_copyup));
26274 + case Opt_fhsm_sec:
26275 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26280 + case Opt_nodirren:
26281 + AuLabel(nodirren);
26297 +void au_opts_free(struct au_opts *opts)
26299 + struct au_opt *opt;
26302 + while (opt->type != Opt_tail) {
26303 + switch (opt->type) {
26306 + case Opt_prepend:
26307 + path_put(&opt->add.path);
26311 + path_put(&opt->del.h_path);
26315 + dput(opt->mod.h_root);
26318 + fput(opt->xino.file);
26325 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26326 + aufs_bindex_t bindex)
26329 + struct au_opt_add *add = &opt->add;
26332 + add->bindex = bindex;
26333 + add->perm = AuBrPerm_RO;
26334 + add->pathname = opt_str;
26335 + p = strchr(opt_str, '=');
26339 + add->perm = br_perm_val(p);
26342 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26345 + add->perm = AuBrPerm_RO;
26346 + if (au_test_fs_rr(add->path.dentry->d_sb))
26347 + add->perm = AuBrPerm_RR;
26348 + else if (!bindex && !(sb_flags & SB_RDONLY))
26349 + add->perm = AuBrPerm_RW;
26351 + opt->type = Opt_add;
26354 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26361 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26365 + del->pathname = args[0].from;
26366 + AuDbg("del path %s\n", del->pathname);
26368 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26369 + if (unlikely(err))
26370 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26375 +#if 0 /* reserved for future use */
26376 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26377 + struct au_opt_del *del, substring_t args[])
26380 + struct dentry *root;
26383 + root = sb->s_root;
26384 + aufs_read_lock(root, AuLock_FLUSH);
26385 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26386 + pr_err("out of bounds, %d\n", bindex);
26391 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26392 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26395 + aufs_read_unlock(root, !AuLock_IR);
26400 +static int noinline_for_stack
26401 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26404 + struct path path;
26408 + mod->path = args[0].from;
26409 + p = strchr(mod->path, '=');
26410 + if (unlikely(!p)) {
26411 + pr_err("no permission %s\n", args[0].from);
26416 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26417 + if (unlikely(err)) {
26418 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26422 + mod->perm = br_perm_val(p);
26423 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26424 + mod->h_root = dget(path.dentry);
26431 +#if 0 /* reserved for future use */
26432 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26433 + struct au_opt_mod *mod, substring_t args[])
26436 + struct dentry *root;
26439 + root = sb->s_root;
26440 + aufs_read_lock(root, AuLock_FLUSH);
26441 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26442 + pr_err("out of bounds, %d\n", bindex);
26447 + mod->perm = br_perm_val(args[1].from);
26448 + AuDbg("mod path %s, perm 0x%x, %s\n",
26449 + mod->path, mod->perm, args[1].from);
26450 + mod->h_root = dget(au_h_dptr(root, bindex));
26453 + aufs_read_unlock(root, !AuLock_IR);
26458 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26459 + substring_t args[])
26462 + struct file *file;
26464 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26465 + err = PTR_ERR(file);
26466 + if (IS_ERR(file))
26470 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26472 + pr_err("%s must be outside\n", args[0].from);
26477 + xino->file = file;
26478 + xino->path = args[0].from;
26484 +static int noinline_for_stack
26485 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26486 + struct au_opt_xino_itrunc *xino_itrunc,
26487 + substring_t args[])
26490 + aufs_bindex_t bbot, bindex;
26491 + struct path path;
26492 + struct dentry *root;
26494 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26495 + if (unlikely(err)) {
26496 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26500 + xino_itrunc->bindex = -1;
26501 + root = sb->s_root;
26502 + aufs_read_lock(root, AuLock_FLUSH);
26503 + bbot = au_sbbot(sb);
26504 + for (bindex = 0; bindex <= bbot; bindex++) {
26505 + if (au_h_dptr(root, bindex) == path.dentry) {
26506 + xino_itrunc->bindex = bindex;
26510 + aufs_read_unlock(root, !AuLock_IR);
26513 + if (unlikely(xino_itrunc->bindex < 0)) {
26514 + pr_err("no such branch %s\n", args[0].from);
26522 +/* called without aufs lock */
26523 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26525 + int err, n, token;
26526 + aufs_bindex_t bindex;
26527 + unsigned char skipped;
26528 + struct dentry *root;
26529 + struct au_opt *opt, *opt_tail;
26531 + /* reduce the stack space */
26533 + struct au_opt_xino_itrunc *xino_itrunc;
26534 + struct au_opt_wbr_create *create;
26537 + substring_t args[MAX_OPT_ARGS];
26541 + a = kmalloc(sizeof(*a), GFP_NOFS);
26542 + if (unlikely(!a))
26545 + root = sb->s_root;
26549 + opt_tail = opt + opts->max_opt - 1;
26550 + opt->type = Opt_tail;
26551 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26554 + token = match_token(opt_str, options, a->args);
26558 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26560 + err = opt_add(opt, opt_str, opts->sb_flags,
26562 + if (unlikely(!err && ++opt > opt_tail)) {
26566 + opt->type = Opt_tail;
26571 + if (unlikely(match_int(&a->args[0], &n))) {
26572 + pr_err("bad integer in %s\n", opt_str);
26576 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26579 + opt->type = token;
26582 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26583 + /*dummy bindex*/1);
26585 + opt->type = token;
26587 + case Opt_prepend:
26588 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26591 + opt->type = token;
26594 + err = au_opts_parse_del(&opt->del, a->args);
26596 + opt->type = token;
26598 +#if 0 /* reserved for future use */
26600 + del->pathname = "(indexed)";
26601 + if (unlikely(match_int(&args[0], &n))) {
26602 + pr_err("bad integer in %s\n", opt_str);
26605 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26607 + opt->type = token;
26611 + err = au_opts_parse_mod(&opt->mod, a->args);
26613 + opt->type = token;
26615 +#ifdef IMOD /* reserved for future use */
26617 + u.mod->path = "(indexed)";
26618 + if (unlikely(match_int(&a->args[0], &n))) {
26619 + pr_err("bad integer in %s\n", opt_str);
26622 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26624 + opt->type = token;
26628 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26630 + opt->type = token;
26633 + case Opt_trunc_xino_path:
26634 + err = au_opts_parse_xino_itrunc_path
26635 + (sb, &opt->xino_itrunc, a->args);
26637 + opt->type = token;
26640 + case Opt_itrunc_xino:
26641 + u.xino_itrunc = &opt->xino_itrunc;
26642 + if (unlikely(match_int(&a->args[0], &n))) {
26643 + pr_err("bad integer in %s\n", opt_str);
26646 + u.xino_itrunc->bindex = n;
26647 + aufs_read_lock(root, AuLock_FLUSH);
26648 + if (n < 0 || au_sbbot(sb) < n) {
26649 + pr_err("out of bounds, %d\n", n);
26650 + aufs_read_unlock(root, !AuLock_IR);
26653 + aufs_read_unlock(root, !AuLock_IR);
26655 + opt->type = token;
26659 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26662 + opt->type = token;
26665 + case Opt_rdcache:
26666 + if (unlikely(match_int(&a->args[0], &n))) {
26667 + pr_err("bad integer in %s\n", opt_str);
26670 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26671 + pr_err("rdcache must be smaller than %d\n",
26672 + AUFS_RDCACHE_MAX);
26675 + opt->rdcache = n;
26677 + opt->type = token;
26680 + if (unlikely(match_int(&a->args[0], &n)
26682 + || n > KMALLOC_MAX_SIZE)) {
26683 + pr_err("bad integer in %s\n", opt_str);
26686 + if (unlikely(n && n < NAME_MAX)) {
26687 + pr_err("rdblk must be larger than %d\n",
26693 + opt->type = token;
26696 + if (unlikely(match_int(&a->args[0], &n)
26698 + || n * sizeof(struct hlist_head)
26699 + > KMALLOC_MAX_SIZE)) {
26700 + pr_err("bad integer in %s\n", opt_str);
26705 + opt->type = token;
26708 + case Opt_trunc_xino:
26709 + case Opt_notrunc_xino:
26711 + case Opt_trunc_xib:
26712 + case Opt_notrunc_xib:
26715 + case Opt_dirperm1:
26716 + case Opt_nodirperm1:
26718 + case Opt_noplink:
26719 + case Opt_list_plink:
26722 + case Opt_diropq_a:
26723 + case Opt_diropq_w:
26724 + case Opt_warn_perm:
26725 + case Opt_nowarn_perm:
26726 + case Opt_verbose:
26727 + case Opt_noverbose:
26731 + case Opt_rdblk_def:
26732 + case Opt_rdhash_def:
26734 + case Opt_nodirren:
26738 + opt->type = token;
26742 + opt->udba = udba_val(a->args[0].from);
26743 + if (opt->udba >= 0) {
26745 + opt->type = token;
26747 + pr_err("wrong value, %s\n", opt_str);
26750 + case Opt_wbr_create:
26751 + u.create = &opt->wbr_create;
26752 + u.create->wbr_create
26753 + = au_wbr_create_val(a->args[0].from, u.create);
26754 + if (u.create->wbr_create >= 0) {
26756 + opt->type = token;
26758 + pr_err("wrong value, %s\n", opt_str);
26760 + case Opt_wbr_copyup:
26761 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26762 + if (opt->wbr_copyup >= 0) {
26764 + opt->type = token;
26766 + pr_err("wrong value, %s\n", opt_str);
26769 + case Opt_fhsm_sec:
26770 + if (unlikely(match_int(&a->args[0], &n)
26772 + pr_err("bad integer in %s\n", opt_str);
26775 + if (sysaufs_brs) {
26776 + opt->fhsm_second = n;
26777 + opt->type = token;
26779 + pr_warn("ignored %s\n", opt_str);
26784 + pr_warn("ignored %s\n", opt_str);
26786 + case Opt_ignore_silent:
26791 + pr_err("unknown option %s\n", opt_str);
26795 + if (!err && !skipped) {
26796 + if (unlikely(++opt > opt_tail)) {
26799 + opt->type = Opt_tail;
26802 + opt->type = Opt_tail;
26808 + if (unlikely(err))
26809 + au_opts_free(opts);
26815 +static int au_opt_wbr_create(struct super_block *sb,
26816 + struct au_opt_wbr_create *create)
26819 + struct au_sbinfo *sbinfo;
26821 + SiMustWriteLock(sb);
26823 + err = 1; /* handled */
26824 + sbinfo = au_sbi(sb);
26825 + if (sbinfo->si_wbr_create_ops->fin) {
26826 + err = sbinfo->si_wbr_create_ops->fin(sb);
26831 + sbinfo->si_wbr_create = create->wbr_create;
26832 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26833 + switch (create->wbr_create) {
26834 + case AuWbrCreate_MFSRRV:
26835 + case AuWbrCreate_MFSRR:
26836 + case AuWbrCreate_TDMFS:
26837 + case AuWbrCreate_TDMFSV:
26838 + case AuWbrCreate_PMFSRR:
26839 + case AuWbrCreate_PMFSRRV:
26840 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26842 + case AuWbrCreate_MFS:
26843 + case AuWbrCreate_MFSV:
26844 + case AuWbrCreate_PMFS:
26845 + case AuWbrCreate_PMFSV:
26846 + sbinfo->si_wbr_mfs.mfs_expire
26847 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26851 + if (sbinfo->si_wbr_create_ops->init)
26852 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26859 + * plus: processed without an error
26860 + * zero: unprocessed
26862 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26863 + struct au_opts *opts)
26866 + struct au_sbinfo *sbinfo;
26868 + SiMustWriteLock(sb);
26870 + err = 1; /* handled */
26871 + sbinfo = au_sbi(sb);
26872 + switch (opt->type) {
26874 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26875 + sbinfo->si_mntflags |= opt->udba;
26876 + opts->given_udba |= opt->udba;
26880 + au_opt_set(sbinfo->si_mntflags, PLINK);
26882 + case Opt_noplink:
26883 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26884 + au_plink_put(sb, /*verbose*/1);
26885 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26887 + case Opt_list_plink:
26888 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26889 + au_plink_list(sb);
26893 + au_opt_set(sbinfo->si_mntflags, DIO);
26894 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26897 + au_opt_clr(sbinfo->si_mntflags, DIO);
26898 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26901 + case Opt_fhsm_sec:
26902 + au_fhsm_set(sbinfo, opt->fhsm_second);
26905 + case Opt_diropq_a:
26906 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26908 + case Opt_diropq_w:
26909 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26912 + case Opt_warn_perm:
26913 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26915 + case Opt_nowarn_perm:
26916 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26919 + case Opt_verbose:
26920 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26922 + case Opt_noverbose:
26923 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26927 + au_opt_set(sbinfo->si_mntflags, SUM);
26930 + au_opt_clr(sbinfo->si_mntflags, SUM);
26931 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26934 + au_opt_clr(sbinfo->si_mntflags, SUM);
26935 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26938 + case Opt_wbr_create:
26939 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26941 + case Opt_wbr_copyup:
26942 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26943 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26947 + sbinfo->si_dirwh = opt->dirwh;
26950 + case Opt_rdcache:
26951 + sbinfo->si_rdcache
26952 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26955 + sbinfo->si_rdblk = opt->rdblk;
26957 + case Opt_rdblk_def:
26958 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26961 + sbinfo->si_rdhash = opt->rdhash;
26963 + case Opt_rdhash_def:
26964 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26968 + au_opt_set(sbinfo->si_mntflags, SHWH);
26971 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26974 + case Opt_dirperm1:
26975 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26977 + case Opt_nodirperm1:
26978 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26981 + case Opt_trunc_xino:
26982 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26984 + case Opt_notrunc_xino:
26985 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26988 + case Opt_trunc_xino_path:
26989 + case Opt_itrunc_xino:
26990 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
26996 + case Opt_trunc_xib:
26997 + au_fset_opts(opts->flags, TRUNC_XIB);
26999 + case Opt_notrunc_xib:
27000 + au_fclr_opts(opts->flags, TRUNC_XIB);
27005 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27006 + err = au_dr_opt_set(sb);
27011 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27013 + case Opt_nodirren:
27015 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27016 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27022 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27026 + sb->s_flags |= SB_POSIXACL;
27029 + sb->s_flags &= ~SB_POSIXACL;
27041 + * returns tri-state.
27042 + * plus: processed without an error
27043 + * zero: unprocessed
27046 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27047 + struct au_opts *opts)
27049 + int err, do_refresh;
27052 + switch (opt->type) {
27054 + opt->add.bindex = au_sbbot(sb) + 1;
27055 + if (opt->add.bindex < 0)
27056 + opt->add.bindex = 0;
27058 + /* Always goto add, not fallthrough */
27059 + case Opt_prepend:
27060 + opt->add.bindex = 0;
27062 + add: /* indented label */
27064 + err = au_br_add(sb, &opt->add,
27065 + au_ftest_opts(opts->flags, REMOUNT));
27068 + au_fset_opts(opts->flags, REFRESH);
27074 + err = au_br_del(sb, &opt->del,
27075 + au_ftest_opts(opts->flags, REMOUNT));
27078 + au_fset_opts(opts->flags, TRUNC_XIB);
27079 + au_fset_opts(opts->flags, REFRESH);
27085 + err = au_br_mod(sb, &opt->mod,
27086 + au_ftest_opts(opts->flags, REMOUNT),
27091 + au_fset_opts(opts->flags, REFRESH);
27098 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27099 + struct au_opt_xino **opt_xino,
27100 + struct au_opts *opts)
27105 + switch (opt->type) {
27107 + err = au_xino_set(sb, &opt->xino,
27108 + !!au_ftest_opts(opts->flags, REMOUNT));
27109 + if (unlikely(err))
27112 + *opt_xino = &opt->xino;
27117 + *opt_xino = (void *)-1;
27124 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27125 + unsigned int pending)
27128 + aufs_bindex_t bindex, bbot;
27129 + unsigned char do_plink, skip, do_free, can_no_dreval;
27130 + struct au_branch *br;
27131 + struct au_wbr *wbr;
27132 + struct dentry *root, *dentry;
27133 + struct inode *dir, *h_dir;
27134 + struct au_sbinfo *sbinfo;
27135 + struct au_hinode *hdir;
27137 + SiMustAnyLock(sb);
27139 + sbinfo = au_sbi(sb);
27140 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27142 + if (!(sb_flags & SB_RDONLY)) {
27143 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27144 + pr_warn("first branch should be rw\n");
27145 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27146 + pr_warn_once("shwh should be used with ro\n");
27149 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27150 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27151 + pr_warn_once("udba=*notify requires xino\n");
27153 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27154 + pr_warn_once("dirperm1 breaks the protection"
27155 + " by the permission bits on the lower branch\n");
27159 + root = sb->s_root;
27160 + dir = d_inode(root);
27161 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27162 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27164 + bbot = au_sbbot(sb);
27165 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27167 + h_dir = au_h_iptr(dir, bindex);
27168 + br = au_sbr(sb, bindex);
27170 + if ((br->br_perm & AuBrAttr_ICEX)
27171 + && !h_dir->i_op->listxattr)
27172 + br->br_perm &= ~AuBrAttr_ICEX;
27173 +#if 0 /* untested */
27174 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27175 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27176 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27180 + wbr = br->br_wbr;
27182 + wbr_wh_read_lock(wbr);
27184 + if (!au_br_writable(br->br_perm)) {
27187 + || (!wbr->wbr_whbase
27188 + && !wbr->wbr_plink
27189 + && !wbr->wbr_orph));
27190 + } else if (!au_br_wh_linkable(br->br_perm)) {
27191 + /* skip = (!br->br_whbase && !br->br_orph); */
27192 + skip = (!wbr || !wbr->wbr_whbase);
27193 + if (skip && wbr) {
27195 + skip = !!wbr->wbr_plink;
27197 + skip = !wbr->wbr_plink;
27200 + /* skip = (br->br_whbase && br->br_ohph); */
27201 + skip = (wbr && wbr->wbr_whbase);
27204 + skip = !!wbr->wbr_plink;
27206 + skip = !wbr->wbr_plink;
27210 + wbr_wh_read_unlock(wbr);
27212 + if (can_no_dreval) {
27213 + dentry = br->br_path.dentry;
27214 + spin_lock(&dentry->d_lock);
27215 + if (dentry->d_flags &
27216 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27217 + can_no_dreval = 0;
27218 + spin_unlock(&dentry->d_lock);
27221 + if (au_br_fhsm(br->br_perm)) {
27223 + AuDebugOn(!br->br_fhsm);
27229 + hdir = au_hi(dir, bindex);
27230 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27232 + wbr_wh_write_lock(wbr);
27233 + err = au_wh_init(br, sb);
27235 + wbr_wh_write_unlock(wbr);
27236 + au_hn_inode_unlock(hdir);
27238 + if (!err && do_free) {
27239 + au_kfree_rcu(wbr);
27240 + br->br_wbr = NULL;
27244 + if (can_no_dreval)
27245 + au_fset_si(sbinfo, NO_DREVAL);
27247 + au_fclr_si(sbinfo, NO_DREVAL);
27250 + au_fset_si(sbinfo, FHSM);
27251 + for (bindex = bbot; bindex >= 0; bindex--) {
27252 + br = au_sbr(sb, bindex);
27253 + if (au_br_fhsm(br->br_perm)) {
27254 + au_fhsm_set_bottom(sb, bindex);
27259 + au_fclr_si(sbinfo, FHSM);
27260 + au_fhsm_set_bottom(sb, -1);
27266 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27269 + unsigned int tmp;
27270 + aufs_bindex_t bindex, bbot;
27271 + struct au_opt *opt;
27272 + struct au_opt_xino *opt_xino, xino;
27273 + struct au_sbinfo *sbinfo;
27274 + struct au_branch *br;
27275 + struct inode *dir;
27277 + SiMustWriteLock(sb);
27282 + while (err >= 0 && opt->type != Opt_tail)
27283 + err = au_opt_simple(sb, opt++, opts);
27286 + else if (unlikely(err < 0))
27289 + /* disable xino and udba temporary */
27290 + sbinfo = au_sbi(sb);
27291 + tmp = sbinfo->si_mntflags;
27292 + au_opt_clr(sbinfo->si_mntflags, XINO);
27293 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27296 + while (err >= 0 && opt->type != Opt_tail)
27297 + err = au_opt_br(sb, opt++, opts);
27300 + else if (unlikely(err < 0))
27303 + bbot = au_sbbot(sb);
27304 + if (unlikely(bbot < 0)) {
27306 + pr_err("no branches\n");
27310 + if (au_opt_test(tmp, XINO))
27311 + au_opt_set(sbinfo->si_mntflags, XINO);
27313 + while (!err && opt->type != Opt_tail)
27314 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27315 + if (unlikely(err))
27318 + err = au_opts_verify(sb, sb->s_flags, tmp);
27319 + if (unlikely(err))
27322 + /* restore xino */
27323 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27324 + xino.file = au_xino_def(sb);
27325 + err = PTR_ERR(xino.file);
27326 + if (IS_ERR(xino.file))
27329 + err = au_xino_set(sb, &xino, /*remount*/0);
27331 + if (unlikely(err))
27335 + /* restore udba */
27336 + tmp &= AuOptMask_UDBA;
27337 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27338 + sbinfo->si_mntflags |= tmp;
27339 + bbot = au_sbbot(sb);
27340 + for (bindex = 0; bindex <= bbot; bindex++) {
27341 + br = au_sbr(sb, bindex);
27342 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27343 + if (unlikely(err))
27344 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27346 + /* go on even if err */
27348 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27349 + dir = d_inode(sb->s_root);
27350 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27357 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27360 + unsigned char no_dreval;
27361 + struct inode *dir;
27362 + struct au_opt_xino *opt_xino;
27363 + struct au_opt *opt;
27364 + struct au_sbinfo *sbinfo;
27366 + SiMustWriteLock(sb);
27368 + err = au_dr_opt_flush(sb);
27369 + if (unlikely(err))
27371 + au_fset_opts(opts->flags, DR_FLUSHED);
27373 + dir = d_inode(sb->s_root);
27374 + sbinfo = au_sbi(sb);
27377 + while (err >= 0 && opt->type != Opt_tail) {
27378 + err = au_opt_simple(sb, opt, opts);
27380 + err = au_opt_br(sb, opt, opts);
27382 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27388 + /* go on even err */
27390 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27391 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27392 + if (unlikely(rerr && !err))
27395 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27396 + au_fset_opts(opts->flags, REFRESH_IDOP);
27398 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27399 + rerr = au_xib_trunc(sb);
27400 + if (unlikely(rerr && !err))
27404 + /* will be handled by the caller */
27405 + if (!au_ftest_opts(opts->flags, REFRESH)
27406 + && (opts->given_udba
27407 + || au_opt_test(sbinfo->si_mntflags, XINO)
27408 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27410 + au_fset_opts(opts->flags, REFRESH);
27412 + AuDbg("status 0x%x\n", opts->flags);
27418 +/* ---------------------------------------------------------------------- */
27420 +unsigned int au_opt_udba(struct super_block *sb)
27422 + return au_mntflags(sb) & AuOptMask_UDBA;
27424 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27425 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27426 +++ linux/fs/aufs/opts.h 2021-02-24 13:33:42.747680497 +0100
27428 +/* SPDX-License-Identifier: GPL-2.0 */
27430 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27432 + * This program, aufs is free software; you can redistribute it and/or modify
27433 + * it under the terms of the GNU General Public License as published by
27434 + * the Free Software Foundation; either version 2 of the License, or
27435 + * (at your option) any later version.
27437 + * This program is distributed in the hope that it will be useful,
27438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27440 + * GNU General Public License for more details.
27442 + * You should have received a copy of the GNU General Public License
27443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27447 + * mount options/flags
27450 +#ifndef __AUFS_OPTS_H__
27451 +#define __AUFS_OPTS_H__
27455 +#include <linux/path.h>
27459 +/* ---------------------------------------------------------------------- */
27462 +#define AuOpt_XINO 1 /* external inode number bitmap
27463 + and translation table */
27464 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27465 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27466 +#define AuOpt_UDBA_REVAL (1 << 3)
27467 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27468 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27469 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27470 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27472 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27473 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27474 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27475 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27476 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27477 +#define AuOpt_DIO (1 << 14) /* direct io */
27478 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27480 +#ifndef CONFIG_AUFS_HNOTIFY
27481 +#undef AuOpt_UDBA_HNOTIFY
27482 +#define AuOpt_UDBA_HNOTIFY 0
27484 +#ifndef CONFIG_AUFS_DIRREN
27485 +#undef AuOpt_DIRREN
27486 +#define AuOpt_DIRREN 0
27488 +#ifndef CONFIG_AUFS_SHWH
27490 +#define AuOpt_SHWH 0
27493 +#define AuOpt_Def (AuOpt_XINO \
27494 + | AuOpt_UDBA_REVAL \
27496 + /* | AuOpt_DIRPERM1 */ \
27497 + | AuOpt_WARN_PERM)
27498 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27499 + | AuOpt_UDBA_REVAL \
27500 + | AuOpt_UDBA_HNOTIFY)
27502 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27503 +#define au_opt_set(flags, name) do { \
27504 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27505 + ((flags) |= AuOpt_##name); \
27507 +#define au_opt_set_udba(flags, name) do { \
27508 + (flags) &= ~AuOptMask_UDBA; \
27509 + ((flags) |= AuOpt_##name); \
27511 +#define au_opt_clr(flags, name) do { \
27512 + ((flags) &= ~AuOpt_##name); \
27515 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27517 +#ifdef CONFIG_PROC_FS
27520 + return mntflags & ~AuOpt_PLINK;
27524 +/* ---------------------------------------------------------------------- */
27526 +/* policies to select one among multiple writable branches */
27528 + AuWbrCreate_TDP, /* top down parent */
27529 + AuWbrCreate_RR, /* round robin */
27530 + AuWbrCreate_MFS, /* most free space */
27531 + AuWbrCreate_MFSV, /* mfs with seconds */
27532 + AuWbrCreate_MFSRR, /* mfs then rr */
27533 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27534 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27535 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27536 + AuWbrCreate_PMFS, /* parent and mfs */
27537 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27538 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27539 + AuWbrCreate_PMFSRRV, /* plus seconds */
27541 + AuWbrCreate_Def = AuWbrCreate_TDP
27545 + AuWbrCopyup_TDP, /* top down parent */
27546 + AuWbrCopyup_BUP, /* bottom up parent */
27547 + AuWbrCopyup_BU, /* bottom up */
27549 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27552 +/* ---------------------------------------------------------------------- */
27554 +struct au_opt_add {
27555 + aufs_bindex_t bindex;
27558 + struct path path;
27561 +struct au_opt_del {
27563 + struct path h_path;
27566 +struct au_opt_mod {
27569 + struct dentry *h_root;
27572 +struct au_opt_xino {
27574 + struct file *file;
27577 +struct au_opt_xino_itrunc {
27578 + aufs_bindex_t bindex;
27581 +struct au_opt_wbr_create {
27584 + unsigned long long mfsrr_watermark;
27590 + struct au_opt_xino xino;
27591 + struct au_opt_xino_itrunc xino_itrunc;
27592 + struct au_opt_add add;
27593 + struct au_opt_del del;
27594 + struct au_opt_mod mod;
27597 + unsigned int rdblk;
27598 + unsigned int rdhash;
27600 + struct au_opt_wbr_create wbr_create;
27602 + unsigned int fhsm_second;
27607 +#define AuOpts_REMOUNT 1
27608 +#define AuOpts_REFRESH (1 << 1)
27609 +#define AuOpts_TRUNC_XIB (1 << 2)
27610 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27611 +#define AuOpts_REFRESH_IDOP (1 << 4)
27612 +#define AuOpts_DR_FLUSHED (1 << 5)
27613 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27614 +#define au_fset_opts(flags, name) \
27615 + do { (flags) |= AuOpts_##name; } while (0)
27616 +#define au_fclr_opts(flags, name) \
27617 + do { (flags) &= ~AuOpts_##name; } while (0)
27619 +#ifndef CONFIG_AUFS_DIRREN
27620 +#undef AuOpts_DR_FLUSHED
27621 +#define AuOpts_DR_FLUSHED 0
27625 + struct au_opt *opt;
27628 + unsigned int given_udba;
27629 + unsigned int flags;
27630 + unsigned long sb_flags;
27633 +/* ---------------------------------------------------------------------- */
27636 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27637 +const char *au_optstr_udba(int udba);
27638 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27639 +const char *au_optstr_wbr_create(int wbr_create);
27641 +void au_opts_free(struct au_opts *opts);
27642 +struct super_block;
27643 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27644 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27645 + unsigned int pending);
27646 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27647 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27649 +unsigned int au_opt_udba(struct super_block *sb);
27651 +#endif /* __KERNEL__ */
27652 +#endif /* __AUFS_OPTS_H__ */
27653 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27654 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27655 +++ linux/fs/aufs/plink.c 2021-02-24 13:33:42.747680497 +0100
27657 +// SPDX-License-Identifier: GPL-2.0
27659 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27661 + * This program, aufs is free software; you can redistribute it and/or modify
27662 + * it under the terms of the GNU General Public License as published by
27663 + * the Free Software Foundation; either version 2 of the License, or
27664 + * (at your option) any later version.
27666 + * This program is distributed in the hope that it will be useful,
27667 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27668 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27669 + * GNU General Public License for more details.
27671 + * You should have received a copy of the GNU General Public License
27672 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27682 + * the pseudo-link maintenance mode.
27683 + * during a user process maintains the pseudo-links,
27684 + * prohibit adding a new plink and branch manipulation.
27688 + * For entry functions which will handle plink, and i_mutex is already held
27690 + * They cannot wait and should return an error at once.
27691 + * Callers has to check the error.
27693 + * For entry functions which will handle plink, but i_mutex is not held
27695 + * They can wait the plink maintenance mode to finish.
27697 + * They behave like F_SETLK and F_SETLKW.
27698 + * If the caller never handle plink, then both flags are unnecessary.
27701 +int au_plink_maint(struct super_block *sb, int flags)
27705 + struct task_struct *parent, *prev;
27706 + struct au_sbinfo *sbi;
27708 + SiMustAnyLock(sb);
27711 + if (!au_opt_test(au_mntflags(sb), PLINK))
27714 + sbi = au_sbi(sb);
27715 + pid = sbi->si_plink_maint_pid;
27716 + if (!pid || pid == current->pid)
27719 + /* todo: it highly depends upon /sbin/mount.aufs */
27721 + parent = current;
27725 + parent = rcu_dereference(parent->real_parent);
27726 + if (parent == prev)
27728 + ppid = task_pid_vnr(parent);
27729 + if (pid == ppid) {
27730 + rcu_read_unlock();
27735 + rcu_read_unlock();
27737 + if (au_ftest_lock(flags, NOPLMW)) {
27738 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27739 + /* AuDebugOn(!lockdep_depth(current)); */
27740 + while (sbi->si_plink_maint_pid) {
27741 + si_read_unlock(sb);
27742 + /* gave up wake_up_bit() */
27743 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27745 + if (au_ftest_lock(flags, FLUSH))
27746 + au_nwt_flush(&sbi->si_nowait);
27747 + si_noflush_read_lock(sb);
27749 + } else if (au_ftest_lock(flags, NOPLM)) {
27750 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27758 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27760 + spin_lock(&sbinfo->si_plink_maint_lock);
27761 + sbinfo->si_plink_maint_pid = 0;
27762 + spin_unlock(&sbinfo->si_plink_maint_lock);
27763 + wake_up_all(&sbinfo->si_plink_wq);
27766 +int au_plink_maint_enter(struct super_block *sb)
27769 + struct au_sbinfo *sbinfo;
27772 + sbinfo = au_sbi(sb);
27773 + /* make sure i am the only one in this fs */
27774 + si_write_lock(sb, AuLock_FLUSH);
27775 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27776 + spin_lock(&sbinfo->si_plink_maint_lock);
27777 + if (!sbinfo->si_plink_maint_pid)
27778 + sbinfo->si_plink_maint_pid = current->pid;
27781 + spin_unlock(&sbinfo->si_plink_maint_lock);
27783 + si_write_unlock(sb);
27788 +/* ---------------------------------------------------------------------- */
27790 +#ifdef CONFIG_AUFS_DEBUG
27791 +void au_plink_list(struct super_block *sb)
27794 + struct au_sbinfo *sbinfo;
27795 + struct hlist_bl_head *hbl;
27796 + struct hlist_bl_node *pos;
27797 + struct au_icntnr *icntnr;
27799 + SiMustAnyLock(sb);
27801 + sbinfo = au_sbi(sb);
27802 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27803 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27805 + for (i = 0; i < AuPlink_NHASH; i++) {
27806 + hbl = sbinfo->si_plink + i;
27807 + hlist_bl_lock(hbl);
27808 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27809 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27810 + hlist_bl_unlock(hbl);
27815 +/* is the inode pseudo-linked? */
27816 +int au_plink_test(struct inode *inode)
27819 + struct au_sbinfo *sbinfo;
27820 + struct hlist_bl_head *hbl;
27821 + struct hlist_bl_node *pos;
27822 + struct au_icntnr *icntnr;
27824 + sbinfo = au_sbi(inode->i_sb);
27825 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27826 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27827 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27830 + i = au_plink_hash(inode->i_ino);
27831 + hbl = sbinfo->si_plink + i;
27832 + hlist_bl_lock(hbl);
27833 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27834 + if (&icntnr->vfs_inode == inode) {
27838 + hlist_bl_unlock(hbl);
27842 +/* ---------------------------------------------------------------------- */
27845 + * generate a name for plink.
27846 + * the file will be stored under AUFS_WH_PLINKDIR.
27848 +/* 20 is max digits length of ulong 64 */
27849 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27851 +static int plink_name(char *name, int len, struct inode *inode,
27852 + aufs_bindex_t bindex)
27855 + struct inode *h_inode;
27857 + h_inode = au_h_iptr(inode, bindex);
27858 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27862 +struct au_do_plink_lkup_args {
27863 + struct dentry **errp;
27864 + struct qstr *tgtname;
27865 + struct dentry *h_parent;
27866 + struct au_branch *br;
27869 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27870 + struct dentry *h_parent,
27871 + struct au_branch *br)
27873 + struct dentry *h_dentry;
27874 + struct inode *h_inode;
27876 + h_inode = d_inode(h_parent);
27877 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27878 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27879 + inode_unlock_shared(h_inode);
27883 +static void au_call_do_plink_lkup(void *args)
27885 + struct au_do_plink_lkup_args *a = args;
27886 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27889 +/* lookup the plink-ed @inode under the branch at @bindex */
27890 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27892 + struct dentry *h_dentry, *h_parent;
27893 + struct au_branch *br;
27895 + char a[PLINK_NAME_LEN];
27896 + struct qstr tgtname = QSTR_INIT(a, 0);
27898 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27900 + br = au_sbr(inode->i_sb, bindex);
27901 + h_parent = br->br_wbr->wbr_plink;
27902 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27904 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27905 + struct au_do_plink_lkup_args args = {
27906 + .errp = &h_dentry,
27907 + .tgtname = &tgtname,
27908 + .h_parent = h_parent,
27912 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27913 + if (unlikely(wkq_err))
27914 + h_dentry = ERR_PTR(wkq_err);
27916 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27921 +/* create a pseudo-link */
27922 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27923 + struct dentry *h_dentry, struct au_branch *br)
27926 + struct path h_path = {
27927 + .mnt = au_br_mnt(br)
27929 + struct inode *h_dir, *delegated;
27931 + h_dir = d_inode(h_parent);
27932 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27934 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27935 + err = PTR_ERR(h_path.dentry);
27936 + if (IS_ERR(h_path.dentry))
27940 + /* wh.plink dir is not monitored */
27941 + /* todo: is it really safe? */
27942 + if (d_is_positive(h_path.dentry)
27943 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27944 + delegated = NULL;
27945 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27946 + if (unlikely(err == -EWOULDBLOCK)) {
27947 + pr_warn("cannot retry for NFSv4 delegation"
27948 + " for an internal unlink\n");
27951 + dput(h_path.dentry);
27952 + h_path.dentry = NULL;
27956 + if (!err && d_is_negative(h_path.dentry)) {
27957 + delegated = NULL;
27958 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27959 + if (unlikely(err == -EWOULDBLOCK)) {
27960 + pr_warn("cannot retry for NFSv4 delegation"
27961 + " for an internal link\n");
27965 + dput(h_path.dentry);
27968 + inode_unlock(h_dir);
27972 +struct do_whplink_args {
27974 + struct qstr *tgt;
27975 + struct dentry *h_parent;
27976 + struct dentry *h_dentry;
27977 + struct au_branch *br;
27980 +static void call_do_whplink(void *args)
27982 + struct do_whplink_args *a = args;
27983 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27986 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27987 + aufs_bindex_t bindex, struct au_branch *br)
27989 + int err, wkq_err;
27990 + struct au_wbr *wbr;
27991 + struct dentry *h_parent;
27992 + char a[PLINK_NAME_LEN];
27993 + struct qstr tgtname = QSTR_INIT(a, 0);
27995 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
27996 + h_parent = wbr->wbr_plink;
27997 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27999 + /* always superio. */
28000 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28001 + struct do_whplink_args args = {
28004 + .h_parent = h_parent,
28005 + .h_dentry = h_dentry,
28008 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28009 + if (unlikely(wkq_err))
28012 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28018 + * create a new pseudo-link for @h_dentry on @bindex.
28019 + * the linked inode is held in aufs @inode.
28021 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28022 + struct dentry *h_dentry)
28024 + struct super_block *sb;
28025 + struct au_sbinfo *sbinfo;
28026 + struct hlist_bl_head *hbl;
28027 + struct hlist_bl_node *pos;
28028 + struct au_icntnr *icntnr;
28029 + int found, err, cnt, i;
28031 + sb = inode->i_sb;
28032 + sbinfo = au_sbi(sb);
28033 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28034 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28036 + found = au_plink_test(inode);
28040 + i = au_plink_hash(inode->i_ino);
28041 + hbl = sbinfo->si_plink + i;
28044 + hlist_bl_lock(hbl);
28045 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28046 + if (&icntnr->vfs_inode == inode) {
28052 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28053 + hlist_bl_add_head(&icntnr->plink, hbl);
28055 + hlist_bl_unlock(hbl);
28057 + cnt = au_hbl_count(hbl);
28058 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28059 + if (cnt > AUFS_PLINK_WARN)
28060 + AuWarn1(msg ", %d\n", cnt);
28062 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28063 + if (unlikely(err)) {
28064 + pr_warn("err %d, damaged pseudo link.\n", err);
28065 + au_hbl_del(&icntnr->plink, hbl);
28066 + iput(&icntnr->vfs_inode);
28069 + iput(&icntnr->vfs_inode);
28072 +/* free all plinks */
28073 +void au_plink_put(struct super_block *sb, int verbose)
28076 + struct au_sbinfo *sbinfo;
28077 + struct hlist_bl_head *hbl;
28078 + struct hlist_bl_node *pos, *tmp;
28079 + struct au_icntnr *icntnr;
28081 + SiMustWriteLock(sb);
28083 + sbinfo = au_sbi(sb);
28084 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28085 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28087 + /* no spin_lock since sbinfo is write-locked */
28089 + for (i = 0; i < AuPlink_NHASH; i++) {
28090 + hbl = sbinfo->si_plink + i;
28091 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28092 + pr_warn("pseudo-link is not flushed");
28095 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28096 + iput(&icntnr->vfs_inode);
28097 + INIT_HLIST_BL_HEAD(hbl);
28101 +void au_plink_clean(struct super_block *sb, int verbose)
28103 + struct dentry *root;
28105 + root = sb->s_root;
28106 + aufs_write_lock(root);
28107 + if (au_opt_test(au_mntflags(sb), PLINK))
28108 + au_plink_put(sb, verbose);
28109 + aufs_write_unlock(root);
28112 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28115 + aufs_bindex_t btop, bbot, bindex;
28118 + btop = au_ibtop(inode);
28119 + bbot = au_ibbot(inode);
28121 + for (bindex = btop; bindex <= bbot; bindex++) {
28122 + if (!au_h_iptr(inode, bindex)
28123 + || au_ii_br_id(inode, bindex) != br_id)
28125 + au_set_h_iptr(inode, bindex, NULL, 0);
28130 + for (bindex = btop; bindex <= bbot; bindex++)
28131 + if (au_h_iptr(inode, bindex)) {
28141 +/* free the plinks on a branch specified by @br_id */
28142 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28144 + struct au_sbinfo *sbinfo;
28145 + struct hlist_bl_head *hbl;
28146 + struct hlist_bl_node *pos, *tmp;
28147 + struct au_icntnr *icntnr;
28148 + struct inode *inode;
28151 + SiMustWriteLock(sb);
28153 + sbinfo = au_sbi(sb);
28154 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28155 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28157 + /* no bit_lock since sbinfo is write-locked */
28158 + for (i = 0; i < AuPlink_NHASH; i++) {
28159 + hbl = sbinfo->si_plink + i;
28160 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28161 + inode = au_igrab(&icntnr->vfs_inode);
28162 + ii_write_lock_child(inode);
28163 + do_put = au_plink_do_half_refresh(inode, br_id);
28165 + hlist_bl_del(&icntnr->plink);
28168 + ii_write_unlock(inode);
28173 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28174 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28175 +++ linux/fs/aufs/poll.c 2021-02-24 13:33:42.747680497 +0100
28177 +// SPDX-License-Identifier: GPL-2.0
28179 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28181 + * This program, aufs is free software; you can redistribute it and/or modify
28182 + * it under the terms of the GNU General Public License as published by
28183 + * the Free Software Foundation; either version 2 of the License, or
28184 + * (at your option) any later version.
28186 + * This program is distributed in the hope that it will be useful,
28187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28189 + * GNU General Public License for more details.
28191 + * You should have received a copy of the GNU General Public License
28192 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28197 + * There is only one filesystem which implements ->poll operation, currently.
28202 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28205 + struct file *h_file;
28206 + struct super_block *sb;
28208 + /* We should pretend an error happened. */
28209 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28210 + sb = file->f_path.dentry->d_sb;
28211 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28213 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28214 + if (IS_ERR(h_file)) {
28215 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28219 + mask = vfs_poll(h_file, pt);
28220 + fput(h_file); /* instead of au_read_post() */
28223 + si_read_unlock(sb);
28224 + if (mask & EPOLLERR)
28225 + AuDbg("mask 0x%x\n", mask);
28228 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28229 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28230 +++ linux/fs/aufs/posix_acl.c 2021-02-24 13:33:42.747680497 +0100
28232 +// SPDX-License-Identifier: GPL-2.0
28234 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28236 + * This program, aufs is free software; you can redistribute it and/or modify
28237 + * it under the terms of the GNU General Public License as published by
28238 + * the Free Software Foundation; either version 2 of the License, or
28239 + * (at your option) any later version.
28241 + * This program is distributed in the hope that it will be useful,
28242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28244 + * GNU General Public License for more details.
28246 + * You should have received a copy of the GNU General Public License
28247 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28251 + * posix acl operations
28254 +#include <linux/fs.h>
28257 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28259 + struct posix_acl *acl;
28261 + aufs_bindex_t bindex;
28262 + struct inode *h_inode;
28263 + struct super_block *sb;
28266 + sb = inode->i_sb;
28267 + si_read_lock(sb, AuLock_FLUSH);
28268 + ii_read_lock_child(inode);
28269 + if (!(sb->s_flags & SB_POSIXACL))
28272 + bindex = au_ibtop(inode);
28273 + h_inode = au_h_iptr(inode, bindex);
28274 + if (unlikely(!h_inode
28275 + || ((h_inode->i_mode & S_IFMT)
28276 + != (inode->i_mode & S_IFMT)))) {
28277 + err = au_busy_or_stale();
28278 + acl = ERR_PTR(err);
28282 + /* always topmost only */
28283 + acl = get_acl(h_inode, type);
28285 + forget_cached_acl(inode, type);
28287 + set_cached_acl(inode, type, acl);
28290 + ii_read_unlock(inode);
28291 + si_read_unlock(sb);
28293 + AuTraceErrPtr(acl);
28297 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28301 + struct dentry *dentry;
28302 + struct au_sxattr arg = {
28303 + .type = AU_ACL_SET,
28310 + IMustLock(inode);
28312 + if (inode->i_ino == AUFS_ROOT_INO)
28313 + dentry = dget(inode->i_sb->s_root);
28315 + dentry = d_find_alias(inode);
28317 + dentry = d_find_any_alias(inode);
28319 + pr_warn("cannot handle this inode, "
28320 + "please report to aufs-users ML\n");
28326 + ssz = au_sxattr(dentry, inode, &arg);
28327 + /* forget even it if succeeds since the branch might set differently */
28328 + forget_cached_acl(inode, type);
28337 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28338 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28339 +++ linux/fs/aufs/procfs.c 2021-02-24 13:33:42.747680497 +0100
28341 +// SPDX-License-Identifier: GPL-2.0
28343 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28345 + * This program, aufs is free software; you can redistribute it and/or modify
28346 + * it under the terms of the GNU General Public License as published by
28347 + * the Free Software Foundation; either version 2 of the License, or
28348 + * (at your option) any later version.
28350 + * This program is distributed in the hope that it will be useful,
28351 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28352 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28353 + * GNU General Public License for more details.
28355 + * You should have received a copy of the GNU General Public License
28356 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28360 + * procfs interfaces
28363 +#include <linux/proc_fs.h>
28366 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28368 + struct au_sbinfo *sbinfo;
28370 + sbinfo = file->private_data;
28372 + au_plink_maint_leave(sbinfo);
28373 + kobject_put(&sbinfo->si_kobj);
28379 +static void au_procfs_plm_write_clean(struct file *file)
28381 + struct au_sbinfo *sbinfo;
28383 + sbinfo = file->private_data;
28385 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28388 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28391 + struct super_block *sb;
28392 + struct au_sbinfo *sbinfo;
28393 + struct hlist_bl_node *pos;
28396 + if (unlikely(file->private_data))
28400 + /* don't use au_sbilist_lock() here */
28401 + hlist_bl_lock(&au_sbilist);
28402 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28403 + if (id == sysaufs_si_id(sbinfo)) {
28404 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28405 + sb = sbinfo->si_sb;
28408 + hlist_bl_unlock(&au_sbilist);
28411 + if (unlikely(!sb))
28414 + err = au_plink_maint_enter(sb);
28416 + /* keep kobject_get() */
28417 + file->private_data = sbinfo;
28419 + kobject_put(&sbinfo->si_kobj);
28425 + * Accept a valid "si=xxxx" only.
28426 + * Once it is accepted successfully, accept "clean" too.
28428 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28429 + size_t count, loff_t *ppos)
28432 + unsigned long id;
28433 + /* last newline is allowed */
28434 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28437 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28441 + if (unlikely(count > sizeof(buf)))
28444 + err = copy_from_user(buf, ubuf, count);
28445 + if (unlikely(err)) {
28452 + if (!strcmp("clean", buf)) {
28453 + au_procfs_plm_write_clean(file);
28454 + goto out_success;
28455 + } else if (unlikely(strncmp("si=", buf, 3)))
28458 + err = kstrtoul(buf + 3, 16, &id);
28459 + if (unlikely(err))
28462 + err = au_procfs_plm_write_si(file, id);
28463 + if (unlikely(err))
28467 + err = count; /* success */
28472 +static const struct proc_ops au_procfs_plm_op = {
28473 + .proc_write = au_procfs_plm_write,
28474 + .proc_release = au_procfs_plm_release
28477 +/* ---------------------------------------------------------------------- */
28479 +static struct proc_dir_entry *au_procfs_dir;
28481 +void au_procfs_fin(void)
28483 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28484 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28487 +int __init au_procfs_init(void)
28490 + struct proc_dir_entry *entry;
28493 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28494 + if (unlikely(!au_procfs_dir))
28497 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28498 + au_procfs_dir, &au_procfs_plm_op);
28499 + if (unlikely(!entry))
28503 + goto out; /* success */
28507 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28511 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28512 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28513 +++ linux/fs/aufs/rdu.c 2021-02-24 13:33:42.747680497 +0100
28515 +// SPDX-License-Identifier: GPL-2.0
28517 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28519 + * This program, aufs is free software; you can redistribute it and/or modify
28520 + * it under the terms of the GNU General Public License as published by
28521 + * the Free Software Foundation; either version 2 of the License, or
28522 + * (at your option) any later version.
28524 + * This program is distributed in the hope that it will be useful,
28525 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28526 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28527 + * GNU General Public License for more details.
28529 + * You should have received a copy of the GNU General Public License
28530 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28534 + * readdir in userspace.
28537 +#include <linux/compat.h>
28538 +#include <linux/fs_stack.h>
28539 +#include <linux/security.h>
28542 +/* bits for struct aufs_rdu.flags */
28543 +#define AuRdu_CALLED 1
28544 +#define AuRdu_CONT (1 << 1)
28545 +#define AuRdu_FULL (1 << 2)
28546 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28547 +#define au_fset_rdu(flags, name) \
28548 + do { (flags) |= AuRdu_##name; } while (0)
28549 +#define au_fclr_rdu(flags, name) \
28550 + do { (flags) &= ~AuRdu_##name; } while (0)
28552 +struct au_rdu_arg {
28553 + struct dir_context ctx;
28554 + struct aufs_rdu *rdu;
28555 + union au_rdu_ent_ul ent;
28556 + unsigned long end;
28558 + struct super_block *sb;
28562 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28563 + loff_t offset, u64 h_ino, unsigned int d_type)
28566 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28567 + struct aufs_rdu *rdu = arg->rdu;
28568 + struct au_rdu_ent ent;
28572 + au_fset_rdu(rdu->cookie.flags, CALLED);
28573 + len = au_rdu_len(nlen);
28574 + if (arg->ent.ul + len < arg->end) {
28576 + ent.bindex = rdu->cookie.bindex;
28577 + ent.type = d_type;
28579 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28580 + ent.type = DT_UNKNOWN;
28582 + /* unnecessary to support mmap_sem since this is a dir */
28584 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28586 + if (copy_to_user(arg->ent.e->name, name, nlen))
28588 + /* the terminating NULL */
28589 + if (__put_user(0, arg->ent.e->name + nlen))
28592 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28593 + arg->ent.ul += len;
28597 + au_fset_rdu(rdu->cookie.flags, FULL);
28599 + rdu->tail = arg->ent;
28603 + /* AuTraceErr(err); */
28607 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28611 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28613 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28614 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28616 + if (unlikely(offset != cookie->h_pos))
28622 + au_fclr_rdu(cookie->flags, CALLED);
28624 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28628 + && au_ftest_rdu(cookie->flags, CALLED)
28629 + && !au_ftest_rdu(cookie->flags, FULL));
28630 + cookie->h_pos = h_file->f_pos;
28637 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28640 + aufs_bindex_t bbot;
28641 + struct au_rdu_arg arg = {
28643 + .actor = au_rdu_fill
28646 + struct dentry *dentry;
28647 + struct inode *inode;
28648 + struct file *h_file;
28649 + struct au_rdu_cookie *cookie = &rdu->cookie;
28651 + /* VERIFY_WRITE */
28652 + err = !access_ok(rdu->ent.e, rdu->sz);
28653 + if (unlikely(err)) {
28659 + rdu->tail = rdu->ent;
28662 + arg.ent = rdu->ent;
28663 + arg.end = arg.ent.ul;
28664 + arg.end += rdu->sz;
28667 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28670 + err = security_file_permission(file, MAY_READ);
28672 + if (unlikely(err))
28675 + dentry = file->f_path.dentry;
28676 + inode = d_inode(dentry);
28677 + inode_lock_shared(inode);
28679 + arg.sb = inode->i_sb;
28680 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28681 + if (unlikely(err))
28683 + err = au_alive_dir(dentry);
28684 + if (unlikely(err))
28686 + /* todo: reval? */
28687 + fi_read_lock(file);
28690 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28691 + && cookie->generation != au_figen(file)))
28696 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28698 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28700 + bbot = au_fbtop(file);
28701 + if (cookie->bindex < bbot)
28702 + cookie->bindex = bbot;
28703 + bbot = au_fbbot_dir(file);
28704 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28705 + for (; !err && cookie->bindex <= bbot;
28706 + cookie->bindex++, cookie->h_pos = 0) {
28707 + h_file = au_hf_dir(file, cookie->bindex);
28711 + au_fclr_rdu(cookie->flags, FULL);
28712 + err = au_rdu_do(h_file, &arg);
28714 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28717 + AuDbg("rent %llu\n", rdu->rent);
28719 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28720 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28721 + au_fset_rdu(cookie->flags, CONT);
28722 + cookie->generation = au_figen(file);
28725 + ii_read_lock_child(inode);
28726 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28727 + ii_read_unlock(inode);
28730 + fi_read_unlock(file);
28732 + si_read_unlock(arg.sb);
28734 + inode_unlock_shared(inode);
28740 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28744 + unsigned long long nent;
28745 + union au_rdu_ent_ul *u;
28746 + struct au_rdu_ent ent;
28747 + struct super_block *sb;
28750 + nent = rdu->nent;
28752 + sb = file->f_path.dentry->d_sb;
28753 + si_read_lock(sb, AuLock_FLUSH);
28754 + while (nent-- > 0) {
28755 + /* unnecessary to support mmap_sem since this is a dir */
28756 + err = copy_from_user(&ent, u->e, sizeof(ent));
28758 + /* VERIFY_WRITE */
28759 + err = !access_ok(&u->e->ino, sizeof(ino));
28760 + if (unlikely(err)) {
28766 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28768 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28770 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28772 + if (unlikely(err)) {
28777 + err = __put_user(ino, &u->e->ino);
28778 + if (unlikely(err)) {
28783 + u->ul += au_rdu_len(ent.nlen);
28785 + si_read_unlock(sb);
28790 +/* ---------------------------------------------------------------------- */
28792 +static int au_rdu_verify(struct aufs_rdu *rdu)
28794 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28795 + "%llu, b%d, 0x%x, g%u}\n",
28796 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28798 + rdu->rent, rdu->shwh, rdu->full,
28799 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28800 + rdu->cookie.generation);
28802 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28806 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28810 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28813 + struct aufs_rdu rdu;
28814 + void __user *p = (void __user *)arg;
28816 + err = copy_from_user(&rdu, p, sizeof(rdu));
28817 + if (unlikely(err)) {
28822 + err = au_rdu_verify(&rdu);
28823 + if (unlikely(err))
28827 + case AUFS_CTL_RDU:
28828 + err = au_rdu(file, &rdu);
28829 + if (unlikely(err))
28832 + e = copy_to_user(p, &rdu, sizeof(rdu));
28833 + if (unlikely(e)) {
28838 + case AUFS_CTL_RDU_INO:
28839 + err = au_rdu_ino(file, &rdu);
28843 + /* err = -ENOTTY; */
28852 +#ifdef CONFIG_COMPAT
28853 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28856 + struct aufs_rdu rdu;
28857 + void __user *p = compat_ptr(arg);
28859 + /* todo: get_user()? */
28860 + err = copy_from_user(&rdu, p, sizeof(rdu));
28861 + if (unlikely(err)) {
28866 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28867 + err = au_rdu_verify(&rdu);
28868 + if (unlikely(err))
28872 + case AUFS_CTL_RDU:
28873 + err = au_rdu(file, &rdu);
28874 + if (unlikely(err))
28877 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28878 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28879 + e = copy_to_user(p, &rdu, sizeof(rdu));
28880 + if (unlikely(e)) {
28885 + case AUFS_CTL_RDU_INO:
28886 + err = au_rdu_ino(file, &rdu);
28890 + /* err = -ENOTTY; */
28899 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28900 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28901 +++ linux/fs/aufs/rwsem.h 2021-02-24 13:33:42.747680497 +0100
28903 +/* SPDX-License-Identifier: GPL-2.0 */
28905 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28907 + * This program, aufs is free software; you can redistribute it and/or modify
28908 + * it under the terms of the GNU General Public License as published by
28909 + * the Free Software Foundation; either version 2 of the License, or
28910 + * (at your option) any later version.
28912 + * This program is distributed in the hope that it will be useful,
28913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28915 + * GNU General Public License for more details.
28917 + * You should have received a copy of the GNU General Public License
28918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28922 + * simple read-write semaphore wrappers
28925 +#ifndef __AUFS_RWSEM_H__
28926 +#define __AUFS_RWSEM_H__
28930 +#include "debug.h"
28932 +/* in the future, the name 'au_rwsem' will be totally gone */
28933 +#define au_rwsem rw_semaphore
28935 +/* to debug easier, do not make them inlined functions */
28936 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28938 +#ifdef CONFIG_LOCKDEP
28939 +/* rwsem_is_locked() is unusable */
28940 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28941 + && !lockdep_recursing(current) \
28943 + && !lockdep_is_held_type(rw, 1))
28944 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28945 + && !lockdep_recursing(current) \
28947 + && !lockdep_is_held_type(rw, 0))
28948 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28949 + && !lockdep_recursing(current) \
28951 + && !lockdep_is_held(rw))
28952 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28953 + && !lockdep_recursing(current) \
28955 + && lockdep_is_held(rw))
28957 +#define AuRwMustReadLock(rw) do {} while (0)
28958 +#define AuRwMustWriteLock(rw) do {} while (0)
28959 +#define AuRwMustAnyLock(rw) do {} while (0)
28960 +#define AuRwDestroy(rw) do {} while (0)
28963 +#define au_rw_init(rw) init_rwsem(rw)
28965 +#define au_rw_init_wlock(rw) do { \
28966 + au_rw_init(rw); \
28967 + down_write(rw); \
28970 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28971 + au_rw_init(rw); \
28972 + down_write_nested(rw, lsc); \
28975 +#define au_rw_read_lock(rw) down_read(rw)
28976 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28977 +#define au_rw_read_unlock(rw) up_read(rw)
28978 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28979 +#define au_rw_write_lock(rw) down_write(rw)
28980 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28981 +#define au_rw_write_unlock(rw) up_write(rw)
28982 +/* why is not _nested version defined? */
28983 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28984 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28986 +#endif /* __KERNEL__ */
28987 +#endif /* __AUFS_RWSEM_H__ */
28988 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28989 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28990 +++ linux/fs/aufs/sbinfo.c 2021-02-24 13:33:42.747680497 +0100
28992 +// SPDX-License-Identifier: GPL-2.0
28994 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28996 + * This program, aufs is free software; you can redistribute it and/or modify
28997 + * it under the terms of the GNU General Public License as published by
28998 + * the Free Software Foundation; either version 2 of the License, or
28999 + * (at your option) any later version.
29001 + * This program is distributed in the hope that it will be useful,
29002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29004 + * GNU General Public License for more details.
29006 + * You should have received a copy of the GNU General Public License
29007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29011 + * superblock private data
29014 +#include <linux/iversion.h>
29018 + * they are necessary regardless sysfs is disabled.
29020 +void au_si_free(struct kobject *kobj)
29023 + struct au_sbinfo *sbinfo;
29024 + char *locked __maybe_unused; /* debug only */
29026 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29027 + for (i = 0; i < AuPlink_NHASH; i++)
29028 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29029 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29031 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29032 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29033 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29034 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29036 + dbgaufs_si_fin(sbinfo);
29037 + au_rw_write_lock(&sbinfo->si_rwsem);
29038 + au_br_free(sbinfo);
29039 + au_rw_write_unlock(&sbinfo->si_rwsem);
29041 + au_kfree_try_rcu(sbinfo->si_branch);
29042 + mutex_destroy(&sbinfo->si_xib_mtx);
29043 + AuRwDestroy(&sbinfo->si_rwsem);
29045 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29046 + /* si_nfiles is waited too */
29047 + au_kfree_rcu(sbinfo);
29050 +int au_si_alloc(struct super_block *sb)
29053 + struct au_sbinfo *sbinfo;
29056 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29057 + if (unlikely(!sbinfo))
29060 + /* will be reallocated separately */
29061 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29062 + if (unlikely(!sbinfo->si_branch))
29065 + err = sysaufs_si_init(sbinfo);
29067 + dbgaufs_si_null(sbinfo);
29068 + err = dbgaufs_si_init(sbinfo);
29069 + if (unlikely(err))
29070 + kobject_put(&sbinfo->si_kobj);
29072 + if (unlikely(err))
29075 + au_nwt_init(&sbinfo->si_nowait);
29076 + au_rw_init_wlock(&sbinfo->si_rwsem);
29078 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29079 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29081 + sbinfo->si_bbot = -1;
29082 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29084 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29085 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29086 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29087 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29089 + au_fhsm_init(sbinfo);
29091 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29093 + sbinfo->si_xino_jiffy = jiffies;
29094 + sbinfo->si_xino_expire
29095 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29096 + mutex_init(&sbinfo->si_xib_mtx);
29097 + /* leave si_xib_last_pindex and si_xib_next_bit */
29099 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29101 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29102 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29103 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29104 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29106 + for (i = 0; i < AuPlink_NHASH; i++)
29107 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29108 + init_waitqueue_head(&sbinfo->si_plink_wq);
29109 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29111 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29113 + /* with getattr by default */
29114 + sbinfo->si_iop_array = aufs_iop;
29116 + /* leave other members for sysaufs and si_mnt. */
29117 + sbinfo->si_sb = sb;
29118 + sb->s_fs_info = sbinfo;
29120 + return 0; /* success */
29123 + au_kfree_try_rcu(sbinfo->si_branch);
29125 + au_kfree_rcu(sbinfo);
29130 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29133 + struct au_branch **brp;
29135 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29138 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29139 + if (unlikely(!sz))
29140 + sz = sizeof(*brp);
29141 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29144 + sbinfo->si_branch = brp;
29151 +/* ---------------------------------------------------------------------- */
29153 +unsigned int au_sigen_inc(struct super_block *sb)
29155 + unsigned int gen;
29156 + struct inode *inode;
29158 + SiMustWriteLock(sb);
29160 + gen = ++au_sbi(sb)->si_generation;
29161 + au_update_digen(sb->s_root);
29162 + inode = d_inode(sb->s_root);
29163 + au_update_iigen(inode, /*half*/0);
29164 + inode_inc_iversion(inode);
29168 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29170 + aufs_bindex_t br_id;
29172 + struct au_sbinfo *sbinfo;
29174 + SiMustWriteLock(sb);
29176 + sbinfo = au_sbi(sb);
29177 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29178 + br_id = ++sbinfo->si_last_br_id;
29179 + AuDebugOn(br_id < 0);
29180 + if (br_id && au_br_index(sb, br_id) < 0)
29187 +/* ---------------------------------------------------------------------- */
29189 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29190 +int si_read_lock(struct super_block *sb, int flags)
29195 + if (au_ftest_lock(flags, FLUSH))
29196 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29198 + si_noflush_read_lock(sb);
29199 + err = au_plink_maint(sb, flags);
29200 + if (unlikely(err))
29201 + si_read_unlock(sb);
29206 +int si_write_lock(struct super_block *sb, int flags)
29210 + if (au_ftest_lock(flags, FLUSH))
29211 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29213 + si_noflush_write_lock(sb);
29214 + err = au_plink_maint(sb, flags);
29215 + if (unlikely(err))
29216 + si_write_unlock(sb);
29221 +/* dentry and super_block lock. call at entry point */
29222 +int aufs_read_lock(struct dentry *dentry, int flags)
29225 + struct super_block *sb;
29227 + sb = dentry->d_sb;
29228 + err = si_read_lock(sb, flags);
29229 + if (unlikely(err))
29232 + if (au_ftest_lock(flags, DW))
29233 + di_write_lock_child(dentry);
29235 + di_read_lock_child(dentry, flags);
29237 + if (au_ftest_lock(flags, GEN)) {
29238 + err = au_digen_test(dentry, au_sigen(sb));
29239 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29240 + AuDebugOn(!err && au_dbrange_test(dentry));
29242 + err = au_dbrange_test(dentry);
29243 + if (unlikely(err))
29244 + aufs_read_unlock(dentry, flags);
29251 +void aufs_read_unlock(struct dentry *dentry, int flags)
29253 + if (au_ftest_lock(flags, DW))
29254 + di_write_unlock(dentry);
29256 + di_read_unlock(dentry, flags);
29257 + si_read_unlock(dentry->d_sb);
29260 +void aufs_write_lock(struct dentry *dentry)
29262 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29263 + di_write_lock_child(dentry);
29266 +void aufs_write_unlock(struct dentry *dentry)
29268 + di_write_unlock(dentry);
29269 + si_write_unlock(dentry->d_sb);
29272 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29275 + unsigned int sigen;
29276 + struct super_block *sb;
29279 + err = si_read_lock(sb, flags);
29280 + if (unlikely(err))
29283 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29285 + if (au_ftest_lock(flags, GEN)) {
29286 + sigen = au_sigen(sb);
29287 + err = au_digen_test(d1, sigen);
29288 + AuDebugOn(!err && au_dbrange_test(d1));
29290 + err = au_digen_test(d2, sigen);
29291 + AuDebugOn(!err && au_dbrange_test(d2));
29293 + if (unlikely(err))
29294 + aufs_read_and_write_unlock2(d1, d2);
29301 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29303 + di_write_unlock2(d1, d2);
29304 + si_read_unlock(d1->d_sb);
29306 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29307 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29308 +++ linux/fs/aufs/super.c 2021-02-24 13:33:42.747680497 +0100
29310 +// SPDX-License-Identifier: GPL-2.0
29312 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29314 + * This program, aufs is free software; you can redistribute it and/or modify
29315 + * it under the terms of the GNU General Public License as published by
29316 + * the Free Software Foundation; either version 2 of the License, or
29317 + * (at your option) any later version.
29319 + * This program is distributed in the hope that it will be useful,
29320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29322 + * GNU General Public License for more details.
29324 + * You should have received a copy of the GNU General Public License
29325 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29329 + * mount and super_block operations
29332 +#include <linux/iversion.h>
29333 +#include <linux/mm.h>
29334 +#include <linux/seq_file.h>
29335 +#include <linux/statfs.h>
29336 +#include <linux/vmalloc.h>
29340 + * super_operations
29342 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29344 + struct au_icntnr *c;
29346 + c = au_cache_alloc_icntnr();
29348 + au_icntnr_init(c);
29349 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29350 + c->iinfo.ii_hinode = NULL;
29351 + return &c->vfs_inode;
29356 +static void aufs_destroy_inode(struct inode *inode)
29358 + if (!au_is_bad_inode(inode))
29359 + au_iinfo_fin(inode);
29362 +static void aufs_free_inode(struct inode *inode)
29364 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29367 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29369 + struct inode *inode;
29372 + inode = iget_locked(sb, ino);
29373 + if (unlikely(!inode)) {
29374 + inode = ERR_PTR(-ENOMEM);
29377 + if (!(inode->i_state & I_NEW))
29380 + err = au_xigen_new(inode);
29382 + err = au_iinfo_init(inode);
29384 + inode_inc_iversion(inode);
29386 + iget_failed(inode);
29387 + inode = ERR_PTR(err);
29391 + /* never return NULL */
29392 + AuDebugOn(!inode);
29393 + AuTraceErrPtr(inode);
29397 +/* lock free root dinfo */
29398 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29401 + aufs_bindex_t bindex, bbot;
29402 + struct path path;
29403 + struct au_hdentry *hdp;
29404 + struct au_branch *br;
29405 + au_br_perm_str_t perm;
29408 + bbot = au_sbbot(sb);
29410 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29411 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29412 + br = au_sbr(sb, bindex);
29413 + path.mnt = au_br_mnt(br);
29414 + path.dentry = hdp->hd_dentry;
29415 + err = au_seq_path(seq, &path);
29417 + au_optstr_br_perm(&perm, br->br_perm);
29418 + seq_printf(seq, "=%s", perm.a);
29419 + if (bindex != bbot)
29420 + seq_putc(seq, ':');
29423 + if (unlikely(err || seq_has_overflowed(seq)))
29429 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29430 + const char *append)
29435 + while (*pat != ':')
29438 + strcpy(p, append);
29439 + AuDebugOn(strlen(fmt) >= len);
29442 +static void au_show_wbr_create(struct seq_file *m, int v,
29443 + struct au_sbinfo *sbinfo)
29447 + struct au_wbr_mfs *mfs;
29449 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29451 + seq_puts(m, ",create=");
29452 + pat = au_optstr_wbr_create(v);
29453 + mfs = &sbinfo->si_wbr_mfs;
29455 + case AuWbrCreate_TDP:
29456 + case AuWbrCreate_RR:
29457 + case AuWbrCreate_MFS:
29458 + case AuWbrCreate_PMFS:
29459 + seq_puts(m, pat);
29461 + case AuWbrCreate_MFSRR:
29462 + case AuWbrCreate_TDMFS:
29463 + case AuWbrCreate_PMFSRR:
29464 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29465 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29467 + case AuWbrCreate_MFSV:
29468 + case AuWbrCreate_PMFSV:
29469 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29470 + seq_printf(m, fmt,
29471 + jiffies_to_msecs(mfs->mfs_expire)
29474 + case AuWbrCreate_MFSRRV:
29475 + case AuWbrCreate_TDMFSV:
29476 + case AuWbrCreate_PMFSRRV:
29477 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29478 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29479 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29486 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29488 +#ifdef CONFIG_SYSFS
29492 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29493 + aufs_bindex_t bindex, brid;
29494 + struct qstr *name;
29496 + struct dentry *d, *h_root;
29497 + struct au_branch *br;
29499 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29502 + f = au_sbi(sb)->si_xib;
29506 + /* stop printing the default xino path on the first writable branch */
29508 + bindex = au_xi_root(sb, f->f_path.dentry);
29509 + if (bindex >= 0) {
29510 + br = au_sbr_sb(sb, bindex);
29511 + h_root = au_br_dentry(br);
29514 + d = f->f_path.dentry;
29515 + name = &d->d_name;
29516 + /* safe ->d_parent because the file is unlinked */
29517 + if (d->d_parent == h_root
29518 + && name->len == len
29519 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29522 + seq_puts(seq, ",xino=");
29523 + err = au_xino_path(seq, f);
29530 +/* seq_file will re-call me in case of too long string */
29531 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29534 + unsigned int mnt_flags, v;
29535 + struct super_block *sb;
29536 + struct au_sbinfo *sbinfo;
29538 +#define AuBool(name, str) do { \
29539 + v = au_opt_test(mnt_flags, name); \
29540 + if (v != au_opt_test(AuOpt_Def, name)) \
29541 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29544 +#define AuStr(name, str) do { \
29545 + v = mnt_flags & AuOptMask_##name; \
29546 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29547 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29550 +#define AuUInt(name, str, val) do { \
29551 + if (val != AUFS_##name##_DEF) \
29552 + seq_printf(m, "," #str "=%u", val); \
29555 + sb = dentry->d_sb;
29556 + if (sb->s_flags & SB_POSIXACL)
29557 + seq_puts(m, ",acl");
29558 +#if 0 /* reserved for future use */
29559 + if (sb->s_flags & SB_I_VERSION)
29560 + seq_puts(m, ",i_version");
29563 + /* lock free root dinfo */
29564 + si_noflush_read_lock(sb);
29565 + sbinfo = au_sbi(sb);
29566 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29568 + mnt_flags = au_mntflags(sb);
29569 + if (au_opt_test(mnt_flags, XINO)) {
29570 + err = au_show_xino(m, sb);
29571 + if (unlikely(err))
29574 + seq_puts(m, ",noxino");
29576 + AuBool(TRUNC_XINO, trunc_xino);
29577 + AuStr(UDBA, udba);
29578 + AuBool(SHWH, shwh);
29579 + AuBool(PLINK, plink);
29580 + AuBool(DIO, dio);
29581 + AuBool(DIRPERM1, dirperm1);
29583 + v = sbinfo->si_wbr_create;
29584 + if (v != AuWbrCreate_Def)
29585 + au_show_wbr_create(m, v, sbinfo);
29587 + v = sbinfo->si_wbr_copyup;
29588 + if (v != AuWbrCopyup_Def)
29589 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29591 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29592 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29593 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29595 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29597 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29598 + AuUInt(RDCACHE, rdcache, v);
29600 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29601 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29603 + au_fhsm_show(m, sbinfo);
29605 + AuBool(DIRREN, dirren);
29606 + AuBool(SUM, sum);
29607 + /* AuBool(SUM_W, wsum); */
29608 + AuBool(WARN_PERM, warn_perm);
29609 + AuBool(VERBOSE, verbose);
29612 + /* be sure to print "br:" last */
29613 + if (!sysaufs_brs) {
29614 + seq_puts(m, ",br:");
29615 + au_show_brs(m, sb);
29617 + si_read_unlock(sb);
29625 +/* ---------------------------------------------------------------------- */
29627 +/* sum mode which returns the summation for statfs(2) */
29629 +static u64 au_add_till_max(u64 a, u64 b)
29637 + return ULLONG_MAX;
29640 +static u64 au_mul_till_max(u64 a, long mul)
29648 + return ULLONG_MAX;
29651 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29654 + long bsize, factor;
29655 + u64 blocks, bfree, bavail, files, ffree;
29656 + aufs_bindex_t bbot, bindex, i;
29657 + unsigned char shared;
29658 + struct path h_path;
29659 + struct super_block *h_sb;
29662 + bsize = LONG_MAX;
29668 + bbot = au_sbbot(sb);
29669 + for (bindex = 0; bindex <= bbot; bindex++) {
29670 + h_path.mnt = au_sbr_mnt(sb, bindex);
29671 + h_sb = h_path.mnt->mnt_sb;
29673 + for (i = 0; !shared && i < bindex; i++)
29674 + shared = (au_sbr_sb(sb, i) == h_sb);
29678 + /* sb->s_root for NFS is unreliable */
29679 + h_path.dentry = h_path.mnt->mnt_root;
29680 + err = vfs_statfs(&h_path, buf);
29681 + if (unlikely(err))
29684 + if (bsize > buf->f_bsize) {
29686 + * we will reduce bsize, so we have to expand blocks
29687 + * etc. to match them again
29689 + factor = (bsize / buf->f_bsize);
29690 + blocks = au_mul_till_max(blocks, factor);
29691 + bfree = au_mul_till_max(bfree, factor);
29692 + bavail = au_mul_till_max(bavail, factor);
29693 + bsize = buf->f_bsize;
29696 + factor = (buf->f_bsize / bsize);
29697 + blocks = au_add_till_max(blocks,
29698 + au_mul_till_max(buf->f_blocks, factor));
29699 + bfree = au_add_till_max(bfree,
29700 + au_mul_till_max(buf->f_bfree, factor));
29701 + bavail = au_add_till_max(bavail,
29702 + au_mul_till_max(buf->f_bavail, factor));
29703 + files = au_add_till_max(files, buf->f_files);
29704 + ffree = au_add_till_max(ffree, buf->f_ffree);
29707 + buf->f_bsize = bsize;
29708 + buf->f_blocks = blocks;
29709 + buf->f_bfree = bfree;
29710 + buf->f_bavail = bavail;
29711 + buf->f_files = files;
29712 + buf->f_ffree = ffree;
29713 + buf->f_frsize = 0;
29719 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29722 + struct path h_path;
29723 + struct super_block *sb;
29725 + /* lock free root dinfo */
29726 + sb = dentry->d_sb;
29727 + si_noflush_read_lock(sb);
29728 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29729 + /* sb->s_root for NFS is unreliable */
29730 + h_path.mnt = au_sbr_mnt(sb, 0);
29731 + h_path.dentry = h_path.mnt->mnt_root;
29732 + err = vfs_statfs(&h_path, buf);
29734 + err = au_statfs_sum(sb, buf);
29735 + si_read_unlock(sb);
29738 + buf->f_type = AUFS_SUPER_MAGIC;
29739 + buf->f_namelen = AUFS_MAX_NAMELEN;
29740 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29742 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29747 +/* ---------------------------------------------------------------------- */
29749 +static int aufs_sync_fs(struct super_block *sb, int wait)
29752 + aufs_bindex_t bbot, bindex;
29753 + struct au_branch *br;
29754 + struct super_block *h_sb;
29757 + si_noflush_read_lock(sb);
29758 + bbot = au_sbbot(sb);
29759 + for (bindex = 0; bindex <= bbot; bindex++) {
29760 + br = au_sbr(sb, bindex);
29761 + if (!au_br_writable(br->br_perm))
29764 + h_sb = au_sbr_sb(sb, bindex);
29765 + e = vfsub_sync_filesystem(h_sb, wait);
29766 + if (unlikely(e && !err))
29768 + /* go on even if an error happens */
29770 + si_read_unlock(sb);
29775 +/* ---------------------------------------------------------------------- */
29777 +/* final actions when unmounting a file system */
29778 +static void aufs_put_super(struct super_block *sb)
29780 + struct au_sbinfo *sbinfo;
29782 + sbinfo = au_sbi(sb);
29784 + kobject_put(&sbinfo->si_kobj);
29787 +/* ---------------------------------------------------------------------- */
29789 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29790 + struct super_block *sb, void *arg)
29793 + unsigned long long n, sz;
29800 + if (*hint > ULLONG_MAX / sizeof(array)) {
29801 + array = ERR_PTR(-EMFILE);
29802 + pr_err("hint %llu\n", *hint);
29806 + sz = sizeof(array) * *hint;
29807 + array = kzalloc(sz, GFP_NOFS);
29808 + if (unlikely(!array))
29809 + array = vzalloc(sz);
29810 + if (unlikely(!array)) {
29811 + array = ERR_PTR(-ENOMEM);
29815 + n = cb(sb, array, *hint, arg);
29816 + AuDebugOn(n > *hint);
29823 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29824 + unsigned long long max __maybe_unused,
29827 + unsigned long long n;
29828 + struct inode **p, *inode;
29829 + struct list_head *head;
29834 + spin_lock(&sb->s_inode_list_lock);
29835 + list_for_each_entry(inode, head, i_sb_list) {
29836 + if (!au_is_bad_inode(inode)
29837 + && au_ii(inode)->ii_btop >= 0) {
29838 + spin_lock(&inode->i_lock);
29839 + if (atomic_read(&inode->i_count)) {
29843 + AuDebugOn(n > max);
29845 + spin_unlock(&inode->i_lock);
29848 + spin_unlock(&sb->s_inode_list_lock);
29853 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29855 + struct au_sbinfo *sbi;
29857 + sbi = au_sbi(sb);
29858 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29859 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29862 +void au_iarray_free(struct inode **a, unsigned long long max)
29864 + unsigned long long ull;
29866 + for (ull = 0; ull < max; ull++)
29871 +/* ---------------------------------------------------------------------- */
29874 + * refresh dentry and inode at remount time.
29876 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29877 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29878 + struct dentry *parent)
29882 + di_write_lock_child(dentry);
29883 + di_read_lock_parent(parent, AuLock_IR);
29884 + err = au_refresh_dentry(dentry, parent);
29885 + if (!err && dir_flags)
29886 + au_hn_reset(d_inode(dentry), dir_flags);
29887 + di_read_unlock(parent, AuLock_IR);
29888 + di_write_unlock(dentry);
29893 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29894 + struct au_sbinfo *sbinfo,
29895 + const unsigned int dir_flags, unsigned int do_idop)
29898 + struct dentry *parent;
29901 + parent = dget_parent(dentry);
29902 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29903 + if (d_really_is_positive(dentry)) {
29904 + if (!d_is_dir(dentry))
29905 + err = au_do_refresh(dentry, /*dir_flags*/0,
29908 + err = au_do_refresh(dentry, dir_flags, parent);
29909 + if (unlikely(err))
29910 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29913 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29914 + AuDbgDentry(dentry);
29920 + au_refresh_dop(dentry, /*force_reval*/0);
29922 + au_refresh_dop(dentry, /*force_reval*/1);
29928 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29930 + int err, i, j, ndentry, e;
29931 + unsigned int sigen;
29932 + struct au_dcsub_pages dpages;
29933 + struct au_dpage *dpage;
29934 + struct dentry **dentries, *d;
29935 + struct au_sbinfo *sbinfo;
29936 + struct dentry *root = sb->s_root;
29937 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29940 + au_refresh_dop(root, /*force_reval*/0);
29942 + err = au_dpages_init(&dpages, GFP_NOFS);
29943 + if (unlikely(err))
29945 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29946 + if (unlikely(err))
29949 + sigen = au_sigen(sb);
29950 + sbinfo = au_sbi(sb);
29951 + for (i = 0; i < dpages.ndpage; i++) {
29952 + dpage = dpages.dpages + i;
29953 + dentries = dpage->dentries;
29954 + ndentry = dpage->ndentry;
29955 + for (j = 0; j < ndentry; j++) {
29957 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29959 + if (unlikely(e && !err))
29961 + /* go on even err */
29966 + au_dpages_free(&dpages);
29971 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29974 + unsigned int sigen;
29975 + unsigned long long max, ull;
29976 + struct inode *inode, **array;
29978 + array = au_iarray_alloc(sb, &max);
29979 + err = PTR_ERR(array);
29980 + if (IS_ERR(array))
29984 + sigen = au_sigen(sb);
29985 + for (ull = 0; ull < max; ull++) {
29986 + inode = array[ull];
29987 + if (unlikely(!inode))
29991 + ii_write_lock_child(inode);
29992 + if (au_iigen(inode, NULL) != sigen) {
29993 + e = au_refresh_hinode_self(inode);
29994 + if (unlikely(e)) {
29995 + au_refresh_iop(inode, /*force_getattr*/1);
29996 + pr_err("error %d, i%lu\n", e, inode->i_ino);
29999 + /* go on even if err */
30002 + if (!e && do_idop)
30003 + au_refresh_iop(inode, /*force_getattr*/0);
30004 + ii_write_unlock(inode);
30007 + au_iarray_free(array, max);
30013 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30016 + unsigned int udba;
30017 + aufs_bindex_t bindex, bbot;
30018 + struct dentry *root;
30019 + struct inode *inode;
30020 + struct au_branch *br;
30021 + struct au_sbinfo *sbi;
30023 + au_sigen_inc(sb);
30024 + sbi = au_sbi(sb);
30025 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30027 + root = sb->s_root;
30028 + DiMustNoWaiters(root);
30029 + inode = d_inode(root);
30030 + IiMustNoWaiters(inode);
30032 + udba = au_opt_udba(sb);
30033 + bbot = au_sbbot(sb);
30034 + for (bindex = 0; bindex <= bbot; bindex++) {
30035 + br = au_sbr(sb, bindex);
30036 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30037 + if (unlikely(err))
30038 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30040 + /* go on even if err */
30042 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30045 + if (au_ftest_si(sbi, NO_DREVAL)) {
30046 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30047 + sb->s_d_op = &aufs_dop_noreval;
30048 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30049 + sbi->si_iop_array = aufs_iop_nogetattr;
30051 + AuDebugOn(sb->s_d_op == &aufs_dop);
30052 + sb->s_d_op = &aufs_dop;
30053 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30054 + sbi->si_iop_array = aufs_iop;
30056 + pr_info("reset to %ps and %ps\n",
30057 + sb->s_d_op, sbi->si_iop_array);
30060 + di_write_unlock(root);
30061 + err = au_refresh_d(sb, do_idop);
30062 + e = au_refresh_i(sb, do_idop);
30063 + if (unlikely(e && !err))
30065 + /* aufs_write_lock() calls ..._child() */
30066 + di_write_lock_child(root);
30068 + au_cpup_attr_all(inode, /*force*/1);
30070 + if (unlikely(err))
30071 + AuIOErr("refresh failed, ignored, %d\n", err);
30074 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30075 +static int cvt_err(int err)
30089 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30092 + unsigned int mntflags;
30093 + struct au_opts opts = {
30096 + struct dentry *root;
30097 + struct inode *inode;
30098 + struct au_sbinfo *sbinfo;
30101 + root = sb->s_root;
30102 + if (!data || !*data) {
30103 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30105 + di_write_lock_child(root);
30106 + err = au_opts_verify(sb, *flags, /*pending*/0);
30107 + aufs_write_unlock(root);
30113 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30114 + if (unlikely(!opts.opt))
30116 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30117 + opts.flags = AuOpts_REMOUNT;
30118 + opts.sb_flags = *flags;
30120 + /* parse it before aufs lock */
30121 + err = au_opts_parse(sb, data, &opts);
30122 + if (unlikely(err))
30125 + sbinfo = au_sbi(sb);
30126 + inode = d_inode(root);
30127 + inode_lock(inode);
30128 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30129 + if (unlikely(err))
30131 + di_write_lock_child(root);
30133 + /* au_opts_remount() may return an error */
30134 + err = au_opts_remount(sb, &opts);
30135 + au_opts_free(&opts);
30137 + if (au_ftest_opts(opts.flags, REFRESH))
30138 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30140 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30141 + mntflags = au_mntflags(sb);
30142 + do_dx = !!au_opt_test(mntflags, DIO);
30143 + au_dy_arefresh(do_dx);
30146 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30147 + aufs_write_unlock(root);
30150 + inode_unlock(inode);
30152 + free_page((unsigned long)opts.opt);
30154 + err = cvt_err(err);
30159 +static const struct super_operations aufs_sop = {
30160 + .alloc_inode = aufs_alloc_inode,
30161 + .destroy_inode = aufs_destroy_inode,
30162 + .free_inode = aufs_free_inode,
30163 + /* always deleting, no clearing */
30164 + .drop_inode = generic_delete_inode,
30165 + .show_options = aufs_show_options,
30166 + .statfs = aufs_statfs,
30167 + .put_super = aufs_put_super,
30168 + .sync_fs = aufs_sync_fs,
30169 + .remount_fs = aufs_remount_fs
30172 +/* ---------------------------------------------------------------------- */
30174 +static int alloc_root(struct super_block *sb)
30177 + struct inode *inode;
30178 + struct dentry *root;
30181 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30182 + err = PTR_ERR(inode);
30183 + if (IS_ERR(inode))
30186 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30187 + inode->i_fop = &aufs_dir_fop;
30188 + inode->i_mode = S_IFDIR;
30189 + set_nlink(inode, 2);
30190 + unlock_new_inode(inode);
30192 + root = d_make_root(inode);
30193 + if (unlikely(!root))
30195 + err = PTR_ERR(root);
30196 + if (IS_ERR(root))
30199 + err = au_di_init(root);
30201 + sb->s_root = root;
30202 + return 0; /* success */
30210 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30211 + int silent __maybe_unused)
30214 + struct au_opts opts = {
30217 + struct au_sbinfo *sbinfo;
30218 + struct dentry *root;
30219 + struct inode *inode;
30220 + char *arg = raw_data;
30222 + if (unlikely(!arg || !*arg)) {
30224 + pr_err("no arg\n");
30229 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30230 + if (unlikely(!opts.opt))
30232 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30233 + opts.sb_flags = sb->s_flags;
30235 + err = au_si_alloc(sb);
30236 + if (unlikely(err))
30238 + sbinfo = au_sbi(sb);
30240 + /* all timestamps always follow the ones on the branch */
30241 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30242 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30243 + sb->s_op = &aufs_sop;
30244 + sb->s_d_op = &aufs_dop;
30245 + sb->s_magic = AUFS_SUPER_MAGIC;
30246 + sb->s_maxbytes = 0;
30247 + sb->s_stack_depth = 1;
30248 + au_export_init(sb);
30249 + au_xattr_init(sb);
30251 + err = alloc_root(sb);
30252 + if (unlikely(err)) {
30253 + si_write_unlock(sb);
30256 + root = sb->s_root;
30257 + inode = d_inode(root);
30260 + * actually we can parse options regardless aufs lock here.
30261 + * but at remount time, parsing must be done before aufs lock.
30262 + * so we follow the same rule.
30264 + ii_write_lock_parent(inode);
30265 + aufs_write_unlock(root);
30266 + err = au_opts_parse(sb, arg, &opts);
30267 + if (unlikely(err))
30270 + /* lock vfs_inode first, then aufs. */
30271 + inode_lock(inode);
30272 + aufs_write_lock(root);
30273 + err = au_opts_mount(sb, &opts);
30274 + au_opts_free(&opts);
30275 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30276 + sb->s_d_op = &aufs_dop_noreval;
30277 + pr_info("%ps\n", sb->s_d_op);
30278 + au_refresh_dop(root, /*force_reval*/0);
30279 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30280 + au_refresh_iop(inode, /*force_getattr*/0);
30282 + aufs_write_unlock(root);
30283 + inode_unlock(inode);
30285 + goto out_opts; /* success */
30289 + sb->s_root = NULL;
30291 + kobject_put(&sbinfo->si_kobj);
30292 + sb->s_fs_info = NULL;
30294 + free_page((unsigned long)opts.opt);
30297 + err = cvt_err(err);
30302 +/* ---------------------------------------------------------------------- */
30304 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30305 + const char *dev_name __maybe_unused,
30308 + struct dentry *root;
30310 + /* all timestamps always follow the ones on the branch */
30311 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30312 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30313 + if (IS_ERR(root))
30316 + au_sbilist_add(root->d_sb);
30322 +static void aufs_kill_sb(struct super_block *sb)
30324 + struct au_sbinfo *sbinfo;
30326 + sbinfo = au_sbi(sb);
30328 + au_sbilist_del(sb);
30329 + aufs_write_lock(sb->s_root);
30331 + if (sbinfo->si_wbr_create_ops->fin)
30332 + sbinfo->si_wbr_create_ops->fin(sb);
30333 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30334 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30335 + au_remount_refresh(sb, /*do_idop*/0);
30337 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30338 + au_plink_put(sb, /*verbose*/1);
30340 + au_dr_opt_flush(sb);
30341 + sbinfo->si_sb = NULL;
30342 + aufs_write_unlock(sb->s_root);
30343 + au_nwt_flush(&sbinfo->si_nowait);
30345 + kill_anon_super(sb);
30348 +struct file_system_type aufs_fs_type = {
30349 + .name = AUFS_FSTYPE,
30350 + /* a race between rename and others */
30351 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30352 + .mount = aufs_mount,
30353 + .kill_sb = aufs_kill_sb,
30354 + /* no need to __module_get() and module_put(). */
30355 + .owner = THIS_MODULE,
30357 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30358 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30359 +++ linux/fs/aufs/super.h 2021-02-24 13:33:42.747680497 +0100
30361 +/* SPDX-License-Identifier: GPL-2.0 */
30363 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30365 + * This program, aufs is free software; you can redistribute it and/or modify
30366 + * it under the terms of the GNU General Public License as published by
30367 + * the Free Software Foundation; either version 2 of the License, or
30368 + * (at your option) any later version.
30370 + * This program is distributed in the hope that it will be useful,
30371 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30372 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30373 + * GNU General Public License for more details.
30375 + * You should have received a copy of the GNU General Public License
30376 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30380 + * super_block operations
30383 +#ifndef __AUFS_SUPER_H__
30384 +#define __AUFS_SUPER_H__
30388 +#include <linux/fs.h>
30389 +#include <linux/kobject.h>
30392 +#include "rwsem.h"
30395 +/* policies to select one among multiple writable branches */
30396 +struct au_wbr_copyup_operations {
30397 + int (*copyup)(struct dentry *dentry);
30400 +#define AuWbr_DIR 1 /* target is a dir */
30401 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30403 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30404 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30405 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30407 +struct au_wbr_create_operations {
30408 + int (*create)(struct dentry *dentry, unsigned int flags);
30409 + int (*init)(struct super_block *sb);
30410 + int (*fin)(struct super_block *sb);
30413 +struct au_wbr_mfs {
30414 + struct mutex mfs_lock; /* protect this structure */
30415 + unsigned long mfs_jiffy;
30416 + unsigned long mfs_expire;
30417 + aufs_bindex_t mfs_bindex;
30419 + unsigned long long mfsrr_bytes;
30420 + unsigned long long mfsrr_watermark;
30423 +#define AuPlink_NHASH 100
30424 +static inline int au_plink_hash(ino_t ino)
30426 + return ino % AuPlink_NHASH;
30429 +/* File-based Hierarchical Storage Management */
30431 +#ifdef CONFIG_AUFS_FHSM
30432 + /* allow only one process who can receive the notification */
30433 + spinlock_t fhsm_spin;
30435 + wait_queue_head_t fhsm_wqh;
30436 + atomic_t fhsm_readable;
30438 + /* these are protected by si_rwsem */
30439 + unsigned long fhsm_expire;
30440 + aufs_bindex_t fhsm_bottom;
30445 +struct au_sbinfo {
30446 + /* nowait tasks in the system-wide workqueue */
30447 + struct au_nowait_tasks si_nowait;
30450 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30451 + * rwsem for au_sbinfo is necessary.
30453 + struct au_rwsem si_rwsem;
30456 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30459 + au_lcnt_t si_ninodes, si_nfiles;
30461 + /* branch management */
30462 + unsigned int si_generation;
30464 + /* see AuSi_ flags */
30465 + unsigned char au_si_status;
30467 + aufs_bindex_t si_bbot;
30469 + /* dirty trick to keep br_id plus */
30470 + unsigned int si_last_br_id :
30471 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30472 + struct au_branch **si_branch;
30474 + /* policy to select a writable branch */
30475 + unsigned char si_wbr_copyup;
30476 + unsigned char si_wbr_create;
30477 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30478 + struct au_wbr_create_operations *si_wbr_create_ops;
30480 + /* round robin */
30481 + atomic_t si_wbr_rr_next;
30483 + /* most free space */
30484 + struct au_wbr_mfs si_wbr_mfs;
30486 + /* File-based Hierarchical Storage Management */
30487 + struct au_fhsm si_fhsm;
30489 + /* mount flags */
30490 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30491 + unsigned int si_mntflags;
30493 + /* external inode number (bitmap and translation table) */
30494 + loff_t si_ximaxent; /* max entries in a xino */
30496 + struct file *si_xib;
30497 + struct mutex si_xib_mtx; /* protect xib members */
30498 + unsigned long *si_xib_buf;
30499 + unsigned long si_xib_last_pindex;
30500 + int si_xib_next_bit;
30502 + unsigned long si_xino_jiffy;
30503 + unsigned long si_xino_expire;
30504 + /* reserved for future use */
30505 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30507 +#ifdef CONFIG_AUFS_EXPORT
30508 + /* i_generation */
30509 + /* todo: make xigen file an array to support many inode numbers */
30510 + struct file *si_xigen;
30511 + atomic_t si_xigen_next;
30514 + /* dirty trick to support atomic_open */
30515 + struct hlist_bl_head si_aopen;
30517 + /* vdir parameters */
30518 + unsigned long si_rdcache; /* max cache time in jiffies */
30519 + unsigned int si_rdblk; /* deblk size */
30520 + unsigned int si_rdhash; /* hash size */
30523 + * If the number of whiteouts are larger than si_dirwh, leave all of
30524 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30525 + * future fsck.aufs or kernel thread will remove them later.
30526 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30528 + unsigned int si_dirwh;
30530 + /* pseudo_link list */
30531 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30532 + wait_queue_head_t si_plink_wq;
30533 + spinlock_t si_plink_maint_lock;
30534 + pid_t si_plink_maint_pid;
30537 + struct hlist_bl_head si_files;
30539 + /* with/without getattr, brother of sb->s_d_op */
30540 + const struct inode_operations *si_iop_array;
30543 + * sysfs and lifetime management.
30544 + * this is not a small structure and it may be a waste of memory in case
30545 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30546 + * but using sysfs is majority.
30548 + struct kobject si_kobj;
30549 +#ifdef CONFIG_DEBUG_FS
30550 + struct dentry *si_dbgaufs;
30551 + struct dentry *si_dbgaufs_plink;
30552 + struct dentry *si_dbgaufs_xib;
30553 +#ifdef CONFIG_AUFS_EXPORT
30554 + struct dentry *si_dbgaufs_xigen;
30558 +#ifdef CONFIG_AUFS_SBILIST
30559 + struct hlist_bl_node si_list;
30562 + /* dirty, necessary for unmounting, sysfs and sysrq */
30563 + struct super_block *si_sb;
30566 +/* sbinfo status flags */
30568 + * set true when refresh_dirs() failed at remount time.
30569 + * then try refreshing dirs at access time again.
30570 + * if it is false, refreshing dirs at access time is unnecessary
30572 +#define AuSi_FAILED_REFRESH_DIR 1
30573 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30574 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30576 +#ifndef CONFIG_AUFS_FHSM
30578 +#define AuSi_FHSM 0
30581 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30582 + unsigned int flag)
30584 + AuRwMustAnyLock(&sbi->si_rwsem);
30585 + return sbi->au_si_status & flag;
30587 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30588 +#define au_fset_si(sbinfo, name) do { \
30589 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30590 + (sbinfo)->au_si_status |= AuSi_##name; \
30592 +#define au_fclr_si(sbinfo, name) do { \
30593 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30594 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30597 +/* ---------------------------------------------------------------------- */
30599 +/* policy to select one among writable branches */
30600 +#define AuWbrCopyup(sbinfo, ...) \
30601 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30602 +#define AuWbrCreate(sbinfo, ...) \
30603 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30605 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30606 +#define AuLock_DW 1 /* write-lock dentry */
30607 +#define AuLock_IR (1 << 1) /* read-lock inode */
30608 +#define AuLock_IW (1 << 2) /* write-lock inode */
30609 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30610 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30611 + /* except RENAME_EXCHANGE */
30612 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30613 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30614 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30615 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30616 +#define au_fset_lock(flags, name) \
30617 + do { (flags) |= AuLock_##name; } while (0)
30618 +#define au_fclr_lock(flags, name) \
30619 + do { (flags) &= ~AuLock_##name; } while (0)
30621 +/* ---------------------------------------------------------------------- */
30624 +extern struct file_system_type aufs_fs_type;
30625 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30626 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30627 + unsigned long long max, void *arg);
30628 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30629 + struct super_block *sb, void *arg);
30630 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30631 +void au_iarray_free(struct inode **a, unsigned long long max);
30634 +void au_si_free(struct kobject *kobj);
30635 +int au_si_alloc(struct super_block *sb);
30636 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30638 +unsigned int au_sigen_inc(struct super_block *sb);
30639 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30641 +int si_read_lock(struct super_block *sb, int flags);
30642 +int si_write_lock(struct super_block *sb, int flags);
30643 +int aufs_read_lock(struct dentry *dentry, int flags);
30644 +void aufs_read_unlock(struct dentry *dentry, int flags);
30645 +void aufs_write_lock(struct dentry *dentry);
30646 +void aufs_write_unlock(struct dentry *dentry);
30647 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30648 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30650 +/* wbr_policy.c */
30651 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30652 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30653 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30654 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30655 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30658 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30660 +#ifdef CONFIG_AUFS_FHSM
30663 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30667 + spin_lock(&fhsm->fhsm_spin);
30668 + pid = fhsm->fhsm_pid;
30669 + spin_unlock(&fhsm->fhsm_spin);
30674 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30675 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30676 +int au_fhsm_fd(struct super_block *sb, int oflags);
30677 +int au_fhsm_br_alloc(struct au_branch *br);
30678 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30679 +void au_fhsm_fin(struct super_block *sb);
30680 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30681 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30682 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30684 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30686 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30687 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30688 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30689 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30690 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30691 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30692 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30693 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30694 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30697 +/* ---------------------------------------------------------------------- */
30699 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30701 + return sb->s_fs_info;
30704 +/* ---------------------------------------------------------------------- */
30706 +#ifdef CONFIG_AUFS_EXPORT
30707 +int au_test_nfsd(void);
30708 +void au_export_init(struct super_block *sb);
30709 +void au_xigen_inc(struct inode *inode);
30710 +int au_xigen_new(struct inode *inode);
30711 +int au_xigen_set(struct super_block *sb, struct path *path);
30712 +void au_xigen_clr(struct super_block *sb);
30714 +static inline int au_busy_or_stale(void)
30716 + if (!au_test_nfsd())
30721 +AuStubInt0(au_test_nfsd, void)
30722 +AuStubVoid(au_export_init, struct super_block *sb)
30723 +AuStubVoid(au_xigen_inc, struct inode *inode)
30724 +AuStubInt0(au_xigen_new, struct inode *inode)
30725 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30726 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30727 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30728 +#endif /* CONFIG_AUFS_EXPORT */
30730 +/* ---------------------------------------------------------------------- */
30732 +#ifdef CONFIG_AUFS_SBILIST
30734 +extern struct hlist_bl_head au_sbilist;
30736 +static inline void au_sbilist_init(void)
30738 + INIT_HLIST_BL_HEAD(&au_sbilist);
30741 +static inline void au_sbilist_add(struct super_block *sb)
30743 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30746 +static inline void au_sbilist_del(struct super_block *sb)
30748 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30751 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30752 +static inline void au_sbilist_lock(void)
30754 + hlist_bl_lock(&au_sbilist);
30757 +static inline void au_sbilist_unlock(void)
30759 + hlist_bl_unlock(&au_sbilist);
30761 +#define AuGFP_SBILIST GFP_ATOMIC
30763 +AuStubVoid(au_sbilist_lock, void)
30764 +AuStubVoid(au_sbilist_unlock, void)
30765 +#define AuGFP_SBILIST GFP_NOFS
30766 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30768 +AuStubVoid(au_sbilist_init, void)
30769 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30770 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30771 +AuStubVoid(au_sbilist_lock, void)
30772 +AuStubVoid(au_sbilist_unlock, void)
30773 +#define AuGFP_SBILIST GFP_NOFS
30776 +/* ---------------------------------------------------------------------- */
30778 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30781 + * This function is a dynamic '__init' function actually,
30782 + * so the tiny check for si_rwsem is unnecessary.
30784 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30785 +#ifdef CONFIG_DEBUG_FS
30786 + sbinfo->si_dbgaufs = NULL;
30787 + sbinfo->si_dbgaufs_plink = NULL;
30788 + sbinfo->si_dbgaufs_xib = NULL;
30789 +#ifdef CONFIG_AUFS_EXPORT
30790 + sbinfo->si_dbgaufs_xigen = NULL;
30795 +/* ---------------------------------------------------------------------- */
30797 +/* current->atomic_flags */
30798 +/* this value should never corrupt the ones defined in linux/sched.h */
30799 +#define PFA_AUFS 0x10
30801 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30802 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30803 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30805 +static inline int si_pid_test(struct super_block *sb)
30807 + return !!task_test_aufs(current);
30810 +static inline void si_pid_clr(struct super_block *sb)
30812 + AuDebugOn(!task_test_aufs(current));
30813 + task_clear_aufs(current);
30816 +static inline void si_pid_set(struct super_block *sb)
30818 + AuDebugOn(task_test_aufs(current));
30819 + task_set_aufs(current);
30822 +/* ---------------------------------------------------------------------- */
30824 +/* lock superblock. mainly for entry point functions */
30825 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30826 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30827 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30828 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30830 +#define __si_read_trylock_nested(sb) \
30831 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30832 +#define __si_write_trylock_nested(sb) \
30833 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30836 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30837 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30838 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30840 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30841 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30842 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30844 +static inline void si_noflush_read_lock(struct super_block *sb)
30846 + __si_read_lock(sb);
30850 +static inline int si_noflush_read_trylock(struct super_block *sb)
30854 + locked = __si_read_trylock(sb);
30860 +static inline void si_noflush_write_lock(struct super_block *sb)
30862 + __si_write_lock(sb);
30866 +static inline int si_noflush_write_trylock(struct super_block *sb)
30870 + locked = __si_write_trylock(sb);
30876 +#if 0 /* reserved */
30877 +static inline int si_read_trylock(struct super_block *sb, int flags)
30879 + if (au_ftest_lock(flags, FLUSH))
30880 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30881 + return si_noflush_read_trylock(sb);
30885 +static inline void si_read_unlock(struct super_block *sb)
30888 + __si_read_unlock(sb);
30891 +#if 0 /* reserved */
30892 +static inline int si_write_trylock(struct super_block *sb, int flags)
30894 + if (au_ftest_lock(flags, FLUSH))
30895 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30896 + return si_noflush_write_trylock(sb);
30900 +static inline void si_write_unlock(struct super_block *sb)
30903 + __si_write_unlock(sb);
30906 +#if 0 /* reserved */
30907 +static inline void si_downgrade_lock(struct super_block *sb)
30909 + __si_downgrade_lock(sb);
30913 +/* ---------------------------------------------------------------------- */
30915 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30917 + SiMustAnyLock(sb);
30918 + return au_sbi(sb)->si_bbot;
30921 +static inline unsigned int au_mntflags(struct super_block *sb)
30923 + SiMustAnyLock(sb);
30924 + return au_sbi(sb)->si_mntflags;
30927 +static inline unsigned int au_sigen(struct super_block *sb)
30929 + SiMustAnyLock(sb);
30930 + return au_sbi(sb)->si_generation;
30933 +static inline struct au_branch *au_sbr(struct super_block *sb,
30934 + aufs_bindex_t bindex)
30936 + SiMustAnyLock(sb);
30937 + return au_sbi(sb)->si_branch[0 + bindex];
30940 +static inline loff_t au_xi_maxent(struct super_block *sb)
30942 + SiMustAnyLock(sb);
30943 + return au_sbi(sb)->si_ximaxent;
30946 +#endif /* __KERNEL__ */
30947 +#endif /* __AUFS_SUPER_H__ */
30948 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30949 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30950 +++ linux/fs/aufs/sysaufs.c 2021-02-24 13:33:42.747680497 +0100
30952 +// SPDX-License-Identifier: GPL-2.0
30954 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30956 + * This program, aufs is free software; you can redistribute it and/or modify
30957 + * it under the terms of the GNU General Public License as published by
30958 + * the Free Software Foundation; either version 2 of the License, or
30959 + * (at your option) any later version.
30961 + * This program is distributed in the hope that it will be useful,
30962 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30963 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30964 + * GNU General Public License for more details.
30966 + * You should have received a copy of the GNU General Public License
30967 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30971 + * sysfs interface and lifetime management
30972 + * they are necessary regardless sysfs is disabled.
30975 +#include <linux/random.h>
30978 +unsigned long sysaufs_si_mask;
30979 +struct kset *sysaufs_kset;
30981 +#define AuSiAttr(_name) { \
30982 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30983 + .show = sysaufs_si_##_name, \
30986 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30987 +struct attribute *sysaufs_si_attrs[] = {
30988 + &sysaufs_si_attr_xi_path.attr,
30992 +static const struct sysfs_ops au_sbi_ops = {
30993 + .show = sysaufs_si_show
30996 +static struct kobj_type au_sbi_ktype = {
30997 + .release = au_si_free,
30998 + .sysfs_ops = &au_sbi_ops,
30999 + .default_attrs = sysaufs_si_attrs
31002 +/* ---------------------------------------------------------------------- */
31004 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31008 + sbinfo->si_kobj.kset = sysaufs_kset;
31009 + /* cf. sysaufs_name() */
31010 + err = kobject_init_and_add
31011 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31012 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31017 +void sysaufs_fin(void)
31019 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31020 + kset_unregister(sysaufs_kset);
31023 +int __init sysaufs_init(void)
31028 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31029 + } while (!sysaufs_si_mask);
31032 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31033 + if (unlikely(!sysaufs_kset))
31035 + err = PTR_ERR(sysaufs_kset);
31036 + if (IS_ERR(sysaufs_kset))
31038 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31039 + if (unlikely(err))
31040 + kset_unregister(sysaufs_kset);
31045 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31046 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31047 +++ linux/fs/aufs/sysaufs.h 2021-02-24 13:33:42.747680497 +0100
31049 +/* SPDX-License-Identifier: GPL-2.0 */
31051 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31053 + * This program, aufs is free software; you can redistribute it and/or modify
31054 + * it under the terms of the GNU General Public License as published by
31055 + * the Free Software Foundation; either version 2 of the License, or
31056 + * (at your option) any later version.
31058 + * This program is distributed in the hope that it will be useful,
31059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31061 + * GNU General Public License for more details.
31063 + * You should have received a copy of the GNU General Public License
31064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31068 + * sysfs interface and mount lifetime management
31071 +#ifndef __SYSAUFS_H__
31072 +#define __SYSAUFS_H__
31076 +#include <linux/sysfs.h>
31077 +#include "module.h"
31079 +struct super_block;
31082 +struct sysaufs_si_attr {
31083 + struct attribute attr;
31084 + int (*show)(struct seq_file *seq, struct super_block *sb);
31087 +/* ---------------------------------------------------------------------- */
31090 +extern unsigned long sysaufs_si_mask;
31091 +extern struct kset *sysaufs_kset;
31092 +extern struct attribute *sysaufs_si_attrs[];
31093 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31094 +int __init sysaufs_init(void);
31095 +void sysaufs_fin(void);
31097 +/* ---------------------------------------------------------------------- */
31099 +/* some people doesn't like to show a pointer in kernel */
31100 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31102 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31105 +#define SysaufsSiNamePrefix "si_"
31106 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31107 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31109 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31110 + sysaufs_si_id(sbinfo));
31114 +#ifdef CONFIG_SYSFS
31116 +extern struct attribute_group *sysaufs_attr_group;
31118 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31119 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31121 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31122 +#ifdef CONFIG_COMPAT
31123 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31126 +void sysaufs_br_init(struct au_branch *br);
31127 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31128 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31130 +#define sysaufs_brs_init() do {} while (0)
31133 +#define sysaufs_attr_group NULL
31135 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31136 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31137 + struct attribute *attr, char *buf)
31138 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31139 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31140 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31142 +static inline void sysaufs_brs_init(void)
31147 +#endif /* CONFIG_SYSFS */
31149 +#endif /* __KERNEL__ */
31150 +#endif /* __SYSAUFS_H__ */
31151 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31152 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31153 +++ linux/fs/aufs/sysfs.c 2021-02-24 13:33:42.747680497 +0100
31155 +// SPDX-License-Identifier: GPL-2.0
31157 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31159 + * This program, aufs is free software; you can redistribute it and/or modify
31160 + * it under the terms of the GNU General Public License as published by
31161 + * the Free Software Foundation; either version 2 of the License, or
31162 + * (at your option) any later version.
31164 + * This program is distributed in the hope that it will be useful,
31165 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31166 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31167 + * GNU General Public License for more details.
31169 + * You should have received a copy of the GNU General Public License
31170 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31174 + * sysfs interface
31177 +#include <linux/compat.h>
31178 +#include <linux/seq_file.h>
31181 +#ifdef CONFIG_AUFS_FS_MODULE
31182 +/* this entry violates the "one line per file" policy of sysfs */
31183 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31187 + static char *conf =
31188 +/* this file is generated at compiling */
31189 +#include "conf.str"
31192 + err = snprintf(buf, PAGE_SIZE, conf);
31193 + if (unlikely(err >= PAGE_SIZE))
31198 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31201 +static struct attribute *au_attr[] = {
31202 +#ifdef CONFIG_AUFS_FS_MODULE
31203 + &au_config_attr.attr,
31205 + NULL, /* need to NULL terminate the list of attributes */
31208 +static struct attribute_group sysaufs_attr_group_body = {
31212 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31214 +/* ---------------------------------------------------------------------- */
31216 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31220 + SiMustAnyLock(sb);
31223 + if (au_opt_test(au_mntflags(sb), XINO)) {
31224 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31225 + seq_putc(seq, '\n');
31231 + * the lifetime of branch is independent from the entry under sysfs.
31232 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31235 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31236 + aufs_bindex_t bindex, int idx)
31239 + struct path path;
31240 + struct dentry *root;
31241 + struct au_branch *br;
31242 + au_br_perm_str_t perm;
31244 + AuDbg("b%d\n", bindex);
31247 + root = sb->s_root;
31248 + di_read_lock_parent(root, !AuLock_IR);
31249 + br = au_sbr(sb, bindex);
31252 + case AuBrSysfs_BR:
31253 + path.mnt = au_br_mnt(br);
31254 + path.dentry = au_h_dptr(root, bindex);
31255 + err = au_seq_path(seq, &path);
31257 + au_optstr_br_perm(&perm, br->br_perm);
31258 + seq_printf(seq, "=%s\n", perm.a);
31261 + case AuBrSysfs_BRID:
31262 + seq_printf(seq, "%d\n", br->br_id);
31265 + di_read_unlock(root, !AuLock_IR);
31266 + if (unlikely(err || seq_has_overflowed(seq)))
31272 +/* ---------------------------------------------------------------------- */
31274 +static struct seq_file *au_seq(char *p, ssize_t len)
31276 + struct seq_file *seq;
31278 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31280 + /* mutex_init(&seq.lock); */
31283 + return seq; /* success */
31286 + seq = ERR_PTR(-ENOMEM);
31290 +#define SysaufsBr_PREFIX "br"
31291 +#define SysaufsBrid_PREFIX "brid"
31293 +/* todo: file size may exceed PAGE_SIZE */
31294 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31300 + aufs_bindex_t bbot;
31301 + struct au_sbinfo *sbinfo;
31302 + struct super_block *sb;
31303 + struct seq_file *seq;
31305 + struct attribute **cattr;
31307 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31308 + sb = sbinfo->si_sb;
31311 + * prevent a race condition between sysfs and aufs.
31312 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31313 + * prohibits maintaining the sysfs entries.
31314 + * hew we acquire read lock after sysfs_get_active_two().
31315 + * on the other hand, the remount process may maintain the sysfs/aufs
31316 + * entries after acquiring write lock.
31317 + * it can cause a deadlock.
31318 + * simply we gave up processing read here.
31321 + if (unlikely(!si_noflush_read_trylock(sb)))
31324 + seq = au_seq(buf, PAGE_SIZE);
31325 + err = PTR_ERR(seq);
31329 + name = (void *)attr->name;
31330 + cattr = sysaufs_si_attrs;
31332 + if (!strcmp(name, (*cattr)->name)) {
31333 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31340 + if (!strncmp(name, SysaufsBrid_PREFIX,
31341 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31342 + idx = AuBrSysfs_BRID;
31343 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31344 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31345 + sizeof(SysaufsBr_PREFIX) - 1)) {
31346 + idx = AuBrSysfs_BR;
31347 + name += sizeof(SysaufsBr_PREFIX) - 1;
31351 + err = kstrtol(name, 10, &l);
31353 + bbot = au_sbbot(sb);
31355 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31362 + err = seq->count;
31363 + /* sysfs limit */
31364 + if (unlikely(err == PAGE_SIZE))
31367 + au_kfree_rcu(seq);
31369 + si_read_unlock(sb);
31374 +/* ---------------------------------------------------------------------- */
31376 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31380 + aufs_bindex_t bindex, bbot;
31383 + struct seq_file *seq;
31384 + struct au_branch *br;
31386 + si_read_lock(sb, AuLock_FLUSH);
31387 + bbot = au_sbbot(sb);
31393 + buf = (void *)__get_free_page(GFP_NOFS);
31394 + if (unlikely(!buf))
31397 + seq = au_seq(buf, PAGE_SIZE);
31398 + err = PTR_ERR(seq);
31402 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31403 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31404 + /* VERIFY_WRITE */
31405 + err = !access_ok(arg, sizeof(*arg));
31406 + if (unlikely(err))
31409 + br = au_sbr(sb, bindex);
31410 + brid = br->br_id;
31411 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31412 + err = __put_user(brid, &arg->id);
31413 + if (unlikely(err))
31416 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31417 + err = __put_user(br->br_perm, &arg->perm);
31418 + if (unlikely(err))
31421 + err = au_seq_path(seq, &br->br_path);
31422 + if (unlikely(err))
31424 + seq_putc(seq, '\0');
31425 + if (!seq_has_overflowed(seq)) {
31426 + err = copy_to_user(arg->path, seq->buf, seq->count);
31428 + if (unlikely(err))
31435 + if (unlikely(err))
31439 + au_kfree_rcu(seq);
31441 + free_page((unsigned long)buf);
31443 + si_read_unlock(sb);
31447 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31449 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31452 +#ifdef CONFIG_COMPAT
31453 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31455 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31459 +/* ---------------------------------------------------------------------- */
31461 +void sysaufs_br_init(struct au_branch *br)
31464 + struct au_brsysfs *br_sysfs;
31465 + struct attribute *attr;
31467 + br_sysfs = br->br_sysfs;
31468 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31469 + attr = &br_sysfs->attr;
31470 + sysfs_attr_init(attr);
31471 + attr->name = br_sysfs->name;
31472 + attr->mode = 0444;
31477 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31479 + struct au_branch *br;
31480 + struct kobject *kobj;
31481 + struct au_brsysfs *br_sysfs;
31483 + aufs_bindex_t bbot;
31485 + if (!sysaufs_brs)
31488 + kobj = &au_sbi(sb)->si_kobj;
31489 + bbot = au_sbbot(sb);
31490 + for (; bindex <= bbot; bindex++) {
31491 + br = au_sbr(sb, bindex);
31492 + br_sysfs = br->br_sysfs;
31493 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31494 + sysfs_remove_file(kobj, &br_sysfs->attr);
31500 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31503 + aufs_bindex_t bbot;
31504 + struct kobject *kobj;
31505 + struct au_branch *br;
31506 + struct au_brsysfs *br_sysfs;
31508 + if (!sysaufs_brs)
31511 + kobj = &au_sbi(sb)->si_kobj;
31512 + bbot = au_sbbot(sb);
31513 + for (; bindex <= bbot; bindex++) {
31514 + br = au_sbr(sb, bindex);
31515 + br_sysfs = br->br_sysfs;
31516 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31517 + SysaufsBr_PREFIX "%d", bindex);
31518 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31519 + SysaufsBrid_PREFIX "%d", bindex);
31520 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31521 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31522 + if (unlikely(err))
31523 + pr_warn("failed %s under sysfs(%d)\n",
31524 + br_sysfs->name, err);
31529 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31530 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31531 +++ linux/fs/aufs/sysrq.c 2021-02-24 13:33:42.747680497 +0100
31533 +// SPDX-License-Identifier: GPL-2.0
31535 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31537 + * This program, aufs is free software; you can redistribute it and/or modify
31538 + * it under the terms of the GNU General Public License as published by
31539 + * the Free Software Foundation; either version 2 of the License, or
31540 + * (at your option) any later version.
31542 + * This program is distributed in the hope that it will be useful,
31543 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31544 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31545 + * GNU General Public License for more details.
31547 + * You should have received a copy of the GNU General Public License
31548 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31552 + * magic sysrq handler
31555 +/* #include <linux/sysrq.h> */
31556 +#include <linux/writeback.h>
31559 +/* ---------------------------------------------------------------------- */
31561 +static void sysrq_sb(struct super_block *sb)
31564 + struct au_sbinfo *sbinfo;
31565 + struct file *file;
31566 + struct hlist_bl_head *files;
31567 + struct hlist_bl_node *pos;
31568 + struct au_finfo *finfo;
31571 + plevel = au_plevel;
31572 + au_plevel = KERN_WARNING;
31574 + /* since we define pr_fmt, call printk directly */
31575 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31577 + sbinfo = au_sbi(sb);
31578 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31579 + pr("superblock\n");
31582 +#if 0 /* reserved */
31584 + int err, i, j, ndentry;
31585 + struct au_dcsub_pages dpages;
31586 + struct au_dpage *dpage;
31588 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31589 + if (unlikely(err))
31591 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31593 + for (i = 0; i < dpages.ndpage; i++) {
31594 + dpage = dpages.dpages + i;
31595 + ndentry = dpage->ndentry;
31596 + for (j = 0; j < ndentry; j++)
31597 + au_dpri_dentry(dpage->dentries[j]);
31599 + au_dpages_free(&dpages);
31603 + pr("isolated inode\n");
31604 + spin_lock(&sb->s_inode_list_lock);
31605 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31606 + spin_lock(&i->i_lock);
31607 + if (hlist_empty(&i->i_dentry))
31608 + au_dpri_inode(i);
31609 + spin_unlock(&i->i_lock);
31611 + spin_unlock(&sb->s_inode_list_lock);
31614 + files = &au_sbi(sb)->si_files;
31615 + hlist_bl_lock(files);
31616 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31619 + file = finfo->fi_file;
31620 + mode = file_inode(file)->i_mode;
31621 + if (!special_file(mode))
31622 + au_dpri_file(file);
31624 + hlist_bl_unlock(files);
31628 + au_plevel = plevel;
31631 +/* ---------------------------------------------------------------------- */
31633 +/* module parameter */
31634 +static char *aufs_sysrq_key = "a";
31635 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31636 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31638 +static void au_sysrq(int key __maybe_unused)
31640 + struct au_sbinfo *sbinfo;
31641 + struct hlist_bl_node *pos;
31644 + au_sbilist_lock();
31645 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31646 + sysrq_sb(sbinfo->si_sb);
31647 + au_sbilist_unlock();
31651 +static struct sysrq_key_op au_sysrq_op = {
31652 + .handler = au_sysrq,
31653 + .help_msg = "Aufs",
31654 + .action_msg = "Aufs",
31655 + .enable_mask = SYSRQ_ENABLE_DUMP
31658 +/* ---------------------------------------------------------------------- */
31660 +int __init au_sysrq_init(void)
31666 + key = *aufs_sysrq_key;
31667 + if ('a' <= key && key <= 'z')
31668 + err = register_sysrq_key(key, &au_sysrq_op);
31669 + if (unlikely(err))
31670 + pr_err("err %d, sysrq=%c\n", err, key);
31674 +void au_sysrq_fin(void)
31678 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31679 + if (unlikely(err))
31680 + pr_err("err %d (ignored)\n", err);
31682 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31683 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31684 +++ linux/fs/aufs/vdir.c 2021-02-24 13:33:42.747680497 +0100
31686 +// SPDX-License-Identifier: GPL-2.0
31688 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31690 + * This program, aufs is free software; you can redistribute it and/or modify
31691 + * it under the terms of the GNU General Public License as published by
31692 + * the Free Software Foundation; either version 2 of the License, or
31693 + * (at your option) any later version.
31695 + * This program is distributed in the hope that it will be useful,
31696 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31697 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31698 + * GNU General Public License for more details.
31700 + * You should have received a copy of the GNU General Public License
31701 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31705 + * virtual or vertical directory
31708 +#include <linux/iversion.h>
31711 +static unsigned int calc_size(int nlen)
31713 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31716 +static int set_deblk_end(union au_vdir_deblk_p *p,
31717 + union au_vdir_deblk_p *deblk_end)
31719 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31720 + p->de->de_str.len = 0;
31724 + return -1; /* error */
31727 +/* returns true or false */
31728 +static int is_deblk_end(union au_vdir_deblk_p *p,
31729 + union au_vdir_deblk_p *deblk_end)
31731 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31732 + return !p->de->de_str.len;
31736 +static unsigned char *last_deblk(struct au_vdir *vdir)
31738 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31741 +/* ---------------------------------------------------------------------- */
31743 +/* estimate the appropriate size for name hash table */
31744 +unsigned int au_rdhash_est(loff_t sz)
31752 + if (sz < AUFS_RDHASH_DEF)
31753 + n = AUFS_RDHASH_DEF;
31754 + /* pr_info("n %u\n", n); */
31759 + * the allocated memory has to be freed by
31760 + * au_nhash_wh_free() or au_nhash_de_free().
31762 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31764 + struct hlist_head *head;
31768 + sz = sizeof(*nhash->nh_head) * num_hash;
31769 + head = kmalloc(sz, gfp);
31771 + nhash->nh_num = num_hash;
31772 + nhash->nh_head = head;
31773 + for (u = 0; u < num_hash; u++)
31774 + INIT_HLIST_HEAD(head++);
31775 + return 0; /* success */
31781 +static void nhash_count(struct hlist_head *head)
31783 +#if 0 /* debugging */
31785 + struct hlist_node *pos;
31788 + hlist_for_each(pos, head)
31790 + pr_info("%lu\n", n);
31794 +static void au_nhash_wh_do_free(struct hlist_head *head)
31796 + struct au_vdir_wh *pos;
31797 + struct hlist_node *node;
31799 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31800 + au_kfree_rcu(pos);
31803 +static void au_nhash_de_do_free(struct hlist_head *head)
31805 + struct au_vdir_dehstr *pos;
31806 + struct hlist_node *node;
31808 + hlist_for_each_entry_safe(pos, node, head, hash)
31809 + au_cache_free_vdir_dehstr(pos);
31812 +static void au_nhash_do_free(struct au_nhash *nhash,
31813 + void (*free)(struct hlist_head *head))
31816 + struct hlist_head *head;
31818 + n = nhash->nh_num;
31822 + head = nhash->nh_head;
31823 + while (n-- > 0) {
31824 + nhash_count(head);
31827 + au_kfree_try_rcu(nhash->nh_head);
31830 +void au_nhash_wh_free(struct au_nhash *whlist)
31832 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31835 +static void au_nhash_de_free(struct au_nhash *delist)
31837 + au_nhash_do_free(delist, au_nhash_de_do_free);
31840 +/* ---------------------------------------------------------------------- */
31842 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31846 + unsigned int u, n;
31847 + struct hlist_head *head;
31848 + struct au_vdir_wh *pos;
31851 + n = whlist->nh_num;
31852 + head = whlist->nh_head;
31853 + for (u = 0; u < n; u++, head++)
31854 + hlist_for_each_entry(pos, head, wh_hash)
31855 + if (pos->wh_bindex == btgt && ++num > limit)
31860 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31861 + unsigned char *name,
31862 + unsigned int len)
31865 + /* const unsigned int magic_bit = 12; */
31867 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31874 + /* v = hash_long(v, magic_bit); */
31875 + v %= nhash->nh_num;
31876 + return nhash->nh_head + v;
31879 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31882 + return str->len == nlen && !memcmp(str->name, name, nlen);
31885 +/* returns found or not */
31886 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31888 + struct hlist_head *head;
31889 + struct au_vdir_wh *pos;
31890 + struct au_vdir_destr *str;
31892 + head = au_name_hash(whlist, name, nlen);
31893 + hlist_for_each_entry(pos, head, wh_hash) {
31894 + str = &pos->wh_str;
31895 + AuDbg("%.*s\n", str->len, str->name);
31896 + if (au_nhash_test_name(str, name, nlen))
31902 +/* returns found(true) or not */
31903 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31905 + struct hlist_head *head;
31906 + struct au_vdir_dehstr *pos;
31907 + struct au_vdir_destr *str;
31909 + head = au_name_hash(delist, name, nlen);
31910 + hlist_for_each_entry(pos, head, hash) {
31912 + AuDbg("%.*s\n", str->len, str->name);
31913 + if (au_nhash_test_name(str, name, nlen))
31919 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31920 + unsigned char d_type)
31922 +#ifdef CONFIG_AUFS_SHWH
31923 + wh->wh_ino = ino;
31924 + wh->wh_type = d_type;
31928 +/* ---------------------------------------------------------------------- */
31930 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31931 + unsigned int d_type, aufs_bindex_t bindex,
31932 + unsigned char shwh)
31935 + struct au_vdir_destr *str;
31936 + struct au_vdir_wh *wh;
31938 + AuDbg("%.*s\n", nlen, name);
31939 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31942 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31943 + if (unlikely(!wh))
31947 + wh->wh_bindex = bindex;
31949 + au_shwh_init_wh(wh, ino, d_type);
31950 + str = &wh->wh_str;
31952 + memcpy(str->name, name, nlen);
31953 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31960 +static int append_deblk(struct au_vdir *vdir)
31963 + unsigned long ul;
31964 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31965 + union au_vdir_deblk_p p, deblk_end;
31966 + unsigned char **o;
31969 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31970 + GFP_NOFS, /*may_shrink*/0);
31971 + if (unlikely(!o))
31974 + vdir->vd_deblk = o;
31975 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31977 + ul = vdir->vd_nblk++;
31978 + vdir->vd_deblk[ul] = p.deblk;
31979 + vdir->vd_last.ul = ul;
31980 + vdir->vd_last.p.deblk = p.deblk;
31981 + deblk_end.deblk = p.deblk + deblk_sz;
31982 + err = set_deblk_end(&p, &deblk_end);
31989 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31990 + unsigned int d_type, struct au_nhash *delist)
31994 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31995 + union au_vdir_deblk_p p, *room, deblk_end;
31996 + struct au_vdir_dehstr *dehstr;
31998 + p.deblk = last_deblk(vdir);
31999 + deblk_end.deblk = p.deblk + deblk_sz;
32000 + room = &vdir->vd_last.p;
32001 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32002 + || !is_deblk_end(room, &deblk_end));
32004 + sz = calc_size(nlen);
32005 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32006 + err = append_deblk(vdir);
32007 + if (unlikely(err))
32010 + p.deblk = last_deblk(vdir);
32011 + deblk_end.deblk = p.deblk + deblk_sz;
32013 + AuDebugOn(room->deblk != p.deblk);
32017 + dehstr = au_cache_alloc_vdir_dehstr();
32018 + if (unlikely(!dehstr))
32021 + dehstr->str = &room->de->de_str;
32022 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32023 + room->de->de_ino = ino;
32024 + room->de->de_type = d_type;
32025 + room->de->de_str.len = nlen;
32026 + memcpy(room->de->de_str.name, name, nlen);
32029 + room->deblk += sz;
32030 + if (unlikely(set_deblk_end(room, &deblk_end)))
32031 + err = append_deblk(vdir);
32038 +/* ---------------------------------------------------------------------- */
32040 +void au_vdir_free(struct au_vdir *vdir)
32042 + unsigned char **deblk;
32044 + deblk = vdir->vd_deblk;
32045 + while (vdir->vd_nblk--)
32046 + au_kfree_try_rcu(*deblk++);
32047 + au_kfree_try_rcu(vdir->vd_deblk);
32048 + au_cache_free_vdir(vdir);
32051 +static struct au_vdir *alloc_vdir(struct file *file)
32053 + struct au_vdir *vdir;
32054 + struct super_block *sb;
32057 + sb = file->f_path.dentry->d_sb;
32058 + SiMustAnyLock(sb);
32061 + vdir = au_cache_alloc_vdir();
32062 + if (unlikely(!vdir))
32065 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32066 + if (unlikely(!vdir->vd_deblk))
32069 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32070 + if (!vdir->vd_deblk_sz) {
32071 + /* estimate the appropriate size for deblk */
32072 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32073 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32075 + vdir->vd_nblk = 0;
32076 + vdir->vd_version = 0;
32077 + vdir->vd_jiffy = 0;
32078 + err = append_deblk(vdir);
32080 + return vdir; /* success */
32082 + au_kfree_try_rcu(vdir->vd_deblk);
32085 + au_cache_free_vdir(vdir);
32087 + vdir = ERR_PTR(err);
32091 +static int reinit_vdir(struct au_vdir *vdir)
32094 + union au_vdir_deblk_p p, deblk_end;
32096 + while (vdir->vd_nblk > 1) {
32097 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32098 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32101 + p.deblk = vdir->vd_deblk[0];
32102 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32103 + err = set_deblk_end(&p, &deblk_end);
32104 + /* keep vd_dblk_sz */
32105 + vdir->vd_last.ul = 0;
32106 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32107 + vdir->vd_version = 0;
32108 + vdir->vd_jiffy = 0;
32113 +/* ---------------------------------------------------------------------- */
32115 +#define AuFillVdir_CALLED 1
32116 +#define AuFillVdir_WHABLE (1 << 1)
32117 +#define AuFillVdir_SHWH (1 << 2)
32118 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32119 +#define au_fset_fillvdir(flags, name) \
32120 + do { (flags) |= AuFillVdir_##name; } while (0)
32121 +#define au_fclr_fillvdir(flags, name) \
32122 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32124 +#ifndef CONFIG_AUFS_SHWH
32125 +#undef AuFillVdir_SHWH
32126 +#define AuFillVdir_SHWH 0
32129 +struct fillvdir_arg {
32130 + struct dir_context ctx;
32131 + struct file *file;
32132 + struct au_vdir *vdir;
32133 + struct au_nhash delist;
32134 + struct au_nhash whlist;
32135 + aufs_bindex_t bindex;
32136 + unsigned int flags;
32140 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32141 + loff_t offset __maybe_unused, u64 h_ino,
32142 + unsigned int d_type)
32144 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32145 + char *name = (void *)__name;
32146 + struct super_block *sb;
32148 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32151 + sb = arg->file->f_path.dentry->d_sb;
32152 + au_fset_fillvdir(arg->flags, CALLED);
32154 + if (nlen <= AUFS_WH_PFX_LEN
32155 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32156 + if (test_known(&arg->delist, name, nlen)
32157 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32158 + goto out; /* already exists or whiteouted */
32160 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32162 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32163 + d_type = DT_UNKNOWN;
32164 + arg->err = append_de(arg->vdir, name, nlen, ino,
32165 + d_type, &arg->delist);
32167 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32168 + name += AUFS_WH_PFX_LEN;
32169 + nlen -= AUFS_WH_PFX_LEN;
32170 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32171 + goto out; /* already whiteouted */
32173 + ino = 0; /* just to suppress a warning */
32175 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32178 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32179 + d_type = DT_UNKNOWN;
32180 + arg->err = au_nhash_append_wh
32181 + (&arg->whlist, name, nlen, ino, d_type,
32182 + arg->bindex, shwh);
32188 + arg->vdir->vd_jiffy = jiffies;
32190 + AuTraceErr(arg->err);
32194 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32195 + struct au_nhash *whlist, struct au_nhash *delist)
32197 +#ifdef CONFIG_AUFS_SHWH
32199 + unsigned int nh, u;
32200 + struct hlist_head *head;
32201 + struct au_vdir_wh *pos;
32202 + struct hlist_node *n;
32204 + struct au_vdir_destr *destr;
32206 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32209 + o = p = (void *)__get_free_page(GFP_NOFS);
32210 + if (unlikely(!p))
32214 + nh = whlist->nh_num;
32215 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32216 + p += AUFS_WH_PFX_LEN;
32217 + for (u = 0; u < nh; u++) {
32218 + head = whlist->nh_head + u;
32219 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32220 + destr = &pos->wh_str;
32221 + memcpy(p, destr->name, destr->len);
32222 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32223 + pos->wh_ino, pos->wh_type, delist);
32224 + if (unlikely(err))
32229 + free_page((unsigned long)o);
32239 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32242 + unsigned int rdhash;
32244 + aufs_bindex_t bbot, bindex, btop;
32245 + unsigned char shwh;
32246 + struct file *hf, *file;
32247 + struct super_block *sb;
32249 + file = arg->file;
32250 + sb = file->f_path.dentry->d_sb;
32251 + SiMustAnyLock(sb);
32253 + rdhash = au_sbi(sb)->si_rdhash;
32255 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32256 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32257 + if (unlikely(err))
32259 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32260 + if (unlikely(err))
32266 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32268 + au_fset_fillvdir(arg->flags, SHWH);
32270 + btop = au_fbtop(file);
32271 + bbot = au_fbbot_dir(file);
32272 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32273 + hf = au_hf_dir(file, bindex);
32277 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32279 + if (unlikely(offset))
32282 + arg->bindex = bindex;
32283 + au_fclr_fillvdir(arg->flags, WHABLE);
32285 + || (bindex != bbot
32286 + && au_br_whable(au_sbr_perm(sb, bindex))))
32287 + au_fset_fillvdir(arg->flags, WHABLE);
32290 + au_fclr_fillvdir(arg->flags, CALLED);
32292 + err = vfsub_iterate_dir(hf, &arg->ctx);
32295 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32298 + * dir_relax() may be good for concurrency, but aufs should not
32299 + * use it since it will cause a lockdep problem.
32303 + if (!err && shwh)
32304 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32306 + au_nhash_wh_free(&arg->whlist);
32309 + au_nhash_de_free(&arg->delist);
32314 +static int read_vdir(struct file *file, int may_read)
32317 + unsigned long expire;
32318 + unsigned char do_read;
32319 + struct fillvdir_arg arg = {
32321 + .actor = fillvdir
32324 + struct inode *inode;
32325 + struct au_vdir *vdir, *allocated;
32328 + inode = file_inode(file);
32329 + IMustLock(inode);
32330 + IiMustWriteLock(inode);
32331 + SiMustAnyLock(inode->i_sb);
32333 + allocated = NULL;
32335 + expire = au_sbi(inode->i_sb)->si_rdcache;
32336 + vdir = au_ivdir(inode);
32339 + vdir = alloc_vdir(file);
32340 + err = PTR_ERR(vdir);
32341 + if (IS_ERR(vdir))
32344 + allocated = vdir;
32345 + } else if (may_read
32346 + && (!inode_eq_iversion(inode, vdir->vd_version)
32347 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32349 + err = reinit_vdir(vdir);
32350 + if (unlikely(err))
32355 + return 0; /* success */
32359 + err = au_do_read_vdir(&arg);
32361 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32362 + vdir->vd_version = inode_query_iversion(inode);
32363 + vdir->vd_last.ul = 0;
32364 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32366 + au_set_ivdir(inode, allocated);
32367 + } else if (allocated)
32368 + au_vdir_free(allocated);
32374 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32377 + unsigned long ul, n;
32378 + const unsigned int deblk_sz = src->vd_deblk_sz;
32380 + AuDebugOn(tgt->vd_nblk != 1);
32383 + if (tgt->vd_nblk < src->vd_nblk) {
32384 + unsigned char **p;
32386 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32387 + GFP_NOFS, /*may_shrink*/0);
32388 + if (unlikely(!p))
32390 + tgt->vd_deblk = p;
32393 + if (tgt->vd_deblk_sz != deblk_sz) {
32394 + unsigned char *p;
32396 + tgt->vd_deblk_sz = deblk_sz;
32397 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32398 + /*may_shrink*/1);
32399 + if (unlikely(!p))
32401 + tgt->vd_deblk[0] = p;
32403 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32404 + tgt->vd_version = src->vd_version;
32405 + tgt->vd_jiffy = src->vd_jiffy;
32407 + n = src->vd_nblk;
32408 + for (ul = 1; ul < n; ul++) {
32409 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32411 + if (unlikely(!tgt->vd_deblk[ul]))
32415 + tgt->vd_nblk = n;
32416 + tgt->vd_last.ul = tgt->vd_last.ul;
32417 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32418 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32419 + - src->vd_deblk[src->vd_last.ul];
32421 + return 0; /* success */
32424 + rerr = reinit_vdir(tgt);
32429 +int au_vdir_init(struct file *file)
32432 + struct inode *inode;
32433 + struct au_vdir *vdir_cache, *allocated;
32435 + /* test file->f_pos here instead of ctx->pos */
32436 + err = read_vdir(file, !file->f_pos);
32437 + if (unlikely(err))
32440 + allocated = NULL;
32441 + vdir_cache = au_fvdir_cache(file);
32442 + if (!vdir_cache) {
32443 + vdir_cache = alloc_vdir(file);
32444 + err = PTR_ERR(vdir_cache);
32445 + if (IS_ERR(vdir_cache))
32447 + allocated = vdir_cache;
32448 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32449 + /* test file->f_pos here instead of ctx->pos */
32450 + err = reinit_vdir(vdir_cache);
32451 + if (unlikely(err))
32454 + return 0; /* success */
32456 + inode = file_inode(file);
32457 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32459 + file->f_version = inode_query_iversion(inode);
32461 + au_set_fvdir_cache(file, allocated);
32462 + } else if (allocated)
32463 + au_vdir_free(allocated);
32469 +static loff_t calc_offset(struct au_vdir *vdir)
32472 + union au_vdir_deblk_p p;
32474 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32475 + offset = vdir->vd_last.p.deblk - p.deblk;
32476 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32480 +/* returns true or false */
32481 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32484 + unsigned int deblk_sz;
32485 + unsigned long ul, n;
32487 + union au_vdir_deblk_p p, deblk_end;
32488 + struct au_vdir *vdir_cache;
32491 + vdir_cache = au_fvdir_cache(file);
32492 + offset = calc_offset(vdir_cache);
32493 + AuDbg("offset %lld\n", offset);
32494 + if (ctx->pos == offset)
32497 + vdir_cache->vd_last.ul = 0;
32498 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32503 + deblk_sz = vdir_cache->vd_deblk_sz;
32504 + ul = div64_u64(ctx->pos, deblk_sz);
32505 + AuDbg("ul %lu\n", ul);
32506 + if (ul >= vdir_cache->vd_nblk)
32509 + n = vdir_cache->vd_nblk;
32510 + for (; ul < n; ul++) {
32511 + p.deblk = vdir_cache->vd_deblk[ul];
32512 + deblk_end.deblk = p.deblk + deblk_sz;
32514 + offset *= deblk_sz;
32515 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32518 + l = calc_size(p.de->de_str.len);
32522 + if (!is_deblk_end(&p, &deblk_end)) {
32524 + vdir_cache->vd_last.ul = ul;
32525 + vdir_cache->vd_last.p = p;
32533 + AuDbg("valid %d\n", !valid);
32537 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32539 + unsigned int l, deblk_sz;
32540 + union au_vdir_deblk_p deblk_end;
32541 + struct au_vdir *vdir_cache;
32542 + struct au_vdir_de *de;
32544 + if (!seek_vdir(file, ctx))
32547 + vdir_cache = au_fvdir_cache(file);
32548 + deblk_sz = vdir_cache->vd_deblk_sz;
32550 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32551 + deblk_end.deblk += deblk_sz;
32552 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32553 + de = vdir_cache->vd_last.p.de;
32554 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32555 + de->de_str.len, de->de_str.name, ctx->pos,
32556 + (unsigned long)de->de_ino, de->de_type);
32557 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32558 + de->de_str.len, de->de_ino,
32560 + /* todo: ignore the error caused by udba? */
32561 + /* return err; */
32565 + l = calc_size(de->de_str.len);
32566 + vdir_cache->vd_last.p.deblk += l;
32569 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32570 + vdir_cache->vd_last.ul++;
32571 + vdir_cache->vd_last.p.deblk
32572 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32573 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32582 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32583 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32584 +++ linux/fs/aufs/vfsub.c 2021-02-24 13:33:42.747680497 +0100
32586 +// SPDX-License-Identifier: GPL-2.0
32588 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32590 + * This program, aufs is free software; you can redistribute it and/or modify
32591 + * it under the terms of the GNU General Public License as published by
32592 + * the Free Software Foundation; either version 2 of the License, or
32593 + * (at your option) any later version.
32595 + * This program is distributed in the hope that it will be useful,
32596 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32597 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32598 + * GNU General Public License for more details.
32600 + * You should have received a copy of the GNU General Public License
32601 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32605 + * sub-routines for VFS
32608 +#include <linux/mnt_namespace.h>
32609 +#include <linux/namei.h>
32610 +#include <linux/nsproxy.h>
32611 +#include <linux/security.h>
32612 +#include <linux/splice.h>
32615 +#ifdef CONFIG_AUFS_BR_FUSE
32616 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32618 + if (!au_test_fuse(h_sb) || !au_userns)
32621 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32625 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32630 + down_read(&h_sb->s_umount);
32631 + err = __sync_filesystem(h_sb, wait);
32632 + up_read(&h_sb->s_umount);
32638 +/* ---------------------------------------------------------------------- */
32640 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32644 + struct super_block *h_sb;
32646 + /* for remote fs, leave work for its getattr or d_revalidate */
32647 + /* for bad i_attr fs, handle them in aufs_getattr() */
32648 + /* still some fs may acquire i_mutex. we need to skip them */
32652 + h_sb = h_path->dentry->d_sb;
32653 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32655 + err = vfsub_getattr(h_path, &st);
32660 +/* ---------------------------------------------------------------------- */
32662 +struct file *vfsub_dentry_open(struct path *path, int flags)
32664 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32668 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32670 + struct file *file;
32673 + file = filp_open(path,
32674 + oflags /* | __FMODE_NONOTIFY */,
32677 + if (IS_ERR(file))
32679 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32686 + * Ideally this function should call VFS:do_last() in order to keep all its
32687 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32688 + * structure such as nameidata. This is a second (or third) best approach.
32689 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32691 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32692 + struct vfsub_aopen_args *args)
32695 + struct au_branch *br = args->br;
32696 + struct file *file = args->file;
32697 + /* copied from linux/fs/namei.c:atomic_open() */
32698 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32701 + AuDebugOn(!dir->i_op->atomic_open);
32703 + err = au_br_test_oflag(args->open_flag, br);
32704 + if (unlikely(err))
32707 + au_lcnt_inc(&br->br_nfiles);
32708 + file->f_path.dentry = DENTRY_NOT_SET;
32709 + file->f_path.mnt = au_br_mnt(br);
32710 + AuDbg("%ps\n", dir->i_op->atomic_open);
32711 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32712 + args->create_mode);
32713 + if (unlikely(err < 0)) {
32714 + au_lcnt_dec(&br->br_nfiles);
32718 + /* temporary workaround for nfsv4 branch */
32719 + if (au_test_nfs(dir->i_sb))
32720 + nfs_mark_for_revalidate(dir);
32722 + if (file->f_mode & FMODE_CREATED)
32723 + fsnotify_create(dir, dentry);
32724 + if (!(file->f_mode & FMODE_OPENED)) {
32725 + au_lcnt_dec(&br->br_nfiles);
32729 + /* todo: call VFS:may_open() here */
32730 + /* todo: ima_file_check() too? */
32731 + if (!err && (args->open_flag & __FMODE_EXEC))
32732 + err = deny_write_access(file);
32734 + fsnotify_open(file);
32736 + au_lcnt_dec(&br->br_nfiles);
32737 + /* note that the file is created and still opened */
32743 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32747 + err = kern_path(name, flags, path);
32748 + if (!err && d_is_positive(path->dentry))
32749 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32753 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32754 + struct dentry *parent, int len)
32756 + struct path path = {
32760 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32761 + if (IS_ERR(path.dentry))
32763 + if (d_is_positive(path.dentry))
32764 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32767 + AuTraceErrPtr(path.dentry);
32768 + return path.dentry;
32771 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32774 + struct path path = {
32778 + /* VFS checks it too, but by WARN_ON_ONCE() */
32779 + IMustLock(d_inode(parent));
32781 + path.dentry = lookup_one_len(name, parent, len);
32782 + if (IS_ERR(path.dentry))
32784 + if (d_is_positive(path.dentry))
32785 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32788 + AuTraceErrPtr(path.dentry);
32789 + return path.dentry;
32792 +void vfsub_call_lkup_one(void *args)
32794 + struct vfsub_lkup_one_args *a = args;
32795 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32798 +/* ---------------------------------------------------------------------- */
32800 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32801 + struct dentry *d2, struct au_hinode *hdir2)
32803 + struct dentry *d;
32806 + d = lock_rename(d1, d2);
32808 + au_hn_suspend(hdir1);
32809 + if (hdir1 != hdir2)
32810 + au_hn_suspend(hdir2);
32815 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32816 + struct dentry *d2, struct au_hinode *hdir2)
32818 + au_hn_resume(hdir1);
32819 + if (hdir1 != hdir2)
32820 + au_hn_resume(hdir2);
32822 + unlock_rename(d1, d2);
32826 +/* ---------------------------------------------------------------------- */
32828 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32831 + struct dentry *d;
32835 + d = path->dentry;
32836 + path->dentry = d->d_parent;
32837 + err = security_path_mknod(path, d, mode, 0);
32838 + path->dentry = d;
32839 + if (unlikely(err))
32843 + err = vfs_create(dir, path->dentry, mode, want_excl);
32846 + struct path tmp = *path;
32849 + vfsub_update_h_iattr(&tmp, &did);
32851 + tmp.dentry = path->dentry->d_parent;
32852 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32861 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32864 + struct dentry *d;
32868 + d = path->dentry;
32869 + path->dentry = d->d_parent;
32870 + err = security_path_symlink(path, d, symname);
32871 + path->dentry = d;
32872 + if (unlikely(err))
32876 + err = vfs_symlink(dir, path->dentry, symname);
32879 + struct path tmp = *path;
32882 + vfsub_update_h_iattr(&tmp, &did);
32884 + tmp.dentry = path->dentry->d_parent;
32885 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32894 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32897 + struct dentry *d;
32901 + d = path->dentry;
32902 + path->dentry = d->d_parent;
32903 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32904 + path->dentry = d;
32905 + if (unlikely(err))
32909 + err = vfs_mknod(dir, path->dentry, mode, dev);
32912 + struct path tmp = *path;
32915 + vfsub_update_h_iattr(&tmp, &did);
32917 + tmp.dentry = path->dentry->d_parent;
32918 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32927 +static int au_test_nlink(struct inode *inode)
32929 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32931 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32932 + || inode->i_nlink < link_max)
32937 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32938 + struct inode **delegated_inode)
32941 + struct dentry *d;
32945 + err = au_test_nlink(d_inode(src_dentry));
32946 + if (unlikely(err))
32949 + /* we don't call may_linkat() */
32950 + d = path->dentry;
32951 + path->dentry = d->d_parent;
32952 + err = security_path_link(src_dentry, path, d);
32953 + path->dentry = d;
32954 + if (unlikely(err))
32958 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32961 + struct path tmp = *path;
32964 + /* fuse has different memory inode for the same inumber */
32965 + vfsub_update_h_iattr(&tmp, &did);
32967 + tmp.dentry = path->dentry->d_parent;
32968 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32969 + tmp.dentry = src_dentry;
32970 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32979 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32980 + struct inode *dir, struct path *path,
32981 + struct inode **delegated_inode, unsigned int flags)
32984 + struct path tmp = {
32987 + struct dentry *d;
32990 + IMustLock(src_dir);
32992 + d = path->dentry;
32993 + path->dentry = d->d_parent;
32994 + tmp.dentry = src_dentry->d_parent;
32995 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32996 + path->dentry = d;
32997 + if (unlikely(err))
33001 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33002 + delegated_inode, flags);
33007 + tmp.dentry = d->d_parent;
33008 + vfsub_update_h_iattr(&tmp, &did);
33010 + tmp.dentry = src_dentry;
33011 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33012 + tmp.dentry = src_dentry->d_parent;
33013 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33022 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33025 + struct dentry *d;
33029 + d = path->dentry;
33030 + path->dentry = d->d_parent;
33031 + err = security_path_mkdir(path, d, mode);
33032 + path->dentry = d;
33033 + if (unlikely(err))
33037 + err = vfs_mkdir(dir, path->dentry, mode);
33040 + struct path tmp = *path;
33043 + vfsub_update_h_iattr(&tmp, &did);
33045 + tmp.dentry = path->dentry->d_parent;
33046 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33055 +int vfsub_rmdir(struct inode *dir, struct path *path)
33058 + struct dentry *d;
33062 + d = path->dentry;
33063 + path->dentry = d->d_parent;
33064 + err = security_path_rmdir(path, d);
33065 + path->dentry = d;
33066 + if (unlikely(err))
33070 + err = vfs_rmdir(dir, path->dentry);
33073 + struct path tmp = {
33074 + .dentry = path->dentry->d_parent,
33078 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33085 +/* ---------------------------------------------------------------------- */
33087 +/* todo: support mmap_sem? */
33088 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33094 + err = vfs_read(file, ubuf, count, ppos);
33097 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33101 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33107 + err = kernel_read(file, kbuf, count, ppos);
33111 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33115 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33121 + err = vfs_write(file, ubuf, count, ppos);
33124 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33128 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33133 + err = kernel_write(file, kbuf, count, ppos);
33136 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33140 +int vfsub_flush(struct file *file, fl_owner_t id)
33145 + if (file->f_op->flush) {
33146 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33147 + err = file->f_op->flush(file, id);
33150 + err = file->f_op->flush(file, id);
33154 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33160 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33164 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33167 + err = iterate_dir(file, ctx);
33170 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33175 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33176 + struct pipe_inode_info *pipe, size_t len,
33177 + unsigned int flags)
33182 + err = do_splice_to(in, ppos, pipe, len, flags);
33184 + file_accessed(in);
33186 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33190 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33191 + loff_t *ppos, size_t len, unsigned int flags)
33196 + err = do_splice_from(pipe, out, ppos, len, flags);
33199 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33203 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33207 + /* file can be NULL */
33209 + err = vfs_fsync(file, datasync);
33213 + AuDebugOn(!file);
33214 + path = &file->f_path;
33216 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33221 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33222 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33223 + struct file *h_file)
33226 + struct inode *h_inode;
33227 + struct super_block *h_sb;
33230 + err = vfsub_truncate(h_path, length);
33234 + h_inode = d_inode(h_path->dentry);
33235 + h_sb = h_inode->i_sb;
33237 + sb_start_write(h_sb);
33239 + err = locks_verify_truncate(h_inode, h_file, length);
33241 + err = security_path_truncate(h_path);
33244 + err = do_truncate(h_path->dentry, length, attr, h_file);
33248 + sb_end_write(h_sb);
33255 +/* ---------------------------------------------------------------------- */
33257 +struct au_vfsub_mkdir_args {
33259 + struct inode *dir;
33260 + struct path *path;
33264 +static void au_call_vfsub_mkdir(void *args)
33266 + struct au_vfsub_mkdir_args *a = args;
33267 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33270 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33272 + int err, do_sio, wkq_err;
33274 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33277 + err = vfsub_mkdir(dir, path, mode);
33280 + struct au_vfsub_mkdir_args args = {
33286 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33287 + if (unlikely(wkq_err))
33294 +struct au_vfsub_rmdir_args {
33296 + struct inode *dir;
33297 + struct path *path;
33300 +static void au_call_vfsub_rmdir(void *args)
33302 + struct au_vfsub_rmdir_args *a = args;
33303 + *a->errp = vfsub_rmdir(a->dir, a->path);
33306 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33308 + int err, do_sio, wkq_err;
33310 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33313 + err = vfsub_rmdir(dir, path);
33316 + struct au_vfsub_rmdir_args args = {
33321 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33322 + if (unlikely(wkq_err))
33329 +/* ---------------------------------------------------------------------- */
33331 +struct notify_change_args {
33333 + struct path *path;
33334 + struct iattr *ia;
33335 + struct inode **delegated_inode;
33338 +static void call_notify_change(void *args)
33340 + struct notify_change_args *a = args;
33341 + struct inode *h_inode;
33343 + h_inode = d_inode(a->path->dentry);
33344 + IMustLock(h_inode);
33346 + *a->errp = -EPERM;
33347 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33349 + *a->errp = notify_change(a->path->dentry, a->ia,
33350 + a->delegated_inode);
33353 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33355 + AuTraceErr(*a->errp);
33358 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33359 + struct inode **delegated_inode)
33362 + struct notify_change_args args = {
33366 + .delegated_inode = delegated_inode
33369 + call_notify_change(&args);
33374 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33375 + struct inode **delegated_inode)
33377 + int err, wkq_err;
33378 + struct notify_change_args args = {
33382 + .delegated_inode = delegated_inode
33385 + wkq_err = au_wkq_wait(call_notify_change, &args);
33386 + if (unlikely(wkq_err))
33392 +/* ---------------------------------------------------------------------- */
33394 +struct unlink_args {
33396 + struct inode *dir;
33397 + struct path *path;
33398 + struct inode **delegated_inode;
33401 +static void call_unlink(void *args)
33403 + struct unlink_args *a = args;
33404 + struct dentry *d = a->path->dentry;
33405 + struct inode *h_inode;
33406 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33407 + && au_dcount(d) == 1);
33409 + IMustLock(a->dir);
33411 + a->path->dentry = d->d_parent;
33412 + *a->errp = security_path_unlink(a->path, d);
33413 + a->path->dentry = d;
33414 + if (unlikely(*a->errp))
33417 + if (!stop_sillyrename)
33420 + if (d_is_positive(d)) {
33421 + h_inode = d_inode(d);
33426 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33429 + struct path tmp = {
33430 + .dentry = d->d_parent,
33431 + .mnt = a->path->mnt
33433 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33436 + if (!stop_sillyrename)
33441 + AuTraceErr(*a->errp);
33445 + * @dir: must be locked.
33446 + * @dentry: target dentry.
33448 +int vfsub_unlink(struct inode *dir, struct path *path,
33449 + struct inode **delegated_inode, int force)
33452 + struct unlink_args args = {
33456 + .delegated_inode = delegated_inode
33460 + call_unlink(&args);
33464 + wkq_err = au_wkq_wait(call_unlink, &args);
33465 + if (unlikely(wkq_err))
33471 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33472 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33473 +++ linux/fs/aufs/vfsub.h 2021-02-24 13:33:42.747680497 +0100
33475 +/* SPDX-License-Identifier: GPL-2.0 */
33477 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33479 + * This program, aufs is free software; you can redistribute it and/or modify
33480 + * it under the terms of the GNU General Public License as published by
33481 + * the Free Software Foundation; either version 2 of the License, or
33482 + * (at your option) any later version.
33484 + * This program is distributed in the hope that it will be useful,
33485 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33486 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33487 + * GNU General Public License for more details.
33489 + * You should have received a copy of the GNU General Public License
33490 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33494 + * sub-routines for VFS
33497 +#ifndef __AUFS_VFSUB_H__
33498 +#define __AUFS_VFSUB_H__
33502 +#include <linux/fs.h>
33503 +#include <linux/mount.h>
33504 +#include <linux/posix_acl.h>
33505 +#include <linux/xattr.h>
33506 +#include "debug.h"
33508 +/* copied from linux/fs/internal.h */
33509 +/* todo: BAD approach!! */
33510 +extern void __mnt_drop_write(struct vfsmount *);
33511 +extern struct file *alloc_empty_file(int, const struct cred *);
33513 +/* ---------------------------------------------------------------------- */
33515 +/* lock subclass for lower inode */
33516 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33517 +/* reduce? gave up. */
33519 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33520 + AuLsc_I_PARENT, /* lower inode, parent first */
33521 + AuLsc_I_PARENT2, /* copyup dirs */
33522 + AuLsc_I_PARENT3, /* copyup wh */
33528 +/* to debug easier, do not make them inlined functions */
33529 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33530 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33532 +/* ---------------------------------------------------------------------- */
33534 +static inline void vfsub_drop_nlink(struct inode *inode)
33536 + AuDebugOn(!inode->i_nlink);
33537 + drop_nlink(inode);
33540 +static inline void vfsub_dead_dir(struct inode *inode)
33542 + AuDebugOn(!S_ISDIR(inode->i_mode));
33543 + inode->i_flags |= S_DEAD;
33544 + clear_nlink(inode);
33547 +static inline int vfsub_native_ro(struct inode *inode)
33549 + return sb_rdonly(inode->i_sb)
33550 + || IS_RDONLY(inode)
33551 + /* || IS_APPEND(inode) */
33552 + || IS_IMMUTABLE(inode);
33555 +#ifdef CONFIG_AUFS_BR_FUSE
33556 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33558 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33561 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33563 +/* ---------------------------------------------------------------------- */
33565 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33566 +struct file *vfsub_dentry_open(struct path *path, int flags);
33567 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33569 +struct vfsub_aopen_args {
33570 + struct file *file;
33571 + unsigned int open_flag;
33572 + umode_t create_mode;
33573 + struct au_branch *br;
33575 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33576 + struct vfsub_aopen_args *args);
33577 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33579 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33580 + struct dentry *parent, int len);
33581 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33584 +struct vfsub_lkup_one_args {
33585 + struct dentry **errp;
33586 + struct qstr *name;
33587 + struct dentry *parent;
33590 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33591 + struct dentry *parent)
33593 + return vfsub_lookup_one_len(name->name, parent, name->len);
33596 +void vfsub_call_lkup_one(void *args);
33598 +/* ---------------------------------------------------------------------- */
33600 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33605 + err = mnt_want_write(mnt);
33610 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33613 + mnt_drop_write(mnt);
33617 +#if 0 /* reserved */
33618 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33621 + mnt_drop_write_file(file);
33626 +/* ---------------------------------------------------------------------- */
33629 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33630 + struct dentry *d2, struct au_hinode *hdir2);
33631 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33632 + struct dentry *d2, struct au_hinode *hdir2);
33634 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33636 +int vfsub_symlink(struct inode *dir, struct path *path,
33637 + const char *symname);
33638 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33639 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33640 + struct path *path, struct inode **delegated_inode);
33641 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33642 + struct inode *hdir, struct path *path,
33643 + struct inode **delegated_inode, unsigned int flags);
33644 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33645 +int vfsub_rmdir(struct inode *dir, struct path *path);
33647 +/* ---------------------------------------------------------------------- */
33649 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33651 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33653 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33655 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33657 +int vfsub_flush(struct file *file, fl_owner_t id);
33658 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33660 +static inline loff_t vfsub_f_size_read(struct file *file)
33662 + return i_size_read(file_inode(file));
33665 +static inline unsigned int vfsub_file_flags(struct file *file)
33667 + unsigned int flags;
33669 + spin_lock(&file->f_lock);
33670 + flags = file->f_flags;
33671 + spin_unlock(&file->f_lock);
33676 +static inline int vfsub_file_execed(struct file *file)
33678 + /* todo: direct access f_flags */
33679 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33682 +#if 0 /* reserved */
33683 +static inline void vfsub_file_accessed(struct file *h_file)
33685 + file_accessed(h_file);
33686 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33690 +#if 0 /* reserved */
33691 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33692 + struct dentry *h_dentry)
33694 + struct path h_path = {
33695 + .dentry = h_dentry,
33698 + touch_atime(&h_path);
33699 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33703 +static inline int vfsub_update_time(struct inode *h_inode,
33704 + struct timespec64 *ts, int flags)
33706 + return update_time(h_inode, ts, flags);
33707 + /* no vfsub_update_h_iattr() since we don't have struct path */
33710 +#ifdef CONFIG_FS_POSIX_ACL
33711 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33715 + err = posix_acl_chmod(h_inode, h_mode);
33716 + if (err == -EOPNOTSUPP)
33721 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33724 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33725 + struct pipe_inode_info *pipe, size_t len,
33726 + unsigned int flags);
33727 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33728 + loff_t *ppos, size_t len, unsigned int flags);
33730 +static inline long vfsub_truncate(struct path *path, loff_t length)
33735 + err = vfs_truncate(path, length);
33740 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33741 + struct file *h_file);
33742 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33745 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33748 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33754 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33760 +/* copy_file_range(2) is a systemcall */
33761 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33762 + struct file *dst, loff_t dst_pos,
33763 + size_t len, unsigned int flags)
33768 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33774 +/* ---------------------------------------------------------------------- */
33776 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33781 + err = vfs_llseek(file, offset, origin);
33786 +/* ---------------------------------------------------------------------- */
33788 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33789 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33790 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33791 + struct inode **delegated_inode);
33792 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33793 + struct inode **delegated_inode);
33794 +int vfsub_unlink(struct inode *dir, struct path *path,
33795 + struct inode **delegated_inode, int force);
33797 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33799 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33802 +/* ---------------------------------------------------------------------- */
33804 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33805 + const void *value, size_t size, int flags)
33810 + err = vfs_setxattr(dentry, name, value, size, flags);
33816 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33821 + err = vfs_removexattr(dentry, name);
33827 +#endif /* __KERNEL__ */
33828 +#endif /* __AUFS_VFSUB_H__ */
33829 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33830 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33831 +++ linux/fs/aufs/wbr_policy.c 2021-02-24 13:33:42.747680497 +0100
33833 +// SPDX-License-Identifier: GPL-2.0
33835 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33837 + * This program, aufs is free software; you can redistribute it and/or modify
33838 + * it under the terms of the GNU General Public License as published by
33839 + * the Free Software Foundation; either version 2 of the License, or
33840 + * (at your option) any later version.
33842 + * This program is distributed in the hope that it will be useful,
33843 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33844 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33845 + * GNU General Public License for more details.
33847 + * You should have received a copy of the GNU General Public License
33848 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33852 + * policies for selecting one among multiple writable branches
33855 +#include <linux/statfs.h>
33858 +/* subset of cpup_attr() */
33859 +static noinline_for_stack
33860 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33864 + struct inode *h_isrc;
33866 + h_isrc = d_inode(h_src);
33867 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33868 + ia.ia_mode = h_isrc->i_mode;
33869 + ia.ia_uid = h_isrc->i_uid;
33870 + ia.ia_gid = h_isrc->i_gid;
33871 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33872 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33873 + /* no delegation since it is just created */
33874 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33876 + /* is this nfs only? */
33877 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33878 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33879 + ia.ia_mode = h_isrc->i_mode;
33880 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33886 +#define AuCpdown_PARENT_OPQ 1
33887 +#define AuCpdown_WHED (1 << 1)
33888 +#define AuCpdown_MADE_DIR (1 << 2)
33889 +#define AuCpdown_DIROPQ (1 << 3)
33890 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33891 +#define au_fset_cpdown(flags, name) \
33892 + do { (flags) |= AuCpdown_##name; } while (0)
33893 +#define au_fclr_cpdown(flags, name) \
33894 + do { (flags) &= ~AuCpdown_##name; } while (0)
33896 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33897 + unsigned int *flags)
33900 + struct dentry *opq_dentry;
33902 + opq_dentry = au_diropq_create(dentry, bdst);
33903 + err = PTR_ERR(opq_dentry);
33904 + if (IS_ERR(opq_dentry))
33906 + dput(opq_dentry);
33907 + au_fset_cpdown(*flags, DIROPQ);
33913 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33914 + struct inode *dir, aufs_bindex_t bdst)
33917 + struct path h_path;
33918 + struct au_branch *br;
33920 + br = au_sbr(dentry->d_sb, bdst);
33921 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33922 + err = PTR_ERR(h_path.dentry);
33923 + if (IS_ERR(h_path.dentry))
33927 + if (d_is_positive(h_path.dentry)) {
33928 + h_path.mnt = au_br_mnt(br);
33929 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33932 + dput(h_path.dentry);
33938 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33939 + struct au_pin *pin,
33940 + struct dentry *h_parent, void *arg)
33943 + aufs_bindex_t bopq, btop;
33944 + struct path h_path;
33945 + struct dentry *parent;
33946 + struct inode *h_dir, *h_inode, *inode, *dir;
33947 + unsigned int *flags = arg;
33949 + btop = au_dbtop(dentry);
33950 + /* dentry is di-locked */
33951 + parent = dget_parent(dentry);
33952 + dir = d_inode(parent);
33953 + h_dir = d_inode(h_parent);
33954 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33955 + IMustLock(h_dir);
33957 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33958 + if (unlikely(err < 0))
33960 + h_path.dentry = au_h_dptr(dentry, bdst);
33961 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33962 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
33963 + if (unlikely(err))
33965 + au_fset_cpdown(*flags, MADE_DIR);
33967 + bopq = au_dbdiropq(dentry);
33968 + au_fclr_cpdown(*flags, WHED);
33969 + au_fclr_cpdown(*flags, DIROPQ);
33970 + if (au_dbwh(dentry) == bdst)
33971 + au_fset_cpdown(*flags, WHED);
33972 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33973 + au_fset_cpdown(*flags, PARENT_OPQ);
33974 + h_inode = d_inode(h_path.dentry);
33975 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33976 + if (au_ftest_cpdown(*flags, WHED)) {
33977 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33978 + if (unlikely(err)) {
33979 + inode_unlock(h_inode);
33984 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33985 + inode_unlock(h_inode);
33986 + if (unlikely(err))
33989 + if (au_ftest_cpdown(*flags, WHED)) {
33990 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33991 + if (unlikely(err))
33995 + inode = d_inode(dentry);
33996 + if (au_ibbot(inode) < bdst)
33997 + au_set_ibbot(inode, bdst);
33998 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
33999 + au_hi_flags(inode, /*isdir*/1));
34000 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34001 + goto out; /* success */
34005 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34006 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34007 + rerr = au_diropq_remove(dentry, bdst);
34008 + inode_unlock(h_inode);
34009 + if (unlikely(rerr)) {
34010 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34011 + dentry, bdst, rerr);
34017 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34018 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34019 + if (unlikely(rerr)) {
34020 + AuIOErr("failed removing %pd b%d (%d)\n",
34021 + dentry, bdst, rerr);
34026 + au_set_h_dptr(dentry, bdst, NULL);
34027 + if (au_dbbot(dentry) == bdst)
34028 + au_update_dbbot(dentry);
34034 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34037 + unsigned int flags;
34040 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34045 +/* ---------------------------------------------------------------------- */
34047 +/* policies for create */
34049 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34051 + int err, i, j, ndentry;
34052 + aufs_bindex_t bopq;
34053 + struct au_dcsub_pages dpages;
34054 + struct au_dpage *dpage;
34055 + struct dentry **dentries, *parent, *d;
34057 + err = au_dpages_init(&dpages, GFP_NOFS);
34058 + if (unlikely(err))
34060 + parent = dget_parent(dentry);
34061 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34062 + if (unlikely(err))
34066 + for (i = 0; i < dpages.ndpage; i++) {
34067 + dpage = dpages.dpages + i;
34068 + dentries = dpage->dentries;
34069 + ndentry = dpage->ndentry;
34070 + for (j = 0; j < ndentry; j++) {
34072 + di_read_lock_parent2(d, !AuLock_IR);
34073 + bopq = au_dbdiropq(d);
34074 + di_read_unlock(d, !AuLock_IR);
34075 + if (bopq >= 0 && bopq < err)
34082 + au_dpages_free(&dpages);
34087 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34089 + for (; bindex >= 0; bindex--)
34090 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34095 +/* top down parent */
34096 +static int au_wbr_create_tdp(struct dentry *dentry,
34097 + unsigned int flags __maybe_unused)
34100 + aufs_bindex_t btop, bindex;
34101 + struct super_block *sb;
34102 + struct dentry *parent, *h_parent;
34104 + sb = dentry->d_sb;
34105 + btop = au_dbtop(dentry);
34107 + if (!au_br_rdonly(au_sbr(sb, btop)))
34111 + parent = dget_parent(dentry);
34112 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34113 + h_parent = au_h_dptr(parent, bindex);
34114 + if (!h_parent || d_is_negative(h_parent))
34117 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34124 + /* bottom up here */
34125 + if (unlikely(err < 0)) {
34126 + err = au_wbr_bu(sb, btop - 1);
34128 + err = au_wbr_nonopq(dentry, err);
34132 + AuDbg("b%d\n", err);
34136 +/* ---------------------------------------------------------------------- */
34138 +/* an exception for the policy other than tdp */
34139 +static int au_wbr_create_exp(struct dentry *dentry)
34142 + aufs_bindex_t bwh, bdiropq;
34143 + struct dentry *parent;
34146 + bwh = au_dbwh(dentry);
34147 + parent = dget_parent(dentry);
34148 + bdiropq = au_dbdiropq(parent);
34150 + if (bdiropq >= 0)
34151 + err = min(bdiropq, bwh);
34154 + AuDbg("%d\n", err);
34155 + } else if (bdiropq >= 0) {
34157 + AuDbg("%d\n", err);
34162 + err = au_wbr_nonopq(dentry, err);
34164 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34167 + AuDbg("%d\n", err);
34171 +/* ---------------------------------------------------------------------- */
34174 +static int au_wbr_create_init_rr(struct super_block *sb)
34178 + err = au_wbr_bu(sb, au_sbbot(sb));
34179 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34182 + AuDbg("b%d\n", err);
34186 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34190 + aufs_bindex_t bindex, bbot;
34191 + struct super_block *sb;
34194 + err = au_wbr_create_exp(dentry);
34198 + sb = dentry->d_sb;
34199 + next = &au_sbi(sb)->si_wbr_rr_next;
34200 + bbot = au_sbbot(sb);
34202 + for (bindex = 0; bindex <= bbot; bindex++) {
34203 + if (!au_ftest_wbr(flags, DIR)) {
34204 + err = atomic_dec_return(next) + 1;
34205 + /* modulo for 0 is meaningless */
34206 + if (unlikely(!err))
34207 + err = atomic_dec_return(next) + 1;
34209 + err = atomic_read(next);
34210 + AuDbg("%d\n", err);
34213 + AuDbg("%d\n", err);
34214 + if (!au_br_rdonly(au_sbr(sb, err)))
34220 + err = au_wbr_nonopq(dentry, err);
34223 + AuDbg("%d\n", err);
34227 +/* ---------------------------------------------------------------------- */
34229 +/* most free space */
34230 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34232 + struct super_block *sb;
34233 + struct au_branch *br;
34234 + struct au_wbr_mfs *mfs;
34235 + struct dentry *h_parent;
34236 + aufs_bindex_t bindex, bbot;
34238 + unsigned long long b, bavail;
34239 + struct path h_path;
34240 + /* reduce the stack usage */
34241 + struct kstatfs *st;
34243 + st = kmalloc(sizeof(*st), GFP_NOFS);
34244 + if (unlikely(!st)) {
34245 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34250 + sb = dentry->d_sb;
34251 + mfs = &au_sbi(sb)->si_wbr_mfs;
34252 + MtxMustLock(&mfs->mfs_lock);
34253 + mfs->mfs_bindex = -EROFS;
34254 + mfs->mfsrr_bytes = 0;
34257 + bbot = au_sbbot(sb);
34259 + bindex = au_dbtop(parent);
34260 + bbot = au_dbtaildir(parent);
34263 + for (; bindex <= bbot; bindex++) {
34265 + h_parent = au_h_dptr(parent, bindex);
34266 + if (!h_parent || d_is_negative(h_parent))
34269 + br = au_sbr(sb, bindex);
34270 + if (au_br_rdonly(br))
34273 + /* sb->s_root for NFS is unreliable */
34274 + h_path.mnt = au_br_mnt(br);
34275 + h_path.dentry = h_path.mnt->mnt_root;
34276 + err = vfs_statfs(&h_path, st);
34277 + if (unlikely(err)) {
34278 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34282 + /* when the available size is equal, select the lower one */
34283 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34284 + || sizeof(b) < sizeof(st->f_bsize));
34285 + b = st->f_bavail * st->f_bsize;
34286 + br->br_wbr->wbr_bytes = b;
34287 + if (b >= bavail) {
34289 + mfs->mfs_bindex = bindex;
34290 + mfs->mfs_jiffy = jiffies;
34294 + mfs->mfsrr_bytes = bavail;
34295 + AuDbg("b%d\n", mfs->mfs_bindex);
34296 + au_kfree_rcu(st);
34299 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34302 + struct dentry *parent;
34303 + struct super_block *sb;
34304 + struct au_wbr_mfs *mfs;
34306 + err = au_wbr_create_exp(dentry);
34310 + sb = dentry->d_sb;
34312 + if (au_ftest_wbr(flags, PARENT))
34313 + parent = dget_parent(dentry);
34314 + mfs = &au_sbi(sb)->si_wbr_mfs;
34315 + mutex_lock(&mfs->mfs_lock);
34316 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34317 + || mfs->mfs_bindex < 0
34318 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34319 + au_mfs(dentry, parent);
34320 + mutex_unlock(&mfs->mfs_lock);
34321 + err = mfs->mfs_bindex;
34325 + err = au_wbr_nonopq(dentry, err);
34328 + AuDbg("b%d\n", err);
34332 +static int au_wbr_create_init_mfs(struct super_block *sb)
34334 + struct au_wbr_mfs *mfs;
34336 + mfs = &au_sbi(sb)->si_wbr_mfs;
34337 + mutex_init(&mfs->mfs_lock);
34338 + mfs->mfs_jiffy = 0;
34339 + mfs->mfs_bindex = -EROFS;
34344 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34346 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34350 +/* ---------------------------------------------------------------------- */
34352 +/* top down regardless parent, and then mfs */
34353 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34354 + unsigned int flags __maybe_unused)
34357 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34358 + unsigned long long watermark;
34359 + struct super_block *sb;
34360 + struct au_wbr_mfs *mfs;
34361 + struct au_branch *br;
34362 + struct dentry *parent;
34364 + sb = dentry->d_sb;
34365 + mfs = &au_sbi(sb)->si_wbr_mfs;
34366 + mutex_lock(&mfs->mfs_lock);
34367 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34368 + || mfs->mfs_bindex < 0)
34369 + au_mfs(dentry, /*parent*/NULL);
34370 + watermark = mfs->mfsrr_watermark;
34371 + bmfs = mfs->mfs_bindex;
34372 + mutex_unlock(&mfs->mfs_lock);
34374 + /* another style of au_wbr_create_exp() */
34375 + bwh = au_dbwh(dentry);
34376 + parent = dget_parent(dentry);
34377 + btail = au_dbtaildir(parent);
34378 + if (bwh >= 0 && bwh < btail)
34381 + err = au_wbr_nonopq(dentry, btail);
34382 + if (unlikely(err < 0))
34386 + for (bindex = 0; bindex <= btail; bindex++) {
34387 + br = au_sbr(sb, bindex);
34388 + if (au_br_rdonly(br))
34390 + if (br->br_wbr->wbr_bytes > watermark) {
34401 + AuDbg("b%d\n", err);
34405 +/* ---------------------------------------------------------------------- */
34407 +/* most free space and then round robin */
34408 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34411 + struct au_wbr_mfs *mfs;
34413 + err = au_wbr_create_mfs(dentry, flags);
34415 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34416 + mutex_lock(&mfs->mfs_lock);
34417 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34418 + err = au_wbr_create_rr(dentry, flags);
34419 + mutex_unlock(&mfs->mfs_lock);
34422 + AuDbg("b%d\n", err);
34426 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34430 + au_wbr_create_init_mfs(sb); /* ignore */
34431 + err = au_wbr_create_init_rr(sb);
34436 +/* ---------------------------------------------------------------------- */
34438 +/* top down parent and most free space */
34439 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34442 + unsigned long long b;
34443 + aufs_bindex_t bindex, btop, bbot;
34444 + struct super_block *sb;
34445 + struct dentry *parent, *h_parent;
34446 + struct au_branch *br;
34448 + err = au_wbr_create_tdp(dentry, flags);
34449 + if (unlikely(err < 0))
34451 + parent = dget_parent(dentry);
34452 + btop = au_dbtop(parent);
34453 + bbot = au_dbtaildir(parent);
34454 + if (btop == bbot)
34455 + goto out_parent; /* success */
34457 + e2 = au_wbr_create_mfs(dentry, flags);
34459 + goto out_parent; /* success */
34461 + /* when the available size is equal, select upper one */
34462 + sb = dentry->d_sb;
34463 + br = au_sbr(sb, err);
34464 + b = br->br_wbr->wbr_bytes;
34465 + AuDbg("b%d, %llu\n", err, b);
34467 + for (bindex = btop; bindex <= bbot; bindex++) {
34468 + h_parent = au_h_dptr(parent, bindex);
34469 + if (!h_parent || d_is_negative(h_parent))
34472 + br = au_sbr(sb, bindex);
34473 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34474 + b = br->br_wbr->wbr_bytes;
34476 + AuDbg("b%d, %llu\n", err, b);
34481 + err = au_wbr_nonopq(dentry, err);
34486 + AuDbg("b%d\n", err);
34490 +/* ---------------------------------------------------------------------- */
34493 + * - top down parent
34494 + * - most free space with parent
34495 + * - most free space round-robin regardless parent
34497 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34500 + unsigned long long watermark;
34501 + struct super_block *sb;
34502 + struct au_branch *br;
34503 + struct au_wbr_mfs *mfs;
34505 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34506 + if (unlikely(err < 0))
34509 + sb = dentry->d_sb;
34510 + br = au_sbr(sb, err);
34511 + mfs = &au_sbi(sb)->si_wbr_mfs;
34512 + mutex_lock(&mfs->mfs_lock);
34513 + watermark = mfs->mfsrr_watermark;
34514 + mutex_unlock(&mfs->mfs_lock);
34515 + if (br->br_wbr->wbr_bytes < watermark)
34516 + /* regardless the parent dir */
34517 + err = au_wbr_create_mfsrr(dentry, flags);
34520 + AuDbg("b%d\n", err);
34524 +/* ---------------------------------------------------------------------- */
34526 +/* policies for copyup */
34528 +/* top down parent */
34529 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34531 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34534 +/* bottom up parent */
34535 +static int au_wbr_copyup_bup(struct dentry *dentry)
34538 + aufs_bindex_t bindex, btop;
34539 + struct dentry *parent, *h_parent;
34540 + struct super_block *sb;
34543 + sb = dentry->d_sb;
34544 + parent = dget_parent(dentry);
34545 + btop = au_dbtop(parent);
34546 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34547 + h_parent = au_h_dptr(parent, bindex);
34548 + if (!h_parent || d_is_negative(h_parent))
34551 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34558 + /* bottom up here */
34559 + if (unlikely(err < 0))
34560 + err = au_wbr_bu(sb, btop - 1);
34562 + AuDbg("b%d\n", err);
34567 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34571 + err = au_wbr_bu(dentry->d_sb, btop);
34572 + AuDbg("b%d\n", err);
34574 + err = au_wbr_nonopq(dentry, err);
34576 + AuDbg("b%d\n", err);
34580 +static int au_wbr_copyup_bu(struct dentry *dentry)
34583 + aufs_bindex_t btop;
34585 + btop = au_dbtop(dentry);
34586 + err = au_wbr_do_copyup_bu(dentry, btop);
34590 +/* ---------------------------------------------------------------------- */
34592 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34593 + [AuWbrCopyup_TDP] = {
34594 + .copyup = au_wbr_copyup_tdp
34596 + [AuWbrCopyup_BUP] = {
34597 + .copyup = au_wbr_copyup_bup
34599 + [AuWbrCopyup_BU] = {
34600 + .copyup = au_wbr_copyup_bu
34604 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34605 + [AuWbrCreate_TDP] = {
34606 + .create = au_wbr_create_tdp
34608 + [AuWbrCreate_RR] = {
34609 + .create = au_wbr_create_rr,
34610 + .init = au_wbr_create_init_rr
34612 + [AuWbrCreate_MFS] = {
34613 + .create = au_wbr_create_mfs,
34614 + .init = au_wbr_create_init_mfs,
34615 + .fin = au_wbr_create_fin_mfs
34617 + [AuWbrCreate_MFSV] = {
34618 + .create = au_wbr_create_mfs,
34619 + .init = au_wbr_create_init_mfs,
34620 + .fin = au_wbr_create_fin_mfs
34622 + [AuWbrCreate_MFSRR] = {
34623 + .create = au_wbr_create_mfsrr,
34624 + .init = au_wbr_create_init_mfsrr,
34625 + .fin = au_wbr_create_fin_mfs
34627 + [AuWbrCreate_MFSRRV] = {
34628 + .create = au_wbr_create_mfsrr,
34629 + .init = au_wbr_create_init_mfsrr,
34630 + .fin = au_wbr_create_fin_mfs
34632 + [AuWbrCreate_TDMFS] = {
34633 + .create = au_wbr_create_tdmfs,
34634 + .init = au_wbr_create_init_mfs,
34635 + .fin = au_wbr_create_fin_mfs
34637 + [AuWbrCreate_TDMFSV] = {
34638 + .create = au_wbr_create_tdmfs,
34639 + .init = au_wbr_create_init_mfs,
34640 + .fin = au_wbr_create_fin_mfs
34642 + [AuWbrCreate_PMFS] = {
34643 + .create = au_wbr_create_pmfs,
34644 + .init = au_wbr_create_init_mfs,
34645 + .fin = au_wbr_create_fin_mfs
34647 + [AuWbrCreate_PMFSV] = {
34648 + .create = au_wbr_create_pmfs,
34649 + .init = au_wbr_create_init_mfs,
34650 + .fin = au_wbr_create_fin_mfs
34652 + [AuWbrCreate_PMFSRR] = {
34653 + .create = au_wbr_create_pmfsrr,
34654 + .init = au_wbr_create_init_mfsrr,
34655 + .fin = au_wbr_create_fin_mfs
34657 + [AuWbrCreate_PMFSRRV] = {
34658 + .create = au_wbr_create_pmfsrr,
34659 + .init = au_wbr_create_init_mfsrr,
34660 + .fin = au_wbr_create_fin_mfs
34663 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34664 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34665 +++ linux/fs/aufs/whout.c 2021-02-24 13:33:42.751013936 +0100
34667 +// SPDX-License-Identifier: GPL-2.0
34669 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34671 + * This program, aufs is free software; you can redistribute it and/or modify
34672 + * it under the terms of the GNU General Public License as published by
34673 + * the Free Software Foundation; either version 2 of the License, or
34674 + * (at your option) any later version.
34676 + * This program is distributed in the hope that it will be useful,
34677 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34678 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34679 + * GNU General Public License for more details.
34681 + * You should have received a copy of the GNU General Public License
34682 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34686 + * whiteout for logical deletion and opaque directory
34691 +#define WH_MASK 0444
34694 + * If a directory contains this file, then it is opaque. We start with the
34695 + * .wh. flag so that it is blocked by lookup.
34697 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34698 + sizeof(AUFS_WH_DIROPQ) - 1);
34701 + * generate whiteout name, which is NOT terminated by NULL.
34702 + * @name: original d_name.name
34703 + * @len: original d_name.len
34704 + * @wh: whiteout qstr
34705 + * returns zero when succeeds, otherwise error.
34706 + * succeeded value as wh->name should be freed by kfree().
34708 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34712 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34713 + return -ENAMETOOLONG;
34715 + wh->len = name->len + AUFS_WH_PFX_LEN;
34716 + p = kmalloc(wh->len, GFP_NOFS);
34719 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34720 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34727 +/* ---------------------------------------------------------------------- */
34730 + * test if the @wh_name exists under @h_parent.
34731 + * @try_sio specifies the necessary of super-io.
34733 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34736 + struct dentry *wh_dentry;
34739 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34741 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34742 + err = PTR_ERR(wh_dentry);
34743 + if (IS_ERR(wh_dentry)) {
34744 + if (err == -ENAMETOOLONG)
34750 + if (d_is_negative(wh_dentry))
34751 + goto out_wh; /* success */
34754 + if (d_is_reg(wh_dentry))
34755 + goto out_wh; /* success */
34758 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34759 + wh_dentry, d_inode(wh_dentry)->i_mode);
34768 + * test if the @h_dentry sets opaque or not.
34770 +int au_diropq_test(struct dentry *h_dentry)
34773 + struct inode *h_dir;
34775 + h_dir = d_inode(h_dentry);
34776 + err = au_wh_test(h_dentry, &diropq_name,
34777 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34782 + * returns a negative dentry whose name is unique and temporary.
34784 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34785 + struct qstr *prefix)
34787 + struct dentry *dentry;
34789 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34791 + /* strict atomic_t is unnecessary here */
34792 + static unsigned short cnt;
34795 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34798 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34799 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34800 + dentry = ERR_PTR(-ENAMETOOLONG);
34801 + if (unlikely(qs.len > NAME_MAX))
34803 + dentry = ERR_PTR(-ENOMEM);
34804 + name = kmalloc(qs.len + 1, GFP_NOFS);
34805 + if (unlikely(!name))
34809 + /* doubly whiteout-ed */
34810 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34811 + p = name + AUFS_WH_PFX_LEN * 2;
34812 + memcpy(p, prefix->name, prefix->len);
34813 + p += prefix->len;
34815 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34818 + for (i = 0; i < 3; i++) {
34819 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34820 + dentry = au_sio_lkup_one(&qs, h_parent);
34821 + if (IS_ERR(dentry) || d_is_negative(dentry))
34825 + /* pr_warn("could not get random name\n"); */
34826 + dentry = ERR_PTR(-EEXIST);
34827 + AuDbg("%.*s\n", AuLNPair(&qs));
34831 + if (name != defname)
34832 + au_kfree_try_rcu(name);
34834 + AuTraceErrPtr(dentry);
34839 + * rename the @h_dentry on @br to the whiteouted temporary name.
34841 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34844 + struct path h_path = {
34845 + .mnt = au_br_mnt(br)
34847 + struct inode *h_dir, *delegated;
34848 + struct dentry *h_parent;
34850 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34851 + h_dir = d_inode(h_parent);
34852 + IMustLock(h_dir);
34854 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34855 + err = PTR_ERR(h_path.dentry);
34856 + if (IS_ERR(h_path.dentry))
34859 + /* under the same dir, no need to lock_rename() */
34860 + delegated = NULL;
34861 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34864 + if (unlikely(err == -EWOULDBLOCK)) {
34865 + pr_warn("cannot retry for NFSv4 delegation"
34866 + " for an internal rename\n");
34869 + dput(h_path.dentry);
34876 +/* ---------------------------------------------------------------------- */
34878 + * functions for removing a whiteout
34881 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34884 + struct inode *delegated;
34887 + * forces superio when the dir has a sticky bit.
34888 + * this may be a violation of unix fs semantics.
34890 + force = (h_dir->i_mode & S_ISVTX)
34891 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34892 + delegated = NULL;
34893 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34894 + if (unlikely(err == -EWOULDBLOCK)) {
34895 + pr_warn("cannot retry for NFSv4 delegation"
34896 + " for an internal unlink\n");
34902 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34903 + struct dentry *dentry)
34907 + err = do_unlink_wh(h_dir, h_path);
34908 + if (!err && dentry)
34909 + au_set_dbwh(dentry, -1);
34914 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34915 + struct au_branch *br)
34918 + struct path h_path = {
34919 + .mnt = au_br_mnt(br)
34923 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34924 + if (IS_ERR(h_path.dentry))
34925 + err = PTR_ERR(h_path.dentry);
34927 + if (d_is_reg(h_path.dentry))
34928 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34929 + dput(h_path.dentry);
34935 +/* ---------------------------------------------------------------------- */
34937 + * initialize/clean whiteout for a branch
34940 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34944 + struct inode *delegated;
34946 + if (d_is_negative(whpath->dentry))
34950 + err = vfsub_rmdir(h_dir, whpath);
34952 + delegated = NULL;
34953 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34954 + if (unlikely(err == -EWOULDBLOCK)) {
34955 + pr_warn("cannot retry for NFSv4 delegation"
34956 + " for an internal unlink\n");
34960 + if (unlikely(err))
34961 + pr_warn("failed removing %pd (%d), ignored.\n",
34962 + whpath->dentry, err);
34965 +static int test_linkable(struct dentry *h_root)
34967 + struct inode *h_dir = d_inode(h_root);
34969 + if (h_dir->i_op->link)
34972 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34973 + h_root, au_sbtype(h_root->d_sb));
34974 + return -ENOSYS; /* the branch doesn't have its ->link() */
34977 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34978 +static int au_whdir(struct inode *h_dir, struct path *path)
34983 + if (d_is_negative(path->dentry)) {
34986 + if (au_test_nfs(path->dentry->d_sb))
34988 + err = vfsub_mkdir(h_dir, path, mode);
34989 + } else if (d_is_dir(path->dentry))
34992 + pr_err("unknown %pd exists\n", path->dentry);
34997 +struct au_wh_base {
34998 + const struct qstr *name;
34999 + struct dentry *dentry;
35002 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35003 + struct path *h_path)
35005 + h_path->dentry = base[AuBrWh_BASE].dentry;
35006 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35007 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35008 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35009 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35010 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35014 + * returns tri-state,
35015 + * minus: error, caller should print the message
35017 + * plus: error, caller should NOT print the message
35019 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35020 + int do_plink, struct au_wh_base base[],
35021 + struct path *h_path)
35024 + struct inode *h_dir;
35026 + h_dir = d_inode(h_root);
35027 + h_path->dentry = base[AuBrWh_BASE].dentry;
35028 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35029 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35031 + err = test_linkable(h_root);
35032 + if (unlikely(err)) {
35037 + err = au_whdir(h_dir, h_path);
35038 + if (unlikely(err))
35040 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35042 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35043 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35044 + err = au_whdir(h_dir, h_path);
35045 + if (unlikely(err))
35047 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35054 + * for the moment, aufs supports the branch filesystem which does not support
35055 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35056 + * copyup failed. finally, such filesystem will not be used as the writable
35059 + * returns tri-state, see above.
35061 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35062 + int do_plink, struct au_wh_base base[],
35063 + struct path *h_path)
35066 + struct inode *h_dir;
35068 + WbrWhMustWriteLock(wbr);
35070 + err = test_linkable(h_root);
35071 + if (unlikely(err)) {
35077 + * todo: should this create be done in /sbin/mount.aufs helper?
35080 + h_dir = d_inode(h_root);
35081 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35082 + h_path->dentry = base[AuBrWh_BASE].dentry;
35083 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35084 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35087 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35088 + if (unlikely(err))
35091 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35093 + err = au_whdir(h_dir, h_path);
35094 + if (unlikely(err))
35096 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35098 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35099 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35101 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35102 + err = au_whdir(h_dir, h_path);
35103 + if (unlikely(err))
35105 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35112 + * initialize the whiteout base file/dir for @br.
35114 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35117 + const unsigned char do_plink
35118 + = !!au_opt_test(au_mntflags(sb), PLINK);
35119 + struct inode *h_dir;
35120 + struct path path = br->br_path;
35121 + struct dentry *h_root = path.dentry;
35122 + struct au_wbr *wbr = br->br_wbr;
35123 + static const struct qstr base_name[] = {
35124 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35125 + sizeof(AUFS_BASE_NAME) - 1),
35126 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35127 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35128 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35129 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35131 + struct au_wh_base base[] = {
35132 + [AuBrWh_BASE] = {
35133 + .name = base_name + AuBrWh_BASE,
35136 + [AuBrWh_PLINK] = {
35137 + .name = base_name + AuBrWh_PLINK,
35140 + [AuBrWh_ORPH] = {
35141 + .name = base_name + AuBrWh_ORPH,
35147 + WbrWhMustWriteLock(wbr);
35149 + for (i = 0; i < AuBrWh_Last; i++) {
35150 + /* doubly whiteouted */
35151 + struct dentry *d;
35153 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35154 + err = PTR_ERR(d);
35158 + base[i].dentry = d;
35160 + && wbr->wbr_wh[i]
35161 + && wbr->wbr_wh[i] != base[i].dentry);
35165 + for (i = 0; i < AuBrWh_Last; i++) {
35166 + dput(wbr->wbr_wh[i]);
35167 + wbr->wbr_wh[i] = NULL;
35171 + if (!au_br_writable(br->br_perm)) {
35172 + h_dir = d_inode(h_root);
35173 + au_wh_init_ro(h_dir, base, &path);
35174 + } else if (!au_br_wh_linkable(br->br_perm)) {
35175 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35181 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35187 + goto out; /* success */
35190 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35191 + err, h_root, au_sbtype(h_root->d_sb));
35193 + for (i = 0; i < AuBrWh_Last; i++)
35194 + dput(base[i].dentry);
35198 +/* ---------------------------------------------------------------------- */
35200 + * whiteouts are all hard-linked usually.
35201 + * when its link count reaches a ceiling, we create a new whiteout base
35202 + * asynchronously.
35205 +struct reinit_br_wh {
35206 + struct super_block *sb;
35207 + struct au_branch *br;
35210 +static void reinit_br_wh(void *arg)
35213 + aufs_bindex_t bindex;
35214 + struct path h_path;
35215 + struct reinit_br_wh *a = arg;
35216 + struct au_wbr *wbr;
35217 + struct inode *dir, *delegated;
35218 + struct dentry *h_root;
35219 + struct au_hinode *hdir;
35222 + wbr = a->br->br_wbr;
35223 + /* big aufs lock */
35224 + si_noflush_write_lock(a->sb);
35225 + if (!au_br_writable(a->br->br_perm))
35227 + bindex = au_br_index(a->sb, a->br->br_id);
35228 + if (unlikely(bindex < 0))
35231 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35232 + dir = d_inode(a->sb->s_root);
35233 + hdir = au_hi(dir, bindex);
35234 + h_root = au_h_dptr(a->sb->s_root, bindex);
35235 + AuDebugOn(h_root != au_br_dentry(a->br));
35237 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35238 + wbr_wh_write_lock(wbr);
35239 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35242 + h_path.dentry = wbr->wbr_whbase;
35243 + h_path.mnt = au_br_mnt(a->br);
35244 + delegated = NULL;
35245 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35247 + if (unlikely(err == -EWOULDBLOCK)) {
35248 + pr_warn("cannot retry for NFSv4 delegation"
35249 + " for an internal unlink\n");
35253 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35256 + dput(wbr->wbr_whbase);
35257 + wbr->wbr_whbase = NULL;
35259 + err = au_wh_init(a->br, a->sb);
35260 + wbr_wh_write_unlock(wbr);
35261 + au_hn_inode_unlock(hdir);
35262 + di_read_unlock(a->sb->s_root, AuLock_IR);
35264 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35268 + atomic_dec(&wbr->wbr_wh_running);
35269 + au_lcnt_dec(&a->br->br_count);
35270 + si_write_unlock(a->sb);
35271 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35273 + if (unlikely(err))
35274 + AuIOErr("err %d\n", err);
35277 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35279 + int do_dec, wkq_err;
35280 + struct reinit_br_wh *arg;
35283 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35286 + /* ignore ENOMEM */
35287 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35290 + * dec(wh_running), kfree(arg) and dec(br_count)
35291 + * in reinit function
35295 + au_lcnt_inc(&br->br_count);
35296 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35297 + if (unlikely(wkq_err)) {
35298 + atomic_dec(&br->br_wbr->wbr_wh_running);
35299 + au_lcnt_dec(&br->br_count);
35300 + au_kfree_rcu(arg);
35307 + atomic_dec(&br->br_wbr->wbr_wh_running);
35310 +/* ---------------------------------------------------------------------- */
35313 + * create the whiteout @wh.
35315 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35316 + struct dentry *wh)
35319 + struct path h_path = {
35322 + struct au_branch *br;
35323 + struct au_wbr *wbr;
35324 + struct dentry *h_parent;
35325 + struct inode *h_dir, *delegated;
35327 + h_parent = wh->d_parent; /* dir inode is locked */
35328 + h_dir = d_inode(h_parent);
35329 + IMustLock(h_dir);
35331 + br = au_sbr(sb, bindex);
35332 + h_path.mnt = au_br_mnt(br);
35333 + wbr = br->br_wbr;
35334 + wbr_wh_read_lock(wbr);
35335 + if (wbr->wbr_whbase) {
35336 + delegated = NULL;
35337 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35338 + if (unlikely(err == -EWOULDBLOCK)) {
35339 + pr_warn("cannot retry for NFSv4 delegation"
35340 + " for an internal link\n");
35343 + if (!err || err != -EMLINK)
35346 + /* link count full. re-initialize br_whbase. */
35347 + kick_reinit_br_wh(sb, br);
35350 + /* return this error in this context */
35351 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35353 + au_fhsm_wrote(sb, bindex, /*force*/0);
35356 + wbr_wh_read_unlock(wbr);
35360 +/* ---------------------------------------------------------------------- */
35363 + * create or remove the diropq.
35365 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35366 + unsigned int flags)
35368 + struct dentry *opq_dentry, *h_dentry;
35369 + struct super_block *sb;
35370 + struct au_branch *br;
35373 + sb = dentry->d_sb;
35374 + br = au_sbr(sb, bindex);
35375 + h_dentry = au_h_dptr(dentry, bindex);
35376 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35377 + if (IS_ERR(opq_dentry))
35380 + if (au_ftest_diropq(flags, CREATE)) {
35381 + err = link_or_create_wh(sb, bindex, opq_dentry);
35383 + au_set_dbdiropq(dentry, bindex);
35384 + goto out; /* success */
35387 + struct path tmp = {
35388 + .dentry = opq_dentry,
35389 + .mnt = au_br_mnt(br)
35391 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35393 + au_set_dbdiropq(dentry, -1);
35395 + dput(opq_dentry);
35396 + opq_dentry = ERR_PTR(err);
35399 + return opq_dentry;
35402 +struct do_diropq_args {
35403 + struct dentry **errp;
35404 + struct dentry *dentry;
35405 + aufs_bindex_t bindex;
35406 + unsigned int flags;
35409 +static void call_do_diropq(void *args)
35411 + struct do_diropq_args *a = args;
35412 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35415 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35416 + unsigned int flags)
35418 + struct dentry *diropq, *h_dentry;
35420 + h_dentry = au_h_dptr(dentry, bindex);
35421 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35422 + diropq = do_diropq(dentry, bindex, flags);
35425 + struct do_diropq_args args = {
35427 + .dentry = dentry,
35428 + .bindex = bindex,
35432 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35433 + if (unlikely(wkq_err))
35434 + diropq = ERR_PTR(wkq_err);
35440 +/* ---------------------------------------------------------------------- */
35443 + * lookup whiteout dentry.
35444 + * @h_parent: lower parent dentry which must exist and be locked
35445 + * @base_name: name of dentry which will be whiteouted
35446 + * returns dentry for whiteout.
35448 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35449 + struct au_branch *br)
35452 + struct qstr wh_name;
35453 + struct dentry *wh_dentry;
35455 + err = au_wh_name_alloc(&wh_name, base_name);
35456 + wh_dentry = ERR_PTR(err);
35458 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35459 + au_kfree_try_rcu(wh_name.name);
35461 + return wh_dentry;
35465 + * link/create a whiteout for @dentry on @bindex.
35467 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35468 + struct dentry *h_parent)
35470 + struct dentry *wh_dentry;
35471 + struct super_block *sb;
35474 + sb = dentry->d_sb;
35475 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35476 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35477 + err = link_or_create_wh(sb, bindex, wh_dentry);
35479 + au_set_dbwh(dentry, bindex);
35480 + au_fhsm_wrote(sb, bindex, /*force*/0);
35483 + wh_dentry = ERR_PTR(err);
35487 + return wh_dentry;
35490 +/* ---------------------------------------------------------------------- */
35492 +/* Delete all whiteouts in this directory on branch bindex. */
35493 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35494 + aufs_bindex_t bindex, struct au_branch *br)
35497 + unsigned long ul, n;
35498 + struct qstr wh_name;
35500 + struct hlist_head *head;
35501 + struct au_vdir_wh *pos;
35502 + struct au_vdir_destr *str;
35505 + p = (void *)__get_free_page(GFP_NOFS);
35506 + wh_name.name = p;
35507 + if (unlikely(!wh_name.name))
35511 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35512 + p += AUFS_WH_PFX_LEN;
35513 + n = whlist->nh_num;
35514 + head = whlist->nh_head;
35515 + for (ul = 0; !err && ul < n; ul++, head++) {
35516 + hlist_for_each_entry(pos, head, wh_hash) {
35517 + if (pos->wh_bindex != bindex)
35520 + str = &pos->wh_str;
35521 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35522 + memcpy(p, str->name, str->len);
35523 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35524 + err = unlink_wh_name(h_dentry, &wh_name, br);
35529 + AuIOErr("whiteout name too long %.*s\n",
35530 + str->len, str->name);
35535 + free_page((unsigned long)wh_name.name);
35541 +struct del_wh_children_args {
35543 + struct dentry *h_dentry;
35544 + struct au_nhash *whlist;
35545 + aufs_bindex_t bindex;
35546 + struct au_branch *br;
35549 +static void call_del_wh_children(void *args)
35551 + struct del_wh_children_args *a = args;
35552 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35555 +/* ---------------------------------------------------------------------- */
35557 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35559 + struct au_whtmp_rmdir *whtmp;
35561 + unsigned int rdhash;
35563 + SiMustAnyLock(sb);
35565 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35566 + if (unlikely(!whtmp)) {
35567 + whtmp = ERR_PTR(-ENOMEM);
35571 + /* no estimation for dir size */
35572 + rdhash = au_sbi(sb)->si_rdhash;
35574 + rdhash = AUFS_RDHASH_DEF;
35575 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35576 + if (unlikely(err)) {
35577 + au_kfree_rcu(whtmp);
35578 + whtmp = ERR_PTR(err);
35585 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35588 + au_lcnt_dec(&whtmp->br->br_count);
35589 + dput(whtmp->wh_dentry);
35590 + iput(whtmp->dir);
35591 + au_nhash_wh_free(&whtmp->whlist);
35592 + au_kfree_rcu(whtmp);
35596 + * rmdir the whiteouted temporary named dir @h_dentry.
35597 + * @whlist: whiteouted children.
35599 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35600 + struct dentry *wh_dentry, struct au_nhash *whlist)
35603 + unsigned int h_nlink;
35604 + struct path h_tmp;
35605 + struct inode *wh_inode, *h_dir;
35606 + struct au_branch *br;
35608 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35609 + IMustLock(h_dir);
35611 + br = au_sbr(dir->i_sb, bindex);
35612 + wh_inode = d_inode(wh_dentry);
35613 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35616 + * someone else might change some whiteouts while we were sleeping.
35617 + * it means this whlist may have an obsoleted entry.
35619 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35620 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35623 + struct del_wh_children_args args = {
35625 + .h_dentry = wh_dentry,
35626 + .whlist = whlist,
35627 + .bindex = bindex,
35631 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35632 + if (unlikely(wkq_err))
35635 + inode_unlock(wh_inode);
35638 + h_tmp.dentry = wh_dentry;
35639 + h_tmp.mnt = au_br_mnt(br);
35640 + h_nlink = h_dir->i_nlink;
35641 + err = vfsub_rmdir(h_dir, &h_tmp);
35642 + /* some fs doesn't change the parent nlink in some cases */
35643 + h_nlink -= h_dir->i_nlink;
35647 + if (au_ibtop(dir) == bindex) {
35648 + /* todo: dir->i_mutex is necessary */
35649 + au_cpup_attr_timesizes(dir);
35651 + vfsub_drop_nlink(dir);
35653 + return 0; /* success */
35656 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35660 +static void call_rmdir_whtmp(void *args)
35663 + aufs_bindex_t bindex;
35664 + struct au_whtmp_rmdir *a = args;
35665 + struct super_block *sb;
35666 + struct dentry *h_parent;
35667 + struct inode *h_dir;
35668 + struct au_hinode *hdir;
35670 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35671 + /* inode_lock(a->dir); */
35673 + sb = a->dir->i_sb;
35674 + si_read_lock(sb, !AuLock_FLUSH);
35675 + if (!au_br_writable(a->br->br_perm))
35677 + bindex = au_br_index(sb, a->br->br_id);
35678 + if (unlikely(bindex < 0))
35682 + ii_write_lock_parent(a->dir);
35683 + h_parent = dget_parent(a->wh_dentry);
35684 + h_dir = d_inode(h_parent);
35685 + hdir = au_hi(a->dir, bindex);
35686 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35687 + if (unlikely(err))
35689 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35690 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35693 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35694 + au_hn_inode_unlock(hdir);
35695 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35699 + ii_write_unlock(a->dir);
35701 + /* inode_unlock(a->dir); */
35702 + au_whtmp_rmdir_free(a);
35703 + si_read_unlock(sb);
35704 + au_nwt_done(&au_sbi(sb)->si_nowait);
35705 + if (unlikely(err))
35706 + AuIOErr("err %d\n", err);
35709 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35710 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35713 + struct super_block *sb;
35717 + /* all post-process will be done in do_rmdir_whtmp(). */
35719 + args->dir = au_igrab(dir);
35720 + args->br = au_sbr(sb, bindex);
35721 + au_lcnt_inc(&args->br->br_count);
35722 + args->wh_dentry = dget(wh_dentry);
35723 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35724 + if (unlikely(wkq_err)) {
35725 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35726 + au_whtmp_rmdir_free(args);
35729 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35730 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35731 +++ linux/fs/aufs/whout.h 2021-02-24 13:33:42.751013936 +0100
35733 +/* SPDX-License-Identifier: GPL-2.0 */
35735 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35737 + * This program, aufs is free software; you can redistribute it and/or modify
35738 + * it under the terms of the GNU General Public License as published by
35739 + * the Free Software Foundation; either version 2 of the License, or
35740 + * (at your option) any later version.
35742 + * This program is distributed in the hope that it will be useful,
35743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35745 + * GNU General Public License for more details.
35747 + * You should have received a copy of the GNU General Public License
35748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35752 + * whiteout for logical deletion and opaque directory
35755 +#ifndef __AUFS_WHOUT_H__
35756 +#define __AUFS_WHOUT_H__
35763 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35764 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35765 +int au_diropq_test(struct dentry *h_dentry);
35767 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35768 + struct qstr *prefix);
35769 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35770 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35771 + struct dentry *dentry);
35772 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35774 +/* diropq flags */
35775 +#define AuDiropq_CREATE 1
35776 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35777 +#define au_fset_diropq(flags, name) \
35778 + do { (flags) |= AuDiropq_##name; } while (0)
35779 +#define au_fclr_diropq(flags, name) \
35780 + do { (flags) &= ~AuDiropq_##name; } while (0)
35782 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35783 + unsigned int flags);
35784 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35785 + struct au_branch *br);
35786 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35787 + struct dentry *h_parent);
35789 +/* real rmdir for the whiteout-ed dir */
35790 +struct au_whtmp_rmdir {
35791 + struct inode *dir;
35792 + struct au_branch *br;
35793 + struct dentry *wh_dentry;
35794 + struct au_nhash whlist;
35797 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35798 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35799 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35800 + struct dentry *wh_dentry, struct au_nhash *whlist);
35801 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35802 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35804 +/* ---------------------------------------------------------------------- */
35806 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35807 + aufs_bindex_t bindex)
35809 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35812 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35814 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35817 +#endif /* __KERNEL__ */
35818 +#endif /* __AUFS_WHOUT_H__ */
35819 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35820 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35821 +++ linux/fs/aufs/wkq.c 2021-02-24 13:33:42.751013936 +0100
35823 +// SPDX-License-Identifier: GPL-2.0
35825 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35827 + * This program, aufs is free software; you can redistribute it and/or modify
35828 + * it under the terms of the GNU General Public License as published by
35829 + * the Free Software Foundation; either version 2 of the License, or
35830 + * (at your option) any later version.
35832 + * This program is distributed in the hope that it will be useful,
35833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35835 + * GNU General Public License for more details.
35837 + * You should have received a copy of the GNU General Public License
35838 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35842 + * workqueue for asynchronous/super-io operations
35843 + * todo: try new credential scheme
35846 +#include <linux/module.h>
35849 +/* internal workqueue named AUFS_WKQ_NAME */
35851 +static struct workqueue_struct *au_wkq;
35853 +struct au_wkinfo {
35854 + struct work_struct wk;
35855 + struct kobject *kobj;
35857 + unsigned int flags; /* see wkq.h */
35859 + au_wkq_func_t func;
35862 +#ifdef CONFIG_LOCKDEP
35864 + struct held_lock **hlock;
35867 + struct completion *comp;
35870 +/* ---------------------------------------------------------------------- */
35872 + * Aufs passes some operations to the workqueue such as the internal copyup.
35873 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35874 + * job run by workqueue depends upon the locks acquired in the other task.
35875 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35876 + * information too. And the job in the workqueue restores the info in order to
35877 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35878 + * correctly and expectedly.
35881 +#ifndef CONFIG_LOCKDEP
35882 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35883 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35884 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35885 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35886 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35888 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35890 + wkinfo->hlock = NULL;
35891 + wkinfo->dont_check = 0;
35898 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35900 + static DEFINE_SPINLOCK(spin);
35903 + struct lock_class_key *key;
35905 + { .name = "&sbinfo->si_rwsem" },
35906 + { .name = "&finfo->fi_rwsem" },
35907 + { .name = "&dinfo->di_rwsem" },
35908 + { .name = "&iinfo->ii_rwsem" }
35913 + /* lockless read from 'set.' see below */
35914 + if (set == ARRAY_SIZE(a)) {
35915 + for (i = 0; i < ARRAY_SIZE(a); i++)
35916 + if (a[i].key == key)
35921 + spin_lock(&spin);
35923 + for (i = 0; i < ARRAY_SIZE(a); i++)
35924 + if (a[i].key == key) {
35925 + spin_unlock(&spin);
35928 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35930 + if (unlikely(a[i].key == key)) { /* rare but possible */
35931 + spin_unlock(&spin);
35936 + if (strstr(a[i].name, name)) {
35938 + * the order of these three lines is important for the
35939 + * lockless read above.
35942 + spin_unlock(&spin);
35944 + /* AuDbg("%d, %s\n", set, name); */
35948 + spin_unlock(&spin);
35957 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35960 + struct task_struct *curr;
35961 + struct held_lock **hl, *held_locks, *p;
35965 + wkinfo->dont_check = lockdep_recursing(curr);
35966 + if (wkinfo->dont_check)
35968 + n = curr->lockdep_depth;
35973 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35974 + if (unlikely(!wkinfo->hlock))
35978 +#if 0 /* left for debugging */
35979 + if (0 && au_debug_test())
35980 + lockdep_print_held_locks(curr);
35982 + held_locks = curr->held_locks;
35983 + hl = wkinfo->hlock;
35985 + p = held_locks++;
35986 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35995 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35997 + au_kfree_try_rcu(wkinfo->hlock);
36000 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36002 + struct held_lock *p, **hl = wkinfo->hlock;
36005 + if (wkinfo->dont_check)
36009 + while ((p = *hl++)) { /* assignment */
36010 + subclass = lockdep_hlock_class(p)->subclass;
36011 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36013 + rwsem_acquire_read(p->instance, subclass, 0,
36014 + /*p->acquire_ip*/_RET_IP_);
36016 + rwsem_acquire(p->instance, subclass, 0,
36017 + /*p->acquire_ip*/_RET_IP_);
36021 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36023 + struct held_lock *p, **hl = wkinfo->hlock;
36025 + if (wkinfo->dont_check)
36029 + while ((p = *hl++)) /* assignment */
36030 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36034 +static void wkq_func(struct work_struct *wk)
36036 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36038 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36039 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36041 + au_wkq_lockdep_pre(wkinfo);
36042 + wkinfo->func(wkinfo->args);
36043 + au_wkq_lockdep_post(wkinfo);
36044 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36045 + complete(wkinfo->comp);
36047 + kobject_put(wkinfo->kobj);
36048 + module_put(THIS_MODULE); /* todo: ?? */
36049 + au_kfree_rcu(wkinfo);
36054 + * Since struct completion is large, try allocating it dynamically.
36056 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36058 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36060 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36062 + init_completion(*comp);
36063 + wkinfo->comp = *comp;
36069 +static void au_wkq_comp_free(struct completion *comp)
36071 + au_kfree_rcu(comp);
36074 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36076 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36077 + if (au_wkq_test()) {
36078 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36079 + " due to a dead dir by UDBA,"
36080 + " or async xino write?\n");
36081 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36084 + au_dbg_verify_kthread();
36086 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36087 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36088 + queue_work(au_wkq, &wkinfo->wk);
36090 + INIT_WORK(&wkinfo->wk, wkq_func);
36091 + schedule_work(&wkinfo->wk);
36096 + * Be careful. It is easy to make deadlock happen.
36097 + * processA: lock, wkq and wait
36098 + * processB: wkq and wait, lock in wkq
36101 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36104 + AuWkqCompDeclare(comp);
36105 + struct au_wkinfo wkinfo = {
36111 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36112 + if (unlikely(err))
36114 + err = au_wkq_lockdep_alloc(&wkinfo);
36115 + if (unlikely(err))
36118 + au_wkq_run(&wkinfo);
36119 + /* no timeout, no interrupt */
36120 + wait_for_completion(wkinfo.comp);
36122 + au_wkq_lockdep_free(&wkinfo);
36125 + au_wkq_comp_free(comp);
36127 + destroy_work_on_stack(&wkinfo.wk);
36132 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36133 + * problem in a concurrent umounting.
36135 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36136 + unsigned int flags)
36139 + struct au_wkinfo *wkinfo;
36141 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36144 + * wkq_func() must free this wkinfo.
36145 + * it highly depends upon the implementation of workqueue.
36148 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36150 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36151 + wkinfo->flags = flags & ~AuWkq_WAIT;
36152 + wkinfo->func = func;
36153 + wkinfo->args = args;
36154 + wkinfo->comp = NULL;
36155 + au_wkq_lockdep_init(wkinfo);
36156 + kobject_get(wkinfo->kobj);
36157 + __module_get(THIS_MODULE); /* todo: ?? */
36159 + au_wkq_run(wkinfo);
36162 + au_nwt_done(&au_sbi(sb)->si_nowait);
36168 +/* ---------------------------------------------------------------------- */
36170 +void au_nwt_init(struct au_nowait_tasks *nwt)
36172 + atomic_set(&nwt->nw_len, 0);
36173 + /* smp_mb(); */ /* atomic_set */
36174 + init_waitqueue_head(&nwt->nw_wq);
36177 +void au_wkq_fin(void)
36179 + destroy_workqueue(au_wkq);
36182 +int __init au_wkq_init(void)
36187 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36188 + if (IS_ERR(au_wkq))
36189 + err = PTR_ERR(au_wkq);
36190 + else if (!au_wkq)
36195 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36196 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36197 +++ linux/fs/aufs/wkq.h 2021-02-24 13:33:42.751013936 +0100
36199 +/* SPDX-License-Identifier: GPL-2.0 */
36201 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36203 + * This program, aufs is free software; you can redistribute it and/or modify
36204 + * it under the terms of the GNU General Public License as published by
36205 + * the Free Software Foundation; either version 2 of the License, or
36206 + * (at your option) any later version.
36208 + * This program is distributed in the hope that it will be useful,
36209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36211 + * GNU General Public License for more details.
36213 + * You should have received a copy of the GNU General Public License
36214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36218 + * workqueue for asynchronous/super-io operations
36219 + * todo: try new credentials management scheme
36222 +#ifndef __AUFS_WKQ_H__
36223 +#define __AUFS_WKQ_H__
36227 +#include <linux/wait.h>
36229 +struct super_block;
36231 +/* ---------------------------------------------------------------------- */
36234 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36236 +struct au_nowait_tasks {
36238 + wait_queue_head_t nw_wq;
36241 +/* ---------------------------------------------------------------------- */
36243 +typedef void (*au_wkq_func_t)(void *args);
36246 +#define AuWkq_WAIT 1
36247 +#define AuWkq_NEST (1 << 1)
36248 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36249 +#define au_fset_wkq(flags, name) \
36250 + do { (flags) |= AuWkq_##name; } while (0)
36251 +#define au_fclr_wkq(flags, name) \
36252 + do { (flags) &= ~AuWkq_##name; } while (0)
36255 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36256 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36257 + unsigned int flags);
36258 +void au_nwt_init(struct au_nowait_tasks *nwt);
36259 +int __init au_wkq_init(void);
36260 +void au_wkq_fin(void);
36262 +/* ---------------------------------------------------------------------- */
36264 +static inline int au_wkq_test(void)
36266 + return current->flags & PF_WQ_WORKER;
36269 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36271 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36274 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36276 + if (atomic_dec_and_test(&nwt->nw_len))
36277 + wake_up_all(&nwt->nw_wq);
36280 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36282 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36286 +#endif /* __KERNEL__ */
36287 +#endif /* __AUFS_WKQ_H__ */
36288 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36289 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36290 +++ linux/fs/aufs/xattr.c 2021-02-24 13:33:42.751013936 +0100
36292 +// SPDX-License-Identifier: GPL-2.0
36294 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36296 + * This program, aufs is free software; you can redistribute it and/or modify
36297 + * it under the terms of the GNU General Public License as published by
36298 + * the Free Software Foundation; either version 2 of the License, or
36299 + * (at your option) any later version.
36301 + * This program is distributed in the hope that it will be useful,
36302 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36303 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36304 + * GNU General Public License for more details.
36306 + * You should have received a copy of the GNU General Public License
36307 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36311 + * handling xattr functions
36314 +#include <linux/fs.h>
36315 +#include <linux/posix_acl_xattr.h>
36316 +#include <linux/xattr.h>
36319 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36321 + if (!ignore_flags)
36329 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36334 +#define cmp(brattr, prefix) do { \
36335 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36336 + XATTR_##prefix##_PREFIX_LEN)) { \
36337 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36343 + cmp(SEC, SECURITY);
36344 + cmp(SYS, SYSTEM);
36345 + cmp(TR, TRUSTED);
36349 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36356 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36358 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36359 + char *name, char **buf, unsigned int ignore_flags,
36360 + unsigned int verbose)
36364 + struct inode *h_idst;
36366 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36368 + if (unlikely(err <= 0)) {
36369 + if (err == -ENODATA
36370 + || (err == -EOPNOTSUPP
36371 + && ((ignore_flags & au_xattr_out_of_list)
36372 + || (au_test_nfs_noacl(d_inode(h_src))
36373 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36375 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36378 + if (err && (verbose || au_debug_test()))
36379 + pr_err("%s, err %d\n", name, err);
36383 + /* unlock it temporary */
36384 + h_idst = d_inode(h_dst);
36385 + inode_unlock(h_idst);
36386 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36387 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36388 + if (unlikely(err)) {
36389 + if (verbose || au_debug_test())
36390 + pr_err("%s, err %d\n", name, err);
36391 + err = au_xattr_ignore(err, name, ignore_flags);
36398 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36399 + unsigned int verbose)
36401 + int err, unlocked, acl_access, acl_default;
36403 + struct inode *h_isrc, *h_idst;
36404 + char *value, *p, *o, *e;
36406 + /* try stopping to update the source inode while we are referencing */
36407 + /* there should not be the parent-child relationship between them */
36408 + h_isrc = d_inode(h_src);
36409 + h_idst = d_inode(h_dst);
36410 + inode_unlock(h_idst);
36411 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36412 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36415 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36416 + ssz = vfs_listxattr(h_src, NULL, 0);
36418 + if (unlikely(err < 0)) {
36420 + if (err == -ENODATA
36421 + || err == -EOPNOTSUPP)
36422 + err = 0; /* ignore */
36431 + p = kmalloc(ssz, GFP_NOFS);
36433 + if (unlikely(!p))
36435 + err = vfs_listxattr(h_src, p, ssz);
36437 + inode_unlock_shared(h_isrc);
36439 + AuDbg("err %d, ssz %zd\n", err, ssz);
36440 + if (unlikely(err < 0))
36448 + while (!err && p < e) {
36449 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36450 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36451 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36452 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36454 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36456 + p += strlen(p) + 1;
36459 + ignore_flags |= au_xattr_out_of_list;
36460 + if (!err && !acl_access) {
36461 + err = au_do_cpup_xattr(h_dst, h_src,
36462 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36463 + ignore_flags, verbose);
36466 + if (!err && !acl_default) {
36467 + err = au_do_cpup_xattr(h_dst, h_src,
36468 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36469 + ignore_flags, verbose);
36473 + au_kfree_try_rcu(value);
36476 + au_kfree_try_rcu(o);
36479 + inode_unlock_shared(h_isrc);
36484 +/* ---------------------------------------------------------------------- */
36486 +static int au_smack_reentering(struct super_block *sb)
36488 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36490 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36491 + * i_op->getxattr(). ouch.
36493 + return si_pid_test(sb);
36504 +struct au_lgxattr {
36512 + const char *name;
36519 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36520 + struct au_lgxattr *arg)
36524 + struct path h_path;
36525 + struct super_block *sb;
36527 + sb = dentry->d_sb;
36528 + reenter = au_smack_reentering(sb);
36530 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36531 + if (unlikely(err))
36534 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36535 + if (unlikely(err))
36537 + if (unlikely(!h_path.dentry))
36538 + /* illegally overlapped or something */
36539 + goto out_di; /* pretending success */
36541 + /* always topmost entry only */
36542 + switch (arg->type) {
36543 + case AU_XATTR_LIST:
36544 + err = vfs_listxattr(h_path.dentry,
36545 + arg->u.list.list, arg->u.list.size);
36547 + case AU_XATTR_GET:
36548 + AuDebugOn(d_is_negative(h_path.dentry));
36549 + err = vfs_getxattr(h_path.dentry,
36550 + arg->u.get.name, arg->u.get.value,
36551 + arg->u.get.size);
36557 + di_read_unlock(dentry, AuLock_IR);
36560 + si_read_unlock(sb);
36566 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36568 + struct au_lgxattr arg = {
36569 + .type = AU_XATTR_LIST,
36576 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36579 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36580 + const char *name, void *value, size_t size)
36582 + struct au_lgxattr arg = {
36583 + .type = AU_XATTR_GET,
36591 + return au_lgxattr(dentry, inode, &arg);
36594 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36595 + const char *name, const void *value, size_t size,
36598 + struct au_sxattr arg = {
36599 + .type = AU_XATTR_SET,
36608 + return au_sxattr(dentry, inode, &arg);
36611 +/* ---------------------------------------------------------------------- */
36613 +static int au_xattr_get(const struct xattr_handler *handler,
36614 + struct dentry *dentry, struct inode *inode,
36615 + const char *name, void *buffer, size_t size)
36617 + return au_getxattr(dentry, inode, name, buffer, size);
36620 +static int au_xattr_set(const struct xattr_handler *handler,
36621 + struct dentry *dentry, struct inode *inode,
36622 + const char *name, const void *value, size_t size,
36625 + return au_setxattr(dentry, inode, name, value, size, flags);
36628 +static const struct xattr_handler au_xattr_handler = {
36631 + .get = au_xattr_get,
36632 + .set = au_xattr_set
36635 +static const struct xattr_handler *au_xattr_handlers[] = {
36636 +#ifdef CONFIG_FS_POSIX_ACL
36637 + &posix_acl_access_xattr_handler,
36638 + &posix_acl_default_xattr_handler,
36640 + &au_xattr_handler, /* must be last */
36644 +void au_xattr_init(struct super_block *sb)
36646 + sb->s_xattr = au_xattr_handlers;
36648 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36649 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36650 +++ linux/fs/aufs/xino.c 2021-02-24 13:33:42.751013936 +0100
36652 +// SPDX-License-Identifier: GPL-2.0
36654 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36656 + * This program, aufs is free software; you can redistribute it and/or modify
36657 + * it under the terms of the GNU General Public License as published by
36658 + * the Free Software Foundation; either version 2 of the License, or
36659 + * (at your option) any later version.
36661 + * This program is distributed in the hope that it will be useful,
36662 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36663 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36664 + * GNU General Public License for more details.
36666 + * You should have received a copy of the GNU General Public License
36667 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36671 + * external inode number translation table and bitmap
36673 + * things to consider
36675 + * + au_xino object
36676 + * + XINO files (xino, xib, xigen)
36677 + * + dynamic debugfs entries (xiN)
36678 + * + static debugfs entries (xib, xigen)
36679 + * + static sysfs entry (xi_path)
36680 + * - several entry points to handle them.
36681 + * + mount(2) without xino option (default)
36682 + * + mount(2) with xino option
36683 + * + mount(2) with noxino option
36685 + * + remount with add/del branches
36686 + * + remount with xino/noxino options
36689 +#include <linux/seq_file.h>
36690 +#include <linux/statfs.h>
36693 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36694 + aufs_bindex_t bbot,
36695 + struct super_block *h_sb)
36697 + /* todo: try binary-search if the branches are many */
36698 + for (; btop <= bbot; btop++)
36699 + if (h_sb == au_sbr_sb(sb, btop))
36705 + * find another branch who is on the same filesystem of the specified
36706 + * branch{@btgt}. search until @bbot.
36708 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36709 + aufs_bindex_t bbot)
36711 + aufs_bindex_t bindex;
36712 + struct super_block *tgt_sb;
36714 + tgt_sb = au_sbr_sb(sb, btgt);
36715 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36717 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36722 +/* ---------------------------------------------------------------------- */
36725 + * stop unnecessary notify events at creating xino files
36728 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36730 + aufs_bindex_t bfound, bindex, bbot;
36731 + struct dentry *parent;
36732 + struct au_branch *br;
36735 + parent = dentry->d_parent; /* safe d_parent access */
36736 + bbot = au_sbbot(sb);
36737 + for (bindex = 0; bindex <= bbot; bindex++) {
36738 + br = au_sbr(sb, bindex);
36739 + if (au_br_dentry(br) == parent) {
36745 + AuDbg("bfound b%d\n", bfound);
36749 +struct au_xino_lock_dir {
36750 + struct au_hinode *hdir;
36751 + struct dentry *parent;
36752 + struct inode *dir;
36755 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36756 + unsigned int lsc)
36758 + struct dentry *parent;
36759 + struct inode *dir;
36761 + parent = dget_parent(dentry);
36762 + dir = d_inode(parent);
36763 + inode_lock_nested(dir, lsc);
36764 +#if 0 /* it should not happen */
36765 + spin_lock(&dentry->d_lock);
36766 + if (unlikely(dentry->d_parent != parent)) {
36767 + spin_unlock(&dentry->d_lock);
36768 + inode_unlock(dir);
36773 + spin_unlock(&dentry->d_lock);
36780 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36781 + struct au_xino_lock_dir *ldir)
36783 + aufs_bindex_t bindex;
36785 + ldir->hdir = NULL;
36786 + bindex = au_xi_root(sb, xipath->dentry);
36787 + if (bindex >= 0) {
36788 + /* rw branch root */
36789 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36790 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36793 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36795 + ldir->dir = d_inode(ldir->parent);
36799 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36802 + au_hn_inode_unlock(ldir->hdir);
36804 + inode_unlock(ldir->dir);
36805 + dput(ldir->parent);
36809 +/* ---------------------------------------------------------------------- */
36812 + * create and set a new xino file
36814 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36817 + struct file *file;
36818 + struct dentry *h_parent, *d;
36819 + struct inode *h_dir, *inode;
36821 + static DEFINE_MUTEX(mtx);
36824 + * at mount-time, and the xino file is the default path,
36825 + * hnotify is disabled so we have no notify events to ignore.
36826 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36829 + mutex_lock(&mtx);
36830 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36831 + /* | __FMODE_NONOTIFY */,
36833 + if (IS_ERR(file)) {
36835 + mutex_unlock(&mtx);
36837 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36841 + /* keep file count */
36843 + d = file->f_path.dentry;
36844 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36846 + mutex_unlock(&mtx);
36847 + /* mnt_want_write() is unnecessary here */
36848 + h_dir = d_inode(h_parent);
36849 + inode = file_inode(file);
36850 + /* no delegation since it is just created */
36851 + if (inode->i_nlink)
36852 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36854 + inode_unlock(h_dir);
36856 + if (unlikely(err)) {
36858 + pr_err("unlink %s(%d)\n", fpath, err);
36863 + if (unlikely(sb == d->d_sb)) {
36865 + pr_err("%s must be outside\n", fpath);
36868 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36870 + pr_err("xino doesn't support %s(%s)\n",
36871 + fpath, au_sbtype(d->d_sb));
36874 + return file; /* success */
36878 + file = ERR_PTR(err);
36883 + * create a new xinofile at the same place/path as @base.
36885 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36886 + struct file *copy_src)
36888 + struct file *file;
36889 + struct dentry *dentry, *parent;
36890 + struct inode *dir, *delegated;
36891 + struct qstr *name;
36892 + struct path path;
36893 + int err, do_unlock;
36894 + struct au_xino_lock_dir ldir;
36897 + au_xino_lock_dir(sb, base, &ldir);
36898 + dentry = base->dentry;
36899 + parent = dentry->d_parent; /* dir inode is locked */
36900 + dir = d_inode(parent);
36903 + name = &dentry->d_name;
36904 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36905 + if (IS_ERR(path.dentry)) {
36906 + file = (void *)path.dentry;
36907 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36911 + /* no need to mnt_want_write() since we call dentry_open() later */
36912 + err = vfs_create(dir, path.dentry, 0666, NULL);
36913 + if (unlikely(err)) {
36914 + file = ERR_PTR(err);
36915 + pr_err("%pd create err %d\n", dentry, err);
36919 + path.mnt = base->mnt;
36920 + file = vfsub_dentry_open(&path,
36921 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36922 + /* | __FMODE_NONOTIFY */);
36923 + if (IS_ERR(file)) {
36924 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36928 + delegated = NULL;
36929 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36930 + au_xino_unlock_dir(&ldir);
36932 + if (unlikely(err == -EWOULDBLOCK)) {
36933 + pr_warn("cannot retry for NFSv4 delegation"
36934 + " for an internal unlink\n");
36937 + if (unlikely(err)) {
36938 + pr_err("%pd unlink err %d\n", dentry, err);
36943 + /* no one can touch copy_src xino */
36944 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36945 + if (unlikely(err)) {
36946 + pr_err("%pd copy err %d\n", dentry, err);
36950 + goto out_dput; /* success */
36954 + file = ERR_PTR(err);
36956 + dput(path.dentry);
36959 + au_xino_unlock_dir(&ldir);
36963 +struct file *au_xino_file1(struct au_xino *xi)
36965 + struct file *file;
36966 + unsigned int u, nfile;
36969 + nfile = xi->xi_nfile;
36970 + for (u = 0; u < nfile; u++) {
36971 + file = xi->xi_file[u];
36979 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
36990 + if (idx < xi->xi_nfile) {
36991 + f = xi->xi_file[idx];
36995 + p = au_kzrealloc(xi->xi_file,
36996 + sizeof(*xi->xi_file) * xi->xi_nfile,
36997 + sizeof(*xi->xi_file) * (idx + 1),
36998 + GFP_NOFS, /*may_shrink*/0);
37000 + MtxMustLock(&xi->xi_mtx);
37002 + xi->xi_nfile = idx + 1;
37010 + xi->xi_file[idx] = file;
37017 + * if @xinew->xi is not set, then create new xigen file.
37019 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37021 + struct file *file;
37024 + SiMustAnyLock(sb);
37026 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37027 + if (IS_ERR(file)) {
37028 + err = PTR_ERR(file);
37029 + pr_err("%s[%d], err %d\n",
37030 + xinew->xi ? "xino" : "xigen",
37031 + xinew->idx, err);
37036 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37039 + /* todo: make xigen file an array */
37040 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37043 + if (unlikely(err))
37044 + file = ERR_PTR(err);
37050 +/* ---------------------------------------------------------------------- */
37053 + * truncate xino files
37055 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37056 + int idx, struct kstatfs *st)
37060 + struct file *file, *new_xino;
37061 + struct au_xi_new xinew = {
37066 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37067 + file = au_xino_file(xinew.xi, idx);
37071 + xinew.base = &file->f_path;
37072 + err = vfs_statfs(xinew.base, st);
37073 + if (unlikely(err)) {
37074 + AuErr1("statfs err %d, ignored\n", err);
37079 + blocks = file_inode(file)->i_blocks;
37080 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37081 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37083 + xinew.copy_src = file;
37084 + new_xino = au_xi_new(sb, &xinew);
37085 + if (IS_ERR(new_xino)) {
37086 + err = PTR_ERR(new_xino);
37087 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37091 + err = vfs_statfs(&new_xino->f_path, st);
37093 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37094 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37095 + st->f_bfree, st->f_blocks);
37097 + AuErr1("statfs err %d, ignored\n", err);
37105 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37108 + unsigned long jiffy;
37109 + aufs_bindex_t bbot;
37110 + struct kstatfs *st;
37111 + struct au_branch *br;
37112 + struct au_xino *xi;
37115 + st = kmalloc(sizeof(*st), GFP_NOFS);
37116 + if (unlikely(!st))
37120 + bbot = au_sbbot(sb);
37121 + if (unlikely(bindex < 0 || bbot < bindex))
37126 + br = au_sbr(sb, bindex);
37127 + xi = br->br_xino;
37128 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37129 + err = au_xino_do_trunc(sb, bindex, i, st);
37131 + au_sbi(sb)->si_xino_jiffy = jiffy;
37134 + au_kfree_rcu(st);
37139 +struct xino_do_trunc_args {
37140 + struct super_block *sb;
37141 + struct au_branch *br;
37145 +static void xino_do_trunc(void *_args)
37147 + struct xino_do_trunc_args *args = _args;
37148 + struct super_block *sb;
37149 + struct au_branch *br;
37150 + struct inode *dir;
37152 + aufs_bindex_t bindex;
37156 + dir = d_inode(sb->s_root);
37160 + si_noflush_write_lock(sb);
37161 + ii_read_lock_parent(dir);
37162 + bindex = au_br_index(sb, br->br_id);
37163 + err = au_xino_trunc(sb, bindex, idx);
37164 + ii_read_unlock(dir);
37165 + if (unlikely(err))
37166 + pr_warn("err b%d, (%d)\n", bindex, err);
37167 + atomic_dec(&br->br_xino->xi_truncating);
37168 + au_lcnt_dec(&br->br_count);
37169 + si_write_unlock(sb);
37170 + au_nwt_done(&au_sbi(sb)->si_nowait);
37171 + au_kfree_rcu(args);
37175 + * returns the index in the xi_file array whose corresponding file is necessary
37176 + * to truncate, or -1 which means no need to truncate.
37178 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37182 + struct kstatfs st;
37183 + struct au_sbinfo *sbinfo;
37184 + struct au_xino *xi;
37185 + struct file *file;
37187 + /* todo: si_xino_expire and the ratio should be customizable */
37188 + sbinfo = au_sbi(sb);
37189 + if (time_before(jiffies,
37190 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37193 + /* truncation border */
37194 + xi = br->br_xino;
37195 + for (u = 0; u < xi->xi_nfile; u++) {
37196 + file = au_xino_file(xi, u);
37200 + err = vfs_statfs(&file->f_path, &st);
37201 + if (unlikely(err)) {
37202 + AuErr1("statfs err %d, ignored\n", err);
37205 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37206 + >= AUFS_XINO_DEF_TRUNC)
37213 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37216 + struct xino_do_trunc_args *args;
37219 + idx = xino_trunc_test(sb, br);
37223 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37226 + /* lock and kfree() will be called in trunc_xino() */
37227 + args = kmalloc(sizeof(*args), GFP_NOFS);
37228 + if (unlikely(!args)) {
37229 + AuErr1("no memory\n");
37233 + au_lcnt_inc(&br->br_count);
37237 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37239 + return; /* success */
37241 + pr_err("wkq %d\n", wkq_err);
37242 + au_lcnt_dec(&br->br_count);
37243 + au_kfree_rcu(args);
37246 + atomic_dec(&br->br_xino->xi_truncating);
37249 +/* ---------------------------------------------------------------------- */
37251 +struct au_xi_calc {
37256 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37257 + struct au_xi_calc *calc)
37261 + maxent = au_xi_maxent(sb);
37262 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37263 + calc->pos *= sizeof(ino_t);
37266 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37267 + struct au_xi_calc *calc)
37270 + struct file *file;
37271 + struct au_xino *xi = br->br_xino;
37272 + struct au_xi_new xinew = {
37276 + SiMustAnyLock(sb);
37282 + mutex_lock(&xi->xi_mtx);
37283 + file = au_xino_file(xi, calc->idx);
37287 + file = au_xino_file(xi, /*idx*/-1);
37288 + AuDebugOn(!file);
37289 + xinew.idx = calc->idx;
37290 + xinew.base = &file->f_path;
37291 + /* xinew.copy_src = NULL; */
37292 + file = au_xi_new(sb, &xinew);
37293 + if (IS_ERR(file))
37294 + err = PTR_ERR(file);
37297 + mutex_unlock(&xi->xi_mtx);
37302 +struct au_xino_do_new_async_args {
37303 + struct super_block *sb;
37304 + struct au_branch *br;
37305 + struct au_xi_calc calc;
37309 +struct au_xi_writing {
37310 + struct hlist_bl_node node;
37311 + ino_t h_ino, ino;
37314 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37317 +static void au_xino_call_do_new_async(void *args)
37319 + struct au_xino_do_new_async_args *a = args;
37320 + struct au_branch *br;
37321 + struct super_block *sb;
37322 + struct au_sbinfo *sbi;
37323 + struct inode *root;
37324 + struct file *file;
37325 + struct au_xi_writing *del, *p;
37326 + struct hlist_bl_head *hbl;
37327 + struct hlist_bl_node *pos;
37332 + sbi = au_sbi(sb);
37333 + si_noflush_read_lock(sb);
37334 + root = d_inode(sb->s_root);
37335 + ii_read_lock_child(root);
37336 + err = au_xino_do_new_async(sb, br, &a->calc);
37337 + if (unlikely(err)) {
37338 + AuIOErr("err %d\n", err);
37342 + file = au_xino_file(br->br_xino, a->calc.idx);
37343 + AuDebugOn(!file);
37344 + err = au_xino_do_write(file, &a->calc, a->ino);
37345 + if (unlikely(err)) {
37346 + AuIOErr("err %d\n", err);
37351 + hbl = &br->br_xino->xi_writing;
37352 + hlist_bl_lock(hbl);
37353 + au_hbl_for_each(pos, hbl) {
37354 + p = container_of(pos, struct au_xi_writing, node);
37355 + if (p->ino == a->ino) {
37357 + hlist_bl_del(&p->node);
37361 + hlist_bl_unlock(hbl);
37362 + au_kfree_rcu(del);
37365 + au_lcnt_dec(&br->br_count);
37366 + ii_read_unlock(root);
37367 + si_read_unlock(sb);
37368 + au_nwt_done(&sbi->si_nowait);
37373 + * create a new xino file asynchronously
37375 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37376 + struct au_xi_calc *calc, ino_t ino)
37379 + struct au_xino_do_new_async_args *arg;
37382 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37383 + if (unlikely(!arg))
37388 + arg->calc = *calc;
37390 + au_lcnt_inc(&br->br_count);
37391 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37392 + if (unlikely(err)) {
37393 + pr_err("wkq %d\n", err);
37394 + au_lcnt_dec(&br->br_count);
37395 + au_kfree_rcu(arg);
37403 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37404 + * at the position of @h_ino.
37406 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37411 + struct au_xi_calc calc;
37412 + struct au_sbinfo *sbinfo;
37413 + struct file *file;
37414 + struct au_xino *xi;
37415 + struct hlist_bl_head *hbl;
37416 + struct hlist_bl_node *pos;
37417 + struct au_xi_writing *p;
37420 + if (!au_opt_test(au_mntflags(sb), XINO))
37421 + return 0; /* no xino */
37424 + au_xi_calc(sb, h_ino, &calc);
37425 + xi = au_sbr(sb, bindex)->br_xino;
37426 + file = au_xino_file(xi, calc.idx);
37428 + hbl = &xi->xi_writing;
37429 + hlist_bl_lock(hbl);
37430 + au_hbl_for_each(pos, hbl) {
37431 + p = container_of(pos, struct au_xi_writing, node);
37432 + if (p->h_ino == h_ino) {
37433 + AuDbg("hi%llu, i%llu, found\n",
37434 + (u64)p->h_ino, (u64)p->ino);
37439 + hlist_bl_unlock(hbl);
37441 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37442 + return 0; /* no xino */
37444 + sbinfo = au_sbi(sb);
37445 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37446 + if (sz == sizeof(*ino))
37447 + return 0; /* success */
37450 + if (unlikely(sz >= 0)) {
37452 + AuIOErr("xino read error (%zd)\n", sz);
37457 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37462 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37463 + if (sz == sizeof(ino))
37464 + return 0; /* success */
37466 + AuIOErr("write failed (%zd)\n", sz);
37471 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37472 + * at the position of @h_ino.
37473 + * even if @ino is zero, it is written to the xinofile and means no entry.
37474 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37475 + * try truncating it.
37477 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37481 + unsigned int mnt_flags;
37482 + struct au_xi_calc calc;
37483 + struct file *file;
37484 + struct au_branch *br;
37485 + struct au_xino *xi;
37486 + struct au_xi_writing *p;
37488 + SiMustAnyLock(sb);
37490 + mnt_flags = au_mntflags(sb);
37491 + if (!au_opt_test(mnt_flags, XINO))
37494 + au_xi_calc(sb, h_ino, &calc);
37495 + br = au_sbr(sb, bindex);
37496 + xi = br->br_xino;
37497 + file = au_xino_file(xi, calc.idx);
37499 + /* store the inum pair into the list */
37500 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37501 + p->h_ino = h_ino;
37503 + au_hbl_add(&p->node, &xi->xi_writing);
37505 + /* create and write a new xino file asynchronously */
37506 + err = au_xino_new_async(sb, br, &calc, ino);
37508 + return 0; /* success */
37512 + err = au_xino_do_write(file, &calc, ino);
37514 + br = au_sbr(sb, bindex);
37515 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37516 + && au_test_fs_trunc_xino(au_br_sb(br)))
37517 + xino_try_trunc(sb, br);
37518 + return 0; /* success */
37522 + AuIOErr("write failed (%d)\n", err);
37526 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37529 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37530 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37534 + const int prevent_endless = 10;
37538 + err = vfsub_read_k(file, kbuf, size, pos);
37539 + if (err == -EINTR
37540 + && !au_wkq_test()
37541 + && fatal_signal_pending(current)) {
37542 + err = xino_fread_wkq(file, kbuf, size, pos);
37543 + BUG_ON(err == -EINTR);
37545 + } while (i++ < prevent_endless
37546 + && (err == -EAGAIN || err == -EINTR));
37548 +#if 0 /* reserved for future use */
37550 + fsnotify_access(file->f_path.dentry);
37556 +struct xino_fread_args {
37558 + struct file *file;
37564 +static void call_xino_fread(void *args)
37566 + struct xino_fread_args *a = args;
37567 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37570 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37575 + struct xino_fread_args args = {
37583 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37584 + if (unlikely(wkq_err))
37590 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37593 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37598 + const int prevent_endless = 10;
37602 + err = vfsub_write_k(file, kbuf, size, pos);
37603 + if (err == -EINTR
37604 + && !au_wkq_test()
37605 + && fatal_signal_pending(current)) {
37606 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37607 + BUG_ON(err == -EINTR);
37609 + } while (i++ < prevent_endless
37610 + && (err == -EAGAIN || err == -EINTR));
37612 +#if 0 /* reserved for future use */
37614 + fsnotify_modify(file->f_path.dentry);
37620 +struct do_xino_fwrite_args {
37622 + struct file *file;
37628 +static void call_do_xino_fwrite(void *args)
37630 + struct do_xino_fwrite_args *a = args;
37631 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37634 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37639 + struct do_xino_fwrite_args args = {
37648 + * it breaks RLIMIT_FSIZE and normal user's limit,
37649 + * users should care about quota and real 'filesystem full.'
37651 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37652 + if (unlikely(wkq_err))
37658 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37662 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37664 + err = do_xino_fwrite(file, buf, size, pos);
37668 + err = xino_fwrite_wkq(file, buf, size, pos);
37675 +/* ---------------------------------------------------------------------- */
37678 + * inode number bitmap
37680 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37681 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37685 + AuDebugOn(bit < 0 || page_bits <= bit);
37686 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37690 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37692 + AuDebugOn(ino < AUFS_FIRST_INO);
37693 + ino -= AUFS_FIRST_INO;
37694 + *pindex = ino / page_bits;
37695 + *bit = ino % page_bits;
37698 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37703 + struct au_sbinfo *sbinfo;
37704 + struct file *xib;
37705 + unsigned long *p;
37707 + sbinfo = au_sbi(sb);
37708 + MtxMustLock(&sbinfo->si_xib_mtx);
37709 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37710 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37712 + if (pindex == sbinfo->si_xib_last_pindex)
37715 + xib = sbinfo->si_xib;
37716 + p = sbinfo->si_xib_buf;
37717 + pos = sbinfo->si_xib_last_pindex;
37718 + pos *= PAGE_SIZE;
37719 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37720 + if (unlikely(sz != PAGE_SIZE))
37724 + pos *= PAGE_SIZE;
37725 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37726 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37728 + memset(p, 0, PAGE_SIZE);
37729 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37731 + if (sz == PAGE_SIZE) {
37732 + sbinfo->si_xib_last_pindex = pindex;
37733 + return 0; /* success */
37737 + AuIOErr1("write failed (%zd)\n", sz);
37744 +static void au_xib_clear_bit(struct inode *inode)
37747 + unsigned long pindex;
37748 + struct super_block *sb;
37749 + struct au_sbinfo *sbinfo;
37751 + AuDebugOn(inode->i_nlink);
37753 + sb = inode->i_sb;
37754 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37755 + AuDebugOn(page_bits <= bit);
37756 + sbinfo = au_sbi(sb);
37757 + mutex_lock(&sbinfo->si_xib_mtx);
37758 + err = xib_pindex(sb, pindex);
37760 + clear_bit(bit, sbinfo->si_xib_buf);
37761 + sbinfo->si_xib_next_bit = bit;
37763 + mutex_unlock(&sbinfo->si_xib_mtx);
37766 +/* ---------------------------------------------------------------------- */
37769 + * truncate a xino bitmap file
37773 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37777 + unsigned long pindex;
37778 + loff_t pos, pend;
37779 + struct au_sbinfo *sbinfo;
37781 + unsigned long *p;
37784 + sbinfo = au_sbi(sb);
37785 + MtxMustLock(&sbinfo->si_xib_mtx);
37786 + p = sbinfo->si_xib_buf;
37787 + pend = vfsub_f_size_read(file);
37789 + while (pos < pend) {
37790 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37792 + if (unlikely(sz <= 0))
37796 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37797 + if (unlikely(*ino < AUFS_FIRST_INO))
37800 + xib_calc_bit(*ino, &pindex, &bit);
37801 + AuDebugOn(page_bits <= bit);
37802 + err = xib_pindex(sb, pindex);
37814 +static int xib_restore(struct super_block *sb)
37817 + unsigned int nfile;
37818 + aufs_bindex_t bindex, bbot;
37820 + struct au_branch *br;
37821 + struct au_xino *xi;
37822 + struct file *file;
37825 + page = (void *)__get_free_page(GFP_NOFS);
37826 + if (unlikely(!page))
37830 + bbot = au_sbbot(sb);
37831 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37832 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37833 + br = au_sbr(sb, bindex);
37834 + xi = br->br_xino;
37835 + nfile = xi->xi_nfile;
37836 + for (i = 0; i < nfile; i++) {
37837 + file = au_xino_file(xi, i);
37839 + err = do_xib_restore(sb, file, page);
37842 + AuDbg("skip shared b%d\n", bindex);
37843 + free_page((unsigned long)page);
37849 +int au_xib_trunc(struct super_block *sb)
37854 + struct au_sbinfo *sbinfo;
37855 + unsigned long *p;
37856 + struct file *file;
37858 + SiMustWriteLock(sb);
37861 + sbinfo = au_sbi(sb);
37862 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37865 + file = sbinfo->si_xib;
37866 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37869 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37870 + err = PTR_ERR(file);
37871 + if (IS_ERR(file))
37873 + fput(sbinfo->si_xib);
37874 + sbinfo->si_xib = file;
37876 + p = sbinfo->si_xib_buf;
37877 + memset(p, 0, PAGE_SIZE);
37879 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
37880 + if (unlikely(sz != PAGE_SIZE)) {
37882 + AuIOErr("err %d\n", err);
37888 + mutex_lock(&sbinfo->si_xib_mtx);
37889 + /* mnt_want_write() is unnecessary here */
37890 + err = xib_restore(sb);
37891 + mutex_unlock(&sbinfo->si_xib_mtx);
37897 +/* ---------------------------------------------------------------------- */
37899 +struct au_xino *au_xino_alloc(unsigned int nfile)
37901 + struct au_xino *xi;
37903 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37904 + if (unlikely(!xi))
37906 + xi->xi_nfile = nfile;
37907 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
37908 + if (unlikely(!xi->xi_file))
37911 + xi->xi_nondir.total = 8; /* initial size */
37912 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37914 + if (unlikely(!xi->xi_nondir.array))
37917 + spin_lock_init(&xi->xi_nondir.spin);
37918 + init_waitqueue_head(&xi->xi_nondir.wqh);
37919 + mutex_init(&xi->xi_mtx);
37920 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
37921 + atomic_set(&xi->xi_truncating, 0);
37922 + kref_init(&xi->xi_kref);
37923 + goto out; /* success */
37926 + au_kfree_try_rcu(xi->xi_file);
37928 + au_kfree_rcu(xi);
37934 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
37937 + struct au_xino *xi;
37940 + xi = au_xino_alloc(idx + 1);
37941 + if (unlikely(!xi)) {
37948 + xi->xi_file[idx] = file;
37949 + AuDebugOn(br->br_xino);
37950 + br->br_xino = xi;
37956 +static void au_xino_release(struct kref *kref)
37958 + struct au_xino *xi;
37960 + unsigned long ul;
37961 + struct hlist_bl_head *hbl;
37962 + struct hlist_bl_node *pos, *n;
37963 + struct au_xi_writing *p;
37965 + xi = container_of(kref, struct au_xino, xi_kref);
37966 + for (i = 0; i < xi->xi_nfile; i++)
37967 + if (xi->xi_file[i])
37968 + fput(xi->xi_file[i]);
37969 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37970 + AuDebugOn(xi->xi_nondir.array[i]);
37971 + mutex_destroy(&xi->xi_mtx);
37972 + hbl = &xi->xi_writing;
37973 + ul = au_hbl_count(hbl);
37974 + if (unlikely(ul)) {
37975 + pr_warn("xi_writing %lu\n", ul);
37976 + hlist_bl_lock(hbl);
37977 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
37978 + hlist_bl_del(&p->node);
37979 + /* kmemleak reported au_kfree_rcu() doesn't free it */
37982 + hlist_bl_unlock(hbl);
37984 + au_kfree_try_rcu(xi->xi_file);
37985 + au_kfree_try_rcu(xi->xi_nondir.array);
37986 + au_kfree_rcu(xi);
37989 +int au_xino_put(struct au_branch *br)
37992 + struct au_xino *xi;
37995 + xi = br->br_xino;
37997 + br->br_xino = NULL;
37998 + ret = kref_put(&xi->xi_kref, au_xino_release);
38004 +/* ---------------------------------------------------------------------- */
38007 + * xino mount option handlers
38011 +static void xino_clear_xib(struct super_block *sb)
38013 + struct au_sbinfo *sbinfo;
38015 + SiMustWriteLock(sb);
38017 + sbinfo = au_sbi(sb);
38018 + if (sbinfo->si_xib)
38019 + fput(sbinfo->si_xib);
38020 + sbinfo->si_xib = NULL;
38021 + if (sbinfo->si_xib_buf)
38022 + free_page((unsigned long)sbinfo->si_xib_buf);
38023 + sbinfo->si_xib_buf = NULL;
38026 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38030 + struct au_sbinfo *sbinfo;
38031 + struct file *file;
38032 + struct super_block *xi_sb;
38034 + SiMustWriteLock(sb);
38036 + sbinfo = au_sbi(sb);
38037 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38038 + err = PTR_ERR(file);
38039 + if (IS_ERR(file))
38041 + if (sbinfo->si_xib)
38042 + fput(sbinfo->si_xib);
38043 + sbinfo->si_xib = file;
38044 + xi_sb = file_inode(file)->i_sb;
38045 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38046 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38048 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38049 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38052 + sbinfo->si_ximaxent /= sizeof(ino_t);
38055 + if (!sbinfo->si_xib_buf)
38056 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38057 + if (unlikely(!sbinfo->si_xib_buf))
38060 + sbinfo->si_xib_last_pindex = 0;
38061 + sbinfo->si_xib_next_bit = 0;
38062 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38064 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38065 + if (unlikely(err != PAGE_SIZE))
38069 + goto out; /* success */
38072 + if (sbinfo->si_xib_buf)
38073 + free_page((unsigned long)sbinfo->si_xib_buf);
38074 + sbinfo->si_xib_buf = NULL;
38078 + fput(sbinfo->si_xib);
38079 + sbinfo->si_xib = NULL;
38085 +/* xino for each branch */
38086 +static void xino_clear_br(struct super_block *sb)
38088 + aufs_bindex_t bindex, bbot;
38089 + struct au_branch *br;
38091 + bbot = au_sbbot(sb);
38092 + for (bindex = 0; bindex <= bbot; bindex++) {
38093 + br = au_sbr(sb, bindex);
38099 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38100 + aufs_bindex_t bshared)
38102 + struct au_branch *brshared;
38104 + brshared = au_sbr(sb, bshared);
38105 + AuDebugOn(!brshared->br_xino);
38106 + AuDebugOn(!brshared->br_xino->xi_file);
38107 + if (br->br_xino != brshared->br_xino) {
38108 + au_xino_get(brshared);
38110 + br->br_xino = brshared->br_xino;
38114 +struct au_xino_do_set_br {
38115 + struct au_branch *br;
38117 + aufs_bindex_t bshared;
38120 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38121 + struct au_xino_do_set_br *args)
38124 + struct au_xi_calc calc;
38125 + struct file *file;
38126 + struct au_branch *br;
38127 + struct au_xi_new xinew = {
38132 + xinew.xi = br->br_xino;
38133 + au_xi_calc(sb, args->h_ino, &calc);
38134 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38135 + if (args->bshared >= 0)
38136 + /* shared xino */
38137 + au_xino_set_br_shared(sb, br, args->bshared);
38138 + else if (!xinew.xi) {
38140 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38141 + if (unlikely(err))
38145 + /* force re-creating */
38146 + xinew.xi = br->br_xino;
38147 + xinew.idx = calc.idx;
38148 + mutex_lock(&xinew.xi->xi_mtx);
38149 + file = au_xi_new(sb, &xinew);
38150 + mutex_unlock(&xinew.xi->xi_mtx);
38151 + err = PTR_ERR(file);
38152 + if (IS_ERR(file))
38154 + AuDebugOn(!file);
38156 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38157 + if (unlikely(err))
38165 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38168 + aufs_bindex_t bindex, bbot;
38169 + struct au_xino_do_set_br args;
38170 + struct inode *inode;
38172 + SiMustWriteLock(sb);
38174 + bbot = au_sbbot(sb);
38175 + inode = d_inode(sb->s_root);
38176 + for (bindex = 0; bindex <= bbot; bindex++) {
38177 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38178 + args.br = au_sbr(sb, bindex);
38179 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38180 + err = au_xino_do_set_br(sb, path, &args);
38181 + if (unlikely(err))
38189 +void au_xino_clr(struct super_block *sb)
38191 + struct au_sbinfo *sbinfo;
38193 + au_xigen_clr(sb);
38194 + xino_clear_xib(sb);
38195 + xino_clear_br(sb);
38196 + dbgaufs_brs_del(sb, 0);
38197 + sbinfo = au_sbi(sb);
38198 + /* lvalue, do not call au_mntflags() */
38199 + au_opt_clr(sbinfo->si_mntflags, XINO);
38202 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38205 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38206 + struct qstr *dname, *cur_name;
38207 + struct file *cur_xino;
38208 + struct au_sbinfo *sbinfo;
38209 + struct path *path, *cur_path;
38211 + SiMustWriteLock(sb);
38214 + sbinfo = au_sbi(sb);
38215 + path = &xiopt->file->f_path;
38216 + dentry = path->dentry;
38217 + parent = dget_parent(dentry);
38220 + cur_xino = sbinfo->si_xib;
38222 + cur_path = &cur_xino->f_path;
38223 + cur_dentry = cur_path->dentry;
38224 + cur_parent = dget_parent(cur_dentry);
38225 + cur_name = &cur_dentry->d_name;
38226 + dname = &dentry->d_name;
38227 + skip = (cur_parent == parent
38228 + && au_qstreq(dname, cur_name));
38229 + dput(cur_parent);
38235 + au_opt_set(sbinfo->si_mntflags, XINO);
38236 + err = au_xino_set_xib(sb, path);
38237 + /* si_x{read,write} are set */
38239 + err = au_xigen_set(sb, path);
38241 + err = au_xino_set_br(sb, path);
38243 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38244 + goto out; /* success */
38248 + AuIOErr("failed setting xino(%d).\n", err);
38257 + * create a xinofile at the default place/path.
38259 +struct file *au_xino_def(struct super_block *sb)
38261 + struct file *file;
38263 + struct au_branch *br;
38264 + struct super_block *h_sb;
38265 + struct path path;
38266 + aufs_bindex_t bbot, bindex, bwr;
38269 + bbot = au_sbbot(sb);
38271 + for (bindex = 0; bindex <= bbot; bindex++) {
38272 + br = au_sbr(sb, bindex);
38273 + if (au_br_writable(br->br_perm)
38274 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38281 + file = ERR_PTR(-ENOMEM);
38282 + page = (void *)__get_free_page(GFP_NOFS);
38283 + if (unlikely(!page))
38285 + path.mnt = au_br_mnt(br);
38286 + path.dentry = au_h_dptr(sb->s_root, bwr);
38287 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38288 + file = (void *)p;
38289 + if (!IS_ERR(p)) {
38290 + strcat(p, "/" AUFS_XINO_FNAME);
38291 + AuDbg("%s\n", p);
38292 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38294 + free_page((unsigned long)page);
38296 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38298 + if (IS_ERR(file))
38300 + h_sb = file->f_path.dentry->d_sb;
38301 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38302 + pr_err("xino doesn't support %s(%s)\n",
38303 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38305 + file = ERR_PTR(-EINVAL);
38313 +/* ---------------------------------------------------------------------- */
38316 + * initialize the xinofile for the specified branch @br
38317 + * at the place/path where @base_file indicates.
38318 + * test whether another branch is on the same filesystem or not,
38319 + * if found then share the xinofile with another branch.
38321 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38322 + struct path *base)
38325 + struct au_xino_do_set_br args = {
38330 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38332 + err = au_xino_do_set_br(sb, base, &args);
38333 + if (unlikely(err))
38339 +/* ---------------------------------------------------------------------- */
38342 + * get an unused inode number from bitmap
38344 +ino_t au_xino_new_ino(struct super_block *sb)
38347 + unsigned long *p, pindex, ul, pend;
38348 + struct au_sbinfo *sbinfo;
38349 + struct file *file;
38350 + int free_bit, err;
38352 + if (!au_opt_test(au_mntflags(sb), XINO))
38353 + return iunique(sb, AUFS_FIRST_INO);
38355 + sbinfo = au_sbi(sb);
38356 + mutex_lock(&sbinfo->si_xib_mtx);
38357 + p = sbinfo->si_xib_buf;
38358 + free_bit = sbinfo->si_xib_next_bit;
38359 + if (free_bit < page_bits && !test_bit(free_bit, p))
38360 + goto out; /* success */
38361 + free_bit = find_first_zero_bit(p, page_bits);
38362 + if (free_bit < page_bits)
38363 + goto out; /* success */
38365 + pindex = sbinfo->si_xib_last_pindex;
38366 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38367 + err = xib_pindex(sb, ul);
38368 + if (unlikely(err))
38370 + free_bit = find_first_zero_bit(p, page_bits);
38371 + if (free_bit < page_bits)
38372 + goto out; /* success */
38375 + file = sbinfo->si_xib;
38376 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38377 + for (ul = pindex + 1; ul <= pend; ul++) {
38378 + err = xib_pindex(sb, ul);
38379 + if (unlikely(err))
38381 + free_bit = find_first_zero_bit(p, page_bits);
38382 + if (free_bit < page_bits)
38383 + goto out; /* success */
38388 + set_bit(free_bit, p);
38389 + sbinfo->si_xib_next_bit = free_bit + 1;
38390 + pindex = sbinfo->si_xib_last_pindex;
38391 + mutex_unlock(&sbinfo->si_xib_mtx);
38392 + ino = xib_calc_ino(pindex, free_bit);
38393 + AuDbg("i%lu\n", (unsigned long)ino);
38396 + mutex_unlock(&sbinfo->si_xib_mtx);
38401 +/* for s_op->delete_inode() */
38402 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38405 + unsigned int mnt_flags;
38406 + aufs_bindex_t bindex, bbot, bi;
38407 + unsigned char try_trunc;
38408 + struct au_iinfo *iinfo;
38409 + struct super_block *sb;
38410 + struct au_hinode *hi;
38411 + struct inode *h_inode;
38412 + struct au_branch *br;
38413 + struct au_xi_calc calc;
38414 + struct file *file;
38416 + AuDebugOn(au_is_bad_inode(inode));
38418 + sb = inode->i_sb;
38419 + mnt_flags = au_mntflags(sb);
38420 + if (!au_opt_test(mnt_flags, XINO)
38421 + || inode->i_ino == AUFS_ROOT_INO)
38425 + au_xigen_inc(inode);
38426 + au_xib_clear_bit(inode);
38429 + iinfo = au_ii(inode);
38430 + bindex = iinfo->ii_btop;
38434 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38435 + hi = au_hinode(iinfo, bindex);
38436 + bbot = iinfo->ii_bbot;
38437 + for (; bindex <= bbot; bindex++, hi++) {
38438 + h_inode = hi->hi_inode;
38440 + || (!unlinked && h_inode->i_nlink))
38443 + /* inode may not be revalidated */
38444 + bi = au_br_index(sb, hi->hi_id);
38448 + br = au_sbr(sb, bi);
38449 + au_xi_calc(sb, h_inode->i_ino, &calc);
38450 + file = au_xino_file(br->br_xino, calc.idx);
38451 + if (IS_ERR_OR_NULL(file))
38454 + err = au_xino_do_write(file, &calc, /*ino*/0);
38455 + if (!err && try_trunc
38456 + && au_test_fs_trunc_xino(au_br_sb(br)))
38457 + xino_try_trunc(sb, br);
38461 +/* ---------------------------------------------------------------------- */
38463 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38465 + int found, total, i;
38468 + total = xi->xi_nondir.total;
38469 + for (i = 0; i < total; i++) {
38470 + if (xi->xi_nondir.array[i] != h_ino)
38479 +static int au_xinondir_expand(struct au_xino *xi)
38484 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38487 + sz = xi->xi_nondir.total * sizeof(ino_t);
38488 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38490 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38491 + /*may_shrink*/0);
38493 + xi->xi_nondir.array = p;
38494 + xi->xi_nondir.total <<= 1;
38495 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38503 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38504 + ino_t h_ino, int idx)
38506 + struct au_xino *xi;
38508 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38509 + xi = au_sbr(sb, bindex)->br_xino;
38510 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38512 + spin_lock(&xi->xi_nondir.spin);
38513 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38514 + xi->xi_nondir.array[idx] = 0;
38515 + spin_unlock(&xi->xi_nondir.spin);
38516 + wake_up_all(&xi->xi_nondir.wqh);
38519 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38522 + int err, found, empty;
38523 + struct au_xino *xi;
38527 + if (!au_opt_test(au_mntflags(sb), XINO))
38528 + goto out; /* no xino */
38530 + xi = au_sbr(sb, bindex)->br_xino;
38533 + spin_lock(&xi->xi_nondir.spin);
38534 + found = au_xinondir_find(xi, h_ino);
38535 + if (found == -1) {
38536 + empty = au_xinondir_find(xi, /*h_ino*/0);
38537 + if (empty == -1) {
38538 + empty = xi->xi_nondir.total;
38539 + err = au_xinondir_expand(xi);
38540 + if (unlikely(err))
38543 + xi->xi_nondir.array[empty] = h_ino;
38546 + spin_unlock(&xi->xi_nondir.spin);
38547 + wait_event(xi->xi_nondir.wqh,
38548 + xi->xi_nondir.array[found] != h_ino);
38553 + spin_unlock(&xi->xi_nondir.spin);
38558 +/* ---------------------------------------------------------------------- */
38560 +int au_xino_path(struct seq_file *seq, struct file *file)
38564 + err = au_seq_path(seq, &file->f_path);
38565 + if (unlikely(err))
38568 +#define Deleted "\\040(deleted)"
38569 + seq->count -= sizeof(Deleted) - 1;
38570 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38571 + sizeof(Deleted) - 1));
38577 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38578 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38579 +++ linux/include/uapi/linux/aufs_type.h 2021-02-24 13:33:42.751013936 +0100
38581 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38583 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38585 + * This program, aufs is free software; you can redistribute it and/or modify
38586 + * it under the terms of the GNU General Public License as published by
38587 + * the Free Software Foundation; either version 2 of the License, or
38588 + * (at your option) any later version.
38590 + * This program is distributed in the hope that it will be useful,
38591 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38592 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38593 + * GNU General Public License for more details.
38595 + * You should have received a copy of the GNU General Public License
38596 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38599 +#ifndef __AUFS_TYPE_H__
38600 +#define __AUFS_TYPE_H__
38602 +#define AUFS_NAME "aufs"
38606 + * define it before including all other headers.
38607 + * sched.h may use pr_* macros before defining "current", so define the
38608 + * no-current version first, and re-define later.
38610 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38611 +#include <linux/sched.h>
38613 +#define pr_fmt(fmt) \
38614 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38615 + (int)sizeof(current->comm), current->comm, current->pid
38616 +#include <linux/limits.h>
38618 +#include <stdint.h>
38619 +#include <sys/types.h>
38620 +#include <limits.h>
38621 +#endif /* __KERNEL__ */
38623 +#define AUFS_VERSION "5.11-20210222"
38625 +/* todo? move this to linux-2.6.19/include/magic.h */
38626 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38628 +/* ---------------------------------------------------------------------- */
38631 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38632 +typedef int8_t aufs_bindex_t;
38633 +#define AUFS_BRANCH_MAX 127
38635 +typedef int16_t aufs_bindex_t;
38636 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38637 +#define AUFS_BRANCH_MAX 511
38638 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38639 +#define AUFS_BRANCH_MAX 1023
38640 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38641 +#define AUFS_BRANCH_MAX 32767
38645 +#ifndef AUFS_BRANCH_MAX
38646 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38648 +#endif /* __KERNEL__ */
38650 +/* ---------------------------------------------------------------------- */
38652 +#define AUFS_FSTYPE AUFS_NAME
38654 +#define AUFS_ROOT_INO 2
38655 +#define AUFS_FIRST_INO 11
38657 +#define AUFS_WH_PFX ".wh."
38658 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38659 +#define AUFS_WH_TMP_LEN 4
38660 +/* a limit for rmdir/rename a dir and copyup */
38661 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38662 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38664 + - AUFS_WH_TMP_LEN) /* hex */
38665 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38666 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38667 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38668 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38669 +#define AUFS_DIRWH_DEF 3
38670 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38671 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38672 +#define AUFS_RDBLK_DEF 512 /* bytes */
38673 +#define AUFS_RDHASH_DEF 32
38674 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38675 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38676 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38677 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38678 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38680 +/* pseudo-link maintenace under /proc */
38681 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38682 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38683 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38685 +/* dirren, renamed dir */
38686 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38687 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38688 +/* whiteouted doubly */
38689 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38690 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38692 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38693 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38695 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38696 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38697 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38699 +/* doubly whiteouted */
38700 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38701 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38702 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38704 +/* branch permissions and attributes */
38705 +#define AUFS_BRPERM_RW "rw"
38706 +#define AUFS_BRPERM_RO "ro"
38707 +#define AUFS_BRPERM_RR "rr"
38708 +#define AUFS_BRATTR_COO_REG "coo_reg"
38709 +#define AUFS_BRATTR_COO_ALL "coo_all"
38710 +#define AUFS_BRATTR_FHSM "fhsm"
38711 +#define AUFS_BRATTR_UNPIN "unpin"
38712 +#define AUFS_BRATTR_ICEX "icex"
38713 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38714 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38715 +#define AUFS_BRATTR_ICEX_TR "icextr"
38716 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38717 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38718 +#define AUFS_BRRATTR_WH "wh"
38719 +#define AUFS_BRWATTR_NLWH "nolwh"
38720 +#define AUFS_BRWATTR_MOO "moo"
38722 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38723 +#define AuBrPerm_RO (1 << 1) /* readonly */
38724 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38725 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38727 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38728 +#define AuBrAttr_COO_ALL (1 << 4)
38729 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38731 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38732 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38733 + branch. meaningless since
38734 + linux-3.18-rc1 */
38736 +/* ignore error in copying XATTR */
38737 +#define AuBrAttr_ICEX_SEC (1 << 7)
38738 +#define AuBrAttr_ICEX_SYS (1 << 8)
38739 +#define AuBrAttr_ICEX_TR (1 << 9)
38740 +#define AuBrAttr_ICEX_USR (1 << 10)
38741 +#define AuBrAttr_ICEX_OTH (1 << 11)
38742 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38743 + | AuBrAttr_ICEX_SYS \
38744 + | AuBrAttr_ICEX_TR \
38745 + | AuBrAttr_ICEX_USR \
38746 + | AuBrAttr_ICEX_OTH)
38748 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38749 +#define AuBrRAttr_Mask AuBrRAttr_WH
38751 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38752 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38753 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38755 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38757 +/* #warning test userspace */
38759 +#ifndef CONFIG_AUFS_FHSM
38760 +#undef AuBrAttr_FHSM
38761 +#define AuBrAttr_FHSM 0
38763 +#ifndef CONFIG_AUFS_XATTR
38764 +#undef AuBrAttr_ICEX
38765 +#define AuBrAttr_ICEX 0
38766 +#undef AuBrAttr_ICEX_SEC
38767 +#define AuBrAttr_ICEX_SEC 0
38768 +#undef AuBrAttr_ICEX_SYS
38769 +#define AuBrAttr_ICEX_SYS 0
38770 +#undef AuBrAttr_ICEX_TR
38771 +#define AuBrAttr_ICEX_TR 0
38772 +#undef AuBrAttr_ICEX_USR
38773 +#define AuBrAttr_ICEX_USR 0
38774 +#undef AuBrAttr_ICEX_OTH
38775 +#define AuBrAttr_ICEX_OTH 0
38779 +/* the longest combination */
38780 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38781 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38782 + "+" AUFS_BRATTR_COO_REG \
38783 + "+" AUFS_BRATTR_FHSM \
38784 + "+" AUFS_BRATTR_UNPIN \
38785 + "+" AUFS_BRATTR_ICEX_SEC \
38786 + "+" AUFS_BRATTR_ICEX_SYS \
38787 + "+" AUFS_BRATTR_ICEX_USR \
38788 + "+" AUFS_BRATTR_ICEX_OTH \
38789 + "+" AUFS_BRWATTR_NLWH)
38792 + char a[AuBrPermStrSz];
38793 +} au_br_perm_str_t;
38795 +static inline int au_br_writable(int brperm)
38797 + return brperm & AuBrPerm_RW;
38800 +static inline int au_br_whable(int brperm)
38802 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38805 +static inline int au_br_wh_linkable(int brperm)
38807 + return !(brperm & AuBrWAttr_NoLinkWH);
38810 +static inline int au_br_cmoo(int brperm)
38812 + return brperm & AuBrAttr_CMOO_Mask;
38815 +static inline int au_br_fhsm(int brperm)
38817 + return brperm & AuBrAttr_FHSM;
38820 +/* ---------------------------------------------------------------------- */
38824 + /* readdir in userspace */
38828 + AuCtl_WBR_FD, /* pathconf wrapper */
38829 + AuCtl_IBUSY, /* busy inode */
38830 + AuCtl_MVDOWN, /* move-down */
38831 + AuCtl_BR, /* info about branches */
38832 + AuCtl_FHSM_FD /* connection for fhsm */
38835 +/* borrowed from linux/include/linux/kernel.h */
38837 +#ifdef _GNU_SOURCE
38838 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38840 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38842 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38845 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38847 +#define __aligned(x) __attribute__((aligned(x)))
38852 +#define __packed __attribute__((packed))
38856 +struct au_rdu_cookie {
38861 + uint32_t generation;
38864 +struct au_rdu_ent {
38873 +static inline int au_rdu_len(int nlen)
38875 + /* include the terminating NULL */
38876 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38877 + sizeof(uint64_t));
38880 +union au_rdu_ent_ul {
38881 + struct au_rdu_ent __user *e;
38893 + uint64_t sz; /* AuCtl_RDU */
38894 + uint64_t nent; /* AuCtl_RDU_INO */
38896 + union au_rdu_ent_ul ent;
38897 + uint16_t verify[AufsCtlRduV_End];
38899 + /* input/output */
38903 + union au_rdu_ent_ul tail;
38904 + /* number of entries which were added in a single call */
38909 + struct au_rdu_cookie cookie;
38912 +/* ---------------------------------------------------------------------- */
38914 +/* dirren. the branch is identified by the filename who contains this */
38915 +struct au_drinfo {
38918 + uint8_t oldnamelen;
38919 + uint64_t _padding;
38921 + uint8_t oldname[];
38924 +struct au_drinfo_fdata {
38926 + struct au_drinfo drinfo;
38929 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38931 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38933 +/* ---------------------------------------------------------------------- */
38935 +struct aufs_wbr_fd {
38940 +/* ---------------------------------------------------------------------- */
38942 +struct aufs_ibusy {
38943 + uint64_t ino, h_ino;
38947 +/* ---------------------------------------------------------------------- */
38949 +/* error code for move-down */
38950 +/* the actual message strings are implemented in aufs-util.git */
38952 + EAU_MVDOWN_OPAQUE = 1,
38953 + EAU_MVDOWN_WHITEOUT,
38954 + EAU_MVDOWN_UPPER,
38955 + EAU_MVDOWN_BOTTOM,
38956 + EAU_MVDOWN_NOUPPER,
38957 + EAU_MVDOWN_NOLOWERBR,
38961 +/* flags for move-down */
38962 +#define AUFS_MVDOWN_DMSG 1
38963 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38964 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38965 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38966 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38967 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38968 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38969 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38970 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38971 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38972 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38973 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38974 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38976 +/* index for move-down */
38978 + AUFS_MVDOWN_UPPER,
38979 + AUFS_MVDOWN_LOWER,
38980 + AUFS_MVDOWN_NARRAY
38984 + * additional info of move-down
38985 + * number of free blocks and inodes.
38986 + * subset of struct kstatfs, but smaller and always 64bit.
38988 +struct aufs_stfs {
38989 + uint64_t f_blocks;
38990 + uint64_t f_bavail;
38991 + uint64_t f_files;
38992 + uint64_t f_ffree;
38995 +struct aufs_stbr {
38996 + int16_t brid; /* optional input */
38997 + int16_t bindex; /* output */
38998 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39001 +struct aufs_mvdown {
39002 + uint32_t flags; /* input/output */
39003 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39004 + int8_t au_errno; /* output */
39007 +/* ---------------------------------------------------------------------- */
39009 +union aufs_brinfo {
39010 + /* PATH_MAX may differ between kernel-space and user-space */
39011 + char _spacer[4096];
39019 +/* ---------------------------------------------------------------------- */
39021 +#define AuCtlType 'A'
39022 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39023 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39024 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39025 + struct aufs_wbr_fd)
39026 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39027 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39028 + struct aufs_mvdown)
39029 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39030 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39032 +#endif /* __AUFS_TYPE_H__ */
39033 SPDX-License-Identifier: GPL-2.0
39034 aufs5.11 loopback patch
39036 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39037 index 39d539df0349d..4109efe2f6a3a 100644
39038 --- a/drivers/block/loop.c
39039 +++ b/drivers/block/loop.c
39040 @@ -646,6 +646,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39044 +static struct file *loop_real_file(struct file *file)
39046 + struct file *f = NULL;
39048 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39049 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39053 static void loop_reread_partitions(struct loop_device *lo,
39054 struct block_device *bdev)
39056 @@ -701,6 +710,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39059 struct file *file = NULL, *old_file;
39060 + struct file *f, *virt_file = NULL, *old_virt_file;
39064 @@ -720,12 +730,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39068 + f = loop_real_file(file);
39070 + virt_file = file;
39075 error = loop_validate_file(file, bdev);
39079 old_file = lo->lo_backing_file;
39080 + old_virt_file = lo->lo_backing_virt_file;
39084 @@ -737,6 +754,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39085 blk_mq_freeze_queue(lo->lo_queue);
39086 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39087 lo->lo_backing_file = file;
39088 + lo->lo_backing_virt_file = virt_file;
39089 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39090 mapping_set_gfp_mask(file->f_mapping,
39091 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39092 @@ -750,6 +768,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39096 + if (old_virt_file)
39097 + fput(old_virt_file);
39099 loop_reread_partitions(lo, bdev);
39101 @@ -758,6 +778,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39102 mutex_unlock(&loop_ctl_mutex);
39110 @@ -1084,7 +1106,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39111 struct block_device *bdev,
39112 const struct loop_config *config)
39114 - struct file *file;
39115 + struct file *file, *f, *virt_file = NULL;
39116 struct inode *inode;
39117 struct address_space *mapping;
39119 @@ -1099,6 +1121,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39120 file = fget(config->fd);
39123 + f = loop_real_file(file);
39125 + virt_file = file;
39131 * If we don't hold exclusive handle for the device, upgrade to it
39132 @@ -1153,6 +1181,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39133 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39134 lo->lo_device = bdev;
39135 lo->lo_backing_file = file;
39136 + lo->lo_backing_virt_file = virt_file;
39137 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39138 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39140 @@ -1203,6 +1232,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39141 bd_abort_claiming(bdev, loop_configure);
39147 /* This is safe: open() is still holding a reference. */
39148 module_put(THIS_MODULE);
39149 @@ -1212,6 +1243,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39150 static int __loop_clr_fd(struct loop_device *lo, bool release)
39152 struct file *filp = NULL;
39153 + struct file *virt_filp = lo->lo_backing_virt_file;
39154 gfp_t gfp = lo->old_gfp_mask;
39155 struct block_device *bdev = lo->lo_device;
39157 @@ -1235,6 +1267,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39159 spin_lock_irq(&lo->lo_lock);
39160 lo->lo_backing_file = NULL;
39161 + lo->lo_backing_virt_file = NULL;
39162 spin_unlock_irq(&lo->lo_lock);
39164 loop_release_xfer(lo);
39165 @@ -1317,6 +1350,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39174 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39175 index af75a5ee40944..1d847cb194ff6 100644
39176 --- a/drivers/block/loop.h
39177 +++ b/drivers/block/loop.h
39178 @@ -46,7 +46,7 @@ struct loop_device {
39179 int (*ioctl)(struct loop_device *, int cmd,
39180 unsigned long arg);
39182 - struct file * lo_backing_file;
39183 + struct file *lo_backing_file, *lo_backing_virt_file;
39184 struct block_device *lo_device;
39187 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39188 index 5ef279a59bb14..6447c37f98756 100644
39189 --- a/fs/aufs/f_op.c
39190 +++ b/fs/aufs/f_op.c
39191 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39192 if (IS_ERR(h_file))
39195 - if (au_test_loopback_kthread()) {
39196 + if (0 && au_test_loopback_kthread()) {
39197 au_warn_loopback(h_file->f_path.dentry->d_sb);
39198 if (file->f_mapping != h_file->f_mapping) {
39199 file->f_mapping = h_file->f_mapping;
39200 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39201 index a8b63acc62045..9d97c3af5686a 100644
39202 --- a/fs/aufs/loop.c
39203 +++ b/fs/aufs/loop.c
39204 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39205 symbol_put(loop_backing_file);
39206 au_kfree_try_rcu(au_warn_loopback_array);
39209 +/* ---------------------------------------------------------------------- */
39211 +/* support the loopback block device insude aufs */
39213 +struct file *aufs_real_loop(struct file *file)
39217 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39218 + fi_read_lock(file);
39219 + f = au_hf_top(file);
39220 + fi_read_unlock(file);
39224 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39225 index 94f4f80ae33bf..ca1194354aff4 100644
39226 --- a/fs/aufs/loop.h
39227 +++ b/fs/aufs/loop.h
39228 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39230 int au_loopback_init(void);
39231 void au_loopback_fin(void);
39233 +struct file *aufs_real_loop(struct file *file);
39235 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39237 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39239 AuStubInt0(au_loopback_init, void)
39240 AuStubVoid(au_loopback_fin, void)
39242 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39243 #endif /* BLK_DEV_LOOP */
39245 #endif /* __KERNEL__ */
39246 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39247 index 589dd01220201..801e0a7faec59 100644
39248 --- a/fs/aufs/super.c
39249 +++ b/fs/aufs/super.c
39250 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39251 .statfs = aufs_statfs,
39252 .put_super = aufs_put_super,
39253 .sync_fs = aufs_sync_fs,
39254 - .remount_fs = aufs_remount_fs
39255 + .remount_fs = aufs_remount_fs,
39256 +#ifdef CONFIG_AUFS_BDEV_LOOP
39257 + .real_loop = aufs_real_loop
39261 /* ---------------------------------------------------------------------- */
39262 diff --git a/include/linux/fs.h b/include/linux/fs.h
39263 index 91f3fbe5b57ff..ad1b2e44d538b 100644
39264 --- a/include/linux/fs.h
39265 +++ b/include/linux/fs.h
39266 @@ -1965,6 +1965,10 @@ struct super_operations {
39267 struct shrink_control *);
39268 long (*free_cached_objects)(struct super_block *,
39269 struct shrink_control *);
39270 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39272 + struct file *(*real_loop)(struct file *);