1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index aa4c122823018..b29bad13b2491 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 281de213ef478..ffc3c1c539ea2 100644
32 @@ -3009,6 +3009,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index a58084c2ed7ce..7be7ca3f54547 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -765,6 +765,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index ea0485861d937..ddca6240e0db4 100644
85 @@ -1285,7 +1285,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index 19ac5baad50fd..073ca6af500f3 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 9d78c37b00b81..e7f0c614a58f3 100644
120 @@ -1770,7 +1770,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 cebaa3e817940..451dee24a546a 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 8667d0cdc71e7..837dd6e727e45 100644
189 --- a/include/linux/fs.h
190 +++ b/include/linux/fs.h
191 @@ -1332,6 +1332,7 @@ extern void fasync_free(struct fasync_struct *);
192 /* can be called from interrupts */
193 extern void kill_fasync(struct fasync_struct **, int, int);
195 +extern int setfl(int fd, struct file *filp, unsigned long arg);
196 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
197 extern int f_setown(struct file *filp, unsigned long arg, int force);
198 extern void f_delown(struct file *filp);
199 @@ -1843,6 +1844,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 @@ -2328,6 +2330,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 @@ -2564,6 +2567,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 f5594879175a6..93bb861981675 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 @@ -375,6 +377,7 @@ static inline void lockdep_unregister_key(struct lock_class_key *key)
238 #define lockdep_depth(tsk) (0)
240 +#define lockdep_is_held(lock) (1)
241 #define lockdep_is_held_type(l, r) (1)
243 #define lockdep_assert_held(l) do { (void)(l); } while (0)
244 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
245 index 8f882f5881e87..6b9808f098435 100644
246 --- a/include/linux/mnt_namespace.h
247 +++ b/include/linux/mnt_namespace.h
248 @@ -7,12 +7,15 @@ struct mnt_namespace;
250 struct user_namespace;
254 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
255 struct user_namespace *, struct fs_struct *);
256 extern void put_mnt_ns(struct mnt_namespace *ns);
257 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
259 +extern int is_current_mnt_ns(struct vfsmount *mnt);
261 extern const struct file_operations proc_mounts_operations;
262 extern const struct file_operations proc_mountinfo_operations;
263 extern const struct file_operations proc_mountstats_operations;
264 diff --git a/include/linux/splice.h b/include/linux/splice.h
265 index a55179fd60fc3..8e21c53cf8831 100644
266 --- a/include/linux/splice.h
267 +++ b/include/linux/splice.h
268 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
270 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
271 extern const struct pipe_buf_operations default_pipe_buf_ops;
273 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
274 + loff_t *ppos, size_t len, unsigned int flags);
275 +extern long do_splice_to(struct file *in, loff_t *ppos,
276 + struct pipe_inode_info *pipe, size_t len,
277 + unsigned int flags);
279 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
280 index c1418b47f625a..7f006a47790cf 100644
281 --- a/kernel/locking/lockdep.c
282 +++ b/kernel/locking/lockdep.c
283 @@ -188,7 +188,7 @@ static
284 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
285 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
287 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
288 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
290 unsigned int class_idx = hlock->class_idx;
292 @@ -209,6 +209,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
294 return lock_classes + class_idx;
296 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
298 #ifdef CONFIG_LOCK_STAT
299 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
300 SPDX-License-Identifier: GPL-2.0
303 diff --git a/fs/proc/base.c b/fs/proc/base.c
304 index b362523a9829a..669448bb8a738 100644
307 @@ -2184,7 +2184,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
309 vma = find_exact_vma(mm, vm_start, vm_end);
310 if (vma && vma->vm_file) {
311 - *path = vma->vm_file->f_path;
312 + *path = vma_pr_or_file(vma)->f_path;
316 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
317 index 13452b32e2bd5..38acccfef9d49 100644
318 --- a/fs/proc/nommu.c
319 +++ b/fs/proc/nommu.c
320 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
321 file = region->vm_file;
324 - struct inode *inode = file_inode(region->vm_file);
325 + struct inode *inode;
327 + file = vmr_pr_or_file(region);
328 + inode = file_inode(file);
329 dev = inode->i_sb->s_dev;
332 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
333 index ee5a235b30562..80a46dcede7be 100644
334 --- a/fs/proc/task_mmu.c
335 +++ b/fs/proc/task_mmu.c
336 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
337 const char *name = NULL;
340 - struct inode *inode = file_inode(vma->vm_file);
341 + struct inode *inode;
343 + file = vma_pr_or_file(vma);
344 + inode = file_inode(file);
345 dev = inode->i_sb->s_dev;
347 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
348 @@ -1855,7 +1858,7 @@ static int show_numa_map(struct seq_file *m, void *v)
349 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
350 struct vm_area_struct *vma = v;
351 struct numa_maps *md = &numa_priv->md;
352 - struct file *file = vma->vm_file;
353 + struct file *file = vma_pr_or_file(vma);
354 struct mm_struct *mm = vma->vm_mm;
355 struct mempolicy *pol;
357 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
358 index a6d21fc0033c6..02c2de31196e0 100644
359 --- a/fs/proc/task_nommu.c
360 +++ b/fs/proc/task_nommu.c
361 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
365 - struct inode *inode = file_inode(vma->vm_file);
366 + struct inode *inode;
368 + file = vma_pr_or_file(vma);
369 + inode = file_inode(file);
370 dev = inode->i_sb->s_dev;
372 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
373 diff --git a/include/linux/mm.h b/include/linux/mm.h
374 index db6ae4d3fb4ed..1a632192d9d9f 100644
375 --- a/include/linux/mm.h
376 +++ b/include/linux/mm.h
377 @@ -1712,6 +1712,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
378 unmap_mapping_range(mapping, holebegin, holelen, 0);
381 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
382 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
384 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
385 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
387 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
389 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
391 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
392 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
395 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
396 +extern void vmr_do_fput(struct vm_region *, const char[], int);
398 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
400 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
401 +#endif /* !CONFIG_MMU */
403 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
404 void *buf, int len, unsigned int gup_flags);
405 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
406 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
407 index 5a9238f6caad9..ad387c3cb14fc 100644
408 --- a/include/linux/mm_types.h
409 +++ b/include/linux/mm_types.h
410 @@ -280,6 +280,7 @@ struct vm_region {
411 unsigned long vm_top; /* region allocated to here */
412 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
413 struct file *vm_file; /* the backing file or NULL */
414 + struct file *vm_prfile; /* the virtual backing file or NULL */
416 int vm_usage; /* region usage count (access under nommu_region_sem) */
417 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
418 @@ -359,6 +360,7 @@ struct vm_area_struct {
419 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
421 struct file * vm_file; /* File we map to (can be NULL). */
422 + struct file *vm_prfile; /* shadow of vm_file */
423 void * vm_private_data; /* was vm_pte (shared mem) */
426 diff --git a/kernel/fork.c b/kernel/fork.c
427 index 6d266388d3804..dd7f13c3bee7d 100644
430 @@ -554,7 +554,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
431 struct inode *inode = file_inode(file);
432 struct address_space *mapping = file->f_mapping;
436 if (tmp->vm_flags & VM_DENYWRITE)
437 put_write_access(inode);
438 i_mmap_lock_write(mapping);
439 diff --git a/mm/Makefile b/mm/Makefile
440 index d73aed0fc99c1..93076a66ad6a5 100644
443 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
444 mm_init.o percpu.o slab_common.o \
445 compaction.o vmacache.o \
446 interval_tree.o list_lru.o workingset.o \
447 - debug.o gup.o $(mmu-y)
448 + prfile.o debug.o gup.o $(mmu-y)
450 # Give 'page_alloc' its own module-parameter namespace
451 page-alloc-y := page_alloc.o
452 diff --git a/mm/filemap.c b/mm/filemap.c
453 index 0b2067b3c3283..3334207431c79 100644
456 @@ -2909,7 +2909,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
457 vm_fault_t ret = VM_FAULT_LOCKED;
459 sb_start_pagefault(inode->i_sb);
460 - file_update_time(vmf->vma->vm_file);
461 + vma_file_update_time(vmf->vma);
463 if (page->mapping != inode->i_mapping) {
465 diff --git a/mm/mmap.c b/mm/mmap.c
466 index 5c8b4485860de..59f2f758d77e5 100644
469 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
470 if (vma->vm_ops && vma->vm_ops->close)
471 vma->vm_ops->close(vma);
473 - fput(vma->vm_file);
475 mpol_put(vma_policy(vma));
478 @@ -951,7 +951,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
481 uprobe_munmap(next, next->vm_start, next->vm_end);
486 anon_vma_merge(vma, next);
487 @@ -1897,8 +1897,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
495 /* Undo any partial mapping done by a device driver. */
496 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
497 @@ -2757,7 +2757,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
501 - get_file(new->vm_file);
504 if (new->vm_ops && new->vm_ops->open)
505 new->vm_ops->open(new);
506 @@ -2776,7 +2776,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
507 if (new->vm_ops && new->vm_ops->close)
508 new->vm_ops->close(new);
510 - fput(new->vm_file);
512 unlink_anon_vmas(new);
514 mpol_put(vma_policy(new));
515 @@ -2969,7 +2969,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
516 struct vm_area_struct *vma;
517 unsigned long populate = 0;
518 unsigned long ret = -EINVAL;
520 + struct file *file, *prfile;
522 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
523 current->comm, current->pid);
524 @@ -3044,10 +3044,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
528 - file = get_file(vma->vm_file);
530 + file = vma->vm_file;
531 + prfile = vma->vm_prfile;
532 ret = do_mmap(vma->vm_file, start, size,
533 prot, flags, pgoff, &populate, NULL);
534 + if (!IS_ERR_VALUE(ret) && file && prfile) {
535 + struct vm_area_struct *new_vma;
537 + new_vma = find_vma(mm, ret);
538 + if (!new_vma->vm_prfile)
539 + new_vma->vm_prfile = prfile;
540 + if (new_vma != vma)
544 + * two fput()s instead of vma_fput(vma),
545 + * coz vma may not be available anymore.
551 mmap_write_unlock(mm);
553 @@ -3334,7 +3351,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
554 if (anon_vma_clone(new_vma, vma))
555 goto out_free_mempol;
556 if (new_vma->vm_file)
557 - get_file(new_vma->vm_file);
558 + vma_get_file(new_vma);
559 if (new_vma->vm_ops && new_vma->vm_ops->open)
560 new_vma->vm_ops->open(new_vma);
561 vma_link(mm, new_vma, prev, rb_link, rb_parent);
562 diff --git a/mm/nommu.c b/mm/nommu.c
563 index 0faf39b32cdb9..78ecad7204c86 100644
566 @@ -533,7 +533,7 @@ static void __put_nommu_region(struct vm_region *region)
567 up_write(&nommu_region_sem);
570 - fput(region->vm_file);
573 /* IO memory and memory shared directly out of the pagecache
574 * from ramfs/tmpfs mustn't be released here */
575 @@ -665,7 +665,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
576 if (vma->vm_ops && vma->vm_ops->close)
577 vma->vm_ops->close(vma);
579 - fput(vma->vm_file);
581 put_nommu_region(vma->vm_region);
584 @@ -1188,7 +1188,7 @@ unsigned long do_mmap(struct file *file,
585 goto error_just_free;
588 - fput(region->vm_file);
590 kmem_cache_free(vm_region_jar, region);
593 @@ -1265,10 +1265,10 @@ unsigned long do_mmap(struct file *file,
594 up_write(&nommu_region_sem);
597 - fput(region->vm_file);
599 kmem_cache_free(vm_region_jar, region);
601 - fput(vma->vm_file);
606 diff --git a/mm/prfile.c b/mm/prfile.c
608 index 0000000000000..00d51187c3250
612 +// SPDX-License-Identifier: GPL-2.0
614 + * Mainly for aufs which mmap(2) different file and wants to print different
615 + * path in /proc/PID/maps.
616 + * Call these functions via macros defined in linux/mm.h.
618 + * See Documentation/filesystems/aufs/design/06mmap.txt
620 + * Copyright (c) 2014-2020 Junjro R. Okajima
621 + * Copyright (c) 2014 Ian Campbell
624 +#include <linux/mm.h>
625 +#include <linux/file.h>
626 +#include <linux/fs.h>
628 +/* #define PRFILE_TRACE */
629 +static inline void prfile_trace(struct file *f, struct file *pr,
630 + const char func[], int line, const char func2[])
634 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
638 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
641 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
643 + prfile_trace(f, pr, func, line, __func__);
644 + file_update_time(f);
646 + file_update_time(pr);
649 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
652 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
654 + prfile_trace(f, pr, func, line, __func__);
655 + return (f && pr) ? pr : f;
658 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
660 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
662 + prfile_trace(f, pr, func, line, __func__);
668 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
670 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
679 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
682 + struct file *f = region->vm_file, *pr = region->vm_prfile;
684 + prfile_trace(f, pr, func, line, __func__);
685 + return (f && pr) ? pr : f;
688 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
690 + struct file *f = region->vm_file, *pr = region->vm_prfile;
692 + prfile_trace(f, pr, func, line, __func__);
697 +#endif /* !CONFIG_MMU */
698 SPDX-License-Identifier: GPL-2.0
699 aufs5.10 standalone patch
701 diff --git a/fs/dcache.c b/fs/dcache.c
702 index ddca6240e0db4..30dec552278dc 100644
705 @@ -1390,6 +1390,7 @@ void d_walk(struct dentry *parent, void *data,
709 +EXPORT_SYMBOL_GPL(d_walk);
712 struct vfsmount *mnt;
713 @@ -2935,6 +2936,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
715 write_sequnlock(&rename_lock);
717 +EXPORT_SYMBOL_GPL(d_exchange);
720 * d_ancestor - search for an ancestor
721 diff --git a/fs/exec.c b/fs/exec.c
722 index 547a2390baf54..18d51d0face68 100644
725 @@ -113,6 +113,7 @@ bool path_noexec(const struct path *path)
726 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
727 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
729 +EXPORT_SYMBOL_GPL(path_noexec);
733 diff --git a/fs/fcntl.c b/fs/fcntl.c
734 index 073ca6af500f3..b18afdf81e762 100644
737 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
741 +EXPORT_SYMBOL_GPL(setfl);
743 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
745 diff --git a/fs/file_table.c b/fs/file_table.c
746 index 709ada3151da5..27a3e3c9f2a82 100644
747 --- a/fs/file_table.c
748 +++ b/fs/file_table.c
749 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
751 return ERR_PTR(-ENFILE);
753 +EXPORT_SYMBOL_GPL(alloc_empty_file);
756 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
757 @@ -376,6 +377,7 @@ void __fput_sync(struct file *file)
761 +EXPORT_SYMBOL_GPL(__fput_sync);
763 void __init files_init(void)
765 diff --git a/fs/inode.c b/fs/inode.c
766 index e7f0c614a58f3..6fe0a92a4c93c 100644
769 @@ -1776,6 +1776,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags)
770 return inode->i_op->update_time(inode, time, flags);
771 return generic_update_time(inode, time, flags);
773 +EXPORT_SYMBOL_GPL(update_time);
776 * touch_atime - update the access time
777 diff --git a/fs/namespace.c b/fs/namespace.c
778 index 451dee24a546a..38078cbede431 100644
781 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
782 mnt_dec_writers(real_mount(mnt));
785 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
788 * mnt_drop_write - give up write access to a mount
789 @@ -797,6 +798,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
791 return check_mnt(real_mount(mnt));
793 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
796 * vfsmount lock must be held for write
797 @@ -1961,6 +1963,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
801 +EXPORT_SYMBOL_GPL(iterate_mounts);
803 static void lock_mnt_tree(struct mount *mnt)
805 diff --git a/fs/notify/group.c b/fs/notify/group.c
806 index a4a4b1c64d32a..86dc2efb1850c 100644
807 --- a/fs/notify/group.c
808 +++ b/fs/notify/group.c
809 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
811 refcount_inc(&group->refcnt);
813 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
816 * Drop a reference to a group. Free it if it's through.
817 diff --git a/fs/open.c b/fs/open.c
818 index 9af548fb841b0..2ff09b709f7bf 100644
821 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
822 inode_unlock(dentry->d_inode);
825 +EXPORT_SYMBOL_GPL(do_truncate);
827 long vfs_truncate(const struct path *path, loff_t length)
829 diff --git a/fs/read_write.c b/fs/read_write.c
830 index 75f764b434184..7582bb3fb634b 100644
831 --- a/fs/read_write.c
832 +++ b/fs/read_write.c
833 @@ -503,6 +503,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
837 +EXPORT_SYMBOL_GPL(vfs_read);
839 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
841 @@ -613,6 +614,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
842 file_end_write(file);
845 +EXPORT_SYMBOL_GPL(vfs_write);
847 /* file_ppos returns &file->f_pos or NULL if file is stream */
848 static inline loff_t *file_ppos(struct file *file)
849 diff --git a/fs/splice.c b/fs/splice.c
850 index 55b5356262085..c13ac0fbac318 100644
853 @@ -763,6 +763,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
854 return warn_unsupported(out, "write");
855 return out->f_op->splice_write(pipe, out, ppos, len, flags);
857 +EXPORT_SYMBOL_GPL(do_splice_from);
860 * Attempt to initiate a splice from a file to a pipe.
861 @@ -787,6 +788,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
862 return warn_unsupported(in, "read");
863 return in->f_op->splice_read(in, ppos, pipe, len, flags);
865 +EXPORT_SYMBOL_GPL(do_splice_to);
868 * splice_direct_to_actor - splices data directly between two non-pipes
869 diff --git a/fs/sync.c b/fs/sync.c
870 index b7b5a0a0df6ff..fa5c7fba7f1ba 100644
873 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
874 sb->s_op->sync_fs(sb, wait);
875 return __sync_blockdev(sb->s_bdev, wait);
877 +EXPORT_SYMBOL_GPL(__sync_filesystem);
880 * Write out and wait upon all dirty data associated with this
881 diff --git a/fs/xattr.c b/fs/xattr.c
882 index cd7a563e8bcd4..7d989d57b0f0d 100644
885 @@ -360,6 +360,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
886 *xattr_value = value;
889 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
892 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
893 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
894 index 7f006a47790cf..be002c3a30833 100644
895 --- a/kernel/locking/lockdep.c
896 +++ b/kernel/locking/lockdep.c
897 @@ -209,6 +209,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
899 return lock_classes + class_idx;
901 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
902 #define hlock_class(hlock) lockdep_hlock_class(hlock)
904 #ifdef CONFIG_LOCK_STAT
905 diff --git a/kernel/task_work.c b/kernel/task_work.c
906 index 8d6e1217c451c..0e73637adda86 100644
907 --- a/kernel/task_work.c
908 +++ b/kernel/task_work.c
909 @@ -154,3 +154,4 @@ void task_work_run(void)
913 +EXPORT_SYMBOL_GPL(task_work_run);
914 diff --git a/security/security.c b/security/security.c
915 index a28045dc9e7f6..310cf38efeec7 100644
916 --- a/security/security.c
917 +++ b/security/security.c
918 @@ -1093,6 +1093,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
920 return call_int_hook(path_rmdir, 0, dir, dentry);
922 +EXPORT_SYMBOL_GPL(security_path_rmdir);
924 int security_path_unlink(const struct path *dir, struct dentry *dentry)
926 @@ -1109,6 +1110,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
928 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
930 +EXPORT_SYMBOL_GPL(security_path_symlink);
932 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
933 struct dentry *new_dentry)
934 @@ -1117,6 +1119,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
936 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
938 +EXPORT_SYMBOL_GPL(security_path_link);
940 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
941 const struct path *new_dir, struct dentry *new_dentry,
942 @@ -1144,6 +1147,7 @@ int security_path_truncate(const struct path *path)
944 return call_int_hook(path_truncate, 0, path);
946 +EXPORT_SYMBOL_GPL(security_path_truncate);
948 int security_path_chmod(const struct path *path, umode_t mode)
950 @@ -1151,6 +1155,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
952 return call_int_hook(path_chmod, 0, path, mode);
954 +EXPORT_SYMBOL_GPL(security_path_chmod);
956 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
958 @@ -1158,6 +1163,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
960 return call_int_hook(path_chown, 0, path, uid, gid);
962 +EXPORT_SYMBOL_GPL(security_path_chown);
964 int security_path_chroot(const struct path *path)
966 @@ -1258,6 +1264,7 @@ int security_inode_permission(struct inode *inode, int mask)
968 return call_int_hook(inode_permission, 0, inode, mask);
970 +EXPORT_SYMBOL_GPL(security_inode_permission);
972 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
974 @@ -1450,6 +1457,7 @@ int security_file_permission(struct file *file, int mask)
976 return fsnotify_perm(file, mask);
978 +EXPORT_SYMBOL_GPL(security_file_permission);
980 int security_file_alloc(struct file *file)
982 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
983 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
984 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-02-22 22:51:59.054745247 +0100
986 +What: /debug/aufs/si_<id>/
988 +Contact: J. R. Okajima <hooanon05g@gmail.com>
990 + Under /debug/aufs, a directory named si_<id> is created
991 + per aufs mount, where <id> is a unique id generated
994 +What: /debug/aufs/si_<id>/plink
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It has three lines and shows the information about the
999 + pseudo-link. The first line is a single number
1000 + representing a number of buckets. The second line is a
1001 + number of pseudo-links per buckets (separated by a
1002 + blank). The last line is a single number representing a
1003 + total number of psedo-links.
1004 + When the aufs mount option 'noplink' is specified, it
1005 + will show "1\n0\n0\n".
1007 +What: /debug/aufs/si_<id>/xib
1009 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1011 + It shows the consumed blocks by xib (External Inode Number
1012 + Bitmap), its block size and file size.
1013 + When the aufs mount option 'noxino' is specified, it
1014 + will be empty. About XINO files, see the aufs manual.
1016 +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N
1018 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1020 + It shows the consumed blocks by xino (External Inode Number
1021 + Translation Table), its link count, block size and file
1023 + Due to the file size limit, there may exist multiple
1024 + xino files per branch. In this case, "-N" is added to
1025 + the filename and it corresponds to the index of the
1026 + internal xino array. "-0" is omitted.
1027 + When the aufs mount option 'noxino' is specified, Those
1028 + entries won't exist. About XINO files, see the aufs
1031 +What: /debug/aufs/si_<id>/xigen
1033 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1035 + It shows the consumed blocks by xigen (External Inode
1036 + Generation Table), its block size and file size.
1037 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1039 + When the aufs mount option 'noxino' is specified, it
1040 + will be empty. About XINO files, see the aufs manual.
1041 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1042 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1043 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-02-22 22:51:59.054745247 +0100
1045 +What: /sys/fs/aufs/si_<id>/
1047 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1049 + Under /sys/fs/aufs, a directory named si_<id> is created
1050 + per aufs mount, where <id> is a unique id generated
1053 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1055 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1057 + It shows the abolute path of a member directory (which
1058 + is called branch) in aufs, and its permission.
1060 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1062 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1064 + It shows the id of a member directory (which is called
1067 +What: /sys/fs/aufs/si_<id>/xi_path
1069 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1071 + It shows the abolute path of XINO (External Inode Number
1072 + Bitmap, Translation Table and Generation Table) file
1073 + even if it is the default path.
1074 + When the aufs mount option 'noxino' is specified, it
1075 + will be empty. About XINO files, see the aufs manual.
1076 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1077 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1078 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-02-22 22:51:59.054745247 +0100
1081 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1083 +# This program is free software; you can redistribute it and/or modify
1084 +# it under the terms of the GNU General Public License as published by
1085 +# the Free Software Foundation; either version 2 of the License, or
1086 +# (at your option) any later version.
1088 +# This program is distributed in the hope that it will be useful,
1089 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1090 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1091 +# GNU General Public License for more details.
1093 +# You should have received a copy of the GNU General Public License
1094 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1097 +----------------------------------------
1099 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1100 +1. abbrev. for "advanced multi-layered unification filesystem".
1101 +2. abbrev. for "another unionfs".
1102 +3. abbrev. for "auf das" in German which means "on the" in English.
1103 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1104 + But "Filesystem aufs Filesystem" is hard to understand.
1105 +4. abbrev. for "African Urban Fashion Show".
1107 +AUFS is a filesystem with features:
1108 +- multi layered stackable unification filesystem, the member directory
1109 + is called as a branch.
1110 +- branch permission and attribute, 'readonly', 'real-readonly',
1111 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1113 +- internal "file copy-on-write".
1114 +- logical deletion, whiteout.
1115 +- dynamic branch manipulation, adding, deleting and changing permission.
1116 +- allow bypassing aufs, user's direct branch access.
1117 +- external inode number translation table and bitmap which maintains the
1118 + persistent aufs inode number.
1119 +- seekable directory, including NFS readdir.
1120 +- file mapping, mmap and sharing pages.
1121 +- pseudo-link, hardlink over branches.
1122 +- loopback mounted filesystem as a branch.
1123 +- several policies to select one among multiple writable branches.
1124 +- revert a single systemcall when an error occurs in aufs.
1128 +Multi Layered Stackable Unification Filesystem
1129 +----------------------------------------------------------------------
1130 +Most people already knows what it is.
1131 +It is a filesystem which unifies several directories and provides a
1132 +merged single directory. When users access a file, the access will be
1133 +passed/re-directed/converted (sorry, I am not sure which English word is
1134 +correct) to the real file on the member filesystem. The member
1135 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1136 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1137 +readonly branch is handled by creating 'whiteout' on the upper writable
1140 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1141 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1142 +different approaches to implement the merged-view.
1143 +The former tries putting it into VFS, and the latter implements as a
1144 +separate filesystem.
1145 +(If I misunderstand about these implementations, please let me know and
1146 +I shall correct it. Because it is a long time ago when I read their
1147 +source files last time).
1149 +UnionMount's approach will be able to small, but may be hard to share
1150 +branches between several UnionMount since the whiteout in it is
1151 +implemented in the inode on branch filesystem and always
1152 +shared. According to Bharata's post, readdir does not seems to be
1154 +There are several missing features known in this implementations such as
1155 +- for users, the inode number may change silently. eg. copy-up.
1156 +- link(2) may break by copy-up.
1157 +- read(2) may get an obsoleted filedata (fstat(2) too).
1158 +- fcntl(F_SETLK) may be broken by copy-up.
1159 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1162 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1163 +merged into mainline. This is another implementation of UnionMount as a
1164 +separated filesystem. All the limitations and known problems which
1165 +UnionMount are equally inherited to "overlay" filesystem.
1167 +Unionfs has a longer history. When I started implementing a stackable
1168 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1169 +inode, dentry and file objects and they have an array pointing lower
1170 +same kind objects. After contributing many patches for Unionfs, I
1171 +re-started my project AUFS (Jun 2006).
1173 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1174 +implemented my own ideas, approaches and enhancements and it became
1175 +totally different one.
1177 +Comparing DM snapshot and fs based implementation
1178 +- the number of bytes to be copied between devices is much smaller.
1179 +- the type of filesystem must be one and only.
1180 +- the fs must be writable, no readonly fs, even for the lower original
1181 + device. so the compression fs will not be usable. but if we use
1182 + loopback mount, we may address this issue.
1184 + mount /cdrom/squashfs.img /sq
1185 + losetup /sq/ext2.img
1186 + losetup /somewhere/cow
1187 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1188 +- it will be difficult (or needs more operations) to extract the
1189 + difference between the original device and COW.
1190 +- DM snapshot-merge may help a lot when users try merging. in the
1191 + fs-layer union, users will use rsync(1).
1193 +You may want to read my old paper "Filesystems in LiveCD"
1194 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1197 +Several characters/aspects/persona of aufs
1198 +----------------------------------------------------------------------
1200 +Aufs has several characters, aspects or persona.
1201 +1. a filesystem, callee of VFS helper
1202 +2. sub-VFS, caller of VFS helper for branches
1203 +3. a virtual filesystem which maintains persistent inode number
1204 +4. reader/writer of files on branches such like an application
1206 +1. Callee of VFS Helper
1207 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1208 +unlink(2) from an application reaches sys_unlink() kernel function and
1209 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1210 +calls filesystem specific unlink operation. Actually aufs implements the
1211 +unlink operation but it behaves like a redirector.
1213 +2. Caller of VFS Helper for Branches
1214 +aufs_unlink() passes the unlink request to the branch filesystem as if
1215 +it were called from VFS. So the called unlink operation of the branch
1216 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1217 +every necessary pre/post operation for the branch filesystem.
1218 +- acquire the lock for the parent dir on a branch
1219 +- lookup in a branch
1220 +- revalidate dentry on a branch
1221 +- mnt_want_write() for a branch
1222 +- vfs_unlink() for a branch
1223 +- mnt_drop_write() for a branch
1224 +- release the lock on a branch
1226 +3. Persistent Inode Number
1227 +One of the most important issue for a filesystem is to maintain inode
1228 +numbers. This is particularly important to support exporting a
1229 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1230 +backend block device for its own. But some storage is necessary to
1231 +keep and maintain the inode numbers. It may be a large space and may not
1232 +suit to keep in memory. Aufs rents some space from its first writable
1233 +branch filesystem (by default) and creates file(s) on it. These files
1234 +are created by aufs internally and removed soon (currently) keeping
1236 +Note: Because these files are removed, they are totally gone after
1237 + unmounting aufs. It means the inode numbers are not persistent
1238 + across unmount or reboot. I have a plan to make them really
1239 + persistent which will be important for aufs on NFS server.
1241 +4. Read/Write Files Internally (copy-on-write)
1242 +Because a branch can be readonly, when you write a file on it, aufs will
1243 +"copy-up" it to the upper writable branch internally. And then write the
1244 +originally requested thing to the file. Generally kernel doesn't
1245 +open/read/write file actively. In aufs, even a single write may cause a
1246 +internal "file copy". This behaviour is very similar to cp(1) command.
1248 +Some people may think it is better to pass such work to user space
1249 +helper, instead of doing in kernel space. Actually I am still thinking
1250 +about it. But currently I have implemented it in kernel space.
1251 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1252 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1253 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-02-22 22:51:59.058078584 +0100
1256 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1258 +# This program is free software; you can redistribute it and/or modify
1259 +# it under the terms of the GNU General Public License as published by
1260 +# the Free Software Foundation; either version 2 of the License, or
1261 +# (at your option) any later version.
1263 +# This program is distributed in the hope that it will be useful,
1264 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1265 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1266 +# GNU General Public License for more details.
1268 +# You should have received a copy of the GNU General Public License
1269 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1271 +Basic Aufs Internal Structure
1273 +Superblock/Inode/Dentry/File Objects
1274 +----------------------------------------------------------------------
1275 +As like an ordinary filesystem, aufs has its own
1276 +superblock/inode/dentry/file objects. All these objects have a
1277 +dynamically allocated array and store the same kind of pointers to the
1278 +lower filesystem, branch.
1279 +For example, when you build a union with one readwrite branch and one
1280 +readonly, mounted /au, /rw and /ro respectively.
1282 +- /ro/fileA exists but /rw/fileA
1284 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1285 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1286 +- [0] = NULL (because /rw/fileA doesn't exist)
1289 +This style of an array is essentially same to the aufs
1290 +superblock/inode/dentry/file objects.
1292 +Because aufs supports manipulating branches, ie. add/delete/change
1293 +branches dynamically, these objects has its own generation. When
1294 +branches are changed, the generation in aufs superblock is
1295 +incremented. And a generation in other object are compared when it is
1296 +accessed. When a generation in other objects are obsoleted, aufs
1297 +refreshes the internal array.
1301 +----------------------------------------------------------------------
1302 +Additionally aufs superblock has some data for policies to select one
1303 +among multiple writable branches, XIB files, pseudo-links and kobject.
1304 +See below in detail.
1305 +About the policies which supports copy-down a directory, see
1306 +wbr_policy.txt too.
1309 +Branch and XINO(External Inode Number Translation Table)
1310 +----------------------------------------------------------------------
1311 +Every branch has its own xino (external inode number translation table)
1312 +file. The xino file is created and unlinked by aufs internally. When two
1313 +members of a union exist on the same filesystem, they share the single
1315 +The struct of a xino file is simple, just a sequence of aufs inode
1316 +numbers which is indexed by the lower inode number.
1317 +In the above sample, assume the inode number of /ro/fileA is i111 and
1318 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1319 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1321 +When the inode numbers are not contiguous, the xino file will be sparse
1322 +which has a hole in it and doesn't consume as much disk space as it
1323 +might appear. If your branch filesystem consumes disk space for such
1324 +holes, then you should specify 'xino=' option at mounting aufs.
1326 +Aufs has a mount option to free the disk blocks for such holes in XINO
1327 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1328 +meet a problem of disk shortage due to XINO files, then you should try
1329 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1330 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1331 +the holes in XINO files.
1333 +Also a writable branch has three kinds of "whiteout bases". All these
1334 +are existed when the branch is joined to aufs, and their names are
1335 +whiteout-ed doubly, so that users will never see their names in aufs
1337 +1. a regular file which will be hardlinked to all whiteouts.
1338 +2. a directory to store a pseudo-link.
1339 +3. a directory to store an "orphan"-ed file temporary.
1342 + When you remove a file on a readonly branch, aufs handles it as a
1343 + logical deletion and creates a whiteout on the upper writable branch
1344 + as a hardlink of this file in order not to consume inode on the
1347 + See below, Pseudo-link.
1349 + When "fileC" exists on the lower readonly branch only and it is
1350 + opened and removed with its parent dir, and then user writes
1351 + something into it, then aufs copies-up fileC to this
1352 + directory. Because there is no other dir to store fileC. After
1353 + creating a file under this dir, the file is unlinked.
1355 +Because aufs supports manipulating branches, ie. add/delete/change
1356 +dynamically, a branch has its own id. When the branch order changes,
1357 +aufs finds the new index by searching the branch id.
1361 +----------------------------------------------------------------------
1362 +Assume "fileA" exists on the lower readonly branch only and it is
1363 +hardlinked to "fileB" on the branch. When you write something to fileA,
1364 +aufs copies-up it to the upper writable branch. Additionally aufs
1365 +creates a hardlink under the Pseudo-link Directory of the writable
1366 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1367 +simple list. If fileB is read after unlinking fileA, aufs returns
1368 +filedata from the pseudo-link instead of the lower readonly
1369 +branch. Because the pseudo-link is based upon the inode, to keep the
1370 +inode number by xino (see above) is essentially necessary.
1372 +All the hardlinks under the Pseudo-link Directory of the writable branch
1373 +should be restored in a proper location later. Aufs provides a utility
1374 +to do this. The userspace helpers executed at remounting and unmounting
1376 +During this utility is running, it puts aufs into the pseudo-link
1377 +maintenance mode. In this mode, only the process which began the
1378 +maintenance mode (and its child processes) is allowed to operate in
1379 +aufs. Some other processes which are not related to the pseudo-link will
1380 +be allowed to run too, but the rest have to return an error or wait
1381 +until the maintenance mode ends. If a process already acquires an inode
1382 +mutex (in VFS), it has to return an error.
1385 +XIB(external inode number bitmap)
1386 +----------------------------------------------------------------------
1387 +Addition to the xino file per a branch, aufs has an external inode number
1388 +bitmap in a superblock object. It is also an internal file such like a
1390 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1392 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1394 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1395 +reduce the number of consumed disk blocks for these files.
1398 +Virtual or Vertical Dir, and Readdir in Userspace
1399 +----------------------------------------------------------------------
1400 +In order to support multiple layers (branches), aufs readdir operation
1401 +constructs a virtual dir block on memory. For readdir, aufs calls
1402 +vfs_readdir() internally for each dir on branches, merges their entries
1403 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1404 +object. So the file object has its entry list until it is closed. The
1405 +entry list will be updated when the file position is zero and becomes
1406 +obsoleted. This decision is made in aufs automatically.
1408 +The dynamically allocated memory block for the name of entries has a
1409 +unit of 512 bytes (by default) and stores the names contiguously (no
1410 +padding). Another block for each entry is handled by kmem_cache too.
1411 +During building dir blocks, aufs creates hash list and judging whether
1412 +the entry is whiteouted by its upper branch or already listed.
1413 +The merged result is cached in the corresponding inode object and
1414 +maintained by a customizable life-time option.
1416 +Some people may call it can be a security hole or invite DoS attack
1417 +since the opened and once readdir-ed dir (file object) holds its entry
1418 +list and becomes a pressure for system memory. But I'd say it is similar
1419 +to files under /proc or /sys. The virtual files in them also holds a
1420 +memory page (generally) while they are opened. When an idea to reduce
1421 +memory for them is introduced, it will be applied to aufs too.
1422 +For those who really hate this situation, I've developed readdir(3)
1423 +library which operates this merging in userspace. You just need to set
1424 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1425 +kernel space for readdir(3).
1429 +----------------------------------------------------------------------
1430 +Aufs sometimes requires privilege access to a branch. For instance,
1431 +in copy-up/down operation. When a user process is going to make changes
1432 +to a file which exists in the lower readonly branch only, and the mode
1433 +of one of ancestor directories may not be writable by a user
1434 +process. Here aufs copy-up the file with its ancestors and they may
1435 +require privilege to set its owner/group/mode/etc.
1436 +This is a typical case of a application character of aufs (see
1439 +Aufs uses workqueue synchronously for this case. It creates its own
1440 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1441 +passes the request to call mkdir or write (for example), and wait for
1442 +its completion. This approach solves a problem of a signal handler
1444 +If aufs didn't adopt the workqueue and changed the privilege of the
1445 +process, then the process may receive the unexpected SIGXFSZ or other
1448 +Also aufs uses the system global workqueue ("events" kernel thread) too
1449 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1450 +whiteout base and etc. This is unrelated to a privilege.
1451 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1452 +superblock at the beginning, at the same time waits for the completion
1453 +of all queued asynchronous tasks.
1457 +----------------------------------------------------------------------
1458 +The whiteout in aufs is very similar to Unionfs's. That is represented
1459 +by its filename. UnionMount takes an approach of a file mode, but I am
1460 +afraid several utilities (find(1) or something) will have to support it.
1462 +Basically the whiteout represents "logical deletion" which stops aufs to
1463 +lookup further, but also it represents "dir is opaque" which also stop
1466 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1467 +In order to make several functions in a single systemcall to be
1468 +revertible, aufs adopts an approach to rename a directory to a temporary
1469 +unique whiteouted name.
1470 +For example, in rename(2) dir where the target dir already existed, aufs
1471 +renames the target dir to a temporary unique whiteouted name before the
1472 +actual rename on a branch, and then handles other actions (make it opaque,
1473 +update the attributes, etc). If an error happens in these actions, aufs
1474 +simply renames the whiteouted name back and returns an error. If all are
1475 +succeeded, aufs registers a function to remove the whiteouted unique
1476 +temporary name completely and asynchronously to the system global
1481 +----------------------------------------------------------------------
1482 +It is a well-known feature or concept.
1483 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1484 +internally and makes change to the new file on the upper writable branch.
1485 +When the trigger systemcall does not update the timestamps of the parent
1486 +dir, aufs reverts it after copy-up.
1489 +Move-down (aufs3.9 and later)
1490 +----------------------------------------------------------------------
1491 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1492 +the lower readonly branch to the upper writable branch when a user
1493 +changes something about the file.
1494 +"Move-down" is an opposite action of copy-up. Basically this action is
1495 +ran manually instead of automatically and internally.
1496 +For desgin and implementation, aufs has to consider these issues.
1497 +- whiteout for the file may exist on the lower branch.
1498 +- ancestor directories may not exist on the lower branch.
1499 +- diropq for the ancestor directories may exist on the upper branch.
1500 +- free space on the lower branch will reduce.
1501 +- another access to the file may happen during moving-down, including
1502 + UDBA (see "Revalidate Dentry and UDBA").
1503 +- the file should not be hard-linked nor pseudo-linked. they should be
1504 + handled by auplink utility later.
1506 +Sometimes users want to move-down a file from the upper writable branch
1507 +to the lower readonly or writable branch. For instance,
1508 +- the free space of the upper writable branch is going to run out.
1509 +- create a new intermediate branch between the upper and lower branch.
1512 +For this purpose, use "aumvdown" command in aufs-util.git.
1513 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1514 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1515 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-02-22 22:51:59.058078584 +0100
1518 +# Copyright (C) 2015-2020 Junjiro R. Okajima
1520 +# This program is free software; you can redistribute it and/or modify
1521 +# it under the terms of the GNU General Public License as published by
1522 +# the Free Software Foundation; either version 2 of the License, or
1523 +# (at your option) any later version.
1525 +# This program is distributed in the hope that it will be useful,
1526 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1527 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1528 +# GNU General Public License for more details.
1530 +# You should have received a copy of the GNU General Public License
1531 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1533 +Support for a branch who has its ->atomic_open()
1534 +----------------------------------------------------------------------
1535 +The filesystems who implement its ->atomic_open() are not majority. For
1536 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1537 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1538 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1539 +sure whether all filesystems who have ->atomic_open() behave like this,
1540 +but NFSv4 surely returns the error.
1542 +In order to support ->atomic_open() for aufs, there are a few
1545 +A. Introduce aufs_atomic_open()
1546 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1548 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1549 + an aufs user Pip Cet's approach
1550 + - calls aufs_create(), VFS finish_open() and notify_change().
1551 + - pass fake-mode to finish_open(), and then correct the mode by
1553 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1554 + - no aufs_atomic_open().
1555 + - aufs_lookup() registers the TID to an aufs internal object.
1556 + - aufs_create() does nothing when the matching TID is registered, but
1557 + registers the mode.
1558 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1559 + TID is registered.
1560 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1562 + - no aufs_atomic_open().
1563 + - aufs_create() registers the TID to an internal object. this info
1564 + represents "this process created this file just now."
1565 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1566 + registered TID and re-try open() with superuser's credential.
1568 +Pros and cons for each approach.
1571 + - straightforward but highly depends upon VFS internal.
1572 + - the atomic behavaiour is kept.
1573 + - some of parameters such as nameidata are hard to reproduce for
1577 + - easy to implement.
1578 + - the atomic behavaiour is lost.
1580 + - the atomic behavaiour is kept.
1581 + - dirty and tricky.
1582 + - VFS checks whether the file is created correctly after calling
1583 + ->create(), which means this approach doesn't work.
1585 + - easy to implement.
1586 + - the atomic behavaiour is lost.
1587 + - to open a file with superuser's credential and give it to a user
1588 + process is a bad idea, since the file object keeps the credential
1589 + in it. It may affect LSM or something. This approach doesn't work
1592 +The approach A is ideal, but it hard to implement. So here is a
1593 +variation of A, which is to be implemented.
1595 +A-1. Introduce aufs_atomic_open()
1596 + - calls branch fs ->atomic_open() if exists. otherwise calls
1597 + vfs_create() and finish_open().
1598 + - the demerit is that the several checks after branch fs
1599 + ->atomic_open() are lost. in the ordinary case, the checks are
1600 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1601 + be implemented in aufs, but not all I am afraid.
1602 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1603 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1604 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-02-22 22:51:59.058078584 +0100
1607 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1609 +# This program is free software; you can redistribute it and/or modify
1610 +# it under the terms of the GNU General Public License as published by
1611 +# the Free Software Foundation; either version 2 of the License, or
1612 +# (at your option) any later version.
1614 +# This program is distributed in the hope that it will be useful,
1615 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1616 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1617 +# GNU General Public License for more details.
1619 +# You should have received a copy of the GNU General Public License
1620 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1623 +----------------------------------------------------------------------
1624 +Since aufs has a character of sub-VFS (see Introduction), it operates
1625 +lookup for branches as VFS does. It may be a heavy work. But almost all
1626 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1627 +directly connected to its parent. Digging down the directory hierarchy
1628 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1631 +When a branch is a remote filesystem, aufs basically relies upon its
1632 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1634 +For d_revalidate, aufs implements three levels of revalidate tests. See
1635 +"Revalidate Dentry and UDBA" in detail.
1638 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1639 +----------------------------------------------------------------------
1640 +Let's try case study.
1641 +- aufs has two branches, upper readwrite and lower readonly.
1643 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1644 +- user invoked "chmod a+rx /au/dirA"
1645 +- the internal copy-up is activated and "/rw/dirA" is created and its
1646 + permission bits are set to world readable.
1647 +- then "/au/dirA" becomes world readable?
1649 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1650 +or it may be a natively readonly filesystem. If aufs respects the lower
1651 +branch, it should not respond readdir request from other users. But user
1652 +allowed it by chmod. Should really aufs rejects showing the entries
1655 +To be honest, I don't have a good solution for this case. So aufs
1656 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1658 +When dirperm1 is specified, aufs checks only the highest one for the
1659 +directory permission, and shows the entries. Otherwise, as usual, checks
1660 +every dir existing on all branches and rejects the request.
1662 +As a side effect, dirperm1 option improves the performance of aufs
1663 +because the number of permission check is reduced when the number of
1667 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1668 +----------------------------------------------------------------------
1669 +Generally VFS helpers re-validate a dentry as a part of lookup.
1670 +0. digging down the directory hierarchy.
1671 +1. lock the parent dir by its i_mutex.
1672 +2. lookup the final (child) entry.
1674 +4. call the actual operation (create, unlink, etc.)
1675 +5. unlock the parent dir
1677 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1678 +called. Actually aufs implements it and checks the dentry on a branch is
1680 +But it is not enough. Because aufs has to release the lock for the
1681 +parent dir on a branch at the end of ->lookup() (step 2) and
1682 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1684 +If the file on a branch is changed directly, eg. bypassing aufs, after
1685 +aufs released the lock, then the subsequent operation may cause
1686 +something unpleasant result.
1688 +This situation is a result of VFS architecture, ->lookup() and
1689 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1690 +design from VFS's point of view. It is just not suitable for sub-VFS
1693 +Aufs supports such case by three level of revalidation which is
1694 +selectable by user.
1695 +1. Simple Revalidate
1696 + Addition to the native flow in VFS's, confirm the child-parent
1697 + relationship on the branch just after locking the parent dir on the
1698 + branch in the "actual operation" (step 4). When this validation
1699 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1700 + checks the validation of the dentry on branches.
1701 +2. Monitor Changes Internally by Inotify/Fsnotify
1702 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1703 + the dentry on the branch, and returns EBUSY if it finds different
1705 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1706 + during it is in cache. When the event is notified, aufs registers a
1707 + function to kernel 'events' thread by schedule_work(). And the
1708 + function sets some special status to the cached aufs dentry and inode
1709 + private data. If they are not cached, then aufs has nothing to
1710 + do. When the same file is accessed through aufs (step 0-3) later,
1711 + aufs will detect the status and refresh all necessary data.
1712 + In this mode, aufs has to ignore the event which is fired by aufs
1714 +3. No Extra Validation
1715 + This is the simplest test and doesn't add any additional revalidation
1716 + test, and skip the revalidation in step 4. It is useful and improves
1717 + aufs performance when system surely hide the aufs branches from user,
1718 + by over-mounting something (or another method).
1719 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1720 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1721 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-02-22 22:51:59.058078584 +0100
1724 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1726 +# This program is free software; you can redistribute it and/or modify
1727 +# it under the terms of the GNU General Public License as published by
1728 +# the Free Software Foundation; either version 2 of the License, or
1729 +# (at your option) any later version.
1731 +# This program is distributed in the hope that it will be useful,
1732 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1733 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1734 +# GNU General Public License for more details.
1736 +# You should have received a copy of the GNU General Public License
1737 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1739 +Branch Manipulation
1741 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1742 +and changing its permission/attribute, there are a lot of works to do.
1746 +----------------------------------------------------------------------
1747 +o Confirm the adding dir exists outside of aufs, including loopback
1748 + mount, and its various attributes.
1749 +o Initialize the xino file and whiteout bases if necessary.
1752 +o Check the owner/group/mode of the directory
1753 + When the owner/group/mode of the adding directory differs from the
1754 + existing branch, aufs issues a warning because it may impose a
1756 + For example, when a upper writable branch has a world writable empty
1757 + top directory, a malicious user can create any files on the writable
1758 + branch directly, like copy-up and modify manually. If something like
1759 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1760 + writable branch, and the writable branch is world-writable, then a
1761 + malicious guy may create /etc/passwd on the writable branch directly
1762 + and the infected file will be valid in aufs.
1763 + I am afraid it can be a security issue, but aufs can do nothing except
1764 + producing a warning.
1768 +----------------------------------------------------------------------
1769 +o Confirm the deleting branch is not busy
1770 + To be general, there is one merit to adopt "remount" interface to
1771 + manipulate branches. It is to discard caches. At deleting a branch,
1772 + aufs checks the still cached (and connected) dentries and inodes. If
1773 + there are any, then they are all in-use. An inode without its
1774 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1776 + For the cached one, aufs checks whether the same named entry exists on
1778 + If the cached one is a directory, because aufs provides a merged view
1779 + to users, as long as one dir is left on any branch aufs can show the
1780 + dir to users. In this case, the branch can be removed from aufs.
1781 + Otherwise aufs rejects deleting the branch.
1783 + If any file on the deleting branch is opened by aufs, then aufs
1787 +Modify the Permission of a Branch
1788 +----------------------------------------------------------------------
1789 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1792 +o rw --> ro: Confirm the modifying branch is not busy
1793 + Aufs rejects the request if any of these conditions are true.
1794 + - a file on the branch is mmap-ed.
1795 + - a regular file on the branch is opened for write and there is no
1796 + same named entry on the upper branch.
1797 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1798 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1799 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-02-22 22:51:59.058078584 +0100
1802 +# Copyright (C) 2005-2020 Junjiro R. Okajima
1804 +# This program is free software; you can redistribute it and/or modify
1805 +# it under the terms of the GNU General Public License as published by
1806 +# the Free Software Foundation; either version 2 of the License, or
1807 +# (at your option) any later version.
1809 +# This program is distributed in the hope that it will be useful,
1810 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1811 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1812 +# GNU General Public License for more details.
1814 +# You should have received a copy of the GNU General Public License
1815 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1817 +Policies to Select One among Multiple Writable Branches
1818 +----------------------------------------------------------------------
1819 +When the number of writable branch is more than one, aufs has to decide
1820 +the target branch for file creation or copy-up. By default, the highest
1821 +writable branch which has the parent (or ancestor) dir of the target
1822 +file is chosen (top-down-parent policy).
1823 +By user's request, aufs implements some other policies to select the
1824 +writable branch, for file creation several policies, round-robin,
1825 +most-free-space, and other policies. For copy-up, top-down-parent,
1826 +bottom-up-parent, bottom-up and others.
1828 +As expected, the round-robin policy selects the branch in circular. When
1829 +you have two writable branches and creates 10 new files, 5 files will be
1830 +created for each branch. mkdir(2) systemcall is an exception. When you
1831 +create 10 new directories, all will be created on the same branch.
1832 +And the most-free-space policy selects the one which has most free
1833 +space among the writable branches. The amount of free space will be
1834 +checked by aufs internally, and users can specify its time interval.
1836 +The policies for copy-up is more simple,
1837 +top-down-parent is equivalent to the same named on in create policy,
1838 +bottom-up-parent selects the writable branch where the parent dir
1839 +exists and the nearest upper one from the copyup-source,
1840 +bottom-up selects the nearest upper writable branch from the
1841 +copyup-source, regardless the existence of the parent dir.
1843 +There are some rules or exceptions to apply these policies.
1844 +- If there is a readonly branch above the policy-selected branch and
1845 + the parent dir is marked as opaque (a variation of whiteout), or the
1846 + target (creating) file is whiteout-ed on the upper readonly branch,
1847 + then the result of the policy is ignored and the target file will be
1848 + created on the nearest upper writable branch than the readonly branch.
1849 +- If there is a writable branch above the policy-selected branch and
1850 + the parent dir is marked as opaque or the target file is whiteouted
1851 + on the branch, then the result of the policy is ignored and the target
1852 + file will be created on the highest one among the upper writable
1853 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1855 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1856 + They try selecting the branch where the source exists as possible
1857 + since copyup a large file will take long time. If it can't be,
1858 + ie. the branch where the source exists is readonly, then they will
1859 + follow the copyup policy.
1860 +- There is an exception for rename(2) when the target exists.
1861 + If the rename target exists, aufs compares the index of the branches
1862 + where the source and the target exists and selects the higher
1863 + one. If the selected branch is readonly, then aufs follows the
1865 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1866 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1867 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-02-22 22:51:59.058078584 +0100
1870 +// to view this graph, run dot(1) command in GRAPHVIZ.
1874 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1878 +aufs_rename -> whinfo [label="store/remove"];
1881 +inode_list [label="h_inum list in branch\ncache"];
1884 +whinode [label="h_inum list file"];
1887 +brmgmt [label="br_add/del/mod/umount"];
1889 +brmgmt -> inode_list [label="create/remove"];
1890 +brmgmt -> whinode [label="load/store"];
1892 +inode_list -> whinode [style=dashed,dir=both];
1894 +aufs_rename -> inode_list [label="add/del"];
1896 +aufs_lookup -> inode_list [label="search"];
1898 +aufs_lookup -> whinfo [label="load/remove"];
1900 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1901 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1902 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-02-22 22:51:59.058078584 +0100
1905 +# Copyright (C) 2017-2020 Junjiro R. Okajima
1907 +# This program is free software; you can redistribute it and/or modify
1908 +# it under the terms of the GNU General Public License as published by
1909 +# the Free Software Foundation; either version 2 of the License, or
1910 +# (at your option) any later version.
1912 +# This program is distributed in the hope that it will be useful,
1913 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1914 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1915 +# GNU General Public License for more details.
1917 +# You should have received a copy of the GNU General Public License
1918 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1920 +Special handling for renaming a directory (DIRREN)
1921 +----------------------------------------------------------------------
1922 +First, let's assume we have a simple usecase.
1926 +- /ro/dirA and /ro/dirA/file exist too
1927 +- there is no dirB on both branches
1928 +- a user issues rename("dirA", "dirB")
1930 +Now, what should aufs behave against this rename(2)?
1931 +There are a few possible cases.
1934 + since dirA exists on a readonly branch which cannot be renamed.
1936 + it is possible to copy-up dirA (only the dir itself), but the child
1937 + entries ("file" in this case) should not be. it must be a bad
1938 + approach to copy-up recursively.
1939 +C. returns a success.
1940 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1941 + is a violation of aufs' policy.
1942 +D. construct an extra information which indicates that /ro/dirA should
1943 + be handled as the name of dirB.
1944 + overlayfs has a similar feature called REDIRECT.
1946 +Until now, aufs implements the case B only which returns EXDEV, and
1947 +expects the userspace application behaves like mv(1) which tries
1948 +issueing rename(2) recursively.
1950 +A new aufs feature called DIRREN is introduced which implements the case
1951 +D. There are several "extra information" added.
1953 +1. detailed info per renamed directory
1954 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1955 +2. the inode-number list of directories on a branch
1956 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1958 +The filename of "detailed info per directory" represents the lower
1959 +branch, and its format is
1960 +- a type of the branch id
1962 + + uuid (not implemented yet)
1965 +- the inode-number of the branch root dir
1967 +And it contains these info in a single regular file.
1969 +- branch's inode-number of the logically renamed dir
1970 +- the name of the before-renamed dir
1972 +The "detailed info per directory" file is created in aufs rename(2), and
1973 +loaded in any lookup.
1974 +The info is considered in lookup for the matching case only. Here
1975 +"matching" means that the root of branch (in the info filename) is same
1976 +to the current looking-up branch. After looking-up the before-renamed
1977 +name, the inode-number is compared. And the matched dentry is used.
1979 +The "inode-number list of directories" is a regular file which contains
1980 +simply the inode-numbers on the branch. The file is created or updated
1981 +in removing the branch, and loaded in adding the branch. Its lifetime is
1982 +equal to the branch.
1983 +The list is refered in lookup, and when the current target inode is
1984 +found in the list, the aufs tries loading the "detailed info per
1985 +directory" and get the changed and valid name of the dir.
1987 +Theoretically these "extra informaiton" may be able to be put into XATTR
1988 +in the dir inode. But aufs doesn't choose this way because
1989 +1. XATTR may not be supported by the branch (or its configuration)
1990 +2. XATTR may have its size limit.
1991 +3. XATTR may be less easy to convert than a regular file, when the
1992 + format of the info is changed in the future.
1993 +At the same time, I agree that the regular file approach is much slower
1994 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1997 +This DIRREN feature is enabled by aufs configuration, and is activated
1998 +by a new mount option.
2000 +For the more complicated case, there is a work with UDBA option, which
2001 +is to dected the direct access to the branches (by-passing aufs) and to
2002 +maintain the cashes in aufs. Since a single cached aufs dentry may
2003 +contains two names, before- and after-rename, the name comparision in
2004 +UDBA handler may not work correctly. In this case, the behaviour will be
2005 +equivalen to udba=reval case.
2006 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
2007 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
2008 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-02-22 22:51:59.058078584 +0100
2011 +# Copyright (C) 2011-2020 Junjiro R. Okajima
2013 +# This program is free software; you can redistribute it and/or modify
2014 +# it under the terms of the GNU General Public License as published by
2015 +# the Free Software Foundation; either version 2 of the License, or
2016 +# (at your option) any later version.
2018 +# This program is distributed in the hope that it will be useful,
2019 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2020 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2021 +# GNU General Public License for more details.
2023 +# You should have received a copy of the GNU General Public License
2024 +# along with this program; if not, write to the Free Software
2025 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2028 +File-based Hierarchical Storage Management (FHSM)
2029 +----------------------------------------------------------------------
2030 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2031 +storage world. Aufs provides this feature as file-based with multiple
2032 +writable branches, based upon the principle of "Colder, the Lower".
2033 +Here the word "colder" means that the less used files, and "lower" means
2034 +that the position in the order of the stacked branches vertically.
2035 +These multiple writable branches are prioritized, ie. the topmost one
2036 +should be the fastest drive and be used heavily.
2038 +o Characters in aufs FHSM story
2039 +- aufs itself and a new branch attribute.
2040 +- a new ioctl interface to move-down and to establish a connection with
2041 + the daemon ("move-down" is a converse of "copy-up").
2042 +- userspace tool and daemon.
2044 +The userspace daemon establishes a connection with aufs and waits for
2045 +the notification. The notified information is very similar to struct
2046 +statfs containing the number of consumed blocks and inodes.
2047 +When the consumed blocks/inodes of a branch exceeds the user-specified
2048 +upper watermark, the daemon activates its move-down process until the
2049 +consumed blocks/inodes reaches the user-specified lower watermark.
2051 +The actual move-down is done by aufs based upon the request from
2052 +user-space since we need to maintain the inode number and the internal
2053 +pointer arrays in aufs.
2055 +Currently aufs FHSM handles the regular files only. Additionally they
2056 +must not be hard-linked nor pseudo-linked.
2059 +o Cowork of aufs and the user-space daemon
2060 + During the userspace daemon established the connection, aufs sends a
2061 + small notification to it whenever aufs writes something into the
2062 + writable branch. But it may cost high since aufs issues statfs(2)
2063 + internally. So user can specify a new option to cache the
2064 + info. Actually the notification is controlled by these factors.
2065 + + the specified cache time.
2066 + + classified as "force" by aufs internally.
2067 + Until the specified time expires, aufs doesn't send the info
2068 + except the forced cases. When aufs decide forcing, the info is always
2069 + notified to userspace.
2070 + For example, the number of free inodes is generally large enough and
2071 + the shortage of it happens rarely. So aufs doesn't force the
2072 + notification when creating a new file, directory and others. This is
2073 + the typical case which aufs doesn't force.
2074 + When aufs writes the actual filedata and the files consumes any of new
2075 + blocks, the aufs forces notifying.
2078 +o Interfaces in aufs
2079 +- New branch attribute.
2081 + Specifies that the branch is managed by FHSM feature. In other word,
2082 + participant in the FHSM.
2083 + When nofhsm is set to the branch, it will not be the source/target
2084 + branch of the move-down operation. This attribute is set
2085 + independently from coo and moo attributes, and if you want full
2086 + FHSM, you should specify them as well.
2087 +- New mount option.
2089 + Specifies a second to suppress many less important info to be
2092 + + AUFS_CTL_FHSM_FD
2093 + create a new file descriptor which userspace can read the notification
2094 + (a subset of struct statfs) from aufs.
2095 +- Module parameter 'brs'
2096 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2098 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2099 + When there are two or more branches with fhsm attributes,
2100 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2101 + terminates it. As a result of remounting and branch-manipulation, the
2102 + number of branches with fhsm attribute can be one. In this case,
2103 + /sbin/mount.aufs will terminate the user-space daemon.
2106 +Finally the operation is done as these steps in kernel-space.
2108 + + no one else is using the file.
2109 + + the file is not hard-linked.
2110 + + the file is not pseudo-linked.
2111 + + the file is a regular file.
2112 + + the parent dir is not opaqued.
2113 +- find the target writable branch.
2114 +- make sure the file is not whiteout-ed by the upper (than the target)
2116 +- make the parent dir on the target branch.
2117 +- mutex lock the inode on the branch.
2118 +- unlink the whiteout on the target branch (if exists).
2119 +- lookup and create the whiteout-ed temporary name on the target branch.
2120 +- copy the file as the whiteout-ed temporary name on the target branch.
2121 +- rename the whiteout-ed temporary name to the original name.
2122 +- unlink the file on the source branch.
2123 +- maintain the internal pointer array and the external inode number
2125 +- maintain the timestamps and other attributes of the parent dir and the
2128 +And of course, in every step, an error may happen. So the operation
2129 +should restore the original file state after an error happens.
2130 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2131 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2132 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-02-22 22:51:59.058078584 +0100
2135 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2137 +# This program is free software; you can redistribute it and/or modify
2138 +# it under the terms of the GNU General Public License as published by
2139 +# the Free Software Foundation; either version 2 of the License, or
2140 +# (at your option) any later version.
2142 +# This program is distributed in the hope that it will be useful,
2143 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2144 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2145 +# GNU General Public License for more details.
2147 +# You should have received a copy of the GNU General Public License
2148 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2150 +mmap(2) -- File Memory Mapping
2151 +----------------------------------------------------------------------
2152 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2153 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2155 +This approach is simple and good, but there is one problem.
2156 +Under /proc, several entries show the mmapped files by its path (with
2157 +device and inode number), and the printed path will be the path on the
2158 +branch fs's instead of virtual aufs's.
2159 +This is not a problem in most cases, but some utilities lsof(1) (and its
2160 +user) may expect the path on aufs.
2162 +To address this issue, aufs adds a new member called vm_prfile in struct
2163 +vm_area_struct (and struct vm_region). The original vm_file points to
2164 +the file on the branch fs in order to handle everything correctly as
2165 +usual. The new vm_prfile points to a virtual file in aufs, and the
2166 +show-functions in procfs refers to vm_prfile if it is set.
2167 +Also we need to maintain several other places where touching vm_file
2169 +- fork()/clone() copies vma and the reference count of vm_file is
2171 +- merging vma maintains the ref count too.
2173 +This is not a good approach. It just fakes the printed path. But it
2174 +leaves all behaviour around f_mapping unchanged. This is surely an
2176 +Actually aufs had adopted another complicated approach which calls
2177 +generic_file_mmap() and handles struct vm_operations_struct. In this
2178 +approach, aufs met a hard problem and I could not solve it without
2179 +switching the approach.
2181 +There may be one more another approach which is
2182 +- bind-mount the branch-root onto the aufs-root internally
2183 +- grab the new vfsmount (ie. struct mount)
2184 +- lazy-umount the branch-root internally
2185 +- in open(2) the aufs-file, open the branch-file with the hidden
2186 + vfsmount (instead of the original branch's vfsmount)
2187 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2188 + but it may be possible from userspace by the mount helper.
2190 +Adding the internal hidden vfsmount and using it in opening a file, the
2191 +file path under /proc will be printed correctly. This approach looks
2192 +smarter, but is not possible I am afraid.
2193 +- aufs-root may be bind-mount later. when it happens, another hidden
2194 + vfsmount will be required.
2195 +- it is hard to get the chance to bind-mount and lazy-umount
2196 + + in kernel-space, FS can have vfsmount in open(2) via
2197 + file->f_path, and aufs can know its vfsmount. But several locks are
2198 + already acquired, and if aufs tries to bind-mount and lazy-umount
2199 + here, then it may cause a deadlock.
2200 + + in user-space, bind-mount doesn't invoke the mount helper.
2201 +- since /proc shows dev and ino, aufs has to give vma these info. it
2202 + means a new member vm_prinode will be necessary. this is essentially
2203 + equivalent to vm_prfile described above.
2205 +I have to give up this "looks-smater" approach.
2206 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2207 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2208 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-02-22 22:51:59.058078584 +0100
2211 +# Copyright (C) 2014-2020 Junjiro R. Okajima
2213 +# This program is free software; you can redistribute it and/or modify
2214 +# it under the terms of the GNU General Public License as published by
2215 +# the Free Software Foundation; either version 2 of the License, or
2216 +# (at your option) any later version.
2218 +# This program is distributed in the hope that it will be useful,
2219 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2220 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2221 +# GNU General Public License for more details.
2223 +# You should have received a copy of the GNU General Public License
2224 +# along with this program; if not, write to the Free Software
2225 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2228 +Listing XATTR/EA and getting the value
2229 +----------------------------------------------------------------------
2230 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2231 +shows the values from the topmost existing file. This behaviour is good
2232 +for the non-dir entries since the bahaviour exactly matches the shown
2233 +information. But for the directories, aufs considers all the same named
2234 +entries on the lower branches. Which means, if one of the lower entry
2235 +rejects readdir call, then aufs returns an error even if the topmost
2236 +entry allows it. This behaviour is necessary to respect the branch fs's
2237 +security, but can make users confused since the user-visible standard
2238 +attributes don't match the behaviour.
2239 +To address this issue, aufs has a mount option called dirperm1 which
2240 +checks the permission for the topmost entry only, and ignores the lower
2241 +entry's permission.
2243 +A similar issue can happen around XATTR.
2244 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2245 +always set. Otherwise these very unpleasant situation would happen.
2246 +- listxattr(2) may return the duplicated entries.
2247 +- users may not be able to remove or reset the XATTR forever,
2250 +XATTR/EA support in the internal (copy,move)-(up,down)
2251 +----------------------------------------------------------------------
2252 +Generally the extended attributes of inode are categorized as these.
2253 +- "security" for LSM and capability.
2254 +- "system" for posix ACL, 'acl' mount option is required for the branch
2256 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2257 +- "user" for userspace, 'user_xattr' mount option is required for the
2258 + branch fs generally.
2260 +Moreover there are some other categories. Aufs handles these rather
2261 +unpopular categories as the ordinary ones, ie. there is no special
2262 +condition nor exception.
2264 +In copy-up, the support for XATTR on the dst branch may differ from the
2265 +src branch. In this case, the copy-up operation will get an error and
2266 +the original user operation which triggered the copy-up will fail. It
2267 +can happen that even all copy-up will fail.
2268 +When both of src and dst branches support XATTR and if an error occurs
2269 +during copying XATTR, then the copy-up should fail obviously. That is a
2270 +good reason and aufs should return an error to userspace. But when only
2271 +the src branch support that XATTR, aufs should not return an error.
2272 +For example, the src branch supports ACL but the dst branch doesn't
2273 +because the dst branch may natively un-support it or temporary
2274 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2275 +may NOT return an error even if the XATTR is not supported. It is
2276 +totally up to the branch fs.
2278 +Anyway when the aufs internal copy-up gets an error from the dst branch
2279 +fs, then aufs tries removing the just copied entry and returns the error
2280 +to the userspace. The worst case of this situation will be all copy-up
2283 +For the copy-up operation, there two basic approaches.
2284 +- copy the specified XATTR only (by category above), and return the
2285 + error unconditionally if it happens.
2286 +- copy all XATTR, and ignore the error on the specified category only.
2288 +In order to support XATTR and to implement the correct behaviour, aufs
2289 +chooses the latter approach and introduces some new branch attributes,
2290 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2291 +They correspond to the XATTR namespaces (see above). Additionally, to be
2292 +convenient, "icex" is also provided which means all "icex*" attributes
2293 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2295 +The meaning of these attributes is to ignore the error from setting
2296 +XATTR on that branch.
2297 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2298 +error from the dst branch according to the specified attributes.
2300 +Some XATTR may have its default value. The default value may come from
2301 +the parent dir or the environment. If the default value is set at the
2302 +file creating-time, it will be overwritten by copy-up.
2303 +Some contradiction may happen I am afraid.
2304 +Do we need another attribute to stop copying XATTR? I am unsure. For
2305 +now, aufs implements the branch attributes to ignore the error.
2306 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2307 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2308 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-02-22 22:51:59.058078584 +0100
2311 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2313 +# This program is free software; you can redistribute it and/or modify
2314 +# it under the terms of the GNU General Public License as published by
2315 +# the Free Software Foundation; either version 2 of the License, or
2316 +# (at your option) any later version.
2318 +# This program is distributed in the hope that it will be useful,
2319 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2320 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2321 +# GNU General Public License for more details.
2323 +# You should have received a copy of the GNU General Public License
2324 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2326 +Export Aufs via NFS
2327 +----------------------------------------------------------------------
2328 +Here is an approach.
2329 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2331 +- iget_locked(): initialize aufs inode generation for a new inode, and
2332 + store it in xigen file.
2333 +- destroy_inode(): increment aufs inode generation and store it in xigen
2334 + file. it is necessary even if it is not unlinked, because any data of
2335 + inode may be changed by UDBA.
2336 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2337 + build file handle by
2338 + + branch id (4 bytes)
2339 + + superblock generation (4 bytes)
2340 + + inode number (4 or 8 bytes)
2341 + + parent dir inode number (4 or 8 bytes)
2342 + + inode generation (4 bytes))
2343 + + return value of exportfs_encode_fh() for the parent on a branch (4
2345 + + file handle for a branch (by exportfs_encode_fh())
2347 + + find the index of a branch from its id in handle, and check it is
2348 + still exist in aufs.
2349 + + 1st level: get the inode number from handle and search it in cache.
2350 + + 2nd level: if not found in cache, get the parent inode number from
2351 + the handle and search it in cache. and then open the found parent
2352 + dir, find the matching inode number by vfs_readdir() and get its
2353 + name, and call lookup_one_len() for the target dentry.
2354 + + 3rd level: if the parent dir is not cached, call
2355 + exportfs_decode_fh() for a branch and get the parent on a branch,
2356 + build a pathname of it, convert it a pathname in aufs, call
2357 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2359 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2360 + for every branch, but not itself. to get this, (currently) aufs
2361 + searches in current->nsproxy->mnt_ns list. it may not be a good
2362 + idea, but I didn't get other approach.
2363 + + test the generation of the gotten inode.
2364 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2365 + convert it into ESTALE for NFSD.
2366 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2367 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2368 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2369 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2370 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-02-22 22:51:59.058078584 +0100
2373 +# Copyright (C) 2005-2020 Junjiro R. Okajima
2375 +# This program is free software; you can redistribute it and/or modify
2376 +# it under the terms of the GNU General Public License as published by
2377 +# the Free Software Foundation; either version 2 of the License, or
2378 +# (at your option) any later version.
2380 +# This program is distributed in the hope that it will be useful,
2381 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2382 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2383 +# GNU General Public License for more details.
2385 +# You should have received a copy of the GNU General Public License
2386 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2388 +Show Whiteout Mode (shwh)
2389 +----------------------------------------------------------------------
2390 +Generally aufs hides the name of whiteouts. But in some cases, to show
2391 +them is very useful for users. For instance, creating a new middle layer
2392 +(branch) by merging existing layers.
2394 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2395 +When you have three branches,
2396 +- Bottom: 'system', squashfs (underlying base system), read-only
2397 +- Middle: 'mods', squashfs, read-only
2398 +- Top: 'overlay', ram (tmpfs), read-write
2400 +The top layer is loaded at boot time and saved at shutdown, to preserve
2401 +the changes made to the system during the session.
2402 +When larger changes have been made, or smaller changes have accumulated,
2403 +the size of the saved top layer data grows. At this point, it would be
2404 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2405 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2406 +restoring save and load speed.
2408 +This merging is simplified by the use of another aufs mount, of just the
2409 +two overlay branches using the 'shwh' option.
2410 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2411 + aufs /livesys/merge_union
2413 +A merged view of these two branches is then available at
2414 +/livesys/merge_union, and the new feature is that the whiteouts are
2416 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2417 +writing to all branches. Also the default mode for all branches is 'ro'.
2418 +It is now possible to save the combined contents of the two overlay
2419 +branches to a new squashfs, e.g.:
2420 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2422 +This new squashfs archive can be stored on the boot device and the
2423 +initramfs will use it to replace the old one at the next boot.
2424 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2425 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2426 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-02-22 22:51:59.058078584 +0100
2429 +# Copyright (C) 2010-2020 Junjiro R. Okajima
2431 +# This program is free software; you can redistribute it and/or modify
2432 +# it under the terms of the GNU General Public License as published by
2433 +# the Free Software Foundation; either version 2 of the License, or
2434 +# (at your option) any later version.
2436 +# This program is distributed in the hope that it will be useful,
2437 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2438 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2439 +# GNU General Public License for more details.
2441 +# You should have received a copy of the GNU General Public License
2442 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2444 +Dynamically customizable FS operations
2445 +----------------------------------------------------------------------
2446 +Generally FS operations (struct inode_operations, struct
2447 +address_space_operations, struct file_operations, etc.) are defined as
2448 +"static const", but it never means that FS have only one set of
2449 +operation. Some FS have multiple sets of them. For instance, ext2 has
2450 +three sets, one for XIP, for NOBH, and for normal.
2451 +Since aufs overrides and redirects these operations, sometimes aufs has
2452 +to change its behaviour according to the branch FS type. More importantly
2453 +VFS acts differently if a function (member in the struct) is set or
2454 +not. It means aufs should have several sets of operations and select one
2455 +among them according to the branch FS definition.
2457 +In order to solve this problem and not to affect the behaviour of VFS,
2458 +aufs defines these operations dynamically. For instance, aufs defines
2459 +dummy direct_IO function for struct address_space_operations, but it may
2460 +not be set to the address_space_operations actually. When the branch FS
2461 +doesn't have it, aufs doesn't set it to its address_space_operations
2462 +while the function definition itself is still alive. So the behaviour
2463 +itself will not change, and it will return an error when direct_IO is
2466 +The lifetime of these dynamically generated operation object is
2467 +maintained by aufs branch object. When the branch is removed from aufs,
2468 +the reference counter of the object is decremented. When it reaches
2469 +zero, the dynamically generated operation object will be freed.
2471 +This approach is designed to support AIO (io_submit), Direct I/O and
2473 +Currently this approach is applied to address_space_operations for
2474 +regular files only.
2475 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2476 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2477 +++ linux/Documentation/filesystems/aufs/README 2021-02-22 22:51:59.054745247 +0100
2480 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2486 +----------------------------------------
2487 +In the early days, aufs was entirely re-designed and re-implemented
2488 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2489 +improvements and implementations, it became totally different from
2490 +Unionfs while keeping the basic features.
2491 +Later, Unionfs Version 2.x series began taking some of the same
2492 +approaches to aufs1's.
2493 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2494 +University and his team.
2496 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2498 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2499 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2500 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2501 + or aufs1 from CVS on SourceForge.
2503 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2504 + According to Christoph Hellwig, linux rejects all union-type
2505 + filesystems but UnionMount.
2506 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2508 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2509 + UnionMount, and he pointed out an issue around a directory mutex
2510 + lock and aufs addressed it. But it is still unsure whether aufs will
2511 + be merged (or any other union solution).
2512 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2516 +----------------------------------------
2517 +- unite several directories into a single virtual filesystem. The member
2518 + directory is called as a branch.
2519 +- you can specify the permission flags to the branch, which are 'readonly',
2520 + 'readwrite' and 'whiteout-able.'
2521 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2522 + readonly branch are modifiable logically.
2523 +- dynamic branch manipulation, add, del.
2526 +Also there are many enhancements in aufs, such as:
2527 +- test only the highest one for the directory permission (dirperm1)
2528 +- copyup on open (coo=)
2529 +- 'move' policy for copy-up between two writable branches, after
2530 + checking free space.
2532 +- readdir(3) in userspace.
2533 +- keep inode number by external inode number table
2534 +- keep the timestamps of file/dir in internal copyup operation
2535 +- seekable directory, supporting NFS readdir.
2536 +- whiteout is hardlinked in order to reduce the consumption of inodes
2538 +- do not copyup, nor create a whiteout when it is unnecessary
2539 +- revert a single systemcall when an error occurs in aufs
2540 +- remount interface instead of ioctl
2541 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2542 +- loopback mounted filesystem as a branch
2543 +- kernel thread for removing the dir who has a plenty of whiteouts
2544 +- support copyup sparse file (a file which has a 'hole' in it)
2545 +- default permission flags for branches
2546 +- selectable permission flags for ro branch, whether whiteout can
2549 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2550 +- support multiple writable branches, some policies to select one
2551 + among multiple writable branches.
2552 +- a new semantics for link(2) and rename(2) to support multiple
2553 + writable branches.
2554 +- no glibc changes are required.
2555 +- pseudo hardlink (hardlink over branches)
2556 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2557 + including NFS or remote filesystem branch.
2558 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2561 +Currently these features are dropped temporary from aufs5.
2562 +See design/08plan.txt in detail.
2563 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2565 +- statistics of aufs thread (/sys/fs/aufs/stat)
2567 +Features or just an idea in the future (see also design/*.txt),
2568 +- reorder the branch index without del/re-add.
2569 +- permanent xino files for NFSD
2570 +- an option for refreshing the opened files after add/del branches
2571 +- light version, without branch manipulation. (unnecessary?)
2572 +- copyup in userspace
2573 +- inotify in userspace
2578 +----------------------------------------
2579 +There are three GIT trees for aufs5, aufs5-linux.git,
2580 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2582 +While the aufs-util is always necessary, you need either of aufs5-linux
2583 +or aufs5-standalone.
2585 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2586 +git://git.kernel.org/.../torvalds/linux.git.
2587 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2588 +build aufs5 as an external kernel module.
2589 +Several extra patches are not included in this tree. Only
2590 +aufs5-standalone tree contains them. They are described in the later
2591 +section "Configuration and Compilation."
2593 +On the other hand, the aufs5-standalone tree has only aufs source files
2594 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2595 +But you need to apply all aufs patches manually.
2597 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2598 +represents the linux kernel version, "linux-5.x". For instance,
2599 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2600 +"aufs5.x-rcN" branch.
2603 +$ git clone --reference /your/linux/git/tree \
2604 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2605 +- if you don't have linux GIT tree, then remove "--reference ..."
2606 +$ cd aufs5-linux.git
2607 +$ git checkout origin/aufs5.0
2609 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2610 +leave the patch-work to GIT.
2611 +$ cd /your/linux/git/tree
2612 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2614 +$ git checkout -b my5.0 v5.0
2615 +$ (add your local change...)
2616 +$ git pull aufs5 aufs5.0
2617 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2618 +- you may need to solve some conflicts between your_changes and
2619 + aufs5.0. in this case, git-rerere is recommended so that you can
2620 + solve the similar conflicts automatically when you upgrade to 5.1 or
2621 + later in the future.
2623 +o aufs5-standalone tree
2624 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2625 +$ cd aufs5-standalone.git
2626 +$ git checkout origin/aufs5.0
2629 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2630 +- note that the public aufs-util.git is on SourceForge instead of
2633 +$ git checkout origin/aufs5.0
2635 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2636 +The minor version number, 'x' in '5.x', of aufs may not always
2637 +follow the minor version number of the kernel.
2638 +Because changes in the kernel that cause the use of a new
2639 +minor version number do not always require changes to aufs-util.
2641 +Since aufs-util has its own minor version number, you may not be
2642 +able to find a GIT branch in aufs-util for your kernel's
2643 +exact minor version number.
2644 +In this case, you should git-checkout the branch for the
2645 +nearest lower number.
2647 +For (an unreleased) example:
2648 +If you are using "linux-5.10" and the "aufs5.10" branch
2649 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2650 +or something numerically smaller is the branch for your kernel.
2652 +Also you can view all branches by
2656 +3. Configuration and Compilation
2657 +----------------------------------------
2658 +Make sure you have git-checkout'ed the correct branch.
2660 +For aufs5-linux tree,
2661 +- enable CONFIG_AUFS_FS.
2662 +- set other aufs configurations if necessary.
2664 +For aufs5-standalone tree,
2665 +There are several ways to build.
2668 +- apply ./aufs5-kbuild.patch to your kernel source files.
2669 +- apply ./aufs5-base.patch too.
2670 +- apply ./aufs5-mmap.patch too.
2671 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2672 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2673 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2674 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2675 +- enable CONFIG_AUFS_FS, you can select either
2677 +- and build your kernel as usual.
2678 +- install the built kernel.
2679 +- install the header files too by "make headers_install" to the
2680 + directory where you specify. By default, it is $PWD/usr.
2681 + "make help" shows a brief note for headers_install.
2682 +- and reboot your system.
2685 +- module only (CONFIG_AUFS_FS=m).
2686 +- apply ./aufs5-base.patch to your kernel source files.
2687 +- apply ./aufs5-mmap.patch too.
2688 +- apply ./aufs5-standalone.patch too.
2689 +- build your kernel, don't forget "make headers_install", and reboot.
2690 +- edit ./config.mk and set other aufs configurations if necessary.
2691 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2692 + every aufs configurations.
2693 +- build the module by simple "make".
2694 +- you can specify ${KDIR} make variable which points to your kernel
2696 +- install the files
2697 + + run "make install" to install the aufs module, or copy the built
2698 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2699 + + run "make install_headers" (instead of headers_install) to install
2700 + the modified aufs header file (you can specify DESTDIR which is
2701 + available in aufs standalone version's Makefile only), or copy
2702 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2703 + you like manually. By default, the target directory is $PWD/usr.
2704 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2705 + kernel source tree.
2707 +Note: The header file aufs_type.h is necessary to build aufs-util
2708 + as well as "make headers_install" in the kernel source tree.
2709 + headers_install is subject to be forgotten, but it is essentially
2710 + necessary, not only for building aufs-util.
2711 + You may not meet problems without headers_install in some older
2715 +- read README in aufs-util, build and install it
2716 +- note that your distribution may contain an obsoleted version of
2717 + aufs_type.h in /usr/include/linux or something. When you build aufs
2718 + utilities, make sure that your compiler refers the correct aufs header
2719 + file which is built by "make headers_install."
2720 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2721 + then run "make install_ulib" too. And refer to the aufs manual in
2724 +There several other patches in aufs5-standalone.git. They are all
2725 +optional. When you meet some problems, they will help you.
2726 +- aufs5-loopback.patch
2727 + Supports a nested loopback mount in a branch-fs. This patch is
2728 + unnecessary until aufs produces a message like "you may want to try
2729 + another patch for loopback file".
2730 +- proc_mounts.patch
2731 + When there are many mountpoints and many mount(2)/umount(2) are
2732 + running, then /proc/mounts may not show the all mountpoints. This
2733 + patch makes /proc/mounts always show the full mountpoints list.
2734 + If you don't want to apply this patch and meet such problem, then you
2735 + need to increase the value of 'ProcMounts_Times' make-variable in
2736 + aufs-util.git as a second best solution.
2738 + Modifies a system global kernel internal function get_next_ino() in
2739 + order to stop assigning 0 for an inode-number. Not directly related to
2740 + aufs, but recommended generally.
2742 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2743 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2744 + duplication of inode number, which is important for backup tools and
2745 + other utilities. When you find aufs XINO files for tmpfs branch
2746 + growing too much, try this patch.
2747 +- lockdep-debug.patch
2748 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2749 + also a caller of VFS functions for branch filesystems, subclassing of
2750 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2751 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2752 + need to apply this debug patch to expand several constant values.
2753 + If you don't know what LOCKDEP is, then you don't have apply this
2758 +----------------------------------------
2759 +At first, make sure aufs-util are installed, and please read the aufs
2760 +manual, aufs.5 in aufs-util.git tree.
2764 +$ mkdir /tmp/rw /tmp/aufs
2765 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2767 +Here is another example. The result is equivalent.
2768 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2770 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2771 +# mount -o remount,append:${HOME} /tmp/aufs
2773 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2774 +you modify a file under /tmp/aufs, the one on your home directory is
2775 +not affected, instead the same named file will be newly created under
2776 +/tmp/rw. And all of your modification to a file will be applied to
2777 +the one under /tmp/rw. This is called the file based Copy on Write
2779 +Aufs mount options are described in aufs.5.
2780 +If you run chroot or something and make your aufs as a root directory,
2781 +then you need to customize the shutdown script. See the aufs manual in
2784 +Additionally, there are some sample usages of aufs which are a
2785 +diskless system with network booting, and LiveCD over NFS.
2786 +See sample dir in CVS tree on SourceForge.
2790 +----------------------------------------
2791 +When you have any problems or strange behaviour in aufs, please let me
2793 +- /proc/mounts (instead of the output of mount(8))
2794 +- /sys/module/aufs/*
2795 +- /sys/fs/aufs/* (if you have them)
2796 +- /debug/aufs/* (if you have them)
2797 +- linux kernel version
2798 + if your kernel is not plain, for example modified by distributor,
2799 + the url where i can download its source is necessary too.
2800 +- aufs version which was printed at loading the module or booting the
2801 + system, instead of the date you downloaded.
2802 +- configuration (define/undefine CONFIG_AUFS_xxx)
2803 +- kernel configuration or /proc/config.gz (if you have it)
2804 +- LSM (linux security module, if you are using)
2805 +- behaviour which you think to be incorrect
2806 +- actual operation, reproducible one is better
2807 +- mailto: aufs-users at lists.sourceforge.net
2809 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2810 +and Feature Requests) on SourceForge. Please join and write to
2814 +6. Acknowledgements
2815 +----------------------------------------
2816 +Thanks to everyone who have tried and are using aufs, whoever
2817 +have reported a bug or any feedback.
2819 +Especially donators:
2820 +Tomas Matejicek(slax.org) made a donation (much more than once).
2821 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2822 + scripts) is making "doubling" donations.
2823 + Unfortunately I cannot list all of the donators, but I really
2825 + It ends Aug 2010, but the ordinary donation URL is still available.
2826 + <http://sourceforge.net/donate/index.php?group_id=167503>
2827 +Dai Itasaka made a donation (2007/8).
2828 +Chuck Smith made a donation (2008/4, 10 and 12).
2829 +Henk Schoneveld made a donation (2008/9).
2830 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2831 +Francois Dupoux made a donation (2008/11).
2832 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2833 + aufs2 GIT tree (2009/2).
2834 +William Grant made a donation (2009/3).
2835 +Patrick Lane made a donation (2009/4).
2836 +The Mail Archive (mail-archive.com) made donations (2009/5).
2837 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2838 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2839 +Pavel Pronskiy made a donation (2011/2).
2840 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2841 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2842 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2844 +Sam Liddicott made a donation (2011/9).
2845 +Era Scarecrow made a donation (2013/4).
2846 +Bor Ratajc made a donation (2013/4).
2847 +Alessandro Gorreta made a donation (2013/4).
2848 +POIRETTE Marc made a donation (2013/4).
2849 +Alessandro Gorreta made a donation (2013/4).
2850 +lauri kasvandik made a donation (2013/5).
2851 +"pemasu from Finland" made a donation (2013/7).
2852 +The Parted Magic Project made a donation (2013/9 and 11).
2853 +Pavel Barta made a donation (2013/10).
2854 +Nikolay Pertsev made a donation (2014/5).
2855 +James B made a donation (2014/7 and 2015/7).
2856 +Stefano Di Biase made a donation (2014/8).
2857 +Daniel Epellei made a donation (2015/1).
2858 +OmegaPhil made a donation (2016/1, 2018/4).
2859 +Tomasz Szewczyk made a donation (2016/4).
2860 +James Burry made a donation (2016/12).
2861 +Carsten Rose made a donation (2018/9).
2862 +Porteus Kiosk made a donation (2018/10).
2864 +Thank you very much.
2865 +Donations are always, including future donations, very important and
2866 +helpful for me to keep on developing aufs.
2870 +----------------------------------------
2871 +If you are an experienced user, no explanation is needed. Aufs is
2872 +just a linux filesystem.
2877 +# Local variables: ;
2880 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2881 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2882 +++ linux/fs/aufs/aufs.h 2021-02-22 22:51:59.058078584 +0100
2884 +/* SPDX-License-Identifier: GPL-2.0 */
2886 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2888 + * This program, aufs is free software; you can redistribute it and/or modify
2889 + * it under the terms of the GNU General Public License as published by
2890 + * the Free Software Foundation; either version 2 of the License, or
2891 + * (at your option) any later version.
2893 + * This program is distributed in the hope that it will be useful,
2894 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2895 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2896 + * GNU General Public License for more details.
2898 + * You should have received a copy of the GNU General Public License
2899 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2903 + * all header files
2911 +#define AuStub(type, name, body, ...) \
2912 + static inline type name(__VA_ARGS__) { body; }
2914 +#define AuStubVoid(name, ...) \
2915 + AuStub(void, name, , __VA_ARGS__)
2916 +#define AuStubInt0(name, ...) \
2917 + AuStub(int, name, return 0, __VA_ARGS__)
2921 +#include "branch.h"
2924 +#include "dbgaufs.h"
2925 +#include "dentry.h"
2927 +#include "dirren.h"
2930 +#include "fstype.h"
2935 +#include "module.h"
2939 +#include "sysaufs.h"
2944 +#endif /* __KERNEL__ */
2945 +#endif /* __AUFS_H__ */
2946 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2947 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2948 +++ linux/fs/aufs/branch.c 2021-02-22 22:51:59.058078584 +0100
2950 +// SPDX-License-Identifier: GPL-2.0
2952 + * Copyright (C) 2005-2020 Junjiro R. Okajima
2954 + * This program, aufs is free software; you can redistribute it and/or modify
2955 + * it under the terms of the GNU General Public License as published by
2956 + * the Free Software Foundation; either version 2 of the License, or
2957 + * (at your option) any later version.
2959 + * This program is distributed in the hope that it will be useful,
2960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2962 + * GNU General Public License for more details.
2964 + * You should have received a copy of the GNU General Public License
2965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2969 + * branch management
2972 +#include <linux/compat.h>
2973 +#include <linux/statfs.h>
2977 + * free a single branch
2979 +static void au_br_do_free(struct au_branch *br)
2982 + struct au_wbr *wbr;
2983 + struct au_dykey **key;
2985 + au_hnotify_fin_br(br);
2986 + /* always, regardless the mount option */
2987 + au_dr_hino_free(&br->br_dirren);
2990 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2991 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2992 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2993 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2997 + for (i = 0; i < AuBrWh_Last; i++)
2998 + dput(wbr->wbr_wh[i]);
2999 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
3000 + AuRwDestroy(&wbr->wbr_wh_rwsem);
3003 + if (br->br_fhsm) {
3004 + au_br_fhsm_fin(br->br_fhsm);
3005 + au_kfree_try_rcu(br->br_fhsm);
3008 + key = br->br_dykey;
3009 + for (i = 0; i < AuBrDynOp; i++, key++)
3015 + /* recursive lock, s_umount of branch's */
3016 + /* synchronize_rcu(); */ /* why? */
3018 + path_put(&br->br_path);
3020 + au_kfree_rcu(wbr);
3021 + au_lcnt_wait_for_fin(&br->br_nfiles);
3022 + au_lcnt_wait_for_fin(&br->br_count);
3023 + /* I don't know why, but percpu_refcount requires this */
3024 + /* synchronize_rcu(); */
3029 + * frees all branches
3031 +void au_br_free(struct au_sbinfo *sbinfo)
3033 + aufs_bindex_t bmax;
3034 + struct au_branch **br;
3036 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3038 + bmax = sbinfo->si_bbot + 1;
3039 + br = sbinfo->si_branch;
3041 + au_br_do_free(*br++);
3045 + * find the index of a branch which is specified by @br_id.
3047 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3049 + aufs_bindex_t bindex, bbot;
3051 + bbot = au_sbbot(sb);
3052 + for (bindex = 0; bindex <= bbot; bindex++)
3053 + if (au_sbr_id(sb, bindex) == br_id)
3058 +/* ---------------------------------------------------------------------- */
3064 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3065 + struct dentry *h_root)
3067 + if (unlikely(h_adding == h_root
3068 + || au_test_loopback_overlap(sb, h_adding)))
3070 + if (h_adding->d_sb != h_root->d_sb)
3072 + return au_test_subdir(h_adding, h_root)
3073 + || au_test_subdir(h_root, h_adding);
3077 + * returns a newly allocated branch. @new_nbranch is a number of branches
3078 + * after adding a branch.
3080 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3083 + struct au_branch *add_branch;
3084 + struct dentry *root;
3085 + struct inode *inode;
3089 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3090 + if (unlikely(!add_branch))
3092 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3093 + if (unlikely(!add_branch->br_xino))
3095 + err = au_hnotify_init_br(add_branch, perm);
3096 + if (unlikely(err))
3099 + if (au_br_writable(perm)) {
3100 + /* may be freed separately at changing the branch permission */
3101 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3103 + if (unlikely(!add_branch->br_wbr))
3107 + if (au_br_fhsm(perm)) {
3108 + err = au_fhsm_br_alloc(add_branch);
3109 + if (unlikely(err))
3113 + root = sb->s_root;
3114 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3116 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3118 + inode = d_inode(root);
3119 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3123 + return add_branch; /* success */
3126 + au_kfree_rcu(add_branch->br_wbr);
3128 + au_hnotify_fin_br(add_branch);
3130 + au_xino_put(add_branch);
3132 + au_kfree_rcu(add_branch);
3134 + return ERR_PTR(err);
3138 + * test if the branch permission is legal or not.
3140 +static int test_br(struct inode *inode, int brperm, char *path)
3144 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3149 + pr_err("write permission for readonly mount or inode, %s\n", path);
3157 + * 0: success, the caller will add it
3158 + * plus: success, it is already unified, the caller should ignore it
3161 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3164 + aufs_bindex_t bbot, bindex;
3165 + struct dentry *root, *h_dentry;
3166 + struct inode *inode, *h_inode;
3168 + root = sb->s_root;
3169 + bbot = au_sbbot(sb);
3170 + if (unlikely(bbot >= 0
3171 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3175 + pr_err("%s duplicated\n", add->pathname);
3180 + err = -ENOSPC; /* -E2BIG; */
3181 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3182 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3183 + pr_err("number of branches exceeded %s\n", add->pathname);
3188 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3189 + pr_err("bad index %d\n", add->bindex);
3193 + inode = d_inode(add->path.dentry);
3195 + if (unlikely(!inode->i_nlink)) {
3196 + pr_err("no existence %s\n", add->pathname);
3201 + if (unlikely(inode->i_sb == sb)) {
3202 + pr_err("%s must be outside\n", add->pathname);
3206 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3207 + pr_err("unsupported filesystem, %s (%s)\n",
3208 + add->pathname, au_sbtype(inode->i_sb));
3212 + if (unlikely(inode->i_sb->s_stack_depth)) {
3213 + pr_err("already stacked, %s (%s)\n",
3214 + add->pathname, au_sbtype(inode->i_sb));
3218 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3219 + if (unlikely(err))
3223 + return 0; /* success */
3226 + for (bindex = 0; bindex <= bbot; bindex++)
3227 + if (unlikely(test_overlap(sb, add->path.dentry,
3228 + au_h_dptr(root, bindex)))) {
3229 + pr_err("%s is overlapped\n", add->pathname);
3234 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3235 + h_dentry = au_h_dptr(root, 0);
3236 + h_inode = d_inode(h_dentry);
3237 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3238 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3239 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3240 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3242 + i_uid_read(inode), i_gid_read(inode),
3243 + (inode->i_mode & S_IALLUGO),
3244 + i_uid_read(h_inode), i_gid_read(h_inode),
3245 + (h_inode->i_mode & S_IALLUGO));
3253 + * initialize or clean the whiteouts for an adding branch
3255 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3258 + int err, old_perm;
3259 + aufs_bindex_t bindex;
3260 + struct inode *h_inode;
3261 + struct au_wbr *wbr;
3262 + struct au_hinode *hdir;
3263 + struct dentry *h_dentry;
3265 + err = vfsub_mnt_want_write(au_br_mnt(br));
3266 + if (unlikely(err))
3270 + old_perm = br->br_perm;
3271 + br->br_perm = new_perm;
3274 + bindex = au_br_index(sb, br->br_id);
3275 + if (0 <= bindex) {
3276 + hdir = au_hi(d_inode(sb->s_root), bindex);
3277 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3279 + h_dentry = au_br_dentry(br);
3280 + h_inode = d_inode(h_dentry);
3281 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3284 + err = au_wh_init(br, sb);
3286 + wbr_wh_write_lock(wbr);
3287 + err = au_wh_init(br, sb);
3288 + wbr_wh_write_unlock(wbr);
3291 + au_hn_inode_unlock(hdir);
3293 + inode_unlock(h_inode);
3294 + vfsub_mnt_drop_write(au_br_mnt(br));
3295 + br->br_perm = old_perm;
3297 + if (!err && wbr && !au_br_writable(new_perm)) {
3298 + au_kfree_rcu(wbr);
3299 + br->br_wbr = NULL;
3306 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3310 + struct kstatfs kst;
3311 + struct au_wbr *wbr;
3314 + au_rw_init(&wbr->wbr_wh_rwsem);
3315 + atomic_set(&wbr->wbr_wh_running, 0);
3318 + * a limit for rmdir/rename a dir
3319 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3321 + err = vfs_statfs(&br->br_path, &kst);
3322 + if (unlikely(err))
3325 + if (kst.f_namelen >= NAME_MAX)
3326 + err = au_br_init_wh(sb, br, perm);
3328 + pr_err("%pd(%s), unsupported namelen %ld\n",
3330 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3336 +/* initialize a new branch */
3337 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3338 + struct au_opt_add *add)
3341 + struct au_branch *brbase;
3343 + struct inode *h_inode;
3346 + br->br_perm = add->perm;
3347 + br->br_path = add->path; /* set first, path_get() later */
3348 + spin_lock_init(&br->br_dykey_lock);
3349 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3350 + au_lcnt_init(&br->br_count, /*release*/NULL);
3351 + br->br_id = au_new_br_id(sb);
3352 + AuDebugOn(br->br_id < 0);
3354 + /* always, regardless the given option */
3355 + err = au_dr_br_init(sb, br, &add->path);
3356 + if (unlikely(err))
3359 + if (au_br_writable(add->perm)) {
3360 + err = au_wbr_init(br, sb, add->perm);
3361 + if (unlikely(err))
3365 + if (au_opt_test(au_mntflags(sb), XINO)) {
3366 + brbase = au_sbr(sb, 0);
3367 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3369 + h_inode = d_inode(add->path.dentry);
3370 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3371 + if (unlikely(err)) {
3372 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3377 + sysaufs_br_init(br);
3378 + path_get(&br->br_path);
3379 + goto out; /* success */
3382 + memset(&br->br_path, 0, sizeof(br->br_path));
3387 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3388 + struct au_branch *br, aufs_bindex_t bbot,
3389 + aufs_bindex_t amount)
3391 + struct au_branch **brp;
3393 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3395 + brp = sbinfo->si_branch + bindex;
3396 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3398 + sbinfo->si_bbot++;
3399 + if (unlikely(bbot < 0))
3400 + sbinfo->si_bbot = 0;
3403 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3404 + aufs_bindex_t bbot, aufs_bindex_t amount)
3406 + struct au_hdentry *hdp;
3408 + AuRwMustWriteLock(&dinfo->di_rwsem);
3410 + hdp = au_hdentry(dinfo, bindex);
3411 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3412 + au_h_dentry_init(hdp);
3414 + if (unlikely(bbot < 0))
3415 + dinfo->di_btop = 0;
3418 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3419 + aufs_bindex_t bbot, aufs_bindex_t amount)
3421 + struct au_hinode *hip;
3423 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3425 + hip = au_hinode(iinfo, bindex);
3426 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3427 + au_hinode_init(hip);
3429 + if (unlikely(bbot < 0))
3430 + iinfo->ii_btop = 0;
3433 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3434 + aufs_bindex_t bindex)
3436 + struct dentry *root, *h_dentry;
3437 + struct inode *root_inode, *h_inode;
3438 + aufs_bindex_t bbot, amount;
3440 + root = sb->s_root;
3441 + root_inode = d_inode(root);
3442 + bbot = au_sbbot(sb);
3443 + amount = bbot + 1 - bindex;
3444 + h_dentry = au_br_dentry(br);
3445 + au_sbilist_lock();
3446 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3447 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3448 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3449 + au_set_h_dptr(root, bindex, dget(h_dentry));
3450 + h_inode = d_inode(h_dentry);
3451 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3452 + au_sbilist_unlock();
3455 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3458 + aufs_bindex_t bbot, add_bindex;
3459 + struct dentry *root, *h_dentry;
3460 + struct inode *root_inode;
3461 + struct au_branch *add_branch;
3463 + root = sb->s_root;
3464 + root_inode = d_inode(root);
3465 + IMustLock(root_inode);
3466 + IiMustWriteLock(root_inode);
3467 + err = test_add(sb, add, remount);
3468 + if (unlikely(err < 0))
3472 + goto out; /* success */
3475 + bbot = au_sbbot(sb);
3476 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3477 + err = PTR_ERR(add_branch);
3478 + if (IS_ERR(add_branch))
3481 + err = au_br_init(add_branch, sb, add);
3482 + if (unlikely(err)) {
3483 + au_br_do_free(add_branch);
3487 + add_bindex = add->bindex;
3488 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3489 + au_br_do_add(sb, add_branch, add_bindex);
3490 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3491 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3493 + h_dentry = add->path.dentry;
3494 + if (!add_bindex) {
3495 + au_cpup_attr_all(root_inode, /*force*/1);
3496 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3498 + au_add_nlink(root_inode, d_inode(h_dentry));
3504 +/* ---------------------------------------------------------------------- */
3506 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3507 + unsigned long long max __maybe_unused,
3510 + unsigned long long n;
3511 + struct file **p, *f;
3512 + struct hlist_bl_head *files;
3513 + struct hlist_bl_node *pos;
3514 + struct au_finfo *finfo;
3518 + files = &au_sbi(sb)->si_files;
3519 + hlist_bl_lock(files);
3520 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3521 + f = finfo->fi_file;
3523 + && !special_file(file_inode(f)->i_mode)) {
3527 + AuDebugOn(n > max);
3530 + hlist_bl_unlock(files);
3535 +static struct file **au_farray_alloc(struct super_block *sb,
3536 + unsigned long long *max)
3538 + struct au_sbinfo *sbi;
3541 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3542 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3545 +static void au_farray_free(struct file **a, unsigned long long max)
3547 + unsigned long long ull;
3549 + for (ull = 0; ull < max; ull++)
3555 +/* ---------------------------------------------------------------------- */
3561 +/* to show the line number, do not make it inlined function */
3562 +#define AuVerbose(do_info, fmt, ...) do { \
3564 + pr_info(fmt, ##__VA_ARGS__); \
3567 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3568 + aufs_bindex_t bbot)
3570 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3573 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3574 + aufs_bindex_t bbot)
3576 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3580 + * test if the branch is deletable or not.
3582 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3583 + unsigned int sigen, const unsigned int verbose)
3585 + int err, i, j, ndentry;
3586 + aufs_bindex_t btop, bbot;
3587 + struct au_dcsub_pages dpages;
3588 + struct au_dpage *dpage;
3591 + err = au_dpages_init(&dpages, GFP_NOFS);
3592 + if (unlikely(err))
3594 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3595 + if (unlikely(err))
3598 + for (i = 0; !err && i < dpages.ndpage; i++) {
3599 + dpage = dpages.dpages + i;
3600 + ndentry = dpage->ndentry;
3601 + for (j = 0; !err && j < ndentry; j++) {
3602 + d = dpage->dentries[j];
3603 + AuDebugOn(au_dcount(d) <= 0);
3604 + if (!au_digen_test(d, sigen)) {
3605 + di_read_lock_child(d, AuLock_IR);
3606 + if (unlikely(au_dbrange_test(d))) {
3607 + di_read_unlock(d, AuLock_IR);
3611 + di_write_lock_child(d);
3612 + if (unlikely(au_dbrange_test(d))) {
3613 + di_write_unlock(d);
3616 + err = au_reval_dpath(d, sigen);
3618 + di_downgrade_lock(d, AuLock_IR);
3620 + di_write_unlock(d);
3625 + /* AuDbgDentry(d); */
3626 + btop = au_dbtop(d);
3627 + bbot = au_dbbot(d);
3628 + if (btop <= bindex
3630 + && au_h_dptr(d, bindex)
3631 + && au_test_dbusy(d, btop, bbot)) {
3633 + AuVerbose(verbose, "busy %pd\n", d);
3636 + di_read_unlock(d, AuLock_IR);
3641 + au_dpages_free(&dpages);
3646 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3647 + unsigned int sigen, const unsigned int verbose)
3650 + unsigned long long max, ull;
3651 + struct inode *i, **array;
3652 + aufs_bindex_t btop, bbot;
3654 + array = au_iarray_alloc(sb, &max);
3655 + err = PTR_ERR(array);
3656 + if (IS_ERR(array))
3660 + AuDbg("b%d\n", bindex);
3661 + for (ull = 0; !err && ull < max; ull++) {
3665 + if (i->i_ino == AUFS_ROOT_INO)
3668 + /* AuDbgInode(i); */
3669 + if (au_iigen(i, NULL) == sigen)
3670 + ii_read_lock_child(i);
3672 + ii_write_lock_child(i);
3673 + err = au_refresh_hinode_self(i);
3676 + ii_downgrade_lock(i);
3678 + ii_write_unlock(i);
3683 + btop = au_ibtop(i);
3684 + bbot = au_ibbot(i);
3685 + if (btop <= bindex
3687 + && au_h_iptr(i, bindex)
3688 + && au_test_ibusy(i, btop, bbot)) {
3690 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3693 + ii_read_unlock(i);
3695 + au_iarray_free(array, max);
3701 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3702 + const unsigned int verbose)
3705 + unsigned int sigen;
3707 + sigen = au_sigen(root->d_sb);
3708 + DiMustNoWaiters(root);
3709 + IiMustNoWaiters(d_inode(root));
3710 + di_write_unlock(root);
3711 + err = test_dentry_busy(root, bindex, sigen, verbose);
3713 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3714 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3719 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3720 + struct file **to_free, int *idx)
3723 + unsigned char matched, root;
3724 + aufs_bindex_t bindex, bbot;
3725 + struct au_fidir *fidir;
3726 + struct au_hfile *hfile;
3729 + root = IS_ROOT(file->f_path.dentry);
3732 + to_free[*idx] = file;
3738 + fidir = au_fi(file)->fi_hdir;
3739 + AuDebugOn(!fidir);
3740 + bbot = au_fbbot_dir(file);
3741 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3742 + hfile = fidir->fd_hfile + bindex;
3743 + if (!hfile->hf_file)
3746 + if (hfile->hf_br->br_id == br_id) {
3758 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3759 + struct file **to_free, int opened)
3762 + unsigned long long ull, max;
3763 + aufs_bindex_t btop;
3764 + struct file *file, **array;
3765 + struct dentry *root;
3766 + struct au_hfile *hfile;
3768 + array = au_farray_alloc(sb, &max);
3769 + err = PTR_ERR(array);
3770 + if (IS_ERR(array))
3775 + root = sb->s_root;
3776 + di_write_unlock(root);
3777 + for (ull = 0; ull < max; ull++) {
3778 + file = array[ull];
3779 + if (unlikely(!file))
3782 + /* AuDbg("%pD\n", file); */
3783 + fi_read_lock(file);
3784 + btop = au_fbtop(file);
3785 + if (!d_is_dir(file->f_path.dentry)) {
3786 + hfile = &au_fi(file)->fi_htop;
3787 + if (hfile->hf_br->br_id == br_id)
3790 + err = test_dir_busy(file, br_id, to_free, &idx);
3791 + fi_read_unlock(file);
3792 + if (unlikely(err))
3795 + di_write_lock_child(root);
3796 + au_farray_free(array, max);
3797 + AuDebugOn(idx > opened);
3803 +static void br_del_file(struct file **to_free, unsigned long long opened,
3804 + aufs_bindex_t br_id)
3806 + unsigned long long ull;
3807 + aufs_bindex_t bindex, btop, bbot, bfound;
3808 + struct file *file;
3809 + struct au_fidir *fidir;
3810 + struct au_hfile *hfile;
3812 + for (ull = 0; ull < opened; ull++) {
3813 + file = to_free[ull];
3814 + if (unlikely(!file))
3817 + /* AuDbg("%pD\n", file); */
3818 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3820 + fidir = au_fi(file)->fi_hdir;
3821 + AuDebugOn(!fidir);
3822 + fi_write_lock(file);
3823 + btop = au_fbtop(file);
3824 + bbot = au_fbbot_dir(file);
3825 + for (bindex = btop; bindex <= bbot; bindex++) {
3826 + hfile = fidir->fd_hfile + bindex;
3827 + if (!hfile->hf_file)
3830 + if (hfile->hf_br->br_id == br_id) {
3835 + AuDebugOn(bfound < 0);
3836 + au_set_h_fptr(file, bfound, NULL);
3837 + if (bfound == btop) {
3838 + for (btop++; btop <= bbot; btop++)
3839 + if (au_hf_dir(file, btop)) {
3840 + au_set_fbtop(file, btop);
3844 + fi_write_unlock(file);
3848 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3849 + const aufs_bindex_t bindex,
3850 + const aufs_bindex_t bbot)
3852 + struct au_branch **brp, **p;
3854 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3856 + brp = sbinfo->si_branch + bindex;
3857 + if (bindex < bbot)
3858 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3859 + sbinfo->si_branch[0 + bbot] = NULL;
3860 + sbinfo->si_bbot--;
3862 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3865 + sbinfo->si_branch = p;
3866 + /* harmless error */
3869 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3870 + const aufs_bindex_t bbot)
3872 + struct au_hdentry *hdp, *p;
3874 + AuRwMustWriteLock(&dinfo->di_rwsem);
3876 + hdp = au_hdentry(dinfo, bindex);
3877 + if (bindex < bbot)
3878 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3879 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3882 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3885 + dinfo->di_hdentry = p;
3886 + /* harmless error */
3889 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3890 + const aufs_bindex_t bbot)
3892 + struct au_hinode *hip, *p;
3894 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3896 + hip = au_hinode(iinfo, bindex);
3897 + if (bindex < bbot)
3898 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3899 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3902 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3905 + iinfo->ii_hinode = p;
3906 + /* harmless error */
3909 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3910 + struct au_branch *br)
3912 + aufs_bindex_t bbot;
3913 + struct au_sbinfo *sbinfo;
3914 + struct dentry *root, *h_root;
3915 + struct inode *inode, *h_inode;
3916 + struct au_hinode *hinode;
3918 + SiMustWriteLock(sb);
3920 + root = sb->s_root;
3921 + inode = d_inode(root);
3922 + sbinfo = au_sbi(sb);
3923 + bbot = sbinfo->si_bbot;
3925 + h_root = au_h_dptr(root, bindex);
3926 + hinode = au_hi(inode, bindex);
3927 + h_inode = au_igrab(hinode->hi_inode);
3930 + au_sbilist_lock();
3931 + au_br_do_del_brp(sbinfo, bindex, bbot);
3932 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3933 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3934 + au_sbilist_unlock();
3936 + /* ignore an error */
3937 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3941 + au_br_do_free(br);
3944 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3945 + unsigned long long max, void *arg)
3950 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3953 + unsigned long long opened;
3954 + unsigned int mnt_flags;
3955 + aufs_bindex_t bindex, bbot, br_id;
3956 + unsigned char do_wh, verbose;
3957 + struct au_branch *br;
3958 + struct au_wbr *wbr;
3959 + struct dentry *root;
3960 + struct file **to_free;
3965 + root = sb->s_root;
3966 + bindex = au_find_dbindex(root, del->h_path.dentry);
3969 + goto out; /* success */
3971 + pr_err("%s no such branch\n", del->pathname);
3974 + AuDbg("bindex b%d\n", bindex);
3977 + mnt_flags = au_mntflags(sb);
3978 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3979 + bbot = au_sbbot(sb);
3980 + if (unlikely(!bbot)) {
3981 + AuVerbose(verbose, "no more branches left\n");
3985 + br = au_sbr(sb, bindex);
3986 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3987 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3988 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3992 + br_id = br->br_id;
3993 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3994 + if (unlikely(opened)) {
3995 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3996 + err = PTR_ERR(to_free);
3997 + if (IS_ERR(to_free))
4000 + err = test_file_busy(sb, br_id, to_free, opened);
4001 + if (unlikely(err)) {
4002 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
4008 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
4010 + /* instead of WbrWhMustWriteLock(wbr) */
4011 + SiMustWriteLock(sb);
4012 + for (i = 0; i < AuBrWh_Last; i++) {
4013 + dput(wbr->wbr_wh[i]);
4014 + wbr->wbr_wh[i] = NULL;
4018 + err = test_children_busy(root, bindex, verbose);
4019 + if (unlikely(err)) {
4028 + * now we confirmed the branch is deletable.
4029 + * let's free the remaining opened dirs on the branch.
4031 + di_write_unlock(root);
4032 + br_del_file(to_free, opened, br_id);
4033 + di_write_lock_child(root);
4036 + sysaufs_brs_del(sb, bindex); /* remove successors */
4037 + dbgaufs_xino_del(br); /* remove one */
4038 + au_br_do_del(sb, bindex, br);
4039 + sysaufs_brs_add(sb, bindex); /* append successors */
4040 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4043 + au_cpup_attr_all(d_inode(root), /*force*/1);
4044 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4046 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4047 + if (au_opt_test(mnt_flags, PLINK))
4048 + au_plink_half_refresh(sb, br_id);
4050 + goto out; /* success */
4054 + rerr = au_br_init_wh(sb, br, br->br_perm);
4056 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4057 + del->pathname, rerr);
4060 + au_farray_free(to_free, opened);
4064 +/* ---------------------------------------------------------------------- */
4066 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4069 + aufs_bindex_t btop, bbot;
4070 + struct aufs_ibusy ibusy;
4071 + struct inode *inode, *h_inode;
4074 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4077 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4079 + /* VERIFY_WRITE */
4080 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4081 + if (unlikely(err)) {
4088 + si_read_lock(sb, AuLock_FLUSH);
4089 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4093 + ibusy.h_ino = 0; /* invalid */
4094 + inode = ilookup(sb, ibusy.ino);
4096 + || inode->i_ino == AUFS_ROOT_INO
4097 + || au_is_bad_inode(inode))
4100 + ii_read_lock_child(inode);
4101 + btop = au_ibtop(inode);
4102 + bbot = au_ibbot(inode);
4103 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4104 + h_inode = au_h_iptr(inode, ibusy.bindex);
4105 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4106 + ibusy.h_ino = h_inode->i_ino;
4108 + ii_read_unlock(inode);
4112 + si_read_unlock(sb);
4114 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4115 + if (unlikely(err)) {
4124 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4126 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4129 +#ifdef CONFIG_COMPAT
4130 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4132 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4136 +/* ---------------------------------------------------------------------- */
4139 + * change a branch permission
4142 +static void au_warn_ima(void)
4145 + /* since it doesn't support mark_files_ro() */
4146 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4150 +static int do_need_sigen_inc(int a, int b)
4152 + return au_br_whable(a) && !au_br_whable(b);
4155 +static int need_sigen_inc(int old, int new)
4157 + return do_need_sigen_inc(old, new)
4158 + || do_need_sigen_inc(new, old);
4161 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4164 + unsigned int mnt_flags;
4165 + unsigned long long ull, max;
4166 + aufs_bindex_t br_id;
4167 + unsigned char verbose, writer;
4168 + struct file *file, *hf, **array;
4169 + struct au_hfile *hfile;
4170 + struct inode *h_inode;
4172 + mnt_flags = au_mntflags(sb);
4173 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4175 + array = au_farray_alloc(sb, &max);
4176 + err = PTR_ERR(array);
4177 + if (IS_ERR(array))
4181 + br_id = au_sbr_id(sb, bindex);
4182 + for (ull = 0; ull < max; ull++) {
4183 + file = array[ull];
4184 + if (unlikely(!file))
4187 + /* AuDbg("%pD\n", file); */
4188 + fi_read_lock(file);
4189 + if (unlikely(au_test_mmapped(file))) {
4191 + AuVerbose(verbose, "mmapped %pD\n", file);
4193 + FiMustNoWaiters(file);
4194 + fi_read_unlock(file);
4198 + hfile = &au_fi(file)->fi_htop;
4199 + hf = hfile->hf_file;
4200 + if (!d_is_reg(file->f_path.dentry)
4201 + || !(file->f_mode & FMODE_WRITE)
4202 + || hfile->hf_br->br_id != br_id
4203 + || !(hf->f_mode & FMODE_WRITE))
4204 + array[ull] = NULL;
4210 + FiMustNoWaiters(file);
4211 + fi_read_unlock(file);
4219 + for (ull = 0; ull < max; ull++) {
4220 + file = array[ull];
4224 + /* todo: already flushed? */
4226 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4227 + * approach which resets f_mode and calls mnt_drop_write() and
4228 + * file_release_write() for each file, because the branch
4229 + * attribute in aufs world is totally different from the native
4232 + /* fi_read_lock(file); */
4233 + hfile = &au_fi(file)->fi_htop;
4234 + hf = hfile->hf_file;
4235 + /* fi_read_unlock(file); */
4236 + spin_lock(&hf->f_lock);
4237 + writer = !!(hf->f_mode & FMODE_WRITER);
4238 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4239 + spin_unlock(&hf->f_lock);
4241 + h_inode = file_inode(hf);
4242 + if (hf->f_mode & FMODE_READ)
4243 + i_readcount_inc(h_inode);
4244 + put_write_access(h_inode);
4245 + __mnt_drop_write(hf->f_path.mnt);
4250 + au_farray_free(array, max);
4256 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4260 + aufs_bindex_t bindex;
4261 + struct dentry *root;
4262 + struct au_branch *br;
4263 + struct au_br_fhsm *bf;
4265 + root = sb->s_root;
4266 + bindex = au_find_dbindex(root, mod->h_root);
4269 + return 0; /* success */
4271 + pr_err("%s no such branch\n", mod->path);
4274 + AuDbg("bindex b%d\n", bindex);
4276 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4277 + if (unlikely(err))
4280 + br = au_sbr(sb, bindex);
4281 + AuDebugOn(mod->h_root != au_br_dentry(br));
4282 + if (br->br_perm == mod->perm)
4283 + return 0; /* success */
4285 + /* pre-allocate for non-fhsm --> fhsm */
4287 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4288 + err = au_fhsm_br_alloc(br);
4289 + if (unlikely(err))
4292 + br->br_fhsm = NULL;
4295 + if (au_br_writable(br->br_perm)) {
4296 + /* remove whiteout base */
4297 + err = au_br_init_wh(sb, br, mod->perm);
4298 + if (unlikely(err))
4301 + if (!au_br_writable(mod->perm)) {
4302 + /* rw --> ro, file might be mmapped */
4303 + DiMustNoWaiters(root);
4304 + IiMustNoWaiters(d_inode(root));
4305 + di_write_unlock(root);
4306 + err = au_br_mod_files_ro(sb, bindex);
4307 + /* aufs_write_lock() calls ..._child() */
4308 + di_write_lock_child(root);
4310 + if (unlikely(err)) {
4312 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4315 + rerr = au_wbr_init(br, sb, br->br_perm);
4316 + if (unlikely(rerr)) {
4317 + AuIOErr("nested error %d (%d)\n",
4319 + br->br_perm = mod->perm;
4323 + } else if (au_br_writable(mod->perm)) {
4326 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4328 + err = au_wbr_init(br, sb, mod->perm);
4329 + if (unlikely(err)) {
4330 + au_kfree_rcu(br->br_wbr);
4331 + br->br_wbr = NULL;
4335 + if (unlikely(err))
4338 + if (au_br_fhsm(br->br_perm)) {
4339 + if (!au_br_fhsm(mod->perm)) {
4340 + /* fhsm --> non-fhsm */
4341 + au_br_fhsm_fin(br->br_fhsm);
4342 + au_kfree_rcu(br->br_fhsm);
4343 + br->br_fhsm = NULL;
4345 + } else if (au_br_fhsm(mod->perm))
4346 + /* non-fhsm --> fhsm */
4349 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4350 + br->br_perm = mod->perm;
4351 + goto out; /* success */
4354 + au_kfree_try_rcu(bf);
4360 +/* ---------------------------------------------------------------------- */
4362 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4365 + struct kstatfs kstfs;
4367 + err = vfs_statfs(&br->br_path, &kstfs);
4369 + stfs->f_blocks = kstfs.f_blocks;
4370 + stfs->f_bavail = kstfs.f_bavail;
4371 + stfs->f_files = kstfs.f_files;
4372 + stfs->f_ffree = kstfs.f_ffree;
4377 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4378 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4379 +++ linux/fs/aufs/branch.h 2021-02-22 22:51:59.058078584 +0100
4381 +/* SPDX-License-Identifier: GPL-2.0 */
4383 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4385 + * This program, aufs is free software; you can redistribute it and/or modify
4386 + * it under the terms of the GNU General Public License as published by
4387 + * the Free Software Foundation; either version 2 of the License, or
4388 + * (at your option) any later version.
4390 + * This program is distributed in the hope that it will be useful,
4391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4393 + * GNU General Public License for more details.
4395 + * You should have received a copy of the GNU General Public License
4396 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4400 + * branch filesystems and xino for them
4403 +#ifndef __AUFS_BRANCH_H__
4404 +#define __AUFS_BRANCH_H__
4408 +#include <linux/mount.h>
4409 +#include "dirren.h"
4415 +/* ---------------------------------------------------------------------- */
4419 + struct file **xi_file;
4420 + unsigned int xi_nfile;
4426 + /* reserved for future use */
4427 + /* unsigned long *bitmap; */
4428 + wait_queue_head_t wqh;
4431 + struct mutex xi_mtx; /* protects xi_file array */
4432 + struct hlist_bl_head xi_writing;
4434 + atomic_t xi_truncating;
4436 + struct kref xi_kref;
4439 +/* File-based Hierarchical Storage Management */
4440 +struct au_br_fhsm {
4441 +#ifdef CONFIG_AUFS_FHSM
4442 + struct mutex bf_lock;
4443 + unsigned long bf_jiffy;
4444 + struct aufs_stfs bf_stfs;
4449 +/* members for writable branch only */
4450 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4452 + struct au_rwsem wbr_wh_rwsem;
4453 + struct dentry *wbr_wh[AuBrWh_Last];
4454 + atomic_t wbr_wh_running;
4455 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4456 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4457 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4460 + unsigned long long wbr_bytes;
4463 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4464 +#define AuBrDynOp (AuDyLast * 4)
4466 +#ifdef CONFIG_AUFS_HFSNOTIFY
4467 +/* support for asynchronous destruction */
4468 +struct au_br_hfsnotify {
4469 + struct fsnotify_group *hfsn_group;
4473 +/* sysfs entries */
4474 +struct au_brsysfs {
4476 + struct attribute attr;
4485 +/* protected by superblock rwsem */
4487 + struct au_xino *br_xino;
4489 + aufs_bindex_t br_id;
4492 + struct path br_path;
4493 + spinlock_t br_dykey_lock;
4494 + struct au_dykey *br_dykey[AuBrDynOp];
4495 + au_lcnt_t br_nfiles; /* opened files */
4496 + au_lcnt_t br_count; /* in-use for other */
4498 + struct au_wbr *br_wbr;
4499 + struct au_br_fhsm *br_fhsm;
4501 +#ifdef CONFIG_AUFS_HFSNOTIFY
4502 + struct au_br_hfsnotify *br_hfsn;
4505 +#ifdef CONFIG_SYSFS
4506 + /* entries under sysfs per mount-point */
4507 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4510 +#ifdef CONFIG_DEBUG_FS
4511 + struct dentry *br_dbgaufs; /* xino */
4514 + struct au_dr_br br_dirren;
4517 +/* ---------------------------------------------------------------------- */
4519 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4521 + return br->br_path.mnt;
4524 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4526 + return br->br_path.dentry;
4529 +static inline struct super_block *au_br_sb(struct au_branch *br)
4531 + return au_br_mnt(br)->mnt_sb;
4534 +static inline int au_br_rdonly(struct au_branch *br)
4536 + return (sb_rdonly(au_br_sb(br))
4537 + || !au_br_writable(br->br_perm))
4541 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4543 +#ifdef CONFIG_AUFS_HNOTIFY
4544 + return !(brperm & AuBrPerm_RR);
4550 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4552 + int err, exec_flag;
4555 + exec_flag = oflag & __FMODE_EXEC;
4556 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4562 +static inline void au_xino_get(struct au_branch *br)
4564 + struct au_xino *xi;
4568 + kref_get(&xi->xi_kref);
4571 +static inline int au_xino_count(struct au_branch *br)
4574 + struct au_xino *xi;
4579 + v = kref_read(&xi->xi_kref);
4584 +/* ---------------------------------------------------------------------- */
4588 +void au_br_free(struct au_sbinfo *sinfo);
4589 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4591 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4593 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4594 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4595 +#ifdef CONFIG_COMPAT
4596 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4599 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4602 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4605 +static const loff_t au_loff_max = LLONG_MAX;
4607 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4608 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4610 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4611 + struct file *copy_src);
4613 + struct au_xino *xi; /* switch between xino and xigen */
4615 + struct path *base;
4616 + struct file *copy_src;
4618 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4620 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4622 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4624 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4625 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4627 +int au_xib_trunc(struct super_block *sb);
4628 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4630 +struct au_xino *au_xino_alloc(unsigned int nfile);
4631 +int au_xino_put(struct au_branch *br);
4632 +struct file *au_xino_file1(struct au_xino *xi);
4634 +struct au_opt_xino;
4635 +void au_xino_clr(struct super_block *sb);
4636 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4637 +struct file *au_xino_def(struct super_block *sb);
4638 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4639 + struct path *base);
4641 +ino_t au_xino_new_ino(struct super_block *sb);
4642 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4644 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4645 + ino_t h_ino, int idx);
4646 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4649 +int au_xino_path(struct seq_file *seq, struct file *file);
4651 +/* ---------------------------------------------------------------------- */
4653 +/* @idx is signed to accept -1 meaning the first file */
4654 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4656 + struct file *file;
4663 + if (idx < xi->xi_nfile)
4664 + file = xi->xi_file[idx];
4666 + file = au_xino_file1(xi);
4672 +/* ---------------------------------------------------------------------- */
4674 +/* Superblock to branch */
4676 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4678 + return au_sbr(sb, bindex)->br_id;
4682 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4684 + return au_br_mnt(au_sbr(sb, bindex));
4688 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4690 + return au_br_sb(au_sbr(sb, bindex));
4693 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4695 + return au_sbr(sb, bindex)->br_perm;
4698 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4700 + return au_br_whable(au_sbr_perm(sb, bindex));
4703 +/* ---------------------------------------------------------------------- */
4705 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4706 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4707 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4708 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4710 +#define wbr_wh_read_trylock_nested(wbr) \
4711 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4712 +#define wbr_wh_write_trylock_nested(wbr) \
4713 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4716 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4717 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4718 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4720 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4721 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4722 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4724 +/* ---------------------------------------------------------------------- */
4726 +#ifdef CONFIG_AUFS_FHSM
4727 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4729 + mutex_init(&brfhsm->bf_lock);
4730 + brfhsm->bf_jiffy = 0;
4731 + brfhsm->bf_readable = 0;
4734 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4736 + mutex_destroy(&brfhsm->bf_lock);
4739 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4740 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4743 +#endif /* __KERNEL__ */
4744 +#endif /* __AUFS_BRANCH_H__ */
4745 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4746 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4747 +++ linux/fs/aufs/conf.mk 2021-02-22 22:51:59.058078584 +0100
4749 +# SPDX-License-Identifier: GPL-2.0
4751 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4755 +AuConfStr += ${1}=${${1}}
4759 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4761 + HNOTIFY HFSNOTIFY \
4773 +$(foreach i, ${AuConfAll}, \
4774 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4776 +AuConfName = ${obj}/conf.str
4777 +${AuConfName}.tmp: FORCE
4778 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4779 +${AuConfName}: ${AuConfName}.tmp
4780 + @diff -q $< $@ > /dev/null 2>&1 || { \
4781 + echo ' GEN ' $@; \
4785 +clean-files += ${AuConfName} ${AuConfName}.tmp
4786 +${obj}/sysfs.o: ${AuConfName}
4788 +-include ${srctree}/${src}/conf_priv.mk
4789 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4790 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4791 +++ linux/fs/aufs/cpup.c 2021-02-22 22:51:59.058078584 +0100
4793 +// SPDX-License-Identifier: GPL-2.0
4795 + * Copyright (C) 2005-2020 Junjiro R. Okajima
4797 + * This program, aufs is free software; you can redistribute it and/or modify
4798 + * it under the terms of the GNU General Public License as published by
4799 + * the Free Software Foundation; either version 2 of the License, or
4800 + * (at your option) any later version.
4802 + * This program is distributed in the hope that it will be useful,
4803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4805 + * GNU General Public License for more details.
4807 + * You should have received a copy of the GNU General Public License
4808 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4812 + * copy-up functions, see wbr_policy.c for copy-down
4815 +#include <linux/fs_stack.h>
4816 +#include <linux/mm.h>
4817 +#include <linux/task_work.h>
4820 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4822 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4823 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4825 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4827 + dst->i_flags |= iflags & ~mask;
4828 + if (au_test_fs_notime(dst->i_sb))
4829 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4832 +void au_cpup_attr_timesizes(struct inode *inode)
4834 + struct inode *h_inode;
4836 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4837 + fsstack_copy_attr_times(inode, h_inode);
4838 + fsstack_copy_inode_size(inode, h_inode);
4841 +void au_cpup_attr_nlink(struct inode *inode, int force)
4843 + struct inode *h_inode;
4844 + struct super_block *sb;
4845 + aufs_bindex_t bindex, bbot;
4848 + bindex = au_ibtop(inode);
4849 + h_inode = au_h_iptr(inode, bindex);
4851 + && !S_ISDIR(h_inode->i_mode)
4852 + && au_opt_test(au_mntflags(sb), PLINK)
4853 + && au_plink_test(inode))
4857 + * 0 can happen in revalidating.
4858 + * h_inode->i_mutex may not be held here, but it is harmless since once
4859 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4861 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4862 + * the incorrect link count.
4864 + set_nlink(inode, h_inode->i_nlink);
4867 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4868 + * it may includes whplink directory.
4870 + if (S_ISDIR(h_inode->i_mode)) {
4871 + bbot = au_ibbot(inode);
4872 + for (bindex++; bindex <= bbot; bindex++) {
4873 + h_inode = au_h_iptr(inode, bindex);
4875 + au_add_nlink(inode, h_inode);
4880 +void au_cpup_attr_changeable(struct inode *inode)
4882 + struct inode *h_inode;
4884 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4885 + inode->i_mode = h_inode->i_mode;
4886 + inode->i_uid = h_inode->i_uid;
4887 + inode->i_gid = h_inode->i_gid;
4888 + au_cpup_attr_timesizes(inode);
4889 + au_cpup_attr_flags(inode, h_inode->i_flags);
4892 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4894 + struct au_iinfo *iinfo = au_ii(inode);
4896 + IiMustWriteLock(inode);
4898 + iinfo->ii_higen = h_inode->i_generation;
4899 + iinfo->ii_hsb1 = h_inode->i_sb;
4902 +void au_cpup_attr_all(struct inode *inode, int force)
4904 + struct inode *h_inode;
4906 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4907 + au_cpup_attr_changeable(inode);
4908 + if (inode->i_nlink > 0)
4909 + au_cpup_attr_nlink(inode, force);
4910 + inode->i_rdev = h_inode->i_rdev;
4911 + inode->i_blkbits = h_inode->i_blkbits;
4912 + au_cpup_igen(inode, h_inode);
4915 +/* ---------------------------------------------------------------------- */
4917 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4919 +/* keep the timestamps of the parent dir when cpup */
4920 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4921 + struct path *h_path)
4923 + struct inode *h_inode;
4925 + dt->dt_dentry = dentry;
4926 + dt->dt_h_path = *h_path;
4927 + h_inode = d_inode(h_path->dentry);
4928 + dt->dt_atime = h_inode->i_atime;
4929 + dt->dt_mtime = h_inode->i_mtime;
4933 +void au_dtime_revert(struct au_dtime *dt)
4935 + struct iattr attr;
4938 + attr.ia_atime = dt->dt_atime;
4939 + attr.ia_mtime = dt->dt_mtime;
4940 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4941 + | ATTR_ATIME | ATTR_ATIME_SET;
4943 + /* no delegation since this is a directory */
4944 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4945 + if (unlikely(err))
4946 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4949 +/* ---------------------------------------------------------------------- */
4951 +/* internal use only */
4952 +struct au_cpup_reg_attr {
4955 + unsigned int iflags; /* inode->i_flags */
4958 +static noinline_for_stack
4959 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4960 + struct au_cpup_reg_attr *h_src_attr)
4962 + int err, sbits, icex;
4963 + unsigned int mnt_flags;
4964 + unsigned char verbose;
4966 + struct path h_path;
4967 + struct inode *h_isrc, *h_idst;
4968 + struct kstat *h_st;
4969 + struct au_branch *br;
4971 + h_path.dentry = au_h_dptr(dst, bindex);
4972 + h_idst = d_inode(h_path.dentry);
4973 + br = au_sbr(dst->d_sb, bindex);
4974 + h_path.mnt = au_br_mnt(br);
4975 + h_isrc = d_inode(h_src);
4976 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4977 + | ATTR_ATIME | ATTR_MTIME
4978 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4979 + if (h_src_attr && h_src_attr->valid) {
4980 + h_st = &h_src_attr->st;
4981 + ia.ia_uid = h_st->uid;
4982 + ia.ia_gid = h_st->gid;
4983 + ia.ia_atime = h_st->atime;
4984 + ia.ia_mtime = h_st->mtime;
4985 + if (h_idst->i_mode != h_st->mode
4986 + && !S_ISLNK(h_idst->i_mode)) {
4987 + ia.ia_valid |= ATTR_MODE;
4988 + ia.ia_mode = h_st->mode;
4990 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4991 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4993 + ia.ia_uid = h_isrc->i_uid;
4994 + ia.ia_gid = h_isrc->i_gid;
4995 + ia.ia_atime = h_isrc->i_atime;
4996 + ia.ia_mtime = h_isrc->i_mtime;
4997 + if (h_idst->i_mode != h_isrc->i_mode
4998 + && !S_ISLNK(h_idst->i_mode)) {
4999 + ia.ia_valid |= ATTR_MODE;
5000 + ia.ia_mode = h_isrc->i_mode;
5002 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
5003 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
5005 + /* no delegation since it is just created */
5006 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5008 + /* is this nfs only? */
5009 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
5010 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
5011 + ia.ia_mode = h_isrc->i_mode;
5012 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
5015 + icex = br->br_perm & AuBrAttr_ICEX;
5017 + mnt_flags = au_mntflags(dst->d_sb);
5018 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
5019 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
5025 +/* ---------------------------------------------------------------------- */
5027 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5028 + char *buf, unsigned long blksize)
5031 + size_t sz, rbytes, wbytes;
5032 + unsigned char all_zero;
5034 + struct inode *h_inode;
5035 + /* reduce stack usage */
5038 + zp = page_address(ZERO_PAGE(0));
5039 + if (unlikely(!zp))
5040 + return -ENOMEM; /* possible? */
5045 + AuDbg("len %lld\n", len);
5047 + if (len < blksize)
5051 + /* todo: signal_pending? */
5052 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5053 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5056 + if (unlikely(err < 0))
5060 + if (len >= rbytes && rbytes == blksize)
5061 + all_zero = !memcmp(buf, zp, rbytes);
5068 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5070 + /* todo: signal_pending? */
5071 + if (unlikely(err == -EAGAIN || err == -EINTR))
5073 + if (unlikely(err < 0))
5078 + if (unlikely(err < 0))
5084 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5086 + if (unlikely(res < 0))
5093 + /* the last block may be a hole */
5094 + if (!err && all_zero) {
5095 + AuLabel(last hole);
5098 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5099 + /* nfs requires this step to make last hole */
5100 + /* is this only nfs? */
5102 + /* todo: signal_pending? */
5103 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5104 + } while (err == -EAGAIN || err == -EINTR);
5111 + ia->ia_size = dst->f_pos;
5112 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5113 + ia->ia_file = dst;
5114 + h_inode = file_inode(dst);
5115 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5116 + /* no delegation since it is just created */
5117 + err = vfsub_notify_change(&dst->f_path, ia,
5118 + /*delegated*/NULL);
5119 + inode_unlock(h_inode);
5126 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5129 + unsigned long blksize;
5130 + unsigned char do_kfree;
5132 + struct super_block *h_sb;
5135 + h_sb = file_inode(dst)->i_sb;
5136 + blksize = h_sb->s_blocksize;
5137 + if (!blksize || PAGE_SIZE < blksize)
5138 + blksize = PAGE_SIZE;
5139 + AuDbg("blksize %lu\n", blksize);
5140 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5142 + buf = kmalloc(blksize, GFP_NOFS);
5144 + buf = (void *)__get_free_page(GFP_NOFS);
5145 + if (unlikely(!buf))
5148 + if (len > (1 << 22))
5149 + AuDbg("copying a large file %lld\n", (long long)len);
5153 + err = au_do_copy_file(dst, src, len, buf, blksize);
5155 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5156 + au_kfree_do_rcu(buf);
5158 + free_page((unsigned long)buf);
5164 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5167 + struct super_block *h_src_sb;
5168 + struct inode *h_src_inode;
5170 + h_src_inode = file_inode(src);
5171 + h_src_sb = h_src_inode->i_sb;
5173 + /* XFS acquires inode_lock */
5174 + if (!au_test_xfs(h_src_sb))
5175 + err = au_copy_file(dst, src, len);
5177 + inode_unlock_shared(h_src_inode);
5178 + err = au_copy_file(dst, src, len);
5179 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5185 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5189 + struct super_block *h_src_sb;
5190 + struct inode *h_src_inode;
5192 + h_src_inode = file_inode(src);
5193 + h_src_sb = h_src_inode->i_sb;
5194 + if (h_src_sb != file_inode(dst)->i_sb
5195 + || !dst->f_op->remap_file_range) {
5196 + err = au_do_copy(dst, src, len);
5200 + if (!au_test_nfs(h_src_sb)) {
5201 + inode_unlock_shared(h_src_inode);
5202 + lo = vfsub_clone_file_range(src, dst, len);
5203 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5205 + lo = vfsub_clone_file_range(src, dst, len);
5208 + goto out; /* success */
5209 + } else if (lo >= 0)
5210 + /* todo: possible? */
5211 + /* paritially succeeded */
5212 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5213 + else if (lo != -EOPNOTSUPP) {
5214 + /* older XFS has a condition in cloning */
5219 + /* the backend fs on NFS may not support cloning */
5220 + err = au_do_copy(dst, src, len);
5228 + * to support a sparse file which is opened with O_APPEND,
5229 + * we need to close the file.
5231 +static int au_cp_regular(struct au_cp_generic *cpg)
5234 + enum { SRC, DST };
5236 + aufs_bindex_t bindex;
5237 + unsigned int flags;
5238 + struct dentry *dentry;
5240 + struct file *file;
5243 + .bindex = cpg->bsrc,
5244 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5247 + .bindex = cpg->bdst,
5248 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5249 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5252 + struct au_branch *br;
5253 + struct super_block *sb, *h_src_sb;
5254 + struct inode *h_src_inode;
5255 + struct task_struct *tsk = current;
5257 + /* bsrc branch can be ro/rw. */
5258 + sb = cpg->dentry->d_sb;
5260 + for (i = 0; i < 2; i++, f++) {
5261 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5262 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5263 + /*file*/NULL, f->force_wr);
5264 + if (IS_ERR(f->file)) {
5265 + err = PTR_ERR(f->file);
5273 + /* try stopping to update while we copyup */
5274 + h_src_inode = d_inode(file[SRC].dentry);
5275 + h_src_sb = h_src_inode->i_sb;
5276 + if (!au_test_nfs(h_src_sb))
5277 + IMustLock(h_src_inode);
5278 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5280 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5281 + if (tsk->flags & PF_KTHREAD)
5282 + __fput_sync(file[DST].file);
5284 + /* it happened actually */
5285 + fput(file[DST].file);
5288 + * we have to call both since we don't know which place the file
5292 + flush_delayed_fput();
5294 + br = au_sbr(sb, file[DST].bindex);
5295 + au_lcnt_dec(&br->br_nfiles);
5298 + fput(file[SRC].file);
5299 + br = au_sbr(sb, file[SRC].bindex);
5300 + au_lcnt_dec(&br->br_nfiles);
5305 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5306 + struct au_cpup_reg_attr *h_src_attr)
5310 + struct path h_path;
5311 + struct inode *h_src_inode, *h_dst_inode;
5314 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5315 + l = i_size_read(h_src_inode);
5316 + if (cpg->len == -1 || l < cpg->len)
5319 + /* try stopping to update while we are referencing */
5320 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5321 + au_pin_hdir_unlock(cpg->pin);
5323 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5324 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5325 + h_src_attr->iflags = h_src_inode->i_flags;
5326 + if (!au_test_nfs(h_src_inode->i_sb))
5327 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5329 + inode_unlock_shared(h_src_inode);
5330 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5331 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5333 + if (unlikely(err)) {
5334 + inode_unlock_shared(h_src_inode);
5337 + h_src_attr->valid = 1;
5338 + if (!au_test_nfs(h_src_inode->i_sb)) {
5339 + err = au_cp_regular(cpg);
5340 + inode_unlock_shared(h_src_inode);
5342 + inode_unlock_shared(h_src_inode);
5343 + err = au_cp_regular(cpg);
5345 + rerr = au_pin_hdir_relock(cpg->pin);
5349 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5350 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5351 + h_dst_inode = d_inode(h_path.dentry);
5352 + spin_lock(&h_dst_inode->i_lock);
5353 + h_dst_inode->i_state |= I_LINKABLE;
5354 + spin_unlock(&h_dst_inode->i_lock);
5361 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5362 + struct inode *h_dir)
5365 + DEFINE_DELAYED_CALL(done);
5368 + sym = vfs_get_link(h_src, &done);
5369 + err = PTR_ERR(sym);
5373 + err = vfsub_symlink(h_dir, h_path, sym);
5376 + do_delayed_call(&done);
5381 + * regardless 'acl' option, reset all ACL.
5382 + * All ACL will be copied up later from the original entry on the lower branch.
5384 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5387 + struct dentry *h_dentry;
5388 + struct inode *h_inode;
5390 + h_dentry = h_path->dentry;
5391 + h_inode = d_inode(h_dentry);
5392 + /* forget_all_cached_acls(h_inode)); */
5393 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5395 + if (err == -EOPNOTSUPP)
5398 + err = vfsub_acl_chmod(h_inode, mode);
5404 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5405 + struct inode *h_dir, struct path *h_path)
5408 + struct inode *dir, *inode;
5410 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5412 + if (err == -EOPNOTSUPP)
5414 + if (unlikely(err))
5418 + * strange behaviour from the users view,
5419 + * particularly setattr case
5421 + dir = d_inode(dst_parent);
5422 + if (au_ibtop(dir) == cpg->bdst)
5423 + au_cpup_attr_nlink(dir, /*force*/1);
5424 + inode = d_inode(cpg->dentry);
5425 + au_cpup_attr_nlink(inode, /*force*/1);
5431 +static noinline_for_stack
5432 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5433 + struct au_cpup_reg_attr *h_src_attr)
5437 + unsigned int mnt_flags;
5438 + unsigned char isdir, isreg, force;
5439 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5440 + struct au_dtime dt;
5441 + struct path h_path;
5442 + struct dentry *h_src, *h_dst, *h_parent;
5443 + struct inode *h_inode, *h_dir;
5444 + struct super_block *sb;
5446 + /* bsrc branch can be ro/rw. */
5447 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5448 + h_inode = d_inode(h_src);
5449 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5451 + /* try stopping to be referenced while we are creating */
5452 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5453 + if (au_ftest_cpup(cpg->flags, RENAME))
5454 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5455 + AUFS_WH_PFX_LEN));
5456 + h_parent = h_dst->d_parent; /* dir inode is locked */
5457 + h_dir = d_inode(h_parent);
5459 + AuDebugOn(h_parent != h_dst->d_parent);
5461 + sb = cpg->dentry->d_sb;
5462 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5464 + h_path.dentry = h_parent;
5465 + au_dtime_store(&dt, dst_parent, &h_path);
5467 + h_path.dentry = h_dst;
5471 + mode = h_inode->i_mode;
5472 + switch (mode & S_IFMT) {
5475 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5477 + err = au_do_cpup_regular(cpg, h_src_attr);
5481 + err = vfsub_mkdir(h_dir, &h_path, mode);
5483 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5486 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5490 + AuDebugOn(!capable(CAP_MKNOD));
5494 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5497 + AuIOErr("Unknown inode type 0%o\n", mode);
5501 + err = au_reset_acl(h_dir, &h_path, mode);
5503 + mnt_flags = au_mntflags(sb);
5504 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5506 + && au_opt_test(mnt_flags, XINO)
5507 + && (h_inode->i_nlink == 1
5508 + || (h_inode->i_state & I_LINKABLE))
5509 + /* todo: unnecessary? */
5510 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5511 + && cpg->bdst < cpg->bsrc
5512 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5513 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5514 + /* ignore this error */
5519 + force = !!cpg->len;
5520 + if (cpg->len == -1)
5521 + force = !!i_size_read(h_inode);
5523 + au_fhsm_wrote(sb, cpg->bdst, force);
5527 + au_dtime_revert(&dt);
5531 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5534 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5535 + struct inode *h_dir;
5536 + aufs_bindex_t bdst;
5538 + dentry = cpg->dentry;
5540 + h_dentry = au_h_dptr(dentry, bdst);
5541 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5543 + au_set_h_dptr(dentry, bdst, NULL);
5544 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5546 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5547 + au_set_h_dptr(dentry, bdst, h_dentry);
5550 + parent = dget_parent(dentry);
5551 + h_parent = au_h_dptr(parent, bdst);
5553 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5554 + if (IS_ERR(h_path->dentry))
5555 + err = PTR_ERR(h_path->dentry);
5557 + if (unlikely(err))
5560 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5561 + h_dir = d_inode(h_parent);
5563 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5564 + /* no delegation since it is just created */
5565 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5567 + dput(h_path->dentry);
5574 + * copyup the @dentry from @bsrc to @bdst.
5575 + * the caller must set the both of lower dentries.
5576 + * @len is for truncating when it is -1 copyup the entire file.
5577 + * in link/rename cases, @dst_parent may be different from the real one.
5578 + * basic->bsrc can be larger than basic->bdst.
5579 + * aufs doesn't touch the credential so
5580 + * security_inode_copy_up{,_xattr}() are unnecessary.
5582 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5585 + aufs_bindex_t old_ibtop;
5586 + unsigned char isdir, plink;
5587 + struct dentry *h_src, *h_dst, *h_parent;
5588 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5589 + struct super_block *sb;
5590 + struct au_branch *br;
5591 + /* to reduce stack size */
5593 + struct au_dtime dt;
5594 + struct path h_path;
5595 + struct au_cpup_reg_attr h_src_attr;
5599 + a = kmalloc(sizeof(*a), GFP_NOFS);
5602 + a->h_src_attr.valid = 0;
5604 + sb = cpg->dentry->d_sb;
5605 + br = au_sbr(sb, cpg->bdst);
5606 + a->h_path.mnt = au_br_mnt(br);
5607 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5608 + h_parent = h_dst->d_parent; /* dir inode is locked */
5609 + h_dir = d_inode(h_parent);
5612 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5613 + inode = d_inode(cpg->dentry);
5616 + dst_parent = dget_parent(cpg->dentry);
5620 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5621 + dst_inode = au_h_iptr(inode, cpg->bdst);
5623 + if (unlikely(!plink)) {
5625 + AuIOErr("hi%lu(i%lu) exists on b%d "
5626 + "but plink is disabled\n",
5627 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5631 + if (dst_inode->i_nlink) {
5632 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5634 + h_src = au_plink_lkup(inode, cpg->bdst);
5635 + err = PTR_ERR(h_src);
5636 + if (IS_ERR(h_src))
5638 + if (unlikely(d_is_negative(h_src))) {
5640 + AuIOErr("i%lu exists on b%d "
5641 + "but not pseudo-linked\n",
5642 + inode->i_ino, cpg->bdst);
5648 + a->h_path.dentry = h_parent;
5649 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5652 + a->h_path.dentry = h_dst;
5654 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5655 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5656 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5658 + au_dtime_revert(&a->dt);
5659 + if (unlikely(err == -EWOULDBLOCK)) {
5660 + pr_warn("cannot retry for NFSv4 delegation"
5661 + " for an internal link\n");
5667 + /* todo: cpup_wh_file? */
5669 + au_update_ibrange(inode, /*do_put_zero*/1);
5672 + isdir = S_ISDIR(inode->i_mode);
5673 + old_ibtop = au_ibtop(inode);
5674 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5675 + if (unlikely(err))
5677 + dst_inode = d_inode(h_dst);
5678 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5679 + /* todo: necessary? */
5680 + /* au_pin_hdir_unlock(cpg->pin); */
5682 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5683 + if (unlikely(err)) {
5684 + /* todo: necessary? */
5685 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5686 + inode_unlock(dst_inode);
5690 + if (cpg->bdst < old_ibtop) {
5691 + if (S_ISREG(inode->i_mode)) {
5692 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5693 + if (unlikely(err)) {
5694 + /* ignore an error */
5695 + /* au_pin_hdir_relock(cpg->pin); */
5696 + inode_unlock(dst_inode);
5700 + au_set_ibtop(inode, cpg->bdst);
5702 + au_set_ibbot(inode, cpg->bdst);
5703 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5704 + au_hi_flags(inode, isdir));
5706 + /* todo: necessary? */
5707 + /* err = au_pin_hdir_relock(cpg->pin); */
5708 + inode_unlock(dst_inode);
5709 + if (unlikely(err))
5712 + src_inode = d_inode(h_src);
5714 + && (src_inode->i_nlink > 1
5715 + || src_inode->i_state & I_LINKABLE)
5717 + au_plink_append(inode, cpg->bdst, h_dst);
5719 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5720 + a->h_path.dentry = h_dst;
5721 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5724 + goto out_parent; /* success */
5728 + a->h_path.dentry = h_parent;
5729 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5730 + a->h_path.dentry = h_dst;
5732 + if (d_is_positive(h_dst)) {
5734 + /* no delegation since it is just created */
5735 + rerr = vfsub_unlink(h_dir, &a->h_path,
5736 + /*delegated*/NULL, /*force*/0);
5738 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5740 + au_dtime_revert(&a->dt);
5742 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5752 +#if 0 /* reserved */
5753 +struct au_cpup_single_args {
5755 + struct au_cp_generic *cpg;
5756 + struct dentry *dst_parent;
5759 +static void au_call_cpup_single(void *args)
5761 + struct au_cpup_single_args *a = args;
5763 + au_pin_hdir_acquire_nest(a->cpg->pin);
5764 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5765 + au_pin_hdir_release(a->cpg->pin);
5770 + * prevent SIGXFSZ in copy-up.
5771 + * testing CAP_MKNOD is for generic fs,
5772 + * but CAP_FSETID is for xfs only, currently.
5774 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5777 + struct super_block *sb;
5778 + struct inode *h_dir;
5781 + sb = au_pinned_parent(pin)->d_sb;
5782 + if (!au_wkq_test()
5783 + && (!au_sbi(sb)->si_plink_maint_pid
5784 + || au_plink_maint(sb, AuLock_NOPLM))) {
5785 + switch (mode & S_IFMT) {
5787 + /* no condition about RLIMIT_FSIZE and the file size */
5792 + do_sio = !capable(CAP_MKNOD);
5796 + do_sio = ((mode & (S_ISUID | S_ISGID))
5797 + && !capable(CAP_FSETID));
5798 + /* this workaround may be removed in the future */
5800 + h_dir = au_pinned_h_dir(pin);
5801 + do_sio = h_dir->i_mode & S_ISVTX;
5808 +#if 0 /* reserved */
5809 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5812 + struct dentry *h_dentry;
5814 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5815 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5816 + err = au_cpup_single(cpg, dst_parent);
5818 + struct au_cpup_single_args args = {
5821 + .dst_parent = dst_parent
5823 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5824 + if (unlikely(wkq_err))
5833 + * copyup the @dentry from the first active lower branch to @bdst,
5834 + * using au_cpup_single().
5836 +static int au_cpup_simple(struct au_cp_generic *cpg)
5839 + unsigned int flags_orig;
5840 + struct dentry *dentry;
5842 + AuDebugOn(cpg->bsrc < 0);
5844 + dentry = cpg->dentry;
5845 + DiMustWriteLock(dentry);
5847 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5849 + flags_orig = cpg->flags;
5850 + au_fset_cpup(cpg->flags, RENAME);
5851 + err = au_cpup_single(cpg, NULL);
5852 + cpg->flags = flags_orig;
5854 + return 0; /* success */
5857 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5858 + au_set_dbtop(dentry, cpg->bsrc);
5864 +struct au_cpup_simple_args {
5866 + struct au_cp_generic *cpg;
5869 +static void au_call_cpup_simple(void *args)
5871 + struct au_cpup_simple_args *a = args;
5873 + au_pin_hdir_acquire_nest(a->cpg->pin);
5874 + *a->errp = au_cpup_simple(a->cpg);
5875 + au_pin_hdir_release(a->cpg->pin);
5878 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5881 + struct dentry *dentry, *parent;
5882 + struct file *h_file;
5883 + struct inode *h_dir;
5885 + dentry = cpg->dentry;
5887 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5888 + AuDebugOn(cpg->bsrc < 0);
5889 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5890 + err = PTR_ERR(h_file);
5891 + if (IS_ERR(h_file))
5895 + parent = dget_parent(dentry);
5896 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5897 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5898 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5899 + err = au_cpup_simple(cpg);
5901 + struct au_cpup_simple_args args = {
5905 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5906 + if (unlikely(wkq_err))
5912 + au_h_open_post(dentry, cpg->bsrc, h_file);
5918 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5920 + aufs_bindex_t bsrc, bbot;
5921 + struct dentry *dentry, *h_dentry;
5923 + if (cpg->bsrc < 0) {
5924 + dentry = cpg->dentry;
5925 + bbot = au_dbbot(dentry);
5926 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5927 + h_dentry = au_h_dptr(dentry, bsrc);
5929 + AuDebugOn(d_is_negative(h_dentry));
5933 + AuDebugOn(bsrc > bbot);
5936 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5937 + return au_do_sio_cpup_simple(cpg);
5940 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5942 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5943 + return au_do_sio_cpup_simple(cpg);
5946 +/* ---------------------------------------------------------------------- */
5949 + * copyup the deleted file for writing.
5951 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5952 + struct file *file)
5955 + unsigned int flags_orig;
5956 + aufs_bindex_t bsrc_orig;
5957 + struct au_dinfo *dinfo;
5959 + struct au_hdentry *hd;
5960 + struct dentry *h_dentry;
5963 + dinfo = au_di(cpg->dentry);
5964 + AuRwMustWriteLock(&dinfo->di_rwsem);
5966 + bsrc_orig = cpg->bsrc;
5967 + cpg->bsrc = dinfo->di_btop;
5968 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5969 + hdst.h_dentry = hdst.hd->hd_dentry;
5970 + hdst.hd->hd_dentry = wh_dentry;
5971 + dinfo->di_btop = cpg->bdst;
5973 + hsrc.h_dentry = NULL;
5975 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5976 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5977 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5979 + flags_orig = cpg->flags;
5980 + cpg->flags = !AuCpup_DTIME;
5981 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5982 + cpg->flags = flags_orig;
5985 + err = au_reopen_nondir(file);
5986 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5988 + hdst.hd->hd_dentry = hdst.h_dentry;
5989 + dinfo->di_btop = cpg->bsrc;
5990 + cpg->bsrc = bsrc_orig;
5995 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5998 + aufs_bindex_t bdst;
5999 + struct au_dtime dt;
6000 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
6001 + struct au_branch *br;
6002 + struct path h_path;
6004 + dentry = cpg->dentry;
6006 + br = au_sbr(dentry->d_sb, bdst);
6007 + parent = dget_parent(dentry);
6008 + h_parent = au_h_dptr(parent, bdst);
6009 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
6010 + err = PTR_ERR(wh_dentry);
6011 + if (IS_ERR(wh_dentry))
6014 + h_path.dentry = h_parent;
6015 + h_path.mnt = au_br_mnt(br);
6016 + au_dtime_store(&dt, parent, &h_path);
6017 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6018 + if (unlikely(err))
6022 + h_path.dentry = wh_dentry;
6023 + if (!d_is_dir(wh_dentry)) {
6024 + /* no delegation since it is just created */
6025 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6026 + /*delegated*/NULL, /*force*/0);
6028 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6029 + if (unlikely(err)) {
6030 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6034 + au_dtime_revert(&dt);
6035 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6044 +struct au_cpup_wh_args {
6046 + struct au_cp_generic *cpg;
6047 + struct file *file;
6050 +static void au_call_cpup_wh(void *args)
6052 + struct au_cpup_wh_args *a = args;
6054 + au_pin_hdir_acquire_nest(a->cpg->pin);
6055 + *a->errp = au_cpup_wh(a->cpg, a->file);
6056 + au_pin_hdir_release(a->cpg->pin);
6059 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6062 + aufs_bindex_t bdst;
6063 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6064 + struct inode *dir, *h_dir, *h_tmpdir;
6065 + struct au_wbr *wbr;
6066 + struct au_pin wh_pin, *pin_orig;
6068 + dentry = cpg->dentry;
6070 + parent = dget_parent(dentry);
6071 + dir = d_inode(parent);
6074 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6077 + if (!h_dir->i_nlink) {
6078 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6079 + h_orph = wbr->wbr_orph;
6081 + h_parent = dget(au_h_dptr(parent, bdst));
6082 + au_set_h_dptr(parent, bdst, dget(h_orph));
6083 + h_tmpdir = d_inode(h_orph);
6084 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6086 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6087 + /* todo: au_h_open_pre()? */
6089 + pin_orig = cpg->pin;
6090 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6091 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6092 + cpg->pin = &wh_pin;
6095 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6096 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6097 + err = au_cpup_wh(cpg, file);
6099 + struct au_cpup_wh_args args = {
6104 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6105 + if (unlikely(wkq_err))
6110 + inode_unlock(h_tmpdir);
6111 + /* todo: au_h_open_post()? */
6112 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6113 + au_set_h_dptr(parent, bdst, h_parent);
6114 + AuDebugOn(!pin_orig);
6115 + cpg->pin = pin_orig;
6123 +/* ---------------------------------------------------------------------- */
6126 + * generic routine for both of copy-up and copy-down.
6128 +/* cf. revalidate function in file.c */
6129 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6130 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6131 + struct au_pin *pin,
6132 + struct dentry *h_parent, void *arg),
6136 + struct au_pin pin;
6137 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6140 + parent = dget_parent(dentry);
6141 + if (IS_ROOT(parent))
6144 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6145 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6147 + /* do not use au_dpage */
6148 + real_parent = parent;
6151 + parent = dget_parent(dentry);
6152 + h_parent = au_h_dptr(parent, bdst);
6154 + goto out; /* success */
6156 + /* find top dir which is necessary to cpup */
6160 + parent = dget_parent(d);
6161 + di_read_lock_parent3(parent, !AuLock_IR);
6162 + h_parent = au_h_dptr(parent, bdst);
6163 + di_read_unlock(parent, !AuLock_IR);
6164 + } while (!h_parent);
6166 + if (d != real_parent)
6167 + di_write_lock_child3(d);
6169 + /* somebody else might create while we were sleeping */
6170 + h_dentry = au_h_dptr(d, bdst);
6171 + if (!h_dentry || d_is_negative(h_dentry)) {
6173 + au_update_dbtop(d);
6175 + au_pin_set_dentry(&pin, d);
6176 + err = au_do_pin(&pin);
6178 + err = cp(d, bdst, &pin, h_parent, arg);
6183 + if (d != real_parent)
6184 + di_write_unlock(d);
6185 + if (unlikely(err))
6194 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6195 + struct au_pin *pin,
6196 + struct dentry *h_parent __maybe_unused,
6197 + void *arg __maybe_unused)
6199 + struct au_cp_generic cpg = {
6205 + .flags = AuCpup_DTIME
6207 + return au_sio_cpup_simple(&cpg);
6210 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6212 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6215 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6218 + struct dentry *parent;
6219 + struct inode *dir;
6221 + parent = dget_parent(dentry);
6222 + dir = d_inode(parent);
6224 + if (au_h_iptr(dir, bdst))
6227 + di_read_unlock(parent, AuLock_IR);
6228 + di_write_lock_parent(parent);
6229 + /* someone else might change our inode while we were sleeping */
6230 + if (!au_h_iptr(dir, bdst))
6231 + err = au_cpup_dirs(dentry, bdst);
6232 + di_downgrade_lock(parent, AuLock_IR);
6238 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6239 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6240 +++ linux/fs/aufs/cpup.h 2021-02-22 22:51:59.058078584 +0100
6242 +/* SPDX-License-Identifier: GPL-2.0 */
6244 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6246 + * This program, aufs is free software; you can redistribute it and/or modify
6247 + * it under the terms of the GNU General Public License as published by
6248 + * the Free Software Foundation; either version 2 of the License, or
6249 + * (at your option) any later version.
6251 + * This program is distributed in the hope that it will be useful,
6252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6254 + * GNU General Public License for more details.
6256 + * You should have received a copy of the GNU General Public License
6257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6261 + * copy-up/down functions
6264 +#ifndef __AUFS_CPUP_H__
6265 +#define __AUFS_CPUP_H__
6269 +#include <linux/path.h>
6275 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6276 +void au_cpup_attr_timesizes(struct inode *inode);
6277 +void au_cpup_attr_nlink(struct inode *inode, int force);
6278 +void au_cpup_attr_changeable(struct inode *inode);
6279 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6280 +void au_cpup_attr_all(struct inode *inode, int force);
6282 +/* ---------------------------------------------------------------------- */
6284 +struct au_cp_generic {
6285 + struct dentry *dentry;
6286 + aufs_bindex_t bdst, bsrc;
6288 + struct au_pin *pin;
6289 + unsigned int flags;
6293 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6294 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6296 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6297 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6299 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6301 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6302 + the branch is marked as RO */
6304 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6305 +#undef AuCpup_HOPEN
6306 +#define AuCpup_HOPEN 0
6309 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6310 +#define au_fset_cpup(flags, name) \
6311 + do { (flags) |= AuCpup_##name; } while (0)
6312 +#define au_fclr_cpup(flags, name) \
6313 + do { (flags) &= ~AuCpup_##name; } while (0)
6315 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6316 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6317 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6318 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6320 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6321 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6322 + struct au_pin *pin,
6323 + struct dentry *h_parent, void *arg),
6325 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6326 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6328 +/* ---------------------------------------------------------------------- */
6330 +/* keep timestamps when copyup */
6332 + struct dentry *dt_dentry;
6333 + struct path dt_h_path;
6334 + struct timespec64 dt_atime, dt_mtime;
6336 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6337 + struct path *h_path);
6338 +void au_dtime_revert(struct au_dtime *dt);
6340 +#endif /* __KERNEL__ */
6341 +#endif /* __AUFS_CPUP_H__ */
6342 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6343 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6344 +++ linux/fs/aufs/dbgaufs.c 2021-02-22 22:51:59.058078584 +0100
6346 +// SPDX-License-Identifier: GPL-2.0
6348 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6350 + * This program, aufs is free software; you can redistribute it and/or modify
6351 + * it under the terms of the GNU General Public License as published by
6352 + * the Free Software Foundation; either version 2 of the License, or
6353 + * (at your option) any later version.
6355 + * This program is distributed in the hope that it will be useful,
6356 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6357 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6358 + * GNU General Public License for more details.
6360 + * You should have received a copy of the GNU General Public License
6361 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6365 + * debugfs interface
6368 +#include <linux/debugfs.h>
6371 +#ifndef CONFIG_SYSFS
6372 +#error DEBUG_FS depends upon SYSFS
6375 +static struct dentry *dbgaufs;
6376 +static const mode_t dbgaufs_mode = 0444;
6378 +/* 20 is max digits length of ulong 64 */
6379 +struct dbgaufs_arg {
6385 + * common function for all XINO files
6387 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6388 + struct file *file)
6392 + p = file->private_data;
6394 + /* this is struct dbgaufs_arg */
6395 + AuDebugOn(!au_kfree_sz_test(p));
6396 + au_kfree_do_rcu(p);
6401 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6406 + struct dbgaufs_arg *p;
6409 + p = kmalloc(sizeof(*p), GFP_NOFS);
6415 + file->private_data = p;
6419 + err = vfsub_getattr(&xf->f_path, &st);
6423 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6424 + cnt, st.blocks, st.blksize,
6425 + (long long)st.size);
6427 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6428 + st.blocks, st.blksize,
6429 + (long long)st.size);
6430 + AuDebugOn(p->n >= sizeof(p->a));
6432 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6440 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6441 + size_t count, loff_t *ppos)
6443 + struct dbgaufs_arg *p;
6445 + p = file->private_data;
6446 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6449 +/* ---------------------------------------------------------------------- */
6451 +struct dbgaufs_plink_arg {
6456 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6457 + struct file *file)
6459 + free_page((unsigned long)file->private_data);
6463 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6465 + int err, i, limit;
6466 + unsigned long n, sum;
6467 + struct dbgaufs_plink_arg *p;
6468 + struct au_sbinfo *sbinfo;
6469 + struct super_block *sb;
6470 + struct hlist_bl_head *hbl;
6473 + p = (void *)get_zeroed_page(GFP_NOFS);
6478 + sbinfo = inode->i_private;
6479 + sb = sbinfo->si_sb;
6480 + si_noflush_read_lock(sb);
6481 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6482 + limit = PAGE_SIZE - sizeof(p->n);
6484 + /* the number of buckets */
6485 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6490 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6492 + n = au_hbl_count(hbl);
6495 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6498 + if (unlikely(limit <= 0))
6501 + p->a[p->n - 1] = '\n';
6503 + /* the sum of plinks */
6504 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6507 + if (unlikely(limit <= 0))
6510 +#define str "1\n0\n0\n"
6511 + p->n = sizeof(str) - 1;
6512 + strcpy(p->a, str);
6515 + si_read_unlock(sb);
6518 + file->private_data = p;
6519 + goto out; /* success */
6522 + free_page((unsigned long)p);
6527 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6528 + size_t count, loff_t *ppos)
6530 + struct dbgaufs_plink_arg *p;
6532 + p = file->private_data;
6533 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6536 +static const struct file_operations dbgaufs_plink_fop = {
6537 + .owner = THIS_MODULE,
6538 + .open = dbgaufs_plink_open,
6539 + .release = dbgaufs_plink_release,
6540 + .read = dbgaufs_plink_read
6543 +/* ---------------------------------------------------------------------- */
6545 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6548 + struct au_sbinfo *sbinfo;
6549 + struct super_block *sb;
6551 + sbinfo = inode->i_private;
6552 + sb = sbinfo->si_sb;
6553 + si_noflush_read_lock(sb);
6554 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6555 + si_read_unlock(sb);
6559 +static const struct file_operations dbgaufs_xib_fop = {
6560 + .owner = THIS_MODULE,
6561 + .open = dbgaufs_xib_open,
6562 + .release = dbgaufs_xi_release,
6563 + .read = dbgaufs_xi_read
6566 +/* ---------------------------------------------------------------------- */
6568 +#define DbgaufsXi_PREFIX "xi"
6570 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6574 + aufs_bindex_t bindex;
6575 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6576 + struct au_sbinfo *sbinfo;
6577 + struct super_block *sb;
6578 + struct au_xino *xi;
6580 + struct qstr *name;
6581 + struct au_branch *br;
6584 + name = &file->f_path.dentry->d_name;
6585 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6586 + || memcmp(name->name, DbgaufsXi_PREFIX,
6587 + sizeof(DbgaufsXi_PREFIX) - 1)))
6590 + AuDebugOn(name->len >= sizeof(a));
6591 + memcpy(a, name->name, name->len);
6592 + a[name->len] = '\0';
6593 + p = strchr(a, '-');
6596 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6597 + if (unlikely(err))
6602 + err = kstrtol(p + 1, 10, &l);
6603 + if (unlikely(err))
6609 + sbinfo = inode->i_private;
6610 + sb = sbinfo->si_sb;
6611 + si_noflush_read_lock(sb);
6612 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6614 + br = au_sbr(sb, bindex);
6616 + if (unlikely(idx >= xi->xi_nfile))
6618 + xf = au_xino_file(xi, idx);
6620 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6621 + au_xino_count(br));
6624 + si_read_unlock(sb);
6630 +static const struct file_operations dbgaufs_xino_fop = {
6631 + .owner = THIS_MODULE,
6632 + .open = dbgaufs_xino_open,
6633 + .release = dbgaufs_xi_release,
6634 + .read = dbgaufs_xi_read
6637 +void dbgaufs_xino_del(struct au_branch *br)
6639 + struct dentry *dbgaufs;
6641 + dbgaufs = br->br_dbgaufs;
6645 + br->br_dbgaufs = NULL;
6646 + /* debugfs acquires the parent i_mutex */
6648 + debugfs_remove(dbgaufs);
6652 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6654 + aufs_bindex_t bbot;
6655 + struct au_branch *br;
6657 + if (!au_sbi(sb)->si_dbgaufs)
6660 + bbot = au_sbbot(sb);
6661 + for (; bindex <= bbot; bindex++) {
6662 + br = au_sbr(sb, bindex);
6663 + dbgaufs_xino_del(br);
6667 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6668 + unsigned int idx, struct dentry *parent,
6669 + struct au_sbinfo *sbinfo)
6671 + struct au_branch *br;
6673 + /* "xi" bindex(5) "-" idx(2) NULL */
6674 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6677 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6679 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6681 + br = au_sbr(sb, bindex);
6682 + if (br->br_dbgaufs) {
6683 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6685 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6686 + /* debugfs acquires the parent i_mutex */
6688 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6692 + pr_warn("failed renaming %pd/%s, ignored.\n",
6697 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6698 + sbinfo, &dbgaufs_xino_fop);
6700 + if (unlikely(!br->br_dbgaufs))
6701 + pr_warn("failed creating %pd/%s, ignored.\n",
6706 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6707 + struct dentry *parent, struct au_sbinfo *sbinfo)
6709 + struct au_branch *br;
6710 + struct au_xino *xi;
6713 + br = au_sbr(sb, bindex);
6715 + for (u = 0; u < xi->xi_nfile; u++)
6716 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6719 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6721 + struct au_sbinfo *sbinfo;
6722 + struct dentry *parent;
6723 + aufs_bindex_t bbot;
6725 + if (!au_opt_test(au_mntflags(sb), XINO))
6728 + sbinfo = au_sbi(sb);
6729 + parent = sbinfo->si_dbgaufs;
6733 + bbot = au_sbbot(sb);
6735 + for (; bindex <= bbot; bindex++)
6736 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6738 + for (; bbot >= bindex; bbot--)
6739 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6742 +/* ---------------------------------------------------------------------- */
6744 +#ifdef CONFIG_AUFS_EXPORT
6745 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6748 + struct au_sbinfo *sbinfo;
6749 + struct super_block *sb;
6751 + sbinfo = inode->i_private;
6752 + sb = sbinfo->si_sb;
6753 + si_noflush_read_lock(sb);
6754 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6755 + si_read_unlock(sb);
6759 +static const struct file_operations dbgaufs_xigen_fop = {
6760 + .owner = THIS_MODULE,
6761 + .open = dbgaufs_xigen_open,
6762 + .release = dbgaufs_xi_release,
6763 + .read = dbgaufs_xi_read
6766 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6771 + * This function is a dynamic '__init' function actually,
6772 + * so the tiny check for si_rwsem is unnecessary.
6774 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6777 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6778 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6779 + &dbgaufs_xigen_fop);
6780 + if (sbinfo->si_dbgaufs_xigen)
6786 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6790 +#endif /* CONFIG_AUFS_EXPORT */
6792 +/* ---------------------------------------------------------------------- */
6794 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6797 + * This function is a dynamic '__fin' function actually,
6798 + * so the tiny check for si_rwsem is unnecessary.
6800 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6802 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6803 + sbinfo->si_dbgaufs = NULL;
6806 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6809 + char name[SysaufsSiNameLen];
6812 + * This function is a dynamic '__init' function actually,
6813 + * so the tiny check for si_rwsem is unnecessary.
6815 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6819 + AuErr1("/debug/aufs is uninitialized\n");
6824 + sysaufs_name(sbinfo, name);
6825 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6826 + if (unlikely(!sbinfo->si_dbgaufs))
6829 + /* regardless plink/noplink option */
6830 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6831 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6832 + &dbgaufs_plink_fop);
6833 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6836 + /* regardless xino/noxino option */
6837 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6838 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6839 + &dbgaufs_xib_fop);
6840 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6843 + err = dbgaufs_xigen_init(sbinfo);
6845 + goto out; /* success */
6848 + dbgaufs_si_fin(sbinfo);
6850 + if (unlikely(err))
6851 + pr_err("debugfs/aufs failed\n");
6855 +/* ---------------------------------------------------------------------- */
6857 +void dbgaufs_fin(void)
6859 + debugfs_remove(dbgaufs);
6862 +int __init dbgaufs_init(void)
6867 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6872 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6873 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6874 +++ linux/fs/aufs/dbgaufs.h 2021-02-22 22:51:59.058078584 +0100
6876 +/* SPDX-License-Identifier: GPL-2.0 */
6878 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6880 + * This program, aufs is free software; you can redistribute it and/or modify
6881 + * it under the terms of the GNU General Public License as published by
6882 + * the Free Software Foundation; either version 2 of the License, or
6883 + * (at your option) any later version.
6885 + * This program is distributed in the hope that it will be useful,
6886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6888 + * GNU General Public License for more details.
6890 + * You should have received a copy of the GNU General Public License
6891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6895 + * debugfs interface
6898 +#ifndef __DBGAUFS_H__
6899 +#define __DBGAUFS_H__
6903 +struct super_block;
6907 +#ifdef CONFIG_DEBUG_FS
6909 +void dbgaufs_xino_del(struct au_branch *br);
6910 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6911 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6912 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6913 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6914 +void dbgaufs_fin(void);
6915 +int __init dbgaufs_init(void);
6917 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6918 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6919 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6921 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6922 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6923 +AuStubVoid(dbgaufs_fin, void)
6924 +AuStubInt0(__init dbgaufs_init, void)
6925 +#endif /* CONFIG_DEBUG_FS */
6927 +#endif /* __KERNEL__ */
6928 +#endif /* __DBGAUFS_H__ */
6929 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6930 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6931 +++ linux/fs/aufs/dcsub.c 2021-02-22 22:51:59.058078584 +0100
6933 +// SPDX-License-Identifier: GPL-2.0
6935 + * Copyright (C) 2005-2020 Junjiro R. Okajima
6937 + * This program, aufs is free software; you can redistribute it and/or modify
6938 + * it under the terms of the GNU General Public License as published by
6939 + * the Free Software Foundation; either version 2 of the License, or
6940 + * (at your option) any later version.
6942 + * This program is distributed in the hope that it will be useful,
6943 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6944 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6945 + * GNU General Public License for more details.
6947 + * You should have received a copy of the GNU General Public License
6948 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6952 + * sub-routines for dentry cache
6957 +static void au_dpage_free(struct au_dpage *dpage)
6960 + struct dentry **p;
6962 + p = dpage->dentries;
6963 + for (i = 0; i < dpage->ndentry; i++)
6965 + free_page((unsigned long)dpage->dentries);
6968 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6974 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6975 + if (unlikely(!dpages->dpages))
6978 + p = (void *)__get_free_page(gfp);
6982 + dpages->dpages[0].ndentry = 0;
6983 + dpages->dpages[0].dentries = p;
6984 + dpages->ndpage = 1;
6985 + return 0; /* success */
6988 + au_kfree_try_rcu(dpages->dpages);
6993 +void au_dpages_free(struct au_dcsub_pages *dpages)
6996 + struct au_dpage *p;
6998 + p = dpages->dpages;
6999 + for (i = 0; i < dpages->ndpage; i++)
7000 + au_dpage_free(p++);
7001 + au_kfree_try_rcu(dpages->dpages);
7004 +static int au_dpages_append(struct au_dcsub_pages *dpages,
7005 + struct dentry *dentry, gfp_t gfp)
7008 + struct au_dpage *dpage;
7011 + dpage = dpages->dpages + dpages->ndpage - 1;
7012 + sz = PAGE_SIZE / sizeof(dentry);
7013 + if (unlikely(dpage->ndentry >= sz)) {
7014 + AuLabel(new dpage);
7016 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7017 + p = au_kzrealloc(dpages->dpages, sz,
7018 + sz + sizeof(*dpages->dpages), gfp,
7023 + dpages->dpages = p;
7024 + dpage = dpages->dpages + dpages->ndpage;
7025 + p = (void *)__get_free_page(gfp);
7029 + dpage->ndentry = 0;
7030 + dpage->dentries = p;
7034 + AuDebugOn(au_dcount(dentry) <= 0);
7035 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7036 + return 0; /* success */
7042 +/* todo: BAD approach */
7043 +/* copied from linux/fs/dcache.c */
7051 +extern void d_walk(struct dentry *parent, void *data,
7052 + enum d_walk_ret (*enter)(void *, struct dentry *));
7054 +struct ac_dpages_arg {
7056 + struct au_dcsub_pages *dpages;
7057 + struct super_block *sb;
7058 + au_dpages_test test;
7062 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7064 + enum d_walk_ret ret;
7065 + struct ac_dpages_arg *arg = _arg;
7067 + ret = D_WALK_CONTINUE;
7068 + if (dentry->d_sb == arg->sb
7069 + && !IS_ROOT(dentry)
7070 + && au_dcount(dentry) > 0
7072 + && (!arg->test || arg->test(dentry, arg->arg))) {
7073 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7074 + if (unlikely(arg->err))
7075 + ret = D_WALK_QUIT;
7081 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7082 + au_dpages_test test, void *arg)
7084 + struct ac_dpages_arg args = {
7092 + d_walk(root, &args, au_call_dpages_append);
7097 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7098 + int do_include, au_dpages_test test, void *arg)
7103 + write_seqlock(&rename_lock);
7104 + spin_lock(&dentry->d_lock);
7106 + && au_dcount(dentry) > 0
7107 + && (!test || test(dentry, arg)))
7108 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7109 + spin_unlock(&dentry->d_lock);
7110 + if (unlikely(err))
7114 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7117 + while (!IS_ROOT(dentry)) {
7118 + dentry = dentry->d_parent; /* rename_lock is locked */
7119 + spin_lock(&dentry->d_lock);
7120 + if (au_dcount(dentry) > 0
7121 + && (!test || test(dentry, arg)))
7122 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7123 + spin_unlock(&dentry->d_lock);
7124 + if (unlikely(err))
7129 + write_sequnlock(&rename_lock);
7133 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7135 + return au_di(dentry) && dentry->d_sb == arg;
7138 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7139 + struct dentry *dentry, int do_include)
7141 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7142 + au_dcsub_dpages_aufs, dentry->d_sb);
7145 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7147 + struct path path[2] = {
7156 + return path_is_under(path + 0, path + 1);
7158 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7159 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7160 +++ linux/fs/aufs/dcsub.h 2021-02-22 22:51:59.058078584 +0100
7162 +/* SPDX-License-Identifier: GPL-2.0 */
7164 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7166 + * This program, aufs is free software; you can redistribute it and/or modify
7167 + * it under the terms of the GNU General Public License as published by
7168 + * the Free Software Foundation; either version 2 of the License, or
7169 + * (at your option) any later version.
7171 + * This program is distributed in the hope that it will be useful,
7172 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7173 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7174 + * GNU General Public License for more details.
7176 + * You should have received a copy of the GNU General Public License
7177 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7181 + * sub-routines for dentry cache
7184 +#ifndef __AUFS_DCSUB_H__
7185 +#define __AUFS_DCSUB_H__
7189 +#include <linux/dcache.h>
7190 +#include <linux/fs.h>
7194 + struct dentry **dentries;
7197 +struct au_dcsub_pages {
7199 + struct au_dpage *dpages;
7202 +/* ---------------------------------------------------------------------- */
7205 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7206 +void au_dpages_free(struct au_dcsub_pages *dpages);
7207 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7208 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7209 + au_dpages_test test, void *arg);
7210 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7211 + int do_include, au_dpages_test test, void *arg);
7212 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7213 + struct dentry *dentry, int do_include);
7214 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7216 +/* ---------------------------------------------------------------------- */
7219 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7220 + * include/linux/dcache.h. Try them (in the future).
7223 +static inline int au_d_hashed_positive(struct dentry *d)
7226 + struct inode *inode = d_inode(d);
7229 + if (unlikely(d_unhashed(d)
7230 + || d_is_negative(d)
7231 + || !inode->i_nlink))
7236 +static inline int au_d_linkable(struct dentry *d)
7239 + struct inode *inode = d_inode(d);
7241 + err = au_d_hashed_positive(d);
7243 + && d_is_positive(d)
7244 + && (inode->i_state & I_LINKABLE))
7249 +static inline int au_d_alive(struct dentry *d)
7252 + struct inode *inode;
7256 + err = au_d_hashed_positive(d);
7258 + inode = d_inode(d);
7259 + if (unlikely(d_unlinked(d)
7260 + || d_is_negative(d)
7261 + || !inode->i_nlink))
7267 +static inline int au_alive_dir(struct dentry *d)
7271 + err = au_d_alive(d);
7272 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7277 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7279 + return a->len == b->len
7280 + && !memcmp(a->name, b->name, a->len);
7285 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7287 + * the type of d_lockref.count became int, but the inlined function d_count()
7288 + * still returns unsigned int.
7289 + * I don't know why. Maybe it is for every d_count() users?
7290 + * Anyway au_dcount() lives on.
7292 +static inline int au_dcount(struct dentry *d)
7294 + return (int)d_count(d);
7297 +#endif /* __KERNEL__ */
7298 +#endif /* __AUFS_DCSUB_H__ */
7299 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7300 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7301 +++ linux/fs/aufs/debug.c 2021-02-22 22:51:59.058078584 +0100
7303 +// SPDX-License-Identifier: GPL-2.0
7305 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7307 + * This program, aufs is free software; you can redistribute it and/or modify
7308 + * it under the terms of the GNU General Public License as published by
7309 + * the Free Software Foundation; either version 2 of the License, or
7310 + * (at your option) any later version.
7312 + * This program is distributed in the hope that it will be useful,
7313 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7314 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7315 + * GNU General Public License for more details.
7317 + * You should have received a copy of the GNU General Public License
7318 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7322 + * debug print functions
7325 +#include <linux/iversion.h>
7328 +/* Returns 0, or -errno. arg is in kp->arg. */
7329 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7333 + err = kstrtoint(val, 0, &n);
7343 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7344 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7349 + return sprintf(buffer, "%d", atomic_read(a));
7352 +static struct kernel_param_ops param_ops_atomic_t = {
7353 + .set = param_atomic_t_set,
7354 + .get = param_atomic_t_get
7355 + /* void (*free)(void *arg) */
7358 +atomic_t aufs_debug = ATOMIC_INIT(0);
7359 +MODULE_PARM_DESC(debug, "debug print");
7360 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7362 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7363 +char *au_plevel = KERN_DEBUG;
7364 +#define dpri(fmt, ...) do { \
7366 + && strcmp(au_plevel, KERN_DEBUG)) \
7367 + || au_debug_test()) \
7368 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7371 +/* ---------------------------------------------------------------------- */
7373 +void au_dpri_whlist(struct au_nhash *whlist)
7375 + unsigned long ul, n;
7376 + struct hlist_head *head;
7377 + struct au_vdir_wh *pos;
7379 + n = whlist->nh_num;
7380 + head = whlist->nh_head;
7381 + for (ul = 0; ul < n; ul++) {
7382 + hlist_for_each_entry(pos, head, wh_hash)
7383 + dpri("b%d, %.*s, %d\n",
7385 + pos->wh_str.len, pos->wh_str.name,
7391 +void au_dpri_vdir(struct au_vdir *vdir)
7394 + union au_vdir_deblk_p p;
7397 + if (!vdir || IS_ERR(vdir)) {
7398 + dpri("err %ld\n", PTR_ERR(vdir));
7402 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7403 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7404 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7405 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7406 + p.deblk = vdir->vd_deblk[ul];
7408 + dpri("[%lu]: %p\n", ul, o);
7412 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7413 + struct dentry *wh)
7418 + if (!inode || IS_ERR(inode)) {
7419 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7423 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7424 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7425 + && sizeof(inode->i_blocks) != sizeof(u64));
7427 + n = (void *)wh->d_name.name;
7428 + l = wh->d_name.len;
7431 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7432 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7434 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7435 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7436 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7437 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7438 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7439 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7440 + inode->i_generation,
7441 + l ? ", wh " : "", l, n);
7445 +void au_dpri_inode(struct inode *inode)
7447 + struct au_iinfo *iinfo;
7448 + struct au_hinode *hi;
7449 + aufs_bindex_t bindex;
7452 + err = do_pri_inode(-1, inode, -1, NULL);
7453 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7456 + iinfo = au_ii(inode);
7457 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7458 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7459 + if (iinfo->ii_btop < 0)
7462 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7463 + hi = au_hinode(iinfo, bindex);
7465 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7469 +void au_dpri_dalias(struct inode *inode)
7473 + spin_lock(&inode->i_lock);
7474 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7475 + au_dpri_dentry(d);
7476 + spin_unlock(&inode->i_lock);
7479 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7481 + struct dentry *wh = NULL;
7483 + struct inode *inode;
7484 + struct au_iinfo *iinfo;
7485 + struct au_hinode *hi;
7487 + if (!dentry || IS_ERR(dentry)) {
7488 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7491 + /* do not call dget_parent() here */
7492 + /* note: access d_xxx without d_lock */
7493 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7494 + bindex, dentry, dentry,
7495 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7496 + au_dcount(dentry), dentry->d_flags,
7497 + d_unhashed(dentry) ? "un" : "");
7500 + if (d_is_positive(dentry))
7501 + inode = d_inode(dentry);
7503 + && au_test_aufs(dentry->d_sb)
7505 + && !au_is_bad_inode(inode)) {
7506 + iinfo = au_ii(inode);
7507 + hi = au_hinode(iinfo, bindex);
7509 + wh = hi->hi_whdentry;
7511 + do_pri_inode(bindex, inode, hn, wh);
7515 +void au_dpri_dentry(struct dentry *dentry)
7517 + struct au_dinfo *dinfo;
7518 + aufs_bindex_t bindex;
7521 + err = do_pri_dentry(-1, dentry);
7522 + if (err || !au_test_aufs(dentry->d_sb))
7525 + dinfo = au_di(dentry);
7528 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7529 + dinfo->di_btop, dinfo->di_bbot,
7530 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7531 + dinfo->di_tmpfile);
7532 + if (dinfo->di_btop < 0)
7534 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7535 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7538 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7542 + if (!file || IS_ERR(file)) {
7543 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7548 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7549 + && au_test_aufs(file->f_path.dentry->d_sb)
7551 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7552 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7553 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7554 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7555 + file->f_version, file->f_pos, a);
7556 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7557 + do_pri_dentry(bindex, file->f_path.dentry);
7561 +void au_dpri_file(struct file *file)
7563 + struct au_finfo *finfo;
7564 + struct au_fidir *fidir;
7565 + struct au_hfile *hfile;
7566 + aufs_bindex_t bindex;
7569 + err = do_pri_file(-1, file);
7571 + || IS_ERR_OR_NULL(file->f_path.dentry)
7572 + || !au_test_aufs(file->f_path.dentry->d_sb))
7575 + finfo = au_fi(file);
7578 + if (finfo->fi_btop < 0)
7580 + fidir = finfo->fi_hdir;
7582 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7584 + for (bindex = finfo->fi_btop;
7585 + bindex >= 0 && bindex <= fidir->fd_bbot;
7587 + hfile = fidir->fd_hfile + bindex;
7588 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7592 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7594 + struct vfsmount *mnt;
7595 + struct super_block *sb;
7597 + if (!br || IS_ERR(br))
7599 + mnt = au_br_mnt(br);
7600 + if (!mnt || IS_ERR(mnt))
7603 + if (!sb || IS_ERR(sb))
7606 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7607 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7609 + bindex, br->br_perm, br->br_id, br->br_wbr,
7610 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7611 + sb->s_flags, sb->s_count,
7612 + atomic_read(&sb->s_active),
7613 + !!au_xino_file(br->br_xino, /*idx*/-1));
7617 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7621 +void au_dpri_sb(struct super_block *sb)
7623 + struct au_sbinfo *sbinfo;
7624 + aufs_bindex_t bindex;
7626 + /* to reduce stack size */
7628 + struct vfsmount mnt;
7629 + struct au_branch fake;
7632 + /* this function can be called from magic sysrq */
7633 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7634 + if (unlikely(!a)) {
7635 + dpri("no memory\n");
7639 + a->mnt.mnt_sb = sb;
7640 + a->fake.br_path.mnt = &a->mnt;
7641 + err = do_pri_br(-1, &a->fake);
7643 + dpri("dev 0x%x\n", sb->s_dev);
7644 + if (err || !au_test_aufs(sb))
7647 + sbinfo = au_sbi(sb);
7650 + dpri("nw %d, gen %u, kobj %d\n",
7651 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7652 + kref_read(&sbinfo->si_kobj.kref));
7653 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7654 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7657 +/* ---------------------------------------------------------------------- */
7659 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7661 + struct inode *h_inode, *inode = d_inode(dentry);
7662 + struct dentry *h_dentry;
7663 + aufs_bindex_t bindex, bbot, bi;
7665 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7668 + bbot = au_dbbot(dentry);
7669 + bi = au_ibbot(inode);
7672 + bindex = au_dbtop(dentry);
7673 + bi = au_ibtop(inode);
7677 + for (; bindex <= bbot; bindex++) {
7678 + h_dentry = au_h_dptr(dentry, bindex);
7681 + h_inode = au_h_iptr(inode, bindex);
7682 + if (unlikely(h_inode != d_inode(h_dentry))) {
7684 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7685 + AuDbgDentry(dentry);
7686 + AuDbgInode(inode);
7693 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7696 + struct au_dcsub_pages dpages;
7697 + struct au_dpage *dpage;
7698 + struct dentry **dentries;
7700 + err = au_dpages_init(&dpages, GFP_NOFS);
7702 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7704 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7705 + dpage = dpages.dpages + i;
7706 + dentries = dpage->dentries;
7707 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7708 + AuDebugOn(au_digen_test(dentries[j], sigen));
7710 + au_dpages_free(&dpages);
7713 +void au_dbg_verify_kthread(void)
7715 + if (au_wkq_test()) {
7718 + * It may be recursive, but udba=notify between two aufs mounts,
7719 + * where a single ro branch is shared, is not a problem.
7725 +/* ---------------------------------------------------------------------- */
7727 +int __init au_debug_init(void)
7729 + aufs_bindex_t bindex;
7730 + struct au_vdir_destr destr;
7733 + AuDebugOn(bindex >= 0);
7736 + AuDebugOn(destr.len < NAME_MAX);
7738 +#ifdef CONFIG_4KSTACKS
7739 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7744 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7745 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7746 +++ linux/fs/aufs/debug.h 2021-02-22 22:51:59.058078584 +0100
7748 +/* SPDX-License-Identifier: GPL-2.0 */
7750 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7752 + * This program, aufs is free software; you can redistribute it and/or modify
7753 + * it under the terms of the GNU General Public License as published by
7754 + * the Free Software Foundation; either version 2 of the License, or
7755 + * (at your option) any later version.
7757 + * This program is distributed in the hope that it will be useful,
7758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7760 + * GNU General Public License for more details.
7762 + * You should have received a copy of the GNU General Public License
7763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7767 + * debug print functions
7770 +#ifndef __AUFS_DEBUG_H__
7771 +#define __AUFS_DEBUG_H__
7775 +#include <linux/atomic.h>
7776 +#include <linux/module.h>
7777 +#include <linux/kallsyms.h>
7778 +#include <linux/sysrq.h>
7780 +#ifdef CONFIG_AUFS_DEBUG
7781 +#define AuDebugOn(a) BUG_ON(a)
7783 +/* module parameter */
7784 +extern atomic_t aufs_debug;
7785 +static inline void au_debug_on(void)
7787 + atomic_inc(&aufs_debug);
7789 +static inline void au_debug_off(void)
7791 + atomic_dec_if_positive(&aufs_debug);
7794 +static inline int au_debug_test(void)
7796 + return atomic_read(&aufs_debug) > 0;
7799 +#define AuDebugOn(a) do {} while (0)
7800 +AuStubVoid(au_debug_on, void)
7801 +AuStubVoid(au_debug_off, void)
7802 +AuStubInt0(au_debug_test, void)
7803 +#endif /* CONFIG_AUFS_DEBUG */
7805 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7807 +/* ---------------------------------------------------------------------- */
7811 +#define AuDbg(fmt, ...) do { \
7812 + if (au_debug_test()) \
7813 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7815 +#define AuLabel(l) AuDbg(#l "\n")
7816 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7817 +#define AuWarn1(fmt, ...) do { \
7818 + static unsigned char _c; \
7820 + pr_warn(fmt, ##__VA_ARGS__); \
7823 +#define AuErr1(fmt, ...) do { \
7824 + static unsigned char _c; \
7826 + pr_err(fmt, ##__VA_ARGS__); \
7829 +#define AuIOErr1(fmt, ...) do { \
7830 + static unsigned char _c; \
7832 + AuIOErr(fmt, ##__VA_ARGS__); \
7835 +#define AuUnsupportMsg "This operation is not supported." \
7836 + " Please report this application to aufs-users ML."
7837 +#define AuUnsupport(fmt, ...) do { \
7838 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7842 +#define AuTraceErr(e) do { \
7843 + if (unlikely((e) < 0)) \
7844 + AuDbg("err %d\n", (int)(e)); \
7847 +#define AuTraceErrPtr(p) do { \
7849 + AuDbg("err %ld\n", PTR_ERR(p)); \
7852 +/* dirty macros for debug print, use with "%.*s" and caution */
7853 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7855 +/* ---------------------------------------------------------------------- */
7858 +#ifdef CONFIG_AUFS_DEBUG
7859 +extern struct mutex au_dbg_mtx;
7860 +extern char *au_plevel;
7862 +void au_dpri_whlist(struct au_nhash *whlist);
7864 +void au_dpri_vdir(struct au_vdir *vdir);
7866 +void au_dpri_inode(struct inode *inode);
7867 +void au_dpri_dalias(struct inode *inode);
7868 +void au_dpri_dentry(struct dentry *dentry);
7870 +void au_dpri_file(struct file *filp);
7871 +struct super_block;
7872 +void au_dpri_sb(struct super_block *sb);
7874 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7875 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7876 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7877 +void au_dbg_verify_kthread(void);
7879 +int __init au_debug_init(void);
7881 +#define AuDbgWhlist(w) do { \
7882 + mutex_lock(&au_dbg_mtx); \
7884 + au_dpri_whlist(w); \
7885 + mutex_unlock(&au_dbg_mtx); \
7888 +#define AuDbgVdir(v) do { \
7889 + mutex_lock(&au_dbg_mtx); \
7891 + au_dpri_vdir(v); \
7892 + mutex_unlock(&au_dbg_mtx); \
7895 +#define AuDbgInode(i) do { \
7896 + mutex_lock(&au_dbg_mtx); \
7898 + au_dpri_inode(i); \
7899 + mutex_unlock(&au_dbg_mtx); \
7902 +#define AuDbgDAlias(i) do { \
7903 + mutex_lock(&au_dbg_mtx); \
7905 + au_dpri_dalias(i); \
7906 + mutex_unlock(&au_dbg_mtx); \
7909 +#define AuDbgDentry(d) do { \
7910 + mutex_lock(&au_dbg_mtx); \
7912 + au_dpri_dentry(d); \
7913 + mutex_unlock(&au_dbg_mtx); \
7916 +#define AuDbgFile(f) do { \
7917 + mutex_lock(&au_dbg_mtx); \
7919 + au_dpri_file(f); \
7920 + mutex_unlock(&au_dbg_mtx); \
7923 +#define AuDbgSb(sb) do { \
7924 + mutex_lock(&au_dbg_mtx); \
7925 + AuDbg(#sb "\n"); \
7927 + mutex_unlock(&au_dbg_mtx); \
7930 +#define AuDbgSym(addr) do { \
7931 + char sym[KSYM_SYMBOL_LEN]; \
7932 + sprint_symbol(sym, (unsigned long)addr); \
7933 + AuDbg("%s\n", sym); \
7936 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7937 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7938 +AuStubVoid(au_dbg_verify_kthread, void)
7939 +AuStubInt0(__init au_debug_init, void)
7941 +#define AuDbgWhlist(w) do {} while (0)
7942 +#define AuDbgVdir(v) do {} while (0)
7943 +#define AuDbgInode(i) do {} while (0)
7944 +#define AuDbgDAlias(i) do {} while (0)
7945 +#define AuDbgDentry(d) do {} while (0)
7946 +#define AuDbgFile(f) do {} while (0)
7947 +#define AuDbgSb(sb) do {} while (0)
7948 +#define AuDbgSym(addr) do {} while (0)
7949 +#endif /* CONFIG_AUFS_DEBUG */
7951 +/* ---------------------------------------------------------------------- */
7953 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7954 +int __init au_sysrq_init(void);
7955 +void au_sysrq_fin(void);
7957 +#ifdef CONFIG_HW_CONSOLE
7958 +#define au_dbg_blocked() do { \
7960 + handle_sysrq('w'); \
7963 +AuStubVoid(au_dbg_blocked, void)
7967 +AuStubInt0(__init au_sysrq_init, void)
7968 +AuStubVoid(au_sysrq_fin, void)
7969 +AuStubVoid(au_dbg_blocked, void)
7970 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7972 +#endif /* __KERNEL__ */
7973 +#endif /* __AUFS_DEBUG_H__ */
7974 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7975 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7976 +++ linux/fs/aufs/dentry.c 2021-02-22 22:51:59.058078584 +0100
7978 +// SPDX-License-Identifier: GPL-2.0
7980 + * Copyright (C) 2005-2020 Junjiro R. Okajima
7982 + * This program, aufs is free software; you can redistribute it and/or modify
7983 + * it under the terms of the GNU General Public License as published by
7984 + * the Free Software Foundation; either version 2 of the License, or
7985 + * (at your option) any later version.
7987 + * This program is distributed in the hope that it will be useful,
7988 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7989 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7990 + * GNU General Public License for more details.
7992 + * You should have received a copy of the GNU General Public License
7993 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7997 + * lookup and dentry operations
8000 +#include <linux/iversion.h>
8001 +#include <linux/namei.h>
8005 + * returns positive/negative dentry, NULL or an error.
8006 + * NULL means whiteout-ed or not-found.
8008 +static struct dentry*
8009 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8010 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8012 + struct dentry *h_dentry;
8013 + struct inode *h_inode;
8014 + struct au_branch *br;
8015 + int wh_found, opq;
8016 + unsigned char wh_able;
8017 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8018 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8022 + br = au_sbr(dentry->d_sb, bindex);
8023 + wh_able = !!au_br_whable(br->br_perm);
8025 + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm);
8026 + h_dentry = ERR_PTR(wh_found);
8029 + if (unlikely(wh_found < 0))
8032 + /* We found a whiteout */
8033 + /* au_set_dbbot(dentry, bindex); */
8034 + au_set_dbwh(dentry, bindex);
8036 + return NULL; /* success */
8040 + h_dentry = vfsub_lkup_one(args->name, h_parent);
8042 + h_dentry = au_sio_lkup_one(args->name, h_parent);
8043 + if (IS_ERR(h_dentry)) {
8044 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8050 + h_inode = d_inode(h_dentry);
8051 + if (d_is_negative(h_dentry)) {
8054 + } else if (wh_found
8055 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8057 + else if (au_ftest_lkup(args->flags, DIRREN)
8059 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8060 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8061 + (unsigned long long)h_inode->i_ino);
8065 + if (au_dbbot(dentry) <= bindex)
8066 + au_set_dbbot(dentry, bindex);
8067 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8068 + au_set_dbtop(dentry, bindex);
8069 + au_set_h_dptr(dentry, bindex, h_dentry);
8071 + if (!d_is_dir(h_dentry)
8073 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8074 + goto out; /* success */
8076 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8077 + opq = au_diropq_test(h_dentry);
8078 + inode_unlock_shared(h_inode);
8080 + au_set_dbdiropq(dentry, bindex);
8081 + else if (unlikely(opq < 0)) {
8082 + au_set_h_dptr(dentry, bindex, NULL);
8083 + h_dentry = ERR_PTR(opq);
8094 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8096 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8097 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8103 + * returns the number of lower positive dentries,
8104 + * otherwise an error.
8105 + * can be called at unlinking with @type is zero.
8107 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8108 + unsigned int flags)
8110 + int npositive, err;
8111 + aufs_bindex_t bindex, btail, bdiropq;
8112 + unsigned char isdir, dirperm1, dirren;
8113 + struct au_do_lookup_args args = {
8115 + .name = &dentry->d_name
8117 + struct dentry *parent;
8118 + struct super_block *sb;
8120 + sb = dentry->d_sb;
8121 + err = au_test_shwh(sb, args.name);
8122 + if (unlikely(err))
8125 + err = au_wh_name_alloc(&args.whname, args.name);
8126 + if (unlikely(err))
8129 + isdir = !!d_is_dir(dentry);
8130 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8131 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8133 + au_fset_lkup(args.flags, DIRREN);
8136 + parent = dget_parent(dentry);
8137 + btail = au_dbtaildir(parent);
8138 + for (bindex = btop; bindex <= btail; bindex++) {
8139 + struct dentry *h_parent, *h_dentry;
8140 + struct inode *h_inode, *h_dir;
8141 + struct au_branch *br;
8143 + h_dentry = au_h_dptr(dentry, bindex);
8145 + if (d_is_positive(h_dentry))
8149 + h_parent = au_h_dptr(parent, bindex);
8150 + if (!h_parent || !d_is_dir(h_parent))
8154 + /* if the inum matches, then use the prepared name */
8155 + err = au_dr_lkup_name(&args, bindex);
8156 + if (unlikely(err))
8160 + h_dir = d_inode(h_parent);
8161 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8162 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8163 + inode_unlock_shared(h_dir);
8164 + err = PTR_ERR(h_dentry);
8165 + if (IS_ERR(h_dentry))
8168 + au_fclr_lkup(args.flags, ALLOW_NEG);
8170 + au_fset_lkup(args.flags, IGNORE_PERM);
8172 + if (au_dbwh(dentry) == bindex)
8176 + if (d_is_negative(h_dentry))
8178 + h_inode = d_inode(h_dentry);
8181 + args.type = h_inode->i_mode & S_IFMT;
8182 + if (args.type != S_IFDIR)
8185 + /* the type of lower may be different */
8186 + bdiropq = au_dbdiropq(dentry);
8187 + if (bdiropq >= 0 && bdiropq <= bindex)
8190 + br = au_sbr(sb, bindex);
8192 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8193 + /*add_ent*/NULL)) {
8194 + /* prepare next name to lookup */
8195 + err = au_dr_lkup(&args, dentry, bindex);
8196 + if (unlikely(err))
8202 + AuLabel(positive);
8203 + au_update_dbtop(dentry);
8206 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8207 + && au_dbtop(dentry) < 0)) {
8209 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8215 + au_kfree_try_rcu(args.whname.name);
8217 + au_dr_lkup_fin(&args);
8222 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
8224 + struct dentry *dentry;
8227 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
8228 + dentry = vfsub_lkup_one(name, parent);
8230 + struct vfsub_lkup_one_args args = {
8236 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8237 + if (unlikely(wkq_err))
8238 + dentry = ERR_PTR(wkq_err);
8245 + * lookup @dentry on @bindex which should be negative.
8247 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8250 + struct dentry *parent, *h_parent, *h_dentry;
8251 + struct au_branch *br;
8253 + parent = dget_parent(dentry);
8254 + h_parent = au_h_dptr(parent, bindex);
8255 + br = au_sbr(dentry->d_sb, bindex);
8257 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
8259 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
8260 + err = PTR_ERR(h_dentry);
8261 + if (IS_ERR(h_dentry))
8263 + if (unlikely(d_is_positive(h_dentry))) {
8265 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8271 + if (bindex < au_dbtop(dentry))
8272 + au_set_dbtop(dentry, bindex);
8273 + if (au_dbbot(dentry) < bindex)
8274 + au_set_dbbot(dentry, bindex);
8275 + au_set_h_dptr(dentry, bindex, h_dentry);
8282 +/* ---------------------------------------------------------------------- */
8284 +/* subset of struct inode */
8286 + unsigned long i_ino;
8287 + /* unsigned int i_nlink; */
8293 + blkcnt_t i_blocks;
8298 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8300 + ia->i_ino = h_inode->i_ino;
8301 + /* ia->i_nlink = h_inode->i_nlink; */
8302 + ia->i_uid = h_inode->i_uid;
8303 + ia->i_gid = h_inode->i_gid;
8304 + ia->i_version = inode_query_iversion(h_inode);
8306 + ia->i_size = h_inode->i_size;
8307 + ia->i_blocks = h_inode->i_blocks;
8309 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8312 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8314 + return ia->i_ino != h_inode->i_ino
8315 + /* || ia->i_nlink != h_inode->i_nlink */
8316 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8317 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8318 + || !inode_eq_iversion(h_inode, ia->i_version)
8320 + || ia->i_size != h_inode->i_size
8321 + || ia->i_blocks != h_inode->i_blocks
8323 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8326 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8327 + struct au_branch *br)
8330 + struct au_iattr ia;
8331 + struct inode *h_inode;
8332 + struct dentry *h_d;
8333 + struct super_block *h_sb;
8336 + memset(&ia, -1, sizeof(ia));
8337 + h_sb = h_dentry->d_sb;
8339 + if (d_is_positive(h_dentry)) {
8340 + h_inode = d_inode(h_dentry);
8341 + au_iattr_save(&ia, h_inode);
8342 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8343 + /* nfs d_revalidate may return 0 for negative dentry */
8344 + /* fuse d_revalidate always return 0 for negative dentry */
8347 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8348 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8349 + err = PTR_ERR(h_d);
8354 + if (unlikely(h_d != h_dentry
8355 + || d_inode(h_d) != h_inode
8356 + || (h_inode && au_iattr_test(&ia, h_inode))))
8357 + err = au_busy_or_stale();
8365 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8366 + struct dentry *h_parent, struct au_branch *br)
8371 + if (udba == AuOpt_UDBA_REVAL
8372 + && !au_test_fs_remote(h_dentry->d_sb)) {
8374 + err = (d_inode(h_dentry->d_parent) != h_dir);
8375 + } else if (udba != AuOpt_UDBA_NONE)
8376 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8381 +/* ---------------------------------------------------------------------- */
8383 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8386 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8387 + struct au_hdentry tmp, *p, *q;
8388 + struct au_dinfo *dinfo;
8389 + struct super_block *sb;
8391 + DiMustWriteLock(dentry);
8393 + sb = dentry->d_sb;
8394 + dinfo = au_di(dentry);
8395 + bbot = dinfo->di_bbot;
8396 + bwh = dinfo->di_bwh;
8397 + bdiropq = dinfo->di_bdiropq;
8398 + bindex = dinfo->di_btop;
8399 + p = au_hdentry(dinfo, bindex);
8400 + for (; bindex <= bbot; bindex++, p++) {
8401 + if (!p->hd_dentry)
8404 + new_bindex = au_br_index(sb, p->hd_id);
8405 + if (new_bindex == bindex)
8408 + if (dinfo->di_bwh == bindex)
8410 + if (dinfo->di_bdiropq == bindex)
8411 + bdiropq = new_bindex;
8412 + if (new_bindex < 0) {
8414 + p->hd_dentry = NULL;
8418 + /* swap two lower dentries, and loop again */
8419 + q = au_hdentry(dinfo, new_bindex);
8423 + if (tmp.hd_dentry) {
8429 + dinfo->di_bwh = -1;
8430 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8431 + dinfo->di_bwh = bwh;
8433 + dinfo->di_bdiropq = -1;
8435 + && bdiropq <= au_sbbot(sb)
8436 + && au_sbr_whable(sb, bdiropq))
8437 + dinfo->di_bdiropq = bdiropq;
8440 + dinfo->di_btop = -1;
8441 + dinfo->di_bbot = -1;
8442 + bbot = au_dbbot(parent);
8444 + p = au_hdentry(dinfo, bindex);
8445 + for (; bindex <= bbot; bindex++, p++)
8446 + if (p->hd_dentry) {
8447 + dinfo->di_btop = bindex;
8451 + if (dinfo->di_btop >= 0) {
8453 + p = au_hdentry(dinfo, bindex);
8454 + for (; bindex >= 0; bindex--, p--)
8455 + if (p->hd_dentry) {
8456 + dinfo->di_bbot = bindex;
8465 +static void au_do_hide(struct dentry *dentry)
8467 + struct inode *inode;
8469 + if (d_really_is_positive(dentry)) {
8470 + inode = d_inode(dentry);
8471 + if (!d_is_dir(dentry)) {
8472 + if (inode->i_nlink && !d_unhashed(dentry))
8473 + drop_nlink(inode);
8475 + clear_nlink(inode);
8476 + /* stop next lookup */
8477 + inode->i_flags |= S_DEAD;
8479 + smp_mb(); /* necessary? */
8484 +static int au_hide_children(struct dentry *parent)
8486 + int err, i, j, ndentry;
8487 + struct au_dcsub_pages dpages;
8488 + struct au_dpage *dpage;
8489 + struct dentry *dentry;
8491 + err = au_dpages_init(&dpages, GFP_NOFS);
8492 + if (unlikely(err))
8494 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8495 + if (unlikely(err))
8498 + /* in reverse order */
8499 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8500 + dpage = dpages.dpages + i;
8501 + ndentry = dpage->ndentry;
8502 + for (j = ndentry - 1; j >= 0; j--) {
8503 + dentry = dpage->dentries[j];
8504 + if (dentry != parent)
8505 + au_do_hide(dentry);
8510 + au_dpages_free(&dpages);
8515 +static void au_hide(struct dentry *dentry)
8519 + AuDbgDentry(dentry);
8520 + if (d_is_dir(dentry)) {
8521 + /* shrink_dcache_parent(dentry); */
8522 + err = au_hide_children(dentry);
8523 + if (unlikely(err))
8524 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8527 + au_do_hide(dentry);
8531 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8533 + * a dirty branch is added
8534 + * - on the top of layers
8535 + * - in the middle of layers
8536 + * - to the bottom of layers
8538 + * on the added branch there exists
8541 + * - a same named entry
8543 + * * negative --> positive
8544 + * * positive --> positive
8545 + * - type is unchanged
8546 + * - type is changed
8548 + * * negative --> negative
8549 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8552 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8553 + struct au_dinfo *tmp)
8556 + aufs_bindex_t bindex, bbot;
8558 + struct dentry *dentry;
8559 + struct inode *inode;
8561 + } orig_h, tmp_h = {
8564 + struct au_hdentry *hd;
8565 + struct inode *inode, *h_inode;
8566 + struct dentry *h_dentry;
8569 + AuDebugOn(dinfo->di_btop < 0);
8571 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8572 + orig_h.inode = NULL;
8573 + if (d_is_positive(orig_h.dentry)) {
8574 + orig_h.inode = d_inode(orig_h.dentry);
8575 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8577 + if (tmp->di_btop >= 0) {
8578 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8579 + if (d_is_positive(tmp_h.dentry)) {
8580 + tmp_h.inode = d_inode(tmp_h.dentry);
8581 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8586 + if (d_really_is_positive(dentry))
8587 + inode = d_inode(dentry);
8588 + if (!orig_h.inode) {
8589 + AuDbg("negative originally\n");
8595 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8596 + AuDebugOn(dinfo->di_bdiropq != -1);
8598 + if (!tmp_h.inode) {
8599 + AuDbg("negative --> negative\n");
8600 + /* should have only one negative lower */
8601 + if (tmp->di_btop >= 0
8602 + && tmp->di_btop < dinfo->di_btop) {
8603 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8604 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8605 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8606 + au_di_cp(dinfo, tmp);
8607 + hd = au_hdentry(tmp, tmp->di_btop);
8608 + au_set_h_dptr(dentry, tmp->di_btop,
8609 + dget(hd->hd_dentry));
8611 + au_dbg_verify_dinode(dentry);
8613 + AuDbg("negative --> positive\n");
8615 + * similar to the behaviour of creating with bypassing
8617 + * unhash it in order to force an error in the
8618 + * succeeding create operation.
8619 + * we should not set S_DEAD here.
8622 + /* au_di_swap(tmp, dinfo); */
8623 + au_dbg_verify_dinode(dentry);
8626 + AuDbg("positive originally\n");
8627 + /* inode may be NULL */
8628 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8629 + if (!tmp_h.inode) {
8630 + AuDbg("positive --> negative\n");
8631 + /* or bypassing aufs */
8633 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8634 + dinfo->di_bwh = tmp->di_bwh;
8636 + err = au_refresh_hinode_self(inode);
8637 + au_dbg_verify_dinode(dentry);
8638 + } else if (orig_h.mode == tmp_h.mode) {
8639 + AuDbg("positive --> positive, same type\n");
8640 + if (!S_ISDIR(orig_h.mode)
8641 + && dinfo->di_btop > tmp->di_btop) {
8643 + * similar to the behaviour of removing and
8648 + err = au_refresh_hinode_self(inode);
8649 + au_dbg_verify_dinode(dentry);
8651 + /* fill empty slots */
8652 + if (dinfo->di_btop > tmp->di_btop)
8653 + dinfo->di_btop = tmp->di_btop;
8654 + if (dinfo->di_bbot < tmp->di_bbot)
8655 + dinfo->di_bbot = tmp->di_bbot;
8656 + dinfo->di_bwh = tmp->di_bwh;
8657 + dinfo->di_bdiropq = tmp->di_bdiropq;
8658 + bbot = dinfo->di_bbot;
8659 + bindex = tmp->di_btop;
8660 + hd = au_hdentry(tmp, bindex);
8661 + for (; bindex <= bbot; bindex++, hd++) {
8662 + if (au_h_dptr(dentry, bindex))
8664 + h_dentry = hd->hd_dentry;
8667 + AuDebugOn(d_is_negative(h_dentry));
8668 + h_inode = d_inode(h_dentry);
8669 + AuDebugOn(orig_h.mode
8670 + != (h_inode->i_mode
8672 + au_set_h_dptr(dentry, bindex,
8676 + err = au_refresh_hinode(inode, dentry);
8677 + au_dbg_verify_dinode(dentry);
8680 + AuDbg("positive --> positive, different type\n");
8681 + /* similar to the behaviour of removing and creating */
8684 + err = au_refresh_hinode_self(inode);
8685 + au_dbg_verify_dinode(dentry);
8693 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8695 + const struct dentry_operations *dop
8696 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8697 + static const unsigned int mask
8698 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8700 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8702 + if (dentry->d_op == dop)
8705 + AuDbg("%pd\n", dentry);
8706 + spin_lock(&dentry->d_lock);
8707 + if (dop == &aufs_dop)
8708 + dentry->d_flags |= mask;
8710 + dentry->d_flags &= ~mask;
8711 + dentry->d_op = dop;
8712 + spin_unlock(&dentry->d_lock);
8715 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8717 + int err, ebrange, nbr;
8718 + unsigned int sigen;
8719 + struct au_dinfo *dinfo, *tmp;
8720 + struct super_block *sb;
8721 + struct inode *inode;
8723 + DiMustWriteLock(dentry);
8724 + AuDebugOn(IS_ROOT(dentry));
8725 + AuDebugOn(d_really_is_negative(parent));
8727 + sb = dentry->d_sb;
8728 + sigen = au_sigen(sb);
8729 + err = au_digen_test(parent, sigen);
8730 + if (unlikely(err))
8733 + nbr = au_sbbot(sb) + 1;
8734 + dinfo = au_di(dentry);
8735 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8736 + if (unlikely(err))
8738 + ebrange = au_dbrange_test(dentry);
8740 + ebrange = au_do_refresh_hdentry(dentry, parent);
8742 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8743 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8744 + if (d_really_is_positive(dentry)) {
8745 + inode = d_inode(dentry);
8746 + err = au_refresh_hinode_self(inode);
8748 + au_dbg_verify_dinode(dentry);
8750 + goto out_dgen; /* success */
8754 + /* temporary dinfo */
8755 + AuDbgDentry(dentry);
8757 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8758 + if (unlikely(!tmp))
8760 + au_di_swap(tmp, dinfo);
8761 + /* returns the number of positive dentries */
8763 + * if current working dir is removed, it returns an error.
8764 + * but the dentry is legal.
8766 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8767 + AuDbgDentry(dentry);
8768 + au_di_swap(tmp, dinfo);
8769 + if (err == -ENOENT)
8772 + /* compare/refresh by dinfo */
8773 + AuDbgDentry(dentry);
8774 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8775 + au_dbg_verify_dinode(dentry);
8778 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8779 + au_rw_write_unlock(&tmp->di_rwsem);
8781 + if (unlikely(err))
8785 + au_update_digen(dentry);
8787 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8788 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8789 + AuDbgDentry(dentry);
8795 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8796 + struct dentry *dentry, aufs_bindex_t bindex)
8801 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8804 + AuDbg("b%d\n", bindex);
8806 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8807 + * due to whiteout and branch permission.
8809 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8810 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8811 + /* it may return tri-state */
8812 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8814 + if (unlikely(valid < 0))
8824 +/* todo: remove this */
8825 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8826 + unsigned int flags, int do_udba, int dirren)
8829 + umode_t mode, h_mode;
8830 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8831 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8832 + struct inode *h_inode, *h_cached_inode;
8833 + struct dentry *h_dentry;
8834 + struct qstr *name, *h_name;
8841 + unhashed = !!d_unhashed(dentry);
8842 + is_root = !!IS_ROOT(dentry);
8843 + name = &dentry->d_name;
8844 + tmpfile = au_di(dentry)->di_tmpfile;
8847 + * Theoretically, REVAL test should be unnecessary in case of
8849 + * But {fs,i}notify doesn't fire some necessary events,
8850 + * IN_ATTRIB for atime/nlink/pageio
8851 + * Let's do REVAL test too.
8853 + if (do_udba && inode) {
8854 + mode = (inode->i_mode & S_IFMT);
8855 + plus = (inode->i_nlink > 0);
8856 + ibs = au_ibtop(inode);
8857 + ibe = au_ibbot(inode);
8860 + btop = au_dbtop(dentry);
8862 + if (inode && S_ISDIR(inode->i_mode))
8863 + btail = au_dbtaildir(dentry);
8864 + for (bindex = btop; bindex <= btail; bindex++) {
8865 + h_dentry = au_h_dptr(dentry, bindex);
8869 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8870 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8871 + spin_lock(&h_dentry->d_lock);
8872 + h_name = &h_dentry->d_name;
8873 + if (unlikely(do_udba
8876 + && (unhashed != !!d_unhashed(h_dentry)
8877 + || (!tmpfile && !dirren
8878 + && !au_qstreq(name, h_name))
8881 + && !(flags & LOOKUP_OPEN)
8882 + && (h_dentry->d_flags
8883 + & DCACHE_NFSFS_RENAMED)))
8887 + h_unhashed = d_unhashed(h_dentry);
8888 + spin_unlock(&h_dentry->d_lock);
8889 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8890 + unhashed, h_unhashed, dentry, h_dentry);
8893 + spin_unlock(&h_dentry->d_lock);
8895 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8896 + if (unlikely(err))
8897 + /* do not goto err, to keep the errno */
8900 + /* todo: plink too? */
8905 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8909 + if (d_is_positive(h_dentry))
8910 + h_inode = d_inode(h_dentry);
8913 + h_cached_inode = h_inode;
8915 + h_mode = (h_inode->i_mode & S_IFMT);
8916 + h_plus = (h_inode->i_nlink > 0);
8918 + if (inode && ibs <= bindex && bindex <= ibe)
8919 + h_cached_inode = au_h_iptr(inode, bindex);
8922 + if (unlikely(plus != h_plus && !tmpfile))
8925 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8927 + && !IS_ROOT(h_dentry)
8928 + && unhashed != d_unhashed(h_dentry)))
8931 + if (unlikely(mode != h_mode
8932 + || h_cached_inode != h_inode))
8945 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8946 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8949 + struct dentry *parent;
8951 + if (!au_digen_test(dentry, sigen))
8954 + parent = dget_parent(dentry);
8955 + di_read_lock_parent(parent, AuLock_IR);
8956 + AuDebugOn(au_digen_test(parent, sigen));
8957 + au_dbg_verify_gen(parent, sigen);
8958 + err = au_refresh_dentry(dentry, parent);
8959 + di_read_unlock(parent, AuLock_IR);
8965 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8968 + struct dentry *d, *parent;
8970 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8971 + return simple_reval_dpath(dentry, sigen);
8973 + /* slow loop, keep it simple and stupid */
8974 + /* cf: au_cpup_dirs() */
8977 + while (au_digen_test(dentry, sigen)) {
8981 + parent = dget_parent(d);
8982 + if (!au_digen_test(parent, sigen))
8988 + di_write_lock_child2(d);
8990 + /* someone might update our dentry while we were sleeping */
8991 + if (au_digen_test(d, sigen)) {
8993 + * todo: consolidate with simple_reval_dpath(),
8994 + * do_refresh() and au_reval_for_attr().
8996 + di_read_lock_parent(parent, AuLock_IR);
8997 + err = au_refresh_dentry(d, parent);
8998 + di_read_unlock(parent, AuLock_IR);
9002 + di_write_unlock(d);
9004 + if (unlikely(err))
9012 + * if valid returns 1, otherwise 0.
9014 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9017 + unsigned int sigen;
9018 + unsigned char do_udba, dirren;
9019 + struct super_block *sb;
9020 + struct inode *inode;
9022 + /* todo: support rcu-walk? */
9023 + if (flags & LOOKUP_RCU)
9027 + if (unlikely(!au_di(dentry)))
9031 + sb = dentry->d_sb;
9034 + * i_mutex of parent dir may be held,
9035 + * but we should not return 'invalid' due to busy.
9037 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9038 + if (unlikely(err)) {
9044 + if (d_really_is_positive(dentry))
9045 + inode = d_inode(dentry);
9046 + if (unlikely(inode && au_is_bad_inode(inode))) {
9051 + if (unlikely(au_dbrange_test(dentry))) {
9057 + sigen = au_sigen(sb);
9058 + if (au_digen_test(dentry, sigen)) {
9059 + AuDebugOn(IS_ROOT(dentry));
9060 + err = au_reval_dpath(dentry, sigen);
9061 + if (unlikely(err)) {
9066 + di_downgrade_lock(dentry, AuLock_IR);
9069 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9071 + && !(inode->i_state && I_LINKABLE)
9072 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9077 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9078 + if (do_udba && inode) {
9079 + aufs_bindex_t btop = au_ibtop(inode);
9080 + struct inode *h_inode;
9083 + h_inode = au_h_iptr(inode, btop);
9084 + if (h_inode && au_test_higen(inode, h_inode)) {
9091 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9092 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9093 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9095 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9101 + di_downgrade_lock(dentry, AuLock_IR);
9103 + aufs_read_unlock(dentry, AuLock_IR);
9108 + AuDbg("%pd invalid, %d\n", dentry, valid);
9114 +static void aufs_d_release(struct dentry *dentry)
9116 + if (au_di(dentry)) {
9117 + au_di_fin(dentry);
9118 + au_hn_di_reinit(dentry);
9122 +const struct dentry_operations aufs_dop = {
9123 + .d_revalidate = aufs_d_revalidate,
9124 + .d_weak_revalidate = aufs_d_revalidate,
9125 + .d_release = aufs_d_release
9128 +/* aufs_dop without d_revalidate */
9129 +const struct dentry_operations aufs_dop_noreval = {
9130 + .d_release = aufs_d_release
9132 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9133 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9134 +++ linux/fs/aufs/dentry.h 2021-02-22 22:51:59.058078584 +0100
9136 +/* SPDX-License-Identifier: GPL-2.0 */
9138 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9140 + * This program, aufs is free software; you can redistribute it and/or modify
9141 + * it under the terms of the GNU General Public License as published by
9142 + * the Free Software Foundation; either version 2 of the License, or
9143 + * (at your option) any later version.
9145 + * This program is distributed in the hope that it will be useful,
9146 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9147 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9148 + * GNU General Public License for more details.
9150 + * You should have received a copy of the GNU General Public License
9151 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9155 + * lookup and dentry operations
9158 +#ifndef __AUFS_DENTRY_H__
9159 +#define __AUFS_DENTRY_H__
9163 +#include <linux/dcache.h>
9164 +#include "dirren.h"
9167 +struct au_hdentry {
9168 + struct dentry *hd_dentry;
9169 + aufs_bindex_t hd_id;
9173 + atomic_t di_generation;
9175 + struct au_rwsem di_rwsem;
9176 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9177 + unsigned char di_tmpfile; /* to allow the different name */
9178 + struct au_hdentry *di_hdentry;
9179 + struct rcu_head rcu;
9180 +} ____cacheline_aligned_in_smp;
9182 +/* ---------------------------------------------------------------------- */
9184 +/* flags for au_lkup_dentry() */
9185 +#define AuLkup_ALLOW_NEG 1
9186 +#define AuLkup_IGNORE_PERM (1 << 1)
9187 +#define AuLkup_DIRREN (1 << 2)
9188 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9189 +#define au_fset_lkup(flags, name) \
9190 + do { (flags) |= AuLkup_##name; } while (0)
9191 +#define au_fclr_lkup(flags, name) \
9192 + do { (flags) &= ~AuLkup_##name; } while (0)
9194 +#ifndef CONFIG_AUFS_DIRREN
9195 +#undef AuLkup_DIRREN
9196 +#define AuLkup_DIRREN 0
9199 +struct au_do_lookup_args {
9200 + unsigned int flags;
9202 + struct qstr whname, *name;
9203 + struct au_dr_lookup dirren;
9206 +/* ---------------------------------------------------------------------- */
9209 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9211 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
9212 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9213 + struct dentry *h_parent, struct au_branch *br);
9215 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9216 + unsigned int flags);
9217 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9218 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9219 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9220 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9223 +void au_di_init_once(void *_di);
9224 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9225 +void au_di_free(struct au_dinfo *dinfo);
9226 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9227 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9228 +int au_di_init(struct dentry *dentry);
9229 +void au_di_fin(struct dentry *dentry);
9230 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9232 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9233 +void di_read_unlock(struct dentry *d, int flags);
9234 +void di_downgrade_lock(struct dentry *d, int flags);
9235 +void di_write_lock(struct dentry *d, unsigned int lsc);
9236 +void di_write_unlock(struct dentry *d);
9237 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9238 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9239 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9241 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9242 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9243 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9244 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9246 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9247 + struct dentry *h_dentry);
9248 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9249 +int au_dbrange_test(struct dentry *dentry);
9250 +void au_update_digen(struct dentry *dentry);
9251 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9252 +void au_update_dbtop(struct dentry *dentry);
9253 +void au_update_dbbot(struct dentry *dentry);
9254 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9256 +/* ---------------------------------------------------------------------- */
9258 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9260 + return dentry->d_fsdata;
9263 +/* ---------------------------------------------------------------------- */
9265 +/* lock subclass for dinfo */
9267 + AuLsc_DI_CHILD, /* child first */
9268 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9269 + AuLsc_DI_CHILD3, /* copyup dirs */
9273 + AuLsc_DI_TMP /* temp for replacing dinfo */
9277 + * di_read_lock_child, di_write_lock_child,
9278 + * di_read_lock_child2, di_write_lock_child2,
9279 + * di_read_lock_child3, di_write_lock_child3,
9280 + * di_read_lock_parent, di_write_lock_parent,
9281 + * di_read_lock_parent2, di_write_lock_parent2,
9282 + * di_read_lock_parent3, di_write_lock_parent3,
9284 +#define AuReadLockFunc(name, lsc) \
9285 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9286 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9288 +#define AuWriteLockFunc(name, lsc) \
9289 +static inline void di_write_lock_##name(struct dentry *d) \
9290 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9292 +#define AuRWLockFuncs(name, lsc) \
9293 + AuReadLockFunc(name, lsc) \
9294 + AuWriteLockFunc(name, lsc)
9296 +AuRWLockFuncs(child, CHILD);
9297 +AuRWLockFuncs(child2, CHILD2);
9298 +AuRWLockFuncs(child3, CHILD3);
9299 +AuRWLockFuncs(parent, PARENT);
9300 +AuRWLockFuncs(parent2, PARENT2);
9301 +AuRWLockFuncs(parent3, PARENT3);
9303 +#undef AuReadLockFunc
9304 +#undef AuWriteLockFunc
9305 +#undef AuRWLockFuncs
9307 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9308 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9309 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9311 +/* ---------------------------------------------------------------------- */
9313 +/* todo: memory barrier? */
9314 +static inline unsigned int au_digen(struct dentry *d)
9316 + return atomic_read(&au_di(d)->di_generation);
9319 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9321 + hdentry->hd_dentry = NULL;
9324 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9325 + aufs_bindex_t bindex)
9327 + return di->di_hdentry + bindex;
9330 +static inline void au_hdput(struct au_hdentry *hd)
9333 + dput(hd->hd_dentry);
9336 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9338 + DiMustAnyLock(dentry);
9339 + return au_di(dentry)->di_btop;
9342 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9344 + DiMustAnyLock(dentry);
9345 + return au_di(dentry)->di_bbot;
9348 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9350 + DiMustAnyLock(dentry);
9351 + return au_di(dentry)->di_bwh;
9354 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9356 + DiMustAnyLock(dentry);
9357 + return au_di(dentry)->di_bdiropq;
9360 +/* todo: hard/soft set? */
9361 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9363 + DiMustWriteLock(dentry);
9364 + au_di(dentry)->di_btop = bindex;
9367 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9369 + DiMustWriteLock(dentry);
9370 + au_di(dentry)->di_bbot = bindex;
9373 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9375 + DiMustWriteLock(dentry);
9376 + /* dbwh can be outside of btop - bbot range */
9377 + au_di(dentry)->di_bwh = bindex;
9380 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9382 + DiMustWriteLock(dentry);
9383 + au_di(dentry)->di_bdiropq = bindex;
9386 +/* ---------------------------------------------------------------------- */
9388 +#ifdef CONFIG_AUFS_HNOTIFY
9389 +static inline void au_digen_dec(struct dentry *d)
9391 + atomic_dec(&au_di(d)->di_generation);
9394 +static inline void au_hn_di_reinit(struct dentry *dentry)
9396 + dentry->d_fsdata = NULL;
9399 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9400 +#endif /* CONFIG_AUFS_HNOTIFY */
9402 +#endif /* __KERNEL__ */
9403 +#endif /* __AUFS_DENTRY_H__ */
9404 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9405 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9406 +++ linux/fs/aufs/dinfo.c 2021-02-22 22:51:59.058078584 +0100
9408 +// SPDX-License-Identifier: GPL-2.0
9410 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9412 + * This program, aufs is free software; you can redistribute it and/or modify
9413 + * it under the terms of the GNU General Public License as published by
9414 + * the Free Software Foundation; either version 2 of the License, or
9415 + * (at your option) any later version.
9417 + * This program is distributed in the hope that it will be useful,
9418 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9419 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9420 + * GNU General Public License for more details.
9422 + * You should have received a copy of the GNU General Public License
9423 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9427 + * dentry private data
9432 +void au_di_init_once(void *_dinfo)
9434 + struct au_dinfo *dinfo = _dinfo;
9436 + au_rw_init(&dinfo->di_rwsem);
9439 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9441 + struct au_dinfo *dinfo;
9444 + dinfo = au_cache_alloc_dinfo();
9445 + if (unlikely(!dinfo))
9448 + nbr = au_sbbot(sb) + 1;
9451 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9452 + if (dinfo->di_hdentry) {
9453 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9454 + dinfo->di_btop = -1;
9455 + dinfo->di_bbot = -1;
9456 + dinfo->di_bwh = -1;
9457 + dinfo->di_bdiropq = -1;
9458 + dinfo->di_tmpfile = 0;
9459 + for (i = 0; i < nbr; i++)
9460 + dinfo->di_hdentry[i].hd_id = -1;
9464 + au_cache_free_dinfo(dinfo);
9471 +void au_di_free(struct au_dinfo *dinfo)
9473 + struct au_hdentry *p;
9474 + aufs_bindex_t bbot, bindex;
9476 + /* dentry may not be revalidated */
9477 + bindex = dinfo->di_btop;
9478 + if (bindex >= 0) {
9479 + bbot = dinfo->di_bbot;
9480 + p = au_hdentry(dinfo, bindex);
9481 + while (bindex++ <= bbot)
9484 + au_kfree_try_rcu(dinfo->di_hdentry);
9485 + au_cache_free_dinfo(dinfo);
9488 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9490 + struct au_hdentry *p;
9493 + AuRwMustWriteLock(&a->di_rwsem);
9494 + AuRwMustWriteLock(&b->di_rwsem);
9496 +#define DiSwap(v, name) \
9498 + v = a->di_##name; \
9499 + a->di_##name = b->di_##name; \
9500 + b->di_##name = v; \
9503 + DiSwap(p, hdentry);
9507 + DiSwap(bi, bdiropq);
9513 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9515 + AuRwMustWriteLock(&dst->di_rwsem);
9516 + AuRwMustWriteLock(&src->di_rwsem);
9518 + dst->di_btop = src->di_btop;
9519 + dst->di_bbot = src->di_bbot;
9520 + dst->di_bwh = src->di_bwh;
9521 + dst->di_bdiropq = src->di_bdiropq;
9525 +int au_di_init(struct dentry *dentry)
9528 + struct super_block *sb;
9529 + struct au_dinfo *dinfo;
9532 + sb = dentry->d_sb;
9533 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9535 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9536 + /* smp_mb(); */ /* atomic_set */
9537 + dentry->d_fsdata = dinfo;
9544 +void au_di_fin(struct dentry *dentry)
9546 + struct au_dinfo *dinfo;
9548 + dinfo = au_di(dentry);
9549 + AuRwDestroy(&dinfo->di_rwsem);
9550 + au_di_free(dinfo);
9553 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9556 + struct au_hdentry *hdp;
9558 + AuRwMustWriteLock(&dinfo->di_rwsem);
9561 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9563 + sz = sizeof(*hdp);
9564 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9567 + dinfo->di_hdentry = hdp;
9574 +/* ---------------------------------------------------------------------- */
9576 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9579 + case AuLsc_DI_CHILD:
9580 + ii_write_lock_child(inode);
9582 + case AuLsc_DI_CHILD2:
9583 + ii_write_lock_child2(inode);
9585 + case AuLsc_DI_CHILD3:
9586 + ii_write_lock_child3(inode);
9588 + case AuLsc_DI_PARENT:
9589 + ii_write_lock_parent(inode);
9591 + case AuLsc_DI_PARENT2:
9592 + ii_write_lock_parent2(inode);
9594 + case AuLsc_DI_PARENT3:
9595 + ii_write_lock_parent3(inode);
9602 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9605 + case AuLsc_DI_CHILD:
9606 + ii_read_lock_child(inode);
9608 + case AuLsc_DI_CHILD2:
9609 + ii_read_lock_child2(inode);
9611 + case AuLsc_DI_CHILD3:
9612 + ii_read_lock_child3(inode);
9614 + case AuLsc_DI_PARENT:
9615 + ii_read_lock_parent(inode);
9617 + case AuLsc_DI_PARENT2:
9618 + ii_read_lock_parent2(inode);
9620 + case AuLsc_DI_PARENT3:
9621 + ii_read_lock_parent3(inode);
9628 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9630 + struct inode *inode;
9632 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9633 + if (d_really_is_positive(d)) {
9634 + inode = d_inode(d);
9635 + if (au_ftest_lock(flags, IW))
9636 + do_ii_write_lock(inode, lsc);
9637 + else if (au_ftest_lock(flags, IR))
9638 + do_ii_read_lock(inode, lsc);
9642 +void di_read_unlock(struct dentry *d, int flags)
9644 + struct inode *inode;
9646 + if (d_really_is_positive(d)) {
9647 + inode = d_inode(d);
9648 + if (au_ftest_lock(flags, IW)) {
9649 + au_dbg_verify_dinode(d);
9650 + ii_write_unlock(inode);
9651 + } else if (au_ftest_lock(flags, IR)) {
9652 + au_dbg_verify_dinode(d);
9653 + ii_read_unlock(inode);
9656 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9659 +void di_downgrade_lock(struct dentry *d, int flags)
9661 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9662 + ii_downgrade_lock(d_inode(d));
9663 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9666 +void di_write_lock(struct dentry *d, unsigned int lsc)
9668 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9669 + if (d_really_is_positive(d))
9670 + do_ii_write_lock(d_inode(d), lsc);
9673 +void di_write_unlock(struct dentry *d)
9675 + au_dbg_verify_dinode(d);
9676 + if (d_really_is_positive(d))
9677 + ii_write_unlock(d_inode(d));
9678 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9681 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9683 + AuDebugOn(d1 == d2
9684 + || d_inode(d1) == d_inode(d2)
9685 + || d1->d_sb != d2->d_sb);
9687 + if ((isdir && au_test_subdir(d1, d2))
9689 + di_write_lock_child(d1);
9690 + di_write_lock_child2(d2);
9692 + di_write_lock_child(d2);
9693 + di_write_lock_child2(d1);
9697 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9699 + AuDebugOn(d1 == d2
9700 + || d_inode(d1) == d_inode(d2)
9701 + || d1->d_sb != d2->d_sb);
9703 + if ((isdir && au_test_subdir(d1, d2))
9705 + di_write_lock_parent(d1);
9706 + di_write_lock_parent2(d2);
9708 + di_write_lock_parent(d2);
9709 + di_write_lock_parent2(d1);
9713 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9715 + di_write_unlock(d1);
9716 + if (d_inode(d1) == d_inode(d2))
9717 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9719 + di_write_unlock(d2);
9722 +/* ---------------------------------------------------------------------- */
9724 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9728 + DiMustAnyLock(dentry);
9730 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9732 + AuDebugOn(bindex < 0);
9733 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9734 + AuDebugOn(d && au_dcount(d) <= 0);
9739 + * extended version of au_h_dptr().
9740 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9743 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9745 + struct dentry *h_dentry;
9746 + struct inode *inode, *h_inode;
9748 + AuDebugOn(d_really_is_negative(dentry));
9751 + if (au_dbtop(dentry) <= bindex
9752 + && bindex <= au_dbbot(dentry))
9753 + h_dentry = au_h_dptr(dentry, bindex);
9754 + if (h_dentry && !au_d_linkable(h_dentry)) {
9756 + goto out; /* success */
9759 + inode = d_inode(dentry);
9760 + AuDebugOn(bindex < au_ibtop(inode));
9761 + AuDebugOn(au_ibbot(inode) < bindex);
9762 + h_inode = au_h_iptr(inode, bindex);
9763 + h_dentry = d_find_alias(h_inode);
9765 + if (!IS_ERR(h_dentry)) {
9766 + if (!au_d_linkable(h_dentry))
9767 + goto out; /* success */
9773 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9774 + h_dentry = au_plink_lkup(inode, bindex);
9775 + AuDebugOn(!h_dentry);
9776 + if (!IS_ERR(h_dentry)) {
9777 + if (!au_d_hashed_positive(h_dentry))
9778 + goto out; /* success */
9785 + AuDbgDentry(h_dentry);
9789 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9791 + aufs_bindex_t bbot, bwh;
9793 + bbot = au_dbbot(dentry);
9795 + bwh = au_dbwh(dentry);
9798 + if (0 < bwh && bwh < bbot)
9804 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9806 + aufs_bindex_t bbot, bopq;
9808 + bbot = au_dbtail(dentry);
9810 + bopq = au_dbdiropq(dentry);
9811 + if (0 <= bopq && bopq < bbot)
9817 +/* ---------------------------------------------------------------------- */
9819 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9820 + struct dentry *h_dentry)
9822 + struct au_dinfo *dinfo;
9823 + struct au_hdentry *hd;
9824 + struct au_branch *br;
9826 + DiMustWriteLock(dentry);
9828 + dinfo = au_di(dentry);
9829 + hd = au_hdentry(dinfo, bindex);
9831 + hd->hd_dentry = h_dentry;
9833 + br = au_sbr(dentry->d_sb, bindex);
9834 + hd->hd_id = br->br_id;
9838 +int au_dbrange_test(struct dentry *dentry)
9841 + aufs_bindex_t btop, bbot;
9844 + btop = au_dbtop(dentry);
9845 + bbot = au_dbbot(dentry);
9847 + AuDebugOn(bbot < 0 && btop > bbot);
9850 + AuDebugOn(bbot >= 0);
9856 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9861 + if (unlikely(au_digen(dentry) != sigen
9862 + || au_iigen_test(d_inode(dentry), sigen)))
9868 +void au_update_digen(struct dentry *dentry)
9870 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9871 + /* smp_mb(); */ /* atomic_set */
9874 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9876 + struct au_dinfo *dinfo;
9877 + struct dentry *h_d;
9878 + struct au_hdentry *hdp;
9879 + aufs_bindex_t bindex, bbot;
9881 + DiMustWriteLock(dentry);
9883 + dinfo = au_di(dentry);
9884 + if (!dinfo || dinfo->di_btop < 0)
9887 + if (do_put_zero) {
9888 + bbot = dinfo->di_bbot;
9889 + bindex = dinfo->di_btop;
9890 + hdp = au_hdentry(dinfo, bindex);
9891 + for (; bindex <= bbot; bindex++, hdp++) {
9892 + h_d = hdp->hd_dentry;
9893 + if (h_d && d_is_negative(h_d))
9894 + au_set_h_dptr(dentry, bindex, NULL);
9898 + dinfo->di_btop = 0;
9899 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9900 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9901 + if (hdp->hd_dentry)
9903 + if (dinfo->di_btop > dinfo->di_bbot) {
9904 + dinfo->di_btop = -1;
9905 + dinfo->di_bbot = -1;
9909 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9910 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9911 + if (hdp->hd_dentry)
9913 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9916 +void au_update_dbtop(struct dentry *dentry)
9918 + aufs_bindex_t bindex, bbot;
9919 + struct dentry *h_dentry;
9921 + bbot = au_dbbot(dentry);
9922 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9923 + h_dentry = au_h_dptr(dentry, bindex);
9926 + if (d_is_positive(h_dentry)) {
9927 + au_set_dbtop(dentry, bindex);
9930 + au_set_h_dptr(dentry, bindex, NULL);
9934 +void au_update_dbbot(struct dentry *dentry)
9936 + aufs_bindex_t bindex, btop;
9937 + struct dentry *h_dentry;
9939 + btop = au_dbtop(dentry);
9940 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9941 + h_dentry = au_h_dptr(dentry, bindex);
9944 + if (d_is_positive(h_dentry)) {
9945 + au_set_dbbot(dentry, bindex);
9948 + au_set_h_dptr(dentry, bindex, NULL);
9952 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9954 + aufs_bindex_t bindex, bbot;
9956 + bbot = au_dbbot(dentry);
9957 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9958 + if (au_h_dptr(dentry, bindex) == h_dentry)
9962 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9963 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9964 +++ linux/fs/aufs/dir.c 2021-02-22 22:51:59.058078584 +0100
9966 +// SPDX-License-Identifier: GPL-2.0
9968 + * Copyright (C) 2005-2020 Junjiro R. Okajima
9970 + * This program, aufs is free software; you can redistribute it and/or modify
9971 + * it under the terms of the GNU General Public License as published by
9972 + * the Free Software Foundation; either version 2 of the License, or
9973 + * (at your option) any later version.
9975 + * This program is distributed in the hope that it will be useful,
9976 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9977 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9978 + * GNU General Public License for more details.
9980 + * You should have received a copy of the GNU General Public License
9981 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9985 + * directory operations
9988 +#include <linux/fs_stack.h>
9989 +#include <linux/iversion.h>
9992 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9994 + unsigned int nlink;
9996 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9998 + nlink = dir->i_nlink;
9999 + nlink += h_dir->i_nlink - 2;
10000 + if (h_dir->i_nlink < 2)
10002 + smp_mb(); /* for i_nlink */
10003 + /* 0 can happen in revaliding */
10004 + set_nlink(dir, nlink);
10007 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10009 + unsigned int nlink;
10011 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10013 + nlink = dir->i_nlink;
10014 + nlink -= h_dir->i_nlink - 2;
10015 + if (h_dir->i_nlink < 2)
10017 + smp_mb(); /* for i_nlink */
10018 + /* nlink == 0 means the branch-fs is broken */
10019 + set_nlink(dir, nlink);
10022 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10025 + aufs_bindex_t bindex, bbot;
10026 + struct file *h_file;
10027 + struct dentry *h_dentry;
10031 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10033 + bbot = au_fbbot_dir(file);
10034 + for (bindex = au_fbtop(file);
10035 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10037 + h_file = au_hf_dir(file, bindex);
10038 + if (h_file && file_inode(h_file))
10039 + sz += vfsub_f_size_read(h_file);
10042 + AuDebugOn(!dentry);
10043 + AuDebugOn(!d_is_dir(dentry));
10045 + bbot = au_dbtaildir(dentry);
10046 + for (bindex = au_dbtop(dentry);
10047 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10049 + h_dentry = au_h_dptr(dentry, bindex);
10050 + if (h_dentry && d_is_positive(h_dentry))
10051 + sz += i_size_read(d_inode(h_dentry));
10054 + if (sz < KMALLOC_MAX_SIZE)
10055 + sz = roundup_pow_of_two(sz);
10056 + if (sz > KMALLOC_MAX_SIZE)
10057 + sz = KMALLOC_MAX_SIZE;
10058 + else if (sz < NAME_MAX) {
10059 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10060 + sz = AUFS_RDBLK_DEF;
10065 +struct au_dir_ts_arg {
10066 + struct dentry *dentry;
10067 + aufs_bindex_t brid;
10070 +static void au_do_dir_ts(void *arg)
10072 + struct au_dir_ts_arg *a = arg;
10073 + struct au_dtime dt;
10074 + struct path h_path;
10075 + struct inode *dir, *h_dir;
10076 + struct super_block *sb;
10077 + struct au_branch *br;
10078 + struct au_hinode *hdir;
10080 + aufs_bindex_t btop, bindex;
10082 + sb = a->dentry->d_sb;
10083 + if (d_really_is_negative(a->dentry))
10085 + /* no dir->i_mutex lock */
10086 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10088 + dir = d_inode(a->dentry);
10089 + btop = au_ibtop(dir);
10090 + bindex = au_br_index(sb, a->brid);
10091 + if (bindex < btop)
10094 + br = au_sbr(sb, bindex);
10095 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10096 + if (!h_path.dentry)
10098 + h_path.mnt = au_br_mnt(br);
10099 + au_dtime_store(&dt, a->dentry, &h_path);
10101 + br = au_sbr(sb, btop);
10102 + if (!au_br_writable(br->br_perm))
10104 + h_path.dentry = au_h_dptr(a->dentry, btop);
10105 + h_path.mnt = au_br_mnt(br);
10106 + err = vfsub_mnt_want_write(h_path.mnt);
10109 + hdir = au_hi(dir, btop);
10110 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10111 + h_dir = au_h_iptr(dir, btop);
10112 + if (h_dir->i_nlink
10113 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10114 + dt.dt_h_path = h_path;
10115 + au_dtime_revert(&dt);
10117 + au_hn_inode_unlock(hdir);
10118 + vfsub_mnt_drop_write(h_path.mnt);
10119 + au_cpup_attr_timesizes(dir);
10122 + aufs_read_unlock(a->dentry, AuLock_DW);
10125 + au_nwt_done(&au_sbi(sb)->si_nowait);
10126 + au_kfree_try_rcu(arg);
10129 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10131 + int perm, wkq_err;
10132 + aufs_bindex_t btop;
10133 + struct au_dir_ts_arg *arg;
10134 + struct dentry *dentry;
10135 + struct super_block *sb;
10139 + dentry = d_find_any_alias(dir);
10140 + AuDebugOn(!dentry);
10141 + sb = dentry->d_sb;
10142 + btop = au_ibtop(dir);
10143 + if (btop == bindex) {
10144 + au_cpup_attr_timesizes(dir);
10148 + perm = au_sbr_perm(sb, btop);
10149 + if (!au_br_writable(perm))
10152 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10156 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10157 + arg->brid = au_sbr_id(sb, bindex);
10158 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10159 + if (unlikely(wkq_err)) {
10160 + pr_err("wkq %d\n", wkq_err);
10162 + au_kfree_try_rcu(arg);
10169 +/* ---------------------------------------------------------------------- */
10171 +static int reopen_dir(struct file *file)
10174 + unsigned int flags;
10175 + aufs_bindex_t bindex, btail, btop;
10176 + struct dentry *dentry, *h_dentry;
10177 + struct file *h_file;
10179 + /* open all lower dirs */
10180 + dentry = file->f_path.dentry;
10181 + btop = au_dbtop(dentry);
10182 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10183 + au_set_h_fptr(file, bindex, NULL);
10184 + au_set_fbtop(file, btop);
10186 + btail = au_dbtaildir(dentry);
10187 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10188 + au_set_h_fptr(file, bindex, NULL);
10189 + au_set_fbbot_dir(file, btail);
10191 + flags = vfsub_file_flags(file);
10192 + for (bindex = btop; bindex <= btail; bindex++) {
10193 + h_dentry = au_h_dptr(dentry, bindex);
10196 + h_file = au_hf_dir(file, bindex);
10200 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10201 + err = PTR_ERR(h_file);
10202 + if (IS_ERR(h_file))
10203 + goto out; /* close all? */
10204 + au_set_h_fptr(file, bindex, h_file);
10206 + au_update_figen(file);
10207 + /* todo: necessary? */
10208 + /* file->f_ra = h_file->f_ra; */
10215 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10218 + aufs_bindex_t bindex, btail;
10219 + struct dentry *dentry, *h_dentry;
10220 + struct vfsmount *mnt;
10222 + FiMustWriteLock(file);
10223 + AuDebugOn(h_file);
10226 + mnt = file->f_path.mnt;
10227 + dentry = file->f_path.dentry;
10228 + file->f_version = inode_query_iversion(d_inode(dentry));
10229 + bindex = au_dbtop(dentry);
10230 + au_set_fbtop(file, bindex);
10231 + btail = au_dbtaildir(dentry);
10232 + au_set_fbbot_dir(file, btail);
10233 + for (; !err && bindex <= btail; bindex++) {
10234 + h_dentry = au_h_dptr(dentry, bindex);
10238 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10239 + if (unlikely(err))
10241 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10242 + if (IS_ERR(h_file)) {
10243 + err = PTR_ERR(h_file);
10246 + au_set_h_fptr(file, bindex, h_file);
10248 + au_update_figen(file);
10249 + /* todo: necessary? */
10250 + /* file->f_ra = h_file->f_ra; */
10252 + return 0; /* success */
10255 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10256 + au_set_h_fptr(file, bindex, NULL);
10257 + au_set_fbtop(file, -1);
10258 + au_set_fbbot_dir(file, -1);
10263 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10264 + struct file *file)
10267 + struct super_block *sb;
10268 + struct au_fidir *fidir;
10271 + sb = file->f_path.dentry->d_sb;
10272 + si_read_lock(sb, AuLock_FLUSH);
10273 + fidir = au_fidir_alloc(sb);
10275 + struct au_do_open_args args = {
10276 + .open = do_open_dir,
10279 + err = au_do_open(file, &args);
10280 + if (unlikely(err))
10281 + au_kfree_rcu(fidir);
10283 + si_read_unlock(sb);
10287 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10288 + struct file *file)
10290 + struct au_vdir *vdir_cache;
10291 + struct au_finfo *finfo;
10292 + struct au_fidir *fidir;
10293 + struct au_hfile *hf;
10294 + aufs_bindex_t bindex, bbot;
10296 + finfo = au_fi(file);
10297 + fidir = finfo->fi_hdir;
10299 + au_hbl_del(&finfo->fi_hlist,
10300 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10301 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10303 + au_vdir_free(vdir_cache);
10305 + bindex = finfo->fi_btop;
10306 + if (bindex >= 0) {
10307 + hf = fidir->fd_hfile + bindex;
10309 + * calls fput() instead of filp_close(),
10310 + * since no dnotify or lock for the lower file.
10312 + bbot = fidir->fd_bbot;
10313 + for (; bindex <= bbot; bindex++, hf++)
10315 + au_hfput(hf, /*execed*/0);
10317 + au_kfree_rcu(fidir);
10318 + finfo->fi_hdir = NULL;
10320 + au_finfo_fin(file);
10324 +/* ---------------------------------------------------------------------- */
10326 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10329 + aufs_bindex_t bindex, bbot;
10330 + struct file *h_file;
10333 + bbot = au_fbbot_dir(file);
10334 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10335 + h_file = au_hf_dir(file, bindex);
10337 + err = vfsub_flush(h_file, id);
10342 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10344 + return au_do_flush(file, id, au_do_flush_dir);
10347 +/* ---------------------------------------------------------------------- */
10349 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10352 + aufs_bindex_t bbot, bindex;
10353 + struct inode *inode;
10354 + struct super_block *sb;
10357 + sb = dentry->d_sb;
10358 + inode = d_inode(dentry);
10359 + IMustLock(inode);
10360 + bbot = au_dbbot(dentry);
10361 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10362 + struct path h_path;
10364 + if (au_test_ro(sb, bindex, inode))
10366 + h_path.dentry = au_h_dptr(dentry, bindex);
10367 + if (!h_path.dentry)
10370 + h_path.mnt = au_sbr_mnt(sb, bindex);
10371 + err = vfsub_fsync(NULL, &h_path, datasync);
10377 +static int au_do_fsync_dir(struct file *file, int datasync)
10380 + aufs_bindex_t bbot, bindex;
10381 + struct file *h_file;
10382 + struct super_block *sb;
10383 + struct inode *inode;
10385 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10386 + if (unlikely(err))
10389 + inode = file_inode(file);
10390 + sb = inode->i_sb;
10391 + bbot = au_fbbot_dir(file);
10392 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10393 + h_file = au_hf_dir(file, bindex);
10394 + if (!h_file || au_test_ro(sb, bindex, inode))
10397 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10405 + * @file may be NULL
10407 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10411 + struct dentry *dentry;
10412 + struct inode *inode;
10413 + struct super_block *sb;
10416 + dentry = file->f_path.dentry;
10417 + inode = d_inode(dentry);
10418 + inode_lock(inode);
10419 + sb = dentry->d_sb;
10420 + si_noflush_read_lock(sb);
10422 + err = au_do_fsync_dir(file, datasync);
10424 + di_write_lock_child(dentry);
10425 + err = au_do_fsync_dir_no_file(dentry, datasync);
10427 + au_cpup_attr_timesizes(inode);
10428 + di_write_unlock(dentry);
10430 + fi_write_unlock(file);
10432 + si_read_unlock(sb);
10433 + inode_unlock(inode);
10437 +/* ---------------------------------------------------------------------- */
10439 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10442 + struct dentry *dentry;
10443 + struct inode *inode, *h_inode;
10444 + struct super_block *sb;
10446 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10448 + dentry = file->f_path.dentry;
10449 + inode = d_inode(dentry);
10450 + IMustLock(inode);
10452 + sb = dentry->d_sb;
10453 + si_read_lock(sb, AuLock_FLUSH);
10454 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10455 + if (unlikely(err))
10457 + err = au_alive_dir(dentry);
10459 + err = au_vdir_init(file);
10460 + di_downgrade_lock(dentry, AuLock_IR);
10461 + if (unlikely(err))
10464 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10465 + if (!au_test_nfsd()) {
10466 + err = au_vdir_fill_de(file, ctx);
10467 + fsstack_copy_attr_atime(inode, h_inode);
10470 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10471 + * encode_fh() and others.
10473 + atomic_inc(&h_inode->i_count);
10474 + di_read_unlock(dentry, AuLock_IR);
10475 + si_read_unlock(sb);
10476 + err = au_vdir_fill_de(file, ctx);
10477 + fsstack_copy_attr_atime(inode, h_inode);
10478 + fi_write_unlock(file);
10486 + di_read_unlock(dentry, AuLock_IR);
10487 + fi_write_unlock(file);
10489 + si_read_unlock(sb);
10493 +/* ---------------------------------------------------------------------- */
10495 +#define AuTestEmpty_WHONLY 1
10496 +#define AuTestEmpty_CALLED (1 << 1)
10497 +#define AuTestEmpty_SHWH (1 << 2)
10498 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10499 +#define au_fset_testempty(flags, name) \
10500 + do { (flags) |= AuTestEmpty_##name; } while (0)
10501 +#define au_fclr_testempty(flags, name) \
10502 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10504 +#ifndef CONFIG_AUFS_SHWH
10505 +#undef AuTestEmpty_SHWH
10506 +#define AuTestEmpty_SHWH 0
10509 +struct test_empty_arg {
10510 + struct dir_context ctx;
10511 + struct au_nhash *whlist;
10512 + unsigned int flags;
10514 + aufs_bindex_t bindex;
10517 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10518 + int namelen, loff_t offset __maybe_unused, u64 ino,
10519 + unsigned int d_type)
10521 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10523 + char *name = (void *)__name;
10526 + au_fset_testempty(arg->flags, CALLED);
10528 + if (name[0] == '.'
10529 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10530 + goto out; /* success */
10532 + if (namelen <= AUFS_WH_PFX_LEN
10533 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10534 + if (au_ftest_testempty(arg->flags, WHONLY)
10535 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10536 + arg->err = -ENOTEMPTY;
10540 + name += AUFS_WH_PFX_LEN;
10541 + namelen -= AUFS_WH_PFX_LEN;
10542 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10543 + arg->err = au_nhash_append_wh
10544 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10545 + au_ftest_testempty(arg->flags, SHWH));
10549 + AuTraceErr(arg->err);
10553 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10556 + struct file *h_file;
10557 + struct au_branch *br;
10559 + h_file = au_h_open(dentry, arg->bindex,
10560 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10561 + /*file*/NULL, /*force_wr*/0);
10562 + err = PTR_ERR(h_file);
10563 + if (IS_ERR(h_file))
10567 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10568 + && !file_inode(h_file)->i_nlink)
10573 + au_fclr_testempty(arg->flags, CALLED);
10575 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10578 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10582 + br = au_sbr(dentry->d_sb, arg->bindex);
10583 + au_lcnt_dec(&br->br_nfiles);
10588 +struct do_test_empty_args {
10590 + struct dentry *dentry;
10591 + struct test_empty_arg *arg;
10594 +static void call_do_test_empty(void *args)
10596 + struct do_test_empty_args *a = args;
10597 + *a->errp = do_test_empty(a->dentry, a->arg);
10600 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10602 + int err, wkq_err;
10603 + struct dentry *h_dentry;
10604 + struct inode *h_inode;
10606 + h_dentry = au_h_dptr(dentry, arg->bindex);
10607 + h_inode = d_inode(h_dentry);
10608 + /* todo: i_mode changes anytime? */
10609 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10610 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10611 + inode_unlock_shared(h_inode);
10613 + err = do_test_empty(dentry, arg);
10615 + struct do_test_empty_args args = {
10617 + .dentry = dentry,
10620 + unsigned int flags = arg->flags;
10622 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10623 + if (unlikely(wkq_err))
10625 + arg->flags = flags;
10631 +int au_test_empty_lower(struct dentry *dentry)
10634 + unsigned int rdhash;
10635 + aufs_bindex_t bindex, btop, btail;
10636 + struct au_nhash whlist;
10637 + struct test_empty_arg arg = {
10639 + .actor = test_empty_cb
10642 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10644 + SiMustAnyLock(dentry->d_sb);
10646 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10648 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10649 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10650 + if (unlikely(err))
10654 + arg.whlist = &whlist;
10655 + btop = au_dbtop(dentry);
10656 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10657 + au_fset_testempty(arg.flags, SHWH);
10658 + test_empty = do_test_empty;
10659 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10660 + test_empty = sio_test_empty;
10661 + arg.bindex = btop;
10662 + err = test_empty(dentry, &arg);
10663 + if (unlikely(err))
10666 + au_fset_testempty(arg.flags, WHONLY);
10667 + btail = au_dbtaildir(dentry);
10668 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10669 + struct dentry *h_dentry;
10671 + h_dentry = au_h_dptr(dentry, bindex);
10672 + if (h_dentry && d_is_positive(h_dentry)) {
10673 + arg.bindex = bindex;
10674 + err = test_empty(dentry, &arg);
10679 + au_nhash_wh_free(&whlist);
10684 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10687 + struct test_empty_arg arg = {
10689 + .actor = test_empty_cb
10692 + aufs_bindex_t bindex, btail;
10695 + arg.whlist = whlist;
10696 + arg.flags = AuTestEmpty_WHONLY;
10697 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10698 + au_fset_testempty(arg.flags, SHWH);
10699 + btail = au_dbtaildir(dentry);
10700 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10701 + struct dentry *h_dentry;
10703 + h_dentry = au_h_dptr(dentry, bindex);
10704 + if (h_dentry && d_is_positive(h_dentry)) {
10705 + arg.bindex = bindex;
10706 + err = sio_test_empty(dentry, &arg);
10713 +/* ---------------------------------------------------------------------- */
10715 +const struct file_operations aufs_dir_fop = {
10716 + .owner = THIS_MODULE,
10717 + .llseek = default_llseek,
10718 + .read = generic_read_dir,
10719 + .iterate_shared = aufs_iterate_shared,
10720 + .unlocked_ioctl = aufs_ioctl_dir,
10721 +#ifdef CONFIG_COMPAT
10722 + .compat_ioctl = aufs_compat_ioctl_dir,
10724 + .open = aufs_open_dir,
10725 + .release = aufs_release_dir,
10726 + .flush = aufs_flush_dir,
10727 + .fsync = aufs_fsync_dir
10729 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10730 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10731 +++ linux/fs/aufs/dir.h 2021-02-22 22:51:59.058078584 +0100
10733 +/* SPDX-License-Identifier: GPL-2.0 */
10735 + * Copyright (C) 2005-2020 Junjiro R. Okajima
10737 + * This program, aufs is free software; you can redistribute it and/or modify
10738 + * it under the terms of the GNU General Public License as published by
10739 + * the Free Software Foundation; either version 2 of the License, or
10740 + * (at your option) any later version.
10742 + * This program is distributed in the hope that it will be useful,
10743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10745 + * GNU General Public License for more details.
10747 + * You should have received a copy of the GNU General Public License
10748 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10752 + * directory operations
10755 +#ifndef __AUFS_DIR_H__
10756 +#define __AUFS_DIR_H__
10760 +#include <linux/fs.h>
10762 +/* ---------------------------------------------------------------------- */
10764 +/* need to be faster and smaller */
10767 + unsigned int nh_num;
10768 + struct hlist_head *nh_head;
10771 +struct au_vdir_destr {
10772 + unsigned char len;
10773 + unsigned char name[];
10776 +struct au_vdir_dehstr {
10777 + struct hlist_node hash;
10778 + struct au_vdir_destr *str;
10779 + struct rcu_head rcu;
10780 +} ____cacheline_aligned_in_smp;
10782 +struct au_vdir_de {
10784 + unsigned char de_type;
10785 + /* caution: packed */
10786 + struct au_vdir_destr de_str;
10789 +struct au_vdir_wh {
10790 + struct hlist_node wh_hash;
10791 +#ifdef CONFIG_AUFS_SHWH
10793 + aufs_bindex_t wh_bindex;
10794 + unsigned char wh_type;
10796 + aufs_bindex_t wh_bindex;
10798 + /* caution: packed */
10799 + struct au_vdir_destr wh_str;
10802 +union au_vdir_deblk_p {
10803 + unsigned char *deblk;
10804 + struct au_vdir_de *de;
10808 + unsigned char **vd_deblk;
10809 + unsigned long vd_nblk;
10811 + unsigned long ul;
10812 + union au_vdir_deblk_p p;
10816 + unsigned int vd_deblk_sz;
10817 + unsigned long vd_jiffy;
10818 + struct rcu_head rcu;
10819 +} ____cacheline_aligned_in_smp;
10821 +/* ---------------------------------------------------------------------- */
10824 +extern const struct file_operations aufs_dir_fop;
10825 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10826 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10827 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10828 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10829 +int au_test_empty_lower(struct dentry *dentry);
10830 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10833 +unsigned int au_rdhash_est(loff_t sz);
10834 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10835 +void au_nhash_wh_free(struct au_nhash *whlist);
10836 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10838 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10839 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10840 + unsigned int d_type, aufs_bindex_t bindex,
10841 + unsigned char shwh);
10842 +void au_vdir_free(struct au_vdir *vdir);
10843 +int au_vdir_init(struct file *file);
10844 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10847 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10849 +#ifdef CONFIG_AUFS_RDU
10851 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10852 +#ifdef CONFIG_COMPAT
10853 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10854 + unsigned long arg);
10857 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10858 + unsigned int cmd, unsigned long arg)
10859 +#ifdef CONFIG_COMPAT
10860 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10861 + unsigned int cmd, unsigned long arg)
10865 +#endif /* __KERNEL__ */
10866 +#endif /* __AUFS_DIR_H__ */
10867 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10868 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10869 +++ linux/fs/aufs/dirren.c 2021-02-22 22:51:59.058078584 +0100
10871 +// SPDX-License-Identifier: GPL-2.0
10873 + * Copyright (C) 2017-2020 Junjiro R. Okajima
10875 + * This program, aufs is free software; you can redistribute it and/or modify
10876 + * it under the terms of the GNU General Public License as published by
10877 + * the Free Software Foundation; either version 2 of the License, or
10878 + * (at your option) any later version.
10880 + * This program is distributed in the hope that it will be useful,
10881 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10882 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10883 + * GNU General Public License for more details.
10885 + * You should have received a copy of the GNU General Public License
10886 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10890 + * special handling in renaming a directory
10891 + * in order to support looking-up the before-renamed name on the lower readonly
10895 +#include <linux/byteorder/generic.h>
10898 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10902 + idx = au_dr_ihash(ent->dr_h_ino);
10903 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10906 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10909 + struct hlist_bl_head *hbl;
10912 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10913 + hbl = dr->dr_h_ino + i;
10914 + hlist_bl_lock(hbl);
10915 + ret &= hlist_bl_empty(hbl);
10916 + hlist_bl_unlock(hbl);
10922 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10924 + struct au_dr_hino *found, *ent;
10925 + struct hlist_bl_head *hbl;
10926 + struct hlist_bl_node *pos;
10930 + idx = au_dr_ihash(ino);
10931 + hbl = dr->dr_h_ino + idx;
10932 + hlist_bl_lock(hbl);
10933 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10934 + if (ent->dr_h_ino == ino) {
10938 + hlist_bl_unlock(hbl);
10943 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10944 + struct au_dr_hino *add_ent)
10947 + struct hlist_bl_head *hbl;
10948 + struct hlist_bl_node *pos;
10949 + struct au_dr_hino *ent;
10952 + idx = au_dr_ihash(ino);
10953 + hbl = dr->dr_h_ino + idx;
10954 +#if 0 /* debug print */
10956 + struct hlist_bl_node *tmp;
10958 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10959 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10962 + hlist_bl_lock(hbl);
10963 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10964 + if (ent->dr_h_ino == ino) {
10968 + if (!found && add_ent)
10969 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10970 + hlist_bl_unlock(hbl);
10972 + if (!found && add_ent)
10973 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10978 +void au_dr_hino_free(struct au_dr_br *dr)
10981 + struct hlist_bl_head *hbl;
10982 + struct hlist_bl_node *pos, *tmp;
10983 + struct au_dr_hino *ent;
10985 + /* SiMustWriteLock(sb); */
10987 + for (i = 0; i < AuDirren_NHASH; i++) {
10988 + hbl = dr->dr_h_ino + i;
10989 + /* no spinlock since sbinfo must be write-locked */
10990 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10991 + au_kfree_rcu(ent);
10992 + INIT_HLIST_BL_HEAD(hbl);
10996 +/* returns the number of inodes or an error */
10997 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10998 + struct file *hinofile)
11002 + loff_t pos, oldsize;
11004 + struct inode *hinoinode;
11005 + struct hlist_bl_head *hbl;
11006 + struct hlist_bl_node *n1, *n2;
11007 + struct au_dr_hino *ent;
11009 + SiMustWriteLock(sb);
11010 + AuDebugOn(!au_br_writable(br->br_perm));
11012 + hinoinode = file_inode(hinofile);
11013 + oldsize = i_size_read(hinoinode);
11017 + hbl = br->br_dirren.dr_h_ino;
11018 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11019 + /* no bit-lock since sbinfo must be write-locked */
11020 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11021 + AuDbg("hi%llu, %pD2\n",
11022 + (unsigned long long)ent->dr_h_ino, hinofile);
11023 + u64 = cpu_to_be64(ent->dr_h_ino);
11024 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11025 + if (ssz == sizeof(u64))
11028 + /* write error */
11029 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11036 + /* regardless the error */
11037 + if (pos < oldsize) {
11038 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11046 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11053 + struct au_dr_hino *ent;
11054 + struct inode *hinoinode;
11055 + struct hlist_bl_head *hbl;
11059 + hbl = dr->dr_h_ino;
11060 + hinoinode = file_inode(hinofile);
11061 + sz = i_size_read(hinoinode);
11062 + AuDebugOn(sz % sizeof(u64));
11063 + n = sz / sizeof(u64);
11065 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11066 + if (unlikely(ssz != sizeof(u64))) {
11067 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11074 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11080 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11081 + AuDbg("hi%llu, %pD2\n",
11082 + (unsigned long long)ent->dr_h_ino, hinofile);
11083 + hidx = au_dr_ihash(ent->dr_h_ino);
11084 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11086 + goto out; /* success */
11089 + au_dr_hino_free(dr);
11096 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11097 + * @path is a switch to distinguish load and store.
11099 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11100 + struct au_branch *br, const struct path *path)
11103 + unsigned char load, suspend;
11104 + struct file *hinofile;
11105 + struct au_hinode *hdir;
11106 + struct inode *dir, *delegated;
11107 + struct path hinopath;
11108 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11109 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11111 + AuDebugOn(bindex < 0 && !br);
11112 + AuDebugOn(bindex >= 0 && br);
11117 + br = au_sbr(sb, bindex);
11120 + path = &br->br_path;
11121 + AuDebugOn(!au_br_writable(br->br_perm));
11122 + if (unlikely(!au_br_writable(br->br_perm)))
11128 + dir = d_inode(sb->s_root);
11129 + hdir = au_hinode(au_ii(dir), bindex);
11130 + dir = hdir->hi_inode;
11131 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11133 + dir = d_inode(path->dentry);
11134 + inode_lock_nested(dir, AuLsc_I_CHILD);
11136 + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry);
11137 + err = PTR_ERR(hinopath.dentry);
11138 + if (IS_ERR(hinopath.dentry))
11142 + flags = O_RDONLY;
11144 + if (d_is_negative(hinopath.dentry))
11145 + goto out_dput; /* success */
11147 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11148 + if (d_is_positive(hinopath.dentry)) {
11149 + delegated = NULL;
11150 + err = vfsub_unlink(dir, &hinopath, &delegated,
11153 + if (unlikely(err))
11154 + pr_err("ignored err %d, %pd2\n",
11155 + err, hinopath.dentry);
11156 + if (unlikely(err == -EWOULDBLOCK))
11161 + } else if (!d_is_positive(hinopath.dentry)) {
11162 + err = vfsub_create(dir, &hinopath, 0600,
11163 + /*want_excl*/false);
11165 + if (unlikely(err))
11168 + flags = O_WRONLY;
11170 + hinopath.mnt = path->mnt;
11171 + hinofile = vfsub_dentry_open(&hinopath, flags);
11173 + au_hn_inode_unlock(hdir);
11175 + inode_unlock(dir);
11176 + dput(hinopath.dentry);
11177 + AuTraceErrPtr(hinofile);
11178 + if (IS_ERR(hinofile)) {
11179 + err = PTR_ERR(hinofile);
11184 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11186 + err = au_dr_hino_store(sb, br, hinofile);
11191 + dput(hinopath.dentry);
11194 + au_hn_inode_unlock(hdir);
11196 + inode_unlock(dir);
11202 +/* ---------------------------------------------------------------------- */
11204 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11207 + struct kstatfs kstfs;
11209 + struct dentry *dentry;
11210 + struct super_block *sb;
11212 + err = vfs_statfs((void *)path, &kstfs);
11214 + if (unlikely(err))
11217 + /* todo: support for UUID */
11219 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11220 + brid->type = AuBrid_FSID;
11221 + brid->fsid = kstfs.f_fsid;
11223 + dentry = path->dentry;
11224 + sb = dentry->d_sb;
11227 + brid->type = AuBrid_DEV;
11236 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11237 + const struct path *path)
11240 + struct au_dr_br *dr;
11241 + struct hlist_bl_head *hbl;
11243 + dr = &br->br_dirren;
11244 + hbl = dr->dr_h_ino;
11245 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11246 + INIT_HLIST_BL_HEAD(hbl);
11248 + err = au_dr_brid_init(&dr->dr_brid, path);
11249 + if (unlikely(err))
11252 + if (au_opt_test(au_mntflags(sb), DIRREN))
11253 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11260 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11265 + if (au_br_writable(br->br_perm))
11266 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11268 + au_dr_hino_free(&br->br_dirren);
11273 +/* ---------------------------------------------------------------------- */
11275 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11276 + char *buf, size_t sz)
11279 + unsigned int major, minor;
11283 + err = snprintf(p, sz, "%d_", brid->type);
11284 + AuDebugOn(err > sz);
11287 + switch (brid->type) {
11288 + case AuBrid_Unset:
11290 + case AuBrid_UUID:
11291 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11293 + case AuBrid_FSID:
11294 + err = snprintf(p, sz, "%08x-%08x",
11295 + brid->fsid.val[0], brid->fsid.val[1]);
11298 + major = MAJOR(brid->dev);
11299 + minor = MINOR(brid->dev);
11300 + if (major <= 0xff && minor <= 0xff)
11301 + err = snprintf(p, sz, "%02x%02x", major, minor);
11303 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11306 + AuDebugOn(err > sz);
11309 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11310 + AuDebugOn(err > sz);
11317 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11320 + struct dentry *br_dentry;
11321 + struct inode *br_inode;
11323 + br_dentry = au_br_dentry(br);
11324 + br_inode = d_inode(br_dentry);
11325 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11326 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11327 + AuDebugOn(rlen > len);
11332 +/* ---------------------------------------------------------------------- */
11335 + * from the given @h_dentry, construct drinfo at @*fdata.
11336 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11339 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11340 + struct dentry *h_dentry,
11341 + unsigned char *allocated)
11344 + struct au_drinfo_fdata *f, *p;
11345 + struct au_drinfo *drinfo;
11346 + struct inode *h_inode;
11347 + struct qstr *qname;
11351 + h_inode = d_inode(h_dentry);
11352 + qname = &h_dentry->d_name;
11353 + drinfo = &f->drinfo;
11354 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11355 + drinfo->oldnamelen = qname->len;
11356 + if (*allocated < sizeof(*f) + qname->len) {
11357 + v = roundup_pow_of_two(*allocated + qname->len);
11358 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11359 + if (unlikely(!p)) {
11367 + drinfo = &f->drinfo;
11369 + memcpy(drinfo->oldname, qname->name, qname->len);
11370 + AuDbg("i%llu, %.*s\n",
11371 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11372 + drinfo->oldname);
11379 +/* callers have to free the return value */
11380 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11382 + struct au_drinfo *ret, *drinfo;
11383 + struct au_drinfo_fdata fdata;
11388 + ret = ERR_PTR(-EIO);
11390 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11391 + if (unlikely(ssz != sizeof(fdata))) {
11392 + AuIOErr("ssz %zd, %u, %pD2\n",
11393 + ssz, (unsigned int)sizeof(fdata), file);
11397 + fdata.magic = ntohl((__force __be32)fdata.magic);
11398 + switch (fdata.magic) {
11399 + case AUFS_DRINFO_MAGIC_V1:
11402 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11403 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11407 + drinfo = &fdata.drinfo;
11408 + len = drinfo->oldnamelen;
11410 + AuIOErr("broken drinfo %pD2\n", file);
11415 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11416 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11417 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11418 + (unsigned long long)drinfo->ino,
11419 + (unsigned long long)h_ino, file);
11420 + goto out; /* success */
11423 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11424 + if (unlikely(!ret)) {
11425 + ret = ERR_PTR(-ENOMEM);
11426 + AuTraceErrPtr(ret);
11431 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11432 + if (unlikely(ssz != len)) {
11433 + au_kfree_rcu(ret);
11434 + ret = ERR_PTR(-EIO);
11435 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11439 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11445 +/* ---------------------------------------------------------------------- */
11447 +/* in order to be revertible */
11448 +struct au_drinfo_rev_elm {
11450 + struct dentry *info_dentry;
11451 + struct au_drinfo *info_last;
11454 +struct au_drinfo_rev {
11455 + unsigned char already;
11456 + aufs_bindex_t nelm;
11457 + struct au_drinfo_rev_elm elm[];
11460 +/* todo: isn't it too large? */
11461 +struct au_drinfo_store {
11462 + struct path h_ppath;
11463 + struct dentry *h_dentry;
11464 + struct au_drinfo_fdata *fdata;
11465 + char *infoname; /* inside of whname, just after PFX */
11466 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11467 + aufs_bindex_t btgt, btail;
11468 + unsigned char no_sio,
11469 + allocated, /* current size of *fdata */
11470 + infonamelen, /* room size for p */
11471 + whnamelen, /* length of the generated name */
11472 + renameback; /* renamed back */
11475 +/* on rename(2) error, the caller should revert it using @elm */
11476 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11477 + struct au_drinfo_rev_elm *elm)
11482 + struct path infopath = {
11483 + .mnt = w->h_ppath.mnt
11485 + struct inode *h_dir, *h_inode, *delegated;
11486 + struct file *infofile;
11487 + struct qstr *qname;
11490 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11492 + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry,
11494 + AuTraceErrPtr(infopath.dentry);
11495 + if (IS_ERR(infopath.dentry)) {
11496 + err = PTR_ERR(infopath.dentry);
11501 + h_dir = d_inode(w->h_ppath.dentry);
11502 + if (elm && d_is_negative(infopath.dentry)) {
11503 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11505 + if (unlikely(err))
11507 + elm->created = 1;
11508 + elm->info_dentry = dget(infopath.dentry);
11511 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11512 + AuTraceErrPtr(infofile);
11513 + if (IS_ERR(infofile)) {
11514 + err = PTR_ERR(infofile);
11518 + h_inode = d_inode(infopath.dentry);
11519 + if (elm && i_size_read(h_inode)) {
11520 + h_inode = d_inode(w->h_dentry);
11521 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11522 + AuTraceErrPtr(elm->info_last);
11523 + if (IS_ERR(elm->info_last)) {
11524 + err = PTR_ERR(elm->info_last);
11525 + elm->info_last = NULL;
11526 + AuDebugOn(elm->info_dentry);
11531 + if (elm && w->renameback) {
11532 + delegated = NULL;
11533 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11535 + if (unlikely(err == -EWOULDBLOCK))
11541 + qname = &w->h_dentry->d_name;
11542 + len = sizeof(*w->fdata) + qname->len;
11544 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11545 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11546 + if (ssz == len) {
11547 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11548 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11549 + goto out_fput; /* success */
11554 + /* the caller should revert it using @elm */
11560 + dput(infopath.dentry);
11566 +struct au_call_drinfo_do_store_args {
11568 + struct au_drinfo_store *w;
11569 + struct au_drinfo_rev_elm *elm;
11572 +static void au_call_drinfo_do_store(void *args)
11574 + struct au_call_drinfo_do_store_args *a = args;
11576 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11579 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11580 + struct au_drinfo_rev_elm *elm)
11582 + int err, wkq_err;
11585 + err = au_drinfo_do_store(w, elm);
11587 + struct au_call_drinfo_do_store_args a = {
11592 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11593 + if (unlikely(wkq_err))
11601 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11602 + aufs_bindex_t btgt)
11606 + memset(w, 0, sizeof(*w));
11607 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11608 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11609 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11610 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11612 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11615 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11616 + if (unlikely(!w->fdata)) {
11620 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11627 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11629 + au_kfree_rcu(w->fdata);
11632 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11633 + struct au_drinfo_store *w)
11635 + struct au_drinfo_rev_elm *elm;
11636 + struct inode *h_dir, *delegated;
11638 + struct path infopath = {
11639 + .mnt = w->h_ppath.mnt
11642 + h_dir = d_inode(w->h_ppath.dentry);
11643 + IMustLock(h_dir);
11647 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11648 + AuDebugOn(elm->created && elm->info_last);
11649 + if (elm->created) {
11651 + delegated = NULL;
11652 + infopath.dentry = elm->info_dentry;
11653 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11656 + if (unlikely(err == -EWOULDBLOCK))
11658 + dput(elm->info_dentry);
11659 + } else if (elm->info_last) {
11661 + w->fdata->drinfo = *elm->info_last;
11662 + memcpy(w->fdata->drinfo.oldname,
11663 + elm->info_last->oldname,
11664 + elm->info_last->oldnamelen);
11665 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11666 + au_kfree_rcu(elm->info_last);
11668 + if (unlikely(err))
11669 + AuIOErr("%d, %s\n", err, w->whname);
11670 + /* go on even if err */
11674 +/* caller has to call au_dr_rename_fin() later */
11675 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11676 + struct qstr *dst_name, void *_rev)
11678 + int err, sz, nelm;
11679 + aufs_bindex_t bindex, btail;
11680 + struct au_drinfo_store work;
11681 + struct au_drinfo_rev *rev, **p;
11682 + struct au_drinfo_rev_elm *elm;
11683 + struct super_block *sb;
11684 + struct au_branch *br;
11685 + struct au_hinode *hdir;
11687 + err = au_drinfo_store_work_init(&work, btgt);
11689 + if (unlikely(err))
11693 + btail = au_dbtaildir(dentry);
11694 + nelm = btail - btgt;
11695 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11696 + rev = kcalloc(1, sz, GFP_NOFS);
11697 + if (unlikely(!rev)) {
11701 + rev->nelm = nelm;
11707 + sb = dentry->d_sb;
11708 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11709 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11710 + hdir = au_hi(d_inode(dentry), btgt);
11711 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11712 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11713 + work.h_dentry = au_h_dptr(dentry, bindex);
11714 + if (!work.h_dentry)
11717 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11718 + &work.allocated);
11720 + if (unlikely(err))
11723 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11724 + br = au_sbr(sb, bindex);
11725 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11726 + work.whnamelen += au_drinfo_name(br, work.infoname,
11727 + work.infonamelen);
11728 + AuDbg("whname %.*s, i%llu, %.*s\n",
11729 + work.whnamelen, work.whname,
11730 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11731 + work.fdata->drinfo.oldnamelen,
11732 + work.fdata->drinfo.oldname);
11734 + err = au_drinfo_store_sio(&work, elm);
11736 + if (unlikely(err))
11739 + if (unlikely(err)) {
11740 + /* revert all drinfo */
11741 + au_drinfo_store_rev(rev, &work);
11742 + au_kfree_try_rcu(rev);
11745 + au_hn_inode_unlock(hdir);
11748 + au_drinfo_store_work_fin(&work);
11753 +/* ---------------------------------------------------------------------- */
11755 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11756 + struct qstr *dst_name, void *_rev)
11758 + int err, already;
11760 + struct super_block *sb;
11761 + struct au_branch *br;
11762 + struct au_dr_br *dr;
11763 + struct dentry *h_dentry;
11764 + struct inode *h_inode;
11765 + struct au_dr_hino *ent;
11766 + struct au_drinfo_rev *rev, **p;
11768 + AuDbg("bindex %d\n", bindex);
11771 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11772 + if (unlikely(!ent))
11776 + br = au_sbr(sb, bindex);
11777 + dr = &br->br_dirren;
11778 + h_dentry = au_h_dptr(src, bindex);
11779 + h_inode = d_inode(h_dentry);
11780 + ino = h_inode->i_ino;
11781 + ent->dr_h_ino = ino;
11782 + already = au_dr_hino_test_add(dr, ino, ent);
11783 + AuDbg("b%d, hi%llu, already %d\n",
11784 + bindex, (unsigned long long)ino, already);
11786 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11791 + rev->already = already;
11792 + goto out; /* success */
11797 + au_dr_hino_del(dr, ent);
11798 + au_kfree_rcu(ent);
11805 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11807 + struct au_drinfo_rev *rev;
11808 + struct au_drinfo_rev_elm *elm;
11813 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11814 + dput(elm->info_dentry);
11815 + au_kfree_rcu(elm->info_last);
11817 + au_kfree_try_rcu(rev);
11820 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11823 + struct au_drinfo_store work;
11824 + struct au_drinfo_rev *rev = _rev;
11825 + struct super_block *sb;
11826 + struct au_branch *br;
11827 + struct inode *h_inode;
11828 + struct au_dr_br *dr;
11829 + struct au_dr_hino *ent;
11831 + err = au_drinfo_store_work_init(&work, btgt);
11832 + if (unlikely(err))
11836 + br = au_sbr(sb, btgt);
11837 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11838 + work.h_ppath.mnt = au_br_mnt(br);
11839 + au_drinfo_store_rev(rev, &work);
11840 + au_drinfo_store_work_fin(&work);
11841 + if (rev->already)
11844 + dr = &br->br_dirren;
11845 + h_inode = d_inode(work.h_ppath.dentry);
11846 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11848 + au_dr_hino_del(dr, ent);
11849 + au_kfree_rcu(ent);
11852 + au_kfree_try_rcu(rev);
11853 + if (unlikely(err))
11854 + pr_err("failed to remove dirren info\n");
11857 +/* ---------------------------------------------------------------------- */
11859 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11860 + char *whname, int whnamelen,
11861 + struct dentry **info_dentry)
11863 + struct au_drinfo *drinfo;
11865 + struct inode *h_dir;
11866 + struct path infopath;
11869 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11871 + *info_dentry = NULL;
11874 + h_dir = d_inode(h_ppath->dentry);
11875 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11876 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry,
11878 + if (IS_ERR(infopath.dentry)) {
11879 + drinfo = (void *)infopath.dentry;
11883 + if (d_is_negative(infopath.dentry))
11884 + goto out_dput; /* success */
11886 + infopath.mnt = h_ppath->mnt;
11887 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11888 + inode_unlock_shared(h_dir);
11891 + drinfo = (void *)f;
11895 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11896 + if (IS_ERR_OR_NULL(drinfo))
11899 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11900 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11905 + dput(infopath.dentry);
11908 + inode_unlock_shared(h_dir);
11909 + AuTraceErrPtr(drinfo);
11913 +struct au_drinfo_do_load_args {
11914 + struct au_drinfo **drinfop;
11915 + struct path *h_ppath;
11918 + struct dentry **info_dentry;
11921 +static void au_call_drinfo_do_load(void *args)
11923 + struct au_drinfo_do_load_args *a = args;
11925 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11929 +struct au_drinfo_load {
11930 + struct path h_ppath;
11931 + struct qstr *qname;
11932 + unsigned char no_sio;
11934 + aufs_bindex_t ninfo;
11935 + struct au_drinfo **drinfo;
11938 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11939 + struct au_branch *br)
11941 + int err, wkq_err, whnamelen, e;
11942 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11943 + = AUFS_WH_DR_INFO_PFX;
11944 + struct au_drinfo *drinfo;
11945 + struct qstr oldname;
11946 + struct inode *h_dir, *delegated;
11947 + struct dentry *info_dentry;
11948 + struct path infopath;
11950 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11951 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11952 + sizeof(whname) - whnamelen);
11954 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11957 + struct au_drinfo_do_load_args args = {
11958 + .drinfop = &drinfo,
11959 + .h_ppath = &w->h_ppath,
11960 + .whname = whname,
11961 + .whnamelen = whnamelen,
11962 + .info_dentry = &info_dentry
11964 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11965 + if (unlikely(wkq_err))
11966 + drinfo = ERR_PTR(wkq_err);
11968 + err = PTR_ERR(drinfo);
11969 + if (IS_ERR_OR_NULL(drinfo))
11973 + oldname.len = drinfo->oldnamelen;
11974 + oldname.name = drinfo->oldname;
11975 + if (au_qstreq(w->qname, &oldname)) {
11976 + /* the name is renamed back */
11977 + au_kfree_rcu(drinfo);
11980 + infopath.dentry = info_dentry;
11981 + infopath.mnt = w->h_ppath.mnt;
11982 + h_dir = d_inode(w->h_ppath.dentry);
11983 + delegated = NULL;
11984 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11985 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11986 + inode_unlock(h_dir);
11988 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11989 + if (unlikely(e == -EWOULDBLOCK))
11992 + au_kfree_rcu(w->drinfo[bindex]);
11993 + w->drinfo[bindex] = drinfo;
11994 + dput(info_dentry);
12001 +/* ---------------------------------------------------------------------- */
12003 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12005 + struct au_drinfo **p = drinfo;
12008 + au_kfree_rcu(*drinfo++);
12009 + au_kfree_try_rcu(p);
12012 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12013 + aufs_bindex_t btgt)
12016 + struct au_drinfo_load w;
12017 + aufs_bindex_t bindex, bbot;
12018 + struct au_branch *br;
12019 + struct inode *h_dir;
12020 + struct au_dr_hino *ent;
12021 + struct super_block *sb;
12023 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12024 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12025 + AuLNPair(&lkup->whname), btgt);
12027 + sb = dentry->d_sb;
12028 + bbot = au_sbbot(sb);
12029 + w.ninfo = bbot + 1;
12030 + if (!lkup->dirren.drinfo) {
12031 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12032 + sizeof(*lkup->dirren.drinfo),
12034 + if (unlikely(!lkup->dirren.drinfo)) {
12038 + lkup->dirren.ninfo = w.ninfo;
12040 + w.drinfo = lkup->dirren.drinfo;
12041 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12042 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12043 + AuDebugOn(!w.h_ppath.dentry);
12044 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12045 + w.qname = &dentry->d_name;
12048 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12049 + br = au_sbr(sb, bindex);
12050 + err = au_drinfo_load(&w, bindex, br);
12051 + if (unlikely(err))
12053 + if (w.drinfo[bindex])
12057 + br = au_sbr(sb, btgt);
12058 + h_dir = d_inode(w.h_ppath.dentry);
12059 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12061 + au_dr_hino_del(&br->br_dirren, ent);
12062 + au_kfree_rcu(ent);
12064 + goto out; /* success */
12067 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12068 + lkup->dirren.ninfo = 0;
12069 + lkup->dirren.drinfo = NULL;
12075 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12077 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12080 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12083 + struct au_drinfo *drinfo;
12086 + if (!lkup->dirren.drinfo)
12088 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12089 + drinfo = lkup->dirren.drinfo[btgt];
12093 + au_kfree_try_rcu(lkup->whname.name);
12094 + lkup->whname.name = NULL;
12095 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12096 + lkup->dirren.dr_name.name = drinfo->oldname;
12097 + lkup->name = &lkup->dirren.dr_name;
12098 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12100 + AuDbg("name %.*s, whname %.*s, b%d\n",
12101 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12109 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12113 + struct au_drinfo *drinfo;
12116 + if (!lkup->dirren.drinfo)
12118 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12119 + drinfo = lkup->dirren.drinfo[bindex];
12123 + match = (drinfo->ino == h_ino);
12124 + AuDbg("match %d\n", match);
12130 +/* ---------------------------------------------------------------------- */
12132 +int au_dr_opt_set(struct super_block *sb)
12135 + aufs_bindex_t bindex, bbot;
12136 + struct au_branch *br;
12139 + bbot = au_sbbot(sb);
12140 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12141 + br = au_sbr(sb, bindex);
12142 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12148 +int au_dr_opt_flush(struct super_block *sb)
12151 + aufs_bindex_t bindex, bbot;
12152 + struct au_branch *br;
12155 + bbot = au_sbbot(sb);
12156 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12157 + br = au_sbr(sb, bindex);
12158 + if (au_br_writable(br->br_perm))
12159 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12165 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12168 + aufs_bindex_t bindex, bbot;
12169 + struct au_branch *br;
12173 + err = au_dr_opt_flush(sb);
12174 + if (unlikely(err))
12178 + bbot = au_sbbot(sb);
12179 + for (bindex = 0; bindex <= bbot; bindex++) {
12180 + br = au_sbr(sb, bindex);
12181 + au_dr_hino_free(&br->br_dirren);
12187 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12188 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12189 +++ linux/fs/aufs/dirren.h 2021-02-22 22:51:59.058078584 +0100
12191 +/* SPDX-License-Identifier: GPL-2.0 */
12193 + * Copyright (C) 2017-2020 Junjiro R. Okajima
12195 + * This program, aufs is free software; you can redistribute it and/or modify
12196 + * it under the terms of the GNU General Public License as published by
12197 + * the Free Software Foundation; either version 2 of the License, or
12198 + * (at your option) any later version.
12200 + * This program is distributed in the hope that it will be useful,
12201 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12202 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12203 + * GNU General Public License for more details.
12205 + * You should have received a copy of the GNU General Public License
12206 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12210 + * renamed dir info
12213 +#ifndef __AUFS_DIRREN_H__
12214 +#define __AUFS_DIRREN_H__
12218 +#include <linux/dcache.h>
12219 +#include <linux/statfs.h>
12220 +#include <linux/uuid.h>
12223 +#define AuDirren_NHASH 100
12225 +#ifdef CONFIG_AUFS_DIRREN
12226 +enum au_brid_type {
12233 +struct au_dr_brid {
12234 + enum au_brid_type type;
12236 + uuid_t uuid; /* unimplemented yet */
12242 +/* 20 is the max digits length of ulong 64 */
12243 +/* brid-type "_" uuid "_" inum */
12244 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12245 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12247 +struct au_dr_hino {
12248 + struct hlist_bl_node dr_hnode;
12253 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12254 + struct au_dr_brid dr_brid;
12257 +struct au_dr_lookup {
12258 + /* dr_name is pointed by struct au_do_lookup_args.name */
12259 + struct qstr dr_name; /* subset of dr_info */
12260 + aufs_bindex_t ninfo;
12261 + struct au_drinfo **drinfo;
12264 +struct au_dr_hino;
12266 +struct au_dr_br { };
12267 +struct au_dr_lookup { };
12270 +/* ---------------------------------------------------------------------- */
12273 +struct au_do_lookup_args;
12275 +#ifdef CONFIG_AUFS_DIRREN
12276 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12277 + struct au_dr_hino *add_ent);
12278 +void au_dr_hino_free(struct au_dr_br *dr);
12279 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12280 + const struct path *path);
12281 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12282 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12283 + struct qstr *dst_name, void *_rev);
12284 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12285 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12286 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12287 + aufs_bindex_t bindex);
12288 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12289 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12291 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12292 +int au_dr_opt_set(struct super_block *sb);
12293 +int au_dr_opt_flush(struct super_block *sb);
12294 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12296 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12297 + struct au_dr_hino *add_ent);
12298 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12299 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12300 + const struct path *path);
12301 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12302 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12303 + struct qstr *dst_name, void *_rev);
12304 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12305 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12307 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12308 + aufs_bindex_t bindex);
12309 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12310 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12311 + aufs_bindex_t bindex, ino_t h_ino);
12312 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12313 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12314 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12315 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12318 +/* ---------------------------------------------------------------------- */
12320 +#ifdef CONFIG_AUFS_DIRREN
12321 +static inline int au_dr_ihash(ino_t h_ino)
12323 + return h_ino % AuDirren_NHASH;
12326 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12329 +#endif /* __KERNEL__ */
12330 +#endif /* __AUFS_DIRREN_H__ */
12331 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12332 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12333 +++ linux/fs/aufs/dynop.c 2021-02-22 22:51:59.058078584 +0100
12335 +// SPDX-License-Identifier: GPL-2.0
12337 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12339 + * This program, aufs is free software; you can redistribute it and/or modify
12340 + * it under the terms of the GNU General Public License as published by
12341 + * the Free Software Foundation; either version 2 of the License, or
12342 + * (at your option) any later version.
12344 + * This program is distributed in the hope that it will be useful,
12345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12347 + * GNU General Public License for more details.
12349 + * You should have received a copy of the GNU General Public License
12350 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12354 + * dynamically customizable operations for regular files
12359 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12362 + * How large will these lists be?
12363 + * Usually just a few elements, 20-30 at most for each, I guess.
12365 +static struct hlist_bl_head dynop[AuDyLast];
12367 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12368 + const void *h_op)
12370 + struct au_dykey *key, *tmp;
12371 + struct hlist_bl_node *pos;
12374 + hlist_bl_lock(hbl);
12375 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12376 + if (tmp->dk_op.dy_hop == h_op) {
12377 + if (kref_get_unless_zero(&tmp->dk_kref))
12381 + hlist_bl_unlock(hbl);
12386 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12388 + struct au_dykey **k, *found;
12389 + const void *h_op = key->dk_op.dy_hop;
12393 + k = br->br_dykey;
12394 + for (i = 0; i < AuBrDynOp; i++)
12396 + if (k[i]->dk_op.dy_hop == h_op) {
12403 + spin_lock(&br->br_dykey_lock);
12404 + for (; i < AuBrDynOp; i++)
12406 + if (k[i]->dk_op.dy_hop == h_op) {
12414 + spin_unlock(&br->br_dykey_lock);
12415 + BUG_ON(i == AuBrDynOp); /* expand the array */
12421 +/* kref_get() if @key is already added */
12422 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12424 + struct au_dykey *tmp, *found;
12425 + struct hlist_bl_node *pos;
12426 + const void *h_op = key->dk_op.dy_hop;
12429 + hlist_bl_lock(hbl);
12430 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12431 + if (tmp->dk_op.dy_hop == h_op) {
12432 + if (kref_get_unless_zero(&tmp->dk_kref))
12437 + hlist_bl_add_head(&key->dk_hnode, hbl);
12438 + hlist_bl_unlock(hbl);
12445 +static void dy_free_rcu(struct rcu_head *rcu)
12447 + struct au_dykey *key;
12449 + key = container_of(rcu, struct au_dykey, dk_rcu);
12454 +static void dy_free(struct kref *kref)
12456 + struct au_dykey *key;
12457 + struct hlist_bl_head *hbl;
12459 + key = container_of(kref, struct au_dykey, dk_kref);
12460 + hbl = dynop + key->dk_op.dy_type;
12461 + au_hbl_del(&key->dk_hnode, hbl);
12462 + call_rcu(&key->dk_rcu, dy_free_rcu);
12465 +void au_dy_put(struct au_dykey *key)
12467 + kref_put(&key->dk_kref, dy_free);
12470 +/* ---------------------------------------------------------------------- */
12472 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12474 +#ifdef CONFIG_AUFS_DEBUG
12475 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12476 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12478 +#define DyDbgDeclare(cnt) do {} while (0)
12479 +#define DyDbgInc(cnt) do {} while (0)
12482 +#define DySet(func, dst, src, h_op, h_sb) do { \
12484 + if (h_op->func) { \
12486 + dst.func = src.func; \
12488 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12492 +#define DySetForce(func, dst, src) do { \
12493 + AuDebugOn(!src.func); \
12495 + dst.func = src.func; \
12498 +#define DySetAop(func) \
12499 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12500 +#define DySetAopForce(func) \
12501 + DySetForce(func, dyaop->da_op, aufs_aop)
12503 +static void dy_aop(struct au_dykey *key, const void *h_op,
12504 + struct super_block *h_sb __maybe_unused)
12506 + struct au_dyaop *dyaop = (void *)key;
12507 + const struct address_space_operations *h_aop = h_op;
12508 + DyDbgDeclare(cnt);
12510 + AuDbg("%s\n", au_sbtype(h_sb));
12512 + DySetAop(writepage);
12513 + DySetAopForce(readpage); /* force */
12514 + DySetAop(writepages);
12515 + DySetAop(set_page_dirty);
12516 + DySetAop(readpages);
12517 + DySetAop(readahead);
12518 + DySetAop(write_begin);
12519 + DySetAop(write_end);
12521 + DySetAop(invalidatepage);
12522 + DySetAop(releasepage);
12523 + DySetAop(freepage);
12524 + /* this one will be changed according to an aufs mount option */
12525 + DySetAop(direct_IO);
12526 + DySetAop(migratepage);
12527 + DySetAop(isolate_page);
12528 + DySetAop(putback_page);
12529 + DySetAop(launder_page);
12530 + DySetAop(is_partially_uptodate);
12531 + DySetAop(is_dirty_writeback);
12532 + DySetAop(error_remove_page);
12533 + DySetAop(swap_activate);
12534 + DySetAop(swap_deactivate);
12536 + DyDbgSize(cnt, *h_aop);
12539 +/* ---------------------------------------------------------------------- */
12541 +static void dy_bug(struct kref *kref)
12546 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12548 + struct au_dykey *key, *old;
12549 + struct hlist_bl_head *hbl;
12552 + void (*set)(struct au_dykey *key, const void *h_op,
12553 + struct super_block *h_sb __maybe_unused);
12555 + static const struct op a[] = {
12557 + .sz = sizeof(struct au_dyaop),
12561 + const struct op *p;
12563 + hbl = dynop + op->dy_type;
12564 + key = dy_gfind_get(hbl, op->dy_hop);
12566 + goto out_add; /* success */
12568 + p = a + op->dy_type;
12569 + key = kzalloc(p->sz, GFP_NOFS);
12570 + if (unlikely(!key)) {
12571 + key = ERR_PTR(-ENOMEM);
12575 + key->dk_op.dy_hop = op->dy_hop;
12576 + kref_init(&key->dk_kref);
12577 + p->set(key, op->dy_hop, au_br_sb(br));
12578 + old = dy_gadd(hbl, key);
12580 + au_kfree_rcu(key);
12585 + old = dy_bradd(br, key);
12587 + /* its ref-count should never be zero here */
12588 + kref_put(&key->dk_kref, dy_bug);
12593 +/* ---------------------------------------------------------------------- */
12595 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12596 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12597 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12598 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12599 + * See the aufs manual in detail.
12601 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12604 + dyaop->da_op.direct_IO = NULL;
12606 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12609 +static struct au_dyaop *dy_aget(struct au_branch *br,
12610 + const struct address_space_operations *h_aop,
12613 + struct au_dyaop *dyaop;
12614 + struct au_dynop op;
12616 + op.dy_type = AuDy_AOP;
12617 + op.dy_haop = h_aop;
12618 + dyaop = (void *)dy_get(&op, br);
12619 + if (IS_ERR(dyaop))
12621 + dy_adx(dyaop, do_dx);
12627 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12628 + struct inode *h_inode)
12631 + struct super_block *sb;
12632 + struct au_branch *br;
12633 + struct au_dyaop *dyaop;
12635 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12636 + IiMustWriteLock(inode);
12638 + sb = inode->i_sb;
12639 + br = au_sbr(sb, bindex);
12640 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12641 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12642 + err = PTR_ERR(dyaop);
12643 + if (IS_ERR(dyaop))
12644 + /* unnecessary to call dy_fput() */
12648 + inode->i_mapping->a_ops = &dyaop->da_op;
12655 + * Is it safe to replace a_ops during the inode/file is in operation?
12656 + * Yes, I hope so.
12658 +int au_dy_irefresh(struct inode *inode)
12661 + aufs_bindex_t btop;
12662 + struct inode *h_inode;
12665 + if (S_ISREG(inode->i_mode)) {
12666 + btop = au_ibtop(inode);
12667 + h_inode = au_h_iptr(inode, btop);
12668 + err = au_dy_iaop(inode, btop, h_inode);
12673 +void au_dy_arefresh(int do_dx)
12675 + struct hlist_bl_head *hbl;
12676 + struct hlist_bl_node *pos;
12677 + struct au_dykey *key;
12679 + hbl = dynop + AuDy_AOP;
12680 + hlist_bl_lock(hbl);
12681 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12682 + dy_adx((void *)key, do_dx);
12683 + hlist_bl_unlock(hbl);
12686 +/* ---------------------------------------------------------------------- */
12688 +void __init au_dy_init(void)
12692 + for (i = 0; i < AuDyLast; i++)
12693 + INIT_HLIST_BL_HEAD(dynop + i);
12696 +void au_dy_fin(void)
12700 + for (i = 0; i < AuDyLast; i++)
12701 + WARN_ON(!hlist_bl_empty(dynop + i));
12703 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12704 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12705 +++ linux/fs/aufs/dynop.h 2021-02-22 22:51:59.058078584 +0100
12707 +/* SPDX-License-Identifier: GPL-2.0 */
12709 + * Copyright (C) 2010-2020 Junjiro R. Okajima
12711 + * This program, aufs is free software; you can redistribute it and/or modify
12712 + * it under the terms of the GNU General Public License as published by
12713 + * the Free Software Foundation; either version 2 of the License, or
12714 + * (at your option) any later version.
12716 + * This program is distributed in the hope that it will be useful,
12717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12719 + * GNU General Public License for more details.
12721 + * You should have received a copy of the GNU General Public License
12722 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12726 + * dynamically customizable operations (for regular files only)
12729 +#ifndef __AUFS_DYNOP_H__
12730 +#define __AUFS_DYNOP_H__
12734 +#include <linux/fs.h>
12735 +#include <linux/kref.h>
12737 +enum {AuDy_AOP, AuDyLast};
12742 + const void *dy_hop;
12743 + const struct address_space_operations *dy_haop;
12749 + struct hlist_bl_node dk_hnode;
12750 + struct rcu_head dk_rcu;
12752 + struct au_dynop dk_op;
12755 + * during I am in the branch local array, kref is gotten. when the
12756 + * branch is removed, kref is put.
12758 + struct kref dk_kref;
12761 +/* stop unioning since their sizes are very different from each other */
12763 + struct au_dykey da_key;
12764 + struct address_space_operations da_op; /* not const */
12766 +/* make sure that 'struct au_dykey *' can be any type */
12767 +static_assert(!offsetof(struct au_dyaop, da_key));
12769 +/* ---------------------------------------------------------------------- */
12773 +void au_dy_put(struct au_dykey *key);
12774 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12775 + struct inode *h_inode);
12776 +int au_dy_irefresh(struct inode *inode);
12777 +void au_dy_arefresh(int do_dio);
12779 +void __init au_dy_init(void);
12780 +void au_dy_fin(void);
12782 +#endif /* __KERNEL__ */
12783 +#endif /* __AUFS_DYNOP_H__ */
12784 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12785 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12786 +++ linux/fs/aufs/export.c 2021-02-22 22:51:59.058078584 +0100
12788 +// SPDX-License-Identifier: GPL-2.0
12790 + * Copyright (C) 2005-2020 Junjiro R. Okajima
12792 + * This program, aufs is free software; you can redistribute it and/or modify
12793 + * it under the terms of the GNU General Public License as published by
12794 + * the Free Software Foundation; either version 2 of the License, or
12795 + * (at your option) any later version.
12797 + * This program is distributed in the hope that it will be useful,
12798 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12799 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12800 + * GNU General Public License for more details.
12802 + * You should have received a copy of the GNU General Public License
12803 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12810 +#include <linux/exportfs.h>
12811 +#include <linux/fs_struct.h>
12812 +#include <linux/namei.h>
12813 +#include <linux/nsproxy.h>
12814 +#include <linux/random.h>
12815 +#include <linux/writeback.h>
12819 +#ifdef CONFIG_AUFS_INO_T_64
12827 +static ino_t decode_ino(__u32 *a)
12831 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12833 +#ifdef CONFIG_AUFS_INO_T_64
12839 +static void encode_ino(__u32 *a, ino_t ino)
12845 +#ifdef CONFIG_AUFS_INO_T_64
12850 +/* NFS file handle */
12854 +#ifdef CONFIG_AUFS_INO_T_64
12855 + /* support 64bit inode number */
12868 + Fh_ino = Fh_ino1,
12869 + Fh_dir_ino = Fh_dir_ino1
12872 +static int au_test_anon(struct dentry *dentry)
12874 + /* note: read d_flags without d_lock */
12875 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12878 +int au_test_nfsd(void)
12881 + struct task_struct *tsk = current;
12882 + char comm[sizeof(tsk->comm)];
12885 + if (tsk->flags & PF_KTHREAD) {
12886 + get_task_comm(comm, tsk);
12887 + ret = !strcmp(comm, "nfsd");
12893 +/* ---------------------------------------------------------------------- */
12894 +/* inode generation external table */
12896 +void au_xigen_inc(struct inode *inode)
12901 + struct super_block *sb;
12902 + struct au_sbinfo *sbinfo;
12904 + sb = inode->i_sb;
12905 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12907 + sbinfo = au_sbi(sb);
12908 + pos = inode->i_ino;
12909 + pos *= sizeof(igen);
12910 + igen = inode->i_generation + 1;
12911 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12912 + if (sz == sizeof(igen))
12913 + return; /* success */
12915 + if (unlikely(sz >= 0))
12916 + AuIOErr("xigen error (%zd)\n", sz);
12919 +int au_xigen_new(struct inode *inode)
12924 + struct super_block *sb;
12925 + struct au_sbinfo *sbinfo;
12926 + struct file *file;
12929 + /* todo: dirty, at mount time */
12930 + if (inode->i_ino == AUFS_ROOT_INO)
12932 + sb = inode->i_sb;
12933 + SiMustAnyLock(sb);
12934 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12938 + pos = inode->i_ino;
12939 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12940 + AuIOErr1("too large i%lld\n", pos);
12943 + pos *= sizeof(inode->i_generation);
12946 + sbinfo = au_sbi(sb);
12947 + file = sbinfo->si_xigen;
12950 + if (vfsub_f_size_read(file)
12951 + < pos + sizeof(inode->i_generation)) {
12952 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12953 + sz = xino_fwrite(file, &inode->i_generation,
12954 + sizeof(inode->i_generation), &pos);
12956 + sz = xino_fread(file, &inode->i_generation,
12957 + sizeof(inode->i_generation), &pos);
12958 + if (sz == sizeof(inode->i_generation))
12959 + goto out; /* success */
12962 + if (unlikely(sz >= 0)) {
12964 + AuIOErr("xigen error (%zd)\n", sz);
12971 +int au_xigen_set(struct super_block *sb, struct path *path)
12974 + struct au_sbinfo *sbinfo;
12975 + struct file *file;
12977 + SiMustWriteLock(sb);
12979 + sbinfo = au_sbi(sb);
12980 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12981 + err = PTR_ERR(file);
12982 + if (IS_ERR(file))
12985 + if (sbinfo->si_xigen)
12986 + fput(sbinfo->si_xigen);
12987 + sbinfo->si_xigen = file;
12994 +void au_xigen_clr(struct super_block *sb)
12996 + struct au_sbinfo *sbinfo;
12998 + SiMustWriteLock(sb);
13000 + sbinfo = au_sbi(sb);
13001 + if (sbinfo->si_xigen) {
13002 + fput(sbinfo->si_xigen);
13003 + sbinfo->si_xigen = NULL;
13007 +/* ---------------------------------------------------------------------- */
13009 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13012 + struct dentry *dentry, *d;
13013 + struct inode *inode;
13014 + unsigned int sigen;
13017 + inode = ilookup(sb, ino);
13021 + dentry = ERR_PTR(-ESTALE);
13022 + sigen = au_sigen(sb);
13023 + if (unlikely(au_is_bad_inode(inode)
13024 + || IS_DEADDIR(inode)
13025 + || sigen != au_iigen(inode, NULL)))
13029 + if (!dir_ino || S_ISDIR(inode->i_mode))
13030 + dentry = d_find_alias(inode);
13032 + spin_lock(&inode->i_lock);
13033 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13034 + spin_lock(&d->d_lock);
13035 + if (!au_test_anon(d)
13036 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13037 + dentry = dget_dlock(d);
13038 + spin_unlock(&d->d_lock);
13041 + spin_unlock(&d->d_lock);
13043 + spin_unlock(&inode->i_lock);
13045 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13046 + /* need to refresh */
13054 + AuTraceErrPtr(dentry);
13058 +/* ---------------------------------------------------------------------- */
13060 +/* todo: dirty? */
13061 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13063 +struct au_compare_mnt_args {
13065 + struct super_block *sb;
13068 + struct vfsmount *mnt;
13071 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13073 + struct au_compare_mnt_args *a = arg;
13075 + if (mnt->mnt_sb != a->sb)
13077 + a->mnt = mntget(mnt);
13081 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13084 + struct path root;
13085 + struct au_compare_mnt_args args = {
13089 + get_fs_root(current->fs, &root);
13091 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13092 + rcu_read_unlock();
13095 + AuDebugOn(!args.mnt);
13099 +struct au_nfsd_si_lock {
13100 + unsigned int sigen;
13101 + aufs_bindex_t bindex, br_id;
13102 + unsigned char force_lock;
13105 +static int si_nfsd_read_lock(struct super_block *sb,
13106 + struct au_nfsd_si_lock *nsi_lock)
13109 + aufs_bindex_t bindex;
13111 + si_read_lock(sb, AuLock_FLUSH);
13113 + /* branch id may be wrapped around */
13115 + bindex = au_br_index(sb, nsi_lock->br_id);
13116 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13117 + goto out; /* success */
13121 + if (!nsi_lock->force_lock)
13122 + si_read_unlock(sb);
13125 + nsi_lock->bindex = bindex;
13129 +struct find_name_by_ino {
13130 + struct dir_context ctx;
13131 + int called, found;
13138 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13139 + loff_t offset, u64 ino, unsigned int d_type)
13141 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13145 + if (a->ino != ino)
13148 + memcpy(a->name, name, namelen);
13149 + a->namelen = namelen;
13154 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13155 + struct au_nfsd_si_lock *nsi_lock)
13157 + struct dentry *dentry, *parent;
13158 + struct file *file;
13159 + struct inode *dir;
13160 + struct find_name_by_ino arg = {
13162 + .actor = find_name_by_ino
13167 + parent = path->dentry;
13169 + si_read_unlock(parent->d_sb);
13170 + file = vfsub_dentry_open(path, au_dir_roflags);
13171 + dentry = (void *)file;
13172 + if (IS_ERR(file))
13175 + dentry = ERR_PTR(-ENOMEM);
13176 + arg.name = (void *)__get_free_page(GFP_NOFS);
13177 + if (unlikely(!arg.name))
13184 + err = vfsub_iterate_dir(file, &arg.ctx);
13185 + } while (!err && !arg.found && arg.called);
13186 + dentry = ERR_PTR(err);
13187 + if (unlikely(err))
13189 + /* instead of ENOENT */
13190 + dentry = ERR_PTR(-ESTALE);
13194 + /* do not call vfsub_lkup_one() */
13195 + dir = d_inode(parent);
13196 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
13197 + AuTraceErrPtr(dentry);
13198 + if (IS_ERR(dentry))
13200 + AuDebugOn(au_test_anon(dentry));
13201 + if (unlikely(d_really_is_negative(dentry))) {
13203 + dentry = ERR_PTR(-ENOENT);
13207 + free_page((unsigned long)arg.name);
13211 + if (unlikely(nsi_lock
13212 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13213 + if (!IS_ERR(dentry)) {
13215 + dentry = ERR_PTR(-ESTALE);
13217 + AuTraceErrPtr(dentry);
13221 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13223 + struct au_nfsd_si_lock *nsi_lock)
13225 + struct dentry *dentry;
13226 + struct path path;
13228 + if (dir_ino != AUFS_ROOT_INO) {
13229 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13230 + dentry = path.dentry;
13231 + if (!path.dentry || IS_ERR(path.dentry))
13233 + AuDebugOn(au_test_anon(path.dentry));
13235 + path.dentry = dget(sb->s_root);
13237 + path.mnt = au_mnt_get(sb);
13238 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13242 + AuTraceErrPtr(dentry);
13246 +/* ---------------------------------------------------------------------- */
13248 +static int h_acceptable(void *expv, struct dentry *dentry)
13253 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13254 + char *buf, int len, struct super_block *sb)
13258 + struct path path;
13260 + p = d_path(h_rootpath, buf, len);
13265 + path.mnt = h_rootpath->mnt;
13266 + path.dentry = h_parent;
13267 + p = d_path(&path, buf, len);
13273 + path.mnt = au_mnt_get(sb);
13274 + path.dentry = sb->s_root;
13275 + p = d_path(&path, buf, len - strlen(p));
13276 + mntput(path.mnt);
13280 + p[strlen(p)] = '/';
13283 + AuTraceErrPtr(p);
13288 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13289 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13291 + struct dentry *dentry, *h_parent, *root;
13292 + struct super_block *h_sb;
13293 + char *pathname, *p;
13294 + struct vfsmount *h_mnt;
13295 + struct au_branch *br;
13297 + struct path path;
13299 + br = au_sbr(sb, nsi_lock->bindex);
13300 + h_mnt = au_br_mnt(br);
13301 + h_sb = h_mnt->mnt_sb;
13302 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13304 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13305 + fh_len - Fh_tail, fh[Fh_h_type],
13306 + h_acceptable, /*context*/NULL);
13308 + dentry = h_parent;
13309 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13310 + AuWarn1("%s decode_fh failed, %ld\n",
13311 + au_sbtype(h_sb), PTR_ERR(h_parent));
13315 + if (unlikely(au_test_anon(h_parent))) {
13316 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13317 + au_sbtype(h_sb));
13318 + goto out_h_parent;
13321 + dentry = ERR_PTR(-ENOMEM);
13322 + pathname = (void *)__get_free_page(GFP_NOFS);
13323 + if (unlikely(!pathname))
13324 + goto out_h_parent;
13326 + root = sb->s_root;
13327 + path.mnt = h_mnt;
13328 + di_read_lock_parent(root, !AuLock_IR);
13329 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13330 + di_read_unlock(root, !AuLock_IR);
13331 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13332 + dentry = (void *)p;
13334 + goto out_pathname;
13336 + si_read_unlock(sb);
13337 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13338 + dentry = ERR_PTR(err);
13339 + if (unlikely(err))
13342 + dentry = ERR_PTR(-ENOENT);
13343 + AuDebugOn(au_test_anon(path.dentry));
13344 + if (unlikely(d_really_is_negative(path.dentry)))
13347 + if (ino != d_inode(path.dentry)->i_ino)
13348 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13350 + dentry = dget(path.dentry);
13355 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13356 + if (!IS_ERR(dentry)) {
13358 + dentry = ERR_PTR(-ESTALE);
13361 + free_page((unsigned long)pathname);
13365 + AuTraceErrPtr(dentry);
13369 +/* ---------------------------------------------------------------------- */
13371 +static struct dentry *
13372 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13375 + struct dentry *dentry;
13376 + __u32 *fh = fid->raw;
13377 + struct au_branch *br;
13378 + ino_t ino, dir_ino;
13379 + struct au_nfsd_si_lock nsi_lock = {
13383 + dentry = ERR_PTR(-ESTALE);
13384 + /* it should never happen, but the file handle is unreliable */
13385 + if (unlikely(fh_len < Fh_tail))
13387 + nsi_lock.sigen = fh[Fh_sigen];
13388 + nsi_lock.br_id = fh[Fh_br_id];
13390 + /* branch id may be wrapped around */
13392 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13394 + nsi_lock.force_lock = 1;
13396 + /* is this inode still cached? */
13397 + ino = decode_ino(fh + Fh_ino);
13398 + /* it should never happen */
13399 + if (unlikely(ino == AUFS_ROOT_INO))
13402 + dir_ino = decode_ino(fh + Fh_dir_ino);
13403 + dentry = decode_by_ino(sb, ino, dir_ino);
13404 + if (IS_ERR(dentry))
13409 + /* is the parent dir cached? */
13410 + br = au_sbr(sb, nsi_lock.bindex);
13411 + au_lcnt_inc(&br->br_nfiles);
13412 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13413 + if (IS_ERR(dentry))
13418 + /* lookup path */
13419 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13420 + if (IS_ERR(dentry))
13422 + if (unlikely(!dentry))
13423 + /* todo?: make it ESTALE */
13427 + if (!au_digen_test(dentry, au_sigen(sb))
13428 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13429 + goto out_unlock; /* success */
13432 + dentry = ERR_PTR(-ESTALE);
13435 + au_lcnt_dec(&br->br_nfiles);
13436 + si_read_unlock(sb);
13438 + AuTraceErrPtr(dentry);
13442 +#if 0 /* reserved for future use */
13443 +/* support subtreecheck option */
13444 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13445 + int fh_len, int fh_type)
13447 + struct dentry *parent;
13448 + __u32 *fh = fid->raw;
13451 + dir_ino = decode_ino(fh + Fh_dir_ino);
13452 + parent = decode_by_ino(sb, dir_ino, 0);
13453 + if (IS_ERR(parent))
13456 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13457 + dir_ino, fh, fh_len);
13460 + AuTraceErrPtr(parent);
13465 +/* ---------------------------------------------------------------------- */
13467 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13468 + struct inode *dir)
13471 + aufs_bindex_t bindex;
13472 + struct super_block *sb, *h_sb;
13473 + struct dentry *dentry, *parent, *h_parent;
13474 + struct inode *h_dir;
13475 + struct au_branch *br;
13478 + if (unlikely(*max_len <= Fh_tail)) {
13479 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13483 + err = FILEID_ROOT;
13484 + if (inode->i_ino == AUFS_ROOT_INO) {
13485 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13490 + sb = inode->i_sb;
13491 + err = si_read_lock(sb, AuLock_FLUSH);
13492 + if (unlikely(err))
13495 +#ifdef CONFIG_AUFS_DEBUG
13496 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13497 + AuWarn1("NFS-exporting requires xino\n");
13501 + ii_read_lock_child(inode);
13502 + bindex = au_ibtop(inode);
13504 + dentry = d_find_any_alias(inode);
13505 + if (unlikely(!dentry))
13507 + AuDebugOn(au_test_anon(dentry));
13508 + parent = dget_parent(dentry);
13510 + if (unlikely(!parent))
13512 + if (d_really_is_positive(parent))
13513 + dir = d_inode(parent);
13516 + ii_read_lock_parent(dir);
13517 + h_dir = au_h_iptr(dir, bindex);
13518 + ii_read_unlock(dir);
13519 + if (unlikely(!h_dir))
13521 + h_parent = d_find_any_alias(h_dir);
13522 + if (unlikely(!h_parent))
13523 + goto out_hparent;
13526 + br = au_sbr(sb, bindex);
13527 + h_sb = au_br_sb(br);
13528 + if (unlikely(!h_sb->s_export_op)) {
13529 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13530 + goto out_hparent;
13533 + fh[Fh_br_id] = br->br_id;
13534 + fh[Fh_sigen] = au_sigen(sb);
13535 + encode_ino(fh + Fh_ino, inode->i_ino);
13536 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13537 + fh[Fh_igen] = inode->i_generation;
13539 + *max_len -= Fh_tail;
13540 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13542 + /*connectable or subtreecheck*/0);
13543 + err = fh[Fh_h_type];
13544 + *max_len += Fh_tail;
13545 + /* todo: macros? */
13546 + if (err != FILEID_INVALID)
13549 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13556 + ii_read_unlock(inode);
13557 + si_read_unlock(sb);
13559 + if (unlikely(err < 0))
13560 + err = FILEID_INVALID;
13564 +/* ---------------------------------------------------------------------- */
13566 +static int aufs_commit_metadata(struct inode *inode)
13569 + aufs_bindex_t bindex;
13570 + struct super_block *sb;
13571 + struct inode *h_inode;
13572 + int (*f)(struct inode *inode);
13574 + sb = inode->i_sb;
13575 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13576 + ii_write_lock_child(inode);
13577 + bindex = au_ibtop(inode);
13578 + AuDebugOn(bindex < 0);
13579 + h_inode = au_h_iptr(inode, bindex);
13581 + f = h_inode->i_sb->s_export_op->commit_metadata;
13583 + err = f(h_inode);
13585 + struct writeback_control wbc = {
13586 + .sync_mode = WB_SYNC_ALL,
13587 + .nr_to_write = 0 /* metadata only */
13590 + err = sync_inode(h_inode, &wbc);
13593 + au_cpup_attr_timesizes(inode);
13594 + ii_write_unlock(inode);
13595 + si_read_unlock(sb);
13599 +/* ---------------------------------------------------------------------- */
13601 +static struct export_operations aufs_export_op = {
13602 + .fh_to_dentry = aufs_fh_to_dentry,
13603 + /* .fh_to_parent = aufs_fh_to_parent, */
13604 + .encode_fh = aufs_encode_fh,
13605 + .commit_metadata = aufs_commit_metadata
13608 +void au_export_init(struct super_block *sb)
13610 + struct au_sbinfo *sbinfo;
13613 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13614 + && IS_MODULE(CONFIG_EXPORTFS),
13615 + AUFS_NAME ": unsupported configuration "
13616 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13618 + sb->s_export_op = &aufs_export_op;
13619 + sbinfo = au_sbi(sb);
13620 + sbinfo->si_xigen = NULL;
13621 + get_random_bytes(&u, sizeof(u));
13622 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13623 + atomic_set(&sbinfo->si_xigen_next, u);
13625 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13626 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13627 +++ linux/fs/aufs/fhsm.c 2021-02-22 22:51:59.058078584 +0100
13629 +// SPDX-License-Identifier: GPL-2.0
13631 + * Copyright (C) 2011-2020 Junjiro R. Okajima
13633 + * This program, aufs is free software; you can redistribute it and/or modify
13634 + * it under the terms of the GNU General Public License as published by
13635 + * the Free Software Foundation; either version 2 of the License, or
13636 + * (at your option) any later version.
13638 + * This program is distributed in the hope that it will be useful,
13639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13641 + * GNU General Public License for more details.
13643 + * You should have received a copy of the GNU General Public License
13644 + * along with this program; if not, write to the Free Software
13645 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13649 + * File-based Hierarchy Storage Management
13652 +#include <linux/anon_inodes.h>
13653 +#include <linux/poll.h>
13654 +#include <linux/seq_file.h>
13655 +#include <linux/statfs.h>
13658 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13660 + struct au_sbinfo *sbinfo;
13661 + struct au_fhsm *fhsm;
13663 + SiMustAnyLock(sb);
13665 + sbinfo = au_sbi(sb);
13666 + fhsm = &sbinfo->si_fhsm;
13667 + AuDebugOn(!fhsm);
13668 + return fhsm->fhsm_bottom;
13671 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13673 + struct au_sbinfo *sbinfo;
13674 + struct au_fhsm *fhsm;
13676 + SiMustWriteLock(sb);
13678 + sbinfo = au_sbi(sb);
13679 + fhsm = &sbinfo->si_fhsm;
13680 + AuDebugOn(!fhsm);
13681 + fhsm->fhsm_bottom = bindex;
13684 +/* ---------------------------------------------------------------------- */
13686 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13688 + struct au_br_fhsm *bf;
13690 + bf = br->br_fhsm;
13691 + MtxMustLock(&bf->bf_lock);
13693 + return !bf->bf_readable
13694 + || time_after(jiffies,
13695 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13698 +/* ---------------------------------------------------------------------- */
13700 +static void au_fhsm_notify(struct super_block *sb, int val)
13702 + struct au_sbinfo *sbinfo;
13703 + struct au_fhsm *fhsm;
13705 + SiMustAnyLock(sb);
13707 + sbinfo = au_sbi(sb);
13708 + fhsm = &sbinfo->si_fhsm;
13709 + if (au_fhsm_pid(fhsm)
13710 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13711 + atomic_set(&fhsm->fhsm_readable, val);
13713 + wake_up(&fhsm->fhsm_wqh);
13717 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13718 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13721 + struct au_branch *br;
13722 + struct au_br_fhsm *bf;
13724 + br = au_sbr(sb, bindex);
13725 + AuDebugOn(au_br_rdonly(br));
13726 + bf = br->br_fhsm;
13730 + mutex_lock(&bf->bf_lock);
13732 + MtxMustLock(&bf->bf_lock);
13734 + /* sb->s_root for NFS is unreliable */
13735 + err = au_br_stfs(br, &bf->bf_stfs);
13736 + if (unlikely(err)) {
13737 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13741 + bf->bf_jiffy = jiffies;
13742 + bf->bf_readable = 1;
13744 + au_fhsm_notify(sb, /*val*/1);
13746 + *rstfs = bf->bf_stfs;
13750 + mutex_unlock(&bf->bf_lock);
13751 + au_fhsm_notify(sb, /*val*/1);
13756 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13759 + struct au_sbinfo *sbinfo;
13760 + struct au_fhsm *fhsm;
13761 + struct au_branch *br;
13762 + struct au_br_fhsm *bf;
13764 + AuDbg("b%d, force %d\n", bindex, force);
13765 + SiMustAnyLock(sb);
13767 + sbinfo = au_sbi(sb);
13768 + fhsm = &sbinfo->si_fhsm;
13769 + if (!au_ftest_si(sbinfo, FHSM)
13770 + || fhsm->fhsm_bottom == bindex)
13773 + br = au_sbr(sb, bindex);
13774 + bf = br->br_fhsm;
13776 + mutex_lock(&bf->bf_lock);
13778 + || au_fhsm_pid(fhsm)
13779 + || au_fhsm_test_jiffy(sbinfo, br))
13780 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13782 + mutex_unlock(&bf->bf_lock);
13785 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13787 + aufs_bindex_t bindex, bbot;
13788 + struct au_branch *br;
13790 + /* exclude the bottom */
13791 + bbot = au_fhsm_bottom(sb);
13792 + for (bindex = 0; bindex < bbot; bindex++) {
13793 + br = au_sbr(sb, bindex);
13794 + if (au_br_fhsm(br->br_perm))
13795 + au_fhsm_wrote(sb, bindex, force);
13799 +/* ---------------------------------------------------------------------- */
13801 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13804 + struct au_sbinfo *sbinfo;
13805 + struct au_fhsm *fhsm;
13808 + sbinfo = file->private_data;
13809 + fhsm = &sbinfo->si_fhsm;
13810 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13811 + if (atomic_read(&fhsm->fhsm_readable))
13812 + mask = EPOLLIN /* | EPOLLRDNORM */;
13815 + AuDbg("mask 0x%x\n", mask);
13819 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13820 + struct aufs_stfs *stfs, __s16 brid)
13824 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13826 + err = __put_user(brid, &stbr->brid);
13827 + if (unlikely(err))
13833 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13834 + struct aufs_stbr __user *stbr, size_t count)
13838 + aufs_bindex_t bindex, bbot;
13839 + struct au_branch *br;
13840 + struct au_br_fhsm *bf;
13842 + /* except the bottom branch */
13845 + bbot = au_fhsm_bottom(sb);
13846 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13847 + br = au_sbr(sb, bindex);
13848 + if (!au_br_fhsm(br->br_perm))
13851 + bf = br->br_fhsm;
13852 + mutex_lock(&bf->bf_lock);
13853 + if (bf->bf_readable) {
13855 + if (count >= sizeof(*stbr))
13856 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13859 + bf->bf_readable = 0;
13860 + count -= sizeof(*stbr);
13864 + mutex_unlock(&bf->bf_lock);
13867 + err = sizeof(*stbr) * nstbr;
13872 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13877 + aufs_bindex_t nfhsm, bindex, bbot;
13878 + struct au_sbinfo *sbinfo;
13879 + struct au_fhsm *fhsm;
13880 + struct au_branch *br;
13881 + struct super_block *sb;
13884 + sbinfo = file->private_data;
13885 + fhsm = &sbinfo->si_fhsm;
13887 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13888 + if (!atomic_read(&fhsm->fhsm_readable)) {
13889 + if (vfsub_file_flags(file) & O_NONBLOCK)
13892 + err = wait_event_interruptible_locked_irq
13894 + atomic_read(&fhsm->fhsm_readable));
13896 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13897 + if (unlikely(err))
13900 + /* sb may already be dead */
13901 + au_rw_read_lock(&sbinfo->si_rwsem);
13902 + readable = atomic_read(&fhsm->fhsm_readable);
13903 + if (readable > 0) {
13904 + sb = sbinfo->si_sb;
13906 + /* exclude the bottom branch */
13908 + bbot = au_fhsm_bottom(sb);
13909 + for (bindex = 0; bindex < bbot; bindex++) {
13910 + br = au_sbr(sb, bindex);
13911 + if (au_br_fhsm(br->br_perm))
13915 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13916 + atomic_set(&fhsm->fhsm_readable, 0);
13917 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13921 + au_rw_read_unlock(&sbinfo->si_rwsem);
13929 +static int au_fhsm_release(struct inode *inode, struct file *file)
13931 + struct au_sbinfo *sbinfo;
13932 + struct au_fhsm *fhsm;
13934 + /* sb may already be dead */
13935 + sbinfo = file->private_data;
13936 + fhsm = &sbinfo->si_fhsm;
13937 + spin_lock(&fhsm->fhsm_spin);
13938 + fhsm->fhsm_pid = 0;
13939 + spin_unlock(&fhsm->fhsm_spin);
13940 + kobject_put(&sbinfo->si_kobj);
13945 +static const struct file_operations au_fhsm_fops = {
13946 + .owner = THIS_MODULE,
13947 + .llseek = noop_llseek,
13948 + .read = au_fhsm_read,
13949 + .poll = au_fhsm_poll,
13950 + .release = au_fhsm_release
13953 +int au_fhsm_fd(struct super_block *sb, int oflags)
13956 + struct au_sbinfo *sbinfo;
13957 + struct au_fhsm *fhsm;
13960 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13964 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13968 + sbinfo = au_sbi(sb);
13969 + fhsm = &sbinfo->si_fhsm;
13970 + spin_lock(&fhsm->fhsm_spin);
13971 + if (!fhsm->fhsm_pid)
13972 + fhsm->fhsm_pid = current->pid;
13975 + spin_unlock(&fhsm->fhsm_spin);
13976 + if (unlikely(err))
13979 + oflags |= O_RDONLY;
13980 + /* oflags |= FMODE_NONOTIFY; */
13981 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13983 + if (unlikely(fd < 0))
13986 + /* succeed regardless 'fhsm' status */
13987 + kobject_get(&sbinfo->si_kobj);
13988 + si_noflush_read_lock(sb);
13989 + if (au_ftest_si(sbinfo, FHSM))
13990 + au_fhsm_wrote_all(sb, /*force*/0);
13991 + si_read_unlock(sb);
13992 + goto out; /* success */
13995 + spin_lock(&fhsm->fhsm_spin);
13996 + fhsm->fhsm_pid = 0;
13997 + spin_unlock(&fhsm->fhsm_spin);
14003 +/* ---------------------------------------------------------------------- */
14005 +int au_fhsm_br_alloc(struct au_branch *br)
14010 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14012 + au_br_fhsm_init(br->br_fhsm);
14019 +/* ---------------------------------------------------------------------- */
14021 +void au_fhsm_fin(struct super_block *sb)
14023 + au_fhsm_notify(sb, /*val*/-1);
14026 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14028 + struct au_fhsm *fhsm;
14030 + fhsm = &sbinfo->si_fhsm;
14031 + spin_lock_init(&fhsm->fhsm_spin);
14032 + init_waitqueue_head(&fhsm->fhsm_wqh);
14033 + atomic_set(&fhsm->fhsm_readable, 0);
14034 + fhsm->fhsm_expire
14035 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14036 + fhsm->fhsm_bottom = -1;
14039 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14041 + sbinfo->si_fhsm.fhsm_expire
14042 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14045 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14049 + if (!au_ftest_si(sbinfo, FHSM))
14052 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14053 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14054 + seq_printf(seq, ",fhsm_sec=%u", u);
14056 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14057 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14058 +++ linux/fs/aufs/file.c 2021-02-22 22:51:59.058078584 +0100
14060 +// SPDX-License-Identifier: GPL-2.0
14062 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14064 + * This program, aufs is free software; you can redistribute it and/or modify
14065 + * it under the terms of the GNU General Public License as published by
14066 + * the Free Software Foundation; either version 2 of the License, or
14067 + * (at your option) any later version.
14069 + * This program is distributed in the hope that it will be useful,
14070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14072 + * GNU General Public License for more details.
14074 + * You should have received a copy of the GNU General Public License
14075 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14079 + * handling file/dir, and address_space operation
14082 +#ifdef CONFIG_AUFS_DEBUG
14083 +#include <linux/migrate.h>
14085 +#include <linux/pagemap.h>
14088 +/* drop flags for writing */
14089 +unsigned int au_file_roflags(unsigned int flags)
14091 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14092 + flags |= O_RDONLY | O_NOATIME;
14096 +/* common functions to regular file and dir */
14097 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14098 + struct file *file, int force_wr)
14100 + struct file *h_file;
14101 + struct dentry *h_dentry;
14102 + struct inode *h_inode;
14103 + struct super_block *sb;
14104 + struct au_branch *br;
14105 + struct path h_path;
14108 + /* a race condition can happen between open and unlink/rmdir */
14109 + h_file = ERR_PTR(-ENOENT);
14110 + h_dentry = au_h_dptr(dentry, bindex);
14111 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14113 + h_inode = d_inode(h_dentry);
14114 + spin_lock(&h_dentry->d_lock);
14115 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14116 + /* || !d_inode(dentry)->i_nlink */
14118 + spin_unlock(&h_dentry->d_lock);
14119 + if (unlikely(err))
14122 + sb = dentry->d_sb;
14123 + br = au_sbr(sb, bindex);
14124 + err = au_br_test_oflag(flags, br);
14125 + h_file = ERR_PTR(err);
14126 + if (unlikely(err))
14129 + /* drop flags for writing */
14130 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14131 + if (force_wr && !(flags & O_WRONLY))
14133 + flags = au_file_roflags(flags);
14135 + h_file = ERR_PTR(-EROFS);
14136 + flags = au_file_roflags(flags);
14137 + if (unlikely(vfsub_native_ro(h_inode)
14138 + || IS_APPEND(h_inode)))
14140 + flags &= ~O_ACCMODE;
14141 + flags |= O_WRONLY;
14144 + flags &= ~O_CREAT;
14145 + au_lcnt_inc(&br->br_nfiles);
14146 + h_path.dentry = h_dentry;
14147 + h_path.mnt = au_br_mnt(br);
14148 + h_file = vfsub_dentry_open(&h_path, flags);
14149 + if (IS_ERR(h_file))
14152 + if (flags & __FMODE_EXEC) {
14153 + err = deny_write_access(h_file);
14154 + if (unlikely(err)) {
14156 + h_file = ERR_PTR(err);
14160 + fsnotify_open(h_file);
14161 + goto out; /* success */
14164 + au_lcnt_dec(&br->br_nfiles);
14169 +static int au_cmoo(struct dentry *dentry)
14171 + int err, cmoo, matched;
14172 + unsigned int udba;
14173 + struct path h_path;
14174 + struct au_pin pin;
14175 + struct au_cp_generic cpg = {
14176 + .dentry = dentry,
14181 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14183 + struct inode *delegated;
14184 + struct super_block *sb;
14185 + struct au_sbinfo *sbinfo;
14186 + struct au_fhsm *fhsm;
14188 + struct au_branch *br;
14189 + struct dentry *parent;
14190 + struct au_hinode *hdir;
14192 + DiMustWriteLock(dentry);
14193 + IiMustWriteLock(d_inode(dentry));
14196 + if (IS_ROOT(dentry))
14198 + cpg.bsrc = au_dbtop(dentry);
14202 + sb = dentry->d_sb;
14203 + sbinfo = au_sbi(sb);
14204 + fhsm = &sbinfo->si_fhsm;
14205 + pid = au_fhsm_pid(fhsm);
14208 + && (current->pid == pid
14209 + || rcu_dereference(current->real_parent)->pid == pid));
14210 + rcu_read_unlock();
14214 + br = au_sbr(sb, cpg.bsrc);
14215 + cmoo = au_br_cmoo(br->br_perm);
14218 + if (!d_is_reg(dentry))
14219 + cmoo &= AuBrAttr_COO_ALL;
14223 + parent = dget_parent(dentry);
14224 + di_write_lock_parent(parent);
14225 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14227 + if (unlikely(err < 0)) {
14228 + err = 0; /* there is no upper writable branch */
14231 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14233 + /* do not respect the coo attrib for the target branch */
14234 + err = au_cpup_dirs(dentry, cpg.bdst);
14235 + if (unlikely(err))
14238 + di_downgrade_lock(parent, AuLock_IR);
14239 + udba = au_opt_udba(sb);
14240 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14241 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14242 + if (unlikely(err))
14245 + err = au_sio_cpup_simple(&cpg);
14247 + if (unlikely(err))
14249 + if (!(cmoo & AuBrWAttr_MOO))
14250 + goto out_parent; /* success */
14252 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14253 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14254 + if (unlikely(err))
14257 + h_path.mnt = au_br_mnt(br);
14258 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14259 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14260 + delegated = NULL;
14261 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14263 + /* todo: keep h_dentry or not? */
14264 + if (unlikely(err == -EWOULDBLOCK)) {
14265 + pr_warn("cannot retry for NFSv4 delegation"
14266 + " for an internal unlink\n");
14269 + if (unlikely(err)) {
14270 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14274 + goto out_parent; /* success */
14277 + di_downgrade_lock(parent, AuLock_IR);
14279 + di_read_unlock(parent, AuLock_IR);
14286 +int au_do_open(struct file *file, struct au_do_open_args *args)
14288 + int err, aopen = args->aopen;
14289 + struct dentry *dentry;
14290 + struct au_finfo *finfo;
14293 + err = au_finfo_init(file, args->fidir);
14296 + err = au_finfo_init(file, args->fidir);
14299 + if (unlikely(err))
14302 + dentry = file->f_path.dentry;
14303 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14304 + di_write_lock_child(dentry);
14305 + err = au_cmoo(dentry);
14306 + di_downgrade_lock(dentry, AuLock_IR);
14309 + err = args->open(file, vfsub_file_flags(file), NULL);
14312 + err = args->open(file, vfsub_file_flags(file),
14317 + di_read_unlock(dentry, AuLock_IR);
14319 + finfo = au_fi(file);
14321 + finfo->fi_file = file;
14322 + au_hbl_add(&finfo->fi_hlist,
14323 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14326 + fi_write_unlock(file);
14329 + fi_write_unlock(file);
14332 + if (unlikely(err)) {
14333 + finfo->fi_hdir = NULL;
14334 + au_finfo_fin(file);
14342 +int au_reopen_nondir(struct file *file)
14345 + aufs_bindex_t btop;
14346 + struct dentry *dentry;
14347 + struct au_branch *br;
14348 + struct file *h_file, *h_file_tmp;
14350 + dentry = file->f_path.dentry;
14351 + btop = au_dbtop(dentry);
14352 + br = au_sbr(dentry->d_sb, btop);
14353 + h_file_tmp = NULL;
14354 + if (au_fbtop(file) == btop) {
14355 + h_file = au_hf_top(file);
14356 + if (file->f_mode == h_file->f_mode)
14357 + return 0; /* success */
14358 + h_file_tmp = h_file;
14359 + get_file(h_file_tmp);
14360 + au_lcnt_inc(&br->br_nfiles);
14361 + au_set_h_fptr(file, btop, NULL);
14363 + AuDebugOn(au_fi(file)->fi_hdir);
14366 + * file exists on both of rw and ro
14367 + * open --> dbtop and fbtop are both 0
14368 + * prepend a branch as rw, "rw" become ro
14370 + * delete the top branch, "rw" becomes rw again
14371 + * --> dbtop is 1, fbtop is still 0
14372 + * write --> fbtop is 0 but dbtop is 1
14374 + /* AuDebugOn(au_fbtop(file) < btop); */
14376 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14377 + file, /*force_wr*/0);
14378 + err = PTR_ERR(h_file);
14379 + if (IS_ERR(h_file)) {
14380 + if (h_file_tmp) {
14382 + au_set_h_fptr(file, btop, h_file_tmp);
14383 + h_file_tmp = NULL;
14385 + goto out; /* todo: close all? */
14389 + au_set_fbtop(file, btop);
14390 + au_set_h_fptr(file, btop, h_file);
14391 + au_update_figen(file);
14392 + /* todo: necessary? */
14393 + /* file->f_ra = h_file->f_ra; */
14396 + if (h_file_tmp) {
14397 + fput(h_file_tmp);
14398 + au_lcnt_dec(&br->br_nfiles);
14403 +/* ---------------------------------------------------------------------- */
14405 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14406 + struct dentry *hi_wh)
14409 + aufs_bindex_t btop;
14410 + struct au_dinfo *dinfo;
14411 + struct dentry *h_dentry;
14412 + struct au_hdentry *hdp;
14414 + dinfo = au_di(file->f_path.dentry);
14415 + AuRwMustWriteLock(&dinfo->di_rwsem);
14417 + btop = dinfo->di_btop;
14418 + dinfo->di_btop = btgt;
14419 + hdp = au_hdentry(dinfo, btgt);
14420 + h_dentry = hdp->hd_dentry;
14421 + hdp->hd_dentry = hi_wh;
14422 + err = au_reopen_nondir(file);
14423 + hdp->hd_dentry = h_dentry;
14424 + dinfo->di_btop = btop;
14429 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14430 + aufs_bindex_t bcpup, struct au_pin *pin)
14433 + struct inode *inode, *h_inode;
14434 + struct dentry *h_dentry, *hi_wh;
14435 + struct au_cp_generic cpg = {
14436 + .dentry = file->f_path.dentry,
14443 + au_update_dbtop(cpg.dentry);
14444 + inode = d_inode(cpg.dentry);
14446 + if (au_dbtop(cpg.dentry) <= bcpup
14447 + && au_dbbot(cpg.dentry) >= bcpup) {
14448 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14449 + if (h_dentry && d_is_positive(h_dentry))
14450 + h_inode = d_inode(h_dentry);
14452 + hi_wh = au_hi_wh(inode, bcpup);
14453 + if (!hi_wh && !h_inode)
14454 + err = au_sio_cpup_wh(&cpg, file);
14456 + /* already copied-up after unlink */
14457 + err = au_reopen_wh(file, bcpup, hi_wh);
14460 + && (inode->i_nlink > 1
14461 + || (inode->i_state & I_LINKABLE))
14462 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14463 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14469 + * prepare the @file for writing.
14471 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14474 + aufs_bindex_t dbtop;
14475 + struct dentry *parent;
14476 + struct inode *inode;
14477 + struct super_block *sb;
14478 + struct file *h_file;
14479 + struct au_cp_generic cpg = {
14480 + .dentry = file->f_path.dentry,
14485 + .flags = AuCpup_DTIME
14488 + sb = cpg.dentry->d_sb;
14489 + inode = d_inode(cpg.dentry);
14490 + cpg.bsrc = au_fbtop(file);
14491 + err = au_test_ro(sb, cpg.bsrc, inode);
14492 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14493 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14498 + /* need to cpup or reopen */
14499 + parent = dget_parent(cpg.dentry);
14500 + di_write_lock_parent(parent);
14501 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14503 + if (unlikely(err < 0))
14507 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14508 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14509 + if (unlikely(err))
14513 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14514 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14515 + if (unlikely(err))
14518 + dbtop = au_dbtop(cpg.dentry);
14519 + if (dbtop <= cpg.bdst)
14520 + cpg.bsrc = cpg.bdst;
14522 + if (dbtop <= cpg.bdst /* just reopen */
14523 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14525 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14526 + if (IS_ERR(h_file))
14527 + err = PTR_ERR(h_file);
14529 + di_downgrade_lock(parent, AuLock_IR);
14530 + if (dbtop > cpg.bdst)
14531 + err = au_sio_cpup_simple(&cpg);
14533 + err = au_reopen_nondir(file);
14534 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14536 + } else { /* copyup as wh and reopen */
14538 + * since writable hfsplus branch is not supported,
14539 + * h_open_pre/post() are unnecessary.
14541 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14542 + di_downgrade_lock(parent, AuLock_IR);
14546 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14547 + goto out_dput; /* success */
14553 + di_downgrade_lock(parent, AuLock_IR);
14555 + di_read_unlock(parent, AuLock_IR);
14562 +/* ---------------------------------------------------------------------- */
14564 +int au_do_flush(struct file *file, fl_owner_t id,
14565 + int (*flush)(struct file *file, fl_owner_t id))
14568 + struct super_block *sb;
14569 + struct inode *inode;
14571 + inode = file_inode(file);
14572 + sb = inode->i_sb;
14573 + si_noflush_read_lock(sb);
14574 + fi_read_lock(file);
14575 + ii_read_lock_child(inode);
14577 + err = flush(file, id);
14578 + au_cpup_attr_timesizes(inode);
14580 + ii_read_unlock(inode);
14581 + fi_read_unlock(file);
14582 + si_read_unlock(sb);
14586 +/* ---------------------------------------------------------------------- */
14588 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14591 + struct au_pin pin;
14592 + struct au_finfo *finfo;
14593 + struct dentry *parent, *hi_wh;
14594 + struct inode *inode;
14595 + struct super_block *sb;
14596 + struct au_cp_generic cpg = {
14597 + .dentry = file->f_path.dentry,
14602 + .flags = AuCpup_DTIME
14605 + FiMustWriteLock(file);
14608 + finfo = au_fi(file);
14609 + sb = cpg.dentry->d_sb;
14610 + inode = d_inode(cpg.dentry);
14611 + cpg.bdst = au_ibtop(inode);
14612 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14615 + parent = dget_parent(cpg.dentry);
14616 + if (au_test_ro(sb, cpg.bdst, inode)) {
14617 + di_read_lock_parent(parent, !AuLock_IR);
14618 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14620 + di_read_unlock(parent, !AuLock_IR);
14621 + if (unlikely(err < 0))
14626 + di_read_lock_parent(parent, AuLock_IR);
14627 + hi_wh = au_hi_wh(inode, cpg.bdst);
14628 + if (!S_ISDIR(inode->i_mode)
14629 + && au_opt_test(au_mntflags(sb), PLINK)
14630 + && au_plink_test(inode)
14631 + && !d_unhashed(cpg.dentry)
14632 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14633 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14634 + if (unlikely(err))
14637 + /* always superio. */
14638 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14639 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14641 + err = au_sio_cpup_simple(&cpg);
14644 + } else if (hi_wh) {
14645 + /* already copied-up after unlink */
14646 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14647 + *need_reopen = 0;
14651 + di_read_unlock(parent, AuLock_IR);
14658 +static void au_do_refresh_dir(struct file *file)
14660 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14661 + struct au_hfile *p, tmp, *q;
14662 + struct au_finfo *finfo;
14663 + struct super_block *sb;
14664 + struct au_fidir *fidir;
14666 + FiMustWriteLock(file);
14668 + sb = file->f_path.dentry->d_sb;
14669 + finfo = au_fi(file);
14670 + fidir = finfo->fi_hdir;
14671 + AuDebugOn(!fidir);
14672 + p = fidir->fd_hfile + finfo->fi_btop;
14673 + brid = p->hf_br->br_id;
14674 + bbot = fidir->fd_bbot;
14675 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14679 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14680 + if (new_bindex == bindex)
14682 + if (new_bindex < 0) {
14683 + au_set_h_fptr(file, bindex, NULL);
14687 + /* swap two lower inode, and loop again */
14688 + q = fidir->fd_hfile + new_bindex;
14692 + if (tmp.hf_file) {
14698 + p = fidir->fd_hfile;
14699 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14700 + bbot = au_sbbot(sb);
14701 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14702 + finfo->fi_btop++, p++)
14703 + if (p->hf_file) {
14704 + if (file_inode(p->hf_file))
14706 + au_hfput(p, /*execed*/0);
14709 + bbot = au_br_index(sb, brid);
14710 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14711 + finfo->fi_btop++, p++)
14713 + au_hfput(p, /*execed*/0);
14714 + bbot = au_sbbot(sb);
14717 + p = fidir->fd_hfile + bbot;
14718 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14719 + fidir->fd_bbot--, p--)
14720 + if (p->hf_file) {
14721 + if (file_inode(p->hf_file))
14723 + au_hfput(p, /*execed*/0);
14725 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14729 + * after branch manipulating, refresh the file.
14731 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14733 + int err, need_reopen, nbr;
14734 + aufs_bindex_t bbot, bindex;
14735 + struct dentry *dentry;
14736 + struct super_block *sb;
14737 + struct au_finfo *finfo;
14738 + struct au_hfile *hfile;
14740 + dentry = file->f_path.dentry;
14741 + sb = dentry->d_sb;
14742 + nbr = au_sbbot(sb) + 1;
14743 + finfo = au_fi(file);
14744 + if (!finfo->fi_hdir) {
14745 + hfile = &finfo->fi_htop;
14746 + AuDebugOn(!hfile->hf_file);
14747 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14748 + AuDebugOn(bindex < 0);
14749 + if (bindex != finfo->fi_btop)
14750 + au_set_fbtop(file, bindex);
14752 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14753 + if (unlikely(err))
14755 + au_do_refresh_dir(file);
14760 + if (!au_test_mmapped(file))
14761 + err = au_file_refresh_by_inode(file, &need_reopen);
14762 + if (finfo->fi_hdir)
14763 + /* harmless if err */
14764 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14765 + if (!err && need_reopen && !d_unlinked(dentry))
14766 + err = reopen(file);
14768 + au_update_figen(file);
14769 + goto out; /* success */
14772 + /* error, close all lower files */
14773 + if (finfo->fi_hdir) {
14774 + bbot = au_fbbot_dir(file);
14775 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14776 + au_set_h_fptr(file, bindex, NULL);
14783 +/* common function to regular file and dir */
14784 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14785 + int wlock, unsigned int fi_lsc)
14788 + unsigned int sigen, figen;
14789 + aufs_bindex_t btop;
14790 + unsigned char pseudo_link;
14791 + struct dentry *dentry;
14792 + struct inode *inode;
14795 + dentry = file->f_path.dentry;
14796 + inode = d_inode(dentry);
14797 + sigen = au_sigen(dentry->d_sb);
14798 + fi_write_lock_nested(file, fi_lsc);
14799 + figen = au_figen(file);
14801 + di_write_lock_child(dentry);
14803 + di_write_lock_child2(dentry);
14804 + btop = au_dbtop(dentry);
14805 + pseudo_link = (btop != au_ibtop(inode));
14806 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14808 + di_downgrade_lock(dentry, AuLock_IR);
14809 + fi_downgrade_lock(file);
14811 + goto out; /* success */
14814 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14815 + if (au_digen_test(dentry, sigen)) {
14816 + err = au_reval_dpath(dentry, sigen);
14817 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14821 + err = refresh_file(file, reopen);
14824 + di_downgrade_lock(dentry, AuLock_IR);
14825 + fi_downgrade_lock(file);
14828 + di_write_unlock(dentry);
14829 + fi_write_unlock(file);
14836 +/* ---------------------------------------------------------------------- */
14838 +/* cf. aufs_nopage() */
14839 +/* for madvise(2) */
14840 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14842 + unlock_page(page);
14846 +/* it will never be called, but necessary to support O_DIRECT */
14847 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14848 +{ BUG(); return 0; }
14850 +/* they will never be called. */
14851 +#ifdef CONFIG_AUFS_DEBUG
14852 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14853 + loff_t pos, unsigned len, unsigned flags,
14854 + struct page **pagep, void **fsdata)
14855 +{ AuUnsupport(); return 0; }
14856 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14857 + loff_t pos, unsigned len, unsigned copied,
14858 + struct page *page, void *fsdata)
14859 +{ AuUnsupport(); return 0; }
14860 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14861 +{ AuUnsupport(); return 0; }
14863 +static int aufs_set_page_dirty(struct page *page)
14864 +{ AuUnsupport(); return 0; }
14865 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14866 + unsigned int length)
14867 +{ AuUnsupport(); }
14868 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14869 +{ AuUnsupport(); return 0; }
14870 +#if 0 /* called by memory compaction regardless file */
14871 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14872 + struct page *page, enum migrate_mode mode)
14873 +{ AuUnsupport(); return 0; }
14875 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14876 +{ AuUnsupport(); return true; }
14877 +static void aufs_putback_page(struct page *page)
14878 +{ AuUnsupport(); }
14879 +static int aufs_launder_page(struct page *page)
14880 +{ AuUnsupport(); return 0; }
14881 +static int aufs_is_partially_uptodate(struct page *page,
14882 + unsigned long from,
14883 + unsigned long count)
14884 +{ AuUnsupport(); return 0; }
14885 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14887 +{ AuUnsupport(); }
14888 +static int aufs_error_remove_page(struct address_space *mapping,
14889 + struct page *page)
14890 +{ AuUnsupport(); return 0; }
14891 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14893 +{ AuUnsupport(); return 0; }
14894 +static void aufs_swap_deactivate(struct file *file)
14895 +{ AuUnsupport(); }
14896 +#endif /* CONFIG_AUFS_DEBUG */
14898 +const struct address_space_operations aufs_aop = {
14899 + .readpage = aufs_readpage,
14900 + .direct_IO = aufs_direct_IO,
14901 +#ifdef CONFIG_AUFS_DEBUG
14902 + .writepage = aufs_writepage,
14903 + /* no writepages, because of writepage */
14904 + .set_page_dirty = aufs_set_page_dirty,
14905 + /* no readpages, because of readpage */
14906 + .write_begin = aufs_write_begin,
14907 + .write_end = aufs_write_end,
14908 + /* no bmap, no block device */
14909 + .invalidatepage = aufs_invalidatepage,
14910 + .releasepage = aufs_releasepage,
14911 + /* is fallback_migrate_page ok? */
14912 + /* .migratepage = aufs_migratepage, */
14913 + .isolate_page = aufs_isolate_page,
14914 + .putback_page = aufs_putback_page,
14915 + .launder_page = aufs_launder_page,
14916 + .is_partially_uptodate = aufs_is_partially_uptodate,
14917 + .is_dirty_writeback = aufs_is_dirty_writeback,
14918 + .error_remove_page = aufs_error_remove_page,
14919 + .swap_activate = aufs_swap_activate,
14920 + .swap_deactivate = aufs_swap_deactivate
14921 +#endif /* CONFIG_AUFS_DEBUG */
14923 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14924 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14925 +++ linux/fs/aufs/file.h 2021-02-22 22:51:59.058078584 +0100
14927 +/* SPDX-License-Identifier: GPL-2.0 */
14929 + * Copyright (C) 2005-2020 Junjiro R. Okajima
14931 + * This program, aufs is free software; you can redistribute it and/or modify
14932 + * it under the terms of the GNU General Public License as published by
14933 + * the Free Software Foundation; either version 2 of the License, or
14934 + * (at your option) any later version.
14936 + * This program is distributed in the hope that it will be useful,
14937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14939 + * GNU General Public License for more details.
14941 + * You should have received a copy of the GNU General Public License
14942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14946 + * file operations
14949 +#ifndef __AUFS_FILE_H__
14950 +#define __AUFS_FILE_H__
14954 +#include <linux/file.h>
14955 +#include <linux/fs.h>
14956 +#include <linux/mm_types.h>
14957 +#include <linux/poll.h>
14958 +#include "rwsem.h"
14962 + struct file *hf_file;
14963 + struct au_branch *hf_br;
14968 + aufs_bindex_t fd_bbot;
14969 + aufs_bindex_t fd_nent;
14970 + struct au_vdir *fd_vdir_cache;
14971 + struct au_hfile fd_hfile[];
14974 +static inline int au_fidir_sz(int nent)
14976 + AuDebugOn(nent < 0);
14977 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14981 + atomic_t fi_generation;
14983 + struct au_rwsem fi_rwsem;
14984 + aufs_bindex_t fi_btop;
14986 + /* do not union them */
14987 + struct { /* for non-dir */
14988 + struct au_hfile fi_htop;
14989 + atomic_t fi_mmapped;
14991 + struct au_fidir *fi_hdir; /* for dir only */
14993 + struct hlist_bl_node fi_hlist;
14994 + struct file *fi_file; /* very ugly */
14995 + struct rcu_head rcu;
14996 +} ____cacheline_aligned_in_smp;
14998 +/* ---------------------------------------------------------------------- */
15001 +extern const struct address_space_operations aufs_aop;
15002 +unsigned int au_file_roflags(unsigned int flags);
15003 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15004 + struct file *file, int force_wr);
15005 +struct au_do_open_args {
15007 + int (*open)(struct file *file, int flags,
15008 + struct file *h_file);
15009 + struct au_fidir *fidir;
15010 + struct file *h_file;
15012 +int au_do_open(struct file *file, struct au_do_open_args *args);
15013 +int au_reopen_nondir(struct file *file);
15015 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15016 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15017 + int wlock, unsigned int fi_lsc);
15018 +int au_do_flush(struct file *file, fl_owner_t id,
15019 + int (*flush)(struct file *file, fl_owner_t id));
15022 +#ifdef CONFIG_AUFS_POLL
15023 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15026 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15028 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15030 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15031 + struct file *h_file);
15033 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15034 + aufs_bindex_t bindex, int force_wr)
15035 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15036 + struct file *h_file);
15040 +extern const struct file_operations aufs_file_fop;
15041 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15042 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15043 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15046 +void au_hfput(struct au_hfile *hf, int execed);
15047 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15048 + struct file *h_file);
15050 +void au_update_figen(struct file *file);
15051 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15052 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15054 +void au_fi_init_once(void *_fi);
15055 +void au_finfo_fin(struct file *file);
15056 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15059 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15060 +#ifdef CONFIG_COMPAT
15061 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15062 + unsigned long arg);
15063 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15064 + unsigned long arg);
15067 +/* ---------------------------------------------------------------------- */
15069 +static inline struct au_finfo *au_fi(struct file *file)
15071 + return file->private_data;
15074 +/* ---------------------------------------------------------------------- */
15076 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15077 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15078 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15079 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15081 +#define fi_read_trylock_nested(f) \
15082 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15083 +#define fi_write_trylock_nested(f) \
15084 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15087 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15088 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15089 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15091 +/* lock subclass for finfo */
15097 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15099 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15102 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15104 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15108 + * fi_read_lock_1, fi_write_lock_1,
15109 + * fi_read_lock_2, fi_write_lock_2
15111 +#define AuReadLockFunc(name) \
15112 +static inline void fi_read_lock_##name(struct file *f) \
15113 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15115 +#define AuWriteLockFunc(name) \
15116 +static inline void fi_write_lock_##name(struct file *f) \
15117 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15119 +#define AuRWLockFuncs(name) \
15120 + AuReadLockFunc(name) \
15121 + AuWriteLockFunc(name)
15126 +#undef AuReadLockFunc
15127 +#undef AuWriteLockFunc
15128 +#undef AuRWLockFuncs
15130 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15131 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15132 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15134 +/* ---------------------------------------------------------------------- */
15136 +/* todo: hard/soft set? */
15137 +static inline aufs_bindex_t au_fbtop(struct file *file)
15139 + FiMustAnyLock(file);
15140 + return au_fi(file)->fi_btop;
15143 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15145 + FiMustAnyLock(file);
15146 + AuDebugOn(!au_fi(file)->fi_hdir);
15147 + return au_fi(file)->fi_hdir->fd_bbot;
15150 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15152 + FiMustAnyLock(file);
15153 + AuDebugOn(!au_fi(file)->fi_hdir);
15154 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15157 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15159 + FiMustWriteLock(file);
15160 + au_fi(file)->fi_btop = bindex;
15163 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15165 + FiMustWriteLock(file);
15166 + AuDebugOn(!au_fi(file)->fi_hdir);
15167 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15170 +static inline void au_set_fvdir_cache(struct file *file,
15171 + struct au_vdir *vdir_cache)
15173 + FiMustWriteLock(file);
15174 + AuDebugOn(!au_fi(file)->fi_hdir);
15175 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15178 +static inline struct file *au_hf_top(struct file *file)
15180 + FiMustAnyLock(file);
15181 + AuDebugOn(au_fi(file)->fi_hdir);
15182 + return au_fi(file)->fi_htop.hf_file;
15185 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15187 + FiMustAnyLock(file);
15188 + AuDebugOn(!au_fi(file)->fi_hdir);
15189 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15192 +/* todo: memory barrier? */
15193 +static inline unsigned int au_figen(struct file *f)
15195 + return atomic_read(&au_fi(f)->fi_generation);
15198 +static inline void au_set_mmapped(struct file *f)
15200 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15202 + pr_warn("fi_mmapped wrapped around\n");
15203 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15207 +static inline void au_unset_mmapped(struct file *f)
15209 + atomic_dec(&au_fi(f)->fi_mmapped);
15212 +static inline int au_test_mmapped(struct file *f)
15214 + return atomic_read(&au_fi(f)->fi_mmapped);
15217 +/* customize vma->vm_file */
15219 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15220 + struct file *file)
15224 + f = vma->vm_file;
15226 + vma->vm_file = file;
15231 +#define AuDbgVmRegion(file, vma) do {} while (0)
15233 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15234 + struct file *file)
15236 + au_do_vm_file_reset(vma, file);
15239 +#define AuDbgVmRegion(file, vma) \
15240 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15242 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15243 + struct file *file)
15247 + au_do_vm_file_reset(vma, file);
15248 + f = vma->vm_region->vm_file;
15250 + vma->vm_region->vm_file = file;
15253 +#endif /* CONFIG_MMU */
15255 +/* handle vma->vm_prfile */
15256 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15257 + struct file *file)
15260 + vma->vm_prfile = file;
15261 +#ifndef CONFIG_MMU
15263 + vma->vm_region->vm_prfile = file;
15267 +#endif /* __KERNEL__ */
15268 +#endif /* __AUFS_FILE_H__ */
15269 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15270 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15271 +++ linux/fs/aufs/finfo.c 2021-02-22 22:51:59.058078584 +0100
15273 +// SPDX-License-Identifier: GPL-2.0
15275 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15277 + * This program, aufs is free software; you can redistribute it and/or modify
15278 + * it under the terms of the GNU General Public License as published by
15279 + * the Free Software Foundation; either version 2 of the License, or
15280 + * (at your option) any later version.
15282 + * This program is distributed in the hope that it will be useful,
15283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15285 + * GNU General Public License for more details.
15287 + * You should have received a copy of the GNU General Public License
15288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15292 + * file private data
15297 +void au_hfput(struct au_hfile *hf, int execed)
15300 + allow_write_access(hf->hf_file);
15301 + fput(hf->hf_file);
15302 + hf->hf_file = NULL;
15303 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15304 + hf->hf_br = NULL;
15307 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15309 + struct au_finfo *finfo = au_fi(file);
15310 + struct au_hfile *hf;
15311 + struct au_fidir *fidir;
15313 + fidir = finfo->fi_hdir;
15315 + AuDebugOn(finfo->fi_btop != bindex);
15316 + hf = &finfo->fi_htop;
15318 + hf = fidir->fd_hfile + bindex;
15320 + if (hf && hf->hf_file)
15321 + au_hfput(hf, vfsub_file_execed(file));
15323 + FiMustWriteLock(file);
15324 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15325 + hf->hf_file = val;
15326 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15330 +void au_update_figen(struct file *file)
15332 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15333 + /* smp_mb(); */ /* atomic_set */
15336 +/* ---------------------------------------------------------------------- */
15338 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15340 + struct au_fidir *fidir;
15343 + nbr = au_sbbot(sb) + 1;
15345 + nbr = 2; /* initial allocate for 2 branches */
15346 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15348 + fidir->fd_bbot = -1;
15349 + fidir->fd_nent = nbr;
15355 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15358 + struct au_fidir *fidir, *p;
15360 + AuRwMustWriteLock(&finfo->fi_rwsem);
15361 + fidir = finfo->fi_hdir;
15362 + AuDebugOn(!fidir);
15365 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15366 + GFP_NOFS, may_shrink);
15368 + p->fd_nent = nbr;
15369 + finfo->fi_hdir = p;
15376 +/* ---------------------------------------------------------------------- */
15378 +void au_finfo_fin(struct file *file)
15380 + struct au_finfo *finfo;
15382 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15384 + finfo = au_fi(file);
15385 + AuDebugOn(finfo->fi_hdir);
15386 + AuRwDestroy(&finfo->fi_rwsem);
15387 + au_cache_free_finfo(finfo);
15390 +void au_fi_init_once(void *_finfo)
15392 + struct au_finfo *finfo = _finfo;
15394 + au_rw_init(&finfo->fi_rwsem);
15397 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15400 + struct au_finfo *finfo;
15401 + struct dentry *dentry;
15404 + dentry = file->f_path.dentry;
15405 + finfo = au_cache_alloc_finfo();
15406 + if (unlikely(!finfo))
15410 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15411 + au_rw_write_lock(&finfo->fi_rwsem);
15412 + finfo->fi_btop = -1;
15413 + finfo->fi_hdir = fidir;
15414 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15415 + /* smp_mb(); */ /* atomic_set */
15417 + file->private_data = finfo;
15422 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15423 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15424 +++ linux/fs/aufs/f_op.c 2021-02-22 22:51:59.058078584 +0100
15426 +// SPDX-License-Identifier: GPL-2.0
15428 + * Copyright (C) 2005-2020 Junjiro R. Okajima
15430 + * This program, aufs is free software; you can redistribute it and/or modify
15431 + * it under the terms of the GNU General Public License as published by
15432 + * the Free Software Foundation; either version 2 of the License, or
15433 + * (at your option) any later version.
15435 + * This program is distributed in the hope that it will be useful,
15436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15438 + * GNU General Public License for more details.
15440 + * You should have received a copy of the GNU General Public License
15441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15445 + * file and vm operations
15448 +#include <linux/aio.h>
15449 +#include <linux/fs_stack.h>
15450 +#include <linux/mman.h>
15451 +#include <linux/security.h>
15454 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15457 + aufs_bindex_t bindex;
15458 + struct dentry *dentry, *h_dentry;
15459 + struct au_finfo *finfo;
15460 + struct inode *h_inode;
15462 + FiMustWriteLock(file);
15465 + dentry = file->f_path.dentry;
15466 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15467 + finfo = au_fi(file);
15468 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15469 + atomic_set(&finfo->fi_mmapped, 0);
15470 + bindex = au_dbtop(dentry);
15472 + h_dentry = au_h_dptr(dentry, bindex);
15473 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15474 + if (unlikely(err))
15476 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15477 + if (IS_ERR(h_file)) {
15478 + err = PTR_ERR(h_file);
15482 + h_dentry = h_file->f_path.dentry;
15483 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15484 + if (unlikely(err))
15486 + /* br ref is already inc-ed */
15489 + if ((flags & __O_TMPFILE)
15490 + && !(flags & O_EXCL)) {
15491 + h_inode = file_inode(h_file);
15492 + spin_lock(&h_inode->i_lock);
15493 + h_inode->i_state |= I_LINKABLE;
15494 + spin_unlock(&h_inode->i_lock);
15496 + au_set_fbtop(file, bindex);
15497 + au_set_h_fptr(file, bindex, h_file);
15498 + au_update_figen(file);
15499 + /* todo: necessary? */
15500 + /* file->f_ra = h_file->f_ra; */
15506 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15507 + struct file *file)
15510 + struct super_block *sb;
15511 + struct au_do_open_args args = {
15512 + .open = au_do_open_nondir
15515 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15516 + file, vfsub_file_flags(file), file->f_mode);
15518 + sb = file->f_path.dentry->d_sb;
15519 + si_read_lock(sb, AuLock_FLUSH);
15520 + err = au_do_open(file, &args);
15521 + si_read_unlock(sb);
15525 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15527 + struct au_finfo *finfo;
15528 + aufs_bindex_t bindex;
15530 + finfo = au_fi(file);
15531 + au_hbl_del(&finfo->fi_hlist,
15532 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15533 + bindex = finfo->fi_btop;
15535 + au_set_h_fptr(file, bindex, NULL);
15537 + au_finfo_fin(file);
15541 +/* ---------------------------------------------------------------------- */
15543 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15546 + struct file *h_file;
15549 + h_file = au_hf_top(file);
15551 + err = vfsub_flush(h_file, id);
15555 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15557 + return au_do_flush(file, id, au_do_flush_nondir);
15560 +/* ---------------------------------------------------------------------- */
15562 + * read and write functions acquire [fdi]_rwsem once, but release before
15563 + * mmap_sem. This is because to stop a race condition between mmap(2).
15564 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15565 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15566 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15569 +/* Callers should call au_read_post() or fput() in the end */
15570 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15572 + struct file *h_file;
15575 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15577 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15578 + h_file = au_hf_top(file);
15579 + get_file(h_file);
15581 + fi_read_unlock(file);
15583 + h_file = ERR_PTR(err);
15588 +static void au_read_post(struct inode *inode, struct file *h_file)
15590 + /* update without lock, I don't think it a problem */
15591 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15595 +struct au_write_pre {
15597 + unsigned int lsc;
15601 + aufs_bindex_t btop;
15605 + * return with iinfo is write-locked
15606 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15609 +static struct file *au_write_pre(struct file *file, int do_ready,
15610 + struct au_write_pre *wpre)
15612 + struct file *h_file;
15613 + struct dentry *dentry;
15615 + unsigned int lsc;
15616 + struct au_pin pin;
15621 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15622 + h_file = ERR_PTR(err);
15623 + if (unlikely(err))
15626 + dentry = file->f_path.dentry;
15628 + err = au_ready_to_write(file, -1, &pin);
15629 + if (unlikely(err)) {
15630 + h_file = ERR_PTR(err);
15631 + di_write_unlock(dentry);
15636 + di_downgrade_lock(dentry, /*flags*/0);
15638 + wpre->btop = au_fbtop(file);
15639 + h_file = au_hf_top(file);
15640 + get_file(h_file);
15642 + wpre->blks = file_inode(h_file)->i_blocks;
15645 + di_read_unlock(dentry, /*flags*/0);
15648 + fi_write_unlock(file);
15653 +static void au_write_post(struct inode *inode, struct file *h_file,
15654 + struct au_write_pre *wpre, ssize_t written)
15656 + struct inode *h_inode;
15658 + au_cpup_attr_timesizes(inode);
15659 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15660 + h_inode = file_inode(h_file);
15661 + inode->i_mode = h_inode->i_mode;
15662 + ii_write_unlock(inode);
15663 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15665 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15666 + /*force*/h_inode->i_blocks > wpre->blks);
15671 + * todo: very ugly
15672 + * it locks both of i_mutex and si_rwsem for read in safe.
15673 + * if the plink maintenance mode continues forever (that is the problem),
15674 + * may loop forever.
15676 +static void au_mtx_and_read_lock(struct inode *inode)
15679 + struct super_block *sb = inode->i_sb;
15682 + inode_lock(inode);
15683 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15686 + inode_unlock(inode);
15687 + si_read_lock(sb, AuLock_NOPLMW);
15688 + si_read_unlock(sb);
15692 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15693 + struct iov_iter *iov_iter)
15696 + struct file *file;
15697 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15699 + err = security_file_permission(h_file, rw);
15700 + if (unlikely(err))
15703 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15705 + if (rw == MAY_READ)
15706 + iter = h_file->f_op->read_iter;
15707 + else if (rw == MAY_WRITE)
15708 + iter = h_file->f_op->write_iter;
15710 + file = kio->ki_filp;
15711 + kio->ki_filp = h_file;
15714 + err = iter(kio, iov_iter);
15717 + /* currently there is no such fs */
15719 + kio->ki_filp = file;
15725 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15728 + struct file *file, *h_file;
15729 + struct inode *inode;
15730 + struct super_block *sb;
15732 + file = kio->ki_filp;
15733 + inode = file_inode(file);
15734 + sb = inode->i_sb;
15735 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15737 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15738 + err = PTR_ERR(h_file);
15739 + if (IS_ERR(h_file))
15742 + if (au_test_loopback_kthread()) {
15743 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15744 + if (file->f_mapping != h_file->f_mapping) {
15745 + file->f_mapping = h_file->f_mapping;
15746 + smp_mb(); /* unnecessary? */
15749 + fi_read_unlock(file);
15751 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15752 + /* todo: necessary? */
15753 + /* file->f_ra = h_file->f_ra; */
15754 + au_read_post(inode, h_file);
15757 + si_read_unlock(sb);
15761 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15764 + struct au_write_pre wpre;
15765 + struct inode *inode;
15766 + struct file *file, *h_file;
15768 + file = kio->ki_filp;
15769 + inode = file_inode(file);
15770 + au_mtx_and_read_lock(inode);
15773 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15774 + err = PTR_ERR(h_file);
15775 + if (IS_ERR(h_file))
15778 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15779 + au_write_post(inode, h_file, &wpre, err);
15782 + si_read_unlock(inode->i_sb);
15783 + inode_unlock(inode);
15787 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15788 + struct pipe_inode_info *pipe, size_t len,
15789 + unsigned int flags)
15792 + struct file *h_file;
15793 + struct inode *inode;
15794 + struct super_block *sb;
15796 + inode = file_inode(file);
15797 + sb = inode->i_sb;
15798 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15800 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15801 + err = PTR_ERR(h_file);
15802 + if (IS_ERR(h_file))
15805 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15806 + /* todo: necessary? */
15807 + /* file->f_ra = h_file->f_ra; */
15808 + au_read_post(inode, h_file);
15811 + si_read_unlock(sb);
15816 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15817 + size_t len, unsigned int flags)
15820 + struct au_write_pre wpre;
15821 + struct inode *inode;
15822 + struct file *h_file;
15824 + inode = file_inode(file);
15825 + au_mtx_and_read_lock(inode);
15828 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15829 + err = PTR_ERR(h_file);
15830 + if (IS_ERR(h_file))
15833 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15834 + au_write_post(inode, h_file, &wpre, err);
15837 + si_read_unlock(inode->i_sb);
15838 + inode_unlock(inode);
15842 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15846 + struct au_write_pre wpre;
15847 + struct inode *inode;
15848 + struct file *h_file;
15850 + inode = file_inode(file);
15851 + au_mtx_and_read_lock(inode);
15854 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15855 + err = PTR_ERR(h_file);
15856 + if (IS_ERR(h_file))
15860 + err = vfs_fallocate(h_file, mode, offset, len);
15862 + au_write_post(inode, h_file, &wpre, /*written*/1);
15865 + si_read_unlock(inode->i_sb);
15866 + inode_unlock(inode);
15870 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15871 + struct file *dst, loff_t dst_pos,
15872 + size_t len, unsigned int flags)
15875 + struct au_write_pre wpre;
15876 + enum { SRC, DST };
15878 + struct inode *inode;
15879 + struct file *h_file;
15880 + struct super_block *h_sb;
15882 +#define a_src a[SRC]
15883 +#define a_dst a[DST]
15886 + a_src.inode = file_inode(src);
15887 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15889 + a_dst.inode = file_inode(dst);
15890 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15893 + au_mtx_and_read_lock(a_dst.inode);
15895 + * in order to match the order in di_write_lock2_{child,parent}(),
15896 + * use f_path.dentry for this comparison.
15898 + if (src->f_path.dentry < dst->f_path.dentry) {
15899 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15900 + err = PTR_ERR(a_src.h_file);
15901 + if (IS_ERR(a_src.h_file))
15904 + wpre.lsc = AuLsc_FI_2;
15905 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15906 + err = PTR_ERR(a_dst.h_file);
15907 + if (IS_ERR(a_dst.h_file)) {
15908 + au_read_post(a_src.inode, a_src.h_file);
15912 + wpre.lsc = AuLsc_FI_1;
15913 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15914 + err = PTR_ERR(a_dst.h_file);
15915 + if (IS_ERR(a_dst.h_file))
15918 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15919 + err = PTR_ERR(a_src.h_file);
15920 + if (IS_ERR(a_src.h_file)) {
15921 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15928 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15929 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15930 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15936 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15937 + dst_pos, len, flags);
15940 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15941 + fi_read_unlock(src);
15942 + au_read_post(a_src.inode, a_src.h_file);
15944 + si_read_unlock(a_dst.inode->i_sb);
15945 + inode_unlock(a_dst.inode);
15952 +/* ---------------------------------------------------------------------- */
15955 + * The locking order around current->mmap_sem.
15956 + * - in most and regular cases
15957 + * file I/O syscall -- aufs_read() or something
15958 + * -- si_rwsem for read -- mmap_sem
15959 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15961 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15962 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15963 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15964 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15965 + * It means that when aufs acquires si_rwsem for write, the process should never
15966 + * acquire mmap_sem.
15968 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15969 + * problem either since any directory is not able to be mmap-ed.
15970 + * The similar scenario is applied to aufs_readlink() too.
15973 +#if 0 /* stop calling security_file_mmap() */
15974 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15975 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15977 +static unsigned long au_arch_prot_conv(unsigned long flags)
15979 + /* currently ppc64 only */
15980 +#ifdef CONFIG_PPC64
15981 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15982 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15983 + return AuConv_VM_PROT(flags, SAO);
15985 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15990 +static unsigned long au_prot_conv(unsigned long flags)
15992 + return AuConv_VM_PROT(flags, READ)
15993 + | AuConv_VM_PROT(flags, WRITE)
15994 + | AuConv_VM_PROT(flags, EXEC)
15995 + | au_arch_prot_conv(flags);
15998 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15999 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16001 +static unsigned long au_flag_conv(unsigned long flags)
16003 + return AuConv_VM_MAP(flags, GROWSDOWN)
16004 + | AuConv_VM_MAP(flags, DENYWRITE)
16005 + | AuConv_VM_MAP(flags, LOCKED);
16009 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16012 + const unsigned char wlock
16013 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16014 + struct super_block *sb;
16015 + struct file *h_file;
16016 + struct inode *inode;
16018 + AuDbgVmRegion(file, vma);
16020 + inode = file_inode(file);
16021 + sb = inode->i_sb;
16023 + si_read_lock(sb, AuLock_NOPLMW);
16025 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16027 + err = PTR_ERR(h_file);
16028 + if (IS_ERR(h_file))
16032 + au_set_mmapped(file);
16033 + au_vm_file_reset(vma, h_file);
16035 + * we cannot call security_mmap_file() here since it may acquire
16036 + * mmap_sem or i_mutex.
16038 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16039 + * au_flag_conv(vma->vm_flags));
16042 + err = call_mmap(h_file, vma);
16044 + au_vm_prfile_set(vma, file);
16045 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16046 + goto out_fput; /* success */
16048 + au_unset_mmapped(file);
16049 + au_vm_file_reset(vma, file);
16053 + ii_write_unlock(inode);
16058 + si_read_unlock(sb);
16064 +/* ---------------------------------------------------------------------- */
16066 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16070 + struct au_write_pre wpre;
16071 + struct inode *inode;
16072 + struct file *h_file;
16074 + err = 0; /* -EBADF; */ /* posix? */
16075 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16078 + inode = file_inode(file);
16079 + au_mtx_and_read_lock(inode);
16082 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16083 + err = PTR_ERR(h_file);
16084 + if (IS_ERR(h_file))
16087 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16088 + au_write_post(inode, h_file, &wpre, /*written*/0);
16091 + si_read_unlock(inode->i_sb);
16092 + inode_unlock(inode);
16097 +static int aufs_fasync(int fd, struct file *file, int flag)
16100 + struct file *h_file;
16101 + struct super_block *sb;
16103 + sb = file->f_path.dentry->d_sb;
16104 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16106 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16107 + err = PTR_ERR(h_file);
16108 + if (IS_ERR(h_file))
16111 + if (h_file->f_op->fasync)
16112 + err = h_file->f_op->fasync(fd, h_file, flag);
16113 + fput(h_file); /* instead of au_read_post() */
16116 + si_read_unlock(sb);
16120 +static int aufs_setfl(struct file *file, unsigned long arg)
16123 + struct file *h_file;
16124 + struct super_block *sb;
16126 + sb = file->f_path.dentry->d_sb;
16127 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16129 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16130 + err = PTR_ERR(h_file);
16131 + if (IS_ERR(h_file))
16134 + /* stop calling h_file->fasync */
16135 + arg |= vfsub_file_flags(file) & FASYNC;
16136 + err = setfl(/*unused fd*/-1, h_file, arg);
16137 + fput(h_file); /* instead of au_read_post() */
16140 + si_read_unlock(sb);
16144 +/* ---------------------------------------------------------------------- */
16146 +/* no one supports this operation, currently */
16147 +#if 0 /* reserved for future use */
16148 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16149 + size_t len, loff_t *pos, int more)
16154 +/* ---------------------------------------------------------------------- */
16156 +const struct file_operations aufs_file_fop = {
16157 + .owner = THIS_MODULE,
16159 + .llseek = default_llseek,
16161 + .read_iter = aufs_read_iter,
16162 + .write_iter = aufs_write_iter,
16164 +#ifdef CONFIG_AUFS_POLL
16165 + .poll = aufs_poll,
16167 + .unlocked_ioctl = aufs_ioctl_nondir,
16168 +#ifdef CONFIG_COMPAT
16169 + .compat_ioctl = aufs_compat_ioctl_nondir,
16171 + .mmap = aufs_mmap,
16172 + .open = aufs_open_nondir,
16173 + .flush = aufs_flush_nondir,
16174 + .release = aufs_release_nondir,
16175 + .fsync = aufs_fsync_nondir,
16176 + .fasync = aufs_fasync,
16177 + /* .sendpage = aufs_sendpage, */
16178 + .setfl = aufs_setfl,
16179 + .splice_write = aufs_splice_write,
16180 + .splice_read = aufs_splice_read,
16181 +#if 0 /* reserved for future use */
16182 + .aio_splice_write = aufs_aio_splice_write,
16183 + .aio_splice_read = aufs_aio_splice_read,
16185 + .fallocate = aufs_fallocate,
16186 + .copy_file_range = aufs_copy_file_range
16188 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16189 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16190 +++ linux/fs/aufs/fstype.h 2021-02-22 22:51:59.058078584 +0100
16192 +/* SPDX-License-Identifier: GPL-2.0 */
16194 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16196 + * This program, aufs is free software; you can redistribute it and/or modify
16197 + * it under the terms of the GNU General Public License as published by
16198 + * the Free Software Foundation; either version 2 of the License, or
16199 + * (at your option) any later version.
16201 + * This program is distributed in the hope that it will be useful,
16202 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16203 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16204 + * GNU General Public License for more details.
16206 + * You should have received a copy of the GNU General Public License
16207 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16211 + * judging filesystem type
16214 +#ifndef __AUFS_FSTYPE_H__
16215 +#define __AUFS_FSTYPE_H__
16219 +#include <linux/fs.h>
16220 +#include <linux/magic.h>
16221 +#include <linux/nfs_fs.h>
16222 +#include <linux/romfs_fs.h>
16224 +static inline int au_test_aufs(struct super_block *sb)
16226 + return sb->s_magic == AUFS_SUPER_MAGIC;
16229 +static inline const char *au_sbtype(struct super_block *sb)
16231 + return sb->s_type->name;
16234 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16236 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16237 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16243 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16245 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16246 + return sb->s_magic == ROMFS_MAGIC;
16252 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16254 +#if IS_ENABLED(CONFIG_CRAMFS)
16255 + return sb->s_magic == CRAMFS_MAGIC;
16260 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16262 +#if IS_ENABLED(CONFIG_NFS_FS)
16263 + return sb->s_magic == NFS_SUPER_MAGIC;
16269 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16271 +#if IS_ENABLED(CONFIG_FUSE_FS)
16272 + return sb->s_magic == FUSE_SUPER_MAGIC;
16278 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16280 +#if IS_ENABLED(CONFIG_XFS_FS)
16281 + return sb->s_magic == XFS_SB_MAGIC;
16287 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16289 +#ifdef CONFIG_TMPFS
16290 + return sb->s_magic == TMPFS_MAGIC;
16296 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16298 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16299 + return !strcmp(au_sbtype(sb), "ecryptfs");
16305 +static inline int au_test_ramfs(struct super_block *sb)
16307 + return sb->s_magic == RAMFS_MAGIC;
16310 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16312 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16313 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16319 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16321 +#ifdef CONFIG_PROC_FS
16322 + return sb->s_magic == PROC_SUPER_MAGIC;
16328 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16330 +#ifdef CONFIG_SYSFS
16331 + return sb->s_magic == SYSFS_MAGIC;
16337 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16339 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16340 + return sb->s_magic == CONFIGFS_MAGIC;
16346 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16348 +#if IS_ENABLED(CONFIG_MINIX_FS)
16349 + return sb->s_magic == MINIX3_SUPER_MAGIC
16350 + || sb->s_magic == MINIX2_SUPER_MAGIC
16351 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16352 + || sb->s_magic == MINIX_SUPER_MAGIC
16353 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16359 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16361 +#if IS_ENABLED(CONFIG_FAT_FS)
16362 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16368 +static inline int au_test_msdos(struct super_block *sb)
16370 + return au_test_fat(sb);
16373 +static inline int au_test_vfat(struct super_block *sb)
16375 + return au_test_fat(sb);
16378 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16380 +#ifdef CONFIG_SECURITYFS
16381 + return sb->s_magic == SECURITYFS_MAGIC;
16387 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16389 +#if IS_ENABLED(CONFIG_SQUASHFS)
16390 + return sb->s_magic == SQUASHFS_MAGIC;
16396 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16398 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16399 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16405 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16407 +#if IS_ENABLED(CONFIG_XENFS)
16408 + return sb->s_magic == XENFS_SUPER_MAGIC;
16414 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16416 +#ifdef CONFIG_DEBUG_FS
16417 + return sb->s_magic == DEBUGFS_MAGIC;
16423 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16425 +#if IS_ENABLED(CONFIG_NILFS)
16426 + return sb->s_magic == NILFS_SUPER_MAGIC;
16432 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16434 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16435 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16441 +/* ---------------------------------------------------------------------- */
16443 + * they can't be an aufs branch.
16445 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16448 +#ifndef CONFIG_AUFS_BR_RAMFS
16449 + au_test_ramfs(sb) ||
16451 + au_test_procfs(sb)
16452 + || au_test_sysfs(sb)
16453 + || au_test_configfs(sb)
16454 + || au_test_debugfs(sb)
16455 + || au_test_securityfs(sb)
16456 + || au_test_xenfs(sb)
16457 + || au_test_ecryptfs(sb)
16458 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16459 + || au_test_aufs(sb); /* will be supported in next version */
16462 +static inline int au_test_fs_remote(struct super_block *sb)
16464 + return !au_test_tmpfs(sb)
16465 +#ifdef CONFIG_AUFS_BR_RAMFS
16466 + && !au_test_ramfs(sb)
16468 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16471 +/* ---------------------------------------------------------------------- */
16474 + * Note: these functions (below) are created after reading ->getattr() in all
16475 + * filesystems under linux/fs. it means we have to do so in every update...
16479 + * some filesystems require getattr to refresh the inode attributes before
16481 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16482 + * and leave the work for d_revalidate()
16484 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16486 + return au_test_nfs(sb)
16487 + || au_test_fuse(sb)
16488 + /* || au_test_btrfs(sb) */ /* untested */
16493 + * filesystems which don't maintain i_size or i_blocks.
16495 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16497 + return au_test_xfs(sb)
16498 + || au_test_btrfs(sb)
16499 + || au_test_ubifs(sb)
16500 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16501 + /* || au_test_minix(sb) */ /* untested */
16506 + * filesystems which don't store the correct value in some of their inode
16509 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16511 + return au_test_fs_bad_iattr_size(sb)
16512 + || au_test_fat(sb)
16513 + || au_test_msdos(sb)
16514 + || au_test_vfat(sb);
16517 +/* they don't check i_nlink in link(2) */
16518 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16520 + return au_test_tmpfs(sb)
16521 +#ifdef CONFIG_AUFS_BR_RAMFS
16522 + || au_test_ramfs(sb)
16524 + || au_test_ubifs(sb)
16525 + || au_test_hfsplus(sb);
16529 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16531 +static inline int au_test_fs_notime(struct super_block *sb)
16533 + return au_test_nfs(sb)
16534 + || au_test_fuse(sb)
16535 + || au_test_ubifs(sb)
16539 +/* temporary support for i#1 in cramfs */
16540 +static inline int au_test_fs_unique_ino(struct inode *inode)
16542 + if (au_test_cramfs(inode->i_sb))
16543 + return inode->i_ino != 1;
16547 +/* ---------------------------------------------------------------------- */
16550 + * the filesystem where the xino files placed must support i/o after unlink and
16551 + * maintain i_size and i_blocks.
16553 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16555 + return au_test_fs_remote(sb)
16556 + || au_test_fs_bad_iattr_size(sb)
16557 + /* don't want unnecessary work for xino */
16558 + || au_test_aufs(sb)
16559 + || au_test_ecryptfs(sb)
16560 + || au_test_nilfs(sb);
16563 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16565 + return au_test_tmpfs(sb)
16566 + || au_test_ramfs(sb);
16570 + * test if the @sb is real-readonly.
16572 +static inline int au_test_fs_rr(struct super_block *sb)
16574 + return au_test_squashfs(sb)
16575 + || au_test_iso9660(sb)
16576 + || au_test_cramfs(sb)
16577 + || au_test_romfs(sb);
16581 + * test if the @inode is nfs with 'noacl' option
16582 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16584 +static inline int au_test_nfs_noacl(struct inode *inode)
16586 + return au_test_nfs(inode->i_sb)
16587 + /* && IS_POSIXACL(inode) */
16588 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16591 +#endif /* __KERNEL__ */
16592 +#endif /* __AUFS_FSTYPE_H__ */
16593 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16594 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16595 +++ linux/fs/aufs/hbl.h 2021-02-22 22:51:59.058078584 +0100
16597 +/* SPDX-License-Identifier: GPL-2.0 */
16599 + * Copyright (C) 2017-2020 Junjiro R. Okajima
16601 + * This program, aufs is free software; you can redistribute it and/or modify
16602 + * it under the terms of the GNU General Public License as published by
16603 + * the Free Software Foundation; either version 2 of the License, or
16604 + * (at your option) any later version.
16606 + * This program is distributed in the hope that it will be useful,
16607 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16608 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16609 + * GNU General Public License for more details.
16611 + * You should have received a copy of the GNU General Public License
16612 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16616 + * helpers for hlist_bl.h
16619 +#ifndef __AUFS_HBL_H__
16620 +#define __AUFS_HBL_H__
16624 +#include <linux/list_bl.h>
16626 +static inline void au_hbl_add(struct hlist_bl_node *node,
16627 + struct hlist_bl_head *hbl)
16629 + hlist_bl_lock(hbl);
16630 + hlist_bl_add_head(node, hbl);
16631 + hlist_bl_unlock(hbl);
16634 +static inline void au_hbl_del(struct hlist_bl_node *node,
16635 + struct hlist_bl_head *hbl)
16637 + hlist_bl_lock(hbl);
16638 + hlist_bl_del(node);
16639 + hlist_bl_unlock(hbl);
16642 +#define au_hbl_for_each(pos, head) \
16643 + for (pos = hlist_bl_first(head); \
16647 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16649 + unsigned long cnt;
16650 + struct hlist_bl_node *pos;
16653 + hlist_bl_lock(hbl);
16654 + au_hbl_for_each(pos, hbl)
16656 + hlist_bl_unlock(hbl);
16660 +#endif /* __KERNEL__ */
16661 +#endif /* __AUFS_HBL_H__ */
16662 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16663 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16664 +++ linux/fs/aufs/hfsnotify.c 2021-02-22 22:51:59.058078584 +0100
16666 +// SPDX-License-Identifier: GPL-2.0
16668 + * Copyright (C) 2005-2020 Junjiro R. Okajima
16670 + * This program, aufs is free software; you can redistribute it and/or modify
16671 + * it under the terms of the GNU General Public License as published by
16672 + * the Free Software Foundation; either version 2 of the License, or
16673 + * (at your option) any later version.
16675 + * This program is distributed in the hope that it will be useful,
16676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16678 + * GNU General Public License for more details.
16680 + * You should have received a copy of the GNU General Public License
16681 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16685 + * fsnotify for the lower directories
16690 +/* FS_IN_IGNORED is unnecessary */
16691 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16692 + | FS_CREATE | FS_EVENT_ON_CHILD);
16693 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16694 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16696 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16698 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16700 + /* AuDbg("here\n"); */
16701 + au_cache_free_hnotify(hn);
16702 + smp_mb__before_atomic(); /* for atomic64_dec */
16703 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16704 + wake_up(&au_hfsn_wq);
16707 +static int au_hfsn_alloc(struct au_hinode *hinode)
16710 + struct au_hnotify *hn;
16711 + struct super_block *sb;
16712 + struct au_branch *br;
16713 + struct fsnotify_mark *mark;
16714 + aufs_bindex_t bindex;
16716 + hn = hinode->hi_notify;
16717 + sb = hn->hn_aufs_inode->i_sb;
16718 + bindex = au_br_index(sb, hinode->hi_id);
16719 + br = au_sbr(sb, bindex);
16720 + AuDebugOn(!br->br_hfsn);
16722 + mark = &hn->hn_mark;
16723 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16724 + mark->mask = AuHfsnMask;
16726 + * by udba rename or rmdir, aufs assign a new inode to the known
16727 + * h_inode, so specify 1 to allow dups.
16730 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16736 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16738 + struct fsnotify_mark *mark;
16739 + unsigned long long ull;
16740 + struct fsnotify_group *group;
16742 + ull = atomic64_inc_return(&au_hfsn_ifree);
16745 + mark = &hn->hn_mark;
16746 + spin_lock(&mark->lock);
16747 + group = mark->group;
16748 + fsnotify_get_group(group);
16749 + spin_unlock(&mark->lock);
16751 + fsnotify_destroy_mark(mark, group);
16752 + fsnotify_put_mark(mark);
16753 + fsnotify_put_group(group);
16756 + /* free hn by myself */
16760 +/* ---------------------------------------------------------------------- */
16762 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16764 + struct fsnotify_mark *mark;
16766 + mark = &hinode->hi_notify->hn_mark;
16767 + spin_lock(&mark->lock);
16769 + AuDebugOn(mark->mask & AuHfsnMask);
16770 + mark->mask |= AuHfsnMask;
16772 + AuDebugOn(!(mark->mask & AuHfsnMask));
16773 + mark->mask &= ~AuHfsnMask;
16775 + spin_unlock(&mark->lock);
16776 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16779 +/* ---------------------------------------------------------------------- */
16781 +/* #define AuDbgHnotify */
16782 +#ifdef AuDbgHnotify
16783 +static char *au_hfsn_name(u32 mask)
16785 +#ifdef CONFIG_AUFS_DEBUG
16786 +#define test_ret(flag) \
16788 + if (mask & flag) \
16791 + test_ret(FS_ACCESS);
16792 + test_ret(FS_MODIFY);
16793 + test_ret(FS_ATTRIB);
16794 + test_ret(FS_CLOSE_WRITE);
16795 + test_ret(FS_CLOSE_NOWRITE);
16796 + test_ret(FS_OPEN);
16797 + test_ret(FS_MOVED_FROM);
16798 + test_ret(FS_MOVED_TO);
16799 + test_ret(FS_CREATE);
16800 + test_ret(FS_DELETE);
16801 + test_ret(FS_DELETE_SELF);
16802 + test_ret(FS_MOVE_SELF);
16803 + test_ret(FS_UNMOUNT);
16804 + test_ret(FS_Q_OVERFLOW);
16805 + test_ret(FS_IN_IGNORED);
16806 + test_ret(FS_ISDIR);
16807 + test_ret(FS_IN_ONESHOT);
16808 + test_ret(FS_EVENT_ON_CHILD);
16817 +/* ---------------------------------------------------------------------- */
16819 +static void au_hfsn_free_group(struct fsnotify_group *group)
16821 + struct au_br_hfsnotify *hfsn = group->private;
16823 + /* AuDbg("here\n"); */
16824 + au_kfree_try_rcu(hfsn);
16827 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16828 + u32 mask, const void *data, int data_type,
16829 + struct inode *dir,
16830 + const struct qstr *file_name, u32 cookie,
16831 + struct fsnotify_iter_info *iter_info)
16834 + struct au_hnotify *hnotify;
16835 + struct inode *h_dir, *h_inode;
16836 + struct fsnotify_mark *inode_mark;
16838 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16841 + /* if FS_UNMOUNT happens, there must be another bug */
16842 + AuDebugOn(mask & FS_UNMOUNT);
16843 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16848 +#ifdef AuDbgHnotify
16850 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16851 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16852 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16853 + h_dir->i_ino, mask, au_hfsn_name(mask),
16854 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16855 + /* WARN_ON(1); */
16860 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16861 + AuDebugOn(!inode_mark);
16862 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16863 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16869 +static struct fsnotify_ops au_hfsn_ops = {
16870 + .handle_event = au_hfsn_handle_event,
16871 + .free_group_priv = au_hfsn_free_group,
16872 + .free_mark = au_hfsn_free_mark
16875 +/* ---------------------------------------------------------------------- */
16877 +static void au_hfsn_fin_br(struct au_branch *br)
16879 + struct au_br_hfsnotify *hfsn;
16881 + hfsn = br->br_hfsn;
16884 + fsnotify_put_group(hfsn->hfsn_group);
16889 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16892 + struct fsnotify_group *group;
16893 + struct au_br_hfsnotify *hfsn;
16896 + br->br_hfsn = NULL;
16897 + if (!au_br_hnotifyable(perm))
16901 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16902 + if (unlikely(!hfsn))
16906 + group = fsnotify_alloc_group(&au_hfsn_ops);
16907 + if (IS_ERR(group)) {
16908 + err = PTR_ERR(group);
16909 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16913 + group->private = hfsn;
16914 + hfsn->hfsn_group = group;
16915 + br->br_hfsn = hfsn;
16916 + goto out; /* success */
16919 + au_kfree_try_rcu(hfsn);
16924 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16929 + if (!br->br_hfsn)
16930 + err = au_hfsn_init_br(br, perm);
16935 +/* ---------------------------------------------------------------------- */
16937 +static void au_hfsn_fin(void)
16939 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16940 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16943 +const struct au_hnotify_op au_hnotify_op = {
16944 + .ctl = au_hfsn_ctl,
16945 + .alloc = au_hfsn_alloc,
16946 + .free = au_hfsn_free,
16948 + .fin = au_hfsn_fin,
16950 + .reset_br = au_hfsn_reset_br,
16951 + .fin_br = au_hfsn_fin_br,
16952 + .init_br = au_hfsn_init_br
16954 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16955 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16956 +++ linux/fs/aufs/hfsplus.c 2021-02-22 22:51:59.058078584 +0100
16958 +// SPDX-License-Identifier: GPL-2.0
16960 + * Copyright (C) 2010-2020 Junjiro R. Okajima
16962 + * This program, aufs is free software; you can redistribute it and/or modify
16963 + * it under the terms of the GNU General Public License as published by
16964 + * the Free Software Foundation; either version 2 of the License, or
16965 + * (at your option) any later version.
16967 + * This program is distributed in the hope that it will be useful,
16968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16970 + * GNU General Public License for more details.
16972 + * You should have received a copy of the GNU General Public License
16973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16977 + * special support for filesystems which acquires an inode mutex
16978 + * at final closing a file, eg, hfsplus.
16980 + * This trick is very simple and stupid, just to open the file before really
16981 + * necessary open to tell hfsplus that this is not the final closing.
16982 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16983 + * and au_h_open_post() after releasing it.
16988 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16991 + struct file *h_file;
16992 + struct dentry *h_dentry;
16994 + h_dentry = au_h_dptr(dentry, bindex);
16995 + AuDebugOn(!h_dentry);
16996 + AuDebugOn(d_is_negative(h_dentry));
16999 + if (au_test_hfsplus(h_dentry->d_sb)
17000 + && d_is_reg(h_dentry))
17001 + h_file = au_h_open(dentry, bindex,
17002 + O_RDONLY | O_NOATIME | O_LARGEFILE,
17003 + /*file*/NULL, force_wr);
17007 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
17008 + struct file *h_file)
17010 + struct au_branch *br;
17014 + br = au_sbr(dentry->d_sb, bindex);
17015 + au_lcnt_dec(&br->br_nfiles);
17018 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17019 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17020 +++ linux/fs/aufs/hnotify.c 2021-02-22 22:51:59.058078584 +0100
17022 +// SPDX-License-Identifier: GPL-2.0
17024 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17026 + * This program, aufs is free software; you can redistribute it and/or modify
17027 + * it under the terms of the GNU General Public License as published by
17028 + * the Free Software Foundation; either version 2 of the License, or
17029 + * (at your option) any later version.
17031 + * This program is distributed in the hope that it will be useful,
17032 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17033 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17034 + * GNU General Public License for more details.
17036 + * You should have received a copy of the GNU General Public License
17037 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17041 + * abstraction to notify the direct changes on lower directories
17044 +/* #include <linux/iversion.h> */
17047 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17050 + struct au_hnotify *hn;
17053 + hn = au_cache_alloc_hnotify();
17055 + hn->hn_aufs_inode = inode;
17056 + hinode->hi_notify = hn;
17057 + err = au_hnotify_op.alloc(hinode);
17059 + if (unlikely(err)) {
17060 + hinode->hi_notify = NULL;
17061 + au_cache_free_hnotify(hn);
17063 + * The upper dir was removed by udba, but the same named
17064 + * dir left. In this case, aufs assigns a new inode
17065 + * number and set the monitor again.
17066 + * For the lower dir, the old monitor is still left.
17068 + if (err == -EEXIST)
17077 +void au_hn_free(struct au_hinode *hinode)
17079 + struct au_hnotify *hn;
17081 + hn = hinode->hi_notify;
17083 + hinode->hi_notify = NULL;
17084 + if (au_hnotify_op.free(hinode, hn))
17085 + au_cache_free_hnotify(hn);
17089 +/* ---------------------------------------------------------------------- */
17091 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17093 + if (hinode->hi_notify)
17094 + au_hnotify_op.ctl(hinode, do_set);
17097 +void au_hn_reset(struct inode *inode, unsigned int flags)
17099 + aufs_bindex_t bindex, bbot;
17100 + struct inode *hi;
17101 + struct dentry *iwhdentry;
17103 + bbot = au_ibbot(inode);
17104 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17105 + hi = au_h_iptr(inode, bindex);
17109 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17110 + iwhdentry = au_hi_wh(inode, bindex);
17114 + au_set_h_iptr(inode, bindex, NULL, 0);
17115 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17116 + flags & ~AuHi_XINO);
17119 + /* inode_unlock(hi); */
17123 +/* ---------------------------------------------------------------------- */
17125 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17128 + aufs_bindex_t bindex, bbot, bfound, btop;
17129 + struct inode *h_i;
17132 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17133 + pr_warn("branch root dir was changed\n");
17138 + bbot = au_ibbot(inode);
17139 + btop = au_ibtop(inode);
17140 +#if 0 /* reserved for future use */
17141 + if (bindex == bbot) {
17142 + /* keep this ino in rename case */
17146 + for (bindex = btop; bindex <= bbot; bindex++)
17147 + if (au_h_iptr(inode, bindex) == h_inode) {
17154 + for (bindex = btop; bindex <= bbot; bindex++) {
17155 + h_i = au_h_iptr(inode, bindex);
17159 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17160 + /* ignore this error */
17161 + /* bad action? */
17164 + /* children inode number will be broken */
17171 +static int hn_gen_tree(struct dentry *dentry)
17173 + int err, i, j, ndentry;
17174 + struct au_dcsub_pages dpages;
17175 + struct au_dpage *dpage;
17176 + struct dentry **dentries;
17178 + err = au_dpages_init(&dpages, GFP_NOFS);
17179 + if (unlikely(err))
17181 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17182 + if (unlikely(err))
17185 + for (i = 0; i < dpages.ndpage; i++) {
17186 + dpage = dpages.dpages + i;
17187 + dentries = dpage->dentries;
17188 + ndentry = dpage->ndentry;
17189 + for (j = 0; j < ndentry; j++) {
17190 + struct dentry *d;
17197 + if (d_really_is_positive(d))
17198 + /* todo: reset children xino?
17199 + cached children only? */
17200 + au_iigen_dec(d_inode(d));
17205 + au_dpages_free(&dpages);
17211 + * return 0 if processed.
17213 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17214 + const unsigned int isdir)
17217 + struct dentry *d;
17218 + struct qstr *dname;
17221 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17222 + pr_warn("branch root dir was changed\n");
17228 + AuDebugOn(!name);
17229 + au_iigen_dec(inode);
17230 + spin_lock(&inode->i_lock);
17231 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17232 + spin_lock(&d->d_lock);
17233 + dname = &d->d_name;
17234 + if (dname->len != nlen
17235 + && memcmp(dname->name, name, nlen)) {
17236 + spin_unlock(&d->d_lock);
17241 + spin_unlock(&d->d_lock);
17244 + spin_unlock(&inode->i_lock);
17246 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17247 + d = d_find_any_alias(inode);
17249 + au_iigen_dec(inode);
17253 + spin_lock(&d->d_lock);
17254 + dname = &d->d_name;
17255 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17256 + spin_unlock(&d->d_lock);
17257 + err = hn_gen_tree(d);
17258 + spin_lock(&d->d_lock);
17260 + spin_unlock(&d->d_lock);
17269 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17273 + if (IS_ROOT(dentry)) {
17274 + pr_warn("branch root dir was changed\n");
17280 + au_digen_dec(dentry);
17281 + if (d_really_is_positive(dentry))
17282 + au_iigen_dec(d_inode(dentry));
17284 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17285 + if (d_really_is_positive(dentry))
17286 + err = hn_gen_tree(dentry);
17293 +/* ---------------------------------------------------------------------- */
17295 +/* hnotify job flags */
17296 +#define AuHnJob_XINO0 1
17297 +#define AuHnJob_GEN (1 << 1)
17298 +#define AuHnJob_DIRENT (1 << 2)
17299 +#define AuHnJob_ISDIR (1 << 3)
17300 +#define AuHnJob_TRYXINO0 (1 << 4)
17301 +#define AuHnJob_MNTPNT (1 << 5)
17302 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17303 +#define au_fset_hnjob(flags, name) \
17304 + do { (flags) |= AuHnJob_##name; } while (0)
17305 +#define au_fclr_hnjob(flags, name) \
17306 + do { (flags) &= ~AuHnJob_##name; } while (0)
17314 +struct au_hnotify_args {
17315 + struct inode *h_dir, *dir, *h_child_inode;
17317 + unsigned int flags[AuHnLast];
17318 + unsigned int h_child_nlen;
17319 + char h_child_name[];
17322 +struct hn_job_args {
17323 + unsigned int flags;
17324 + struct inode *inode, *h_inode, *dir, *h_dir;
17325 + struct dentry *dentry;
17330 +static int hn_job(struct hn_job_args *a)
17332 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17336 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17337 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17339 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17342 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17343 + if (!a->h_inode->i_nlink
17344 + && !(a->h_inode->i_state & I_LINKABLE))
17345 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17346 + inode_unlock_shared(a->h_inode);
17349 + /* make the generation obsolete */
17350 + if (au_ftest_hnjob(a->flags, GEN)) {
17353 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17355 + if (e && a->dentry)
17356 + hn_gen_by_name(a->dentry, isdir);
17357 + /* ignore this error */
17360 + /* make dir entries obsolete */
17361 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17362 + struct au_vdir *vdir;
17364 + vdir = au_ivdir(a->inode);
17366 + vdir->vd_jiffy = 0;
17367 + /* IMustLock(a->inode); */
17368 + /* inode_inc_iversion(a->inode); */
17371 + /* can do nothing but warn */
17372 + if (au_ftest_hnjob(a->flags, MNTPNT)
17374 + && d_mountpoint(a->dentry))
17375 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17380 +/* ---------------------------------------------------------------------- */
17382 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17383 + struct inode *dir)
17385 + struct dentry *dentry, *d, *parent;
17386 + struct qstr *dname;
17388 + parent = d_find_any_alias(dir);
17393 + spin_lock(&parent->d_lock);
17394 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17395 + /* AuDbg("%pd\n", d); */
17396 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17397 + dname = &d->d_name;
17398 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17399 + goto cont_unlock;
17403 + goto cont_unlock;
17404 + if (au_dcount(d) > 0) {
17405 + dentry = dget_dlock(d);
17406 + spin_unlock(&d->d_lock);
17411 + spin_unlock(&d->d_lock);
17413 + spin_unlock(&parent->d_lock);
17417 + di_write_lock_child(dentry);
17422 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17423 + aufs_bindex_t bindex, ino_t h_ino)
17425 + struct inode *inode;
17430 + err = au_xino_read(sb, bindex, h_ino, &ino);
17432 + inode = ilookup(sb, ino);
17436 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17437 + pr_warn("wrong root branch\n");
17443 + ii_write_lock_child(inode);
17449 +static void au_hn_bh(void *_args)
17451 + struct au_hnotify_args *a = _args;
17452 + struct super_block *sb;
17453 + aufs_bindex_t bindex, bbot, bfound;
17454 + unsigned char xino, try_iput;
17456 + struct inode *inode;
17458 + struct hn_job_args args;
17459 + struct dentry *dentry;
17460 + struct au_sbinfo *sbinfo;
17462 + AuDebugOn(!_args);
17463 + AuDebugOn(!a->h_dir);
17464 + AuDebugOn(!a->dir);
17465 + AuDebugOn(!a->mask);
17466 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17467 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17468 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17473 + * do not lock a->dir->i_mutex here
17474 + * because of d_revalidate() may cause a deadlock.
17476 + sb = a->dir->i_sb;
17478 + sbinfo = au_sbi(sb);
17479 + AuDebugOn(!sbinfo);
17480 + si_write_lock(sb, AuLock_NOPLMW);
17482 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17483 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17484 + case FS_MOVED_FROM:
17485 + case FS_MOVED_TO:
17486 + AuWarn1("DIRREN with UDBA may not work correctly "
17487 + "for the direct rename(2)\n");
17490 + ii_read_lock_parent(a->dir);
17492 + bbot = au_ibbot(a->dir);
17493 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17494 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17498 + ii_read_unlock(a->dir);
17499 + if (unlikely(bfound < 0))
17502 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17504 + if (a->h_child_inode)
17505 + h_ino = a->h_child_inode->i_ino;
17507 + if (a->h_child_nlen
17508 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17509 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17510 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17513 + if (dentry && d_really_is_positive(dentry))
17514 + inode = d_inode(dentry);
17515 + if (xino && !inode && h_ino
17516 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17517 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17518 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17519 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17523 + args.flags = a->flags[AuHn_CHILD];
17524 + args.dentry = dentry;
17525 + args.inode = inode;
17526 + args.h_inode = a->h_child_inode;
17527 + args.dir = a->dir;
17528 + args.h_dir = a->h_dir;
17529 + args.h_name = a->h_child_name;
17530 + args.h_nlen = a->h_child_nlen;
17531 + err = hn_job(&args);
17533 + if (au_di(dentry))
17534 + di_write_unlock(dentry);
17537 + if (inode && try_iput) {
17538 + ii_write_unlock(inode);
17542 + ii_write_lock_parent(a->dir);
17543 + args.flags = a->flags[AuHn_PARENT];
17544 + args.dentry = NULL;
17545 + args.inode = a->dir;
17546 + args.h_inode = a->h_dir;
17548 + args.h_dir = NULL;
17549 + args.h_name = NULL;
17551 + err = hn_job(&args);
17552 + ii_write_unlock(a->dir);
17555 + iput(a->h_child_inode);
17558 + si_write_unlock(sb);
17559 + au_nwt_done(&sbinfo->si_nowait);
17563 +/* ---------------------------------------------------------------------- */
17565 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17566 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17569 + unsigned int flags[AuHnLast], f;
17570 + unsigned char isdir, isroot, wh;
17571 + struct inode *dir;
17572 + struct au_hnotify_args *args;
17573 + char *p, *h_child_name;
17576 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17577 + dir = igrab(hnotify->hn_aufs_inode);
17581 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17583 + h_child_name = (void *)h_child_qstr->name;
17584 + len = h_child_qstr->len;
17585 + if (h_child_name) {
17586 + if (len > AUFS_WH_PFX_LEN
17587 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17588 + h_child_name += AUFS_WH_PFX_LEN;
17589 + len -= AUFS_WH_PFX_LEN;
17595 + if (h_child_inode)
17596 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17597 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17598 + flags[AuHn_CHILD] = 0;
17600 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17601 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17602 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17603 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17604 + case FS_MOVED_FROM:
17605 + case FS_MOVED_TO:
17606 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17607 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17610 + AuDebugOn(!h_child_name);
17615 + * aufs never be able to get this child inode.
17616 + * revalidation should be in d_revalidate()
17617 + * by checking i_nlink, i_generation or d_unhashed().
17619 + AuDebugOn(!h_child_name);
17620 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17621 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17629 + h_child_inode = NULL;
17632 + /* iput() and kfree() will be called in au_hnotify() */
17633 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17634 + if (unlikely(!args)) {
17635 + AuErr1("no memory\n");
17639 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17640 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17641 + args->mask = mask;
17643 + args->h_dir = igrab(h_dir);
17644 + if (h_child_inode)
17645 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17646 + args->h_child_inode = h_child_inode;
17647 + args->h_child_nlen = len;
17649 + p = (void *)args;
17650 + p += sizeof(*args);
17651 + memcpy(p, h_child_name, len);
17655 + /* NFS fires the event for silly-renamed one from kworker */
17657 + if (!dir->i_nlink
17658 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17660 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17661 + if (unlikely(err)) {
17662 + pr_err("wkq %d\n", err);
17663 + iput(args->h_child_inode);
17664 + iput(args->h_dir);
17666 + au_kfree_rcu(args);
17673 +/* ---------------------------------------------------------------------- */
17675 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17679 + AuDebugOn(!(udba & AuOptMask_UDBA));
17682 + if (au_hnotify_op.reset_br)
17683 + err = au_hnotify_op.reset_br(udba, br, perm);
17688 +int au_hnotify_init_br(struct au_branch *br, int perm)
17693 + if (au_hnotify_op.init_br)
17694 + err = au_hnotify_op.init_br(br, perm);
17699 +void au_hnotify_fin_br(struct au_branch *br)
17701 + if (au_hnotify_op.fin_br)
17702 + au_hnotify_op.fin_br(br);
17705 +static void au_hn_destroy_cache(void)
17707 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17708 + au_cache[AuCache_HNOTIFY] = NULL;
17711 +int __init au_hnotify_init(void)
17716 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17717 + if (au_cache[AuCache_HNOTIFY]) {
17719 + if (au_hnotify_op.init)
17720 + err = au_hnotify_op.init();
17721 + if (unlikely(err))
17722 + au_hn_destroy_cache();
17728 +void au_hnotify_fin(void)
17730 + if (au_hnotify_op.fin)
17731 + au_hnotify_op.fin();
17733 + /* cf. au_cache_fin() */
17734 + if (au_cache[AuCache_HNOTIFY])
17735 + au_hn_destroy_cache();
17737 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17738 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17739 +++ linux/fs/aufs/iinfo.c 2021-02-22 22:51:59.061411920 +0100
17741 +// SPDX-License-Identifier: GPL-2.0
17743 + * Copyright (C) 2005-2020 Junjiro R. Okajima
17745 + * This program, aufs is free software; you can redistribute it and/or modify
17746 + * it under the terms of the GNU General Public License as published by
17747 + * the Free Software Foundation; either version 2 of the License, or
17748 + * (at your option) any later version.
17750 + * This program is distributed in the hope that it will be useful,
17751 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17752 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17753 + * GNU General Public License for more details.
17755 + * You should have received a copy of the GNU General Public License
17756 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17760 + * inode private data
17765 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17767 + struct inode *h_inode;
17768 + struct au_hinode *hinode;
17770 + IiMustAnyLock(inode);
17772 + hinode = au_hinode(au_ii(inode), bindex);
17773 + h_inode = hinode->hi_inode;
17774 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17778 +/* todo: hard/soft set? */
17779 +void au_hiput(struct au_hinode *hinode)
17781 + au_hn_free(hinode);
17782 + dput(hinode->hi_whdentry);
17783 + iput(hinode->hi_inode);
17786 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17788 + unsigned int flags;
17789 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17792 + if (au_opt_test(mnt_flags, XINO))
17793 + au_fset_hi(flags, XINO);
17794 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17795 + au_fset_hi(flags, HNOTIFY);
17799 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17800 + struct inode *h_inode, unsigned int flags)
17802 + struct au_hinode *hinode;
17803 + struct inode *hi;
17804 + struct au_iinfo *iinfo = au_ii(inode);
17806 + IiMustWriteLock(inode);
17808 + hinode = au_hinode(iinfo, bindex);
17809 + hi = hinode->hi_inode;
17810 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17813 + au_hiput(hinode);
17814 + hinode->hi_inode = h_inode;
17817 + struct super_block *sb = inode->i_sb;
17818 + struct au_branch *br;
17820 + AuDebugOn(inode->i_mode
17821 + && (h_inode->i_mode & S_IFMT)
17822 + != (inode->i_mode & S_IFMT));
17823 + if (bindex == iinfo->ii_btop)
17824 + au_cpup_igen(inode, h_inode);
17825 + br = au_sbr(sb, bindex);
17826 + hinode->hi_id = br->br_id;
17827 + if (au_ftest_hi(flags, XINO)) {
17828 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17830 + if (unlikely(err))
17831 + AuIOErr1("failed au_xino_write() %d\n", err);
17834 + if (au_ftest_hi(flags, HNOTIFY)
17835 + && au_br_hnotifyable(br->br_perm)) {
17836 + err = au_hn_alloc(hinode, inode);
17837 + if (unlikely(err))
17838 + AuIOErr1("au_hn_alloc() %d\n", err);
17843 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17844 + struct dentry *h_wh)
17846 + struct au_hinode *hinode;
17848 + IiMustWriteLock(inode);
17850 + hinode = au_hinode(au_ii(inode), bindex);
17851 + AuDebugOn(hinode->hi_whdentry);
17852 + hinode->hi_whdentry = h_wh;
17855 +void au_update_iigen(struct inode *inode, int half)
17857 + struct au_iinfo *iinfo;
17858 + struct au_iigen *iigen;
17859 + unsigned int sigen;
17861 + sigen = au_sigen(inode->i_sb);
17862 + iinfo = au_ii(inode);
17863 + iigen = &iinfo->ii_generation;
17864 + spin_lock(&iigen->ig_spin);
17865 + iigen->ig_generation = sigen;
17867 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17869 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17870 + spin_unlock(&iigen->ig_spin);
17873 +/* it may be called at remount time, too */
17874 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17876 + struct au_iinfo *iinfo;
17877 + aufs_bindex_t bindex, bbot;
17879 + AuDebugOn(au_is_bad_inode(inode));
17880 + IiMustWriteLock(inode);
17882 + iinfo = au_ii(inode);
17883 + if (do_put_zero && iinfo->ii_btop >= 0) {
17884 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17886 + struct inode *h_i;
17888 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17891 + && !(h_i->i_state & I_LINKABLE))
17892 + au_set_h_iptr(inode, bindex, NULL, 0);
17896 + iinfo->ii_btop = -1;
17897 + iinfo->ii_bbot = -1;
17898 + bbot = au_sbbot(inode->i_sb);
17899 + for (bindex = 0; bindex <= bbot; bindex++)
17900 + if (au_hinode(iinfo, bindex)->hi_inode) {
17901 + iinfo->ii_btop = bindex;
17904 + if (iinfo->ii_btop >= 0)
17905 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17906 + if (au_hinode(iinfo, bindex)->hi_inode) {
17907 + iinfo->ii_bbot = bindex;
17910 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17913 +/* ---------------------------------------------------------------------- */
17915 +void au_icntnr_init_once(void *_c)
17917 + struct au_icntnr *c = _c;
17918 + struct au_iinfo *iinfo = &c->iinfo;
17920 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17921 + au_rw_init(&iinfo->ii_rwsem);
17922 + inode_init_once(&c->vfs_inode);
17925 +void au_hinode_init(struct au_hinode *hinode)
17927 + hinode->hi_inode = NULL;
17928 + hinode->hi_id = -1;
17929 + au_hn_init(hinode);
17930 + hinode->hi_whdentry = NULL;
17933 +int au_iinfo_init(struct inode *inode)
17935 + struct au_iinfo *iinfo;
17936 + struct super_block *sb;
17937 + struct au_hinode *hi;
17940 + sb = inode->i_sb;
17941 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17942 + nbr = au_sbbot(sb) + 1;
17943 + if (unlikely(nbr <= 0))
17945 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17947 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17949 + iinfo->ii_hinode = hi;
17950 + for (i = 0; i < nbr; i++, hi++)
17951 + au_hinode_init(hi);
17953 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17954 + iinfo->ii_btop = -1;
17955 + iinfo->ii_bbot = -1;
17956 + iinfo->ii_vdir = NULL;
17962 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17965 + struct au_hinode *hip;
17967 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17970 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17973 + iinfo->ii_hinode = hip;
17974 + i = iinfo->ii_bbot + 1;
17976 + for (; i < nbr; i++, hip++)
17977 + au_hinode_init(hip);
17984 +void au_iinfo_fin(struct inode *inode)
17986 + struct au_iinfo *iinfo;
17987 + struct au_hinode *hi;
17988 + struct super_block *sb;
17989 + aufs_bindex_t bindex, bbot;
17990 + const unsigned char unlinked = !inode->i_nlink;
17992 + AuDebugOn(au_is_bad_inode(inode));
17994 + sb = inode->i_sb;
17995 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
17996 + if (si_pid_test(sb))
17997 + au_xino_delete_inode(inode, unlinked);
18000 + * it is safe to hide the dependency between sbinfo and
18004 + si_noflush_read_lock(sb);
18005 + au_xino_delete_inode(inode, unlinked);
18006 + si_read_unlock(sb);
18010 + iinfo = au_ii(inode);
18011 + if (iinfo->ii_vdir)
18012 + au_vdir_free(iinfo->ii_vdir);
18014 + bindex = iinfo->ii_btop;
18015 + if (bindex >= 0) {
18016 + hi = au_hinode(iinfo, bindex);
18017 + bbot = iinfo->ii_bbot;
18018 + while (bindex++ <= bbot) {
18019 + if (hi->hi_inode)
18024 + au_kfree_rcu(iinfo->ii_hinode);
18025 + AuRwDestroy(&iinfo->ii_rwsem);
18027 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18028 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18029 +++ linux/fs/aufs/inode.c 2021-02-22 22:51:59.061411920 +0100
18031 +// SPDX-License-Identifier: GPL-2.0
18033 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18035 + * This program, aufs is free software; you can redistribute it and/or modify
18036 + * it under the terms of the GNU General Public License as published by
18037 + * the Free Software Foundation; either version 2 of the License, or
18038 + * (at your option) any later version.
18040 + * This program is distributed in the hope that it will be useful,
18041 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18042 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18043 + * GNU General Public License for more details.
18045 + * You should have received a copy of the GNU General Public License
18046 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18050 + * inode functions
18053 +#include <linux/iversion.h>
18056 +struct inode *au_igrab(struct inode *inode)
18059 + AuDebugOn(!atomic_read(&inode->i_count));
18065 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18067 + au_cpup_attr_all(inode, /*force*/0);
18068 + au_update_iigen(inode, /*half*/1);
18070 + inode_inc_iversion(inode);
18073 +static int au_ii_refresh(struct inode *inode, int *update)
18077 + aufs_bindex_t bindex, new_bindex;
18078 + struct super_block *sb;
18079 + struct au_iinfo *iinfo;
18080 + struct au_hinode *p, *q, tmp;
18082 + AuDebugOn(au_is_bad_inode(inode));
18083 + IiMustWriteLock(inode);
18086 + sb = inode->i_sb;
18087 + nbr = au_sbbot(sb) + 1;
18088 + type = inode->i_mode & S_IFMT;
18089 + iinfo = au_ii(inode);
18090 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18091 + if (unlikely(err))
18094 + AuDebugOn(iinfo->ii_btop < 0);
18095 + p = au_hinode(iinfo, iinfo->ii_btop);
18096 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18098 + if (!p->hi_inode)
18101 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18102 + new_bindex = au_br_index(sb, p->hi_id);
18103 + if (new_bindex == bindex)
18106 + if (new_bindex < 0) {
18109 + p->hi_inode = NULL;
18113 + if (new_bindex < iinfo->ii_btop)
18114 + iinfo->ii_btop = new_bindex;
18115 + if (iinfo->ii_bbot < new_bindex)
18116 + iinfo->ii_bbot = new_bindex;
18117 + /* swap two lower inode, and loop again */
18118 + q = au_hinode(iinfo, new_bindex);
18122 + if (tmp.hi_inode) {
18127 + au_update_ibrange(inode, /*do_put_zero*/0);
18128 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18129 + e = au_dy_irefresh(inode);
18130 + if (unlikely(e && !err))
18138 +void au_refresh_iop(struct inode *inode, int force_getattr)
18141 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18142 + const struct inode_operations *iop
18143 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18145 + if (inode->i_op == iop)
18148 + switch (inode->i_mode & S_IFMT) {
18150 + type = AuIop_DIR;
18153 + type = AuIop_SYMLINK;
18156 + type = AuIop_OTHER;
18160 + inode->i_op = iop + type;
18161 + /* unnecessary smp_wmb() */
18164 +int au_refresh_hinode_self(struct inode *inode)
18168 + err = au_ii_refresh(inode, &update);
18170 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18176 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18178 + int err, e, update;
18179 + unsigned int flags;
18181 + aufs_bindex_t bindex, bbot;
18182 + unsigned char isdir;
18183 + struct au_hinode *p;
18184 + struct au_iinfo *iinfo;
18186 + err = au_ii_refresh(inode, &update);
18187 + if (unlikely(err))
18191 + iinfo = au_ii(inode);
18192 + p = au_hinode(iinfo, iinfo->ii_btop);
18193 + mode = (inode->i_mode & S_IFMT);
18194 + isdir = S_ISDIR(mode);
18195 + flags = au_hi_flags(inode, isdir);
18196 + bbot = au_dbbot(dentry);
18197 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18198 + struct inode *h_i, *h_inode;
18199 + struct dentry *h_d;
18201 + h_d = au_h_dptr(dentry, bindex);
18202 + if (!h_d || d_is_negative(h_d))
18205 + h_inode = d_inode(h_d);
18206 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18207 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18208 + h_i = au_h_iptr(inode, bindex);
18210 + if (h_i == h_inode)
18216 + if (bindex < iinfo->ii_btop)
18217 + iinfo->ii_btop = bindex;
18218 + if (iinfo->ii_bbot < bindex)
18219 + iinfo->ii_bbot = bindex;
18220 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18223 + au_update_ibrange(inode, /*do_put_zero*/0);
18224 + e = au_dy_irefresh(inode);
18225 + if (unlikely(e && !err))
18228 + au_refresh_hinode_attr(inode, update && isdir);
18235 +static int set_inode(struct inode *inode, struct dentry *dentry)
18238 + unsigned int flags;
18240 + aufs_bindex_t bindex, btop, btail;
18241 + unsigned char isdir;
18242 + struct dentry *h_dentry;
18243 + struct inode *h_inode;
18244 + struct au_iinfo *iinfo;
18245 + const struct inode_operations *iop;
18247 + IiMustWriteLock(inode);
18251 + iop = au_sbi(inode->i_sb)->si_iop_array;
18252 + btop = au_dbtop(dentry);
18253 + h_dentry = au_h_dptr(dentry, btop);
18254 + h_inode = d_inode(h_dentry);
18255 + mode = h_inode->i_mode;
18256 + switch (mode & S_IFMT) {
18258 + btail = au_dbtail(dentry);
18259 + inode->i_op = iop + AuIop_OTHER;
18260 + inode->i_fop = &aufs_file_fop;
18261 + err = au_dy_iaop(inode, btop, h_inode);
18262 + if (unlikely(err))
18267 + btail = au_dbtaildir(dentry);
18268 + inode->i_op = iop + AuIop_DIR;
18269 + inode->i_fop = &aufs_dir_fop;
18272 + btail = au_dbtail(dentry);
18273 + inode->i_op = iop + AuIop_SYMLINK;
18279 + btail = au_dbtail(dentry);
18280 + inode->i_op = iop + AuIop_OTHER;
18281 + init_special_inode(inode, mode, h_inode->i_rdev);
18284 + AuIOErr("Unknown file type 0%o\n", mode);
18289 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18290 + flags = au_hi_flags(inode, isdir);
18291 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18292 + && au_ftest_hi(flags, HNOTIFY)
18293 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18294 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18295 + au_fclr_hi(flags, HNOTIFY);
18296 + iinfo = au_ii(inode);
18297 + iinfo->ii_btop = btop;
18298 + iinfo->ii_bbot = btail;
18299 + for (bindex = btop; bindex <= btail; bindex++) {
18300 + h_dentry = au_h_dptr(dentry, bindex);
18302 + au_set_h_iptr(inode, bindex,
18303 + au_igrab(d_inode(h_dentry)), flags);
18305 + au_cpup_attr_all(inode, /*force*/1);
18307 + * to force calling aufs_get_acl() every time,
18308 + * do not call cache_no_acl() for aufs inode.
18316 + * successful returns with iinfo write_locked
18318 + * zero: success, matched
18319 + * plus: no error, but unmatched
18321 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18324 + unsigned int gen, igflags;
18325 + aufs_bindex_t bindex, bbot;
18326 + struct inode *h_inode, *h_dinode;
18327 + struct dentry *h_dentry;
18330 + * before this function, if aufs got any iinfo lock, it must be only
18331 + * one, the parent dir.
18332 + * it can happen by UDBA and the obsoleted inode number.
18335 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18339 + ii_write_lock_new_child(inode);
18340 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18341 + h_dinode = d_inode(h_dentry);
18342 + bbot = au_ibbot(inode);
18343 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18344 + h_inode = au_h_iptr(inode, bindex);
18345 + if (!h_inode || h_inode != h_dinode)
18349 + gen = au_iigen(inode, &igflags);
18350 + if (gen == au_digen(dentry)
18351 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18354 + /* fully refresh inode using dentry */
18355 + err = au_refresh_hinode(inode, dentry);
18357 + au_update_iigen(inode, /*half*/0);
18361 + if (unlikely(err))
18362 + ii_write_unlock(inode);
18367 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18368 + unsigned int d_type, ino_t *ino)
18371 + const int isnondir = d_type != DT_DIR;
18373 + /* prevent hardlinked inode number from race condition */
18375 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18376 + if (unlikely(err))
18380 + err = au_xino_read(sb, bindex, h_ino, ino);
18381 + if (unlikely(err))
18382 + goto out_xinondir;
18386 + *ino = au_xino_new_ino(sb);
18387 + if (unlikely(!*ino))
18388 + goto out_xinondir;
18389 + err = au_xino_write(sb, bindex, h_ino, *ino);
18390 + if (unlikely(err))
18391 + goto out_xinondir;
18395 + if (isnondir && idx >= 0)
18396 + au_xinondir_leave(sb, bindex, h_ino, idx);
18401 +/* successful returns with iinfo write_locked */
18402 +/* todo: return with unlocked? */
18403 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18405 + struct inode *inode, *h_inode;
18406 + struct dentry *h_dentry;
18407 + struct super_block *sb;
18408 + ino_t h_ino, ino;
18409 + int err, idx, hlinked;
18410 + aufs_bindex_t btop;
18412 + sb = dentry->d_sb;
18413 + btop = au_dbtop(dentry);
18414 + h_dentry = au_h_dptr(dentry, btop);
18415 + h_inode = d_inode(h_dentry);
18416 + h_ino = h_inode->i_ino;
18417 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18421 + * stop 'race'-ing between hardlinks under different
18425 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18426 + inode = ERR_PTR(err);
18427 + if (unlikely(err))
18431 + err = au_xino_read(sb, btop, h_ino, &ino);
18432 + inode = ERR_PTR(err);
18433 + if (unlikely(err))
18434 + goto out_xinondir;
18437 + ino = au_xino_new_ino(sb);
18438 + if (unlikely(!ino)) {
18439 + inode = ERR_PTR(-EIO);
18440 + goto out_xinondir;
18444 + AuDbg("i%lu\n", (unsigned long)ino);
18445 + inode = au_iget_locked(sb, ino);
18446 + err = PTR_ERR(inode);
18447 + if (IS_ERR(inode))
18448 + goto out_xinondir;
18450 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18451 + if (inode->i_state & I_NEW) {
18452 + ii_write_lock_new_child(inode);
18453 + err = set_inode(inode, dentry);
18455 + unlock_new_inode(inode);
18456 + goto out_xinondir; /* success */
18460 + * iget_failed() calls iput(), but we need to call
18461 + * ii_write_unlock() after iget_failed(). so dirty hack for
18464 + atomic_inc(&inode->i_count);
18465 + iget_failed(inode);
18466 + ii_write_unlock(inode);
18467 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18468 + /* ignore this error */
18470 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18472 + * horrible race condition between lookup, readdir and copyup
18473 + * (or something).
18475 + if (hlinked && idx >= 0)
18476 + au_xinondir_leave(sb, btop, h_ino, idx);
18477 + err = reval_inode(inode, dentry);
18478 + if (unlikely(err < 0)) {
18483 + goto out; /* success */
18484 + else if (hlinked && idx >= 0) {
18485 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18486 + if (unlikely(err)) {
18488 + inode = ERR_PTR(err);
18494 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18495 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18496 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18497 + btop, au_sbtype(h_dentry->d_sb), dentry,
18498 + (unsigned long)h_ino, (unsigned long)ino);
18500 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18503 + if (hlinked && idx >= 0)
18504 + au_xinondir_leave(sb, btop, h_ino, idx);
18510 + inode = ERR_PTR(err);
18512 + if (hlinked && idx >= 0)
18513 + au_xinondir_leave(sb, btop, h_ino, idx);
18518 +/* ---------------------------------------------------------------------- */
18520 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18521 + struct inode *inode)
18524 + struct inode *hi;
18526 + err = au_br_rdonly(au_sbr(sb, bindex));
18528 + /* pseudo-link after flushed may happen out of bounds */
18531 + && au_ibtop(inode) <= bindex
18532 + && bindex <= au_ibbot(inode)) {
18534 + * permission check is unnecessary since vfsub routine
18535 + * will be called later
18537 + hi = au_h_iptr(inode, bindex);
18539 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18545 +int au_test_h_perm(struct inode *h_inode, int mask)
18547 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18549 + return inode_permission(h_inode, mask);
18552 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18554 + if (au_test_nfs(h_inode->i_sb)
18555 + && (mask & MAY_WRITE)
18556 + && S_ISDIR(h_inode->i_mode))
18557 + mask |= MAY_READ; /* force permission check */
18558 + return au_test_h_perm(h_inode, mask);
18560 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18561 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18562 +++ linux/fs/aufs/inode.h 2021-02-22 22:51:59.061411920 +0100
18564 +/* SPDX-License-Identifier: GPL-2.0 */
18566 + * Copyright (C) 2005-2020 Junjiro R. Okajima
18568 + * This program, aufs is free software; you can redistribute it and/or modify
18569 + * it under the terms of the GNU General Public License as published by
18570 + * the Free Software Foundation; either version 2 of the License, or
18571 + * (at your option) any later version.
18573 + * This program is distributed in the hope that it will be useful,
18574 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18575 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18576 + * GNU General Public License for more details.
18578 + * You should have received a copy of the GNU General Public License
18579 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18583 + * inode operations
18586 +#ifndef __AUFS_INODE_H__
18587 +#define __AUFS_INODE_H__
18591 +#include <linux/fsnotify.h>
18592 +#include "rwsem.h"
18596 +struct au_hnotify {
18597 +#ifdef CONFIG_AUFS_HNOTIFY
18598 +#ifdef CONFIG_AUFS_HFSNOTIFY
18599 + /* never use fsnotify_add_vfsmount_mark() */
18600 + struct fsnotify_mark hn_mark;
18602 + struct inode *hn_aufs_inode; /* no get/put */
18603 + struct rcu_head rcu;
18605 +} ____cacheline_aligned_in_smp;
18607 +struct au_hinode {
18608 + struct inode *hi_inode;
18609 + aufs_bindex_t hi_id;
18610 +#ifdef CONFIG_AUFS_HNOTIFY
18611 + struct au_hnotify *hi_notify;
18614 + /* reference to the copied-up whiteout with get/put */
18615 + struct dentry *hi_whdentry;
18619 +#define AuIG_HALF_REFRESHED 1
18620 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18621 +#define au_ig_fset(flags, name) \
18622 + do { (flags) |= AuIG_##name; } while (0)
18623 +#define au_ig_fclr(flags, name) \
18624 + do { (flags) &= ~AuIG_##name; } while (0)
18627 + spinlock_t ig_spin;
18628 + __u32 ig_generation, ig_flags;
18633 + struct au_iigen ii_generation;
18634 + struct super_block *ii_hsb1; /* no get/put */
18636 + struct au_rwsem ii_rwsem;
18637 + aufs_bindex_t ii_btop, ii_bbot;
18639 + struct au_hinode *ii_hinode;
18640 + struct au_vdir *ii_vdir;
18643 +struct au_icntnr {
18644 + struct au_iinfo iinfo;
18645 + struct inode vfs_inode;
18646 + struct hlist_bl_node plink;
18647 + struct rcu_head rcu;
18648 +} ____cacheline_aligned_in_smp;
18650 +/* au_pin flags */
18651 +#define AuPin_DI_LOCKED 1
18652 +#define AuPin_MNT_WRITE (1 << 1)
18653 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18654 +#define au_fset_pin(flags, name) \
18655 + do { (flags) |= AuPin_##name; } while (0)
18656 +#define au_fclr_pin(flags, name) \
18657 + do { (flags) &= ~AuPin_##name; } while (0)
18661 + struct dentry *dentry;
18662 + unsigned int udba;
18663 + unsigned char lsc_di, lsc_hi, flags;
18664 + aufs_bindex_t bindex;
18667 + struct dentry *parent;
18668 + struct au_hinode *hdir;
18669 + struct vfsmount *h_mnt;
18671 + /* temporary unlock/relock for copyup */
18672 + struct dentry *h_dentry, *h_parent;
18673 + struct au_branch *br;
18674 + struct task_struct *task;
18677 +void au_pin_hdir_unlock(struct au_pin *p);
18678 +int au_pin_hdir_lock(struct au_pin *p);
18679 +int au_pin_hdir_relock(struct au_pin *p);
18680 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18681 +void au_pin_hdir_release(struct au_pin *p);
18683 +/* ---------------------------------------------------------------------- */
18685 +static inline struct au_iinfo *au_ii(struct inode *inode)
18687 + BUG_ON(is_bad_inode(inode));
18688 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18691 +/* ---------------------------------------------------------------------- */
18694 +struct inode *au_igrab(struct inode *inode);
18695 +void au_refresh_iop(struct inode *inode, int force_getattr);
18696 +int au_refresh_hinode_self(struct inode *inode);
18697 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18698 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18699 + unsigned int d_type, ino_t *ino);
18700 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18701 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18702 + struct inode *inode);
18703 +int au_test_h_perm(struct inode *h_inode, int mask);
18704 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18706 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18707 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18709 +#ifdef CONFIG_AUFS_SHWH
18710 + return au_ino(sb, bindex, h_ino, d_type, ino);
18723 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18724 + aufs_iop_nogetattr[AuIop_Last];
18726 +/* au_wr_dir flags */
18727 +#define AuWrDir_ADD_ENTRY 1
18728 +#define AuWrDir_ISDIR (1 << 1)
18729 +#define AuWrDir_TMPFILE (1 << 2)
18730 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18731 +#define au_fset_wrdir(flags, name) \
18732 + do { (flags) |= AuWrDir_##name; } while (0)
18733 +#define au_fclr_wrdir(flags, name) \
18734 + do { (flags) &= ~AuWrDir_##name; } while (0)
18736 +struct au_wr_dir_args {
18737 + aufs_bindex_t force_btgt;
18738 + unsigned char flags;
18740 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18741 + struct au_wr_dir_args *args);
18743 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18744 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18745 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18746 + unsigned int udba, unsigned char flags);
18747 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18748 + unsigned int udba, unsigned char flags) __must_check;
18749 +int au_do_pin(struct au_pin *pin) __must_check;
18750 +void au_unpin(struct au_pin *pin);
18751 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18753 +#define AuIcpup_DID_CPUP 1
18754 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18755 +#define au_fset_icpup(flags, name) \
18756 + do { (flags) |= AuIcpup_##name; } while (0)
18757 +#define au_fclr_icpup(flags, name) \
18758 + do { (flags) &= ~AuIcpup_##name; } while (0)
18760 +struct au_icpup_args {
18761 + unsigned char flags;
18762 + unsigned char pin_flags;
18763 + aufs_bindex_t btgt;
18764 + unsigned int udba;
18765 + struct au_pin pin;
18766 + struct path h_path;
18767 + struct inode *h_inode;
18770 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18771 + struct au_icpup_args *a);
18773 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18774 + struct path *h_path, int locked);
18777 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18778 + struct dentry *h_parent, int isdir);
18779 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18781 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18782 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18784 +struct vfsub_aopen_args;
18785 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18786 + struct vfsub_aopen_args *args);
18787 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18788 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18789 + struct dentry *dentry);
18790 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18793 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18794 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18795 + struct dentry *h_parent, int isdir);
18796 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18797 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18800 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18801 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18802 + struct inode *dir, struct dentry *dentry,
18803 + unsigned int flags);
18806 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18807 +void au_hiput(struct au_hinode *hinode);
18808 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18809 + struct dentry *h_wh);
18810 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18812 +/* hinode flags */
18813 +#define AuHi_XINO 1
18814 +#define AuHi_HNOTIFY (1 << 1)
18815 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18816 +#define au_fset_hi(flags, name) \
18817 + do { (flags) |= AuHi_##name; } while (0)
18818 +#define au_fclr_hi(flags, name) \
18819 + do { (flags) &= ~AuHi_##name; } while (0)
18821 +#ifndef CONFIG_AUFS_HNOTIFY
18822 +#undef AuHi_HNOTIFY
18823 +#define AuHi_HNOTIFY 0
18826 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18827 + struct inode *h_inode, unsigned int flags);
18829 +void au_update_iigen(struct inode *inode, int half);
18830 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18832 +void au_icntnr_init_once(void *_c);
18833 +void au_hinode_init(struct au_hinode *hinode);
18834 +int au_iinfo_init(struct inode *inode);
18835 +void au_iinfo_fin(struct inode *inode);
18836 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18838 +#ifdef CONFIG_PROC_FS
18840 +int au_plink_maint(struct super_block *sb, int flags);
18842 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18843 +int au_plink_maint_enter(struct super_block *sb);
18844 +#ifdef CONFIG_AUFS_DEBUG
18845 +void au_plink_list(struct super_block *sb);
18847 +AuStubVoid(au_plink_list, struct super_block *sb)
18849 +int au_plink_test(struct inode *inode);
18850 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18851 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18852 + struct dentry *h_dentry);
18853 +void au_plink_put(struct super_block *sb, int verbose);
18854 +void au_plink_clean(struct super_block *sb, int verbose);
18855 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18857 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18858 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18859 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18860 +AuStubVoid(au_plink_list, struct super_block *sb);
18861 +AuStubInt0(au_plink_test, struct inode *inode);
18862 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18863 + struct inode *inode, aufs_bindex_t bindex);
18864 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18865 + struct dentry *h_dentry);
18866 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18867 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18868 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18869 +#endif /* CONFIG_PROC_FS */
18871 +#ifdef CONFIG_AUFS_XATTR
18873 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18874 + unsigned int verbose);
18875 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18876 +void au_xattr_init(struct super_block *sb);
18878 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18879 + int ignore_flags, unsigned int verbose);
18880 +AuStubVoid(au_xattr_init, struct super_block *sb);
18883 +#ifdef CONFIG_FS_POSIX_ACL
18884 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18885 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18888 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18894 +struct au_sxattr {
18898 + const char *name;
18899 + const void *value;
18904 + struct posix_acl *acl;
18909 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18910 + struct au_sxattr *arg);
18913 +/* ---------------------------------------------------------------------- */
18915 +/* lock subclass for iinfo */
18917 + AuLsc_II_CHILD, /* child first */
18918 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18919 + AuLsc_II_CHILD3, /* copyup dirs */
18920 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18921 + AuLsc_II_PARENT2,
18922 + AuLsc_II_PARENT3, /* copyup dirs */
18923 + AuLsc_II_NEW_CHILD
18927 + * ii_read_lock_child, ii_write_lock_child,
18928 + * ii_read_lock_child2, ii_write_lock_child2,
18929 + * ii_read_lock_child3, ii_write_lock_child3,
18930 + * ii_read_lock_parent, ii_write_lock_parent,
18931 + * ii_read_lock_parent2, ii_write_lock_parent2,
18932 + * ii_read_lock_parent3, ii_write_lock_parent3,
18933 + * ii_read_lock_new_child, ii_write_lock_new_child,
18935 +#define AuReadLockFunc(name, lsc) \
18936 +static inline void ii_read_lock_##name(struct inode *i) \
18938 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18941 +#define AuWriteLockFunc(name, lsc) \
18942 +static inline void ii_write_lock_##name(struct inode *i) \
18944 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18947 +#define AuRWLockFuncs(name, lsc) \
18948 + AuReadLockFunc(name, lsc) \
18949 + AuWriteLockFunc(name, lsc)
18951 +AuRWLockFuncs(child, CHILD);
18952 +AuRWLockFuncs(child2, CHILD2);
18953 +AuRWLockFuncs(child3, CHILD3);
18954 +AuRWLockFuncs(parent, PARENT);
18955 +AuRWLockFuncs(parent2, PARENT2);
18956 +AuRWLockFuncs(parent3, PARENT3);
18957 +AuRWLockFuncs(new_child, NEW_CHILD);
18959 +#undef AuReadLockFunc
18960 +#undef AuWriteLockFunc
18961 +#undef AuRWLockFuncs
18963 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18964 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18965 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18967 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18968 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18969 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18971 +/* ---------------------------------------------------------------------- */
18973 +static inline void au_icntnr_init(struct au_icntnr *c)
18975 +#ifdef CONFIG_AUFS_DEBUG
18976 + c->vfs_inode.i_mode = 0;
18980 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18982 + unsigned int gen;
18983 + struct au_iinfo *iinfo;
18984 + struct au_iigen *iigen;
18986 + iinfo = au_ii(inode);
18987 + iigen = &iinfo->ii_generation;
18988 + spin_lock(&iigen->ig_spin);
18990 + *igflags = iigen->ig_flags;
18991 + gen = iigen->ig_generation;
18992 + spin_unlock(&iigen->ig_spin);
18997 +/* tiny test for inode number */
18998 +/* tmpfs generation is too rough */
18999 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
19001 + struct au_iinfo *iinfo;
19003 + iinfo = au_ii(inode);
19004 + AuRwMustAnyLock(&iinfo->ii_rwsem);
19005 + return !(iinfo->ii_hsb1 == h_inode->i_sb
19006 + && iinfo->ii_higen == h_inode->i_generation);
19009 +static inline void au_iigen_dec(struct inode *inode)
19011 + struct au_iinfo *iinfo;
19012 + struct au_iigen *iigen;
19014 + iinfo = au_ii(inode);
19015 + iigen = &iinfo->ii_generation;
19016 + spin_lock(&iigen->ig_spin);
19017 + iigen->ig_generation--;
19018 + spin_unlock(&iigen->ig_spin);
19021 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19026 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19032 +/* ---------------------------------------------------------------------- */
19034 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19035 + aufs_bindex_t bindex)
19037 + return iinfo->ii_hinode + bindex;
19040 +static inline int au_is_bad_inode(struct inode *inode)
19042 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19045 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19046 + aufs_bindex_t bindex)
19048 + IiMustAnyLock(inode);
19049 + return au_hinode(au_ii(inode), bindex)->hi_id;
19052 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19054 + IiMustAnyLock(inode);
19055 + return au_ii(inode)->ii_btop;
19058 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19060 + IiMustAnyLock(inode);
19061 + return au_ii(inode)->ii_bbot;
19064 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19066 + IiMustAnyLock(inode);
19067 + return au_ii(inode)->ii_vdir;
19070 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19072 + IiMustAnyLock(inode);
19073 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19076 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19078 + IiMustWriteLock(inode);
19079 + au_ii(inode)->ii_btop = bindex;
19082 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19084 + IiMustWriteLock(inode);
19085 + au_ii(inode)->ii_bbot = bindex;
19088 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19090 + IiMustWriteLock(inode);
19091 + au_ii(inode)->ii_vdir = vdir;
19094 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19096 + IiMustAnyLock(inode);
19097 + return au_hinode(au_ii(inode), bindex);
19100 +/* ---------------------------------------------------------------------- */
19102 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19105 + return pin->parent;
19109 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19111 + if (pin && pin->hdir)
19112 + return pin->hdir->hi_inode;
19116 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19119 + return pin->hdir;
19123 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19126 + pin->dentry = dentry;
19129 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19130 + unsigned char lflag)
19134 + au_fset_pin(pin->flags, DI_LOCKED);
19136 + au_fclr_pin(pin->flags, DI_LOCKED);
19140 +#if 0 /* reserved */
19141 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19144 + dput(pin->parent);
19145 + pin->parent = dget(parent);
19150 +/* ---------------------------------------------------------------------- */
19153 +#ifdef CONFIG_AUFS_HNOTIFY
19154 +struct au_hnotify_op {
19155 + void (*ctl)(struct au_hinode *hinode, int do_set);
19156 + int (*alloc)(struct au_hinode *hinode);
19159 + * if it returns true, the caller should free hinode->hi_notify,
19160 + * otherwise ->free() frees it.
19162 + int (*free)(struct au_hinode *hinode,
19163 + struct au_hnotify *hn) __must_check;
19165 + void (*fin)(void);
19166 + int (*init)(void);
19168 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19169 + void (*fin_br)(struct au_branch *br);
19170 + int (*init_br)(struct au_branch *br, int perm);
19174 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19175 +void au_hn_free(struct au_hinode *hinode);
19176 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19177 +void au_hn_reset(struct inode *inode, unsigned int flags);
19178 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19179 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19180 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19181 +int au_hnotify_init_br(struct au_branch *br, int perm);
19182 +void au_hnotify_fin_br(struct au_branch *br);
19183 +int __init au_hnotify_init(void);
19184 +void au_hnotify_fin(void);
19187 +extern const struct au_hnotify_op au_hnotify_op;
19190 +void au_hn_init(struct au_hinode *hinode)
19192 + hinode->hi_notify = NULL;
19195 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19197 + return hinode->hi_notify;
19201 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19202 + struct au_hinode *hinode __maybe_unused,
19203 + struct inode *inode __maybe_unused)
19204 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19205 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19206 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19207 + int do_set __maybe_unused)
19208 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19209 + unsigned int flags __maybe_unused)
19210 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19211 + struct au_branch *br __maybe_unused,
19212 + int perm __maybe_unused)
19213 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19214 + int perm __maybe_unused)
19215 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19216 +AuStubInt0(__init au_hnotify_init, void)
19217 +AuStubVoid(au_hnotify_fin, void)
19218 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19219 +#endif /* CONFIG_AUFS_HNOTIFY */
19221 +static inline void au_hn_suspend(struct au_hinode *hdir)
19223 + au_hn_ctl(hdir, /*do_set*/0);
19226 +static inline void au_hn_resume(struct au_hinode *hdir)
19228 + au_hn_ctl(hdir, /*do_set*/1);
19231 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19233 + inode_lock(hdir->hi_inode);
19234 + au_hn_suspend(hdir);
19237 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19238 + unsigned int sc __maybe_unused)
19240 + inode_lock_nested(hdir->hi_inode, sc);
19241 + au_hn_suspend(hdir);
19244 +#if 0 /* unused */
19245 +#include "vfsub.h"
19246 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19249 + inode_lock_shared_nested(hdir->hi_inode, sc);
19250 + au_hn_suspend(hdir);
19254 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19256 + au_hn_resume(hdir);
19257 + inode_unlock(hdir->hi_inode);
19260 +#endif /* __KERNEL__ */
19261 +#endif /* __AUFS_INODE_H__ */
19262 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19263 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19264 +++ linux/fs/aufs/ioctl.c 2021-02-22 22:51:59.061411920 +0100
19266 +// SPDX-License-Identifier: GPL-2.0
19268 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19270 + * This program, aufs is free software; you can redistribute it and/or modify
19271 + * it under the terms of the GNU General Public License as published by
19272 + * the Free Software Foundation; either version 2 of the License, or
19273 + * (at your option) any later version.
19275 + * This program is distributed in the hope that it will be useful,
19276 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19277 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19278 + * GNU General Public License for more details.
19280 + * You should have received a copy of the GNU General Public License
19281 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19286 + * plink-management and readdir in userspace.
19287 + * assist the pathconf(3) wrapper library.
19289 + * File-based Hierarchical Storage Management.
19292 +#include <linux/compat.h>
19293 +#include <linux/file.h>
19296 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19299 + aufs_bindex_t wbi, bindex, bbot;
19300 + struct file *h_file;
19301 + struct super_block *sb;
19302 + struct dentry *root;
19303 + struct au_branch *br;
19304 + struct aufs_wbr_fd wbrfd = {
19305 + .oflags = au_dir_roflags,
19308 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19309 + | O_NOATIME | O_CLOEXEC;
19311 + AuDebugOn(wbrfd.oflags & ~valid);
19314 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19315 + if (unlikely(err)) {
19321 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19322 + wbrfd.oflags |= au_dir_roflags;
19323 + AuDbg("0%o\n", wbrfd.oflags);
19324 + if (unlikely(wbrfd.oflags & ~valid))
19328 + fd = get_unused_fd_flags(0);
19330 + if (unlikely(fd < 0))
19333 + h_file = ERR_PTR(-EINVAL);
19336 + sb = path->dentry->d_sb;
19337 + root = sb->s_root;
19338 + aufs_read_lock(root, AuLock_IR);
19339 + bbot = au_sbbot(sb);
19340 + if (wbrfd.brid >= 0) {
19341 + wbi = au_br_index(sb, wbrfd.brid);
19342 + if (unlikely(wbi < 0 || wbi > bbot))
19346 + h_file = ERR_PTR(-ENOENT);
19347 + br = au_sbr(sb, wbi);
19348 + if (!au_br_writable(br->br_perm)) {
19352 + bindex = wbi + 1;
19354 + for (; bindex <= bbot; bindex++) {
19355 + br = au_sbr(sb, bindex);
19356 + if (au_br_writable(br->br_perm)) {
19358 + br = au_sbr(sb, wbi);
19363 + AuDbg("wbi %d\n", wbi);
19365 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19369 + aufs_read_unlock(root, AuLock_IR);
19370 + err = PTR_ERR(h_file);
19371 + if (IS_ERR(h_file))
19374 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19375 + fd_install(fd, h_file);
19377 + goto out; /* success */
19380 + put_unused_fd(fd);
19386 +/* ---------------------------------------------------------------------- */
19388 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19391 + struct dentry *dentry;
19394 + case AUFS_CTL_RDU:
19395 + case AUFS_CTL_RDU_INO:
19396 + err = au_rdu_ioctl(file, cmd, arg);
19399 + case AUFS_CTL_WBR_FD:
19400 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19403 + case AUFS_CTL_IBUSY:
19404 + err = au_ibusy_ioctl(file, arg);
19407 + case AUFS_CTL_BRINFO:
19408 + err = au_brinfo_ioctl(file, arg);
19411 + case AUFS_CTL_FHSM_FD:
19412 + dentry = file->f_path.dentry;
19413 + if (IS_ROOT(dentry))
19414 + err = au_fhsm_fd(dentry->d_sb, arg);
19420 + /* do not call the lower */
19421 + AuDbg("0x%x\n", cmd);
19429 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19434 + case AUFS_CTL_MVDOWN:
19435 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19438 + case AUFS_CTL_WBR_FD:
19439 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19443 + /* do not call the lower */
19444 + AuDbg("0x%x\n", cmd);
19452 +#ifdef CONFIG_COMPAT
19453 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19454 + unsigned long arg)
19459 + case AUFS_CTL_RDU:
19460 + case AUFS_CTL_RDU_INO:
19461 + err = au_rdu_compat_ioctl(file, cmd, arg);
19464 + case AUFS_CTL_IBUSY:
19465 + err = au_ibusy_compat_ioctl(file, arg);
19468 + case AUFS_CTL_BRINFO:
19469 + err = au_brinfo_compat_ioctl(file, arg);
19473 + err = aufs_ioctl_dir(file, cmd, arg);
19480 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19481 + unsigned long arg)
19483 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19486 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19487 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19488 +++ linux/fs/aufs/i_op_add.c 2021-02-22 22:51:59.058078584 +0100
19490 +// SPDX-License-Identifier: GPL-2.0
19492 + * Copyright (C) 2005-2020 Junjiro R. Okajima
19494 + * This program, aufs is free software; you can redistribute it and/or modify
19495 + * it under the terms of the GNU General Public License as published by
19496 + * the Free Software Foundation; either version 2 of the License, or
19497 + * (at your option) any later version.
19499 + * This program is distributed in the hope that it will be useful,
19500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19502 + * GNU General Public License for more details.
19504 + * You should have received a copy of the GNU General Public License
19505 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19509 + * inode operations (add entry)
19512 +#include <linux/iversion.h>
19516 + * final procedure of adding a new entry, except link(2).
19517 + * remove whiteout, instantiate, copyup the parent dir's times and size
19518 + * and update version.
19519 + * if it failed, re-create the removed whiteout.
19521 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19522 + struct dentry *wh_dentry, struct dentry *dentry)
19525 + aufs_bindex_t bwh;
19526 + struct path h_path;
19527 + struct super_block *sb;
19528 + struct inode *inode, *h_dir;
19529 + struct dentry *wh;
19534 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19535 + IMustLock(h_dir);
19536 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19537 + bwh = au_dbwh(dentry);
19538 + h_path.dentry = wh_dentry;
19539 + h_path.mnt = au_sbr_mnt(sb, bindex);
19540 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19542 + if (unlikely(err))
19546 + inode = au_new_inode(dentry, /*must_new*/1);
19547 + if (!IS_ERR(inode)) {
19548 + d_instantiate(dentry, inode);
19549 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19551 + au_dir_ts(dir, bindex);
19552 + inode_inc_iversion(dir);
19553 + au_fhsm_wrote(sb, bindex, /*force*/0);
19554 + return 0; /* success */
19557 + err = PTR_ERR(inode);
19562 + /* dir inode is locked */
19563 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19564 + rerr = PTR_ERR(wh);
19565 + if (IS_ERR(wh)) {
19566 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19567 + dentry, err, rerr);
19576 +static int au_d_may_add(struct dentry *dentry)
19581 + if (unlikely(d_unhashed(dentry)))
19583 + if (unlikely(d_really_is_positive(dentry)))
19589 + * simple tests for the adding inode operations.
19590 + * following the checks in vfs, plus the parent-child relationship.
19592 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19593 + struct dentry *h_parent, int isdir)
19597 + struct dentry *h_dentry;
19598 + struct inode *h_inode;
19600 + err = -ENAMETOOLONG;
19601 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19604 + h_dentry = au_h_dptr(dentry, bindex);
19605 + if (d_really_is_negative(dentry)) {
19607 + if (unlikely(d_is_positive(h_dentry)))
19610 + /* rename(2) case */
19612 + if (unlikely(d_is_negative(h_dentry)))
19614 + h_inode = d_inode(h_dentry);
19615 + if (unlikely(!h_inode->i_nlink))
19618 + h_mode = h_inode->i_mode;
19621 + if (unlikely(S_ISDIR(h_mode)))
19623 + } else if (unlikely(!S_ISDIR(h_mode))) {
19630 + /* expected parent dir is locked */
19631 + if (unlikely(h_parent != h_dentry->d_parent))
19640 + * initial procedure of adding a new entry.
19641 + * prepare writable branch and the parent dir, lock it,
19642 + * and lookup whiteout for the new entry.
19644 +static struct dentry*
19645 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19646 + struct dentry *src_dentry, struct au_pin *pin,
19647 + struct au_wr_dir_args *wr_dir_args)
19649 + struct dentry *wh_dentry, *h_parent;
19650 + struct super_block *sb;
19651 + struct au_branch *br;
19653 + unsigned int udba;
19654 + aufs_bindex_t bcpup;
19656 + AuDbg("%pd\n", dentry);
19658 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19660 + wh_dentry = ERR_PTR(err);
19661 + if (unlikely(err < 0))
19664 + sb = dentry->d_sb;
19665 + udba = au_opt_udba(sb);
19666 + err = au_pin(pin, dentry, bcpup, udba,
19667 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19668 + wh_dentry = ERR_PTR(err);
19669 + if (unlikely(err))
19672 + h_parent = au_pinned_h_parent(pin);
19673 + if (udba != AuOpt_UDBA_NONE
19674 + && au_dbtop(dentry) == bcpup)
19675 + err = au_may_add(dentry, bcpup, h_parent,
19676 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19677 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19678 + err = -ENAMETOOLONG;
19679 + wh_dentry = ERR_PTR(err);
19680 + if (unlikely(err))
19683 + br = au_sbr(sb, bcpup);
19685 + struct path tmp = {
19686 + .dentry = h_parent,
19687 + .mnt = au_br_mnt(br)
19689 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19692 + wh_dentry = NULL;
19693 + if (bcpup != au_dbwh(dentry))
19694 + goto out; /* success */
19697 + * ENAMETOOLONG here means that if we allowed create such name, then it
19698 + * would not be able to removed in the future. So we don't allow such
19699 + * name here and we don't handle ENAMETOOLONG differently here.
19701 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19704 + if (IS_ERR(wh_dentry))
19707 + return wh_dentry;
19710 +/* ---------------------------------------------------------------------- */
19712 +enum { Mknod, Symlink, Creat };
19713 +struct simple_arg {
19720 + struct vfsub_aopen_args *aopen;
19723 + const char *symname;
19732 +static int add_simple(struct inode *dir, struct dentry *dentry,
19733 + struct simple_arg *arg)
19736 + aufs_bindex_t btop;
19737 + unsigned char created;
19738 + const unsigned char try_aopen
19739 + = (arg->type == Creat && arg->u.c.try_aopen);
19740 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19741 + struct dentry *wh_dentry, *parent;
19742 + struct inode *h_dir;
19743 + struct super_block *sb;
19744 + struct au_branch *br;
19745 + /* to reduce stack size */
19747 + struct au_dtime dt;
19748 + struct au_pin pin;
19749 + struct path h_path;
19750 + struct au_wr_dir_args wr_dir_args;
19753 + AuDbg("%pd\n", dentry);
19757 + a = kmalloc(sizeof(*a), GFP_NOFS);
19758 + if (unlikely(!a))
19760 + a->wr_dir_args.force_btgt = -1;
19761 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19763 + parent = dentry->d_parent; /* dir inode is locked */
19764 + if (!try_aopen) {
19765 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19766 + if (unlikely(err))
19769 + err = au_d_may_add(dentry);
19770 + if (unlikely(err))
19773 + di_write_lock_parent(parent);
19774 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19775 + &a->pin, &a->wr_dir_args);
19776 + err = PTR_ERR(wh_dentry);
19777 + if (IS_ERR(wh_dentry))
19780 + btop = au_dbtop(dentry);
19781 + sb = dentry->d_sb;
19782 + br = au_sbr(sb, btop);
19783 + a->h_path.dentry = au_h_dptr(dentry, btop);
19784 + a->h_path.mnt = au_br_mnt(br);
19785 + h_dir = au_pinned_h_dir(&a->pin);
19786 + switch (arg->type) {
19788 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19789 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19790 + arg->u.c.want_excl);
19792 + if (!err && try_aopen)
19793 + aopen->file->f_mode |= FMODE_CREATED;
19796 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19797 + AuDbg("err %d\n", err);
19798 + AuDbgFile(aopen->file);
19799 + created = err >= 0
19800 + && !!(aopen->file->f_mode & FMODE_CREATED);
19804 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19808 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19815 + if (unlikely(err < 0))
19818 + err = epilog(dir, btop, wh_dentry, dentry);
19820 + goto out_unpin; /* success */
19823 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19824 + /* no delegation since it is just created */
19825 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19828 + AuIOErr("%pd revert failure(%d, %d)\n",
19829 + dentry, err, rerr);
19832 + au_dtime_revert(&a->dt);
19834 + if (try_aopen && h_dir->i_op->atomic_open
19835 + && (aopen->file->f_mode & FMODE_OPENED))
19836 + /* aopen->file is still opened */
19837 + au_lcnt_dec(&aopen->br->br_nfiles);
19840 + au_unpin(&a->pin);
19844 + di_write_unlock(parent);
19846 + if (unlikely(err)) {
19847 + au_update_dbtop(dentry);
19851 + aufs_read_unlock(dentry, AuLock_DW);
19858 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19861 + struct simple_arg arg = {
19868 + return add_simple(dir, dentry, &arg);
19871 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19873 + struct simple_arg arg = {
19875 + .u.s.symname = symname
19877 + return add_simple(dir, dentry, &arg);
19880 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19883 + struct simple_arg arg = {
19887 + .want_excl = want_excl
19890 + return add_simple(dir, dentry, &arg);
19893 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19894 + struct vfsub_aopen_args *aopen_args)
19896 + struct simple_arg arg = {
19899 + .mode = aopen_args->create_mode,
19900 + .want_excl = aopen_args->open_flag & O_EXCL,
19901 + .try_aopen = true,
19902 + .aopen = aopen_args
19905 + return add_simple(dir, dentry, &arg);
19908 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19911 + aufs_bindex_t bindex;
19912 + struct super_block *sb;
19913 + struct dentry *parent, *h_parent, *h_dentry;
19914 + struct inode *h_dir, *inode;
19915 + struct vfsmount *h_mnt;
19916 + struct au_wr_dir_args wr_dir_args = {
19917 + .force_btgt = -1,
19918 + .flags = AuWrDir_TMPFILE
19921 + /* copy-up may happen */
19925 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19926 + if (unlikely(err))
19929 + err = au_di_init(dentry);
19930 + if (unlikely(err))
19934 + parent = d_find_any_alias(dir);
19935 + AuDebugOn(!parent);
19936 + di_write_lock_parent(parent);
19937 + if (unlikely(d_inode(parent) != dir))
19940 + err = au_digen_test(parent, au_sigen(sb));
19941 + if (unlikely(err))
19944 + bindex = au_dbtop(parent);
19945 + au_set_dbtop(dentry, bindex);
19946 + au_set_dbbot(dentry, bindex);
19947 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19949 + if (unlikely(err < 0))
19952 + err = -EOPNOTSUPP;
19953 + h_dir = au_h_iptr(dir, bindex);
19954 + if (unlikely(!h_dir->i_op->tmpfile))
19957 + h_mnt = au_sbr_mnt(sb, bindex);
19958 + err = vfsub_mnt_want_write(h_mnt);
19959 + if (unlikely(err))
19962 + h_parent = au_h_dptr(parent, bindex);
19963 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
19964 + if (IS_ERR(h_dentry)) {
19965 + err = PTR_ERR(h_dentry);
19969 + au_set_dbtop(dentry, bindex);
19970 + au_set_dbbot(dentry, bindex);
19971 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19972 + inode = au_new_inode(dentry, /*must_new*/1);
19973 + if (IS_ERR(inode)) {
19974 + err = PTR_ERR(inode);
19975 + au_set_h_dptr(dentry, bindex, NULL);
19976 + au_set_dbtop(dentry, -1);
19977 + au_set_dbbot(dentry, -1);
19979 + if (!inode->i_nlink)
19980 + set_nlink(inode, 1);
19981 + d_tmpfile(dentry, inode);
19982 + au_di(dentry)->di_tmpfile = 1;
19984 + /* update without i_mutex */
19985 + if (au_ibtop(dir) == au_dbtop(dentry))
19986 + au_cpup_attr_timesizes(dir);
19991 + vfsub_mnt_drop_write(h_mnt);
19993 + di_write_unlock(parent);
19995 + di_write_unlock(dentry);
19996 + if (unlikely(err)) {
19997 + au_di_fin(dentry);
19998 + dentry->d_fsdata = NULL;
20001 + si_read_unlock(sb);
20003 + inode_unlock(dir);
20007 +/* ---------------------------------------------------------------------- */
20009 +struct au_link_args {
20010 + aufs_bindex_t bdst, bsrc;
20011 + struct au_pin pin;
20012 + struct path h_path;
20013 + struct dentry *src_parent, *parent;
20016 +static int au_cpup_before_link(struct dentry *src_dentry,
20017 + struct au_link_args *a)
20020 + struct dentry *h_src_dentry;
20021 + struct au_cp_generic cpg = {
20022 + .dentry = src_dentry,
20027 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20030 + di_read_lock_parent(a->src_parent, AuLock_IR);
20031 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20032 + if (unlikely(err))
20035 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20036 + err = au_pin(&a->pin, src_dentry, a->bdst,
20037 + au_opt_udba(src_dentry->d_sb),
20038 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20039 + if (unlikely(err))
20042 + err = au_sio_cpup_simple(&cpg);
20043 + au_unpin(&a->pin);
20046 + di_read_unlock(a->src_parent, AuLock_IR);
20050 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20051 + struct au_link_args *a)
20054 + unsigned char plink;
20055 + aufs_bindex_t bbot;
20056 + struct dentry *h_src_dentry;
20057 + struct inode *h_inode, *inode, *delegated;
20058 + struct super_block *sb;
20059 + struct file *h_file;
20063 + sb = src_dentry->d_sb;
20064 + inode = d_inode(src_dentry);
20065 + if (au_ibtop(inode) <= a->bdst)
20066 + h_inode = au_h_iptr(inode, a->bdst);
20067 + if (!h_inode || !h_inode->i_nlink) {
20068 + /* copyup src_dentry as the name of dentry. */
20069 + bbot = au_dbbot(dentry);
20070 + if (bbot < a->bsrc)
20071 + au_set_dbbot(dentry, a->bsrc);
20072 + au_set_h_dptr(dentry, a->bsrc,
20073 + dget(au_h_dptr(src_dentry, a->bsrc)));
20074 + dget(a->h_path.dentry);
20075 + au_set_h_dptr(dentry, a->bdst, NULL);
20076 + AuDbg("temporary d_inode...\n");
20077 + spin_lock(&dentry->d_lock);
20078 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20079 + spin_unlock(&dentry->d_lock);
20080 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20081 + if (IS_ERR(h_file))
20082 + err = PTR_ERR(h_file);
20084 + struct au_cp_generic cpg = {
20085 + .dentry = dentry,
20090 + .flags = AuCpup_KEEPLINO
20092 + err = au_sio_cpup_simple(&cpg);
20093 + au_h_open_post(dentry, a->bsrc, h_file);
20095 + dput(a->h_path.dentry);
20096 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20098 + au_set_h_dptr(dentry, a->bdst,
20099 + a->h_path.dentry);
20101 + spin_lock(&dentry->d_lock);
20102 + dentry->d_inode = NULL; /* restore */
20103 + spin_unlock(&dentry->d_lock);
20104 + AuDbg("temporary d_inode...done\n");
20105 + au_set_h_dptr(dentry, a->bsrc, NULL);
20106 + au_set_dbbot(dentry, bbot);
20108 + /* the inode of src_dentry already exists on a.bdst branch */
20109 + h_src_dentry = d_find_alias(h_inode);
20110 + if (!h_src_dentry && au_plink_test(inode)) {
20112 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20113 + err = PTR_ERR(h_src_dentry);
20114 + if (IS_ERR(h_src_dentry))
20117 + if (unlikely(d_is_negative(h_src_dentry))) {
20118 + dput(h_src_dentry);
20119 + h_src_dentry = NULL;
20123 + if (h_src_dentry) {
20124 + delegated = NULL;
20125 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20126 + &a->h_path, &delegated);
20127 + if (unlikely(err == -EWOULDBLOCK)) {
20128 + pr_warn("cannot retry for NFSv4 delegation"
20129 + " for an internal link\n");
20132 + dput(h_src_dentry);
20134 + AuIOErr("no dentry found for hi%lu on b%d\n",
20135 + h_inode->i_ino, a->bdst);
20140 + if (!err && !plink)
20141 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20148 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20149 + struct dentry *dentry)
20152 + struct au_dtime dt;
20153 + struct au_link_args *a;
20154 + struct dentry *wh_dentry, *h_src_dentry;
20155 + struct inode *inode, *delegated;
20156 + struct super_block *sb;
20157 + struct au_wr_dir_args wr_dir_args = {
20158 + /* .force_btgt = -1, */
20159 + .flags = AuWrDir_ADD_ENTRY
20163 + inode = d_inode(src_dentry);
20164 + IMustLock(inode);
20167 + a = kzalloc(sizeof(*a), GFP_NOFS);
20168 + if (unlikely(!a))
20171 + a->parent = dentry->d_parent; /* dir inode is locked */
20172 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20173 + AuLock_NOPLM | AuLock_GEN);
20174 + if (unlikely(err))
20176 + err = au_d_linkable(src_dentry);
20177 + if (unlikely(err))
20179 + err = au_d_may_add(dentry);
20180 + if (unlikely(err))
20183 + a->src_parent = dget_parent(src_dentry);
20184 + wr_dir_args.force_btgt = au_ibtop(inode);
20186 + di_write_lock_parent(a->parent);
20187 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20188 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20190 + err = PTR_ERR(wh_dentry);
20191 + if (IS_ERR(wh_dentry))
20195 + sb = dentry->d_sb;
20196 + a->bdst = au_dbtop(dentry);
20197 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20198 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20199 + a->bsrc = au_ibtop(inode);
20200 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20201 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20202 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20203 + if (!h_src_dentry) {
20204 + a->bsrc = au_dbtop(src_dentry);
20205 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20206 + AuDebugOn(!h_src_dentry);
20207 + } else if (IS_ERR(h_src_dentry)) {
20208 + err = PTR_ERR(h_src_dentry);
20213 + * aufs doesn't touch the credential so
20214 + * security_dentry_create_files_as() is unnecessary.
20216 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20217 + if (a->bdst < a->bsrc
20218 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20219 + err = au_cpup_or_link(src_dentry, dentry, a);
20221 + delegated = NULL;
20222 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20223 + &a->h_path, &delegated);
20224 + if (unlikely(err == -EWOULDBLOCK)) {
20225 + pr_warn("cannot retry for NFSv4 delegation"
20226 + " for an internal link\n");
20230 + dput(h_src_dentry);
20233 + * copyup src_dentry to the branch we process,
20234 + * and then link(2) to it.
20236 + dput(h_src_dentry);
20237 + if (a->bdst < a->bsrc
20238 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20239 + au_unpin(&a->pin);
20240 + di_write_unlock(a->parent);
20241 + err = au_cpup_before_link(src_dentry, a);
20242 + di_write_lock_parent(a->parent);
20244 + err = au_pin(&a->pin, dentry, a->bdst,
20246 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20247 + if (unlikely(err))
20251 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20253 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20254 + delegated = NULL;
20255 + err = vfsub_link(h_src_dentry,
20256 + au_pinned_h_dir(&a->pin),
20257 + &a->h_path, &delegated);
20258 + if (unlikely(err == -EWOULDBLOCK)) {
20259 + pr_warn("cannot retry"
20260 + " for NFSv4 delegation"
20261 + " for an internal link\n");
20267 + if (unlikely(err))
20271 + a->h_path.dentry = wh_dentry;
20272 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20274 + if (unlikely(err))
20278 + au_dir_ts(dir, a->bdst);
20279 + inode_inc_iversion(dir);
20280 + inc_nlink(inode);
20281 + inode->i_ctime = dir->i_ctime;
20282 + d_instantiate(dentry, au_igrab(inode));
20283 + if (d_unhashed(a->h_path.dentry))
20284 + /* some filesystem calls d_drop() */
20286 + /* some filesystems consume an inode even hardlink */
20287 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20288 + goto out_unpin; /* success */
20291 + /* no delegation since it is just created */
20292 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20293 + /*delegated*/NULL, /*force*/0);
20294 + if (unlikely(rerr)) {
20295 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20298 + au_dtime_revert(&dt);
20300 + au_unpin(&a->pin);
20304 + di_write_unlock(a->parent);
20305 + dput(a->src_parent);
20307 + if (unlikely(err)) {
20308 + au_update_dbtop(dentry);
20311 + aufs_read_and_write_unlock2(dentry, src_dentry);
20319 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20322 + aufs_bindex_t bindex;
20323 + unsigned char diropq;
20324 + struct path h_path;
20325 + struct dentry *wh_dentry, *parent, *opq_dentry;
20326 + struct inode *h_inode;
20327 + struct super_block *sb;
20329 + struct au_pin pin;
20330 + struct au_dtime dt;
20331 + } *a; /* reduce the stack usage */
20332 + struct au_wr_dir_args wr_dir_args = {
20333 + .force_btgt = -1,
20334 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20340 + a = kmalloc(sizeof(*a), GFP_NOFS);
20341 + if (unlikely(!a))
20344 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20345 + if (unlikely(err))
20347 + err = au_d_may_add(dentry);
20348 + if (unlikely(err))
20351 + parent = dentry->d_parent; /* dir inode is locked */
20352 + di_write_lock_parent(parent);
20353 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20354 + &a->pin, &wr_dir_args);
20355 + err = PTR_ERR(wh_dentry);
20356 + if (IS_ERR(wh_dentry))
20359 + sb = dentry->d_sb;
20360 + bindex = au_dbtop(dentry);
20361 + h_path.dentry = au_h_dptr(dentry, bindex);
20362 + h_path.mnt = au_sbr_mnt(sb, bindex);
20363 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20364 + if (unlikely(err))
20367 + /* make the dir opaque */
20369 + h_inode = d_inode(h_path.dentry);
20371 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20372 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20373 + opq_dentry = au_diropq_create(dentry, bindex);
20374 + inode_unlock(h_inode);
20375 + err = PTR_ERR(opq_dentry);
20376 + if (IS_ERR(opq_dentry))
20378 + dput(opq_dentry);
20382 + err = epilog(dir, bindex, wh_dentry, dentry);
20385 + goto out_unpin; /* success */
20390 + AuLabel(revert opq);
20391 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20392 + rerr = au_diropq_remove(dentry, bindex);
20393 + inode_unlock(h_inode);
20395 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20396 + dentry, err, rerr);
20402 + AuLabel(revert dir);
20403 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20405 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20406 + dentry, err, rerr);
20409 + au_dtime_revert(&a->dt);
20411 + au_unpin(&a->pin);
20414 + di_write_unlock(parent);
20416 + if (unlikely(err)) {
20417 + au_update_dbtop(dentry);
20420 + aufs_read_unlock(dentry, AuLock_DW);
20426 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20427 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20428 +++ linux/fs/aufs/i_op.c 2021-02-22 22:51:59.058078584 +0100
20430 +// SPDX-License-Identifier: GPL-2.0
20432 + * Copyright (C) 2005-2020 Junjiro R. Okajima
20434 + * This program, aufs is free software; you can redistribute it and/or modify
20435 + * it under the terms of the GNU General Public License as published by
20436 + * the Free Software Foundation; either version 2 of the License, or
20437 + * (at your option) any later version.
20439 + * This program is distributed in the hope that it will be useful,
20440 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20441 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20442 + * GNU General Public License for more details.
20444 + * You should have received a copy of the GNU General Public License
20445 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20449 + * inode operations (except add/del/rename)
20452 +#include <linux/device_cgroup.h>
20453 +#include <linux/fs_stack.h>
20454 +#include <linux/iversion.h>
20455 +#include <linux/namei.h>
20456 +#include <linux/security.h>
20459 +static int h_permission(struct inode *h_inode, int mask,
20460 + struct path *h_path, int brperm)
20463 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20466 + if (write_mask && IS_IMMUTABLE(h_inode))
20470 + if (((mask & MAY_EXEC)
20471 + && S_ISREG(h_inode->i_mode)
20472 + && (path_noexec(h_path)
20473 + || !(h_inode->i_mode & 0111))))
20477 + * - skip the lower fs test in the case of write to ro branch.
20478 + * - nfs dir permission write check is optimized, but a policy for
20479 + * link/rename requires a real check.
20480 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20481 + * in this case, generic_permission() returns -EOPNOTSUPP.
20483 + if ((write_mask && !au_br_writable(brperm))
20484 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20485 + && write_mask && !(mask & MAY_READ))
20486 + || !h_inode->i_op->permission) {
20487 + /* AuLabel(generic_permission); */
20488 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20489 + err = generic_permission(h_inode, mask);
20490 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20491 + err = h_inode->i_op->permission(h_inode, mask);
20494 + /* AuLabel(h_inode->permission); */
20495 + err = h_inode->i_op->permission(h_inode, mask);
20500 + err = devcgroup_inode_permission(h_inode, mask);
20502 + err = security_inode_permission(h_inode, mask);
20508 +static int aufs_permission(struct inode *inode, int mask)
20511 + aufs_bindex_t bindex, bbot;
20512 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20513 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20514 + struct inode *h_inode;
20515 + struct super_block *sb;
20516 + struct au_branch *br;
20518 + /* todo: support rcu-walk? */
20519 + if (mask & MAY_NOT_BLOCK)
20522 + sb = inode->i_sb;
20523 + si_read_lock(sb, AuLock_FLUSH);
20524 + ii_read_lock_child(inode);
20525 +#if 0 /* reserved for future use */
20527 + * This test may be rather 'too much' since the test is essentially done
20528 + * in the aufs_lookup(). Theoretically it is possible that the inode
20529 + * generation doesn't match to the superblock's here. But it isn't a
20530 + * big deal I suppose.
20532 + err = au_iigen_test(inode, au_sigen(sb));
20533 + if (unlikely(err))
20539 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20540 + err = au_busy_or_stale();
20541 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20542 + if (unlikely(!h_inode
20543 + || (h_inode->i_mode & S_IFMT)
20544 + != (inode->i_mode & S_IFMT)))
20548 + bindex = au_ibtop(inode);
20549 + br = au_sbr(sb, bindex);
20550 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20553 + && !special_file(h_inode->i_mode)) {
20554 + /* test whether the upper writable branch exists */
20556 + for (; bindex >= 0; bindex--)
20557 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20565 + /* non-write to dir */
20567 + bbot = au_ibbot(inode);
20568 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20569 + h_inode = au_h_iptr(inode, bindex);
20571 + err = au_busy_or_stale();
20572 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20575 + br = au_sbr(sb, bindex);
20576 + err = h_permission(h_inode, mask, &br->br_path,
20582 + ii_read_unlock(inode);
20583 + si_read_unlock(sb);
20587 +/* ---------------------------------------------------------------------- */
20589 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20590 + unsigned int flags)
20592 + struct dentry *ret, *parent;
20593 + struct inode *inode;
20594 + struct super_block *sb;
20595 + int err, npositive;
20599 + /* todo: support rcu-walk? */
20600 + ret = ERR_PTR(-ECHILD);
20601 + if (flags & LOOKUP_RCU)
20604 + ret = ERR_PTR(-ENAMETOOLONG);
20605 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20609 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20610 + ret = ERR_PTR(err);
20611 + if (unlikely(err))
20614 + err = au_di_init(dentry);
20615 + ret = ERR_PTR(err);
20616 + if (unlikely(err))
20620 + npositive = 0; /* suppress a warning */
20621 + parent = dentry->d_parent; /* dir inode is locked */
20622 + di_read_lock_parent(parent, AuLock_IR);
20623 + err = au_alive_dir(parent);
20625 + err = au_digen_test(parent, au_sigen(sb));
20627 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20628 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20629 + AuLkup_ALLOW_NEG);
20632 + di_read_unlock(parent, AuLock_IR);
20633 + ret = ERR_PTR(err);
20634 + if (unlikely(err < 0))
20638 + inode = au_new_inode(dentry, /*must_new*/0);
20639 + if (IS_ERR(inode)) {
20640 + ret = (void *)inode;
20647 + atomic_inc(&inode->i_count);
20648 + ret = d_splice_alias(inode, dentry);
20649 +#if 0 /* reserved for future use */
20650 + if (unlikely(d_need_lookup(dentry))) {
20651 + spin_lock(&dentry->d_lock);
20652 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20653 + spin_unlock(&dentry->d_lock);
20657 + if (!IS_ERR(ret)) {
20659 + if (ret && ret != dentry)
20660 + ii_write_unlock(inode);
20662 + ii_write_unlock(inode);
20669 + di_write_unlock(dentry);
20671 + si_read_unlock(sb);
20676 +/* ---------------------------------------------------------------------- */
20679 + * very dirty and complicated aufs ->atomic_open().
20680 + * aufs_atomic_open()
20681 + * + au_aopen_or_create()
20683 + * + vfsub_atomic_open()
20684 + * + branch fs ->atomic_open()
20685 + * may call the actual 'open' for h_file
20686 + * + inc br_nfiles only if opened
20687 + * + au_aopen_no_open() or au_aopen_do_open()
20689 + * au_aopen_do_open()
20690 + * + finish_open()
20691 + * + au_do_aopen()
20692 + * + au_do_open() the body of all 'open'
20693 + * + au_do_open_nondir()
20694 + * set the passed h_file
20696 + * au_aopen_no_open()
20697 + * + finish_no_open()
20700 +struct aopen_node {
20701 + struct hlist_bl_node hblist;
20702 + struct file *file, *h_file;
20705 +static int au_do_aopen(struct inode *inode, struct file *file)
20707 + struct hlist_bl_head *aopen;
20708 + struct hlist_bl_node *pos;
20709 + struct aopen_node *node;
20710 + struct au_do_open_args args = {
20712 + .open = au_do_open_nondir
20715 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20716 + hlist_bl_lock(aopen);
20717 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20718 + if (node->file == file) {
20719 + args.h_file = node->h_file;
20722 + hlist_bl_unlock(aopen);
20723 + /* AuDebugOn(!args.h_file); */
20725 + return au_do_open(file, &args);
20728 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20729 + struct aopen_node *aopen_node)
20732 + struct hlist_bl_head *aopen;
20735 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20736 + au_hbl_add(&aopen_node->hblist, aopen);
20737 + err = finish_open(file, dentry, au_do_aopen);
20738 + au_hbl_del(&aopen_node->hblist, aopen);
20739 + /* AuDbgFile(file); */
20740 + AuDbg("%pd%s%s\n", dentry,
20741 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20742 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20748 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20754 + err = finish_no_open(file, dentry);
20760 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20761 + struct file *file, unsigned int open_flag,
20762 + umode_t create_mode)
20764 + int err, did_open;
20765 + unsigned int lkup_flags;
20766 + aufs_bindex_t bindex;
20767 + struct super_block *sb;
20768 + struct dentry *parent, *d;
20769 + struct vfsub_aopen_args args = {
20770 + .open_flag = open_flag,
20771 + .create_mode = create_mode
20773 + struct aopen_node aopen_node = {
20778 + AuDbg("open_flag 0%o\n", open_flag);
20779 + AuDbgDentry(dentry);
20782 + if (!au_di(dentry)) {
20783 + lkup_flags = LOOKUP_OPEN;
20784 + if (open_flag & O_CREAT)
20785 + lkup_flags |= LOOKUP_CREATE;
20786 + d = aufs_lookup(dir, dentry, lkup_flags);
20788 + err = PTR_ERR(d);
20793 + * obsoleted dentry found.
20794 + * another error will be returned later.
20800 + AuDbgDentry(dentry);
20803 + if (d_is_positive(dentry)
20804 + || d_unhashed(dentry)
20805 + || d_unlinked(dentry)
20806 + || !(open_flag & O_CREAT)) {
20807 + err = au_aopen_no_open(file, dentry);
20808 + goto out; /* success */
20811 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20812 + if (unlikely(err))
20815 + sb = dentry->d_sb;
20816 + parent = dentry->d_parent; /* dir is locked */
20817 + di_write_lock_parent(parent);
20818 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20819 + if (unlikely(err < 0))
20822 + AuDbgDentry(dentry);
20823 + if (d_is_positive(dentry)) {
20824 + err = au_aopen_no_open(file, dentry);
20825 + goto out_parent; /* success */
20828 + args.file = alloc_empty_file(file->f_flags, current_cred());
20829 + err = PTR_ERR(args.file);
20830 + if (IS_ERR(args.file))
20833 + bindex = au_dbtop(dentry);
20834 + err = au_aopen_or_create(dir, dentry, &args);
20836 + AuDbgFile(args.file);
20837 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20838 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20841 + args.file = NULL;
20843 + di_write_unlock(parent);
20844 + di_write_unlock(dentry);
20845 + if (unlikely(err < 0)) {
20852 + err = au_aopen_no_open(file, dentry);
20854 + aopen_node.h_file = args.file;
20855 + err = au_aopen_do_open(file, dentry, &aopen_node);
20857 + if (unlikely(err < 0)) {
20861 + au_lcnt_dec(&args.br->br_nfiles);
20863 + goto out_sb; /* success */
20866 + di_write_unlock(parent);
20867 + di_write_unlock(dentry);
20869 + si_read_unlock(sb);
20877 +/* ---------------------------------------------------------------------- */
20879 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20880 + const unsigned char add_entry, aufs_bindex_t bcpup,
20881 + aufs_bindex_t btop)
20884 + struct dentry *h_parent;
20885 + struct inode *h_dir;
20888 + IMustLock(d_inode(parent));
20890 + di_write_lock_parent(parent);
20893 + if (!au_h_dptr(parent, bcpup)) {
20894 + if (btop > bcpup)
20895 + err = au_cpup_dirs(dentry, bcpup);
20896 + else if (btop < bcpup)
20897 + err = au_cpdown_dirs(dentry, bcpup);
20901 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20902 + h_parent = au_h_dptr(parent, bcpup);
20903 + h_dir = d_inode(h_parent);
20904 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20905 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20906 + /* todo: no unlock here */
20907 + inode_unlock_shared(h_dir);
20909 + AuDbg("bcpup %d\n", bcpup);
20911 + if (d_really_is_negative(dentry))
20912 + au_set_h_dptr(dentry, btop, NULL);
20913 + au_update_dbrange(dentry, /*do_put_zero*/0);
20918 + di_write_unlock(parent);
20920 + err = bcpup; /* success */
20927 + * decide the branch and the parent dir where we will create a new entry.
20928 + * returns new bindex or an error.
20929 + * copyup the parent dir if needed.
20931 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20932 + struct au_wr_dir_args *args)
20935 + unsigned int flags;
20936 + aufs_bindex_t bcpup, btop, src_btop;
20937 + const unsigned char add_entry
20938 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20939 + | au_ftest_wrdir(args->flags, TMPFILE);
20940 + struct super_block *sb;
20941 + struct dentry *parent;
20942 + struct au_sbinfo *sbinfo;
20944 + sb = dentry->d_sb;
20945 + sbinfo = au_sbi(sb);
20946 + parent = dget_parent(dentry);
20947 + btop = au_dbtop(dentry);
20949 + if (args->force_btgt < 0) {
20950 + if (src_dentry) {
20951 + src_btop = au_dbtop(src_dentry);
20952 + if (src_btop < btop)
20953 + bcpup = src_btop;
20954 + } else if (add_entry) {
20956 + if (au_ftest_wrdir(args->flags, ISDIR))
20957 + au_fset_wbr(flags, DIR);
20958 + err = AuWbrCreate(sbinfo, dentry, flags);
20962 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20964 + err = AuWbrCopyup(sbinfo, dentry);
20966 + if (!IS_ROOT(dentry)) {
20967 + di_read_lock_parent(parent, !AuLock_IR);
20968 + err = AuWbrCopyup(sbinfo, dentry);
20969 + di_read_unlock(parent, !AuLock_IR);
20971 + err = AuWbrCopyup(sbinfo, dentry);
20974 + if (unlikely(err < 0))
20978 + bcpup = args->force_btgt;
20979 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20982 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20984 + if (bcpup == btop)
20985 + goto out; /* success */
20987 + /* copyup the new parent into the branch we process */
20988 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20990 + if (d_really_is_negative(dentry)) {
20991 + au_set_h_dptr(dentry, btop, NULL);
20992 + au_set_dbtop(dentry, bcpup);
20993 + au_set_dbbot(dentry, bcpup);
20995 + AuDebugOn(add_entry
20996 + && !au_ftest_wrdir(args->flags, TMPFILE)
20997 + && !au_h_dptr(dentry, bcpup));
21005 +/* ---------------------------------------------------------------------- */
21007 +void au_pin_hdir_unlock(struct au_pin *p)
21010 + au_hn_inode_unlock(p->hdir);
21013 +int au_pin_hdir_lock(struct au_pin *p)
21021 + /* even if an error happens later, keep this lock */
21022 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21025 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21030 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21031 + p->h_parent, p->br);
21037 +int au_pin_hdir_relock(struct au_pin *p)
21040 + struct inode *h_i;
21041 + struct dentry *h_d[] = {
21046 + err = au_pin_hdir_lock(p);
21047 + if (unlikely(err))
21050 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21053 + if (d_is_positive(h_d[i])) {
21054 + h_i = d_inode(h_d[i]);
21055 + err = !h_i->i_nlink;
21063 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21065 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21068 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21071 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21072 + p->lsc_hi, 0, NULL, _RET_IP_);
21073 + au_pin_hdir_set_owner(p, current);
21077 +void au_pin_hdir_release(struct au_pin *p)
21080 + au_pin_hdir_set_owner(p, p->task);
21081 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21085 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21087 + if (pin && pin->parent)
21088 + return au_h_dptr(pin->parent, pin->bindex);
21092 +void au_unpin(struct au_pin *p)
21095 + au_pin_hdir_unlock(p);
21096 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21097 + vfsub_mnt_drop_write(p->h_mnt);
21101 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21102 + di_read_unlock(p->parent, AuLock_IR);
21103 + iput(p->hdir->hi_inode);
21105 + p->parent = NULL;
21108 + /* do not clear p->task */
21111 +int au_do_pin(struct au_pin *p)
21114 + struct super_block *sb;
21115 + struct inode *h_dir;
21118 + sb = p->dentry->d_sb;
21119 + p->br = au_sbr(sb, p->bindex);
21120 + if (IS_ROOT(p->dentry)) {
21121 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21122 + p->h_mnt = au_br_mnt(p->br);
21123 + err = vfsub_mnt_want_write(p->h_mnt);
21124 + if (unlikely(err)) {
21125 + au_fclr_pin(p->flags, MNT_WRITE);
21132 + p->h_dentry = NULL;
21133 + if (p->bindex <= au_dbbot(p->dentry))
21134 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21136 + p->parent = dget_parent(p->dentry);
21137 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21138 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21141 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21142 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21144 + h_dir = p->hdir->hi_inode;
21148 + * if DI_LOCKED is not set, then p->parent may be different
21149 + * and h_parent can be NULL.
21151 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21153 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21154 + di_read_unlock(p->parent, AuLock_IR);
21156 + p->parent = NULL;
21160 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21161 + p->h_mnt = au_br_mnt(p->br);
21162 + err = vfsub_mnt_want_write(p->h_mnt);
21163 + if (unlikely(err)) {
21164 + au_fclr_pin(p->flags, MNT_WRITE);
21165 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21166 + di_read_unlock(p->parent, AuLock_IR);
21168 + p->parent = NULL;
21174 + err = au_pin_hdir_lock(p);
21176 + goto out; /* success */
21181 + pr_err("err %d\n", err);
21182 + err = au_busy_or_stale();
21187 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21188 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21189 + unsigned int udba, unsigned char flags)
21191 + p->dentry = dentry;
21193 + p->lsc_di = lsc_di;
21194 + p->lsc_hi = lsc_hi;
21195 + p->flags = flags;
21196 + p->bindex = bindex;
21198 + p->parent = NULL;
21202 + p->h_dentry = NULL;
21203 + p->h_parent = NULL;
21205 + p->task = current;
21208 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21209 + unsigned int udba, unsigned char flags)
21211 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21213 + return au_do_pin(pin);
21216 +/* ---------------------------------------------------------------------- */
21219 + * ->setattr() and ->getattr() are called in various cases.
21220 + * chmod, stat: dentry is revalidated.
21221 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21223 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21225 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21226 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21229 + struct dentry *parent;
21232 + if (au_digen_test(dentry, sigen)) {
21233 + parent = dget_parent(dentry);
21234 + di_read_lock_parent(parent, AuLock_IR);
21235 + err = au_refresh_dentry(dentry, parent);
21236 + di_read_unlock(parent, AuLock_IR);
21244 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21245 + struct au_icpup_args *a)
21249 + aufs_bindex_t btop, ibtop;
21250 + struct dentry *hi_wh, *parent;
21251 + struct inode *inode;
21252 + struct au_wr_dir_args wr_dir_args = {
21253 + .force_btgt = -1,
21257 + if (d_is_dir(dentry))
21258 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21259 + /* plink or hi_wh() case */
21260 + btop = au_dbtop(dentry);
21261 + inode = d_inode(dentry);
21262 + ibtop = au_ibtop(inode);
21263 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21264 + wr_dir_args.force_btgt = ibtop;
21265 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21266 + if (unlikely(err < 0))
21270 + au_fset_icpup(a->flags, DID_CPUP);
21273 + a->pin_flags = AuPin_MNT_WRITE;
21275 + if (!IS_ROOT(dentry)) {
21276 + au_fset_pin(a->pin_flags, DI_LOCKED);
21277 + parent = dget_parent(dentry);
21278 + di_write_lock_parent(parent);
21281 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21282 + if (unlikely(err))
21286 + a->h_path.dentry = au_h_dptr(dentry, btop);
21287 + a->h_inode = d_inode(a->h_path.dentry);
21288 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21289 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21290 + if (ia->ia_size < i_size_read(a->h_inode))
21291 + sz = ia->ia_size;
21292 + inode_unlock_shared(a->h_inode);
21296 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21297 + hi_wh = au_hi_wh(inode, a->btgt);
21299 + struct au_cp_generic cpg = {
21300 + .dentry = dentry,
21306 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21307 + if (unlikely(err))
21309 + hi_wh = au_hi_wh(inode, a->btgt);
21310 + /* todo: revalidate hi_wh? */
21315 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21316 + di_downgrade_lock(parent, AuLock_IR);
21320 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21321 + goto out; /* success */
21323 + if (!d_unhashed(dentry)) {
21324 + struct au_cp_generic cpg = {
21325 + .dentry = dentry,
21330 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21332 + err = au_sio_cpup_simple(&cpg);
21334 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21335 + } else if (!hi_wh)
21336 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21338 + a->h_path.dentry = hi_wh; /* do not dget here */
21341 + a->h_inode = d_inode(a->h_path.dentry);
21343 + goto out; /* success */
21344 + au_unpin(&a->pin);
21347 + di_write_unlock(parent);
21352 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21356 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21359 + struct inode *inode, *delegated;
21360 + struct super_block *sb;
21361 + struct file *file;
21362 + struct au_icpup_args *a;
21364 + inode = d_inode(dentry);
21365 + IMustLock(inode);
21367 + err = setattr_prepare(dentry, ia);
21368 + if (unlikely(err))
21372 + a = kzalloc(sizeof(*a), GFP_NOFS);
21373 + if (unlikely(!a))
21376 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21377 + ia->ia_valid &= ~ATTR_MODE;
21380 + sb = dentry->d_sb;
21381 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21382 + if (unlikely(err))
21385 + if (ia->ia_valid & ATTR_FILE) {
21386 + /* currently ftruncate(2) only */
21387 + AuDebugOn(!d_is_reg(dentry));
21388 + file = ia->ia_file;
21389 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21391 + if (unlikely(err))
21393 + ia->ia_file = au_hf_top(file);
21394 + a->udba = AuOpt_UDBA_NONE;
21396 + /* fchmod() doesn't pass ia_file */
21397 + a->udba = au_opt_udba(sb);
21398 + di_write_lock_child(dentry);
21399 + /* no d_unlinked(), to set UDBA_NONE for root */
21400 + if (d_unhashed(dentry))
21401 + a->udba = AuOpt_UDBA_NONE;
21402 + if (a->udba != AuOpt_UDBA_NONE) {
21403 + AuDebugOn(IS_ROOT(dentry));
21404 + err = au_reval_for_attr(dentry, au_sigen(sb));
21405 + if (unlikely(err))
21410 + err = au_pin_and_icpup(dentry, ia, a);
21411 + if (unlikely(err < 0))
21413 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21414 + ia->ia_file = NULL;
21415 + ia->ia_valid &= ~ATTR_FILE;
21418 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21419 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21420 + == (ATTR_MODE | ATTR_CTIME)) {
21421 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21422 + if (unlikely(err))
21424 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21425 + && (ia->ia_valid & ATTR_CTIME)) {
21426 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21427 + if (unlikely(err))
21431 + if (ia->ia_valid & ATTR_SIZE) {
21434 + if (ia->ia_size < i_size_read(inode))
21436 + truncate_setsize(inode, ia->ia_size);
21439 + if (ia->ia_valid & ATTR_FILE)
21441 + inode_unlock(a->h_inode);
21442 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21443 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21445 + delegated = NULL;
21447 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21449 + err = break_deleg_wait(&delegated);
21457 + * regardless aufs 'acl' option setting.
21458 + * why don't all acl-aware fs call this func from their ->setattr()?
21460 + if (!err && (ia->ia_valid & ATTR_MODE))
21461 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21463 + au_cpup_attr_changeable(inode);
21466 + inode_unlock(a->h_inode);
21467 + au_unpin(&a->pin);
21468 + if (unlikely(err))
21469 + au_update_dbtop(dentry);
21471 + di_write_unlock(dentry);
21473 + fi_write_unlock(file);
21474 + ia->ia_file = file;
21475 + ia->ia_valid |= ATTR_FILE;
21478 + si_read_unlock(sb);
21486 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21487 +static int au_h_path_to_set_attr(struct dentry *dentry,
21488 + struct au_icpup_args *a, struct path *h_path)
21491 + struct super_block *sb;
21493 + sb = dentry->d_sb;
21494 + a->udba = au_opt_udba(sb);
21495 + /* no d_unlinked(), to set UDBA_NONE for root */
21496 + if (d_unhashed(dentry))
21497 + a->udba = AuOpt_UDBA_NONE;
21498 + if (a->udba != AuOpt_UDBA_NONE) {
21499 + AuDebugOn(IS_ROOT(dentry));
21500 + err = au_reval_for_attr(dentry, au_sigen(sb));
21501 + if (unlikely(err))
21504 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21505 + if (unlikely(err < 0))
21508 + h_path->dentry = a->h_path.dentry;
21509 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21515 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21516 + struct au_sxattr *arg)
21519 + struct path h_path;
21520 + struct super_block *sb;
21521 + struct au_icpup_args *a;
21522 + struct inode *h_inode;
21524 + IMustLock(inode);
21527 + a = kzalloc(sizeof(*a), GFP_NOFS);
21528 + if (unlikely(!a))
21531 + sb = dentry->d_sb;
21532 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21533 + if (unlikely(err))
21536 + h_path.dentry = NULL; /* silence gcc */
21537 + di_write_lock_child(dentry);
21538 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21539 + if (unlikely(err))
21542 + inode_unlock(a->h_inode);
21543 + switch (arg->type) {
21544 + case AU_XATTR_SET:
21545 + AuDebugOn(d_is_negative(h_path.dentry));
21546 + err = vfsub_setxattr(h_path.dentry,
21547 + arg->u.set.name, arg->u.set.value,
21548 + arg->u.set.size, arg->u.set.flags);
21551 + err = -EOPNOTSUPP;
21552 + h_inode = d_inode(h_path.dentry);
21553 + if (h_inode->i_op->set_acl)
21554 + /* this will call posix_acl_update_mode */
21555 + err = h_inode->i_op->set_acl(h_inode,
21556 + arg->u.acl_set.acl,
21557 + arg->u.acl_set.type);
21561 + au_cpup_attr_timesizes(inode);
21563 + au_unpin(&a->pin);
21564 + if (unlikely(err))
21565 + au_update_dbtop(dentry);
21568 + di_write_unlock(dentry);
21569 + si_read_unlock(sb);
21578 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21579 + unsigned int nlink)
21583 + inode->i_mode = st->mode;
21584 + /* don't i_[ug]id_write() here */
21585 + inode->i_uid = st->uid;
21586 + inode->i_gid = st->gid;
21587 + inode->i_atime = st->atime;
21588 + inode->i_mtime = st->mtime;
21589 + inode->i_ctime = st->ctime;
21591 + au_cpup_attr_nlink(inode, /*force*/0);
21592 + if (S_ISDIR(inode->i_mode)) {
21593 + n = inode->i_nlink;
21596 + smp_mb(); /* for i_nlink */
21597 + /* 0 can happen */
21598 + set_nlink(inode, n);
21601 + spin_lock(&inode->i_lock);
21602 + inode->i_blocks = st->blocks;
21603 + i_size_write(inode, st->size);
21604 + spin_unlock(&inode->i_lock);
21608 + * common routine for aufs_getattr() and au_getxattr().
21609 + * returns zero or negative (an error).
21610 + * @dentry will be read-locked in success.
21612 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21613 + struct path *h_path, int locked)
21616 + unsigned int mnt_flags, sigen;
21617 + unsigned char udba_none;
21618 + aufs_bindex_t bindex;
21619 + struct super_block *sb, *h_sb;
21621 + h_path->mnt = NULL;
21622 + h_path->dentry = NULL;
21625 + sb = dentry->d_sb;
21626 + mnt_flags = au_mntflags(sb);
21627 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21629 + if (unlikely(locked))
21630 + goto body; /* skip locking dinfo */
21632 + /* support fstat(2) */
21633 + if (!d_unlinked(dentry) && !udba_none) {
21634 + sigen = au_sigen(sb);
21635 + err = au_digen_test(dentry, sigen);
21637 + di_read_lock_child(dentry, AuLock_IR);
21638 + err = au_dbrange_test(dentry);
21639 + if (unlikely(err)) {
21640 + di_read_unlock(dentry, AuLock_IR);
21644 + AuDebugOn(IS_ROOT(dentry));
21645 + di_write_lock_child(dentry);
21646 + err = au_dbrange_test(dentry);
21648 + err = au_reval_for_attr(dentry, sigen);
21650 + di_downgrade_lock(dentry, AuLock_IR);
21652 + di_write_unlock(dentry);
21657 + di_read_lock_child(dentry, AuLock_IR);
21661 + inode = d_inode(dentry);
21662 + if (unlikely(!inode))
21665 + bindex = au_ibtop(inode);
21666 + h_path->mnt = au_sbr_mnt(sb, bindex);
21667 + h_sb = h_path->mnt->mnt_sb;
21669 + && !au_test_fs_bad_iattr(h_sb)
21671 + goto out; /* success */
21673 + if (au_dbtop(dentry) == bindex)
21674 + h_path->dentry = au_h_dptr(dentry, bindex);
21675 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21676 + h_path->dentry = au_plink_lkup(inode, bindex);
21677 + if (IS_ERR(h_path->dentry))
21678 + /* pretending success */
21679 + h_path->dentry = NULL;
21681 + dput(h_path->dentry);
21688 +static int aufs_getattr(const struct path *path, struct kstat *st,
21689 + u32 request, unsigned int query)
21692 + unsigned char positive;
21693 + struct path h_path;
21694 + struct dentry *dentry;
21695 + struct inode *inode;
21696 + struct super_block *sb;
21698 + dentry = path->dentry;
21699 + inode = d_inode(dentry);
21700 + sb = dentry->d_sb;
21701 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21702 + if (unlikely(err))
21704 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21706 + if (unlikely(err))
21708 + if (unlikely(!h_path.dentry))
21709 + /* illegally overlapped or something */
21710 + goto out_fill; /* pretending success */
21712 + positive = d_is_positive(h_path.dentry);
21714 + /* no vfsub version */
21715 + err = vfs_getattr(&h_path, st, request, query);
21718 + au_refresh_iattr(inode, st,
21719 + d_inode(h_path.dentry)->i_nlink);
21720 + goto out_fill; /* success */
21726 + generic_fillattr(inode, st);
21728 + di_read_unlock(dentry, AuLock_IR);
21730 + si_read_unlock(sb);
21736 +/* ---------------------------------------------------------------------- */
21738 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21739 + struct delayed_call *done)
21742 + struct dentry *h_dentry;
21743 + struct inode *h_inode;
21745 + aufs_bindex_t bindex;
21747 + ret = NULL; /* suppress a warning */
21752 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21753 + if (unlikely(err))
21756 + err = au_d_hashed_positive(dentry);
21757 + if (unlikely(err))
21761 + inode = d_inode(dentry);
21762 + bindex = au_ibtop(inode);
21763 + h_inode = au_h_iptr(inode, bindex);
21764 + if (unlikely(!h_inode->i_op->get_link))
21769 + if (au_dbtop(dentry) <= bindex) {
21770 + h_dentry = au_h_dptr(dentry, bindex);
21775 + h_dentry = d_find_any_alias(h_inode);
21776 + if (IS_ERR(h_dentry)) {
21777 + err = PTR_ERR(h_dentry);
21781 + if (unlikely(!h_dentry))
21785 + AuDbg("%ps\n", h_inode->i_op->get_link);
21786 + AuDbgDentry(h_dentry);
21787 + ret = vfs_get_link(h_dentry, done);
21790 + err = PTR_ERR(ret);
21793 + aufs_read_unlock(dentry, AuLock_IR);
21795 + if (unlikely(err))
21796 + ret = ERR_PTR(err);
21797 + AuTraceErrPtr(ret);
21801 +/* ---------------------------------------------------------------------- */
21803 +static int au_is_special(struct inode *inode)
21805 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21808 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21812 + aufs_bindex_t bindex;
21813 + struct super_block *sb;
21814 + struct inode *h_inode;
21815 + struct vfsmount *h_mnt;
21817 + sb = inode->i_sb;
21818 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21819 + "unexpected s_flags 0x%lx", sb->s_flags);
21821 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21823 + si_read_lock(sb, AuLock_FLUSH);
21824 + ii_write_lock_child(inode);
21827 + bindex = au_ibtop(inode);
21828 + h_inode = au_h_iptr(inode, bindex);
21829 + if (!au_test_ro(sb, bindex, inode)) {
21830 + h_mnt = au_sbr_mnt(sb, bindex);
21831 + err = vfsub_mnt_want_write(h_mnt);
21833 + err = vfsub_update_time(h_inode, ts, flags);
21834 + vfsub_mnt_drop_write(h_mnt);
21836 + } else if (au_is_special(h_inode)) {
21838 + * Never copy-up here.
21839 + * These special files may already be opened and used for
21840 + * communicating. If we copied it up, then the communication
21841 + * would be corrupted.
21843 + AuWarn1("timestamps for i%lu are ignored "
21844 + "since it is on readonly branch (hi%lu).\n",
21845 + inode->i_ino, h_inode->i_ino);
21846 + } else if (flags & ~S_ATIME) {
21848 + AuIOErr1("unexpected flags 0x%x\n", flags);
21853 + au_cpup_attr_timesizes(inode);
21854 + ii_write_unlock(inode);
21855 + si_read_unlock(sb);
21858 + if (!err && (flags & S_VERSION))
21859 + inode_inc_iversion(inode);
21864 +/* ---------------------------------------------------------------------- */
21866 +/* no getattr version will be set by module.c:aufs_init() */
21867 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21869 + [AuIop_SYMLINK] = {
21870 + .permission = aufs_permission,
21871 +#ifdef CONFIG_FS_POSIX_ACL
21872 + .get_acl = aufs_get_acl,
21873 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21876 + .setattr = aufs_setattr,
21877 + .getattr = aufs_getattr,
21879 +#ifdef CONFIG_AUFS_XATTR
21880 + .listxattr = aufs_listxattr,
21883 + .get_link = aufs_get_link,
21885 + /* .update_time = aufs_update_time */
21888 + .create = aufs_create,
21889 + .lookup = aufs_lookup,
21890 + .link = aufs_link,
21891 + .unlink = aufs_unlink,
21892 + .symlink = aufs_symlink,
21893 + .mkdir = aufs_mkdir,
21894 + .rmdir = aufs_rmdir,
21895 + .mknod = aufs_mknod,
21896 + .rename = aufs_rename,
21898 + .permission = aufs_permission,
21899 +#ifdef CONFIG_FS_POSIX_ACL
21900 + .get_acl = aufs_get_acl,
21901 + .set_acl = aufs_set_acl,
21904 + .setattr = aufs_setattr,
21905 + .getattr = aufs_getattr,
21907 +#ifdef CONFIG_AUFS_XATTR
21908 + .listxattr = aufs_listxattr,
21911 + .update_time = aufs_update_time,
21912 + .atomic_open = aufs_atomic_open,
21913 + .tmpfile = aufs_tmpfile
21915 + [AuIop_OTHER] = {
21916 + .permission = aufs_permission,
21917 +#ifdef CONFIG_FS_POSIX_ACL
21918 + .get_acl = aufs_get_acl,
21919 + .set_acl = aufs_set_acl,
21922 + .setattr = aufs_setattr,
21923 + .getattr = aufs_getattr,
21925 +#ifdef CONFIG_AUFS_XATTR
21926 + .listxattr = aufs_listxattr,
21929 + .update_time = aufs_update_time
21932 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21933 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21934 +++ linux/fs/aufs/i_op_del.c 2021-02-22 22:51:59.058078584 +0100
21936 +// SPDX-License-Identifier: GPL-2.0
21938 + * Copyright (C) 2005-2020 Junjiro R. Okajima
21940 + * This program, aufs is free software; you can redistribute it and/or modify
21941 + * it under the terms of the GNU General Public License as published by
21942 + * the Free Software Foundation; either version 2 of the License, or
21943 + * (at your option) any later version.
21945 + * This program is distributed in the hope that it will be useful,
21946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21948 + * GNU General Public License for more details.
21950 + * You should have received a copy of the GNU General Public License
21951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21955 + * inode operations (del entry)
21958 +#include <linux/iversion.h>
21962 + * decide if a new whiteout for @dentry is necessary or not.
21963 + * when it is necessary, prepare the parent dir for the upper branch whose
21964 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21965 + * be done by caller.
21967 + * 0: wh is unnecessary
21968 + * plus: wh is necessary
21971 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21973 + int need_wh, err;
21974 + aufs_bindex_t btop;
21975 + struct super_block *sb;
21977 + sb = dentry->d_sb;
21978 + btop = au_dbtop(dentry);
21979 + if (*bcpup < 0) {
21981 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21982 + err = AuWbrCopyup(au_sbi(sb), dentry);
21984 + if (unlikely(err < 0))
21988 + AuDebugOn(btop < *bcpup
21989 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
21990 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
21992 + if (*bcpup != btop) {
21993 + err = au_cpup_dirs(dentry, *bcpup);
21994 + if (unlikely(err))
21998 + struct au_dinfo *dinfo, *tmp;
22000 + need_wh = -ENOMEM;
22001 + dinfo = au_di(dentry);
22002 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
22004 + au_di_cp(tmp, dinfo);
22005 + au_di_swap(tmp, dinfo);
22006 + /* returns the number of positive dentries */
22007 + need_wh = au_lkup_dentry(dentry, btop + 1,
22008 + /* AuLkup_IGNORE_PERM */ 0);
22009 + au_di_swap(tmp, dinfo);
22010 + au_rw_write_unlock(&tmp->di_rwsem);
22014 + AuDbg("need_wh %d\n", need_wh);
22022 + * simple tests for the del-entry operations.
22023 + * following the checks in vfs, plus the parent-child relationship.
22025 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22026 + struct dentry *h_parent, int isdir)
22030 + struct dentry *h_dentry, *h_latest;
22031 + struct inode *h_inode;
22033 + h_dentry = au_h_dptr(dentry, bindex);
22034 + if (d_really_is_positive(dentry)) {
22036 + if (unlikely(d_is_negative(h_dentry)))
22038 + h_inode = d_inode(h_dentry);
22039 + if (unlikely(!h_inode->i_nlink))
22042 + h_mode = h_inode->i_mode;
22045 + if (unlikely(S_ISDIR(h_mode)))
22047 + } else if (unlikely(!S_ISDIR(h_mode))) {
22052 + /* rename(2) case */
22054 + if (unlikely(d_is_positive(h_dentry)))
22059 + /* expected parent dir is locked */
22060 + if (unlikely(h_parent != h_dentry->d_parent))
22065 + * rmdir a dir may break the consistency on some filesystem.
22066 + * let's try heavy test.
22069 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
22070 + && au_test_h_perm(d_inode(h_parent),
22071 + MAY_EXEC | MAY_WRITE)))
22074 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
22076 + if (IS_ERR(h_latest))
22078 + if (h_latest == h_dentry)
22087 + * decide the branch where we operate for @dentry. the branch index will be set
22088 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22089 + * dir for reverting.
22090 + * when a new whiteout is necessary, create it.
22092 +static struct dentry*
22093 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22094 + struct au_dtime *dt, struct au_pin *pin)
22096 + struct dentry *wh_dentry;
22097 + struct super_block *sb;
22098 + struct path h_path;
22099 + int err, need_wh;
22100 + unsigned int udba;
22101 + aufs_bindex_t bcpup;
22103 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22104 + wh_dentry = ERR_PTR(need_wh);
22105 + if (unlikely(need_wh < 0))
22108 + sb = dentry->d_sb;
22109 + udba = au_opt_udba(sb);
22111 + err = au_pin(pin, dentry, bcpup, udba,
22112 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22113 + wh_dentry = ERR_PTR(err);
22114 + if (unlikely(err))
22117 + h_path.dentry = au_pinned_h_parent(pin);
22118 + if (udba != AuOpt_UDBA_NONE
22119 + && au_dbtop(dentry) == bcpup) {
22120 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22121 + wh_dentry = ERR_PTR(err);
22122 + if (unlikely(err))
22126 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22127 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22128 + wh_dentry = NULL;
22130 + goto out; /* success, no need to create whiteout */
22132 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22133 + if (IS_ERR(wh_dentry))
22136 + /* returns with the parent is locked and wh_dentry is dget-ed */
22137 + goto out; /* success */
22142 + return wh_dentry;
22146 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22147 + * in order to be revertible and save time for removing many child whiteouts
22149 + * returns 1 when there are too many child whiteout and caller should remove
22150 + * them asynchronously. returns 0 when the number of children is enough small to
22151 + * remove now or the branch fs is a remote fs.
22152 + * otherwise return an error.
22154 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22155 + struct au_nhash *whlist, struct inode *dir)
22157 + int rmdir_later, err, dirwh;
22158 + struct dentry *h_dentry;
22159 + struct super_block *sb;
22160 + struct inode *inode;
22162 + sb = dentry->d_sb;
22163 + SiMustAnyLock(sb);
22164 + h_dentry = au_h_dptr(dentry, bindex);
22165 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22166 + if (unlikely(err))
22169 + /* stop monitoring */
22170 + inode = d_inode(dentry);
22171 + au_hn_free(au_hi(inode, bindex));
22173 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22174 + dirwh = au_sbi(sb)->si_dirwh;
22175 + rmdir_later = (dirwh <= 1);
22176 + if (!rmdir_later)
22177 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22180 + return rmdir_later;
22183 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22184 + if (unlikely(err)) {
22185 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22186 + h_dentry, bindex, err);
22196 + * final procedure for deleting a entry.
22197 + * maintain dentry and iattr.
22199 +static void epilog(struct inode *dir, struct dentry *dentry,
22200 + aufs_bindex_t bindex)
22202 + struct inode *inode;
22204 + inode = d_inode(dentry);
22206 + inode->i_ctime = dir->i_ctime;
22208 + au_dir_ts(dir, bindex);
22209 + inode_inc_iversion(dir);
22213 + * when an error happened, remove the created whiteout and revert everything.
22215 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22216 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22217 + struct dentry *dentry, struct au_dtime *dt)
22220 + struct path h_path = {
22221 + .dentry = wh_dentry,
22222 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22225 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22227 + au_set_dbwh(dentry, bwh);
22228 + au_dtime_revert(dt);
22232 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22236 +/* ---------------------------------------------------------------------- */
22238 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22241 + aufs_bindex_t bwh, bindex, btop;
22242 + struct inode *inode, *h_dir, *delegated;
22243 + struct dentry *parent, *wh_dentry;
22244 + /* to reduce stack size */
22246 + struct au_dtime dt;
22247 + struct au_pin pin;
22248 + struct path h_path;
22254 + a = kmalloc(sizeof(*a), GFP_NOFS);
22255 + if (unlikely(!a))
22258 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22259 + if (unlikely(err))
22261 + err = au_d_hashed_positive(dentry);
22262 + if (unlikely(err))
22264 + inode = d_inode(dentry);
22265 + IMustLock(inode);
22267 + if (unlikely(d_is_dir(dentry)))
22268 + goto out_unlock; /* possible? */
22270 + btop = au_dbtop(dentry);
22271 + bwh = au_dbwh(dentry);
22273 + parent = dentry->d_parent; /* dir inode is locked */
22274 + di_write_lock_parent(parent);
22275 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22277 + err = PTR_ERR(wh_dentry);
22278 + if (IS_ERR(wh_dentry))
22281 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22282 + a->h_path.dentry = au_h_dptr(dentry, btop);
22283 + dget(a->h_path.dentry);
22284 + if (bindex == btop) {
22285 + h_dir = au_pinned_h_dir(&a->pin);
22286 + delegated = NULL;
22287 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22288 + if (unlikely(err == -EWOULDBLOCK)) {
22289 + pr_warn("cannot retry for NFSv4 delegation"
22290 + " for an internal unlink\n");
22294 + /* dir inode is locked */
22295 + h_dir = d_inode(wh_dentry->d_parent);
22296 + IMustLock(h_dir);
22301 + vfsub_drop_nlink(inode);
22302 + epilog(dir, dentry, bindex);
22304 + /* update target timestamps */
22305 + if (bindex == btop) {
22306 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22308 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22310 + /* todo: this timestamp may be reverted later */
22311 + inode->i_ctime = h_dir->i_ctime;
22312 + goto out_unpin; /* success */
22319 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22326 + au_unpin(&a->pin);
22328 + dput(a->h_path.dentry);
22330 + di_write_unlock(parent);
22332 + aufs_read_unlock(dentry, AuLock_DW);
22339 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22341 + int err, rmdir_later;
22342 + aufs_bindex_t bwh, bindex, btop;
22343 + struct inode *inode;
22344 + struct dentry *parent, *wh_dentry, *h_dentry;
22345 + struct au_whtmp_rmdir *args;
22346 + /* to reduce stack size */
22348 + struct au_dtime dt;
22349 + struct au_pin pin;
22355 + a = kmalloc(sizeof(*a), GFP_NOFS);
22356 + if (unlikely(!a))
22359 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22360 + if (unlikely(err))
22362 + err = au_alive_dir(dentry);
22363 + if (unlikely(err))
22365 + inode = d_inode(dentry);
22366 + IMustLock(inode);
22368 + if (unlikely(!d_is_dir(dentry)))
22369 + goto out_unlock; /* possible? */
22372 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22373 + if (unlikely(!args))
22376 + parent = dentry->d_parent; /* dir inode is locked */
22377 + di_write_lock_parent(parent);
22378 + err = au_test_empty(dentry, &args->whlist);
22379 + if (unlikely(err))
22382 + btop = au_dbtop(dentry);
22383 + bwh = au_dbwh(dentry);
22385 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22387 + err = PTR_ERR(wh_dentry);
22388 + if (IS_ERR(wh_dentry))
22391 + h_dentry = au_h_dptr(dentry, btop);
22394 + if (bindex == btop) {
22395 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22397 + rmdir_later = err;
22401 + /* stop monitoring */
22402 + au_hn_free(au_hi(inode, btop));
22404 + /* dir inode is locked */
22405 + IMustLock(d_inode(wh_dentry->d_parent));
22410 + vfsub_dead_dir(inode);
22411 + au_set_dbdiropq(dentry, -1);
22412 + epilog(dir, dentry, bindex);
22414 + if (rmdir_later) {
22415 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22419 + goto out_unpin; /* success */
22427 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22434 + au_unpin(&a->pin);
22438 + di_write_unlock(parent);
22440 + au_whtmp_rmdir_free(args);
22442 + aufs_read_unlock(dentry, AuLock_DW);
22449 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22450 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22451 +++ linux/fs/aufs/i_op_ren.c 2021-02-22 22:51:59.061411920 +0100
22453 +// SPDX-License-Identifier: GPL-2.0
22455 + * Copyright (C) 2005-2020 Junjiro R. Okajima
22457 + * This program, aufs is free software; you can redistribute it and/or modify
22458 + * it under the terms of the GNU General Public License as published by
22459 + * the Free Software Foundation; either version 2 of the License, or
22460 + * (at your option) any later version.
22462 + * This program is distributed in the hope that it will be useful,
22463 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22464 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22465 + * GNU General Public License for more details.
22467 + * You should have received a copy of the GNU General Public License
22468 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22472 + * inode operation (rename entry)
22473 + * todo: this is crazy monster
22476 +#include <linux/iversion.h>
22479 +enum { AuSRC, AuDST, AuSrcDst };
22480 +enum { AuPARENT, AuCHILD, AuParentChild };
22482 +#define AuRen_ISDIR_SRC 1
22483 +#define AuRen_ISDIR_DST (1 << 1)
22484 +#define AuRen_ISSAMEDIR (1 << 2)
22485 +#define AuRen_WHSRC (1 << 3)
22486 +#define AuRen_WHDST (1 << 4)
22487 +#define AuRen_MNT_WRITE (1 << 5)
22488 +#define AuRen_DT_DSTDIR (1 << 6)
22489 +#define AuRen_DIROPQ_SRC (1 << 7)
22490 +#define AuRen_DIROPQ_DST (1 << 8)
22491 +#define AuRen_DIRREN (1 << 9)
22492 +#define AuRen_DROPPED_SRC (1 << 10)
22493 +#define AuRen_DROPPED_DST (1 << 11)
22494 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22495 +#define au_fset_ren(flags, name) \
22496 + do { (flags) |= AuRen_##name; } while (0)
22497 +#define au_fclr_ren(flags, name) \
22498 + do { (flags) &= ~AuRen_##name; } while (0)
22500 +#ifndef CONFIG_AUFS_DIRREN
22501 +#undef AuRen_DIRREN
22502 +#define AuRen_DIRREN 0
22505 +struct au_ren_args {
22507 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22509 + struct inode *dir, *inode;
22510 + struct au_hinode *hdir, *hinode;
22511 + struct au_dtime dt[AuParentChild];
22512 + aufs_bindex_t btop, bdiropq;
22515 +#define src_dentry sd[AuSRC].dentry
22516 +#define src_dir sd[AuSRC].dir
22517 +#define src_inode sd[AuSRC].inode
22518 +#define src_h_dentry sd[AuSRC].h_dentry
22519 +#define src_parent sd[AuSRC].parent
22520 +#define src_h_parent sd[AuSRC].h_parent
22521 +#define src_wh_dentry sd[AuSRC].wh_dentry
22522 +#define src_hdir sd[AuSRC].hdir
22523 +#define src_hinode sd[AuSRC].hinode
22524 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22525 +#define src_dt sd[AuSRC].dt
22526 +#define src_btop sd[AuSRC].btop
22527 +#define src_bdiropq sd[AuSRC].bdiropq
22529 +#define dst_dentry sd[AuDST].dentry
22530 +#define dst_dir sd[AuDST].dir
22531 +#define dst_inode sd[AuDST].inode
22532 +#define dst_h_dentry sd[AuDST].h_dentry
22533 +#define dst_parent sd[AuDST].parent
22534 +#define dst_h_parent sd[AuDST].h_parent
22535 +#define dst_wh_dentry sd[AuDST].wh_dentry
22536 +#define dst_hdir sd[AuDST].hdir
22537 +#define dst_hinode sd[AuDST].hinode
22538 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22539 +#define dst_dt sd[AuDST].dt
22540 +#define dst_btop sd[AuDST].btop
22541 +#define dst_bdiropq sd[AuDST].bdiropq
22543 + struct dentry *h_trap;
22544 + struct au_branch *br;
22545 + struct path h_path;
22546 + struct au_nhash whlist;
22547 + aufs_bindex_t btgt, src_bwh;
22550 + unsigned short auren_flags;
22551 + unsigned char flags; /* syscall parameter */
22552 + unsigned char exchange;
22555 + struct au_whtmp_rmdir *thargs;
22556 + struct dentry *h_dst;
22557 + struct au_hinode *h_root;
22560 +/* ---------------------------------------------------------------------- */
22563 + * functions for reverting.
22564 + * when an error happened in a single rename systemcall, we should revert
22565 + * everything as if nothing happened.
22566 + * we don't need to revert the copied-up/down the parent dir since they are
22570 +#define RevertFailure(fmt, ...) do { \
22571 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22572 + ##__VA_ARGS__, err, rerr); \
22576 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22579 + struct dentry *d;
22580 +#define src_or_dst(member) a->sd[idx].member
22582 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22583 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22584 + rerr = au_diropq_remove(d, a->btgt);
22585 + au_hn_inode_unlock(src_or_dst(hinode));
22586 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22588 + RevertFailure("remove diropq %pd", d);
22590 +#undef src_or_dst_
22593 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22595 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22596 + au_ren_do_rev_diropq(err, a, AuSRC);
22597 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22598 + au_ren_do_rev_diropq(err, a, AuDST);
22601 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22604 + struct inode *delegated;
22606 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
22607 + a->src_h_parent);
22608 + rerr = PTR_ERR(a->h_path.dentry);
22609 + if (IS_ERR(a->h_path.dentry)) {
22610 + RevertFailure("lkup one %pd", a->src_dentry);
22614 + delegated = NULL;
22615 + rerr = vfsub_rename(a->dst_h_dir,
22616 + au_h_dptr(a->src_dentry, a->btgt),
22617 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22618 + if (unlikely(rerr == -EWOULDBLOCK)) {
22619 + pr_warn("cannot retry for NFSv4 delegation"
22620 + " for an internal rename\n");
22623 + d_drop(a->h_path.dentry);
22624 + dput(a->h_path.dentry);
22625 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22627 + RevertFailure("rename %pd", a->src_dentry);
22630 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22633 + struct inode *delegated;
22635 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
22636 + a->dst_h_parent);
22637 + rerr = PTR_ERR(a->h_path.dentry);
22638 + if (IS_ERR(a->h_path.dentry)) {
22639 + RevertFailure("lkup one %pd", a->dst_dentry);
22642 + if (d_is_positive(a->h_path.dentry)) {
22643 + d_drop(a->h_path.dentry);
22644 + dput(a->h_path.dentry);
22648 + delegated = NULL;
22649 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22650 + &delegated, a->flags);
22651 + if (unlikely(rerr == -EWOULDBLOCK)) {
22652 + pr_warn("cannot retry for NFSv4 delegation"
22653 + " for an internal rename\n");
22656 + d_drop(a->h_path.dentry);
22657 + dput(a->h_path.dentry);
22659 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22661 + RevertFailure("rename %pd", a->h_dst);
22664 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22668 + a->h_path.dentry = a->src_wh_dentry;
22669 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22670 + au_set_dbwh(a->src_dentry, a->src_bwh);
22672 + RevertFailure("unlink %pd", a->src_wh_dentry);
22674 +#undef RevertFailure
22676 +/* ---------------------------------------------------------------------- */
22679 + * when we have to copyup the renaming entry, do it with the rename-target name
22680 + * in order to minimize the cost (the later actual rename is unnecessary).
22681 + * otherwise rename it on the target branch.
22683 +static int au_ren_or_cpup(struct au_ren_args *a)
22686 + struct dentry *d;
22687 + struct inode *delegated;
22689 + d = a->src_dentry;
22690 + if (au_dbtop(d) == a->btgt) {
22691 + a->h_path.dentry = a->dst_h_dentry;
22692 + AuDebugOn(au_dbtop(d) != a->btgt);
22693 + delegated = NULL;
22694 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22695 + a->dst_h_dir, &a->h_path, &delegated,
22697 + if (unlikely(err == -EWOULDBLOCK)) {
22698 + pr_warn("cannot retry for NFSv4 delegation"
22699 + " for an internal rename\n");
22705 + if (!err && a->h_dst)
22706 + /* it will be set to dinfo later */
22712 +/* cf. aufs_rmdir() */
22713 +static int au_ren_del_whtmp(struct au_ren_args *a)
22716 + struct inode *dir;
22718 + dir = a->dst_dir;
22719 + SiMustAnyLock(dir->i_sb);
22720 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22721 + au_sbi(dir->i_sb)->si_dirwh)
22722 + || au_test_fs_remote(a->h_dst->d_sb)) {
22723 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22724 + if (unlikely(err))
22725 + pr_warn("failed removing whtmp dir %pd (%d), "
22726 + "ignored.\n", a->h_dst, err);
22728 + au_nhash_wh_free(&a->thargs->whlist);
22729 + a->thargs->whlist = a->whlist;
22730 + a->whlist.nh_num = 0;
22731 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22733 + a->thargs = NULL;
22739 +/* make it 'opaque' dir. */
22740 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22743 + struct dentry *d, *diropq;
22744 +#define src_or_dst(member) a->sd[idx].member
22747 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22748 + src_or_dst(bdiropq) = au_dbdiropq(d);
22749 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22750 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22751 + diropq = au_diropq_create(d, a->btgt);
22752 + au_hn_inode_unlock(src_or_dst(hinode));
22753 + if (IS_ERR(diropq))
22754 + err = PTR_ERR(diropq);
22758 +#undef src_or_dst_
22762 +static int au_ren_diropq(struct au_ren_args *a)
22765 + unsigned char always;
22766 + struct dentry *d;
22769 + d = a->dst_dentry; /* already renamed on the branch */
22770 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22771 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22772 + && !au_ftest_ren(a->auren_flags, DIRREN)
22773 + && a->btgt != au_dbdiropq(a->src_dentry)
22774 + && (a->dst_wh_dentry
22775 + || a->btgt <= au_dbdiropq(d)
22776 + /* hide the lower to keep xino */
22777 + /* the lowers may not be a dir, but we hide them anyway */
22778 + || a->btgt < au_dbbot(d)
22781 + err = au_ren_do_diropq(a, AuSRC);
22782 + if (unlikely(err))
22784 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22786 + if (!a->exchange)
22787 + goto out; /* success */
22789 + d = a->src_dentry; /* already renamed on the branch */
22790 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22791 + && a->btgt != au_dbdiropq(a->dst_dentry)
22792 + && (a->btgt < au_dbdiropq(d)
22793 + || a->btgt < au_dbbot(d)
22795 + AuDbgDentry(a->src_dentry);
22796 + AuDbgDentry(a->dst_dentry);
22797 + err = au_ren_do_diropq(a, AuDST);
22798 + if (unlikely(err))
22799 + goto out_rev_src;
22800 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22802 + goto out; /* success */
22805 + AuDbg("err %d, reverting src\n", err);
22806 + au_ren_rev_diropq(err, a);
22811 +static int do_rename(struct au_ren_args *a)
22814 + struct dentry *d, *h_d;
22816 + if (!a->exchange) {
22817 + /* prepare workqueue args for asynchronous rmdir */
22818 + h_d = a->dst_h_dentry;
22819 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22820 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22821 + && d_is_positive(h_d)) {
22823 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22825 + if (unlikely(!a->thargs))
22827 + a->h_dst = dget(h_d);
22830 + /* create whiteout for src_dentry */
22831 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22832 + a->src_bwh = au_dbwh(a->src_dentry);
22833 + AuDebugOn(a->src_bwh >= 0);
22834 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22835 + a->src_h_parent);
22836 + err = PTR_ERR(a->src_wh_dentry);
22837 + if (IS_ERR(a->src_wh_dentry))
22841 + /* lookup whiteout for dentry */
22842 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22843 + h_d = au_wh_lkup(a->dst_h_parent,
22844 + &a->dst_dentry->d_name, a->br);
22845 + err = PTR_ERR(h_d);
22848 + if (d_is_negative(h_d))
22851 + a->dst_wh_dentry = h_d;
22854 + /* rename dentry to tmpwh */
22856 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22857 + if (unlikely(err))
22860 + d = a->dst_dentry;
22861 + au_set_h_dptr(d, a->btgt, NULL);
22862 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22863 + if (unlikely(err))
22865 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22869 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22870 +#if 0 /* debugging */
22871 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22872 + && d_is_positive(a->dst_h_dentry)
22873 + && a->src_btop != a->btgt);
22876 + /* rename by vfs_rename or cpup */
22877 + err = au_ren_or_cpup(a);
22878 + if (unlikely(err))
22879 + /* leave the copied-up one */
22882 + /* make dir opaque */
22883 + err = au_ren_diropq(a);
22884 + if (unlikely(err))
22887 + /* update target timestamps */
22888 + if (a->exchange) {
22889 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22890 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22891 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22892 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22894 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22895 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22896 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22897 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22899 + if (!a->exchange) {
22900 + /* remove whiteout for dentry */
22901 + if (a->dst_wh_dentry) {
22902 + a->h_path.dentry = a->dst_wh_dentry;
22903 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22905 + if (unlikely(err))
22909 + /* remove whtmp */
22911 + au_ren_del_whtmp(a); /* ignore this error */
22913 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22916 + goto out_success;
22919 + au_ren_rev_diropq(err, a);
22921 + au_ren_rev_rename(err, a);
22925 + au_ren_rev_whtmp(err, a);
22927 + dput(a->dst_wh_dentry);
22928 + a->dst_wh_dentry = NULL;
22930 + if (a->src_wh_dentry)
22931 + au_ren_rev_whsrc(err, a);
22933 + dput(a->src_wh_dentry);
22934 + dput(a->dst_wh_dentry);
22938 + au_whtmp_rmdir_free(a->thargs);
22939 + a->thargs = NULL;
22945 +/* ---------------------------------------------------------------------- */
22948 + * test if @dentry dir can be rename destination or not.
22949 + * success means, it is a logically empty dir.
22951 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22953 + return au_test_empty(dentry, whlist);
22957 + * test if @a->src_dentry dir can be rename source or not.
22958 + * if it can, return 0.
22960 + * - it is a logically empty dir.
22961 + * - or, it exists on writable branch and has no children including whiteouts
22962 + * on the lower branch unless DIRREN is on.
22964 +static int may_rename_srcdir(struct au_ren_args *a)
22967 + unsigned int rdhash;
22968 + aufs_bindex_t btop, btgt;
22969 + struct dentry *dentry;
22970 + struct super_block *sb;
22971 + struct au_sbinfo *sbinfo;
22973 + dentry = a->src_dentry;
22974 + sb = dentry->d_sb;
22975 + sbinfo = au_sbi(sb);
22976 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22977 + au_fset_ren(a->auren_flags, DIRREN);
22980 + btop = au_dbtop(dentry);
22981 + if (btop != btgt) {
22982 + struct au_nhash whlist;
22984 + SiMustAnyLock(sb);
22985 + rdhash = sbinfo->si_rdhash;
22987 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
22989 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
22990 + if (unlikely(err))
22992 + err = au_test_empty(dentry, &whlist);
22993 + au_nhash_wh_free(&whlist);
22997 + if (btop == au_dbtaildir(dentry))
22998 + return 0; /* success */
23000 + err = au_test_empty_lower(dentry);
23003 + if (err == -ENOTEMPTY) {
23004 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23007 + AuWarn1("renaming dir who has child(ren) on multiple "
23008 + "branches, is not supported\n");
23015 +/* side effect: sets whlist and h_dentry */
23016 +static int au_ren_may_dir(struct au_ren_args *a)
23019 + unsigned int rdhash;
23020 + struct dentry *d;
23022 + d = a->dst_dentry;
23023 + SiMustAnyLock(d->d_sb);
23026 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23027 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23029 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23030 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23031 + if (unlikely(err))
23034 + if (!a->exchange) {
23035 + au_set_dbtop(d, a->dst_btop);
23036 + err = may_rename_dstdir(d, &a->whlist);
23037 + au_set_dbtop(d, a->btgt);
23039 + err = may_rename_srcdir(a);
23041 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23042 + if (unlikely(err))
23045 + d = a->src_dentry;
23046 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23047 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23048 + err = may_rename_srcdir(a);
23049 + if (unlikely(err)) {
23050 + au_nhash_wh_free(&a->whlist);
23051 + a->whlist.nh_num = 0;
23058 +/* ---------------------------------------------------------------------- */
23061 + * simple tests for rename.
23062 + * following the checks in vfs, plus the parent-child relationship.
23064 +static int au_may_ren(struct au_ren_args *a)
23067 + struct inode *h_inode;
23069 + if (a->src_btop == a->btgt) {
23070 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23071 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23072 + if (unlikely(err))
23075 + if (unlikely(a->src_h_dentry == a->h_trap))
23080 + if (a->dst_btop != a->btgt)
23083 + err = -ENOTEMPTY;
23084 + if (unlikely(a->dst_h_dentry == a->h_trap))
23088 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23089 + if (d_really_is_negative(a->dst_dentry)) {
23090 + if (d_is_negative(a->dst_h_dentry))
23091 + err = au_may_add(a->dst_dentry, a->btgt,
23092 + a->dst_h_parent, isdir);
23094 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23096 + h_inode = d_inode(a->dst_h_dentry);
23097 + if (h_inode->i_nlink)
23098 + err = au_may_del(a->dst_dentry, a->btgt,
23099 + a->dst_h_parent, isdir);
23103 + if (unlikely(err == -ENOENT || err == -EEXIST))
23109 +/* ---------------------------------------------------------------------- */
23114 + * - src_dir and dir by lock_rename()
23115 + * - inode if exists
23118 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23120 + * + di_write_lock2_child()
23121 + * + di_write_lock_child()
23122 + * + ii_write_lock_child()
23123 + * + di_write_lock_child2()
23124 + * + ii_write_lock_child2()
23125 + * + src_parent and parent
23126 + * + di_write_lock_parent()
23127 + * + ii_write_lock_parent()
23128 + * + di_write_lock_parent2()
23129 + * + ii_write_lock_parent2()
23130 + * + lower src_dir and dir by vfsub_lock_rename()
23131 + * + verify the every relationships between child and parent. if any
23132 + * of them failed, unlock all and return -EBUSY.
23134 +static void au_ren_unlock(struct au_ren_args *a)
23136 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23137 + a->dst_h_parent, a->dst_hdir);
23138 + if (au_ftest_ren(a->auren_flags, DIRREN)
23140 + au_hn_inode_unlock(a->h_root);
23141 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23142 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23145 +static int au_ren_lock(struct au_ren_args *a)
23148 + unsigned int udba;
23151 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23152 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23153 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23154 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23156 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23157 + if (unlikely(err))
23159 + au_fset_ren(a->auren_flags, MNT_WRITE);
23160 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23161 + struct dentry *root;
23162 + struct inode *dir;
23165 + * sbinfo is already locked, so this ii_read_lock is
23166 + * unnecessary. but our debugging feature checks it.
23168 + root = a->src_inode->i_sb->s_root;
23169 + if (root != a->src_parent && root != a->dst_parent) {
23170 + dir = d_inode(root);
23171 + ii_read_lock_parent3(dir);
23172 + a->h_root = au_hi(dir, a->btgt);
23173 + ii_read_unlock(dir);
23174 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23177 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23178 + a->dst_h_parent, a->dst_hdir);
23179 + udba = au_opt_udba(a->src_dentry->d_sb);
23180 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23181 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23182 + err = au_busy_or_stale();
23183 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23184 + err = au_h_verify(a->src_h_dentry, udba,
23185 + d_inode(a->src_h_parent), a->src_h_parent,
23187 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23188 + err = au_h_verify(a->dst_h_dentry, udba,
23189 + d_inode(a->dst_h_parent), a->dst_h_parent,
23192 + goto out; /* success */
23194 + err = au_busy_or_stale();
23195 + au_ren_unlock(a);
23201 +/* ---------------------------------------------------------------------- */
23203 +static void au_ren_refresh_dir(struct au_ren_args *a)
23205 + struct inode *dir;
23207 + dir = a->dst_dir;
23208 + inode_inc_iversion(dir);
23209 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23210 + /* is this updating defined in POSIX? */
23211 + au_cpup_attr_timesizes(a->src_inode);
23212 + au_cpup_attr_nlink(dir, /*force*/1);
23214 + au_dir_ts(dir, a->btgt);
23216 + if (a->exchange) {
23217 + dir = a->src_dir;
23218 + inode_inc_iversion(dir);
23219 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23220 + /* is this updating defined in POSIX? */
23221 + au_cpup_attr_timesizes(a->dst_inode);
23222 + au_cpup_attr_nlink(dir, /*force*/1);
23224 + au_dir_ts(dir, a->btgt);
23227 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23230 + dir = a->src_dir;
23231 + inode_inc_iversion(dir);
23232 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23233 + au_cpup_attr_nlink(dir, /*force*/1);
23234 + au_dir_ts(dir, a->btgt);
23237 +static void au_ren_refresh(struct au_ren_args *a)
23239 + aufs_bindex_t bbot, bindex;
23240 + struct dentry *d, *h_d;
23241 + struct inode *i, *h_i;
23242 + struct super_block *sb;
23244 + d = a->dst_dentry;
23247 + /* already dget-ed by au_ren_or_cpup() */
23248 + au_set_h_dptr(d, a->btgt, a->h_dst);
23250 + i = a->dst_inode;
23252 + if (!a->exchange) {
23253 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23254 + vfsub_drop_nlink(i);
23256 + vfsub_dead_dir(i);
23257 + au_cpup_attr_timesizes(i);
23259 + au_update_dbrange(d, /*do_put_zero*/1);
23261 + au_cpup_attr_nlink(i, /*force*/1);
23264 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23265 + au_set_h_dptr(d, bindex, NULL);
23266 + bbot = au_dbbot(d);
23267 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23268 + au_set_h_dptr(d, bindex, NULL);
23269 + au_update_dbrange(d, /*do_put_zero*/0);
23273 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23274 + d_drop(a->src_dentry);
23275 + if (au_ftest_ren(a->auren_flags, DIRREN))
23276 + au_set_dbwh(a->src_dentry, -1);
23280 + d = a->src_dentry;
23281 + au_set_dbwh(d, -1);
23282 + bbot = au_dbbot(d);
23283 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23284 + h_d = au_h_dptr(d, bindex);
23286 + au_set_h_dptr(d, bindex, NULL);
23288 + au_set_dbbot(d, a->btgt);
23291 + i = a->src_inode;
23292 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23293 + return; /* success */
23295 + bbot = au_ibbot(i);
23296 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23297 + h_i = au_h_iptr(i, bindex);
23299 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23300 + /* ignore this error */
23301 + au_set_h_iptr(i, bindex, NULL, 0);
23304 + au_set_ibbot(i, a->btgt);
23307 +/* ---------------------------------------------------------------------- */
23309 +/* mainly for link(2) and rename(2) */
23310 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23312 + aufs_bindex_t bdiropq, bwh;
23313 + struct dentry *parent;
23314 + struct au_branch *br;
23316 + parent = dentry->d_parent;
23317 + IMustLock(d_inode(parent)); /* dir is locked */
23319 + bdiropq = au_dbdiropq(parent);
23320 + bwh = au_dbwh(dentry);
23321 + br = au_sbr(dentry->d_sb, btgt);
23322 + if (au_br_rdonly(br)
23323 + || (0 <= bdiropq && bdiropq < btgt)
23324 + || (0 <= bwh && bwh < btgt))
23327 + AuDbg("btgt %d\n", btgt);
23331 +/* sets src_btop, dst_btop and btgt */
23332 +static int au_ren_wbr(struct au_ren_args *a)
23335 + struct au_wr_dir_args wr_dir_args = {
23336 + /* .force_btgt = -1, */
23337 + .flags = AuWrDir_ADD_ENTRY
23340 + a->src_btop = au_dbtop(a->src_dentry);
23341 + a->dst_btop = au_dbtop(a->dst_dentry);
23342 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23343 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23344 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23345 + wr_dir_args.force_btgt = a->src_btop;
23346 + if (a->dst_inode && a->dst_btop < a->src_btop)
23347 + wr_dir_args.force_btgt = a->dst_btop;
23348 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23349 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23352 + au_update_dbtop(a->dst_dentry);
23357 +static void au_ren_dt(struct au_ren_args *a)
23359 + a->h_path.dentry = a->src_h_parent;
23360 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23361 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23362 + a->h_path.dentry = a->dst_h_parent;
23363 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23366 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23367 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23371 + a->h_path.dentry = a->src_h_dentry;
23372 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23373 + if (d_is_positive(a->dst_h_dentry)) {
23374 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23375 + a->h_path.dentry = a->dst_h_dentry;
23376 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23380 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23382 + struct dentry *h_d;
23383 + struct inode *h_inode;
23385 + au_dtime_revert(a->src_dt + AuPARENT);
23386 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23387 + au_dtime_revert(a->dst_dt + AuPARENT);
23389 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23390 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23391 + h_inode = d_inode(h_d);
23392 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23393 + au_dtime_revert(a->src_dt + AuCHILD);
23394 + inode_unlock(h_inode);
23396 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23397 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23398 + h_inode = d_inode(h_d);
23399 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23400 + au_dtime_revert(a->dst_dt + AuCHILD);
23401 + inode_unlock(h_inode);
23406 +/* ---------------------------------------------------------------------- */
23408 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23409 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23410 + unsigned int _flags)
23412 + int err, lock_flags;
23414 + /* reduce stack space */
23415 + struct au_ren_args *a;
23416 + struct au_pin pin;
23418 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23419 + IMustLock(_src_dir);
23420 + IMustLock(_dst_dir);
23423 + if (unlikely(_flags & RENAME_WHITEOUT))
23427 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23428 + a = kzalloc(sizeof(*a), GFP_NOFS);
23429 + if (unlikely(!a))
23432 + a->flags = _flags;
23433 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23434 + && RENAME_EXCHANGE > U8_MAX);
23435 + a->exchange = _flags & RENAME_EXCHANGE;
23436 + a->src_dir = _src_dir;
23437 + a->src_dentry = _src_dentry;
23438 + a->src_inode = NULL;
23439 + if (d_really_is_positive(a->src_dentry))
23440 + a->src_inode = d_inode(a->src_dentry);
23441 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23442 + a->dst_dir = _dst_dir;
23443 + a->dst_dentry = _dst_dentry;
23444 + a->dst_inode = NULL;
23445 + if (d_really_is_positive(a->dst_dentry))
23446 + a->dst_inode = d_inode(a->dst_dentry);
23447 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23448 + if (a->dst_inode) {
23450 + * if EXCHANGE && src is non-dir && dst is dir,
23451 + * dst is not locked.
23453 + /* IMustLock(a->dst_inode); */
23454 + au_igrab(a->dst_inode);
23458 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23459 + if (d_is_dir(a->src_dentry)) {
23460 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23461 + if (unlikely(!a->exchange
23462 + && d_really_is_positive(a->dst_dentry)
23463 + && !d_is_dir(a->dst_dentry)))
23465 + lock_flags |= AuLock_DIRS;
23467 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23468 + au_fset_ren(a->auren_flags, ISDIR_DST);
23469 + if (unlikely(!a->exchange
23470 + && d_really_is_positive(a->src_dentry)
23471 + && !d_is_dir(a->src_dentry)))
23473 + lock_flags |= AuLock_DIRS;
23475 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23477 + if (unlikely(err))
23480 + err = au_d_hashed_positive(a->src_dentry);
23481 + if (unlikely(err))
23484 + if (a->dst_inode) {
23486 + * If it is a dir, VFS unhash it before this
23487 + * function. It means we cannot rely upon d_unhashed().
23489 + if (unlikely(!a->dst_inode->i_nlink))
23491 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23492 + err = au_d_hashed_positive(a->dst_dentry);
23493 + if (unlikely(err && !a->exchange))
23495 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23497 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23501 + * is it possible?
23502 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23503 + * there may exist a problem somewhere else.
23506 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23509 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23510 + di_write_lock_parent(a->dst_parent);
23512 + /* which branch we process */
23513 + err = au_ren_wbr(a);
23514 + if (unlikely(err < 0))
23516 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23517 + a->h_path.mnt = au_br_mnt(a->br);
23519 + /* are they available to be renamed */
23520 + err = au_ren_may_dir(a);
23521 + if (unlikely(err))
23522 + goto out_children;
23524 + /* prepare the writable parent dir on the same branch */
23525 + if (a->dst_btop == a->btgt) {
23526 + au_fset_ren(a->auren_flags, WHDST);
23528 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23529 + if (unlikely(err))
23530 + goto out_children;
23534 + if (!a->exchange) {
23535 + if (a->src_dir != a->dst_dir) {
23537 + * this temporary unlock is safe,
23538 + * because both dir->i_mutex are locked.
23540 + di_write_unlock(a->dst_parent);
23541 + di_write_lock_parent(a->src_parent);
23542 + err = au_wr_dir_need_wh(a->src_dentry,
23543 + au_ftest_ren(a->auren_flags,
23546 + di_write_unlock(a->src_parent);
23547 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23549 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23551 + err = au_wr_dir_need_wh(a->src_dentry,
23552 + au_ftest_ren(a->auren_flags,
23556 + if (unlikely(err < 0))
23557 + goto out_children;
23559 + au_fset_ren(a->auren_flags, WHSRC);
23562 + if (a->src_btop != a->btgt) {
23563 + err = au_pin(&pin, a->src_dentry, a->btgt,
23564 + au_opt_udba(a->src_dentry->d_sb),
23565 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23567 + struct au_cp_generic cpg = {
23568 + .dentry = a->src_dentry,
23570 + .bsrc = a->src_btop,
23573 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23575 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23576 + err = au_sio_cpup_simple(&cpg);
23579 + if (unlikely(err))
23580 + goto out_children;
23581 + a->src_btop = a->btgt;
23582 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23583 + if (!a->exchange)
23584 + au_fset_ren(a->auren_flags, WHSRC);
23588 + if (a->exchange && a->dst_inode
23589 + && a->dst_btop != a->btgt) {
23590 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23591 + au_opt_udba(a->dst_dentry->d_sb),
23592 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23594 + struct au_cp_generic cpg = {
23595 + .dentry = a->dst_dentry,
23597 + .bsrc = a->dst_btop,
23600 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23602 + err = au_sio_cpup_simple(&cpg);
23605 + if (unlikely(err))
23606 + goto out_children;
23607 + a->dst_btop = a->btgt;
23608 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23611 + /* lock them all */
23612 + err = au_ren_lock(a);
23613 + if (unlikely(err))
23614 + /* leave the copied-up one */
23615 + goto out_children;
23617 + if (!a->exchange) {
23618 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23619 + err = au_may_ren(a);
23620 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23621 + err = -ENAMETOOLONG;
23622 + if (unlikely(err))
23626 + /* store timestamps to be revertible */
23629 + /* store dirren info */
23630 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23631 + err = au_dr_rename(a->src_dentry, a->btgt,
23632 + &a->dst_dentry->d_name, &rev);
23634 + if (unlikely(err))
23639 + err = do_rename(a);
23640 + if (unlikely(err))
23643 + if (au_ftest_ren(a->auren_flags, DIRREN))
23644 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23646 + /* update dir attributes */
23647 + au_ren_refresh_dir(a);
23649 + /* dput/iput all lower dentries */
23650 + au_ren_refresh(a);
23652 + goto out_hdir; /* success */
23655 + if (au_ftest_ren(a->auren_flags, DIRREN))
23656 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23658 + au_ren_rev_dt(err, a);
23660 + au_ren_unlock(a);
23662 + au_nhash_wh_free(&a->whlist);
23663 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23664 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23665 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23666 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23670 + if (d_unhashed(a->src_dentry))
23671 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23672 + if (d_unhashed(a->dst_dentry))
23673 + au_fset_ren(a->auren_flags, DROPPED_DST);
23674 + if (!a->exchange)
23675 + d_move(a->src_dentry, a->dst_dentry);
23677 + d_exchange(a->src_dentry, a->dst_dentry);
23678 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23679 + d_drop(a->dst_dentry);
23681 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23682 + d_drop(a->src_dentry);
23684 + au_update_dbtop(a->dst_dentry);
23685 + if (!a->dst_inode)
23686 + d_drop(a->dst_dentry);
23688 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23689 + di_write_unlock(a->dst_parent);
23691 + di_write_unlock2(a->src_parent, a->dst_parent);
23693 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23695 + iput(a->dst_inode);
23697 + au_whtmp_rmdir_free(a->thargs);
23703 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23704 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23705 +++ linux/fs/aufs/Kconfig 2021-02-22 22:51:59.058078584 +0100
23707 +# SPDX-License-Identifier: GPL-2.0
23709 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23711 + Aufs is a stackable unification filesystem such as Unionfs,
23712 + which unifies several directories and provides a merged single
23714 + In the early days, aufs was entirely re-designed and
23715 + re-implemented Unionfs Version 1.x series. Introducing many
23716 + original ideas, approaches and improvements, it becomes totally
23717 + different from Unionfs while keeping the basic features.
23721 + prompt "Maximum number of branches"
23722 + default AUFS_BRANCH_MAX_127
23724 + Specifies the maximum number of branches (or member directories)
23725 + in a single aufs. The larger value consumes more system
23726 + resources and has a minor impact to performance.
23727 +config AUFS_BRANCH_MAX_127
23730 + Specifies the maximum number of branches (or member directories)
23731 + in a single aufs. The larger value consumes more system
23732 + resources and has a minor impact to performance.
23733 +config AUFS_BRANCH_MAX_511
23736 + Specifies the maximum number of branches (or member directories)
23737 + in a single aufs. The larger value consumes more system
23738 + resources and has a minor impact to performance.
23739 +config AUFS_BRANCH_MAX_1023
23742 + Specifies the maximum number of branches (or member directories)
23743 + in a single aufs. The larger value consumes more system
23744 + resources and has a minor impact to performance.
23745 +config AUFS_BRANCH_MAX_32767
23748 + Specifies the maximum number of branches (or member directories)
23749 + in a single aufs. The larger value consumes more system
23750 + resources and has a minor impact to performance.
23753 +config AUFS_SBILIST
23755 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23758 + Automatic configuration for internal use.
23759 + When aufs supports Magic SysRq or /proc, enabled automatically.
23761 +config AUFS_HNOTIFY
23762 + bool "Detect direct branch access (bypassing aufs)"
23764 + If you want to modify files on branches directly, eg. bypassing aufs,
23765 + and want aufs to detect the changes of them fully, then enable this
23766 + option and use 'udba=notify' mount option.
23767 + Currently there is only one available configuration, "fsnotify".
23768 + It will have a negative impact to the performance.
23769 + See detail in aufs.5.
23772 + prompt "method" if AUFS_HNOTIFY
23773 + default AUFS_HFSNOTIFY
23774 +config AUFS_HFSNOTIFY
23779 +config AUFS_EXPORT
23780 + bool "NFS-exportable aufs"
23781 + depends on EXPORTFS
23783 + If you want to export your mounted aufs via NFS, then enable this
23784 + option. There are several requirements for this configuration.
23785 + See detail in aufs.5.
23787 +config AUFS_INO_T_64
23789 + depends on AUFS_EXPORT
23790 + depends on 64BIT && !(ALPHA || S390)
23793 + Automatic configuration for internal use.
23794 + /* typedef unsigned long/int __kernel_ino_t */
23795 + /* alpha and s390x are int */
23798 + bool "support for XATTR/EA (including Security Labels)"
23800 + If your branch fs supports XATTR/EA and you want to make them
23801 + available in aufs too, then enable this opsion and specify the
23802 + branch attributes for EA.
23803 + See detail in aufs.5.
23806 + bool "File-based Hierarchical Storage Management"
23808 + Hierarchical Storage Management (or HSM) is a well-known feature
23809 + in the storage world. Aufs provides this feature as file-based.
23810 + with multiple branches.
23811 + These multiple branches are prioritized, ie. the topmost one
23812 + should be the fastest drive and be used heavily.
23815 + bool "Readdir in userspace"
23817 + Aufs has two methods to provide a merged view for a directory,
23818 + by a user-space library and by kernel-space natively. The latter
23819 + is always enabled but sometimes large and slow.
23820 + If you enable this option, install the library in aufs2-util
23821 + package, and set some environment variables for your readdir(3),
23822 + then the work will be handled in user-space which generally
23823 + shows better performance in most cases.
23824 + See detail in aufs.5.
23826 +config AUFS_DIRREN
23827 + bool "Workaround for rename(2)-ing a directory"
23829 + By default, aufs returns EXDEV error in renameing a dir who has
23830 + his child on the lower branch, since it is a bad idea to issue
23831 + rename(2) internally for every lower branch. But user may not
23832 + accept this behaviour. So here is a workaround to allow such
23833 + rename(2) and store some extra infromation on the writable
23834 + branch. Obviously this costs high (and I don't like it).
23835 + To use this feature, you need to enable this configuration AND
23836 + to specify the mount option `dirren.'
23837 + See details in aufs.5 and the design documents.
23840 + bool "Show whiteouts"
23842 + If you want to make the whiteouts in aufs visible, then enable
23843 + this option and specify 'shwh' mount option. Although it may
23844 + sounds like philosophy or something, but in technically it
23845 + simply shows the name of whiteout with keeping its behaviour.
23847 +config AUFS_BR_RAMFS
23848 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23850 + If you want to use ramfs as an aufs branch fs, then enable this
23851 + option. Generally tmpfs is recommended.
23852 + Aufs prohibited them to be a branch fs by default, because
23853 + initramfs becomes unusable after switch_root or something
23854 + generally. If you sets initramfs as an aufs branch and boot your
23855 + system by switch_root, you will meet a problem easily since the
23856 + files in initramfs may be inaccessible.
23857 + Unless you are going to use ramfs as an aufs branch fs without
23858 + switch_root or something, leave it N.
23860 +config AUFS_BR_FUSE
23861 + bool "Fuse fs as an aufs branch"
23862 + depends on FUSE_FS
23865 + If you want to use fuse-based userspace filesystem as an aufs
23866 + branch fs, then enable this option.
23867 + It implements the internal poll(2) operation which is
23868 + implemented by fuse only (curretnly).
23873 + Automatic configuration for internal use.
23875 +config AUFS_BR_HFSPLUS
23876 + bool "Hfsplus as an aufs branch"
23877 + depends on HFSPLUS_FS
23880 + If you want to use hfsplus fs as an aufs branch fs, then enable
23881 + this option. This option introduces a small overhead at
23882 + copying-up a file on hfsplus.
23884 +config AUFS_BDEV_LOOP
23886 + depends on BLK_DEV_LOOP
23889 + Automatic configuration for internal use.
23890 + Convert =[ym] into =y.
23893 + bool "Debug aufs"
23895 + Enable this to compile aufs internal debug code.
23896 + It will have a negative impact to the performance.
23898 +config AUFS_MAGIC_SYSRQ
23900 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23903 + Automatic configuration for internal use.
23904 + When aufs supports Magic SysRq, enabled automatically.
23906 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23907 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23908 +++ linux/fs/aufs/lcnt.h 2021-02-22 22:51:59.061411920 +0100
23910 +/* SPDX-License-Identifier: GPL-2.0 */
23912 + * Copyright (C) 2018-2020 Junjiro R. Okajima
23914 + * This program, aufs is free software; you can redistribute it and/or modify
23915 + * it under the terms of the GNU General Public License as published by
23916 + * the Free Software Foundation; either version 2 of the License, or
23917 + * (at your option) any later version.
23919 + * This program is distributed in the hope that it will be useful,
23920 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23921 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23922 + * GNU General Public License for more details.
23924 + * You should have received a copy of the GNU General Public License
23925 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23929 + * simple long counter wrapper
23932 +#ifndef __AUFS_LCNT_H__
23933 +#define __AUFS_LCNT_H__
23937 +#include "debug.h"
23939 +#define AuLCntATOMIC 1
23940 +#define AuLCntPCPUCNT 2
23942 + * why does percpu_refcount require extra synchronize_rcu()s in
23943 + * au_br_do_free()
23945 +#define AuLCntPCPUREF 3
23947 +/* #define AuLCntChosen AuLCntATOMIC */
23948 +#define AuLCntChosen AuLCntPCPUCNT
23949 +/* #define AuLCntChosen AuLCntPCPUREF */
23951 +#if AuLCntChosen == AuLCntATOMIC
23952 +#include <linux/atomic.h>
23954 +typedef atomic_long_t au_lcnt_t;
23956 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23958 + atomic_long_set(cnt, 0);
23962 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23967 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
23968 + int do_sync __maybe_unused)
23973 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
23975 + atomic_long_inc(cnt);
23978 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
23980 + atomic_long_dec(cnt);
23983 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
23985 + return atomic_long_read(cnt);
23989 +#if AuLCntChosen == AuLCntPCPUCNT
23990 +#include <linux/percpu_counter.h>
23992 +typedef struct percpu_counter au_lcnt_t;
23994 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23996 + return percpu_counter_init(cnt, 0, GFP_NOFS);
23999 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24004 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24006 + percpu_counter_destroy(cnt);
24009 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24011 + percpu_counter_inc(cnt);
24014 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24016 + percpu_counter_dec(cnt);
24019 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24023 + n = percpu_counter_sum(cnt);
24025 + if (LONG_MAX != LLONG_MAX
24027 + AuWarn1("%s\n", "wrap-around");
24033 +#if AuLCntChosen == AuLCntPCPUREF
24034 +#include <linux/percpu-refcount.h>
24036 +typedef struct percpu_ref au_lcnt_t;
24038 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24041 + release = percpu_ref_exit;
24042 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24045 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24047 + synchronize_rcu();
24050 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24052 + percpu_ref_kill(cnt);
24054 + au_lcnt_wait_for_fin(cnt);
24057 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24059 + percpu_ref_get(cnt);
24062 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24064 + percpu_ref_put(cnt);
24068 + * avoid calling this func as possible.
24070 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24074 + percpu_ref_switch_to_atomic_sync(cnt);
24075 + l = atomic_long_read(&cnt->count);
24077 + percpu_ref_switch_to_percpu(cnt);
24079 + /* percpu_ref is initialized by 1 instead of 0 */
24084 +#ifdef CONFIG_AUFS_DEBUG
24085 +#define AuLCntZero(val) do { \
24088 + AuDbg("%s = %ld\n", #val, l); \
24091 +#define AuLCntZero(val) do {} while (0)
24094 +#endif /* __KERNEL__ */
24095 +#endif /* __AUFS_LCNT_H__ */
24096 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24097 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24098 +++ linux/fs/aufs/loop.c 2021-02-22 22:51:59.061411920 +0100
24100 +// SPDX-License-Identifier: GPL-2.0
24102 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24104 + * This program, aufs is free software; you can redistribute it and/or modify
24105 + * it under the terms of the GNU General Public License as published by
24106 + * the Free Software Foundation; either version 2 of the License, or
24107 + * (at your option) any later version.
24109 + * This program is distributed in the hope that it will be useful,
24110 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24111 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24112 + * GNU General Public License for more details.
24114 + * You should have received a copy of the GNU General Public License
24115 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24119 + * support for loopback block device as a branch
24124 +/* added into drivers/block/loop.c */
24125 +static struct file *(*backing_file_func)(struct super_block *sb);
24128 + * test if two lower dentries have overlapping branches.
24130 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24132 + struct super_block *h_sb;
24133 + struct file *backing_file;
24135 + if (unlikely(!backing_file_func)) {
24136 + /* don't load "loop" module here */
24137 + backing_file_func = symbol_get(loop_backing_file);
24138 + if (unlikely(!backing_file_func))
24139 + /* "loop" module is not loaded */
24143 + h_sb = h_adding->d_sb;
24144 + backing_file = backing_file_func(h_sb);
24145 + if (!backing_file)
24148 + h_adding = backing_file->f_path.dentry;
24150 + * h_adding can be local NFS.
24151 + * in this case aufs cannot detect the loop.
24153 + if (unlikely(h_adding->d_sb == sb))
24155 + return !!au_test_subdir(h_adding, sb->s_root);
24158 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24159 +int au_test_loopback_kthread(void)
24162 + struct task_struct *tsk = current;
24163 + char c, comm[sizeof(tsk->comm)];
24166 + if (tsk->flags & PF_KTHREAD) {
24167 + get_task_comm(comm, tsk);
24169 + ret = ('0' <= c && c <= '9'
24170 + && !strncmp(comm, "loop", 4));
24176 +/* ---------------------------------------------------------------------- */
24178 +#define au_warn_loopback_step 16
24179 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24180 +static unsigned long *au_warn_loopback_array;
24182 +void au_warn_loopback(struct super_block *h_sb)
24184 + int i, new_nelem;
24185 + unsigned long *a, magic;
24186 + static DEFINE_SPINLOCK(spin);
24188 + magic = h_sb->s_magic;
24189 + spin_lock(&spin);
24190 + a = au_warn_loopback_array;
24191 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24192 + if (a[i] == magic) {
24193 + spin_unlock(&spin);
24197 + /* h_sb is new to us, print it */
24198 + if (i < au_warn_loopback_nelem) {
24203 + /* expand the array */
24204 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24205 + a = au_kzrealloc(au_warn_loopback_array,
24206 + au_warn_loopback_nelem * sizeof(unsigned long),
24207 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24208 + /*may_shrink*/0);
24210 + au_warn_loopback_nelem = new_nelem;
24211 + au_warn_loopback_array = a;
24216 + spin_unlock(&spin);
24217 + AuWarn1("realloc failed, ignored\n");
24221 + spin_unlock(&spin);
24222 + pr_warn("you may want to try another patch for loopback file "
24223 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24226 +int au_loopback_init(void)
24229 + struct super_block *sb __maybe_unused;
24231 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24234 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24235 + sizeof(unsigned long), GFP_NOFS);
24236 + if (unlikely(!au_warn_loopback_array))
24242 +void au_loopback_fin(void)
24244 + if (backing_file_func)
24245 + symbol_put(loop_backing_file);
24246 + au_kfree_try_rcu(au_warn_loopback_array);
24248 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24249 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24250 +++ linux/fs/aufs/loop.h 2021-02-22 22:51:59.061411920 +0100
24252 +/* SPDX-License-Identifier: GPL-2.0 */
24254 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24256 + * This program, aufs is free software; you can redistribute it and/or modify
24257 + * it under the terms of the GNU General Public License as published by
24258 + * the Free Software Foundation; either version 2 of the License, or
24259 + * (at your option) any later version.
24261 + * This program is distributed in the hope that it will be useful,
24262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24264 + * GNU General Public License for more details.
24266 + * You should have received a copy of the GNU General Public License
24267 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24271 + * support for loopback mount as a branch
24274 +#ifndef __AUFS_LOOP_H__
24275 +#define __AUFS_LOOP_H__
24280 +struct super_block;
24282 +#ifdef CONFIG_AUFS_BDEV_LOOP
24283 +/* drivers/block/loop.c */
24284 +struct file *loop_backing_file(struct super_block *sb);
24287 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24288 +int au_test_loopback_kthread(void);
24289 +void au_warn_loopback(struct super_block *h_sb);
24291 +int au_loopback_init(void);
24292 +void au_loopback_fin(void);
24294 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24296 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24297 + struct dentry *h_adding)
24298 +AuStubInt0(au_test_loopback_kthread, void)
24299 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24301 +AuStubInt0(au_loopback_init, void)
24302 +AuStubVoid(au_loopback_fin, void)
24303 +#endif /* BLK_DEV_LOOP */
24305 +#endif /* __KERNEL__ */
24306 +#endif /* __AUFS_LOOP_H__ */
24307 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24308 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24309 +++ linux/fs/aufs/magic.mk 2021-02-22 22:51:59.061411920 +0100
24311 +# SPDX-License-Identifier: GPL-2.0
24313 +# defined in ${srctree}/fs/fuse/inode.c
24315 +ifdef CONFIG_FUSE_FS
24316 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24319 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24321 +ifdef CONFIG_XFS_FS
24322 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24325 +# defined in ${srctree}/fs/configfs/mount.c
24327 +ifdef CONFIG_CONFIGFS_FS
24328 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24331 +# defined in ${srctree}/fs/ubifs/ubifs.h
24333 +ifdef CONFIG_UBIFS_FS
24334 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24337 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24339 +ifdef CONFIG_HFSPLUS_FS
24340 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24342 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24343 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24344 +++ linux/fs/aufs/Makefile 2021-02-22 22:51:59.058078584 +0100
24346 +# SPDX-License-Identifier: GPL-2.0
24348 +include ${src}/magic.mk
24349 +ifeq (${CONFIG_AUFS_FS},m)
24350 +include ${src}/conf.mk
24352 +-include ${src}/priv_def.mk
24354 +# cf. include/linux/kernel.h
24356 +ccflags-y += -DDEBUG
24357 +# sparse requires the full pathname
24359 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24361 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24364 +obj-$(CONFIG_AUFS_FS) += aufs.o
24365 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24366 + wkq.o vfsub.o dcsub.o \
24367 + cpup.o whout.o wbr_policy.o \
24368 + dinfo.o dentry.o \
24370 + finfo.o file.o f_op.o \
24372 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24376 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24377 +aufs-$(CONFIG_SYSFS) += sysfs.o
24378 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24379 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24380 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24381 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24382 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24383 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24384 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24385 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24386 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24387 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24388 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24389 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24390 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24391 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24392 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24393 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24394 +++ linux/fs/aufs/module.c 2021-02-22 22:51:59.061411920 +0100
24396 +// SPDX-License-Identifier: GPL-2.0
24398 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24400 + * This program, aufs is free software; you can redistribute it and/or modify
24401 + * it under the terms of the GNU General Public License as published by
24402 + * the Free Software Foundation; either version 2 of the License, or
24403 + * (at your option) any later version.
24405 + * This program is distributed in the hope that it will be useful,
24406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24408 + * GNU General Public License for more details.
24410 + * You should have received a copy of the GNU General Public License
24411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24415 + * module global variables and operations
24418 +#include <linux/module.h>
24419 +#include <linux/seq_file.h>
24422 +/* shrinkable realloc */
24423 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24431 +#if 0 /* unused */
24438 + AuDebugOn(!new_sz);
24441 + diff = au_kmidx_sub(sz, new_sz);
24447 + /* expand or SLOB */
24448 + p = krealloc(p, new_sz, gfp);
24449 + else if (new_sz < sz && may_shrink) {
24453 + q = kmalloc(new_sz, gfp);
24456 + memcpy(q, p, new_sz);
24457 + au_kfree_try_rcu(p);
24468 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24471 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24472 + if (p && new_sz > nused)
24473 + memset(p + nused, 0, new_sz - nused);
24477 +/* ---------------------------------------------------------------------- */
24481 +struct kmem_cache *au_cache[AuCache_Last];
24483 +static void au_cache_fin(void)
24488 + * Make sure all delayed rcu free inodes are flushed before we
24493 + /* excluding AuCache_HNOTIFY */
24494 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24495 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24496 + kmem_cache_destroy(au_cache[i]);
24497 + au_cache[i] = NULL;
24501 +static int __init au_cache_init(void)
24503 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24504 + if (au_cache[AuCache_DINFO])
24505 + /* SLAB_DESTROY_BY_RCU */
24506 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24507 + au_icntnr_init_once);
24508 + if (au_cache[AuCache_ICNTNR])
24509 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24510 + au_fi_init_once);
24511 + if (au_cache[AuCache_FINFO])
24512 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24513 + if (au_cache[AuCache_VDIR])
24514 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24515 + if (au_cache[AuCache_DEHSTR])
24522 +/* ---------------------------------------------------------------------- */
24524 +int au_dir_roflags;
24526 +#ifdef CONFIG_AUFS_SBILIST
24528 + * iterate_supers_type() doesn't protect us from
24529 + * remounting (branch management)
24531 +struct hlist_bl_head au_sbilist;
24535 + * functions for module interface.
24537 +MODULE_LICENSE("GPL");
24538 +/* MODULE_LICENSE("GPL v2"); */
24539 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24540 +MODULE_DESCRIPTION(AUFS_NAME
24541 + " -- Advanced multi layered unification filesystem");
24542 +MODULE_VERSION(AUFS_VERSION);
24543 +MODULE_ALIAS_FS(AUFS_NAME);
24545 +/* this module parameter has no meaning when SYSFS is disabled */
24546 +int sysaufs_brs = 1;
24547 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24548 +module_param_named(brs, sysaufs_brs, int, 0444);
24550 +/* this module parameter has no meaning when USER_NS is disabled */
24552 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24553 +module_param_named(allow_userns, au_userns, bool, 0444);
24555 +/* ---------------------------------------------------------------------- */
24557 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24559 +int au_seq_path(struct seq_file *seq, struct path *path)
24563 + err = seq_path(seq, path, au_esc_chars);
24572 +/* ---------------------------------------------------------------------- */
24574 +static int __init aufs_init(void)
24579 + p = au_esc_chars;
24580 + for (i = 1; i <= ' '; i++)
24586 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24588 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24589 + for (i = 0; i < AuIop_Last; i++)
24590 + aufs_iop_nogetattr[i].getattr = NULL;
24592 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24594 + au_sbilist_init();
24595 + sysaufs_brs_init();
24598 + err = sysaufs_init();
24599 + if (unlikely(err))
24601 + err = dbgaufs_init();
24602 + if (unlikely(err))
24603 + goto out_sysaufs;
24604 + err = au_procfs_init();
24605 + if (unlikely(err))
24606 + goto out_dbgaufs;
24607 + err = au_wkq_init();
24608 + if (unlikely(err))
24610 + err = au_loopback_init();
24611 + if (unlikely(err))
24613 + err = au_hnotify_init();
24614 + if (unlikely(err))
24615 + goto out_loopback;
24616 + err = au_sysrq_init();
24617 + if (unlikely(err))
24619 + err = au_cache_init();
24620 + if (unlikely(err))
24623 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24624 + err = register_filesystem(&aufs_fs_type);
24625 + if (unlikely(err))
24628 + /* since we define pr_fmt, call printk directly */
24629 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24630 + goto out; /* success */
24637 + au_hnotify_fin();
24639 + au_loopback_fin();
24653 +static void __exit aufs_exit(void)
24655 + unregister_filesystem(&aufs_fs_type);
24658 + au_hnotify_fin();
24659 + au_loopback_fin();
24667 +module_init(aufs_init);
24668 +module_exit(aufs_exit);
24669 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24670 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24671 +++ linux/fs/aufs/module.h 2021-02-22 22:51:59.061411920 +0100
24673 +/* SPDX-License-Identifier: GPL-2.0 */
24675 + * Copyright (C) 2005-2020 Junjiro R. Okajima
24677 + * This program, aufs is free software; you can redistribute it and/or modify
24678 + * it under the terms of the GNU General Public License as published by
24679 + * the Free Software Foundation; either version 2 of the License, or
24680 + * (at your option) any later version.
24682 + * This program is distributed in the hope that it will be useful,
24683 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24684 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24685 + * GNU General Public License for more details.
24687 + * You should have received a copy of the GNU General Public License
24688 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24692 + * module initialization and module-global
24695 +#ifndef __AUFS_MODULE_H__
24696 +#define __AUFS_MODULE_H__
24700 +#include <linux/slab.h>
24701 +#include "debug.h"
24702 +#include "dentry.h"
24705 +#include "inode.h"
24710 +/* module parameters */
24711 +extern int sysaufs_brs;
24712 +extern bool au_userns;
24714 +/* ---------------------------------------------------------------------- */
24716 +extern int au_dir_roflags;
24718 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24719 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24723 + * Comparing the size of the object with sizeof(struct rcu_head)
24724 + * case 1: object is always larger
24725 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24726 + * case 2: object is always smaller
24727 + * --> au_kfree_small()
24728 + * case 3: object can be any size
24729 + * --> au_kfree_try_rcu()
24732 +static inline void au_kfree_do_rcu(const void *p)
24735 + struct rcu_head rcu;
24736 + } *a = (void *)p;
24738 + kfree_rcu(a, rcu);
24741 +#define au_kfree_rcu(_p) do { \
24742 + typeof(_p) p = (_p); \
24743 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24745 + au_kfree_do_rcu(p); \
24748 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24749 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24751 +static inline void au_kfree_try_rcu(const void *p)
24755 + if (au_kfree_sz_test(p))
24756 + au_kfree_do_rcu(p);
24761 +static inline void au_kfree_small(const void *p)
24765 + AuDebugOn(au_kfree_sz_test(p));
24769 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24771 +#ifndef CONFIG_SLOB
24772 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24774 + return -1; /* SLOB is untested */
24778 +int au_seq_path(struct seq_file *seq, struct path *path);
24780 +#ifdef CONFIG_PROC_FS
24782 +int __init au_procfs_init(void);
24783 +void au_procfs_fin(void);
24785 +AuStubInt0(au_procfs_init, void);
24786 +AuStubVoid(au_procfs_fin, void);
24789 +/* ---------------------------------------------------------------------- */
24798 + AuCache_HNOTIFY, /* must be last */
24802 +extern struct kmem_cache *au_cache[AuCache_Last];
24804 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24805 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24806 +#define AuCacheCtor(type, ctor) \
24807 + kmem_cache_create(#type, sizeof(struct type), \
24808 + __alignof__(struct type), AuCacheFlags, ctor)
24810 +#define AuCacheFuncs(name, index) \
24811 + static inline struct au_##name *au_cache_alloc_##name(void) \
24812 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24813 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24814 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24816 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24817 + { void *p = rcu; \
24818 + p -= offsetof(struct au_##name, rcu); \
24819 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24820 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24821 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24822 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24824 + static inline void au_cache_free_##name(struct au_##name *p) \
24825 + { /* au_cache_free_##name##_norcu(p); */ \
24826 + au_cache_free_##name##_rcu(p); }
24828 +AuCacheFuncs(dinfo, DINFO);
24829 +AuCacheFuncs(icntnr, ICNTNR);
24830 +AuCacheFuncs(finfo, FINFO);
24831 +AuCacheFuncs(vdir, VDIR);
24832 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24833 +#ifdef CONFIG_AUFS_HNOTIFY
24834 +AuCacheFuncs(hnotify, HNOTIFY);
24837 +#endif /* __KERNEL__ */
24838 +#endif /* __AUFS_MODULE_H__ */
24839 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24840 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24841 +++ linux/fs/aufs/mvdown.c 2021-02-22 22:51:59.061411920 +0100
24843 +// SPDX-License-Identifier: GPL-2.0
24845 + * Copyright (C) 2011-2020 Junjiro R. Okajima
24847 + * This program, aufs is free software; you can redistribute it and/or modify
24848 + * it under the terms of the GNU General Public License as published by
24849 + * the Free Software Foundation; either version 2 of the License, or
24850 + * (at your option) any later version.
24852 + * This program is distributed in the hope that it will be useful,
24853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24855 + * GNU General Public License for more details.
24857 + * You should have received a copy of the GNU General Public License
24858 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24862 + * move-down, opposite of copy-up
24867 +struct au_mvd_args {
24869 + struct super_block *h_sb;
24870 + struct dentry *h_parent;
24871 + struct au_hinode *hdir;
24872 + struct inode *h_dir, *h_inode;
24873 + struct au_pin pin;
24874 + } info[AUFS_MVDOWN_NARRAY];
24876 + struct aufs_mvdown mvdown;
24877 + struct dentry *dentry, *parent;
24878 + struct inode *inode, *dir;
24879 + struct super_block *sb;
24880 + aufs_bindex_t bopq, bwh, bfound;
24881 + unsigned char rename_lock;
24884 +#define mvd_errno mvdown.au_errno
24885 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24886 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24887 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24888 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24890 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24891 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24892 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24893 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24894 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24895 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24897 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24898 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24899 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24900 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24901 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24902 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24904 +#define AU_MVD_PR(flag, ...) do { \
24906 + pr_err(__VA_ARGS__); \
24909 +static int find_lower_writable(struct au_mvd_args *a)
24911 + struct super_block *sb;
24912 + aufs_bindex_t bindex, bbot;
24913 + struct au_branch *br;
24916 + bindex = a->mvd_bsrc;
24917 + bbot = au_sbbot(sb);
24918 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24919 + for (bindex++; bindex <= bbot; bindex++) {
24920 + br = au_sbr(sb, bindex);
24921 + if (au_br_fhsm(br->br_perm)
24922 + && !sb_rdonly(au_br_sb(br)))
24925 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24926 + for (bindex++; bindex <= bbot; bindex++) {
24927 + br = au_sbr(sb, bindex);
24928 + if (!au_br_rdonly(br))
24932 + for (bindex++; bindex <= bbot; bindex++) {
24933 + br = au_sbr(sb, bindex);
24934 + if (!sb_rdonly(au_br_sb(br))) {
24935 + if (au_br_rdonly(br))
24937 + |= AUFS_MVDOWN_ROLOWER_R;
24945 +/* make the parent dir on bdst */
24946 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24951 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24952 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24953 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24954 + a->mvd_h_dst_parent = NULL;
24955 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24956 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24957 + if (!a->mvd_h_dst_parent) {
24958 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24959 + if (unlikely(err)) {
24960 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24963 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24971 +/* lock them all */
24972 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24975 + struct dentry *h_trap;
24977 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24978 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24979 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24980 + au_opt_udba(a->sb),
24981 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24983 + if (unlikely(err)) {
24984 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24988 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24989 + a->rename_lock = 0;
24990 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24991 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24992 + au_opt_udba(a->sb),
24993 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24994 + err = au_do_pin(&a->mvd_pin_src);
24996 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
24997 + if (unlikely(err)) {
24998 + AU_MVD_PR(dmsg, "pin_src failed\n");
25001 + goto out; /* success */
25004 + a->rename_lock = 1;
25005 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25006 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25007 + au_opt_udba(a->sb),
25008 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25010 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25011 + if (unlikely(err)) {
25012 + AU_MVD_PR(dmsg, "pin_src failed\n");
25013 + au_pin_hdir_lock(&a->mvd_pin_dst);
25016 + au_pin_hdir_unlock(&a->mvd_pin_src);
25017 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25018 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25020 + err = (h_trap != a->mvd_h_src_parent);
25022 + err = (h_trap != a->mvd_h_dst_parent);
25024 + BUG_ON(err); /* it should never happen */
25025 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25028 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25029 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25030 + au_pin_hdir_lock(&a->mvd_pin_src);
25031 + au_unpin(&a->mvd_pin_src);
25032 + au_pin_hdir_lock(&a->mvd_pin_dst);
25035 + goto out; /* success */
25038 + au_unpin(&a->mvd_pin_dst);
25044 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25046 + if (!a->rename_lock)
25047 + au_unpin(&a->mvd_pin_src);
25049 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25050 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25051 + au_pin_hdir_lock(&a->mvd_pin_src);
25052 + au_unpin(&a->mvd_pin_src);
25053 + au_pin_hdir_lock(&a->mvd_pin_dst);
25055 + au_unpin(&a->mvd_pin_dst);
25058 +/* copy-down the file */
25059 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25062 + struct au_cp_generic cpg = {
25063 + .dentry = a->dentry,
25064 + .bdst = a->mvd_bdst,
25065 + .bsrc = a->mvd_bsrc,
25067 + .pin = &a->mvd_pin_dst,
25068 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25071 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25072 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25073 + au_fset_cpup(cpg.flags, OVERWRITE);
25074 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25075 + au_fset_cpup(cpg.flags, RWDST);
25076 + err = au_sio_cpdown_simple(&cpg);
25077 + if (unlikely(err))
25078 + AU_MVD_PR(dmsg, "cpdown failed\n");
25085 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25088 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25091 + struct path h_path;
25092 + struct au_branch *br;
25093 + struct inode *delegated;
25095 + br = au_sbr(a->sb, a->mvd_bdst);
25096 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25097 + err = PTR_ERR(h_path.dentry);
25098 + if (IS_ERR(h_path.dentry)) {
25099 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25104 + if (d_is_positive(h_path.dentry)) {
25105 + h_path.mnt = au_br_mnt(br);
25106 + delegated = NULL;
25107 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25108 + &delegated, /*force*/0);
25109 + if (unlikely(err == -EWOULDBLOCK)) {
25110 + pr_warn("cannot retry for NFSv4 delegation"
25111 + " for an internal unlink\n");
25114 + if (unlikely(err))
25115 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25117 + dput(h_path.dentry);
25125 + * unlink the topmost h_dentry
25127 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25130 + struct path h_path;
25131 + struct inode *delegated;
25133 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25134 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25135 + delegated = NULL;
25136 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25137 + if (unlikely(err == -EWOULDBLOCK)) {
25138 + pr_warn("cannot retry for NFSv4 delegation"
25139 + " for an internal unlink\n");
25142 + if (unlikely(err))
25143 + AU_MVD_PR(dmsg, "unlink failed\n");
25149 +/* Since mvdown succeeded, we ignore an error of this function */
25150 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25153 + struct au_branch *br;
25155 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25156 + br = au_sbr(a->sb, a->mvd_bsrc);
25157 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25159 + br = au_sbr(a->sb, a->mvd_bdst);
25160 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25161 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25164 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25166 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25170 + * copy-down the file and unlink the bsrc file.
25171 + * - unlink the bdst whout if exist
25172 + * - copy-down the file (with whtmp name and rename)
25173 + * - unlink the bsrc file
25175 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25179 + err = au_do_mkdir(dmsg, a);
25181 + err = au_do_lock(dmsg, a);
25182 + if (unlikely(err))
25186 + * do not revert the activities we made on bdst since they should be
25187 + * harmless in aufs.
25190 + err = au_do_cpdown(dmsg, a);
25192 + err = au_do_unlink_wh(dmsg, a);
25193 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25194 + err = au_do_unlink(dmsg, a);
25195 + if (unlikely(err))
25198 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25199 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25200 + if (find_lower_writable(a) < 0)
25201 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25203 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25204 + au_do_stfs(dmsg, a);
25206 + /* maintain internal array */
25207 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25208 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25209 + au_set_dbtop(a->dentry, a->mvd_bdst);
25210 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25211 + au_set_ibtop(a->inode, a->mvd_bdst);
25213 + /* hide the lower */
25214 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25215 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25216 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25217 + au_set_ibbot(a->inode, a->mvd_bsrc);
25219 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25220 + au_set_dbbot(a->dentry, a->mvd_bdst);
25221 + if (au_ibbot(a->inode) < a->mvd_bdst)
25222 + au_set_ibbot(a->inode, a->mvd_bdst);
25225 + au_do_unlock(dmsg, a);
25231 +/* ---------------------------------------------------------------------- */
25233 +/* make sure the file is idle */
25234 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25236 + int err, plinked;
25239 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25240 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25241 + && au_dcount(a->dentry) == 1
25242 + && atomic_read(&a->inode->i_count) == 1
25243 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25244 + && (!plinked || !au_plink_test(a->inode))
25245 + && a->inode->i_nlink == 1)
25250 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25251 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25252 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25253 + a->mvd_h_src_inode->i_nlink,
25254 + plinked, plinked ? au_plink_test(a->inode) : 0);
25261 +/* make sure the parent dir is fine */
25262 +static int au_mvd_args_parent(const unsigned char dmsg,
25263 + struct au_mvd_args *a)
25266 + aufs_bindex_t bindex;
25269 + if (unlikely(au_alive_dir(a->parent))) {
25271 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25275 + a->bopq = au_dbdiropq(a->parent);
25276 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25277 + AuDbg("b%d\n", bindex);
25278 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25279 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25281 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25282 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25283 + a->bopq, a->mvd_bdst);
25291 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25292 + struct au_mvd_args *a)
25295 + struct au_dinfo *dinfo, *tmp;
25297 + /* lookup the next lower positive entry */
25299 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25300 + if (unlikely(!tmp))
25305 + dinfo = au_di(a->dentry);
25306 + au_di_cp(tmp, dinfo);
25307 + au_di_swap(tmp, dinfo);
25309 + /* returns the number of positive dentries */
25310 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25311 + /* AuLkup_IGNORE_PERM */ 0);
25313 + a->bwh = au_dbwh(a->dentry);
25314 + else if (err > 0)
25315 + a->bfound = au_dbtop(a->dentry);
25317 + au_di_swap(tmp, dinfo);
25318 + au_rw_write_unlock(&tmp->di_rwsem);
25320 + if (unlikely(err < 0))
25321 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25324 + * here, we have these cases.
25326 + * no positive dentry under bsrc. there are more sub-cases.
25328 + * there no whiteout, we can safely move-down.
25331 + * bsrc < bwh && bwh < bdst
25332 + * there is a whiteout on RO branch. cannot proceed.
25334 + * there is a whiteout on the RW target branch. it should
25337 + * there is a whiteout somewhere unrelated branch.
25338 + * -1 < bfound && bfound <= bsrc
25341 + * found, but it is on RO branch between bsrc and bdst. cannot
25344 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25347 + * found, after we create the file on bdst, it will be hidden.
25350 + AuDebugOn(a->bfound == -1
25352 + && a->bwh <= a->mvd_bsrc);
25353 + AuDebugOn(-1 < a->bfound
25354 + && a->bfound <= a->mvd_bsrc);
25357 + if (a->bfound == -1
25358 + && a->mvd_bsrc < a->bwh
25360 + && a->bwh < a->mvd_bdst) {
25361 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25362 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25363 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25365 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25366 + a->mvd_errno = EAU_MVDOWN_UPPER;
25367 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25368 + a->mvd_bdst, a->bfound);
25372 + err = 0; /* success */
25379 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25384 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25385 + && a->bfound == a->mvd_bdst)
25391 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25394 + struct au_branch *br;
25397 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25401 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25402 + a->mvd_bsrc = au_ibtop(a->inode);
25404 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25405 + if (unlikely(a->mvd_bsrc < 0
25406 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25407 + || au_dbbot(a->dentry) < a->mvd_bsrc
25408 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25409 + || (a->mvd_bsrc < au_ibtop(a->inode)
25410 + || au_ibbot(a->inode) < a->mvd_bsrc
25411 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25412 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25413 + AU_MVD_PR(dmsg, "no upper\n");
25417 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25418 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25419 + AU_MVD_PR(dmsg, "on the bottom\n");
25422 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25423 + br = au_sbr(a->sb, a->mvd_bsrc);
25424 + err = au_br_rdonly(br);
25425 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25426 + if (unlikely(err))
25428 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25429 + || IS_APPEND(a->mvd_h_src_inode))) {
25431 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25437 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25438 + a->mvd_bdst = find_lower_writable(a);
25439 + if (unlikely(a->mvd_bdst < 0)) {
25440 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25441 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25445 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25446 + if (unlikely(a->mvd_bdst < 0
25447 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25448 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25449 + AU_MVD_PR(dmsg, "no lower brid\n");
25454 + err = au_mvd_args_busy(dmsg, a);
25456 + err = au_mvd_args_parent(dmsg, a);
25458 + err = au_mvd_args_intermediate(dmsg, a);
25460 + err = au_mvd_args_exist(dmsg, a);
25462 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25469 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25472 + unsigned char dmsg;
25473 + struct au_mvd_args *args;
25474 + struct inode *inode;
25476 + inode = d_inode(dentry);
25478 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25482 + args = kmalloc(sizeof(*args), GFP_NOFS);
25483 + if (unlikely(!args))
25486 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25488 + /* VERIFY_WRITE */
25489 + err = !access_ok(uarg, sizeof(*uarg));
25490 + if (unlikely(err)) {
25495 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25496 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25497 + args->mvdown.au_errno = 0;
25498 + args->dentry = dentry;
25499 + args->inode = inode;
25500 + args->sb = dentry->d_sb;
25503 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25504 + args->parent = dget_parent(dentry);
25505 + args->dir = d_inode(args->parent);
25506 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25507 + dput(args->parent);
25508 + if (unlikely(args->parent != dentry->d_parent)) {
25509 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25513 + inode_lock_nested(inode, I_MUTEX_CHILD);
25514 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25515 + if (unlikely(err))
25518 + di_write_lock_parent(args->parent);
25519 + err = au_mvd_args(dmsg, args);
25520 + if (unlikely(err))
25523 + err = au_do_mvdown(dmsg, args);
25524 + if (unlikely(err))
25527 + au_cpup_attr_timesizes(args->dir);
25528 + au_cpup_attr_timesizes(inode);
25529 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25530 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25531 + /* au_digen_dec(dentry); */
25534 + di_write_unlock(args->parent);
25535 + aufs_read_unlock(dentry, AuLock_DW);
25537 + inode_unlock(inode);
25539 + inode_unlock(args->dir);
25541 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25544 + au_kfree_rcu(args);
25549 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25550 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25551 +++ linux/fs/aufs/opts.c 2021-02-22 22:51:59.061411920 +0100
25553 +// SPDX-License-Identifier: GPL-2.0
25555 + * Copyright (C) 2005-2020 Junjiro R. Okajima
25557 + * This program, aufs is free software; you can redistribute it and/or modify
25558 + * it under the terms of the GNU General Public License as published by
25559 + * the Free Software Foundation; either version 2 of the License, or
25560 + * (at your option) any later version.
25562 + * This program is distributed in the hope that it will be useful,
25563 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25565 + * GNU General Public License for more details.
25567 + * You should have received a copy of the GNU General Public License
25568 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25572 + * mount options/flags
25575 +#include <linux/namei.h>
25576 +#include <linux/types.h> /* a distribution requires */
25577 +#include <linux/parser.h>
25580 +/* ---------------------------------------------------------------------- */
25584 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25585 + Opt_idel, Opt_imod,
25586 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25587 + Opt_rdblk_def, Opt_rdhash_def,
25588 + Opt_xino, Opt_noxino,
25589 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25590 + Opt_trunc_xino_path, Opt_itrunc_xino,
25591 + Opt_trunc_xib, Opt_notrunc_xib,
25592 + Opt_shwh, Opt_noshwh,
25593 + Opt_plink, Opt_noplink, Opt_list_plink,
25595 + Opt_dio, Opt_nodio,
25596 + Opt_diropq_a, Opt_diropq_w,
25597 + Opt_warn_perm, Opt_nowarn_perm,
25598 + Opt_wbr_copyup, Opt_wbr_create,
25600 + Opt_verbose, Opt_noverbose,
25601 + Opt_sum, Opt_nosum, Opt_wsum,
25602 + Opt_dirperm1, Opt_nodirperm1,
25603 + Opt_dirren, Opt_nodirren,
25604 + Opt_acl, Opt_noacl,
25605 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25608 +static match_table_t options = {
25609 + {Opt_br, "br=%s"},
25610 + {Opt_br, "br:%s"},
25612 + {Opt_add, "add=%d:%s"},
25613 + {Opt_add, "add:%d:%s"},
25614 + {Opt_add, "ins=%d:%s"},
25615 + {Opt_add, "ins:%d:%s"},
25616 + {Opt_append, "append=%s"},
25617 + {Opt_append, "append:%s"},
25618 + {Opt_prepend, "prepend=%s"},
25619 + {Opt_prepend, "prepend:%s"},
25621 + {Opt_del, "del=%s"},
25622 + {Opt_del, "del:%s"},
25623 + /* {Opt_idel, "idel:%d"}, */
25624 + {Opt_mod, "mod=%s"},
25625 + {Opt_mod, "mod:%s"},
25626 + /* {Opt_imod, "imod:%d:%s"}, */
25628 + {Opt_dirwh, "dirwh=%d"},
25630 + {Opt_xino, "xino=%s"},
25631 + {Opt_noxino, "noxino"},
25632 + {Opt_trunc_xino, "trunc_xino"},
25633 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25634 + {Opt_notrunc_xino, "notrunc_xino"},
25635 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25636 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25637 + /* {Opt_zxino, "zxino=%s"}, */
25638 + {Opt_trunc_xib, "trunc_xib"},
25639 + {Opt_notrunc_xib, "notrunc_xib"},
25641 +#ifdef CONFIG_PROC_FS
25642 + {Opt_plink, "plink"},
25644 + {Opt_ignore_silent, "plink"},
25647 + {Opt_noplink, "noplink"},
25649 +#ifdef CONFIG_AUFS_DEBUG
25650 + {Opt_list_plink, "list_plink"},
25653 + {Opt_udba, "udba=%s"},
25655 + {Opt_dio, "dio"},
25656 + {Opt_nodio, "nodio"},
25658 +#ifdef CONFIG_AUFS_DIRREN
25659 + {Opt_dirren, "dirren"},
25660 + {Opt_nodirren, "nodirren"},
25662 + {Opt_ignore, "dirren"},
25663 + {Opt_ignore_silent, "nodirren"},
25666 +#ifdef CONFIG_AUFS_FHSM
25667 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25669 + {Opt_ignore, "fhsm_sec=%d"},
25672 + {Opt_diropq_a, "diropq=always"},
25673 + {Opt_diropq_a, "diropq=a"},
25674 + {Opt_diropq_w, "diropq=whiteouted"},
25675 + {Opt_diropq_w, "diropq=w"},
25677 + {Opt_warn_perm, "warn_perm"},
25678 + {Opt_nowarn_perm, "nowarn_perm"},
25680 + /* keep them temporary */
25681 + {Opt_ignore_silent, "nodlgt"},
25682 + {Opt_ignore, "clean_plink"},
25684 +#ifdef CONFIG_AUFS_SHWH
25685 + {Opt_shwh, "shwh"},
25687 + {Opt_noshwh, "noshwh"},
25689 + {Opt_dirperm1, "dirperm1"},
25690 + {Opt_nodirperm1, "nodirperm1"},
25692 + {Opt_verbose, "verbose"},
25693 + {Opt_verbose, "v"},
25694 + {Opt_noverbose, "noverbose"},
25695 + {Opt_noverbose, "quiet"},
25696 + {Opt_noverbose, "q"},
25697 + {Opt_noverbose, "silent"},
25699 + {Opt_sum, "sum"},
25700 + {Opt_nosum, "nosum"},
25701 + {Opt_wsum, "wsum"},
25703 + {Opt_rdcache, "rdcache=%d"},
25704 + {Opt_rdblk, "rdblk=%d"},
25705 + {Opt_rdblk_def, "rdblk=def"},
25706 + {Opt_rdhash, "rdhash=%d"},
25707 + {Opt_rdhash_def, "rdhash=def"},
25709 + {Opt_wbr_create, "create=%s"},
25710 + {Opt_wbr_create, "create_policy=%s"},
25711 + {Opt_wbr_copyup, "cpup=%s"},
25712 + {Opt_wbr_copyup, "copyup=%s"},
25713 + {Opt_wbr_copyup, "copyup_policy=%s"},
25715 + /* generic VFS flag */
25716 +#ifdef CONFIG_FS_POSIX_ACL
25717 + {Opt_acl, "acl"},
25718 + {Opt_noacl, "noacl"},
25720 + {Opt_ignore, "acl"},
25721 + {Opt_ignore_silent, "noacl"},
25724 + /* internal use for the scripts */
25725 + {Opt_ignore_silent, "si=%s"},
25727 + {Opt_br, "dirs=%s"},
25728 + {Opt_ignore, "debug=%d"},
25729 + {Opt_ignore, "delete=whiteout"},
25730 + {Opt_ignore, "delete=all"},
25731 + {Opt_ignore, "imap=%s"},
25733 + /* temporary workaround, due to old mount(8)? */
25734 + {Opt_ignore_silent, "relatime"},
25739 +/* ---------------------------------------------------------------------- */
25741 +static const char *au_parser_pattern(int val, match_table_t tbl)
25743 + struct match_token *p;
25746 + while (p->pattern) {
25747 + if (p->token == val)
25748 + return p->pattern;
25755 +static const char *au_optstr(int *val, match_table_t tbl)
25757 + struct match_token *p;
25764 + while (p->pattern) {
25766 + && (v & p->token) == p->token) {
25767 + *val &= ~p->token;
25768 + return p->pattern;
25777 +/* ---------------------------------------------------------------------- */
25779 +static match_table_t brperm = {
25780 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25781 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25782 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25786 +static match_table_t brattr = {
25788 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25789 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25790 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25791 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25792 +#ifdef CONFIG_AUFS_FHSM
25793 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25795 +#ifdef CONFIG_AUFS_XATTR
25796 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25797 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25798 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25799 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25800 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25801 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25804 + /* ro/rr branch */
25805 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25808 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25809 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25814 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25821 + p = strchr(str, '+');
25824 + v = match_token(str, table, args);
25826 + if (v & AuBrAttr_CMOO_Mask)
25827 + attr &= ~AuBrAttr_CMOO_Mask;
25832 + pr_warn("ignored branch attribute %s\n", str);
25842 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25850 + p = au_optstr(&perm, brattr);
25853 + memcpy(q, p, sz + 1);
25859 + p = au_optstr(&perm, brattr);
25863 + memcpy(q, p, sz + 1);
25869 + return q - str->a;
25872 +static int noinline_for_stack br_perm_val(char *perm)
25874 + int val, bad, sz;
25876 + substring_t args[MAX_OPT_ARGS];
25877 + au_br_perm_str_t attr;
25879 + p = strchr(perm, '+');
25882 + val = match_token(perm, brperm, args);
25886 + pr_warn("ignored branch permission %s\n", perm);
25887 + val = AuBrPerm_RO;
25893 + val |= br_attr_val(p + 1, brattr, args);
25896 + switch (val & AuBrPerm_Mask) {
25897 + case AuBrPerm_RO:
25898 + case AuBrPerm_RR:
25899 + bad = val & AuBrWAttr_Mask;
25900 + val &= ~AuBrWAttr_Mask;
25902 + case AuBrPerm_RW:
25903 + bad = val & AuBrRAttr_Mask;
25904 + val &= ~AuBrRAttr_Mask;
25909 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25910 + * does not treat it as an error, just warning.
25911 + * this is a tiny guard for the user operation.
25913 + if (val & AuBrAttr_UNPIN) {
25914 + bad |= AuBrAttr_UNPIN;
25915 + val &= ~AuBrAttr_UNPIN;
25918 + if (unlikely(bad)) {
25919 + sz = au_do_optstr_br_attr(&attr, bad);
25921 + pr_warn("ignored branch attribute %s\n", attr.a);
25928 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25930 + au_br_perm_str_t attr;
25936 + p = au_optstr(&perm, brperm);
25937 + AuDebugOn(!p || !*p);
25939 + memcpy(q, p, sz + 1);
25942 + sz = au_do_optstr_br_attr(&attr, perm);
25945 + memcpy(q, attr.a, sz + 1);
25948 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25951 +/* ---------------------------------------------------------------------- */
25953 +static match_table_t udbalevel = {
25954 + {AuOpt_UDBA_REVAL, "reval"},
25955 + {AuOpt_UDBA_NONE, "none"},
25956 +#ifdef CONFIG_AUFS_HNOTIFY
25957 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25958 +#ifdef CONFIG_AUFS_HFSNOTIFY
25959 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25965 +static int noinline_for_stack udba_val(char *str)
25967 + substring_t args[MAX_OPT_ARGS];
25969 + return match_token(str, udbalevel, args);
25972 +const char *au_optstr_udba(int udba)
25974 + return au_parser_pattern(udba, udbalevel);
25977 +/* ---------------------------------------------------------------------- */
25979 +static match_table_t au_wbr_create_policy = {
25980 + {AuWbrCreate_TDP, "tdp"},
25981 + {AuWbrCreate_TDP, "top-down-parent"},
25982 + {AuWbrCreate_RR, "rr"},
25983 + {AuWbrCreate_RR, "round-robin"},
25984 + {AuWbrCreate_MFS, "mfs"},
25985 + {AuWbrCreate_MFS, "most-free-space"},
25986 + {AuWbrCreate_MFSV, "mfs:%d"},
25987 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25989 + /* top-down regardless the parent, and then mfs */
25990 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25991 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25993 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25994 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25995 + {AuWbrCreate_PMFS, "pmfs"},
25996 + {AuWbrCreate_PMFSV, "pmfs:%d"},
25997 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
25998 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26003 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26004 + struct au_opt_wbr_create *create)
26007 + unsigned long long ull;
26010 + if (!match_u64(arg, &ull))
26011 + create->mfsrr_watermark = ull;
26013 + pr_err("bad integer in %s\n", str);
26020 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26021 + struct au_opt_wbr_create *create)
26026 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26027 + create->mfs_second = n;
26029 + pr_err("bad integer in %s\n", str);
26036 +static int noinline_for_stack
26037 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26040 + substring_t args[MAX_OPT_ARGS];
26042 + err = match_token(str, au_wbr_create_policy, args);
26043 + create->wbr_create = err;
26045 + case AuWbrCreate_MFSRRV:
26046 + case AuWbrCreate_TDMFSV:
26047 + case AuWbrCreate_PMFSRRV:
26048 + e = au_wbr_mfs_wmark(&args[0], str, create);
26050 + e = au_wbr_mfs_sec(&args[1], str, create);
26054 + case AuWbrCreate_MFSRR:
26055 + case AuWbrCreate_TDMFS:
26056 + case AuWbrCreate_PMFSRR:
26057 + e = au_wbr_mfs_wmark(&args[0], str, create);
26058 + if (unlikely(e)) {
26063 + case AuWbrCreate_MFS:
26064 + case AuWbrCreate_PMFS:
26065 + create->mfs_second = AUFS_MFS_DEF_SEC;
26067 + case AuWbrCreate_MFSV:
26068 + case AuWbrCreate_PMFSV:
26069 + e = au_wbr_mfs_sec(&args[0], str, create);
26078 +const char *au_optstr_wbr_create(int wbr_create)
26080 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26083 +static match_table_t au_wbr_copyup_policy = {
26084 + {AuWbrCopyup_TDP, "tdp"},
26085 + {AuWbrCopyup_TDP, "top-down-parent"},
26086 + {AuWbrCopyup_BUP, "bup"},
26087 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26088 + {AuWbrCopyup_BU, "bu"},
26089 + {AuWbrCopyup_BU, "bottom-up"},
26093 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26095 + substring_t args[MAX_OPT_ARGS];
26097 + return match_token(str, au_wbr_copyup_policy, args);
26100 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26102 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26105 +/* ---------------------------------------------------------------------- */
26107 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26109 +static void dump_opts(struct au_opts *opts)
26111 +#ifdef CONFIG_AUFS_DEBUG
26112 + /* reduce stack space */
26114 + struct au_opt_add *add;
26115 + struct au_opt_del *del;
26116 + struct au_opt_mod *mod;
26117 + struct au_opt_xino *xino;
26118 + struct au_opt_xino_itrunc *xino_itrunc;
26119 + struct au_opt_wbr_create *create;
26121 + struct au_opt *opt;
26124 + while (opt->type != Opt_tail) {
26125 + switch (opt->type) {
26127 + u.add = &opt->add;
26128 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26129 + u.add->bindex, u.add->pathname, u.add->perm,
26130 + u.add->path.dentry);
26134 + u.del = &opt->del;
26135 + AuDbg("del {%s, %p}\n",
26136 + u.del->pathname, u.del->h_path.dentry);
26140 + u.mod = &opt->mod;
26141 + AuDbg("mod {%s, 0x%x, %p}\n",
26142 + u.mod->path, u.mod->perm, u.mod->h_root);
26145 + u.add = &opt->add;
26146 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26147 + u.add->bindex, u.add->pathname, u.add->perm,
26148 + u.add->path.dentry);
26150 + case Opt_prepend:
26151 + u.add = &opt->add;
26152 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26153 + u.add->bindex, u.add->pathname, u.add->perm,
26154 + u.add->path.dentry);
26157 + AuDbg("dirwh %d\n", opt->dirwh);
26159 + case Opt_rdcache:
26160 + AuDbg("rdcache %d\n", opt->rdcache);
26163 + AuDbg("rdblk %u\n", opt->rdblk);
26165 + case Opt_rdblk_def:
26166 + AuDbg("rdblk_def\n");
26169 + AuDbg("rdhash %u\n", opt->rdhash);
26171 + case Opt_rdhash_def:
26172 + AuDbg("rdhash_def\n");
26175 + u.xino = &opt->xino;
26176 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26178 + case Opt_trunc_xino:
26179 + AuLabel(trunc_xino);
26181 + case Opt_notrunc_xino:
26182 + AuLabel(notrunc_xino);
26184 + case Opt_trunc_xino_path:
26185 + case Opt_itrunc_xino:
26186 + u.xino_itrunc = &opt->xino_itrunc;
26187 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26192 + case Opt_trunc_xib:
26193 + AuLabel(trunc_xib);
26195 + case Opt_notrunc_xib:
26196 + AuLabel(notrunc_xib);
26204 + case Opt_dirperm1:
26205 + AuLabel(dirperm1);
26207 + case Opt_nodirperm1:
26208 + AuLabel(nodirperm1);
26213 + case Opt_noplink:
26214 + AuLabel(noplink);
26216 + case Opt_list_plink:
26217 + AuLabel(list_plink);
26220 + AuDbg("udba %d, %s\n",
26221 + opt->udba, au_optstr_udba(opt->udba));
26229 + case Opt_diropq_a:
26230 + AuLabel(diropq_a);
26232 + case Opt_diropq_w:
26233 + AuLabel(diropq_w);
26235 + case Opt_warn_perm:
26236 + AuLabel(warn_perm);
26238 + case Opt_nowarn_perm:
26239 + AuLabel(nowarn_perm);
26241 + case Opt_verbose:
26242 + AuLabel(verbose);
26244 + case Opt_noverbose:
26245 + AuLabel(noverbose);
26256 + case Opt_wbr_create:
26257 + u.create = &opt->wbr_create;
26258 + AuDbg("create %d, %s\n", u.create->wbr_create,
26259 + au_optstr_wbr_create(u.create->wbr_create));
26260 + switch (u.create->wbr_create) {
26261 + case AuWbrCreate_MFSV:
26262 + case AuWbrCreate_PMFSV:
26263 + AuDbg("%d sec\n", u.create->mfs_second);
26265 + case AuWbrCreate_MFSRR:
26266 + case AuWbrCreate_TDMFS:
26267 + AuDbg("%llu watermark\n",
26268 + u.create->mfsrr_watermark);
26270 + case AuWbrCreate_MFSRRV:
26271 + case AuWbrCreate_TDMFSV:
26272 + case AuWbrCreate_PMFSRRV:
26273 + AuDbg("%llu watermark, %d sec\n",
26274 + u.create->mfsrr_watermark,
26275 + u.create->mfs_second);
26279 + case Opt_wbr_copyup:
26280 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26281 + au_optstr_wbr_copyup(opt->wbr_copyup));
26283 + case Opt_fhsm_sec:
26284 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26289 + case Opt_nodirren:
26290 + AuLabel(nodirren);
26306 +void au_opts_free(struct au_opts *opts)
26308 + struct au_opt *opt;
26311 + while (opt->type != Opt_tail) {
26312 + switch (opt->type) {
26315 + case Opt_prepend:
26316 + path_put(&opt->add.path);
26320 + path_put(&opt->del.h_path);
26324 + dput(opt->mod.h_root);
26327 + fput(opt->xino.file);
26334 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26335 + aufs_bindex_t bindex)
26338 + struct au_opt_add *add = &opt->add;
26341 + add->bindex = bindex;
26342 + add->perm = AuBrPerm_RO;
26343 + add->pathname = opt_str;
26344 + p = strchr(opt_str, '=');
26348 + add->perm = br_perm_val(p);
26351 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26354 + add->perm = AuBrPerm_RO;
26355 + if (au_test_fs_rr(add->path.dentry->d_sb))
26356 + add->perm = AuBrPerm_RR;
26357 + else if (!bindex && !(sb_flags & SB_RDONLY))
26358 + add->perm = AuBrPerm_RW;
26360 + opt->type = Opt_add;
26363 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26370 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26374 + del->pathname = args[0].from;
26375 + AuDbg("del path %s\n", del->pathname);
26377 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26378 + if (unlikely(err))
26379 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26384 +#if 0 /* reserved for future use */
26385 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26386 + struct au_opt_del *del, substring_t args[])
26389 + struct dentry *root;
26392 + root = sb->s_root;
26393 + aufs_read_lock(root, AuLock_FLUSH);
26394 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26395 + pr_err("out of bounds, %d\n", bindex);
26400 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26401 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26404 + aufs_read_unlock(root, !AuLock_IR);
26409 +static int noinline_for_stack
26410 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26413 + struct path path;
26417 + mod->path = args[0].from;
26418 + p = strchr(mod->path, '=');
26419 + if (unlikely(!p)) {
26420 + pr_err("no permission %s\n", args[0].from);
26425 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26426 + if (unlikely(err)) {
26427 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26431 + mod->perm = br_perm_val(p);
26432 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26433 + mod->h_root = dget(path.dentry);
26440 +#if 0 /* reserved for future use */
26441 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26442 + struct au_opt_mod *mod, substring_t args[])
26445 + struct dentry *root;
26448 + root = sb->s_root;
26449 + aufs_read_lock(root, AuLock_FLUSH);
26450 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26451 + pr_err("out of bounds, %d\n", bindex);
26456 + mod->perm = br_perm_val(args[1].from);
26457 + AuDbg("mod path %s, perm 0x%x, %s\n",
26458 + mod->path, mod->perm, args[1].from);
26459 + mod->h_root = dget(au_h_dptr(root, bindex));
26462 + aufs_read_unlock(root, !AuLock_IR);
26467 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26468 + substring_t args[])
26471 + struct file *file;
26473 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26474 + err = PTR_ERR(file);
26475 + if (IS_ERR(file))
26479 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26481 + pr_err("%s must be outside\n", args[0].from);
26486 + xino->file = file;
26487 + xino->path = args[0].from;
26493 +static int noinline_for_stack
26494 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26495 + struct au_opt_xino_itrunc *xino_itrunc,
26496 + substring_t args[])
26499 + aufs_bindex_t bbot, bindex;
26500 + struct path path;
26501 + struct dentry *root;
26503 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26504 + if (unlikely(err)) {
26505 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26509 + xino_itrunc->bindex = -1;
26510 + root = sb->s_root;
26511 + aufs_read_lock(root, AuLock_FLUSH);
26512 + bbot = au_sbbot(sb);
26513 + for (bindex = 0; bindex <= bbot; bindex++) {
26514 + if (au_h_dptr(root, bindex) == path.dentry) {
26515 + xino_itrunc->bindex = bindex;
26519 + aufs_read_unlock(root, !AuLock_IR);
26522 + if (unlikely(xino_itrunc->bindex < 0)) {
26523 + pr_err("no such branch %s\n", args[0].from);
26531 +/* called without aufs lock */
26532 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26534 + int err, n, token;
26535 + aufs_bindex_t bindex;
26536 + unsigned char skipped;
26537 + struct dentry *root;
26538 + struct au_opt *opt, *opt_tail;
26540 + /* reduce the stack space */
26542 + struct au_opt_xino_itrunc *xino_itrunc;
26543 + struct au_opt_wbr_create *create;
26546 + substring_t args[MAX_OPT_ARGS];
26550 + a = kmalloc(sizeof(*a), GFP_NOFS);
26551 + if (unlikely(!a))
26554 + root = sb->s_root;
26558 + opt_tail = opt + opts->max_opt - 1;
26559 + opt->type = Opt_tail;
26560 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26563 + token = match_token(opt_str, options, a->args);
26567 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26569 + err = opt_add(opt, opt_str, opts->sb_flags,
26571 + if (unlikely(!err && ++opt > opt_tail)) {
26575 + opt->type = Opt_tail;
26580 + if (unlikely(match_int(&a->args[0], &n))) {
26581 + pr_err("bad integer in %s\n", opt_str);
26585 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26588 + opt->type = token;
26591 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26592 + /*dummy bindex*/1);
26594 + opt->type = token;
26596 + case Opt_prepend:
26597 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26600 + opt->type = token;
26603 + err = au_opts_parse_del(&opt->del, a->args);
26605 + opt->type = token;
26607 +#if 0 /* reserved for future use */
26609 + del->pathname = "(indexed)";
26610 + if (unlikely(match_int(&args[0], &n))) {
26611 + pr_err("bad integer in %s\n", opt_str);
26614 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26616 + opt->type = token;
26620 + err = au_opts_parse_mod(&opt->mod, a->args);
26622 + opt->type = token;
26624 +#ifdef IMOD /* reserved for future use */
26626 + u.mod->path = "(indexed)";
26627 + if (unlikely(match_int(&a->args[0], &n))) {
26628 + pr_err("bad integer in %s\n", opt_str);
26631 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26633 + opt->type = token;
26637 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26639 + opt->type = token;
26642 + case Opt_trunc_xino_path:
26643 + err = au_opts_parse_xino_itrunc_path
26644 + (sb, &opt->xino_itrunc, a->args);
26646 + opt->type = token;
26649 + case Opt_itrunc_xino:
26650 + u.xino_itrunc = &opt->xino_itrunc;
26651 + if (unlikely(match_int(&a->args[0], &n))) {
26652 + pr_err("bad integer in %s\n", opt_str);
26655 + u.xino_itrunc->bindex = n;
26656 + aufs_read_lock(root, AuLock_FLUSH);
26657 + if (n < 0 || au_sbbot(sb) < n) {
26658 + pr_err("out of bounds, %d\n", n);
26659 + aufs_read_unlock(root, !AuLock_IR);
26662 + aufs_read_unlock(root, !AuLock_IR);
26664 + opt->type = token;
26668 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26671 + opt->type = token;
26674 + case Opt_rdcache:
26675 + if (unlikely(match_int(&a->args[0], &n))) {
26676 + pr_err("bad integer in %s\n", opt_str);
26679 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26680 + pr_err("rdcache must be smaller than %d\n",
26681 + AUFS_RDCACHE_MAX);
26684 + opt->rdcache = n;
26686 + opt->type = token;
26689 + if (unlikely(match_int(&a->args[0], &n)
26691 + || n > KMALLOC_MAX_SIZE)) {
26692 + pr_err("bad integer in %s\n", opt_str);
26695 + if (unlikely(n && n < NAME_MAX)) {
26696 + pr_err("rdblk must be larger than %d\n",
26702 + opt->type = token;
26705 + if (unlikely(match_int(&a->args[0], &n)
26707 + || n * sizeof(struct hlist_head)
26708 + > KMALLOC_MAX_SIZE)) {
26709 + pr_err("bad integer in %s\n", opt_str);
26714 + opt->type = token;
26717 + case Opt_trunc_xino:
26718 + case Opt_notrunc_xino:
26720 + case Opt_trunc_xib:
26721 + case Opt_notrunc_xib:
26724 + case Opt_dirperm1:
26725 + case Opt_nodirperm1:
26727 + case Opt_noplink:
26728 + case Opt_list_plink:
26731 + case Opt_diropq_a:
26732 + case Opt_diropq_w:
26733 + case Opt_warn_perm:
26734 + case Opt_nowarn_perm:
26735 + case Opt_verbose:
26736 + case Opt_noverbose:
26740 + case Opt_rdblk_def:
26741 + case Opt_rdhash_def:
26743 + case Opt_nodirren:
26747 + opt->type = token;
26751 + opt->udba = udba_val(a->args[0].from);
26752 + if (opt->udba >= 0) {
26754 + opt->type = token;
26756 + pr_err("wrong value, %s\n", opt_str);
26759 + case Opt_wbr_create:
26760 + u.create = &opt->wbr_create;
26761 + u.create->wbr_create
26762 + = au_wbr_create_val(a->args[0].from, u.create);
26763 + if (u.create->wbr_create >= 0) {
26765 + opt->type = token;
26767 + pr_err("wrong value, %s\n", opt_str);
26769 + case Opt_wbr_copyup:
26770 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26771 + if (opt->wbr_copyup >= 0) {
26773 + opt->type = token;
26775 + pr_err("wrong value, %s\n", opt_str);
26778 + case Opt_fhsm_sec:
26779 + if (unlikely(match_int(&a->args[0], &n)
26781 + pr_err("bad integer in %s\n", opt_str);
26784 + if (sysaufs_brs) {
26785 + opt->fhsm_second = n;
26786 + opt->type = token;
26788 + pr_warn("ignored %s\n", opt_str);
26793 + pr_warn("ignored %s\n", opt_str);
26795 + case Opt_ignore_silent:
26800 + pr_err("unknown option %s\n", opt_str);
26804 + if (!err && !skipped) {
26805 + if (unlikely(++opt > opt_tail)) {
26808 + opt->type = Opt_tail;
26811 + opt->type = Opt_tail;
26817 + if (unlikely(err))
26818 + au_opts_free(opts);
26824 +static int au_opt_wbr_create(struct super_block *sb,
26825 + struct au_opt_wbr_create *create)
26828 + struct au_sbinfo *sbinfo;
26830 + SiMustWriteLock(sb);
26832 + err = 1; /* handled */
26833 + sbinfo = au_sbi(sb);
26834 + if (sbinfo->si_wbr_create_ops->fin) {
26835 + err = sbinfo->si_wbr_create_ops->fin(sb);
26840 + sbinfo->si_wbr_create = create->wbr_create;
26841 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26842 + switch (create->wbr_create) {
26843 + case AuWbrCreate_MFSRRV:
26844 + case AuWbrCreate_MFSRR:
26845 + case AuWbrCreate_TDMFS:
26846 + case AuWbrCreate_TDMFSV:
26847 + case AuWbrCreate_PMFSRR:
26848 + case AuWbrCreate_PMFSRRV:
26849 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26851 + case AuWbrCreate_MFS:
26852 + case AuWbrCreate_MFSV:
26853 + case AuWbrCreate_PMFS:
26854 + case AuWbrCreate_PMFSV:
26855 + sbinfo->si_wbr_mfs.mfs_expire
26856 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26860 + if (sbinfo->si_wbr_create_ops->init)
26861 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26868 + * plus: processed without an error
26869 + * zero: unprocessed
26871 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26872 + struct au_opts *opts)
26875 + struct au_sbinfo *sbinfo;
26877 + SiMustWriteLock(sb);
26879 + err = 1; /* handled */
26880 + sbinfo = au_sbi(sb);
26881 + switch (opt->type) {
26883 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26884 + sbinfo->si_mntflags |= opt->udba;
26885 + opts->given_udba |= opt->udba;
26889 + au_opt_set(sbinfo->si_mntflags, PLINK);
26891 + case Opt_noplink:
26892 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26893 + au_plink_put(sb, /*verbose*/1);
26894 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26896 + case Opt_list_plink:
26897 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26898 + au_plink_list(sb);
26902 + au_opt_set(sbinfo->si_mntflags, DIO);
26903 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26906 + au_opt_clr(sbinfo->si_mntflags, DIO);
26907 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26910 + case Opt_fhsm_sec:
26911 + au_fhsm_set(sbinfo, opt->fhsm_second);
26914 + case Opt_diropq_a:
26915 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26917 + case Opt_diropq_w:
26918 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26921 + case Opt_warn_perm:
26922 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26924 + case Opt_nowarn_perm:
26925 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26928 + case Opt_verbose:
26929 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26931 + case Opt_noverbose:
26932 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26936 + au_opt_set(sbinfo->si_mntflags, SUM);
26939 + au_opt_clr(sbinfo->si_mntflags, SUM);
26940 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26943 + au_opt_clr(sbinfo->si_mntflags, SUM);
26944 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26947 + case Opt_wbr_create:
26948 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26950 + case Opt_wbr_copyup:
26951 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26952 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26956 + sbinfo->si_dirwh = opt->dirwh;
26959 + case Opt_rdcache:
26960 + sbinfo->si_rdcache
26961 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26964 + sbinfo->si_rdblk = opt->rdblk;
26966 + case Opt_rdblk_def:
26967 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26970 + sbinfo->si_rdhash = opt->rdhash;
26972 + case Opt_rdhash_def:
26973 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26977 + au_opt_set(sbinfo->si_mntflags, SHWH);
26980 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26983 + case Opt_dirperm1:
26984 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26986 + case Opt_nodirperm1:
26987 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26990 + case Opt_trunc_xino:
26991 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26993 + case Opt_notrunc_xino:
26994 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
26997 + case Opt_trunc_xino_path:
26998 + case Opt_itrunc_xino:
26999 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27005 + case Opt_trunc_xib:
27006 + au_fset_opts(opts->flags, TRUNC_XIB);
27008 + case Opt_notrunc_xib:
27009 + au_fclr_opts(opts->flags, TRUNC_XIB);
27014 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27015 + err = au_dr_opt_set(sb);
27020 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27022 + case Opt_nodirren:
27024 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27025 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27031 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27035 + sb->s_flags |= SB_POSIXACL;
27038 + sb->s_flags &= ~SB_POSIXACL;
27050 + * returns tri-state.
27051 + * plus: processed without an error
27052 + * zero: unprocessed
27055 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27056 + struct au_opts *opts)
27058 + int err, do_refresh;
27061 + switch (opt->type) {
27063 + opt->add.bindex = au_sbbot(sb) + 1;
27064 + if (opt->add.bindex < 0)
27065 + opt->add.bindex = 0;
27067 + /* Always goto add, not fallthrough */
27068 + case Opt_prepend:
27069 + opt->add.bindex = 0;
27071 + add: /* indented label */
27073 + err = au_br_add(sb, &opt->add,
27074 + au_ftest_opts(opts->flags, REMOUNT));
27077 + au_fset_opts(opts->flags, REFRESH);
27083 + err = au_br_del(sb, &opt->del,
27084 + au_ftest_opts(opts->flags, REMOUNT));
27087 + au_fset_opts(opts->flags, TRUNC_XIB);
27088 + au_fset_opts(opts->flags, REFRESH);
27094 + err = au_br_mod(sb, &opt->mod,
27095 + au_ftest_opts(opts->flags, REMOUNT),
27100 + au_fset_opts(opts->flags, REFRESH);
27107 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27108 + struct au_opt_xino **opt_xino,
27109 + struct au_opts *opts)
27114 + switch (opt->type) {
27116 + err = au_xino_set(sb, &opt->xino,
27117 + !!au_ftest_opts(opts->flags, REMOUNT));
27118 + if (unlikely(err))
27121 + *opt_xino = &opt->xino;
27126 + *opt_xino = (void *)-1;
27133 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27134 + unsigned int pending)
27137 + aufs_bindex_t bindex, bbot;
27138 + unsigned char do_plink, skip, do_free, can_no_dreval;
27139 + struct au_branch *br;
27140 + struct au_wbr *wbr;
27141 + struct dentry *root, *dentry;
27142 + struct inode *dir, *h_dir;
27143 + struct au_sbinfo *sbinfo;
27144 + struct au_hinode *hdir;
27146 + SiMustAnyLock(sb);
27148 + sbinfo = au_sbi(sb);
27149 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27151 + if (!(sb_flags & SB_RDONLY)) {
27152 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27153 + pr_warn("first branch should be rw\n");
27154 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27155 + pr_warn_once("shwh should be used with ro\n");
27158 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27159 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27160 + pr_warn_once("udba=*notify requires xino\n");
27162 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27163 + pr_warn_once("dirperm1 breaks the protection"
27164 + " by the permission bits on the lower branch\n");
27168 + root = sb->s_root;
27169 + dir = d_inode(root);
27170 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27171 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27173 + bbot = au_sbbot(sb);
27174 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27176 + h_dir = au_h_iptr(dir, bindex);
27177 + br = au_sbr(sb, bindex);
27179 + if ((br->br_perm & AuBrAttr_ICEX)
27180 + && !h_dir->i_op->listxattr)
27181 + br->br_perm &= ~AuBrAttr_ICEX;
27182 +#if 0 /* untested */
27183 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27184 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27185 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27189 + wbr = br->br_wbr;
27191 + wbr_wh_read_lock(wbr);
27193 + if (!au_br_writable(br->br_perm)) {
27196 + || (!wbr->wbr_whbase
27197 + && !wbr->wbr_plink
27198 + && !wbr->wbr_orph));
27199 + } else if (!au_br_wh_linkable(br->br_perm)) {
27200 + /* skip = (!br->br_whbase && !br->br_orph); */
27201 + skip = (!wbr || !wbr->wbr_whbase);
27202 + if (skip && wbr) {
27204 + skip = !!wbr->wbr_plink;
27206 + skip = !wbr->wbr_plink;
27209 + /* skip = (br->br_whbase && br->br_ohph); */
27210 + skip = (wbr && wbr->wbr_whbase);
27213 + skip = !!wbr->wbr_plink;
27215 + skip = !wbr->wbr_plink;
27219 + wbr_wh_read_unlock(wbr);
27221 + if (can_no_dreval) {
27222 + dentry = br->br_path.dentry;
27223 + spin_lock(&dentry->d_lock);
27224 + if (dentry->d_flags &
27225 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27226 + can_no_dreval = 0;
27227 + spin_unlock(&dentry->d_lock);
27230 + if (au_br_fhsm(br->br_perm)) {
27232 + AuDebugOn(!br->br_fhsm);
27238 + hdir = au_hi(dir, bindex);
27239 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27241 + wbr_wh_write_lock(wbr);
27242 + err = au_wh_init(br, sb);
27244 + wbr_wh_write_unlock(wbr);
27245 + au_hn_inode_unlock(hdir);
27247 + if (!err && do_free) {
27248 + au_kfree_rcu(wbr);
27249 + br->br_wbr = NULL;
27253 + if (can_no_dreval)
27254 + au_fset_si(sbinfo, NO_DREVAL);
27256 + au_fclr_si(sbinfo, NO_DREVAL);
27259 + au_fset_si(sbinfo, FHSM);
27260 + for (bindex = bbot; bindex >= 0; bindex--) {
27261 + br = au_sbr(sb, bindex);
27262 + if (au_br_fhsm(br->br_perm)) {
27263 + au_fhsm_set_bottom(sb, bindex);
27268 + au_fclr_si(sbinfo, FHSM);
27269 + au_fhsm_set_bottom(sb, -1);
27275 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27278 + unsigned int tmp;
27279 + aufs_bindex_t bindex, bbot;
27280 + struct au_opt *opt;
27281 + struct au_opt_xino *opt_xino, xino;
27282 + struct au_sbinfo *sbinfo;
27283 + struct au_branch *br;
27284 + struct inode *dir;
27286 + SiMustWriteLock(sb);
27291 + while (err >= 0 && opt->type != Opt_tail)
27292 + err = au_opt_simple(sb, opt++, opts);
27295 + else if (unlikely(err < 0))
27298 + /* disable xino and udba temporary */
27299 + sbinfo = au_sbi(sb);
27300 + tmp = sbinfo->si_mntflags;
27301 + au_opt_clr(sbinfo->si_mntflags, XINO);
27302 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27305 + while (err >= 0 && opt->type != Opt_tail)
27306 + err = au_opt_br(sb, opt++, opts);
27309 + else if (unlikely(err < 0))
27312 + bbot = au_sbbot(sb);
27313 + if (unlikely(bbot < 0)) {
27315 + pr_err("no branches\n");
27319 + if (au_opt_test(tmp, XINO))
27320 + au_opt_set(sbinfo->si_mntflags, XINO);
27322 + while (!err && opt->type != Opt_tail)
27323 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27324 + if (unlikely(err))
27327 + err = au_opts_verify(sb, sb->s_flags, tmp);
27328 + if (unlikely(err))
27331 + /* restore xino */
27332 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27333 + xino.file = au_xino_def(sb);
27334 + err = PTR_ERR(xino.file);
27335 + if (IS_ERR(xino.file))
27338 + err = au_xino_set(sb, &xino, /*remount*/0);
27340 + if (unlikely(err))
27344 + /* restore udba */
27345 + tmp &= AuOptMask_UDBA;
27346 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27347 + sbinfo->si_mntflags |= tmp;
27348 + bbot = au_sbbot(sb);
27349 + for (bindex = 0; bindex <= bbot; bindex++) {
27350 + br = au_sbr(sb, bindex);
27351 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27352 + if (unlikely(err))
27353 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27355 + /* go on even if err */
27357 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27358 + dir = d_inode(sb->s_root);
27359 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27366 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27369 + unsigned char no_dreval;
27370 + struct inode *dir;
27371 + struct au_opt_xino *opt_xino;
27372 + struct au_opt *opt;
27373 + struct au_sbinfo *sbinfo;
27375 + SiMustWriteLock(sb);
27377 + err = au_dr_opt_flush(sb);
27378 + if (unlikely(err))
27380 + au_fset_opts(opts->flags, DR_FLUSHED);
27382 + dir = d_inode(sb->s_root);
27383 + sbinfo = au_sbi(sb);
27386 + while (err >= 0 && opt->type != Opt_tail) {
27387 + err = au_opt_simple(sb, opt, opts);
27389 + err = au_opt_br(sb, opt, opts);
27391 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27397 + /* go on even err */
27399 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27400 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27401 + if (unlikely(rerr && !err))
27404 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27405 + au_fset_opts(opts->flags, REFRESH_IDOP);
27407 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27408 + rerr = au_xib_trunc(sb);
27409 + if (unlikely(rerr && !err))
27413 + /* will be handled by the caller */
27414 + if (!au_ftest_opts(opts->flags, REFRESH)
27415 + && (opts->given_udba
27416 + || au_opt_test(sbinfo->si_mntflags, XINO)
27417 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27419 + au_fset_opts(opts->flags, REFRESH);
27421 + AuDbg("status 0x%x\n", opts->flags);
27427 +/* ---------------------------------------------------------------------- */
27429 +unsigned int au_opt_udba(struct super_block *sb)
27431 + return au_mntflags(sb) & AuOptMask_UDBA;
27433 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27434 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27435 +++ linux/fs/aufs/opts.h 2021-02-22 22:51:59.061411920 +0100
27437 +/* SPDX-License-Identifier: GPL-2.0 */
27439 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27441 + * This program, aufs is free software; you can redistribute it and/or modify
27442 + * it under the terms of the GNU General Public License as published by
27443 + * the Free Software Foundation; either version 2 of the License, or
27444 + * (at your option) any later version.
27446 + * This program is distributed in the hope that it will be useful,
27447 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27448 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27449 + * GNU General Public License for more details.
27451 + * You should have received a copy of the GNU General Public License
27452 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27456 + * mount options/flags
27459 +#ifndef __AUFS_OPTS_H__
27460 +#define __AUFS_OPTS_H__
27464 +#include <linux/path.h>
27468 +/* ---------------------------------------------------------------------- */
27471 +#define AuOpt_XINO 1 /* external inode number bitmap
27472 + and translation table */
27473 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27474 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27475 +#define AuOpt_UDBA_REVAL (1 << 3)
27476 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27477 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27478 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27479 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27481 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27482 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27483 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27484 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27485 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27486 +#define AuOpt_DIO (1 << 14) /* direct io */
27487 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27489 +#ifndef CONFIG_AUFS_HNOTIFY
27490 +#undef AuOpt_UDBA_HNOTIFY
27491 +#define AuOpt_UDBA_HNOTIFY 0
27493 +#ifndef CONFIG_AUFS_DIRREN
27494 +#undef AuOpt_DIRREN
27495 +#define AuOpt_DIRREN 0
27497 +#ifndef CONFIG_AUFS_SHWH
27499 +#define AuOpt_SHWH 0
27502 +#define AuOpt_Def (AuOpt_XINO \
27503 + | AuOpt_UDBA_REVAL \
27505 + /* | AuOpt_DIRPERM1 */ \
27506 + | AuOpt_WARN_PERM)
27507 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27508 + | AuOpt_UDBA_REVAL \
27509 + | AuOpt_UDBA_HNOTIFY)
27511 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27512 +#define au_opt_set(flags, name) do { \
27513 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27514 + ((flags) |= AuOpt_##name); \
27516 +#define au_opt_set_udba(flags, name) do { \
27517 + (flags) &= ~AuOptMask_UDBA; \
27518 + ((flags) |= AuOpt_##name); \
27520 +#define au_opt_clr(flags, name) do { \
27521 + ((flags) &= ~AuOpt_##name); \
27524 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27526 +#ifdef CONFIG_PROC_FS
27529 + return mntflags & ~AuOpt_PLINK;
27533 +/* ---------------------------------------------------------------------- */
27535 +/* policies to select one among multiple writable branches */
27537 + AuWbrCreate_TDP, /* top down parent */
27538 + AuWbrCreate_RR, /* round robin */
27539 + AuWbrCreate_MFS, /* most free space */
27540 + AuWbrCreate_MFSV, /* mfs with seconds */
27541 + AuWbrCreate_MFSRR, /* mfs then rr */
27542 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27543 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27544 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27545 + AuWbrCreate_PMFS, /* parent and mfs */
27546 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27547 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27548 + AuWbrCreate_PMFSRRV, /* plus seconds */
27550 + AuWbrCreate_Def = AuWbrCreate_TDP
27554 + AuWbrCopyup_TDP, /* top down parent */
27555 + AuWbrCopyup_BUP, /* bottom up parent */
27556 + AuWbrCopyup_BU, /* bottom up */
27558 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27561 +/* ---------------------------------------------------------------------- */
27563 +struct au_opt_add {
27564 + aufs_bindex_t bindex;
27567 + struct path path;
27570 +struct au_opt_del {
27572 + struct path h_path;
27575 +struct au_opt_mod {
27578 + struct dentry *h_root;
27581 +struct au_opt_xino {
27583 + struct file *file;
27586 +struct au_opt_xino_itrunc {
27587 + aufs_bindex_t bindex;
27590 +struct au_opt_wbr_create {
27593 + unsigned long long mfsrr_watermark;
27599 + struct au_opt_xino xino;
27600 + struct au_opt_xino_itrunc xino_itrunc;
27601 + struct au_opt_add add;
27602 + struct au_opt_del del;
27603 + struct au_opt_mod mod;
27606 + unsigned int rdblk;
27607 + unsigned int rdhash;
27609 + struct au_opt_wbr_create wbr_create;
27611 + unsigned int fhsm_second;
27616 +#define AuOpts_REMOUNT 1
27617 +#define AuOpts_REFRESH (1 << 1)
27618 +#define AuOpts_TRUNC_XIB (1 << 2)
27619 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27620 +#define AuOpts_REFRESH_IDOP (1 << 4)
27621 +#define AuOpts_DR_FLUSHED (1 << 5)
27622 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27623 +#define au_fset_opts(flags, name) \
27624 + do { (flags) |= AuOpts_##name; } while (0)
27625 +#define au_fclr_opts(flags, name) \
27626 + do { (flags) &= ~AuOpts_##name; } while (0)
27628 +#ifndef CONFIG_AUFS_DIRREN
27629 +#undef AuOpts_DR_FLUSHED
27630 +#define AuOpts_DR_FLUSHED 0
27634 + struct au_opt *opt;
27637 + unsigned int given_udba;
27638 + unsigned int flags;
27639 + unsigned long sb_flags;
27642 +/* ---------------------------------------------------------------------- */
27645 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27646 +const char *au_optstr_udba(int udba);
27647 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27648 +const char *au_optstr_wbr_create(int wbr_create);
27650 +void au_opts_free(struct au_opts *opts);
27651 +struct super_block;
27652 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27653 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27654 + unsigned int pending);
27655 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27656 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27658 +unsigned int au_opt_udba(struct super_block *sb);
27660 +#endif /* __KERNEL__ */
27661 +#endif /* __AUFS_OPTS_H__ */
27662 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27663 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27664 +++ linux/fs/aufs/plink.c 2021-02-22 22:51:59.061411920 +0100
27666 +// SPDX-License-Identifier: GPL-2.0
27668 + * Copyright (C) 2005-2020 Junjiro R. Okajima
27670 + * This program, aufs is free software; you can redistribute it and/or modify
27671 + * it under the terms of the GNU General Public License as published by
27672 + * the Free Software Foundation; either version 2 of the License, or
27673 + * (at your option) any later version.
27675 + * This program is distributed in the hope that it will be useful,
27676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27678 + * GNU General Public License for more details.
27680 + * You should have received a copy of the GNU General Public License
27681 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27691 + * the pseudo-link maintenance mode.
27692 + * during a user process maintains the pseudo-links,
27693 + * prohibit adding a new plink and branch manipulation.
27697 + * For entry functions which will handle plink, and i_mutex is already held
27699 + * They cannot wait and should return an error at once.
27700 + * Callers has to check the error.
27702 + * For entry functions which will handle plink, but i_mutex is not held
27704 + * They can wait the plink maintenance mode to finish.
27706 + * They behave like F_SETLK and F_SETLKW.
27707 + * If the caller never handle plink, then both flags are unnecessary.
27710 +int au_plink_maint(struct super_block *sb, int flags)
27714 + struct task_struct *parent, *prev;
27715 + struct au_sbinfo *sbi;
27717 + SiMustAnyLock(sb);
27720 + if (!au_opt_test(au_mntflags(sb), PLINK))
27723 + sbi = au_sbi(sb);
27724 + pid = sbi->si_plink_maint_pid;
27725 + if (!pid || pid == current->pid)
27728 + /* todo: it highly depends upon /sbin/mount.aufs */
27730 + parent = current;
27734 + parent = rcu_dereference(parent->real_parent);
27735 + if (parent == prev)
27737 + ppid = task_pid_vnr(parent);
27738 + if (pid == ppid) {
27739 + rcu_read_unlock();
27744 + rcu_read_unlock();
27746 + if (au_ftest_lock(flags, NOPLMW)) {
27747 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27748 + /* AuDebugOn(!lockdep_depth(current)); */
27749 + while (sbi->si_plink_maint_pid) {
27750 + si_read_unlock(sb);
27751 + /* gave up wake_up_bit() */
27752 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27754 + if (au_ftest_lock(flags, FLUSH))
27755 + au_nwt_flush(&sbi->si_nowait);
27756 + si_noflush_read_lock(sb);
27758 + } else if (au_ftest_lock(flags, NOPLM)) {
27759 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27767 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27769 + spin_lock(&sbinfo->si_plink_maint_lock);
27770 + sbinfo->si_plink_maint_pid = 0;
27771 + spin_unlock(&sbinfo->si_plink_maint_lock);
27772 + wake_up_all(&sbinfo->si_plink_wq);
27775 +int au_plink_maint_enter(struct super_block *sb)
27778 + struct au_sbinfo *sbinfo;
27781 + sbinfo = au_sbi(sb);
27782 + /* make sure i am the only one in this fs */
27783 + si_write_lock(sb, AuLock_FLUSH);
27784 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27785 + spin_lock(&sbinfo->si_plink_maint_lock);
27786 + if (!sbinfo->si_plink_maint_pid)
27787 + sbinfo->si_plink_maint_pid = current->pid;
27790 + spin_unlock(&sbinfo->si_plink_maint_lock);
27792 + si_write_unlock(sb);
27797 +/* ---------------------------------------------------------------------- */
27799 +#ifdef CONFIG_AUFS_DEBUG
27800 +void au_plink_list(struct super_block *sb)
27803 + struct au_sbinfo *sbinfo;
27804 + struct hlist_bl_head *hbl;
27805 + struct hlist_bl_node *pos;
27806 + struct au_icntnr *icntnr;
27808 + SiMustAnyLock(sb);
27810 + sbinfo = au_sbi(sb);
27811 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27812 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27814 + for (i = 0; i < AuPlink_NHASH; i++) {
27815 + hbl = sbinfo->si_plink + i;
27816 + hlist_bl_lock(hbl);
27817 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27818 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27819 + hlist_bl_unlock(hbl);
27824 +/* is the inode pseudo-linked? */
27825 +int au_plink_test(struct inode *inode)
27828 + struct au_sbinfo *sbinfo;
27829 + struct hlist_bl_head *hbl;
27830 + struct hlist_bl_node *pos;
27831 + struct au_icntnr *icntnr;
27833 + sbinfo = au_sbi(inode->i_sb);
27834 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27835 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27836 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27839 + i = au_plink_hash(inode->i_ino);
27840 + hbl = sbinfo->si_plink + i;
27841 + hlist_bl_lock(hbl);
27842 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27843 + if (&icntnr->vfs_inode == inode) {
27847 + hlist_bl_unlock(hbl);
27851 +/* ---------------------------------------------------------------------- */
27854 + * generate a name for plink.
27855 + * the file will be stored under AUFS_WH_PLINKDIR.
27857 +/* 20 is max digits length of ulong 64 */
27858 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27860 +static int plink_name(char *name, int len, struct inode *inode,
27861 + aufs_bindex_t bindex)
27864 + struct inode *h_inode;
27866 + h_inode = au_h_iptr(inode, bindex);
27867 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27871 +struct au_do_plink_lkup_args {
27872 + struct dentry **errp;
27873 + struct qstr *tgtname;
27874 + struct dentry *h_parent;
27875 + struct au_branch *br;
27878 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27879 + struct dentry *h_parent,
27880 + struct au_branch *br)
27882 + struct dentry *h_dentry;
27883 + struct inode *h_inode;
27885 + h_inode = d_inode(h_parent);
27886 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27887 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
27888 + inode_unlock_shared(h_inode);
27892 +static void au_call_do_plink_lkup(void *args)
27894 + struct au_do_plink_lkup_args *a = args;
27895 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
27898 +/* lookup the plink-ed @inode under the branch at @bindex */
27899 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27901 + struct dentry *h_dentry, *h_parent;
27902 + struct au_branch *br;
27904 + char a[PLINK_NAME_LEN];
27905 + struct qstr tgtname = QSTR_INIT(a, 0);
27907 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27909 + br = au_sbr(inode->i_sb, bindex);
27910 + h_parent = br->br_wbr->wbr_plink;
27911 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27913 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27914 + struct au_do_plink_lkup_args args = {
27915 + .errp = &h_dentry,
27916 + .tgtname = &tgtname,
27917 + .h_parent = h_parent,
27921 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27922 + if (unlikely(wkq_err))
27923 + h_dentry = ERR_PTR(wkq_err);
27925 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
27930 +/* create a pseudo-link */
27931 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
27932 + struct dentry *h_dentry, struct au_branch *br)
27935 + struct path h_path = {
27936 + .mnt = au_br_mnt(br)
27938 + struct inode *h_dir, *delegated;
27940 + h_dir = d_inode(h_parent);
27941 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27943 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
27944 + err = PTR_ERR(h_path.dentry);
27945 + if (IS_ERR(h_path.dentry))
27949 + /* wh.plink dir is not monitored */
27950 + /* todo: is it really safe? */
27951 + if (d_is_positive(h_path.dentry)
27952 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27953 + delegated = NULL;
27954 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27955 + if (unlikely(err == -EWOULDBLOCK)) {
27956 + pr_warn("cannot retry for NFSv4 delegation"
27957 + " for an internal unlink\n");
27960 + dput(h_path.dentry);
27961 + h_path.dentry = NULL;
27965 + if (!err && d_is_negative(h_path.dentry)) {
27966 + delegated = NULL;
27967 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27968 + if (unlikely(err == -EWOULDBLOCK)) {
27969 + pr_warn("cannot retry for NFSv4 delegation"
27970 + " for an internal link\n");
27974 + dput(h_path.dentry);
27977 + inode_unlock(h_dir);
27981 +struct do_whplink_args {
27983 + struct qstr *tgt;
27984 + struct dentry *h_parent;
27985 + struct dentry *h_dentry;
27986 + struct au_branch *br;
27989 +static void call_do_whplink(void *args)
27991 + struct do_whplink_args *a = args;
27992 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
27995 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27996 + aufs_bindex_t bindex, struct au_branch *br)
27998 + int err, wkq_err;
27999 + struct au_wbr *wbr;
28000 + struct dentry *h_parent;
28001 + char a[PLINK_NAME_LEN];
28002 + struct qstr tgtname = QSTR_INIT(a, 0);
28004 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
28005 + h_parent = wbr->wbr_plink;
28006 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28008 + /* always superio. */
28009 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28010 + struct do_whplink_args args = {
28013 + .h_parent = h_parent,
28014 + .h_dentry = h_dentry,
28017 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28018 + if (unlikely(wkq_err))
28021 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
28027 + * create a new pseudo-link for @h_dentry on @bindex.
28028 + * the linked inode is held in aufs @inode.
28030 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28031 + struct dentry *h_dentry)
28033 + struct super_block *sb;
28034 + struct au_sbinfo *sbinfo;
28035 + struct hlist_bl_head *hbl;
28036 + struct hlist_bl_node *pos;
28037 + struct au_icntnr *icntnr;
28038 + int found, err, cnt, i;
28040 + sb = inode->i_sb;
28041 + sbinfo = au_sbi(sb);
28042 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28043 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28045 + found = au_plink_test(inode);
28049 + i = au_plink_hash(inode->i_ino);
28050 + hbl = sbinfo->si_plink + i;
28053 + hlist_bl_lock(hbl);
28054 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28055 + if (&icntnr->vfs_inode == inode) {
28061 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28062 + hlist_bl_add_head(&icntnr->plink, hbl);
28064 + hlist_bl_unlock(hbl);
28066 + cnt = au_hbl_count(hbl);
28067 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28068 + if (cnt > AUFS_PLINK_WARN)
28069 + AuWarn1(msg ", %d\n", cnt);
28071 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
28072 + if (unlikely(err)) {
28073 + pr_warn("err %d, damaged pseudo link.\n", err);
28074 + au_hbl_del(&icntnr->plink, hbl);
28075 + iput(&icntnr->vfs_inode);
28078 + iput(&icntnr->vfs_inode);
28081 +/* free all plinks */
28082 +void au_plink_put(struct super_block *sb, int verbose)
28085 + struct au_sbinfo *sbinfo;
28086 + struct hlist_bl_head *hbl;
28087 + struct hlist_bl_node *pos, *tmp;
28088 + struct au_icntnr *icntnr;
28090 + SiMustWriteLock(sb);
28092 + sbinfo = au_sbi(sb);
28093 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28094 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28096 + /* no spin_lock since sbinfo is write-locked */
28098 + for (i = 0; i < AuPlink_NHASH; i++) {
28099 + hbl = sbinfo->si_plink + i;
28100 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28101 + pr_warn("pseudo-link is not flushed");
28104 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28105 + iput(&icntnr->vfs_inode);
28106 + INIT_HLIST_BL_HEAD(hbl);
28110 +void au_plink_clean(struct super_block *sb, int verbose)
28112 + struct dentry *root;
28114 + root = sb->s_root;
28115 + aufs_write_lock(root);
28116 + if (au_opt_test(au_mntflags(sb), PLINK))
28117 + au_plink_put(sb, verbose);
28118 + aufs_write_unlock(root);
28121 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28124 + aufs_bindex_t btop, bbot, bindex;
28127 + btop = au_ibtop(inode);
28128 + bbot = au_ibbot(inode);
28130 + for (bindex = btop; bindex <= bbot; bindex++) {
28131 + if (!au_h_iptr(inode, bindex)
28132 + || au_ii_br_id(inode, bindex) != br_id)
28134 + au_set_h_iptr(inode, bindex, NULL, 0);
28139 + for (bindex = btop; bindex <= bbot; bindex++)
28140 + if (au_h_iptr(inode, bindex)) {
28150 +/* free the plinks on a branch specified by @br_id */
28151 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28153 + struct au_sbinfo *sbinfo;
28154 + struct hlist_bl_head *hbl;
28155 + struct hlist_bl_node *pos, *tmp;
28156 + struct au_icntnr *icntnr;
28157 + struct inode *inode;
28160 + SiMustWriteLock(sb);
28162 + sbinfo = au_sbi(sb);
28163 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28164 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28166 + /* no bit_lock since sbinfo is write-locked */
28167 + for (i = 0; i < AuPlink_NHASH; i++) {
28168 + hbl = sbinfo->si_plink + i;
28169 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28170 + inode = au_igrab(&icntnr->vfs_inode);
28171 + ii_write_lock_child(inode);
28172 + do_put = au_plink_do_half_refresh(inode, br_id);
28174 + hlist_bl_del(&icntnr->plink);
28177 + ii_write_unlock(inode);
28182 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28183 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28184 +++ linux/fs/aufs/poll.c 2021-02-22 22:51:59.061411920 +0100
28186 +// SPDX-License-Identifier: GPL-2.0
28188 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28190 + * This program, aufs is free software; you can redistribute it and/or modify
28191 + * it under the terms of the GNU General Public License as published by
28192 + * the Free Software Foundation; either version 2 of the License, or
28193 + * (at your option) any later version.
28195 + * This program is distributed in the hope that it will be useful,
28196 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28197 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28198 + * GNU General Public License for more details.
28200 + * You should have received a copy of the GNU General Public License
28201 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28206 + * There is only one filesystem which implements ->poll operation, currently.
28211 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28214 + struct file *h_file;
28215 + struct super_block *sb;
28217 + /* We should pretend an error happened. */
28218 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28219 + sb = file->f_path.dentry->d_sb;
28220 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28222 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28223 + if (IS_ERR(h_file)) {
28224 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28228 + mask = vfs_poll(h_file, pt);
28229 + fput(h_file); /* instead of au_read_post() */
28232 + si_read_unlock(sb);
28233 + if (mask & EPOLLERR)
28234 + AuDbg("mask 0x%x\n", mask);
28237 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28238 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28239 +++ linux/fs/aufs/posix_acl.c 2021-02-22 22:51:59.061411920 +0100
28241 +// SPDX-License-Identifier: GPL-2.0
28243 + * Copyright (C) 2014-2020 Junjiro R. Okajima
28245 + * This program, aufs is free software; you can redistribute it and/or modify
28246 + * it under the terms of the GNU General Public License as published by
28247 + * the Free Software Foundation; either version 2 of the License, or
28248 + * (at your option) any later version.
28250 + * This program is distributed in the hope that it will be useful,
28251 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28252 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28253 + * GNU General Public License for more details.
28255 + * You should have received a copy of the GNU General Public License
28256 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28260 + * posix acl operations
28263 +#include <linux/fs.h>
28266 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28268 + struct posix_acl *acl;
28270 + aufs_bindex_t bindex;
28271 + struct inode *h_inode;
28272 + struct super_block *sb;
28275 + sb = inode->i_sb;
28276 + si_read_lock(sb, AuLock_FLUSH);
28277 + ii_read_lock_child(inode);
28278 + if (!(sb->s_flags & SB_POSIXACL))
28281 + bindex = au_ibtop(inode);
28282 + h_inode = au_h_iptr(inode, bindex);
28283 + if (unlikely(!h_inode
28284 + || ((h_inode->i_mode & S_IFMT)
28285 + != (inode->i_mode & S_IFMT)))) {
28286 + err = au_busy_or_stale();
28287 + acl = ERR_PTR(err);
28291 + /* always topmost only */
28292 + acl = get_acl(h_inode, type);
28294 + forget_cached_acl(inode, type);
28296 + set_cached_acl(inode, type, acl);
28299 + ii_read_unlock(inode);
28300 + si_read_unlock(sb);
28302 + AuTraceErrPtr(acl);
28306 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28310 + struct dentry *dentry;
28311 + struct au_sxattr arg = {
28312 + .type = AU_ACL_SET,
28319 + IMustLock(inode);
28321 + if (inode->i_ino == AUFS_ROOT_INO)
28322 + dentry = dget(inode->i_sb->s_root);
28324 + dentry = d_find_alias(inode);
28326 + dentry = d_find_any_alias(inode);
28328 + pr_warn("cannot handle this inode, "
28329 + "please report to aufs-users ML\n");
28335 + ssz = au_sxattr(dentry, inode, &arg);
28336 + /* forget even it if succeeds since the branch might set differently */
28337 + forget_cached_acl(inode, type);
28346 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28347 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28348 +++ linux/fs/aufs/procfs.c 2021-02-22 22:51:59.061411920 +0100
28350 +// SPDX-License-Identifier: GPL-2.0
28352 + * Copyright (C) 2010-2020 Junjiro R. Okajima
28354 + * This program, aufs is free software; you can redistribute it and/or modify
28355 + * it under the terms of the GNU General Public License as published by
28356 + * the Free Software Foundation; either version 2 of the License, or
28357 + * (at your option) any later version.
28359 + * This program is distributed in the hope that it will be useful,
28360 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28362 + * GNU General Public License for more details.
28364 + * You should have received a copy of the GNU General Public License
28365 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28369 + * procfs interfaces
28372 +#include <linux/proc_fs.h>
28375 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28377 + struct au_sbinfo *sbinfo;
28379 + sbinfo = file->private_data;
28381 + au_plink_maint_leave(sbinfo);
28382 + kobject_put(&sbinfo->si_kobj);
28388 +static void au_procfs_plm_write_clean(struct file *file)
28390 + struct au_sbinfo *sbinfo;
28392 + sbinfo = file->private_data;
28394 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28397 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28400 + struct super_block *sb;
28401 + struct au_sbinfo *sbinfo;
28402 + struct hlist_bl_node *pos;
28405 + if (unlikely(file->private_data))
28409 + /* don't use au_sbilist_lock() here */
28410 + hlist_bl_lock(&au_sbilist);
28411 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28412 + if (id == sysaufs_si_id(sbinfo)) {
28413 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28414 + sb = sbinfo->si_sb;
28417 + hlist_bl_unlock(&au_sbilist);
28420 + if (unlikely(!sb))
28423 + err = au_plink_maint_enter(sb);
28425 + /* keep kobject_get() */
28426 + file->private_data = sbinfo;
28428 + kobject_put(&sbinfo->si_kobj);
28434 + * Accept a valid "si=xxxx" only.
28435 + * Once it is accepted successfully, accept "clean" too.
28437 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28438 + size_t count, loff_t *ppos)
28441 + unsigned long id;
28442 + /* last newline is allowed */
28443 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28446 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28450 + if (unlikely(count > sizeof(buf)))
28453 + err = copy_from_user(buf, ubuf, count);
28454 + if (unlikely(err)) {
28461 + if (!strcmp("clean", buf)) {
28462 + au_procfs_plm_write_clean(file);
28463 + goto out_success;
28464 + } else if (unlikely(strncmp("si=", buf, 3)))
28467 + err = kstrtoul(buf + 3, 16, &id);
28468 + if (unlikely(err))
28471 + err = au_procfs_plm_write_si(file, id);
28472 + if (unlikely(err))
28476 + err = count; /* success */
28481 +static const struct proc_ops au_procfs_plm_op = {
28482 + .proc_write = au_procfs_plm_write,
28483 + .proc_release = au_procfs_plm_release
28486 +/* ---------------------------------------------------------------------- */
28488 +static struct proc_dir_entry *au_procfs_dir;
28490 +void au_procfs_fin(void)
28492 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28493 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28496 +int __init au_procfs_init(void)
28499 + struct proc_dir_entry *entry;
28502 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28503 + if (unlikely(!au_procfs_dir))
28506 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28507 + au_procfs_dir, &au_procfs_plm_op);
28508 + if (unlikely(!entry))
28512 + goto out; /* success */
28516 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28520 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28521 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28522 +++ linux/fs/aufs/rdu.c 2021-02-22 22:51:59.061411920 +0100
28524 +// SPDX-License-Identifier: GPL-2.0
28526 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28528 + * This program, aufs is free software; you can redistribute it and/or modify
28529 + * it under the terms of the GNU General Public License as published by
28530 + * the Free Software Foundation; either version 2 of the License, or
28531 + * (at your option) any later version.
28533 + * This program is distributed in the hope that it will be useful,
28534 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28535 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28536 + * GNU General Public License for more details.
28538 + * You should have received a copy of the GNU General Public License
28539 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28543 + * readdir in userspace.
28546 +#include <linux/compat.h>
28547 +#include <linux/fs_stack.h>
28548 +#include <linux/security.h>
28551 +/* bits for struct aufs_rdu.flags */
28552 +#define AuRdu_CALLED 1
28553 +#define AuRdu_CONT (1 << 1)
28554 +#define AuRdu_FULL (1 << 2)
28555 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28556 +#define au_fset_rdu(flags, name) \
28557 + do { (flags) |= AuRdu_##name; } while (0)
28558 +#define au_fclr_rdu(flags, name) \
28559 + do { (flags) &= ~AuRdu_##name; } while (0)
28561 +struct au_rdu_arg {
28562 + struct dir_context ctx;
28563 + struct aufs_rdu *rdu;
28564 + union au_rdu_ent_ul ent;
28565 + unsigned long end;
28567 + struct super_block *sb;
28571 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28572 + loff_t offset, u64 h_ino, unsigned int d_type)
28575 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28576 + struct aufs_rdu *rdu = arg->rdu;
28577 + struct au_rdu_ent ent;
28581 + au_fset_rdu(rdu->cookie.flags, CALLED);
28582 + len = au_rdu_len(nlen);
28583 + if (arg->ent.ul + len < arg->end) {
28585 + ent.bindex = rdu->cookie.bindex;
28586 + ent.type = d_type;
28588 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28589 + ent.type = DT_UNKNOWN;
28591 + /* unnecessary to support mmap_sem since this is a dir */
28593 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28595 + if (copy_to_user(arg->ent.e->name, name, nlen))
28597 + /* the terminating NULL */
28598 + if (__put_user(0, arg->ent.e->name + nlen))
28601 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28602 + arg->ent.ul += len;
28606 + au_fset_rdu(rdu->cookie.flags, FULL);
28608 + rdu->tail = arg->ent;
28612 + /* AuTraceErr(err); */
28616 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28620 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28622 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28623 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28625 + if (unlikely(offset != cookie->h_pos))
28631 + au_fclr_rdu(cookie->flags, CALLED);
28633 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28637 + && au_ftest_rdu(cookie->flags, CALLED)
28638 + && !au_ftest_rdu(cookie->flags, FULL));
28639 + cookie->h_pos = h_file->f_pos;
28646 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28649 + aufs_bindex_t bbot;
28650 + struct au_rdu_arg arg = {
28652 + .actor = au_rdu_fill
28655 + struct dentry *dentry;
28656 + struct inode *inode;
28657 + struct file *h_file;
28658 + struct au_rdu_cookie *cookie = &rdu->cookie;
28660 + /* VERIFY_WRITE */
28661 + err = !access_ok(rdu->ent.e, rdu->sz);
28662 + if (unlikely(err)) {
28668 + rdu->tail = rdu->ent;
28671 + arg.ent = rdu->ent;
28672 + arg.end = arg.ent.ul;
28673 + arg.end += rdu->sz;
28676 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28679 + err = security_file_permission(file, MAY_READ);
28681 + if (unlikely(err))
28684 + dentry = file->f_path.dentry;
28685 + inode = d_inode(dentry);
28686 + inode_lock_shared(inode);
28688 + arg.sb = inode->i_sb;
28689 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28690 + if (unlikely(err))
28692 + err = au_alive_dir(dentry);
28693 + if (unlikely(err))
28695 + /* todo: reval? */
28696 + fi_read_lock(file);
28699 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28700 + && cookie->generation != au_figen(file)))
28705 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28707 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28709 + bbot = au_fbtop(file);
28710 + if (cookie->bindex < bbot)
28711 + cookie->bindex = bbot;
28712 + bbot = au_fbbot_dir(file);
28713 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28714 + for (; !err && cookie->bindex <= bbot;
28715 + cookie->bindex++, cookie->h_pos = 0) {
28716 + h_file = au_hf_dir(file, cookie->bindex);
28720 + au_fclr_rdu(cookie->flags, FULL);
28721 + err = au_rdu_do(h_file, &arg);
28723 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28726 + AuDbg("rent %llu\n", rdu->rent);
28728 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28729 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28730 + au_fset_rdu(cookie->flags, CONT);
28731 + cookie->generation = au_figen(file);
28734 + ii_read_lock_child(inode);
28735 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28736 + ii_read_unlock(inode);
28739 + fi_read_unlock(file);
28741 + si_read_unlock(arg.sb);
28743 + inode_unlock_shared(inode);
28749 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28753 + unsigned long long nent;
28754 + union au_rdu_ent_ul *u;
28755 + struct au_rdu_ent ent;
28756 + struct super_block *sb;
28759 + nent = rdu->nent;
28761 + sb = file->f_path.dentry->d_sb;
28762 + si_read_lock(sb, AuLock_FLUSH);
28763 + while (nent-- > 0) {
28764 + /* unnecessary to support mmap_sem since this is a dir */
28765 + err = copy_from_user(&ent, u->e, sizeof(ent));
28767 + /* VERIFY_WRITE */
28768 + err = !access_ok(&u->e->ino, sizeof(ino));
28769 + if (unlikely(err)) {
28775 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28777 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28779 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28781 + if (unlikely(err)) {
28786 + err = __put_user(ino, &u->e->ino);
28787 + if (unlikely(err)) {
28792 + u->ul += au_rdu_len(ent.nlen);
28794 + si_read_unlock(sb);
28799 +/* ---------------------------------------------------------------------- */
28801 +static int au_rdu_verify(struct aufs_rdu *rdu)
28803 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28804 + "%llu, b%d, 0x%x, g%u}\n",
28805 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28807 + rdu->rent, rdu->shwh, rdu->full,
28808 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28809 + rdu->cookie.generation);
28811 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28815 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28819 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28822 + struct aufs_rdu rdu;
28823 + void __user *p = (void __user *)arg;
28825 + err = copy_from_user(&rdu, p, sizeof(rdu));
28826 + if (unlikely(err)) {
28831 + err = au_rdu_verify(&rdu);
28832 + if (unlikely(err))
28836 + case AUFS_CTL_RDU:
28837 + err = au_rdu(file, &rdu);
28838 + if (unlikely(err))
28841 + e = copy_to_user(p, &rdu, sizeof(rdu));
28842 + if (unlikely(e)) {
28847 + case AUFS_CTL_RDU_INO:
28848 + err = au_rdu_ino(file, &rdu);
28852 + /* err = -ENOTTY; */
28861 +#ifdef CONFIG_COMPAT
28862 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28865 + struct aufs_rdu rdu;
28866 + void __user *p = compat_ptr(arg);
28868 + /* todo: get_user()? */
28869 + err = copy_from_user(&rdu, p, sizeof(rdu));
28870 + if (unlikely(err)) {
28875 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28876 + err = au_rdu_verify(&rdu);
28877 + if (unlikely(err))
28881 + case AUFS_CTL_RDU:
28882 + err = au_rdu(file, &rdu);
28883 + if (unlikely(err))
28886 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28887 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28888 + e = copy_to_user(p, &rdu, sizeof(rdu));
28889 + if (unlikely(e)) {
28894 + case AUFS_CTL_RDU_INO:
28895 + err = au_rdu_ino(file, &rdu);
28899 + /* err = -ENOTTY; */
28908 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28909 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28910 +++ linux/fs/aufs/rwsem.h 2021-02-22 22:51:59.061411920 +0100
28912 +/* SPDX-License-Identifier: GPL-2.0 */
28914 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28916 + * This program, aufs is free software; you can redistribute it and/or modify
28917 + * it under the terms of the GNU General Public License as published by
28918 + * the Free Software Foundation; either version 2 of the License, or
28919 + * (at your option) any later version.
28921 + * This program is distributed in the hope that it will be useful,
28922 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28923 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28924 + * GNU General Public License for more details.
28926 + * You should have received a copy of the GNU General Public License
28927 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28931 + * simple read-write semaphore wrappers
28934 +#ifndef __AUFS_RWSEM_H__
28935 +#define __AUFS_RWSEM_H__
28939 +#include "debug.h"
28941 +/* in the future, the name 'au_rwsem' will be totally gone */
28942 +#define au_rwsem rw_semaphore
28944 +/* to debug easier, do not make them inlined functions */
28945 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28946 +/* rwsem_is_locked() is unusable */
28947 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28948 + && !lockdep_recursing(current) \
28950 + && !lockdep_is_held_type(rw, 1))
28951 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28952 + && !lockdep_recursing(current) \
28954 + && !lockdep_is_held_type(rw, 0))
28955 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28956 + && !lockdep_recursing(current) \
28958 + && !lockdep_is_held(rw))
28959 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28960 + && !lockdep_recursing(current) \
28962 + && lockdep_is_held(rw))
28964 +#define au_rw_init(rw) init_rwsem(rw)
28966 +#define au_rw_init_wlock(rw) do { \
28967 + au_rw_init(rw); \
28968 + down_write(rw); \
28971 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28972 + au_rw_init(rw); \
28973 + down_write_nested(rw, lsc); \
28976 +#define au_rw_read_lock(rw) down_read(rw)
28977 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28978 +#define au_rw_read_unlock(rw) up_read(rw)
28979 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28980 +#define au_rw_write_lock(rw) down_write(rw)
28981 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28982 +#define au_rw_write_unlock(rw) up_write(rw)
28983 +/* why is not _nested version defined? */
28984 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28985 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28987 +#endif /* __KERNEL__ */
28988 +#endif /* __AUFS_RWSEM_H__ */
28989 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28990 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28991 +++ linux/fs/aufs/sbinfo.c 2021-02-22 22:51:59.061411920 +0100
28993 +// SPDX-License-Identifier: GPL-2.0
28995 + * Copyright (C) 2005-2020 Junjiro R. Okajima
28997 + * This program, aufs is free software; you can redistribute it and/or modify
28998 + * it under the terms of the GNU General Public License as published by
28999 + * the Free Software Foundation; either version 2 of the License, or
29000 + * (at your option) any later version.
29002 + * This program is distributed in the hope that it will be useful,
29003 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29004 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29005 + * GNU General Public License for more details.
29007 + * You should have received a copy of the GNU General Public License
29008 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29012 + * superblock private data
29015 +#include <linux/iversion.h>
29019 + * they are necessary regardless sysfs is disabled.
29021 +void au_si_free(struct kobject *kobj)
29024 + struct au_sbinfo *sbinfo;
29025 + char *locked __maybe_unused; /* debug only */
29027 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29028 + for (i = 0; i < AuPlink_NHASH; i++)
29029 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29030 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29032 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29033 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29034 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29035 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29037 + dbgaufs_si_fin(sbinfo);
29038 + au_rw_write_lock(&sbinfo->si_rwsem);
29039 + au_br_free(sbinfo);
29040 + au_rw_write_unlock(&sbinfo->si_rwsem);
29042 + au_kfree_try_rcu(sbinfo->si_branch);
29043 + mutex_destroy(&sbinfo->si_xib_mtx);
29044 + AuRwDestroy(&sbinfo->si_rwsem);
29046 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29047 + /* si_nfiles is waited too */
29048 + au_kfree_rcu(sbinfo);
29051 +int au_si_alloc(struct super_block *sb)
29054 + struct au_sbinfo *sbinfo;
29057 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29058 + if (unlikely(!sbinfo))
29061 + /* will be reallocated separately */
29062 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29063 + if (unlikely(!sbinfo->si_branch))
29066 + err = sysaufs_si_init(sbinfo);
29068 + dbgaufs_si_null(sbinfo);
29069 + err = dbgaufs_si_init(sbinfo);
29070 + if (unlikely(err))
29071 + kobject_put(&sbinfo->si_kobj);
29073 + if (unlikely(err))
29076 + au_nwt_init(&sbinfo->si_nowait);
29077 + au_rw_init_wlock(&sbinfo->si_rwsem);
29079 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29080 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29082 + sbinfo->si_bbot = -1;
29083 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29085 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29086 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29087 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29088 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29090 + au_fhsm_init(sbinfo);
29092 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29094 + sbinfo->si_xino_jiffy = jiffies;
29095 + sbinfo->si_xino_expire
29096 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29097 + mutex_init(&sbinfo->si_xib_mtx);
29098 + /* leave si_xib_last_pindex and si_xib_next_bit */
29100 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29102 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29103 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29104 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29105 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29107 + for (i = 0; i < AuPlink_NHASH; i++)
29108 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29109 + init_waitqueue_head(&sbinfo->si_plink_wq);
29110 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29112 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29114 + /* with getattr by default */
29115 + sbinfo->si_iop_array = aufs_iop;
29117 + /* leave other members for sysaufs and si_mnt. */
29118 + sbinfo->si_sb = sb;
29119 + sb->s_fs_info = sbinfo;
29121 + return 0; /* success */
29124 + au_kfree_try_rcu(sbinfo->si_branch);
29126 + au_kfree_rcu(sbinfo);
29131 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29134 + struct au_branch **brp;
29136 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29139 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29140 + if (unlikely(!sz))
29141 + sz = sizeof(*brp);
29142 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29145 + sbinfo->si_branch = brp;
29152 +/* ---------------------------------------------------------------------- */
29154 +unsigned int au_sigen_inc(struct super_block *sb)
29156 + unsigned int gen;
29157 + struct inode *inode;
29159 + SiMustWriteLock(sb);
29161 + gen = ++au_sbi(sb)->si_generation;
29162 + au_update_digen(sb->s_root);
29163 + inode = d_inode(sb->s_root);
29164 + au_update_iigen(inode, /*half*/0);
29165 + inode_inc_iversion(inode);
29169 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29171 + aufs_bindex_t br_id;
29173 + struct au_sbinfo *sbinfo;
29175 + SiMustWriteLock(sb);
29177 + sbinfo = au_sbi(sb);
29178 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29179 + br_id = ++sbinfo->si_last_br_id;
29180 + AuDebugOn(br_id < 0);
29181 + if (br_id && au_br_index(sb, br_id) < 0)
29188 +/* ---------------------------------------------------------------------- */
29190 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29191 +int si_read_lock(struct super_block *sb, int flags)
29196 + if (au_ftest_lock(flags, FLUSH))
29197 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29199 + si_noflush_read_lock(sb);
29200 + err = au_plink_maint(sb, flags);
29201 + if (unlikely(err))
29202 + si_read_unlock(sb);
29207 +int si_write_lock(struct super_block *sb, int flags)
29211 + if (au_ftest_lock(flags, FLUSH))
29212 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29214 + si_noflush_write_lock(sb);
29215 + err = au_plink_maint(sb, flags);
29216 + if (unlikely(err))
29217 + si_write_unlock(sb);
29222 +/* dentry and super_block lock. call at entry point */
29223 +int aufs_read_lock(struct dentry *dentry, int flags)
29226 + struct super_block *sb;
29228 + sb = dentry->d_sb;
29229 + err = si_read_lock(sb, flags);
29230 + if (unlikely(err))
29233 + if (au_ftest_lock(flags, DW))
29234 + di_write_lock_child(dentry);
29236 + di_read_lock_child(dentry, flags);
29238 + if (au_ftest_lock(flags, GEN)) {
29239 + err = au_digen_test(dentry, au_sigen(sb));
29240 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29241 + AuDebugOn(!err && au_dbrange_test(dentry));
29243 + err = au_dbrange_test(dentry);
29244 + if (unlikely(err))
29245 + aufs_read_unlock(dentry, flags);
29252 +void aufs_read_unlock(struct dentry *dentry, int flags)
29254 + if (au_ftest_lock(flags, DW))
29255 + di_write_unlock(dentry);
29257 + di_read_unlock(dentry, flags);
29258 + si_read_unlock(dentry->d_sb);
29261 +void aufs_write_lock(struct dentry *dentry)
29263 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29264 + di_write_lock_child(dentry);
29267 +void aufs_write_unlock(struct dentry *dentry)
29269 + di_write_unlock(dentry);
29270 + si_write_unlock(dentry->d_sb);
29273 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29276 + unsigned int sigen;
29277 + struct super_block *sb;
29280 + err = si_read_lock(sb, flags);
29281 + if (unlikely(err))
29284 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29286 + if (au_ftest_lock(flags, GEN)) {
29287 + sigen = au_sigen(sb);
29288 + err = au_digen_test(d1, sigen);
29289 + AuDebugOn(!err && au_dbrange_test(d1));
29291 + err = au_digen_test(d2, sigen);
29292 + AuDebugOn(!err && au_dbrange_test(d2));
29294 + if (unlikely(err))
29295 + aufs_read_and_write_unlock2(d1, d2);
29302 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29304 + di_write_unlock2(d1, d2);
29305 + si_read_unlock(d1->d_sb);
29307 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29308 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29309 +++ linux/fs/aufs/super.c 2021-02-22 22:51:59.061411920 +0100
29311 +// SPDX-License-Identifier: GPL-2.0
29313 + * Copyright (C) 2005-2020 Junjiro R. Okajima
29315 + * This program, aufs is free software; you can redistribute it and/or modify
29316 + * it under the terms of the GNU General Public License as published by
29317 + * the Free Software Foundation; either version 2 of the License, or
29318 + * (at your option) any later version.
29320 + * This program is distributed in the hope that it will be useful,
29321 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29322 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29323 + * GNU General Public License for more details.
29325 + * You should have received a copy of the GNU General Public License
29326 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29330 + * mount and super_block operations
29333 +#include <linux/iversion.h>
29334 +#include <linux/mm.h>
29335 +#include <linux/seq_file.h>
29336 +#include <linux/statfs.h>
29337 +#include <linux/vmalloc.h>
29341 + * super_operations
29343 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29345 + struct au_icntnr *c;
29347 + c = au_cache_alloc_icntnr();
29349 + au_icntnr_init(c);
29350 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29351 + c->iinfo.ii_hinode = NULL;
29352 + return &c->vfs_inode;
29357 +static void aufs_destroy_inode(struct inode *inode)
29359 + if (!au_is_bad_inode(inode))
29360 + au_iinfo_fin(inode);
29363 +static void aufs_free_inode(struct inode *inode)
29365 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29368 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29370 + struct inode *inode;
29373 + inode = iget_locked(sb, ino);
29374 + if (unlikely(!inode)) {
29375 + inode = ERR_PTR(-ENOMEM);
29378 + if (!(inode->i_state & I_NEW))
29381 + err = au_xigen_new(inode);
29383 + err = au_iinfo_init(inode);
29385 + inode_inc_iversion(inode);
29387 + iget_failed(inode);
29388 + inode = ERR_PTR(err);
29392 + /* never return NULL */
29393 + AuDebugOn(!inode);
29394 + AuTraceErrPtr(inode);
29398 +/* lock free root dinfo */
29399 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29402 + aufs_bindex_t bindex, bbot;
29403 + struct path path;
29404 + struct au_hdentry *hdp;
29405 + struct au_branch *br;
29406 + au_br_perm_str_t perm;
29409 + bbot = au_sbbot(sb);
29411 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29412 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29413 + br = au_sbr(sb, bindex);
29414 + path.mnt = au_br_mnt(br);
29415 + path.dentry = hdp->hd_dentry;
29416 + err = au_seq_path(seq, &path);
29418 + au_optstr_br_perm(&perm, br->br_perm);
29419 + seq_printf(seq, "=%s", perm.a);
29420 + if (bindex != bbot)
29421 + seq_putc(seq, ':');
29424 + if (unlikely(err || seq_has_overflowed(seq)))
29430 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29431 + const char *append)
29436 + while (*pat != ':')
29439 + strcpy(p, append);
29440 + AuDebugOn(strlen(fmt) >= len);
29443 +static void au_show_wbr_create(struct seq_file *m, int v,
29444 + struct au_sbinfo *sbinfo)
29448 + struct au_wbr_mfs *mfs;
29450 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29452 + seq_puts(m, ",create=");
29453 + pat = au_optstr_wbr_create(v);
29454 + mfs = &sbinfo->si_wbr_mfs;
29456 + case AuWbrCreate_TDP:
29457 + case AuWbrCreate_RR:
29458 + case AuWbrCreate_MFS:
29459 + case AuWbrCreate_PMFS:
29460 + seq_puts(m, pat);
29462 + case AuWbrCreate_MFSRR:
29463 + case AuWbrCreate_TDMFS:
29464 + case AuWbrCreate_PMFSRR:
29465 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29466 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29468 + case AuWbrCreate_MFSV:
29469 + case AuWbrCreate_PMFSV:
29470 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29471 + seq_printf(m, fmt,
29472 + jiffies_to_msecs(mfs->mfs_expire)
29475 + case AuWbrCreate_MFSRRV:
29476 + case AuWbrCreate_TDMFSV:
29477 + case AuWbrCreate_PMFSRRV:
29478 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29479 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29480 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29487 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29489 +#ifdef CONFIG_SYSFS
29493 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29494 + aufs_bindex_t bindex, brid;
29495 + struct qstr *name;
29497 + struct dentry *d, *h_root;
29498 + struct au_branch *br;
29500 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29503 + f = au_sbi(sb)->si_xib;
29507 + /* stop printing the default xino path on the first writable branch */
29509 + bindex = au_xi_root(sb, f->f_path.dentry);
29510 + if (bindex >= 0) {
29511 + br = au_sbr_sb(sb, bindex);
29512 + h_root = au_br_dentry(br);
29515 + d = f->f_path.dentry;
29516 + name = &d->d_name;
29517 + /* safe ->d_parent because the file is unlinked */
29518 + if (d->d_parent == h_root
29519 + && name->len == len
29520 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29523 + seq_puts(seq, ",xino=");
29524 + err = au_xino_path(seq, f);
29531 +/* seq_file will re-call me in case of too long string */
29532 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29535 + unsigned int mnt_flags, v;
29536 + struct super_block *sb;
29537 + struct au_sbinfo *sbinfo;
29539 +#define AuBool(name, str) do { \
29540 + v = au_opt_test(mnt_flags, name); \
29541 + if (v != au_opt_test(AuOpt_Def, name)) \
29542 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29545 +#define AuStr(name, str) do { \
29546 + v = mnt_flags & AuOptMask_##name; \
29547 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29548 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29551 +#define AuUInt(name, str, val) do { \
29552 + if (val != AUFS_##name##_DEF) \
29553 + seq_printf(m, "," #str "=%u", val); \
29556 + sb = dentry->d_sb;
29557 + if (sb->s_flags & SB_POSIXACL)
29558 + seq_puts(m, ",acl");
29559 +#if 0 /* reserved for future use */
29560 + if (sb->s_flags & SB_I_VERSION)
29561 + seq_puts(m, ",i_version");
29564 + /* lock free root dinfo */
29565 + si_noflush_read_lock(sb);
29566 + sbinfo = au_sbi(sb);
29567 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29569 + mnt_flags = au_mntflags(sb);
29570 + if (au_opt_test(mnt_flags, XINO)) {
29571 + err = au_show_xino(m, sb);
29572 + if (unlikely(err))
29575 + seq_puts(m, ",noxino");
29577 + AuBool(TRUNC_XINO, trunc_xino);
29578 + AuStr(UDBA, udba);
29579 + AuBool(SHWH, shwh);
29580 + AuBool(PLINK, plink);
29581 + AuBool(DIO, dio);
29582 + AuBool(DIRPERM1, dirperm1);
29584 + v = sbinfo->si_wbr_create;
29585 + if (v != AuWbrCreate_Def)
29586 + au_show_wbr_create(m, v, sbinfo);
29588 + v = sbinfo->si_wbr_copyup;
29589 + if (v != AuWbrCopyup_Def)
29590 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29592 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29593 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29594 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29596 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29598 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29599 + AuUInt(RDCACHE, rdcache, v);
29601 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29602 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29604 + au_fhsm_show(m, sbinfo);
29606 + AuBool(DIRREN, dirren);
29607 + AuBool(SUM, sum);
29608 + /* AuBool(SUM_W, wsum); */
29609 + AuBool(WARN_PERM, warn_perm);
29610 + AuBool(VERBOSE, verbose);
29613 + /* be sure to print "br:" last */
29614 + if (!sysaufs_brs) {
29615 + seq_puts(m, ",br:");
29616 + au_show_brs(m, sb);
29618 + si_read_unlock(sb);
29626 +/* ---------------------------------------------------------------------- */
29628 +/* sum mode which returns the summation for statfs(2) */
29630 +static u64 au_add_till_max(u64 a, u64 b)
29638 + return ULLONG_MAX;
29641 +static u64 au_mul_till_max(u64 a, long mul)
29649 + return ULLONG_MAX;
29652 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29655 + long bsize, factor;
29656 + u64 blocks, bfree, bavail, files, ffree;
29657 + aufs_bindex_t bbot, bindex, i;
29658 + unsigned char shared;
29659 + struct path h_path;
29660 + struct super_block *h_sb;
29663 + bsize = LONG_MAX;
29669 + bbot = au_sbbot(sb);
29670 + for (bindex = 0; bindex <= bbot; bindex++) {
29671 + h_path.mnt = au_sbr_mnt(sb, bindex);
29672 + h_sb = h_path.mnt->mnt_sb;
29674 + for (i = 0; !shared && i < bindex; i++)
29675 + shared = (au_sbr_sb(sb, i) == h_sb);
29679 + /* sb->s_root for NFS is unreliable */
29680 + h_path.dentry = h_path.mnt->mnt_root;
29681 + err = vfs_statfs(&h_path, buf);
29682 + if (unlikely(err))
29685 + if (bsize > buf->f_bsize) {
29687 + * we will reduce bsize, so we have to expand blocks
29688 + * etc. to match them again
29690 + factor = (bsize / buf->f_bsize);
29691 + blocks = au_mul_till_max(blocks, factor);
29692 + bfree = au_mul_till_max(bfree, factor);
29693 + bavail = au_mul_till_max(bavail, factor);
29694 + bsize = buf->f_bsize;
29697 + factor = (buf->f_bsize / bsize);
29698 + blocks = au_add_till_max(blocks,
29699 + au_mul_till_max(buf->f_blocks, factor));
29700 + bfree = au_add_till_max(bfree,
29701 + au_mul_till_max(buf->f_bfree, factor));
29702 + bavail = au_add_till_max(bavail,
29703 + au_mul_till_max(buf->f_bavail, factor));
29704 + files = au_add_till_max(files, buf->f_files);
29705 + ffree = au_add_till_max(ffree, buf->f_ffree);
29708 + buf->f_bsize = bsize;
29709 + buf->f_blocks = blocks;
29710 + buf->f_bfree = bfree;
29711 + buf->f_bavail = bavail;
29712 + buf->f_files = files;
29713 + buf->f_ffree = ffree;
29714 + buf->f_frsize = 0;
29720 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29723 + struct path h_path;
29724 + struct super_block *sb;
29726 + /* lock free root dinfo */
29727 + sb = dentry->d_sb;
29728 + si_noflush_read_lock(sb);
29729 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29730 + /* sb->s_root for NFS is unreliable */
29731 + h_path.mnt = au_sbr_mnt(sb, 0);
29732 + h_path.dentry = h_path.mnt->mnt_root;
29733 + err = vfs_statfs(&h_path, buf);
29735 + err = au_statfs_sum(sb, buf);
29736 + si_read_unlock(sb);
29739 + buf->f_type = AUFS_SUPER_MAGIC;
29740 + buf->f_namelen = AUFS_MAX_NAMELEN;
29741 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29743 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29748 +/* ---------------------------------------------------------------------- */
29750 +static int aufs_sync_fs(struct super_block *sb, int wait)
29753 + aufs_bindex_t bbot, bindex;
29754 + struct au_branch *br;
29755 + struct super_block *h_sb;
29758 + si_noflush_read_lock(sb);
29759 + bbot = au_sbbot(sb);
29760 + for (bindex = 0; bindex <= bbot; bindex++) {
29761 + br = au_sbr(sb, bindex);
29762 + if (!au_br_writable(br->br_perm))
29765 + h_sb = au_sbr_sb(sb, bindex);
29766 + e = vfsub_sync_filesystem(h_sb, wait);
29767 + if (unlikely(e && !err))
29769 + /* go on even if an error happens */
29771 + si_read_unlock(sb);
29776 +/* ---------------------------------------------------------------------- */
29778 +/* final actions when unmounting a file system */
29779 +static void aufs_put_super(struct super_block *sb)
29781 + struct au_sbinfo *sbinfo;
29783 + sbinfo = au_sbi(sb);
29785 + kobject_put(&sbinfo->si_kobj);
29788 +/* ---------------------------------------------------------------------- */
29790 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29791 + struct super_block *sb, void *arg)
29794 + unsigned long long n, sz;
29801 + if (*hint > ULLONG_MAX / sizeof(array)) {
29802 + array = ERR_PTR(-EMFILE);
29803 + pr_err("hint %llu\n", *hint);
29807 + sz = sizeof(array) * *hint;
29808 + array = kzalloc(sz, GFP_NOFS);
29809 + if (unlikely(!array))
29810 + array = vzalloc(sz);
29811 + if (unlikely(!array)) {
29812 + array = ERR_PTR(-ENOMEM);
29816 + n = cb(sb, array, *hint, arg);
29817 + AuDebugOn(n > *hint);
29824 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29825 + unsigned long long max __maybe_unused,
29828 + unsigned long long n;
29829 + struct inode **p, *inode;
29830 + struct list_head *head;
29835 + spin_lock(&sb->s_inode_list_lock);
29836 + list_for_each_entry(inode, head, i_sb_list) {
29837 + if (!au_is_bad_inode(inode)
29838 + && au_ii(inode)->ii_btop >= 0) {
29839 + spin_lock(&inode->i_lock);
29840 + if (atomic_read(&inode->i_count)) {
29844 + AuDebugOn(n > max);
29846 + spin_unlock(&inode->i_lock);
29849 + spin_unlock(&sb->s_inode_list_lock);
29854 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29856 + struct au_sbinfo *sbi;
29858 + sbi = au_sbi(sb);
29859 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29860 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29863 +void au_iarray_free(struct inode **a, unsigned long long max)
29865 + unsigned long long ull;
29867 + for (ull = 0; ull < max; ull++)
29872 +/* ---------------------------------------------------------------------- */
29875 + * refresh dentry and inode at remount time.
29877 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29878 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29879 + struct dentry *parent)
29883 + di_write_lock_child(dentry);
29884 + di_read_lock_parent(parent, AuLock_IR);
29885 + err = au_refresh_dentry(dentry, parent);
29886 + if (!err && dir_flags)
29887 + au_hn_reset(d_inode(dentry), dir_flags);
29888 + di_read_unlock(parent, AuLock_IR);
29889 + di_write_unlock(dentry);
29894 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29895 + struct au_sbinfo *sbinfo,
29896 + const unsigned int dir_flags, unsigned int do_idop)
29899 + struct dentry *parent;
29902 + parent = dget_parent(dentry);
29903 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29904 + if (d_really_is_positive(dentry)) {
29905 + if (!d_is_dir(dentry))
29906 + err = au_do_refresh(dentry, /*dir_flags*/0,
29909 + err = au_do_refresh(dentry, dir_flags, parent);
29910 + if (unlikely(err))
29911 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29914 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29915 + AuDbgDentry(dentry);
29921 + au_refresh_dop(dentry, /*force_reval*/0);
29923 + au_refresh_dop(dentry, /*force_reval*/1);
29929 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29931 + int err, i, j, ndentry, e;
29932 + unsigned int sigen;
29933 + struct au_dcsub_pages dpages;
29934 + struct au_dpage *dpage;
29935 + struct dentry **dentries, *d;
29936 + struct au_sbinfo *sbinfo;
29937 + struct dentry *root = sb->s_root;
29938 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29941 + au_refresh_dop(root, /*force_reval*/0);
29943 + err = au_dpages_init(&dpages, GFP_NOFS);
29944 + if (unlikely(err))
29946 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29947 + if (unlikely(err))
29950 + sigen = au_sigen(sb);
29951 + sbinfo = au_sbi(sb);
29952 + for (i = 0; i < dpages.ndpage; i++) {
29953 + dpage = dpages.dpages + i;
29954 + dentries = dpage->dentries;
29955 + ndentry = dpage->ndentry;
29956 + for (j = 0; j < ndentry; j++) {
29958 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29960 + if (unlikely(e && !err))
29962 + /* go on even err */
29967 + au_dpages_free(&dpages);
29972 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29975 + unsigned int sigen;
29976 + unsigned long long max, ull;
29977 + struct inode *inode, **array;
29979 + array = au_iarray_alloc(sb, &max);
29980 + err = PTR_ERR(array);
29981 + if (IS_ERR(array))
29985 + sigen = au_sigen(sb);
29986 + for (ull = 0; ull < max; ull++) {
29987 + inode = array[ull];
29988 + if (unlikely(!inode))
29992 + ii_write_lock_child(inode);
29993 + if (au_iigen(inode, NULL) != sigen) {
29994 + e = au_refresh_hinode_self(inode);
29995 + if (unlikely(e)) {
29996 + au_refresh_iop(inode, /*force_getattr*/1);
29997 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30000 + /* go on even if err */
30003 + if (!e && do_idop)
30004 + au_refresh_iop(inode, /*force_getattr*/0);
30005 + ii_write_unlock(inode);
30008 + au_iarray_free(array, max);
30014 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30017 + unsigned int udba;
30018 + aufs_bindex_t bindex, bbot;
30019 + struct dentry *root;
30020 + struct inode *inode;
30021 + struct au_branch *br;
30022 + struct au_sbinfo *sbi;
30024 + au_sigen_inc(sb);
30025 + sbi = au_sbi(sb);
30026 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30028 + root = sb->s_root;
30029 + DiMustNoWaiters(root);
30030 + inode = d_inode(root);
30031 + IiMustNoWaiters(inode);
30033 + udba = au_opt_udba(sb);
30034 + bbot = au_sbbot(sb);
30035 + for (bindex = 0; bindex <= bbot; bindex++) {
30036 + br = au_sbr(sb, bindex);
30037 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30038 + if (unlikely(err))
30039 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30041 + /* go on even if err */
30043 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30046 + if (au_ftest_si(sbi, NO_DREVAL)) {
30047 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30048 + sb->s_d_op = &aufs_dop_noreval;
30049 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30050 + sbi->si_iop_array = aufs_iop_nogetattr;
30052 + AuDebugOn(sb->s_d_op == &aufs_dop);
30053 + sb->s_d_op = &aufs_dop;
30054 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30055 + sbi->si_iop_array = aufs_iop;
30057 + pr_info("reset to %ps and %ps\n",
30058 + sb->s_d_op, sbi->si_iop_array);
30061 + di_write_unlock(root);
30062 + err = au_refresh_d(sb, do_idop);
30063 + e = au_refresh_i(sb, do_idop);
30064 + if (unlikely(e && !err))
30066 + /* aufs_write_lock() calls ..._child() */
30067 + di_write_lock_child(root);
30069 + au_cpup_attr_all(inode, /*force*/1);
30071 + if (unlikely(err))
30072 + AuIOErr("refresh failed, ignored, %d\n", err);
30075 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30076 +static int cvt_err(int err)
30090 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30093 + unsigned int mntflags;
30094 + struct au_opts opts = {
30097 + struct dentry *root;
30098 + struct inode *inode;
30099 + struct au_sbinfo *sbinfo;
30102 + root = sb->s_root;
30103 + if (!data || !*data) {
30104 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30106 + di_write_lock_child(root);
30107 + err = au_opts_verify(sb, *flags, /*pending*/0);
30108 + aufs_write_unlock(root);
30114 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30115 + if (unlikely(!opts.opt))
30117 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30118 + opts.flags = AuOpts_REMOUNT;
30119 + opts.sb_flags = *flags;
30121 + /* parse it before aufs lock */
30122 + err = au_opts_parse(sb, data, &opts);
30123 + if (unlikely(err))
30126 + sbinfo = au_sbi(sb);
30127 + inode = d_inode(root);
30128 + inode_lock(inode);
30129 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30130 + if (unlikely(err))
30132 + di_write_lock_child(root);
30134 + /* au_opts_remount() may return an error */
30135 + err = au_opts_remount(sb, &opts);
30136 + au_opts_free(&opts);
30138 + if (au_ftest_opts(opts.flags, REFRESH))
30139 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30141 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30142 + mntflags = au_mntflags(sb);
30143 + do_dx = !!au_opt_test(mntflags, DIO);
30144 + au_dy_arefresh(do_dx);
30147 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30148 + aufs_write_unlock(root);
30151 + inode_unlock(inode);
30153 + free_page((unsigned long)opts.opt);
30155 + err = cvt_err(err);
30160 +static const struct super_operations aufs_sop = {
30161 + .alloc_inode = aufs_alloc_inode,
30162 + .destroy_inode = aufs_destroy_inode,
30163 + .free_inode = aufs_free_inode,
30164 + /* always deleting, no clearing */
30165 + .drop_inode = generic_delete_inode,
30166 + .show_options = aufs_show_options,
30167 + .statfs = aufs_statfs,
30168 + .put_super = aufs_put_super,
30169 + .sync_fs = aufs_sync_fs,
30170 + .remount_fs = aufs_remount_fs
30173 +/* ---------------------------------------------------------------------- */
30175 +static int alloc_root(struct super_block *sb)
30178 + struct inode *inode;
30179 + struct dentry *root;
30182 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30183 + err = PTR_ERR(inode);
30184 + if (IS_ERR(inode))
30187 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30188 + inode->i_fop = &aufs_dir_fop;
30189 + inode->i_mode = S_IFDIR;
30190 + set_nlink(inode, 2);
30191 + unlock_new_inode(inode);
30193 + root = d_make_root(inode);
30194 + if (unlikely(!root))
30196 + err = PTR_ERR(root);
30197 + if (IS_ERR(root))
30200 + err = au_di_init(root);
30202 + sb->s_root = root;
30203 + return 0; /* success */
30211 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30212 + int silent __maybe_unused)
30215 + struct au_opts opts = {
30218 + struct au_sbinfo *sbinfo;
30219 + struct dentry *root;
30220 + struct inode *inode;
30221 + char *arg = raw_data;
30223 + if (unlikely(!arg || !*arg)) {
30225 + pr_err("no arg\n");
30230 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30231 + if (unlikely(!opts.opt))
30233 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30234 + opts.sb_flags = sb->s_flags;
30236 + err = au_si_alloc(sb);
30237 + if (unlikely(err))
30239 + sbinfo = au_sbi(sb);
30241 + /* all timestamps always follow the ones on the branch */
30242 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30243 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30244 + sb->s_op = &aufs_sop;
30245 + sb->s_d_op = &aufs_dop;
30246 + sb->s_magic = AUFS_SUPER_MAGIC;
30247 + sb->s_maxbytes = 0;
30248 + sb->s_stack_depth = 1;
30249 + au_export_init(sb);
30250 + au_xattr_init(sb);
30252 + err = alloc_root(sb);
30253 + if (unlikely(err)) {
30254 + si_write_unlock(sb);
30257 + root = sb->s_root;
30258 + inode = d_inode(root);
30261 + * actually we can parse options regardless aufs lock here.
30262 + * but at remount time, parsing must be done before aufs lock.
30263 + * so we follow the same rule.
30265 + ii_write_lock_parent(inode);
30266 + aufs_write_unlock(root);
30267 + err = au_opts_parse(sb, arg, &opts);
30268 + if (unlikely(err))
30271 + /* lock vfs_inode first, then aufs. */
30272 + inode_lock(inode);
30273 + aufs_write_lock(root);
30274 + err = au_opts_mount(sb, &opts);
30275 + au_opts_free(&opts);
30276 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30277 + sb->s_d_op = &aufs_dop_noreval;
30278 + pr_info("%ps\n", sb->s_d_op);
30279 + au_refresh_dop(root, /*force_reval*/0);
30280 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30281 + au_refresh_iop(inode, /*force_getattr*/0);
30283 + aufs_write_unlock(root);
30284 + inode_unlock(inode);
30286 + goto out_opts; /* success */
30290 + sb->s_root = NULL;
30292 + kobject_put(&sbinfo->si_kobj);
30293 + sb->s_fs_info = NULL;
30295 + free_page((unsigned long)opts.opt);
30298 + err = cvt_err(err);
30303 +/* ---------------------------------------------------------------------- */
30305 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30306 + const char *dev_name __maybe_unused,
30309 + struct dentry *root;
30311 + /* all timestamps always follow the ones on the branch */
30312 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30313 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30314 + if (IS_ERR(root))
30317 + au_sbilist_add(root->d_sb);
30323 +static void aufs_kill_sb(struct super_block *sb)
30325 + struct au_sbinfo *sbinfo;
30327 + sbinfo = au_sbi(sb);
30329 + au_sbilist_del(sb);
30330 + aufs_write_lock(sb->s_root);
30332 + if (sbinfo->si_wbr_create_ops->fin)
30333 + sbinfo->si_wbr_create_ops->fin(sb);
30334 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30335 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30336 + au_remount_refresh(sb, /*do_idop*/0);
30338 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30339 + au_plink_put(sb, /*verbose*/1);
30341 + au_dr_opt_flush(sb);
30342 + sbinfo->si_sb = NULL;
30343 + aufs_write_unlock(sb->s_root);
30344 + au_nwt_flush(&sbinfo->si_nowait);
30346 + kill_anon_super(sb);
30349 +struct file_system_type aufs_fs_type = {
30350 + .name = AUFS_FSTYPE,
30351 + /* a race between rename and others */
30352 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30353 + .mount = aufs_mount,
30354 + .kill_sb = aufs_kill_sb,
30355 + /* no need to __module_get() and module_put(). */
30356 + .owner = THIS_MODULE,
30358 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30359 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30360 +++ linux/fs/aufs/super.h 2021-02-22 22:51:59.061411920 +0100
30362 +/* SPDX-License-Identifier: GPL-2.0 */
30364 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30366 + * This program, aufs is free software; you can redistribute it and/or modify
30367 + * it under the terms of the GNU General Public License as published by
30368 + * the Free Software Foundation; either version 2 of the License, or
30369 + * (at your option) any later version.
30371 + * This program is distributed in the hope that it will be useful,
30372 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30373 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30374 + * GNU General Public License for more details.
30376 + * You should have received a copy of the GNU General Public License
30377 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30381 + * super_block operations
30384 +#ifndef __AUFS_SUPER_H__
30385 +#define __AUFS_SUPER_H__
30389 +#include <linux/fs.h>
30390 +#include <linux/kobject.h>
30393 +#include "rwsem.h"
30396 +/* policies to select one among multiple writable branches */
30397 +struct au_wbr_copyup_operations {
30398 + int (*copyup)(struct dentry *dentry);
30401 +#define AuWbr_DIR 1 /* target is a dir */
30402 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30404 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30405 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30406 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30408 +struct au_wbr_create_operations {
30409 + int (*create)(struct dentry *dentry, unsigned int flags);
30410 + int (*init)(struct super_block *sb);
30411 + int (*fin)(struct super_block *sb);
30414 +struct au_wbr_mfs {
30415 + struct mutex mfs_lock; /* protect this structure */
30416 + unsigned long mfs_jiffy;
30417 + unsigned long mfs_expire;
30418 + aufs_bindex_t mfs_bindex;
30420 + unsigned long long mfsrr_bytes;
30421 + unsigned long long mfsrr_watermark;
30424 +#define AuPlink_NHASH 100
30425 +static inline int au_plink_hash(ino_t ino)
30427 + return ino % AuPlink_NHASH;
30430 +/* File-based Hierarchical Storage Management */
30432 +#ifdef CONFIG_AUFS_FHSM
30433 + /* allow only one process who can receive the notification */
30434 + spinlock_t fhsm_spin;
30436 + wait_queue_head_t fhsm_wqh;
30437 + atomic_t fhsm_readable;
30439 + /* these are protected by si_rwsem */
30440 + unsigned long fhsm_expire;
30441 + aufs_bindex_t fhsm_bottom;
30446 +struct au_sbinfo {
30447 + /* nowait tasks in the system-wide workqueue */
30448 + struct au_nowait_tasks si_nowait;
30451 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30452 + * rwsem for au_sbinfo is necessary.
30454 + struct au_rwsem si_rwsem;
30457 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30460 + au_lcnt_t si_ninodes, si_nfiles;
30462 + /* branch management */
30463 + unsigned int si_generation;
30465 + /* see AuSi_ flags */
30466 + unsigned char au_si_status;
30468 + aufs_bindex_t si_bbot;
30470 + /* dirty trick to keep br_id plus */
30471 + unsigned int si_last_br_id :
30472 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30473 + struct au_branch **si_branch;
30475 + /* policy to select a writable branch */
30476 + unsigned char si_wbr_copyup;
30477 + unsigned char si_wbr_create;
30478 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30479 + struct au_wbr_create_operations *si_wbr_create_ops;
30481 + /* round robin */
30482 + atomic_t si_wbr_rr_next;
30484 + /* most free space */
30485 + struct au_wbr_mfs si_wbr_mfs;
30487 + /* File-based Hierarchical Storage Management */
30488 + struct au_fhsm si_fhsm;
30490 + /* mount flags */
30491 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30492 + unsigned int si_mntflags;
30494 + /* external inode number (bitmap and translation table) */
30495 + loff_t si_ximaxent; /* max entries in a xino */
30497 + struct file *si_xib;
30498 + struct mutex si_xib_mtx; /* protect xib members */
30499 + unsigned long *si_xib_buf;
30500 + unsigned long si_xib_last_pindex;
30501 + int si_xib_next_bit;
30503 + unsigned long si_xino_jiffy;
30504 + unsigned long si_xino_expire;
30505 + /* reserved for future use */
30506 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30508 +#ifdef CONFIG_AUFS_EXPORT
30509 + /* i_generation */
30510 + /* todo: make xigen file an array to support many inode numbers */
30511 + struct file *si_xigen;
30512 + atomic_t si_xigen_next;
30515 + /* dirty trick to support atomic_open */
30516 + struct hlist_bl_head si_aopen;
30518 + /* vdir parameters */
30519 + unsigned long si_rdcache; /* max cache time in jiffies */
30520 + unsigned int si_rdblk; /* deblk size */
30521 + unsigned int si_rdhash; /* hash size */
30524 + * If the number of whiteouts are larger than si_dirwh, leave all of
30525 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30526 + * future fsck.aufs or kernel thread will remove them later.
30527 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30529 + unsigned int si_dirwh;
30531 + /* pseudo_link list */
30532 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30533 + wait_queue_head_t si_plink_wq;
30534 + spinlock_t si_plink_maint_lock;
30535 + pid_t si_plink_maint_pid;
30538 + struct hlist_bl_head si_files;
30540 + /* with/without getattr, brother of sb->s_d_op */
30541 + const struct inode_operations *si_iop_array;
30544 + * sysfs and lifetime management.
30545 + * this is not a small structure and it may be a waste of memory in case
30546 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30547 + * but using sysfs is majority.
30549 + struct kobject si_kobj;
30550 +#ifdef CONFIG_DEBUG_FS
30551 + struct dentry *si_dbgaufs;
30552 + struct dentry *si_dbgaufs_plink;
30553 + struct dentry *si_dbgaufs_xib;
30554 +#ifdef CONFIG_AUFS_EXPORT
30555 + struct dentry *si_dbgaufs_xigen;
30559 +#ifdef CONFIG_AUFS_SBILIST
30560 + struct hlist_bl_node si_list;
30563 + /* dirty, necessary for unmounting, sysfs and sysrq */
30564 + struct super_block *si_sb;
30567 +/* sbinfo status flags */
30569 + * set true when refresh_dirs() failed at remount time.
30570 + * then try refreshing dirs at access time again.
30571 + * if it is false, refreshing dirs at access time is unnecessary
30573 +#define AuSi_FAILED_REFRESH_DIR 1
30574 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30575 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30577 +#ifndef CONFIG_AUFS_FHSM
30579 +#define AuSi_FHSM 0
30582 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30583 + unsigned int flag)
30585 + AuRwMustAnyLock(&sbi->si_rwsem);
30586 + return sbi->au_si_status & flag;
30588 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30589 +#define au_fset_si(sbinfo, name) do { \
30590 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30591 + (sbinfo)->au_si_status |= AuSi_##name; \
30593 +#define au_fclr_si(sbinfo, name) do { \
30594 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30595 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30598 +/* ---------------------------------------------------------------------- */
30600 +/* policy to select one among writable branches */
30601 +#define AuWbrCopyup(sbinfo, ...) \
30602 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30603 +#define AuWbrCreate(sbinfo, ...) \
30604 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30606 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30607 +#define AuLock_DW 1 /* write-lock dentry */
30608 +#define AuLock_IR (1 << 1) /* read-lock inode */
30609 +#define AuLock_IW (1 << 2) /* write-lock inode */
30610 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30611 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30612 + /* except RENAME_EXCHANGE */
30613 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30614 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30615 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30616 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30617 +#define au_fset_lock(flags, name) \
30618 + do { (flags) |= AuLock_##name; } while (0)
30619 +#define au_fclr_lock(flags, name) \
30620 + do { (flags) &= ~AuLock_##name; } while (0)
30622 +/* ---------------------------------------------------------------------- */
30625 +extern struct file_system_type aufs_fs_type;
30626 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30627 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30628 + unsigned long long max, void *arg);
30629 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30630 + struct super_block *sb, void *arg);
30631 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30632 +void au_iarray_free(struct inode **a, unsigned long long max);
30635 +void au_si_free(struct kobject *kobj);
30636 +int au_si_alloc(struct super_block *sb);
30637 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30639 +unsigned int au_sigen_inc(struct super_block *sb);
30640 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30642 +int si_read_lock(struct super_block *sb, int flags);
30643 +int si_write_lock(struct super_block *sb, int flags);
30644 +int aufs_read_lock(struct dentry *dentry, int flags);
30645 +void aufs_read_unlock(struct dentry *dentry, int flags);
30646 +void aufs_write_lock(struct dentry *dentry);
30647 +void aufs_write_unlock(struct dentry *dentry);
30648 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30649 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30651 +/* wbr_policy.c */
30652 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30653 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30654 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30655 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30656 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30659 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30661 +#ifdef CONFIG_AUFS_FHSM
30664 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30668 + spin_lock(&fhsm->fhsm_spin);
30669 + pid = fhsm->fhsm_pid;
30670 + spin_unlock(&fhsm->fhsm_spin);
30675 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30676 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30677 +int au_fhsm_fd(struct super_block *sb, int oflags);
30678 +int au_fhsm_br_alloc(struct au_branch *br);
30679 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30680 +void au_fhsm_fin(struct super_block *sb);
30681 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30682 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30683 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30685 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30687 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30688 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30689 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30690 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30691 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30692 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30693 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30694 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30695 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30698 +/* ---------------------------------------------------------------------- */
30700 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30702 + return sb->s_fs_info;
30705 +/* ---------------------------------------------------------------------- */
30707 +#ifdef CONFIG_AUFS_EXPORT
30708 +int au_test_nfsd(void);
30709 +void au_export_init(struct super_block *sb);
30710 +void au_xigen_inc(struct inode *inode);
30711 +int au_xigen_new(struct inode *inode);
30712 +int au_xigen_set(struct super_block *sb, struct path *path);
30713 +void au_xigen_clr(struct super_block *sb);
30715 +static inline int au_busy_or_stale(void)
30717 + if (!au_test_nfsd())
30722 +AuStubInt0(au_test_nfsd, void)
30723 +AuStubVoid(au_export_init, struct super_block *sb)
30724 +AuStubVoid(au_xigen_inc, struct inode *inode)
30725 +AuStubInt0(au_xigen_new, struct inode *inode)
30726 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30727 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30728 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30729 +#endif /* CONFIG_AUFS_EXPORT */
30731 +/* ---------------------------------------------------------------------- */
30733 +#ifdef CONFIG_AUFS_SBILIST
30735 +extern struct hlist_bl_head au_sbilist;
30737 +static inline void au_sbilist_init(void)
30739 + INIT_HLIST_BL_HEAD(&au_sbilist);
30742 +static inline void au_sbilist_add(struct super_block *sb)
30744 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30747 +static inline void au_sbilist_del(struct super_block *sb)
30749 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30752 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30753 +static inline void au_sbilist_lock(void)
30755 + hlist_bl_lock(&au_sbilist);
30758 +static inline void au_sbilist_unlock(void)
30760 + hlist_bl_unlock(&au_sbilist);
30762 +#define AuGFP_SBILIST GFP_ATOMIC
30764 +AuStubVoid(au_sbilist_lock, void)
30765 +AuStubVoid(au_sbilist_unlock, void)
30766 +#define AuGFP_SBILIST GFP_NOFS
30767 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30769 +AuStubVoid(au_sbilist_init, void)
30770 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30771 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30772 +AuStubVoid(au_sbilist_lock, void)
30773 +AuStubVoid(au_sbilist_unlock, void)
30774 +#define AuGFP_SBILIST GFP_NOFS
30777 +/* ---------------------------------------------------------------------- */
30779 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30782 + * This function is a dynamic '__init' function actually,
30783 + * so the tiny check for si_rwsem is unnecessary.
30785 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30786 +#ifdef CONFIG_DEBUG_FS
30787 + sbinfo->si_dbgaufs = NULL;
30788 + sbinfo->si_dbgaufs_plink = NULL;
30789 + sbinfo->si_dbgaufs_xib = NULL;
30790 +#ifdef CONFIG_AUFS_EXPORT
30791 + sbinfo->si_dbgaufs_xigen = NULL;
30796 +/* ---------------------------------------------------------------------- */
30798 +/* current->atomic_flags */
30799 +/* this value should never corrupt the ones defined in linux/sched.h */
30800 +#define PFA_AUFS 0x10
30802 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30803 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30804 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30806 +static inline int si_pid_test(struct super_block *sb)
30808 + return !!task_test_aufs(current);
30811 +static inline void si_pid_clr(struct super_block *sb)
30813 + AuDebugOn(!task_test_aufs(current));
30814 + task_clear_aufs(current);
30817 +static inline void si_pid_set(struct super_block *sb)
30819 + AuDebugOn(task_test_aufs(current));
30820 + task_set_aufs(current);
30823 +/* ---------------------------------------------------------------------- */
30825 +/* lock superblock. mainly for entry point functions */
30826 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30827 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30828 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30829 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30831 +#define __si_read_trylock_nested(sb) \
30832 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30833 +#define __si_write_trylock_nested(sb) \
30834 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30837 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30838 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30839 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30841 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30842 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30843 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30845 +static inline void si_noflush_read_lock(struct super_block *sb)
30847 + __si_read_lock(sb);
30851 +static inline int si_noflush_read_trylock(struct super_block *sb)
30855 + locked = __si_read_trylock(sb);
30861 +static inline void si_noflush_write_lock(struct super_block *sb)
30863 + __si_write_lock(sb);
30867 +static inline int si_noflush_write_trylock(struct super_block *sb)
30871 + locked = __si_write_trylock(sb);
30877 +#if 0 /* reserved */
30878 +static inline int si_read_trylock(struct super_block *sb, int flags)
30880 + if (au_ftest_lock(flags, FLUSH))
30881 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30882 + return si_noflush_read_trylock(sb);
30886 +static inline void si_read_unlock(struct super_block *sb)
30889 + __si_read_unlock(sb);
30892 +#if 0 /* reserved */
30893 +static inline int si_write_trylock(struct super_block *sb, int flags)
30895 + if (au_ftest_lock(flags, FLUSH))
30896 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30897 + return si_noflush_write_trylock(sb);
30901 +static inline void si_write_unlock(struct super_block *sb)
30904 + __si_write_unlock(sb);
30907 +#if 0 /* reserved */
30908 +static inline void si_downgrade_lock(struct super_block *sb)
30910 + __si_downgrade_lock(sb);
30914 +/* ---------------------------------------------------------------------- */
30916 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30918 + SiMustAnyLock(sb);
30919 + return au_sbi(sb)->si_bbot;
30922 +static inline unsigned int au_mntflags(struct super_block *sb)
30924 + SiMustAnyLock(sb);
30925 + return au_sbi(sb)->si_mntflags;
30928 +static inline unsigned int au_sigen(struct super_block *sb)
30930 + SiMustAnyLock(sb);
30931 + return au_sbi(sb)->si_generation;
30934 +static inline struct au_branch *au_sbr(struct super_block *sb,
30935 + aufs_bindex_t bindex)
30937 + SiMustAnyLock(sb);
30938 + return au_sbi(sb)->si_branch[0 + bindex];
30941 +static inline loff_t au_xi_maxent(struct super_block *sb)
30943 + SiMustAnyLock(sb);
30944 + return au_sbi(sb)->si_ximaxent;
30947 +#endif /* __KERNEL__ */
30948 +#endif /* __AUFS_SUPER_H__ */
30949 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30950 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30951 +++ linux/fs/aufs/sysaufs.c 2021-02-22 22:51:59.061411920 +0100
30953 +// SPDX-License-Identifier: GPL-2.0
30955 + * Copyright (C) 2005-2020 Junjiro R. Okajima
30957 + * This program, aufs is free software; you can redistribute it and/or modify
30958 + * it under the terms of the GNU General Public License as published by
30959 + * the Free Software Foundation; either version 2 of the License, or
30960 + * (at your option) any later version.
30962 + * This program is distributed in the hope that it will be useful,
30963 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30964 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30965 + * GNU General Public License for more details.
30967 + * You should have received a copy of the GNU General Public License
30968 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30972 + * sysfs interface and lifetime management
30973 + * they are necessary regardless sysfs is disabled.
30976 +#include <linux/random.h>
30979 +unsigned long sysaufs_si_mask;
30980 +struct kset *sysaufs_kset;
30982 +#define AuSiAttr(_name) { \
30983 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30984 + .show = sysaufs_si_##_name, \
30987 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30988 +struct attribute *sysaufs_si_attrs[] = {
30989 + &sysaufs_si_attr_xi_path.attr,
30993 +static const struct sysfs_ops au_sbi_ops = {
30994 + .show = sysaufs_si_show
30997 +static struct kobj_type au_sbi_ktype = {
30998 + .release = au_si_free,
30999 + .sysfs_ops = &au_sbi_ops,
31000 + .default_attrs = sysaufs_si_attrs
31003 +/* ---------------------------------------------------------------------- */
31005 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31009 + sbinfo->si_kobj.kset = sysaufs_kset;
31010 + /* cf. sysaufs_name() */
31011 + err = kobject_init_and_add
31012 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31013 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31018 +void sysaufs_fin(void)
31020 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31021 + kset_unregister(sysaufs_kset);
31024 +int __init sysaufs_init(void)
31029 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31030 + } while (!sysaufs_si_mask);
31033 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31034 + if (unlikely(!sysaufs_kset))
31036 + err = PTR_ERR(sysaufs_kset);
31037 + if (IS_ERR(sysaufs_kset))
31039 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31040 + if (unlikely(err))
31041 + kset_unregister(sysaufs_kset);
31046 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31047 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31048 +++ linux/fs/aufs/sysaufs.h 2021-02-22 22:51:59.061411920 +0100
31050 +/* SPDX-License-Identifier: GPL-2.0 */
31052 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31054 + * This program, aufs is free software; you can redistribute it and/or modify
31055 + * it under the terms of the GNU General Public License as published by
31056 + * the Free Software Foundation; either version 2 of the License, or
31057 + * (at your option) any later version.
31059 + * This program is distributed in the hope that it will be useful,
31060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31062 + * GNU General Public License for more details.
31064 + * You should have received a copy of the GNU General Public License
31065 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31069 + * sysfs interface and mount lifetime management
31072 +#ifndef __SYSAUFS_H__
31073 +#define __SYSAUFS_H__
31077 +#include <linux/sysfs.h>
31078 +#include "module.h"
31080 +struct super_block;
31083 +struct sysaufs_si_attr {
31084 + struct attribute attr;
31085 + int (*show)(struct seq_file *seq, struct super_block *sb);
31088 +/* ---------------------------------------------------------------------- */
31091 +extern unsigned long sysaufs_si_mask;
31092 +extern struct kset *sysaufs_kset;
31093 +extern struct attribute *sysaufs_si_attrs[];
31094 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31095 +int __init sysaufs_init(void);
31096 +void sysaufs_fin(void);
31098 +/* ---------------------------------------------------------------------- */
31100 +/* some people doesn't like to show a pointer in kernel */
31101 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31103 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31106 +#define SysaufsSiNamePrefix "si_"
31107 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31108 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31110 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31111 + sysaufs_si_id(sbinfo));
31115 +#ifdef CONFIG_SYSFS
31117 +extern struct attribute_group *sysaufs_attr_group;
31119 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31120 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31122 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31123 +#ifdef CONFIG_COMPAT
31124 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31127 +void sysaufs_br_init(struct au_branch *br);
31128 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31129 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31131 +#define sysaufs_brs_init() do {} while (0)
31134 +#define sysaufs_attr_group NULL
31136 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31137 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31138 + struct attribute *attr, char *buf)
31139 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31140 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31141 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31143 +static inline void sysaufs_brs_init(void)
31148 +#endif /* CONFIG_SYSFS */
31150 +#endif /* __KERNEL__ */
31151 +#endif /* __SYSAUFS_H__ */
31152 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31153 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31154 +++ linux/fs/aufs/sysfs.c 2021-02-22 22:51:59.061411920 +0100
31156 +// SPDX-License-Identifier: GPL-2.0
31158 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31160 + * This program, aufs is free software; you can redistribute it and/or modify
31161 + * it under the terms of the GNU General Public License as published by
31162 + * the Free Software Foundation; either version 2 of the License, or
31163 + * (at your option) any later version.
31165 + * This program is distributed in the hope that it will be useful,
31166 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31167 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31168 + * GNU General Public License for more details.
31170 + * You should have received a copy of the GNU General Public License
31171 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31175 + * sysfs interface
31178 +#include <linux/compat.h>
31179 +#include <linux/seq_file.h>
31182 +#ifdef CONFIG_AUFS_FS_MODULE
31183 +/* this entry violates the "one line per file" policy of sysfs */
31184 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31188 + static char *conf =
31189 +/* this file is generated at compiling */
31190 +#include "conf.str"
31193 + err = snprintf(buf, PAGE_SIZE, conf);
31194 + if (unlikely(err >= PAGE_SIZE))
31199 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31202 +static struct attribute *au_attr[] = {
31203 +#ifdef CONFIG_AUFS_FS_MODULE
31204 + &au_config_attr.attr,
31206 + NULL, /* need to NULL terminate the list of attributes */
31209 +static struct attribute_group sysaufs_attr_group_body = {
31213 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31215 +/* ---------------------------------------------------------------------- */
31217 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31221 + SiMustAnyLock(sb);
31224 + if (au_opt_test(au_mntflags(sb), XINO)) {
31225 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31226 + seq_putc(seq, '\n');
31232 + * the lifetime of branch is independent from the entry under sysfs.
31233 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31236 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31237 + aufs_bindex_t bindex, int idx)
31240 + struct path path;
31241 + struct dentry *root;
31242 + struct au_branch *br;
31243 + au_br_perm_str_t perm;
31245 + AuDbg("b%d\n", bindex);
31248 + root = sb->s_root;
31249 + di_read_lock_parent(root, !AuLock_IR);
31250 + br = au_sbr(sb, bindex);
31253 + case AuBrSysfs_BR:
31254 + path.mnt = au_br_mnt(br);
31255 + path.dentry = au_h_dptr(root, bindex);
31256 + err = au_seq_path(seq, &path);
31258 + au_optstr_br_perm(&perm, br->br_perm);
31259 + seq_printf(seq, "=%s\n", perm.a);
31262 + case AuBrSysfs_BRID:
31263 + seq_printf(seq, "%d\n", br->br_id);
31266 + di_read_unlock(root, !AuLock_IR);
31267 + if (unlikely(err || seq_has_overflowed(seq)))
31273 +/* ---------------------------------------------------------------------- */
31275 +static struct seq_file *au_seq(char *p, ssize_t len)
31277 + struct seq_file *seq;
31279 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31281 + /* mutex_init(&seq.lock); */
31284 + return seq; /* success */
31287 + seq = ERR_PTR(-ENOMEM);
31291 +#define SysaufsBr_PREFIX "br"
31292 +#define SysaufsBrid_PREFIX "brid"
31294 +/* todo: file size may exceed PAGE_SIZE */
31295 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31301 + aufs_bindex_t bbot;
31302 + struct au_sbinfo *sbinfo;
31303 + struct super_block *sb;
31304 + struct seq_file *seq;
31306 + struct attribute **cattr;
31308 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31309 + sb = sbinfo->si_sb;
31312 + * prevent a race condition between sysfs and aufs.
31313 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31314 + * prohibits maintaining the sysfs entries.
31315 + * hew we acquire read lock after sysfs_get_active_two().
31316 + * on the other hand, the remount process may maintain the sysfs/aufs
31317 + * entries after acquiring write lock.
31318 + * it can cause a deadlock.
31319 + * simply we gave up processing read here.
31322 + if (unlikely(!si_noflush_read_trylock(sb)))
31325 + seq = au_seq(buf, PAGE_SIZE);
31326 + err = PTR_ERR(seq);
31330 + name = (void *)attr->name;
31331 + cattr = sysaufs_si_attrs;
31333 + if (!strcmp(name, (*cattr)->name)) {
31334 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31341 + if (!strncmp(name, SysaufsBrid_PREFIX,
31342 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31343 + idx = AuBrSysfs_BRID;
31344 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31345 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31346 + sizeof(SysaufsBr_PREFIX) - 1)) {
31347 + idx = AuBrSysfs_BR;
31348 + name += sizeof(SysaufsBr_PREFIX) - 1;
31352 + err = kstrtol(name, 10, &l);
31354 + bbot = au_sbbot(sb);
31356 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31363 + err = seq->count;
31364 + /* sysfs limit */
31365 + if (unlikely(err == PAGE_SIZE))
31368 + au_kfree_rcu(seq);
31370 + si_read_unlock(sb);
31375 +/* ---------------------------------------------------------------------- */
31377 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31381 + aufs_bindex_t bindex, bbot;
31384 + struct seq_file *seq;
31385 + struct au_branch *br;
31387 + si_read_lock(sb, AuLock_FLUSH);
31388 + bbot = au_sbbot(sb);
31394 + buf = (void *)__get_free_page(GFP_NOFS);
31395 + if (unlikely(!buf))
31398 + seq = au_seq(buf, PAGE_SIZE);
31399 + err = PTR_ERR(seq);
31403 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31404 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31405 + /* VERIFY_WRITE */
31406 + err = !access_ok(arg, sizeof(*arg));
31407 + if (unlikely(err))
31410 + br = au_sbr(sb, bindex);
31411 + brid = br->br_id;
31412 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31413 + err = __put_user(brid, &arg->id);
31414 + if (unlikely(err))
31417 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31418 + err = __put_user(br->br_perm, &arg->perm);
31419 + if (unlikely(err))
31422 + err = au_seq_path(seq, &br->br_path);
31423 + if (unlikely(err))
31425 + seq_putc(seq, '\0');
31426 + if (!seq_has_overflowed(seq)) {
31427 + err = copy_to_user(arg->path, seq->buf, seq->count);
31429 + if (unlikely(err))
31436 + if (unlikely(err))
31440 + au_kfree_rcu(seq);
31442 + free_page((unsigned long)buf);
31444 + si_read_unlock(sb);
31448 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31450 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31453 +#ifdef CONFIG_COMPAT
31454 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31456 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31460 +/* ---------------------------------------------------------------------- */
31462 +void sysaufs_br_init(struct au_branch *br)
31465 + struct au_brsysfs *br_sysfs;
31466 + struct attribute *attr;
31468 + br_sysfs = br->br_sysfs;
31469 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31470 + attr = &br_sysfs->attr;
31471 + sysfs_attr_init(attr);
31472 + attr->name = br_sysfs->name;
31473 + attr->mode = 0444;
31478 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31480 + struct au_branch *br;
31481 + struct kobject *kobj;
31482 + struct au_brsysfs *br_sysfs;
31484 + aufs_bindex_t bbot;
31486 + if (!sysaufs_brs)
31489 + kobj = &au_sbi(sb)->si_kobj;
31490 + bbot = au_sbbot(sb);
31491 + for (; bindex <= bbot; bindex++) {
31492 + br = au_sbr(sb, bindex);
31493 + br_sysfs = br->br_sysfs;
31494 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31495 + sysfs_remove_file(kobj, &br_sysfs->attr);
31501 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31504 + aufs_bindex_t bbot;
31505 + struct kobject *kobj;
31506 + struct au_branch *br;
31507 + struct au_brsysfs *br_sysfs;
31509 + if (!sysaufs_brs)
31512 + kobj = &au_sbi(sb)->si_kobj;
31513 + bbot = au_sbbot(sb);
31514 + for (; bindex <= bbot; bindex++) {
31515 + br = au_sbr(sb, bindex);
31516 + br_sysfs = br->br_sysfs;
31517 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31518 + SysaufsBr_PREFIX "%d", bindex);
31519 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31520 + SysaufsBrid_PREFIX "%d", bindex);
31521 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31522 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31523 + if (unlikely(err))
31524 + pr_warn("failed %s under sysfs(%d)\n",
31525 + br_sysfs->name, err);
31530 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31531 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31532 +++ linux/fs/aufs/sysrq.c 2021-02-22 22:51:59.061411920 +0100
31534 +// SPDX-License-Identifier: GPL-2.0
31536 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31538 + * This program, aufs is free software; you can redistribute it and/or modify
31539 + * it under the terms of the GNU General Public License as published by
31540 + * the Free Software Foundation; either version 2 of the License, or
31541 + * (at your option) any later version.
31543 + * This program is distributed in the hope that it will be useful,
31544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31546 + * GNU General Public License for more details.
31548 + * You should have received a copy of the GNU General Public License
31549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31553 + * magic sysrq handler
31556 +/* #include <linux/sysrq.h> */
31557 +#include <linux/writeback.h>
31560 +/* ---------------------------------------------------------------------- */
31562 +static void sysrq_sb(struct super_block *sb)
31565 + struct au_sbinfo *sbinfo;
31566 + struct file *file;
31567 + struct hlist_bl_head *files;
31568 + struct hlist_bl_node *pos;
31569 + struct au_finfo *finfo;
31572 + plevel = au_plevel;
31573 + au_plevel = KERN_WARNING;
31575 + /* since we define pr_fmt, call printk directly */
31576 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31578 + sbinfo = au_sbi(sb);
31579 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31580 + pr("superblock\n");
31583 +#if 0 /* reserved */
31585 + int err, i, j, ndentry;
31586 + struct au_dcsub_pages dpages;
31587 + struct au_dpage *dpage;
31589 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31590 + if (unlikely(err))
31592 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31594 + for (i = 0; i < dpages.ndpage; i++) {
31595 + dpage = dpages.dpages + i;
31596 + ndentry = dpage->ndentry;
31597 + for (j = 0; j < ndentry; j++)
31598 + au_dpri_dentry(dpage->dentries[j]);
31600 + au_dpages_free(&dpages);
31604 + pr("isolated inode\n");
31605 + spin_lock(&sb->s_inode_list_lock);
31606 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31607 + spin_lock(&i->i_lock);
31608 + if (hlist_empty(&i->i_dentry))
31609 + au_dpri_inode(i);
31610 + spin_unlock(&i->i_lock);
31612 + spin_unlock(&sb->s_inode_list_lock);
31615 + files = &au_sbi(sb)->si_files;
31616 + hlist_bl_lock(files);
31617 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31620 + file = finfo->fi_file;
31621 + mode = file_inode(file)->i_mode;
31622 + if (!special_file(mode))
31623 + au_dpri_file(file);
31625 + hlist_bl_unlock(files);
31629 + au_plevel = plevel;
31632 +/* ---------------------------------------------------------------------- */
31634 +/* module parameter */
31635 +static char *aufs_sysrq_key = "a";
31636 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31637 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31639 +static void au_sysrq(int key __maybe_unused)
31641 + struct au_sbinfo *sbinfo;
31642 + struct hlist_bl_node *pos;
31645 + au_sbilist_lock();
31646 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31647 + sysrq_sb(sbinfo->si_sb);
31648 + au_sbilist_unlock();
31652 +static struct sysrq_key_op au_sysrq_op = {
31653 + .handler = au_sysrq,
31654 + .help_msg = "Aufs",
31655 + .action_msg = "Aufs",
31656 + .enable_mask = SYSRQ_ENABLE_DUMP
31659 +/* ---------------------------------------------------------------------- */
31661 +int __init au_sysrq_init(void)
31667 + key = *aufs_sysrq_key;
31668 + if ('a' <= key && key <= 'z')
31669 + err = register_sysrq_key(key, &au_sysrq_op);
31670 + if (unlikely(err))
31671 + pr_err("err %d, sysrq=%c\n", err, key);
31675 +void au_sysrq_fin(void)
31679 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31680 + if (unlikely(err))
31681 + pr_err("err %d (ignored)\n", err);
31683 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31684 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31685 +++ linux/fs/aufs/vdir.c 2021-02-22 22:51:59.061411920 +0100
31687 +// SPDX-License-Identifier: GPL-2.0
31689 + * Copyright (C) 2005-2020 Junjiro R. Okajima
31691 + * This program, aufs is free software; you can redistribute it and/or modify
31692 + * it under the terms of the GNU General Public License as published by
31693 + * the Free Software Foundation; either version 2 of the License, or
31694 + * (at your option) any later version.
31696 + * This program is distributed in the hope that it will be useful,
31697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31699 + * GNU General Public License for more details.
31701 + * You should have received a copy of the GNU General Public License
31702 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31706 + * virtual or vertical directory
31709 +#include <linux/iversion.h>
31712 +static unsigned int calc_size(int nlen)
31714 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31717 +static int set_deblk_end(union au_vdir_deblk_p *p,
31718 + union au_vdir_deblk_p *deblk_end)
31720 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31721 + p->de->de_str.len = 0;
31725 + return -1; /* error */
31728 +/* returns true or false */
31729 +static int is_deblk_end(union au_vdir_deblk_p *p,
31730 + union au_vdir_deblk_p *deblk_end)
31732 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31733 + return !p->de->de_str.len;
31737 +static unsigned char *last_deblk(struct au_vdir *vdir)
31739 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31742 +/* ---------------------------------------------------------------------- */
31744 +/* estimate the appropriate size for name hash table */
31745 +unsigned int au_rdhash_est(loff_t sz)
31753 + if (sz < AUFS_RDHASH_DEF)
31754 + n = AUFS_RDHASH_DEF;
31755 + /* pr_info("n %u\n", n); */
31760 + * the allocated memory has to be freed by
31761 + * au_nhash_wh_free() or au_nhash_de_free().
31763 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31765 + struct hlist_head *head;
31769 + sz = sizeof(*nhash->nh_head) * num_hash;
31770 + head = kmalloc(sz, gfp);
31772 + nhash->nh_num = num_hash;
31773 + nhash->nh_head = head;
31774 + for (u = 0; u < num_hash; u++)
31775 + INIT_HLIST_HEAD(head++);
31776 + return 0; /* success */
31782 +static void nhash_count(struct hlist_head *head)
31784 +#if 0 /* debugging */
31786 + struct hlist_node *pos;
31789 + hlist_for_each(pos, head)
31791 + pr_info("%lu\n", n);
31795 +static void au_nhash_wh_do_free(struct hlist_head *head)
31797 + struct au_vdir_wh *pos;
31798 + struct hlist_node *node;
31800 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31801 + au_kfree_rcu(pos);
31804 +static void au_nhash_de_do_free(struct hlist_head *head)
31806 + struct au_vdir_dehstr *pos;
31807 + struct hlist_node *node;
31809 + hlist_for_each_entry_safe(pos, node, head, hash)
31810 + au_cache_free_vdir_dehstr(pos);
31813 +static void au_nhash_do_free(struct au_nhash *nhash,
31814 + void (*free)(struct hlist_head *head))
31817 + struct hlist_head *head;
31819 + n = nhash->nh_num;
31823 + head = nhash->nh_head;
31824 + while (n-- > 0) {
31825 + nhash_count(head);
31828 + au_kfree_try_rcu(nhash->nh_head);
31831 +void au_nhash_wh_free(struct au_nhash *whlist)
31833 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31836 +static void au_nhash_de_free(struct au_nhash *delist)
31838 + au_nhash_do_free(delist, au_nhash_de_do_free);
31841 +/* ---------------------------------------------------------------------- */
31843 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31847 + unsigned int u, n;
31848 + struct hlist_head *head;
31849 + struct au_vdir_wh *pos;
31852 + n = whlist->nh_num;
31853 + head = whlist->nh_head;
31854 + for (u = 0; u < n; u++, head++)
31855 + hlist_for_each_entry(pos, head, wh_hash)
31856 + if (pos->wh_bindex == btgt && ++num > limit)
31861 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31862 + unsigned char *name,
31863 + unsigned int len)
31866 + /* const unsigned int magic_bit = 12; */
31868 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31875 + /* v = hash_long(v, magic_bit); */
31876 + v %= nhash->nh_num;
31877 + return nhash->nh_head + v;
31880 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31883 + return str->len == nlen && !memcmp(str->name, name, nlen);
31886 +/* returns found or not */
31887 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31889 + struct hlist_head *head;
31890 + struct au_vdir_wh *pos;
31891 + struct au_vdir_destr *str;
31893 + head = au_name_hash(whlist, name, nlen);
31894 + hlist_for_each_entry(pos, head, wh_hash) {
31895 + str = &pos->wh_str;
31896 + AuDbg("%.*s\n", str->len, str->name);
31897 + if (au_nhash_test_name(str, name, nlen))
31903 +/* returns found(true) or not */
31904 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31906 + struct hlist_head *head;
31907 + struct au_vdir_dehstr *pos;
31908 + struct au_vdir_destr *str;
31910 + head = au_name_hash(delist, name, nlen);
31911 + hlist_for_each_entry(pos, head, hash) {
31913 + AuDbg("%.*s\n", str->len, str->name);
31914 + if (au_nhash_test_name(str, name, nlen))
31920 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31921 + unsigned char d_type)
31923 +#ifdef CONFIG_AUFS_SHWH
31924 + wh->wh_ino = ino;
31925 + wh->wh_type = d_type;
31929 +/* ---------------------------------------------------------------------- */
31931 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31932 + unsigned int d_type, aufs_bindex_t bindex,
31933 + unsigned char shwh)
31936 + struct au_vdir_destr *str;
31937 + struct au_vdir_wh *wh;
31939 + AuDbg("%.*s\n", nlen, name);
31940 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31943 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31944 + if (unlikely(!wh))
31948 + wh->wh_bindex = bindex;
31950 + au_shwh_init_wh(wh, ino, d_type);
31951 + str = &wh->wh_str;
31953 + memcpy(str->name, name, nlen);
31954 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31961 +static int append_deblk(struct au_vdir *vdir)
31964 + unsigned long ul;
31965 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31966 + union au_vdir_deblk_p p, deblk_end;
31967 + unsigned char **o;
31970 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31971 + GFP_NOFS, /*may_shrink*/0);
31972 + if (unlikely(!o))
31975 + vdir->vd_deblk = o;
31976 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31978 + ul = vdir->vd_nblk++;
31979 + vdir->vd_deblk[ul] = p.deblk;
31980 + vdir->vd_last.ul = ul;
31981 + vdir->vd_last.p.deblk = p.deblk;
31982 + deblk_end.deblk = p.deblk + deblk_sz;
31983 + err = set_deblk_end(&p, &deblk_end);
31990 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31991 + unsigned int d_type, struct au_nhash *delist)
31995 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31996 + union au_vdir_deblk_p p, *room, deblk_end;
31997 + struct au_vdir_dehstr *dehstr;
31999 + p.deblk = last_deblk(vdir);
32000 + deblk_end.deblk = p.deblk + deblk_sz;
32001 + room = &vdir->vd_last.p;
32002 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32003 + || !is_deblk_end(room, &deblk_end));
32005 + sz = calc_size(nlen);
32006 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32007 + err = append_deblk(vdir);
32008 + if (unlikely(err))
32011 + p.deblk = last_deblk(vdir);
32012 + deblk_end.deblk = p.deblk + deblk_sz;
32014 + AuDebugOn(room->deblk != p.deblk);
32018 + dehstr = au_cache_alloc_vdir_dehstr();
32019 + if (unlikely(!dehstr))
32022 + dehstr->str = &room->de->de_str;
32023 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32024 + room->de->de_ino = ino;
32025 + room->de->de_type = d_type;
32026 + room->de->de_str.len = nlen;
32027 + memcpy(room->de->de_str.name, name, nlen);
32030 + room->deblk += sz;
32031 + if (unlikely(set_deblk_end(room, &deblk_end)))
32032 + err = append_deblk(vdir);
32039 +/* ---------------------------------------------------------------------- */
32041 +void au_vdir_free(struct au_vdir *vdir)
32043 + unsigned char **deblk;
32045 + deblk = vdir->vd_deblk;
32046 + while (vdir->vd_nblk--)
32047 + au_kfree_try_rcu(*deblk++);
32048 + au_kfree_try_rcu(vdir->vd_deblk);
32049 + au_cache_free_vdir(vdir);
32052 +static struct au_vdir *alloc_vdir(struct file *file)
32054 + struct au_vdir *vdir;
32055 + struct super_block *sb;
32058 + sb = file->f_path.dentry->d_sb;
32059 + SiMustAnyLock(sb);
32062 + vdir = au_cache_alloc_vdir();
32063 + if (unlikely(!vdir))
32066 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32067 + if (unlikely(!vdir->vd_deblk))
32070 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32071 + if (!vdir->vd_deblk_sz) {
32072 + /* estimate the appropriate size for deblk */
32073 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32074 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32076 + vdir->vd_nblk = 0;
32077 + vdir->vd_version = 0;
32078 + vdir->vd_jiffy = 0;
32079 + err = append_deblk(vdir);
32081 + return vdir; /* success */
32083 + au_kfree_try_rcu(vdir->vd_deblk);
32086 + au_cache_free_vdir(vdir);
32088 + vdir = ERR_PTR(err);
32092 +static int reinit_vdir(struct au_vdir *vdir)
32095 + union au_vdir_deblk_p p, deblk_end;
32097 + while (vdir->vd_nblk > 1) {
32098 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32099 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32102 + p.deblk = vdir->vd_deblk[0];
32103 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32104 + err = set_deblk_end(&p, &deblk_end);
32105 + /* keep vd_dblk_sz */
32106 + vdir->vd_last.ul = 0;
32107 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32108 + vdir->vd_version = 0;
32109 + vdir->vd_jiffy = 0;
32114 +/* ---------------------------------------------------------------------- */
32116 +#define AuFillVdir_CALLED 1
32117 +#define AuFillVdir_WHABLE (1 << 1)
32118 +#define AuFillVdir_SHWH (1 << 2)
32119 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32120 +#define au_fset_fillvdir(flags, name) \
32121 + do { (flags) |= AuFillVdir_##name; } while (0)
32122 +#define au_fclr_fillvdir(flags, name) \
32123 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32125 +#ifndef CONFIG_AUFS_SHWH
32126 +#undef AuFillVdir_SHWH
32127 +#define AuFillVdir_SHWH 0
32130 +struct fillvdir_arg {
32131 + struct dir_context ctx;
32132 + struct file *file;
32133 + struct au_vdir *vdir;
32134 + struct au_nhash delist;
32135 + struct au_nhash whlist;
32136 + aufs_bindex_t bindex;
32137 + unsigned int flags;
32141 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32142 + loff_t offset __maybe_unused, u64 h_ino,
32143 + unsigned int d_type)
32145 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32146 + char *name = (void *)__name;
32147 + struct super_block *sb;
32149 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32152 + sb = arg->file->f_path.dentry->d_sb;
32153 + au_fset_fillvdir(arg->flags, CALLED);
32155 + if (nlen <= AUFS_WH_PFX_LEN
32156 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32157 + if (test_known(&arg->delist, name, nlen)
32158 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32159 + goto out; /* already exists or whiteouted */
32161 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32163 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32164 + d_type = DT_UNKNOWN;
32165 + arg->err = append_de(arg->vdir, name, nlen, ino,
32166 + d_type, &arg->delist);
32168 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32169 + name += AUFS_WH_PFX_LEN;
32170 + nlen -= AUFS_WH_PFX_LEN;
32171 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32172 + goto out; /* already whiteouted */
32174 + ino = 0; /* just to suppress a warning */
32176 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32179 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32180 + d_type = DT_UNKNOWN;
32181 + arg->err = au_nhash_append_wh
32182 + (&arg->whlist, name, nlen, ino, d_type,
32183 + arg->bindex, shwh);
32189 + arg->vdir->vd_jiffy = jiffies;
32191 + AuTraceErr(arg->err);
32195 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32196 + struct au_nhash *whlist, struct au_nhash *delist)
32198 +#ifdef CONFIG_AUFS_SHWH
32200 + unsigned int nh, u;
32201 + struct hlist_head *head;
32202 + struct au_vdir_wh *pos;
32203 + struct hlist_node *n;
32205 + struct au_vdir_destr *destr;
32207 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32210 + o = p = (void *)__get_free_page(GFP_NOFS);
32211 + if (unlikely(!p))
32215 + nh = whlist->nh_num;
32216 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32217 + p += AUFS_WH_PFX_LEN;
32218 + for (u = 0; u < nh; u++) {
32219 + head = whlist->nh_head + u;
32220 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32221 + destr = &pos->wh_str;
32222 + memcpy(p, destr->name, destr->len);
32223 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32224 + pos->wh_ino, pos->wh_type, delist);
32225 + if (unlikely(err))
32230 + free_page((unsigned long)o);
32240 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32243 + unsigned int rdhash;
32245 + aufs_bindex_t bbot, bindex, btop;
32246 + unsigned char shwh;
32247 + struct file *hf, *file;
32248 + struct super_block *sb;
32250 + file = arg->file;
32251 + sb = file->f_path.dentry->d_sb;
32252 + SiMustAnyLock(sb);
32254 + rdhash = au_sbi(sb)->si_rdhash;
32256 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32257 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32258 + if (unlikely(err))
32260 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32261 + if (unlikely(err))
32267 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32269 + au_fset_fillvdir(arg->flags, SHWH);
32271 + btop = au_fbtop(file);
32272 + bbot = au_fbbot_dir(file);
32273 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32274 + hf = au_hf_dir(file, bindex);
32278 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32280 + if (unlikely(offset))
32283 + arg->bindex = bindex;
32284 + au_fclr_fillvdir(arg->flags, WHABLE);
32286 + || (bindex != bbot
32287 + && au_br_whable(au_sbr_perm(sb, bindex))))
32288 + au_fset_fillvdir(arg->flags, WHABLE);
32291 + au_fclr_fillvdir(arg->flags, CALLED);
32293 + err = vfsub_iterate_dir(hf, &arg->ctx);
32296 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32299 + * dir_relax() may be good for concurrency, but aufs should not
32300 + * use it since it will cause a lockdep problem.
32304 + if (!err && shwh)
32305 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32307 + au_nhash_wh_free(&arg->whlist);
32310 + au_nhash_de_free(&arg->delist);
32315 +static int read_vdir(struct file *file, int may_read)
32318 + unsigned long expire;
32319 + unsigned char do_read;
32320 + struct fillvdir_arg arg = {
32322 + .actor = fillvdir
32325 + struct inode *inode;
32326 + struct au_vdir *vdir, *allocated;
32329 + inode = file_inode(file);
32330 + IMustLock(inode);
32331 + IiMustWriteLock(inode);
32332 + SiMustAnyLock(inode->i_sb);
32334 + allocated = NULL;
32336 + expire = au_sbi(inode->i_sb)->si_rdcache;
32337 + vdir = au_ivdir(inode);
32340 + vdir = alloc_vdir(file);
32341 + err = PTR_ERR(vdir);
32342 + if (IS_ERR(vdir))
32345 + allocated = vdir;
32346 + } else if (may_read
32347 + && (!inode_eq_iversion(inode, vdir->vd_version)
32348 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32350 + err = reinit_vdir(vdir);
32351 + if (unlikely(err))
32356 + return 0; /* success */
32360 + err = au_do_read_vdir(&arg);
32362 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32363 + vdir->vd_version = inode_query_iversion(inode);
32364 + vdir->vd_last.ul = 0;
32365 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32367 + au_set_ivdir(inode, allocated);
32368 + } else if (allocated)
32369 + au_vdir_free(allocated);
32375 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32378 + unsigned long ul, n;
32379 + const unsigned int deblk_sz = src->vd_deblk_sz;
32381 + AuDebugOn(tgt->vd_nblk != 1);
32384 + if (tgt->vd_nblk < src->vd_nblk) {
32385 + unsigned char **p;
32387 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32388 + GFP_NOFS, /*may_shrink*/0);
32389 + if (unlikely(!p))
32391 + tgt->vd_deblk = p;
32394 + if (tgt->vd_deblk_sz != deblk_sz) {
32395 + unsigned char *p;
32397 + tgt->vd_deblk_sz = deblk_sz;
32398 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32399 + /*may_shrink*/1);
32400 + if (unlikely(!p))
32402 + tgt->vd_deblk[0] = p;
32404 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32405 + tgt->vd_version = src->vd_version;
32406 + tgt->vd_jiffy = src->vd_jiffy;
32408 + n = src->vd_nblk;
32409 + for (ul = 1; ul < n; ul++) {
32410 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32412 + if (unlikely(!tgt->vd_deblk[ul]))
32416 + tgt->vd_nblk = n;
32417 + tgt->vd_last.ul = tgt->vd_last.ul;
32418 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32419 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32420 + - src->vd_deblk[src->vd_last.ul];
32422 + return 0; /* success */
32425 + rerr = reinit_vdir(tgt);
32430 +int au_vdir_init(struct file *file)
32433 + struct inode *inode;
32434 + struct au_vdir *vdir_cache, *allocated;
32436 + /* test file->f_pos here instead of ctx->pos */
32437 + err = read_vdir(file, !file->f_pos);
32438 + if (unlikely(err))
32441 + allocated = NULL;
32442 + vdir_cache = au_fvdir_cache(file);
32443 + if (!vdir_cache) {
32444 + vdir_cache = alloc_vdir(file);
32445 + err = PTR_ERR(vdir_cache);
32446 + if (IS_ERR(vdir_cache))
32448 + allocated = vdir_cache;
32449 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32450 + /* test file->f_pos here instead of ctx->pos */
32451 + err = reinit_vdir(vdir_cache);
32452 + if (unlikely(err))
32455 + return 0; /* success */
32457 + inode = file_inode(file);
32458 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32460 + file->f_version = inode_query_iversion(inode);
32462 + au_set_fvdir_cache(file, allocated);
32463 + } else if (allocated)
32464 + au_vdir_free(allocated);
32470 +static loff_t calc_offset(struct au_vdir *vdir)
32473 + union au_vdir_deblk_p p;
32475 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32476 + offset = vdir->vd_last.p.deblk - p.deblk;
32477 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32481 +/* returns true or false */
32482 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32485 + unsigned int deblk_sz;
32486 + unsigned long ul, n;
32488 + union au_vdir_deblk_p p, deblk_end;
32489 + struct au_vdir *vdir_cache;
32492 + vdir_cache = au_fvdir_cache(file);
32493 + offset = calc_offset(vdir_cache);
32494 + AuDbg("offset %lld\n", offset);
32495 + if (ctx->pos == offset)
32498 + vdir_cache->vd_last.ul = 0;
32499 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32504 + deblk_sz = vdir_cache->vd_deblk_sz;
32505 + ul = div64_u64(ctx->pos, deblk_sz);
32506 + AuDbg("ul %lu\n", ul);
32507 + if (ul >= vdir_cache->vd_nblk)
32510 + n = vdir_cache->vd_nblk;
32511 + for (; ul < n; ul++) {
32512 + p.deblk = vdir_cache->vd_deblk[ul];
32513 + deblk_end.deblk = p.deblk + deblk_sz;
32515 + offset *= deblk_sz;
32516 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32519 + l = calc_size(p.de->de_str.len);
32523 + if (!is_deblk_end(&p, &deblk_end)) {
32525 + vdir_cache->vd_last.ul = ul;
32526 + vdir_cache->vd_last.p = p;
32534 + AuDbg("valid %d\n", !valid);
32538 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32540 + unsigned int l, deblk_sz;
32541 + union au_vdir_deblk_p deblk_end;
32542 + struct au_vdir *vdir_cache;
32543 + struct au_vdir_de *de;
32545 + if (!seek_vdir(file, ctx))
32548 + vdir_cache = au_fvdir_cache(file);
32549 + deblk_sz = vdir_cache->vd_deblk_sz;
32551 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32552 + deblk_end.deblk += deblk_sz;
32553 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32554 + de = vdir_cache->vd_last.p.de;
32555 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32556 + de->de_str.len, de->de_str.name, ctx->pos,
32557 + (unsigned long)de->de_ino, de->de_type);
32558 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32559 + de->de_str.len, de->de_ino,
32561 + /* todo: ignore the error caused by udba? */
32562 + /* return err; */
32566 + l = calc_size(de->de_str.len);
32567 + vdir_cache->vd_last.p.deblk += l;
32570 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32571 + vdir_cache->vd_last.ul++;
32572 + vdir_cache->vd_last.p.deblk
32573 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32574 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32583 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32584 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32585 +++ linux/fs/aufs/vfsub.c 2021-02-22 22:51:59.061411920 +0100
32587 +// SPDX-License-Identifier: GPL-2.0
32589 + * Copyright (C) 2005-2020 Junjiro R. Okajima
32591 + * This program, aufs is free software; you can redistribute it and/or modify
32592 + * it under the terms of the GNU General Public License as published by
32593 + * the Free Software Foundation; either version 2 of the License, or
32594 + * (at your option) any later version.
32596 + * This program is distributed in the hope that it will be useful,
32597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32599 + * GNU General Public License for more details.
32601 + * You should have received a copy of the GNU General Public License
32602 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32606 + * sub-routines for VFS
32609 +#include <linux/mnt_namespace.h>
32610 +#include <linux/namei.h>
32611 +#include <linux/nsproxy.h>
32612 +#include <linux/security.h>
32613 +#include <linux/splice.h>
32616 +#ifdef CONFIG_AUFS_BR_FUSE
32617 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32619 + if (!au_test_fuse(h_sb) || !au_userns)
32622 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32626 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32631 + down_read(&h_sb->s_umount);
32632 + err = __sync_filesystem(h_sb, wait);
32633 + up_read(&h_sb->s_umount);
32639 +/* ---------------------------------------------------------------------- */
32641 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32645 + struct super_block *h_sb;
32647 + /* for remote fs, leave work for its getattr or d_revalidate */
32648 + /* for bad i_attr fs, handle them in aufs_getattr() */
32649 + /* still some fs may acquire i_mutex. we need to skip them */
32653 + h_sb = h_path->dentry->d_sb;
32654 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32656 + err = vfsub_getattr(h_path, &st);
32661 +/* ---------------------------------------------------------------------- */
32663 +struct file *vfsub_dentry_open(struct path *path, int flags)
32665 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32669 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32671 + struct file *file;
32674 + file = filp_open(path,
32675 + oflags /* | __FMODE_NONOTIFY */,
32678 + if (IS_ERR(file))
32680 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32687 + * Ideally this function should call VFS:do_last() in order to keep all its
32688 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32689 + * structure such as nameidata. This is a second (or third) best approach.
32690 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32692 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32693 + struct vfsub_aopen_args *args)
32696 + struct au_branch *br = args->br;
32697 + struct file *file = args->file;
32698 + /* copied from linux/fs/namei.c:atomic_open() */
32699 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32702 + AuDebugOn(!dir->i_op->atomic_open);
32704 + err = au_br_test_oflag(args->open_flag, br);
32705 + if (unlikely(err))
32708 + au_lcnt_inc(&br->br_nfiles);
32709 + file->f_path.dentry = DENTRY_NOT_SET;
32710 + file->f_path.mnt = au_br_mnt(br);
32711 + AuDbg("%ps\n", dir->i_op->atomic_open);
32712 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32713 + args->create_mode);
32714 + if (unlikely(err < 0)) {
32715 + au_lcnt_dec(&br->br_nfiles);
32719 + /* temporary workaround for nfsv4 branch */
32720 + if (au_test_nfs(dir->i_sb))
32721 + nfs_mark_for_revalidate(dir);
32723 + if (file->f_mode & FMODE_CREATED)
32724 + fsnotify_create(dir, dentry);
32725 + if (!(file->f_mode & FMODE_OPENED)) {
32726 + au_lcnt_dec(&br->br_nfiles);
32730 + /* todo: call VFS:may_open() here */
32731 + /* todo: ima_file_check() too? */
32732 + if (!err && (args->open_flag & __FMODE_EXEC))
32733 + err = deny_write_access(file);
32735 + fsnotify_open(file);
32737 + au_lcnt_dec(&br->br_nfiles);
32738 + /* note that the file is created and still opened */
32744 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32748 + err = kern_path(name, flags, path);
32749 + if (!err && d_is_positive(path->dentry))
32750 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32754 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32755 + struct dentry *parent, int len)
32757 + struct path path = {
32761 + path.dentry = lookup_one_len_unlocked(name, parent, len);
32762 + if (IS_ERR(path.dentry))
32764 + if (d_is_positive(path.dentry))
32765 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32768 + AuTraceErrPtr(path.dentry);
32769 + return path.dentry;
32772 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
32775 + struct path path = {
32779 + /* VFS checks it too, but by WARN_ON_ONCE() */
32780 + IMustLock(d_inode(parent));
32782 + path.dentry = lookup_one_len(name, parent, len);
32783 + if (IS_ERR(path.dentry))
32785 + if (d_is_positive(path.dentry))
32786 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32789 + AuTraceErrPtr(path.dentry);
32790 + return path.dentry;
32793 +void vfsub_call_lkup_one(void *args)
32795 + struct vfsub_lkup_one_args *a = args;
32796 + *a->errp = vfsub_lkup_one(a->name, a->parent);
32799 +/* ---------------------------------------------------------------------- */
32801 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32802 + struct dentry *d2, struct au_hinode *hdir2)
32804 + struct dentry *d;
32807 + d = lock_rename(d1, d2);
32809 + au_hn_suspend(hdir1);
32810 + if (hdir1 != hdir2)
32811 + au_hn_suspend(hdir2);
32816 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32817 + struct dentry *d2, struct au_hinode *hdir2)
32819 + au_hn_resume(hdir1);
32820 + if (hdir1 != hdir2)
32821 + au_hn_resume(hdir2);
32823 + unlock_rename(d1, d2);
32827 +/* ---------------------------------------------------------------------- */
32829 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32832 + struct dentry *d;
32836 + d = path->dentry;
32837 + path->dentry = d->d_parent;
32838 + err = security_path_mknod(path, d, mode, 0);
32839 + path->dentry = d;
32840 + if (unlikely(err))
32844 + err = vfs_create(dir, path->dentry, mode, want_excl);
32847 + struct path tmp = *path;
32850 + vfsub_update_h_iattr(&tmp, &did);
32852 + tmp.dentry = path->dentry->d_parent;
32853 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32862 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32865 + struct dentry *d;
32869 + d = path->dentry;
32870 + path->dentry = d->d_parent;
32871 + err = security_path_symlink(path, d, symname);
32872 + path->dentry = d;
32873 + if (unlikely(err))
32877 + err = vfs_symlink(dir, path->dentry, symname);
32880 + struct path tmp = *path;
32883 + vfsub_update_h_iattr(&tmp, &did);
32885 + tmp.dentry = path->dentry->d_parent;
32886 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32895 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32898 + struct dentry *d;
32902 + d = path->dentry;
32903 + path->dentry = d->d_parent;
32904 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32905 + path->dentry = d;
32906 + if (unlikely(err))
32910 + err = vfs_mknod(dir, path->dentry, mode, dev);
32913 + struct path tmp = *path;
32916 + vfsub_update_h_iattr(&tmp, &did);
32918 + tmp.dentry = path->dentry->d_parent;
32919 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32928 +static int au_test_nlink(struct inode *inode)
32930 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32932 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32933 + || inode->i_nlink < link_max)
32938 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32939 + struct inode **delegated_inode)
32942 + struct dentry *d;
32946 + err = au_test_nlink(d_inode(src_dentry));
32947 + if (unlikely(err))
32950 + /* we don't call may_linkat() */
32951 + d = path->dentry;
32952 + path->dentry = d->d_parent;
32953 + err = security_path_link(src_dentry, path, d);
32954 + path->dentry = d;
32955 + if (unlikely(err))
32959 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32962 + struct path tmp = *path;
32965 + /* fuse has different memory inode for the same inumber */
32966 + vfsub_update_h_iattr(&tmp, &did);
32968 + tmp.dentry = path->dentry->d_parent;
32969 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32970 + tmp.dentry = src_dentry;
32971 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32980 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32981 + struct inode *dir, struct path *path,
32982 + struct inode **delegated_inode, unsigned int flags)
32985 + struct path tmp = {
32988 + struct dentry *d;
32991 + IMustLock(src_dir);
32993 + d = path->dentry;
32994 + path->dentry = d->d_parent;
32995 + tmp.dentry = src_dentry->d_parent;
32996 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
32997 + path->dentry = d;
32998 + if (unlikely(err))
33002 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33003 + delegated_inode, flags);
33008 + tmp.dentry = d->d_parent;
33009 + vfsub_update_h_iattr(&tmp, &did);
33011 + tmp.dentry = src_dentry;
33012 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33013 + tmp.dentry = src_dentry->d_parent;
33014 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33023 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33026 + struct dentry *d;
33030 + d = path->dentry;
33031 + path->dentry = d->d_parent;
33032 + err = security_path_mkdir(path, d, mode);
33033 + path->dentry = d;
33034 + if (unlikely(err))
33038 + err = vfs_mkdir(dir, path->dentry, mode);
33041 + struct path tmp = *path;
33044 + vfsub_update_h_iattr(&tmp, &did);
33046 + tmp.dentry = path->dentry->d_parent;
33047 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33056 +int vfsub_rmdir(struct inode *dir, struct path *path)
33059 + struct dentry *d;
33063 + d = path->dentry;
33064 + path->dentry = d->d_parent;
33065 + err = security_path_rmdir(path, d);
33066 + path->dentry = d;
33067 + if (unlikely(err))
33071 + err = vfs_rmdir(dir, path->dentry);
33074 + struct path tmp = {
33075 + .dentry = path->dentry->d_parent,
33079 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33086 +/* ---------------------------------------------------------------------- */
33088 +/* todo: support mmap_sem? */
33089 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33095 + err = vfs_read(file, ubuf, count, ppos);
33098 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33102 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33108 + err = kernel_read(file, kbuf, count, ppos);
33112 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33116 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33122 + err = vfs_write(file, ubuf, count, ppos);
33125 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33129 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33134 + err = kernel_write(file, kbuf, count, ppos);
33137 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33141 +int vfsub_flush(struct file *file, fl_owner_t id)
33146 + if (file->f_op->flush) {
33147 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33148 + err = file->f_op->flush(file, id);
33151 + err = file->f_op->flush(file, id);
33155 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33161 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33165 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33168 + err = iterate_dir(file, ctx);
33171 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33176 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33177 + struct pipe_inode_info *pipe, size_t len,
33178 + unsigned int flags)
33183 + err = do_splice_to(in, ppos, pipe, len, flags);
33185 + file_accessed(in);
33187 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33191 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33192 + loff_t *ppos, size_t len, unsigned int flags)
33197 + err = do_splice_from(pipe, out, ppos, len, flags);
33200 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33204 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33208 + /* file can be NULL */
33210 + err = vfs_fsync(file, datasync);
33214 + AuDebugOn(!file);
33215 + path = &file->f_path;
33217 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33222 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33223 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33224 + struct file *h_file)
33227 + struct inode *h_inode;
33228 + struct super_block *h_sb;
33231 + err = vfsub_truncate(h_path, length);
33235 + h_inode = d_inode(h_path->dentry);
33236 + h_sb = h_inode->i_sb;
33238 + sb_start_write(h_sb);
33240 + err = locks_verify_truncate(h_inode, h_file, length);
33242 + err = security_path_truncate(h_path);
33245 + err = do_truncate(h_path->dentry, length, attr, h_file);
33249 + sb_end_write(h_sb);
33256 +/* ---------------------------------------------------------------------- */
33258 +struct au_vfsub_mkdir_args {
33260 + struct inode *dir;
33261 + struct path *path;
33265 +static void au_call_vfsub_mkdir(void *args)
33267 + struct au_vfsub_mkdir_args *a = args;
33268 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33271 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33273 + int err, do_sio, wkq_err;
33275 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33278 + err = vfsub_mkdir(dir, path, mode);
33281 + struct au_vfsub_mkdir_args args = {
33287 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33288 + if (unlikely(wkq_err))
33295 +struct au_vfsub_rmdir_args {
33297 + struct inode *dir;
33298 + struct path *path;
33301 +static void au_call_vfsub_rmdir(void *args)
33303 + struct au_vfsub_rmdir_args *a = args;
33304 + *a->errp = vfsub_rmdir(a->dir, a->path);
33307 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33309 + int err, do_sio, wkq_err;
33311 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33314 + err = vfsub_rmdir(dir, path);
33317 + struct au_vfsub_rmdir_args args = {
33322 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33323 + if (unlikely(wkq_err))
33330 +/* ---------------------------------------------------------------------- */
33332 +struct notify_change_args {
33334 + struct path *path;
33335 + struct iattr *ia;
33336 + struct inode **delegated_inode;
33339 +static void call_notify_change(void *args)
33341 + struct notify_change_args *a = args;
33342 + struct inode *h_inode;
33344 + h_inode = d_inode(a->path->dentry);
33345 + IMustLock(h_inode);
33347 + *a->errp = -EPERM;
33348 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33350 + *a->errp = notify_change(a->path->dentry, a->ia,
33351 + a->delegated_inode);
33354 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33356 + AuTraceErr(*a->errp);
33359 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33360 + struct inode **delegated_inode)
33363 + struct notify_change_args args = {
33367 + .delegated_inode = delegated_inode
33370 + call_notify_change(&args);
33375 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33376 + struct inode **delegated_inode)
33378 + int err, wkq_err;
33379 + struct notify_change_args args = {
33383 + .delegated_inode = delegated_inode
33386 + wkq_err = au_wkq_wait(call_notify_change, &args);
33387 + if (unlikely(wkq_err))
33393 +/* ---------------------------------------------------------------------- */
33395 +struct unlink_args {
33397 + struct inode *dir;
33398 + struct path *path;
33399 + struct inode **delegated_inode;
33402 +static void call_unlink(void *args)
33404 + struct unlink_args *a = args;
33405 + struct dentry *d = a->path->dentry;
33406 + struct inode *h_inode;
33407 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33408 + && au_dcount(d) == 1);
33410 + IMustLock(a->dir);
33412 + a->path->dentry = d->d_parent;
33413 + *a->errp = security_path_unlink(a->path, d);
33414 + a->path->dentry = d;
33415 + if (unlikely(*a->errp))
33418 + if (!stop_sillyrename)
33421 + if (d_is_positive(d)) {
33422 + h_inode = d_inode(d);
33427 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33430 + struct path tmp = {
33431 + .dentry = d->d_parent,
33432 + .mnt = a->path->mnt
33434 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33437 + if (!stop_sillyrename)
33442 + AuTraceErr(*a->errp);
33446 + * @dir: must be locked.
33447 + * @dentry: target dentry.
33449 +int vfsub_unlink(struct inode *dir, struct path *path,
33450 + struct inode **delegated_inode, int force)
33453 + struct unlink_args args = {
33457 + .delegated_inode = delegated_inode
33461 + call_unlink(&args);
33465 + wkq_err = au_wkq_wait(call_unlink, &args);
33466 + if (unlikely(wkq_err))
33472 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33473 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33474 +++ linux/fs/aufs/vfsub.h 2021-02-22 22:51:59.061411920 +0100
33476 +/* SPDX-License-Identifier: GPL-2.0 */
33478 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33480 + * This program, aufs is free software; you can redistribute it and/or modify
33481 + * it under the terms of the GNU General Public License as published by
33482 + * the Free Software Foundation; either version 2 of the License, or
33483 + * (at your option) any later version.
33485 + * This program is distributed in the hope that it will be useful,
33486 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33487 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33488 + * GNU General Public License for more details.
33490 + * You should have received a copy of the GNU General Public License
33491 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33495 + * sub-routines for VFS
33498 +#ifndef __AUFS_VFSUB_H__
33499 +#define __AUFS_VFSUB_H__
33503 +#include <linux/fs.h>
33504 +#include <linux/mount.h>
33505 +#include <linux/posix_acl.h>
33506 +#include <linux/xattr.h>
33507 +#include "debug.h"
33509 +/* copied from linux/fs/internal.h */
33510 +/* todo: BAD approach!! */
33511 +extern void __mnt_drop_write(struct vfsmount *);
33512 +extern struct file *alloc_empty_file(int, const struct cred *);
33514 +/* ---------------------------------------------------------------------- */
33516 +/* lock subclass for lower inode */
33517 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33518 +/* reduce? gave up. */
33520 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33521 + AuLsc_I_PARENT, /* lower inode, parent first */
33522 + AuLsc_I_PARENT2, /* copyup dirs */
33523 + AuLsc_I_PARENT3, /* copyup wh */
33529 +/* to debug easier, do not make them inlined functions */
33530 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33531 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33533 +/* ---------------------------------------------------------------------- */
33535 +static inline void vfsub_drop_nlink(struct inode *inode)
33537 + AuDebugOn(!inode->i_nlink);
33538 + drop_nlink(inode);
33541 +static inline void vfsub_dead_dir(struct inode *inode)
33543 + AuDebugOn(!S_ISDIR(inode->i_mode));
33544 + inode->i_flags |= S_DEAD;
33545 + clear_nlink(inode);
33548 +static inline int vfsub_native_ro(struct inode *inode)
33550 + return sb_rdonly(inode->i_sb)
33551 + || IS_RDONLY(inode)
33552 + /* || IS_APPEND(inode) */
33553 + || IS_IMMUTABLE(inode);
33556 +#ifdef CONFIG_AUFS_BR_FUSE
33557 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33559 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33562 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33564 +/* ---------------------------------------------------------------------- */
33566 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33567 +struct file *vfsub_dentry_open(struct path *path, int flags);
33568 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33570 +struct vfsub_aopen_args {
33571 + struct file *file;
33572 + unsigned int open_flag;
33573 + umode_t create_mode;
33574 + struct au_branch *br;
33576 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33577 + struct vfsub_aopen_args *args);
33578 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33580 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33581 + struct dentry *parent, int len);
33582 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
33585 +struct vfsub_lkup_one_args {
33586 + struct dentry **errp;
33587 + struct qstr *name;
33588 + struct dentry *parent;
33591 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33592 + struct dentry *parent)
33594 + return vfsub_lookup_one_len(name->name, parent, name->len);
33597 +void vfsub_call_lkup_one(void *args);
33599 +/* ---------------------------------------------------------------------- */
33601 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33606 + err = mnt_want_write(mnt);
33611 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33614 + mnt_drop_write(mnt);
33618 +#if 0 /* reserved */
33619 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33622 + mnt_drop_write_file(file);
33627 +/* ---------------------------------------------------------------------- */
33630 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33631 + struct dentry *d2, struct au_hinode *hdir2);
33632 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33633 + struct dentry *d2, struct au_hinode *hdir2);
33635 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33637 +int vfsub_symlink(struct inode *dir, struct path *path,
33638 + const char *symname);
33639 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33640 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33641 + struct path *path, struct inode **delegated_inode);
33642 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33643 + struct inode *hdir, struct path *path,
33644 + struct inode **delegated_inode, unsigned int flags);
33645 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33646 +int vfsub_rmdir(struct inode *dir, struct path *path);
33648 +/* ---------------------------------------------------------------------- */
33650 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33652 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33654 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33656 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33658 +int vfsub_flush(struct file *file, fl_owner_t id);
33659 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33661 +static inline loff_t vfsub_f_size_read(struct file *file)
33663 + return i_size_read(file_inode(file));
33666 +static inline unsigned int vfsub_file_flags(struct file *file)
33668 + unsigned int flags;
33670 + spin_lock(&file->f_lock);
33671 + flags = file->f_flags;
33672 + spin_unlock(&file->f_lock);
33677 +static inline int vfsub_file_execed(struct file *file)
33679 + /* todo: direct access f_flags */
33680 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33683 +#if 0 /* reserved */
33684 +static inline void vfsub_file_accessed(struct file *h_file)
33686 + file_accessed(h_file);
33687 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33691 +#if 0 /* reserved */
33692 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33693 + struct dentry *h_dentry)
33695 + struct path h_path = {
33696 + .dentry = h_dentry,
33699 + touch_atime(&h_path);
33700 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33704 +static inline int vfsub_update_time(struct inode *h_inode,
33705 + struct timespec64 *ts, int flags)
33707 + return update_time(h_inode, ts, flags);
33708 + /* no vfsub_update_h_iattr() since we don't have struct path */
33711 +#ifdef CONFIG_FS_POSIX_ACL
33712 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33716 + err = posix_acl_chmod(h_inode, h_mode);
33717 + if (err == -EOPNOTSUPP)
33722 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33725 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33726 + struct pipe_inode_info *pipe, size_t len,
33727 + unsigned int flags);
33728 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33729 + loff_t *ppos, size_t len, unsigned int flags);
33731 +static inline long vfsub_truncate(struct path *path, loff_t length)
33736 + err = vfs_truncate(path, length);
33741 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33742 + struct file *h_file);
33743 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33746 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33749 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33755 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33761 +/* copy_file_range(2) is a systemcall */
33762 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33763 + struct file *dst, loff_t dst_pos,
33764 + size_t len, unsigned int flags)
33769 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33775 +/* ---------------------------------------------------------------------- */
33777 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33782 + err = vfs_llseek(file, offset, origin);
33787 +/* ---------------------------------------------------------------------- */
33789 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33790 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33791 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33792 + struct inode **delegated_inode);
33793 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33794 + struct inode **delegated_inode);
33795 +int vfsub_unlink(struct inode *dir, struct path *path,
33796 + struct inode **delegated_inode, int force);
33798 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33800 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33803 +/* ---------------------------------------------------------------------- */
33805 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33806 + const void *value, size_t size, int flags)
33811 + err = vfs_setxattr(dentry, name, value, size, flags);
33817 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33822 + err = vfs_removexattr(dentry, name);
33828 +#endif /* __KERNEL__ */
33829 +#endif /* __AUFS_VFSUB_H__ */
33830 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33831 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33832 +++ linux/fs/aufs/wbr_policy.c 2021-02-22 22:51:59.061411920 +0100
33834 +// SPDX-License-Identifier: GPL-2.0
33836 + * Copyright (C) 2005-2020 Junjiro R. Okajima
33838 + * This program, aufs is free software; you can redistribute it and/or modify
33839 + * it under the terms of the GNU General Public License as published by
33840 + * the Free Software Foundation; either version 2 of the License, or
33841 + * (at your option) any later version.
33843 + * This program is distributed in the hope that it will be useful,
33844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33846 + * GNU General Public License for more details.
33848 + * You should have received a copy of the GNU General Public License
33849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33853 + * policies for selecting one among multiple writable branches
33856 +#include <linux/statfs.h>
33859 +/* subset of cpup_attr() */
33860 +static noinline_for_stack
33861 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33865 + struct inode *h_isrc;
33867 + h_isrc = d_inode(h_src);
33868 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33869 + ia.ia_mode = h_isrc->i_mode;
33870 + ia.ia_uid = h_isrc->i_uid;
33871 + ia.ia_gid = h_isrc->i_gid;
33872 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33873 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33874 + /* no delegation since it is just created */
33875 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33877 + /* is this nfs only? */
33878 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33879 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33880 + ia.ia_mode = h_isrc->i_mode;
33881 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33887 +#define AuCpdown_PARENT_OPQ 1
33888 +#define AuCpdown_WHED (1 << 1)
33889 +#define AuCpdown_MADE_DIR (1 << 2)
33890 +#define AuCpdown_DIROPQ (1 << 3)
33891 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33892 +#define au_fset_cpdown(flags, name) \
33893 + do { (flags) |= AuCpdown_##name; } while (0)
33894 +#define au_fclr_cpdown(flags, name) \
33895 + do { (flags) &= ~AuCpdown_##name; } while (0)
33897 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33898 + unsigned int *flags)
33901 + struct dentry *opq_dentry;
33903 + opq_dentry = au_diropq_create(dentry, bdst);
33904 + err = PTR_ERR(opq_dentry);
33905 + if (IS_ERR(opq_dentry))
33907 + dput(opq_dentry);
33908 + au_fset_cpdown(*flags, DIROPQ);
33914 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33915 + struct inode *dir, aufs_bindex_t bdst)
33918 + struct path h_path;
33919 + struct au_branch *br;
33921 + br = au_sbr(dentry->d_sb, bdst);
33922 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33923 + err = PTR_ERR(h_path.dentry);
33924 + if (IS_ERR(h_path.dentry))
33928 + if (d_is_positive(h_path.dentry)) {
33929 + h_path.mnt = au_br_mnt(br);
33930 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33933 + dput(h_path.dentry);
33939 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33940 + struct au_pin *pin,
33941 + struct dentry *h_parent, void *arg)
33944 + aufs_bindex_t bopq, btop;
33945 + struct path h_path;
33946 + struct dentry *parent;
33947 + struct inode *h_dir, *h_inode, *inode, *dir;
33948 + unsigned int *flags = arg;
33950 + btop = au_dbtop(dentry);
33951 + /* dentry is di-locked */
33952 + parent = dget_parent(dentry);
33953 + dir = d_inode(parent);
33954 + h_dir = d_inode(h_parent);
33955 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33956 + IMustLock(h_dir);
33958 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33959 + if (unlikely(err < 0))
33961 + h_path.dentry = au_h_dptr(dentry, bdst);
33962 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33963 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
33964 + if (unlikely(err))
33966 + au_fset_cpdown(*flags, MADE_DIR);
33968 + bopq = au_dbdiropq(dentry);
33969 + au_fclr_cpdown(*flags, WHED);
33970 + au_fclr_cpdown(*flags, DIROPQ);
33971 + if (au_dbwh(dentry) == bdst)
33972 + au_fset_cpdown(*flags, WHED);
33973 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33974 + au_fset_cpdown(*flags, PARENT_OPQ);
33975 + h_inode = d_inode(h_path.dentry);
33976 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33977 + if (au_ftest_cpdown(*flags, WHED)) {
33978 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33979 + if (unlikely(err)) {
33980 + inode_unlock(h_inode);
33985 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33986 + inode_unlock(h_inode);
33987 + if (unlikely(err))
33990 + if (au_ftest_cpdown(*flags, WHED)) {
33991 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
33992 + if (unlikely(err))
33996 + inode = d_inode(dentry);
33997 + if (au_ibbot(inode) < bdst)
33998 + au_set_ibbot(inode, bdst);
33999 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34000 + au_hi_flags(inode, /*isdir*/1));
34001 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34002 + goto out; /* success */
34006 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34007 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34008 + rerr = au_diropq_remove(dentry, bdst);
34009 + inode_unlock(h_inode);
34010 + if (unlikely(rerr)) {
34011 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34012 + dentry, bdst, rerr);
34018 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34019 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34020 + if (unlikely(rerr)) {
34021 + AuIOErr("failed removing %pd b%d (%d)\n",
34022 + dentry, bdst, rerr);
34027 + au_set_h_dptr(dentry, bdst, NULL);
34028 + if (au_dbbot(dentry) == bdst)
34029 + au_update_dbbot(dentry);
34035 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34038 + unsigned int flags;
34041 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34046 +/* ---------------------------------------------------------------------- */
34048 +/* policies for create */
34050 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34052 + int err, i, j, ndentry;
34053 + aufs_bindex_t bopq;
34054 + struct au_dcsub_pages dpages;
34055 + struct au_dpage *dpage;
34056 + struct dentry **dentries, *parent, *d;
34058 + err = au_dpages_init(&dpages, GFP_NOFS);
34059 + if (unlikely(err))
34061 + parent = dget_parent(dentry);
34062 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34063 + if (unlikely(err))
34067 + for (i = 0; i < dpages.ndpage; i++) {
34068 + dpage = dpages.dpages + i;
34069 + dentries = dpage->dentries;
34070 + ndentry = dpage->ndentry;
34071 + for (j = 0; j < ndentry; j++) {
34073 + di_read_lock_parent2(d, !AuLock_IR);
34074 + bopq = au_dbdiropq(d);
34075 + di_read_unlock(d, !AuLock_IR);
34076 + if (bopq >= 0 && bopq < err)
34083 + au_dpages_free(&dpages);
34088 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34090 + for (; bindex >= 0; bindex--)
34091 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34096 +/* top down parent */
34097 +static int au_wbr_create_tdp(struct dentry *dentry,
34098 + unsigned int flags __maybe_unused)
34101 + aufs_bindex_t btop, bindex;
34102 + struct super_block *sb;
34103 + struct dentry *parent, *h_parent;
34105 + sb = dentry->d_sb;
34106 + btop = au_dbtop(dentry);
34108 + if (!au_br_rdonly(au_sbr(sb, btop)))
34112 + parent = dget_parent(dentry);
34113 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34114 + h_parent = au_h_dptr(parent, bindex);
34115 + if (!h_parent || d_is_negative(h_parent))
34118 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34125 + /* bottom up here */
34126 + if (unlikely(err < 0)) {
34127 + err = au_wbr_bu(sb, btop - 1);
34129 + err = au_wbr_nonopq(dentry, err);
34133 + AuDbg("b%d\n", err);
34137 +/* ---------------------------------------------------------------------- */
34139 +/* an exception for the policy other than tdp */
34140 +static int au_wbr_create_exp(struct dentry *dentry)
34143 + aufs_bindex_t bwh, bdiropq;
34144 + struct dentry *parent;
34147 + bwh = au_dbwh(dentry);
34148 + parent = dget_parent(dentry);
34149 + bdiropq = au_dbdiropq(parent);
34151 + if (bdiropq >= 0)
34152 + err = min(bdiropq, bwh);
34155 + AuDbg("%d\n", err);
34156 + } else if (bdiropq >= 0) {
34158 + AuDbg("%d\n", err);
34163 + err = au_wbr_nonopq(dentry, err);
34165 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34168 + AuDbg("%d\n", err);
34172 +/* ---------------------------------------------------------------------- */
34175 +static int au_wbr_create_init_rr(struct super_block *sb)
34179 + err = au_wbr_bu(sb, au_sbbot(sb));
34180 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34183 + AuDbg("b%d\n", err);
34187 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34191 + aufs_bindex_t bindex, bbot;
34192 + struct super_block *sb;
34195 + err = au_wbr_create_exp(dentry);
34199 + sb = dentry->d_sb;
34200 + next = &au_sbi(sb)->si_wbr_rr_next;
34201 + bbot = au_sbbot(sb);
34203 + for (bindex = 0; bindex <= bbot; bindex++) {
34204 + if (!au_ftest_wbr(flags, DIR)) {
34205 + err = atomic_dec_return(next) + 1;
34206 + /* modulo for 0 is meaningless */
34207 + if (unlikely(!err))
34208 + err = atomic_dec_return(next) + 1;
34210 + err = atomic_read(next);
34211 + AuDbg("%d\n", err);
34214 + AuDbg("%d\n", err);
34215 + if (!au_br_rdonly(au_sbr(sb, err)))
34221 + err = au_wbr_nonopq(dentry, err);
34224 + AuDbg("%d\n", err);
34228 +/* ---------------------------------------------------------------------- */
34230 +/* most free space */
34231 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34233 + struct super_block *sb;
34234 + struct au_branch *br;
34235 + struct au_wbr_mfs *mfs;
34236 + struct dentry *h_parent;
34237 + aufs_bindex_t bindex, bbot;
34239 + unsigned long long b, bavail;
34240 + struct path h_path;
34241 + /* reduce the stack usage */
34242 + struct kstatfs *st;
34244 + st = kmalloc(sizeof(*st), GFP_NOFS);
34245 + if (unlikely(!st)) {
34246 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34251 + sb = dentry->d_sb;
34252 + mfs = &au_sbi(sb)->si_wbr_mfs;
34253 + MtxMustLock(&mfs->mfs_lock);
34254 + mfs->mfs_bindex = -EROFS;
34255 + mfs->mfsrr_bytes = 0;
34258 + bbot = au_sbbot(sb);
34260 + bindex = au_dbtop(parent);
34261 + bbot = au_dbtaildir(parent);
34264 + for (; bindex <= bbot; bindex++) {
34266 + h_parent = au_h_dptr(parent, bindex);
34267 + if (!h_parent || d_is_negative(h_parent))
34270 + br = au_sbr(sb, bindex);
34271 + if (au_br_rdonly(br))
34274 + /* sb->s_root for NFS is unreliable */
34275 + h_path.mnt = au_br_mnt(br);
34276 + h_path.dentry = h_path.mnt->mnt_root;
34277 + err = vfs_statfs(&h_path, st);
34278 + if (unlikely(err)) {
34279 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34283 + /* when the available size is equal, select the lower one */
34284 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34285 + || sizeof(b) < sizeof(st->f_bsize));
34286 + b = st->f_bavail * st->f_bsize;
34287 + br->br_wbr->wbr_bytes = b;
34288 + if (b >= bavail) {
34290 + mfs->mfs_bindex = bindex;
34291 + mfs->mfs_jiffy = jiffies;
34295 + mfs->mfsrr_bytes = bavail;
34296 + AuDbg("b%d\n", mfs->mfs_bindex);
34297 + au_kfree_rcu(st);
34300 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34303 + struct dentry *parent;
34304 + struct super_block *sb;
34305 + struct au_wbr_mfs *mfs;
34307 + err = au_wbr_create_exp(dentry);
34311 + sb = dentry->d_sb;
34313 + if (au_ftest_wbr(flags, PARENT))
34314 + parent = dget_parent(dentry);
34315 + mfs = &au_sbi(sb)->si_wbr_mfs;
34316 + mutex_lock(&mfs->mfs_lock);
34317 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34318 + || mfs->mfs_bindex < 0
34319 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34320 + au_mfs(dentry, parent);
34321 + mutex_unlock(&mfs->mfs_lock);
34322 + err = mfs->mfs_bindex;
34326 + err = au_wbr_nonopq(dentry, err);
34329 + AuDbg("b%d\n", err);
34333 +static int au_wbr_create_init_mfs(struct super_block *sb)
34335 + struct au_wbr_mfs *mfs;
34337 + mfs = &au_sbi(sb)->si_wbr_mfs;
34338 + mutex_init(&mfs->mfs_lock);
34339 + mfs->mfs_jiffy = 0;
34340 + mfs->mfs_bindex = -EROFS;
34345 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34347 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34351 +/* ---------------------------------------------------------------------- */
34353 +/* top down regardless parent, and then mfs */
34354 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34355 + unsigned int flags __maybe_unused)
34358 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34359 + unsigned long long watermark;
34360 + struct super_block *sb;
34361 + struct au_wbr_mfs *mfs;
34362 + struct au_branch *br;
34363 + struct dentry *parent;
34365 + sb = dentry->d_sb;
34366 + mfs = &au_sbi(sb)->si_wbr_mfs;
34367 + mutex_lock(&mfs->mfs_lock);
34368 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34369 + || mfs->mfs_bindex < 0)
34370 + au_mfs(dentry, /*parent*/NULL);
34371 + watermark = mfs->mfsrr_watermark;
34372 + bmfs = mfs->mfs_bindex;
34373 + mutex_unlock(&mfs->mfs_lock);
34375 + /* another style of au_wbr_create_exp() */
34376 + bwh = au_dbwh(dentry);
34377 + parent = dget_parent(dentry);
34378 + btail = au_dbtaildir(parent);
34379 + if (bwh >= 0 && bwh < btail)
34382 + err = au_wbr_nonopq(dentry, btail);
34383 + if (unlikely(err < 0))
34387 + for (bindex = 0; bindex <= btail; bindex++) {
34388 + br = au_sbr(sb, bindex);
34389 + if (au_br_rdonly(br))
34391 + if (br->br_wbr->wbr_bytes > watermark) {
34402 + AuDbg("b%d\n", err);
34406 +/* ---------------------------------------------------------------------- */
34408 +/* most free space and then round robin */
34409 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34412 + struct au_wbr_mfs *mfs;
34414 + err = au_wbr_create_mfs(dentry, flags);
34416 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34417 + mutex_lock(&mfs->mfs_lock);
34418 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34419 + err = au_wbr_create_rr(dentry, flags);
34420 + mutex_unlock(&mfs->mfs_lock);
34423 + AuDbg("b%d\n", err);
34427 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34431 + au_wbr_create_init_mfs(sb); /* ignore */
34432 + err = au_wbr_create_init_rr(sb);
34437 +/* ---------------------------------------------------------------------- */
34439 +/* top down parent and most free space */
34440 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34443 + unsigned long long b;
34444 + aufs_bindex_t bindex, btop, bbot;
34445 + struct super_block *sb;
34446 + struct dentry *parent, *h_parent;
34447 + struct au_branch *br;
34449 + err = au_wbr_create_tdp(dentry, flags);
34450 + if (unlikely(err < 0))
34452 + parent = dget_parent(dentry);
34453 + btop = au_dbtop(parent);
34454 + bbot = au_dbtaildir(parent);
34455 + if (btop == bbot)
34456 + goto out_parent; /* success */
34458 + e2 = au_wbr_create_mfs(dentry, flags);
34460 + goto out_parent; /* success */
34462 + /* when the available size is equal, select upper one */
34463 + sb = dentry->d_sb;
34464 + br = au_sbr(sb, err);
34465 + b = br->br_wbr->wbr_bytes;
34466 + AuDbg("b%d, %llu\n", err, b);
34468 + for (bindex = btop; bindex <= bbot; bindex++) {
34469 + h_parent = au_h_dptr(parent, bindex);
34470 + if (!h_parent || d_is_negative(h_parent))
34473 + br = au_sbr(sb, bindex);
34474 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34475 + b = br->br_wbr->wbr_bytes;
34477 + AuDbg("b%d, %llu\n", err, b);
34482 + err = au_wbr_nonopq(dentry, err);
34487 + AuDbg("b%d\n", err);
34491 +/* ---------------------------------------------------------------------- */
34494 + * - top down parent
34495 + * - most free space with parent
34496 + * - most free space round-robin regardless parent
34498 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34501 + unsigned long long watermark;
34502 + struct super_block *sb;
34503 + struct au_branch *br;
34504 + struct au_wbr_mfs *mfs;
34506 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34507 + if (unlikely(err < 0))
34510 + sb = dentry->d_sb;
34511 + br = au_sbr(sb, err);
34512 + mfs = &au_sbi(sb)->si_wbr_mfs;
34513 + mutex_lock(&mfs->mfs_lock);
34514 + watermark = mfs->mfsrr_watermark;
34515 + mutex_unlock(&mfs->mfs_lock);
34516 + if (br->br_wbr->wbr_bytes < watermark)
34517 + /* regardless the parent dir */
34518 + err = au_wbr_create_mfsrr(dentry, flags);
34521 + AuDbg("b%d\n", err);
34525 +/* ---------------------------------------------------------------------- */
34527 +/* policies for copyup */
34529 +/* top down parent */
34530 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34532 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34535 +/* bottom up parent */
34536 +static int au_wbr_copyup_bup(struct dentry *dentry)
34539 + aufs_bindex_t bindex, btop;
34540 + struct dentry *parent, *h_parent;
34541 + struct super_block *sb;
34544 + sb = dentry->d_sb;
34545 + parent = dget_parent(dentry);
34546 + btop = au_dbtop(parent);
34547 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34548 + h_parent = au_h_dptr(parent, bindex);
34549 + if (!h_parent || d_is_negative(h_parent))
34552 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34559 + /* bottom up here */
34560 + if (unlikely(err < 0))
34561 + err = au_wbr_bu(sb, btop - 1);
34563 + AuDbg("b%d\n", err);
34568 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34572 + err = au_wbr_bu(dentry->d_sb, btop);
34573 + AuDbg("b%d\n", err);
34575 + err = au_wbr_nonopq(dentry, err);
34577 + AuDbg("b%d\n", err);
34581 +static int au_wbr_copyup_bu(struct dentry *dentry)
34584 + aufs_bindex_t btop;
34586 + btop = au_dbtop(dentry);
34587 + err = au_wbr_do_copyup_bu(dentry, btop);
34591 +/* ---------------------------------------------------------------------- */
34593 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34594 + [AuWbrCopyup_TDP] = {
34595 + .copyup = au_wbr_copyup_tdp
34597 + [AuWbrCopyup_BUP] = {
34598 + .copyup = au_wbr_copyup_bup
34600 + [AuWbrCopyup_BU] = {
34601 + .copyup = au_wbr_copyup_bu
34605 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34606 + [AuWbrCreate_TDP] = {
34607 + .create = au_wbr_create_tdp
34609 + [AuWbrCreate_RR] = {
34610 + .create = au_wbr_create_rr,
34611 + .init = au_wbr_create_init_rr
34613 + [AuWbrCreate_MFS] = {
34614 + .create = au_wbr_create_mfs,
34615 + .init = au_wbr_create_init_mfs,
34616 + .fin = au_wbr_create_fin_mfs
34618 + [AuWbrCreate_MFSV] = {
34619 + .create = au_wbr_create_mfs,
34620 + .init = au_wbr_create_init_mfs,
34621 + .fin = au_wbr_create_fin_mfs
34623 + [AuWbrCreate_MFSRR] = {
34624 + .create = au_wbr_create_mfsrr,
34625 + .init = au_wbr_create_init_mfsrr,
34626 + .fin = au_wbr_create_fin_mfs
34628 + [AuWbrCreate_MFSRRV] = {
34629 + .create = au_wbr_create_mfsrr,
34630 + .init = au_wbr_create_init_mfsrr,
34631 + .fin = au_wbr_create_fin_mfs
34633 + [AuWbrCreate_TDMFS] = {
34634 + .create = au_wbr_create_tdmfs,
34635 + .init = au_wbr_create_init_mfs,
34636 + .fin = au_wbr_create_fin_mfs
34638 + [AuWbrCreate_TDMFSV] = {
34639 + .create = au_wbr_create_tdmfs,
34640 + .init = au_wbr_create_init_mfs,
34641 + .fin = au_wbr_create_fin_mfs
34643 + [AuWbrCreate_PMFS] = {
34644 + .create = au_wbr_create_pmfs,
34645 + .init = au_wbr_create_init_mfs,
34646 + .fin = au_wbr_create_fin_mfs
34648 + [AuWbrCreate_PMFSV] = {
34649 + .create = au_wbr_create_pmfs,
34650 + .init = au_wbr_create_init_mfs,
34651 + .fin = au_wbr_create_fin_mfs
34653 + [AuWbrCreate_PMFSRR] = {
34654 + .create = au_wbr_create_pmfsrr,
34655 + .init = au_wbr_create_init_mfsrr,
34656 + .fin = au_wbr_create_fin_mfs
34658 + [AuWbrCreate_PMFSRRV] = {
34659 + .create = au_wbr_create_pmfsrr,
34660 + .init = au_wbr_create_init_mfsrr,
34661 + .fin = au_wbr_create_fin_mfs
34664 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34665 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34666 +++ linux/fs/aufs/whout.c 2021-02-22 22:51:59.061411920 +0100
34668 +// SPDX-License-Identifier: GPL-2.0
34670 + * Copyright (C) 2005-2020 Junjiro R. Okajima
34672 + * This program, aufs is free software; you can redistribute it and/or modify
34673 + * it under the terms of the GNU General Public License as published by
34674 + * the Free Software Foundation; either version 2 of the License, or
34675 + * (at your option) any later version.
34677 + * This program is distributed in the hope that it will be useful,
34678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34680 + * GNU General Public License for more details.
34682 + * You should have received a copy of the GNU General Public License
34683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34687 + * whiteout for logical deletion and opaque directory
34692 +#define WH_MASK 0444
34695 + * If a directory contains this file, then it is opaque. We start with the
34696 + * .wh. flag so that it is blocked by lookup.
34698 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34699 + sizeof(AUFS_WH_DIROPQ) - 1);
34702 + * generate whiteout name, which is NOT terminated by NULL.
34703 + * @name: original d_name.name
34704 + * @len: original d_name.len
34705 + * @wh: whiteout qstr
34706 + * returns zero when succeeds, otherwise error.
34707 + * succeeded value as wh->name should be freed by kfree().
34709 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34713 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34714 + return -ENAMETOOLONG;
34716 + wh->len = name->len + AUFS_WH_PFX_LEN;
34717 + p = kmalloc(wh->len, GFP_NOFS);
34720 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34721 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34728 +/* ---------------------------------------------------------------------- */
34731 + * test if the @wh_name exists under @h_parent.
34732 + * @try_sio specifies the necessary of super-io.
34734 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
34737 + struct dentry *wh_dentry;
34740 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
34742 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
34743 + err = PTR_ERR(wh_dentry);
34744 + if (IS_ERR(wh_dentry)) {
34745 + if (err == -ENAMETOOLONG)
34751 + if (d_is_negative(wh_dentry))
34752 + goto out_wh; /* success */
34755 + if (d_is_reg(wh_dentry))
34756 + goto out_wh; /* success */
34759 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34760 + wh_dentry, d_inode(wh_dentry)->i_mode);
34769 + * test if the @h_dentry sets opaque or not.
34771 +int au_diropq_test(struct dentry *h_dentry)
34774 + struct inode *h_dir;
34776 + h_dir = d_inode(h_dentry);
34777 + err = au_wh_test(h_dentry, &diropq_name,
34778 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34783 + * returns a negative dentry whose name is unique and temporary.
34785 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34786 + struct qstr *prefix)
34788 + struct dentry *dentry;
34790 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34792 + /* strict atomic_t is unnecessary here */
34793 + static unsigned short cnt;
34796 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34799 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34800 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34801 + dentry = ERR_PTR(-ENAMETOOLONG);
34802 + if (unlikely(qs.len > NAME_MAX))
34804 + dentry = ERR_PTR(-ENOMEM);
34805 + name = kmalloc(qs.len + 1, GFP_NOFS);
34806 + if (unlikely(!name))
34810 + /* doubly whiteout-ed */
34811 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34812 + p = name + AUFS_WH_PFX_LEN * 2;
34813 + memcpy(p, prefix->name, prefix->len);
34814 + p += prefix->len;
34816 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34819 + for (i = 0; i < 3; i++) {
34820 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34821 + dentry = au_sio_lkup_one(&qs, h_parent);
34822 + if (IS_ERR(dentry) || d_is_negative(dentry))
34826 + /* pr_warn("could not get random name\n"); */
34827 + dentry = ERR_PTR(-EEXIST);
34828 + AuDbg("%.*s\n", AuLNPair(&qs));
34832 + if (name != defname)
34833 + au_kfree_try_rcu(name);
34835 + AuTraceErrPtr(dentry);
34840 + * rename the @h_dentry on @br to the whiteouted temporary name.
34842 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34845 + struct path h_path = {
34846 + .mnt = au_br_mnt(br)
34848 + struct inode *h_dir, *delegated;
34849 + struct dentry *h_parent;
34851 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34852 + h_dir = d_inode(h_parent);
34853 + IMustLock(h_dir);
34855 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34856 + err = PTR_ERR(h_path.dentry);
34857 + if (IS_ERR(h_path.dentry))
34860 + /* under the same dir, no need to lock_rename() */
34861 + delegated = NULL;
34862 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34865 + if (unlikely(err == -EWOULDBLOCK)) {
34866 + pr_warn("cannot retry for NFSv4 delegation"
34867 + " for an internal rename\n");
34870 + dput(h_path.dentry);
34877 +/* ---------------------------------------------------------------------- */
34879 + * functions for removing a whiteout
34882 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34885 + struct inode *delegated;
34888 + * forces superio when the dir has a sticky bit.
34889 + * this may be a violation of unix fs semantics.
34891 + force = (h_dir->i_mode & S_ISVTX)
34892 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34893 + delegated = NULL;
34894 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34895 + if (unlikely(err == -EWOULDBLOCK)) {
34896 + pr_warn("cannot retry for NFSv4 delegation"
34897 + " for an internal unlink\n");
34903 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34904 + struct dentry *dentry)
34908 + err = do_unlink_wh(h_dir, h_path);
34909 + if (!err && dentry)
34910 + au_set_dbwh(dentry, -1);
34915 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
34916 + struct au_branch *br)
34919 + struct path h_path = {
34920 + .mnt = au_br_mnt(br)
34924 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
34925 + if (IS_ERR(h_path.dentry))
34926 + err = PTR_ERR(h_path.dentry);
34928 + if (d_is_reg(h_path.dentry))
34929 + err = do_unlink_wh(d_inode(h_parent), &h_path);
34930 + dput(h_path.dentry);
34936 +/* ---------------------------------------------------------------------- */
34938 + * initialize/clean whiteout for a branch
34941 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34945 + struct inode *delegated;
34947 + if (d_is_negative(whpath->dentry))
34951 + err = vfsub_rmdir(h_dir, whpath);
34953 + delegated = NULL;
34954 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34955 + if (unlikely(err == -EWOULDBLOCK)) {
34956 + pr_warn("cannot retry for NFSv4 delegation"
34957 + " for an internal unlink\n");
34961 + if (unlikely(err))
34962 + pr_warn("failed removing %pd (%d), ignored.\n",
34963 + whpath->dentry, err);
34966 +static int test_linkable(struct dentry *h_root)
34968 + struct inode *h_dir = d_inode(h_root);
34970 + if (h_dir->i_op->link)
34973 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34974 + h_root, au_sbtype(h_root->d_sb));
34975 + return -ENOSYS; /* the branch doesn't have its ->link() */
34978 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34979 +static int au_whdir(struct inode *h_dir, struct path *path)
34984 + if (d_is_negative(path->dentry)) {
34987 + if (au_test_nfs(path->dentry->d_sb))
34989 + err = vfsub_mkdir(h_dir, path, mode);
34990 + } else if (d_is_dir(path->dentry))
34993 + pr_err("unknown %pd exists\n", path->dentry);
34998 +struct au_wh_base {
34999 + const struct qstr *name;
35000 + struct dentry *dentry;
35003 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35004 + struct path *h_path)
35006 + h_path->dentry = base[AuBrWh_BASE].dentry;
35007 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35008 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35009 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35010 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35011 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35015 + * returns tri-state,
35016 + * minus: error, caller should print the message
35018 + * plus: error, caller should NOT print the message
35020 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35021 + int do_plink, struct au_wh_base base[],
35022 + struct path *h_path)
35025 + struct inode *h_dir;
35027 + h_dir = d_inode(h_root);
35028 + h_path->dentry = base[AuBrWh_BASE].dentry;
35029 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35030 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35032 + err = test_linkable(h_root);
35033 + if (unlikely(err)) {
35038 + err = au_whdir(h_dir, h_path);
35039 + if (unlikely(err))
35041 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35043 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35044 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35045 + err = au_whdir(h_dir, h_path);
35046 + if (unlikely(err))
35048 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35055 + * for the moment, aufs supports the branch filesystem which does not support
35056 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35057 + * copyup failed. finally, such filesystem will not be used as the writable
35060 + * returns tri-state, see above.
35062 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35063 + int do_plink, struct au_wh_base base[],
35064 + struct path *h_path)
35067 + struct inode *h_dir;
35069 + WbrWhMustWriteLock(wbr);
35071 + err = test_linkable(h_root);
35072 + if (unlikely(err)) {
35078 + * todo: should this create be done in /sbin/mount.aufs helper?
35081 + h_dir = d_inode(h_root);
35082 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35083 + h_path->dentry = base[AuBrWh_BASE].dentry;
35084 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35085 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35088 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35089 + if (unlikely(err))
35092 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35094 + err = au_whdir(h_dir, h_path);
35095 + if (unlikely(err))
35097 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35099 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35100 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35102 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35103 + err = au_whdir(h_dir, h_path);
35104 + if (unlikely(err))
35106 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35113 + * initialize the whiteout base file/dir for @br.
35115 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35118 + const unsigned char do_plink
35119 + = !!au_opt_test(au_mntflags(sb), PLINK);
35120 + struct inode *h_dir;
35121 + struct path path = br->br_path;
35122 + struct dentry *h_root = path.dentry;
35123 + struct au_wbr *wbr = br->br_wbr;
35124 + static const struct qstr base_name[] = {
35125 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35126 + sizeof(AUFS_BASE_NAME) - 1),
35127 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35128 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35129 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35130 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35132 + struct au_wh_base base[] = {
35133 + [AuBrWh_BASE] = {
35134 + .name = base_name + AuBrWh_BASE,
35137 + [AuBrWh_PLINK] = {
35138 + .name = base_name + AuBrWh_PLINK,
35141 + [AuBrWh_ORPH] = {
35142 + .name = base_name + AuBrWh_ORPH,
35148 + WbrWhMustWriteLock(wbr);
35150 + for (i = 0; i < AuBrWh_Last; i++) {
35151 + /* doubly whiteouted */
35152 + struct dentry *d;
35154 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35155 + err = PTR_ERR(d);
35159 + base[i].dentry = d;
35161 + && wbr->wbr_wh[i]
35162 + && wbr->wbr_wh[i] != base[i].dentry);
35166 + for (i = 0; i < AuBrWh_Last; i++) {
35167 + dput(wbr->wbr_wh[i]);
35168 + wbr->wbr_wh[i] = NULL;
35172 + if (!au_br_writable(br->br_perm)) {
35173 + h_dir = d_inode(h_root);
35174 + au_wh_init_ro(h_dir, base, &path);
35175 + } else if (!au_br_wh_linkable(br->br_perm)) {
35176 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35182 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35188 + goto out; /* success */
35191 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35192 + err, h_root, au_sbtype(h_root->d_sb));
35194 + for (i = 0; i < AuBrWh_Last; i++)
35195 + dput(base[i].dentry);
35199 +/* ---------------------------------------------------------------------- */
35201 + * whiteouts are all hard-linked usually.
35202 + * when its link count reaches a ceiling, we create a new whiteout base
35203 + * asynchronously.
35206 +struct reinit_br_wh {
35207 + struct super_block *sb;
35208 + struct au_branch *br;
35211 +static void reinit_br_wh(void *arg)
35214 + aufs_bindex_t bindex;
35215 + struct path h_path;
35216 + struct reinit_br_wh *a = arg;
35217 + struct au_wbr *wbr;
35218 + struct inode *dir, *delegated;
35219 + struct dentry *h_root;
35220 + struct au_hinode *hdir;
35223 + wbr = a->br->br_wbr;
35224 + /* big aufs lock */
35225 + si_noflush_write_lock(a->sb);
35226 + if (!au_br_writable(a->br->br_perm))
35228 + bindex = au_br_index(a->sb, a->br->br_id);
35229 + if (unlikely(bindex < 0))
35232 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35233 + dir = d_inode(a->sb->s_root);
35234 + hdir = au_hi(dir, bindex);
35235 + h_root = au_h_dptr(a->sb->s_root, bindex);
35236 + AuDebugOn(h_root != au_br_dentry(a->br));
35238 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35239 + wbr_wh_write_lock(wbr);
35240 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35243 + h_path.dentry = wbr->wbr_whbase;
35244 + h_path.mnt = au_br_mnt(a->br);
35245 + delegated = NULL;
35246 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35248 + if (unlikely(err == -EWOULDBLOCK)) {
35249 + pr_warn("cannot retry for NFSv4 delegation"
35250 + " for an internal unlink\n");
35254 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35257 + dput(wbr->wbr_whbase);
35258 + wbr->wbr_whbase = NULL;
35260 + err = au_wh_init(a->br, a->sb);
35261 + wbr_wh_write_unlock(wbr);
35262 + au_hn_inode_unlock(hdir);
35263 + di_read_unlock(a->sb->s_root, AuLock_IR);
35265 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35269 + atomic_dec(&wbr->wbr_wh_running);
35270 + au_lcnt_dec(&a->br->br_count);
35271 + si_write_unlock(a->sb);
35272 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35274 + if (unlikely(err))
35275 + AuIOErr("err %d\n", err);
35278 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35280 + int do_dec, wkq_err;
35281 + struct reinit_br_wh *arg;
35284 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35287 + /* ignore ENOMEM */
35288 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35291 + * dec(wh_running), kfree(arg) and dec(br_count)
35292 + * in reinit function
35296 + au_lcnt_inc(&br->br_count);
35297 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35298 + if (unlikely(wkq_err)) {
35299 + atomic_dec(&br->br_wbr->wbr_wh_running);
35300 + au_lcnt_dec(&br->br_count);
35301 + au_kfree_rcu(arg);
35308 + atomic_dec(&br->br_wbr->wbr_wh_running);
35311 +/* ---------------------------------------------------------------------- */
35314 + * create the whiteout @wh.
35316 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35317 + struct dentry *wh)
35320 + struct path h_path = {
35323 + struct au_branch *br;
35324 + struct au_wbr *wbr;
35325 + struct dentry *h_parent;
35326 + struct inode *h_dir, *delegated;
35328 + h_parent = wh->d_parent; /* dir inode is locked */
35329 + h_dir = d_inode(h_parent);
35330 + IMustLock(h_dir);
35332 + br = au_sbr(sb, bindex);
35333 + h_path.mnt = au_br_mnt(br);
35334 + wbr = br->br_wbr;
35335 + wbr_wh_read_lock(wbr);
35336 + if (wbr->wbr_whbase) {
35337 + delegated = NULL;
35338 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35339 + if (unlikely(err == -EWOULDBLOCK)) {
35340 + pr_warn("cannot retry for NFSv4 delegation"
35341 + " for an internal link\n");
35344 + if (!err || err != -EMLINK)
35347 + /* link count full. re-initialize br_whbase. */
35348 + kick_reinit_br_wh(sb, br);
35351 + /* return this error in this context */
35352 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35354 + au_fhsm_wrote(sb, bindex, /*force*/0);
35357 + wbr_wh_read_unlock(wbr);
35361 +/* ---------------------------------------------------------------------- */
35364 + * create or remove the diropq.
35366 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35367 + unsigned int flags)
35369 + struct dentry *opq_dentry, *h_dentry;
35370 + struct super_block *sb;
35371 + struct au_branch *br;
35374 + sb = dentry->d_sb;
35375 + br = au_sbr(sb, bindex);
35376 + h_dentry = au_h_dptr(dentry, bindex);
35377 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
35378 + if (IS_ERR(opq_dentry))
35381 + if (au_ftest_diropq(flags, CREATE)) {
35382 + err = link_or_create_wh(sb, bindex, opq_dentry);
35384 + au_set_dbdiropq(dentry, bindex);
35385 + goto out; /* success */
35388 + struct path tmp = {
35389 + .dentry = opq_dentry,
35390 + .mnt = au_br_mnt(br)
35392 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
35394 + au_set_dbdiropq(dentry, -1);
35396 + dput(opq_dentry);
35397 + opq_dentry = ERR_PTR(err);
35400 + return opq_dentry;
35403 +struct do_diropq_args {
35404 + struct dentry **errp;
35405 + struct dentry *dentry;
35406 + aufs_bindex_t bindex;
35407 + unsigned int flags;
35410 +static void call_do_diropq(void *args)
35412 + struct do_diropq_args *a = args;
35413 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35416 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35417 + unsigned int flags)
35419 + struct dentry *diropq, *h_dentry;
35421 + h_dentry = au_h_dptr(dentry, bindex);
35422 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35423 + diropq = do_diropq(dentry, bindex, flags);
35426 + struct do_diropq_args args = {
35428 + .dentry = dentry,
35429 + .bindex = bindex,
35433 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35434 + if (unlikely(wkq_err))
35435 + diropq = ERR_PTR(wkq_err);
35441 +/* ---------------------------------------------------------------------- */
35444 + * lookup whiteout dentry.
35445 + * @h_parent: lower parent dentry which must exist and be locked
35446 + * @base_name: name of dentry which will be whiteouted
35447 + * returns dentry for whiteout.
35449 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35450 + struct au_branch *br)
35453 + struct qstr wh_name;
35454 + struct dentry *wh_dentry;
35456 + err = au_wh_name_alloc(&wh_name, base_name);
35457 + wh_dentry = ERR_PTR(err);
35459 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
35460 + au_kfree_try_rcu(wh_name.name);
35462 + return wh_dentry;
35466 + * link/create a whiteout for @dentry on @bindex.
35468 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35469 + struct dentry *h_parent)
35471 + struct dentry *wh_dentry;
35472 + struct super_block *sb;
35475 + sb = dentry->d_sb;
35476 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35477 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35478 + err = link_or_create_wh(sb, bindex, wh_dentry);
35480 + au_set_dbwh(dentry, bindex);
35481 + au_fhsm_wrote(sb, bindex, /*force*/0);
35484 + wh_dentry = ERR_PTR(err);
35488 + return wh_dentry;
35491 +/* ---------------------------------------------------------------------- */
35493 +/* Delete all whiteouts in this directory on branch bindex. */
35494 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
35495 + aufs_bindex_t bindex, struct au_branch *br)
35498 + unsigned long ul, n;
35499 + struct qstr wh_name;
35501 + struct hlist_head *head;
35502 + struct au_vdir_wh *pos;
35503 + struct au_vdir_destr *str;
35506 + p = (void *)__get_free_page(GFP_NOFS);
35507 + wh_name.name = p;
35508 + if (unlikely(!wh_name.name))
35512 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35513 + p += AUFS_WH_PFX_LEN;
35514 + n = whlist->nh_num;
35515 + head = whlist->nh_head;
35516 + for (ul = 0; !err && ul < n; ul++, head++) {
35517 + hlist_for_each_entry(pos, head, wh_hash) {
35518 + if (pos->wh_bindex != bindex)
35521 + str = &pos->wh_str;
35522 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35523 + memcpy(p, str->name, str->len);
35524 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35525 + err = unlink_wh_name(h_dentry, &wh_name, br);
35530 + AuIOErr("whiteout name too long %.*s\n",
35531 + str->len, str->name);
35536 + free_page((unsigned long)wh_name.name);
35542 +struct del_wh_children_args {
35544 + struct dentry *h_dentry;
35545 + struct au_nhash *whlist;
35546 + aufs_bindex_t bindex;
35547 + struct au_branch *br;
35550 +static void call_del_wh_children(void *args)
35552 + struct del_wh_children_args *a = args;
35553 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
35556 +/* ---------------------------------------------------------------------- */
35558 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35560 + struct au_whtmp_rmdir *whtmp;
35562 + unsigned int rdhash;
35564 + SiMustAnyLock(sb);
35566 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35567 + if (unlikely(!whtmp)) {
35568 + whtmp = ERR_PTR(-ENOMEM);
35572 + /* no estimation for dir size */
35573 + rdhash = au_sbi(sb)->si_rdhash;
35575 + rdhash = AUFS_RDHASH_DEF;
35576 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35577 + if (unlikely(err)) {
35578 + au_kfree_rcu(whtmp);
35579 + whtmp = ERR_PTR(err);
35586 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35589 + au_lcnt_dec(&whtmp->br->br_count);
35590 + dput(whtmp->wh_dentry);
35591 + iput(whtmp->dir);
35592 + au_nhash_wh_free(&whtmp->whlist);
35593 + au_kfree_rcu(whtmp);
35597 + * rmdir the whiteouted temporary named dir @h_dentry.
35598 + * @whlist: whiteouted children.
35600 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35601 + struct dentry *wh_dentry, struct au_nhash *whlist)
35604 + unsigned int h_nlink;
35605 + struct path h_tmp;
35606 + struct inode *wh_inode, *h_dir;
35607 + struct au_branch *br;
35609 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35610 + IMustLock(h_dir);
35612 + br = au_sbr(dir->i_sb, bindex);
35613 + wh_inode = d_inode(wh_dentry);
35614 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35617 + * someone else might change some whiteouts while we were sleeping.
35618 + * it means this whlist may have an obsoleted entry.
35620 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35621 + err = del_wh_children(wh_dentry, whlist, bindex, br);
35624 + struct del_wh_children_args args = {
35626 + .h_dentry = wh_dentry,
35627 + .whlist = whlist,
35628 + .bindex = bindex,
35632 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35633 + if (unlikely(wkq_err))
35636 + inode_unlock(wh_inode);
35639 + h_tmp.dentry = wh_dentry;
35640 + h_tmp.mnt = au_br_mnt(br);
35641 + h_nlink = h_dir->i_nlink;
35642 + err = vfsub_rmdir(h_dir, &h_tmp);
35643 + /* some fs doesn't change the parent nlink in some cases */
35644 + h_nlink -= h_dir->i_nlink;
35648 + if (au_ibtop(dir) == bindex) {
35649 + /* todo: dir->i_mutex is necessary */
35650 + au_cpup_attr_timesizes(dir);
35652 + vfsub_drop_nlink(dir);
35654 + return 0; /* success */
35657 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35661 +static void call_rmdir_whtmp(void *args)
35664 + aufs_bindex_t bindex;
35665 + struct au_whtmp_rmdir *a = args;
35666 + struct super_block *sb;
35667 + struct dentry *h_parent;
35668 + struct inode *h_dir;
35669 + struct au_hinode *hdir;
35671 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35672 + /* inode_lock(a->dir); */
35674 + sb = a->dir->i_sb;
35675 + si_read_lock(sb, !AuLock_FLUSH);
35676 + if (!au_br_writable(a->br->br_perm))
35678 + bindex = au_br_index(sb, a->br->br_id);
35679 + if (unlikely(bindex < 0))
35683 + ii_write_lock_parent(a->dir);
35684 + h_parent = dget_parent(a->wh_dentry);
35685 + h_dir = d_inode(h_parent);
35686 + hdir = au_hi(a->dir, bindex);
35687 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35688 + if (unlikely(err))
35690 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35691 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35694 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35695 + au_hn_inode_unlock(hdir);
35696 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35700 + ii_write_unlock(a->dir);
35702 + /* inode_unlock(a->dir); */
35703 + au_whtmp_rmdir_free(a);
35704 + si_read_unlock(sb);
35705 + au_nwt_done(&au_sbi(sb)->si_nowait);
35706 + if (unlikely(err))
35707 + AuIOErr("err %d\n", err);
35710 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35711 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35714 + struct super_block *sb;
35718 + /* all post-process will be done in do_rmdir_whtmp(). */
35720 + args->dir = au_igrab(dir);
35721 + args->br = au_sbr(sb, bindex);
35722 + au_lcnt_inc(&args->br->br_count);
35723 + args->wh_dentry = dget(wh_dentry);
35724 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35725 + if (unlikely(wkq_err)) {
35726 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35727 + au_whtmp_rmdir_free(args);
35730 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35731 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35732 +++ linux/fs/aufs/whout.h 2021-02-22 22:51:59.061411920 +0100
35734 +/* SPDX-License-Identifier: GPL-2.0 */
35736 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35738 + * This program, aufs is free software; you can redistribute it and/or modify
35739 + * it under the terms of the GNU General Public License as published by
35740 + * the Free Software Foundation; either version 2 of the License, or
35741 + * (at your option) any later version.
35743 + * This program is distributed in the hope that it will be useful,
35744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35746 + * GNU General Public License for more details.
35748 + * You should have received a copy of the GNU General Public License
35749 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35753 + * whiteout for logical deletion and opaque directory
35756 +#ifndef __AUFS_WHOUT_H__
35757 +#define __AUFS_WHOUT_H__
35764 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35765 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
35766 +int au_diropq_test(struct dentry *h_dentry);
35768 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35769 + struct qstr *prefix);
35770 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35771 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35772 + struct dentry *dentry);
35773 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35775 +/* diropq flags */
35776 +#define AuDiropq_CREATE 1
35777 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35778 +#define au_fset_diropq(flags, name) \
35779 + do { (flags) |= AuDiropq_##name; } while (0)
35780 +#define au_fclr_diropq(flags, name) \
35781 + do { (flags) &= ~AuDiropq_##name; } while (0)
35783 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35784 + unsigned int flags);
35785 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35786 + struct au_branch *br);
35787 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35788 + struct dentry *h_parent);
35790 +/* real rmdir for the whiteout-ed dir */
35791 +struct au_whtmp_rmdir {
35792 + struct inode *dir;
35793 + struct au_branch *br;
35794 + struct dentry *wh_dentry;
35795 + struct au_nhash whlist;
35798 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35799 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35800 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35801 + struct dentry *wh_dentry, struct au_nhash *whlist);
35802 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35803 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35805 +/* ---------------------------------------------------------------------- */
35807 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35808 + aufs_bindex_t bindex)
35810 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35813 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35815 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35818 +#endif /* __KERNEL__ */
35819 +#endif /* __AUFS_WHOUT_H__ */
35820 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35821 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35822 +++ linux/fs/aufs/wkq.c 2021-02-22 22:51:59.061411920 +0100
35824 +// SPDX-License-Identifier: GPL-2.0
35826 + * Copyright (C) 2005-2020 Junjiro R. Okajima
35828 + * This program, aufs is free software; you can redistribute it and/or modify
35829 + * it under the terms of the GNU General Public License as published by
35830 + * the Free Software Foundation; either version 2 of the License, or
35831 + * (at your option) any later version.
35833 + * This program is distributed in the hope that it will be useful,
35834 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35835 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35836 + * GNU General Public License for more details.
35838 + * You should have received a copy of the GNU General Public License
35839 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35843 + * workqueue for asynchronous/super-io operations
35844 + * todo: try new credential scheme
35847 +#include <linux/module.h>
35850 +/* internal workqueue named AUFS_WKQ_NAME */
35852 +static struct workqueue_struct *au_wkq;
35854 +struct au_wkinfo {
35855 + struct work_struct wk;
35856 + struct kobject *kobj;
35858 + unsigned int flags; /* see wkq.h */
35860 + au_wkq_func_t func;
35863 +#ifdef CONFIG_LOCKDEP
35865 + struct held_lock **hlock;
35868 + struct completion *comp;
35871 +/* ---------------------------------------------------------------------- */
35873 + * Aufs passes some operations to the workqueue such as the internal copyup.
35874 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35875 + * job run by workqueue depends upon the locks acquired in the other task.
35876 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35877 + * information too. And the job in the workqueue restores the info in order to
35878 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35879 + * correctly and expectedly.
35882 +#ifndef CONFIG_LOCKDEP
35883 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35884 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35885 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35886 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35887 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35889 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35891 + wkinfo->hlock = NULL;
35892 + wkinfo->dont_check = 0;
35899 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35901 + static DEFINE_SPINLOCK(spin);
35904 + struct lock_class_key *key;
35906 + { .name = "&sbinfo->si_rwsem" },
35907 + { .name = "&finfo->fi_rwsem" },
35908 + { .name = "&dinfo->di_rwsem" },
35909 + { .name = "&iinfo->ii_rwsem" }
35914 + /* lockless read from 'set.' see below */
35915 + if (set == ARRAY_SIZE(a)) {
35916 + for (i = 0; i < ARRAY_SIZE(a); i++)
35917 + if (a[i].key == key)
35922 + spin_lock(&spin);
35924 + for (i = 0; i < ARRAY_SIZE(a); i++)
35925 + if (a[i].key == key) {
35926 + spin_unlock(&spin);
35929 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35931 + if (unlikely(a[i].key == key)) { /* rare but possible */
35932 + spin_unlock(&spin);
35937 + if (strstr(a[i].name, name)) {
35939 + * the order of these three lines is important for the
35940 + * lockless read above.
35943 + spin_unlock(&spin);
35945 + /* AuDbg("%d, %s\n", set, name); */
35949 + spin_unlock(&spin);
35958 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35961 + struct task_struct *curr;
35962 + struct held_lock **hl, *held_locks, *p;
35966 + wkinfo->dont_check = lockdep_recursing(curr);
35967 + if (wkinfo->dont_check)
35969 + n = curr->lockdep_depth;
35974 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35975 + if (unlikely(!wkinfo->hlock))
35979 +#if 0 /* left for debugging */
35980 + if (0 && au_debug_test())
35981 + lockdep_print_held_locks(curr);
35983 + held_locks = curr->held_locks;
35984 + hl = wkinfo->hlock;
35986 + p = held_locks++;
35987 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
35996 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
35998 + au_kfree_try_rcu(wkinfo->hlock);
36001 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36003 + struct held_lock *p, **hl = wkinfo->hlock;
36006 + if (wkinfo->dont_check)
36010 + while ((p = *hl++)) { /* assignment */
36011 + subclass = lockdep_hlock_class(p)->subclass;
36012 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36014 + rwsem_acquire_read(p->instance, subclass, 0,
36015 + /*p->acquire_ip*/_RET_IP_);
36017 + rwsem_acquire(p->instance, subclass, 0,
36018 + /*p->acquire_ip*/_RET_IP_);
36022 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36024 + struct held_lock *p, **hl = wkinfo->hlock;
36026 + if (wkinfo->dont_check)
36030 + while ((p = *hl++)) /* assignment */
36031 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36035 +static void wkq_func(struct work_struct *wk)
36037 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36039 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36040 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36042 + au_wkq_lockdep_pre(wkinfo);
36043 + wkinfo->func(wkinfo->args);
36044 + au_wkq_lockdep_post(wkinfo);
36045 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36046 + complete(wkinfo->comp);
36048 + kobject_put(wkinfo->kobj);
36049 + module_put(THIS_MODULE); /* todo: ?? */
36050 + au_kfree_rcu(wkinfo);
36055 + * Since struct completion is large, try allocating it dynamically.
36057 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36059 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36061 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36063 + init_completion(*comp);
36064 + wkinfo->comp = *comp;
36070 +static void au_wkq_comp_free(struct completion *comp)
36072 + au_kfree_rcu(comp);
36075 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36077 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36078 + if (au_wkq_test()) {
36079 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36080 + " due to a dead dir by UDBA,"
36081 + " or async xino write?\n");
36082 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36085 + au_dbg_verify_kthread();
36087 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36088 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36089 + queue_work(au_wkq, &wkinfo->wk);
36091 + INIT_WORK(&wkinfo->wk, wkq_func);
36092 + schedule_work(&wkinfo->wk);
36097 + * Be careful. It is easy to make deadlock happen.
36098 + * processA: lock, wkq and wait
36099 + * processB: wkq and wait, lock in wkq
36102 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36105 + AuWkqCompDeclare(comp);
36106 + struct au_wkinfo wkinfo = {
36112 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36113 + if (unlikely(err))
36115 + err = au_wkq_lockdep_alloc(&wkinfo);
36116 + if (unlikely(err))
36119 + au_wkq_run(&wkinfo);
36120 + /* no timeout, no interrupt */
36121 + wait_for_completion(wkinfo.comp);
36123 + au_wkq_lockdep_free(&wkinfo);
36126 + au_wkq_comp_free(comp);
36128 + destroy_work_on_stack(&wkinfo.wk);
36133 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36134 + * problem in a concurrent umounting.
36136 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36137 + unsigned int flags)
36140 + struct au_wkinfo *wkinfo;
36142 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36145 + * wkq_func() must free this wkinfo.
36146 + * it highly depends upon the implementation of workqueue.
36149 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36151 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36152 + wkinfo->flags = flags & ~AuWkq_WAIT;
36153 + wkinfo->func = func;
36154 + wkinfo->args = args;
36155 + wkinfo->comp = NULL;
36156 + au_wkq_lockdep_init(wkinfo);
36157 + kobject_get(wkinfo->kobj);
36158 + __module_get(THIS_MODULE); /* todo: ?? */
36160 + au_wkq_run(wkinfo);
36163 + au_nwt_done(&au_sbi(sb)->si_nowait);
36169 +/* ---------------------------------------------------------------------- */
36171 +void au_nwt_init(struct au_nowait_tasks *nwt)
36173 + atomic_set(&nwt->nw_len, 0);
36174 + /* smp_mb(); */ /* atomic_set */
36175 + init_waitqueue_head(&nwt->nw_wq);
36178 +void au_wkq_fin(void)
36180 + destroy_workqueue(au_wkq);
36183 +int __init au_wkq_init(void)
36188 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36189 + if (IS_ERR(au_wkq))
36190 + err = PTR_ERR(au_wkq);
36191 + else if (!au_wkq)
36196 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36197 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36198 +++ linux/fs/aufs/wkq.h 2021-02-22 22:51:59.061411920 +0100
36200 +/* SPDX-License-Identifier: GPL-2.0 */
36202 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36204 + * This program, aufs is free software; you can redistribute it and/or modify
36205 + * it under the terms of the GNU General Public License as published by
36206 + * the Free Software Foundation; either version 2 of the License, or
36207 + * (at your option) any later version.
36209 + * This program is distributed in the hope that it will be useful,
36210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36212 + * GNU General Public License for more details.
36214 + * You should have received a copy of the GNU General Public License
36215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36219 + * workqueue for asynchronous/super-io operations
36220 + * todo: try new credentials management scheme
36223 +#ifndef __AUFS_WKQ_H__
36224 +#define __AUFS_WKQ_H__
36228 +#include <linux/wait.h>
36230 +struct super_block;
36232 +/* ---------------------------------------------------------------------- */
36235 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36237 +struct au_nowait_tasks {
36239 + wait_queue_head_t nw_wq;
36242 +/* ---------------------------------------------------------------------- */
36244 +typedef void (*au_wkq_func_t)(void *args);
36247 +#define AuWkq_WAIT 1
36248 +#define AuWkq_NEST (1 << 1)
36249 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36250 +#define au_fset_wkq(flags, name) \
36251 + do { (flags) |= AuWkq_##name; } while (0)
36252 +#define au_fclr_wkq(flags, name) \
36253 + do { (flags) &= ~AuWkq_##name; } while (0)
36256 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36257 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36258 + unsigned int flags);
36259 +void au_nwt_init(struct au_nowait_tasks *nwt);
36260 +int __init au_wkq_init(void);
36261 +void au_wkq_fin(void);
36263 +/* ---------------------------------------------------------------------- */
36265 +static inline int au_wkq_test(void)
36267 + return current->flags & PF_WQ_WORKER;
36270 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36272 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36275 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36277 + if (atomic_dec_and_test(&nwt->nw_len))
36278 + wake_up_all(&nwt->nw_wq);
36281 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36283 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36287 +#endif /* __KERNEL__ */
36288 +#endif /* __AUFS_WKQ_H__ */
36289 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36290 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36291 +++ linux/fs/aufs/xattr.c 2021-02-22 22:51:59.061411920 +0100
36293 +// SPDX-License-Identifier: GPL-2.0
36295 + * Copyright (C) 2014-2020 Junjiro R. Okajima
36297 + * This program, aufs is free software; you can redistribute it and/or modify
36298 + * it under the terms of the GNU General Public License as published by
36299 + * the Free Software Foundation; either version 2 of the License, or
36300 + * (at your option) any later version.
36302 + * This program is distributed in the hope that it will be useful,
36303 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36304 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36305 + * GNU General Public License for more details.
36307 + * You should have received a copy of the GNU General Public License
36308 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36312 + * handling xattr functions
36315 +#include <linux/fs.h>
36316 +#include <linux/posix_acl_xattr.h>
36317 +#include <linux/xattr.h>
36320 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36322 + if (!ignore_flags)
36330 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36335 +#define cmp(brattr, prefix) do { \
36336 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36337 + XATTR_##prefix##_PREFIX_LEN)) { \
36338 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36344 + cmp(SEC, SECURITY);
36345 + cmp(SYS, SYSTEM);
36346 + cmp(TR, TRUSTED);
36350 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36357 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36359 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36360 + char *name, char **buf, unsigned int ignore_flags,
36361 + unsigned int verbose)
36365 + struct inode *h_idst;
36367 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36369 + if (unlikely(err <= 0)) {
36370 + if (err == -ENODATA
36371 + || (err == -EOPNOTSUPP
36372 + && ((ignore_flags & au_xattr_out_of_list)
36373 + || (au_test_nfs_noacl(d_inode(h_src))
36374 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36376 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36379 + if (err && (verbose || au_debug_test()))
36380 + pr_err("%s, err %d\n", name, err);
36384 + /* unlock it temporary */
36385 + h_idst = d_inode(h_dst);
36386 + inode_unlock(h_idst);
36387 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36388 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36389 + if (unlikely(err)) {
36390 + if (verbose || au_debug_test())
36391 + pr_err("%s, err %d\n", name, err);
36392 + err = au_xattr_ignore(err, name, ignore_flags);
36399 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36400 + unsigned int verbose)
36402 + int err, unlocked, acl_access, acl_default;
36404 + struct inode *h_isrc, *h_idst;
36405 + char *value, *p, *o, *e;
36407 + /* try stopping to update the source inode while we are referencing */
36408 + /* there should not be the parent-child relationship between them */
36409 + h_isrc = d_inode(h_src);
36410 + h_idst = d_inode(h_dst);
36411 + inode_unlock(h_idst);
36412 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36413 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36416 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36417 + ssz = vfs_listxattr(h_src, NULL, 0);
36419 + if (unlikely(err < 0)) {
36421 + if (err == -ENODATA
36422 + || err == -EOPNOTSUPP)
36423 + err = 0; /* ignore */
36432 + p = kmalloc(ssz, GFP_NOFS);
36434 + if (unlikely(!p))
36436 + err = vfs_listxattr(h_src, p, ssz);
36438 + inode_unlock_shared(h_isrc);
36440 + AuDbg("err %d, ssz %zd\n", err, ssz);
36441 + if (unlikely(err < 0))
36449 + while (!err && p < e) {
36450 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36451 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36452 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36453 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36455 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36457 + p += strlen(p) + 1;
36460 + ignore_flags |= au_xattr_out_of_list;
36461 + if (!err && !acl_access) {
36462 + err = au_do_cpup_xattr(h_dst, h_src,
36463 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36464 + ignore_flags, verbose);
36467 + if (!err && !acl_default) {
36468 + err = au_do_cpup_xattr(h_dst, h_src,
36469 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36470 + ignore_flags, verbose);
36474 + au_kfree_try_rcu(value);
36477 + au_kfree_try_rcu(o);
36480 + inode_unlock_shared(h_isrc);
36485 +/* ---------------------------------------------------------------------- */
36487 +static int au_smack_reentering(struct super_block *sb)
36489 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36491 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36492 + * i_op->getxattr(). ouch.
36494 + return si_pid_test(sb);
36505 +struct au_lgxattr {
36513 + const char *name;
36520 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36521 + struct au_lgxattr *arg)
36525 + struct path h_path;
36526 + struct super_block *sb;
36528 + sb = dentry->d_sb;
36529 + reenter = au_smack_reentering(sb);
36531 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36532 + if (unlikely(err))
36535 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36536 + if (unlikely(err))
36538 + if (unlikely(!h_path.dentry))
36539 + /* illegally overlapped or something */
36540 + goto out_di; /* pretending success */
36542 + /* always topmost entry only */
36543 + switch (arg->type) {
36544 + case AU_XATTR_LIST:
36545 + err = vfs_listxattr(h_path.dentry,
36546 + arg->u.list.list, arg->u.list.size);
36548 + case AU_XATTR_GET:
36549 + AuDebugOn(d_is_negative(h_path.dentry));
36550 + err = vfs_getxattr(h_path.dentry,
36551 + arg->u.get.name, arg->u.get.value,
36552 + arg->u.get.size);
36558 + di_read_unlock(dentry, AuLock_IR);
36561 + si_read_unlock(sb);
36567 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36569 + struct au_lgxattr arg = {
36570 + .type = AU_XATTR_LIST,
36577 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36580 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36581 + const char *name, void *value, size_t size)
36583 + struct au_lgxattr arg = {
36584 + .type = AU_XATTR_GET,
36592 + return au_lgxattr(dentry, inode, &arg);
36595 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36596 + const char *name, const void *value, size_t size,
36599 + struct au_sxattr arg = {
36600 + .type = AU_XATTR_SET,
36609 + return au_sxattr(dentry, inode, &arg);
36612 +/* ---------------------------------------------------------------------- */
36614 +static int au_xattr_get(const struct xattr_handler *handler,
36615 + struct dentry *dentry, struct inode *inode,
36616 + const char *name, void *buffer, size_t size)
36618 + return au_getxattr(dentry, inode, name, buffer, size);
36621 +static int au_xattr_set(const struct xattr_handler *handler,
36622 + struct dentry *dentry, struct inode *inode,
36623 + const char *name, const void *value, size_t size,
36626 + return au_setxattr(dentry, inode, name, value, size, flags);
36629 +static const struct xattr_handler au_xattr_handler = {
36632 + .get = au_xattr_get,
36633 + .set = au_xattr_set
36636 +static const struct xattr_handler *au_xattr_handlers[] = {
36637 +#ifdef CONFIG_FS_POSIX_ACL
36638 + &posix_acl_access_xattr_handler,
36639 + &posix_acl_default_xattr_handler,
36641 + &au_xattr_handler, /* must be last */
36645 +void au_xattr_init(struct super_block *sb)
36647 + sb->s_xattr = au_xattr_handlers;
36649 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36650 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36651 +++ linux/fs/aufs/xino.c 2021-02-22 22:51:59.061411920 +0100
36653 +// SPDX-License-Identifier: GPL-2.0
36655 + * Copyright (C) 2005-2020 Junjiro R. Okajima
36657 + * This program, aufs is free software; you can redistribute it and/or modify
36658 + * it under the terms of the GNU General Public License as published by
36659 + * the Free Software Foundation; either version 2 of the License, or
36660 + * (at your option) any later version.
36662 + * This program is distributed in the hope that it will be useful,
36663 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36664 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36665 + * GNU General Public License for more details.
36667 + * You should have received a copy of the GNU General Public License
36668 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36672 + * external inode number translation table and bitmap
36674 + * things to consider
36676 + * + au_xino object
36677 + * + XINO files (xino, xib, xigen)
36678 + * + dynamic debugfs entries (xiN)
36679 + * + static debugfs entries (xib, xigen)
36680 + * + static sysfs entry (xi_path)
36681 + * - several entry points to handle them.
36682 + * + mount(2) without xino option (default)
36683 + * + mount(2) with xino option
36684 + * + mount(2) with noxino option
36686 + * + remount with add/del branches
36687 + * + remount with xino/noxino options
36690 +#include <linux/seq_file.h>
36691 +#include <linux/statfs.h>
36694 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36695 + aufs_bindex_t bbot,
36696 + struct super_block *h_sb)
36698 + /* todo: try binary-search if the branches are many */
36699 + for (; btop <= bbot; btop++)
36700 + if (h_sb == au_sbr_sb(sb, btop))
36706 + * find another branch who is on the same filesystem of the specified
36707 + * branch{@btgt}. search until @bbot.
36709 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36710 + aufs_bindex_t bbot)
36712 + aufs_bindex_t bindex;
36713 + struct super_block *tgt_sb;
36715 + tgt_sb = au_sbr_sb(sb, btgt);
36716 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36718 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36723 +/* ---------------------------------------------------------------------- */
36726 + * stop unnecessary notify events at creating xino files
36729 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36731 + aufs_bindex_t bfound, bindex, bbot;
36732 + struct dentry *parent;
36733 + struct au_branch *br;
36736 + parent = dentry->d_parent; /* safe d_parent access */
36737 + bbot = au_sbbot(sb);
36738 + for (bindex = 0; bindex <= bbot; bindex++) {
36739 + br = au_sbr(sb, bindex);
36740 + if (au_br_dentry(br) == parent) {
36746 + AuDbg("bfound b%d\n", bfound);
36750 +struct au_xino_lock_dir {
36751 + struct au_hinode *hdir;
36752 + struct dentry *parent;
36753 + struct inode *dir;
36756 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36757 + unsigned int lsc)
36759 + struct dentry *parent;
36760 + struct inode *dir;
36762 + parent = dget_parent(dentry);
36763 + dir = d_inode(parent);
36764 + inode_lock_nested(dir, lsc);
36765 +#if 0 /* it should not happen */
36766 + spin_lock(&dentry->d_lock);
36767 + if (unlikely(dentry->d_parent != parent)) {
36768 + spin_unlock(&dentry->d_lock);
36769 + inode_unlock(dir);
36774 + spin_unlock(&dentry->d_lock);
36781 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36782 + struct au_xino_lock_dir *ldir)
36784 + aufs_bindex_t bindex;
36786 + ldir->hdir = NULL;
36787 + bindex = au_xi_root(sb, xipath->dentry);
36788 + if (bindex >= 0) {
36789 + /* rw branch root */
36790 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36791 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36794 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36796 + ldir->dir = d_inode(ldir->parent);
36800 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36803 + au_hn_inode_unlock(ldir->hdir);
36805 + inode_unlock(ldir->dir);
36806 + dput(ldir->parent);
36810 +/* ---------------------------------------------------------------------- */
36813 + * create and set a new xino file
36815 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36818 + struct file *file;
36819 + struct dentry *h_parent, *d;
36820 + struct inode *h_dir, *inode;
36822 + static DEFINE_MUTEX(mtx);
36825 + * at mount-time, and the xino file is the default path,
36826 + * hnotify is disabled so we have no notify events to ignore.
36827 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36830 + mutex_lock(&mtx);
36831 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36832 + /* | __FMODE_NONOTIFY */,
36834 + if (IS_ERR(file)) {
36836 + mutex_unlock(&mtx);
36838 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36842 + /* keep file count */
36844 + d = file->f_path.dentry;
36845 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36847 + mutex_unlock(&mtx);
36848 + /* mnt_want_write() is unnecessary here */
36849 + h_dir = d_inode(h_parent);
36850 + inode = file_inode(file);
36851 + /* no delegation since it is just created */
36852 + if (inode->i_nlink)
36853 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36855 + inode_unlock(h_dir);
36857 + if (unlikely(err)) {
36859 + pr_err("unlink %s(%d)\n", fpath, err);
36864 + if (unlikely(sb == d->d_sb)) {
36866 + pr_err("%s must be outside\n", fpath);
36869 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36871 + pr_err("xino doesn't support %s(%s)\n",
36872 + fpath, au_sbtype(d->d_sb));
36875 + return file; /* success */
36879 + file = ERR_PTR(err);
36884 + * create a new xinofile at the same place/path as @base.
36886 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36887 + struct file *copy_src)
36889 + struct file *file;
36890 + struct dentry *dentry, *parent;
36891 + struct inode *dir, *delegated;
36892 + struct qstr *name;
36893 + struct path path;
36894 + int err, do_unlock;
36895 + struct au_xino_lock_dir ldir;
36898 + au_xino_lock_dir(sb, base, &ldir);
36899 + dentry = base->dentry;
36900 + parent = dentry->d_parent; /* dir inode is locked */
36901 + dir = d_inode(parent);
36904 + name = &dentry->d_name;
36905 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
36906 + if (IS_ERR(path.dentry)) {
36907 + file = (void *)path.dentry;
36908 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36912 + /* no need to mnt_want_write() since we call dentry_open() later */
36913 + err = vfs_create(dir, path.dentry, 0666, NULL);
36914 + if (unlikely(err)) {
36915 + file = ERR_PTR(err);
36916 + pr_err("%pd create err %d\n", dentry, err);
36920 + path.mnt = base->mnt;
36921 + file = vfsub_dentry_open(&path,
36922 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36923 + /* | __FMODE_NONOTIFY */);
36924 + if (IS_ERR(file)) {
36925 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36929 + delegated = NULL;
36930 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36931 + au_xino_unlock_dir(&ldir);
36933 + if (unlikely(err == -EWOULDBLOCK)) {
36934 + pr_warn("cannot retry for NFSv4 delegation"
36935 + " for an internal unlink\n");
36938 + if (unlikely(err)) {
36939 + pr_err("%pd unlink err %d\n", dentry, err);
36944 + /* no one can touch copy_src xino */
36945 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36946 + if (unlikely(err)) {
36947 + pr_err("%pd copy err %d\n", dentry, err);
36951 + goto out_dput; /* success */
36955 + file = ERR_PTR(err);
36957 + dput(path.dentry);
36960 + au_xino_unlock_dir(&ldir);
36964 +struct file *au_xino_file1(struct au_xino *xi)
36966 + struct file *file;
36967 + unsigned int u, nfile;
36970 + nfile = xi->xi_nfile;
36971 + for (u = 0; u < nfile; u++) {
36972 + file = xi->xi_file[u];
36980 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
36991 + if (idx < xi->xi_nfile) {
36992 + f = xi->xi_file[idx];
36996 + p = au_kzrealloc(xi->xi_file,
36997 + sizeof(*xi->xi_file) * xi->xi_nfile,
36998 + sizeof(*xi->xi_file) * (idx + 1),
36999 + GFP_NOFS, /*may_shrink*/0);
37001 + MtxMustLock(&xi->xi_mtx);
37003 + xi->xi_nfile = idx + 1;
37011 + xi->xi_file[idx] = file;
37018 + * if @xinew->xi is not set, then create new xigen file.
37020 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37022 + struct file *file;
37025 + SiMustAnyLock(sb);
37027 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37028 + if (IS_ERR(file)) {
37029 + err = PTR_ERR(file);
37030 + pr_err("%s[%d], err %d\n",
37031 + xinew->xi ? "xino" : "xigen",
37032 + xinew->idx, err);
37037 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37040 + /* todo: make xigen file an array */
37041 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37044 + if (unlikely(err))
37045 + file = ERR_PTR(err);
37051 +/* ---------------------------------------------------------------------- */
37054 + * truncate xino files
37056 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37057 + int idx, struct kstatfs *st)
37061 + struct file *file, *new_xino;
37062 + struct au_xi_new xinew = {
37067 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37068 + file = au_xino_file(xinew.xi, idx);
37072 + xinew.base = &file->f_path;
37073 + err = vfs_statfs(xinew.base, st);
37074 + if (unlikely(err)) {
37075 + AuErr1("statfs err %d, ignored\n", err);
37080 + blocks = file_inode(file)->i_blocks;
37081 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37082 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37084 + xinew.copy_src = file;
37085 + new_xino = au_xi_new(sb, &xinew);
37086 + if (IS_ERR(new_xino)) {
37087 + err = PTR_ERR(new_xino);
37088 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37092 + err = vfs_statfs(&new_xino->f_path, st);
37094 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37095 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37096 + st->f_bfree, st->f_blocks);
37098 + AuErr1("statfs err %d, ignored\n", err);
37106 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37109 + unsigned long jiffy;
37110 + aufs_bindex_t bbot;
37111 + struct kstatfs *st;
37112 + struct au_branch *br;
37113 + struct au_xino *xi;
37116 + st = kmalloc(sizeof(*st), GFP_NOFS);
37117 + if (unlikely(!st))
37121 + bbot = au_sbbot(sb);
37122 + if (unlikely(bindex < 0 || bbot < bindex))
37127 + br = au_sbr(sb, bindex);
37128 + xi = br->br_xino;
37129 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37130 + err = au_xino_do_trunc(sb, bindex, i, st);
37132 + au_sbi(sb)->si_xino_jiffy = jiffy;
37135 + au_kfree_rcu(st);
37140 +struct xino_do_trunc_args {
37141 + struct super_block *sb;
37142 + struct au_branch *br;
37146 +static void xino_do_trunc(void *_args)
37148 + struct xino_do_trunc_args *args = _args;
37149 + struct super_block *sb;
37150 + struct au_branch *br;
37151 + struct inode *dir;
37153 + aufs_bindex_t bindex;
37157 + dir = d_inode(sb->s_root);
37161 + si_noflush_write_lock(sb);
37162 + ii_read_lock_parent(dir);
37163 + bindex = au_br_index(sb, br->br_id);
37164 + err = au_xino_trunc(sb, bindex, idx);
37165 + ii_read_unlock(dir);
37166 + if (unlikely(err))
37167 + pr_warn("err b%d, (%d)\n", bindex, err);
37168 + atomic_dec(&br->br_xino->xi_truncating);
37169 + au_lcnt_dec(&br->br_count);
37170 + si_write_unlock(sb);
37171 + au_nwt_done(&au_sbi(sb)->si_nowait);
37172 + au_kfree_rcu(args);
37176 + * returns the index in the xi_file array whose corresponding file is necessary
37177 + * to truncate, or -1 which means no need to truncate.
37179 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37183 + struct kstatfs st;
37184 + struct au_sbinfo *sbinfo;
37185 + struct au_xino *xi;
37186 + struct file *file;
37188 + /* todo: si_xino_expire and the ratio should be customizable */
37189 + sbinfo = au_sbi(sb);
37190 + if (time_before(jiffies,
37191 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37194 + /* truncation border */
37195 + xi = br->br_xino;
37196 + for (u = 0; u < xi->xi_nfile; u++) {
37197 + file = au_xino_file(xi, u);
37201 + err = vfs_statfs(&file->f_path, &st);
37202 + if (unlikely(err)) {
37203 + AuErr1("statfs err %d, ignored\n", err);
37206 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37207 + >= AUFS_XINO_DEF_TRUNC)
37214 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37217 + struct xino_do_trunc_args *args;
37220 + idx = xino_trunc_test(sb, br);
37224 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37227 + /* lock and kfree() will be called in trunc_xino() */
37228 + args = kmalloc(sizeof(*args), GFP_NOFS);
37229 + if (unlikely(!args)) {
37230 + AuErr1("no memory\n");
37234 + au_lcnt_inc(&br->br_count);
37238 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37240 + return; /* success */
37242 + pr_err("wkq %d\n", wkq_err);
37243 + au_lcnt_dec(&br->br_count);
37244 + au_kfree_rcu(args);
37247 + atomic_dec(&br->br_xino->xi_truncating);
37250 +/* ---------------------------------------------------------------------- */
37252 +struct au_xi_calc {
37257 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37258 + struct au_xi_calc *calc)
37262 + maxent = au_xi_maxent(sb);
37263 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37264 + calc->pos *= sizeof(ino_t);
37267 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37268 + struct au_xi_calc *calc)
37271 + struct file *file;
37272 + struct au_xino *xi = br->br_xino;
37273 + struct au_xi_new xinew = {
37277 + SiMustAnyLock(sb);
37283 + mutex_lock(&xi->xi_mtx);
37284 + file = au_xino_file(xi, calc->idx);
37288 + file = au_xino_file(xi, /*idx*/-1);
37289 + AuDebugOn(!file);
37290 + xinew.idx = calc->idx;
37291 + xinew.base = &file->f_path;
37292 + /* xinew.copy_src = NULL; */
37293 + file = au_xi_new(sb, &xinew);
37294 + if (IS_ERR(file))
37295 + err = PTR_ERR(file);
37298 + mutex_unlock(&xi->xi_mtx);
37303 +struct au_xino_do_new_async_args {
37304 + struct super_block *sb;
37305 + struct au_branch *br;
37306 + struct au_xi_calc calc;
37310 +struct au_xi_writing {
37311 + struct hlist_bl_node node;
37312 + ino_t h_ino, ino;
37315 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37318 +static void au_xino_call_do_new_async(void *args)
37320 + struct au_xino_do_new_async_args *a = args;
37321 + struct au_branch *br;
37322 + struct super_block *sb;
37323 + struct au_sbinfo *sbi;
37324 + struct inode *root;
37325 + struct file *file;
37326 + struct au_xi_writing *del, *p;
37327 + struct hlist_bl_head *hbl;
37328 + struct hlist_bl_node *pos;
37333 + sbi = au_sbi(sb);
37334 + si_noflush_read_lock(sb);
37335 + root = d_inode(sb->s_root);
37336 + ii_read_lock_child(root);
37337 + err = au_xino_do_new_async(sb, br, &a->calc);
37338 + if (unlikely(err)) {
37339 + AuIOErr("err %d\n", err);
37343 + file = au_xino_file(br->br_xino, a->calc.idx);
37344 + AuDebugOn(!file);
37345 + err = au_xino_do_write(file, &a->calc, a->ino);
37346 + if (unlikely(err)) {
37347 + AuIOErr("err %d\n", err);
37352 + hbl = &br->br_xino->xi_writing;
37353 + hlist_bl_lock(hbl);
37354 + au_hbl_for_each(pos, hbl) {
37355 + p = container_of(pos, struct au_xi_writing, node);
37356 + if (p->ino == a->ino) {
37358 + hlist_bl_del(&p->node);
37362 + hlist_bl_unlock(hbl);
37363 + au_kfree_rcu(del);
37366 + au_lcnt_dec(&br->br_count);
37367 + ii_read_unlock(root);
37368 + si_read_unlock(sb);
37369 + au_nwt_done(&sbi->si_nowait);
37374 + * create a new xino file asynchronously
37376 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37377 + struct au_xi_calc *calc, ino_t ino)
37380 + struct au_xino_do_new_async_args *arg;
37383 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37384 + if (unlikely(!arg))
37389 + arg->calc = *calc;
37391 + au_lcnt_inc(&br->br_count);
37392 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37393 + if (unlikely(err)) {
37394 + pr_err("wkq %d\n", err);
37395 + au_lcnt_dec(&br->br_count);
37396 + au_kfree_rcu(arg);
37404 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37405 + * at the position of @h_ino.
37407 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37412 + struct au_xi_calc calc;
37413 + struct au_sbinfo *sbinfo;
37414 + struct file *file;
37415 + struct au_xino *xi;
37416 + struct hlist_bl_head *hbl;
37417 + struct hlist_bl_node *pos;
37418 + struct au_xi_writing *p;
37421 + if (!au_opt_test(au_mntflags(sb), XINO))
37422 + return 0; /* no xino */
37425 + au_xi_calc(sb, h_ino, &calc);
37426 + xi = au_sbr(sb, bindex)->br_xino;
37427 + file = au_xino_file(xi, calc.idx);
37429 + hbl = &xi->xi_writing;
37430 + hlist_bl_lock(hbl);
37431 + au_hbl_for_each(pos, hbl) {
37432 + p = container_of(pos, struct au_xi_writing, node);
37433 + if (p->h_ino == h_ino) {
37434 + AuDbg("hi%llu, i%llu, found\n",
37435 + (u64)p->h_ino, (u64)p->ino);
37440 + hlist_bl_unlock(hbl);
37442 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37443 + return 0; /* no xino */
37445 + sbinfo = au_sbi(sb);
37446 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37447 + if (sz == sizeof(*ino))
37448 + return 0; /* success */
37451 + if (unlikely(sz >= 0)) {
37453 + AuIOErr("xino read error (%zd)\n", sz);
37458 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37463 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37464 + if (sz == sizeof(ino))
37465 + return 0; /* success */
37467 + AuIOErr("write failed (%zd)\n", sz);
37472 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37473 + * at the position of @h_ino.
37474 + * even if @ino is zero, it is written to the xinofile and means no entry.
37475 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37476 + * try truncating it.
37478 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37482 + unsigned int mnt_flags;
37483 + struct au_xi_calc calc;
37484 + struct file *file;
37485 + struct au_branch *br;
37486 + struct au_xino *xi;
37487 + struct au_xi_writing *p;
37489 + SiMustAnyLock(sb);
37491 + mnt_flags = au_mntflags(sb);
37492 + if (!au_opt_test(mnt_flags, XINO))
37495 + au_xi_calc(sb, h_ino, &calc);
37496 + br = au_sbr(sb, bindex);
37497 + xi = br->br_xino;
37498 + file = au_xino_file(xi, calc.idx);
37500 + /* store the inum pair into the list */
37501 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37502 + p->h_ino = h_ino;
37504 + au_hbl_add(&p->node, &xi->xi_writing);
37506 + /* create and write a new xino file asynchronously */
37507 + err = au_xino_new_async(sb, br, &calc, ino);
37509 + return 0; /* success */
37513 + err = au_xino_do_write(file, &calc, ino);
37515 + br = au_sbr(sb, bindex);
37516 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37517 + && au_test_fs_trunc_xino(au_br_sb(br)))
37518 + xino_try_trunc(sb, br);
37519 + return 0; /* success */
37523 + AuIOErr("write failed (%d)\n", err);
37527 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37530 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37531 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37535 + const int prevent_endless = 10;
37539 + err = vfsub_read_k(file, kbuf, size, pos);
37540 + if (err == -EINTR
37541 + && !au_wkq_test()
37542 + && fatal_signal_pending(current)) {
37543 + err = xino_fread_wkq(file, kbuf, size, pos);
37544 + BUG_ON(err == -EINTR);
37546 + } while (i++ < prevent_endless
37547 + && (err == -EAGAIN || err == -EINTR));
37549 +#if 0 /* reserved for future use */
37551 + fsnotify_access(file->f_path.dentry);
37557 +struct xino_fread_args {
37559 + struct file *file;
37565 +static void call_xino_fread(void *args)
37567 + struct xino_fread_args *a = args;
37568 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37571 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37576 + struct xino_fread_args args = {
37584 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37585 + if (unlikely(wkq_err))
37591 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37594 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37599 + const int prevent_endless = 10;
37603 + err = vfsub_write_k(file, kbuf, size, pos);
37604 + if (err == -EINTR
37605 + && !au_wkq_test()
37606 + && fatal_signal_pending(current)) {
37607 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37608 + BUG_ON(err == -EINTR);
37610 + } while (i++ < prevent_endless
37611 + && (err == -EAGAIN || err == -EINTR));
37613 +#if 0 /* reserved for future use */
37615 + fsnotify_modify(file->f_path.dentry);
37621 +struct do_xino_fwrite_args {
37623 + struct file *file;
37629 +static void call_do_xino_fwrite(void *args)
37631 + struct do_xino_fwrite_args *a = args;
37632 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37635 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37640 + struct do_xino_fwrite_args args = {
37649 + * it breaks RLIMIT_FSIZE and normal user's limit,
37650 + * users should care about quota and real 'filesystem full.'
37652 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37653 + if (unlikely(wkq_err))
37659 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37663 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37665 + err = do_xino_fwrite(file, buf, size, pos);
37669 + err = xino_fwrite_wkq(file, buf, size, pos);
37676 +/* ---------------------------------------------------------------------- */
37679 + * inode number bitmap
37681 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37682 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37686 + AuDebugOn(bit < 0 || page_bits <= bit);
37687 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37691 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37693 + AuDebugOn(ino < AUFS_FIRST_INO);
37694 + ino -= AUFS_FIRST_INO;
37695 + *pindex = ino / page_bits;
37696 + *bit = ino % page_bits;
37699 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37704 + struct au_sbinfo *sbinfo;
37705 + struct file *xib;
37706 + unsigned long *p;
37708 + sbinfo = au_sbi(sb);
37709 + MtxMustLock(&sbinfo->si_xib_mtx);
37710 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37711 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37713 + if (pindex == sbinfo->si_xib_last_pindex)
37716 + xib = sbinfo->si_xib;
37717 + p = sbinfo->si_xib_buf;
37718 + pos = sbinfo->si_xib_last_pindex;
37719 + pos *= PAGE_SIZE;
37720 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37721 + if (unlikely(sz != PAGE_SIZE))
37725 + pos *= PAGE_SIZE;
37726 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37727 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37729 + memset(p, 0, PAGE_SIZE);
37730 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37732 + if (sz == PAGE_SIZE) {
37733 + sbinfo->si_xib_last_pindex = pindex;
37734 + return 0; /* success */
37738 + AuIOErr1("write failed (%zd)\n", sz);
37745 +static void au_xib_clear_bit(struct inode *inode)
37748 + unsigned long pindex;
37749 + struct super_block *sb;
37750 + struct au_sbinfo *sbinfo;
37752 + AuDebugOn(inode->i_nlink);
37754 + sb = inode->i_sb;
37755 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37756 + AuDebugOn(page_bits <= bit);
37757 + sbinfo = au_sbi(sb);
37758 + mutex_lock(&sbinfo->si_xib_mtx);
37759 + err = xib_pindex(sb, pindex);
37761 + clear_bit(bit, sbinfo->si_xib_buf);
37762 + sbinfo->si_xib_next_bit = bit;
37764 + mutex_unlock(&sbinfo->si_xib_mtx);
37767 +/* ---------------------------------------------------------------------- */
37770 + * truncate a xino bitmap file
37774 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37778 + unsigned long pindex;
37779 + loff_t pos, pend;
37780 + struct au_sbinfo *sbinfo;
37782 + unsigned long *p;
37785 + sbinfo = au_sbi(sb);
37786 + MtxMustLock(&sbinfo->si_xib_mtx);
37787 + p = sbinfo->si_xib_buf;
37788 + pend = vfsub_f_size_read(file);
37790 + while (pos < pend) {
37791 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37793 + if (unlikely(sz <= 0))
37797 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37798 + if (unlikely(*ino < AUFS_FIRST_INO))
37801 + xib_calc_bit(*ino, &pindex, &bit);
37802 + AuDebugOn(page_bits <= bit);
37803 + err = xib_pindex(sb, pindex);
37815 +static int xib_restore(struct super_block *sb)
37818 + unsigned int nfile;
37819 + aufs_bindex_t bindex, bbot;
37821 + struct au_branch *br;
37822 + struct au_xino *xi;
37823 + struct file *file;
37826 + page = (void *)__get_free_page(GFP_NOFS);
37827 + if (unlikely(!page))
37831 + bbot = au_sbbot(sb);
37832 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37833 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37834 + br = au_sbr(sb, bindex);
37835 + xi = br->br_xino;
37836 + nfile = xi->xi_nfile;
37837 + for (i = 0; i < nfile; i++) {
37838 + file = au_xino_file(xi, i);
37840 + err = do_xib_restore(sb, file, page);
37843 + AuDbg("skip shared b%d\n", bindex);
37844 + free_page((unsigned long)page);
37850 +int au_xib_trunc(struct super_block *sb)
37855 + struct au_sbinfo *sbinfo;
37856 + unsigned long *p;
37857 + struct file *file;
37859 + SiMustWriteLock(sb);
37862 + sbinfo = au_sbi(sb);
37863 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37866 + file = sbinfo->si_xib;
37867 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37870 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37871 + err = PTR_ERR(file);
37872 + if (IS_ERR(file))
37874 + fput(sbinfo->si_xib);
37875 + sbinfo->si_xib = file;
37877 + p = sbinfo->si_xib_buf;
37878 + memset(p, 0, PAGE_SIZE);
37880 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
37881 + if (unlikely(sz != PAGE_SIZE)) {
37883 + AuIOErr("err %d\n", err);
37889 + mutex_lock(&sbinfo->si_xib_mtx);
37890 + /* mnt_want_write() is unnecessary here */
37891 + err = xib_restore(sb);
37892 + mutex_unlock(&sbinfo->si_xib_mtx);
37898 +/* ---------------------------------------------------------------------- */
37900 +struct au_xino *au_xino_alloc(unsigned int nfile)
37902 + struct au_xino *xi;
37904 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37905 + if (unlikely(!xi))
37907 + xi->xi_nfile = nfile;
37908 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
37909 + if (unlikely(!xi->xi_file))
37912 + xi->xi_nondir.total = 8; /* initial size */
37913 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37915 + if (unlikely(!xi->xi_nondir.array))
37918 + spin_lock_init(&xi->xi_nondir.spin);
37919 + init_waitqueue_head(&xi->xi_nondir.wqh);
37920 + mutex_init(&xi->xi_mtx);
37921 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
37922 + atomic_set(&xi->xi_truncating, 0);
37923 + kref_init(&xi->xi_kref);
37924 + goto out; /* success */
37927 + au_kfree_try_rcu(xi->xi_file);
37929 + au_kfree_rcu(xi);
37935 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
37938 + struct au_xino *xi;
37941 + xi = au_xino_alloc(idx + 1);
37942 + if (unlikely(!xi)) {
37949 + xi->xi_file[idx] = file;
37950 + AuDebugOn(br->br_xino);
37951 + br->br_xino = xi;
37957 +static void au_xino_release(struct kref *kref)
37959 + struct au_xino *xi;
37961 + unsigned long ul;
37962 + struct hlist_bl_head *hbl;
37963 + struct hlist_bl_node *pos, *n;
37964 + struct au_xi_writing *p;
37966 + xi = container_of(kref, struct au_xino, xi_kref);
37967 + for (i = 0; i < xi->xi_nfile; i++)
37968 + if (xi->xi_file[i])
37969 + fput(xi->xi_file[i]);
37970 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37971 + AuDebugOn(xi->xi_nondir.array[i]);
37972 + mutex_destroy(&xi->xi_mtx);
37973 + hbl = &xi->xi_writing;
37974 + ul = au_hbl_count(hbl);
37975 + if (unlikely(ul)) {
37976 + pr_warn("xi_writing %lu\n", ul);
37977 + hlist_bl_lock(hbl);
37978 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
37979 + hlist_bl_del(&p->node);
37980 + /* kmemleak reported au_kfree_rcu() doesn't free it */
37983 + hlist_bl_unlock(hbl);
37985 + au_kfree_try_rcu(xi->xi_file);
37986 + au_kfree_try_rcu(xi->xi_nondir.array);
37987 + au_kfree_rcu(xi);
37990 +int au_xino_put(struct au_branch *br)
37993 + struct au_xino *xi;
37996 + xi = br->br_xino;
37998 + br->br_xino = NULL;
37999 + ret = kref_put(&xi->xi_kref, au_xino_release);
38005 +/* ---------------------------------------------------------------------- */
38008 + * xino mount option handlers
38012 +static void xino_clear_xib(struct super_block *sb)
38014 + struct au_sbinfo *sbinfo;
38016 + SiMustWriteLock(sb);
38018 + sbinfo = au_sbi(sb);
38019 + if (sbinfo->si_xib)
38020 + fput(sbinfo->si_xib);
38021 + sbinfo->si_xib = NULL;
38022 + if (sbinfo->si_xib_buf)
38023 + free_page((unsigned long)sbinfo->si_xib_buf);
38024 + sbinfo->si_xib_buf = NULL;
38027 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38031 + struct au_sbinfo *sbinfo;
38032 + struct file *file;
38033 + struct super_block *xi_sb;
38035 + SiMustWriteLock(sb);
38037 + sbinfo = au_sbi(sb);
38038 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38039 + err = PTR_ERR(file);
38040 + if (IS_ERR(file))
38042 + if (sbinfo->si_xib)
38043 + fput(sbinfo->si_xib);
38044 + sbinfo->si_xib = file;
38045 + xi_sb = file_inode(file)->i_sb;
38046 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38047 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38049 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38050 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38053 + sbinfo->si_ximaxent /= sizeof(ino_t);
38056 + if (!sbinfo->si_xib_buf)
38057 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38058 + if (unlikely(!sbinfo->si_xib_buf))
38061 + sbinfo->si_xib_last_pindex = 0;
38062 + sbinfo->si_xib_next_bit = 0;
38063 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38065 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38066 + if (unlikely(err != PAGE_SIZE))
38070 + goto out; /* success */
38073 + if (sbinfo->si_xib_buf)
38074 + free_page((unsigned long)sbinfo->si_xib_buf);
38075 + sbinfo->si_xib_buf = NULL;
38079 + fput(sbinfo->si_xib);
38080 + sbinfo->si_xib = NULL;
38086 +/* xino for each branch */
38087 +static void xino_clear_br(struct super_block *sb)
38089 + aufs_bindex_t bindex, bbot;
38090 + struct au_branch *br;
38092 + bbot = au_sbbot(sb);
38093 + for (bindex = 0; bindex <= bbot; bindex++) {
38094 + br = au_sbr(sb, bindex);
38100 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38101 + aufs_bindex_t bshared)
38103 + struct au_branch *brshared;
38105 + brshared = au_sbr(sb, bshared);
38106 + AuDebugOn(!brshared->br_xino);
38107 + AuDebugOn(!brshared->br_xino->xi_file);
38108 + if (br->br_xino != brshared->br_xino) {
38109 + au_xino_get(brshared);
38111 + br->br_xino = brshared->br_xino;
38115 +struct au_xino_do_set_br {
38116 + struct au_branch *br;
38118 + aufs_bindex_t bshared;
38121 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38122 + struct au_xino_do_set_br *args)
38125 + struct au_xi_calc calc;
38126 + struct file *file;
38127 + struct au_branch *br;
38128 + struct au_xi_new xinew = {
38133 + xinew.xi = br->br_xino;
38134 + au_xi_calc(sb, args->h_ino, &calc);
38135 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38136 + if (args->bshared >= 0)
38137 + /* shared xino */
38138 + au_xino_set_br_shared(sb, br, args->bshared);
38139 + else if (!xinew.xi) {
38141 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38142 + if (unlikely(err))
38146 + /* force re-creating */
38147 + xinew.xi = br->br_xino;
38148 + xinew.idx = calc.idx;
38149 + mutex_lock(&xinew.xi->xi_mtx);
38150 + file = au_xi_new(sb, &xinew);
38151 + mutex_unlock(&xinew.xi->xi_mtx);
38152 + err = PTR_ERR(file);
38153 + if (IS_ERR(file))
38155 + AuDebugOn(!file);
38157 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38158 + if (unlikely(err))
38166 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38169 + aufs_bindex_t bindex, bbot;
38170 + struct au_xino_do_set_br args;
38171 + struct inode *inode;
38173 + SiMustWriteLock(sb);
38175 + bbot = au_sbbot(sb);
38176 + inode = d_inode(sb->s_root);
38177 + for (bindex = 0; bindex <= bbot; bindex++) {
38178 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38179 + args.br = au_sbr(sb, bindex);
38180 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38181 + err = au_xino_do_set_br(sb, path, &args);
38182 + if (unlikely(err))
38190 +void au_xino_clr(struct super_block *sb)
38192 + struct au_sbinfo *sbinfo;
38194 + au_xigen_clr(sb);
38195 + xino_clear_xib(sb);
38196 + xino_clear_br(sb);
38197 + dbgaufs_brs_del(sb, 0);
38198 + sbinfo = au_sbi(sb);
38199 + /* lvalue, do not call au_mntflags() */
38200 + au_opt_clr(sbinfo->si_mntflags, XINO);
38203 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38206 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38207 + struct qstr *dname, *cur_name;
38208 + struct file *cur_xino;
38209 + struct au_sbinfo *sbinfo;
38210 + struct path *path, *cur_path;
38212 + SiMustWriteLock(sb);
38215 + sbinfo = au_sbi(sb);
38216 + path = &xiopt->file->f_path;
38217 + dentry = path->dentry;
38218 + parent = dget_parent(dentry);
38221 + cur_xino = sbinfo->si_xib;
38223 + cur_path = &cur_xino->f_path;
38224 + cur_dentry = cur_path->dentry;
38225 + cur_parent = dget_parent(cur_dentry);
38226 + cur_name = &cur_dentry->d_name;
38227 + dname = &dentry->d_name;
38228 + skip = (cur_parent == parent
38229 + && au_qstreq(dname, cur_name));
38230 + dput(cur_parent);
38236 + au_opt_set(sbinfo->si_mntflags, XINO);
38237 + err = au_xino_set_xib(sb, path);
38238 + /* si_x{read,write} are set */
38240 + err = au_xigen_set(sb, path);
38242 + err = au_xino_set_br(sb, path);
38244 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38245 + goto out; /* success */
38249 + AuIOErr("failed setting xino(%d).\n", err);
38258 + * create a xinofile at the default place/path.
38260 +struct file *au_xino_def(struct super_block *sb)
38262 + struct file *file;
38264 + struct au_branch *br;
38265 + struct super_block *h_sb;
38266 + struct path path;
38267 + aufs_bindex_t bbot, bindex, bwr;
38270 + bbot = au_sbbot(sb);
38272 + for (bindex = 0; bindex <= bbot; bindex++) {
38273 + br = au_sbr(sb, bindex);
38274 + if (au_br_writable(br->br_perm)
38275 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38282 + file = ERR_PTR(-ENOMEM);
38283 + page = (void *)__get_free_page(GFP_NOFS);
38284 + if (unlikely(!page))
38286 + path.mnt = au_br_mnt(br);
38287 + path.dentry = au_h_dptr(sb->s_root, bwr);
38288 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38289 + file = (void *)p;
38290 + if (!IS_ERR(p)) {
38291 + strcat(p, "/" AUFS_XINO_FNAME);
38292 + AuDbg("%s\n", p);
38293 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38295 + free_page((unsigned long)page);
38297 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38299 + if (IS_ERR(file))
38301 + h_sb = file->f_path.dentry->d_sb;
38302 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38303 + pr_err("xino doesn't support %s(%s)\n",
38304 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38306 + file = ERR_PTR(-EINVAL);
38314 +/* ---------------------------------------------------------------------- */
38317 + * initialize the xinofile for the specified branch @br
38318 + * at the place/path where @base_file indicates.
38319 + * test whether another branch is on the same filesystem or not,
38320 + * if found then share the xinofile with another branch.
38322 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38323 + struct path *base)
38326 + struct au_xino_do_set_br args = {
38331 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38333 + err = au_xino_do_set_br(sb, base, &args);
38334 + if (unlikely(err))
38340 +/* ---------------------------------------------------------------------- */
38343 + * get an unused inode number from bitmap
38345 +ino_t au_xino_new_ino(struct super_block *sb)
38348 + unsigned long *p, pindex, ul, pend;
38349 + struct au_sbinfo *sbinfo;
38350 + struct file *file;
38351 + int free_bit, err;
38353 + if (!au_opt_test(au_mntflags(sb), XINO))
38354 + return iunique(sb, AUFS_FIRST_INO);
38356 + sbinfo = au_sbi(sb);
38357 + mutex_lock(&sbinfo->si_xib_mtx);
38358 + p = sbinfo->si_xib_buf;
38359 + free_bit = sbinfo->si_xib_next_bit;
38360 + if (free_bit < page_bits && !test_bit(free_bit, p))
38361 + goto out; /* success */
38362 + free_bit = find_first_zero_bit(p, page_bits);
38363 + if (free_bit < page_bits)
38364 + goto out; /* success */
38366 + pindex = sbinfo->si_xib_last_pindex;
38367 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38368 + err = xib_pindex(sb, ul);
38369 + if (unlikely(err))
38371 + free_bit = find_first_zero_bit(p, page_bits);
38372 + if (free_bit < page_bits)
38373 + goto out; /* success */
38376 + file = sbinfo->si_xib;
38377 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38378 + for (ul = pindex + 1; ul <= pend; ul++) {
38379 + err = xib_pindex(sb, ul);
38380 + if (unlikely(err))
38382 + free_bit = find_first_zero_bit(p, page_bits);
38383 + if (free_bit < page_bits)
38384 + goto out; /* success */
38389 + set_bit(free_bit, p);
38390 + sbinfo->si_xib_next_bit = free_bit + 1;
38391 + pindex = sbinfo->si_xib_last_pindex;
38392 + mutex_unlock(&sbinfo->si_xib_mtx);
38393 + ino = xib_calc_ino(pindex, free_bit);
38394 + AuDbg("i%lu\n", (unsigned long)ino);
38397 + mutex_unlock(&sbinfo->si_xib_mtx);
38402 +/* for s_op->delete_inode() */
38403 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38406 + unsigned int mnt_flags;
38407 + aufs_bindex_t bindex, bbot, bi;
38408 + unsigned char try_trunc;
38409 + struct au_iinfo *iinfo;
38410 + struct super_block *sb;
38411 + struct au_hinode *hi;
38412 + struct inode *h_inode;
38413 + struct au_branch *br;
38414 + struct au_xi_calc calc;
38415 + struct file *file;
38417 + AuDebugOn(au_is_bad_inode(inode));
38419 + sb = inode->i_sb;
38420 + mnt_flags = au_mntflags(sb);
38421 + if (!au_opt_test(mnt_flags, XINO)
38422 + || inode->i_ino == AUFS_ROOT_INO)
38426 + au_xigen_inc(inode);
38427 + au_xib_clear_bit(inode);
38430 + iinfo = au_ii(inode);
38431 + bindex = iinfo->ii_btop;
38435 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38436 + hi = au_hinode(iinfo, bindex);
38437 + bbot = iinfo->ii_bbot;
38438 + for (; bindex <= bbot; bindex++, hi++) {
38439 + h_inode = hi->hi_inode;
38441 + || (!unlinked && h_inode->i_nlink))
38444 + /* inode may not be revalidated */
38445 + bi = au_br_index(sb, hi->hi_id);
38449 + br = au_sbr(sb, bi);
38450 + au_xi_calc(sb, h_inode->i_ino, &calc);
38451 + file = au_xino_file(br->br_xino, calc.idx);
38452 + if (IS_ERR_OR_NULL(file))
38455 + err = au_xino_do_write(file, &calc, /*ino*/0);
38456 + if (!err && try_trunc
38457 + && au_test_fs_trunc_xino(au_br_sb(br)))
38458 + xino_try_trunc(sb, br);
38462 +/* ---------------------------------------------------------------------- */
38464 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38466 + int found, total, i;
38469 + total = xi->xi_nondir.total;
38470 + for (i = 0; i < total; i++) {
38471 + if (xi->xi_nondir.array[i] != h_ino)
38480 +static int au_xinondir_expand(struct au_xino *xi)
38485 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38488 + sz = xi->xi_nondir.total * sizeof(ino_t);
38489 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38491 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38492 + /*may_shrink*/0);
38494 + xi->xi_nondir.array = p;
38495 + xi->xi_nondir.total <<= 1;
38496 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38504 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38505 + ino_t h_ino, int idx)
38507 + struct au_xino *xi;
38509 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38510 + xi = au_sbr(sb, bindex)->br_xino;
38511 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38513 + spin_lock(&xi->xi_nondir.spin);
38514 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38515 + xi->xi_nondir.array[idx] = 0;
38516 + spin_unlock(&xi->xi_nondir.spin);
38517 + wake_up_all(&xi->xi_nondir.wqh);
38520 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38523 + int err, found, empty;
38524 + struct au_xino *xi;
38528 + if (!au_opt_test(au_mntflags(sb), XINO))
38529 + goto out; /* no xino */
38531 + xi = au_sbr(sb, bindex)->br_xino;
38534 + spin_lock(&xi->xi_nondir.spin);
38535 + found = au_xinondir_find(xi, h_ino);
38536 + if (found == -1) {
38537 + empty = au_xinondir_find(xi, /*h_ino*/0);
38538 + if (empty == -1) {
38539 + empty = xi->xi_nondir.total;
38540 + err = au_xinondir_expand(xi);
38541 + if (unlikely(err))
38544 + xi->xi_nondir.array[empty] = h_ino;
38547 + spin_unlock(&xi->xi_nondir.spin);
38548 + wait_event(xi->xi_nondir.wqh,
38549 + xi->xi_nondir.array[found] != h_ino);
38554 + spin_unlock(&xi->xi_nondir.spin);
38559 +/* ---------------------------------------------------------------------- */
38561 +int au_xino_path(struct seq_file *seq, struct file *file)
38565 + err = au_seq_path(seq, &file->f_path);
38566 + if (unlikely(err))
38569 +#define Deleted "\\040(deleted)"
38570 + seq->count -= sizeof(Deleted) - 1;
38571 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38572 + sizeof(Deleted) - 1));
38578 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38579 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38580 +++ linux/include/uapi/linux/aufs_type.h 2021-02-22 22:51:59.061411920 +0100
38582 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38584 + * Copyright (C) 2005-2020 Junjiro R. Okajima
38586 + * This program, aufs is free software; you can redistribute it and/or modify
38587 + * it under the terms of the GNU General Public License as published by
38588 + * the Free Software Foundation; either version 2 of the License, or
38589 + * (at your option) any later version.
38591 + * This program is distributed in the hope that it will be useful,
38592 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38593 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38594 + * GNU General Public License for more details.
38596 + * You should have received a copy of the GNU General Public License
38597 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38600 +#ifndef __AUFS_TYPE_H__
38601 +#define __AUFS_TYPE_H__
38603 +#define AUFS_NAME "aufs"
38607 + * define it before including all other headers.
38608 + * sched.h may use pr_* macros before defining "current", so define the
38609 + * no-current version first, and re-define later.
38611 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38612 +#include <linux/sched.h>
38614 +#define pr_fmt(fmt) \
38615 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38616 + (int)sizeof(current->comm), current->comm, current->pid
38617 +#include <linux/limits.h>
38619 +#include <stdint.h>
38620 +#include <sys/types.h>
38621 +#include <limits.h>
38622 +#endif /* __KERNEL__ */
38624 +#define AUFS_VERSION "5.10-20210215"
38626 +/* todo? move this to linux-2.6.19/include/magic.h */
38627 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38629 +/* ---------------------------------------------------------------------- */
38632 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38633 +typedef int8_t aufs_bindex_t;
38634 +#define AUFS_BRANCH_MAX 127
38636 +typedef int16_t aufs_bindex_t;
38637 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38638 +#define AUFS_BRANCH_MAX 511
38639 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38640 +#define AUFS_BRANCH_MAX 1023
38641 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38642 +#define AUFS_BRANCH_MAX 32767
38646 +#ifndef AUFS_BRANCH_MAX
38647 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38649 +#endif /* __KERNEL__ */
38651 +/* ---------------------------------------------------------------------- */
38653 +#define AUFS_FSTYPE AUFS_NAME
38655 +#define AUFS_ROOT_INO 2
38656 +#define AUFS_FIRST_INO 11
38658 +#define AUFS_WH_PFX ".wh."
38659 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38660 +#define AUFS_WH_TMP_LEN 4
38661 +/* a limit for rmdir/rename a dir and copyup */
38662 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38663 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38665 + - AUFS_WH_TMP_LEN) /* hex */
38666 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38667 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38668 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38669 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38670 +#define AUFS_DIRWH_DEF 3
38671 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38672 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38673 +#define AUFS_RDBLK_DEF 512 /* bytes */
38674 +#define AUFS_RDHASH_DEF 32
38675 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38676 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38677 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38678 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38679 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38681 +/* pseudo-link maintenace under /proc */
38682 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38683 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38684 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38686 +/* dirren, renamed dir */
38687 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38688 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38689 +/* whiteouted doubly */
38690 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38691 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38693 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38694 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38696 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38697 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38698 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38700 +/* doubly whiteouted */
38701 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38702 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38703 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38705 +/* branch permissions and attributes */
38706 +#define AUFS_BRPERM_RW "rw"
38707 +#define AUFS_BRPERM_RO "ro"
38708 +#define AUFS_BRPERM_RR "rr"
38709 +#define AUFS_BRATTR_COO_REG "coo_reg"
38710 +#define AUFS_BRATTR_COO_ALL "coo_all"
38711 +#define AUFS_BRATTR_FHSM "fhsm"
38712 +#define AUFS_BRATTR_UNPIN "unpin"
38713 +#define AUFS_BRATTR_ICEX "icex"
38714 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38715 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38716 +#define AUFS_BRATTR_ICEX_TR "icextr"
38717 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38718 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38719 +#define AUFS_BRRATTR_WH "wh"
38720 +#define AUFS_BRWATTR_NLWH "nolwh"
38721 +#define AUFS_BRWATTR_MOO "moo"
38723 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38724 +#define AuBrPerm_RO (1 << 1) /* readonly */
38725 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38726 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38728 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38729 +#define AuBrAttr_COO_ALL (1 << 4)
38730 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38732 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38733 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38734 + branch. meaningless since
38735 + linux-3.18-rc1 */
38737 +/* ignore error in copying XATTR */
38738 +#define AuBrAttr_ICEX_SEC (1 << 7)
38739 +#define AuBrAttr_ICEX_SYS (1 << 8)
38740 +#define AuBrAttr_ICEX_TR (1 << 9)
38741 +#define AuBrAttr_ICEX_USR (1 << 10)
38742 +#define AuBrAttr_ICEX_OTH (1 << 11)
38743 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38744 + | AuBrAttr_ICEX_SYS \
38745 + | AuBrAttr_ICEX_TR \
38746 + | AuBrAttr_ICEX_USR \
38747 + | AuBrAttr_ICEX_OTH)
38749 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38750 +#define AuBrRAttr_Mask AuBrRAttr_WH
38752 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38753 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38754 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38756 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38758 +/* #warning test userspace */
38760 +#ifndef CONFIG_AUFS_FHSM
38761 +#undef AuBrAttr_FHSM
38762 +#define AuBrAttr_FHSM 0
38764 +#ifndef CONFIG_AUFS_XATTR
38765 +#undef AuBrAttr_ICEX
38766 +#define AuBrAttr_ICEX 0
38767 +#undef AuBrAttr_ICEX_SEC
38768 +#define AuBrAttr_ICEX_SEC 0
38769 +#undef AuBrAttr_ICEX_SYS
38770 +#define AuBrAttr_ICEX_SYS 0
38771 +#undef AuBrAttr_ICEX_TR
38772 +#define AuBrAttr_ICEX_TR 0
38773 +#undef AuBrAttr_ICEX_USR
38774 +#define AuBrAttr_ICEX_USR 0
38775 +#undef AuBrAttr_ICEX_OTH
38776 +#define AuBrAttr_ICEX_OTH 0
38780 +/* the longest combination */
38781 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38782 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38783 + "+" AUFS_BRATTR_COO_REG \
38784 + "+" AUFS_BRATTR_FHSM \
38785 + "+" AUFS_BRATTR_UNPIN \
38786 + "+" AUFS_BRATTR_ICEX_SEC \
38787 + "+" AUFS_BRATTR_ICEX_SYS \
38788 + "+" AUFS_BRATTR_ICEX_USR \
38789 + "+" AUFS_BRATTR_ICEX_OTH \
38790 + "+" AUFS_BRWATTR_NLWH)
38793 + char a[AuBrPermStrSz];
38794 +} au_br_perm_str_t;
38796 +static inline int au_br_writable(int brperm)
38798 + return brperm & AuBrPerm_RW;
38801 +static inline int au_br_whable(int brperm)
38803 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38806 +static inline int au_br_wh_linkable(int brperm)
38808 + return !(brperm & AuBrWAttr_NoLinkWH);
38811 +static inline int au_br_cmoo(int brperm)
38813 + return brperm & AuBrAttr_CMOO_Mask;
38816 +static inline int au_br_fhsm(int brperm)
38818 + return brperm & AuBrAttr_FHSM;
38821 +/* ---------------------------------------------------------------------- */
38825 + /* readdir in userspace */
38829 + AuCtl_WBR_FD, /* pathconf wrapper */
38830 + AuCtl_IBUSY, /* busy inode */
38831 + AuCtl_MVDOWN, /* move-down */
38832 + AuCtl_BR, /* info about branches */
38833 + AuCtl_FHSM_FD /* connection for fhsm */
38836 +/* borrowed from linux/include/linux/kernel.h */
38838 +#ifdef _GNU_SOURCE
38839 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38841 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38843 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38846 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38848 +#define __aligned(x) __attribute__((aligned(x)))
38853 +#define __packed __attribute__((packed))
38857 +struct au_rdu_cookie {
38862 + uint32_t generation;
38865 +struct au_rdu_ent {
38874 +static inline int au_rdu_len(int nlen)
38876 + /* include the terminating NULL */
38877 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38878 + sizeof(uint64_t));
38881 +union au_rdu_ent_ul {
38882 + struct au_rdu_ent __user *e;
38894 + uint64_t sz; /* AuCtl_RDU */
38895 + uint64_t nent; /* AuCtl_RDU_INO */
38897 + union au_rdu_ent_ul ent;
38898 + uint16_t verify[AufsCtlRduV_End];
38900 + /* input/output */
38904 + union au_rdu_ent_ul tail;
38905 + /* number of entries which were added in a single call */
38910 + struct au_rdu_cookie cookie;
38913 +/* ---------------------------------------------------------------------- */
38915 +/* dirren. the branch is identified by the filename who contains this */
38916 +struct au_drinfo {
38919 + uint8_t oldnamelen;
38920 + uint64_t _padding;
38922 + uint8_t oldname[];
38925 +struct au_drinfo_fdata {
38927 + struct au_drinfo drinfo;
38930 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38932 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38934 +/* ---------------------------------------------------------------------- */
38936 +struct aufs_wbr_fd {
38941 +/* ---------------------------------------------------------------------- */
38943 +struct aufs_ibusy {
38944 + uint64_t ino, h_ino;
38948 +/* ---------------------------------------------------------------------- */
38950 +/* error code for move-down */
38951 +/* the actual message strings are implemented in aufs-util.git */
38953 + EAU_MVDOWN_OPAQUE = 1,
38954 + EAU_MVDOWN_WHITEOUT,
38955 + EAU_MVDOWN_UPPER,
38956 + EAU_MVDOWN_BOTTOM,
38957 + EAU_MVDOWN_NOUPPER,
38958 + EAU_MVDOWN_NOLOWERBR,
38962 +/* flags for move-down */
38963 +#define AUFS_MVDOWN_DMSG 1
38964 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38965 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38966 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38967 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38968 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38969 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38970 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38971 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38972 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38973 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38974 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38975 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38977 +/* index for move-down */
38979 + AUFS_MVDOWN_UPPER,
38980 + AUFS_MVDOWN_LOWER,
38981 + AUFS_MVDOWN_NARRAY
38985 + * additional info of move-down
38986 + * number of free blocks and inodes.
38987 + * subset of struct kstatfs, but smaller and always 64bit.
38989 +struct aufs_stfs {
38990 + uint64_t f_blocks;
38991 + uint64_t f_bavail;
38992 + uint64_t f_files;
38993 + uint64_t f_ffree;
38996 +struct aufs_stbr {
38997 + int16_t brid; /* optional input */
38998 + int16_t bindex; /* output */
38999 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39002 +struct aufs_mvdown {
39003 + uint32_t flags; /* input/output */
39004 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39005 + int8_t au_errno; /* output */
39008 +/* ---------------------------------------------------------------------- */
39010 +union aufs_brinfo {
39011 + /* PATH_MAX may differ between kernel-space and user-space */
39012 + char _spacer[4096];
39020 +/* ---------------------------------------------------------------------- */
39022 +#define AuCtlType 'A'
39023 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39024 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39025 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39026 + struct aufs_wbr_fd)
39027 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39028 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39029 + struct aufs_mvdown)
39030 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39031 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39033 +#endif /* __AUFS_TYPE_H__ */
39034 SPDX-License-Identifier: GPL-2.0
39035 aufs5.10 loopback patch
39037 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39038 index 7be7ca3f54547..a163aeade6148 100644
39039 --- a/drivers/block/loop.c
39040 +++ b/drivers/block/loop.c
39041 @@ -650,6 +650,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39045 +static struct file *loop_real_file(struct file *file)
39047 + struct file *f = NULL;
39049 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39050 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39054 static void loop_reread_partitions(struct loop_device *lo,
39055 struct block_device *bdev)
39057 @@ -705,6 +714,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39060 struct file *file = NULL, *old_file;
39061 + struct file *f, *virt_file = NULL, *old_virt_file;
39065 @@ -724,12 +734,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39069 + f = loop_real_file(file);
39071 + virt_file = file;
39076 error = loop_validate_file(file, bdev);
39080 old_file = lo->lo_backing_file;
39081 + old_virt_file = lo->lo_backing_virt_file;
39085 @@ -741,6 +758,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39086 blk_mq_freeze_queue(lo->lo_queue);
39087 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39088 lo->lo_backing_file = file;
39089 + lo->lo_backing_virt_file = virt_file;
39090 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39091 mapping_set_gfp_mask(file->f_mapping,
39092 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39093 @@ -754,6 +772,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39097 + if (old_virt_file)
39098 + fput(old_virt_file);
39100 loop_reread_partitions(lo, bdev);
39102 @@ -762,6 +782,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39103 mutex_unlock(&loop_ctl_mutex);
39111 @@ -1090,7 +1112,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39112 struct block_device *bdev,
39113 const struct loop_config *config)
39115 - struct file *file;
39116 + struct file *file, *f, *virt_file = NULL;
39117 struct inode *inode;
39118 struct address_space *mapping;
39119 struct block_device *claimed_bdev = NULL;
39120 @@ -1106,6 +1128,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39121 file = fget(config->fd);
39124 + f = loop_real_file(file);
39126 + virt_file = file;
39132 * If we don't hold exclusive handle for the device, upgrade to it
39133 @@ -1161,6 +1189,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39134 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39135 lo->lo_device = bdev;
39136 lo->lo_backing_file = file;
39137 + lo->lo_backing_virt_file = virt_file;
39138 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39139 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39141 @@ -1214,6 +1243,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39142 bd_abort_claiming(bdev, claimed_bdev, loop_configure);
39148 /* This is safe: open() is still holding a reference. */
39149 module_put(THIS_MODULE);
39150 @@ -1223,6 +1254,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39151 static int __loop_clr_fd(struct loop_device *lo, bool release)
39153 struct file *filp = NULL;
39154 + struct file *virt_filp = lo->lo_backing_virt_file;
39155 gfp_t gfp = lo->old_gfp_mask;
39156 struct block_device *bdev = lo->lo_device;
39158 @@ -1246,6 +1278,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39160 spin_lock_irq(&lo->lo_lock);
39161 lo->lo_backing_file = NULL;
39162 + lo->lo_backing_virt_file = NULL;
39163 spin_unlock_irq(&lo->lo_lock);
39165 loop_release_xfer(lo);
39166 @@ -1329,6 +1362,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39175 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39176 index af75a5ee40944..1d847cb194ff6 100644
39177 --- a/drivers/block/loop.h
39178 +++ b/drivers/block/loop.h
39179 @@ -46,7 +46,7 @@ struct loop_device {
39180 int (*ioctl)(struct loop_device *, int cmd,
39181 unsigned long arg);
39183 - struct file * lo_backing_file;
39184 + struct file *lo_backing_file, *lo_backing_virt_file;
39185 struct block_device *lo_device;
39188 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39189 index 5ef279a59bb14..6447c37f98756 100644
39190 --- a/fs/aufs/f_op.c
39191 +++ b/fs/aufs/f_op.c
39192 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39193 if (IS_ERR(h_file))
39196 - if (au_test_loopback_kthread()) {
39197 + if (0 && au_test_loopback_kthread()) {
39198 au_warn_loopback(h_file->f_path.dentry->d_sb);
39199 if (file->f_mapping != h_file->f_mapping) {
39200 file->f_mapping = h_file->f_mapping;
39201 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39202 index a8b63acc62045..9d97c3af5686a 100644
39203 --- a/fs/aufs/loop.c
39204 +++ b/fs/aufs/loop.c
39205 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39206 symbol_put(loop_backing_file);
39207 au_kfree_try_rcu(au_warn_loopback_array);
39210 +/* ---------------------------------------------------------------------- */
39212 +/* support the loopback block device insude aufs */
39214 +struct file *aufs_real_loop(struct file *file)
39218 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39219 + fi_read_lock(file);
39220 + f = au_hf_top(file);
39221 + fi_read_unlock(file);
39225 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39226 index 94f4f80ae33bf..ca1194354aff4 100644
39227 --- a/fs/aufs/loop.h
39228 +++ b/fs/aufs/loop.h
39229 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39231 int au_loopback_init(void);
39232 void au_loopback_fin(void);
39234 +struct file *aufs_real_loop(struct file *file);
39236 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39238 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39240 AuStubInt0(au_loopback_init, void)
39241 AuStubVoid(au_loopback_fin, void)
39243 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39244 #endif /* BLK_DEV_LOOP */
39246 #endif /* __KERNEL__ */
39247 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39248 index 589dd01220201..801e0a7faec59 100644
39249 --- a/fs/aufs/super.c
39250 +++ b/fs/aufs/super.c
39251 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39252 .statfs = aufs_statfs,
39253 .put_super = aufs_put_super,
39254 .sync_fs = aufs_sync_fs,
39255 - .remount_fs = aufs_remount_fs
39256 + .remount_fs = aufs_remount_fs,
39257 +#ifdef CONFIG_AUFS_BDEV_LOOP
39258 + .real_loop = aufs_real_loop
39262 /* ---------------------------------------------------------------------- */
39263 diff --git a/include/linux/fs.h b/include/linux/fs.h
39264 index 837dd6e727e45..0a05534f8582f 100644
39265 --- a/include/linux/fs.h
39266 +++ b/include/linux/fs.h
39267 @@ -1967,6 +1967,10 @@ struct super_operations {
39268 struct shrink_control *);
39269 long (*free_cached_objects)(struct super_block *,
39270 struct shrink_control *);
39271 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39273 + struct file *(*real_loop)(struct file *);